Index: extensions/BatchDownloader/admin/sets.php
===================================================================
--- extensions/BatchDownloader/admin/sets.php	(revision 16392)
+++ extensions/BatchDownloader/admin/sets.php	(revision 16400)
@@ -1,4 +1,133 @@
 <?php
 if (!defined('BATCH_DOWNLOAD_PATH')) die('Hacking attempt!');
+
+// actions
+if (isset($_GET['delete']))
+{
+  $BatchDownloader = new BatchDownloader($_GET['delete']);
+  $BatchDownloader->deleteLastArchive();
+  $BatchDownloader->clearImages();
+  pwg_query('DELETE FROM '.BATCH_DOWNLOAD_TSETS.' WHERE id = '.$_GET['delete'].';');
+}
+if (isset($_GET['cancel']))
+{
+  $BatchDownloader = new BatchDownloader($_GET['cancel']);
+  $BatchDownloader->deleteLastArchive();
+  $BatchDownloader->clearImages();
+  $BatchDownloader->updateParam('status', 'done');
+}
+
+
+// filter
+$where_clauses = array('1=1');
+$order_by = 'date_creation DESC, status DESC';
+
+if (isset($_POST['filter']))
+{
+  if (!empty($_POST['username']))
+  {
+    array_push($where_clauses, 'username LIKE "%'.$_POST['username'].'%"');
+  }
+  
+  if ($_POST['type'] != -1)
+  {
+    array_push($where_clauses, 'type = "'.$_POST['type'].'"');
+  }
+  
+  if ($_POST['status'] != -1)
+  {
+    array_push($where_clauses, 'status = "'.$_POST['status'].'"');
+  }
+  
+  $order_by = $_POST['order_by'].' '.$_POST['direction'];
+}
+
+
+// get sets
+$query = '
+SELECT 
+    s.id,
+    u.'.$conf['user_fields']['username'].' AS username
+  FROM '.BATCH_DOWNLOAD_TSETS.' AS s
+    INNER JOIN '.USERS_TABLE.' AS u
+    ON s.user_id = u.'.$conf['user_fields']['id'].'
+  WHERE
+    '.implode("\n    AND ", $where_clauses).'
+  ORDER BY '.$order_by.'
+;';
+$sets = simple_hash_from_query($query, 'id', 'username');
+
+foreach ($sets as $set_id => $username)
+{
+  $set = new BatchDownloader($set_id);
+  $template->append('sets', array_merge(
+    $set->getSetInfo(),
+    array(
+      'USERNAME' => $username,
+      'STATUS' => $set->getParam('status'),
+      'LAST_ZIP' => $set->getParam('last_zip'),
+      'U_DELETE' => BATCH_DOWNLOAD_ADMIN . '-sets&amp;delete='.$set->getParam('set_id'),
+      'U_CANCEL' => BATCH_DOWNLOAD_ADMIN . '-sets&amp;cancel='.$set->getParam('set_id'),
+    )
+    ));
+}
+
+
+// filter options
+$page['status_items'] = array(
+  -1 => '------------',
+  'new' => l10n('new'),
+  'download' => l10n('download'),
+  'done' => l10n('done'),
+  );
+
+$page['type_items'] = array(
+  -1 => '------------',
+  'calendar' => l10n('Calendar'),
+  'category' => l10n('Album'),
+  'flat' => l10n('Whole gallery'),
+  'tags' => l10n('Tags'),
+  'search' => l10n('Search'),
+  'favorites' => l10n('Favorites'),
+  'most_visited' => l10n('Most visited'),
+  'best_rated' => l10n('Best rated'),
+  'list' => l10n('Random'),
+  'recent_pics' => l10n('Recent photos'),
+  // 'selection' => l10n('Selection'),
+  );
+
+$page['order_by_items'] = array(
+  'date_creation' => l10n('Creation date'),
+  'total_size' => l10n('Total size'),
+  'nb_images' => l10n('Nb images'),
+  'nb_archives' => l10n('Nb archives'),
+  );
+
+$page['direction_items'] = array(
+  'DESC' => l10n('descending'),
+  'ASC' => l10n('ascending'),
+  );
+
+$template->assign('status_options', $page['status_items']);
+$template->assign('status_selected',
+    isset($_POST['status']) ? $_POST['status'] : '');
+
+$template->assign('type_options', $page['type_items']);
+$template->assign('type_selected',
+    isset($_POST['type']) ? $_POST['type'] : '');
+
+$template->assign('order_options', $page['order_by_items']);
+$template->assign('order_selected',
+    isset($_POST['order_by']) ? $_POST['order_by'] : '');
+
+$template->assign('direction_options', $page['direction_items']);
+$template->assign('direction_selected',
+    isset($_POST['direction']) ? $_POST['direction'] : '');
+
+
+$template->assign(array(
+  'F_USERNAME' => @htmlentities($_POST['username'], ENT_COMPAT, 'UTF-8'),
+  'F_FILTER_ACTION' => BATCH_DOWNLOAD_ADMIN . '-sets',
+  ));
 
 
Index: extensions/BatchDownloader/admin/template/sets.tpl
===================================================================
--- extensions/BatchDownloader/admin/template/sets.tpl	(revision 16392)
+++ extensions/BatchDownloader/admin/template/sets.tpl	(revision 16400)
@@ -5,8 +5,77 @@
 </div>
 
