Index: trunk/category.php
===================================================================
--- trunk/category.php	(revision 1050)
+++ trunk/category.php	(revision 1051)
@@ -301,5 +301,5 @@
   'special_cat',
   array(
-    'URL' => PHPWG_ROOT_PATH.'category.php?cat=calendar',
+    'URL' => PHPWG_ROOT_PATH.'category.php?calendar=m-c',
     'TITLE' => $lang['calendar_hint'],
     'NAME' => $lang['calendar']
@@ -401,4 +401,33 @@
     );
 }
+
+if ($page['cat_nb_images']>0 and 
+    ( !isset($page['cat']) 
+      or ($page['cat'] != 'most_visited' and $page['cat'] != 'best_rated') )
+   )
+{
+  // image order
+  $template->assign_block_vars( 'preferred_image_order', array() );
+
+  $order_idx = isset($_COOKIE['pwg_image_order']) ? 
+                   $_COOKIE['pwg_image_order'] : 0;
+
+  $orders = get_category_preferred_image_orders();
+  for ( $i = 0; $i < count($orders); $i++)
+  {
+    if ($orders[$i][2])
+    {
+      $url = PHPWG_ROOT_PATH.'category.php'
+               .get_query_string_diff(array('image_order'));
+      $url .= '&amp;image_order='.$i;
+      $template->assign_block_vars( 'preferred_image_order.order', array(
+        'DISPLAY' => $orders[$i][0],
+        'URL' => $url,
+        'SELECTED_OPTION' => ($order_idx==$i ? 'SELECTED' : '' ),
+        ) );
+    }
+  }
+}
+
 if ( isset ( $page['cat'] ) )
 {
@@ -423,29 +452,4 @@
       );
   }
-  if ($page['cat_nb_images']>0 and 
-       $page['cat'] != 'most_visited' and $page['cat'] != 'best_rated')
-  {
-    // image order
-    $template->assign_block_vars( 'preferred_image_order', array() );
-  
-    $order_idx = isset($_COOKIE['pwg_image_order']) ? 
-                     $_COOKIE['pwg_image_order'] : 0;
-
-    $orders = get_category_preferred_image_orders();
-    for ( $i = 0; $i < count($orders); $i++)
-    {
-      if ($orders[$i][2])
-      {
-        $url = PHPWG_ROOT_PATH.'category.php'
-                 .get_query_string_diff(array('image_order'));
-        $url .= '&amp;image_order='.$i;
-        $template->assign_block_vars( 'preferred_image_order.order', array(
-          'DISPLAY' => $orders[$i][0],
-          'URL' => $url,
-          'SELECTED_OPTION' => ($order_idx==$i ? 'SELECTED' : '' ),
-          ) );
-      }
-    }
-  }
 }
 //------------------------------------------------------------ log informations
Index: trunk/include/calendar_monthly.class.php
===================================================================
--- trunk/include/calendar_monthly.class.php	(revision 1050)
+++ trunk/include/calendar_monthly.class.php	(revision 1051)
@@ -127,5 +127,5 @@
       }
     }
-    $res = " AND $this->date_field BETWEEN '$b' AND '$e'" . $res;
+    $res = " AND $this->date_field BETWEEN '$b' AND '$e 23:59:59'" . $res;
   }
   else
@@ -236,10 +236,12 @@
     $url_base = $this->url_base.'c-'.$requested[0].'-'.$month;
 
-    $nav_bar = '<span class="calCalHead"><a href="'.$url_base.'">'.$lang['month'][$month].'</a>';
+    $nav_bar = '<span class="calCalHead"><a href="'.$url_base.'">';
+    $nav_bar .= $lang['month'][$month].'</a>';
     $nav_bar .= ' ('.$month_data['nb_images'].')';
     $nav_bar .= '</span><br>';
 
     $url_base .= '-';
