source: branches/2.4/admin/include/functions_history.inc.php @ 16926

Revision 16926, 4.7 KB checked in by mistic100, 8 years ago (diff)

Merged revision(s) 16925 from trunk:
feature 2703: make it easy for plugins to add tabs in admin screens
add a trigger a give an id to each core tabsheets

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