Changeset 4436


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

Location:
extensions/event_cats
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/event_cats/admin/autolog_new.inc.php

    r4421 r4436  
    5858  if (
    5959    array_key_exists($_POST['ec_entry_sel'], $ec_lists['ec_table']) or
    60     $_POST['ec_entry_sel'] == '-1'
     60    $_POST['ec_entry_sel'] == '-1' or
     61    $_POST['ec_act1'] == 'delete' // occurs when last entry is deleted
    6162  ) {
    6263    switch ($_POST['ec_act1']) {
     
    6970      case 'create':
    7071        $ec_default_action = $_POST['ec_act1'];
    71         $ec_default_entry =  $_POST['ec_entry_sel'];
     72        $ec_default_entry  = $_POST['ec_entry_sel'];
     73      break;
     74      case 'delete':
     75        $ec_default_action = 'create';
     76        $ec_default_entry  = '-1';
    7277      break;
    7378      default:
  • extensions/event_cats/admin/evntcats_admin.php

    r4421 r4436  
    325325// +-----------------------------------------------------------------------+
    326326
    327 check_DB();
     327check_DB(); $ec_debug['ec_exist_entries'] = $ec_exist_entries;
    328328 
    329329if (
     
    331331  read_ec_conf('dup_allow') != '2'
    332332) $page['tab'] = 'config';
     333
     334if (!$ec_exist_entries and $page['tab'] == 'autolog_entries') $page['tab'] =
     335 (read_ec_conf('dup_allow') == '2' and $dup_entries_exist) ?
     336 'duplication' : 'autolog_new';
    333337
    334338$tabsheet = new tabsheet();
  • 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}
  • extensions/event_cats/include/evntcats_main_funcs.inc.php

    r4421 r4436  
    187187function build_ec_addp() {
    188188  global $ec_lists;
     189  $ec_lists['add_pages'] = array();
    189190  if (defined('ADD_PAGES_TABLE')) {
    190     $res = pwg_query("SELECT `id`, `title` FROM `".ADD_PAGES_TABLE."`");
    191     while ($r = mysql_fetch_assoc($res)) {
    192       $c = (is_in($r['title'], '/user_id=')) ? '/user_id=' : '/group_id=';
    193       $a = explode($c ,$r['title']);
    194       $ec_lists['add_pages'][$r['id']] = $a[0];
     191    $res = pwg_query("SELECT `id`, `title` FROM `".ADD_PAGES_TABLE."`;");
     192    while ($r = mysql_fetch_array($res)) {
     193      $a = (is_in($r['title'], '/user_id=')) ?
     194       explode('/user_id=' , $r['title']) : array($r['title']);
     195      $b = (is_in($a[0], '/group_id=')) ?
     196       explode('/group_id=' , $a[0]) : $a;
     197      $ec_lists['add_pages'][$r['id']] = $b[0];
    195198    }
    196199  }
     
    209212function build_ec_categories($dsp) {
    210213  global $template, $ec_lists;
     214  $ec_lists['categories'] = array();
    211215  $c = array();
    212216  display_select_cat_wrapper("
     
    228232function build_ec_userids() {
    229233  global $ec_lists, $conf;
     234  $ec_lists['user_ids'] = array();
    230235  $ec_lists['user_ids'] = simple_hash_from_query("
    231236    SELECT
     
    252257  global $ec_lists;
    253258 
     259  $ec_lists['ec_table'] = array();
    254260  $q = pwg_query("
    255     SELECT * FROM `".EVNTCATS_TABLE."`
     261    SELECT *
     262    FROM `".EVNTCATS_TABLE."`
    256263    WHERE `code` IS NOT NULL
    257264    ORDER BY `id`
  • extensions/event_cats/language/fr_FR/plugin.lang.php

    r4421 r4436  
    142142
    143143// Infos
    144 $lang['ec_user_create_OK']         = 'Création utilisateur %s';
     144$lang['ec_user_create_OK']         = 'Création utilisateur "%s"';
    145145$lang['ec_user_generic_OK']        = 'Utilisateur "%s" générique';
    146 $lang['ec_group_create_OK']        = 'Création groupe %s';
    147 $lang['ec_group_create_OK2']       = '%1$s associé à %2$s';
    148                                  // %1$s : username ; %2$s : group
    149 $lang['ec_entry_create_OK']        = 'Création entrée %s';
     146$lang['ec_group_create_OK']        = 'Création groupe "%s"';
     147$lang['ec_group_create_OK2']       = '"%1$s" associé à "%2$s"';
     148$lang['ec_entry_create_OK']        = 'Création entrée : %s';
    150149$lang['ec_cnfrm_forced']           = ' (affichage forcé)';
    151 $lang['ec_entry_modify_OK']        = 'Modification entrée %s';
    152 $lang['ec_entry_del_ok']           = 'Entrée %s supprimée.';
     150$lang['ec_entry_modify_OK']        = 'Modification entrée "%s"';
     151$lang['ec_entry_del_ok']           = 'Entrée %1$s ("%2$s") supprimée.';
    153152$lang['ec_config_saved']           = 'Configuration sauvegardée';
    154153// Errors
     
    159158$lang['ec_image_miss']             = 'image inexistante (probablement supprimée)';
    160159$lang['ec_add_page_miss']          = 'page Additional Pages inexistante (probablement supprimée)';
    161 $lang['ec_entry_del_nok']          = 'Problème avec suppression entrée %s : ';
     160$lang['ec_entry_del_nok']          = 'Problème avec suppression entrée "%s" : ';
    162161$lang['ec_user_create_pb']         = 'Création nouvel utilisateur impossible';
    163 $lang['ec_user_generic_pb']        = 'Problème passage générique utilisateur %s';
    164 $lang['ec_group_create_pb']        = 'Création groupe %s impossible';
     162$lang['ec_user_generic_pb']        = 'Problème passage générique utilisateur "%s"';
     163$lang['ec_group_create_pb']        = 'Création groupe "%s" impossible';
     164$lang['ec_user_access_AP']         = 'Attention à ce que la page "%1$s" soit autorisée pour l\'utilisateur "%2$s".';
    165165$lang['ec_entry_create_pb']        = 'Création entrée impossible';
    166 $lang['ec_entry_already_exists']   = 'Entrée %s déjà existante';
    167 $lang['ec_DB_problem']             = 'Problème d\'accès à la base (n°%s) : ';
     166$lang['ec_entry_already_exists']   = 'Entrée "%s" existe déjà avec exactement la même configuration';
     167$lang['ec_entry_dont_exist']       = 'Entrée %s inexistante';
     168$lang['ec_assoc_pb']               = 'Association "%1$s" à "%2$s" impossible';
     169$lang['ec_DB_problem']             = 'Problème d\'accès à la base (position %s) : ';
    168170
    169171// Entries table
  • extensions/event_cats/maintain.inc.php

    r4421 r4436  
    6868    )
    6969    DEFAULT CHARACTER SET utf8
    70     TYPE=MyISAM;
     70    ENGINE=MyISAM;
    7171  ") !== false);
    7272
Note: See TracChangeset for help on using the changeset viewer.