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

Last change on this file since 1687 was 1687, checked in by rub, 17 years ago

Issue ID 0000529 Fixed.

Problem with $_SERVERSCRIPT_FILENAME on IIS server

Merge branch-1_6 1685:1686 into BSF

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