1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
25 | |
---|
26 | function history_tabsheet() |
---|
27 | { |
---|
28 | global $page, $link_start; |
---|
29 | |
---|
30 | // TabSheet |
---|
31 | $tabsheet = new tabsheet(); |
---|
32 | // TabSheet initialization |
---|
33 | $tabsheet->add('stats', l10n('Statistics'), $link_start.'stats'); |
---|
34 | $tabsheet->add('history', l10n('Search'), $link_start.'history'); |
---|
35 | // TabSheet selection |
---|
36 | $tabsheet->select($page['page']); |
---|
37 | // Assign tabsheet to template |
---|
38 | $tabsheet->assign(); |
---|
39 | } |
---|
40 | |
---|
41 | function history_compare($a, $b) |
---|
42 | { |
---|
43 | return strcmp($a['date'].$a['time'], $b['date'].$b['time']); |
---|
44 | } |
---|
45 | |
---|
46 | function get_history($data, $search, $types) |
---|
47 | { |
---|
48 | if (isset($search['fields']['filename'])) |
---|
49 | { |
---|
50 | $query = ' |
---|
51 | SELECT |
---|
52 | id |
---|
53 | FROM '.IMAGES_TABLE.' |
---|
54 | WHERE file LIKE \''.$search['fields']['filename'].'\' |
---|
55 | ;'; |
---|
56 | $search['image_ids'] = array_from_query($query, 'id'); |
---|
57 | } |
---|
58 | |
---|
59 | // echo '<pre>'; print_r($search); echo '</pre>'; |
---|
60 | |
---|
61 | $clauses = array(); |
---|
62 | |
---|
63 | if (isset($search['fields']['date-after'])) |
---|
64 | { |
---|
65 | array_push( |
---|
66 | $clauses, |
---|
67 | "date >= '".$search['fields']['date-after']."'" |
---|
68 | ); |
---|
69 | } |
---|
70 | |
---|
71 | if (isset($search['fields']['date-before'])) |
---|
72 | { |
---|
73 | array_push( |
---|
74 | $clauses, |
---|
75 | "date <= '".$search['fields']['date-before']."'" |
---|
76 | ); |
---|
77 | } |
---|
78 | |
---|
79 | if (isset($search['fields']['types'])) |
---|
80 | { |
---|
81 | $local_clauses = array(); |
---|
82 | |
---|
83 | foreach ($types as $type) { |
---|
84 | if (in_array($type, $search['fields']['types'])) { |
---|
85 | $clause = 'image_type '; |
---|
86 | if ($type == 'none') |
---|
87 | { |
---|
88 | $clause.= 'IS NULL'; |
---|
89 | } |
---|
90 | else |
---|
91 | { |
---|
92 | $clause.= "= '".$type."'"; |
---|
93 | } |
---|
94 | |
---|
95 | array_push($local_clauses, $clause); |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | if (count($local_clauses) > 0) |
---|
100 | { |
---|
101 | array_push( |
---|
102 | $clauses, |
---|
103 | implode(' OR ', $local_clauses) |
---|
104 | ); |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | if (isset($search['fields']['user']) |
---|
109 | and $search['fields']['user'] != -1) |
---|
110 | { |
---|
111 | array_push( |
---|
112 | $clauses, |
---|
113 | 'user_id = '.$search['fields']['user'] |
---|
114 | ); |
---|
115 | } |
---|
116 | |
---|
117 | if (isset($search['fields']['image_id'])) |
---|
118 | { |
---|
119 | array_push( |
---|
120 | $clauses, |
---|
121 | 'image_id = '.$search['fields']['image_id'] |
---|
122 | ); |
---|
123 | } |
---|
124 | |
---|
125 | if (isset($search['fields']['filename'])) |
---|
126 | { |
---|
127 | if (count($search['image_ids']) == 0) |
---|
128 | { |
---|
129 | // a clause that is always false |
---|
130 | array_push($clauses, '1 = 2 '); |
---|
131 | } |
---|
132 | else |
---|
133 | { |
---|
134 | array_push( |
---|
135 | $clauses, |
---|
136 | 'image_id IN ('.implode(', ', $search['image_ids']).')' |
---|
137 | ); |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | $clauses = prepend_append_array_items($clauses, '(', ')'); |
---|
142 | |
---|
143 | $where_separator = |
---|
144 | implode( |
---|
145 | "\n AND ", |
---|
146 | $clauses |
---|
147 | ); |
---|
148 | |
---|
149 | $query = ' |
---|
150 | SELECT |
---|
151 | date, |
---|
152 | time, |
---|
153 | user_id, |
---|
154 | IP, |
---|
155 | section, |
---|
156 | category_id, |
---|
157 | tag_ids, |
---|
158 | image_id, |
---|
159 | image_type |
---|
160 | FROM '.HISTORY_TABLE.' |
---|
161 | WHERE '.$where_separator.' |
---|
162 | ;'; |
---|
163 | |
---|
164 | // LIMIT '.$conf['nb_logs_page'].' OFFSET '.$page['start'].' |
---|
165 | |
---|
166 | $result = pwg_query($query); |
---|
167 | |
---|
168 | while ($row = pwg_db_fetch_assoc($result)) |
---|
169 | { |
---|
170 | array_push($data, $row); |
---|
171 | } |
---|
172 | |
---|
173 | return $data; |
---|
174 | } |
---|
175 | |
---|
176 | add_event_handler('get_history', 'get_history', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
177 | trigger_action('functions_history_included'); |
---|
178 | |
---|
179 | ?> |
---|