Index: extensions/event_cats/include/ec_conf.inc.php
===================================================================
--- extensions/event_cats/include/ec_conf.inc.php	(revision 4233)
+++ extensions/event_cats/include/ec_conf.inc.php	(revision 4239)
@@ -23,40 +23,67 @@
 // +-----------------------------------------------------------------------+
 
-/*****************************************************************************
-Parameters ($ec_conf) :
- _ plugin activated ($ec_conf[0] <=> read_ec_conf('activated')) yes/no ;
- _ duplication allowance ($ec_conf[1] <=> read_ec_conf('dup_allow')) :
-   0 : no account ;
-   1 : all accounts ;
-   2 : no account but those specified ;    \
-   3 : all accounts but those specified ;  | could be different finally
- _ the number of digits when creating a new code automatically
-   ($ec_conf[2] <=> read_ec_conf('auto_code_dg_nb')) ;
- _ the way the "register" link is displayed, together with the original $lang
-   value for this label ( $ec_conf[3] <=> read_ec_conf('') ) ;
- _ whether the "how to" banner has already been displayed or not
-   ($ec_conf[4] <=> read_ec_conf('howto')) ;
- _ what to do in case an unknown code is used with "autolog" parameter
-   ($ec_conf[5] <=> read_ec_conf('unknown_code')) :
-   0 : nothing ("goto" home page, index.php (not logged in of course)) ;
-   1 : redirected to "access denied" page ;
-   2 : redirected to an Additional Page precised below.
- _ the id of the Additional Page which must be used in case of usage of an
-   unknow code ($ec_conf[6] <=> read_ec_conf('unknown_code_ap_id')).
-*****************************************************************************/
+global $ec_conf, $page, $ec_conf_index;
 
-global $ec_conf, $page;
+// $ec_conf initalization
 
-// $ec_conf initalization / check
-if ($t = mysql_fetch_row(pwg_query("
- SELECT `value`
- FROM `".CONFIG_TABLE."`
- WHERE `param` = 'event_cats';
-"))) $ec_conf = explode(',' , $t[0]);
-else {
-  $ec_conf = explode(',' , '0,1,10,0,0,0,0');
-  if (!change_ec_conf('activated', 0))
-   $page['errors'][] = 'Error updating $ec_conf';
+$ec_conf_default = array( // PLUGIN CONFIGURATION ($ec_conf) :
+                          // ---------------------------------
+  'activated'             // plugin activated
+    => '0',               // 
+                          // 
+  'dup_allow'             // duplication allowance :
+    => '0',               //   0 : no account ;
+                          //   1 : all accounts ;
+                          //   2 : specified by group and user ids ;
+                          // 
+  'auto_code_dg_nb'       // number of digits when creating a new code
+    => '10',              // automatically
+                          // 
+  'reg_display'           // the way the "register" link is displayed,
+    => '0',               // together with the original $lang value for this
+                          // label
+                          // 
+  'howto'                 // whether the small aknowledgement message has
+    => '0',               // already been displayed
+                          // 
+  'unknown_code'          // what to do in case an unknown code is used with
+    => '1',               // "autolog" parameter :
+                          //   0 : nothing (display home page, index.php (not
+                          //       logged in of course)) ;
+                          //   1 : display "access denied" page ;
+                          //   2 : display an Additional Page precised below.
+                          // 
+  'unknown_code_ap_id'    // the id of the Additional Page which must be used
+    => '0',               // in case of usage of an unknow code.
+);
+
+$ec_conf_index = array_flip(array_keys($ec_conf_default));
+
+$t = array(); $u = '0'; $v = false;
+if ($v = (
+  ($t = mysql_fetch_row(pwg_query("
+    SELECT `value`
+    FROM `".CONFIG_TABLE."`
+    WHERE `param` = 'event_cats';
+  "))) !== false)
+) {
+  $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index));
+  $u = $ec_conf[0];
 }
+// $v is false
+//   _ if the entry in the table doesn't exist ;
+//   _ if the entry in the table exists, but its number of parameters is
+//     different than the number of default parameters.
+// $u is '0' if the plugin has not yet been activated, '1' if it has been.
+if (!$v) {
+  $ec_conf = array_values($ec_conf_default);
+  change_ec_conf('activated', $u);
+}
+// now :
+//   _ the number of parameters is the same in the DB as the number of
+//     default parameters ;
+//   _ the parameters have the default values if needed ;
+//   _ the plugin shows it is active if it is the case.
+unset($t, $u, $v);
 
 /*
@@ -72,36 +99,17 @@
  */
 function change_ec_conf($c, $v) {
-  global $ec_conf, $page;
-  switch ($c) {
-    case 'activated':
-      $ec_conf[0] = $v;
-    break;
-    case 'dup_allow':
-      $ec_conf[1] = $v;
-    break;
-    case 'auto_code_dg_nb':
-      $ec_conf[2] = $v;
-    break;
-    case 'reg_display':
-      $ec_conf[3] = $v;
-    break;
-    case 'howto':
-      $ec_conf[4] = $v;
-    break;
-    case 'unknown_code':
-      $ec_conf[5] = $v;
-    break;
-    case 'unknown_code_ap_id':
-      $ec_conf[6] = $v;
-    break;
-    default:
-      $page['errors'][] = 'Bad change_ec_conf argument';
+  global $ec_conf, $page, $ec_conf_index;
+  if (array_key_exists($c, $ec_conf_index)) {
+    $ec_conf[$ec_conf_index[$c]] = $v;
+    return (pwg_query("
+      UPDATE `".CONFIG_TABLE."`
+      SET `value` = \"".implode(',', $ec_conf)."\"
+      WHERE `param` = 'event_cats';
+    ") !== false);
+  }
+  else {
+    $page['errors'][] = 'Bad change_ec_conf argument';
     return false;
   }
-  return (pwg_query("
-   UPDATE `".CONFIG_TABLE."`
-   SET `value` = \"".implode(',', $ec_conf)."\"
-   WHERE `param` = 'event_cats';
-  ") !== false);
 }
 
@@ -116,15 +124,9 @@
  */
 function read_ec_conf($c) {
-  global $ec_conf, $page;
-  switch ($c) {
-    case 'activated'         : return $ec_conf[0];
-    case 'dup_allow'         : return $ec_conf[1];
-    case 'auto_code_dg_nb'   : return $ec_conf[2];
-    case 'reg_display'       : return $ec_conf[3];
-    case 'howto'             : return $ec_conf[4];
-    case 'unknown_code'      : return $ec_conf[5];
-    case 'unknown_code_ap_id': return $ec_conf[6];
-    default:
-      $page['errors'][] = 'Bad read_ec_conf argument';
+  global $ec_conf, $page, $ec_conf_index;
+  if (array_key_exists($c, $ec_conf_index))
+   return $ec_conf[$ec_conf_index[$c]];
+  else {
+    $page['errors'][] = 'Bad read_ec_conf argument';
     return false;
   }