-<form method="post" action="" class="properties">
+<form class="filter" method="post" name="filter" action="{$F_FILTER_ACTION}">
 <fieldset>
-  <legend>{'TODO'|@translate}</legend>
+  <legend>{'Filter'|@translate}</legend>
+  <input type="hidden" name="page" value="user_list">
+
+  <label>{'Username'|@translate} <input type="text" name="username" value="{$F_USERNAME}"></label>
+
+  <label>
+  {'Set type'|@translate}
+  {html_options name=type options=$type_options selected=$type_selected}
+  </label>
   
+  <label>
+  {'Status'|@translate}
+  {html_options name=status options=$status_options selected=$status_selected}
+  </label>
+
+  <label>
+  {'Sort by'|@translate}
+  {html_options name=order_by options=$order_options selected=$order_selected}
+  </label>
+
+  <label>
+  {'Sort order'|@translate}
+  {html_options name=direction options=$direction_options selected=$direction_selected}
+  </label>
+
+  <label>
+  &nbsp;
+  <span><input class="submit" type="submit" name="filter" value="{'Submit'|@translate}"> <a href="{$F_FILTER_ACTION}">{'Reset'|@translate}</a></span>
+  </label>
+
 </fieldset>
+
 </form>
+
+<table class="table2" width="97%">
+  <thead>
+    <tr class="throw">
+      <td class="user">{'Username'|@translate}</td>
+      <td class="type">{'Set type'|@translate}</td>
+      <td class="date">{'Creation date'|@translate}</td>
+      <td class="size">{'Total size'|@translate}</td>
+      <td class="images">{'Nb images'|@translate}</td>
+      <td class="archives">{'Nb archives'|@translate}</td>
+      <td class="status">{'Status'|@translate}</td>
+      <td class="action">{'Actions'|@translate}</td>
+    </tr>
+  </thead>
+
+  {foreach from=$sets item=set name=sets_loop}
+  <tr class="{if $smarty.foreach.sets_loop.index is odd}row1{else}row2{/if}">
+    <td>{$set.USERNAME}</td>
+    <td>{$set.NAME}</td>
+    <td style="text-align:center;">{$set.DATE_CREATION}</td>
+    <td>{$set.TOTAL_SIZE} MB</td>
+    <td>{$set.NB_IMAGES}</td>
+    <td>{$set.NB_ARCHIVES}</td>
+    <td>
+      {$set.STATUS}
+      {if $set.STATUS == 'download'}({$set.LAST_ZIP}/{$set.NB_ARCHIVES}){/if}
+    </td>
+    <td style="padding-left:25px;">
+      <a href="{$set.U_DELETE}" title="{'Delete this set'|@translate}" onClick="return confirm('{'Are your sure?'|@translate}');"><img src="admin/themes/default/icon/delete.png"></a>
+      {if $set.STATUS != 'done'}<a href="{$set.U_CANCEL}" title="{'Cancel this set'|@translate}" onClick="return confirm('{'Are your sure?'|@translate}');"><img src="admin/themes/default/icon/permissions.png"></a>{/if}
+    </td>
+  </tr>
+  {/foreach}
+  
+  {if not $sets}
+  <tr class="row2">
+    <td colspan="8" style="text-align:center;font-style:italic;">{'No result'|@translate}</td>
+  </tr>
+  {/if}
+</table>
Index: extensions/BatchDownloader/admin/template/style.css
===================================================================
--- extensions/BatchDownloader/admin/template/style.css	(revision 16392)
+++ extensions/BatchDownloader/admin/template/style.css	(revision 16400)
@@ -18,2 +18,24 @@
   width:300px;
 }
