Ignore:
Timestamp:
Dec 7, 2009, 12:20:39 AM (14 years ago)
Author:
LucMorizur
Message:

[Event Cats] Add new group/user association to posted cat/AP ; fix bugs 1306 and 1305

File:
1 edited

Legend:

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

    r4421 r4436  
    100100  // $_POST it uses, have already been checked.
    101101 
    102   // Check if a category id has been posted, and if yes if this category is
    103   // private.
    104   /* $cat_assoc_needed = (
    105   ); */
    106  
    107   // Check if an add. p. id has been posted, and if yes if this add. p. is
    108   // private.
    109   /* $ap_assoc_needed = (
    110   ); */
    111  
    112102  // User creation, as generic
    113103  $ec_user_id = false;
    114104  $page['errors'] = register_user(
    115    $_POST['login'], $_POST['password'], '', false
     105    $_POST['login'], $_POST['password'], '', false
    116106  );
    117107  if (
     
    135125   $page['errors'][] = sprintf(l10n('ec_user_generic_pb'), $_POST['login']);
    136126 
    137   // New group creation if required,
    138   // and association with user_id at the same time
     127  // New group creation if required, and association with user_id, and if
     128  // needed category or add. p., at the same time
    139129  if (
    140130    isset($_POST['ec_in_up_newgroup']) and
     
    153143      "))) and
    154144      $t2++ == 0 // The check is executed twice at maximum
    155     )  // Cannot be executed twice
     145    )
    156146      $t4 = pwg_query("
    157147        INSERT INTO `".GROUPS_TABLE."` (`name`, `is_default`)
    158148        VALUES ('".$_POST['groupname']."', 'false');
    159       ");
     149      "); // Cannot be executed twice
    160150    if ($t4)
    161151     $page['infos'][] =
     
    180170    // If a category id has been posted, the newly created group must be
    181171    // allowed to navigate in this category
    182     if (isset($_POST['ec_in_up_cat'])) {
     172    // We are in the group creation block, thus the we know this group cannot
     173    // be associated to any category
     174    if (
     175      isset($_POST['ec_in_up_cat']) and
     176      array_key_exists($_POST['ec_in_up_cat'], $ec_lists['categories'])
     177    ) {
    183178      if (mysql_num_rows(pwg_query("
    184179        SELECT `id`
     
    208203         );
    209204        else
    210          $page['errors'][] =
    211           sprintf(l10n('ec_group_create_pb'), $_POST['groupname']).' (3) : '.
    212           'MySQL error '.mysql_errno().', "'.mysql_error().'"';
     205         $page['errors'][] = sprintf(
     206          l10n('ec_assoc_pb'),
     207          $_POST['groupname'],$ec_lists['categories'][$_POST['ec_in_up_cat']]
     208         ).' : MySQL error '.mysql_errno().', "'.mysql_error().'"';
    213209      }
    214210    }
     
    216212    // If an add. p. id has been posted, the newly created group must be
    217213    // allowed to navigate in this additional page
    218    
    219     /*
    220    
    221    
    222    
    223    
    224     */
     214    if (
     215      isset($_POST['ec_in_up_aps']) and
     216      array_key_exists($_POST['ec_in_up_aps'], $ec_lists['add_pages'])
     217    ) {
     218      $granted_groups = array();
     219      $title_arr = array_from_query("
     220        SELECT `title`
     221        FROM `".ADD_PAGES_TABLE."`
     222        WHERE `id` = ".$_POST['ec_in_up_aps'].";
     223      ", 'title');
     224      $t_user = (is_in($title_arr[0], '/user_id=')) ?
     225       explode('/user_id=', $title_arr[0]) : array($title_arr[0]);
     226      if (is_in($t_user[0], '/group_id=')) {
     227        $t_group = explode('/group_id=', $t_user[0]);
     228        $granted_groups = explode(',', $t_group[1]);
     229      }
     230      else $t_group[0] = $t_user[0];
     231      if (!in_array($t3[0], $granted_groups)) {
     232        $granted_groups[] = $t3[0];
     233        $t_group[1] = implode(',', $granted_groups);
     234        $t_user[0] = implode('/group_id=', $t_group);
     235        if (pwg_query("
     236          UPDATE `".ADD_PAGES_TABLE."`
     237            SET `title` = '".implode('/user_id=', $t_user)."'
     238            WHERE `id` = ".$_POST['ec_in_up_aps'].";
     239        ") === false)
     240         $page['errors'][] = sprintf(
     241          l10n('ec_assoc_pb'),
     242          $_POST['groupname'],$ec_lists['add_pages'][$_POST['ec_in_up_aps']]
     243         ).' : MySQL error '.mysql_errno().', "'.mysql_error().'"';
     244        else $page['infos'][] = sprintf(
     245         l10n('ec_group_create_OK2'),
     246         $_POST['groupname'],$ec_lists['add_pages'][$_POST['ec_in_up_aps']]
     247        );
     248      }
     249    }
    225250  }
    226251  else {
    227252    // If a category id has been posted, the newly created user must be
    228     // allowed to navigate in this category
    229    
    230     // If an add. p. id has been posted, the newly created user must be
    231     // allowed to navigate in this additional page => not possible to
    232     // allow individually => must give a warning message ?
    233    
     253    // allowed to navigate in this category, if it is not the case yet
     254    if (
     255      isset($_POST['ec_in_up_cat']) and
     256      array_key_exists($_POST['ec_in_up_cat'], $ec_lists['categories'])
     257    ) {
     258      $private_uppercats = array_from_query("
     259        SELECT `id`
     260        FROM `".CATEGORIES_TABLE."`
     261        WHERE `id` IN (".
     262          implode(',', get_uppercat_ids(array($_POST['ec_in_up_cat']))).
     263        ")
     264        AND `status` = 'private';
     265      ", 'id');
     266      // We must not reinsert already existing lines in user_access table
     267      $granteds = array();
     268      foreach ($private_uppercats as $cat_id)
     269       $granteds[$cat_id] = array();
     270      $result = pwg_query("
     271        SELECT `user_id`, `cat_id`
     272        FROM `".USER_ACCESS_TABLE."`
     273        WHERE `cat_id` IN (".implode(',', $private_uppercats).")
     274          AND `user_id` = '$ec_user_id';
     275      ");
     276      while ($row = mysql_fetch_array($result))
     277       $granteds[$row['cat_id']][] = $row['user_id'];
     278      $inserts = array();
     279      foreach ($private_uppercats as $cat_id)
     280       if (!in_array($ec_user_id, $granteds[$cat_id]))
     281        $inserts[] = array(
     282          'user_id' => $ec_user_id,
     283          'cat_id'  => $cat_id
     284        );
     285      if (count($inserts) != 0) {
     286        mass_inserts(USER_ACCESS_TABLE, array('user_id','cat_id'), $inserts);
     287        if (mysql_errno() == 0)
     288         $page['infos'][] = sprintf(
     289           l10n('ec_group_create_OK2'),
     290           $_POST['login'], $ec_lists['categories'][$_POST['ec_in_up_cat']]
     291         );
     292        else
     293         $page['errors'][] = sprintf(
     294          l10n('ec_assoc_pb'),
     295          $_POST['login'], $ec_lists['categories'][$_POST['ec_in_up_cat']]
     296         ).' : MySQL error '.mysql_errno().', "'.mysql_error().'"';
     297      }
     298    }
     299     
     300    // If an add. p. id has been posted, the newly created user should be
     301    // allowed to navigate in this additional page => give a warning message
     302    if (
     303      isset($_POST['ec_in_up_aps']) and
     304      array_key_exists($_POST['ec_in_up_aps'], $ec_lists['add_pages'])
     305    ) $page['errors'][] = sprintf(
     306      l10n('ec_user_access_AP'),
     307      $ec_lists['add_pages'][$_POST['ec_in_up_aps']],
     308      $_POST['login']
     309    );
    234310  }
    235311  return $ec_user_id;
     
    294370 */
    295371function ec_create_modify_entry_OK() {
    296   global $page, $ec_lists, $ec_debug;
     372  global $page, $ec_lists;
    297373 
    298374  // $_POST validity checks : action prevented in case of bad arguments
     
    476552  $arg2p = ($arg2 == 'NULL') ? 'IS NULL' : ' = '.$arg2;
    477553  $ec_user_idp = ($ec_user_id == 'NULL') ? 'IS NULL' : ' = '.$ec_user_id;
    478   if (($t1 = mysql_fetch_row(pwg_query(// $q =
    479   "
     554  if (($t1 = mysql_fetch_row(pwg_query("
    480555    SELECT `id`
    481556    FROM `".EVNTCATS_TABLE."`
     
    510585     return false;
    511586  }
    512  
    513   $ec_debug[] = array(
    514     'del_other' => $del_other,
    515     'code' => $ec_code,
    516     'user_id' => $ec_user_id,
    517     'user_idp' => $ec_user_idp,
    518     'action' => $action,
    519     'arg1' => $arg1,
    520     'arg2' => $arg2,
    521     'arg1p' => $arg1p,
    522     'arg2p' => $arg2p,
    523     'forced' => $forced,
    524     'comment' => $comment,
    525   );
    526587 
    527588  // Action !
     
    554615      $forced = ($forced == 'false') ? '' : l10n('ec_cnfrm_forced');
    555616      $page['infos'][] =
    556        sprintf(l10n('ec_entry_create_OK'), mysql_insert_id()).' : '.
     617       sprintf(l10n('ec_entry_create_OK'), mysql_insert_id()).
    557618       $ec_code.' => '.
    558619       $ec_lists['user_ids'][$ec_user_id].$forced
     
    600661function ec_delete_entry_OK($ec_id) {
    601662  global $page;
     663  if (count($t = mysql_fetch_row(pwg_query("
     664    SELECT `code`
     665    FROM `".EVNTCATS_TABLE."`
     666    WHERE `id` = $ec_id;
     667  "))) == 0) {
     668    $page['errors'][] = sprintf(l10n('ec_entry_dont_exist'), $ec_id);
     669    return false;
     670  }
    602671  if (pwg_query("
    603672    DELETE FROM `".EVNTCATS_TABLE."`
     
    610679    return false;
    611680  }
    612   else $page['infos'][] = sprintf(l10n('ec_entry_del_ok'), $ec_id);
     681  $page['infos'][] = sprintf(l10n('ec_entry_del_ok'), $ec_id, $t[0]);
    613682  return true;
    614683}
Note: See TracChangeset for help on using the changeset viewer.