Changeset 13580


Ignore:
Timestamp:
Mar 17, 2012, 1:47:17 AM (12 years ago)
Author:
plg
Message:

feature 2594: redesign on album permission screen. The choice "public/private"
is not on the "properties" tab anymore. Simpler ergonomy to select grant users
and groups.

Location:
trunk/admin
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/album.php

    r13013 r13580  
    4444$category = pwg_db_fetch_assoc(pwg_query($query));
    4545
     46if (!isset($category['id']))
     47{
     48  die("unknown album");
     49}
     50
    4651// +-----------------------------------------------------------------------+
    4752// | Tabs                                                                  |
     
    6065$tabsheet->add('properties', l10n('Properties'), $admin_album_base_url.'-properties');
    6166$tabsheet->add('sort_order', l10n('Manage photo ranks'), $admin_album_base_url.'-sort_order');
    62 
    63 if ('private' == $category['status'])
    64 {
    65   $tabsheet->add('permissions', l10n('Permissions'), $admin_album_base_url.'-permissions');
    66 }
    67 
     67$tabsheet->add('permissions', l10n('Permissions'), $admin_album_base_url.'-permissions');
    6868$tabsheet->select($page['tab']);
    6969$tabsheet->assign();
  • trunk/admin/cat_modify.php

    r13077 r13580  
    145145    set_cat_visible(array($_GET['cat_id']), $_POST['visible']);
    146146  }
    147   if ($cat_info['status'] != $_POST['status'] )
    148   {
    149     set_cat_status(array($_GET['cat_id']), $_POST['status']);
    150   }
    151147
    152148  // in case the use moves his album to the gallery root, we force
     
    164160  }
    165161
    166   // we redirect to hide/show the "permissions" tab if the category status
    167   // has changed
    168   $_SESSION['page_infos'] = array(l10n('Album updated successfully'));
    169   redirect($admin_album_base_url);
     162  array_push($page['infos'], l10n('Album updated successfully'));
    170163}
    171164elseif (isset($_POST['set_random_representant']))
     
    227220    'CAT_NAME'           => @htmlspecialchars($category['name']),
    228221    'CAT_COMMENT'        => @htmlspecialchars($category['comment']),
    229 
    230     'status_values'     => array('public','private'),
    231 
    232     'CAT_STATUS'        => $category['status'],
    233222    'CAT_VISIBLE'       => boolean_to_string($category['visible']),
    234223
  • trunk/admin/cat_perm.php

    r13013 r13580  
    3838// +-----------------------------------------------------------------------+
    3939
    40 // if the category is not correct (not numeric, not private)
    41 if (isset($_GET['cat']) and is_numeric($_GET['cat']))
     40$page['cat'] = $category['id'];
     41
     42// +-----------------------------------------------------------------------+
     43// |                           form submission                             |
     44// +-----------------------------------------------------------------------+
     45
     46if (!empty($_POST))
    4247{
    43   $query = '
    44 SELECT status
    45   FROM '.CATEGORIES_TABLE.'
    46   WHERE id = '.$_GET['cat'].'
    47 ;';
    48   list($status) = pwg_db_fetch_row(pwg_query($query));
    49  
    50   if ('private' == $status)
    51   {
    52     $page['cat'] = $_GET['cat'];
    53   }
    54 }
    55 
    56 if (!isset($page['cat']))
    57 {
    58   $query = '
     48  check_pwg_token();
     49
     50  if ($category['status'] != $_POST['status'])
     51  {
     52    set_cat_status(array($page['cat']), $_POST['status']);
     53    $category['status'] = $_POST['status'];
     54  }
     55
     56  if ('private' == $_POST['status'])
     57  {
     58    //
     59    // manage groups
     60    //
     61    $query = '
     62SELECT group_id
     63  FROM '.GROUP_ACCESS_TABLE.'
     64  WHERE cat_id = '.$page['cat'].'
     65;';
     66    $groups_granted = array_from_query($query, 'group_id');
     67
     68    if (!isset($_POST['groups']))
     69    {
     70      $_POST['groups'] = array();
     71    }
     72   
     73    //
     74    // remove permissions to groups
     75    //
     76    $deny_groups = array_diff($groups_granted, $_POST['groups']);
     77    if (count($deny_groups) > 0)
     78    {
     79      // if you forbid access to an album, all sub-albums become
     80      // automatically forbidden
     81      $query = '
     82DELETE
     83  FROM '.GROUP_ACCESS_TABLE.'
     84  WHERE group_id IN ('.implode(',', $deny_groups).')
     85    AND cat_id IN ('.implode(',', get_subcat_ids(array($page['cat']))).')
     86;';
     87      pwg_query($query);
     88    }
     89
     90    //
     91    // add permissions to groups
     92    //
     93    $grant_groups = array_diff($_POST['groups'], $groups_granted);
     94    if (count($grant_groups) > 0)
     95    {
     96      $cat_ids = get_uppercat_ids(array($page['cat']));
     97      if (isset($_POST['apply_on_sub']))
     98      {
     99        $cat_ids = array_merge($cat_ids, get_subcat_ids(array($page['cat'])));
     100      }
     101     
     102      $query = '
    59103SELECT id
    60104  FROM '.CATEGORIES_TABLE.'
    61   WHERE status = \'private\'
    62   LIMIT 1
    63 ;';
    64 
    65   list($page['cat']) = pwg_db_fetch_row(pwg_query($query));
    66 }
    67 
    68 // +-----------------------------------------------------------------------+
    69 // |                           form submission                             |
    70 // +-----------------------------------------------------------------------+
    71 if (isset($_POST['deny_groups_submit']) or isset($_POST['grant_groups_submit']) or isset($_POST['deny_users_submit']) or isset($_POST['grant_users_submit']) )
    72 {
    73   check_pwg_token();
    74 }
    75 
    76 if (isset($_POST['deny_groups_submit'])
    77          and isset($_POST['deny_groups'])
    78          and count($_POST['deny_groups']) > 0)
    79 {
    80   // if you forbid access to a category, all sub-categories become
    81   // automatically forbidden
    82   $query = '
    83 DELETE
    84   FROM '.GROUP_ACCESS_TABLE.'
    85   WHERE group_id IN ('.implode(',', $_POST['deny_groups']).')
    86     AND cat_id IN ('.implode(',', get_subcat_ids(array($page['cat']))).')
    87 ;';
    88   pwg_query($query);
    89 }
    90 else if (isset($_POST['grant_groups_submit'])
    91          and isset($_POST['grant_groups'])
    92          and count($_POST['grant_groups']) > 0)
    93 {
    94   $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'])));
    95 
    96   $query = '
    97 SELECT id
    98   FROM '.CATEGORIES_TABLE.'
    99   WHERE id IN ('.$cat_ids.')
    100   AND status = \'private\'
    101 ;';
    102   $private_cats = array_from_query($query, 'id');
    103 
    104   // We must not reinsert already existing lines in group_access table
    105   $granteds = array();
    106   foreach ($private_cats as $cat_id)
    107   {
    108     $granteds[$cat_id] = array();
    109   }
     105  WHERE id IN ('.implode(',', $cat_ids).')
     106    AND status = \'private\'
     107;';
     108      $private_cats = array_from_query($query, 'id');
     109
     110      // We must not reinsert already existing lines in group_access table
     111      $granteds = array();
     112      foreach ($private_cats as $cat_id)
     113      {
     114        $granteds[$cat_id] = array();
     115      }
    110116 
    111   $query = '
    112 SELECT group_id, cat_id
     117      $query = '
     118SELECT
     119    group_id,
     120    cat_id
    113121  FROM '.GROUP_ACCESS_TABLE.'
    114122  WHERE cat_id IN ('.implode(',', $private_cats).')
    115     AND group_id IN ('.implode(',', $_POST['grant_groups']).')
    116 ;';
    117   $result = pwg_query($query);
    118   while ($row = pwg_db_fetch_assoc($result))
    119   {
    120     array_push($granteds[$row['cat_id']], $row['group_id']);
    121   }
    122 
    123   $inserts = array();
    124  
    125   foreach ($private_cats as $cat_id)
    126   {
    127     $group_ids = array_diff($_POST['grant_groups'], $granteds[$cat_id]);
    128     foreach ($group_ids as $group_id)
    129     {
    130       array_push($inserts, array('group_id' => $group_id,
    131                                  'cat_id' => $cat_id));
    132     }
    133   }
    134 
    135   mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $inserts);
    136 }
    137 else if (isset($_POST['deny_users_submit'])
    138          and isset($_POST['deny_users'])
    139          and count($_POST['deny_users']) > 0)
    140 {
    141   // if you forbid access to a category, all sub-categories become
    142   // automatically forbidden
    143   $query = '
     123    AND group_id IN ('.implode(',', $grant_groups).')
     124;';
     125      $result = pwg_query($query);
     126      while ($row = pwg_db_fetch_assoc($result))
     127      {
     128        array_push($granteds[$row['cat_id']], $row['group_id']);
     129      }
     130
     131      $inserts = array();
     132     
     133      foreach ($private_cats as $cat_id)
     134      {
     135        $group_ids = array_diff($grant_groups, $granteds[$cat_id]);
     136        foreach ($group_ids as $group_id)
     137        {
     138          array_push(
     139            $inserts,
     140            array(
     141              'group_id' => $group_id,
     142              'cat_id' => $cat_id
     143              )
     144            );
     145        }
     146      }
     147
     148      mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $inserts);
     149    }
     150
     151    //
     152    // users
     153    //
     154    $query = '
     155SELECT user_id
     156  FROM '.USER_ACCESS_TABLE.'
     157  WHERE cat_id = '.$page['cat'].'
     158;';
     159    $users_granted = array_from_query($query, 'user_id');
     160
     161    if (!isset($_POST['users']))
     162    {
     163      $_POST['users'] = array();
     164    }
     165   
     166    //
     167    // remove permissions to users
     168    //
     169    $deny_users = array_diff($users_granted, $_POST['users']);
     170    if (count($deny_users) > 0)
     171    {
     172      // if you forbid access to an album, all sub-album become automatically
     173      // forbidden
     174      $query = '
    144175DELETE
    145176  FROM '.USER_ACCESS_TABLE.'
    146   WHERE user_id IN ('.implode(',', $_POST['deny_users']).')
     177  WHERE user_id IN ('.implode(',', $deny_users).')
    147178    AND cat_id IN ('.implode(',', get_subcat_ids(array($page['cat']))).')
    148179;';
    149   pwg_query($query);
    150 }
    151 else if (isset($_POST['grant_users_submit'])
    152          and isset($_POST['grant_users'])
    153          and count($_POST['grant_users']) > 0)
    154 {
    155   add_permission_on_category($page['cat'], $_POST['grant_users']);
     180      pwg_query($query);
     181    }
     182
     183    //
     184    // add permissions to users
     185    //
     186    $grant_users = array_diff($_POST['users'], $users_granted);
     187    if (count($grant_users) > 0)
     188    {
     189      add_permission_on_category($page['cat'], $grant_users);
     190    }
     191  }
     192
     193  array_push($page['infos'], l10n('Album updated successfully'));
    156194}
    157195
     
    171209    'U_HELP' => get_root_url().'admin/popuphelp.php?page=cat_perm',
    172210    'F_ACTION' => $admin_album_base_url.'-permissions',
     211    'private' => ('private' == $category['status']),
    173212    )
    174213  );
     
    189228;';
    190229$groups = simple_hash_from_query($query, 'id', 'name');
    191 $template->assign('all_groups', $groups);
     230$template->assign('groups', $groups);
    192231
    193232// groups granted to access the category
     
    198237;';
    199238$group_granted_ids = array_from_query($query, 'group_id');
    200 $group_granted_ids = order_by_name($group_granted_ids, $groups);
    201 $template->assign('group_granted_ids', $group_granted_ids);
    202 
    203 
    204 // groups denied
    205 $template->assign('group_denied_ids',
    206     order_by_name(array_diff(array_keys($groups), $group_granted_ids), $groups)
    207   );
     239$template->assign('groups_selected', $group_granted_ids);
    208240
    209241// users...
     
    216248;';
    217249$users = simple_hash_from_query($query, 'id', 'username');
    218 $template->assign('all_users', $users);
     250$template->assign('users', $users);
    219251
    220252
     
    225257;';
    226258$user_granted_direct_ids = array_from_query($query, 'user_id');
    227 $user_granted_direct_ids = order_by_name($user_granted_direct_ids, $users);
    228 $template->assign('user_granted_direct_ids', $user_granted_direct_ids);
    229 
     259$template->assign('users_selected', $user_granted_direct_ids);
    230260
    231261
     
    283313}
    284314
    285 $user_denied_ids = array_diff(array_keys($users),
    286                               $user_granted_indirect_ids,
    287                               $user_granted_direct_ids);
    288 $user_denied_ids = order_by_name($user_denied_ids, $users);
    289 $template->assign('user_denied_ids', $user_denied_ids);
    290 
    291 
    292315// +-----------------------------------------------------------------------+
    293316// |                           sending html code                           |
  • trunk/admin/themes/default/template/cat_modify.tpl

    r13020 r13580  
    8282
    8383  <p>
    84     <strong>{'Access type'|@translate}</strong>
    85     <br>
    86     {html_radios name='status' values=$status_values output=$status_values|translate selected=$CAT_STATUS}
    87   </p>
    88 
    89   <p>
    9084    <strong>{'Lock'|@translate}</strong>
    9185    <br>
  • trunk/admin/themes/default/template/cat_perm.tpl

    r13013 r13580  
     1{combine_script id='jquery.chosen' load='footer' path='themes/default/js/plugins/chosen.jquery.min.js'}
     2{combine_css path="themes/default/js/plugins/chosen.css"}
     3
     4{footer_script}{literal}
     5jQuery(document).ready(function() {
     6  jQuery(".chzn-select").chosen();
     7
     8  function checkStatusOptions() {
     9    if (jQuery("input[name=status]:checked").val() == "private") {
     10      jQuery("#privateOptions, #applytoSubAction").show();
     11    }
     12    else {
     13      jQuery("#privateOptions, #applytoSubAction").hide();
     14    }
     15  }
     16
     17  checkStatusOptions();
     18  jQuery("#selectStatus").change(function() {
     19    checkStatusOptions();
     20  });
     21});
     22{/literal}{/footer_script}
     23
    124<div class="titrePage">
    225  <h2><span style="letter-spacing:0">{$CATEGORIES_NAV}</span> &#8250; {'Edit album'|@translate} {$TABSHEET_TITLE}</h2>
     
    528<form action="{$F_ACTION}" method="post" id="categoryPermissions">
    629
     30<fieldset>
     31  <legend>{'Access type'|@translate}</legend>
     32
     33  <p id="selectStatus">
     34    <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>
     35    <br>
     36    <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>
     37  </p>
     38</fieldset>
     39
     40<fieldset id="privateOptions">
     41  <legend>{'Groups and users'|@translate}</legend>
     42
     43  <p>
     44    <strong>{'Permission granted for groups'|@translate}</strong>
     45    <br>
     46    <select data-placeholder="{'Select groups...'|@translate}" class="chzn-select" multiple style="width:700px;" name="groups[]">
     47      {html_options options=$groups selected=$groups_selected}
     48    </select>
     49  </p>
     50
     51  <p>
     52    <strong>{'Permission granted for users'|@translate}</strong>
     53    <br>
     54    <select data-placeholder="{'Select users...'|@translate}" class="chzn-select" multiple style="width:700px;" name="users[]">
     55      {html_options options=$users selected=$users_selected}
     56    </select>
     57  </p>
     58
     59{*
    760  <h4>{'Groups'|@translate}</h4>
    861
     
    61114    <label><input type="checkbox" name="apply_on_sub">{'Apply to sub-albums'|@translate}</label>
    62115  </fieldset>
     116*}
     117</fieldset>
     118
     119  <p style="margin:12px;text-align:left;">
     120    <input class="submit" type="submit" value="{'Save Settings'|@translate}" name="submit">
     121    <label id="applytoSubAction" style="display:none;"><input type="checkbox" name="apply_on_sub">{'Apply to sub-albums'|@translate}</label>
     122  </p>
    63123
    64124<input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
  • trunk/admin/themes/default/theme.css

    r13451 r13580  
    243243TABLE.doubleSelect SELECT.categoryList {
    244244        width: 100%; max-width: 100%; overflow-x: auto;
    245 }
    246 
    247 FORM#categoryPermissions LI {
    248         display:inline;
    249         white-space: nowrap;
    250245}
    251246
Note: See TracChangeset for help on using the changeset viewer.