+
+.table2 .action {
+  width:70px;
+}
+.table2 .user {
+  width:120px;
+}
+.table2 .date {
+  width:180px;
+}
+.table2 .size {
+  width:100px;
+}
+.table2 .images {
+  width:100px;
+}
+.table2 .archives {
+  width:110px;
+}
+.table2 .status {
+  width:100px;
+}
Index: extensions/BatchDownloader/include/BatchDownloader.class.php
===================================================================
--- extensions/BatchDownloader/include/BatchDownloader.class.php	(revision 16392)
+++ extensions/BatchDownloader/include/BatchDownloader.class.php	(revision 16400)
@@ -21,6 +21,7 @@
     $this->conf = $conf['batch_download'];
     $this->data = array(
+      'set_id' => 0,
       'user_id' => $user['id'],
-      'set_id' => 0,
+      'date_creation' => '0000-00-00 00:00:00',
       'type' => null,
       'type_id' => null,
@@ -28,4 +29,5 @@
       'last_zip' => 0,
       'nb_images' => 0,
+      'total_size' => 0,
       'status' => 'new',
       );
@@ -37,4 +39,5 @@
       $query = '
 SELECT
+    date_creation,
     type,
     type_id,
@@ -42,9 +45,10 @@
     last_zip,
     nb_images,
+    total_size,
     status
   FROM '.BATCH_DOWNLOAD_TSETS.'
   WHERE
-    user_id = '.$this->data['user_id'].'
-    AND id = '.$set_id.'
+    id = '.$set_id.'
+    '.(!is_admin() ? 'AND user_id = '.$this->data['user_id'] : null).'
 ;';
       $result = pwg_query($query);
@@ -54,4 +58,5 @@
         $this->data['set_id'] = $set_id;
         list(
+          $this->data['date_creation'],
           $this->data['type'], 
           $this->data['type_id'], 
@@ -59,4 +64,5 @@
           $this->data['last_zip'], 
           $this->data['nb_images'], 
+          $this->data['total_size'],
           $this->data['status']
           ) = pwg_db_fetch_row($result);
@@ -80,5 +86,5 @@
         $this->images = simple_hash_from_query($query, 'image_id', 'zip');
         
-        if (count($this->images) != $this->data['nb_images'])
+        if ( $this->data['status'] != 'done' and count($this->images) != $this->data['nb_images'] )
         {
           $this->updateParam('nb_images', count($this->images));
@@ -105,4 +111,5 @@
     last_zip,
     nb_images,
+    total_size,
     status
   ) 
@@ -115,4 +122,5 @@
     0,
     0,
+    0,
     "new"
   )
@@ -120,4 +128,7 @@
       pwg_query($query);
       $this->data['set_id'] = pwg_db_insert_id();
+      
+      $date = pwg_query('SELECT FROM_UNIXTIME(NOW());');
+      list($this->data['date_creation']) = pwg_db_fetch_row($date);
       
       if (!empty($images))
@@ -225,7 +236,7 @@
   
   /**
-   * clear
-   */
-  function clear($reset=true)
+   * clearImages
+   */
+  function clearImages()
   {
     $this->images = array();
@@ -236,11 +247,4 @@
 ;';
     pwg_query($query);
-    
-    if ($reset)
-    {
-      $this->updateParam('nb_zip', 0);
-      $this->updateParam('last_zip', 0);
-      $this->updateParam('nb_images', 0);
-    }
   }
   
