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

Last change on this file since 1056 was 1056, checked in by rvelices, 18 years ago

fix: remove all php warnings and notices

  • Property svn:eol-style set to native
File size: 7.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | branch        : BSF (Best So Far)
7// | file          : $RCSfile$
8// | last update   : $Date: 2006-01-27 02:11:43 +0100 (ven, 27 jan 2006) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 1014 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27define('CAL_VIEW_LIST',     'l');
28define('CAL_VIEW_CALENDAR', 'c');
29
30function initialize_calendar()
31{
32  global $page, $conf, $user, $template;
33
34//------------------ initialize the condition on items to take into account ---
35  $inner_sql = ' FROM ' . IMAGES_TABLE;
36 
37  if (!isset($page['cat']) or is_numeric($page['cat']))
38  { // we will regenerate the items by including subcats elements
39    $page['cat_nb_images'] = 0;
40    $page['items'] = array();
41    $inner_sql .= '
42INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
43   
44    if (isset($page['cat']) and is_numeric($page['cat']))
45    {
46      $sub_ids = array_diff(
47        get_subcat_ids(array($page['cat'])),
48        explode(',', $user['forbidden_categories'])
49        );
50     
51      if (empty($sub_ids))
52      {
53        return; // nothing to do
54      }
55      $inner_sql .= '
56WHERE category_id IN ('.implode(',',$sub_ids).')';
57    }
58    else
59    {
60      $inner_sql .= '
61WHERE category_id NOT IN ('.$user['forbidden_categories'].')';
62    }
63  }
64  else
65  {
66    if ( empty($page['items']) )
67    {
68      return; // nothing to do
69    }
70    $inner_sql .= '
71WHERE id IN (' . implode(',',$page['items']) .')';
72  }
73
74//-------------------------------------- initialize the calendar parameters ---
75  pwg_debug('start initialize_calendar');
76 
77  $cal_styles = array(
78    // Monthly style
79    array(
80      'link'           => 'm',
81      'default_link'   => '',
82      'name'           => l10n('Monthly'),
83      'include'        => 'calendar_monthly.class.php',
84      'view_calendar'  => true,
85      ),
86    // Weekly style   
87    array(
88      'link'           => 'w',
89      'default_link'   => 'w-',
90      'name'           => l10n('Weekly'),
91      'include'        => 'calendar_weekly.class.php',
92      'view_calendar'  => false,
93      ),
94    );
95
96  $requested = explode('-', $_GET['calendar']);
97  $calendar = null;
98  foreach ($cal_styles as $cal_style)
99  {
100    if ($requested[0] == $cal_style['link'])
101    {
102      include(PHPWG_ROOT_PATH.'include/'.$cal_style['include']);
103      $calendar = new Calendar();
104      array_shift($requested);
105      break;
106    }
107  }
108 
109  if (!isset($calendar))
110  {
111    foreach($cal_styles as $cal_style)
112    {
113      if ('' == $cal_style['default_link'])
114      {
115        break;
116      }
117    }
118    include( PHPWG_ROOT_PATH.'include/'.$cal_style['include']);
119    $calendar = new Calendar();
120  }
121
122  $view_type = CAL_VIEW_LIST;
123  if ($requested[0] == CAL_VIEW_LIST)
124  {
125    array_shift($requested);
126  }
127  elseif ($requested[0] == CAL_VIEW_CALENDAR)
128  {
129    if ($cal_style['view_calendar'])
130    {
131      $view_type = CAL_VIEW_CALENDAR;
132    }
133    array_shift($requested);
134  }
135  // perform a sanity check on $requested
136  while (count($requested) > 3)
137  {
138    array_pop($requested);
139  }
140
141  $any_count = 0;
142  for ($i = 0; $i < count($requested); $i++)
143  {
144    if ($requested[$i] == 'any')
145    {
146      if ($view_type == CAL_VIEW_CALENDAR)
147      {// we dont allow any in calendar view
148        while ($i < count($requested))
149        {
150          array_pop($requested);
151        }
152        break;
153      }
154      $any_count++;
155    }
156    elseif ($requested[$i] == '')
157    {
158      while ($i < count($requested))
159      {
160        array_pop($requested);
161      }
162    }
163  }
164  if ($any_count == 3)
165  {
166    array_pop($requested);
167  }
168
169  $calendar->initialize($conf['calendar_datefield'], $inner_sql);
170  //echo ('<pre>'. var_export($requested, true) . '</pre>');
171  //echo ('<pre>'. var_export($calendar, true) . '</pre>');
172
173  // TODO: what makes the list view required?
174  $must_show_list = true;
175 
176  if (basename($_SERVER["PHP_SELF"]) == 'category.php')
177  {
178    $template->assign_block_vars('calendar', array());
179
180    $url_base =
181      PHPWG_ROOT_PATH.'category.php'
182      .get_query_string_diff(array('start', 'calendar'))
183      .(empty($url_base) ? '?' : '&')
184      .'calendar='
185      ;
186
187    if ($calendar->generate_category_content(
188          $url_base.$cal_style['default_link'],
189          $view_type,
190          $requested
191          )
192       )
193    {
194      unset(
195        $page['thumbnails_include'],
196        $page['items'],
197        $page['cat_nb_images']
198        );
199     
200      $must_show_list = false;
201    }
202
203    if ($cal_style['view_calendar'])
204    { // Build bar for views (List/Calendar)
205      $views = array(
206        // list view
207        array(
208          'type'  => CAL_VIEW_LIST,
209          'label' => l10n('List')
210          ),
211        // calendar view
212        array(
213          'type'  => CAL_VIEW_CALENDAR,
214          'label' => l10n('calendar')
215          ),
216        );
217     
218      $views_bar = '';
219
220      foreach ($views as $view)
221      {
222        if ($view_type != $view['type'])
223        {
224          $views_bar.=
225            '<a href="'
226            .$url_base.$cal_style['default_link'].$view['type'].'-'
227            .implode('-', $requested)
228            .'">'.$view['label'].'</a> ';
229        }
230        else
231        {
232          $views_bar.= $view['label'].' ';
233        }
234       
235        $views_bar.= ' ';
236      }
237     
238      $template->assign_block_vars(
239        'calendar.views',
240        array(
241          'BAR' => $views_bar,
242          )
243        );
244    }
245
246    // Build bar for calendar styles (Monthly, Weekly)
247    $styles_bar = '';
248    foreach ($cal_styles as $style)
249    {
250      if ($cal_style['link'] != $style['link'])
251      {
252        $url = $url_base.$style['default_link'];
253        $url .= $view_type;
254        if (isset($requested[0]))
255        {
256          $url .= '-' . $requested[0];
257        }
258        $styles_bar .= '<a href="'. $url . '">'.$style['name'].'</a> ';
259      }
260      else
261      {
262        $styles_bar .=  $style['name'].' ';
263      }
264    }
265    $template->assign_block_vars(
266      'calendar.styles',
267      array(
268        'BAR' => $styles_bar,
269        )
270      );
271  } // end category calling
272
273  if ($must_show_list)
274  {
275    $query = 'SELECT DISTINCT(id)';
276    $query .= $calendar->inner_sql;
277    $query .= $calendar->get_date_where($requested);
278    if ( isset($page['super_order_by']) )
279    {
280      $query .= '
281  '.$conf['order_by'];
282    }
283    else
284    {
285      $order_by = str_replace(
286        'ORDER BY ',
287        'ORDER BY '.$calendar->date_field.',', $conf['order_by']
288        );
289      $query .= $order_by;
290    }
291
292    $page['items']              = array_from_query($query, 'id');
293    $page['cat_nb_images']      = count($page['items']);
294    $page['thumbnails_include'] = 'include/category_default.inc.php';
295  }
296  pwg_debug('end initialize_calendar');
297}
298
299?>
Note: See TracBrowser for help on using the repository browser.