source: trunk/admin/history.php @ 1881

Last change on this file since 1881 was 1881, checked in by rub, 17 years ago

Add tabsheet on administration pages.

Step 3: Tabsheet for configuration & history

Change css tabsheet to do like p0w0 for all themes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.4 KB
RevLine 
[1727]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)
[1782]8// | file          : $Id: history.php 1881 2007-03-08 22:14:14Z rub $
9// | last update   : $Date: 2007-03-08 22:14:14 +0000 (Thu, 08 Mar 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1881 $
[1727]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');
[1881]51include_once(PHPWG_ROOT_PATH.'admin/include/functions_history.inc.php');
[1727]52
53if (isset($_GET['start']) and is_numeric($_GET['start']))
54{
55  $page['start'] = $_GET['start'];
56}
57else
58{
59  $page['start'] = 0;
60}
61
[1844]62$types = array('none', 'picture', 'high', 'other');
63
[1727]64// +-----------------------------------------------------------------------+
65// | Check Access and exit when user status is not ok                      |
66// +-----------------------------------------------------------------------+
67
68check_status(ACCESS_ADMINISTRATOR);
69
70// +-----------------------------------------------------------------------+
71// | Build search criteria and redirect to results                         |
72// +-----------------------------------------------------------------------+
73
74$errors = array();
75$search = array();
76
77if (isset($_POST['submit']))
78{
79  // dates
80  if (!empty($_POST['start_year']))
81  {
82    $search['fields']['date-after'] = sprintf(
83      '%d-%02d-%02d',
84      $_POST['start_year'],
85      $_POST['start_month'],
86      $_POST['start_day']
87      );
88  }
89
90  if (!empty($_POST['end_year']))
91  {
92    $search['fields']['date-before'] = sprintf(
93      '%d-%02d-%02d',
94      $_POST['end_year'],
95      $_POST['end_month'],
96      $_POST['end_day']
97      );
98  }
99
[1844]100  $search['fields']['types'] = $_POST['types'];
[1817]101 
[1727]102  // echo '<pre>'; print_r($search); echo '</pre>';
103 
104  if (!empty($search))
105  {
106    // register search rules in database, then they will be available on
107    // thumbnails page and picture page.
108    $query ='
109INSERT INTO '.SEARCH_TABLE.'
110  (rules)
111  VALUES
112  (\''.serialize($search).'\')
113;';
114    pwg_query($query);
115
116    $search_id = mysql_insert_id();
117   
118    redirect(
119      PHPWG_ROOT_PATH.'admin.php?page=history&search_id='.$search_id
120      );
121  }
122  else
123  {
124    array_push($errors, $lang['search_one_clause_at_least']);
125  }
126}
127
128// +-----------------------------------------------------------------------+
129// |                             template init                             |
130// +-----------------------------------------------------------------------+
131
[1881]132$template->set_filename('history', 'admin/history.tpl');
[1727]133
[1881]134// TabSheet initialization
135history_tabsheet();
136
[1727]137$base_url = PHPWG_ROOT_PATH.'admin.php?page=history';
138
139$template->assign_vars(
140  array(
141    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=history',
142
143    'F_ACTION' => PHPWG_ROOT_PATH.'admin.php?page=history'
144    )
145  );
146
147$template->assign_vars(
148  array(
149    'TODAY_DAY'   => date('d', time()),
150    'TODAY_MONTH' => date('m', time()),
151    'TODAY_YEAR'  => date('Y', time()),
152    )
153  );
154
155// +-----------------------------------------------------------------------+
156// |                             history lines                             |
157// +-----------------------------------------------------------------------+
158
159if (isset($_GET['search_id'])
160    and $page['search_id'] = (int)$_GET['search_id'])
161{
162  // what are the lines to display in reality ?
163  $query = '
164SELECT rules
165  FROM '.SEARCH_TABLE.'
166  WHERE id = '.$page['search_id'].'
167;';
168  list($serialized_rules) = mysql_fetch_row(pwg_query($query));
169
170  $page['search'] = unserialize($serialized_rules);
171
172  // echo '<pre>'; print_r($page['search']); echo '</pre>';
173 
174  $clauses = array();
175
176  if (isset($page['search']['fields']['date-after']))
177  {
178    array_push(
179      $clauses,
180      "date >= '".$page['search']['fields']['date-after']."'"
181      );
182  }
183
184  if (isset($page['search']['fields']['date-before']))
185  {
186    array_push(
187      $clauses,
188      "date <= '".$page['search']['fields']['date-before']."'"
189      );
190  }
191
[1844]192  if (isset($page['search']['fields']['types']))
[1817]193  {
[1844]194    $local_clauses = array();
[1817]195   
[1844]196    foreach ($types as $type) {
197      if (in_array($type, $page['search']['fields']['types'])) {
198        $clause = 'image_type ';
199        if ($type == 'none')
200        {
201          $clause.= 'IS NULL';
202        }
203        else
204        {
205          $clause.= "= '".$type."'";
206        }
207       
208        array_push($local_clauses, $clause);
209      }
[1817]210    }
211   
[1844]212    if (count($local_clauses) > 0)
[1817]213    {
[1844]214      array_push(
215        $clauses,
216        implode(' OR ', $local_clauses)
217        );
[1817]218    }
219  }
220 
[1727]221  $clauses = prepend_append_array_items($clauses, '(', ')');
222
223  $where_separator =
224    implode(
225      "\n    AND ",
226      $clauses
227      );
228 
229  $query = '
230SELECT COUNT(*)
231  FROM '.HISTORY_TABLE.'
232  WHERE '.$where_separator.'
[1844]233;';
[1727]234
[1844]235  // echo '<pre>'.$query.'</pre>';
236 
[1727]237  list($page['nb_lines']) = mysql_fetch_row(pwg_query($query));
238
239  $query = '
[1817]240SELECT
241    date,
242    time,
243    user_id,
244    IP,
245    section,
246    category_id,
247    tag_ids,
248    image_id,
[1844]249    image_type
[1727]250  FROM '.HISTORY_TABLE.'
251  WHERE '.$where_separator.'
252  LIMIT '.$page['start'].', '.$conf['nb_logs_page'].'
253;';
254
255  $result = pwg_query($query);
[1782]256  $history_lines = $user_ids = $category_ids = $image_ids = array();
[1821]257  while ($row = mysql_fetch_assoc($result))
[1727]258  {
259    $user_ids[$row['user_id']] = 1;
260
261    if (isset($row['category_id']))
262    {
263      $category_ids[$row['category_id']] = 1;
264    }
265
266    if (isset($row['image_id']))
267    {
268      $image_ids[$row['image_id']] = 1;
269    }
270
271    array_push(
272      $history_lines,
273      $row
274      );
275  }
276
277  // prepare reference data (users, tags, categories...)
278  if (count($user_ids) > 0)
279  {
280    $query = '
281SELECT '.$conf['user_fields']['id'].' AS id
282     , '.$conf['user_fields']['username'].' AS username
283  FROM '.USERS_TABLE.'
284  WHERE id IN ('.implode(',', array_keys($user_ids)).')
285;';
286    $result = pwg_query($query);
287
288    $username_of = array();
289    while ($row = mysql_fetch_array($result))
290    {
291      $username_of[$row['id']] = $row['username'];
292    }
293  }
294
295  if (count($category_ids) > 0)
296  {
297    $query = '
298SELECT id, uppercats
299  FROM '.CATEGORIES_TABLE.'
300  WHERE id IN ('.implode(',', array_keys($category_ids)).')
301;';
302    $uppercats_of = simple_hash_from_query($query, 'id', 'uppercats');
303
304    $name_of_category = array();
305   
306    foreach ($uppercats_of as $category_id => $uppercats)
307    {
308      $name_of_category[$category_id] = get_cat_display_name_cache(
309        $uppercats
310        );
311    }
312  }
313
314  if (count($image_ids) > 0)
315  {
316    $query = '
317SELECT id, IF(name IS NULL, file, name) AS label
318  FROM '.IMAGES_TABLE.'
319  WHERE id IN ('.implode(',', array_keys($image_ids)).')
320;';
321    $label_of_image = simple_hash_from_query($query, 'id', 'label');
322  }
323 
324  $i = 0;
325
326  foreach ($history_lines as $line)
327  {
328    $template->assign_block_vars(
329      'detail',
330      array(
331        'DATE'      => $line['date'],
332        'TIME'      => $line['time'],
333        'USER'      => isset($username_of[$line['user_id']])
334          ? $username_of[$line['user_id']]
335          : $line['user_id']
336        ,
337        'IP'        => $line['IP'],
338        'IMAGE'     => isset($line['image_id'])
[1821]339          ? ( isset($label_of_image[$line['image_id']])
340                ? $label_of_image[$line['image_id']]
341                : 'deleted '.$line['image_id'])
[1727]342          : $line['image_id'],
[1844]343        'TYPE'      => $line['image_type'],
[1727]344        'SECTION'   => $line['section'],
345        'CATEGORY'  => isset($line['category_id'])
[1821]346          ? ( isset($name_of_category[$line['category_id']])
347                ? $name_of_category[$line['category_id']]
348                : 'deleted '.$line['category_id'] )
[1727]349          : '',
[1821]350        'TAGS'       => $line['tag_ids'],
[1727]351        'T_CLASS'   => ($i++ % 2) ? 'row1' : 'row2',
352        )
353      );
354  }
355}
356
357// $groups_string = preg_replace(
358//     '/(\d+)/e',
359//     "\$groups['$1']",
360//     implode(
361//       ', ',
362//       $local_user['groups']
363//       )
364//     );
365
366// +-----------------------------------------------------------------------+
367// |                            navigation bar                             |
368// +-----------------------------------------------------------------------+
369
370if (isset($page['search_id']))
371{
372  $navbar = create_navigation_bar(
373    PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start')),
374    $page['nb_lines'],
375    $page['start'],
376    $conf['nb_logs_page']
377    );
378
379  $template->assign_block_vars(
380    'navigation',
381    array(
382      'NAVBAR' => $navbar
383      )
384    );
385}
386
387// +-----------------------------------------------------------------------+
388// |                             filter form                               |
389// +-----------------------------------------------------------------------+
390
391$form = array();
392
393if (isset($page['search']))
394{
395  if (isset($page['search']['fields']['date-after']))
396  {
397    $tokens = explode('-', $page['search']['fields']['date-after']);
398   
399    $form['start_year']  = (int)$tokens[0];
400    $form['start_month'] = (int)$tokens[1];
401    $form['start_day']   = (int)$tokens[2];
402  }
403
404  if (isset($page['search']['fields']['date-before']))
405  {
406    $tokens = explode('-', $page['search']['fields']['date-before']);
[1817]407
408    $form['end_year']  = (int)$tokens[0];
409    $form['end_month'] = (int)$tokens[1];
410    $form['end_day']   = (int)$tokens[2];
[1727]411  }
[1817]412
[1844]413  $form['types'] = $page['search']['fields']['types'];
[1727]414}
415else
416{
417  // by default, at page load, we want the selected date to be the current
418  // date
419  $form['start_year']  = $form['end_year']  = date('Y');
420  $form['start_month'] = $form['end_month'] = date('n');
421  $form['start_day']   = $form['end_day']   = date('j');
[1844]422  $form['types'] = $types;
[1727]423}
424
425// start date
426get_day_list('start_day', @$form['start_day']);
427get_month_list('start_month', @$form['start_month']);
428// end date
429get_day_list('end_day', @$form['end_day']);
430get_month_list('end_month', @$form['end_month']);
431
432$template->assign_vars(
433  array(
434    'START_YEAR' => @$form['start_year'],
435    'END_YEAR'   => @$form['end_year'],
436    )
437  );
[1817]438
[1844]439foreach ($types as $option)
[1817]440{
[1844]441  $selected = '';
442 
443  if (in_array($option, $form['types']))
[1817]444  {
[1844]445    $selected = 'selected="selected"';
[1817]446  }
[1844]447 
448  $template->assign_block_vars(
449    'types_option',
450    array(
451      'VALUE' => $option,
452      'CONTENT' => l10n($option),
453      'SELECTED' => $selected,
454      )
455    );
[1817]456}
[1727]457 
458// +-----------------------------------------------------------------------+
459// |                           html code display                           |
460// +-----------------------------------------------------------------------+
461
462$template->assign_var_from_handle('ADMIN_CONTENT', 'history');
463?>
Note: See TracBrowser for help on using the repository browser.