@@ -259,4 +263,6 @@
   /**
    * createNextArchive
+   * @param: bool force all elements in one archive
+   * @return: string zip path or false
    */
   function createNextArchive($force_one_archive=false)
@@ -277,5 +283,5 @@
       {
         $images_ids = array_slice(array_keys($this->images), 0, $this->conf['max_elements']);
-        $this->clear(false);
+        $this->clearImages();
         $this->addImages($images_ids);
       }
@@ -283,5 +289,5 @@
       $this->getEstimatedArchiveNumber();
       
-      pwg_query('UPDATE '.BATCH_DOWNLOAD_TSETS.' SET date_creation = NOW() WHERE id = '.$this->data['set_id'].';');
+      $this->updateParam('date_creation', date('Y-m-d H:i:s'));
     }
     
@@ -332,4 +338,6 @@
       }
       
+      $this->updateParam('total_size', $this->data['total_size'] + $total_size);
+      
       // archive comment
       global $conf;
@@ -358,5 +366,4 @@
       {
         $this->updateParam('status', 'done');
-        $this->clear(false);
       }
       
@@ -386,4 +393,5 @@
   function getEstimatedTotalSize()
   {
+    if ($this->data['status'] == 'done') return $this->data['total_size'];
     if ($this->data['nb_images'] == 0) return 0;
     
@@ -416,34 +424,25 @@
   function getDownloadList($url='')
   {
-    $nb_archives = $this->getEstimatedArchiveNumber();
-    
     $out = '';
-    /*if ($this->data['status'] == 'done')
-    {
-      $out.= '<li id="zip-1">Already downloaded</li>';
-    }*/
-    if (true)
-    {
-      for ($i=1; $i<=$this->data['nb_zip']; $i++)
-      {
-        $out.= '<li id="zip-'.$i.'">';
-        
-        if ($i < $this->data['last_zip']+1)
-        {
-          $out.= '<img src="'.BATCH_DOWNLOAD_PATH.'template/drive.png"> Archive #'.$i.' (already downloaded)';
-        }
-        else if ($i == $this->data['last_zip']+1)
-        {
-            $out.= '<a href="'.add_url_params($url, array('set_id'=>$this->data['set_id'],'zip'=>$i)).'" rel="nofollow" style="font-weight:bold;"' 
-              .($i!=1 ? 'onClick="return confirm(\'Starting download Archive #'.$i.' will destroy Archive #'.($i-1).', be sure you finish the download. Continue ?\');"' : null).
-              '><img src="'.BATCH_DOWNLOAD_PATH.'template/drive_go.png"> Archive #'.$i.' (ready)</a>';
-        }
-        else
-        {
-          $out.= '<img src="'.BATCH_DOWNLOAD_PATH.'template/drive.png"> Archive #'.$i.' (pending)';
-        }
-        
-        $out.= '</li>';
-      }
+    for ($i=1; $i<=$this->data['nb_zip']; $i++)
+    {
+      $out.= '<li id="zip-'.$i.'">';
+      
+      if ($i < $this->data['last_zip']+1)
+      {
+        $out.= '<img src="'.BATCH_DOWNLOAD_PATH.'template/drive.png"> Archive #'.$i.' (already downloaded)';
+      }
+      else if ($i == $this->data['last_zip']+1)
+      {
+          $out.= '<a href="'.add_url_params($url, array('set_id'=>$this->data['set_id'],'zip'=>$i)).'" rel="nofollow" style="font-weight:bold;"' 
+            .($i!=1 ? 'onClick="return confirm(\'Starting download Archive #'.$i.' will destroy Archive #'.($i-1).', be sure you finish the download. Continue ?\');"' : null).
+            '><img src="'.BATCH_DOWNLOAD_PATH.'template/drive_go.png"> Archive #'.$i.' (ready)</a>';
+      }
+      else
+      {
+        $out.= '<img src="'.BATCH_DOWNLOAD_PATH.'template/drive.png"> Archive #'.$i.' (pending)';
+      }
+      
+      $out.= '</li>';
     }
     
@@ -471,6 +470,6 @@
           get_username($this->data['user_id']) .'_'. 
           $this->data['type'] .'-'. $this->data['type_id'] .'_'.
-          $this->data['user_id'] . $this->data['set_id'] .'_'.
-          ($this->data['nb_zip']!=1 ? 'part'. $i : null).
+          $this->data['user_id'] . $this->data['set_id'] .
+          ($this->data['nb_zip']!=1 ? '_part'. $i : null).
           '.zip';
   }
@@ -487,4 +486,5 @@
       'TOTAL_SIZE' => ceil($this->getEstimatedTotalSize()/1024),
       'LINKS' => $this->getDownloadList(BATCH_DOWNLOAD_PUBLIC . 'init_zip'),
+      'DATE_CREATION' => format_date($this->data['date_creation'], true),
       );
         
@@ -496,11 +496,37 @@
     switch ($this->data['type'])
     {
+      // calendar
       case 'calendar':
       {
-        $set['NAME'] = l10n('Calendar');
-        $set['COMMENT'] = $this->data['type_id'];
-        break;
-      }
-      
+        global $conf, $page;
+        $old_page = $page;
+        
+        $fields = array(
+          'created' => l10n('Creation date'),
+          'posted' => l10n('Post date'),
+          );
+        
+        $chronology = explode('-', $this->data['type_id']);
+        $page['chronology_field'] = $chronology[0];
+        $page['chronology_style'] = $chronology[1];
+        $page['chronology_view'] = $chronology[2];
+        $page['chronology_date'] = array_splice($chronology, 3);
+        
+        if (!class_exists('Calendar'))
+        {
+          include_once(PHPWG_ROOT_PATH.'include/calendar_'. $page['chronology_style'] .'.class.php');
+        }
+        $calendar = new Calendar();
+        $calendar->initialize('');
+        $display_name = strip_tags($calendar->get_display_name());
+        
+        $set['NAME'] = l10n('Calendar').': '.$fields[$page['chronology_field']].$display_name;
+        $set['sNAME'] = l10n('Calendar').': '.ltrim($display_name, $conf['level_separator']);
+        
+        $page = $old_page;
+        break;
+      }
+      
+      // category
       case 'category':
       {
@@ -512,4 +538,5 @@
       }
       
+      // flat
       case 'flat':
       {
@@ -518,24 +545,24 @@
       }
       
+      // tags
       case 'tags':
       {
         $tags = find_tags(explode(',', $this->data['type_id']));
-        $set['NAME'] = l10n('Tags');
-        
-        $set['COMMENT'] = ''; $first = true;
+        $set['NAME'] = l10n('Tags').': ';
+        
+        $first = true;
         foreach ($tags as $tag)
         {
           if ($first) $first = false;
-          else $set['COMMENT'].= ', ';
-          $set['COMMENT'].=
+          else $set['NAME'].= ', ';
+          $set['NAME'].=
             '<a href="' . make_index_url(array('tags'=>array($tag))) . '">'
             .trigger_event('render_tag_name', $tag['name'])
             .'</a>';
         }
-        
-        $set['sNAME'] = l10n('Tags').': '.strip_tags($set['COMMENT']);
-        break;
-      }
-      
+        break;
+      }
+      
+      // search
       case 'search':
       {
@@ -544,4 +571,5 @@
       }
       
