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

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      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// | PhpWebGallery - a PHP based picture gallery                           |
25// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
26// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
27// +-----------------------------------------------------------------------+
28// | file          : $Id: functions_history.inc.php 2297 2008-04-04 22:57:23Z plg $
29// | last update   : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $
30// | last modifier : $Author: plg $
31// | revision      : $Revision: 2297 $
32// +-----------------------------------------------------------------------+
33// | This program is free software; you can redistribute it and/or modify  |
34// | it under the terms of the GNU General Public License as published by  |
35// | the Free Software Foundation                                          |
36// |                                                                       |
37// | This program is distributed in the hope that it will be useful, but   |
38// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
39// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
40// | General Public License for more details.                              |
41// |                                                                       |
42// | You should have received a copy of the GNU General Public License     |
43// | along with this program; if not, write to the Free Software           |
44// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
45// | USA.                                                                  |
46// +-----------------------------------------------------------------------+
47
48include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
49
50function history_tabsheet()
51{
52  global $page, $link_start;
53
54  // TabSheet
55  $tabsheet = new tabsheet();
56  // TabSheet initialization
57  $tabsheet->add('stats', l10n('Statistics'), $link_start.'stats');
58  $tabsheet->add('history', l10n('Search'), $link_start.'history');
59  // TabSheet selection
60  $tabsheet->select($page['page']);
61  // Assign tabsheet to template
62  $tabsheet->assign();
63}
64
65function history_compare($a, $b)
66{
67  return strcmp($a['date'].$a['time'], $b['date'].$b['time']);
68}
69
70function get_history($data, $search, $types)
71{
72  if (isset($search['fields']['filename']))
73  {
74    $query = '
75SELECT
76    id
77  FROM '.IMAGES_TABLE.'
78  WHERE file LIKE \''.$search['fields']['filename'].'\'
79;';
80    $search['image_ids'] = array_from_query($query, 'id');
81  }
82 
83  // echo '<pre>'; print_r($search); echo '</pre>';
84 
85  $clauses = array();
86
87  if (isset($search['fields']['date-after']))
88  {
89    array_push(
90      $clauses,
91      "date >= '".$search['fields']['date-after']."'"
92      );
93  }
94
95  if (isset($search['fields']['date-before']))
96  {
97    array_push(
98      $clauses,
99      "date <= '".$search['fields']['date-before']."'"
100      );
101  }
102
103  if (isset($search['fields']['types']))
104  {
105    $local_clauses = array();
106   
107    foreach ($types as $type) {
108      if (in_array($type, $search['fields']['types'])) {
109        $clause = 'image_type ';
110        if ($type == 'none')
111        {
112          $clause.= 'IS NULL';
113        }
114        else
115        {
116          $clause.= "= '".$type."'";
117        }
118       
119        array_push($local_clauses, $clause);
120      }
121    }
122   
123    if (count($local_clauses) > 0)
124    {
125      array_push(
126        $clauses,
127        implode(' OR ', $local_clauses)
128        );
129    }
130  }
131
132  if (isset($search['fields']['user'])
133      and $search['fields']['user'] != -1)
134  {
135    array_push(
136      $clauses,
137      'user_id = '.$search['fields']['user']
138      );
139  }
140
141  if (isset($search['fields']['image_id']))
142  {
143    array_push(
144      $clauses,
145      'image_id = '.$search['fields']['image_id']
146      );
147  }
148 
149  if (isset($search['fields']['filename']))
150  {
151    if (count($search['image_ids']) == 0)
152    {
153      // a clause that is always false
154      array_push($clauses, '1 = 2 ');
155    }
156    else
157    {
158      array_push(
159        $clauses,
160        'image_id IN ('.implode(', ', $search['image_ids']).')'
161        );
162    }
163  }
164 
165  $clauses = prepend_append_array_items($clauses, '(', ')');
166
167  $where_separator =
168    implode(
169      "\n    AND ",
170      $clauses
171      );
172 
173  $query = '
174SELECT
175    date,
176    time,
177    user_id,
178    IP,
179    section,
180    category_id,
181    tag_ids,
182    image_id,
183    image_type
184  FROM '.HISTORY_TABLE.'
185  WHERE '.$where_separator.'
186;';
187
188  // LIMIT '.$page['start'].', '.$conf['nb_logs_page'].'
189
190  $result = pwg_query($query);
191
192  while ($row = mysql_fetch_assoc($result))
193  {
194    array_push($data, $row);
195  }
196
197  return $data;
198}
199
200add_event_handler('get_history', 'get_history', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
201trigger_action('functions_history_included');
202
203?>
Note: See TracBrowser for help on using the repository browser.