Ignore:
Timestamp:
Nov 20, 2009, 10:56:32 PM (14 years ago)
Author:
LucMorizur
Message:

[Event Cats] Finish duplication management, configuration management, code cleaning

Location:
extensions/event_cats/include
Files:
3 edited

Legend:

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

    r4263 r4329  
    2323// +-----------------------------------------------------------------------+
    2424
    25 global $ec_conf, $page, $ec_conf_index;
     25global $ec_conf, $page, $ec_conf_index, $ec_conf_default,
     26       $ec_conf_possible_values;
    2627
    2728// $ec_conf initalization
    2829
     30// $ec_conf has numeric indexes (instead of string keys like 'activated',
     31// 'howto'...) because of its first reading, done with the "explode" function.
     32// It would be  very easy to build a string keys indexed array, thanks to
     33// following instructions :
     34/*
     35$t = mysql_fetch_row(pwg_query("
     36  SELECT `value`
     37  FROM `".CONFIG_TABLE."`
     38  WHERE `param` = 'event_cats';
     39"));
     40$ec_conf_temp = explode(',', $t[0]);
     41$ec_conf = array(); $i = 0;
     42foreach ($ec_conf_default as $k => $v) $ec_conf[$k] = ec_conf_temp[$i++];
     43*/
     44// Though, I prefer to keep $ec_conf with numeric indexes, so to be compelled
     45// to go through function change_ec_conf() to modify ec_conf, and thus update
     46// the DB at the same time.
     47
    2948$ec_conf_default = array( // PLUGIN CONFIGURATION ($ec_conf) :
    3049                          // ---------------------------------
    31   'activated'             // plugin activated
     50  'activated'             // plugin activated, 0 or 1
    3251    => '0',               //
    3352                          //
     53  'howto'                 // whether the small aknowledgement message has
     54    => '0',               // already been displayed, 0 or 1
     55                          //
    3456  'dup_allow'             // duplication allowance :
    35     => '0',               //   0 : no account ;
     57    => '2',               //   0 : no account ;
    3658                          //   1 : all accounts ;
    3759                          //   2 : specified by group and user ids ;
    3860                          //
     61  'duplic_display'        // duplication link display in the menubar :
     62    => '2',               //   0 : "Register" for everybody ;
     63                          //   1 : "Duplicate" for everybody ;
     64                          //   2 : "Register" only for generic accounts,
     65                          //       "Duplicate" for all other accounts ;
     66                          //
    3967  'auto_code_dg_nb'       // number of digits when creating a new code
    40     => '10',              // automatically
    41                           //
    42   'duplic_gen'            // whether Generic accounts allow to be duplicated
    43     => '0',               //
    44                           //
    45   'duplic_type'           // the kind of account type (Contacts, Friends,
    46     => '0',               // Family) allowed to duplicate account
    47                           //
    48   'howto'                 // whether the small aknowledgement message has
    49     => '0',               // already been displayed
     68    => '10',              // automatically, several values
    5069                          //
    5170  'unknown_code'          // what to do in case an unknown code is used with
     
    5776                          //
    5877  'unknown_code_ap_id'    // the id of the Additional Page which must be used
    59     => '0',               // in case of usage of an unknow code.
     78    => '0',               // in case of usage of an unknow code, several vals.
     79);
     80
     81$ec_conf_possible_values = array(
     82  'activated'          => array('0', '1'),
     83  'howto'              => array('0', '1'),
     84  'dup_allow'          => array('0', '1', '2'),
     85  'duplic_display'     => array('0', '1', '2'),
     86  'auto_code_dg_nb'    => array( '4',  '5',  '8', '10', '12', '15',
     87                                '16', '20', '24', '25', '30', '32'),
     88  'unknown_code'       => array('0', '1', '2'),
     89  'unknown_code_ap_id' => array()
    6090);
    6191
     
    101131 */
    102132function change_ec_conf($c, $v) {
    103   global $ec_conf, $page, $ec_conf_index;
     133  global $ec_conf, $page, $ec_conf_index, $ec_conf_possible_values;
    104134  if (array_key_exists($c, $ec_conf_index)) {
    105     $ec_conf[$ec_conf_index[$c]] = $v;
    106     return (pwg_query("
    107       UPDATE `".CONFIG_TABLE."`
    108       SET `value` = \"".implode(',', $ec_conf)."\"
    109       WHERE `param` = 'event_cats';
    110     ") !== false);
     135    if (
     136      count($ec_conf_possible_values[$c]) == 0 or
     137      in_array($v, $ec_conf_possible_values[$c])
     138    ) {
     139      $ec_conf[$ec_conf_index[$c]] = $v;
     140      return (pwg_query("
     141        UPDATE `".CONFIG_TABLE."`
     142        SET `value` = \"".implode(',', $ec_conf)."\"
     143        WHERE `param` = 'event_cats';
     144      ") !== false);
     145    }
     146    else {
     147      $page['errors'][] = 'Bad change_ec_conf value';
     148      return false;
     149    }
    111150  }
    112151  else {
    113     $page['errors'][] = 'Bad change_ec_conf argument';
     152    $page['errors'][] = 'Bad change_ec_conf index';
    114153    return false;
    115154  }
     
    130169   return $ec_conf[$ec_conf_index[$c]];
    131170  else {
    132     $page['errors'][] = 'Bad read_ec_conf argument';
     171    $page['errors'][] = 'Bad read_ec_conf index';
    133172    return false;
    134173  }
  • extensions/event_cats/include/evntcats_admin_funcs.inc.php

    r4282 r4329  
    6363
    6464/*
     65 * ec_end2()
     66 * Process repetitive task when error in database modifying functions.
     67 *
     68 * @param
     69 *   $n : number to display
     70 * @return
     71 *   false as this function is used when there is a problem
     72 */
     73function ec_end2($n) {
     74  global $page;
     75  $page['errors'][] =
     76   sprintf(l10n('ec_DB_problem'), $n).
     77   'MySQL error '.mysql_errno().', "'.mysql_error().'"';
     78  return false;
     79}
     80
     81/*
    6582 * ec_create_user_OK()
    6683 * Creates new generic user and eventually new group as described in $_POST.
     
    92109  }
    93110  else
    94    $page['infos'][] = l10n('ec_user_create_OK').$_POST['login'];
     111   $page['infos'][] = sprintf(l10n('ec_user_create_OK'), $_POST['login']);
    95112  if (
    96113    pwg_query("
     
    100117    ") !== false
    101118  )
    102    $page['infos'][] = l10n('ec_user_generic_OK').$_POST['login'];
     119   $page['infos'][] = sprintf(l10n('ec_user_generic_OK'), $_POST['login']);
    103120  else
    104    $page['errors'][] =l10n('ec_user_generic_pb').$_POST['login'];
     121   $page['errors'][] = sprintf(l10n('ec_user_generic_pb'), $_POST['login']);
    105122 
    106123  // New group creation if required,
     
    124141      ");
    125142    if ($t4)
    126      $page['infos'][]=l10n('ec_group_create_OK').$_POST['groupname'];
     143     $page['infos'][] =
     144      sprintf(l10n('ec_group_create_OK'), $_POST['groupname']);
    127145    if (!$t3)
    128146     $page['errors'][] =
    129       l10n('ec_group_create_pb').' (1) ; '.
     147      sprintf(l10n('ec_group_create_pb'), $_POST['groupname']).' (1) : '.
    130148      'MySQL error '.mysql_errno().', "'.mysql_error().'"';
    131149    if (
     
    135153      ") === false
    136154    ) $page['errors'][] =
    137      l10n('ec_group_create_pb').' (2) ; '.
     155      sprintf(l10n('ec_group_create_pb'), $_POST['groupname']).' (2) : '.
    138156     'MySQL error '.mysql_errno().', "'.mysql_error().'"';
    139     else
    140      $page['infos'][] =
    141       $_POST['login'].
    142       l10n('ec_group_create_OK2').
    143       $_POST['groupname']
    144      ;
     157    else $page['infos'][] = sprintf(
     158      l10n('ec_group_create_OK2'),
     159      $_POST['login'], $_POST['groupname']
     160    );
    145161  }
    146162  return $ec_user_id;
     
    206222 
    207223  if (!isset($_POST['ec_act1']))
    208    return ec_end1('ec_act1', 'ec_bad_argument1');
     224   return ec_end1('ec_act1', 'Bad argument : ');
    209225 
    210226  if (
    211227    ($_POST['ec_act1']) != 'toggle_forced' and
    212228    !isset($_POST['ec_input_action'])
    213   ) return ec_end1('ec_input_action', 'ec_bad_argument1');
     229  ) return ec_end1('ec_input_action', 'Bad argument : ');
    214230 
    215231  $is_creation = true;
     
    234250        !isset($_POST['ec_in_up_code']) or
    235251        !ereg('^[a-zA-Z0-9_-]{4,32}$', $_POST['ec_in_up_code'])
    236       ) return ec_end1('ec_in_up_code', 'ec_bad_argument7');
     252      ) return ec_end1('ec_in_up_code', 'Improper code : ');
    237253      else $ec_code = $_POST['ec_in_up_code'];
    238254     
    239255      foreach ($ec_lists['ec_table'] as $ec_entry)
    240256       if ($ec_code == $ec_entry['code'])
    241         return ec_end1('ec_in_up_code', 'ec_bad_argument2');
     257        return ec_end1('ec_in_up_code', 'Code already exists : ');
    242258     
    243259      if (
     
    246262          $_POST['ec_sel_user'] != 'old'
    247263        )
    248       ) return ec_end1('ec_sel_user', 'ec_bad_argument1');
     264      ) return ec_end1('ec_sel_user', 'Bad argument : ');
    249265   
    250266    case 'modify_entry_submit':
     
    256272            !isset($_POST['login']) or
    257273            $_POST['login'] == ''
    258           ) return ec_end1('login', 'ec_bad_argument1');
     274          ) return ec_end1('login', 'Bad argument : ');
    259275          if (in_array($_POST['login'], $ec_lists['user_ids']))
    260            return ec_end1('login', 'ec_bad_argument3');
     276           return ec_end1('login', 'User already exists : ');
    261277        }
    262278        elseif ($_POST['ec_sel_user'] == 'old') {
    263279          if (!isset($_POST['ec_in_up_usr_list']))
    264            return ec_end1('login', 'ec_bad_argument1');
     280           return ec_end1('login', 'Bad argument : ');
    265281          $ec_user_id = $_POST['ec_in_up_usr_list'];
    266282          if (!array_key_exists($ec_user_id, $ec_lists['user_ids']))
    267            return ec_end1('ec_in_up_usr_list', 'ec_bad_argument6');
     283           return ec_end1('ec_in_up_usr_list', 'User doesn\'t exist : ');
    268284        }
    269285        else $action = 'ec_nok';
     
    279295        !isset($_POST['ec_entry_sel']) or
    280296        !array_key_exists($_POST['ec_entry_sel'], $ec_lists['ec_table'])
    281       ) return ec_end1('ec_entry_sel', 'ec_bad_argument5');
     297      ) return ec_end1(
     298        'ec_entry_sel', 'Code doesn\'t exist or non-duplicable code : '
     299      );
    282300     
    283301      // Other checks for user type and value
     
    324342      if (!array_key_exists($_POST['ec_entry_sel'],
    325343       $ec_lists['duplicable_codes']['ids'])
    326       ) return ec_end1('ec_entry_sel', 'ec_bad_argument5');
     344      ) return ec_end1(
     345        'ec_entry_sel', 'Code doesn\'t exist or non-duplicable code : '
     346      );
    327347     
    328348    break;
    329     default: ec_end1('ec_act1', 'ec_bad_argument1');
     349    default: ec_end1('ec_act1', 'Bad argument : ');
    330350  }
    331351  // Pfew !
     
    336356      case 'add_p': // Additional Page
    337357        if (isset($_POST['ec_in_up_aps'])) $arg2 = $_POST['ec_in_up_aps'];
    338         else ec_end1('ec_in_up_aps', 'ec_bad_argument1');
     358        else ec_end1('ec_in_up_aps', 'Bad argument : ');
    339359        $arg1 = 'NULL';
    340360      break;
     
    345365          if ($_POST['ec_input_action'] == 'img') {
    346366            if (isset($_POST['ec_in_up_img'])) $arg2 = $_POST['ec_in_up_img'];
    347             else ec_end1('ec_in_up_img', 'ec_bad_argument1');
     367            else ec_end1('ec_in_up_img', 'Bad argument : ');
    348368          }
    349369          else $arg2 = 'NULL';
    350370        }
    351         else ec_end1('ec_in_up_cat', 'ec_bad_argument1');
     371        else ec_end1('ec_in_up_cat', 'Bad argument : ');
    352372      break;
    353373      case 'home':    // Home : nothing to do : "arg"s are ''
     
    355375        $arg1 = 'NULL'; $arg2 = 'NULL';
    356376      break;
    357       default: ec_end1('ec_input_action', 'ec_bad_argument1');
     377      default: ec_end1('ec_input_action', 'Bad argument : ');
    358378    }
    359379   
     
    361381    $forced = (isset($_POST['ec_in_up_forced'])) ? 'true' : 'false';
    362382    if ($_POST['ec_act1'] == 'duplicate_entry_submit' and $forced == 'true')
    363      return ec_end1('ec_in_up_forced', 'ec_bad_argument1');
     383     return ec_end1('ec_in_up_forced', 'Bad argument : ');
    364384   
    365385    // User and eventually group creation, if needed
     
    384404      AND `forced`  = '".$forced."'
    385405  "))) !== false) { // print("<pre>$arg1 $arg2<br>$q</pre>");
    386     $page['errors'][] = l10n('ec_entry_already_exists').$t1[0];
     406    $page['errors'][] = sprintf(l10n('ec_entry_already_exists'), $t1[0]);
    387407    return false;
    388408  }
     
    440460    ) {
    441461      $page['errors'][] =
    442        l10n('ec_entry_create_pb').
     462       l10n('ec_entry_create_pb').' : '.
    443463       'MySQL error '.mysql_errno().', "'.mysql_error().'"'
    444464      ;
     
    449469      $forced = ($forced == 'false') ? '' : l10n('ec_cnfrm_forced');
    450470      $page['infos'][] =
    451        l10n('ec_entry_create_OK').mysql_insert_id().' : '.
     471       sprintf(l10n('ec_entry_create_OK'), mysql_insert_id()).' : '.
    452472       $ec_code.' => '.
    453473       $ec_lists['user_ids'][$ec_user_id].$forced
     
    470490    ) {
    471491      $page['errors'][] =
    472        l10n('ec_entry_create_pb').
     492       l10n('ec_entry_create_pb').' : '.
    473493       'MySQL error '.mysql_errno().', "'.mysql_error().'"'
    474494      ;
    475495      $ret = false;
    476496    }
    477     else $page['infos'][] = l10n('ec_entry_modify_OK').$_POST['ec_entry_sel'];
     497    else $page['infos'][] = sprintf(
     498      l10n('ec_entry_modify_OK'), $_POST['ec_entry_sel']
     499    );
    478500  }
    479501  build_ec_lists();
     
    492514function ec_delete_entry_OK($ec_id) {
    493515  global $page;
    494   if (!pwg_query("
     516  if (pwg_query("
    495517    DELETE FROM `".EVNTCATS_TABLE."`
    496518    WHERE `id` = ".$ec_id
    497   )) {
     519  ) === false) {
    498520    $page['errors'][] =
    499      l10n('ec_entry_del_nok_pre').
    500      $ec_id.
    501      l10n('ec_entry_del_nok_end').
     521     sprintf(l10n('ec_entry_del_nok'),
     522     $ec_id).
    502523     'MySQL error '.mysql_errno().', "'.mysql_error().'"';
    503524    return false;
    504525  }
    505   else $page['infos'][] =
    506    l10n('ec_entry_del_ok_pre').
    507    $ec_id.
    508    l10n('ec_entry_del_ok_end');
     526  else $page['infos'][] = sprintf(l10n('ec_entry_del_ok'), $ec_id);
    509527  return true;
    510528}
  • extensions/event_cats/include/evntcats_main_funcs.inc.php

    r4282 r4329  
    180180 */
    181181function build_ec_addp() {
    182   global $ec_lists, $ec_ap_ok;
    183   if ($ec_ap_ok) {
     182  global $ec_lists;
     183  if (EC_AP_OK) {
    184184    $res = pwg_query("SELECT `id`, `title` FROM `".ADD_PAGES_TABLE."`");
    185185    while ($r = mysql_fetch_assoc($res)) {
     
    244244 */
    245245function build_ec_table() {
    246   global $ec_lists, $ec_ap_ok;
     246  global $ec_lists;
    247247 
    248248  $q = pwg_query("
     
    287287      case 2: // Additional Page
    288288        if (
    289           $ec_ap_ok and (
     289          EC_AP_OK and (
    290290            is_in($ec_entry['action'], 'ec_ok') or
    291291            $ec_entry['action'] == 'ec_nok'
     
    322322function build_ec_lists() {
    323323 
    324   global $ec_ap_ok, $template, $ec_lists, $conf;
    325  
    326324  // Construction of $ec_lists['add_pages'] array var
    327325  build_ec_addp();
     
    373371        FROM ".EVNTCATS_TABLE."
    374372        WHERE `code` IS NULL
    375           AND `arg1` = '1'
     373          AND `arg1` = 1
    376374          AND `arg2` IS NOT NULL
    377375      ;",
     
    385383    array_from_query("
    386384      SELECT `arg2`
    387         FROM ".EVNTCATS_TABLE."
     385        FROM `".EVNTCATS_TABLE."`
    388386        WHERE `code` IS NULL
    389           AND `arg1` = '2'
     387          AND `arg1` = 2
    390388          AND `arg2` IS NOT NULL
    391389      ;",
     
    400398  $users_granted_ids = array();
    401399 
     400  $c = (count($t = mysql_fetch_row(pwg_query("
     401    SELECT `arg2`
     402    FROM `".EVNTCATS_TABLE."`
     403    WHERE `code` IS NULL
     404      AND `arg1` = 3
     405      AND `arg2` IS NOT NULL
     406    LIMIT 1;
     407  "))) == 0) ? 0 : intval($t[0]);
     408 
    402409  $users_granted_thks_gen_ids = array();
    403   if ($ec_gen_granted = (read_ec_conf('duplic_gen') != '0')) {
     410  if ($ec_gen_granted = (($c & 8) != 0)) {
    404411    $users_granted_thks_gen_ids = order_by_name(
    405412      array_diff(
     
    425432  $types_granted_ids = array();
    426433  $users_granted_thks_types_ids = array();
    427   $c = intval(read_ec_conf('duplic_type'));
    428   if ($c != 0) {
     434  if (($c & 7) != 0) {
    429435    if (($c & 1) != 0) $types_granted_ids[] = '1';
    430436    if (($c & 2) != 0) $types_granted_ids[] = '2';
     
    547553  // Returns an array which values are all the user_ids allowed to display a
    548554  // "duplicate" link. The keys of this array are strange (for direct allowed
    549   // users, keys are usernames), but normally not used
     555  // users, keys are usernames), but should not used
    550556  return $users_granted_ids;
    551557}
     
    561567 */
    562568function dup_allowed($user_id) {
    563   return true;
     569  return in_array($user_id, build_dup_arrays());
    564570}
    565571
Note: See TracChangeset for help on using the changeset viewer.