Changeset 7084 for extensions/event_cats


Ignore:
Timestamp:
Oct 4, 2010, 1:38:27 AM (14 years ago)
Author:
LucMorizur
Message:

At last a configuration management working as desired

Location:
extensions/event_cats
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/event_cats/include/ec_conf.inc.php

    r7068 r7084  
    3333// ---------------------------------------------------------------------------
    3434
     35// ----- Introduction
     36// Not sure I'm very proud of this quite complex configuration initialization
     37// part :-/ ...
     38// The reason of the complexity is the inital intention of building a
     39// configuration management allowing to use in the rest of the script only
     40// two functions: change_ec_conf() and read_ec_conf() .
     41// change_ec_conf() updates the DB systematically. The initialization part
     42// has the only function of determining what is the value of $ec_conf, which
     43// is the root configuration parameters provider.
     44// -----
     45
    3546// $ec_conf has numeric indexes (instead of string keys like 'activated',
    3647// 'howto'...) because of its first reading, done with the "explode" function.
     
    5263
    5364//----------------------------------------------------------------------------
    54 // The following lines allow to change the number of configuration items, the
    55 // default values they can have, and also their possible other values, very
    56 // quickly.
    5765
    5866// Give possible $ec_conf values. In case values cannot be predicted, just
     
    6068$ec_conf_possible_values = array(
    6169  'activated'           => array('0', '1'),                           //  0
     70    // plugin activated
    6271  'howto'               => array('0', '1'),                           //  1
     72    // whether the small aknowledgement message has already been displayed
    6373  'dup_allow'           => array('0', '1', '2'),                      //  2
     74    // duplication allowance :
     75    //   0 : no account;
     76    //   1 : all accounts;
     77    //   2 : specified by group, type, and user ids (default).
     78    // If Event Cats is in "simple mode", get the value of
     79    // $conf['ec_dup_allow'] if it is set; and an allowance to duplicate only
     80    // generic accounts will be defined if the value is 2.
    6481  'duplic_display'      => array('0', '1', '2'),                      //  3
     82    // duplication link display in the menubar :
     83    //   0 : "Register" for everybody;
     84    //   1 : "Duplicate" for everybody;
     85    //   2 : "Register" only for generic accounts,
     86    //       "Duplicate" for all other accounts (default);
     87    // If Event Cats is in "simple mode", takes the value of
     88    // $conf['ec_duplic_display'] if it's set.
    6589  'auto_code_dg_nb'     => array( '4',  '5',  '8', '10', '12', '15',
    6690                                 '16', '20', '24', '25', '30', '32'), //  4
     91    // number of digits when creating a new code automatically, several values
     92    // (default: 10)
     93    // If Event Cats is in "simple mode", get the value of
     94    // $conf['ec_auto_code_dg_nb'] if set.
    6795  'unknown_code'        => array('0', '1', '2'),                      //  5
     96    // what to do in case an unknown code is used with "autolog" parameter :
     97    //   0 : nothing (display home page, index.php (not logged in of course));
     98    //   1 : display "access denied" page (default);
     99    //   2 : display an A. P. precised below.
    68100  'unknown_code_ap_id'  => array(),                                   //  6
     101    // the id of the Additional Page which must be used in case of usage of an
     102    // unknow code; several vals (default: 0).
    69103  'comment_display'     => array('0', '1'),                           //  7
     104    // the way the comment is displayed in "entries" tab:
     105    // 0, as tooltip; 1 (default), on a line under code
     106    // If Event Cats is in "simple mode", get the value of
     107    // $conf['ec_comment_display'] if set.
    70108  'in_help_display'     => array('0', '1'),                           //  8
     109    // whether the help banner is displayed (default: 1).
    71110  'display_connection'  => array('0', '1'),                           //  9
     111    // whether the "Connection" link must be displayed for generic users
     112    // (default: 1)
     113    // If Event Cats is in "simple mode", takes the value of
     114    // $conf['ec_display_connection'] if set.
    72115  'simple_mode_on'      => array('0', '1'),                           // 10
     116    // whether the presentation of the plugin is in "simple mode" or not.
     117    // (default: 1)
     118    // The default value can be modified to 0 (normal view) if Event Cats was
     119    // already installed previously.
    73120  'display_full_button' => array('0', '1'),                           // 11
     121    // whether the "Show full features" button must be displayed (default: 1).
     122    // The default value can be modified to 0 (don't display) if
     123    // $conf['ec_display_full_button'] is set, and false.
    74124);
    75125
     
    81131$t = array(); $u = '0'; $v = false; $w = false; $ec_conf = array(); $s = '0';
    82132if ($w = ( // $w becomes true if the query succeeds <=> if EC was already in
    83   // $t gets event_cats config value, as an array with one unique entry
     133  // $t gets event_cats config value (array to be "exploded")
    84134  ($t = pwg_db_fetch_row(pwg_query("
    85135    SELECT `value`
     
    89139) {
    90140  $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index));
    91   $u = $ec_conf[0];
    92   $s = ($v) ? $ec_conf[1] : '0'; // the aknowledgement message is displayed
    93   // again if the configuration changes
     141  $u = $ec_conf[$ec_conf_index['activated']];
     142  $s = ($v) ? $ec_conf[$ec_conf_index['howto']] : '0'; // the aknowledgement
     143  // message is displayed again if the configuration changes
    94144}
    95145if ($v and !$w) die('$v true with $w false in ec_conf.inc.php');
     
    97147// $v is false if the entry in the table doesn't exist; or exists, but its
    98148// number of parameters is different than the number of default parameters.
    99 // $u is '0' if the plugin has not yet been activated, '1' if it has been.
     149// $u is '0' if the plugin is not activated, '1' if it is.
    100150// $s allows to display the aknowledgement message when config changes.
    101151// If $v or $w are false, all $ec_conf values are set to default values. But
    102152// default values must first take values specified in $conf, if they are set.
    103153
    104 // Determine whether simple mode is ON or OFF
     154// Determine whether simple mode is ON or OFF: simple mode must be on if Event
     155// Cats is just installed, or if it was ON previously, or if
     156// $conf['ec_display_full_button'] is set and is false.
    105157$simple_mode_on = (
    106158  (!$v and !$w) or (
    107     // $ec_conf[10] <=> read_ec_conf('simple_mode_on')
    108     isset($ec_conf[10]) and $ec_conf[10] == '1'
     159    isset($ec_conf[$ec_conf_index['simple_mode_on']]) and
     160    $ec_conf[$ec_conf_index['simple_mode_on']] == '1'
    109161  ) or (
    110162    isset($conf['ec_display_full_button']) and
     
    113165);
    114166
    115 if (!$v) {
    116   // Give configuration items names and default values. Only strings.
    117   $ec_conf_default = array( // PLUGIN CONFIGURATION ($ec_conf) :
    118                             // ---------------------------------
    119     'activated'       //  0 // plugin activated, 0 or 1
    120       => $u,                //
    121                             //
    122     'howto'           //  1 // whether the small aknowledgement message has
    123       => $s,                // already been displayed, 0 or 1
    124                             //
    125     'dup_allow' => ($simple_mode_on and isset($conf['ec_dup_allow']) and
    126                     in_array($conf['ec_dup_allow'],
    127                     $ec_conf_possible_values['ec_dup_allow'])) ?
    128       $conf['ec_dup_allow'] : (isset($ec_conf[2]) and in_array($ec_conf[2],
    129       $ec_conf_possible_values['dup_allow'])) ? $ec_conf[2] : '2',
    130                       //  2 // duplication allowance :
    131                             //   0 : no account;
    132                             //   1 : all accounts;
    133                             //   2 : specified by group, type, and user ids.
    134                             // If Event Cats is in "simple mode", takes the
    135                             // value of $conf['ec_dup_allow'] if it is set;
    136                             // and an allowance to duplicate only generic
    137                             // accounts will be defined.
    138                             //
    139     'duplic_display' => ($simple_mode_on and isset($conf['ec_duplic_display'])
    140                     and in_array($conf['ec_duplic_display'],
    141                     $ec_conf_possible_values['ec_duplic_display'])) ?
    142       $conf['ec_duplic_display'] : (isset($ec_conf[3]) and
    143       in_array($ec_conf[3], $ec_conf_possible_values['duplic_display'])) ?
    144       $ec_conf[3] : '2',
    145                       //  3 // duplication link display in the menubar :
    146                             //   0 : "Register" for everybody;
    147                             //   1 : "Duplicate" for everybody;
    148                             //   2 : "Register" only for generic accounts,
    149                             //       "Duplicate" for all other accounts;
    150                             // If Event Cats is in "simple mode", takes the
    151                             // value of $conf['ec_duplic_display'] if it's set.
    152                             //
    153   'auto_code_dg_nb' => ($simple_mode_on and isset($conf['ec_auto_code_dg_nb'])
    154                     and in_array($conf['ec_auto_code_dg_nb'],
    155                     $ec_conf_possible_values['ec_auto_code_dg_nb'])) ?
    156       $conf['ec_auto_code_dg_nb'] : (isset($ec_conf[4]) and
    157       in_array($ec_conf[4], $ec_conf_possible_values['auto_code_dg_nb'])) ?
    158       $ec_conf[4] : '10',
    159                       //  4 // number of digits when creating a new code
    160                             // automatically, several values
    161                             // If Event Cats is in "simple mode", takes the
    162                             // value of $conf['ec_auto_code_dg_nb'] if set.
    163                             //
    164     'unknown_code'    //  5 // what to do in case an unknown code is used with
    165       => (isset($ec_conf[5]) and in_array($ec_conf[5],
    166       $ec_conf_possible_values['unknown_code'])) ? $ec_conf[5] : '1',
    167                             // "autolog" parameter :
    168                             //   0 : nothing (display home page, index.php
    169                             //       (not logged in of course));
    170                             //   1 : display "access denied" page;
    171                             //   2 : display an A. P. precised below.
    172                             //
    173     'unknown_code_ap_id' // 6| the id of the Additional Page which must be
    174       => (isset($ec_conf[6])) ? $ec_conf[6] : '0',
    175                             // used in case of usage of an unknow code;
    176                             // several vals.
    177                             //
    178     'comment_display' => ($simple_mode_on and isset($conf['ec_comment_display'])
    179                     and in_array($conf['ec_comment_display'],
    180                     $ec_conf_possible_values['ec_comment_display'])) ?
    181       $conf['ec_comment_display'] : (isset($ec_conf[7]) and
    182       in_array($ec_conf[7], $ec_conf_possible_values['comment_display'])) ?
    183       $ec_conf[7] : '1',
    184                       //  7 // the way the comment is displayed in "entries"
    185                             // tab : 0, as tooltip; 1, on a line under code
    186                             // If Event Cats is in "simple mode", takes the
    187                             // value of $conf['ec_comment_display'] if set.
    188                             //
    189     'in_help_display' //  8 // whether the help banner is displayed.
    190       => (isset($ec_conf[8]) and in_array($ec_conf[8],
    191       $ec_conf_possible_values['in_help_display'])) ? $ec_conf[8] : '1',
    192                             // 0: not displayed; 1 : displayed (surprising !)
    193                             //
    194     'display_connection' => ($simple_mode_on and
    195                     isset($conf['ec_display_connection']) and
    196                     in_array($conf['ec_display_connection'],
    197                     $ec_conf_possible_values['ec_display_connection'])) ?
    198       $conf['ec_display_connection'] : (isset($ec_conf[9]) and
    199       in_array($ec_conf[9], $ec_conf_possible_values['display_connection'])) ?
    200       $ec_conf[9] : '1',
    201                       //  9 // whether the "Connection" link must be displayed
    202                             // for generic users, 0 or 1.
    203                             // If Event Cats is in "simple mode", takes the
    204                             // value of $conf['ec_display_connection'] if set.
    205                             //
    206     'simple_mode_on' => ($simple_mode_on) ?
    207       '1' : '0',      // 10 // whether the presentation of the plugin is in
    208                             // "simple mode" or not.
    209                             // 0: normal view; 1 : simple view.
    210                             // The default value can be modified to 0 (normal
    211                             // view) if Event Cats was already installed
    212                             // previously.
    213                             //
    214     'display_full_button' => ($simple_mode_on and
    215                     isset($conf['ec_display_full_button']) and
    216                     in_array($conf['ec_display_full_button'],
    217                     $ec_conf_possible_values['ec_display_full_button'])) ?
    218       $conf['ec_display_full_button'] : (isset($ec_conf[11]) and
    219     in_array($ec_conf[11], $ec_conf_possible_values['display_full_button'])) ?
    220        $ec_conf[11] : '1',
    221                       // 11 // whether the "Show full features" button must be
    222                             // displayed, 0 or 1. The default value can be
    223                             // modified to 0 (don't display) if
    224                             // $conf['ec_display_full_button'] has val. false.
    225   );
     167// Change $ec_conf values if needed
     168if (!$v or $simple_mode_on) {
    226169 
    227 // Once these lines have been updated, you don't need to change anything
    228 // else. Everything is managed by the code.
    229 //----------------------------------------------------------------------------
    230 
    231   // Set $ec_conf to proper default values if needed, and writes its values
    232   // in the DB
    233   $ec_conf = array_values($ec_conf_default);
    234 
    235   change_ec_conf('activated', $u); // writes in the DB
     170  // Perform repetitve work
     171  function test_conf($tbl, $k, $k2 = NULL) {
     172  global $ec_conf_possible_values;
     173    if (!isset($k2)) $k2 = $k;
     174    return (isset($tbl[$k]) and
     175     in_array($tbl[$k], $ec_conf_possible_values[$k2]));
     176  }
     177 
     178  // Avoid that $conf (very big) is passed as argument to function test_conf
     179  $conf_temp = array();
     180  foreach ($ec_conf_possible_values as $key => $val)
     181   if (isset($conf['ec_'.$key])) $conf_temp[$key] = $conf['ec_'.$key];
     182 
     183  if (!$v) {
     184    // Determine default values of $ec_conf
     185    $ec_conf = array(
     186      $ec_conf_index['activated'] => $u,
     187      $ec_conf_index['howto'] => $s,
     188      $ec_conf_index['dup_allow'] =>
     189        ($simple_mode_on and test_conf($conf_temp, 'dup_allow')) ?
     190          $conf_temp['dup_allow']
     191          : (test_conf($ec_conf, $ec_conf_index['dup_allow'], 'dup_allow')) ?
     192            $ec_conf[$ec_conf_index['dup_allow']]
     193            : '2',
     194      $ec_conf_index['duplic_display'] =>
     195        ($simple_mode_on and test_conf($conf_temp, 'duplic_display')) ?
     196          $conf_temp['duplic_display']
     197          : (test_conf($ec_conf, $ec_conf_index['duplic_display'],
     198             'duplic_display')) ?
     199            $ec_conf[$ec_conf_index['duplic_display']]
     200            : '2',
     201      $ec_conf_index['auto_code_dg_nb'] =>
     202        ($simple_mode_on and test_conf($conf_temp, 'auto_code_dg_nb')) ?
     203          $conf_temp['auto_code_dg_nb']
     204          : (test_conf($ec_conf, $ec_conf_index['auto_code_dg_nb'],
     205             'auto_code_dg_nb')) ?
     206            $ec_conf[$ec_conf_index['auto_code_dg_nb']]
     207            : '10',
     208      $ec_conf_index['unknown_code'] =>
     209        (test_conf($ec_conf, $ec_conf_index['unknown_code'],
     210         'unknown_code')) ?
     211          $ec_conf[$ec_conf_index['unknown_code']]
     212          : '1',
     213      $ec_conf_index['unknown_code_ap_id'] =>
     214        (isset($ec_conf[$ec_conf_index['unknown_code_ap_id']])) ?
     215          $ec_conf[$ec_conf_index['unknown_code_ap_id']]
     216          : '0',
     217      $ec_conf_index['comment_display'] =>
     218        ($simple_mode_on and test_conf($conf_temp, 'comment_display')) ?
     219          $conf_temp['comment_display']
     220          : (test_conf($ec_conf, $ec_conf_index['comment_display'],
     221             'comment_display')) ?
     222            $ec_conf[$ec_conf_index['comment_display']]
     223            : '1',
     224      $ec_conf_index['in_help_display'] =>
     225        (test_conf($ec_conf, $ec_conf_index['in_help_display'],
     226         'in_help_display')) ?
     227            $ec_conf[$ec_conf_index['in_help_display']]
     228            : '1',
     229      $ec_conf_index['display_connection'] =>
     230        ($simple_mode_on and test_conf($conf_temp, 'display_connection')) ?
     231          $conf_temp['display_connection']
     232          : (test_conf($ec_conf, $ec_conf_index['display_connection'],
     233             'display_connection')) ?
     234            $ec_conf[$ec_conf_index['display_connection']]
     235            : '1',
     236      $ec_conf_index['simple_mode_on'] =>
     237        ($simple_mode_on) ? '1' : '0',
     238      $ec_conf_index['display_full_button'] =>
     239        ($simple_mode_on and test_conf($conf_temp, 'display_full_button')) ?
     240          $conf_temp['display_full_button']
     241          : (test_conf($ec_conf, $ec_conf_index['display_full_button'],
     242             'display_full_button')) ?
     243            $ec_conf[$ec_conf_index['display_full_button']]
     244            : '1',
     245    );
     246    change_ec_conf('activated', $u); // write in the DB
     247  }
     248  else { // $simple_mode_on is true ; check $conf values for Event Cats
     249    foreach ($ec_conf_possible_values as $key => $val)
     250     if (test_conf($conf_temp, $key))
     251      change_ec_conf($key, $conf_temp[$key]);
     252  }
     253  unset($conf_temp);
    236254}
    237255// now :
    238256//   _ the number of parameters is the same in the DB as the number of
    239 //     default parameters;
     257//     possible parameters;
    240258//   _ the parameters have the default values if needed;
    241259//   _ the plugin shows it is active if it is the case;
  • extensions/event_cats/main.inc.php

    r7066 r7084  
    3232// +-----------------------------------------------------------------------+
    3333
    34 // Keeps file coded in UTF-8 without BOM : é
     34// Keeps file coded in UTF-8 without BOM: é
    3535
    3636if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     
    4343
    4444define( // -------------------------------------------------------------------
    45   'EVNTCATS_INFO_VERSION', // VERSION HISTORY :
     45  'EVNTCATS_INFO_VERSION', // VERSION HISTORY:
    4646   '1.2.3' // Re-fix bug 1432 :-/ ...
    4747// '2.1.0' // When done, will simplfy and allow EC management from categories
     
    5050// '1.2.1' // Improve EN translation thanks to Tosca
    5151// '1.2.0' // Add feature 1335, Possibility to display the 'Connection'
    52 //         // link in identification block menu for generic users ;
     52//         // link in identification block menu for generic users;
    5353//         // finish (yes !) english translation
    5454// '1.1.5' // Fix bugs 1324 and 1325
    5555// '1.1.4' // Improve help banner
    56 // '1.1.3' // Better help banner management ; finalize banner texts
    57 // '1.1.2' // Better help banner example : some examples
    58 // '1.1.1' // Better help banner example ; but still no text in it
    59 // '1.1.0' // First bugs (1305 and 1306) corrected ;
     56// '1.1.3' // Better help banner management; finalize banner texts
     57// '1.1.2' // Better help banner example: some examples
     58// '1.1.1' // Better help banner example; but still no text in it
     59// '1.1.0' // First bugs (1305 and 1306) corrected;
    6060           // add newly created user/group association with cat/AP (was
    61            // forgotten) ; begin help banner
     61           // forgotten); begin help banner
    6262// '1.0.0' // Conception version
    6363); // ------------------------------------------------------------------------
     
    103103  return (
    104104   $help_content = (is_admin() and $page == 'help') ?
    105     load_language($page.'.html', EVNTCATS_PATH, array('return' => true)) : false
     105    load_language($page.'.html',EVNTCATS_PATH,array('return' => true)) : false
    106106  ) ? $popup_help_content.$help_content : $popup_help_content;
    107107}
     
    112112 *
    113113 * auto_log_user()
    114  * the function uses the value of the argument "autolog" of the posted URL, as a code
    115  * to know which username has to be logged in.
     114 * the function uses the value of the argument "autolog" of the posted URL,
     115 * as a code to know which username has to be logged in.
    116116 *
    117117 * @param no parameter
     
    128128  $ec_img = NULL;
    129129 
    130   if (isset($_GET['autolog']) and (read_ec_conf('activated') == 1)) {
     130  if (isset($_GET['autolog']) and (read_ec_conf('activated') == '1')) {
    131131    if (!is_a_guest()) {
    132132      $url = '';
     
    166166            if (isset($ec_img)) {
    167167              if (ec_image_exists($ec_cat, $ec_img)) {
    168                 redirect(PHPWG_ROOT_PATH.'picture.php?/'.$ec_img.'/category/'.$ec_cat);
     168       redirect(PHPWG_ROOT_PATH.'picture.php?/'.$ec_img.'/category/'.$ec_cat);
    169169              }
    170170            }
     
    230230  global $user;
    231231
    232   if (!is_a_guest() and !is_admin()) if (
    233     read_ec_conf('dup_allow') == '1' or (
    234       read_ec_conf('dup_allow') == '2' and
    235       dup_allowed($user['id'])
    236     )
    237   ) {
    238     // User access
    239     $result = pwg_query("
    240       SELECT `cat_id`
    241       FROM `".USER_ACCESS_TABLE."`
    242       WHERE `user_id` = ".$user['id'].";
    243     ");
    244     $insert = array();
    245     while ($row = pwg_db_fetch_assoc($result))
    246      $insert[] = "(".$new_user['id'].",".$row['cat_id'].")";
    247     if (!empty($insert)) pwg_query("
    248       INSERT INTO `".USER_ACCESS_TABLE."`
    249       VALUES ".implode(',', $insert).";
    250     ");
    251 
    252     // User groups
    253     $result = pwg_query("
    254       SELECT `group_id`
    255       FROM `".USER_GROUP_TABLE."`
    256       WHERE `user_id` = ".$user['id'].";
    257     ");
    258     $insert = array();
    259     while ($row = pwg_db_fetch_assoc($result))
    260      $insert[] = "(".$new_user['id'].",".$row['group_id'].")";
    261     if (!empty($insert)) pwg_query("
    262       INSERT INTO `".USER_GROUP_TABLE."`
    263       VALUES ".implode(',', $insert).";
    264     ");
    265 
    266     // User infos
    267     $result = pwg_query("
    268       SELECT `level`
    269       FROM `".USER_INFOS_TABLE."`
    270       WHERE `user_id` = ".$user['id'].";
    271     ");
    272     $insert = array();
    273     while ($row = pwg_db_fetch_assoc($result))
    274      $insert[] = "(".$new_user['id'].",".$row['level'].")";
    275     if (!empty($insert)) pwg_query("
    276       UPDATE `".USER_INFOS_TABLE."`
    277       SET `level` = ".$user['level']."
    278       WHERE `user_id` = ".$new_user['id'].";
    279     ");
     232  if (read_ec_conf('activated') == '1') {
     233    if (
     234      !is_a_guest() and !is_admin() and (
     235        read_ec_conf('dup_allow') == '1' or (
     236          read_ec_conf('dup_allow') == '2' and (
     237            dup_allowed($user['id']) or (
     238              read_ec_conf('simple_mode_on') == '1' and
     239              is_generic()
     240            )
     241          )
     242        )
     243      )
     244    ) {
     245      // User access
     246      $result = pwg_query("
     247        SELECT `cat_id`
     248        FROM `".USER_ACCESS_TABLE."`
     249        WHERE `user_id` = ".$user['id'].";
     250      ");
     251      $insert = array();
     252      while ($row = pwg_db_fetch_assoc($result))
     253       $insert[] = "(".$new_user['id'].",".$row['cat_id'].")";
     254      if (!empty($insert)) pwg_query("
     255        INSERT INTO `".USER_ACCESS_TABLE."`
     256        VALUES ".implode(',', $insert).";
     257      ");
     258
     259      // User groups
     260      $result = pwg_query("
     261        SELECT `group_id`
     262        FROM `".USER_GROUP_TABLE."`
     263        WHERE `user_id` = ".$user['id'].";
     264      ");
     265      $insert = array();
     266      while ($row = pwg_db_fetch_assoc($result))
     267       $insert[] = "(".$new_user['id'].",".$row['group_id'].")";
     268      if (!empty($insert)) pwg_query("
     269        INSERT INTO `".USER_GROUP_TABLE."`
     270        VALUES ".implode(',', $insert).";
     271      ");
     272
     273      // User infos
     274      $result = pwg_query("
     275        SELECT `level`
     276        FROM `".USER_INFOS_TABLE."`
     277        WHERE `user_id` = ".$user['id'].";
     278      ");
     279      $insert = array();
     280      while ($row = pwg_db_fetch_assoc($result))
     281       $insert[] = "(".$new_user['id'].",".$row['level'].")";
     282      if (!empty($insert)) pwg_query("
     283        UPDATE `".USER_INFOS_TABLE."`
     284        SET `level` = ".$user['level']."
     285        WHERE `user_id` = ".$new_user['id'].";
     286      ");
     287    }
    280288  }
    281289}
     
    313321  global $lang, $template, $user;
    314322 
    315   if (version_compare(PHPWG_VERSION, '2.1.0', '<')) {
    316     // Makes the "quick connect" fieldset able to redirect to current page
    317     // after user identification, just as does the "connection" link.
    318     $template->assign(array('U_REDIRECT' => $_SERVER['REQUEST_URI']));
    319     $template->set_prefilter('menubar', 'ec_duplicate_prefilter');
    320   }
    321  
    322   // Adds duplication link, if needed
    323   if (!is_admin() and !is_a_guest()) if (
    324     read_ec_conf('dup_allow') == '1' or (
    325       read_ec_conf('dup_allow') == '2' and
    326       dup_allowed($user['id'])
    327     )
    328   ) {
    329     $template->assign('U_REGISTER', get_root_url().'register.php');
     323  if (read_ec_conf('activated') == '1') {
     324    if (version_compare(PHPWG_VERSION, '2.1.0', '<')) {
     325      // Makes the "quick connect" fieldset able to redirect to current page
     326      // after user identification, just as does the "connection" link.
     327      $template->assign(array('U_REDIRECT' => $_SERVER['REQUEST_URI']));
     328      $template->set_prefilter('menubar', 'ec_duplicate_prefilter');
     329    }
     330   
     331    // Add duplication link, if needed
    330332    if (
    331       read_ec_conf('duplic_display') == '1' or (
    332         read_ec_conf('duplic_display') == '2' and
    333         !is_generic()
     333      !is_admin() and !is_a_guest() and (
     334        read_ec_conf('dup_allow') == '1' or (
     335          read_ec_conf('dup_allow') == '2' and (
     336            dup_allowed($user['id']) or (
     337              read_ec_conf('simple_mode_on') == '1' and
     338              is_generic()
     339            )
     340          )
     341        )
    334342      )
    335343    ) {
    336       $lang['Register'] = $lang['Duplicate'];
    337       $lang['Create a new account'] =
    338        $lang['Create a new account with same properties'];
    339     }
    340   }
    341  
    342   // Adds connection link, if needed
    343   if (read_ec_conf('display_connection') == '1' and is_generic()) {
    344     // Adds connection link
    345     $template->assign(
    346       'U_LOGIN',
    347       get_root_url().'identification.php?redirect='.$_SERVER['REQUEST_URI']
    348     );
     344      $template->assign('U_REGISTER', get_root_url().'register.php');
     345      if (
     346        read_ec_conf('duplic_display') == '1' or (
     347          read_ec_conf('duplic_display') == '2' and
     348          !is_generic()
     349        )
     350      ) {
     351        $lang['Register'] = $lang['Duplicate'];
     352        $lang['Create a new account'] =
     353         $lang['Create a new account with same properties'];
     354      }
     355    }
     356   
     357    // Adds connection link, if needed
     358    if (read_ec_conf('display_connection') == '1' and is_generic()) {
     359      // Adds connection link
     360      $template->assign(
     361        'U_LOGIN',
     362        get_root_url().'identification.php?redirect='.$_SERVER['REQUEST_URI']
     363      );
     364    }
    349365  }
    350366}
  • extensions/event_cats/maintain.inc.php

    r4436 r7084  
    2323// +-----------------------------------------------------------------------+
    2424
    25 // Keeps file coded in UTF-8 without BOM : é
     25// Keeps file coded in UTF-8 without BOM: é
    2626
    2727// ***********************************************************************
    28 // ** maintain.inc.php : Installation page for Piwigo plugin Event Cats **
     28// ** maintain.inc.php: Installation page for Piwigo plugin Event Cats **
    2929// ***********************************************************************
    3030
     
    4242  global $prefixeTable;
    4343
    44         pwg_query("DELETE FROM `".CONFIG_TABLE."` WHERE `param` = 'event_cats' LIMIT 1;");
     44        pwg_query("
     45   DELETE IGNORE FROM `".CONFIG_TABLE."` WHERE `param` = 'event_cats' LIMIT 1;
     46  ");
    4547        return pwg_query('DROP TABLE IF EXISTS `'.$prefixeTable.'event_cats`;');
    4648}
     
    7274
    7375/*
    74 Explanations on table structure :
     76Explanations on table structure:
    7577
    76 code    : the code used as "autolog" argument. If thie code provided by the
    77           visitor does not exist in the table, the administrator can choose
    78           whether the visitor is redirected to the home page (nothing
    79           happens) or to the "access denied" page ;
    80 user_id : the account concerned in following values ;
    81 action  : the action to perform :
    82    ec_nok : code disabled : account not logged in, visitor (guest) redirected
    83             to an explaining Additional Page (arg2 field). If Additional Page
    84             plugin is not activated, redirection to the "access denied" page ;
    85    ec_ok  : code OK, account logged in. Redirection depends on arg1 and arg2
    86             values. There are four cases :
    87      arg1 and arg2 are both NULL : home page ;
    88      arg1 not NULL and arg2 NULL : category ;
    89      arg1 NULL and arg2 not NULL : Additional Page ;
    90      arg1 and arg2 both not NULL : Image page.
    91             If arg1 is a valid category id, and arg2 is not a valid image id,
    92             redirection to category. In all other cases where the arg1 or arg2
    93             is not valid, redirection to home page.
    94 arg1    : (described above) ;
    95 arg2    : (described above) ;
    96 forced  : allows the administrator to impose that, for certain codes, the
    97           settings specified in the database ("action", "arg1", "arg2") are
    98           applied, whatever can be the arguments given in the URL.
     78code   : the code used as "autolog" argument. If thie code provided by the
     79         visitor does not exist in the table, the administrator can choose
     80         whether the visitor is redirected to the home page (nothing
     81         happens) or to the "access denied" page;
     82user_id: the account concerned in following values;
     83action : the action to perform:
     84   ec_nok: code disabled: account not logged in, visitor (guest) redirected
     85           to an explaining Additional Page (arg2 field). If Additional Page
     86           plugin is not activated, redirection to the "access denied" page;
     87   ec_ok : code OK, account logged in. Redirection depends on arg1 and arg2
     88           values. There are four cases:
     89     arg1 and arg2 are both NULL: home page;
     90     arg1 not NULL and arg2 NULL: category;
     91     arg1 NULL and arg2 not NULL: Additional Page;
     92     arg1 and arg2 both not NULL: Image page.
     93           If arg1 is a valid category id, and arg2 is not a valid image id,
     94           redirection to category. In all other cases where the arg1 or arg2
     95           is not valid, redirection to home page.
     96arg1   : (described above);
     97arg2   : (described above);
     98forced : allows the administrator to impose that, for certain codes, the
     99         settings specified in the database ("action", "arg1", "arg2") are
     100         applied, whatever can be the arguments given in the URL;
     101comment: a reminder for the webmaster.
    99102           
    100 * As a precision :
     103* As a precision:
    101104    in the PHP code, the "action" can also have the following values, so to
    102     display accurate messages in the admin page :
    103   ec_nok_action_pb   : the same "code" is used in more than one entries in the
    104                        DB (which is allowed) and is not always associated to
    105                        the same action ('ec_ok' in one or more entries, and
    106                        'ec_nok' in one or more other entries). This is
    107                        confusing and makes impossible to log in using this
    108                        code ;
    109   ec_nok_userid_pb   : the same "code" is used in more than one entries in the
    110                        DB (which is allowed) and is not always associated to
    111                        the same user id. This is confusing and makes
    112                        impossible to log in using this code ;
    113   ec_nok_userid_miss : the user id associated to this code does not exist in
    114                        the user ids table ;
    115   ec_nok_ap_pb       : not valid Additional Page id -> access denied ;
    116   ec_ok_ap_pb        : not valid Additional Page id -> home page ;
    117   ec_ok_cat_pb       : not valid category id -> home page ;
    118   ec_ok_img_pb       : not valid image id -> category page ;
     105    display accurate messages in the admin page:
     106  ec_nok_action_pb  : the same "code" is used in more than one entries in the
     107                      DB (which is allowed) and is not always associated to
     108                      the same action ('ec_ok' in one or more entries, and
     109                      'ec_nok' in one or more other entries). This is
     110                      confusing and makes impossible to log in using this
     111                      code;
     112  ec_nok_userid_pb  : the same "code" is used in more than one entries in the
     113                      DB (which is allowed) and is not always associated to
     114                      the same user id. This is confusing and makes
     115                      impossible to log in using this code;
     116  ec_nok_userid_miss: the user id associated to this code does not exist in
     117                      the user ids table;
     118  ec_nok_ap_pb      : not valid Additional Page id -> access denied;
     119  ec_ok_ap_pb       : not valid Additional Page id -> home page;
     120  ec_ok_cat_pb      : not valid category id -> home page;
     121  ec_ok_img_pb      : not valid image id -> category page;
    119122
    120123_ the two main fields are "user_id" and "code", as the main purpose of the
     
    124127_ though, even if "action", "user_id" and "code" are important, all of them
    125128  can be omitted (thus can be NULL), and both "user_id" and "code" can be
    126   repeated (thus are not UNIQUE). This because :
     129  repeated (thus are not UNIQUE). This because:
    127130  _ the same code can automatically log in ("autolog") the same account
    128131    following several ways, depending on "cat", "img", and "ap" arguments of
    129     the URL ; and thus different ways can be stored in the DB ;
     132    the URL; and thus different ways can be stored in the DB;
    130133  _ a "disabled" code (the user tries to "autolog", but (s)he's not allowed
    131     to) does not need a corresponding "user_id", thus "user_id" can be NULL ;
     134    to) does not need a corresponding "user_id", thus "user_id" can be NULL;
    132135  _ "user_id" field is used to store groups ids when "code" is NULL, to
    133     identify groups authorized to duplication ;
     136    identify groups authorized to duplication;
    134137_ "code" does not have the MySQL UNIQUE attribute, but it has to be unique
    135138  when the "forced" Event Cats parameter is true, which is the case when this
Note: See TracChangeset for help on using the changeset viewer.