-    $nav_bar .= $this->get_nav_bar_from_items( $url_base, $month_data['children'], $requested[1], 'calCal', false );
+    $nav_bar .= $this->get_nav_bar_from_items( $url_base, 
+                     $month_data['children'], $requested[1], 'calCal', false );
 
     $template->assign_block_vars( 'calendar.calbar',
@@ -279,4 +281,7 @@
     $query.= $this->inner_sql;
     $query.= $this->get_date_where($requested);
+    $query.= '
+  ORDER BY RAND()
+  LIMIT 0,1';
 
     $row = mysql_fetch_array(pwg_query($query));
@@ -306,4 +311,3 @@
 
 }
-
 ?>
Index: trunk/include/calendar_weekly.class.php
===================================================================
--- trunk/include/calendar_weekly.class.php	(revision 1050)
+++ trunk/include/calendar_weekly.class.php	(revision 1051)
@@ -73,5 +73,5 @@
   {
     $y = $requested[0];
-    $res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31'";
+    $res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'";
   }
 
Index: trunk/include/category_calendar.inc.php
===================================================================
--- trunk/include/category_calendar.inc.php	(revision 1050)
+++ 	(revision )
@@ -1,458 +1,0 @@
-<?php
-// +-----------------------------------------------------------------------+
-// | PhpWebGallery - a PHP based picture gallery                           |
-// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
-// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
-// +-----------------------------------------------------------------------+
-// | branch        : BSF (Best So Far)
-// | file          : $RCSfile$
-// | last update   : $Date$
-// | last modifier : $Author$
-// | revision      : $Revision$
-// +-----------------------------------------------------------------------+
-// | This program is free software; you can redistribute it and/or modify  |
-// | it under the terms of the GNU General Public License as published by  |
-// | the Free Software Foundation                                          |
-// |                                                                       |
-// | This program is distributed in the hope that it will be useful, but   |
-// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
-// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
-// | General Public License for more details.                              |
-// |                                                                       |
-// | You should have received a copy of the GNU General Public License     |
-// | along with this program; if not, write to the Free Software           |
-// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
-// | USA.                                                                  |
-// +-----------------------------------------------------------------------+
-
-/**
- * This file is included by category.php to show thumbnails for the category
- * calendar
- * 
- */
-
-// years of image availability
-$query = '
-SELECT YEAR('.$conf['calendar_datefield'].') AS year, COUNT(id) AS count
-  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
-  '.$page['where'].'
-    AND id = image_id
-  GROUP BY year
-;';
-$result = pwg_query($query);
-$calendar_years = array();
-while ($row = mysql_fetch_array($result))
-{
-  $calendar_years[$row['year']] = $row['count'];
-}
-
-// if the year requested is not among the available years, we unset the
-// variable
-if (isset($page['calendar_year'])
-    and !isset($calendar_years[$page['calendar_year']]))
-{
-  unset($page['calendar_year']);
-}
-
-// years navigation bar creation
-$years_nav_bar = '';
-foreach ($calendar_years as $calendar_year => $nb_picture_year)
-{
-  if (isset($page['calendar_year'])
-      and $calendar_year == $page['calendar_year'])
-  {
-    $years_nav_bar.= ' <span class="dateSelected">'.$calendar_year.'</span>';
-  }
-  else
-  {
-    $url = PHPWG_ROOT_PATH.'category.php?cat=calendar';
-    $url.= '&amp;year='.$calendar_year;
-    $years_nav_bar.= ' <a href="'.$url.'">'.$calendar_year.'</a>';
-  }
-}
-
-$template->assign_block_vars(
-  'calendar',
-  array('YEARS_NAV_BAR' => $years_nav_bar)
-  );
-
-// months are calculated (to know which months are available, and how many
-// pictures per month we can find) only if a year is requested.
-if (isset($page['calendar_year']))
-{
-  // creation of hash associating the number of the month in the year with
-  // the number of picture for this month : $calendar_months
-  $query = '
-SELECT DISTINCT(MONTH('.$conf['calendar_datefield'].')) AS month
-     , COUNT(id) AS count
-  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
-  '.$page['where'].'
-    AND '.$conf['calendar_datefield'].'
-      BETWEEN \''.$page['calendar_year'].'-1-1\'
-      AND \''.$page['calendar_year'].'-12-31\'
-  GROUP BY MONTH('.$conf['calendar_datefield'].')
-;';
-  $result = pwg_query($query);
-  $calendar_months = array();
-  while ($row = mysql_fetch_array($result))
-  {
-    $calendar_months[$row['month']] = $row['count'];
-  }
-
-  // if a month is requested and is not among the available months, we unset
-  // the requested month
-  if (isset($page['calendar_month'])
-      and !isset($calendar_months[$page['calendar_month']]))
-  {
-    unset($page['calendar_month']);
-  }
-
-  // months navigation bar creation
-  $months_nav_bar = '';
-  foreach ($calendar_months as $calendar_month => $nb_picture_month)
-  {
-    if (isset($page['calendar_month'])
-        and $calendar_month == $page['calendar_month'])
-    {
-      $months_nav_bar.= ' <span class="dateSelected">';
-      $months_nav_bar.= $lang['month'][(int)$calendar_month];
-      $months_nav_bar.= '</span>';
-    }
-    else
-    {
-      $url = PHPWG_ROOT_PATH.'category.php?cat=calendar&amp;month=';
-      $url.= $page['calendar_year'].'.'.sprintf('%02s', $calendar_month);
-      $months_nav_bar.= ' ';
-      $months_nav_bar.= '<a href="'.$url.'">';
-      $months_nav_bar.= $lang['month'][(int)$calendar_month];
-      $months_nav_bar.= '</a>';
-    }
-  }
-  $template->assign_block_vars(
-    'calendar',
-    array('MONTHS_NAV_BAR' => $months_nav_bar));
-}
-
-/**
- * 4 sub-cases are possibles for the calendar category :
- *
- *  1. show years if no year is requested
- *  2. show months of the requested year if no month is requested
- *  3. show days of the {year,month} requested if no day requested
- *  4. show categories of the requested day (+ a special category gathering
- *     all categories)
- */
-
-if (!isset($page['calendar_year']))
-{
-  $nb_pics = count($calendar_years);
-}
-elseif (!isset($page['calendar_month']))
-{
-  $nb_pics = count($calendar_months);
-}
-elseif (!isset($page['calendar_day']))
-{
-  // creation of hash associating the number of the day in the month with
-  // the number of picture for this day : $calendar_days
-  $query = '
-SELECT
-    DISTINCT DATE_FORMAT('.$conf['calendar_datefield'].', \'%Y-%m-%d\') AS day
-  , COUNT(id) AS count
-  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
-  '.$page['where'].'
-    AND '.$conf['calendar_datefield'].'
-      BETWEEN \''.$page['calendar_year'].'-'.$page['calendar_month'].'-1\'
-      AND \''.$page['calendar_year'].'-'.$page['calendar_month'].'-31\'
-  GROUP BY day
-;';
-  $result = pwg_query($query);
-  $calendar_days = array();
-  while ($row = mysql_fetch_array($result))
-  {
-    $calendar_days[$row['day']] = $row['count'];
-  }
-  $nb_pics = count($calendar_days);
-}
-elseif (isset($page['calendar_day']))
-{
-  // $page['calendar_date'] is the concatenation of year-month-day. simplier
-  // to use in SQ queries
-  $page['calendar_date'] = $page['calendar_year'];
-  $page['calendar_date'].= '-'.$page['calendar_month'];
-  $page['calendar_date'].= '-'.$page['calendar_day'];
-  
-  $query = '
-SELECT category_id AS category, COUNT(id) AS count
-  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
-  '.$page['where'].'
-    AND '.$conf['calendar_datefield'].' = \''.$page['calendar_date'].'\'
-  GROUP BY category_id
-;';
-  $result = pwg_query($query);
-  $calendar_categories = array();
-  // special category 0 : gathering all available categories (0 cannot be a
-  // oregular category identifier)
-  $calendar_categories[0] = 0;
-  while ($row = mysql_fetch_array($result))
-  {
-    $calendar_categories[$row['category']] = $row['count'];
-  }
-  // update the total number of pictures for this day
-  $calendar_categories[0] = array_sum($calendar_categories);
-  
-  $nb_pics = count($calendar_categories);
-}
-
-// template thumbnail initialization
-if ($nb_pics > 0)
-{
-  $template->assign_block_vars('thumbnails', array());
-  // first line
-  $template->assign_block_vars('thumbnails.line', array());
-  // current row displayed
-  $row_number = 0;
-}
-
-if (!isset($page['calendar_year']))
-{
-  // for each month of this year, display a random picture
-  foreach ($calendar_years as $calendar_year => $nb_pics)
-  {
-    $query = '
-SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
-  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
-  '.$page['where'].'
-    AND '.$conf['calendar_datefield'].'
-      BETWEEN \''.$calendar_year.'-1-1\'
-      AND \''.$calendar_year.'-12-31\'
-  ORDER BY RAND()
-  LIMIT 0,1
-;';
-    $row = mysql_fetch_array(pwg_query($query));
-    
-    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
-    
-    $name = $calendar_year.' ('.$nb_pics.')';
-
-    $thumbnail_title = $lang['calendar_picture_hint'].$name;
-      
-    $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar';
-    $url_link.= '&amp;year='.$calendar_year;
-    
-    $template->assign_block_vars(
-      'thumbnails.line.thumbnail',
-      array(
-        'IMAGE'=>$thumbnail_src,
-        'IMAGE_ALT'=>$row['file'],
-        'IMAGE_TITLE'=>$thumbnail_title,
-          
-        'U_IMG_LINK'=>$url_link
-       )
-     );
-
-    $template->assign_block_vars(
-      'thumbnails.line.thumbnail.category_name',
-      array(
-        'NAME' => $name
-        )
-      );
-
-    // create a new line ?
-    if (++$row_number == $user['nb_image_line'])
-    {
-      $template->assign_block_vars('thumbnails.line', array());
-      $row_number = 0;
-    }
-  }
-}
-elseif (!isset($page['calendar_month']))
-{
-  // for each month of this year, display a random picture
-  foreach ($calendar_months as $calendar_month => $nb_pics)
-  {
-    $query = '
-SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
-  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
-  '.$page['where'].'
-    AND '.$conf['calendar_datefield'].'
-      BETWEEN \''.$page['calendar_year'].'-'.$calendar_month.'-1\'
-      AND \''.$page['calendar_year'].'-'.$calendar_month.'-31\'
-  ORDER BY RAND()
-  LIMIT 0,1
-;';
-    $row = mysql_fetch_array(pwg_query($query));
-    
-    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
-    
-    $name = $lang['month'][$calendar_month];
-    $name.= ' '.$page['calendar_year'];
-    $name.= ' ('.$nb_pics.')';
-
-    $thumbnail_title = $lang['calendar_picture_hint'].$name;
-      
-    $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar';
-    $url_link.= '&amp;month='.$page['calendar_year'].'.';
-    if ($calendar_month < 10)
-    {
-      // adding leading zero
-      $url_link.= '0';
-    }
-    $url_link.= $calendar_month;
-    
-    $template->assign_block_vars(
-      'thumbnails.line.thumbnail',
-      array(
-        'IMAGE'=>$thumbnail_src,
-        'IMAGE_ALT'=>$row['file'],
-        'IMAGE_TITLE'=>$thumbnail_title,
-          
-        'U_IMG_LINK'=>$url_link
-       )
-     );
-
-    $template->assign_block_vars(
-      'thumbnails.line.thumbnail.category_name',
-      array(
-        'NAME' => $name
-        )
-      );
-
-    // create a new line ?
-    if (++$row_number == $user['nb_image_line'])
-    {
-      $template->assign_block_vars('thumbnails.line', array());
-      $row_number = 0;
-    }
-  }
-}
-elseif (!isset($page['calendar_day']))
-{
-  // for each day of the requested month, display a random picture
-  foreach ($calendar_days as $calendar_day => $nb_pics)
-  {
-    $query = '
-SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
-       , DAYOFWEEK(\''.$calendar_day.'\') AS dow
-  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
-  '.$page['where'].'
-    AND '.$conf['calendar_datefield'].' = \''.$calendar_day.'\'
-  ORDER BY RAND()
-  LIMIT 0,1
-;';
-    $row = mysql_fetch_array(pwg_query($query));
-    
-    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
-
-    list($year,$month,$day) = explode('-', $calendar_day);
-    $name = $lang['day'][$row['dow']-1];
-    $name.= ' '.$day;
-    $name.= ' ('.$nb_pics.')';
-      
-    $thumbnail_title = $lang['calendar_picture_hint'].$name;
-
-    $url_link = PHPWG_ROOT_PATH.'category.php';
-    $url_link.= '?cat=calendar&amp;day='.str_replace('-', '.', $calendar_day);
-    
-    $template->assign_block_vars(
-      'thumbnails.line.thumbnail',
-      array(
-        'IMAGE'=>$thumbnail_src,
-        'IMAGE_ALT'=>$row['file'],
-        'IMAGE_TITLE'=>$thumbnail_title,
-          
-        'U_IMG_LINK'=>$url_link
-         )
-       );
-
-    $template->assign_block_vars(
-      'thumbnails.line.thumbnail.category_name',
-      array(
-        'NAME' => $name
-        )
-      );
-
-    // create a new line ?
-    if (++$row_number == $user['nb_image_line'])
-    {
-      $template->assign_block_vars('thumbnails.line', array());
-      $row_number = 0;
-    }
-  }
-}
-elseif (isset($page['calendar_day']))
-{
-  $old_level_separator = $conf['level_separator'];
-  $conf['level_separator'] = '<br />';
-  // for each category of this day, display a random picture
-  foreach ($calendar_categories as $calendar_category => $nb_pics)
-  {
-    if ($calendar_category == 0)
-    {
-      $name = '['.$lang['all_categories'].']';
-    }
-    else
-    {
-      $cat_infos = get_cat_info( $calendar_category );
-      
-      $name = get_cat_display_name($cat_infos['name'],'',false);
-      $name = '['.$name.']';
-    }
-    $name.= ' ('.$nb_pics.')';
-    
-    $query = '
-SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
-  FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
-  '.$page['where'].'
-    AND '.$conf['calendar_datefield'].' = \''.$page['calendar_date'].'\'';
-    if ($calendar_category != 0)
-    {
-      $query.= '
-    AND category_id = '.$calendar_category;
-    }
-    $query.= '
-    AND id = image_id
-  ORDER BY RAND()
-  LIMIT 0,1
-;';
-    $row = mysql_fetch_array(pwg_query($query));
-    
-    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
-    
-    $thumbnail_title = $lang['calendar_picture_hint'].$name;
-
-    $url_link = PHPWG_ROOT_PATH.'category.php?cat=search';
-    $url_link.= '&amp;search='.$conf['calendar_datefield'].':'.$_GET['day'];
-    if ($calendar_category != 0)
-    {
-      $url_link.= '--cat:'.$calendar_category.'|AND';
-    }
-    
-    $template->assign_block_vars(
-      'thumbnails.line.thumbnail',
-      array(
-        'IMAGE'=>$thumbnail_src,
-        'IMAGE_ALT'=>$row['file'],
-        'IMAGE_TITLE'=>$thumbnail_title,
-          
-        'U_IMG_LINK'=>$url_link
-         )
-       );
-
-    $template->assign_block_vars(
-      'thumbnails.line.thumbnail.category_name',
-      array(
-        'NAME' => $name
-        )
-      );
-    
-    // create a new line ?
-    if (++$row_number == $user['nb_image_line'])
-    {
-      $template->assign_block_vars('thumbnails.line', array());
-      $row_number = 0;
-    }
-  }
-  $conf['level_separator'] = $old_level_separator;
-}
-?>
Index: trunk/include/functions_calendar.inc.php
===================================================================
--- trunk/include/functions_calendar.inc.php	(revision 1050)
+++ trunk/include/functions_calendar.inc.php	(revision 1051)
@@ -232,4 +232,17 @@
     $query .= $calendar->inner_sql;
     $query .= $calendar->get_date_where($requested);
+    if ( isset($page['super_order_by']) )
+    {
+      $query .= '
+  '.$conf['order_by'];
+    }
+    else
+    {
+      $order_by = str_replace(
+                'ORDER BY ',
+                'ORDER BY '.$calendar->date_field.',', $conf['order_by']
+               );
+      $query .= $order_by;
+    }
 
     $page['items'] = array_from_query($query, 'id');
Index: trunk/include/section_init.inc.php
===================================================================
--- trunk/include/section_init.inc.php	(revision 1050)
+++ trunk/include/section_init.inc.php	(revision 1051)
@@ -53,6 +53,5 @@
            or $_GET['cat'] == 'best_rated'
            or $_GET['cat'] == 'recent_pics'
-           or $_GET['cat'] == 'recent_cats'
-           or $_GET['cat'] == 'calendar')
+           or $_GET['cat'] == 'recent_cats')
   {
     $page['cat'] = $_GET['cat'];
@@ -98,22 +97,21 @@
 $page['nb_image_page'] = $user['nb_image_page'];
 
+if (isset($_COOKIE['pwg_image_order'])
+    and is_numeric($_COOKIE['pwg_image_order'])
+    and $_COOKIE['pwg_image_order'] > 0)
+{
+  $orders = get_category_preferred_image_orders();
+
+  $conf['order_by'] = str_replace(
+    'ORDER BY ',
+    'ORDER BY '.$orders[ $_COOKIE['pwg_image_order'] ][1].',', 
+    $conf['order_by']
+    );
+  $page['super_order_by'] = true;
+}
+
 if (isset($page['cat']))
 {
-  if ($page['cat'] != 'most_visited' and $page['cat'] != 'best_rated')
-  {
-    if (isset($_COOKIE['pwg_image_order'])
-        and is_numeric($_COOKIE['pwg_image_order'])
-        and $_COOKIE['pwg_image_order'] > 0)
-    {
-      $orders = get_category_preferred_image_orders();
-
-      $conf['order_by'] = str_replace(
-        'ORDER BY ',
-        'ORDER BY '.$orders[ $_COOKIE['pwg_image_order'] ][1].',', 
-        $conf['order_by']
-        );
-    }
-  }
-  
+ 
 // +-----------------------------------------------------------------------+
 // |                              category                                 |
@@ -121,14 +119,6 @@
   if (is_numeric($page['cat']))
   {
-    $query = '
-SELECT image_id
-  FROM '.IMAGE_CATEGORY_TABLE.'
-    INNER JOIN '.IMAGES_TABLE.' ON id = image_id
-  WHERE category_id = '.$page['cat'].'
-  '.$conf['order_by'].'
-;';
-
     $result = get_cat_info($page['cat']);
-    
+
     $page = array_merge(
       $page,
@@ -143,13 +133,23 @@
         'cat_id_uppercat'  => $result['id_uppercat'],
         'uppercats'        => $result['uppercats'],
-                
+
         'title' => get_cat_display_name($result['name'], '', false),
-        'items' => array_from_query($query, 'image_id'),
-        'thumbnails_include' =>
+        )
+      );
+    if ( !isset($_GET['calendar']) )
+    {
+      $query = '
+SELECT image_id
+  FROM '.IMAGE_CATEGORY_TABLE.'
+    INNER JOIN '.IMAGES_TABLE.' ON id = image_id
+  WHERE category_id = '.$page['cat'].'
+  '.$conf['order_by'].'
+;';
+      $page['items'] = array_from_query($query, 'image_id');
+      $page['thumbnails_include'] =
           $result['nb_images'] > 0
           ? 'include/category_default.inc.php'
-          : 'include/category_subcats.inc.php',
-        )
-      );
+          : 'include/category_subcats.inc.php';
+    }//otherwise the calendar will requery all subitems
   }
   // special section
