Changeset 8956 for extensions/event_cats/include/ec_conf.inc.php
- Timestamp:
- Jan 28, 2011, 8:56:39 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/event_cats/include/ec_conf.inc.php
r7832 r8956 23 23 // +-----------------------------------------------------------------------+ 24 24 25 // Keeps file coded in UTF-8 without BOM : é25 // Keeps file coded in UTF-8 without BOM : é 26 26 27 27 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 28 28 29 global $ec_conf, $page, $ec_conf_index, $ec_conf_possible_values, $ec_debug; 30 31 // --------------------------------------------------------------------------- 32 // $ec_conf initalization 33 // --------------------------------------------------------------------------- 34 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 // ----- 29 global $ec_conf, $page, $ec_conf_index, $ec_conf_default, 30 $ec_conf_possible_values; 31 32 // $ec_conf initalization 45 33 46 34 // $ec_conf has numeric indexes (instead of string keys like 'activated', 47 35 // 'howto'...) because of its first reading, done with the "explode" function. 48 // It would be very easy to build a string keys indexed array, thanks to36 // It would be very easy to build a string keys indexed array, thanks to 49 37 // following instructions : 50 38 /* 51 $t = pwg_db_fetch_row(pwg_query("39 $t = mysql_fetch_row(pwg_query(" 52 40 SELECT `value` 53 41 FROM `".CONFIG_TABLE."` … … 63 51 64 52 //---------------------------------------------------------------------------- 65 66 // Give possible $ec_conf values. In case values cannot be predicted, just 67 // provide an empty array : array() . 53 // The following lines allow to change the number of configuration items, the 54 // default values they can have, and also their possible other values, very 55 // quickly. 56 57 // Gives configuration items names and default values. Only strings. 58 $ec_conf_default = array( // PLUGIN CONFIGURATION ($ec_conf) : 59 // --------------------------------- 60 'activated' // plugin activated, 0 or 1 61 => '0', // 62 // 63 'howto' // whether the small aknowledgement message has 64 => '0', // already been displayed, 0 or 1 65 // 66 'dup_allow' // duplication allowance : 67 => '2', // 0 : no account ; 68 // 1 : all accounts ; 69 // 2 : specified by group and user ids ; 70 // 71 'duplic_display' // duplication link display in the menubar : 72 => '2', // 0 : "Register" for everybody ; 73 // 1 : "Duplicate" for everybody ; 74 // 2 : "Register" only for generic accounts, 75 // "Duplicate" for all other accounts ; 76 // 77 'auto_code_dg_nb' // number of digits when creating a new code 78 => '10', // automatically, several values 79 // 80 'unknown_code' // what to do in case an unknown code is used with 81 => '1', // "autolog" parameter : 82 // 0 : nothing (display home page, index.php (not 83 // logged in of course)) ; 84 // 1 : display "access denied" page ; 85 // 2 : display an Additional Page precised below. 86 // 87 'unknown_code_ap_id' // the id of the Additional Page which must be used 88 => '0', // in case of usage of an unknow code, several vals. 89 // 90 'comment_display' // the way the comment is displayed in "entries" 91 => '1', // tab : 0, as tooltip ; 1, on a line under code 92 // 93 'in_help_display' // whether the help banner is displayed. 94 => '1', // 0: not displayed ; 1 : displayed (surprising !) 95 // 96 'display_connection' // whether the "Connection" link must be displayed 97 => '0', // for generic users, 0 or 1. 98 ); 99 100 // Gives possible values. In case values cannot be predicted, just provide an 101 // empty array : array() . 68 102 $ec_conf_possible_values = array( 69 'activated' => array('0', '1'), // 0 70 // plugin activated 71 'howto' => array('0', '1'), // 1 72 // whether the small aknowledgement message has already been displayed 73 '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. 81 '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. 89 'auto_code_dg_nb' => array( '4', '5', '8', '10', '12', '15', 90 '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. 95 '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. 100 '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). 103 '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. 108 'in_help_display' => array('0', '1'), // 8 109 // whether the help banner is displayed (default: 1). 110 '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. 115 '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. 120 '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. 103 'activated' => array('0', '1'), 104 'howto' => array('0', '1'), 105 'dup_allow' => array('0', '1', '2'), 106 'duplic_display' => array('0', '1', '2'), 107 'auto_code_dg_nb' => array( '4', '5', '8', '10', '12', '15', 108 '16', '20', '24', '25', '30', '32'), 109 'unknown_code' => array('0', '1', '2'), 110 'unknown_code_ap_id' => array(), 111 'comment_display' => array('0', '1'), 112 'in_help_display' => array('0', '1'), 113 'display_connection' => array('0', '1'), 124 114 ); 125 115 126 // $ec_conf_index is an array of the indexes of $ec_conf. Thus does it allow 127 // to check if X exists when asking for $ec_conf[X]. 128 $ec_conf_index = array_flip(array_keys($ec_conf_possible_values)); 129 130 // Get current value of $ec_conf, if the entry in the DB exists. 131 $t = array(); $u = '0'; $v = false; $w = false; $ec_conf = array(); $s = '0'; 132 if ($w = ( // $w becomes true if the query succeeds <=> if EC was already in 133 // $t gets event_cats config value (array to be "exploded") 134 ($t = pwg_db_fetch_row(pwg_query(" 116 // Once these lines have been updated, you don't need to change anything 117 // else. Everything is managed by the code ; the only effect being that 118 // existing configuration values in the DB are reset to their default 119 // values -- normally not a harmful effect. 120 //---------------------------------------------------------------------------- 121 122 $ec_conf_index = array_flip(array_keys($ec_conf_default)); 123 124 $t = array(); $u = '0'; $v = false; 125 if ($v = ( 126 ($t = mysql_fetch_row(pwg_query(" 135 127 SELECT `value` 136 128 FROM `".CONFIG_TABLE."` … … 139 131 ) { 140 132 $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index)); 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 144 } 145 if ($v and !$w) die('$v true with $w false in ec_conf.inc.php'); 146 // $w is false if the entry in the table doesn't exist; 147 // $v is false if the entry in the table doesn't exist; or exists, but its 148 // number of parameters is different than the number of default parameters. 149 // $u is '0' if the plugin is not activated, '1' if it is. 150 // $s allows to display the aknowledgement message when config changes. 151 // If $v or $w are false, all $ec_conf values are set to default values. But 152 // default values must first take values specified in $conf, if they are set. 153 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. 157 $simple_mode_on = ( 158 (!$v and !$w) or ( 159 isset($ec_conf[$ec_conf_index['simple_mode_on']]) and 160 $ec_conf[$ec_conf_index['simple_mode_on']] == '1' 161 ) or ( 162 isset($conf['ec_display_full_button']) and 163 $conf['ec_display_full_button'] == false 164 ) 165 ); 166 167 // Change $ec_conf values if needed 168 if (!$v or $simple_mode_on) { 169 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); 133 $u = $ec_conf[0]; 134 } 135 // $v is false 136 // _ if the entry in the table doesn't exist ; 137 // _ if the entry in the table exists, but its number of parameters is 138 // different than the number of default parameters. 139 // $u is '0' if the plugin has not yet been activated, '1' if it has been. 140 if (!$v) { 141 $ec_conf = array_values($ec_conf_default); 142 change_ec_conf('activated', $u); // writes in the DB 254 143 } 255 144 // now : 256 145 // _ the number of parameters is the same in the DB as the number of 257 // possible parameters; 258 // _ the parameters have the default values if needed; 259 // _ the plugin shows it is active if it is the case; 260 // _ correct values will be returned when using procedure read_ec_conf($c). 261 262 unset($s, $t, $u, $v, $w, $simple_mode_on); 263 // And NOW can change_ec_conf and read_ec_conf be used properly... 264 265 // --------------------------------------------------------------------------- 266 // End of $ec_conf initalization 267 // --------------------------------------------------------------------------- 146 // default parameters ; 147 // _ the parameters have the default values if needed ; 148 // _ the plugin shows it is active if it is the case. 149 unset($t, $u, $v); 268 150 269 151 /* … … 273 155 * 274 156 * @param 275 * $c : conf value to update ;157 * $c : conf value to update ; 276 158 * $v : value to give to $ec_conf[$c]. 277 159 * @return … … 280 162 function change_ec_conf($c, $v) { 281 163 global $ec_conf, $page, $ec_conf_index, $ec_conf_possible_values; 282 283 164 if (array_key_exists($c, $ec_conf_index)) { 284 165 if ( … … 309 190 * 310 191 * @param 311 * $c : conf value to update ;192 * $c : conf value to update ; 312 193 * @return 313 194 * $ec_conf value
Note: See TracChangeset
for help on using the changeset viewer.