source: trunk/admin/history.php @ 1821

Last change on this file since 1821 was 1821, checked in by rvelices, 18 years ago
  • plugins: added new action user_init
  • put in a new admin_multi_view:allows admins to change on the fly language/theme and view gallery as guest (useful for developers and just to show a 'new' way of using plugins)
  • removed some warnings from history.php and increased table width to 99%
  • remove unused admin language strings
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $Id: history.php 1821 2007-02-15 03:03:16Z rvelices $
9// | last update   : $Date: 2007-02-15 03:03:16 +0000 (Thu, 15 Feb 2007) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1821 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28/**
29 * Display filtered history lines
30 */
31
32// echo '<pre>$_POST:
33// '; print_r($_POST); echo '</pre>';
34// echo '<pre>$_GET:
35// '; print_r($_GET); echo '</pre>';
36
37// +-----------------------------------------------------------------------+
38// |                              functions                                |
39// +-----------------------------------------------------------------------+
40
41// +-----------------------------------------------------------------------+
42// |                           initialization                              |
43// +-----------------------------------------------------------------------+
44
45if (!defined('PHPWG_ROOT_PATH'))
46{
47  die('Hacking attempt!');
48}
49
50include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
51
52if (isset($_GET['start']) and is_numeric($_GET['start']))
53{
54  $page['start'] = $_GET['start'];
55}
56else
57{
58  $page['start'] = 0;
59}
60
61// +-----------------------------------------------------------------------+
62// | Check Access and exit when user status is not ok                      |
63// +-----------------------------------------------------------------------+
64
65check_status(ACCESS_ADMINISTRATOR);
66
67// +-----------------------------------------------------------------------+
68// | Build search criteria and redirect to results                         |
69// +-----------------------------------------------------------------------+
70
71$errors = array();
72$search = array();
73
74if (isset($_POST['submit']))
75{
76  // dates
77  if (!empty($_POST['start_year']))
78  {
79    $search['fields']['date-after'] = sprintf(
80      '%d-%02d-%02d',
81      $_POST['start_year'],
82      $_POST['start_month'],
83      $_POST['start_day']
84      );
85  }
86
87  if (!empty($_POST['end_year']))
88  {
89    $search['fields']['date-before'] = sprintf(
90      '%d-%02d-%02d',
91      $_POST['end_year'],
92      $_POST['end_month'],
93      $_POST['end_day']
94      );
95  }
96
97  $search['fields']['pictures'] = $_POST['pictures'];
98  $search['fields']['high'] = $_POST['high'];
99 
100  // echo '<pre>'; print_r($search); echo '</pre>';
101 
102  if (!empty($search))
103  {
104    // register search rules in database, then they will be available on
105    // thumbnails page and picture page.
106    $query ='
107INSERT INTO '.SEARCH_TABLE.'
108  (rules)
109  VALUES
110  (\''.serialize($search).'\')
111;';
112    pwg_query($query);
113
114    $search_id = mysql_insert_id();
115   
116    redirect(
117      PHPWG_ROOT_PATH.'admin.php?page=history&search_id='.$search_id
118      );
119  }
120  else
121  {
122    array_push($errors, $lang['search_one_clause_at_least']);
123  }
124}
125
126// +-----------------------------------------------------------------------+
127// |                             template init                             |
128// +-----------------------------------------------------------------------+
129
130$template->set_filenames(array('history'=>'admin/history.tpl'));
131
132$base_url = PHPWG_ROOT_PATH.'admin.php?page=history';
133
134$template->assign_vars(
135  array(
136    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=history',
137
138    'F_ACTION' => PHPWG_ROOT_PATH.'admin.php?page=history'
139    )
140  );
141
142$template->assign_vars(
143  array(
144    'TODAY_DAY'   => date('d', time()),
145    'TODAY_MONTH' => date('m', time()),
146    'TODAY_YEAR'  => date('Y', time()),
147    )
148  );
149
150// +-----------------------------------------------------------------------+
151// |                             history lines                             |
152// +-----------------------------------------------------------------------+
153
154if (isset($_GET['search_id'])
155    and $page['search_id'] = (int)$_GET['search_id'])
156{
157  // what are the lines to display in reality ?
158  $query = '
159SELECT rules
160  FROM '.SEARCH_TABLE.'
161  WHERE id = '.$page['search_id'].'
162;';
163  list($serialized_rules) = mysql_fetch_row(pwg_query($query));
164
165  $page['search'] = unserialize($serialized_rules);
166
167  // echo '<pre>'; print_r($page['search']); echo '</pre>';
168 
169  $clauses = array();
170
171  if (isset($page['search']['fields']['date-after']))
172  {
173    array_push(
174      $clauses,
175      "date >= '".$page['search']['fields']['date-after']."'"
176      );
177  }
178
179  if (isset($page['search']['fields']['date-before']))
180  {
181    array_push(
182      $clauses,
183      "date <= '".$page['search']['fields']['date-before']."'"
184      );
185  }
186
187  if (isset($page['search']['fields']['pictures']))
188  {
189    $clause = null;
190   
191    if ($page['search']['fields']['pictures'] == 'no')
192    {
193      $clause = 'image_id IS NULL';
194    }
195
196    if ($page['search']['fields']['pictures'] == 'only')
197    {
198      $clause = 'image_id IS NOT NULL';
199    }
200
201    if (isset($clause))
202    {
203      array_push($clauses, $clause);
204    }
205  }
206
207  if (isset($page['search']['fields']['high']))
208  {
209    $clause = null;
210   
211    if ($page['search']['fields']['high'] == 'no')
212    {
213      $clause = "is_high IS NULL or is_high = 'false'";
214    }
215
216    if ($page['search']['fields']['high'] == 'only')
217    {
218      $clause = "is_high = 'true'";
219    }
220
221    if (isset($clause))
222    {
223      array_push($clauses, $clause);
224    }
225  }
226 
227  $clauses = prepend_append_array_items($clauses, '(', ')');
228
229  $where_separator =
230    implode(
231      "\n    AND ",
232      $clauses
233      );
234 
235  $query = '
236SELECT COUNT(*)
237  FROM '.HISTORY_TABLE.'
238  WHERE '.$where_separator.'
239';
240
241  list($page['nb_lines']) = mysql_fetch_row(pwg_query($query));
242
243  $query = '
244SELECT
245    date,
246    time,
247    user_id,
248    IP,
249    section,
250    category_id,
251    tag_ids,
252    image_id,
253    is_high
254  FROM '.HISTORY_TABLE.'
255  WHERE '.$where_separator.'
256  LIMIT '.$page['start'].', '.$conf['nb_logs_page'].'
257;';
258
259  $result = pwg_query($query);
260  $history_lines = $user_ids = $category_ids = $image_ids = array();
261  while ($row = mysql_fetch_assoc($result))
262  {
263    $user_ids[$row['user_id']] = 1;
264
265    if (isset($row['category_id']))
266    {
267      $category_ids[$row['category_id']] = 1;
268    }
269
270    if (isset($row['image_id']))
271    {
272      $image_ids[$row['image_id']] = 1;
273    }
274
275    array_push(
276      $history_lines,
277      $row
278      );
279  }
280
281  // prepare reference data (users, tags, categories...)
282  if (count($user_ids) > 0)
283  {
284    $query = '
285SELECT '.$conf['user_fields']['id'].' AS id
286     , '.$conf['user_fields']['username'].' AS username
287  FROM '.USERS_TABLE.'
288  WHERE id IN ('.implode(',', array_keys($user_ids)).')
289;';
290    $result = pwg_query($query);
291
292    $username_of = array();
293    while ($row = mysql_fetch_array($result))
294    {
295      $username_of[$row['id']] = $row['username'];
296    }
297  }
298
299  if (count($category_ids) > 0)
300  {
301    $query = '
302SELECT id, uppercats
303  FROM '.CATEGORIES_TABLE.'
304  WHERE id IN ('.implode(',', array_keys($category_ids)).')
305;';
306    $uppercats_of = simple_hash_from_query($query, 'id', 'uppercats');
307
308    $name_of_category = array();
309   
310    foreach ($uppercats_of as $category_id => $uppercats)
311    {
312      $name_of_category[$category_id] = get_cat_display_name_cache(
313        $uppercats
314        );
315    }
316  }
317
318  if (count($image_ids) > 0)
319  {
320    $query = '
321SELECT id, IF(name IS NULL, file, name) AS label
322  FROM '.IMAGES_TABLE.'
323  WHERE id IN ('.implode(',', array_keys($image_ids)).')
324;';
325    $label_of_image = simple_hash_from_query($query, 'id', 'label');
326  }
327 
328  $i = 0;
329
330  foreach ($history_lines as $line)
331  {
332    $template->assign_block_vars(
333      'detail',
334      array(
335        'DATE'      => $line['date'],
336        'TIME'      => $line['time'],
337        'USER'      => isset($username_of[$line['user_id']])
338          ? $username_of[$line['user_id']]
339          : $line['user_id']
340        ,
341        'IP'        => $line['IP'],
342        'IMAGE'     => isset($line['image_id'])
343          ? ( isset($label_of_image[$line['image_id']])
344                ? $label_of_image[$line['image_id']]
345                : 'deleted '.$line['image_id'])
346          : $line['image_id'],
347        'SECTION'   => $line['section'],
348        'CATEGORY'  => isset($line['category_id'])
349          ? ( isset($name_of_category[$line['category_id']])
350                ? $name_of_category[$line['category_id']]
351                : 'deleted '.$line['category_id'] )
352          : '',
353        'TAGS'       => $line['tag_ids'],
354        'T_CLASS'   => ($i++ % 2) ? 'row1' : 'row2',
355        )
356      );
357
358    if (isset($line['image_id']))
359    {
360      if ($line['is_high'] == 'true')
361      {
362        $template->assign_block_vars('detail.high', array());
363      }
364      else
365      {
366        $template->assign_block_vars('detail.no_high', array());
367      }
368    }
369  }
370}
371
372// $groups_string = preg_replace(
373//     '/(\d+)/e',
374//     "\$groups['$1']",
375//     implode(
376//       ', ',
377//       $local_user['groups']
378//       )
379//     );
380
381// +-----------------------------------------------------------------------+
382// |                            navigation bar                             |
383// +-----------------------------------------------------------------------+
384
385if (isset($page['search_id']))
386{
387  $navbar = create_navigation_bar(
388    PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start')),
389    $page['nb_lines'],
390    $page['start'],
391    $conf['nb_logs_page']
392    );
393
394  $template->assign_block_vars(
395    'navigation',
396    array(
397      'NAVBAR' => $navbar
398      )
399    );
400}
401
402// +-----------------------------------------------------------------------+
403// |                             filter form                               |
404// +-----------------------------------------------------------------------+
405
406$form = array();
407
408if (isset($page['search']))
409{
410  if (isset($page['search']['fields']['date-after']))
411  {
412    $tokens = explode('-', $page['search']['fields']['date-after']);
413   
414    $form['start_year']  = (int)$tokens[0];
415    $form['start_month'] = (int)$tokens[1];
416    $form['start_day']   = (int)$tokens[2];
417  }
418
419  if (isset($page['search']['fields']['date-before']))
420  {
421    $tokens = explode('-', $page['search']['fields']['date-before']);
422
423    $form['end_year']  = (int)$tokens[0];
424    $form['end_month'] = (int)$tokens[1];
425    $form['end_day']   = (int)$tokens[2];
426  }
427
428  $form['pictures'] = $page['search']['fields']['pictures'];
429  $form['high'] = $page['search']['fields']['high'];
430}
431else
432{
433  // by default, at page load, we want the selected date to be the current
434  // date
435  $form['start_year']  = $form['end_year']  = date('Y');
436  $form['start_month'] = $form['end_month'] = date('n');
437  $form['start_day']   = $form['end_day']   = date('j');
438  $form['pictures'] = 'yes';
439  $form['high'] = 'yes';
440}
441
442// start date
443get_day_list('start_day', @$form['start_day']);
444get_month_list('start_month', @$form['start_month']);
445// end date
446get_day_list('end_day', @$form['end_day']);
447get_month_list('end_month', @$form['end_month']);
448
449$template->assign_vars(
450  array(
451    'START_YEAR' => @$form['start_year'],
452    'END_YEAR'   => @$form['end_year'],
453    )
454  );
455
456foreach (array('pictures', 'high') as $block)
457{
458  foreach (array('yes', 'no', 'only') as $item)
459  {
460    $selected = '';
461   
462    if ($item == $form[$block])
463    {
464      $selected = 'selected="selected"';
465    }
466   
467    $template->assign_block_vars(
468      $block.'_option',
469      array(
470        'VALUE' => $item,
471        'CONTENT' => l10n($item),
472        'SELECTED' => $selected,
473        )
474      );
475  }
476}
477 
478// +-----------------------------------------------------------------------+
479// |                           html code display                           |
480// +-----------------------------------------------------------------------+
481
482$template->assign_var_from_handle('ADMIN_CONTENT', 'history');
483?>
Note: See TracBrowser for help on using the repository browser.