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

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

non picture files management

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