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

edit a permission

File:
1 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    );
Note: See TracChangeset for help on using the changeset viewer.