source: tags/build-Alligator02/include/functions_calendar.inc.php @ 5647

Last change on this file since 5647 was 1759, checked in by rvelices, 17 years ago
  • added missing get_sql_condition_FandF in calendar
  • cat list removed closing element tags never opened
  • removed php warning from web service (cant get the result)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 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: 2007-01-27 18:20:58 +0000 (Sat, 27 Jan 2007) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 1759 $
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',     'list');
28define('CAL_VIEW_CALENDAR', 'calendar');
29
30function initialize_calendar()
31{
32  global $page, $conf, $user, $template, $filter;
33
34//------------------ initialize the condition on items to take into account ---
35  $inner_sql = ' FROM ' . IMAGES_TABLE;
36
37  if ($page['section']=='categories' or
38      ( isset($page['category']) and is_numeric($page['category']) ) )
39  { // we will regenerate the items by including subcats elements
40    $page['items'] = array();
41    $inner_sql .= '
42INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
43
44    if (isset($page['category']) and is_numeric($page['category']))
45    {
46      $sub_ids = array_diff(
47        get_subcat_ids(array($page['category'])),
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      $inner_sql .= '
58    '.get_sql_condition_FandF
59      (
60        array
61          (
62            'visible_images' => 'id'
63          ),
64        'AND', false
65      );
66    }
67    else
68    {
69      $inner_sql .= '
70    '.get_sql_condition_FandF
71      (
72        array
73          (
74            'forbidden_categories' => 'category_id',
75            'visible_categories' => 'category_id',
76            'visible_images' => 'id'
77          ),
78        'WHERE', true
79      );
80    }
81  }
82  else
83  {
84    if ( empty($page['items']) )
85    {
86      return; // nothing to do
87    }
88    $inner_sql .= '
89WHERE id IN (' . implode(',',$page['items']) .')';
90  }
91
92//-------------------------------------- initialize the calendar parameters ---
93  pwg_debug('start initialize_calendar');
94
95  $fields = array(
96    // Created
97    'created' => array(
98      'label'          => l10n('Creation date'),
99      ),
100    // Posted
101    'posted' => array(
102      'label'          => l10n('Post date'),
103      ),
104    );
105
106  $styles = array(
107    // Monthly style
108    'monthly' => array(
109      'include'        => 'calendar_monthly.class.php',
110      'view_calendar'  => true,
111      ),
112    // Weekly style
113    'weekly' => array(
114      'include'        => 'calendar_weekly.class.php',
115      'view_calendar'  => false,
116      ),
117    );
118
119  $views = array(CAL_VIEW_LIST,CAL_VIEW_CALENDAR);
120
121  // Retrieve calendar field
122  if ( !isset( $fields[ $page['chronology_field'] ] ) )
123  {
124    die('bad chronology field');
125  }
126
127  // Retrieve style
128  if ( !isset( $styles[ $page['chronology_style'] ] ) )
129  {
130    $page['chronology_style'] = 'monthly';
131  }
132  $cal_style = $page['chronology_style'];
133  include(PHPWG_ROOT_PATH.'include/'. $styles[$cal_style]['include']);
134  $calendar = new Calendar();
135
136  // Retrieve view
137
138  if ( !isset($page['chronology_view']) or
139       !in_array( $page['chronology_view'], $views ) )
140  {
141    $page['chronology_view'] = CAL_VIEW_LIST;
142  }
143
144  if ( CAL_VIEW_CALENDAR==$page['chronology_view'] and
145        !$styles[$cal_style]['view_calendar'] )
146  {
147
148    $page['chronology_view'] = CAL_VIEW_LIST;
149  }
150
151  // perform a sanity check on $requested
152  if (!isset($page['chronology_date']))
153  {
154    $page['chronology_date'] = array();
155  }
156  while ( count($page['chronology_date']) > 3)
157  {
158    array_pop($page['chronology_date']);
159  }
160
161  $any_count = 0;
162  for ($i = 0; $i < count($page['chronology_date']); $i++)
163  {
164    if ($page['chronology_date'][$i] == 'any')
165    {
166      if ($page['chronology_view'] == CAL_VIEW_CALENDAR)
167      {// we dont allow any in calendar view
168        while ($i < count($page['chronology_date']))
169        {
170          array_pop($page['chronology_date']);
171        }
172        break;
173      }
174      $any_count++;
175    }
176    elseif ($page['chronology_date'][$i] == '')
177    {
178      while ($i < count($page['chronology_date']))
179      {
180        array_pop($page['chronology_date']);
181      }
182    }
183    else
184    {
185      $page['chronology_date'][$i] = (int)$page['chronology_date'][$i];
186    }
187  }
188  if ($any_count == 3)
189  {
190    array_pop($page['chronology_date']);
191  }
192
193  $calendar->initialize($inner_sql);
194
195  //echo ('<pre>'. var_export($calendar, true) . '</pre>');
196
197  $must_show_list = true; // true until calendar generates its own display
198  if (script_basename() != 'picture') // basename without file extention
199  {
200    $template->assign_block_vars('calendar', array());
201
202    if ($calendar->generate_category_content())
203    {
204      unset(
205        $page['thumbnails_include'],
206        $page['items']
207        );
208
209      $must_show_list = false;
210    }
211
212    $template->assign_block_vars( 'calendar.views', array() );
213    foreach ($styles as $style => $style_data)
214    {
215      foreach ($views as $view)
216      {
217        if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR)
218        {
219          $selected = '';
220
221          if ($style!=$cal_style)
222          {
223            $chronology_date = array();
224            if ( isset($page['chronology_date'][0]) )
225            {
226              array_push($chronology_date, $page['chronology_date'][0]);
227            }
228          }
229          else
230          {
231            $chronology_date = $page['chronology_date'];
232          }
233          $url = duplicate_index_url(
234              array(
235                'chronology_style' => $style,
236                'chronology_view' => $view,
237                'chronology_date' => $chronology_date,
238                )
239             );
240
241          if ($style==$cal_style and $view==$page['chronology_view'] )
242          {
243            $selected = 'SELECTED';
244          }
245
246          $template->assign_block_vars(
247            'calendar.views.view',
248            array(
249              'VALUE' => $url,
250              'CONTENT' => l10n('chronology_'.$style.'_'.$view),
251              'SELECTED' => $selected,
252              )
253            );
254        }
255      }
256    }
257    $url = duplicate_index_url(
258              array(), array('start', 'chronology_date')
259            );
260    $calendar_title = '<a href="'.$url.'">'
261        .$fields[$page['chronology_field']]['label'].'</a>';
262    $calendar_title.= $calendar->get_display_name();
263    //this should be an assign_block_vars, but I need to assign 'calendar'
264    //above and at that point I don't have the title yet.
265    $template->_tpldata['calendar.'][0]['TITLE'] = $calendar_title;
266  } // end category calling
267
268  if ($must_show_list)
269  {
270    $query = 'SELECT DISTINCT(id)';
271    $query .= $calendar->inner_sql.'
272  '.$calendar->get_date_where();
273    if ( isset($page['super_order_by']) )
274    {
275      $query .= '
276  '.$conf['order_by'];
277    }
278    else
279    {
280      if ( count($page['chronology_date'])==0
281           or in_array('any', $page['chronology_date']) )
282      {// selected period is very big so we show newest first
283        $order = ' DESC, ';
284      }
285      else
286      {// selected period is small (month,week) so we show oldest first
287        $order = ' ASC, ';
288      }
289      $order_by = str_replace(
290        'ORDER BY ',
291        'ORDER BY '.$calendar->date_field.$order, $conf['order_by']
292        );
293      $query .= '
294  '.$order_by;
295    }
296
297    $page['items']              = array_from_query($query, 'id');
298    $page['thumbnails_include'] = 'include/category_default.inc.php';
299  }
300  pwg_debug('end initialize_calendar');
301}
302
303?>
Note: See TracBrowser for help on using the repository browser.