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

Last change on this file since 25018 was 25018, checked in by mistic100, 11 years ago

remove all array_push (50% slower than []) + some changes missing for feature:2978

  • Property svn:eol-style set to LF
File size: 4.3 KB
Line 
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
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->set_id('history');
33  $tabsheet->select($page['page']);
34  $tabsheet->assign();
35}
36
37function history_compare($a, $b)
38{
39  return strcmp($a['date'].$a['time'], $b['date'].$b['time']);
40}
41
42function get_history($data, $search, $types)
43{
44  if (isset($search['fields']['filename']))
45  {
46    $query = '
47SELECT
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    $clauses[] = "date >= '".$search['fields']['date-after']."'";
62  }
63
64  if (isset($search['fields']['date-before']))
65  {
66    $clauses[] = "date <= '".$search['fields']['date-before']."'";
67  }
68
69  if (isset($search['fields']['types']))
70  {
71    $local_clauses = array();
72   
73    foreach ($types as $type) {
74      if (in_array($type, $search['fields']['types'])) {
75        $clause = 'image_type ';
76        if ($type == 'none')
77        {
78          $clause.= 'IS NULL';
79        }
80        else
81        {
82          $clause.= "= '".$type."'";
83        }
84       
85        $local_clauses[] = $clause;
86      }
87    }
88   
89    if (count($local_clauses) > 0)
90    {
91      $clauses[] = implode(' OR ', $local_clauses);
92    }
93  }
94
95  if (isset($search['fields']['user'])
96      and $search['fields']['user'] != -1)
97  {
98    $clauses[] = 'user_id = '.$search['fields']['user'];
99  }
100
101  if (isset($search['fields']['image_id']))
102  {
103    $clauses[] = 'image_id = '.$search['fields']['image_id'];
104  }
105 
106  if (isset($search['fields']['filename']))
107  {
108    if (count($search['image_ids']) == 0)
109    {
110      // a clause that is always false
111      $clauses[] = '1 = 2 ';
112    }
113    else
114    {
115      $clauses[] = 'image_id IN ('.implode(', ', $search['image_ids']).')';
116    }
117  }
118
119  if (isset($search['fields']['ip']))
120  {
121    $clauses[] = 'IP LIKE "'.$search['fields']['ip'].'"';
122  }
123 
124  $clauses = prepend_append_array_items($clauses, '(', ')');
125
126  $where_separator =
127    implode(
128      "\n    AND ",
129      $clauses
130      );
131 
132  $query = '
133SELECT
134    date,
135    time,
136    user_id,
137    IP,
138    section,
139    category_id,
140    tag_ids,
141    image_id,
142    image_type
143  FROM '.HISTORY_TABLE.'
144  WHERE '.$where_separator.'
145;';
146
147  // LIMIT '.$conf['nb_logs_page'].' OFFSET '.$page['start'].'
148
149  $result = pwg_query($query);
150
151  while ($row = pwg_db_fetch_assoc($result))
152  {
153    $data[] = $row;
154  }
155
156  return $data;
157}
158
159add_event_handler('get_history', 'get_history', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
160trigger_action('functions_history_included');
161
162?>
Note: See TracBrowser for help on using the repository browser.