Changeset 7067 for extensions/event_cats/include
- Timestamp:
- Oct 1, 2010, 10:47:38 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/event_cats/include/ec_conf.inc.php
r7066 r7067 27 27 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 28 28 29 global $ec_conf, $page, $ec_conf_index, $ec_conf_default, 30 $ec_conf_possible_values; 31 32 // $ec_conf initalization 29 global $ec_conf, $page, $ec_conf_index, $ec_conf_possible_values, $ec_debug; 30 31 // --------------------------------------------------------------------------- 32 // $ec_conf initalization 33 // --------------------------------------------------------------------------- 33 34 34 35 // $ec_conf has numeric indexes (instead of string keys like 'activated', 35 36 // 'howto'...) because of its first reading, done with the "explode" function. 36 // It would be 37 // It would be very easy to build a string keys indexed array, thanks to 37 38 // following instructions : 38 39 /* … … 55 56 // quickly. 56 57 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. 58 // Give possible $ec_conf values. In case values cannot be predicted, just 59 // provide an empty array : array() . 60 $ec_conf_possible_values = array( 61 'activated' => array('0', '1'), // 0 62 'howto' => array('0', '1'), // 1 63 'dup_allow' => array('0', '1', '2'), // 2 64 'duplic_display' => array('0', '1', '2'), // 3 65 'auto_code_dg_nb' => array( '4', '5', '8', '10', '12', '15', 66 '16', '20', '24', '25', '30', '32'), // 4 67 'unknown_code' => array('0', '1', '2'), // 5 68 'unknown_code_ap_id' => array(), // 6 69 'comment_display' => array('0', '1'), // 7 70 'in_help_display' => array('0', '1'), // 8 71 'display_connection' => array('0', '1'), // 9 72 'simple_mode_on' => array('0', '1'), // 10 73 'display_full_button' => array('0', '1'), // 11 98 74 ); 99 75 100 // Gives possible values. In case values cannot be predicted, just provide an 101 // empty array : array() . 102 $ec_conf_possible_values = array( 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'), 114 ); 115 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 = ( 76 // $ec_conf_index is an array of the indexes of $ec_conf. Thus does it allow 77 // to check if X exists when asking for $ec_conf[X]. 78 $ec_conf_index = array_flip(array_keys($ec_conf_possible_values)); 79 80 // Get current value of $ec_conf, if the entry in the DB exists. 81 $t = array(); $u = '0'; $v = false; $w = false; $ec_conf = array(); $s = '0'; 82 if ($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 126 84 ($t = pwg_db_fetch_row(pwg_query(" 127 85 SELECT `value` … … 132 90 $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index)); 133 91 $u = $ec_conf[0]; 92 $s = ($v) ? $ec_conf[1] : '0'; // the aknowledgement message is displayed 93 // again if the configuration changes 134 94 } 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 is138 // 95 if ($v and !$w) die('$v true with $w false in ec_conf.inc.php'); 96 // $w is false if the entry in the table doesn't exist; 97 // $v is false if the entry in the table doesn't exist; or exists, but its 98 // number of parameters is different than the number of default parameters. 139 99 // $u is '0' if the plugin has not yet been activated, '1' if it has been. 100 // $s allows to display the aknowledgement message when config changes. 101 // If $v or $w are false, all $ec_conf values are set to default values. But 102 // default values must first take values specified in $conf, if they are set. 103 104 // Determine whether simple mode is ON or OFF 105 $simple_mode_on = ( 106 (!$v and !$w) or ( 107 // $ec_conf[10] <=> read_ec_conf('simple_mode_on') 108 isset($ec_conf[10]) and $ec_conf[10] == '1' 109 ) or ( 110 isset($conf['ec_display_full_button']) and 111 $conf['ec_display_full_button'] == false 112 ) 113 ); 114 140 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 ); 226 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 141 233 $ec_conf = array_values($ec_conf_default); 234 142 235 change_ec_conf('activated', $u); // writes in the DB 143 236 } 144 237 // now : 145 238 // _ the number of parameters is the same in the DB as the number of 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); 239 // default parameters; 240 // _ the parameters have the default values if needed; 241 // _ the plugin shows it is active if it is the case; 242 // _ correct values will be returned when using procedure read_ec_conf($c). 243 244 unset($t, $u, $v, $w, $simple_mode_on); 245 // And NOW can change_ec_conf and read_ec_conf be used properly... 246 247 // --------------------------------------------------------------------------- 248 // End of $ec_conf initalization 249 // --------------------------------------------------------------------------- 150 250 151 251 /* … … 155 255 * 156 256 * @param 157 * $c : conf value to update 257 * $c : conf value to update; 158 258 * $v : value to give to $ec_conf[$c]. 159 259 * @return … … 162 262 function change_ec_conf($c, $v) { 163 263 global $ec_conf, $page, $ec_conf_index, $ec_conf_possible_values; 264 164 265 if (array_key_exists($c, $ec_conf_index)) { 165 266 if ( … … 168 269 ) { 169 270 $ec_conf[$ec_conf_index[$c]] = $v; 170 return ( pwg_query("271 return ($a=(pwg_query(" 171 272 UPDATE `".CONFIG_TABLE."` 172 273 SET `value` = \"".implode(',', $ec_conf)."\" 173 274 WHERE `param` = 'event_cats'; 174 ") !== false) ;275 ") !== false)); 175 276 } 176 277 else { … … 190 291 * 191 292 * @param 192 * $c : conf value to update 293 * $c : conf value to update; 193 294 * @return 194 295 * $ec_conf value
Note: See TracChangeset
for help on using the changeset viewer.