source: trunk/include/category_calendar.inc.php @ 593

Last change on this file since 593 was 593, checked in by z0rglub, 19 years ago

update headers to comply with GPL

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-11-06 21:12:59 +0000 (Sat, 06 Nov 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 593 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28/**
29 * This file is included by category.php to show thumbnails for the category
30 * calendar
31 *
32 */
33
34// years of image availability
35$query = '
36SELECT YEAR('.$conf['calendar_datefield'].') AS year, COUNT(id) AS count
37  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
38  '.$page['where'].'
39    AND id = image_id
40  GROUP BY year
41;';
42$result = pwg_query($query);
43$calendar_years = array();
44while ($row = mysql_fetch_array($result))
45{
46  $calendar_years[$row['year']] = $row['count'];
47}
48
49// if the year requested is not among the available years, we unset the
50// variable
51if (isset($page['calendar_year'])
52    and !isset($calendar_years[$page['calendar_year']]))
53{
54  unset($page['calendar_year']);
55}
56
57// years navigation bar creation
58$years_nav_bar = '';
59foreach ($calendar_years as $calendar_year => $nb_picture_year)
60{
61  if (isset($page['calendar_year'])
62      and $calendar_year == $page['calendar_year'])
63  {
64    $years_nav_bar.= ' <span class="dateSelected">'.$calendar_year.'</span>';
65  }
66  else
67  {
68    $url = PHPWG_ROOT_PATH.'category.php?cat=calendar';
69    $url.= '&amp;year='.$calendar_year;
70    $url = add_session_id($url);
71    $years_nav_bar.= ' <a href="'.$url.'">'.$calendar_year.'</a>';
72  }
73}
74
75$template->assign_block_vars(
76  'calendar',
77  array('YEARS_NAV_BAR' => $years_nav_bar)
78  );
79
80// months are calculated (to know which months are available, and how many
81// pictures per month we can find) only if a year is requested.
82if (isset($page['calendar_year']))
83{
84  // creation of hash associating the number of the month in the year with
85  // the number of picture for this month : $calendar_months
86  $query = '
87SELECT DISTINCT(MONTH('.$conf['calendar_datefield'].')) AS month
88     , COUNT(id) AS count
89  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
90  '.$page['where'].'
91    AND id = image_id
92    AND YEAR('.$conf['calendar_datefield'].') = '.$page['calendar_year'].'
93  GROUP BY MONTH('.$conf['calendar_datefield'].')
94;';
95  $result = pwg_query($query);
96  $calendar_months = array();
97  while ($row = mysql_fetch_array($result))
98  {
99    $calendar_months[$row['month']] = $row['count'];
100  }
101
102  // if a month is requested and is not among the available months, we unset
103  // the requested month
104  if (isset($page['calendar_month'])
105      and !isset($calendar_months[$page['calendar_month']]))
106  {
107    unset($page['calendar_month']);
108  }
109
110  // months navigation bar creation
111  $months_nav_bar = '';
112  foreach ($calendar_months as $calendar_month => $nb_picture_month)
113  {
114    if (isset($page['calendar_month'])
115        and $calendar_month == $page['calendar_month'])
116    {
117      $months_nav_bar.= ' <span class="dateSelected">';
118      $months_nav_bar.= $lang['month'][(int)$calendar_month];
119      $months_nav_bar.= '</span>';
120    }
121    else
122    {
123      $url = PHPWG_ROOT_PATH.'category.php?cat=calendar&amp;month=';
124      $url.= $page['calendar_year'].'.'.sprintf('%02s', $calendar_month);
125      $months_nav_bar.= ' ';
126      $months_nav_bar.= '<a href="'.add_session_id($url).'">';
127      $months_nav_bar.= $lang['month'][(int)$calendar_month];
128      $months_nav_bar.= '</a>';
129    }
130  }
131  $template->assign_block_vars(
132    'calendar',
133    array('MONTHS_NAV_BAR' => $months_nav_bar));
134}
135
136/**
137 * 4 sub-cases are possibles for the calendar category :
138 *
139 *  1. show years if no year is requested
140 *  2. show months of the requested year if no month is requested
141 *  3. show days of the {year,month} requested if no day requested
142 *  4. show categories of the requested day (+ a special category gathering
143 *     all categories)
144 */
145
146if (!isset($page['calendar_year']))
147{
148  $nb_pics = count($calendar_years);
149}
150elseif (!isset($page['calendar_month']))
151{
152  $nb_pics = count($calendar_months);
153}
154elseif (!isset($page['calendar_day']))
155{
156  // creation of hash associating the number of the day in the month with
157  // the number of picture for this day : $calendar_days
158  $query = '
159SELECT DISTINCT('.$conf['calendar_datefield'].') AS day, COUNT(id) AS count
160  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
161  '.$page['where'].'
162    AND id = image_id
163    AND YEAR('.$conf['calendar_datefield'].') = '.$page['calendar_year'].'
164    AND MONTH('.$conf['calendar_datefield'].') = '.$page['calendar_month'].'
165  GROUP BY day
166;';
167  $result = pwg_query($query);
168  $calendar_days = array();
169  while ($row = mysql_fetch_array($result))
170  {
171    $calendar_days[$row['day']] = $row['count'];
172  }
173  $nb_pics = count($calendar_days);
174}
175elseif (isset($page['calendar_day']))
176{
177  // $page['calendar_date'] is the concatenation of year-month-day. simplier
178  // to use in SQ queries
179  $page['calendar_date'] = $page['calendar_year'];
180  $page['calendar_date'].= '-'.$page['calendar_month'];
181  $page['calendar_date'].= '-'.$page['calendar_day'];
182 
183  $query = '
184SELECT category_id AS category, COUNT(id) AS count
185  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
186  '.$page['where'].'
187    AND '.$conf['calendar_datefield'].' = \''.$page['calendar_date'].'\'
188    AND id = image_id
189  GROUP BY category_id
190;';
191  $result = pwg_query($query);
192  $calendar_categories = array();
193  // special category 0 : gathering all available categories (0 cannot be a
194  // oregular category identifier)
195  $calendar_categories[0] = 0;
196  while ($row = mysql_fetch_array($result))
197  {
198    $calendar_categories[$row['category']] = $row['count'];
199  }
200  // update the total number of pictures for this day
201  $calendar_categories[0] = array_sum($calendar_categories);
202 
203  $nb_pics = count($calendar_categories);
204}
205
206// template thumbnail initialization
207if ($nb_pics > 0)
208{
209  $template->assign_block_vars('thumbnails', array());
210  // first line
211  $template->assign_block_vars('thumbnails.line', array());
212  // current row displayed
213  $row_number = 0;
214}
215
216if (!isset($page['calendar_year']))
217{
218  // for each month of this year, display a random picture
219  foreach ($calendar_years as $calendar_year => $nb_pics)
220  {
221    $query = '
222SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
223  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
224  '.$page['where'].'
225    AND YEAR('.$conf['calendar_datefield'].') = '.$calendar_year.'
226    AND id = image_id
227  ORDER BY RAND()
228  LIMIT 0,1
229;';
230    $row = mysql_fetch_array(pwg_query($query));
231   
232    $thumbnail_src = get_thumbnail_src($row['file'],
233                                       $row['storage_category_id'],
234                                       @$row['tn_ext']);
235   
236    $name = $calendar_year.' ('.$nb_pics.')';
237
238    $thumbnail_title = $lang['calendar_picture_hint'].$name;
239     
240    $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar';
241    $url_link.= '&amp;year='.$calendar_year;
242   
243    $template->assign_block_vars(
244      'thumbnails.line.thumbnail',
245      array(
246        'IMAGE'=>$thumbnail_src,
247        'IMAGE_ALT'=>$row['file'],
248        'IMAGE_TITLE'=>$thumbnail_title,
249        'IMAGE_NAME'=>$name,
250         
251        'U_IMG_LINK'=>add_session_id($url_link)
252       )
253     );
254
255    // create a new line ?
256    if (++$row_number == $user['nb_image_line'])
257    {
258      $template->assign_block_vars('thumbnails.line', array());
259      $row_number = 0;
260    }
261  }
262}
263elseif (!isset($page['calendar_month']))
264{
265  // for each month of this year, display a random picture
266  foreach ($calendar_months as $calendar_month => $nb_pics)
267  {
268    $query = '
269SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
270  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
271  '.$page['where'].'
272    AND YEAR('.$conf['calendar_datefield'].') = '.$page['calendar_year'].'
273    AND MONTH('.$conf['calendar_datefield'].') = '.$calendar_month.'
274    AND id = image_id
275  ORDER BY RAND()
276  LIMIT 0,1
277;';
278    $row = mysql_fetch_array(pwg_query($query));
279   
280    $thumbnail_src = get_thumbnail_src($row['file'],
281                                       $row['storage_category_id'],
282                                       @$row['tn_ext']);
283   
284    $name = $lang['month'][$calendar_month];
285    $name.= ' '.$page['calendar_year'];
286    $name.= ' ('.$nb_pics.')';
287
288    $thumbnail_title = $lang['calendar_picture_hint'].$name;
289     
290    $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar';
291    $url_link.= '&amp;month='.$page['calendar_year'].'.';
292    if ($calendar_month < 10)
293    {
294      // adding leading zero
295      $url_link.= '0';
296    }
297    $url_link.= $calendar_month;
298   
299    $template->assign_block_vars(
300      'thumbnails.line.thumbnail',
301      array(
302        'IMAGE'=>$thumbnail_src,
303        'IMAGE_ALT'=>$row['file'],
304        'IMAGE_TITLE'=>$thumbnail_title,
305        'IMAGE_NAME'=>$name,
306         
307        'U_IMG_LINK'=>add_session_id($url_link)
308       )
309     );
310
311    // create a new line ?
312    if (++$row_number == $user['nb_image_line'])
313    {
314      $template->assign_block_vars('thumbnails.line', array());
315      $row_number = 0;
316    }
317  }
318}
319elseif (!isset($page['calendar_day']))
320{
321  // for each day of the requested month, display a random picture
322  foreach ($calendar_days as $calendar_day => $nb_pics)
323  {
324    $query = '
325SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
326  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
327  '.$page['where'].'
328    AND '.$conf['calendar_datefield'].' = \''.$calendar_day.'\'
329    AND id = image_id
330  ORDER BY RAND()
331  LIMIT 0,1
332;';
333    $row = mysql_fetch_array(pwg_query($query));
334   
335    $thumbnail_src = get_thumbnail_src($row['file'],
336                                       $row['storage_category_id'],
337                                       @$row['tn_ext']);
338
339    list($year,$month,$day) = explode('-', $calendar_day);
340    $unixdate = mktime(0,0,0,$month,$day,$year);
341    $name = $lang['day'][date("w", $unixdate)];
342    $name.= ' '.$day;
343    $name.= ' ('.$nb_pics.')';
344     
345    $thumbnail_title = $lang['calendar_picture_hint'].$name;
346
347    $url_link = PHPWG_ROOT_PATH.'category.php';
348    $url_link.= '?cat=calendar&amp;day='.str_replace('-', '.', $calendar_day);
349   
350    $template->assign_block_vars(
351      'thumbnails.line.thumbnail',
352      array(
353        'IMAGE'=>$thumbnail_src,
354        'IMAGE_ALT'=>$row['file'],
355        'IMAGE_TITLE'=>$thumbnail_title,
356        'IMAGE_NAME'=>$name,
357         
358        'U_IMG_LINK'=>add_session_id($url_link)
359         )
360       );
361
362    // create a new line ?
363    if (++$row_number == $user['nb_image_line'])
364    {
365      $template->assign_block_vars('thumbnails.line', array());
366      $row_number = 0;
367    }
368  }
369}
370elseif (isset($page['calendar_day']))
371{
372  // for each category of this day, display a random picture
373  foreach ($calendar_categories as $calendar_category => $nb_pics)
374  {
375    if ($calendar_category == 0)
376    {
377      $name = '[all]';
378    }
379    else
380    {
381      $cat_infos = get_cat_info( $calendar_category );
382      $name = get_cat_display_name($cat_infos['name'],'<br />','',false);
383      $name = '['.$name.']';
384    }
385    $name.= ' ('.$nb_pics.')';
386   
387    $query = '
388SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
389  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
390  '.$page['where'].'
391    AND '.$conf['calendar_datefield'].' = \''.$page['calendar_date'].'\'';
392    if ($calendar_category != 0)
393    {
394      $query.= '
395    AND category_id = '.$calendar_category;
396    }
397    $query.= '
398    AND id = image_id
399  ORDER BY RAND()
400  LIMIT 0,1
401;';
402    $row = mysql_fetch_array(pwg_query($query));
403   
404    $thumbnail_src = get_thumbnail_src($row['file'],
405                                       $row['storage_category_id'],
406                                       @$row['tn_ext']);
407   
408    $thumbnail_title = $lang['calendar_picture_hint'].$name;
409
410    $url_link = PHPWG_ROOT_PATH.'category.php?cat=search';
411    $url_link.= '&amp;search='.$conf['calendar_datefield'].':'.$_GET['day'];
412    if ($calendar_category != 0)
413    {
414      $url_link.= ';cat:'.$calendar_category.'|AND';
415    }
416   
417    $template->assign_block_vars(
418      'thumbnails.line.thumbnail',
419      array(
420        'IMAGE'=>$thumbnail_src,
421        'IMAGE_ALT'=>$row['file'],
422        'IMAGE_TITLE'=>$thumbnail_title,
423        'IMAGE_NAME'=>$name,
424         
425        'U_IMG_LINK'=>add_session_id($url_link)
426         )
427       );
428    $template->assign_block_vars('thumbnails.line.thumbnail.bullet',array());
429   
430    // create a new line ?
431    if (++$row_number == $user['nb_image_line'])
432    {
433      $template->assign_block_vars('thumbnails.line', array());
434      $row_number = 0;
435    }
436  }
437}
438?>
Note: See TracBrowser for help on using the repository browser.