Changeset 4239 for extensions/event_cats


Ignore:
Timestamp:
Nov 10, 2009, 4:04:07 PM (14 years ago)
Author:
LucMorizur
Message:

[Event Cats] Improve configuration parameters management

Location:
extensions/event_cats
Files:
5 edited

Legend:

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

    r4219 r4239  
    3838if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    3939
    40 global $template, $conf, $lang, $test1, $prefixeTable, $ec_conf, $page, $ec_debug,
     40global $template, $conf, $lang, $prefixeTable, $ec_conf, $page, $ec_debug,
    4141 $ec_lists,   // array of following arrays :
    4242              //   $ec_lists['ec_table'] :
     
    6868  EVNTCATS_PATH.'admin/evntcats_theme.css">'
    6969);
    70 $ec_debug = array();
     70if (!isset($ec_debug)) $ec_debug = array();
    7171
    7272if (
     
    7575) change_ec_conf('auto_code_dg_nb', $_POST['ec_in_up_auto_code_length']);
    7676
    77 $ec_howto = (read_ec_conf('howto') == '0');
    78 if ($ec_howto) change_ec_conf('howto', '1');
     77if ($ec_howto = (read_ec_conf('howto') == '0')) change_ec_conf('howto', '1');
    7978
    8079build_ec_lists(); // in evntcats_main_funcs.php
  • extensions/event_cats/include/ec_conf.inc.php

    r4233 r4239  
    2323// +-----------------------------------------------------------------------+
    2424
    25 /*****************************************************************************
    26 Parameters ($ec_conf) :
    27  _ plugin activated ($ec_conf[0] <=> read_ec_conf('activated')) yes/no ;
    28  _ duplication allowance ($ec_conf[1] <=> read_ec_conf('dup_allow')) :
    29    0 : no account ;
    30    1 : all accounts ;
    31    2 : no account but those specified ;    \
    32    3 : all accounts but those specified ;  | could be different finally
    33  _ the number of digits when creating a new code automatically
    34    ($ec_conf[2] <=> read_ec_conf('auto_code_dg_nb')) ;
    35  _ the way the "register" link is displayed, together with the original $lang
    36    value for this label ( $ec_conf[3] <=> read_ec_conf('') ) ;
    37  _ whether the "how to" banner has already been displayed or not
    38    ($ec_conf[4] <=> read_ec_conf('howto')) ;
    39  _ what to do in case an unknown code is used with "autolog" parameter
    40    ($ec_conf[5] <=> read_ec_conf('unknown_code')) :
    41    0 : nothing ("goto" home page, index.php (not logged in of course)) ;
    42    1 : redirected to "access denied" page ;
    43    2 : redirected to an Additional Page precised below.
    44  _ the id of the Additional Page which must be used in case of usage of an
    45    unknow code ($ec_conf[6] <=> read_ec_conf('unknown_code_ap_id')).
    46 *****************************************************************************/
     25global $ec_conf, $page, $ec_conf_index;
    4726
    48 global $ec_conf, $page;
     27// $ec_conf initalization
    4928
    50 // $ec_conf initalization / check
    51 if ($t = mysql_fetch_row(pwg_query("
    52  SELECT `value`
    53  FROM `".CONFIG_TABLE."`
    54  WHERE `param` = 'event_cats';
    55 "))) $ec_conf = explode(',' , $t[0]);
    56 else {
    57   $ec_conf = explode(',' , '0,1,10,0,0,0,0');
    58   if (!change_ec_conf('activated', 0))
    59    $page['errors'][] = 'Error updating $ec_conf';
     29$ec_conf_default = array( // PLUGIN CONFIGURATION ($ec_conf) :
     30                          // ---------------------------------
     31  'activated'             // plugin activated
     32    => '0',               //
     33                          //
     34  'dup_allow'             // duplication allowance :
     35    => '0',               //   0 : no account ;
     36                          //   1 : all accounts ;
     37                          //   2 : specified by group and user ids ;
     38                          //
     39  'auto_code_dg_nb'       // number of digits when creating a new code
     40    => '10',              // automatically
     41                          //
     42  'reg_display'           // the way the "register" link is displayed,
     43    => '0',               // together with the original $lang value for this
     44                          // label
     45                          //
     46  'howto'                 // whether the small aknowledgement message has
     47    => '0',               // already been displayed
     48                          //
     49  'unknown_code'          // what to do in case an unknown code is used with
     50    => '1',               // "autolog" parameter :
     51                          //   0 : nothing (display home page, index.php (not
     52                          //       logged in of course)) ;
     53                          //   1 : display "access denied" page ;
     54                          //   2 : display an Additional Page precised below.
     55                          //
     56  'unknown_code_ap_id'    // the id of the Additional Page which must be used
     57    => '0',               // in case of usage of an unknow code.
     58);
     59
     60$ec_conf_index = array_flip(array_keys($ec_conf_default));
     61
     62$t = array(); $u = '0'; $v = false;
     63if ($v = (
     64  ($t = mysql_fetch_row(pwg_query("
     65    SELECT `value`
     66    FROM `".CONFIG_TABLE."`
     67    WHERE `param` = 'event_cats';
     68  "))) !== false)
     69) {
     70  $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index));
     71  $u = $ec_conf[0];
    6072}
     73// $v is false
     74//   _ if the entry in the table doesn't exist ;
     75//   _ if the entry in the table exists, but its number of parameters is
     76//     different than the number of default parameters.
     77// $u is '0' if the plugin has not yet been activated, '1' if it has been.
     78if (!$v) {
     79  $ec_conf = array_values($ec_conf_default);
     80  change_ec_conf('activated', $u);
     81}
     82// now :
     83//   _ the number of parameters is the same in the DB as the number of
     84//     default parameters ;
     85//   _ the parameters have the default values if needed ;
     86//   _ the plugin shows it is active if it is the case.
     87unset($t, $u, $v);
    6188
    6289/*
     
    7299 */
    73100function change_ec_conf($c, $v) {
    74   global $ec_conf, $page;
    75   switch ($c) {
    76     case 'activated':
    77       $ec_conf[0] = $v;
    78     break;
    79     case 'dup_allow':
    80       $ec_conf[1] = $v;
    81     break;
    82     case 'auto_code_dg_nb':
    83       $ec_conf[2] = $v;
    84     break;
    85     case 'reg_display':
    86       $ec_conf[3] = $v;
    87     break;
    88     case 'howto':
    89       $ec_conf[4] = $v;
    90     break;
    91     case 'unknown_code':
    92       $ec_conf[5] = $v;
    93     break;
    94     case 'unknown_code_ap_id':
    95       $ec_conf[6] = $v;
    96     break;
    97     default:
    98       $page['errors'][] = 'Bad change_ec_conf argument';
     101  global $ec_conf, $page, $ec_conf_index;
     102  if (array_key_exists($c, $ec_conf_index)) {
     103    $ec_conf[$ec_conf_index[$c]] = $v;
     104    return (pwg_query("
     105      UPDATE `".CONFIG_TABLE."`
     106      SET `value` = \"".implode(',', $ec_conf)."\"
     107      WHERE `param` = 'event_cats';
     108    ") !== false);
     109  }
     110  else {
     111    $page['errors'][] = 'Bad change_ec_conf argument';
    99112    return false;
    100113  }
    101   return (pwg_query("
    102    UPDATE `".CONFIG_TABLE."`
    103    SET `value` = \"".implode(',', $ec_conf)."\"
    104    WHERE `param` = 'event_cats';
    105   ") !== false);
    106114}
    107115
     
    116124 */
    117125function read_ec_conf($c) {
    118   global $ec_conf, $page;
    119   switch ($c) {
    120     case 'activated'         : return $ec_conf[0];
    121     case 'dup_allow'         : return $ec_conf[1];
    122     case 'auto_code_dg_nb'   : return $ec_conf[2];
    123     case 'reg_display'       : return $ec_conf[3];
    124     case 'howto'             : return $ec_conf[4];
    125     case 'unknown_code'      : return $ec_conf[5];
    126     case 'unknown_code_ap_id': return $ec_conf[6];
    127     default:
    128       $page['errors'][] = 'Bad read_ec_conf argument';
     126  global $ec_conf, $page, $ec_conf_index;
     127  if (array_key_exists($c, $ec_conf_index))
     128   return $ec_conf[$ec_conf_index[$c]];
     129  else {
     130    $page['errors'][] = 'Bad read_ec_conf argument';
    129131    return false;
    130132  }
  • extensions/event_cats/include/evntcats_main_funcs.inc.php

    r4219 r4239  
    3232// +-----------------------------------------------------------------------+
    3333
    34 global $conf;
    35 
    3634include_once(EVNTCATS_PATH.'include/ec_conf.inc.php');
    3735
     
    111109  $to_correct = array();
    112110 
     111  /*
    113112  // $to_correct is needed cause following code would not work everywhere :
    114   /*
    115113  foreach ($table as $value) {
    116114    if ($value == $value_to_check and $value == $problem) {
     
    196194 */
    197195function build_ec_table() {
    198   global $ec_lists, $conf, $ec_ap_ok;
     196  global $ec_lists, $ec_ap_ok;
    199197 
    200198  $ec_lists['ec_table'] = array();
  • extensions/event_cats/main.inc.php

    r4233 r4239  
    3838//ini_set('display_errors', true);
    3939
    40 global
    41   $conf, $prefixeTable,
     40global $conf, $prefixeTable, $ec_lists, $ec_debug,
    4241  $ec_ap_ok;   // whether Additional Pages is installed and activated
    4342
     
    4948$ec_ap_ok = defined('AP_DIR');
    5049
    51 if (!isset($ec_lists)) {
    52   $ec_lists = array();
    53 }
     50if (!isset($ec_lists)) $ec_lists = array();
    5451
    5552include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php');
  • extensions/event_cats/maintain.inc.php

    r4092 r4239  
    3737
    3838function plugin_uninstall() {
    39 
    4039  global $prefixeTable, $ec_conf;
    4140
     
    4645
    4746function plugin_install() {
    48 
    4947  global $prefixeTable;
    5048 
     
    133131
    134132*/
    135   pwg_query('
    136    INSERT INTO '.CONFIG_TABLE.' (param,value,comment)
    137    VALUES ("event_cats","0,1,0,0","Paramètres du plugin Event Cats");
    138   ');
    139   change_ec_conf('activated', 0);
     133  pwg_query("
     134    INSERT INTO `".CONFIG_TABLE."` (`param`,`value`,`comment`)
     135    VALUES ('event_cats','0','Paramètres du plugin Event Cats');
     136  ");
     137  change_ec_conf('activated', '0');
    140138  return $q;
    141139}
    142140
    143141function plugin_activate() {
    144   change_ec_conf('activated', 1);
     142  change_ec_conf('activated', '1');
    145143}
    146144
    147145function plugin_deactivate() {
    148   change_ec_conf('activated', 0);
     146  change_ec_conf('activated', '0');
    149147}
    150148
Note: See TracChangeset for help on using the changeset viewer.