Changeset 2157 for trunk


Ignore:
Timestamp:
Nov 1, 2007, 6:11:52 PM (17 years ago)
Author:
rub
Message:

Resolved issue 0000774: Statistics & plugin triggers => multi history

First part

Merge branch-1_7 2155:2156 into BSF

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        66map.php
        77upgrade65.log
         8fstats
  • trunk/admin/history.php

    r1992 r2157  
    9393  }
    9494
    95   $search['fields']['types'] = $_POST['types'];
     95  if (empty($_POST['types']))
     96  {
     97    $search['fields']['types'] = $types;
     98  }
     99  else
     100  {
     101    $search['fields']['types'] = $_POST['types'];
     102  }
    96103
    97104  $search['fields']['user'] = $_POST['user'];
     
    196203
    197204    $page['search']['fields']['user'] = $_GET['user_id'];
    198    
     205
    199206    $query ='
    200207INSERT INTO '.SEARCH_TABLE.'
     
    212219  }
    213220
    214  
    215   if (isset($page['search']['fields']['filename']))
    216   {
    217     $query = '
    218 SELECT
    219     id
    220   FROM '.IMAGES_TABLE.'
    221   WHERE file LIKE \''.$page['search']['fields']['filename'].'\'
    222 ;';
    223     $page['search']['image_ids'] = array_from_query($query, 'id');
    224   }
    225  
    226   // echo '<pre>'; print_r($page['search']); echo '</pre>';
    227  
    228   $clauses = array();
    229 
    230   if (isset($page['search']['fields']['date-after']))
    231   {
    232     array_push(
    233       $clauses,
    234       "date >= '".$page['search']['fields']['date-after']."'"
    235       );
    236   }
    237 
    238   if (isset($page['search']['fields']['date-before']))
    239   {
    240     array_push(
    241       $clauses,
    242       "date <= '".$page['search']['fields']['date-before']."'"
    243       );
    244   }
    245 
    246   if (isset($page['search']['fields']['types']))
    247   {
    248     $local_clauses = array();
    249    
    250     foreach ($types as $type) {
    251       if (in_array($type, $page['search']['fields']['types'])) {
    252         $clause = 'image_type ';
    253         if ($type == 'none')
    254         {
    255           $clause.= 'IS NULL';
    256         }
    257         else
    258         {
    259           $clause.= "= '".$type."'";
    260         }
    261        
    262         array_push($local_clauses, $clause);
    263       }
    264     }
    265    
    266     if (count($local_clauses) > 0)
    267     {
    268       array_push(
    269         $clauses,
    270         implode(' OR ', $local_clauses)
    271         );
    272     }
    273   }
    274 
    275   if (isset($page['search']['fields']['user'])
    276       and $page['search']['fields']['user'] != -1)
    277   {
    278     array_push(
    279       $clauses,
    280       'user_id = '.$page['search']['fields']['user']
    281       );
    282   }
    283 
    284   if (isset($page['search']['fields']['image_id']))
    285   {
    286     array_push(
    287       $clauses,
    288       'image_id = '.$page['search']['fields']['image_id']
    289       );
    290   }
    291  
    292   if (isset($page['search']['fields']['filename']))
    293   {
    294     if (count($page['search']['image_ids']) == 0)
    295     {
    296       // a clause that is always false
    297       array_push($clauses, '1 = 2 ');
    298     }
    299     else
    300     {
    301       array_push(
    302         $clauses,
    303         'image_id IN ('.implode(', ', $page['search']['image_ids']).')'
    304         );
    305     }
    306   }
    307  
    308   $clauses = prepend_append_array_items($clauses, '(', ')');
    309 
    310   $where_separator =
    311     implode(
    312       "\n    AND ",
    313       $clauses
    314       );
    315  
    316   $query = '
    317 SELECT
    318     date,
    319     time,
    320     user_id,
    321     IP,
    322     section,
    323     category_id,
    324     tag_ids,
    325     image_id,
    326     image_type
    327   FROM '.HISTORY_TABLE.'
    328   WHERE '.$where_separator.'
    329 ;';
    330 
    331   // LIMIT '.$page['start'].', '.$conf['nb_logs_page'].'
    332 
    333   $result = pwg_query($query);
    334 
    335   $page['nb_lines'] = mysql_num_rows($result);
    336  
     221  $data = trigger_event('get_history', array(), $page['search'], $types);
     222  usort($data, 'history_compare');
     223
     224  $page['nb_lines'] = count($data);
     225
    337226  $history_lines = array();
    338227  $user_ids = array();
     
    341230  $image_ids = array();
    342231  $tag_ids = array();
    343  
    344   while ($row = mysql_fetch_assoc($result))
     232
     233  foreach ($data as $row)
    345234  {
    346235    $user_ids[$row['user_id']] = 1;
  • trunk/admin/include/functions_history.inc.php

    r1912 r2157  
    5252}
    5353
     54function history_compare($a, $b)
     55{
     56  return strcmp($a['date'].$a['time'], $b['date'].$b['time']);
     57}
     58
     59function get_history($data, $search, $types)
     60{
     61  if (isset($search['fields']['filename']))
     62  {
     63    $query = '
     64SELECT
     65    id
     66  FROM '.IMAGES_TABLE.'
     67  WHERE file LIKE \''.$search['fields']['filename'].'\'
     68;';
     69    $search['image_ids'] = array_from_query($query, 'id');
     70  }
     71 
     72  // echo '<pre>'; print_r($search); echo '</pre>';
     73 
     74  $clauses = array();
     75
     76  if (isset($search['fields']['date-after']))
     77  {
     78    array_push(
     79      $clauses,
     80      "date >= '".$search['fields']['date-after']."'"
     81      );
     82  }
     83
     84  if (isset($search['fields']['date-before']))
     85  {
     86    array_push(
     87      $clauses,
     88      "date <= '".$search['fields']['date-before']."'"
     89      );
     90  }
     91
     92  if (isset($search['fields']['types']))
     93  {
     94    $local_clauses = array();
     95   
     96    foreach ($types as $type) {
     97      if (in_array($type, $search['fields']['types'])) {
     98        $clause = 'image_type ';
     99        if ($type == 'none')
     100        {
     101          $clause.= 'IS NULL';
     102        }
     103        else
     104        {
     105          $clause.= "= '".$type."'";
     106        }
     107       
     108        array_push($local_clauses, $clause);
     109      }
     110    }
     111   
     112    if (count($local_clauses) > 0)
     113    {
     114      array_push(
     115        $clauses,
     116        implode(' OR ', $local_clauses)
     117        );
     118    }
     119  }
     120
     121  if (isset($search['fields']['user'])
     122      and $search['fields']['user'] != -1)
     123  {
     124    array_push(
     125      $clauses,
     126      'user_id = '.$search['fields']['user']
     127      );
     128  }
     129
     130  if (isset($search['fields']['image_id']))
     131  {
     132    array_push(
     133      $clauses,
     134      'image_id = '.$search['fields']['image_id']
     135      );
     136  }
     137 
     138  if (isset($search['fields']['filename']))
     139  {
     140    if (count($search['image_ids']) == 0)
     141    {
     142      // a clause that is always false
     143      array_push($clauses, '1 = 2 ');
     144    }
     145    else
     146    {
     147      array_push(
     148        $clauses,
     149        'image_id IN ('.implode(', ', $search['image_ids']).')'
     150        );
     151    }
     152  }
     153 
     154  $clauses = prepend_append_array_items($clauses, '(', ')');
     155
     156  $where_separator =
     157    implode(
     158      "\n    AND ",
     159      $clauses
     160      );
     161 
     162  $query = '
     163SELECT
     164    date,
     165    time,
     166    user_id,
     167    IP,
     168    section,
     169    category_id,
     170    tag_ids,
     171    image_id,
     172    image_type
     173  FROM '.HISTORY_TABLE.'
     174  WHERE '.$where_separator.'
     175;';
     176
     177  // LIMIT '.$page['start'].', '.$conf['nb_logs_page'].'
     178
     179  $result = pwg_query($query);
     180
     181  while ($row = mysql_fetch_assoc($result))
     182  {
     183    array_push($data, $row);
     184  }
     185
     186  return $data;
     187}
     188
     189add_event_handler('get_history', 'get_history', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
     190trigger_action('functions_history_included');
     191
    54192?>
Note: See TracChangeset for help on using the changeset viewer.