Index: /extensions/community/admin_permissions.php
===================================================================
--- /extensions/community/admin_permissions.php	(revision 9509)
+++ /extensions/community/admin_permissions.php	(revision 9510)
@@ -32,4 +32,11 @@
 $admin_base_url = get_root_url().'admin.php?page=plugin-community-permissions';
 
+$who_options = array(
+  'any_visitor' => l10n('any visitor'),
+  'any_registered_user' => l10n('any registered user'),
+  'user' => l10n('a specific user'),
+  'group' => l10n('a group'),
+  );
+
 // +-----------------------------------------------------------------------+
 // | Check Access and exit when user status is not ok                      |
@@ -44,7 +51,5 @@
 if (isset($_POST['submit_add']))
 {
-  $who_options = array('any_visitor', 'any_registered_user', 'user', 'group');
-  
-  if (!in_array($_POST['who'], $who_options))
+  if (!in_array($_POST['who'], array_keys($who_options)))
   {
     die('hacking attempt: invalid "who" option');
@@ -66,5 +71,5 @@
   }
 
-  check_input_parameter('moderate', $_POST, false, '/^(true|false)$/');
+  check_input_parameter('moderated', $_POST, false, '/^(true|false)$/');
 
   // creating the permission
@@ -76,17 +81,44 @@
     'recursive' => isset($_POST['recursive']) ? 'true' : 'false',
     'create_subcategories' => isset($_POST['create_subcategories']) ? 'true' : 'false',
-    'moderated' => $_POST['moderate'],
+    'moderated' => $_POST['moderated'],
     );
-  
-  mass_inserts(
-    COMMUNITY_PERMISSIONS_TABLE,
-    array_keys($insert),
-    array($insert)
-    );
-  
-  array_push(
-    $page['infos'],
-    l10n('Permission added')
-    );
+
+  if (isset($_POST['edit']))
+  {
+    check_input_parameter('edit', $_POST, false, PATTERN_ID);
+
+    $insert['id'] = $_POST['edit'];
+
+    mass_updates(
+      COMMUNITY_PERMISSIONS_TABLE,
+      array(
+        'primary' => array('id'),
+        'update' => array_keys($insert),
+        ),
+      array($insert)
+      );
+
+    $page['highlight'] = $insert['id'];
+
+    array_push(
+      $page['infos'],
+      l10n('Permission updated')
+      );
+  }
+  else
+  {
+    mass_inserts(
+      COMMUNITY_PERMISSIONS_TABLE,
+      array_keys($insert),
+      array($insert)
+      );
+
+    $page['highlight'] = pwg_db_insert_id(COMMUNITY_PERMISSIONS_TABLE);
+  
+    array_push(
+      $page['infos'],
+      l10n('Permission added')
+      );
+  }
 
   conf_update_param('community_update', time());
@@ -128,4 +160,49 @@
 // +-----------------------------------------------------------------------+
 
+// edit mode?
+if (isset($_GET['edit']))
+{
+  check_input_parameter('edit', $_GET, false, PATTERN_ID);
+  
+  $query = '
+SELECT
+    *
+  FROM '.COMMUNITY_PERMISSIONS_TABLE.'
+  WHERE id = '.$_GET['edit'].'
+;';
+  $result = pwg_query($query);
+  $row = pwg_db_fetch_assoc($result);
+
+  if (isset($row['id']))
+  {
+    $template->assign(
+      array(
+        'edit' => $row['id'],
+        'who_options_selected' => $row['type'],
+        'user_options_selected' => $row['user_id'],
+        'group_options_selected' => $row['group_id'],
+        'category_options_selected' => $row['category_id'],
+        'recursive' => get_boolean($row['recursive']),
+        'create_subcategories' => get_boolean($row['create_subcategories']),
+        'moderated' => get_boolean($row['moderated']),
+        )
+      );
+  }
+}
+else
+{
+  $template->assign(
+    array(
+      'moderated' => true,
+      )
+    );
+}
+
+// who options
+$template->assign(
+  array(
+    'who_options' => $who_options,
+    )
+  );
 
 // list of users
