Index: /extensions/event_cats/admin/duplication.inc.php
===================================================================
--- /extensions/event_cats/admin/duplication.inc.php	(revision 4275)
+++ /extensions/event_cats/admin/duplication.inc.php	(revision 4276)
@@ -1,3 +1,15 @@
 <?php
+
+
+
+
+
+
+/* */
+
+
+
+
+
 
 
@@ -16,6 +28,3 @@
 
 
-/* */
-
-
 ?>
Index: /extensions/event_cats/admin/evntcats_admin.php
===================================================================
--- /extensions/event_cats/admin/evntcats_admin.php	(revision 4275)
+++ /extensions/event_cats/admin/evntcats_admin.php	(revision 4276)
@@ -71,4 +71,10 @@
 if (!isset($ec_debug)) $ec_debug = array();
 
+// +-----------------------------------------------------------------------+
+// | $_POST analysis, to determine which tab to display (tabsheet prep.)
+// +-----------------------------------------------------------------------+
+
+// If needed, stores in the DB the new value of the number of digits of
+// automatically created codes
 if (
   isset($_POST['ec_in_up_auto_code_length']) and
@@ -76,21 +82,62 @@
 ) change_ec_conf('auto_code_dg_nb', $_POST['ec_in_up_auto_code_length']);
 
+
+// If needed, stores in the DB that acknowledgement message has been displayed
 if ($ec_howto = (read_ec_conf('howto') == '0')) change_ec_conf('howto', '1');
 
 build_ec_lists(); // in evntcats_main_funcs.php
 
