Changeset 4173


Ignore:
Timestamp:
Nov 2, 2009, 10:46:10 PM (14 years ago)
Author:
LucMorizur
Message:

[Event Cats] Continue entry creation in DB

Location:
extensions/event_cats
Files:
7 edited

Legend:

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

    r4171 r4173  
    110110$template->assign('ec_ap_ok',               $ec_ap_ok);
    111111$template->assign('ec_lists',               $ec_lists);
    112 $template->assign('cat_display',            (read_ec_conf('cat_display') == '0'));
    113112$template->assign('ec_default_entry',       $ec_default_entry);
    114113$template->assign('ec_default_action',      $ec_default_action);
  • extensions/event_cats/admin/template/autolog_new.js

    r4171 r4173  
    77var ec_flag1                    = false;
    88var ec_flag2                    = false;
    9 var cat_display                 = false;
    109var ec_dont_check               = false;
    1110var ec_selected_old_group       = false;
     
    445444            d.ec_new_code.ec_in_up_cat.selectedIndex
    446445           ].label;
    447           if (cat_display) ec_new_user_text =
     446          /* if (cat_display) ec_new_user_text =
    448447           (ec_reg_cat2.test(ec_cat_sel)) ?
    449448            ec_reg_cat1.exec(ec_cat_sel)[1] : ec_cat_sel;
    450           else ec_new_user_text = ec_reg_cat3.exec(ec_cat_sel)[1];
     449          else */ ec_new_user_text = ec_reg_cat3.exec(ec_cat_sel)[1];
    451450          ec_new_user_text = ec_new_user_text.replace(/\s/g, '_');
    452451          ec_new_user_text = ec_new_user_text.substr(0, 32);
  • extensions/event_cats/admin/template/autolog_new.tpl

    r4171 r4173  
    267267<script type = "text/javascript"><!--
    268268  ec_is_creation                          = {if $ec_is_creation}true{else}false{/if};
    269   cat_display                             = {if $cat_display}true{else}false{/if};
    270269  ec_up_code_lbl_forced_txt               = "{'ec_up_code_lbl_forced'|@translate}";
    271270  ec_JS_message['ec_gen_user_act_miss']   = "{'ec_gen_user_act_miss'|@translate|@escape:javascript}";
  • extensions/event_cats/include/ec_conf.inc.php

    r4171 r4173  
    3333 _ the number of digits when creating a new code automatically
    3434   ($ec_conf[2] <=> read_ec_conf('auto_code_dg_nb')) ;
    35  _ whether categories are displayed "cat / under_cat / ..." or
    36    "cat <CR LF> - under_cat <CR LF> - ..." ($ec_conf[3] <=>
    37    read_ec_conf('cat_display')) ;
     35 _ -----------------------------------------------------------
     36   --------------------------------------- ( $ec_conf[3] <=>
     37   read_ec_conf('') ) ;
    3838 _ whether the "how to" banner has already been displayed or not
    3939   ($ec_conf[4] <=> read_ec_conf('howto')) ;
     
    4747*****************************************************************************/
    4848
    49 global $ec_conf;
     49global $ec_conf, $page;
    5050
    5151// $ec_conf initalization / check
     
    5454 FROM `".CONFIG_TABLE."`
    5555 WHERE `param` = 'event_cats';
    56 "))) {
    57   $ec_conf = explode(',' , $t[0]);
    58 }
     56"))) $ec_conf = explode(',' , $t[0]);
    5957else {
    6058  $ec_conf = explode(',' , '0,1,10,0,0,0,0');
    61   change_ec_conf('activated', 0);
     59  if (!change_ec_conf('activated', 0))
     60   $page['errors'][] = 'Error updating $ec_conf';
    6261}
    6362
     
    7473 */
    7574function change_ec_conf($c, $v) {
    76   global $ec_conf;
     75  global $ec_conf, $page;
    7776  switch ($c) {
    7877    case 'activated':
     
    8483    case 'auto_code_dg_nb':
    8584      $ec_conf[2] = $v;
    86     break;
     85    break;                  /*
    8786    case 'cat_display':
    8887      $ec_conf[3] = $v;
    89     break;
     88    break;                  */
    9089    case 'howto':
    9190      $ec_conf[4] = $v;
     
    9796      $ec_conf[6] = $v;
    9897    break;
    99     default: return false;
     98    default:
     99      $page['errors'][] = 'Bad change_ec_conf argument';
     100    return false;
    100101  }
    101   return pwg_query("
     102  return (pwg_query("
    102103   UPDATE `".CONFIG_TABLE."`
    103104   SET `value` = '".implode(',', $ec_conf)."'
    104105   WHERE `param` = 'event_cats';
    105   ");
     106  ") !== false);
    106107}
    107108
     
    116117 */
    117118function read_ec_conf($c) {
    118   global $ec_conf;
     119  global $ec_conf, $page;
    119120  switch ($c) {
    120121    case 'activated'         : return $ec_conf[0];
    121122    case 'dup_allow'         : return $ec_conf[1];
    122     case 'auto_code_dg_nb'   : return $ec_conf[2];
    123     case 'cat_display'       : return $ec_conf[3];
     123    case 'auto_code_dg_nb'   : return $ec_conf[2]; /*
     124    case 'cat_display'       : return $ec_conf[3]; */
    124125    case 'howto'             : return $ec_conf[4];
    125126    case 'unknown_code'      : return $ec_conf[5];
    126127    case 'unknown_code_ap_id': return $ec_conf[6];
    127     default                  : return false;
     128    default:
     129      $page['errors'][] = 'Bad read_ec_conf argument';
     130    return false;
    128131  }
    129132}
  • extensions/event_cats/include/evntcats_admin_funcs.inc.php

    r4169 r4173  
    9292 */
    9393function build_ec_duplicable_codes() {
    94   global $ec_lists;
     94  global $ec_lists, $template;
    9595  $ec_lists['duplicable_codes'] = array();
    9696  $t                            = array();
     
    111111     $ec_lists['duplicable_codes']['codes'][$ec_code]['id'];
    112112  }
     113 
     114  // Builds a category list displayed a best way
     115  build_ec_categories(false);
    113116}
    114117
     
    148151)
    149152
     153(
     154    [ec_act1] => create
     155    [ec_entry_sel] => -1
     156    [ec_sel_code] => new
     157    [ec_in_up_auto_code_length] => 10
     158    [ec_in_up_code] => NU1pah0qVJ
     159    [ec_in_up_usr_txt] =>
     160    [ec_in_up_psd_txt] =>
     161    [ec_in_up_grp_txt] =>
     162    [ec_sel_user] => old
     163    [ec_in_up_usr_list] => 9
     164    [ec_input_action] => cat
     165    [ec_in_up_cat] => 6
     166    [ec_in_up_img] =>
     167)
     168
    150169*/
    151   /* foreach ($ec_lists['ec_table'] as $ec_entry) {
    152     if ($_POST['ec_in_up_code'] == $ec_entry['code'])
    153       return ec_end1('ec_in_up_code', 'ec_bad_argument2');
    154   }
    155   if ($t1 = (in_array($_POST['ec_in_up_usr_txt'], $ec_lists['user_ids'])))
    156    $ec_user_id = $_POST['ec_in_up_usr_txt'];
     170  // $_POST validity checks : creation prevented in case of bad arguments
     171  /* if (
     172    !isset($_POST['ec_in_up_code']) or
     173    !ereg('^[a-zA-Z0-9_-]{4,32}$', $_POST['ec_in_up_code'])
     174  ) return ec_end1('ec_in_up_code', 'ec_bad_argument7');
     175 
     176  foreach ($ec_lists['ec_table'] as $ec_entry)
     177   if ($_POST['ec_in_up_code'] == $ec_entry['code'])
     178    return ec_end1('ec_in_up_code', 'ec_bad_argument2');
     179 
     180  if (
     181    !isset($_POST['ec_sel_user']) or (
     182      $_POST['ec_sel_user'] != 'new' and
     183      $_POST['ec_sel_user'] != 'old'
     184    )
     185  ) return ec_end1('ec_sel_user', 'ec_bad_argument1');
     186 
    157187  if ($_POST['ec_sel_user'] == 'new') {
     188    if (
     189      !isset($_POST['ec_in_up_usr_txt']) or
     190      $_POST['ec_in_up_usr_txt'] == ''
     191    ) return ec_end1('ec_in_up_usr_txt', 'ec_bad_argument1');
     192    $t1 = (in_array($_POST['ec_in_up_usr_txt'], $ec_lists['user_ids']));
    158193    if ($t1) return ec_end1('ec_in_up_usr_txt', 'ec_bad_argument3');
    159     else { // New user account creation
    160       $page['errors'] = register_user(
    161        $_POST['ec_in_up_usr_txt'], $_POST['ec_in_up_psd_txt'], '', false
    162       );
     194  }
     195  else {
     196    if (!isset($_POST['ec_in_up_usr_list']))
     197     return ec_end1('ec_in_up_usr_txt', 'ec_bad_argument1');
     198    $ec_user_id = $_POST['ec_in_up_usr_list'];
     199    $t1 = (array_key_exists($ec_user_id, $ec_lists['user_ids']));
     200    if (!$t1) return ec_end1('ec_in_up_usr_list', 'ec_bad_argument6');
     201  }
     202 
     203  // code and user_id (if needed) are OK, creation can be done
     204  if ($_POST['ec_sel_user'] == 'new') {
     205    $page['errors'] = register_user(
     206     $_POST['ec_in_up_usr_txt'], $_POST['ec_in_up_psd_txt'], '', false
     207    );
     208    if (
     209      count($page['errors']) != 0 or
     210      !($ec_user_id = get_userid($_POST['ec_in_up_usr_txt'])) or
     211      !pwg_query("
     212        UPDATE `".USER_INFOS_TABLE."`
     213        SET `status` = 'generic'
     214        WHERE `user_id` = ".$ec_user_id.";
     215      ")
     216    ) {
     217      array_unshift($page['errors'], l10n('ec_user_create_pb'));
     218      return false;
     219    }
     220    else $page['infos'][] = l10n('ec_user_create_OK').$ec_user_id;
     221    if (
     222      isset($_POST['ec_in_up_newgroup']) and
     223      isset($_POST['ec_in_up_grp_txt']) and
     224      $_POST['ec_in_up_grp_txt'] != ''
     225    ) { // New group creation, and association with user_id at the same time
    163226      if (
    164         count($page['errors']) != 0 or
    165         !($ec_user_id = get_userid($_POST['ec_in_up_usr_txt'])) or
    166         !pwg_query("
    167           UPDATE `".USER_INFOS_TABLE."`
    168           SET `status` = 'generic'
    169           WHERE `user_id` = ".$ec_user_id.";
    170         ")
     227        !($t = mysql_fetch_row(pwg_query("
     228          SELECT `id`
     229          FROM `".GROUPS_TABLE."`
     230          WHERE `name` = '".$_POST['ec_in_up_grp_txt']."';
     231        ")))
    171232      ) {
    172         array_unshift($page['errors'], l10n('ec_user_create_pb'));
    173         return false;
    174       }
    175       if (
    176         isset($_POST['ec_in_up_newgroup']) and
    177         isset($_POST['ec_in_up_grp_txt']) and
    178         $_POST['ec_in_up_grp_txt'] != ''
    179       ) { // New group creation, and association with user_id at the same time
     233        if (
     234          !pwg_query("
     235            INSERT INTO `".GROUPS_TABLE."` (`name`, `is_default`)
     236            VALUES ('".$_POST['ec_in_up_grp_txt']."', 'false');
     237          ")
     238        ) return ec_end2('ec_group_create_pb', '1');
    180239        if (
    181240          !($t = mysql_fetch_row(pwg_query("
     
    184243            WHERE `name` = '".$_POST['ec_in_up_grp_txt']."';
    185244          ")))
    186         ) {
    187           if (
    188             !pwg_query("
    189               INSERT INTO `".GROUPS_TABLE."` (`name`, `is_default`)
    190               VALUES ('".$_POST['ec_in_up_grp_txt']."', 'false');
    191             ")
    192           ) return ec_end2('ec_group_create_pb', '1');
    193           if (
    194             !($t = mysql_fetch_row(pwg_query("
    195               SELECT `id`
    196               FROM `".GROUPS_TABLE."`
    197               WHERE `name` = '".$_POST['ec_in_up_grp_txt']."';
    198             ")))
    199           ) return ec_end2('ec_group_create_pb', '2');
    200         }
    201         if (
    202           !(pwg_query("
    203             INSERT INTO `".USER_GROUP_TABLE."` (`user_id `, `group_id`)
    204             VALUES ('".$ec_user_id."', '".$t['id']."');
    205           "))
    206         ) return ec_end2('ec_group_create_pb', '3');
     245        ) return ec_end2('ec_group_create_pb', '2');
    207246      }
     247      if (
     248        !(pwg_query("
     249          INSERT INTO `".USER_GROUP_TABLE."` (`user_id `, `group_id`)
     250          VALUES ('".$ec_user_id."', '".$t['id']."');
     251        "))
     252      ) return ec_end2('ec_group_create_pb', '3');
    208253    }
    209254  }
    210255  else {
    211256    if ($t1) {
    212       if (ereg('^[a-zA-Z0-9_-]{4,32}$',$_POST['ec_in_up_code'])) {
    213         $arg1 = ''; $arg2 = '';
    214         switch ($_POST['ec_input_action']) {
    215           // case 'home':  // Home : nothing to do : "arg"s are ''
    216           case 'add_p': // Additional Page
    217           break;
    218           case 'cat':   // Category
    219           case 'img':   // Image
    220           break;
    221           default : return ec_end1('ec_input_action', 'ec_bad_argument1');
    222         }
     257     
     258      $arg1 = ''; $arg2 = '';
     259      switch ($_POST['ec_input_action']) {
     260        // case 'home':  // Home : nothing to do : "arg"s are ''
     261        case 'add_p': // Additional Page
     262        break;
     263        case 'cat':   // Category
     264        case 'img':   // Image
     265        break;
     266        default : return ec_end1('ec_input_action', 'ec_bad_argument1');
    223267      }
     268     
    224269      else return ec_end1('ec_in_up_code', 'ec_bad_argument7');
    225270    }
  • extensions/event_cats/include/evntcats_main_funcs.inc.php

    r4171 r4173  
    162162
    163163/*
     164 * build_ec_categories($dsp)
     165 * builds $ec_lists['categories'].
     166 *
     167 * @param
     168 *   whether $ec_lists['categories'] must be of type "cat / sub-cat" or
     169 *   or "cat <CR LF> - sub-cat".
     170 * @return
     171 *   (no return value)
     172 */
     173function build_ec_categories($dsp) {
     174  global $template, $ec_lists;
     175  $c = array();
     176  display_select_cat_wrapper('
     177     SELECT id,name,uppercats,global_rank
     178     FROM '.CATEGORIES_TABLE,
     179   $c, 'category_options', $dsp);
     180  $ec_lists['categories'] = $template->smarty->_tpl_vars['category_options'];
     181}
     182
     183/*
    164184 * build_ec_table()
    165185 * builds a table showing the content of the <pwg>_event_cats database table,
     
    326346 
    327347  // Construction of $ec_lists['categories'] array var
    328   $c = array();
    329   display_select_cat_wrapper('
    330      SELECT id,name,uppercats,global_rank
    331      FROM '.CATEGORIES_TABLE,
    332    $c, 'category_options', (read_ec_conf('cat_display') == '0'));
    333   $ec_lists['categories'] = $template->smarty->_tpl_vars['category_options'];
     348  build_ec_categories(true);
    334349 
    335350  // Construction of $ec_lists['user_ids'] array var
  • extensions/event_cats/language/fr_FR/plugin.lang.php

    r4171 r4173  
    113113$lang['ec_entry_dis_nok_end3']    = ' (arg1 = NULL)';
    114114$lang['ec_user_create_pb']        = 'Création nouvel utilisateur impossible';
     115$lang['ec_user_create_OK']        = 'Création utilisateur ';
    115116$lang['ec_group_create_pb']       = 'Création nouveau groupe impossible : ';
    116117$lang['ec_bad_argument1']         = 'Mauvais argument : ';
Note: See TracChangeset for help on using the changeset viewer.