Index: /trunk/admin/album.php
===================================================================
--- /trunk/admin/album.php	(revision 13579)
+++ /trunk/admin/album.php	(revision 13580)
@@ -44,4 +44,9 @@
 $category = pwg_db_fetch_assoc(pwg_query($query));
 
+if (!isset($category['id']))
+{
+  die("unknown album");
+}
+
 // +-----------------------------------------------------------------------+
 // | Tabs                                                                  |
@@ -60,10 +65,5 @@
 $tabsheet->add('properties', l10n('Properties'), $admin_album_base_url.'-properties');
 $tabsheet->add('sort_order', l10n('Manage photo ranks'), $admin_album_base_url.'-sort_order');
-
-if ('private' == $category['status'])
-{
-  $tabsheet->add('permissions', l10n('Permissions'), $admin_album_base_url.'-permissions');
-}
-
+$tabsheet->add('permissions', l10n('Permissions'), $admin_album_base_url.'-permissions');
 $tabsheet->select($page['tab']);
 $tabsheet->assign();
Index: /trunk/admin/cat_modify.php
===================================================================
--- /trunk/admin/cat_modify.php	(revision 13579)
+++ /trunk/admin/cat_modify.php	(revision 13580)
@@ -145,8 +145,4 @@
     set_cat_visible(array($_GET['cat_id']), $_POST['visible']);
   }
-  if ($cat_info['status'] != $_POST['status'] )
-  {
-    set_cat_status(array($_GET['cat_id']), $_POST['status']);
-  }
 
   // in case the use moves his album to the gallery root, we force
@@ -164,8 +160,5 @@
   }
 
-  // we redirect to hide/show the "permissions" tab if the category status
-  // has changed
-  $_SESSION['page_infos'] = array(l10n('Album updated successfully'));
-  redirect($admin_album_base_url);
+  array_push($page['infos'], l10n('Album updated successfully'));
 }
 elseif (isset($_POST['set_random_representant']))
@@ -227,8 +220,4 @@
     'CAT_NAME'           => @htmlspecialchars($category['name']),
     'CAT_COMMENT'        => @htmlspecialchars($category['comment']),
-
-    'status_values'     => array('public','private'),
-
-    'CAT_STATUS'        => $category['status'],
     'CAT_VISIBLE'       => boolean_to_string($category['visible']),
 
Index: /trunk/admin/cat_perm.php
===================================================================
--- /trunk/admin/cat_perm.php	(revision 13579)
+++ /trunk/admin/cat_perm.php	(revision 13580)
@@ -38,120 +38,158 @@
 // +-----------------------------------------------------------------------+
 