+      // favorites
       case 'favorites':
       {
@@ -550,4 +578,5 @@
       }
       
+      // most_visited
       case 'most_visited':
       {
@@ -556,4 +585,5 @@
       }
       
+      // best_rated
       case 'best_rated':
       {
@@ -562,4 +592,5 @@
       }
       
+      // list
       case 'list':
       {
@@ -568,4 +599,5 @@
       }
       
+      // recent_pics
       case 'recent_pics':
       {
@@ -574,4 +606,5 @@
       }
       
+      // selection
       // case 'selection':
       // {
@@ -582,5 +615,5 @@
     }
     
-    if (!isset($set['sNAME'])) $set['sNAME'] = $set['NAME'];
+    if (!isset($set['sNAME'])) $set['sNAME'] = strip_tags($set['NAME']);
     if (!isset($set['COMMENT'])) $set['COMMENT'] = null;
     
Index: extensions/BatchDownloader/include/download.inc.php
===================================================================
--- extensions/BatchDownloader/include/download.inc.php	(revision 16392)
+++ extensions/BatchDownloader/include/download.inc.php	(revision 16400)
@@ -18,5 +18,5 @@
     {
       $BatchDownloader->deleteLastArchive();
-      $BatchDownloader->clear();
+      $BatchDownloader->clearImages();
       pwg_query('DELETE FROM '.BATCH_DOWNLOAD_TSETS.' WHERE id = '.$_GET['set_id'].';');
       $_SESSION['page_infos'][] = l10n('Download set deleted');
Index: extensions/BatchDownloader/include/events.inc.php
===================================================================
--- extensions/BatchDownloader/include/events.inc.php	(revision 16392)
+++ extensions/BatchDownloader/include/events.inc.php	(revision 16400)
@@ -73,4 +73,5 @@
       $BatchDownloader->getEstimatedArchiveNumber();
       
+      // if we plan only one zip with less elements than 'max_elements', the download starts immediately
       if (
         $BatchDownloader->getParam('nb_images') <= $conf['batch_download']['max_elements']
@@ -78,5 +79,5 @@
       )
       {
-        $BatchDownloader->createNextArchive(true);
+        $BatchDownloader->createNextArchive(true); // make sure we have only one zip, even if 'max_size' is exceeded
         
         $u_download = BATCH_DOWNLOAD_PATH . 'download.php?set_id='.$BatchDownloader->getParam('set_id').'&amp;zip=1';
@@ -87,4 +88,5 @@
         array_push($page['infos'], sprintf(l10n('The archive is downloading, if the download doesn\'t start automatically please <a href="%s">click here</a>'), $u_download));
       }
+      // oterwise we go to summary page
       else
       {
@@ -190,5 +192,5 @@
     $BatchDownloader = new BatchDownloader($set_id);
     $BatchDownloader->deleteLastArchive();
-    $BatchDownloader->clear(false);
+    $BatchDownloader->clearImages();
     $BatchDownloader->updateParam('status', 'done');
   }
Index: extensions/BatchDownloader/include/functions.inc.php
===================================================================
--- extensions/BatchDownloader/include/functions.inc.php	(revision 16392)
+++ extensions/BatchDownloader/include/functions.inc.php	(revision 16400)
@@ -73,4 +73,5 @@
   global $user, $conf;
   
+  if (is_a_guest()) return false;
   if (is_admin()) return true;
   
Index: extensions/BatchDownloader/maintain.inc.php
===================================================================
--- extensions/BatchDownloader/maintain.inc.php	(revision 16392)
+++ extensions/BatchDownloader/maintain.inc.php	(revision 16400)
@@ -28,7 +28,8 @@
   `type` varchar(16) CHARACTER SET utf8 NOT NULL,
   `type_id` varchar(64) CHARACTER SET utf8 NOT NULL,
-  `nb_zip` smallint(2) NOT NULL DEFAULT 0,
-  `last_zip` smallint(2) NOT NULL DEFAULT 0,
+  `nb_zip` smallint(3) NOT NULL DEFAULT 0,
+  `last_zip` smallint(3) NOT NULL DEFAULT 0,
   `nb_images` mediumint(8) NOT NULL DEFAULT 0,
+  `total_size` int(10) NOT NULL DEFAULT 0,
   `status` enum("new","download","done") CHARACTER SET utf8 NOT NULL DEFAULT "new",
   PRIMARY KEY (`id`)
Index: extensions/BatchDownloader/template/init_zip.tpl
===================================================================
--- extensions/BatchDownloader/template/init_zip.tpl	(revision 16392)
+++ extensions/BatchDownloader/template/init_zip.tpl	(revision 16400)
@@ -30,4 +30,5 @@
     <li><b>{'Estimated size'|@translate}:</b> {$set.TOTAL_SIZE} MB</li>
     <li><b>{'Estimated number of archives'|@translate}:</b> {$set.NB_ARCHIVES} <i>({'real number of archives can differ'|@translate})</i></li>
+    <li><b>{'Created on'|@translate}:</b> {$set.DATE_CREATION}</li>
   </ul>
   
