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

Last change on this file since 606 was 606, checked in by plg, 19 years ago
  • images.path column added to reduce database access
  • function mass_inserts moved from admin/remote_sites.php to admin/include/function.php
  • function mass_inserts used in admin/update.php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.2 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-16 23:38:34 +0000 (Tue, 16 Nov 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 606 $
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'].',path
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['path'], @$row['tn_ext']);
233   
234    $name = $calendar_year.' ('.$nb_pics.')';
235
236    $thumbnail_title = $lang['calendar_picture_hint'].$name;
237     
238    $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar';
239    $url_link.= '&amp;year='.$calendar_year;
240   
241    $template->assign_block_vars(
242      'thumbnails.line.thumbnail',
243      array(
244        'IMAGE'=>$thumbnail_src,
245        'IMAGE_ALT'=>$row['file'],
246        'IMAGE_TITLE'=>$thumbnail_title,
247        'IMAGE_NAME'=>$name,
248         
249        'U_IMG_LINK'=>add_session_id($url_link)
250       )
251     );
252
253    // create a new line ?
254    if (++$row_number == $user['nb_image_line'])
255    {
256      $template->assign_block_vars('thumbnails.line', array());
257      $row_number = 0;
258    }
259  }
260}
261elseif (!isset($page['calendar_month']))
262{
263  // for each month of this year, display a random picture
264  foreach ($calendar_months as $calendar_month => $nb_pics)
265  {
266    $query = '
267SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
268  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
269  '.$page['where'].'
270    AND YEAR('.$conf['calendar_datefield'].') = '.$page['calendar_year'].'
271    AND MONTH('.$conf['calendar_datefield'].') = '.$calendar_month.'
272    AND id = image_id
273  ORDER BY RAND()
274  LIMIT 0,1
275;';
276    $row = mysql_fetch_array(pwg_query($query));
277   
278    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
279   
280    $name = $lang['month'][$calendar_month];
281    $name.= ' '.$page['calendar_year'];
282    $name.= ' ('.$nb_pics.')';
283
284    $thumbnail_title = $lang['calendar_picture_hint'].$name;
285     
286    $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar';
287    $url_link.= '&amp;month='.$page['calendar_year'].'.';
288    if ($calendar_month < 10)
289    {
290      // adding leading zero
291      $url_link.= '0';
292    }
293    $url_link.= $calendar_month;
294   
295    $template->assign_block_vars(
296      'thumbnails.line.thumbnail',
297      array(
298        'IMAGE'=>$thumbnail_src,
299        'IMAGE_ALT'=>$row['file'],
300        'IMAGE_TITLE'=>$thumbnail_title,
301        'IMAGE_NAME'=>$name,
302         
303        'U_IMG_LINK'=>add_session_id($url_link)
304       )
305     );
306
307    // create a new line ?
308    if (++$row_number == $user['nb_image_line'])
309    {
310      $template->assign_block_vars('thumbnails.line', array());
311      $row_number = 0;
312    }
313  }
314}
315elseif (!isset($page['calendar_day']))
316{
317  // for each day of the requested month, display a random picture
318  foreach ($calendar_days as $calendar_day => $nb_pics)
319  {
320    $query = '
321SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
322  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
323  '.$page['where'].'
324    AND '.$conf['calendar_datefield'].' = \''.$calendar_day.'\'
325    AND id = image_id
326  ORDER BY RAND()
327  LIMIT 0,1
328;';
329    $row = mysql_fetch_array(pwg_query($query));
330   
331    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
332
333    list($year,$month,$day) = explode('-', $calendar_day);
334    $unixdate = mktime(0,0,0,$month,$day,$year);
335    $name = $lang['day'][date("w", $unixdate)];
336    $name.= ' '.$day;
337    $name.= ' ('.$nb_pics.')';
338     
339    $thumbnail_title = $lang['calendar_picture_hint'].$name;
340
341    $url_link = PHPWG_ROOT_PATH.'category.php';
342    $url_link.= '?cat=calendar&amp;day='.str_replace('-', '.', $calendar_day);
343   
344    $template->assign_block_vars(
345      'thumbnails.line.thumbnail',
346      array(
347        'IMAGE'=>$thumbnail_src,
348        'IMAGE_ALT'=>$row['file'],
349        'IMAGE_TITLE'=>$thumbnail_title,
350        'IMAGE_NAME'=>$name,
351         
352        'U_IMG_LINK'=>add_session_id($url_link)
353         )
354       );
355
356    // create a new line ?
357    if (++$row_number == $user['nb_image_line'])
358    {
359      $template->assign_block_vars('thumbnails.line', array());
360      $row_number = 0;
361    }
362  }
363}
364elseif (isset($page['calendar_day']))
365{
366  // for each category of this day, display a random picture
367  foreach ($calendar_categories as $calendar_category => $nb_pics)
368  {
369    if ($calendar_category == 0)
370    {
371      $name = '[all]';
372    }
373    else
374    {
375      $cat_infos = get_cat_info( $calendar_category );
376      $name = get_cat_display_name($cat_infos['name'],'<br />','',false);
377      $name = '['.$name.']';
378    }
379    $name.= ' ('.$nb_pics.')';
380   
381    $query = '
382SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
383  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
384  '.$page['where'].'
385    AND '.$conf['calendar_datefield'].' = \''.$page['calendar_date'].'\'';
386    if ($calendar_category != 0)
387    {
388      $query.= '
389    AND category_id = '.$calendar_category;
390    }
391    $query.= '
392    AND id = image_id
393  ORDER BY RAND()
394  LIMIT 0,1
395;';
396    $row = mysql_fetch_array(pwg_query($query));
397   
398    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
399   
400    $thumbnail_title = $lang['calendar_picture_hint'].$name;
401
402    $url_link = PHPWG_ROOT_PATH.'category.php?cat=search';
403    $url_link.= '&amp;search='.$conf['calendar_datefield'].':'.$_GET['day'];
404    if ($calendar_category != 0)
405    {
406      $url_link.= ';cat:'.$calendar_category.'|AND';
407    }
408   
409    $template->assign_block_vars(
410      'thumbnails.line.thumbnail',
411      array(
412        'IMAGE'=>$thumbnail_src,
413        'IMAGE_ALT'=>$row['file'],
414        'IMAGE_TITLE'=>$thumbnail_title,
415        'IMAGE_NAME'=>$name,
416         
417        'U_IMG_LINK'=>add_session_id($url_link)
418         )
419       );
420    $template->assign_block_vars('thumbnails.line.thumbnail.bullet',array());
421   
422    // create a new line ?
423    if (++$row_number == $user['nb_image_line'])
424    {
425      $template->assign_block_vars('thumbnails.line', array());
426      $row_number = 0;
427    }
428  }
429}
430?>
Note: See TracBrowser for help on using the repository browser.