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
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2014 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/**
25 * @package functions\admin\history
26 */
27
28
29include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
30
31/**
32 * Init tabsheet for history pages
33 * @ignore
34 */
35function history_tabsheet()
36{
37  global $page, $link_start;
38
39  // TabSheet
40  $tabsheet = new tabsheet();
41  $tabsheet->set_id('history');
42  $tabsheet->select($page['page']);
43  $tabsheet->assign();
44}
45
46/**
47 * Callback used to sort history entries
48 */
49function history_compare($a, $b)
50{
51  return strcmp($a['date'].$a['time'], $b['date'].$b['time']);
52}
53
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 */
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  {
81    $clauses[] = "date >= '".$search['fields']['date-after']."'";
82  }
83
84  if (isset($search['fields']['date-before']))
85  {
86    $clauses[] = "date <= '".$search['fields']['date-before']."'";
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       
105        $local_clauses[] = $clause;
106      }
107    }
108   
109    if (count($local_clauses) > 0)
110    {
111      $clauses[] = implode(' OR ', $local_clauses);
112    }
113  }
114
115  if (isset($search['fields']['user'])
116      and $search['fields']['user'] != -1)
117  {
118    $clauses[] = 'user_id = '.$search['fields']['user'];
119  }
120
121  if (isset($search['fields']['image_id']))
122  {
123    $clauses[] = 'image_id = '.$search['fields']['image_id'];
124  }
125 
126  if (isset($search['fields']['filename']))
127  {
128    if (count($search['image_ids']) == 0)
129    {
130      // a clause that is always false
131      $clauses[] = '1 = 2 ';
132    }
133    else
134    {
135      $clauses[] = 'image_id IN ('.implode(', ', $search['image_ids']).')';
136    }
137  }
138
139  if (isset($search['fields']['ip']))
140  {
141    $clauses[] = 'IP LIKE "'.$search['fields']['ip'].'"';
142  }
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
167  // LIMIT '.$conf['nb_logs_page'].' OFFSET '.$page['start'].'
168
169  $result = pwg_query($query);
170
171  while ($row = pwg_db_fetch_assoc($result))
172  {
173    $data[] = $row;
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
182?>
Note: See TracBrowser for help on using the repository browser.