source: extensions/lightbox/admin/functions.inc.php @ 26985

Last change on this file since 26985 was 20207, checked in by mistic100, 11 years ago

replace mysql functions by pwg_db

File size: 3.2 KB
Line 
1<?php
2
3add_event_handler('get_admin_plugin_menu_links', 'lightbox_admin_menu');
4add_event_handler('functions_history_included', 'lightbox_history');
5
6function lightbox_admin_menu($menu)
7{
8  array_push($menu, array(
9    'NAME' => 'Lightbox',
10    'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin.php')));
11  return $menu;
12}
13
14function lightbox_history()
15{
16  remove_event_handler('get_history', 'get_history');
17  add_event_handler('get_history', 'get_lightbox_history', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
18 
19  function get_lightbox_history($data, $search, $types)
20  {
21    if (isset($search['fields']['filename']))
22    {
23      $query = '
24  SELECT
25      id
26    FROM '.IMAGES_TABLE.'
27    WHERE file LIKE \''.$search['fields']['filename'].'\'
28  ;';
29      $search['image_ids'] = array_from_query($query, 'id');
30    }
31   
32    // echo '<pre>'; print_r($search); echo '</pre>';
33   
34    $clauses = array();
35
36    if (isset($search['fields']['date-after']))
37    {
38      array_push(
39        $clauses,
40        "date >= '".$search['fields']['date-after']."'"
41        );
42    }
43
44    if (isset($search['fields']['date-before']))
45    {
46      array_push(
47        $clauses,
48        "date <= '".$search['fields']['date-before']."'"
49        );
50    }
51
52    if (isset($search['fields']['types']))
53    {
54      $local_clauses = array();
55     
56      foreach ($types as $type) {
57        if (in_array($type, $search['fields']['types'])) {
58          $clause = 'image_type ';
59          if ($type == 'none')
60          {
61            $clause.= 'IS NULL';
62          }
63          else
64          {
65            $clause.= "= '".$type."'";
66          }
67         
68          array_push($local_clauses, $clause);
69        }
70      }
71     
72      if (count($local_clauses) > 0)
73      {
74        array_push(
75          $clauses,
76          implode(' OR ', $local_clauses)
77          );
78      }
79    }
80
81    if (isset($search['fields']['user'])
82        and $search['fields']['user'] != -1)
83    {
84      array_push(
85        $clauses,
86        'user_id = '.$search['fields']['user']
87        );
88    }
89
90    if (isset($search['fields']['image_id']))
91    {
92      array_push(
93        $clauses,
94        'image_id = '.$search['fields']['image_id']
95        );
96    }
97   
98    if (isset($search['fields']['filename']))
99    {
100      if (count($search['image_ids']) == 0)
101      {
102        // a clause that is always false
103        array_push($clauses, '1 = 2 ');
104      }
105      else
106      {
107        array_push(
108          $clauses,
109          'image_id IN ('.implode(', ', $search['image_ids']).')'
110          );
111      }
112    }
113   
114    $clauses = prepend_append_array_items($clauses, '(', ')');
115
116    $where_separator =
117      implode(
118        "\n    AND ",
119        $clauses
120        );
121   
122    $query = '
123  SELECT
124      date,
125      time,
126      user_id,
127      IP,
128      section,
129      category_id,
130      tag_ids,
131      image_id,
132      image_type,
133      lightbox
134    FROM '.HISTORY_TABLE.'
135    WHERE '.$where_separator.'
136  ;';
137
138    // LIMIT '.$page['start'].', '.$conf['nb_logs_page'].'
139
140    $result = pwg_query($query);
141
142    while ($row = pwg_db_fetch_assoc($result))
143    {
144      if ($row['lightbox'] == 'true')
145      {
146        $row['image_type'] .= ' (lightbox)';
147      }
148      array_push($data, $row);
149    }
150
151    return $data;
152  }
153}
154
155?>
Note: See TracBrowser for help on using the repository browser.