Changeset 19286


Ignore:
Timestamp:
Dec 4, 2012, 11:23:54 PM (11 years ago)
Author:
flop25
Message:

bug:2425
New interface like the Batch Mananger :
rename, delete, duplicate and toggle-default

TODO soon merge & finalisation of the interface

Location:
trunk/admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/group_list.php

    r12922 r19286  
    3838  check_pwg_token();
    3939}
    40 
    41 // +-----------------------------------------------------------------------+
    42 // |                             delete a group                            |
    43 // +-----------------------------------------------------------------------+
    44 
    45 if (isset($_GET['delete']) and is_numeric($_GET['delete']))
    46 {
    47   // destruction of the access linked to the group
    48   $query = '
    49 DELETE
    50   FROM '.GROUP_ACCESS_TABLE.'
    51   WHERE group_id = '.$_GET['delete'].'
    52 ;';
    53   pwg_query($query);
    54  
    55   // destruction of the users links for this group
    56   $query = '
    57 DELETE
    58   FROM '.USER_GROUP_TABLE.'
    59   WHERE group_id = '.$_GET['delete'].'
    60 ;';
    61   pwg_query($query);
    62 
    63   $query = '
    64 SELECT name
    65   FROM '.GROUPS_TABLE.'
    66   WHERE id = '.$_GET['delete'].'
    67 ;';
    68   list($groupname) = pwg_db_fetch_row(pwg_query($query));
    69  
    70   // destruction of the group
    71   $query = '
    72 DELETE
    73   FROM '.GROUPS_TABLE.'
    74   WHERE id = '.$_GET['delete'].'
    75 ;';
    76   pwg_query($query);
    77 
    78   array_push(
    79     $page['infos'],
    80     sprintf(l10n('group "%s" deleted'), $groupname)
    81     );
    82 }
    83 
    8440// +-----------------------------------------------------------------------+
    8541// |                              add a group                              |
     
    12581
    12682// +-----------------------------------------------------------------------+
    127 // | toggle is default group property                                      |
    128 // +-----------------------------------------------------------------------+
    129 
    130 if (isset($_GET['toggle_is_default']) and is_numeric($_GET['toggle_is_default']))
    131 {
    132   $query = '
    133 SELECT name, is_default
    134   FROM '.GROUPS_TABLE.'
    135   WHERE id = '.$_GET['toggle_is_default'].'
    136 ;';
    137   list($groupname, $is_default) = pwg_db_fetch_row(pwg_query($query));
     83// |                             action send                               |
     84// +-----------------------------------------------------------------------+
     85if (isset($_POST['submit']) and isset($_POST['selectAction']) and isset($_POST['group_selection']))
     86{
     87  // if the user tries to apply an action, it means that there is at least 1
     88  // photo in the selection
     89  $groups = $_POST['group_selection'];
     90  if (count($groups) == 0)
     91  {
     92    array_push($page['errors'], l10n('Select at least one group'));
     93  }
     94
     95  $action = $_POST['selectAction'];
     96
     97  // +
     98  // |rename a group
     99  // +
     100
     101  if ($action=="rename")
     102  {
     103    foreach($groups as $group)
     104    {
     105      if ( !empty($_POST['rename_'.$group.'']) )
     106      {
     107        $query = '
     108        UPDATE '.GROUPS_TABLE.'
     109        SET name = \''.$_POST['rename_'.$group.''].'\'
     110        WHERE id = '.$group.'
     111      ;';
     112        pwg_query($query);
     113      }
     114    }
     115  }
     116
     117  // +
     118  // |delete a group
     119  // +
     120
     121  if ($action=="delete" and $_POST['confirm_deletion'])
     122  {
     123    foreach($groups as $group)
     124    {
     125        // destruction of the access linked to the group
     126      $query = '
     127    DELETE
     128      FROM '.GROUP_ACCESS_TABLE.'
     129      WHERE group_id = '.$group.'
     130    ;';
     131      pwg_query($query);
     132     
     133      // destruction of the users links for this group
     134      $query = '
     135    DELETE
     136      FROM '.USER_GROUP_TABLE.'
     137      WHERE group_id = '.$group.'
     138    ;';
     139      pwg_query($query);
     140   
     141      $query = '
     142    SELECT name
     143      FROM '.GROUPS_TABLE.'
     144      WHERE id = '.$group.'
     145    ;';
     146      list($groupname) = pwg_db_fetch_row(pwg_query($query));
     147     
     148      // destruction of the group
     149      $query = '
     150    DELETE
     151      FROM '.GROUPS_TABLE.'
     152      WHERE id = '.$group.'
     153    ;';
     154      pwg_query($query);
     155   
     156      array_push(
     157        $page['infos'],
     158        sprintf(l10n('group "%s" deleted'), $groupname)
     159        );
     160    }
     161  }
     162
     163  // +
     164  // |duplicate a group
     165  // +
     166
     167  if ($action=="duplicate" )
     168  {
     169    foreach($groups as $group)
     170    {
     171      if ( empty($_POST['duplicate_'.$group.'']) )
     172      {
     173        break;
     174      }
     175      // is the group not already existing ?
     176      $query = '
     177  SELECT COUNT(*)
     178    FROM '.GROUPS_TABLE.'
     179    WHERE name = \''.pwg_db_real_escape_string($_POST['duplicate_'.$group.'']).'\'
     180  ;';
     181      list($count) = pwg_db_fetch_row(pwg_query($query));
     182      if ($count != 0)
     183      {
     184        array_push($page['errors'], l10n('This name is already used by another group.'));
     185        break;
     186      }
     187      // creating the group
     188      $query = '
     189  INSERT INTO '.GROUPS_TABLE.'
     190    (name)
     191    VALUES
     192    (\''.pwg_db_real_escape_string($_POST['duplicate_'.$group.'']).'\')
     193  ;';
     194      pwg_query($query);
     195      $query = '
     196      SELECT id
     197        FROM '.GROUPS_TABLE.'
     198        WHERE name = \''.pwg_db_real_escape_string($_POST['duplicate_'.$group.'']).'\'
     199      ;';
     200     
     201      list($groupid) = pwg_db_fetch_row(pwg_query($query));
     202      $query = '
     203    SELECT *
     204      FROM '.GROUP_ACCESS_TABLE.'
     205      WHERE group_id = '.$group.'
     206    ;';
     207      $grp_access = array();
     208      $res=pwg_query($query);
     209      while ($row = pwg_db_fetch_assoc($res))
     210      {
     211          $grp_access[] = array(
     212            'cat_id' => $row['cat_id'],
     213            'group_id' => $groupid
     214          );
     215      }
     216      mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $grp_access);
     217
     218      $query = '
     219    SELECT *
     220      FROM '.USER_GROUP_TABLE.'
     221      WHERE group_id = '.$group.'
     222    ;';
     223      $usr_grp = array();
     224      $res=pwg_query($query);
     225      while ($row = pwg_db_fetch_assoc($res))
     226      {
     227          $usr_grp[] = array(
     228            'user_id' => $row['user_id'],
     229            'group_id' => $groupid
     230          );
     231      }
     232      mass_inserts(USER_GROUP_TABLE, array('user_id','group_id'), $usr_grp);
    138233 
    139   // update of the group
    140   $query = '
    141 UPDATE '.GROUPS_TABLE.'
    142   SET is_default = \''.boolean_to_string(!get_boolean($is_default)).'\'
    143   WHERE id = '.$_GET['toggle_is_default'].'
    144 ;';
    145   pwg_query($query);
    146 
    147   array_push(
    148     $page['infos'],
    149     sprintf(l10n('group "%s" updated'), $groupname)
    150     );
    151 }
    152 
     234      array_push(
     235        $page['infos'],
     236        sprintf(l10n('group "%s" added'), $_POST['duplicate_'.$group.''])
     237        );
     238    }
     239  }
     240
     241
     242  // +
     243  // | toggle_default
     244  // +
     245 
     246  if ($action=="toggle_default")
     247  {
     248    foreach($groups as $group)
     249    {
     250      $query = '
     251    SELECT name, is_default
     252      FROM '.GROUPS_TABLE.'
     253      WHERE id = '.$group.'
     254    ;';
     255      list($groupname, $is_default) = pwg_db_fetch_row(pwg_query($query));
     256     
     257      // update of the group
     258      $query = '
     259    UPDATE '.GROUPS_TABLE.'
     260      SET is_default = \''.boolean_to_string(!get_boolean($is_default)).'\'
     261      WHERE id = '.$group.'
     262    ;';
     263      pwg_query($query);
     264   
     265      array_push(
     266        $page['infos'],
     267        sprintf(l10n('group "%s" updated'), $groupname)
     268        );
     269    }
     270  }
     271}
    153272// +-----------------------------------------------------------------------+
    154273// |                             template init                             |
     
    195314    array(
    196315      'NAME' => $row['name'],
     316      'ID' => $row['id'],
    197317      'IS_DEFAULT' => (get_boolean($row['is_default']) ? ' ['.l10n('default').']' : ''),
     318      'NB_MEMBERS' => $counter,
    198319      'MEMBERS' => l10n_dec('%d member', '%d members', $counter),
    199320      'U_MEMBERS' => $members_url.$row['id'],
  • trunk/admin/themes/default/template/group_list.tpl

    r19230 r19286  
    44
    55  $(".grp_action").hide();
    6   $("input[name=group_selection]").click(function() {
     6  $("input.group_selection").click(function() {
    77
    88    var nbSelected = 0;
    9     nbSelected = $("input[name=group_selection]").filter(':checked').length;
     9    nbSelected = $("input.group_selection").filter(':checked').length;
    1010
    1111    if (nbSelected == 0) {
     
    7777    {foreach from=$groups item=group name=group_loop}
    7878    <tr class="{if $smarty.foreach.group_loop.index is odd}row1{else}row2{/if}">
    79       <td><input name="group_selection" type="checkbox" value="{$group.ID}"></td>
     79      <td><input class="group_selection" name="group_selection[]" type="checkbox" value="{$group.ID}"></td>
    8080      <td>{$group.NAME}<i><small>{$group.IS_DEFAULT}</small></i></td>
    8181      <td><a href="{$group.U_MEMBERS}">{$group.MEMBERS}</a></td>
     
    9797  <fieldset id="action">
    9898    <legend>{'Action'|@translate}</legend>
    99       <div id="forbidAction"{if count($selection) != 0} style="display:none"{/if}>{'No group selected, no action possible.'|@translate}</div>
    100       <div id="permitAction"{if count($selection) == 0} style="display:none"{/if}>
     99      <div id="forbidAction">{'No group selected, no action possible.'|@translate}</div>
     100      <div id="permitAction" style="display:none">
    101101
    102102        <select name="selectAction">
Note: See TracChangeset for help on using the changeset viewer.