Ignore:
Timestamp:
Nov 4, 2009, 7:14:50 PM (15 years ago)
Author:
LucMorizur
Message:

[Event Cats] Some debugging ; adapt certain labels so that it can be recognized in other modules

(See http://fr.piwigo.org/forum/viewtopic.php?pid=122608#p122608 ) mainly

File:
1 edited

Legend:

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

    r4179 r4181  
    6363
    6464/*
    65  * ec_end2()
    66  * Process repetitive task when error in database modifying functions.
    67  *
    68  * @param
    69  *   $msg : message
    70  *   $num : number precising the point where the error occurred
    71  * @return
    72  *   false as this function is used when there is a problem
    73  */
    74 function ec_end2($msg, $num) {
     65 * ec_create_user_OK()
     66 * Creates new generic user and eventually new group as described in $_POST.
     67 *
     68 * @param
     69 *   no param needed
     70 * @return
     71 *   the created user_id or false whether all operations suceeded or not
     72 */
     73function ec_create_user_OK() {
    7574  global $page;
    7675 
    77   return false;
     76  // This function assumes that the validity of the different indexes it uses,
     77  // have been checked before it is used.
     78 
     79  // User creation, as generic
     80  $ec_user_id = false;
     81  $page['errors'] = register_user(
     82   $_POST['login'], $_POST['password'], '', false
     83  );
     84  if (
     85    count($page['errors']) != 0 or
     86    !($ec_user_id = get_userid($_POST['login']))
     87  ) {
     88    array_unshift($page['errors'], l10n('ec_user_create_pb'));
     89    return false;
     90  }
     91  else
     92   $page['infos'][] = l10n('ec_user_create_OK').$_POST['login'];
     93  if (
     94    pwg_query("
     95      UPDATE `".USER_INFOS_TABLE."`
     96      SET `status` = 'generic'
     97      WHERE `user_id` = ".$ec_user_id.";
     98    ") !== false
     99  )
     100   $page['infos'][] = l10n('ec_user_generic_OK').$_POST['login'];
     101  else
     102   $page['errors'][] =l10n('ec_user_generic_pb').$_POST['login'];
     103 
     104  // New group creation if required,
     105  // and association with user_id at the same time
     106  if (
     107    isset($_POST['ec_in_up_newgroup']) and
     108    isset($_POST['groupname']) and
     109    $_POST['groupname'] != ''
     110  ) {
     111    $t2 = 0; $t3 = false; $t4 = false;
     112    while (
     113      !($t3 = mysql_fetch_row(pwg_query("
     114        SELECT `id`
     115        FROM `".GROUPS_TABLE."`
     116        WHERE `name` = '".$_POST['groupname']."';
     117      "))) and
     118      $t2++ == 0
     119    ) $t4 = pwg_query("
     120        INSERT INTO `".GROUPS_TABLE."` (`name`, `is_default`)
     121        VALUES ('".$_POST['groupname']."', 'false');
     122      ");
     123    if ($t4)
     124     $page['infos'][]=l10n('ec_group_create_OK').$_POST['groupname'];
     125    if (!$t3)
     126     $page['errors'][] =
     127      l10n('ec_group_create_pb').' (1) ; '.
     128      'MySQL error '.mysql_errno().', "'.mysql_error().'"';
     129    if (
     130      pwg_query("
     131        INSERT INTO `".USER_GROUP_TABLE."` (`user_id`, `group_id`)
     132        VALUES ('".$ec_user_id."', '".$t3[0]."');
     133      ") === false
     134    ) $page['errors'][] =
     135     l10n('ec_group_create_pb').' (2) ; '.
     136     'MySQL error '.mysql_errno().', "'.mysql_error().'"';
     137    else
     138     $page['infos'][] =
     139      $_POST['login'].
     140      l10n('ec_group_create_OK2').
     141      $_POST['groupname']
     142     ;
     143  }
     144  return $ec_user_id;
    78145}
    79146
     
    168235 
    169236  // code and user_id (if needed) are OK, creation can be done
    170   if ($_POST['ec_sel_user'] == 'new') {
    171    
    172     // User creation, as generic
    173     $page['errors'] = register_user(
    174      $_POST['login'], $_POST['password'], '', false
    175     );
    176     if (
    177       count($page['errors']) != 0 or
    178       !($ec_user_id = get_userid($_POST['login']))
    179     ) {
    180       array_unshift($page['errors'], l10n('ec_user_create_pb'));
    181       return false;
    182     }
    183     else
    184      $page['infos'][] = l10n('ec_user_create_OK').$_POST['login'];
    185     if (
    186       pwg_query("
    187         UPDATE `".USER_INFOS_TABLE."`
    188         SET `status` = 'generic'
    189         WHERE `user_id` = ".$ec_user_id.";
    190       ") !== false
    191     )
    192      $page['infos'][] = l10n('ec_user_generic_OK').$_POST['login'];
    193     else
    194      $page['errors'][] =l10n('ec_user_generic_pb').$_POST['login'];
    195    
    196     // New group creation if required,
    197     // and association with user_id at the same time
    198     if (
    199       isset($_POST['ec_in_up_newgroup']) and
    200       isset($_POST['ec_in_up_grp_txt']) and
    201       $_POST['ec_in_up_grp_txt'] != ''
    202     ) {
    203       $t2 = 0; $t4 = false;
    204       while (
    205         !($t3 = mysql_fetch_row(pwg_query("
    206           SELECT `id`
    207           FROM `".GROUPS_TABLE."`
    208           WHERE `name` = '".$_POST['ec_in_up_grp_txt']."';
    209         "))) and
    210         $t2++ == 0
    211       ) $t4 = pwg_query("
    212           INSERT INTO `".GROUPS_TABLE."` (`name`, `is_default`)
    213           VALUES ('".$_POST['ec_in_up_grp_txt']."', 'false');
    214         ");
    215       if ($t4)
    216        $page['infos'][]=l10n('ec_group_create_OK').$_POST['ec_in_up_grp_txt'];
    217       if (!$t3)
    218        $page['errors'][] =
    219         l10n('ec_group_create_pb').' (1) ; '.
    220         'MySQL error '.mysql_errno().', "'.mysql_error().'"';
    221       if (
    222         pwg_query("
    223           INSERT INTO `".USER_GROUP_TABLE."` (`user_id`, `group_id`)
    224           VALUES ('".$ec_user_id."', '".$t3[0]."');
    225         ") === false
    226       ) $page['errors'][] =
    227        l10n('ec_group_create_pb').' (2) ; '.
    228        'MySQL error '.mysql_errno().', "'.mysql_error().'"';
    229       else
    230        $page['infos'][] =
    231         $_POST['login'].
    232         l10n('ec_group_create_OK2').
    233         $_POST['ec_in_up_grp_txt']
    234        ;
    235     }
    236   }
     237 
     238  // User and eventually group creation, if needed
     239  if ($_POST['ec_sel_user'] == 'new')
     240   if (!($ec_user_id = ec_create_user_OK())) return false;
    237241 
    238242  // Preparation of $arg1, $arg2 and $forced
     
    293297    return true;
    294298  }
    295   /*
    296  
    297   $page['errors'][] = 'Y\'a p\'têt\' ben eu une erreur...';
    298  
    299    */
    300299}
    301300
     
    318317    $arg1 = ''; $arg2 = '';
    319318    switch ($_POST['ec_input_action']) {
     319      // case 'home':  // Home : nothing to do : "arg"s are ''
    320320      case 'add_p':
    321321        if (array_key_exists($_POST['ec_in_up_aps'],$ec_lists['add_pages'])) {
    322322         $arg2 = $_POST['ec_in_up_aps']; }
    323323        else return ec_end1('ec_in_up_aps', 'ec_bad_argument4');
    324       case 'home':
    325       break;
    326324      case 'img':
    327325      case 'cat':
Note: See TracChangeset for help on using the changeset viewer.