1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2013 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->set_id('history'); |
---|
33 | $tabsheet->select($page['page']); |
---|
34 | $tabsheet->assign(); |
---|
35 | } |
---|
36 | |
---|
37 | function history_compare($a, $b) |
---|
38 | { |
---|
39 | return strcmp($a['date'].$a['time'], $b['date'].$b['time']); |
---|
40 | } |
---|
41 | |
---|
42 | function get_history($data, $search, $types) |
---|
43 | { |
---|
44 | if (isset($search['fields']['filename'])) |
---|
45 | { |
---|
46 | $query = ' |
---|
47 | SELECT |
---|
48 | id |
---|
49 | FROM '.IMAGES_TABLE.' |
---|
50 | WHERE file LIKE \''.$search['fields']['filename'].'\' |
---|
51 | ;'; |
---|
52 | $search['image_ids'] = array_from_query($query, 'id'); |
---|
53 | } |
---|
54 | |
---|
55 | // echo '<pre>'; print_r($search); echo '</pre>'; |
---|
56 | |
---|
57 | $clauses = array(); |
---|
58 | |
---|
59 | if (isset($search['fields']['date-after'])) |
---|
60 | { |
---|
61 | array_push( |
---|
62 | $clauses, |
---|
63 | "date >= '".$search['fields']['date-after']."'" |
---|
64 | ); |
---|
65 | } |
---|
66 | |
---|
67 | if (isset($search['fields']['date-before'])) |
---|
68 | { |
---|
69 | array_push( |
---|
70 | $clauses, |
---|
71 | "date <= '".$search['fields']['date-before']."'" |
---|
72 | ); |
---|
73 | } |
---|
74 | |
---|
75 | if (isset($search['fields']['types'])) |
---|
76 | { |
---|
77 | $local_clauses = array(); |
---|
78 | |
---|
79 | foreach ($types as $type) { |
---|
80 | if (in_array($type, $search['fields']['types'])) { |
---|
81 | $clause = 'image_type '; |
---|
82 | if ($type == 'none') |
---|
83 | { |
---|
84 | $clause.= 'IS NULL'; |
---|
85 | } |
---|
86 | else |
---|
87 | { |
---|
88 | $clause.= "= '".$type."'"; |
---|
89 | } |
---|
90 | |
---|
91 | array_push($local_clauses, $clause); |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | if (count($local_clauses) > 0) |
---|
96 | { |
---|
97 | array_push( |
---|
98 | $clauses, |
---|
99 | implode(' OR ', $local_clauses) |
---|
100 | ); |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | if (isset($search['fields']['user']) |
---|
105 | and $search['fields']['user'] != -1) |
---|
106 | { |
---|
107 | array_push( |
---|
108 | $clauses, |
---|
109 | 'user_id = '.$search['fields']['user'] |
---|
110 | ); |
---|
111 | } |
---|
112 | |
---|
113 | if (isset($search['fields']['image_id'])) |
---|
114 | { |
---|
115 | array_push( |
---|
116 | $clauses, |
---|
117 | 'image_id = '.$search['fields']['image_id'] |
---|
118 | ); |
---|
119 | } |
---|
120 | |
---|
121 | if (isset($search['fields']['filename'])) |
---|
122 | { |
---|
123 | if (count($search['image_ids']) == 0) |
---|
124 | { |
---|
125 | // a clause that is always false |
---|
126 | array_push($clauses, '1 = 2 '); |
---|
127 | } |
---|
128 | else |
---|
129 | { |
---|
130 | array_push( |
---|
131 | $clauses, |
---|
132 | 'image_id IN ('.implode(', ', $search['image_ids']).')' |
---|
133 | ); |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | if (isset($search['fields']['ip'])) |
---|
138 | { |
---|
139 | $clauses[] = 'IP LIKE "'.$search['fields']['ip'].'"'; |
---|
140 | } |
---|
141 | |
---|
142 | $clauses = prepend_append_array_items($clauses, '(', ')'); |
---|
143 | |
---|
144 | $where_separator = |
---|
145 | implode( |
---|
146 | "\n AND ", |
---|
147 | $clauses |
---|
148 | ); |
---|
149 | |
---|
150 | $query = ' |
---|
151 | SELECT |
---|
152 | date, |
---|
153 | time, |
---|
154 | user_id, |
---|
155 | IP, |
---|
156 | section, |
---|
157 | category_id, |
---|
158 | tag_ids, |
---|
159 | image_id, |
---|
160 | image_type |
---|
161 | FROM '.HISTORY_TABLE.' |
---|
162 | WHERE '.$where_separator.' |
---|
163 | ;'; |
---|
164 | |
---|
165 | // LIMIT '.$conf['nb_logs_page'].' OFFSET '.$page['start'].' |
---|
166 | |
---|
167 | $result = pwg_query($query); |
---|
168 | |
---|
169 | while ($row = pwg_db_fetch_assoc($result)) |
---|
170 | { |
---|
171 | array_push($data, $row); |
---|
172 | } |
---|
173 | |
---|
174 | return $data; |
---|
175 | } |
---|
176 | |
---|
177 | add_event_handler('get_history', 'get_history', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
178 | trigger_action('functions_history_included'); |
---|
179 | |
---|
180 | ?> |
---|