source: extensions/dynareceperio/period.inc.php @ 16859

Last change on this file since 16859 was 8421, checked in by rub, 13 years ago

Fix bad argument passed

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Dynamic Recent Period - a Piwigo Plugin                               |
4// | Copyright (C) 2007-2011 Ruben ARNAUD - rub@piwigo.org                 |
5// +-----------------------------------------------------------------------+
6// | This program is free software; you can redistribute it and/or modify  |
7// | it under the terms of the GNU General Public License as published by  |
8// | the Free Software Foundation                                          |
9// |                                                                       |
10// | This program is distributed in the hope that it will be useful, but   |
11// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
12// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
13// | General Public License for more details.                              |
14// |                                                                       |
15// | You should have received a copy of the GNU General Public License     |
16// | along with this program; if not, write to the Free Software           |
17// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
18// | USA.                                                                  |
19// +-----------------------------------------------------------------------+
20
21if (!defined('PHPWG_ROOT_PATH'))
22{
23  die('Hacking attempt!');
24}
25
26// in order to prevent of system witch set array value not empty
27// when array is not set
28// pb with $filter
29//add_event_handler('user_init', 'dynareceperio_user_init');
30add_event_handler('init', 'dynareceperio_user_init');
31
32function dynareceperio_user_init()
33{
34  global $conf, $user;
35
36  if 
37    (
38      $conf['dynareceperio']['force']
39      or
40      (get_default_user_value('recent_period', $user['recent_period']) === $user['recent_period'])
41    )
42  {
43    $query = '
44select
45  Max(D) D
46from
47  (
48    select
49      D
50    from
51      (
52        select
53          DATEDIFF(CURRENT_DATE, date_available) D
54        from
55          '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=image_id
56      '.get_sql_condition_FandF
57          (
58            array
59              (
60                'forbidden_categories' => 'ic.category_id',
61                'visible_categories' => 'ic.category_id',
62                'visible_images' => 'ic.image_id'
63              ),
64            'WHERE',
65              true
66          ).'
67      ) as ListDate
68    where
69      D >= 0
70    group by D
71    order by D asc
72    limit 0,'.$conf['dynareceperio']['day_number'].'
73  ) as MaxD
74;';
75
76    $result = pwg_query($query);
77    if (list($period) = mysql_fetch_array($result))
78    {
79      $user['recent_period'] =
80        max($period, 
81          get_default_user_value('recent_period', $user['recent_period']));
82    }
83  }
84
85  return;
86}
87
88?>
Note: See TracBrowser for help on using the repository browser.