Changeset 4420


Ignore:
Timestamp:
Dec 4, 2009, 1:34:19 AM (14 years ago)
Author:
LucMorizur
Message:

[Event Cats] Begin categories association (which was forgotten) to newly created user, and group if needed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/event_cats/include/evntcats_admin_funcs.inc.php

    r4418 r4420  
    9393 */
    9494function ec_create_user_OK() {
    95   global $page;
     95  global $page, $ec_lists;
    9696 
    9797  // This function assumes that the validity of the different indexes of
     
    140140    $_POST['groupname'] != ''
    141141  ) {
     142    // Checks if a group named $_POST['groupname'] already exists.
     143    // If not, creates it : then, t4 is no more false. In any case, t3 gets
     144    // the id of the group named $_POST['groupname'].
    142145    $t2 = 0; $t3 = false; $t4 = false;
    143     while (
     146    while ( // The check is executed once at minimum
    144147      !($t3 = mysql_fetch_row(pwg_query("
    145148        SELECT `id`
     
    147150        WHERE `name` = '".$_POST['groupname']."';
    148151      "))) and
    149       $t2++ == 0
    150     ) $t4 = pwg_query("
     152      $t2++ == 0 // The check is executed twice at maximum
     153    )  // Cannot be executed twice
     154      $t4 = pwg_query("
    151155        INSERT INTO `".GROUPS_TABLE."` (`name`, `is_default`)
    152156        VALUES ('".$_POST['groupname']."', 'false');
     
    166170    ) $page['errors'][] =
    167171      sprintf(l10n('ec_group_create_pb'), $_POST['groupname']).' (2) : '.
    168      'MySQL error '.mysql_errno().', "'.mysql_error().'"';
     172      'MySQL error '.mysql_errno().', "'.mysql_error().'"';
    169173    else $page['infos'][] = sprintf(
    170174      l10n('ec_group_create_OK2'),
     
    174178    // If a category id has been posted, the newly created group must be
    175179    // allowed to navigate in this category
    176    
    177     /*
    178    
    179180    if (isset($_POST['ec_in_up_cat'])) {
    180181      if (mysql_num_rows(pwg_query("
     
    184185      ")) == 0) return ec_end1('ec_in_up_cat', 'Category doesn\'t exist : ');
    185186      else {
    186    
    187   $query = '
    188 SELECT id
    189   FROM '.CATEGORIES_TABLE.'
    190   WHERE id IN ('.implode(',', get_uppercat_ids(array($page['cat']))).')
    191   AND status = \'private\'
    192 ;';
    193   $private_uppercats = array_from_query($query, 'id');
    194 
    195   // We must not reinsert already existing lines in group_access table
    196   $granteds = array();
    197   foreach ($private_uppercats as $cat_id)
    198   {
    199     $granteds[$cat_id] = array();
    200   }
    201  
    202   $query = '
    203 SELECT group_id, cat_id
    204   FROM '.GROUP_ACCESS_TABLE.'
    205   WHERE cat_id IN ('.implode(',', $private_uppercats).')
    206     AND group_id IN ('.implode(',', $_POST['grant_groups']).')
    207 ;';
    208   $result = pwg_query($query);
    209   while ($row = mysql_fetch_array($result))
    210   {
    211     array_push($granteds[$row['cat_id']], $row['group_id']);
    212   }
    213 
    214   $inserts = array();
    215  
    216   foreach ($private_uppercats as $cat_id)
    217   {
    218     $group_ids = array_diff($_POST['grant_groups'], $granteds[$cat_id]);
    219     foreach ($group_ids as $group_id)
    220     {
    221       array_push($inserts, array('group_id' => $group_id,
    222                                  'cat_id' => $cat_id));
    223     }
    224   }
    225 
    226   mass_inserts(GROUP_ACCESS_TABLE, array('group_id','cat_id'), $inserts);
    227    
    228    
     187        $private_uppercats = array_from_query("
     188          SELECT `id`
     189          FROM `".CATEGORIES_TABLE."`
     190          WHERE `id` IN (".
     191            implode(',', get_uppercat_ids(array($_POST['ec_in_up_cat']))).
     192          ")
     193          AND `status` = 'private';
     194        ", 'id');
     195        $inserts = array();
     196        foreach ($private_uppercats as $cat_id)
     197         $inserts[] = array(
     198           'group_id' => $t3[0],
     199           'cat_id'   => $cat_id
     200         );
     201        mass_inserts(GROUP_ACCESS_TABLE,array('group_id','cat_id'), $inserts);
     202        if (mysql_errno() == 0)
     203         $page['infos'][] = sprintf(
     204           l10n('ec_group_create_OK2'),
     205           $_POST['groupname'],$ec_lists['categories'][$_POST['ec_in_up_cat']]
     206         );
     207        else
     208         $page['errors'][] =
     209          sprintf(l10n('ec_group_create_pb'), $_POST['groupname']).' (3) : '.
     210          'MySQL error '.mysql_errno().', "'.mysql_error().'"';
    229211      }
    230212    }
    231213   
    232     */
    233    
    234214    // If an add. p. id has been posted, the newly created group must be
    235215    // allowed to navigate in this additional page
     216   
     217    /*
     218   
     219   
     220   
     221   
     222    */
    236223  }
    237224  else {
     
    241228    // If an add. p. id has been posted, the newly created user must be
    242229    // allowed to navigate in this additional page => not possible to
    243     // allow individually => must give a warning message
     230    // allow individually => must give a warning message ?
    244231   
    245232  }
Note: See TracChangeset for help on using the changeset viewer.