-// if the category is not correct (not numeric, not private)
-if (isset($_GET['cat']) and is_numeric($_GET['cat']))
+$page['cat'] = $category['id'];
+
+// +-----------------------------------------------------------------------+
+// |                           form submission                             |
+// +-----------------------------------------------------------------------+
+
+if (!empty($_POST))
 {
-  $query = '
-SELECT status
-  FROM '.CATEGORIES_TABLE.'
-  WHERE id = '.$_GET['cat'].'
-;';
-  list($status) = pwg_db_fetch_row(pwg_query($query));
-  
-  if ('private' == $status)
-  {
-    $page['cat'] = $_GET['cat'];
-  }
-}
-
-if (!isset($page['cat']))
-{
-  $query = '
+  check_pwg_token();
+
+  if ($category['status'] != $_POST['status'])
+  {
+    set_cat_status(array($page['cat']), $_POST['status']);
+    $category['status'] = $_POST['status'];
+  }
+
+  if ('private' == $_POST['status'])
+  {
+    //
+    // manage groups
+    //
+    $query = '
+SELECT group_id
+  FROM '.GROUP_ACCESS_TABLE.'
+  WHERE cat_id = '.$page['cat'].'
+;';
+    $groups_granted = array_from_query($query, 'group_id');
+
+    if (!isset($_POST['groups']))
+    {
+      $_POST['groups'] = array();
+    }
+    
+    //
+    // remove permissions to groups
+    //
+    $deny_groups = array_diff($groups_granted, $_POST['groups']);
+    if (count($deny_groups) > 0)
+    {
+      // if you forbid access to an album, all sub-albums become
+      // automatically forbidden
+      $query = '
+DELETE
+  FROM '.GROUP_ACCESS_TABLE.'
+  WHERE group_id IN ('.implode(',', $deny_groups).')
+    AND cat_id IN ('.implode(',', get_subcat_ids(array($page['cat']))).')
+;';
+      pwg_query($query);
+    }
+
+    //
+    // add permissions to groups
+    //
+    $grant_groups = array_diff($_POST['groups'], $groups_granted);
+    if (count($grant_groups) > 0)
+    {
+      $cat_ids = get_uppercat_ids(array($page['cat']));
+      if (isset($_POST['apply_on_sub']))
+      {
+        $cat_ids = array_merge($cat_ids, get_subcat_ids(array($page['cat'])));
+      }
+      
+      $query = '
 SELECT id
   FROM '.CATEGORIES_TABLE.'
-  WHERE status = \'private\'
-  LIMIT 1
-;';
-
-  list($page['cat']) = pwg_db_fetch_row(pwg_query($query));
-}
-
-// +-----------------------------------------------------------------------+
-// |                           form submission                             |
-// +-----------------------------------------------------------------------+
-if (isset($_POST['deny_groups_submit']) or isset($_POST['grant_groups_submit']) or isset($_POST['deny_users_submit']) or isset($_POST['grant_users_submit']) )
-{
-  check_pwg_token();
-}
-
-if (isset($_POST['deny_groups_submit'])
-         and isset($_POST['deny_groups'])
-         and count($_POST['deny_groups']) > 0)
-{
-  // if you forbid access to a category, all sub-categories become
-  // automatically forbidden
-  $query = '
-DELETE
-  FROM '.GROUP_ACCESS_TABLE.'
-  WHERE group_id IN ('.implode(',', $_POST['deny_groups']).')
-    AND cat_id IN ('.implode(',', get_subcat_ids(array($page['cat']))).')
-;';
-  pwg_query($query);
-}
-else if (isset($_POST['grant_groups_submit'])
-         and isset($_POST['grant_groups'])
-         and count($_POST['grant_groups']) > 0)
-{
-  $cat_ids = (isset($_POST['apply_on_sub'])) ? implode(',', get_subcat_ids(array($page['cat']))).",".implode(',', get_uppercat_ids(array($page['cat']))) : implode(',', get_uppercat_ids(array($page['cat'])));
-
-  $query = '
-SELECT id
-  FROM '.CATEGORIES_TABLE.'
-  WHERE id IN ('.$cat_ids.')
-  AND status = \'private\'
-;';
-  $private_cats = array_from_query($query, 'id');
-
-  // We must not reinsert already existing lines in group_access table
-  $granteds = array();
-  foreach ($private_cats as $cat_id)
-  {
-    $granteds[$cat_id] = array();
-  }
+  WHERE id IN ('.implode(',', $cat_ids).')
+    AND status = \'private\'
+;';
+      $private_cats = array_from_query($query, 'id');
+
+      // We must not reinsert already existing lines in group_access table
+      $granteds = array();
+      foreach ($private_cats as $cat_id)
+      {
+        $granteds[$cat_id] = array();
+      }
   
-  $query = '
-SELECT group_id, cat_id
+      $query = '
+SELECT
+    group_id,
+    cat_id
   FROM '.GROUP_ACCESS_TABLE.'
   WHERE cat_id IN ('.implode(',', $private_cats).')
-    AND group_id IN ('.implode(',', $_POST['grant_groups']).')
-;';
-  $result = pwg_query($query);
-  while ($row = pwg_db_fetch_assoc($result))
-  {
-    array_push($granteds[$row['cat_id']], $row['group_id']);
-  }
-
-  $inserts = array();
-  
-  foreach ($private_cats as $cat_id)
-  {
-    $group_ids = array_diff($_POST['grant_groups'], $granteds[$cat_id]);
-    foreach ($group_ids as $group_id)
-    {
-      array_push($inserts, array('group_id' => $group_id,
-                                 'cat_id' => $cat_id));
-    }
-  }
-
-  mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $inserts);
-}
-else if (isset($_POST['deny_users_submit'])
-         and isset($_POST['deny_users'])
-         and count($_POST['deny_users']) > 0)
-{
-  // if you forbid access to a category, all sub-categories become
-  // automatically forbidden
-  $query = '
+    AND group_id IN ('.implode(',', $grant_groups).')
+;';
+      $result = pwg_query($query);
+      while ($row = pwg_db_fetch_assoc($result))
+      {
+        array_push($granteds[$row['cat_id']], $row['group_id']);
+      }
+
+      $inserts = array();
+      
+      foreach ($private_cats as $cat_id)
+      {
+        $group_ids = array_diff($grant_groups, $granteds[$cat_id]);
+        foreach ($group_ids as $group_id)
+        {
+          array_push(
+            $inserts,
+            array(
+              'group_id' => $group_id,
+              'cat_id' => $cat_id
+              )
+            );
+        }
+      }
+
+      mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $inserts);
+    }
+
+    //
+    // users
+    //
+    $query = '
+SELECT user_id
+  FROM '.USER_ACCESS_TABLE.'
+  WHERE cat_id = '.$page['cat'].'
+;';
+    $users_granted = array_from_query($query, 'user_id');
+
+    if (!isset($_POST['users']))
+    {
+      $_POST['users'] = array();
+    }
+    
+    //
+    // remove permissions to users
+    //
+    $deny_users = array_diff($users_granted, $_POST['users']);
+    if (count($deny_users) > 0)
+    {
+      // if you forbid access to an album, all sub-album become automatically
+      // forbidden
+      $query = '
 DELETE
   FROM '.USER_ACCESS_TABLE.'
-  WHERE user_id IN ('.implode(',', $_POST['deny_users']).')
+  WHERE user_id IN ('.implode(',', $deny_users).')
     AND cat_id IN ('.implode(',', get_subcat_ids(array($page['cat']))).')
 ;';
-  pwg_query($query);
-}
-else if (isset($_POST['grant_users_submit'])
-         and isset($_POST['grant_users'])
-         and count($_POST['grant_users']) > 0)
-{
-  add_permission_on_category($page['cat'], $_POST['grant_users']);
+      pwg_query($query);
+    }
+
+    //
+    // add permissions to users
+    //
+    $grant_users = array_diff($_POST['users'], $users_granted);
+    if (count($grant_users) > 0)
+    {
+      add_permission_on_category($page['cat'], $grant_users);
+    }
+  }
+
+  array_push($page['infos'], l10n('Album updated successfully'));
 }
 
