source: trunk/include/functions_calendar.inc.php @ 2299

Last change on this file since 2299 was 2299, checked in by plg, 16 years ago

Bug fixed: as rvelices notified me by email, my header replacement script was
bugged (r2297 was repeating new and old header).

By the way, I've also removed the replacement keywords. We were using them
because it was a common usage with CVS but it is advised not to use them with
Subversion. Personnaly, it is a problem when I search differences between 2
Piwigo installations outside Subversion.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24define('CAL_VIEW_LIST',     'list');
25define('CAL_VIEW_CALENDAR', 'calendar');
26
27function initialize_calendar()
28{
29  global $page, $conf, $user, $template, $filter;
30
31//------------------ initialize the condition on items to take into account ---
32  $inner_sql = ' FROM ' . IMAGES_TABLE;
33
34  if ($page['section']=='categories')
35  { // we will regenerate the items by including subcats elements
36    $page['items'] = array();
37    $inner_sql .= '
38INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
39
40    if ( isset($page['category']) )
41    {
42      $sub_ids = array_diff(
43        get_subcat_ids(array($page['category']['id'])),
44        explode(',', $user['forbidden_categories'])
45        );
46
47      if (empty($sub_ids))
48      {
49        return; // nothing to do
50      }
51      $inner_sql .= '
52WHERE category_id IN ('.implode(',',$sub_ids).')';
53      $inner_sql .= '
54    '.get_sql_condition_FandF
55      (
56        array
57          (
58            'visible_images' => 'id'
59          ),
60        'AND', false
61      );
62    }
63    else
64    {
65      $inner_sql .= '
66    '.get_sql_condition_FandF
67      (
68        array
69          (
70            'forbidden_categories' => 'category_id',
71            'visible_categories' => 'category_id',
72            'visible_images' => 'id'
73          ),
74        'WHERE', true
75      );
76    }
77  }
78  else
79  {
80    if ( empty($page['items']) )
81    {
82      return; // nothing to do
83    }
84    $inner_sql .= '
85WHERE id IN (' . implode(',',$page['items']) .')';
86  }
87
88//-------------------------------------- initialize the calendar parameters ---
89  pwg_debug('start initialize_calendar');
90
91  $fields = array(
92    // Created
93    'created' => array(
94      'label'          => l10n('Creation date'),
95      ),
96    // Posted
97    'posted' => array(
98      'label'          => l10n('Post date'),
99      ),
100    );
101
102  $styles = array(
103    // Monthly style
104    'monthly' => array(
105      'include'        => 'calendar_monthly.class.php',
106      'view_calendar'  => true,
107      ),
108    // Weekly style
109    'weekly' => array(
110      'include'        => 'calendar_weekly.class.php',
111      'view_calendar'  => false,
112      ),
113    );
114
115  $views = array(CAL_VIEW_LIST,CAL_VIEW_CALENDAR);
116
117  // Retrieve calendar field
118  if ( !isset( $fields[ $page['chronology_field'] ] ) )
119  {
120    die('bad chronology field');
121  }
122
123  // Retrieve style
124  if ( !isset( $styles[ $page['chronology_style'] ] ) )
125  {
126    $page['chronology_style'] = 'monthly';
127  }
128  $cal_style = $page['chronology_style'];
129  include(PHPWG_ROOT_PATH.'include/'. $styles[$cal_style]['include']);
130  $calendar = new Calendar();
131
132  // Retrieve view
133
134  if ( !isset($page['chronology_view']) or
135       !in_array( $page['chronology_view'], $views ) )
136  {
137    $page['chronology_view'] = CAL_VIEW_LIST;
138  }
139
140  if ( CAL_VIEW_CALENDAR==$page['chronology_view'] and
141        !$styles[$cal_style]['view_calendar'] )
142  {
143
144    $page['chronology_view'] = CAL_VIEW_LIST;
145  }
146
147  // perform a sanity check on $requested
148  if (!isset($page['chronology_date']))
149  {
150    $page['chronology_date'] = array();
151  }
152  while ( count($page['chronology_date']) > 3)
153  {
154    array_pop($page['chronology_date']);
155  }
156
157  $any_count = 0;
158  for ($i = 0; $i < count($page['chronology_date']); $i++)
159  {
160    if ($page['chronology_date'][$i] == 'any')
161    {
162      if ($page['chronology_view'] == CAL_VIEW_CALENDAR)
163      {// we dont allow any in calendar view
164        while ($i < count($page['chronology_date']))
165        {
166          array_pop($page['chronology_date']);
167        }
168        break;
169      }
170      $any_count++;
171    }
172    elseif ($page['chronology_date'][$i] == '')
173    {
174      while ($i < count($page['chronology_date']))
175      {
176        array_pop($page['chronology_date']);
177      }
178    }
179    else
180    {
181      $page['chronology_date'][$i] = (int)$page['chronology_date'][$i];
182    }
183  }
184  if ($any_count == 3)
185  {
186    array_pop($page['chronology_date']);
187  }
188
189  $calendar->initialize($inner_sql);
190
191  //echo ('<pre>'. var_export($calendar, true) . '</pre>');
192
193  $must_show_list = true; // true until calendar generates its own display
194  if (script_basename() != 'picture') // basename without file extention
195  {
196    if ($calendar->generate_category_content())
197    {
198      $page['items'] = array();
199      $must_show_list = false;
200    }
201   
202    $page['comment'] = '';
203    $template->assign('FILE_CHRONOLOGY_VIEW', 'month_calendar.tpl');
204
205    foreach ($styles as $style => $style_data)
206    {
207      foreach ($views as $view)
208      {
209        if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR)
210        {
211          $selected = false;
212
213          if ($style!=$cal_style)
214          {
215            $chronology_date = array();
216            if ( isset($page['chronology_date'][0]) )
217            {
218              array_push($chronology_date, $page['chronology_date'][0]);
219            }
220          }
221          else
222          {
223            $chronology_date = $page['chronology_date'];
224          }
225          $url = duplicate_index_url(
226              array(
227                'chronology_style' => $style,
228                'chronology_view' => $view,
229                'chronology_date' => $chronology_date,
230                )
231             );
232
233          if ($style==$cal_style and $view==$page['chronology_view'] )
234          {
235            $selected = true;
236          }
237
238          $template->append(
239            'chronology_views',
240            array(
241              'VALUE' => $url,
242              'CONTENT' => l10n('chronology_'.$style.'_'.$view),
243              'SELECTED' => $selected,
244              )
245            );
246        }
247      }
248    }
249    $url = duplicate_index_url(
250              array(), array('start', 'chronology_date')
251            );
252    $calendar_title = '<a href="'.$url.'">'
253        .$fields[$page['chronology_field']]['label'].'</a>';
254    $calendar_title.= $calendar->get_display_name();
255    $template->assign('chronology',
256        array(
257          'TITLE' => $calendar_title
258        )
259      );
260  } // end category calling
261
262  if ($must_show_list)
263  {
264    $query = 'SELECT DISTINCT(id)';
265    $query .= $calendar->inner_sql.'
266  '.$calendar->get_date_where();
267    if ( isset($page['super_order_by']) )
268    {
269      $query .= '
270  '.$conf['order_by'];
271    }
272    else
273    {
274      if ( count($page['chronology_date'])==0
275           or in_array('any', $page['chronology_date']) )
276      {// selected period is very big so we show newest first
277        $order = ' DESC, ';
278      }
279      else
280      {// selected period is small (month,week) so we show oldest first
281        $order = ' ASC, ';
282      }
283      $order_by = str_replace(
284        'ORDER BY ',
285        'ORDER BY '.$calendar->date_field.$order, $conf['order_by']
286        );
287      $query .= '
288  '.$order_by;
289    }
290    $page['items']              = array_from_query($query, 'id');
291  }
292  pwg_debug('end initialize_calendar');
293}
294
295?>
Note: See TracBrowser for help on using the repository browser.