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

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

initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.9 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-06-25 20:27:09 +0000 (Fri, 25 Jun 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 440 $
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// echo '<pre>'.$query.'</pre>';
43$result = mysql_query($query);
44$calendar_years = array();
45while ($row = mysql_fetch_array($result))
46{
47  $calendar_years[$row['year']] = $row['count'];
48}
49
50// if the year requested is not among the available years, we unset the
51// variable
52if (isset($page['calendar_year'])
53    and !isset($calendar_years[$page['calendar_year']]))
54{
55  unset($page['calendar_year']);
56}
57
58// years navigation bar creation
59$years_nav_bar = '';
60foreach ($calendar_years as $calendar_year => $nb_picture_year)
61{
62  if (isset($page['calendar_year'])
63      and $calendar_year == $page['calendar_year'])
64  {
65    $years_nav_bar.= ' <span class="selected">'.$calendar_year.'</span>';
66  }
67  else
68  {
69    $url = PHPWG_ROOT_PATH.'category.php?cat=calendar';
70    $url.= '&amp;year='.$calendar_year;
71    $url = add_session_id($url);
72    $years_nav_bar.= ' <a href="'.$url.'">'.$calendar_year.'</a>';
73  }
74}
75
76$template->assign_block_vars(
77  'calendar',
78  array('YEARS_NAV_BAR' => $years_nav_bar)
79  );
80
81// months are calculated (to know which months are available, and how many
82// pictures per month we can find) only if a year is requested.
83if (isset($page['calendar_year']))
84{
85  // creation of hash associating the number of the month in the year with
86  // the number of picture for this month : $calendar_months
87  $query = '
88SELECT DISTINCT(MONTH(date_available)) AS month, COUNT(id) AS count
89  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
90  '.$page['where'].'
91    AND id = image_id
92    AND YEAR(date_available) = '.$page['calendar_year'].'
93  GROUP BY MONTH(date_available)
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="selected">';
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(date_available) AS day, COUNT(id) AS count
160  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
161  '.$page['where'].'
162    AND id = image_id
163    AND YEAR(date_available) = '.$page['calendar_year'].'
164    AND MONTH(date_available) = '.$page['calendar_month'].'
165  GROUP BY day
166;';
167  echo '<pre>'.$query.'</pre>';
168  $result = mysql_query($query);
169  $calendar_days = array();
170  while ($row = mysql_fetch_array($result))
171  {
172    $calendar_days[$row['day']] = $row['count'];
173  }
174  $nb_pics = count($calendar_days);
175}
176elseif (isset($page['calendar_day']))
177{
178  // $page['calendar_date'] is the concatenation of year-month-day. simplier
179  // to use in SQ queries
180  $page['calendar_date'] = $page['calendar_year'];
181  $page['calendar_date'].= '-'.$page['calendar_month'];
182  $page['calendar_date'].= '-'.$page['calendar_day'];
183 
184  $query = '
185SELECT category_id AS category, COUNT(id) AS count
186  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
187  '.$page['where'].'
188    AND date_available = \''.$page['calendar_date'].'\'
189    AND id = image_id
190  GROUP BY category_id
191;';
192//  echo '<pre>'.$query.'</pre>';
193  $result = mysql_query($query);
194  $calendar_categories = array();
195  // special category 0 : gathering all available categories (0 cannot be a
196  // oregular category identifier)
197  $calendar_categories[0] = 0;
198  while ($row = mysql_fetch_array($result))
199  {
200    $calendar_categories[$row['category']] = $row['count'];
201  }
202  // update the total number of pictures for this day
203  $calendar_categories[0] = array_sum($calendar_categories);
204 
205  $nb_pics = count($calendar_categories);
206}
207
208// template thumbnail initialization
209if ($nb_pics > 0)
210{
211  $template->assign_block_vars('thumbnails', array());
212  // first line
213  $template->assign_block_vars('thumbnails.line', array());
214  // current row displayed
215  $row_number = 0;
216}
217
218if (!isset($page['calendar_year']))
219{
220  // for each month of this year, display a random picture
221  foreach ($calendar_years as $calendar_year => $nb_pics)
222  {
223    $query = '
224SELECT file,tn_ext,date_available,storage_category_id
225  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
226  '.$page['where'].'
227    AND YEAR(date_available) = '.$calendar_year.'
228    AND id = image_id
229  ORDER BY RAND()
230  LIMIT 0,1
231;';
232    $row = mysql_fetch_array(mysql_query($query));
233   
234    $file = get_filename_wo_extension($row['file']);
235   
236    // creating links for thumbnail and associated category
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    $name = $calendar_year.' ('.$nb_pics.')';
242
243    $thumbnail_title = $lang['calendar_picture_hint'].$name;
244     
245    $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar';
246    $url_link.= '&amp;year='.$calendar_year;
247   
248    $template->assign_block_vars(
249      'thumbnails.line.thumbnail',
250      array(
251        'IMAGE'=>$thumbnail_link,
252        'IMAGE_ALT'=>$row['file'],
253        'IMAGE_TITLE'=>$thumbnail_title,
254        'IMAGE_NAME'=>$name,
255         
256        'U_IMG_LINK'=>add_session_id($url_link)
257       )
258     );
259
260    // create a new line ?
261    if (++$row_number == $user['nb_image_line'])
262    {
263      $template->assign_block_vars('thumbnails.line', array());
264      $row_number = 0;
265    }
266  }
267}
268elseif (!isset($page['calendar_month']))
269{
270  // for each month of this year, display a random picture
271  foreach ($calendar_months as $calendar_month => $nb_pics)
272  {
273    $query = '
274SELECT file,tn_ext,date_available,storage_category_id
275  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
276  '.$page['where'].'
277    AND YEAR(date_available) = '.$page['calendar_year'].'
278    AND MONTH(date_available) = '.$calendar_month.'
279    AND id = image_id
280  ORDER BY RAND()
281  LIMIT 0,1
282;';
283//    echo '<pre>'.$query.'</pre>';
284    $row = mysql_fetch_array(mysql_query($query));
285   
286    $file = get_filename_wo_extension($row['file']);
287   
288    // creating links for thumbnail and associated category
289    $thumbnail_link = get_complete_dir($row['storage_category_id']);
290    $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
291    $thumbnail_link.= $file.'.'.$row['tn_ext'];
292     
293    $name = $lang['month'][$calendar_month];
294    $name.= ' '.$page['calendar_year'];
295    $name.= ' ('.$nb_pics.')';
296
297    $thumbnail_title = $lang['calendar_picture_hint'].$name;
298     
299    $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar';
300    $url_link.= '&amp;month='.$page['calendar_year'].'.';
301    if ($calendar_month < 10)
302    {
303      // adding leading zero
304      $url_link.= '0';
305    }
306    $url_link.= $calendar_month;
307   
308    $template->assign_block_vars(
309      'thumbnails.line.thumbnail',
310      array(
311        'IMAGE'=>$thumbnail_link,
312        'IMAGE_ALT'=>$row['file'],
313        'IMAGE_TITLE'=>$thumbnail_title,
314        'IMAGE_NAME'=>$name,
315         
316        'U_IMG_LINK'=>add_session_id($url_link)
317       )
318     );
319
320    // create a new line ?
321    if (++$row_number == $user['nb_image_line'])
322    {
323      $template->assign_block_vars('thumbnails.line', array());
324      $row_number = 0;
325    }
326  }
327}
328elseif (!isset($page['calendar_day']))
329{
330  // for each day of the requested month, display a random picture
331  foreach ($calendar_days as $calendar_day => $nb_pics)
332  {
333    $query = '
334SELECT file,tn_ext,date_available,storage_category_id
335  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
336  '.$page['where'].'
337    AND date_available = \''.$calendar_day.'\'
338    AND id = image_id
339  ORDER BY RAND()
340  LIMIT 0,1
341;';
342    $row = mysql_fetch_array(mysql_query($query));
343   
344    $file = get_filename_wo_extension($row['file']);
345   
346    // creating links for thumbnail and associated category
347    $thumbnail_link = get_complete_dir($row['storage_category_id']);
348    $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
349    $thumbnail_link.= $file.'.'.$row['tn_ext'];
350
351    list($year,$month,$day) = explode('-', $calendar_day);
352    $unixdate = mktime(0,0,0,$month,$day,$year);
353    $name = $lang['day'][date("w", $unixdate)];
354    $name.= ' '.$day;
355    $name.= ' ('.$nb_pics.')';
356     
357    $thumbnail_title = $lang['calendar_picture_hint'].$name;
358
359    $url_link = PHPWG_ROOT_PATH.'category.php';
360    $url_link.= '?cat=calendar&amp;day='.str_replace('-', '.', $calendar_day);
361   
362    $template->assign_block_vars(
363      'thumbnails.line.thumbnail',
364      array(
365        'IMAGE'=>$thumbnail_link,
366        'IMAGE_ALT'=>$row['file'],
367        'IMAGE_TITLE'=>$thumbnail_title,
368        'IMAGE_NAME'=>$name,
369         
370        'U_IMG_LINK'=>add_session_id($url_link)
371         )
372       );
373
374    // create a new line ?
375    if (++$row_number == $user['nb_image_line'])
376    {
377      $template->assign_block_vars('thumbnails.line', array());
378      $row_number = 0;
379    }
380  }
381}
382elseif (isset($page['calendar_day']))
383{
384  // for each category of this day, display a random picture
385  foreach ($calendar_categories as $calendar_category => $nb_pics)
386  {
387    if ($calendar_category == 0)
388    {
389      $name = '[all]';
390    }
391    else
392    {
393      $cat_infos = get_cat_info( $calendar_category );
394      $name = get_cat_display_name($cat_infos['name'],'<br />','',false);
395      $name = '['.$name.']';
396    }
397    $name.= ' ('.$nb_pics.')';
398   
399    $query = '
400SELECT file,tn_ext,date_available,storage_category_id
401  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
402  '.$page['where'].'
403    AND date_available = \''.$page['calendar_date'].'\'';
404    if ($calendar_category != 0)
405    {
406      $query.= '
407    AND category_id = '.$calendar_category;
408    }
409    $query.= '
410    AND id = image_id
411  ORDER BY RAND()
412  LIMIT 0,1
413;';
414    $row = mysql_fetch_array(mysql_query($query));
415   
416    $file = get_filename_wo_extension($row['file']);
417   
418    // creating links for thumbnail and associated category
419    $thumbnail_link = get_complete_dir($row['storage_category_id']);
420    $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
421    $thumbnail_link.= $file.'.'.$row['tn_ext'];
422   
423    $thumbnail_title = $lang['calendar_picture_hint'].$name;
424
425    $url_link = PHPWG_ROOT_PATH.'category.php?cat=search';
426    $template->assign_block_vars(
427      'thumbnails.line.thumbnail',
428      array(
429        'IMAGE'=>$thumbnail_link,
430        'IMAGE_ALT'=>$row['file'],
431        'IMAGE_TITLE'=>$thumbnail_title,
432        'IMAGE_NAME'=>$name,
433         
434        'U_IMG_LINK'=>add_session_id($url_link)
435         )
436       );
437    $template->assign_block_vars('thumbnails.line.thumbnail.bullet',array());
438   
439    // create a new line ?
440    if (++$row_number == $user['nb_image_line'])
441    {
442      $template->assign_block_vars('thumbnails.line', array());
443      $row_number = 0;
444    }
445  }
446}
447?>
Note: See TracBrowser for help on using the repository browser.