$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. //---------------------------------------------------------------------------- // The following lines allow to change the number of configuration items, the // default values they can have, and also their possible other values, very // quickly. // Gives configuration items names and default values. Only strings. $ec_conf_default = array( // PLUGIN CONFIGURATION ($ec_conf) : // --------------------------------- 'activated' // plugin activated, 0 or 1 => '0', // // 'howto' // whether the small aknowledgement message has => '0', // already been displayed, 0 or 1 // 'dup_allow' // duplication allowance : => '2', // 0 : no account ; // 1 : all accounts ; // 2 : specified by group and user ids ; // 'duplic_display' // duplication link display in the menubar : => '2', // 0 : "Register" for everybody ; // 1 : "Duplicate" for everybody ; // 2 : "Register" only for generic accounts, // "Duplicate" for all other accounts ; // 'auto_code_dg_nb' // number of digits when creating a new code => '10', // automatically, several values // 'unknown_code' // what to do in case an unknown code is used with => '1', // "autolog" parameter : // 0 : nothing (display home page, index.php (not // logged in of course)) ; // 1 : display "access denied" page ; // 2 : display an Additional Page precised below. // 'unknown_code_ap_id' // the id of the Additional Page which must be used => '0', // in case of usage of an unknow code, several vals. // 'comment_display' // the way the comment is displayed in "entries" => '1', // tab : 0, as tooltip ; 1, on a line under code // 'in_help_display' // whether the help banner is displayed. => '1', // 0: not displayed ; 1 : displayed (surprising !) // 'display_connection' // whether the "Connection" link must be displayed => '0', // for generic users, 0 or 1. ); // Gives possible values. In case values cannot be predicted, just provide an // empty array : array() . $ec_conf_possible_values = array( 'activated' => array('0', '1'), 'howto' => array('0', '1'), 'dup_allow' => array('0', '1', '2'), 'duplic_display' => array('0', '1', '2'), 'auto_code_dg_nb' => array( '4', '5', '8', '10', '12', '15', '16', '20', '24', '25', '30', '32'), 'unknown_code' => array('0', '1', '2'), 'unknown_code_ap_id' => array(), 'comment_display' => array('0', '1'), 'in_help_display' => array('0', '1'), 'display_connection' => array('0', '1'), ); // Once these lines have been updated, you don't need to change anything // else. Everything is managed by the code ; the only effect being that // existing configuration values in the DB are reset to their default // values -- normally not a harmful effect. //---------------------------------------------------------------------------- $ec_conf_index = array_flip(array_keys($ec_conf_default)); $t = array(); $u = '0'; $v = false; $r = pwg_query(" SELECT `value` FROM `".CONFIG_TABLE."` WHERE `param` = 'event_cats'; "); if (pwg_db_num_rows($r)) { $t = pwg_db_fetch_row($r); $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index)); $u = $ec_conf[0]; } // $v is false // _ if the entry in the table doesn't exist ; // _ if the entry in the table exists, but its number of parameters is // different than the number of default parameters. // $u is '0' if the plugin has not yet been activated, '1' if it has been. if (!$v) { $ec_conf = array_values($ec_conf_default); change_ec_conf('activated', $u); // writes in the DB } // now : // _ the number of parameters is the same in the DB as the number of // default parameters ; // _ the parameters have the default values if needed ; // _ the plugin shows it is active if it is the case. unset($t, $u, $v); /* * 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; } } ?>