@@ -171,4 +209,5 @@
     'U_HELP' => get_root_url().'admin/popuphelp.php?page=cat_perm',
     'F_ACTION' => $admin_album_base_url.'-permissions',
+    'private' => ('private' == $category['status']),
     )
   );
@@ -189,5 +228,5 @@
 ;';
 $groups = simple_hash_from_query($query, 'id', 'name');
-$template->assign('all_groups', $groups);
+$template->assign('groups', $groups);
 
 // groups granted to access the category
@@ -198,12 +237,5 @@
 ;';
 $group_granted_ids = array_from_query($query, 'group_id');
-$group_granted_ids = order_by_name($group_granted_ids, $groups);
-$template->assign('group_granted_ids', $group_granted_ids);
-
-
-// groups denied
-$template->assign('group_denied_ids',
-    order_by_name(array_diff(array_keys($groups), $group_granted_ids), $groups)
-  );
+$template->assign('groups_selected', $group_granted_ids);
 
 // users...
@@ -216,5 +248,5 @@
 ;';
 $users = simple_hash_from_query($query, 'id', 'username');
-$template->assign('all_users', $users);
+$template->assign('users', $users);
 
 
@@ -225,7 +257,5 @@
 ;';
 $user_granted_direct_ids = array_from_query($query, 'user_id');
-$user_granted_direct_ids = order_by_name($user_granted_direct_ids, $users);
-$template->assign('user_granted_direct_ids', $user_granted_direct_ids);
-
+$template->assign('users_selected', $user_granted_direct_ids);
 
 
@@ -283,11 +313,4 @@
 }
 
-$user_denied_ids = array_diff(array_keys($users),
-                              $user_granted_indirect_ids,
-                              $user_granted_direct_ids);
-$user_denied_ids = order_by_name($user_denied_ids, $users);
-$template->assign('user_denied_ids', $user_denied_ids);
-
-
 // +-----------------------------------------------------------------------+
 // |                           sending html code                           |