@@ -256,4 +256,6 @@
     else if ($page['cat'] == 'most_visited')
     {
+      $page['super_order_by'] = true;
+      $conf['order_by'] = ' ORDER BY hit DESC, file ASC';
       $query = '
 SELECT DISTINCT(id)
@@ -261,6 +263,6 @@
     INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
   WHERE hit > 0
-    AND '.$forbidden.'
-  ORDER BY hit DESC, file ASC
+    AND '.$forbidden.
+  $conf['order_by'].'
   LIMIT 0, '.$conf['top_number'].'
 ;';
@@ -276,70 +278,11 @@
     }
 // +-----------------------------------------------------------------------+
-// |                           calendar section                            |
-// +-----------------------------------------------------------------------+
-    else if ($page['cat'] == 'calendar')
-    {
-      $page['cat_nb_images'] = 0;
-      $page['title'] = $lang['calendar'];
-      if (isset($_GET['year'])
-          and preg_match('/^\d+$/', $_GET['year']))
-      {
-        $page['calendar_year'] = (int)$_GET['year'];
-      }
-      if (isset($_GET['month'])
-          and preg_match('/^(\d+)\.(\d{2})$/', $_GET['month'], $matches))
-      {
-        $page['calendar_year'] = (int)$matches[1];
-        $page['calendar_month'] = (int)$matches[2];
-      }
-      if (isset($_GET['day'])
-          and preg_match('/^(\d+)\.(\d{2})\.(\d{2})$/',
-                         $_GET['day'],
-                         $matches))
-      {
-        $page['calendar_year'] = (int)$matches[1];
-        $page['calendar_month'] = (int)$matches[2];
-        $page['calendar_day'] = (int)$matches[3];
-      }
-      if (isset($page['calendar_year']))
-      {
-        $page['title'] .= ' (';
-        if (isset($page['calendar_day']))
-        {
-          if ($page['calendar_year'] >= 1970)
-          {
-            $unixdate = mktime(
-              0,
-              0,
-              0,
-              $page['calendar_month'],
-              $page['calendar_day'],
-              $page['calendar_year']
-              );
-            $page['title'].= $lang['day'][date("w", $unixdate)];
-          }
-          $page['title'].= ' '.$page['calendar_day'].', ';
-        }
-        if (isset($page['calendar_month']))
-        {
-          $page['title'] .= $lang['month'][$page['calendar_month']].' ';
-        }
-        $page['title'] .= $page['calendar_year'];
-        $page['title'] .= ')';
-      }
-        
-      $page['where'] = 'WHERE '.$conf['calendar_datefield'].' IS NOT NULL';
-      if (isset($forbidden))
-      {
-        $page['where'].= ' AND '.$forbidden;
-      }
-
-      $page['thumbnails_include'] = 'include/category_calendar.inc.php';
-    }
-// +-----------------------------------------------------------------------+
 // |                          best rated section                           |
 // +-----------------------------------------------------------------------+
     else if ($page['cat'] == 'best_rated')
     {
+      $page['super_order_by'] = true;
+      $conf['order_by'] = ' ORDER BY average_rate DESC, id ASC';
+
       $query ='
 SELECT DISTINCT(id)
@@ -347,6 +290,6 @@
     INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
   WHERE average_rate IS NOT NULL
-    AND '.$forbidden.'
-  ORDER BY average_rate DESC, id ASC
+    AND '.$forbidden.
+  $conf['order_by'].'
   LIMIT 0, '.$conf['top_number'].'
 ;';
Index: trunk/picture.php
===================================================================
--- trunk/picture.php	(revision 1050)
+++ trunk/picture.php	(revision 1051)
@@ -363,5 +363,13 @@
 }
 