@@ -322,4 +399,15 @@
     $trust_tooltip = l10n('uploaded photos are directly displayed in the gallery');
   }
+
+  $highlight = false;
+  if (isset($_GET['edit']) and $permission['id'] == $_GET['edit'])
+  {
+    $highlight = true;
+  }
+  if (isset($page['highlight']) and $permission['id'] == $page['highlight'])
+  {
+    $highlight = true;
+  }
+  
   
   $template->append(
@@ -333,5 +421,7 @@
       'RECURSIVE_TOOLTIP' => l10n('Apply to sub-albums'),
       'CREATE_SUBCATEGORIES' => get_boolean($permission['create_subcategories']),
-      'U_DELETE' => $admin_base_url.'&amp;delete='.$permission['id']
+      'U_DELETE' => $admin_base_url.'&amp;delete='.$permission['id'],
+      'U_EDIT' => $admin_base_url.'&amp;edit='.$permission['id'],
+      'HIGHLIGHT' => $highlight,
       )
     );
Index: /extensions/community/admin_permissions.tpl
===================================================================
--- /extensions/community/admin_permissions.tpl	(revision 9509)
+++ /extensions/community/admin_permissions.tpl	(revision 9510)
@@ -2,4 +2,8 @@
 <style>
 form fieldset p {text-align:left;margin:0 0 1.5em 0;line-height:20px;}
