- Timestamp:
- Nov 6, 2009, 2:37:20 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/event_cats/include/evntcats_admin_funcs.inc.php
r4181 r4218 65 65 * ec_create_user_OK() 66 66 * Creates new generic user and eventually new group as described in $_POST. 67 * Assumes that the validity of the different indexes of $_POST it uses, have 68 * already been checked. 67 69 * 68 70 * @param … … 74 76 global $page; 75 77 76 // This function assumes that the validity of the different indexes it uses,77 // have been checked before it is used.78 // This function assumes that the validity of the different indexes of 79 // $_POST it uses, have already been checked. 78 80 79 81 // User creation, as generic … … 189 191 190 192 /* 191 * ec_create_ entry_OK()193 * ec_create_modify_entry_OK() 192 194 * returns true or false whether the creation of a new entry described by 193 195 * $_POST was OK or not. … … 198 200 * true if creation was OK ; false if not 199 201 */ 200 function ec_create_ entry_OK() {202 function ec_create_modify_entry_OK() { 201 203 global $page, $ec_lists; 202 204 203 // $_POST validity checks : creation prevented in case of bad arguments 204 if ( 205 !isset($_POST['ec_in_up_code']) or 206 !ereg('^[a-zA-Z0-9_-]{4,32}$', $_POST['ec_in_up_code']) 207 ) return ec_end1('ec_in_up_code', 'ec_bad_argument7'); 208 209 foreach ($ec_lists['ec_table'] as $ec_entry) 210 if ($_POST['ec_in_up_code'] == $ec_entry['code']) 211 return ec_end1('ec_in_up_code', 'ec_bad_argument2'); 212 213 if ( 214 !isset($_POST['ec_sel_user']) or ( 215 $_POST['ec_sel_user'] != 'new' and 216 $_POST['ec_sel_user'] != 'old' 217 ) 218 ) return ec_end1('ec_sel_user', 'ec_bad_argument1'); 219 220 if ($_POST['ec_sel_user'] == 'new') { 221 if ( 222 !isset($_POST['login']) or 223 $_POST['login'] == '' 224 ) return ec_end1('login', 'ec_bad_argument1'); 225 if (in_array($_POST['login'], $ec_lists['user_ids'])) 226 return ec_end1('login', 'ec_bad_argument3'); 227 } 228 else { 229 if (!isset($_POST['ec_in_up_usr_list'])) 230 return ec_end1('login', 'ec_bad_argument1'); 231 $ec_user_id = $_POST['ec_in_up_usr_list']; 232 if (!array_key_exists($ec_user_id, $ec_lists['user_ids'])) 233 return ec_end1('ec_in_up_usr_list', 'ec_bad_argument6'); 234 } 235 236 // code and user_id (if needed) are OK, creation can be done 237 238 // User and eventually group creation, if needed 239 if ($_POST['ec_sel_user'] == 'new') 240 if (!($ec_user_id = ec_create_user_OK())) return false; 205 // $_POST validity checks : action prevented in case of bad arguments 206 207 if (!isset($_POST['ec_act1'])) 208 return ec_end1('ec_act1', 'ec_bad_argument1'); 209 210 if (!isset($_POST['ec_input_action'])) 211 return ec_end1('ec_input_action', 'ec_bad_argument1'); 212 213 $is_creation = true; 214 $action = 'ec_ok'; 215 $arg1 = ''; 216 $arg2 = ''; 217 switch ($_POST['ec_act1']) { 218 219 case 'create': 220 221 if ( 222 !isset($_POST['ec_in_up_code']) or 223 !ereg('^[a-zA-Z0-9_-]{4,32}$', $_POST['ec_in_up_code']) 224 ) return ec_end1('ec_in_up_code', 'ec_bad_argument7'); 225 else $ec_code = $_POST['ec_in_up_code']; 226 227 foreach ($ec_lists['ec_table'] as $ec_entry) 228 if ($ec_code == $ec_entry['code']) 229 return ec_end1('ec_in_up_code', 'ec_bad_argument2'); 230 231 if ( 232 !isset($_POST['ec_sel_user']) or ( 233 $_POST['ec_sel_user'] != 'new' and 234 $_POST['ec_sel_user'] != 'old' 235 ) 236 ) return ec_end1('ec_sel_user', 'ec_bad_argument1'); 237 238 case 'modify_entry_submit': 239 240 $ec_user_id = ''; 241 if (isset($_POST['ec_sel_user'])) { 242 if ($_POST['ec_sel_user'] == 'new') { 243 if ( 244 !isset($_POST['login']) or 245 $_POST['login'] == '' 246 ) return ec_end1('login', 'ec_bad_argument1'); 247 if (in_array($_POST['login'], $ec_lists['user_ids'])) 248 return ec_end1('login', 'ec_bad_argument3'); 249 } 250 elseif ($_POST['ec_sel_user'] == 'old') { 251 if (!isset($_POST['ec_in_up_usr_list'])) 252 return ec_end1('login', 'ec_bad_argument1'); 253 $ec_user_id = $_POST['ec_in_up_usr_list']; 254 if (!array_key_exists($ec_user_id, $ec_lists['user_ids'])) 255 return ec_end1('ec_in_up_usr_list', 'ec_bad_argument6'); 256 } 257 else $action = 'ec_nok'; 258 } 259 else $action = 'ec_nok'; 260 261 if ($_POST['ec_act1'] == 'create') break; 262 263 $is_creation = false; 264 265 case 'duplicate_entry_submit': 266 267 if ( 268 !isset($_POST['ec_entry_sel']) or 269 !array_key_exists($_POST['ec_entry_sel'], $ec_lists['ec_table']) 270 ) return ec_end1('ec_entry_sel', 'ec_bad_argument5'); 271 272 if ($_POST['ec_act1'] == 'modify_entry_submit') break; 273 274 build_ec_duplicable_codes(); 275 if (!array_key_exists($_POST['ec_entry_sel'], 276 $ec_lists['duplicable_codes']['ids']) 277 ) return ec_end1('ec_entry_sel', 'ec_bad_argument5'); 278 $ec_code = $ec_lists['ec_table'][$_POST['ec_entry_sel']]['code']; 279 $ec_user_id = $ec_lists['ec_table'][$_POST['ec_entry_sel']]['user_id']; 280 281 break; 282 default: ec_end1('ec_act1', 'ec_bad_argument1'); 283 } 241 284 242 285 // Preparation of $arg1, $arg2 and $forced 243 $arg1 = ''; $arg2 = ''; 244 if (isset($_POST['ec_input_action'])) switch ($_POST['ec_input_action']) { 286 switch ($_POST['ec_input_action']) { 245 287 // case 'home': // Home : nothing to do : "arg"s are '' 288 // case 'refused': $_POST['ec_sel_user'] unset, nothing to do 246 289 case 'add_p': // Additional Page 247 290 if (isset($_POST['ec_in_up_aps'])) $arg2 = $_POST['ec_in_up_aps']; … … 261 304 default: ec_end1('ec_input_action', 'ec_bad_argument1'); 262 305 } 263 else ec_end1('ec_input_action', 'ec_bad_argument1'); 264 $forced = (isset($_POST['ec_in_up_forced'])) ? 'true' : 'false'; 265 266 // Now we have the code, the user_id, arg1, arg2, and forced arguments 267 if ( 268 pwg_query(" 269 INSERT INTO `".EVNTCATS_TABLE."` ( 270 `code`, 271 `user_id`, 272 `action`, 273 `arg1`, `arg2`, `forced` 274 ) 275 VALUES ( 276 '".$_POST['ec_in_up_code']."', 277 '".$ec_user_id."', 278 'ec_ok', 279 '".$arg1."', '".$arg2."', '".$forced."' 280 ); 281 ") === false 282 ) { 283 $page['errors'][] = 284 l10n('ec_entry_create_pb'). 285 'MySQL error '.mysql_errno().', "'.mysql_error().'"' 286 ; 287 return false; 288 } 289 else { 290 build_ec_lists(); 291 $forced = ($forced == 'false') ? '' : l10n('ec_cnfrm_forced'); 292 $page['infos'][] = 293 l10n('ec_entry_create_OK').mysql_insert_id().' : '. 294 $_POST['ec_in_up_code'].' => '. 295 $ec_lists['user_ids'][$ec_user_id].$forced 296 ; 297 return true; 298 } 299 } 300 301 /* 302 * ec_duplicate_entry_OK() 303 * returns true or false whether the duplication of an existing entry which # 304 * is given by $_POST['ec_entry_sel'] was OK or not. 305 * 306 * @param 307 * no param 308 * @return 309 * true if creation was OK ; false if not 310 */ 311 function ec_duplicate_entry_OK() { 312 global $page, $ec_lists; 313 314 build_ec_duplicable_codes(); 315 if (array_key_exists($_POST['ec_entry_sel'], 316 $ec_lists['duplicable_codes']['ids'])) { 317 $arg1 = ''; $arg2 = ''; 318 switch ($_POST['ec_input_action']) { 319 // case 'home': // Home : nothing to do : "arg"s are '' 320 case 'add_p': 321 if (array_key_exists($_POST['ec_in_up_aps'],$ec_lists['add_pages'])) { 322 $arg2 = $_POST['ec_in_up_aps']; } 323 else return ec_end1('ec_in_up_aps', 'ec_bad_argument4'); 324 case 'img': 325 case 'cat': 326 if (array_key_exists($_POST['ec_in_up_cat'], 327 $ec_lists['categories'])) { 328 if ($_POST['ec_input_action'] == 'img') { 329 if ( 330 ec_image_exists($_POST['ec_in_up_cat'], $_POST['ec_in_up_img']) 331 ) $arg2 = $_POST['ec_in_up_img']; 332 else return ec_end1('ec_in_up_img', 'ec_bad_argument4'); 333 } 334 $arg1 = $_POST['ec_in_up_cat']; 335 } 336 else return ec_end1('ec_in_up_cat', 'ec_bad_argument4'); 337 break; 338 default: return ec_end1('ec_input_action', 'ec_bad_argument1'); 339 } 306 307 if (isset($_POST['ec_in_up_forced'])) { 308 if ($_POST['ec_act1'] == 'duplicate_entry_submit') 309 ec_end1('ec_in_up_forced', 'ec_bad_argument1'); 310 if (!$is_creation) { 311 if ( 312 $t1 = mysql_fetch_row(pwg_query(" 313 SELECT `code` 314 FROM `".EVNTCATS_TABLE."` 315 WHERE `id` = '".$_POST['ec_entry_sel']."' 316 ")) === false 317 ) die('Code not found in DB ?!'); 318 $r = pwg_query(" 319 SELECT `id` 320 FROM `".EVNTCATS_TABLE."` 321 WHERE `code` = '".$t1[0]."' 322 AND `id` <> '".$_POST['ec_entry_sel']."' 323 "); 324 while ($t2 = mysql_fetch_row($r)) if (!ec_delete_entry_OK($t2[0])) 325 return false; 326 } 327 $forced = 'true'; 328 } 329 else $forced = 'false'; 330 331 // User and eventually group creation, if needed 332 if ($_POST['ec_act1'] != 'duplicate_entry_submit') 333 if ($_POST['ec_sel_user'] == 'new') 334 if (!($ec_user_id = ec_create_user_OK())) return false; 335 336 // Now we have all infos 337 if ($is_creation) { 340 338 if ( 341 339 pwg_query(" 342 INSERT INTO `".EVNTCATS_TABLE."` 343 (`code`, `user_id`, `action`, `arg1`, `arg2`) 340 INSERT INTO `".EVNTCATS_TABLE."` ( 341 `code`, 342 `user_id`, 343 `action`, 344 `arg1`, `arg2`, `forced` 345 ) 344 346 VALUES ( 345 '".$ec_lists['ec_table'][$_POST['ec_entry_sel']]['code']."', 346 '".$ec_lists['ec_table'][$_POST['ec_entry_sel']]['user_id']."', 347 'ec_ok', 348 '".$arg1."', 349 '".$arg2."' 347 '".$ec_code."', 348 '".$ec_user_id."', 349 '".$action."', 350 '".$arg1."', '".$arg2."', '".$forced."' 350 351 ); 351 352 ") === false 352 353 ) { 353 354 $page['errors'][] = 354 l10n('ec_entry_dup_nok_pre1'). 355 $_POST['ec_entry_sel']. 356 l10n('ec_entry_dup_nok_end1'). 355 l10n('ec_entry_create_pb'). 357 356 'MySQL error '.mysql_errno().', "'.mysql_error().'"' 358 357 ; … … 360 359 } 361 360 else { 361 build_ec_lists(); 362 $forced = ($forced == 'false') ? '' : l10n('ec_cnfrm_forced'); 362 363 $page['infos'][] = 363 l10n('ec_entry_dup_ok_pre'). 364 $_POST['ec_entry_sel'].' ('. 365 $ec_lists['ec_table'][$_POST['ec_entry_sel']]['code'].')'. 366 l10n('ec_entry_dup_ok_end') 364 l10n('ec_entry_create_OK').mysql_insert_id().' : '. 365 $_POST['ec_in_up_code'].' => '. 366 $ec_lists['user_ids'][$ec_user_id].$forced 367 367 ; 368 build_ec_table(); 369 return true; 370 } 371 } 372 else return ec_end1('ec_entry_sel', 'ec_bad_argument5'); 373 } 374 375 /* 376 * ec_modify_entry_OK() 377 * returns true or false whether the modification of an existing entry which # 378 * is given by $_POST['ec_entry_sel'] was OK or not. 379 * 380 * @param 381 * no param 382 * @return 383 * true if modification was OK ; false if not 384 */ 385 function ec_modify_entry_OK() { 386 global $page; 387 $page['errors'][] = 'Y\'a pas eu une erreur ?...'; 388 return false; 368 } 369 } 370 else { 371 if ( 372 pwg_query(" 373 UPDATE `".EVNTCATS_TABLE."` 374 SET 375 `user_id` = '".$ec_user_id."', 376 `action` = '".$action."', 377 `arg1` = '".$arg1."', 378 `arg2` = '".$arg2."', 379 `forced` = '".$forced."' 380 WHERE `id` = '".$_POST['ec_entry_sel']."' 381 ") === false 382 ) { 383 $page['errors'][] = 384 l10n('ec_entry_create_pb'). 385 'MySQL error '.mysql_errno().', "'.mysql_error().'"' 386 ; 387 return false; 388 } 389 else { 390 $page['infos'][] = l10n('ec_entry_modify_OK').$_POST['ec_entry_sel']; 391 build_ec_lists(); 392 } 393 } 394 return true; 389 395 } 390 396 … … 405 411 406 412 /* 407 * ec_delete_entry() 408 * tries to delete an existing entry which # is given by 409 * $_POST['ec_entry_sel']. 410 * 411 * @param 412 * no param 413 * @return 414 * no return value : modifies $page['errors'] or $page['infos'] 415 */ 416 function ec_delete_entry() { 417 global $page, $ec_lists; 418 if (array_key_exists($_POST['ec_entry_sel'], $ec_lists['ec_table'])) { 419 if (!pwg_query(' 420 DELETE FROM `'.EVNTCATS_TABLE.'` 421 WHERE `id` = '.$_POST['ec_entry_sel'] 422 )) { 423 $page['errors'][] = 424 l10n('ec_entry_del_nok_pre'). 425 $_POST['ec_entry_sel']. 426 l10n('ec_entry_del_nok_end'). 427 'MySQL error '.mysql_errno().', "'.mysql_error().'"' 428 ; 429 } 430 else { 431 $page['infos'][] = 432 l10n('ec_entry_del_ok_pre'). 433 $_POST['ec_entry_sel']. 434 l10n('ec_entry_del_ok_end'); 435 build_ec_table(); 436 } 437 } 438 else ec_end1('ec_entry_sel', 'ec_bad_argument1'); 413 * ec_delete_entry_OK($ec_id) 414 * tries to delete an existing entry. 415 * 416 * @param 417 * $ec_id : the entry to be deleted 418 * @return 419 * true or false whether deleting succeeded. 420 */ 421 function ec_delete_entry_OK($ec_id) { 422 global $page; 423 if (!pwg_query(" 424 DELETE FROM `".EVNTCATS_TABLE."` 425 WHERE `id` = ".$ec_id 426 )) { 427 $page['errors'][] = 428 l10n('ec_entry_del_nok_pre'). 429 $ec_id. 430 l10n('ec_entry_del_nok_end'). 431 'MySQL error '.mysql_errno().', "'.mysql_error().'"'; 432 return false; 433 } 434 else $page['infos'][] = 435 l10n('ec_entry_del_ok_pre'). 436 $ec_id. 437 l10n('ec_entry_del_ok_end'); 438 return true; 439 439 } 440 440
Note: See TracChangeset
for help on using the changeset viewer.