source: tags/release-1_7_0RC1/include/functions_calendar.inc.php @ 4383

Last change on this file since 4383 was 1820, checked in by rvelices, 17 years ago
  • feature 642: display both subcategory thumbnails and element thumbnails (if a

category has both) in the index page

flat category view

  • web service fixes for categories.getList
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 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-02-15 00:10:41 +0000 (Thu, 15 Feb 2007) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 1820 $
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    if ($calendar->generate_category_content())
201    {
202      $page['items'] = array();
203      $must_show_list = false;
204    }
205
206    foreach ($styles as $style => $style_data)
207    {
208      foreach ($views as $view)
209      {
210        if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR)
211        {
212          $selected = '';
213
214          if ($style!=$cal_style)
215          {
216            $chronology_date = array();
217            if ( isset($page['chronology_date'][0]) )
218            {
219              array_push($chronology_date, $page['chronology_date'][0]);
220            }
221          }
222          else
223          {
224            $chronology_date = $page['chronology_date'];
225          }
226          $url = duplicate_index_url(
227              array(
228                'chronology_style' => $style,
229                'chronology_view' => $view,
230                'chronology_date' => $chronology_date,
231                )
232             );
233
234          if ($style==$cal_style and $view==$page['chronology_view'] )
235          {
236            $selected = 'SELECTED';
237          }
238
239          $template->assign_block_vars(
240            'calendar.views.view',
241            array(
242              'VALUE' => $url,
243              'CONTENT' => l10n('chronology_'.$style.'_'.$view),
244              'SELECTED' => $selected,
245              )
246            );
247        }
248      }
249    }
250    $url = duplicate_index_url(
251              array(), array('start', 'chronology_date')
252            );
253    $calendar_title = '<a href="'.$url.'">'
254        .$fields[$page['chronology_field']]['label'].'</a>';
255    $calendar_title.= $calendar->get_display_name();
256    $template->merge_block_vars('calendar',
257        array(
258          'TITLE' => $calendar_title
259        )
260      );
261  } // end category calling
262
263  if ($must_show_list)
264  {
265    $query = 'SELECT DISTINCT(id)';
266    $query .= $calendar->inner_sql.'
267  '.$calendar->get_date_where();
268    if ( isset($page['super_order_by']) )
269    {
270      $query .= '
271  '.$conf['order_by'];
272    }
273    else
274    {
275      if ( count($page['chronology_date'])==0
276           or in_array('any', $page['chronology_date']) )
277      {// selected period is very big so we show newest first
278        $order = ' DESC, ';
279      }
280      else
281      {// selected period is small (month,week) so we show oldest first
282        $order = ' ASC, ';
283      }
284      $order_by = str_replace(
285        'ORDER BY ',
286        'ORDER BY '.$calendar->date_field.$order, $conf['order_by']
287        );
288      $query .= '
289  '.$order_by;
290    }
291    $page['items']              = array_from_query($query, 'id');
292  }
293  pwg_debug('end initialize_calendar');
294}
295
296?>
Note: See TracBrowser for help on using the repository browser.