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

Last change on this file since 486 was 480, checked in by z0rglub, 20 years ago

deletion of debug traces

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.8 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-08-07 17:57:00 +0000 (Sat, 07 Aug 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 480 $
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(date_available) 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="selected">'.$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(date_available)) AS month, COUNT(id) AS count
88  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
89  '.$page['where'].'
90    AND id = image_id
91    AND YEAR(date_available) = '.$page['calendar_year'].'
92  GROUP BY MONTH(date_available)
93;';
94  $result = mysql_query($query);
95  $calendar_months = array();
96  while ($row = mysql_fetch_array($result))
97  {
98    $calendar_months[$row['month']] = $row['count'];
99  }
100
101  // if a month is requested and is not among the available months, we unset
102  // the requested month
103  if (isset($page['calendar_month'])
104      and !isset($calendar_months[$page['calendar_month']]))
105  {
106    unset($page['calendar_month']);
107  }
108
109  // months navigation bar creation
110  $months_nav_bar = '';
111  foreach ($calendar_months as $calendar_month => $nb_picture_month)
112  {
113    if (isset($page['calendar_month'])
114        and $calendar_month == $page['calendar_month'])
115    {
116      $months_nav_bar.= ' <span class="selected">';
117      $months_nav_bar.= $lang['month'][(int)$calendar_month];
118      $months_nav_bar.= '</span>';
119    }
120    else
121    {
122      $url = PHPWG_ROOT_PATH.'category.php?cat=calendar&amp;month=';
123      $url.= $page['calendar_year'].'.'.sprintf('%02s', $calendar_month);
124      $months_nav_bar.= ' ';
125      $months_nav_bar.= '<a href="'.add_session_id($url).'">';
126      $months_nav_bar.= $lang['month'][(int)$calendar_month];
127      $months_nav_bar.= '</a>';
128    }
129  }
130  $template->assign_block_vars(
131    'calendar',
132    array('MONTHS_NAV_BAR' => $months_nav_bar));
133}
134
135/**
136 * 4 sub-cases are possibles for the calendar category :
137 *
138 *  1. show years if no year is requested
139 *  2. show months of the requested year if no month is requested
140 *  3. show days of the {year,month} requested if no day requested
141 *  4. show categories of the requested day (+ a special category gathering
142 *     all categories)
143 */
144
145if (!isset($page['calendar_year']))
146{
147  $nb_pics = count($calendar_years);
148}
149elseif (!isset($page['calendar_month']))
150{
151  $nb_pics = count($calendar_months);
152}
153elseif (!isset($page['calendar_day']))
154{
155  // creation of hash associating the number of the day in the month with
156  // the number of picture for this day : $calendar_days
157  $query = '
158SELECT DISTINCT(date_available) AS day, COUNT(id) AS count
159  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
160  '.$page['where'].'
161    AND id = image_id
162    AND YEAR(date_available) = '.$page['calendar_year'].'
163    AND MONTH(date_available) = '.$page['calendar_month'].'
164  GROUP BY day
165;';
166  $result = mysql_query($query);
167  $calendar_days = array();
168  while ($row = mysql_fetch_array($result))
169  {
170    $calendar_days[$row['day']] = $row['count'];
171  }
172  $nb_pics = count($calendar_days);
173}
174elseif (isset($page['calendar_day']))
175{
176  // $page['calendar_date'] is the concatenation of year-month-day. simplier
177  // to use in SQ queries
178  $page['calendar_date'] = $page['calendar_year'];
179  $page['calendar_date'].= '-'.$page['calendar_month'];
180  $page['calendar_date'].= '-'.$page['calendar_day'];
181 
182  $query = '
183SELECT category_id AS category, COUNT(id) AS count
184  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
185  '.$page['where'].'
186    AND date_available = \''.$page['calendar_date'].'\'
187    AND id = image_id
188  GROUP BY category_id
189;';
190  $result = mysql_query($query);
191  $calendar_categories = array();
192  // special category 0 : gathering all available categories (0 cannot be a
193  // oregular category identifier)
194  $calendar_categories[0] = 0;
195  while ($row = mysql_fetch_array($result))
196  {
197    $calendar_categories[$row['category']] = $row['count'];
198  }
199  // update the total number of pictures for this day
200  $calendar_categories[0] = array_sum($calendar_categories);
201 
202  $nb_pics = count($calendar_categories);
203}
204
205// template thumbnail initialization
206if ($nb_pics > 0)
207{
208  $template->assign_block_vars('thumbnails', array());
209  // first line
210  $template->assign_block_vars('thumbnails.line', array());
211  // current row displayed
212  $row_number = 0;
213}
214
215if (!isset($page['calendar_year']))
216{
217  // for each month of this year, display a random picture
218  foreach ($calendar_years as $calendar_year => $nb_pics)
219  {
220    $query = '
221SELECT file,tn_ext,date_available,storage_category_id
222  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
223  '.$page['where'].'
224    AND YEAR(date_available) = '.$calendar_year.'
225    AND id = image_id
226  ORDER BY RAND()
227  LIMIT 0,1
228;';
229    $row = mysql_fetch_array(mysql_query($query));
230   
231    $file = get_filename_wo_extension($row['file']);
232   
233    // creating links for thumbnail and associated category
234    if (isset($row['tn_ext']) and $row['tn_ext'] != '')
235    {
236      $thumbnail_link = get_complete_dir($row['storage_category_id']);
237      $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
238      $thumbnail_link.= $file.'.'.$row['tn_ext'];
239    }
240    else
241    {
242      $thumbnail_link = './template/'.$user['template'].'/mimetypes/';
243      $thumbnail_link.= strtolower(get_extension($row['file'])).'.png';
244    }
245   
246    $name = $calendar_year.' ('.$nb_pics.')';
247
248    $thumbnail_title = $lang['calendar_picture_hint'].$name;
249     
250    $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar';
251    $url_link.= '&amp;year='.$calendar_year;
252   
253    $template->assign_block_vars(
254      'thumbnails.line.thumbnail',
255      array(
256        'IMAGE'=>$thumbnail_link,
257        'IMAGE_ALT'=>$row['file'],
258        'IMAGE_TITLE'=>$thumbnail_title,
259        'IMAGE_NAME'=>$name,
260         
261        'U_IMG_LINK'=>add_session_id($url_link)
262       )
263     );
264
265    // create a new line ?
266    if (++$row_number == $user['nb_image_line'])
267    {
268      $template->assign_block_vars('thumbnails.line', array());
269      $row_number = 0;
270    }
271  }
272}
273elseif (!isset($page['calendar_month']))
274{
275  // for each month of this year, display a random picture
276  foreach ($calendar_months as $calendar_month => $nb_pics)
277  {
278    $query = '
279SELECT file,tn_ext,date_available,storage_category_id
280  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
281  '.$page['where'].'
282    AND YEAR(date_available) = '.$page['calendar_year'].'
283    AND MONTH(date_available) = '.$calendar_month.'
284    AND id = image_id
285  ORDER BY RAND()
286  LIMIT 0,1
287;';
288    $row = mysql_fetch_array(mysql_query($query));
289   
290    $file = get_filename_wo_extension($row['file']);
291
292    // creating links for thumbnail and associated category
293    if (isset($row['tn_ext']) and $row['tn_ext'] != '')
294    {
295      $thumbnail_link = get_complete_dir($row['storage_category_id']);
296      $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
297      $thumbnail_link.= $file.'.'.$row['tn_ext'];
298    }
299    else
300    {
301      $thumbnail_link = './template/'.$user['template'].'/mimetypes/';
302      $thumbnail_link.= strtolower(get_extension($row['file'])).'.png';
303    }
304     
305    $name = $lang['month'][$calendar_month];
306    $name.= ' '.$page['calendar_year'];
307    $name.= ' ('.$nb_pics.')';
308
309    $thumbnail_title = $lang['calendar_picture_hint'].$name;
310     
311    $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar';
312    $url_link.= '&amp;month='.$page['calendar_year'].'.';
313    if ($calendar_month < 10)
314    {
315      // adding leading zero
316      $url_link.= '0';
317    }
318    $url_link.= $calendar_month;
319   
320    $template->assign_block_vars(
321      'thumbnails.line.thumbnail',
322      array(
323        'IMAGE'=>$thumbnail_link,
324        'IMAGE_ALT'=>$row['file'],
325        'IMAGE_TITLE'=>$thumbnail_title,
326        'IMAGE_NAME'=>$name,
327         
328        'U_IMG_LINK'=>add_session_id($url_link)
329       )
330     );
331
332    // create a new line ?
333    if (++$row_number == $user['nb_image_line'])
334    {
335      $template->assign_block_vars('thumbnails.line', array());
336      $row_number = 0;
337    }
338  }
339}
340elseif (!isset($page['calendar_day']))
341{
342  // for each day of the requested month, display a random picture
343  foreach ($calendar_days as $calendar_day => $nb_pics)
344  {
345    $query = '
346SELECT file,tn_ext,date_available,storage_category_id
347  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
348  '.$page['where'].'
349    AND date_available = \''.$calendar_day.'\'
350    AND id = image_id
351  ORDER BY RAND()
352  LIMIT 0,1
353;';
354    $row = mysql_fetch_array(mysql_query($query));
355   
356    $file = get_filename_wo_extension($row['file']);
357   
358    // creating links for thumbnail and associated category
359    if (isset($row['tn_ext']) and $row['tn_ext'] != '')
360    {
361      $thumbnail_link = get_complete_dir($row['storage_category_id']);
362      $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
363      $thumbnail_link.= $file.'.'.$row['tn_ext'];
364    }
365    else
366    {
367      $thumbnail_link = './template/'.$user['template'].'/mimetypes/';
368      $thumbnail_link.= strtolower(get_extension($row['file'])).'.png';
369    }
370
371    list($year,$month,$day) = explode('-', $calendar_day);
372    $unixdate = mktime(0,0,0,$month,$day,$year);
373    $name = $lang['day'][date("w", $unixdate)];
374    $name.= ' '.$day;
375    $name.= ' ('.$nb_pics.')';
376     
377    $thumbnail_title = $lang['calendar_picture_hint'].$name;
378
379    $url_link = PHPWG_ROOT_PATH.'category.php';
380    $url_link.= '?cat=calendar&amp;day='.str_replace('-', '.', $calendar_day);
381   
382    $template->assign_block_vars(
383      'thumbnails.line.thumbnail',
384      array(
385        'IMAGE'=>$thumbnail_link,
386        'IMAGE_ALT'=>$row['file'],
387        'IMAGE_TITLE'=>$thumbnail_title,
388        'IMAGE_NAME'=>$name,
389         
390        'U_IMG_LINK'=>add_session_id($url_link)
391         )
392       );
393
394    // create a new line ?
395    if (++$row_number == $user['nb_image_line'])
396    {
397      $template->assign_block_vars('thumbnails.line', array());
398      $row_number = 0;
399    }
400  }
401}
402elseif (isset($page['calendar_day']))
403{
404  // for each category of this day, display a random picture
405  foreach ($calendar_categories as $calendar_category => $nb_pics)
406  {
407    if ($calendar_category == 0)
408    {
409      $name = '[all]';
410    }
411    else
412    {
413      $cat_infos = get_cat_info( $calendar_category );
414      $name = get_cat_display_name($cat_infos['name'],'<br />','',false);
415      $name = '['.$name.']';
416    }
417    $name.= ' ('.$nb_pics.')';
418   
419    $query = '
420SELECT file,tn_ext,date_available,storage_category_id
421  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
422  '.$page['where'].'
423    AND date_available = \''.$page['calendar_date'].'\'';
424    if ($calendar_category != 0)
425    {
426      $query.= '
427    AND category_id = '.$calendar_category;
428    }
429    $query.= '
430    AND id = image_id
431  ORDER BY RAND()
432  LIMIT 0,1
433;';
434    $row = mysql_fetch_array(mysql_query($query));
435   
436    $file = get_filename_wo_extension($row['file']);
437   
438    // creating links for thumbnail and associated category
439    if (isset($row['tn_ext']) and $row['tn_ext'] != '')
440    {
441      $thumbnail_link = get_complete_dir($row['storage_category_id']);
442      $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
443      $thumbnail_link.= $file.'.'.$row['tn_ext'];
444    }
445    else
446    {
447      $thumbnail_link = './template/'.$user['template'].'/mimetypes/';
448      $thumbnail_link.= strtolower(get_extension($row['file'])).'.png';
449    }
450   
451    $thumbnail_title = $lang['calendar_picture_hint'].$name;
452
453    $url_link = PHPWG_ROOT_PATH.'category.php?cat=search';
454    $url_link.= '&amp;search=date_available:'.$_GET['day'];
455    if ($calendar_category != 0)
456    {
457      $url_link.= ';cat:'.$calendar_category.'|AND';
458    }
459   
460    $template->assign_block_vars(
461      'thumbnails.line.thumbnail',
462      array(
463        'IMAGE'=>$thumbnail_link,
464        'IMAGE_ALT'=>$row['file'],
465        'IMAGE_TITLE'=>$thumbnail_title,
466        'IMAGE_NAME'=>$name,
467         
468        'U_IMG_LINK'=>add_session_id($url_link)
469         )
470       );
471    $template->assign_block_vars('thumbnails.line.thumbnail.bullet',array());
472   
473    // create a new line ?
474    if (++$row_number == $user['nb_image_line'])
475    {
476      $template->assign_block_vars('thumbnails.line', array());
477      $row_number = 0;
478    }
479  }
480}
481?>
Note: See TracBrowser for help on using the repository browser.