Index: /trunk/admin/themes/default/template/cat_modify.tpl
===================================================================
--- /trunk/admin/themes/default/template/cat_modify.tpl	(revision 13579)
+++ /trunk/admin/themes/default/template/cat_modify.tpl	(revision 13580)
@@ -82,10 +82,4 @@
 
   <p>
-    <strong>{'Access type'|@translate}</strong>
-    <br>
-    {html_radios name='status' values=$status_values output=$status_values|translate selected=$CAT_STATUS}
-  </p>
-
-  <p>
     <strong>{'Lock'|@translate}</strong>
     <br>
Index: /trunk/admin/themes/default/template/cat_perm.tpl
===================================================================
--- /trunk/admin/themes/default/template/cat_perm.tpl	(revision 13579)
+++ /trunk/admin/themes/default/template/cat_perm.tpl	(revision 13580)
@@ -1,2 +1,25 @@
+{combine_script id='jquery.chosen' load='footer' path='themes/default/js/plugins/chosen.jquery.min.js'}
+{combine_css path="themes/default/js/plugins/chosen.css"}
+
+{footer_script}{literal}
+jQuery(document).ready(function() {
+  jQuery(".chzn-select").chosen();
+
+  function checkStatusOptions() {
+    if (jQuery("input[name=status]:checked").val() == "private") {
+      jQuery("#privateOptions, #applytoSubAction").show();
+    }
+    else {
+      jQuery("#privateOptions, #applytoSubAction").hide();
+    }
+  }
+
+  checkStatusOptions();
+  jQuery("#selectStatus").change(function() {
+    checkStatusOptions();
+  });
+});
+{/literal}{/footer_script}
+
 <div class="titrePage">
   <h2><span style="letter-spacing:0">{$CATEGORIES_NAV}</span> &#8250; {'Edit album'|@translate} {$TABSHEET_TITLE}</h2>
@@ -5,4 +28,34 @@
 <form action="{$F_ACTION}" method="post" id="categoryPermissions">
 
+<fieldset>
+  <legend>{'Access type'|@translate}</legend>
+
+  <p id="selectStatus">
+    <label><input type="radio" name="status" value="public" {if not $private}checked="checked"{/if}> <strong>{'public'|@translate}</strong> : <em>{'any visitor can see this album'|@translate}</em></label>
+    <br>
+    <label><input type="radio" name="status" value="private" {if $private}checked="checked"{/if}> <strong>{'private'|@translate}</strong> : <em>{'visitors need to login and have the appropriate permissions to see this album'|@translate}</em></label>
+  </p>
+</fieldset>
+
+<fieldset id="privateOptions">
+  <legend>{'Groups and users'|@translate}</legend>
+
+  <p>
+    <strong>{'Permission granted for groups'|@translate}</strong>
+    <br>
+    <select data-placeholder="{'Select groups...'|@translate}" class="chzn-select" multiple style="width:700px;" name="groups[]">
+      {html_options options=$groups selected=$groups_selected}
+    </select>
+  </p>
+
+  <p>
+    <strong>{'Permission granted for users'|@translate}</strong>
+    <br>
+    <select data-placeholder="{'Select users...'|@translate}" class="chzn-select" multiple style="width:700px;" name="users[]">
+      {html_options options=$users selected=$users_selected}
+    </select>
+  </p>
+
+{*
   <h4>{'Groups'|@translate}</h4>
 
@@ -61,4 +114,11 @@
     <label><input type="checkbox" name="apply_on_sub">{'Apply to sub-albums'|@translate}</label>
   </fieldset>
+*}
+</fieldset>
+
+  <p style="margin:12px;text-align:left;">
+    <input class="submit" type="submit" value="{'Save Settings'|@translate}" name="submit">
+    <label id="applytoSubAction" style="display:none;"><input type="checkbox" name="apply_on_sub">{'Apply to sub-albums'|@translate}</label>
+  </p>
 
 <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
Index: /trunk/admin/themes/default/theme.css
===================================================================
--- /trunk/admin/themes/default/theme.css	(revision 13579)
+++ /trunk/admin/themes/default/theme.css	(revision 13580)
@@ -243,9 +243,4 @@
 TABLE.doubleSelect SELECT.categoryList {
 	width: 100%; max-width: 100%; overflow-x: auto;
-}
-
-FORM#categoryPermissions LI {
-	display:inline;
-	white-space: nowrap;
 }
 
