Index: extensions/event_cats/admin/evntcats_admin.php
===================================================================
--- extensions/event_cats/admin/evntcats_admin.php	(revision 4163)
+++ extensions/event_cats/admin/evntcats_admin.php	(revision 4169)
@@ -57,5 +57,6 @@
 include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
 include_once(PHPWG_ROOT_PATH.'include/functions_url.inc.php');
-include_once(EVNTCATS_PATH.'include/evntcats_funcs.inc.php');
+include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php');
+include_once(EVNTCATS_PATH.'include/evntcats_admin_funcs.inc.php');
 $my_base_url = get_admin_plugin_menu_link(__FILE__);
 
@@ -76,5 +77,5 @@
 if ($ec_howto) change_ec_conf('howto', '1');
 
-build_ec_lists(); // in evntcats_funcs.php
+build_ec_lists(); // in evntcats_main_funcs.php
 
 // +-----------------------------------------------------------------------+
Index: extensions/event_cats/include/evntcats_admin_funcs.inc.php
===================================================================
--- extensions/event_cats/include/evntcats_admin_funcs.inc.php	(revision 4169)
+++ extensions/event_cats/include/evntcats_admin_funcs.inc.php	(revision 4169)
@@ -0,0 +1,372 @@
+<?php
+
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// ***************************************************************************
+// ** evntcats_admin_funcs.php : Admin functions (include)                  **
+// ** for Piwigo plugin Event Cats                                          **
+// ***************************************************************************
+
+// +-----------------------------------------------------------------------+
+// | Header                                                                |
+// +-----------------------------------------------------------------------+
+
+global $conf, $page;
+
+// +-----------------------------------------------------------------------+
+// | Utilities functions                                                   |
+// +-----------------------------------------------------------------------+
+
+/*
+ * ec_end1()
+ * Process repetitive task when error in database modifying functions.
+ *
+ * @param
+ *   $pst : $_POST argument
+ *   $msg : message
+ * @return
+ *   false as this function is used when there is a problem
+ */
+function ec_end1($pst, $msg) {
+  global $page;
+  $page['errors'][] =
+   l10n($msg).
+   '$_POST[\''.$pst.'\'] = '.
+   $_POST[$pst]
+  ;
+  return false;
+}
+
+/*
+ * ec_end2()
+ * Process repetitive task when error in database modifying functions.
+ *
+ * @param
+ *   $msg : message
+ *   $num : number precising the point where the error occurred
+ * @return
+ *   false as this function is used when there is a problem
+ */
+function ec_end2($msg, $num) {
+  global $page;
+  $page['errors'][] =
+   l10n($msg).' ('.$num.') '.
+   'MySQL error '.mysql_errno().', "'.mysql_error().'"'
+  ;
+  return false;
+}
+
+// +-----------------------------------------------------------------------+
+// | Tables building functions                                             |
+// +-----------------------------------------------------------------------+
+
+/*
+ * build_ec_duplicable_codes()
+ * 
+ *
+ * @param
+ *   no parameter passed, the main material on which works the function, is
+ *   the global array variable $ec_lists.
+ * @return
+ *   (no return value)
+ */
+function build_ec_duplicable_codes() {
+  global $ec_lists;
+  $ec_lists['duplicable_codes'] = array();
+  $t                            = array();
+  foreach ($ec_lists['ec_table'] as $ec_entry) {
+    if (
+      is_in($ec_entry['action'], 'ec_ok') and
+      $ec_entry['forced'] == 'false'
+    ) {
+      $t[$ec_entry['id']] = $ec_entry['code'];
+      $ec_lists['duplicable_codes']['codes'][$ec_entry['code']]['id'] =
+       $ec_entry['id'];
+      $ec_lists['duplicable_codes']['codes'][$ec_entry['code']]['user_id'] =
+       $ec_entry['user_id'];
+    }
+  }
+  foreach ($t as $ec_id => $ec_code) {
+    $ec_lists['duplicable_codes']['ids'][$ec_id] =
+     $ec_lists['duplicable_codes']['codes'][$ec_code]['id'];
+  }
+}
+
+// +-----------------------------------------------------------------------+
+// | Database modifying functions                                          |
+// +-----------------------------------------------------------------------+
+
+/*
+ * ec_create_entry_OK()
+ * returns true or false whether the creation of a new entry described by
+ * $_POST was OK or not.
+ *
+ * @param
+ *   no param
+ * @return
+ *   true if creation was OK ; false if not
+ */
+function ec_create_entry_OK() {
+  global $page, $ec_lists;
+  
+/*
+
+(
+    [ec_act1] => create
+    [ec_entry_sel] => -1
+    [ec_sel_code] => new
+    [ec_in_up_auto_code_length] => 10
+    [ec_in_up_code] => 94q0V1067D
+    [ec_sel_user] => new
+    [ec_in_up_usr_txt] => san_gimi
+    [ec_in_up_psd_txt] => 7Mv8QxZV
+    [ec_in_up_newgroup] => on
+    [ec_in_up_grp_txt] => EC_san_gimi
+    [ec_input_action] => cat
+    [ec_in_up_cat] => 6
+    [ec_in_up_img] => 
+)
+
+*/
+  /* foreach ($ec_lists['ec_table'] as $ec_entry) {
+    if ($_POST['ec_in_up_code'] == $ec_entry['code'])
+      return ec_end1('ec_in_up_code', 'ec_bad_argument2');
+  }
+  if ($t1 = (in_array($_POST['ec_in_up_usr_txt'], $ec_lists['user_ids'])))
+   $ec_user_id = $_POST['ec_in_up_usr_txt'];
+  if ($_POST['ec_sel_user'] == 'new') {
+    if ($t1) return ec_end1('ec_in_up_usr_txt', 'ec_bad_argument3');
+    else { // New user account creation
+      $page['errors'] = register_user(
+       $_POST['ec_in_up_usr_txt'], $_POST['ec_in_up_psd_txt'], '', false
+      );
+      if (
+        count($page['errors']) != 0 or
+        !($ec_user_id = get_userid($_POST['ec_in_up_usr_txt'])) or
+        !pwg_query("
+          UPDATE `".USER_INFOS_TABLE."`
+          SET `status` = 'generic'
+          WHERE `user_id` = ".$ec_user_id.";
+        ")
+      ) {
+        array_unshift($page['errors'], l10n('ec_user_create_pb'));
+        return false;
+      }
+      if (
+        isset($_POST['ec_in_up_newgroup']) and
+        isset($_POST['ec_in_up_grp_txt']) and
+        $_POST['ec_in_up_grp_txt'] != ''
+      ) { // New group creation, and association with user_id at the same time
+        if (
+          !($t = mysql_fetch_row(pwg_query("
+            SELECT `id`
+            FROM `".GROUPS_TABLE."`
+            WHERE `name` = '".$_POST['ec_in_up_grp_txt']."';
+          ")))
+        ) {
+          if (
+            !pwg_query("
+              INSERT INTO `".GROUPS_TABLE."` (`name`, `is_default`)
+              VALUES ('".$_POST['ec_in_up_grp_txt']."', 'false');
+            ")
+          ) return ec_end2('ec_group_create_pb', '1');
+          if (
+            !($t = mysql_fetch_row(pwg_query("
+              SELECT `id`
+              FROM `".GROUPS_TABLE."`
+              WHERE `name` = '".$_POST['ec_in_up_grp_txt']."';
+            ")))
+          ) return ec_end2('ec_group_create_pb', '2');
+        }
+        if (
+          !(pwg_query("
+            INSERT INTO `".USER_GROUP_TABLE."` (`user_id `, `group_id`)
+            VALUES ('".$ec_user_id."', '".$t['id']."');
+          "))
+        ) return ec_end2('ec_group_create_pb', '3');
+      }
+    }
+  }
+  else {
+    if ($t1) {
+      if (ereg('^[a-zA-Z0-9_-]{4,32}$',$_POST['ec_in_up_code'])) {
+        $arg1 = ''; $arg2 = '';
+        switch ($_POST['ec_input_action']) {
+          // case 'home':  // Home : nothing to do : "arg"s are ''
+          case 'add_p': // Additional Page
+          break;
+          case 'cat':   // Category
+          case 'img':   // Image
+          break;
+          default : return ec_end1('ec_input_action', 'ec_bad_argument1');
+        }
+      }
+      else return ec_end1('ec_in_up_code', 'ec_bad_argument7');
+    }
+    else return ec_end1('ec_in_up_usr_txt', 'ec_bad_argument6');
+  }
+  */
+  
+  $page['errors'][] = 'Y\'a p\'têt\' ben eu une erreur...';
+}
+
+/*
+ * ec_duplicate_entry_OK()
+ * returns true or false whether the duplication of an existing entry which #
+ * is given by $_POST['ec_entry_sel'] was OK or not.
+ *
+ * @param
+ *   no param
+ * @return
+ *   true if creation was OK ; false if not
+ */
+function ec_duplicate_entry_OK() {
+  global $page, $ec_lists;
+  
+  build_ec_duplicable_codes();
+  if (array_key_exists($_POST['ec_entry_sel'],
+   $ec_lists['duplicable_codes']['ids'])) {
+    $arg1 = ''; $arg2 = '';
+    switch ($_POST['ec_input_action']) {
+      case 'add_p':
+        if (array_key_exists($_POST['ec_in_up_aps'],$ec_lists['add_pages'])) {
+         $arg2 = $_POST['ec_in_up_aps']; }
+        else return ec_end1('ec_in_up_aps', 'ec_bad_argument4');
+      case 'home':
+      break;
+      case 'img':
+      case 'cat':
+        if (array_key_exists($_POST['ec_in_up_cat'],
+         $ec_lists['categories'])) {
+          if ($_POST['ec_input_action'] == 'img') {
+            if (
+             ec_image_exists($_POST['ec_in_up_cat'], $_POST['ec_in_up_img'])
+            ) $arg2 = $_POST['ec_in_up_img'];
+            else return ec_end1('ec_in_up_img', 'ec_bad_argument4');
+          }
+          $arg1 = $_POST['ec_in_up_cat'];
+        }
+        else return ec_end1('ec_in_up_cat', 'ec_bad_argument4');
+      break;
+      default: return ec_end1('ec_input_action', 'ec_bad_argument1');
+    }
+    if (pwg_query("
+      INSERT INTO `".EVNTCATS_TABLE."`
+       (`code`, `user_id`, `action`, `arg1`, `arg2`)
+      VALUES (
+        '".$ec_lists['ec_table'][$_POST['ec_entry_sel']]['code']."',
+        '".$ec_lists['ec_table'][$_POST['ec_entry_sel']]['user_id']."',
+        'ec_ok',
+        '".$arg1."',
+        '".$arg2."'
+      );
+    ")) {
+      $page['infos'][] =
+       l10n('ec_entry_dup_ok_pre').
+       $_POST['ec_entry_sel'].' ('.
+       $ec_lists['ec_table'][$_POST['ec_entry_sel']]['code'].')'.
+       l10n('ec_entry_dup_ok_end')
+      ;
+      build_ec_table();
+      return true;
+    }
+    else {
+      $page['errors'][] =
+       l10n('ec_entry_dup_nok_pre1').
+       $_POST['ec_entry_sel'].
+       l10n('ec_entry_dup_nok_end1').
+       'MySQL error '.mysql_errno().', "'.mysql_error().'"'
+      ;
+      return false;
+    }
+  }
+  else return ec_end1('ec_entry_sel', 'ec_bad_argument5');
+}
+
+/*
+ * ec_modify_entry_OK()
+ * returns true or false whether the modification of an existing entry which #
+ * is given by $_POST['ec_entry_sel'] was OK or not.
+ *
+ * @param
+ *   no param
+ * @return
+ *   true if modification was OK ; false if not
+ */
+function ec_modify_entry_OK() {
+  global $page;
+  $page['errors'][] = 'Y\'a pas eu une erreur ?...';
+  return false;
+}
+
+/*
+ * ec_toggle_forced_entry()
+ * Toggles the 'forced' property of an entry, provided it complies to the
+ * rules.
+ *
+ * @param
+ *   no param
+ * @return
+ *   no return value
+ */
+function ec_toggle_forced_entry() {
+  global $page;
+  $page['errors'][] = 'ec_toggle_forced_entry';
+}
+
+/*
+ * ec_delete_entry()
+ * tries to delete an existing entry which # is given by
+ * $_POST['ec_entry_sel'].
+ *
+ * @param
+ *   no param
+ * @return
+ *   no return value : modifies $page['errors'] or $page['infos']
+ */
+function ec_delete_entry() {
+  global $page, $ec_lists;
+  if (array_key_exists($_POST['ec_entry_sel'], $ec_lists['ec_table'])) {
+    if (!pwg_query('
+      DELETE FROM `'.EVNTCATS_TABLE.'`
+      WHERE `id` = '.$_POST['ec_entry_sel']
+    )) {
+      $page['errors'][] =
+        l10n('ec_entry_del_nok_pre').
+        $_POST['ec_entry_sel'].
+        l10n('ec_entry_del_nok_end').
+        'MySQL error '.mysql_errno().', "'.mysql_error().'"'
+      ;
+    }
+    else {
+      $page['infos'][] =
+        l10n('ec_entry_del_ok_pre').
+        $_POST['ec_entry_sel'].
+        l10n('ec_entry_del_ok_end');
+      build_ec_table();
+    }
+  }
+  else ec_end1('ec_entry_sel', 'ec_bad_argument1');
+}
+
+?>
Index: extensions/event_cats/include/evntcats_funcs.inc.php
===================================================================
--- extensions/event_cats/include/evntcats_funcs.inc.php	(revision 4163)
+++ 	(revision )
@@ -1,666 +1,0 @@
-<?php
-
-// +-----------------------------------------------------------------------+
-// | Piwigo - a PHP based picture gallery                                  |
-// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
-// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
-// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
-// +-----------------------------------------------------------------------+
-// | This program is free software; you can redistribute it and/or modify  |
-// | it under the terms of the GNU General Public License as published by  |
-// | the Free Software Foundation                                          |
-// |                                                                       |
-// | This program is distributed in the hope that it will be useful, but   |
-// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
-// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
-// | General Public License for more details.                              |
-// |                                                                       |
-// | You should have received a copy of the GNU General Public License     |
-// | along with this program; if not, write to the Free Software           |
-// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
-// | USA.                                                                  |
-// +-----------------------------------------------------------------------+
-
-// ***************************************************************************
-// ** evntcats_funcs.php : Functions (include) for Piwigo plugin Event Cats **
-// ***************************************************************************
-
-// +-----------------------------------------------------------------------+
-// | Header                                                                |
-// +-----------------------------------------------------------------------+
-
-global $conf;
-
-include_once(EVNTCATS_PATH.'include/ec_conf.inc.php');
-
-// +-----------------------------------------------------------------------+
-// | Utilities functions                                                   |
-// +-----------------------------------------------------------------------+
-
-/*
- * is_in($haystack, $needle)
- * returns true or false whether $needle is a string found in string $haystack
- *
- * @param
- *   $haystack : the string in which to search
- *   $needle   : the string looked for
- * @return
- *   true if $needle is found in $haystack ; false if not
- */
-function is_in($haystack, $needle) {
-  return (strpos($haystack, $needle) !== false);
-}
-
-/*
- * ec_image_exists($cat, $img)
- * returns true or false whether the image is associated with the category.
- *
- * @param
- *   $cat : the category
- *   $img : the image
- * @return
- *   treu or false whether the image is associated with the category.
- */
-function ec_image_exists($cat, $img) {
-  return (mysql_fetch_row(pwg_query('
-   SELECT *
-   FROM `'.IMAGE_CATEGORY_TABLE.'` 
-   WHERE `category_id` = '.$cat.'
-    AND `image_id` = '.$img
-  )) !== false);
-}
-
-/*
- * str_from_var($var)
- * returns a string easing array var informations displaying in Piwigo :
- *   _ the string return value starts with"<p align="left">" ;
- *   _ all "TAB" characters (chr(10)) are replaced by "<br>" ;
- *   _ all spaces are replaced by "&nbsp;".
- *
- * @param
- *   $var : variable to display
- * @return
- *   string easy to display in Piwigo
- */
-function str_from_var($var) {
-  return '<p align="left">'.str_replace(chr(10),'<br>',str_replace(' ','&nbsp;', print_r /* var_dump */ ($var,true))).'</p>';
-}
-
-/*
- * ec_inspect()
- * goes through ec_lists['ec_table'] to check errors on (multiple) entries
- * using the same code. Cannot be used elsewhere than here in
- * build_ec_table() .
- *
- * @param
- *   
- * @return
- *   (no return value)
- */
-function ec_inspect($checked_item, $new_action, $check_ec_nok = true) {
-  global $ec_lists;
-  $first = array();
-  $to_correct = array();
-  
-  // $to_correct is needed cause following code would not work everywhere :
-  /*
-  foreach ($table as $value) {
-    if ($value == $value_to_check and $value == $problem) {
-      foreach ($table as &$value2) { // key index of $table can be reset
-        if ($value2 == $value_to_check) {
-          $value2 = $better_value;
-        }
-      }
-    }
-  }
-  // It works with WinAmp Server, but not on Apache server of Free (french
-  // Internet provider).
-  */
-  
-  foreach ($ec_lists['ec_table'] as &$ec_entry) { // & is not really needed
-    $ec_current_code = $ec_entry['code'];
-    if (
-     $ec_entry['action'] == 'ec_ok' or
-     ($check_ec_nok and $ec_entry['action'] == 'ec_nok')
-    ) {
-      if (isset($first[$ec_current_code])) {
-        // $first[$ec_current_code] is set <=> code has already been met.
-        // Checked item MUST be equal to the first item (thus all items) for
-        // this code.
-        if (
-         $first[$ec_current_code] != $ec_entry[$checked_item] or
-         ($new_action == '' and $ec_entry[$checked_item] == 'true')
-        ) {
-          $to_correct[$ec_current_code] = true; // value not used in fact
-        } // but using $ec_current_code as a key makes a smaller table
-      } // if the error comes back several times
-      else {
-        $first[$ec_current_code] = $ec_entry[$checked_item];
-      }
-    }
-  }
-  foreach ($ec_lists['ec_table'] as &$ec_entry) { // & is needed here
-    if (isset($to_correct[$ec_entry['code']])) {
-      if ($new_action == '') {
-        if (!pwg_query('
-          UPDATE `'.EVNTCATS_TABLE.'`
-          SET `forced` = "false"
-          WHERE `id` = '.$ec_entry['id']
-        )) die('Could not fix a "_f_pb"');
-        $ec_entry['forced'] = 'false';
-      }
-      else $ec_entry['action'] = $new_action;
-    }
-  }
-}
-
-/*
- * ec_end1()
- * Process repetitive task when error in database modifying functions.
- *
- * @param
- *   $pst : $_POST argument
- *   $msg : message
- * @return
- *   false as this function is used when there is a problem
- */
-function ec_end1($pst, $msg) {
-  global $page;
-  $page['errors'][] =
-   l10n($msg).
-   '$_POST[\''.$pst.'\'] = '.
-   $_POST[$pst]
-  ;
-  return false;
-}
-
-/*
- * ec_end2()
- * Process repetitive task when error in database modifying functions.
- *
- * @param
- *   $msg : message
- *   $num : number precising the point where the error occurred
- * @return
- *   false as this function is used when there is a problem
- */
-function ec_end2($msg, $num) {
-  global $page;
-  $page['errors'][] =
-   l10n($msg).' ('.$num.') '.
-   'MySQL error '.mysql_errno().', "'.mysql_error().'"'
-  ;
-  return false;
-}
-
-// +-----------------------------------------------------------------------+
-// | Tables building functions                                             |
-// +-----------------------------------------------------------------------+
-
-/*
- * build_ec_table()
- * builds a table showing the content of the <pwg>_event_cats database table,
- * and a table showing the eventual errors.
- *
- * @param
- *   no parameters passed ; the main material on which works the function, is
- *   the global array variable $ec_lists.
- * @return
- *   (no return value)
- */
-function build_ec_table() {
-  global $ec_lists, $conf, $ec_ap_ok;
-  
-  $ec_lists['ec_table'] = array();
-  
-  if (isset($conf['auto_log'])) {
-    // For tests purpose : table not in MySQL, but in $conf['xxx'] vars in
-    // config_local.inc.php
-    
-    foreach ($conf['auto_log'] as $ec_current_code => $ec_entry) {
-      $ec_current_entry = array_push($ec_lists['ec_table'], array(
-       'code'    => $ec_current_code,
-       'user_id' => get_userid($ec_entry[$ec_current_code]),
-       'action'  => 'ec_ok',
-       'arg1'    => NULL,
-       'arg2'    => NULL,
-       'forced'  => 'false',
-      )) - 1;
-      $ec_lists['ec_table'][$ec_current_entry]['id'] = $ec_current_entry;
-      if (isset($conf['prior_page'])) {
-        if (array_key_exists($ec_current_code, $conf['prior_page'])) {
-          $ec_lists['ec_table'][$ec_current_entry]['arg2'] =
-           $conf['prior_page'][$ec_current_code];
-          $ec_lists['ec_table'][$ec_current_entry]['forced'] = 'true';
-        }
-      }
-      if (isset($conf['outdated_page'])) {
-        if (array_key_exists($ec_current_code, $conf['outdated_page'])) {
-          $ec_lists['ec_table'][$ec_current_entry]['action'] = 'ec_nok';
-          $ec_lists['ec_table'][$ec_current_entry]['arg2'] =
-           $conf['outdated_page'][$ec_current_code];
-          $ec_lists['ec_table'][$ec_current_entry]['forced'] = 'true';
-        }
-      }
-    }
-    
-    // Inspection of $conf['outdated_page']
-    if (isset($conf['outdated_page'])) {
-      foreach ($conf['outdated_page'] as $ec_current_code => $ec_current_AP) {
-        if (!array_key_exists($ec_current_code, $conf['auto_log'])) {
-          $ec_current_entry = array_push($ec_lists['ec_table'], array(
-           'code'    => $ec_current_code,
-           'user_id' => '',
-           'action'  => 'ec_nok',
-           'arg1'    => NULL,
-           'arg2'    => $ec_current_AP,
-           'forced'  => 'true',
-          )) - 1;
-          $ec_lists['ec_table'][$ec_current_entry]['id'] = $ec_current_entry;
-        }
-      }
-    }
-    
-  }
-  else { // in "normal" use ($conf['auto_log'] NOT set), $ec_lists['ec_table']
-         // is built thanks to below code only. A little bit more simple...
-    $q = pwg_query('
-     SELECT * FROM `'.EVNTCATS_TABLE.'`
-     WHERE `code` IS NOT NULL
-     ORDER BY `id`
-    ');
-    while ($r = mysql_fetch_assoc($q)) {
-      $ec_lists['ec_table'][intval($r['id'])] = $r;
-    }
-  }
-  
-  // Construction of behaviour
-  
-  // Multiple action params for a single code check
-  ec_inspect('action', 'ec_nok_action_pb');
-  
-  // Multiple user_ids for a single code check
-  ec_inspect('user_id', 'ec_nok_userid_pb', false);
-  
-  // Multiple "forced" params for a single code check
-  ec_inspect('forced', '');
-  
-  // User id and associated page validities checks
-  foreach ($ec_lists['ec_table'] as &$ec_entry) {
-    
-    // Check if associated user_id exists
-    if (
-     is_in($ec_entry['action'], 'ec_ok') and
-     !array_key_exists($ec_entry['user_id'], $ec_lists['user_ids'])
-    ) {
-      $ec_entry['action'] = 'ec_nok_userid_miss';
-    }
-    
-    // Check if associated displayed page exists
-    $a = 0;
-    if (!empty($ec_entry['arg1']) and
-     is_in($ec_entry['action'], 'ec_ok')) $a++; // Only arg2
-    // is significant if action is ec_nok[_xxx] .
-    if (!empty($ec_entry['arg2'])) $a+= 2;
-    switch ($a) {
-      // case 0 : home, nothing to check
-      
-      case 2: // Additional Page
-        if (
-          $ec_ap_ok and (
-            is_in($ec_entry['action'], 'ec_ok') or
-            $ec_entry['action'] == 'ec_nok'
-          ) and
-          !array_key_exists($ec_entry['arg2'], $ec_lists['add_pages'])
-        ) {
-          $ec_entry['action'].= '_ap_pb';
-        }
-      break;
-      
-      case 1: // Category
-      case 3: // Image
-        if (is_in($ec_entry['action'], 'ec_ok')) {
-          if (array_key_exists($ec_entry['arg1'], $ec_lists['categories'])) {
-            if ($a == 3) { // case 3: // Image
-              if (!ec_image_exists($ec_entry['arg1'], $ec_entry['arg2'])) {
-                $ec_entry['action'].= '_img_pb';
-              }
-            }
-          }
-          else {
-            $ec_entry['action'].= '_cat_pb';
-          }
-        }
-      break;
-    }
-  }
-}
-
-/*
- * build_ec_lists()
- * builds the main array variable contaning all informations for the plugin
- *
- * @param
- *   no parameter passed, the main material on which works the function, is
- *   the global array variable $ec_lists.
- * @return
- *   (no return value)
- */
-function build_ec_lists() {
-  
-  global $ec_ap_ok, $template, $ec_lists;
-  
-  $ec_lists = array();
-
-  // Construction of $ec_lists['add_pages'] array var
-  $ec_lists['add_pages'] = array();
-  if ($ec_ap_ok) {
-    $res = pwg_query('SELECT id,title FROM '.ADD_PAGES_TABLE);
-    while ($r = mysql_fetch_assoc($res)) {
-      $c = (is_in($r['title'], '/user_id=')) ? '/user_id=' : '/group_id=';
-      $a = explode($c ,$r['title']);
-      $ec_lists['add_pages'][$r['id']] = $a[0];
-    }
-  }
-  
-  // Construction of $ec_lists['categories'] array var
-  $c = array();
-  display_select_cat_wrapper('
-     SELECT id,name,uppercats,global_rank
-     FROM '.CATEGORIES_TABLE,
-   $c, 'category_options', true);
-  $ec_lists['categories'] = $template->smarty->_tpl_vars['category_options'];
-  
-  // Construction of $ec_lists['user_ids'] array var
-  $ec_lists['user_ids'] = array();
-  $q = pwg_query('SELECT id,username FROM '.USERS_TABLE. ' WHERE id > 2');
-  while ($r = mysql_fetch_assoc($q)) {
-    $ec_lists['user_ids'][$r['id']] = $r['username'];
-  }
-  
-  // Construction of $ec_lists['ec_table'] array var
-  build_ec_table();
-}
-
-/*
- * build_ec_duplicable_codes()
- * 
- *
- * @param
- *   no parameter passed, the main material on which works the function, is
- *   the global array variable $ec_lists.
- * @return
- *   (no return value)
- */
-function build_ec_duplicable_codes() {
-  global $ec_lists;
-  $ec_lists['duplicable_codes'] = array();
-  $t                            = array();
-  foreach ($ec_lists['ec_table'] as $ec_entry) {
-    if (
-      is_in($ec_entry['action'], 'ec_ok') and
-      $ec_entry['forced'] == 'false'
-    ) {
-      $t[$ec_entry['id']] = $ec_entry['code'];
-      $ec_lists['duplicable_codes']['codes'][$ec_entry['code']]['id'] =
-       $ec_entry['id'];
-      $ec_lists['duplicable_codes']['codes'][$ec_entry['code']]['user_id'] =
-       $ec_entry['user_id'];
-    }
-  }
-  foreach ($t as $ec_id => $ec_code) {
-    $ec_lists['duplicable_codes']['ids'][$ec_id] =
-     $ec_lists['duplicable_codes']['codes'][$ec_code]['id'];
-  }
-}
-
-// +-----------------------------------------------------------------------+
-// | Database modifying functions                                          |
-// +-----------------------------------------------------------------------+
-
-/*
- * ec_create_entry_OK()
- * returns true or false whether the creation of a new entry described by
- * $_POST was OK or not.
- *
- * @param
- *   no param
- * @return
- *   true if creation was OK ; false if not
- */
-function ec_create_entry_OK() {
-  global $page, $ec_lists;
-  
-/*
-
-(
-    [ec_act1] => create
-    [ec_entry_sel] => -1
-    [ec_sel_code] => new
-    [ec_in_up_auto_code_length] => 10
-    [ec_in_up_code] => 94q0V1067D
-    [ec_sel_user] => new
-    [ec_in_up_usr_txt] => san_gimi
-    [ec_in_up_psd_txt] => 7Mv8QxZV
-    [ec_in_up_newgroup] => on
-    [ec_in_up_grp_txt] => EC_san_gimi
-    [ec_input_action] => cat
-    [ec_in_up_cat] => 6
-    [ec_in_up_img] => 
-)
-
-*/
-  /* foreach ($ec_lists['ec_table'] as $ec_entry) {
-    if ($_POST['ec_in_up_code'] == $ec_entry['code'])
-      return ec_end1('ec_in_up_code', 'ec_bad_argument2');
-  }
-  if ($t1 = (in_array($_POST['ec_in_up_usr_txt'], $ec_lists['user_ids'])))
-   $ec_user_id = $_POST['ec_in_up_usr_txt'];
-  if ($_POST['ec_sel_user'] == 'new') {
-    if ($t1) return ec_end1('ec_in_up_usr_txt', 'ec_bad_argument3');
-    else { // New user account creation
-      $page['errors'] = register_user(
-       $_POST['ec_in_up_usr_txt'], $_POST['ec_in_up_psd_txt'], '', false
-      );
-      if (
-        count($page['errors']) != 0 or
-        !($ec_user_id = get_userid($_POST['ec_in_up_usr_txt'])) or
-        !pwg_query("
-          UPDATE `".USER_INFOS_TABLE."`
-          SET `status` = 'generic'
-          WHERE `user_id` = ".$ec_user_id.";
-        ")
-      ) {
-        array_unshift($page['errors'], l10n('ec_user_create_pb'));
-        return false;
-      }
-      if (
-        isset($_POST['ec_in_up_newgroup']) and
-        isset($_POST['ec_in_up_grp_txt']) and
-        $_POST['ec_in_up_grp_txt'] != ''
-      ) { // New group creation, and association with user_id at the same time
-        if (
-          !($t = mysql_fetch_row(pwg_query("
-            SELECT `id`
-            FROM `".GROUPS_TABLE."`
-            WHERE `name` = '".$_POST['ec_in_up_grp_txt']."';
-          ")))
-        ) {
-          if (
-            !pwg_query("
-              INSERT INTO `".GROUPS_TABLE."` (`name`, `is_default`)
-              VALUES ('".$_POST['ec_in_up_grp_txt']."', 'false');
-            ")
-          ) return ec_end2('ec_group_create_pb', '1');
-          if (
-            !($t = mysql_fetch_row(pwg_query("
-              SELECT `id`
-              FROM `".GROUPS_TABLE."`
-              WHERE `name` = '".$_POST['ec_in_up_grp_txt']."';
-            ")))
-          ) return ec_end2('ec_group_create_pb', '2');
-        }
-        if (
-          !(pwg_query("
-            INSERT INTO `".USER_GROUP_TABLE."` (`user_id `, `group_id`)
-            VALUES ('".$ec_user_id."', '".$t['id']."');
-          "))
-        ) return ec_end2('ec_group_create_pb', '3');
-      }
-    }
-  }
-  else {
-    if ($t1) {
-      if (ereg('^[a-zA-Z0-9_-]{4,32}$',$_POST['ec_in_up_code'])) {
-        if 
-      }
-      else return ec_end1('ec_in_up_code', 'ec_bad_argument7');
-    }
-    else return ec_end1('ec_in_up_usr_txt', 'ec_bad_argument6');
-  }
-  */
-  
-  $page['errors'][] = 'Y\'a p\'têt\' ben eu une erreur...';
-}
-
-/*
- * ec_duplicate_entry_OK()
- * returns true or false whether the duplication of an existing entry which #
- * is given by $_POST['ec_entry_sel'] was OK or not.
- *
- * @param
- *   no param
- * @return
- *   true if creation was OK ; false if not
- */
-function ec_duplicate_entry_OK() {
-  global $page, $ec_lists;
-  
-  build_ec_duplicable_codes();
-  if (array_key_exists($_POST['ec_entry_sel'],
-   $ec_lists['duplicable_codes']['ids'])) {
-    $arg1 = ''; $arg2 = '';
-    switch ($_POST['ec_input_action']) {
-      case 'add_p':
-        if (array_key_exists($_POST['ec_in_up_aps'],$ec_lists['add_pages'])) {
-         $arg2 = $_POST['ec_in_up_aps']; }
-        else return ec_end1('ec_in_up_aps', 'ec_bad_argument4');
-      case 'home':
-      break;
-      case 'img':
-      case 'cat':
-        if (array_key_exists($_POST['ec_in_up_cat'],
-         $ec_lists['categories'])) {
-          if ($_POST['ec_input_action'] == 'img') {
-            if (
-             ec_image_exists($_POST['ec_in_up_cat'], $_POST['ec_in_up_img'])
-            ) $arg2 = $_POST['ec_in_up_img'];
-            else return ec_end1('ec_in_up_img', 'ec_bad_argument4');
-          }
-          $arg1 = $_POST['ec_in_up_cat'];
-        }
-        else return ec_end1('ec_in_up_cat', 'ec_bad_argument4');
-      break;
-      default: return ec_end1('ec_input_action', 'ec_bad_argument1');
-    }
-    if (pwg_query("
-      INSERT INTO `".EVNTCATS_TABLE."`
-       (`code`, `user_id`, `action`, `arg1`, `arg2`)
-      VALUES (
-        '".$ec_lists['ec_table'][$_POST['ec_entry_sel']]['code']."',
-        '".$ec_lists['ec_table'][$_POST['ec_entry_sel']]['user_id']."',
-        'ec_ok',
-        '".$arg1."',
-        '".$arg2."'
-      );
-    ")) {
-      $page['infos'][] =
-       l10n('ec_entry_dup_ok_pre').
-       $_POST['ec_entry_sel'].' ('.
-       $ec_lists['ec_table'][$_POST['ec_entry_sel']]['code'].')'.
-       l10n('ec_entry_dup_ok_end')
-      ;
-      build_ec_table();
-      return true;
-    }
-    else {
-      $page['errors'][] =
-       l10n('ec_entry_dup_nok_pre1').
-       $_POST['ec_entry_sel'].
-       l10n('ec_entry_dup_nok_end1').
-       'MySQL error '.mysql_errno().', "'.mysql_error().'"'
-      ;
-      return false;
-    }
-  }
-  else return ec_end1('ec_entry_sel', 'ec_bad_argument5');
-}
-
-/*
- * ec_modify_entry_OK()
- * returns true or false whether the modification of an existing entry which #
- * is given by $_POST['ec_entry_sel'] was OK or not.
- *
- * @param
- *   no param
- * @return
- *   true if modification was OK ; false if not
- */
-function ec_modify_entry_OK() {
-  global $page;
-  $page['errors'][] = 'Y\'a pas eu une erreur ?...';
-  return false;
-}
-
-/*
- * ec_toggle_forced_entry()
- * Toggles the 'forced' property of an entry, provided it complies to the
- * rules.
- *
- * @param
- *   no param
- * @return
- *   no return value
- */
-function ec_toggle_forced_entry() {
-  global $page;
-  $page['errors'][] = 'ec_toggle_forced_entry';
-}
-
-/*
- * ec_delete_entry()
- * tries to delete an existing entry which # is given by
- * $_POST['ec_entry_sel'].
- *
- * @param
- *   no param
- * @return
- *   no return value : modifies $page['errors'] or $page['infos']
- */
-function ec_delete_entry() {
-  global $page, $ec_lists;
-  if (array_key_exists($_POST['ec_entry_sel'], $ec_lists['ec_table'])) {
-    if (!pwg_query('
-      DELETE FROM `'.EVNTCATS_TABLE.'`
-      WHERE `id` = '.$_POST['ec_entry_sel']
-    )) {
-      $page['errors'][] =
-        l10n('ec_entry_del_nok_pre').
-        $_POST['ec_entry_sel'].
-        l10n('ec_entry_del_nok_end').
-        'MySQL error '.mysql_errno().', "'.mysql_error().'"'
-      ;
-    }
-    else {
-      $page['infos'][] =
-        l10n('ec_entry_del_ok_pre').
-        $_POST['ec_entry_sel'].
-        l10n('ec_entry_del_ok_end');
-      build_ec_table();
-    }
-  }
-  else ec_end1('ec_entry_sel', 'ec_bad_argument1');
-}
-
-?>
Index: extensions/event_cats/include/evntcats_main_funcs.inc.php
===================================================================
--- extensions/event_cats/include/evntcats_main_funcs.inc.php	(revision 4169)
+++ extensions/event_cats/include/evntcats_main_funcs.inc.php	(revision 4169)
@@ -0,0 +1,348 @@
+<?php
+
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// ***************************************************************************
+// ** evntcats_admin_funcs.php : Main functions (include)                   **
+// ** for Piwigo plugin Event Cats                                          **
+// ***************************************************************************
+
+// +-----------------------------------------------------------------------+
+// | Header                                                                |
+// +-----------------------------------------------------------------------+
+
+global $conf;
+
+include_once(EVNTCATS_PATH.'include/ec_conf.inc.php');
+
+// +-----------------------------------------------------------------------+
+// | Utilities functions                                                   |
+// +-----------------------------------------------------------------------+
+
+/*
+ * is_in($haystack, $needle)
+ * returns true or false whether $needle is a string found in string $haystack
+ *
+ * @param
+ *   $haystack : the string in which to search
+ *   $needle   : the string looked for
+ * @return
+ *   true if $needle is found in $haystack ; false if not
+ */
+function is_in($haystack, $needle) {
+  return (strpos($haystack, $needle) !== false);
+}
+
+/*
+ * ec_image_exists($cat, $img)
+ * returns true or false whether the image is associated with the category.
+ *
+ * @param
+ *   $cat : the category
+ *   $img : the image
+ * @return
+ *   treu or false whether the image is associated with the category.
+ */
+function ec_image_exists($cat, $img) {
+  return (mysql_fetch_row(pwg_query('
+   SELECT *
+   FROM `'.IMAGE_CATEGORY_TABLE.'` 
+   WHERE `category_id` = '.$cat.'
+    AND `image_id` = '.$img
+  )) !== false);
+}
+
+/*
+ * str_from_var($var)
+ * returns a string easing array var informations displaying in Piwigo :
+ *   _ the string return value starts with"<p align="left">" ;
+ *   _ all "TAB" characters (chr(10)) are replaced by "<br>" ;
+ *   _ all spaces are replaced by "&nbsp;".
+ *
+ * @param
+ *   $var : variable to display
+ * @return
+ *   string easy to display in Piwigo
+ */
+function str_from_var($var) {
+  return '<p align="left">'.str_replace(chr(10),'<br>',str_replace(' ','&nbsp;', print_r /* var_dump */ ($var,true))).'</p>';
+}
+
+/*
+ * ec_inspect()
+ * goes through ec_lists['ec_table'] to check errors on (multiple) entries
+ * using the same code. Cannot really be used elsewhere than here in
+ * build_ec_table() .
+ *
+ * @param
+ *   
+ * @return
+ *   (no return value)
+ */
+function ec_inspect($checked_item, $new_action, $check_ec_nok = true) {
+  global $ec_lists;
+  $first = array();
+  $to_correct = array();
+  
+  // $to_correct is needed cause following code would not work everywhere :
+  /*
+  foreach ($table as $value) {
+    if ($value == $value_to_check and $value == $problem) {
+      foreach ($table as &$value2) { // key index of $table can be reset
+        if ($value2 == $value_to_check) {
+          $value2 = $better_value;
+        }
+      }
+    }
+  }
+  // It works with WinAmp Server, but not on Apache server of Free (french
+  // Internet provider).
+  */
+  
+  foreach ($ec_lists['ec_table'] as &$ec_entry) { // & is not really needed
+    $ec_current_code = $ec_entry['code'];
+    if (
+     $ec_entry['action'] == 'ec_ok' or
+     ($check_ec_nok and $ec_entry['action'] == 'ec_nok')
+    ) {
+      if (isset($first[$ec_current_code])) {
+        // $first[$ec_current_code] is set <=> code has already been met.
+        // Checked item MUST be equal to the first item (thus all items) for
+        // this code.
+        if (
+         $first[$ec_current_code] != $ec_entry[$checked_item] or
+         ($new_action == '' and $ec_entry[$checked_item] == 'true')
+        ) {
+          $to_correct[$ec_current_code] = true; // value not used in fact
+        } // but using $ec_current_code as a key makes a smaller table
+      } // if the error comes back several times
+      else {
+        $first[$ec_current_code] = $ec_entry[$checked_item];
+      }
+    }
+  }
+  foreach ($ec_lists['ec_table'] as &$ec_entry) { // & is needed here
+    if (isset($to_correct[$ec_entry['code']])) {
+      if ($new_action == '') {
+        if (!pwg_query('
+          UPDATE `'.EVNTCATS_TABLE.'`
+          SET `forced` = "false"
+          WHERE `id` = '.$ec_entry['id']
+        )) die('Could not fix a "_f_pb"');
+        $ec_entry['forced'] = 'false';
+      }
+      else $ec_entry['action'] = $new_action;
+    }
+  }
+}
+
+// +-----------------------------------------------------------------------+
+// | Tables building functions                                             |
+// +-----------------------------------------------------------------------+
+
+/*
+ * build_ec_table()
+ * builds a table showing the content of the <pwg>_event_cats database table,
+ * and a table showing the eventual errors.
+ *
+ * @param
+ *   no parameters passed ; the main material on which works the function, is
+ *   the global array variable $ec_lists.
+ * @return
+ *   (no return value)
+ */
+function build_ec_table() {
+  global $ec_lists, $conf, $ec_ap_ok;
+  
+  $ec_lists['ec_table'] = array();
+  
+  if (isset($conf['auto_log'])) {
+    // For tests purpose : table not in MySQL, but in $conf['xxx'] vars in
+    // config_local.inc.php
+    
+    foreach ($conf['auto_log'] as $ec_current_code => $ec_entry) {
+      $ec_current_entry = array_push($ec_lists['ec_table'], array(
+       'code'    => $ec_current_code,
+       'user_id' => get_userid($ec_entry[$ec_current_code]),
+       'action'  => 'ec_ok',
+       'arg1'    => NULL,
+       'arg2'    => NULL,
+       'forced'  => 'false',
+      )) - 1;
+      $ec_lists['ec_table'][$ec_current_entry]['id'] = $ec_current_entry;
+      if (isset($conf['prior_page'])) {
+        if (array_key_exists($ec_current_code, $conf['prior_page'])) {
+          $ec_lists['ec_table'][$ec_current_entry]['arg2'] =
+           $conf['prior_page'][$ec_current_code];
+          $ec_lists['ec_table'][$ec_current_entry]['forced'] = 'true';
+        }
+      }
+      if (isset($conf['outdated_page'])) {
+        if (array_key_exists($ec_current_code, $conf['outdated_page'])) {
+          $ec_lists['ec_table'][$ec_current_entry]['action'] = 'ec_nok';
+          $ec_lists['ec_table'][$ec_current_entry]['arg2'] =
+           $conf['outdated_page'][$ec_current_code];
+          $ec_lists['ec_table'][$ec_current_entry]['forced'] = 'true';
+        }
+      }
+    }
+    
+    // Inspection of $conf['outdated_page']
+    if (isset($conf['outdated_page'])) {
+      foreach ($conf['outdated_page'] as $ec_current_code => $ec_current_AP) {
+        if (!array_key_exists($ec_current_code, $conf['auto_log'])) {
+          $ec_current_entry = array_push($ec_lists['ec_table'], array(
+           'code'    => $ec_current_code,
+           'user_id' => '',
+           'action'  => 'ec_nok',
+           'arg1'    => NULL,
+           'arg2'    => $ec_current_AP,
+           'forced'  => 'true',
+          )) - 1;
+          $ec_lists['ec_table'][$ec_current_entry]['id'] = $ec_current_entry;
+        }
+      }
+    }
+    
+  }
+  else { // in "normal" use ($conf['auto_log'] NOT set), $ec_lists['ec_table']
+         // is built thanks to below code only. A little bit more simple...
+    $q = pwg_query('
+     SELECT * FROM `'.EVNTCATS_TABLE.'`
+     WHERE `code` IS NOT NULL
+     ORDER BY `id`
+    ');
+    while ($r = mysql_fetch_assoc($q)) {
+      $ec_lists['ec_table'][intval($r['id'])] = $r;
+    }
+  }
+  
+  // Construction of behaviour
+  
+  // Multiple action params for a single code check
+  ec_inspect('action', 'ec_nok_action_pb');
+  
+  // Multiple user_ids for a single code check
+  ec_inspect('user_id', 'ec_nok_userid_pb', false);
+  
+  // Multiple "forced" params for a single code check
+  ec_inspect('forced', '');
+  
+  // User id and associated page validities checks
+  foreach ($ec_lists['ec_table'] as &$ec_entry) {
+    
+    // Check if associated user_id exists
+    if (
+     is_in($ec_entry['action'], 'ec_ok') and
+     !array_key_exists($ec_entry['user_id'], $ec_lists['user_ids'])
+    ) {
+      $ec_entry['action'] = 'ec_nok_userid_miss';
+    }
+    
+    // Check if associated displayed page exists
+    $a = 0;
+    if (!empty($ec_entry['arg1']) and
+     is_in($ec_entry['action'], 'ec_ok')) $a++; // Only arg2
+    // is significant if action is ec_nok[_xxx] .
+    if (!empty($ec_entry['arg2'])) $a+= 2;
+    switch ($a) {
+      // case 0 : home, nothing to check
+      
+      case 2: // Additional Page
+        if (
+          $ec_ap_ok and (
+            is_in($ec_entry['action'], 'ec_ok') or
+            $ec_entry['action'] == 'ec_nok'
+          ) and
+          !array_key_exists($ec_entry['arg2'], $ec_lists['add_pages'])
+        ) {
+          $ec_entry['action'].= '_ap_pb';
+        }
+      break;
+      
+      case 1: // Category
+      case 3: // Image
+        if (is_in($ec_entry['action'], 'ec_ok')) {
+          if (array_key_exists($ec_entry['arg1'], $ec_lists['categories'])) {
+            if ($a == 3) { // case 3: // Image
+              if (!ec_image_exists($ec_entry['arg1'], $ec_entry['arg2'])) {
+                $ec_entry['action'].= '_img_pb';
+              }
+            }
+          }
+          else {
+            $ec_entry['action'].= '_cat_pb';
+          }
+        }
+      break;
+    }
+  }
+}
+
+/*
+ * build_ec_lists()
+ * builds the main array variable contaning all informations for the plugin
+ *
+ * @param
+ *   no parameter passed, the main material on which works the function, is
+ *   the global array variable $ec_lists.
+ * @return
+ *   (no return value)
+ */
+function build_ec_lists() {
+  
+  global $ec_ap_ok, $template, $ec_lists;
+  
+  $ec_lists = array();
+
+  // Construction of $ec_lists['add_pages'] array var
+  $ec_lists['add_pages'] = array();
+  if ($ec_ap_ok) {
+    $res = pwg_query('SELECT id,title FROM '.ADD_PAGES_TABLE);
+    while ($r = mysql_fetch_assoc($res)) {
+      $c = (is_in($r['title'], '/user_id=')) ? '/user_id=' : '/group_id=';
+      $a = explode($c ,$r['title']);
+      $ec_lists['add_pages'][$r['id']] = $a[0];
+    }
+  }
+  
+  // Construction of $ec_lists['categories'] array var
+  $c = array();
+  display_select_cat_wrapper('
+     SELECT id,name,uppercats,global_rank
+     FROM '.CATEGORIES_TABLE,
+   $c, 'category_options', true);
+  $ec_lists['categories'] = $template->smarty->_tpl_vars['category_options'];
+  
+  // Construction of $ec_lists['user_ids'] array var
+  $ec_lists['user_ids'] = array();
+  $q = pwg_query('SELECT id,username FROM '.USERS_TABLE. ' WHERE id > 2');
+  while ($r = mysql_fetch_assoc($q)) {
+    $ec_lists['user_ids'][$r['id']] = $r['username'];
+  }
+  
+  // Construction of $ec_lists['ec_table'] array var
+  build_ec_table();
+}
+
+?>
Index: extensions/event_cats/main.inc.php
===================================================================
--- extensions/event_cats/main.inc.php	(revision 4163)
+++ extensions/event_cats/main.inc.php	(revision 4169)
@@ -53,5 +53,5 @@
 }
 
-include_once(EVNTCATS_PATH.'include/evntcats_funcs.inc.php');
+include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php');
 
 class event_cats {
