Changeset 9510 for extensions


Ignore:
Timestamp:
Mar 4, 2011, 9:18:39 AM (13 years ago)
Author:
plg
Message:

edit a permission

Location:
extensions/community
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/community/admin_permissions.php

    r9501 r9510  
    3232$admin_base_url = get_root_url().'admin.php?page=plugin-community-permissions';
    3333
     34$who_options = array(
     35  'any_visitor' => l10n('any visitor'),
     36  'any_registered_user' => l10n('any registered user'),
     37  'user' => l10n('a specific user'),
     38  'group' => l10n('a group'),
     39  );
     40
    3441// +-----------------------------------------------------------------------+
    3542// | Check Access and exit when user status is not ok                      |
     
    4451if (isset($_POST['submit_add']))
    4552{
    46   $who_options = array('any_visitor', 'any_registered_user', 'user', 'group');
    47  
    48   if (!in_array($_POST['who'], $who_options))
     53  if (!in_array($_POST['who'], array_keys($who_options)))
    4954  {
    5055    die('hacking attempt: invalid "who" option');
     
    6671  }
    6772
    68   check_input_parameter('moderate', $_POST, false, '/^(true|false)$/');
     73  check_input_parameter('moderated', $_POST, false, '/^(true|false)$/');
    6974
    7075  // creating the permission
     
    7681    'recursive' => isset($_POST['recursive']) ? 'true' : 'false',
    7782    'create_subcategories' => isset($_POST['create_subcategories']) ? 'true' : 'false',
    78     'moderated' => $_POST['moderate'],
     83    'moderated' => $_POST['moderated'],
    7984    );
    80  
    81   mass_inserts(
    82     COMMUNITY_PERMISSIONS_TABLE,
    83     array_keys($insert),
    84     array($insert)
    85     );
    86  
    87   array_push(
    88     $page['infos'],
    89     l10n('Permission added')
    90     );
     85
     86  if (isset($_POST['edit']))
     87  {
     88    check_input_parameter('edit', $_POST, false, PATTERN_ID);
     89
     90    $insert['id'] = $_POST['edit'];
     91
     92    mass_updates(
     93      COMMUNITY_PERMISSIONS_TABLE,
     94      array(
     95        'primary' => array('id'),
     96        'update' => array_keys($insert),
     97        ),
     98      array($insert)
     99      );
     100
     101    $page['highlight'] = $insert['id'];
     102
     103    array_push(
     104      $page['infos'],
     105      l10n('Permission updated')
     106      );
     107  }
     108  else
     109  {
     110    mass_inserts(
     111      COMMUNITY_PERMISSIONS_TABLE,
     112      array_keys($insert),
     113      array($insert)
     114      );
     115
     116    $page['highlight'] = pwg_db_insert_id(COMMUNITY_PERMISSIONS_TABLE);
     117 
     118    array_push(
     119      $page['infos'],
     120      l10n('Permission added')
     121      );
     122  }
    91123
    92124  conf_update_param('community_update', time());
     
    128160// +-----------------------------------------------------------------------+
    129161
     162// edit mode?
     163if (isset($_GET['edit']))
     164{
     165  check_input_parameter('edit', $_GET, false, PATTERN_ID);
     166 
     167  $query = '
     168SELECT
     169    *
     170  FROM '.COMMUNITY_PERMISSIONS_TABLE.'
     171  WHERE id = '.$_GET['edit'].'
     172;';
     173  $result = pwg_query($query);
     174  $row = pwg_db_fetch_assoc($result);
     175
     176  if (isset($row['id']))
     177  {
     178    $template->assign(
     179      array(
     180        'edit' => $row['id'],
     181        'who_options_selected' => $row['type'],
     182        'user_options_selected' => $row['user_id'],
     183        'group_options_selected' => $row['group_id'],
     184        'category_options_selected' => $row['category_id'],
     185        'recursive' => get_boolean($row['recursive']),
     186        'create_subcategories' => get_boolean($row['create_subcategories']),
     187        'moderated' => get_boolean($row['moderated']),
     188        )
     189      );
     190  }
     191}
     192else
     193{
     194  $template->assign(
     195    array(
     196      'moderated' => true,
     197      )
     198    );
     199}
     200
     201// who options
     202$template->assign(
     203  array(
     204    'who_options' => $who_options,
     205    )
     206  );
    130207
    131208// list of users
     
    322399    $trust_tooltip = l10n('uploaded photos are directly displayed in the gallery');
    323400  }
     401
     402  $highlight = false;
     403  if (isset($_GET['edit']) and $permission['id'] == $_GET['edit'])
     404  {
     405    $highlight = true;
     406  }
     407  if (isset($page['highlight']) and $permission['id'] == $page['highlight'])
     408  {
     409    $highlight = true;
     410  }
     411 
    324412 
    325413  $template->append(
     
    333421      'RECURSIVE_TOOLTIP' => l10n('Apply to sub-albums'),
    334422      'CREATE_SUBCATEGORIES' => get_boolean($permission['create_subcategories']),
    335       'U_DELETE' => $admin_base_url.'&delete='.$permission['id']
     423      'U_DELETE' => $admin_base_url.'&delete='.$permission['id'],
     424      'U_EDIT' => $admin_base_url.'&edit='.$permission['id'],
     425      'HIGHLIGHT' => $highlight,
    336426      )
    337427    );
  • extensions/community/admin_permissions.tpl

    r9500 r9510  
    22<style>
    33form fieldset p {text-align:left;margin:0 0 1.5em 0;line-height:20px;}
     4.permissionActions {text-align:center;height:20px}
     5.permissionActions a:hover {border:none}
     6.permissionActions img {margin-bottom:-2px}
     7.rowSelected {background-color:#C2F5C2 !important}
    48</style>
    59{/literal}
     
    5660</div>
    5761
     62{if not isset($edit)}
    5863<a id="displayForm" href="#">{'Add a permission'|@translate}</a>
     64{/if}
    5965
    60 <form method="post" name="add_permission" action="{$F_ADD_ACTION}" class="properties" style="display:none">
     66<form method="post" name="add_permission" action="{$F_ADD_ACTION}" class="properties" {if not isset($edit)}style="display:none"{/if}>
    6167  <fieldset>
    62     <legend>{'Add a permission'|@translate}</legend>
     68    <legend>{if isset($edit)}{'Edit a permission'|@translate}{else}{'Add a permission'|@translate}{/if}</legend>
    6369
    6470    <p>
     
    6672      <br>
    6773      <select name="who">
    68         <option value="any_visitor">{'any visitor'|@translate}</option>
    69         <option value="any_registered_user">{'any registered user'|@translate}</option>
    70         <option value="user">{'a specific user'|@translate}</option>
    71         <option value="group">{'a group'|@translate}</option>
     74{html_options options=$who_options selected=$who_options_selected}
    7275      </select>
    7376
    74       <select name="who_user" style="display:none">
     77      <select name="who_user" {if not isset($user_options_selected)}style="display:none"{/if}>
    7578{html_options options=$user_options selected=$user_options_selected}
    7679      </select>
    7780
    78       <select name="who_group" style="display:none">
     81      <select name="who_group" {if not isset($group_options_selected)}style="display:none"{/if}>
    7982{html_options options=$group_options selected=$group_options_selected}
    8083      </select>
     
    8588      <br>
    8689      <select class="categoryDropDown" name="category">
    87         <option value="0">{'The whole gallery'|@translate}</option>
     90        <option value="0" {if not isset($category_options_selected)}selected="selected"{/if}>{'The whole gallery'|@translate}</option>
    8891        <option disabled="disabled">------------</option>
    8992        {html_options options=$category_options selected=$category_options_selected}
    9093      </select>
    9194      <br>
    92       <label><input type="checkbox" name="recursive" checked="checked"> {'Apply to sub-albums'|@translate}</label>
     95      <label><input type="checkbox" name="recursive" {if $recursive}checked="checked"{/if}> {'Apply to sub-albums'|@translate}</label>
    9396      <br>
    94       <label><input type="checkbox" name="create_subcategories"> {'ability to create sub-albums'|@translate}</label>
     97      <label><input type="checkbox" name="create_subcategories" {if $create_subcategories}checked="checked"{/if}> {'ability to create sub-albums'|@translate}</label>
    9598    </p>
    9699
    97100    <p>
    98101      <strong>{'Which level of trust?'|@translate}</strong>
    99       <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>
    100       <br><label><input type="radio" name="moderate" value="false"> <em>{'high trust'|@translate}</em> : {'uploaded photos are directly displayed in the gallery'|@translate}</label>
     102      <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>
     103      <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>
    101104    </p>
     105
     106    {if isset($edit)}
     107      <input type="hidden" name="edit" value="{$edit}">
     108    {/if}
    102109   
    103110    <p style="margin:0;">
    104       <input class="submit" type="submit" name="submit_add" value="{'Add'|@translate}"/>
     111      <input class="submit" type="submit" name="submit_add" value="{if isset($edit)}{'Submit'|@translate}{else}{'Add'|@translate}{/if}"/>
     112      <a href="{$F_ADD_ACTION}">{'Cancel'|@translate}</a>
    105113    </p>
    106114  </fieldset>
     
    116124{if not empty($permissions)}
    117125  {foreach from=$permissions item=permission name=permission_loop}
    118   <tr class="{if $smarty.foreach.permission_loop.index is odd}row1{else}row2{/if}">
     126  <tr class="{if $smarty.foreach.permission_loop.index is odd}row1{else}row2{/if}{if $permission.HIGHLIGHT} rowSelected{/if}">
    119127    <td>{$permission.WHO}</td>
    120128    <td>{$permission.WHERE}</td>
     
    128136    {/if}
    129137    </td>
    130     <td style="text-align:center;">
     138    <td class="permissionActions">
     139      <a href="{$permission.U_EDIT}">
     140        <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/edit_s.png" alt="{'edit'|@translate}" title="{'edit'|@translate}" />
     141      </a>
    131142      <a href="{$permission.U_DELETE}" onclick="return confirm( document.getElementById('btn_delete').title + '\n\n' + '{'Are you sure?'|@translate|@escape:'javascript'}');">
    132         <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/delete.png" class="button" style="border:none" id="btn_delete" alt="{'delete'|@translate}" title="{'delete'|@translate}" />
     143        <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/delete.png" id="btn_delete" alt="{'delete'|@translate}" title="{'Delete permission'|@translate}" />
    133144      </a>
    134145    </td>
  • extensions/community/language/en_UK/plugin.lang.php

    r9453 r9510  
    5252
    5353$lang['No album, this photo is orphan'] = 'No album, this photo is orphan';
     54
     55$lang['Cancel'] = 'Cancel';
     56$lang['Permission updated'] = 'Permission updated';
     57$lang['Delete permission'] = 'Delete permission';
    5458?>
  • extensions/community/language/fr_FR/plugin.lang.php

    r9453 r9510  
    5454
    5555$lang['No album, this photo is orphan'] = 'Aucun album, cette photo est orpheline';
     56$lang['Cancel'] = 'Annuler';
     57$lang['Permission updated'] = 'Permission mise à jour';
     58$lang['Delete permission'] = 'Supprimer la permission';
    5659?>
Note: See TracChangeset for help on using the changeset viewer.