-$url_up = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'];
+$url_up = PHPWG_ROOT_PATH.'category.php?';
+if ( isset($page['cat']) )
+{
+  $url_up .= 'cat='.$page['cat'];
+}
+elseif ( isset($_GET['calendar']) )
+{
+  $url_up .= 'calendar='.$_GET['calendar'];
+}
 
 $url_up_start = floor( $page['current_rank'] / $user['nb_image_page'] );
@@ -374,9 +382,9 @@
 if ( $page['cat'] == 'search' )
 {
-  $url_up.= "&amp;search=".$_GET['search'];
+  $url_up.= '&amp;search='.$_GET['search'];
 }
 if ( $page['cat'] == 'list' )
 {
-  $url_up.= "&amp;list=".$_GET['list'];
+  $url_up.= '&amp;list='.$_GET['list'];
 }
 
@@ -778,13 +786,15 @@
 if (!empty($picture['current']['date_creation']))
 {
-  $infos['INFO_CREATION_DATE'] =
-    // FIXME because of search engine partial rewrite, giving the author
-    // name threw GET is not supported anymore. This feature should come
-    // back later, with a better design (calendar view).
-//     '<a href="'.
-//       PHPWG_ROOT_PATH.'category.php?cat=search'.
-//       '&amp;search=date_creation:'.$picture['current']['date_creation']
-//       .'">'.format_date($picture['current']['date_creation']).'</a>';
-    format_date($picture['current']['date_creation']);
+  $val = format_date($picture['current']['date_creation']);
+  if ( $conf['calendar_datefield'] == 'date_creation' )
+  {
+    $infos['INFO_CREATION_DATE'] = '<a href="'.
+       PHPWG_ROOT_PATH.'category.php?calendar=c-'.
+       $picture['current']['date_creation'].'">'.$val.'</a>';
+  }
+  else
+  {
+     $infos['INFO_CREATION_DATE'] = $val;
+  }
 }
 else
