Index: extensions/event_cats/admin/evntcats_admin.php
===================================================================
--- extensions/event_cats/admin/evntcats_admin.php	(revision 4282)
+++ extensions/event_cats/admin/evntcats_admin.php	(revision 4329)
@@ -38,17 +38,6 @@
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
 
-global $template, $conf, $lang, $prefixeTable, $ec_conf, $page, $ec_debug,
- $ec_lists,   // array of following arrays :
-              //   $ec_lists['ec_table'] :
-              //     Event Cats table, in function of each entry id
-              //   $ec_lists['ec_codes'] : // Used ?
-              //     array of useful data, in function of entries codes
-              //   $ec_lists['add_pages'] :
-              //     array of Add. Pages names in function of their id
-              //   $ec_lists['categories'] :
-              //     array of category names in function of their id
-              //   $ec_lists['user_ids'] :
-              //     array of usernames in function of their id
- $ec_ap_ok;   // whether Additional Pages is installed and activated
+global $template, $conf, $lang, $prefixeTable,
+       $ec_conf, $page, $ec_debug, $ec_lists;
 
 load_language('plugin.lang', EVNTCATS_PATH);
@@ -88,5 +77,5 @@
 build_ec_lists(); // in evntcats_main_funcs.php
 
-// If no entry exist, default page is 'autolog_new'.
+// If no entry exist, default tab is 'autolog_new'.
 $page['tab'] = (!($ec_exist_entries = (mysql_num_rows(pwg_query("
   SELECT * FROM `".EVNTCATS_TABLE."`
@@ -94,55 +83,169 @@
 ")) != 0))) ? 'autolog_new' : 'autolog_entries';
 
-$ec_exist_duplic = ((mysql_num_rows(pwg_query("
-  SELECT * FROM `".EVNTCATS_TABLE."`
-  WHERE `code` IS NULL
-  AND `arg1` IS NOT NULL
-  AND `arg2` IS NOT NULL ;
-  ")) != 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'])) {
+// If no entry exist, but some duplication management entries exist, default
+// tab is 'duplication'.
+if (!$ec_exist_entries and read_ec_conf('dup_allow') == '2') $page['tab'] = 'duplication';
+
+// If a modification of duplication management has been posted, default tab
+// is 'duplication'.
+if (
+  count($_POST) > 0 and
+  count(array_intersect(array(
+    'ec_duplic_conf_submit',
+    'deny_groups_submit',
+    'grant_groups_submit',
+    'deny_types_submit',
+    'grant_types_submit',
+    'deny_users_submit',
+    'grant_users_submit',
+  ),
+  array_keys($_POST))) > 0
+) $page['tab'] = 'duplication';
+
+if (isset($_POST['ec_conf_submit'])) {
+  if (isset($_POST['ec_dup_conf']))
+   if (!change_ec_conf('dup_allow', $_POST['ec_dup_conf']))
+    ec_end2(7);
+  if (isset($_POST['ec_dup_disp']))
+   if (!change_ec_conf('duplic_display', $_POST['ec_dup_disp']))
+    ec_end2(8);
+  if (isset($_POST['ec_unknown']))
+   if (!change_ec_conf('unknown_code', $_POST['ec_unknown']))
+    ec_end2(9);
+  if (isset($_POST['ec_in_up_aps']))
+   if (!change_ec_conf('unknown_code_ap_id', $_POST['ec_in_up_aps']))
+    ec_end2(10);
+  $page['tab'] = 'config';
+  $page['infos'][] = l10n('ec_config_saved');
+}
+elseif (isset($_POST['ec_duplic_conf_submit'])) {
+  if (isset($_POST['ec_dup_conf'])) {
+    if (
+      read_ec_conf('dup_allow') == '2' and
+      $_POST['ec_dup_conf'] != '2'
+    ) $page['tab'] = 'config';
+    if (!change_ec_conf('dup_allow', $_POST['ec_dup_conf']))
+     ec_end2(5);
+  }
+  if (isset($_POST['ec_dup_disp']))
+   if (!change_ec_conf('duplic_display', $_POST['ec_dup_disp']))
+    ec_end2(6);
+  $page['infos'][] = l10n('ec_config_saved');
+}
+elseif (
+  isset($_POST['deny_groups_submit']) and
+  isset($_POST['deny_groups']) and
+  count($_POST['deny_groups']) > 0
+) {
+  if (pwg_query("
+    DELETE
+    FROM `".EVNTCATS_TABLE."`
+    WHERE `arg1` = 1
+      AND `arg2` IN (".implode(',', $_POST['deny_groups']).");
+  ") === false) ec_end2(1);
+  else $page['infos'][] = l10n('ec_config_saved');
+}
+elseif (
+  isset($_POST['grant_groups_submit']) and
+  isset($_POST['grant_groups']) and
+  count($_POST['grant_groups']) > 0
+) {
+  $inserts = array();
+  foreach ($_POST['grant_groups'] as $v) $inserts[] = array(
+    'arg1' => 1,
+    'arg2' => intval($v)
+  );
+  mass_inserts(EVNTCATS_TABLE, array('arg1', 'arg2'), $inserts);
+  $page['infos'][] = l10n('ec_config_saved');
+}
+elseif (
+  isset($_POST['deny_types_submit']) and (
+    isset($_POST['deny_types']) and
+    count($_POST['deny_types']) > 0 or
+    isset($_POST['deny_generic'])
+  )
+) {
+  $c = ($no_previous = (count($t = mysql_fetch_row(pwg_query("
+    SELECT `arg2`
+    FROM `".EVNTCATS_TABLE."`
+    WHERE `code` IS NULL
+      AND `arg1` = 3
+      AND `arg2` IS NOT NULL
+    LIMIT 1;
+  "))) == 0)) ? 0 : intval($t[0]);
+  if (isset($_POST['deny_types']))
+   foreach ($_POST['deny_types'] as $v) $c = $c & ~$v;
+  if (isset($_POST['deny_generic'])) $c = $c & 7;
+  $q = ($no_previous) ? "
+    INSERT INTO `".EVNTCATS_TABLE."`
+    (`arg1`, `arg2`)
+    VALUES (3, $c);
+  " : "
+    UPDATE `".EVNTCATS_TABLE."`
+    SET `arg2` = $c
+    WHERE `arg1` = 3
+    LIMIT 1 ;
+  ";
+  if (pwg_query($q) === false) ec_end2(3);
+  else $page['infos'][] = l10n('ec_config_saved');
+}
+elseif (
+  isset($_POST['grant_types_submit']) and (
+    isset($_POST['grant_types']) and
+    count($_POST['grant_types']) > 0 or
+    isset($_POST['grant_generic'])
+  )
+) {
+  $c = ($no_previous = (count($t = mysql_fetch_row(pwg_query("
+    SELECT `arg2`
+    FROM `".EVNTCATS_TABLE."`
+    WHERE `code` IS NULL
+      AND `arg1` = 3
+      AND `arg2` IS NOT NULL
+    LIMIT 1;
+  "))) == 0)) ? 0 : intval($t[0]);
+  if (isset($_POST['grant_types']))
+   foreach ($_POST['grant_types'] as $v) $c = $c | $v;
+  if (isset($_POST['grant_generic'])) $c = $c | 8;
+  $q = ($no_previous) ? "
+    INSERT INTO `".EVNTCATS_TABLE."`
+    (`arg1`, `arg2`)
+    VALUES (3, $c);
+  " : "
+    UPDATE `".EVNTCATS_TABLE."`
+    SET `arg2` = $c
+    WHERE `arg1` = 3
+    LIMIT 1 ;
+  ";
+  if (pwg_query($q) === false) ec_end2(4);
+  else $page['infos'][] = l10n('ec_config_saved');
+}
+elseif (
+  isset($_POST['deny_users_submit']) and
+  isset($_POST['deny_users']) and
+  count($_POST['deny_users']) > 0
+) {
+  if (pwg_query("
+    DELETE
+    FROM `".EVNTCATS_TABLE."`
+    WHERE `arg1` = 2
+      AND `arg2` IN (".implode(',', $_POST['deny_users']).");
+  ") === false) ec_end2(2);
+  else $page['infos'][] = l10n('ec_config_saved');
+}
+elseif (
+  isset($_POST['grant_users_submit']) and
+  isset($_POST['grant_users']) and
+  count($_POST['grant_users']) > 0
+) {
+  $inserts = array();
+  foreach ($_POST['grant_users'] as $v) $inserts[] = array(
+    'arg1' => 2,
+    'arg2' => intval($v)
+  );
+  mass_inserts(EVNTCATS_TABLE, array('arg1', 'arg2'), $inserts);
+  $page['infos'][] = l10n('ec_config_saved');
+}
+elseif (isset($_POST['ec_act1'])) {
   if (
     $_POST['ec_act1'] == 'disable' and
@@ -180,5 +283,5 @@
           build_ec_table();
         }
-        else ec_end1('ec_entry_sel', 'ec_bad_argument1');
+        else ec_end1('ec_entry_sel', 'Bad argument : ');
       }
       else if ($_POST['ec_act1'] == 'toggle_forced')
@@ -193,5 +296,5 @@
     break;
     case 'duplication':
-      if ($ec_exist_duplic) $page['tab'] = $_GET['tab'];
+      if (read_ec_conf('dup_allow') == '2') $page['tab'] = $_GET['tab'];
     break;
     case 'autolog_new':
@@ -211,13 +314,8 @@
 ")) != 0);
 
-$ec_exist_duplic = ((mysql_num_rows(pwg_query("
-  SELECT * FROM `".EVNTCATS_TABLE."`
-  WHERE `code` IS NULL
-  AND `arg1` IS NOT NULL
-  AND `arg2` IS NOT NULL ;
-  ")) != 0) or
-  (read_ec_conf('duplic_gen') != 0) or
-  (read_ec_conf('duplic_type') != 0)
-);
+if (
+  $page['tab'] == 'duplication' and
+  read_ec_conf('dup_allow') != '2'
+) $page['tab'] = 'config';
 
 $tabsheet = new tabsheet();
@@ -233,5 +331,5 @@
                l10n('ec_tab_autoid_new'),
                $my_base_url.'&amp;tab=autolog_new');
-if ($ec_exist_duplic) $tabsheet->add('duplication',
+if (read_ec_conf('dup_allow') == '2') $tabsheet->add('duplication',
                l10n('ec_tab_duplication'),
                $my_base_url.'&amp;tab=duplication');