-// +-----------------------------------------------------------------------+
-// |                            Tabsheet
-// +-----------------------------------------------------------------------+
-
+// If no entry exist, default page is 'autolog_new'.
 $page['tab'] = (!($ec_exist_entries = (mysql_num_rows(pwg_query("
-  SELECT * FROM `".EVNTCATS_TABLE."`
-  WHERE `code` IS NOT NULL
+  SELECT * FROM `".EVNTCATS_AUTOLOG_TABLE."`
+  WHERE `code` IS NOT NULL ;
 ")) != 0))) ? 'autolog_new' : 'autolog_entries';
 
-// Rajouter un test pour que si $ec_exist_entries est faux, mais qu'il y a
-// quand même des entrées dans la table (donc pour gérer la duplication de
-// compte), l'onglet sélectionné par défaut soit celui de la gestion de la
-// duplication de compte.
+$ec_exist_duplic = ((mysql_num_rows(pwg_query("
+    SELECT * FROM `".EVNTCATS_DUPLIC_TABLE."` ;
+  ")) != 0) or
+  (read_ec_conf('duplic_gen') != 0) or
+  (read_ec_conf('duplic_type') != 0)
+);
+
+// If no entry exist, but some duplication management entries exist, default tab is 'duplication'.
+if (!$ec_exist_entries and $ec_exist_duplic) $page['tab'] = 'duplication';
+
+
+/* 
+
+if (isset($_POST[''])) {
+}
+
+
+if (isset($_POST['ec_duplic_conf_submit'])) {
+}
+
+if (isset($_POST['deny_groups_submit'])) {
+}
+
+if (isset($_POST['grant_groups_submit'])) {
+}
+
+if (isset($_POST['deny_types_submit'])) {
+}
+
+if (isset($_POST['grant_types_submit'])) {
+}
+
+if (isset($_POST['deny_users_submit'])) {
+}
+
+if (isset($_POST['grant_users_submit'])) {
+}
+
+
+
+
+*/
+
+
+
+
 
 if (isset($_POST['ec_act1'])) {
@@ -140,6 +187,10 @@
   if (isset($_GET['tab'])) switch ($_GET['tab']) {
     case 'autolog_modif':
+      if ($ec_exist_entries) $page['tab'] = $_GET['tab'];
+    break;
+    case 'duplication':
+      if ($ec_exist_duplic) $page['tab'] = $_GET['tab'];
+    break;
     case 'autolog_new':
-    case 'duplication':
     case 'config':
       $page['tab'] = $_GET['tab'];
@@ -148,8 +199,19 @@
 }
 
+// +-----------------------------------------------------------------------+
+// |                            Tabsheet
+// +-----------------------------------------------------------------------+
+
 $ec_exist_entries = (mysql_num_rows(pwg_query("
-  SELECT * FROM `".EVNTCATS_TABLE."`
+  SELECT * FROM `".EVNTCATS_AUTOLOG_TABLE."`
   WHERE `code` IS NOT NULL
 ")) != 0);
+
+$ec_exist_duplic = ((mysql_num_rows(pwg_query("
+    SELECT * FROM `".EVNTCATS_DUPLIC_TABLE."` ;
+  ")) != 0) or
+  (read_ec_conf('duplic_gen') != 0) or
+  (read_ec_conf('duplic_type') != 0)
+);
 
 $tabsheet = new tabsheet();
@@ -165,5 +227,5 @@
                l10n('ec_tab_autoid_new'),
                $my_base_url.'&amp;tab=autolog_new');
-$tabsheet->add('duplication',
+if ($ec_exist_duplic) $tabsheet->add('duplication',
                l10n('ec_tab_duplication'),
                $my_base_url.'&amp;tab=duplication');
Index: /extensions/event_cats/admin/template/duplication.tpl
===================================================================
--- /extensions/event_cats/admin/template/duplication.tpl	(revision 4275)
+++ /extensions/event_cats/admin/template/duplication.tpl	(revision 4276)
@@ -12,5 +12,5 @@
 
 {* <!-- Duplication configuration parameters --> *}
-<form class = "titrePage" name = "ec_duplic_conf">
+<form action = "" method = "post" class = "titrePage" name = "ec_duplic_conf">
   <fieldset>
     <legend>{'ec_duplication_config'|@translate}</legend>
@@ -22,17 +22,13 @@
         <td>
           <label for = "ec_dup_conf_none_id">
-            <input type = "radio" name = "ec_dup_conf" id = "ec_dup_conf_none_id" />
+            <input type = "radio" name = "ec_dup_conf[]" value = "none" id = "ec_dup_conf_none_id" />
             {'ec_dup_allowance_none'|@translate}
           </label><br>
           <label for = "ec_dup_conf_group_id">
-            <input type = "radio" name = "ec_dup_conf" id = "ec_dup_conf_group_id" />
+            <input type = "radio" name = "ec_dup_conf[]" value = "group" id = "ec_dup_conf_group_id" />
             {'ec_dup_allowance_group'|@translate}
-          </label><br> {* <!--
-          <label for = "ec_dup_conf_gen_id">
-            <input type = "radio" name = "ec_dup_conf" id = "ec_dup_conf_gen_id" />
-            {'ec_dup_allowance_gen'|@translate}
-          </label><br> --> *}
+          </label><br>
           <label for = "ec_dup_conf_all_id">
-            <input type = "radio" name = "ec_dup_conf" id = "ec_dup_conf_all_id" />
+            <input type = "radio" name = "ec_dup_conf[]" value = "all" id = "ec_dup_conf_all_id" />
             {'ec_dup_allowance_all'|@translate}
           </label>
@@ -46,11 +42,11 @@
 {* <!-- Duplication settings by groups / types / user ids --> *}
 <form action = "" method = "post" name = "ec_duplic_set" id="categoryPermissions">
-
+  
   <h4>{'Groups'|@translate}</h4>
-
+  
   <fieldset>
     <legend>{'ec_duplic_ok'|@translate}</legend>
     <ul>
-      {foreach from=$group_granted_ids item=id}
+      {foreach from=$groups_granted_ids item=id}
       <li><label><input type = "checkbox" name = "deny_groups[]" value = "{$id}" /> {$all_groups[$id]}</label></li>
       {/foreach}
@@ -58,9 +54,9 @@
     <input class = "submit" type = "submit" name = "deny_groups_submit" value = "{'ec_dup_grp_ok_sbmt_lbl'|@translate}" />
   </fieldset>
-
+  
   <fieldset>
     <legend>{'ec_duplic_nok'|@translate}</legend>
     <ul>
-      {foreach from=$group_denied_ids item=id}
+      {foreach from=$groups_denied_ids item=id}
       <li><label><input type = "checkbox" name = "grant_groups[]" value = "{$id}"> {$all_groups[$id]}</label></li>
       {/foreach}
@@ -68,25 +64,41 @@
     <input class = "submit" type = "submit" name = "grant_groups_submit" value = "{'ec_dup_grp_nok_sbmt_lbl'|@translate}" />
   </fieldset>
-
+  
   <h4>{'ec_dup_types'|@translate}</h4>
-
+  
   <fieldset>
     <legend>{'ec_duplic_ok'|@translate}</legend>
     <ul>
-      <li><label><input type = "checkbox" name = "ec_dup_types_generic_ok" value = "ec_dup_types_generic_ok_id" /> {'user_status_generic'|@translate}</label></li>
+      {if $ec_gen_granted}
+      <li><label><input type = "checkbox" name = "deny_generic" {* id = "ec_dup_types_generic_nok_id" *} /> {'user_status_generic'|@translate}</label></li>
       <br />
-      <li><label><input type = "checkbox" name = "ec_dup_types_contacts_ok" value = "ec_dup_types_contacts_ok_id" /> {'Level 1'|@translate}</label></li>
-      <li><label><input type = "checkbox" name = "ec_dup_types_friends_ok" value = "ec_dup_types_friends_ok_id" /> {'Level 2'|@translate}</label></li>
-      <li><label><input type = "checkbox" name = "ec_dup_types_family_ok" value = "ec_dup_types_family_ok_id" /> {'Level 4'|@translate}</label></li>
+      {/if}
+      {foreach from=$types_granted_ids item=id}
+        <li><label><input type = "checkbox" name = "deny_types[]" value = "{$id}" /> {$all_types[$id]}</label></li>
+      {/foreach}
     </ul>
-    <input class = "submit" type = "submit" name = "deny_users_submit" value = "{'ec_dup_typ_sbmt_lbl'|@translate}" />
+    <input class = "submit" type = "submit" name = "deny_types_submit" value = "{'ec_dup_typ_sbmt_nok_lbl'|@translate}" />
   </fieldset>
-
+  
+  <fieldset>
+    <legend>{'ec_duplic_nok'|@translate}</legend>
+    <ul>
+      {if !$ec_gen_granted}
+      <li><label><input type = "checkbox" name = "grant_generic" {* id = "ec_dup_types_generic_ok_id" *} /> {'user_status_generic'|@translate}</label></li>
+      <br />
+      {/if}
+      {foreach from=$types_denied_ids item=id}
+        <li><label><input type = "checkbox" name = "grant_types[]" value = "{$id}" /> {$all_types[$id]}</label></li>
+      {/foreach}
+    </ul>
+    <input class = "submit" type = "submit" name = "grant_types_submit" value = "{'ec_dup_typ_sbmt_ok_lbl'|@translate}" />
+  </fieldset>
+  
   <h4>{'Users'|@translate}</h4>
-
+  
   <fieldset>
     <legend>{'ec_duplic_ok'|@translate}</legend>
     <ul>
-      {foreach from=$user_granted_direct_ids item=id}
+      {foreach from=$users_granted_direct_ids item=id}
       <li><label><input type = "checkbox" name = "deny_users[]" value = "{$id}" /> {$all_users[$id]}</label></li>
       {/foreach}
@@ -94,5 +106,5 @@
     <input class = "submit" type = "submit" name = "deny_users_submit" value = "{'ec_dup_usr_ok_sbmt_lbl'|@translate}" />
   </fieldset>
-
+  
   <fieldset>
     <legend>{'ec_duplic_ok_groups'|@translate}</legend>
@@ -105,9 +117,9 @@
     {/if}
   </fieldset>
-
+  
   <fieldset>
     <legend>{'ec_duplic_nok'|@translate}</legend>
     <ul>
-      {foreach from=$user_denied_ids item=id}
+      {foreach from=$users_denied_ids item=id}
       <li><label><input type = "checkbox" name = "grant_users[]" value = "{$id}"> {$all_users[$id]}</label></li>
       {/foreach}
@@ -115,5 +127,5 @@
     <input class = "submit" type = "submit" name = "grant_users_submit" value = "{'ec_dup_usr_nok_sbmt_lbl'|@translate}" />
   </fieldset>
-
+  
 </form>
 
Index: /extensions/event_cats/include/evntcats_admin_funcs.inc.php
===================================================================
--- /extensions/event_cats/include/evntcats_admin_funcs.inc.php	(revision 4275)
+++ /extensions/event_cats/include/evntcats_admin_funcs.inc.php	(revision 4276)
@@ -376,5 +376,5 @@
   "
     SELECT `id`
-    FROM `".EVNTCATS_TABLE."`
+    FROM `".EVNTCATS_AUTOLOG_TABLE."`
     WHERE `code`    = '".$ec_code."'
       AND `user_id`    ".$ec_user_idp."
@@ -393,5 +393,5 @@
       $t1 = mysql_fetch_row(pwg_query("
         SELECT `code`
-        FROM `".EVNTCATS_TABLE."`
+        FROM `".EVNTCATS_AUTOLOG_TABLE."`
         WHERE `id` = ".$_POST['ec_entry_sel']
       ))) === false
@@ -399,5 +399,5 @@
     $r = pwg_query("
       SELECT `id`
-      FROM `".EVNTCATS_TABLE."`
+      FROM `".EVNTCATS_AUTOLOG_TABLE."`
       WHERE `code` = '".$t1[0]."'
        AND `id` <> ".$_POST['ec_entry_sel']
@@ -425,5 +425,5 @@
     if (
       pwg_query("
-        INSERT INTO `".EVNTCATS_TABLE."` (
+        INSERT INTO `".EVNTCATS_AUTOLOG_TABLE."` (
           `code`,
           `user_id`,
@@ -459,5 +459,5 @@
     if (
       pwg_query("
-        UPDATE `".EVNTCATS_TABLE."`
+        UPDATE `".EVNTCATS_AUTOLOG_TABLE."`
         SET
           `user_id` =  ".$ec_user_id.",
@@ -493,5 +493,5 @@
   global $page;
   if (!pwg_query("
-    DELETE FROM `".EVNTCATS_TABLE."`
+    DELETE FROM `".EVNTCATS_AUTOLOG_TABLE."`
     WHERE `id` = ".$ec_id
   )) {
Index: /extensions/event_cats/include/evntcats_main_funcs.inc.php
===================================================================
--- /extensions/event_cats/include/evntcats_main_funcs.inc.php	(revision 4275)
+++ /extensions/event_cats/include/evntcats_main_funcs.inc.php	(revision 4276)
@@ -155,5 +155,5 @@
       if ($new_action == '') {
         if (!pwg_query("
-          UPDATE `".EVNTCATS_TABLE."`
+          UPDATE `".EVNTCATS_AUTOLOG_TABLE."`
           SET `forced` = 'false'
           WHERE `id` = ".$ec_entry['id']
@@ -247,5 +247,5 @@
   
   $q = pwg_query("
-    SELECT * FROM `".EVNTCATS_TABLE."`
+    SELECT * FROM `".EVNTCATS_AUTOLOG_TABLE."`
     WHERE `code` IS NOT NULL
     ORDER BY `id`
@@ -352,5 +352,5 @@
  */
 function build_dup_arrays($append_tpl = false) {
-  global $template, $ec_lists, $conf, $ec_debug;
+  global $template, $ec_lists, $conf;
   
   if (count($ec_lists['user_ids']) == 0) build_ec_userids();
@@ -368,13 +368,11 @@
   
   // groups granted to duplication
-  $group_granted_ids = order_by_name(
+  $groups_granted_ids = order_by_name(
     array_from_query("
-      SELECT `arg2`
-        FROM ".EVNTCATS_TABLE."
-        WHERE `code` IS NULL
-          AND `arg1` = '1'
-          AND `arg2` IS NOT NULL
+      SELECT `val`
+        FROM ".EVNTCATS_DUPLIC_TABLE."
+        WHERE `item` = 'grp'
       ;",
-      'arg2'
+      'val'
     ),
     $groups
@@ -384,11 +382,9 @@
   $users_granted_direct_ids = order_by_name(
     array_from_query("
-      SELECT `arg2`
-        FROM ".EVNTCATS_TABLE."
-        WHERE `code` IS NULL
-          AND `arg1` = '2'
-          AND `arg2` IS NOT NULL
+      SELECT `val`
+        FROM ".EVNTCATS_DUPLIC_TABLE."
+        WHERE `item` = 'usr'
       ;",
-      'arg2'
+      'val'
     ),
     $ec_lists['user_ids']
@@ -398,8 +394,8 @@
   // certain group (in groups, level (friends, family, contacts),
   // or user status (generic))
-  $user_granted_ids = array();
-
+  $users_granted_ids = array();
+  
   $users_granted_thks_gen_ids = array();
-  if (read_ec_conf('duplic_gen') != '0') {
+  if ($ec_gen_granted = (read_ec_conf('duplic_gen') != '0')) {
     $users_granted_thks_gen_ids = order_by_name(
       array_diff(
@@ -415,25 +411,25 @@
     );
     foreach ($users_granted_thks_gen_ids as $user_id)
-     $user_granted_ids[$user_id] = l10n('user_status_generic');
-  } global $ec_debug; $ec_debug['1'] = $user_granted_ids;
-
+     $users_granted_ids[$user_id] = l10n('user_status_generic');
+  }
+
+  $types = array(
+    '1' => l10n('Level 1'),
+    '2' => l10n('Level 2'),
+    '4' => l10n('Level 4'),
+  );
+  $types_granted_ids = array();
   $users_granted_thks_types_ids = array();
   $c = intval(read_ec_conf('duplic_type'));
   if ($c != 0) {
-    $t = array();
-    if (($c & 1) != 0) $t[] = '1';
-    if (($c & 2) != 0) $t[] = '2';
-    if (($c & 4) != 0) $t[] = '4';
-    if (count($t) > 0) {
-      $types = array(
-        '1' => l10n('Level 1'),
-        '2' => l10n('Level 2'),
-        '4' => l10n('Level 4'),
-      );
+    if (($c & 1) != 0) $types_granted_ids[] = '1';
+    if (($c & 2) != 0) $types_granted_ids[] = '2';
+    if (($c & 4) != 0) $types_granted_ids[] = '4';
+    if (count($types_granted_ids) > 0) {
       $user_granted_from_type = array();
       $result = pwg_query("
         SELECT `user_id`, `level`
         FROM `".USER_INFOS_TABLE."`
-        WHERE `level` IN (".implode(',', $t).");
+        WHERE `level` IN (".implode(',', $types_granted_ids).");
       ");
       while ($row = mysql_fetch_array($result)) {
@@ -459,13 +455,13 @@
        foreach ($user_granted_from_type as $type_id => $type_users) {
         if (in_array($user_id, $type_users)) {
-          $user_granted_ids[$user_id]= $types[$type_id];
+          $users_granted_ids[$user_id]= $types[$type_id];
           break;
         }
        }
     }
-  } $ec_debug['2'] = $user_granted_ids;
+  }
 
   $users_granted_thks_groups_ids = array();
-  if (count($group_granted_ids) > 0) {
+  if (count($groups_granted_ids) > 0) {
     $granted_groups = array();
 
@@ -473,5 +469,5 @@
       SELECT `user_id`, `group_id`
       FROM `".USER_GROUP_TABLE."`
-      WHERE `group_id` IN (".implode(',', $group_granted_ids).");
+      WHERE `group_id` IN (".implode(',', $groups_granted_ids).");
     ");
     while ($row = mysql_fetch_array($result)) {
@@ -499,12 +495,12 @@
      foreach ($granted_groups as $group_id => $group_users)
       if (in_array($user_id, $group_users)) {
-        $user_granted_ids[$user_id]= $groups[$group_id];
+        $users_granted_ids[$user_id]= $groups[$group_id];
         break;
       }
     
-  } $ec_debug['3'] = $user_granted_ids;
+  }
 
   if ($append_tpl) {
-    $user_denied_ids = order_by_name(
+    $users_denied_ids = order_by_name(
       array_diff(
         array_keys($ec_lists['user_ids']),
@@ -517,5 +513,5 @@
     );
     
-    foreach ($user_granted_ids as $u => $g) $template->append(
+    foreach ($users_granted_ids as $u => $g) $template->append(
       'user_granted_indirects',
       array(
@@ -525,19 +521,28 @@
     );
     
-    $ec_debug['4'] = $user_granted_ids;
     $template->assign('all_groups', $groups);
-    $template->assign('group_granted_ids', $group_granted_ids);
-    $template->assign('group_denied_ids',order_by_name(
-      array_diff(array_keys($groups), $group_granted_ids), $groups
+    $template->assign('groups_granted_ids', $groups_granted_ids);
+    $template->assign('groups_denied_ids', order_by_name(
+      array_diff(array_keys($groups), $groups_granted_ids), $groups
+    ));
+    $template->assign('ec_gen_granted', $ec_gen_granted);
+    $template->assign('all_types', $types);
+    $template->assign('types_granted_ids', $types_granted_ids);
+    $template->assign('types_denied_ids', order_by_name(
+      array_diff(array_keys($types), $types_granted_ids), $types
     ));
     $template->assign('all_users', $ec_lists['user_ids']);
     $template->assign('users_granted_direct_ids', $users_granted_direct_ids);
-    $template->assign('user_denied_ids', $user_denied_ids);
-  }
-   $user_granted_ids = array_merge(
-    $user_granted_ids,
+    $template->assign('users_denied_ids', $users_denied_ids);
+  }
+  $users_granted_ids = array_merge(
+    array_keys($users_granted_ids),
     $users_granted_direct_ids
-   );
-  return $user_granted_ids;
+  );
+  
+  // Returns an array which values are all the user_ids allowed to display a
+  // "duplicate" link. The keys of this array are strange (for direct allowed
+  // users, keys are usernames), but normally not used
+  return $users_granted_ids;
 }
 
Index: /extensions/event_cats/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/event_cats/language/fr_FR/plugin.lang.php	(revision 4275)
+++ /extensions/event_cats/language/fr_FR/plugin.lang.php	(revision 4276)
@@ -93,7 +93,8 @@
 $lang['ec_dup_grp_ok_sbmt_lbl']   = 'Interdire la duplication aux groupes sélectionnés';
 $lang['ec_dup_grp_nok_sbmt_lbl']  = 'Autoriser la duplication aux groupes sélectionnés';
+$lang['ec_dup_typ_sbmt_nok_lbl']  = 'Interdire la duplication aux types sélectionnés';
+$lang['ec_dup_typ_sbmt_ok_lbl']   = 'Autoriser la duplication aux types sélectionnés';
 $lang['ec_dup_usr_ok_sbmt_lbl']   = 'Interdire la duplication aux utilisateurs sélectionnés';
 $lang['ec_dup_usr_nok_sbmt_lbl']  = 'Autoriser la duplication aux utilisateurs sélectionnés';
-$lang['ec_dup_typ_sbmt_lbl']      = 'Sauvegarder';
 $lang['ec_dup_conf_sbmt_lbl']     = 'Sauvegarder la configuration de la duplication';
 // JS checks
Index: /extensions/event_cats/main.inc.php
===================================================================
--- /extensions/event_cats/main.inc.php	(revision 4275)
+++ /extensions/event_cats/main.inc.php	(revision 4276)
@@ -43,5 +43,6 @@
 define('EVNTCATS_INFO_VERSION','1.0.0');
 define('EVNTCATS_PATH',PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)). '/');
-define('EVNTCATS_TABLE',$prefixeTable.'event_cats');
+define('EVNTCATS_AUTOLOG_TABLE', $prefixeTable.'event_cats_autolog');
+define('EVNTCATS_DUPLIC_TABLE', $prefixeTable.'event_cats_duplic');
 define('ROOT_URL',get_absolute_root_url());
 
Index: /extensions/event_cats/maintain.inc.php
===================================================================
--- /extensions/event_cats/maintain.inc.php	(revision 4275)
+++ /extensions/event_cats/maintain.inc.php	(revision 4276)
@@ -36,19 +36,22 @@
 include_once(EVNTCATS_PATH.'include/ec_conf.inc.php');
 
+// ***********************************************************************
 function plugin_uninstall() {
-  global $prefixeTable, $ec_conf;
+  global $prefixeTable;
 
-  unset($ec_conf);
 	pwg_query("DELETE FROM `".CONFIG_TABLE."` WHERE `param` = 'event_cats' LIMIT 1;");
-	return pwg_query('DROP TABLE IF EXISTS `'.$prefixeTable.'event_cats`;');
+	pwg_query('DROP TABLE IF EXISTS `'.$prefixeTable.'event_cats_duplic`;');
+	return pwg_query('DROP TABLE IF EXISTS `'.$prefixeTable.'event_cats_autolog`;');
 }
 
+// ***********************************************************************
 function plugin_install() {
   global $prefixeTable;
   
   plugin_uninstall();
+  
   // create table for plugin, if it doesn't exist yet
-  $q = pwg_query("
-    CREATE TABLE `".$prefixeTable."event_cats` (
+  $r = (pwg_query("
+    CREATE TABLE `".$prefixeTable."event_cats_autolog` (
       `id`      SMALLINT(5)             UNSIGNED NOT NULL     AUTO_INCREMENT ,
       `code`    VARCHAR(32)                               DEFAULT NULL ,
@@ -63,5 +66,5 @@
     )
     DEFAULT CHARACTER SET utf8;
-  ");
+  ") !== false);
 
 /*
@@ -131,16 +134,46 @@
 
 */
-  pwg_query("
+  
+  if ($r) $r = (pwg_query("
+    CREATE TABLE `".$prefixeTable."event_cats_duplic` (
+      `item`  VARCHAR(5) NOT NULL ,
+      `val` VARCHAR(32) NOT NULL ,
+      KEY `item` (`item`),
+      KEY `val` (`val`)
+    )
+    DEFAULT CHARACTER SET utf8;
+  ") !== false);
+
+/*
+Explanations on table structure :
+
+item  : the code used as "autolog" argument. If thie code provided by the
+          visitor does not exist in the table, the administrator can choose
+          whether the visitor is redirected to the home page (nothing
+          happens) or to the "access denied" page ;
+value : the account concerned in following values ;
+
+*/
+  
+  if ($r) $r = (pwg_query("
     INSERT INTO `".CONFIG_TABLE."` (`param`,`value`,`comment`)
     VALUES ('event_cats','0','Paramètres du plugin Event Cats');
-  ");
-  change_ec_conf('activated', '0');
-  return $q;
+  ") !== false);
+  
+  if ($r) $r = (change_ec_conf('activated', '0'));
+  
+  if ($r) return true;
+  else {
+    plugin_uninstall();
+    return false;
+  }
 }
 
+// ***********************************************************************
 function plugin_activate() {
   change_ec_conf('activated', '1');
 }
 
+// ***********************************************************************
 function plugin_deactivate() {
   change_ec_conf('activated', '0');
