Changeset 19290


Ignore:
Timestamp:
Dec 5, 2012, 8:58:09 PM (11 years ago)
Author:
flop25
Message:

bug:2425
New interface like the Batch Mananger :
merge & interface finished

Location:
trunk/admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/group_list.php

    r19286 r19290  
    119119  // +
    120120
    121   if ($action=="delete" and $_POST['confirm_deletion'])
     121  if ($action=="delete" and isset($_POST['confirm_deletion']) and $_POST['confirm_deletion'])
    122122  {
    123123    foreach($groups as $group)
     
    161161  }
    162162
     163  // +
     164  // |merge groups into a new one
     165  // +
     166
     167  if ($action=="merge" )
     168  {
     169    // is the group not already existing ?
     170    $query = '
     171SELECT COUNT(*)
     172  FROM '.GROUPS_TABLE.'
     173  WHERE name = \''.pwg_db_real_escape_string($_POST['merge']).'\'
     174;';
     175    list($count) = pwg_db_fetch_row(pwg_query($query));
     176    if ($count != 0)
     177    {
     178      array_push($page['errors'], l10n('This name is already used by another group.'));
     179    }
     180    else
     181    {
     182      // creating the group
     183      $query = '
     184  INSERT INTO '.GROUPS_TABLE.'
     185    (name)
     186    VALUES
     187    (\''.pwg_db_real_escape_string($_POST['merge']).'\')
     188  ;';
     189      pwg_query($query);
     190      $query = '
     191      SELECT id
     192        FROM '.GROUPS_TABLE.'
     193        WHERE name = \''.pwg_db_real_escape_string($_POST['merge']).'\'
     194      ;';
     195      list($groupid) = pwg_db_fetch_row(pwg_query($query));
     196    }
     197    $grp_access = array();
     198    $usr_grp = array();
     199    foreach($groups as $group)
     200    {
     201      $query = '
     202    SELECT *
     203      FROM '.GROUP_ACCESS_TABLE.'
     204      WHERE group_id = '.$group.'
     205    ;';
     206      $res=pwg_query($query);
     207      while ($row = pwg_db_fetch_assoc($res))
     208      {
     209        $new_grp_access= array(
     210          'cat_id' => $row['cat_id'],
     211          'group_id' => $groupid
     212        );
     213        if (!in_array($new_grp_access,$grp_access))
     214        {
     215          $grp_access[]=$new_grp_access;
     216        }
     217      }
     218
     219      $query = '
     220    SELECT *
     221      FROM '.USER_GROUP_TABLE.'
     222      WHERE group_id = '.$group.'
     223    ;';
     224      $res=pwg_query($query);
     225      while ($row = pwg_db_fetch_assoc($res))
     226      {
     227        $new_usr_grp= array(
     228          'user_id' => $row['user_id'],
     229          'group_id' => $groupid
     230        );
     231        if (!in_array($new_usr_grp,$usr_grp))
     232        {
     233          $usr_grp[]=$new_usr_grp;
     234        }
     235      }
     236    }
     237    mass_inserts(USER_GROUP_TABLE, array('user_id','group_id'), $usr_grp);
     238    mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $grp_access);
     239    array_push(
     240      $page['infos'],
     241      sprintf(l10n('group "%s" added'), $_POST['merge'])
     242      );
     243  }
     244 
    163245  // +
    164246  // |duplicate a group
     
    304386{
    305387  $query = '
    306 SELECT COUNT(*)
    307   FROM '.USER_GROUP_TABLE.'
    308   WHERE group_id = '.$row['id'].'
     388SELECT username
     389  FROM '.USERS_TABLE.' AS u
     390  INNER JOIN '.USER_GROUP_TABLE.' AS ug
     391    ON u.'.$conf['user_fields']['id'].' = ug.user_id
     392  WHERE ug.group_id = '.$row['id'].'
    309393;';
    310   list($counter) = pwg_db_fetch_row(pwg_query($query));
    311  
     394  $members=array();
     395  $res=pwg_query($query);
     396  while ($us= pwg_db_fetch_assoc($res))
     397  {
     398    $members[]=$us['username'];
     399  }
    312400  $template->append(
    313401    'groups',
     
    316404      'ID' => $row['id'],
    317405      'IS_DEFAULT' => (get_boolean($row['is_default']) ? ' ['.l10n('default').']' : ''),
    318       'NB_MEMBERS' => $counter,
    319       'MEMBERS' => l10n_dec('%d member', '%d members', $counter),
     406      'NB_MEMBERS' => count($members),
     407      'L_MEMBERS' => implode(' - ', $members),
     408      'MEMBERS' => l10n_dec('%d member', '%d members', count($members)),
    320409      'U_MEMBERS' => $members_url.$row['id'],
    321410      'U_DELETE' => $del_url.$row['id'].'&pwg_token='.get_pwg_token(),
  • trunk/admin/themes/default/template/group_list.tpl

    r19286 r19290  
    7272      <th>{'Group name'|@translate}</th>
    7373      <th>{'Members'|@translate}</th>
    74       <th>{'Actions'|@translate}</th>
    7574    </tr>
    7675    {if not empty($groups)}
     
    7978      <td><input class="group_selection" name="group_selection[]" type="checkbox" value="{$group.ID}"></td>
    8079      <td>{$group.NAME}<i><small>{$group.IS_DEFAULT}</small></i></td>
    81       <td><a href="{$group.U_MEMBERS}">{$group.MEMBERS}</a></td>
    82       <td style="text-align:center;">
    83         <a href="{$group.U_PERM}">
    84           <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/permissions.png" style="border:none" alt="{'Permissions'|@translate}" title="{'Permissions'|@translate}"></a>
    85         <a href="{$group.U_DELETE}" onclick="return confirm('{'delete'|@translate|@escape:'javascript'}'
    86           + '\n\n' + '{'Are you sure?'|@translate|@escape:'javascript'}');">
    87           <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/delete.png" style="border:none" alt="{'Delete'|@translate}" title="{'Delete'|@translate}"></a>
    88         <a href="{$group.U_ISDEFAULT}" onclick="return confirm('{'Toggle \'default group\' property'|@translate|@escape:'javascript'}'
    89           +'\n\n' + '{'Are you sure?'|@translate|@escape:'javascript'}');">
    90           <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/toggle_is_default_group.png" style="border:none" alt="{'Toggle \'default group\' property'|@translate}" title="{'Toggle \'default group\' property'|@translate}"></a>
    91       </td>
     80      <td>{if $group.MEMBERS>0}<a href="{$group.U_MEMBERS}" title="{'Manage the members'|@translate}">{$group.MEMBERS}</a><br>{$group.L_MEMBERS}{else}{$group.MEMBERS}{/if}</td>
    9281    </tr>
    9382    {/foreach}
Note: See TracChangeset for help on using the changeset viewer.