Changeset 4333 for extensions/event_cats


Ignore:
Timestamp:
Nov 21, 2009, 6:59:31 PM (14 years ago)
Author:
LucMorizur
Message:

[Event Cats] Remove bug types could not be granted to duplication when from blank

Location:
extensions/event_cats
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/event_cats/admin/evntcats_admin.php

    r4329 r4333  
    7777build_ec_lists(); // in evntcats_main_funcs.php
    7878
     79$dup_types_exist = false;
     80$dup_entries_exist = false;
     81$ec_exist_entries = false;
     82function check_DB() {
     83  global $dup_types_exist, $dup_entries_exist, $ec_exist_entries, $ec_lists;
     84 
     85  $dup_types_exist = build_dup_groups(); // build_dup_groups() returns
     86  // true if an entry exists for duplication management for types
     87 
     88  // both arrays below are built when executing build_dup_groups() function
     89  $dup_entries_exist = (
     90    $dup_types_exist or
     91    count($ec_lists['groups_granted_ids']) > 0 or
     92    count($ec_lists['users_granted_direct_ids']) > 0
     93  );
     94 
     95  $ec_exist_entries = (mysql_num_rows(pwg_query("
     96    SELECT * FROM `".EVNTCATS_TABLE."`
     97    WHERE `code` IS NOT NULL ;
     98  ")) != 0);
     99}
     100
     101check_DB();
     102
    79103// If no entry exist, default tab is 'autolog_new'.
    80 $page['tab'] = (!($ec_exist_entries = (mysql_num_rows(pwg_query("
    81   SELECT * FROM `".EVNTCATS_TABLE."`
    82   WHERE `code` IS NOT NULL ;
    83 ")) != 0))) ? 'autolog_new' : 'autolog_entries';
    84 
    85 // If no entry exist, but some duplication management entries exist, default
    86 // tab is 'duplication'.
    87 if (!$ec_exist_entries and read_ec_conf('dup_allow') == '2') $page['tab'] = 'duplication';
     104$page['tab'] = (!$ec_exist_entries) ? 'autolog_new' : 'autolog_entries';
     105
     106// If no entry exist, but some duplication management entries exist, and
     107// duplication setting is "managed per groups", default tab is 'duplication'
     108if (
     109  !$ec_exist_entries and
     110  read_ec_conf('dup_allow') == '2' and
     111  $dup_entries_exist
     112) $page['tab'] = 'duplication';
    88113
    89114// If a modification of duplication management has been posted, default tab
     
    166191  )
    167192) {
    168   $c = ($no_previous = (count($t = mysql_fetch_row(pwg_query("
    169     SELECT `arg2`
    170     FROM `".EVNTCATS_TABLE."`
    171     WHERE `code` IS NULL
    172       AND `arg1` = 3
    173       AND `arg2` IS NOT NULL
    174     LIMIT 1;
    175   "))) == 0)) ? 0 : intval($t[0]);
     193  $c = $ec_lists['types_granted'];
    176194  if (isset($_POST['deny_types']))
    177195   foreach ($_POST['deny_types'] as $v) $c = $c & ~$v;
    178196  if (isset($_POST['deny_generic'])) $c = $c & 7;
    179   $q = ($no_previous) ? "
    180     INSERT INTO `".EVNTCATS_TABLE."`
    181     (`arg1`, `arg2`)
    182     VALUES (3, $c);
    183   " : "
     197  $q = ($dup_types_exist) ? "
    184198    UPDATE `".EVNTCATS_TABLE."`
    185199    SET `arg2` = $c
    186200    WHERE `arg1` = 3
    187201    LIMIT 1 ;
     202  " : "
     203    INSERT INTO `".EVNTCATS_TABLE."`
     204    (`arg1`, `arg2`)
     205    VALUES (3, $c);
    188206  ";
    189207  if (pwg_query($q) === false) ec_end2(3);
     
    197215  )
    198216) {
    199   $c = ($no_previous = (count($t = mysql_fetch_row(pwg_query("
    200     SELECT `arg2`
    201     FROM `".EVNTCATS_TABLE."`
    202     WHERE `code` IS NULL
    203       AND `arg1` = 3
    204       AND `arg2` IS NOT NULL
    205     LIMIT 1;
    206   "))) == 0)) ? 0 : intval($t[0]);
     217  $c = $ec_lists['types_granted'];
    207218  if (isset($_POST['grant_types']))
    208219   foreach ($_POST['grant_types'] as $v) $c = $c | $v;
    209220  if (isset($_POST['grant_generic'])) $c = $c | 8;
    210   $q = ($no_previous) ? "
    211     INSERT INTO `".EVNTCATS_TABLE."`
    212     (`arg1`, `arg2`)
    213     VALUES (3, $c);
    214   " : "
     221  $q = ($dup_types_exist) ? "
    215222    UPDATE `".EVNTCATS_TABLE."`
    216223    SET `arg2` = $c
    217224    WHERE `arg1` = 3
    218225    LIMIT 1 ;
     226  " : "
     227    INSERT INTO `".EVNTCATS_TABLE."`
     228    (`arg1`, `arg2`)
     229    VALUES (3, $c);
    219230  ";
    220231  if (pwg_query($q) === false) ec_end2(4);
     
    309320// +-----------------------------------------------------------------------+
    310321
    311 $ec_exist_entries = (mysql_num_rows(pwg_query("
    312   SELECT * FROM `".EVNTCATS_TABLE."`
    313   WHERE `code` IS NOT NULL
    314 ")) != 0);
    315 
     322check_DB();
     323 
    316324if (
    317325  $page['tab'] == 'duplication' and
  • extensions/event_cats/include/ec_conf.inc.php

    r4329 r4333  
    2222// | USA.                                                                  |
    2323// +-----------------------------------------------------------------------+
     24
     25if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    2426
    2527global $ec_conf, $page, $ec_conf_index, $ec_conf_default,
  • extensions/event_cats/include/evntcats_admin_funcs.inc.php

    r4329 r4333  
    3131// | Header                                                                |
    3232// +-----------------------------------------------------------------------+
     33
     34if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    3335
    3436global $conf, $page;
  • extensions/event_cats/include/evntcats_main_funcs.inc.php

    r4329 r4333  
    2222// | USA.                                                                  |
    2323// +-----------------------------------------------------------------------+
     24
     25if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    2426
    2527// ***************************************************************************
     
    311313
    312314/*
    313  * build_ec_lists()
    314  * builds the main array variable contaning all informations for the plugin
     315 * build_dup_groups()
     316 * builds the information telling who is allowed to duplicate
    315317 *
    316318 * @param
     
    320322 *   (no return value)
    321323 */
    322 function build_ec_lists() {
    323  
    324   // Construction of $ec_lists['add_pages'] array var
    325   build_ec_addp();
    326  
    327   // Construction of $ec_lists['categories'] array var
    328   build_ec_categories(true);
    329  
    330   // Construction of $ec_lists['user_ids'] array var
    331   build_ec_userids();
    332  
    333   // Construction of $ec_lists['ec_table'] array var
    334   build_ec_table();
    335 }
    336 
    337 // +-----------------------------------------------------------------------+
    338 // | Duplication analysis functions                                        |
    339 // +-----------------------------------------------------------------------+
    340 
    341 /*
    342  * build_dup_arrays($append_tpl = false)
    343  * builds arrays telling which accounts are allowed to display a duplicate
    344  * account link. Returns an array of all the user ids allowed to duplicate.
    345  *
    346  * @param
    347  *   $append_tpl : tells if $template must be appended with built arrays
    348  * @return
    349  *   (no return value)
    350  */
    351 function build_dup_arrays($append_tpl = false) {
    352   global $template, $ec_lists, $conf;
     324function build_dup_groups() {
     325  global $ec_lists;
    353326 
    354327  if (count($ec_lists['user_ids']) == 0) build_ec_userids();
    355328 
    356   // A lot of below code has simply been copied from file cat_perm.php .
    357   // Many thanks to people who wrote it !
    358  
    359   $groups = simple_hash_from_query("
     329  // Existing groups (needed later)
     330  $ec_lists['groups'] = simple_hash_from_query("
    360331    SELECT `id`, `name`
    361332      FROM `".GROUPS_TABLE."`
     
    366337 
    367338  // groups granted to duplication
    368   $groups_granted_ids = order_by_name(
     339  $ec_lists['groups_granted_ids'] = order_by_name(
    369340    array_from_query("
    370341      SELECT `arg2`
     
    376347      'arg2'
    377348    ),
    378     $groups
     349    $ec_lists['groups']
    379350  );
    380351 
    381352  // users directly granted to duplication
    382   $users_granted_direct_ids = order_by_name(
     353  $ec_lists['users_granted_direct_ids'] = order_by_name(
    383354    array_from_query("
    384355      SELECT `arg2`
     
    396367  // certain group (in groups, level (friends, family, contacts),
    397368  // or user status (generic))
    398   $users_granted_ids = array();
    399  
    400   $c = (count($t = mysql_fetch_row(pwg_query("
     369  $types_entry_exists = (($t = mysql_fetch_row(pwg_query("
    401370    SELECT `arg2`
    402371    FROM `".EVNTCATS_TABLE."`
     
    405374      AND `arg2` IS NOT NULL
    406375    LIMIT 1;
    407   "))) == 0) ? 0 : intval($t[0]);
     376  "))) !== false);
     377  $ec_lists['types_granted'] = ($types_entry_exists) ? $t[0] : 0;
     378 
     379  return $types_entry_exists;
     380}
     381
     382/*
     383 * build_ec_lists()
     384 * builds the main array variable contaning all informations for the plugin
     385 *
     386 * @param
     387 *   no parameter passed, the main material on which works the function, is
     388 *   the global array variable $ec_lists.
     389 * @return
     390 *   (no return value)
     391 */
     392function build_ec_lists() {
     393 
     394  // Construction of $ec_lists['add_pages'] array var
     395  build_ec_addp();
     396 
     397  // Construction of $ec_lists['categories'] array var
     398  build_ec_categories(true);
     399 
     400  // Construction of $ec_lists['user_ids'] array var
     401  build_ec_userids();
     402 
     403  // Construction of $ec_lists['ec_table'] array var
     404  build_ec_table();
     405}
     406
     407// +-----------------------------------------------------------------------+
     408// | Duplication analysis functions                                        |
     409// +-----------------------------------------------------------------------+
     410
     411/*
     412 * build_dup_arrays($append_tpl = false)
     413 * builds arrays telling which accounts are allowed to display a duplicate
     414 * account link. Returns an array of all the user ids allowed to duplicate.
     415 *
     416 * @param
     417 *   $append_tpl : tells if $template must be appended with built arrays
     418 * @return
     419 *   (no return value)
     420 */
     421function build_dup_arrays($append_tpl = false) {
     422  global $template, $ec_lists, $conf;
     423 
     424  // A lot of below code has simply been copied from file cat_perm.php .
     425  // Many thanks to people who wrote it !
     426 
     427  build_dup_groups();
     428 
     429  $users_granted_ids = array();
    408430 
    409431  $users_granted_thks_gen_ids = array();
    410   if ($ec_gen_granted = (($c & 8) != 0)) {
     432  if ($ec_gen_granted = (($ec_lists['types_granted'] & 8) != 0)) {
    411433    $users_granted_thks_gen_ids = order_by_name(
    412434      array_diff(
     
    417439          'user_id'
    418440        ),
    419         $users_granted_direct_ids
     441        $ec_lists['users_granted_direct_ids']
    420442      ),
    421443      $ec_lists['user_ids']
     
    432454  $types_granted_ids = array();
    433455  $users_granted_thks_types_ids = array();
    434   if (($c & 7) != 0) {
    435     if (($c & 1) != 0) $types_granted_ids[] = '1';
    436     if (($c & 2) != 0) $types_granted_ids[] = '2';
    437     if (($c & 4) != 0) $types_granted_ids[] = '4';
     456  if (($ec_lists['types_granted'] & 7) != 0) {
     457    if (($ec_lists['types_granted'] & 1) != 0) $types_granted_ids[] = '1';
     458    if (($ec_lists['types_granted'] & 2) != 0) $types_granted_ids[] = '2';
     459    if (($ec_lists['types_granted'] & 4) != 0) $types_granted_ids[] = '4';
    438460    if (count($types_granted_ids) > 0) {
    439461      $user_granted_from_type = array();
     
    458480        array_diff(
    459481          array_unique($user_granted_by_type_ids),
    460           $users_granted_direct_ids
     482          $ec_lists['users_granted_direct_ids']
    461483        ),
    462484        $ec_lists['user_ids']
     
    473495
    474496  $users_granted_thks_groups_ids = array();
    475   if (count($groups_granted_ids) > 0) {
     497  if (count($ec_lists['groups_granted_ids']) > 0) {
    476498    $granted_groups = array();
    477499
     
    479501      SELECT `user_id`, `group_id`
    480502      FROM `".USER_GROUP_TABLE."`
    481       WHERE `group_id` IN (".implode(',', $groups_granted_ids).");
     503      WHERE `group_id` IN (".implode(',', $ec_lists['groups_granted_ids']).");
    482504    ");
    483505    while ($row = mysql_fetch_array($result)) {
     
    498520      array_diff(
    499521        array_unique($user_granted_by_group_ids),
    500         $users_granted_direct_ids
     522        $ec_lists['users_granted_direct_ids']
    501523      ),
    502524      $ec_lists['user_ids']
     
    505527     foreach ($granted_groups as $group_id => $group_users)
    506528      if (in_array($user_id, $group_users)) {
    507         $users_granted_ids[$user_id]= $groups[$group_id];
     529        $users_granted_ids[$user_id]= $ec_lists['groups'][$group_id];
    508530        break;
    509531      }
     
    518540        $users_granted_thks_types_ids,
    519541        $users_granted_thks_groups_ids,
    520         $users_granted_direct_ids
     542        $ec_lists['users_granted_direct_ids']
    521543      ),
    522544      $ec_lists['user_ids']
     
    531553    );
    532554   
    533     $template->assign('all_groups', $groups);
    534     $template->assign('groups_granted_ids', $groups_granted_ids);
     555    $template->assign('all_groups', $ec_lists['groups']);
     556    $template->assign('groups_granted_ids', $ec_lists['groups_granted_ids']);
    535557    $template->assign('groups_denied_ids', order_by_name(
    536       array_diff(array_keys($groups), $groups_granted_ids), $groups
     558      array_diff(
     559        array_keys($ec_lists['groups']),
     560        $ec_lists['groups_granted_ids']
     561      ),
     562      $ec_lists['groups']
    537563    ));
    538564    $template->assign('ec_gen_granted', $ec_gen_granted);
     
    543569    ));
    544570    $template->assign('all_users', $ec_lists['user_ids']);
    545     $template->assign('users_granted_direct_ids', $users_granted_direct_ids);
     571    $template->assign(
     572      'users_granted_direct_ids',
     573      $ec_lists['users_granted_direct_ids']
     574    );
    546575    $template->assign('users_denied_ids', $users_denied_ids);
    547576  }
    548577  $users_granted_ids = array_merge(
    549578    array_keys($users_granted_ids),
    550     $users_granted_direct_ids
     579    $ec_lists['users_granted_direct_ids']
    551580  );
    552581 
Note: See TracChangeset for help on using the changeset viewer.