source: trunk/admin/include/functions_history.inc.php @ 14688

Revision 14688, 4.7 KB checked in by rvelices, 8 years ago (diff)

feature 2601: Allow searching by ip in admin history
also remove php warnings when tags zere deleted after visits

  • Property svn:eol-style set to LF
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 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
24include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
25
26function 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
41function history_compare($a, $b)
42{
43  return strcmp($a['date'].$a['time'], $b['date'].$b['time']);
44}
45
46function get_history($data, $search, $types)
47{
48  if (isset($search['fields']['filename']))
49  {
50    $query = '
51SELECT
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  if (isset($search['fields']['ip']))
142  {
143    $clauses[] = 'IP LIKE "'.$search['fields']['ip'].'"';
144  }
145 
146  $clauses = prepend_append_array_items($clauses, '(', ')');
147
148  $where_separator =
149    implode(
150      "\n    AND ",
151      $clauses
152      );
153 
154  $query = '
155SELECT
156    date,
157    time,
158    user_id,
159    IP,
160    section,
161    category_id,
162    tag_ids,
163    image_id,
164    image_type
165  FROM '.HISTORY_TABLE.'
166  WHERE '.$where_separator.'
167;';
168
169  // LIMIT '.$conf['nb_logs_page'].' OFFSET '.$page['start'].'
170
171  $result = pwg_query($query);
172
173  while ($row = pwg_db_fetch_assoc($result))
174  {
175    array_push($data, $row);
176  }
177
178  return $data;
179}
180
181add_event_handler('get_history', 'get_history', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
182trigger_action('functions_history_included');
183
184?>
Note: See TracBrowser for help on using the repository browser.