+.permissionActions {text-align:center;height:20px}
+.permissionActions a:hover {border:none}
+.permissionActions img {margin-bottom:-2px}
+.rowSelected {background-color:#C2F5C2 !important}
 </style>
 {/literal}
@@ -56,9 +60,11 @@
 </div>
 
+{if not isset($edit)}
 <a id="displayForm" href="#">{'Add a permission'|@translate}</a>
+{/if}
 
-<form method="post" name="add_permission" action="{$F_ADD_ACTION}" class="properties" style="display:none">
+<form method="post" name="add_permission" action="{$F_ADD_ACTION}" class="properties" {if not isset($edit)}style="display:none"{/if}>
   <fieldset>
-    <legend>{'Add a permission'|@translate}</legend>
+    <legend>{if isset($edit)}{'Edit a permission'|@translate}{else}{'Add a permission'|@translate}{/if}</legend>
 
     <p>
@@ -66,15 +72,12 @@
       <br>
       <select name="who">
-        <option value="any_visitor">{'any visitor'|@translate}</option>
-        <option value="any_registered_user">{'any registered user'|@translate}</option>
-        <option value="user">{'a specific user'|@translate}</option>
-        <option value="group">{'a group'|@translate}</option>
+{html_options options=$who_options selected=$who_options_selected}
       </select>
 
-      <select name="who_user" style="display:none">
+      <select name="who_user" {if not isset($user_options_selected)}style="display:none"{/if}>
 {html_options options=$user_options selected=$user_options_selected}
       </select>
 
-      <select name="who_group" style="display:none">
+      <select name="who_group" {if not isset($group_options_selected)}style="display:none"{/if}>
 {html_options options=$group_options selected=$group_options_selected}
       </select>
@@ -85,22 +88,27 @@
       <br>
       <select class="categoryDropDown" name="category">
-        <option value="0">{'The whole gallery'|@translate}</option>
+        <option value="0" {if not isset($category_options_selected)}selected="selected"{/if}>{'The whole gallery'|@translate}</option>
         <option disabled="disabled">------------</option>
         {html_options options=$category_options selected=$category_options_selected}
       </select>
       <br>
-      <label><input type="checkbox" name="recursive" checked="checked"> {'Apply to sub-albums'|@translate}</label>
+      <label><input type="checkbox" name="recursive" {if $recursive}checked="checked"{/if}> {'Apply to sub-albums'|@translate}</label>
       <br>
-      <label><input type="checkbox" name="create_subcategories"> {'ability to create sub-albums'|@translate}</label>
+      <label><input type="checkbox" name="create_subcategories" {if $create_subcategories}checked="checked"{/if}> {'ability to create sub-albums'|@translate}</label>
     </p>
 
     <p>
       <strong>{'Which level of trust?'|@translate}</strong>
-      <br><label><input type="radio" name="moderate" value="true" checked="checked"> <em>{'low trust'|@translate}</em> : {'uploaded photos must be validated by an administrator'|@translate}</label>
-      <br><label><input type="radio" name="moderate" value="false"> <em>{'high trust'|@translate}</em> : {'uploaded photos are directly displayed in the gallery'|@translate}</label>
+      <br><label><input type="radio" name="moderated" value="true" {if $moderated}checked="checked"{/if}> <em>{'low trust'|@translate}</em> : {'uploaded photos must be validated by an administrator'|@translate}</label>
+      <br><label><input type="radio" name="moderated" value="false" {if not $moderated}checked="checked"{/if}> <em>{'high trust'|@translate}</em> : {'uploaded photos are directly displayed in the gallery'|@translate}</label>
     </p>
+
+    {if isset($edit)}
+      <input type="hidden" name="edit" value="{$edit}">
+    {/if}
     
     <p style="margin:0;">
-      <input class="submit" type="submit" name="submit_add" value="{'Add'|@translate}"/>
+      <input class="submit" type="submit" name="submit_add" value="{if isset($edit)}{'Submit'|@translate}{else}{'Add'|@translate}{/if}"/>
+      <a href="{$F_ADD_ACTION}">{'Cancel'|@translate}</a>
     </p>
   </fieldset>
@@ -116,5 +124,5 @@
 {if not empty($permissions)}
   {foreach from=$permissions item=permission name=permission_loop}
-  <tr class="{if $smarty.foreach.permission_loop.index is odd}row1{else}row2{/if}">
+  <tr class="{if $smarty.foreach.permission_loop.index is odd}row1{else}row2{/if}{if $permission.HIGHLIGHT} rowSelected{/if}">
     <td>{$permission.WHO}</td>
     <td>{$permission.WHERE}</td>
@@ -128,7 +136,10 @@
     {/if}
     </td>
-    <td style="text-align:center;">
+    <td class="permissionActions">
+      <a href="{$permission.U_EDIT}">
+        <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/edit_s.png" alt="{'edit'|@translate}" title="{'edit'|@translate}" />
+      </a>
       <a href="{$permission.U_DELETE}" onclick="return confirm( document.getElementById('btn_delete').title + '\n\n' + '{'Are you sure?'|@translate|@escape:'javascript'}');">
-        <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/delete.png" class="button" style="border:none" id="btn_delete" alt="{'delete'|@translate}" title="{'delete'|@translate}" />
+        <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/delete.png" id="btn_delete" alt="{'delete'|@translate}" title="{'Delete permission'|@translate}" />
       </a>
     </td>
Index: /extensions/community/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/community/language/en_UK/plugin.lang.php	(revision 9509)
+++ /extensions/community/language/en_UK/plugin.lang.php	(revision 9510)
@@ -52,3 +52,7 @@
 
 $lang['No album, this photo is orphan'] = 'No album, this photo is orphan';
+
+$lang['Cancel'] = 'Cancel';
+$lang['Permission updated'] = 'Permission updated';
+$lang['Delete permission'] = 'Delete permission';
 ?>
Index: /extensions/community/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/community/language/fr_FR/plugin.lang.php	(revision 9509)
+++ /extensions/community/language/fr_FR/plugin.lang.php	(revision 9510)
@@ -54,3 +54,6 @@
 
 $lang['No album, this photo is orphan'] = 'Aucun album, cette photo est orpheline';
+$lang['Cancel'] = 'Annuler';
+$lang['Permission updated'] = 'Permission mise à jour';
+$lang['Delete permission'] = 'Supprimer la permission';
 ?>
