1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of dcLog, a plugin for Dotclear. |
---|
4 | # |
---|
5 | # Copyright (c) 2010 Tomtom |
---|
6 | # http://blog.zenstyle.fr/ |
---|
7 | # |
---|
8 | # Licensed under the GPL version 2.0 license. |
---|
9 | # A copy of this license is available in LICENSE file or at |
---|
10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
13 | |
---|
14 | # Get out not superAdmin! |
---|
15 | if (!$core->auth->isSuperAdmin()) { return; } |
---|
16 | |
---|
17 | # Var initialisation |
---|
18 | $p_url = 'plugin.php?p=dcLog'; |
---|
19 | $page = isset($_GET['page']) ? $_GET['page'] : 1; |
---|
20 | $status = isset($_GET['status']) ? $_GET['status'] : null; |
---|
21 | # filter initialisation |
---|
22 | $blog_id = isset($_GET['blog_id']) ? $_GET['blog_id'] : null; |
---|
23 | $user_id = isset($_GET['user_id']) ? $_GET['user_id'] : null; |
---|
24 | $table = isset($_GET['table']) ? $_GET['table'] : null; |
---|
25 | $ip = isset($_GET['ip']) ? $_GET['ip'] : null; |
---|
26 | $nb = isset($_GET['nb']) ? $_GET['nb'] : 20; |
---|
27 | # form initialisation |
---|
28 | $ids = isset($_POST['ids']) ? $_POST['ids'] : null; |
---|
29 | $del_all_log = isset($_POST['del_all_logs']) ? true : false; |
---|
30 | |
---|
31 | # Delete logs |
---|
32 | if (isset($_POST['del_logs']) || isset($_POST['del_all_logs'])) |
---|
33 | { |
---|
34 | try { |
---|
35 | $core->log->delLogs($ids,$del_all_log); |
---|
36 | $status = $del_all_log ? '2' : '1'; |
---|
37 | http::redirect($p_url.'&del='.$status); |
---|
38 | } |
---|
39 | catch (Exception $e) { |
---|
40 | $core->error->add($e->getMessage()); |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | # Gets logs & prepares display object |
---|
45 | $params = array( |
---|
46 | 'blog_id' => $blog_id, |
---|
47 | 'user_id' => !is_null($user_id) && $user_id !== '' ? explode(',',$user_id) : $user_id, |
---|
48 | 'log_table' => !is_null($table) && $table !== '' ? explode(',',$table) : $table, |
---|
49 | 'log_ip' => !is_null($ip) && $ip !== '' ? explode(',',$ip) : $ip |
---|
50 | ); |
---|
51 | $l_rs = $core->log->getLogs($params); |
---|
52 | $l_nb = $l_rs->count(); |
---|
53 | $l_list = new dcLogList($core,$l_rs,$l_nb); |
---|
54 | |
---|
55 | # Display |
---|
56 | echo |
---|
57 | '<html>'. |
---|
58 | '<head>'. |
---|
59 | '<title>'.__('Log').'</title>'. |
---|
60 | dcPage::jsLoad('js/filter-controls.js'). |
---|
61 | dcPage::jsLoad('index.php?pf=dcLog/js/dclog.js'). |
---|
62 | '<script type="text/javascript">'. |
---|
63 | '//<![CDATA['."\n". |
---|
64 | dcPage::jsVar('dotclear.msg.confirm_delete_selected_log',__('Are you sure you want to delete selected logs?')). |
---|
65 | dcPage::jsVar('dotclear.msg.confirm_delete_all_log',__('Are you sure you want to delete all logs?')). |
---|
66 | '//]]>'. |
---|
67 | '</script>'. |
---|
68 | '</head>'."\n". |
---|
69 | '<body>'; |
---|
70 | |
---|
71 | # Message |
---|
72 | if (isset($_GET['del'])) { |
---|
73 | $msg = ''; |
---|
74 | |
---|
75 | if ((integer) $_GET['del'] === 1) { |
---|
76 | $msg = __('Selected logs have been successfully deleted'); |
---|
77 | } |
---|
78 | if ((integer) $_GET['del'] === 2) { |
---|
79 | $msg = __('All logs have been successfully deleted'); |
---|
80 | } |
---|
81 | |
---|
82 | echo !empty($msg) ? '<p class="message">'.$msg.'</p>' : ''; |
---|
83 | } |
---|
84 | |
---|
85 | # Combo blog |
---|
86 | $combo_blog = array(__('All blogs') => 'all'); |
---|
87 | $blogs = $core->getBlogs(); |
---|
88 | while ($blogs->fetch()) { |
---|
89 | $combo_blog[sprintf('%s (%s)',$blogs->blog_name,$blogs->blog_id)] = $blogs->blog_id; |
---|
90 | } |
---|
91 | |
---|
92 | echo |
---|
93 | '<h2>'.html::escapeHTML($core->blog->name).' › '.__('Log').'</h2>'. |
---|
94 | '<p><a id="filter-control" class="form-control" href="#">'. |
---|
95 | __('Filters').'</a></p>'. |
---|
96 | '<form action="'.$p_url.'" method="get" id="filters-form">'. |
---|
97 | form::hidden('p','dcLog'). |
---|
98 | '<fieldset><legend>'.__('Filters').'</legend>'. |
---|
99 | '<div class="two-cols"><div class="col">'. |
---|
100 | '<p><label>'.__('Blog:'). |
---|
101 | form::combo('blog_id',$combo_blog,$blog_id).'</label></p>'. |
---|
102 | '<p><label>'.__('User:'). |
---|
103 | form::field('user_id',20,50,$user_id).'</label></p>'. |
---|
104 | '<p><label class="classic">'. form::field('nb',3,3,$nb).' '. |
---|
105 | __('Logs per page').'</label> '. |
---|
106 | '<input type="submit" value="'.__('filter').'" /></p>'. |
---|
107 | '</div><div class="col">'. |
---|
108 | '<p><label>'.__('IP:'). |
---|
109 | form::field('ip',20,50,$ip).'</label></p>'. |
---|
110 | '<p><label>'.__('Component:'). |
---|
111 | form::field('table',20,50,$table).'</label></p>'. |
---|
112 | '</div></div>'. |
---|
113 | '<br class="clear" />'. //Opera sucks |
---|
114 | '</fieldset>'. |
---|
115 | '</form>'; |
---|
116 | |
---|
117 | $l_list->display($page,$nb, |
---|
118 | '<form action="'.$p_url.'" method="post" id="form-logs">'. |
---|
119 | |
---|
120 | '%s'. |
---|
121 | |
---|
122 | '<div class="two-cols">'. |
---|
123 | '<p class="col checkboxes-helpers"></p>'. |
---|
124 | |
---|
125 | '<p class="col right"><input type="submit" value="'. |
---|
126 | __('Delete selected logs').'" name="del_logs" /> '. |
---|
127 | '<input type="submit" value="'.__('Delete all logs').'" '. |
---|
128 | 'name="del_all_logs" /></p>'. |
---|
129 | $core->formNonce(). |
---|
130 | '</div>'. |
---|
131 | '</form>' |
---|
132 | ); |
---|
133 | |
---|
134 | echo |
---|
135 | '</body>'. |
---|
136 | '</html>'; |
---|
137 | |
---|
138 | ?> |
---|