@@ -794,17 +804,15 @@
 
 // date of availability
-$infos['INFO_AVAILABILITY_DATE'] =
-// FIXME because of search engine partial rewrite, giving the author
-// name threw GET is not supported anymore. This feature should come
-// back later, with a better design (calendar view).
-//
-//   '<a href="'.
-//     PHPWG_ROOT_PATH.'category.php?cat=search'.
-//     '&amp;search=date_available:'.
-//     substr($picture['current']['date_available'], 0, 10)
-//     .'">'.
-//   format_date($picture['current']['date_available'], 'mysql_datetime').
-//   '</a>';
-format_date($picture['current']['date_available'], 'mysql_datetime');
+$val = format_date($picture['current']['date_available'], 'mysql_datetime');
+if ( $conf['calendar_datefield'] == 'date_available' )
+{
+  $infos['INFO_AVAILABILITY_DATE'] = '<a href="'.
+     PHPWG_ROOT_PATH.'category.php?calendar=c-'.
+     substr($picture['current']['date_available'],0,10).'">'.$val.'</a>';
+}
+else
+{
+   $infos['INFO_AVAILABILITY_DATE'] = $val;
+}
 
 // size in pixels
Index: trunk/template/yoga/category.tpl
===================================================================
--- trunk/template/yoga/category.tpl	(revision 1050)
+++ trunk/template/yoga/category.tpl	(revision 1051)
@@ -132,5 +132,5 @@
       
       <!-- BEGIN calendar_view -->
-      <li><a href="{calendar_view.URL}" title="{lang:calendar}"><img src="{themeconf:icon_dir}/calendar.png" class="button" alt="{lang:calendar}"></a></li>
+      <li><a href="{calendar_view.URL}" title="{lang:calendar_hint}"><img src="{themeconf:icon_dir}/calendar.png" class="button" alt="{lang:calendar}"></a></li>
       <!-- END calendar_view -->
       <!-- BEGIN normal_view -->
@@ -144,10 +144,4 @@
     
 <!-- BEGIN calendar -->
-<div class="navigationBar">{calendar.YEARS_NAV_BAR}</div>
-<div class="navigationBar">{calendar.MONTHS_NAV_BAR}</div>
-<!-- END calendar -->
-
-<!-- BEGIN calendar -->
-
 <!-- BEGIN styles -->
 <div class="calendarStyles">Style: {calendar.styles.BAR}</div>
