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

Last change on this file since 568 was 514, checked in by z0rglub, 20 years ago
  • bug correction : when coming from picture.php on a picture of category.php page superior to the first, the right page was displayed (the one including the element) but the navigation bar was always saying we were on the first page
  • distinguish CSS classes span.dateSelected and span.pageNumberSelected
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                       category_calendar.inc.php                       |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-09-04 08:07:33 +0000 (Sat, 04 Sep 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 514 $
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 = mysql_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 = mysql_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 = mysql_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 = mysql_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(mysql_query($query));
231   
232    $file = get_filename_wo_extension($row['file']);
233   
234    // creating links for thumbnail and associated category
235    if (isset($row['tn_ext']) and $row['tn_ext'] != '')
236    {
237      $thumbnail_link = get_complete_dir($row['storage_category_id']);
238      $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
239      $thumbnail_link.= $file.'.'.$row['tn_ext'];
240    }
241    else
242    {
243      $thumbnail_link = './template/'.$user['template'].'/mimetypes/';
244      $thumbnail_link.= strtolower(get_extension($row['file'])).'.png';
245    }
246   
247    $name = $calendar_year.' ('.$nb_pics.')';
248
249    $thumbnail_title = $lang['calendar_picture_hint'].$name;
250     
251    $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar';
252    $url_link.= '&amp;year='.$calendar_year;
253   
254    $template->assign_block_vars(
255      'thumbnails.line.thumbnail',
256      array(
257        'IMAGE'=>$thumbnail_link,
258        'IMAGE_ALT'=>$row['file'],
259        'IMAGE_TITLE'=>$thumbnail_title,
260        'IMAGE_NAME'=>$name,
261         
262        'U_IMG_LINK'=>add_session_id($url_link)
263       )
264     );
265
266    // create a new line ?
267    if (++$row_number == $user['nb_image_line'])
268    {
269      $template->assign_block_vars('thumbnails.line', array());
270      $row_number = 0;
271    }
272  }
273}
274elseif (!isset($page['calendar_month']))
275{
276  // for each month of this year, display a random picture
277  foreach ($calendar_months as $calendar_month => $nb_pics)
278  {
279    $query = '
280SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
281  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
282  '.$page['where'].'
283    AND YEAR('.$conf['calendar_datefield'].') = '.$page['calendar_year'].'
284    AND MONTH('.$conf['calendar_datefield'].') = '.$calendar_month.'
285    AND id = image_id
286  ORDER BY RAND()
287  LIMIT 0,1
288;';
289    $row = mysql_fetch_array(mysql_query($query));
290   
291    $file = get_filename_wo_extension($row['file']);
292
293    // creating links for thumbnail and associated category
294    if (isset($row['tn_ext']) and $row['tn_ext'] != '')
295    {
296      $thumbnail_link = get_complete_dir($row['storage_category_id']);
297      $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
298      $thumbnail_link.= $file.'.'.$row['tn_ext'];
299    }
300    else
301    {
302      $thumbnail_link = './template/'.$user['template'].'/mimetypes/';
303      $thumbnail_link.= strtolower(get_extension($row['file'])).'.png';
304    }
305     
306    $name = $lang['month'][$calendar_month];
307    $name.= ' '.$page['calendar_year'];
308    $name.= ' ('.$nb_pics.')';
309
310    $thumbnail_title = $lang['calendar_picture_hint'].$name;
311     
312    $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar';
313    $url_link.= '&amp;month='.$page['calendar_year'].'.';
314    if ($calendar_month < 10)
315    {
316      // adding leading zero
317      $url_link.= '0';
318    }
319    $url_link.= $calendar_month;
320   
321    $template->assign_block_vars(
322      'thumbnails.line.thumbnail',
323      array(
324        'IMAGE'=>$thumbnail_link,
325        'IMAGE_ALT'=>$row['file'],
326        'IMAGE_TITLE'=>$thumbnail_title,
327        'IMAGE_NAME'=>$name,
328         
329        'U_IMG_LINK'=>add_session_id($url_link)
330       )
331     );
332
333    // create a new line ?
334    if (++$row_number == $user['nb_image_line'])
335    {
336      $template->assign_block_vars('thumbnails.line', array());
337      $row_number = 0;
338    }
339  }
340}
341elseif (!isset($page['calendar_day']))
342{
343  // for each day of the requested month, display a random picture
344  foreach ($calendar_days as $calendar_day => $nb_pics)
345  {
346    $query = '
347SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
348  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
349  '.$page['where'].'
350    AND '.$conf['calendar_datefield'].' = \''.$calendar_day.'\'
351    AND id = image_id
352  ORDER BY RAND()
353  LIMIT 0,1
354;';
355    $row = mysql_fetch_array(mysql_query($query));
356   
357    $file = get_filename_wo_extension($row['file']);
358   
359    // creating links for thumbnail and associated category
360    if (isset($row['tn_ext']) and $row['tn_ext'] != '')
361    {
362      $thumbnail_link = get_complete_dir($row['storage_category_id']);
363      $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
364      $thumbnail_link.= $file.'.'.$row['tn_ext'];
365    }
366    else
367    {
368      $thumbnail_link = './template/'.$user['template'].'/mimetypes/';
369      $thumbnail_link.= strtolower(get_extension($row['file'])).'.png';
370    }
371
372    list($year,$month,$day) = explode('-', $calendar_day);
373    $unixdate = mktime(0,0,0,$month,$day,$year);
374    $name = $lang['day'][date("w", $unixdate)];
375    $name.= ' '.$day;
376    $name.= ' ('.$nb_pics.')';
377     
378    $thumbnail_title = $lang['calendar_picture_hint'].$name;
379
380    $url_link = PHPWG_ROOT_PATH.'category.php';
381    $url_link.= '?cat=calendar&amp;day='.str_replace('-', '.', $calendar_day);
382   
383    $template->assign_block_vars(
384      'thumbnails.line.thumbnail',
385      array(
386        'IMAGE'=>$thumbnail_link,
387        'IMAGE_ALT'=>$row['file'],
388        'IMAGE_TITLE'=>$thumbnail_title,
389        'IMAGE_NAME'=>$name,
390         
391        'U_IMG_LINK'=>add_session_id($url_link)
392         )
393       );
394
395    // create a new line ?
396    if (++$row_number == $user['nb_image_line'])
397    {
398      $template->assign_block_vars('thumbnails.line', array());
399      $row_number = 0;
400    }
401  }
402}
403elseif (isset($page['calendar_day']))
404{
405  // for each category of this day, display a random picture
406  foreach ($calendar_categories as $calendar_category => $nb_pics)
407  {
408    if ($calendar_category == 0)
409    {
410      $name = '[all]';
411    }
412    else
413    {
414      $cat_infos = get_cat_info( $calendar_category );
415      $name = get_cat_display_name($cat_infos['name'],'<br />','',false);
416      $name = '['.$name.']';
417    }
418    $name.= ' ('.$nb_pics.')';
419   
420    $query = '
421SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
422  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
423  '.$page['where'].'
424    AND '.$conf['calendar_datefield'].' = \''.$page['calendar_date'].'\'';
425    if ($calendar_category != 0)
426    {
427      $query.= '
428    AND category_id = '.$calendar_category;
429    }
430    $query.= '
431    AND id = image_id
432  ORDER BY RAND()
433  LIMIT 0,1
434;';
435    $row = mysql_fetch_array(mysql_query($query));
436   
437    $file = get_filename_wo_extension($row['file']);
438   
439    // creating links for thumbnail and associated category
440    if (isset($row['tn_ext']) and $row['tn_ext'] != '')
441    {
442      $thumbnail_link = get_complete_dir($row['storage_category_id']);
443      $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
444      $thumbnail_link.= $file.'.'.$row['tn_ext'];
445    }
446    else
447    {
448      $thumbnail_link = './template/'.$user['template'].'/mimetypes/';
449      $thumbnail_link.= strtolower(get_extension($row['file'])).'.png';
450    }
451   
452    $thumbnail_title = $lang['calendar_picture_hint'].$name;
453
454    $url_link = PHPWG_ROOT_PATH.'category.php?cat=search';
455    $url_link.= '&amp;search='.$conf['calendar_datefield'].':'.$_GET['day'];
456    if ($calendar_category != 0)
457    {
458      $url_link.= ';cat:'.$calendar_category.'|AND';
459    }
460   
461    $template->assign_block_vars(
462      'thumbnails.line.thumbnail',
463      array(
464        'IMAGE'=>$thumbnail_link,
465        'IMAGE_ALT'=>$row['file'],
466        'IMAGE_TITLE'=>$thumbnail_title,
467        'IMAGE_NAME'=>$name,
468         
469        'U_IMG_LINK'=>add_session_id($url_link)
470         )
471       );
472    $template->assign_block_vars('thumbnails.line.thumbnail.bullet',array());
473   
474    // create a new line ?
475    if (++$row_number == $user['nb_image_line'])
476    {
477      $template->assign_block_vars('thumbnails.line', array());
478      $row_number = 0;
479    }
480  }
481}
482?>
Note: See TracBrowser for help on using the repository browser.