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

Last change on this file since 26946 was 26946, checked in by mistic100, 10 years ago

feature 2999; docblocks for history, install and metadata

  • Property svn:eol-style set to LF
File size: 4.6 KB
RevLine 
[1900]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[26461]5// | Copyright(C) 2008-2014 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[1900]23
[26946]24/**
25 * @package functions\admin\history
26 */
27
28
[2226]29include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
[1900]30
[26946]31/**
32 * Init tabsheet for history pages
33 * @ignore
34 */
[1900]35function history_tabsheet()
36{
37  global $page, $link_start;
38
[2226]39  // TabSheet
40  $tabsheet = new tabsheet();
[16925]41  $tabsheet->set_id('history');
[2226]42  $tabsheet->select($page['page']);
43  $tabsheet->assign();
[1900]44}
45
[26946]46/**
47 * Callback used to sort history entries
48 */
[2157]49function history_compare($a, $b)
50{
51  return strcmp($a['date'].$a['time'], $b['date'].$b['time']);
52}
53
[26946]54/**
55 * Perform history search.
56 *
57 * @param array $data  - used in trigger_change
58 * @param array $search
59 * @param string[] $types
60 * @param array
61 */
[2157]62function get_history($data, $search, $types)
63{
64  if (isset($search['fields']['filename']))
65  {
66    $query = '
67SELECT
68    id
69  FROM '.IMAGES_TABLE.'
70  WHERE file LIKE \''.$search['fields']['filename'].'\'
71;';
72    $search['image_ids'] = array_from_query($query, 'id');
73  }
74 
75  // echo '<pre>'; print_r($search); echo '</pre>';
76 
77  $clauses = array();
78
79  if (isset($search['fields']['date-after']))
80  {
[25018]81    $clauses[] = "date >= '".$search['fields']['date-after']."'";
[2157]82  }
83
84  if (isset($search['fields']['date-before']))
85  {
[25018]86    $clauses[] = "date <= '".$search['fields']['date-before']."'";
[2157]87  }
88
89  if (isset($search['fields']['types']))
90  {
91    $local_clauses = array();
92   
93    foreach ($types as $type) {
94      if (in_array($type, $search['fields']['types'])) {
95        $clause = 'image_type ';
96        if ($type == 'none')
97        {
98          $clause.= 'IS NULL';
99        }
100        else
101        {
102          $clause.= "= '".$type."'";
103        }
104       
[25018]105        $local_clauses[] = $clause;
[2157]106      }
107    }
108   
109    if (count($local_clauses) > 0)
110    {
[25018]111      $clauses[] = implode(' OR ', $local_clauses);
[2157]112    }
113  }
114
115  if (isset($search['fields']['user'])
116      and $search['fields']['user'] != -1)
117  {
[25018]118    $clauses[] = 'user_id = '.$search['fields']['user'];
[2157]119  }
120
121  if (isset($search['fields']['image_id']))
122  {
[25018]123    $clauses[] = 'image_id = '.$search['fields']['image_id'];
[2157]124  }
125 
126  if (isset($search['fields']['filename']))
127  {
128    if (count($search['image_ids']) == 0)
129    {
130      // a clause that is always false
[25018]131      $clauses[] = '1 = 2 ';
[2157]132    }
133    else
134    {
[25018]135      $clauses[] = 'image_id IN ('.implode(', ', $search['image_ids']).')';
[2157]136    }
137  }
[14688]138
139  if (isset($search['fields']['ip']))
140  {
141    $clauses[] = 'IP LIKE "'.$search['fields']['ip'].'"';
142  }
[2157]143 
144  $clauses = prepend_append_array_items($clauses, '(', ')');
145
146  $where_separator =
147    implode(
148      "\n    AND ",
149      $clauses
150      );
151 
152  $query = '
153SELECT
154    date,
155    time,
156    user_id,
157    IP,
158    section,
159    category_id,
160    tag_ids,
161    image_id,
162    image_type
163  FROM '.HISTORY_TABLE.'
164  WHERE '.$where_separator.'
165;';
166
[4334]167  // LIMIT '.$conf['nb_logs_page'].' OFFSET '.$page['start'].'
[2157]168
169  $result = pwg_query($query);
170
[4325]171  while ($row = pwg_db_fetch_assoc($result))
[2157]172  {
[25018]173    $data[] = $row;
[2157]174  }
175
176  return $data;
177}
178
179add_event_handler('get_history', 'get_history', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
180trigger_action('functions_history_included');
181
[25018]182?>
Note: See TracBrowser for help on using the repository browser.