$v) $ec_conf[$k] = ec_conf_temp[$i++]; */ // Though, I prefer to keep $ec_conf with numeric indexes, so to be compelled // to go through function change_ec_conf() to modify ec_conf, and thus update // the DB at the same time. //---------------------------------------------------------------------------- // Give possible $ec_conf values. In case values cannot be predicted, just // provide an empty array : array() . $ec_conf_possible_values = array( 'activated' => array('0', '1'), // 0 // plugin activated 'howto' => array('0', '1'), // 1 // whether the small aknowledgement message has already been displayed 'dup_allow' => array('0', '1', '2'), // 2 // duplication allowance : // 0 : no account; // 1 : all accounts; // 2 : specified by group, type, and user ids (default). // If Event Cats is in "simple mode", get the value of // $conf['ec_dup_allow'] if it is set; and an allowance to duplicate only // generic accounts will be defined if the value is 2. 'duplic_display' => array('0', '1', '2'), // 3 // duplication link display in the menubar : // 0 : "Register" for everybody; // 1 : "Duplicate" for everybody; // 2 : "Register" only for generic accounts, // "Duplicate" for all other accounts (default); // If Event Cats is in "simple mode", takes the value of // $conf['ec_duplic_display'] if it's set. 'auto_code_dg_nb' => array( '4', '5', '8', '10', '12', '15', '16', '20', '24', '25', '30', '32'), // 4 // number of digits when creating a new code automatically, several values // (default: 10) // If Event Cats is in "simple mode", get the value of // $conf['ec_auto_code_dg_nb'] if set. 'unknown_code' => array('0', '1', '2'), // 5 // what to do in case an unknown code is used with "autolog" parameter : // 0 : nothing (display home page, index.php (not logged in of course)); // 1 : display "access denied" page (default); // 2 : display an A. P. precised below. 'unknown_code_ap_id' => array(), // 6 // the id of the Additional Page which must be used in case of usage of an // unknow code; several vals (default: 0). 'comment_display' => array('0', '1'), // 7 // the way the comment is displayed in "entries" tab: // 0, as tooltip; 1 (default), on a line under code // If Event Cats is in "simple mode", get the value of // $conf['ec_comment_display'] if set. 'in_help_display' => array('0', '1'), // 8 // whether the help banner is displayed (default: 1). 'display_connection' => array('0', '1'), // 9 // whether the "Connection" link must be displayed for generic users // (default: 1) // If Event Cats is in "simple mode", takes the value of // $conf['ec_display_connection'] if set. 'simple_mode_on' => array('0', '1'), // 10 // whether the presentation of the plugin is in "simple mode" or not. // (default: 1) // The default value can be modified to 0 (normal view) if Event Cats was // already installed previously. 'display_full_button' => array('0', '1'), // 11 // whether the "Show full features" button must be displayed (default: 1). // The default value can be modified to 0 (don't display) if // $conf['ec_display_full_button'] is set, and false. ); // $ec_conf_index is an array of the indexes of $ec_conf. Thus does it allow // to check if X exists when asking for $ec_conf[X]. $ec_conf_index = array_flip(array_keys($ec_conf_possible_values)); // Get current value of $ec_conf, if the entry in the DB exists. $t = array(); $u = '0'; $v = false; $w = false; $ec_conf = array(); $s = '0'; if ($w = ( // $w becomes true if the query succeeds <=> if EC was already in // $t gets event_cats config value (array to be "exploded") ($t = pwg_db_fetch_row(pwg_query(" SELECT `value` FROM `".CONFIG_TABLE."` WHERE `param` = 'event_cats'; "))) !== false) ) { $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index)); $u = $ec_conf[$ec_conf_index['activated']]; $s = ($v) ? $ec_conf[$ec_conf_index['howto']] : '0'; // the aknowledgement // message is displayed again if the configuration changes } if ($v and !$w) die('$v true with $w false in ec_conf.inc.php'); // $w is false if the entry in the table doesn't exist; // $v is false if the entry in the table doesn't exist; or exists, but its // number of parameters is different than the number of default parameters. // $u is '0' if the plugin is not activated, '1' if it is. // $s allows to display the aknowledgement message when config changes. // If $v or $w are false, all $ec_conf values are set to default values. But // default values must first take values specified in $conf, if they are set. // Determine whether simple mode is ON or OFF: simple mode must be on if Event // Cats is just installed, or if it was ON previously, or if // $conf['ec_display_full_button'] is set and is false. $simple_mode_on = ( (!$v and !$w) or ( isset($ec_conf[$ec_conf_index['simple_mode_on']]) and $ec_conf[$ec_conf_index['simple_mode_on']] == '1' ) or ( isset($conf['ec_display_full_button']) and $conf['ec_display_full_button'] == false ) ); // Change $ec_conf values if needed if (!$v or $simple_mode_on) { // Perform repetitve work function test_conf($tbl, $k, $k2 = NULL) { global $ec_conf_possible_values; if (!isset($k2)) $k2 = $k; return (isset($tbl[$k]) and in_array($tbl[$k], $ec_conf_possible_values[$k2])); } // Avoid that $conf (very big) is passed as argument to function test_conf $conf_temp = array(); foreach ($ec_conf_possible_values as $key => $val) if (isset($conf['ec_'.$key])) $conf_temp[$key] = $conf['ec_'.$key]; if (!$v) { // Determine default values of $ec_conf $ec_conf = array( $ec_conf_index['activated'] => $u, $ec_conf_index['howto'] => $s, $ec_conf_index['dup_allow'] => ($simple_mode_on and test_conf($conf_temp, 'dup_allow')) ? $conf_temp['dup_allow'] : (test_conf($ec_conf, $ec_conf_index['dup_allow'], 'dup_allow')) ? $ec_conf[$ec_conf_index['dup_allow']] : '2', $ec_conf_index['duplic_display'] => ($simple_mode_on and test_conf($conf_temp, 'duplic_display')) ? $conf_temp['duplic_display'] : (test_conf($ec_conf, $ec_conf_index['duplic_display'], 'duplic_display')) ? $ec_conf[$ec_conf_index['duplic_display']] : '2', $ec_conf_index['auto_code_dg_nb'] => ($simple_mode_on and test_conf($conf_temp, 'auto_code_dg_nb')) ? $conf_temp['auto_code_dg_nb'] : (test_conf($ec_conf, $ec_conf_index['auto_code_dg_nb'], 'auto_code_dg_nb')) ? $ec_conf[$ec_conf_index['auto_code_dg_nb']] : '10', $ec_conf_index['unknown_code'] => (test_conf($ec_conf, $ec_conf_index['unknown_code'], 'unknown_code')) ? $ec_conf[$ec_conf_index['unknown_code']] : '1', $ec_conf_index['unknown_code_ap_id'] => (isset($ec_conf[$ec_conf_index['unknown_code_ap_id']])) ? $ec_conf[$ec_conf_index['unknown_code_ap_id']] : '0', $ec_conf_index['comment_display'] => ($simple_mode_on and test_conf($conf_temp, 'comment_display')) ? $conf_temp['comment_display'] : (test_conf($ec_conf, $ec_conf_index['comment_display'], 'comment_display')) ? $ec_conf[$ec_conf_index['comment_display']] : '1', $ec_conf_index['in_help_display'] => (test_conf($ec_conf, $ec_conf_index['in_help_display'], 'in_help_display')) ? $ec_conf[$ec_conf_index['in_help_display']] : '1', $ec_conf_index['display_connection'] => ($simple_mode_on and test_conf($conf_temp, 'display_connection')) ? $conf_temp['display_connection'] : (test_conf($ec_conf, $ec_conf_index['display_connection'], 'display_connection')) ? $ec_conf[$ec_conf_index['display_connection']] : '1', $ec_conf_index['simple_mode_on'] => ($simple_mode_on) ? '1' : '0', $ec_conf_index['display_full_button'] => ($simple_mode_on and test_conf($conf_temp, 'display_full_button')) ? $conf_temp['display_full_button'] : (test_conf($ec_conf, $ec_conf_index['display_full_button'], 'display_full_button')) ? $ec_conf[$ec_conf_index['display_full_button']] : '1', ); change_ec_conf('activated', $u); // write in the DB } else { // $simple_mode_on is true ; check $conf values for Event Cats foreach ($ec_conf_possible_values as $key => $val) if (test_conf($conf_temp, $key)) change_ec_conf($key, $conf_temp[$key]); } unset($conf_temp); } // now : // _ the number of parameters is the same in the DB as the number of // possible parameters; // _ the parameters have the default values if needed; // _ the plugin shows it is active if it is the case; // _ correct values will be returned when using procedure read_ec_conf($c). unset($s, $t, $u, $v, $w, $simple_mode_on); // And NOW can change_ec_conf and read_ec_conf be used properly... // --------------------------------------------------------------------------- // End of $ec_conf initalization // --------------------------------------------------------------------------- /* * change_ec_conf($c, $v) * updates Event Cats configuration values in the database as well as in * $ec_conf. * * @param * $c : conf value to update; * $v : value to give to $ec_conf[$c]. * @return * true or false whether the change was OK or not */ function change_ec_conf($c, $v) { global $ec_conf, $page, $ec_conf_index, $ec_conf_possible_values; if (array_key_exists($c, $ec_conf_index)) { if ( count($ec_conf_possible_values[$c]) == 0 or in_array($v, $ec_conf_possible_values[$c]) ) { $ec_conf[$ec_conf_index[$c]] = $v; return (pwg_query(" UPDATE `".CONFIG_TABLE."` SET `value` = \"".implode(',', $ec_conf)."\" WHERE `param` = 'event_cats'; ") !== false); } else { $page['errors'][] = 'Bad change_ec_conf value'; return false; } } else { $page['errors'][] = 'Bad change_ec_conf index'; return false; } } /* * read_ec_conf($c) * returns the value in $ec_conf using string keys. * * @param * $c : conf value to update; * @return * $ec_conf value */ function read_ec_conf($c) { global $ec_conf, $page, $ec_conf_index; if (array_key_exists($c, $ec_conf_index)) return $ec_conf[$ec_conf_index[$c]]; else { $page['errors'][] = 'Bad read_ec_conf index'; return false; } } ?>