Changeset 4115 for extensions/event_cats/include
- Timestamp:
- Oct 26, 2009, 1:36:23 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/event_cats/include/evntcats_funcs.inc.php
r4092 r4115 32 32 33 33 /* 34 * ec_inspect() 35 * goes through ec_lists['ec_table'] to check errors on (multiple) entries 36 * using the same code. Cannot be used elsewhere than here in 37 * build_ec_table() . 38 * 39 * @param 40 * 41 * @return 42 * (no return value) 43 */ 44 function ec_inspect($checked_item, $new_action, $check_ec_nok = true) { 45 global $ec_lists; 46 $first = array(); 47 $to_correct = array(); 48 49 // $to_correct is needed cause following code would not work everywhere : 50 /* 51 foreach ($table as $value) { 52 if ($value == $value_to_check and $value == $problem) { 53 foreach ($table as &$value2) { // key index of $table can be reset 54 if ($value2 == $value_to_check) { 55 $value2 = $better_value; 56 } 57 } 58 } 59 } 60 // It works with WinAmp Server, but not on Apache server of Free (french 61 // Internet provider). 62 */ 63 64 foreach ($ec_lists['ec_table'] as &$ec_entry) { // & is not really needed 65 $ec_current_code = $ec_entry['code']; 66 if ( 67 $ec_entry['action'] == 'ec_ok' or 68 ($check_ec_nok and $ec_entry['action'] == 'ec_nok') 69 ) { 70 if (isset($first[$ec_current_code])) { 71 // $first[$ec_current_code] is set <=> code has already been met. 72 // Checked item MUST be equal to the first item (thus all items) for 73 // this code. 74 if ( 75 $first[$ec_current_code] != $ec_entry[$checked_item] or 76 ($new_action == '' and $ec_entry[$checked_item] == 'true') 77 ) { 78 $to_correct[$ec_current_code] = true; // value not used in fact 79 } // but using $ec_current_code as a key makes a smaller table 80 } // if the error comes back several times 81 else { 82 $first[$ec_current_code] = $ec_entry[$checked_item]; 83 } 84 } 85 } 86 foreach ($ec_lists['ec_table'] as &$ec_entry) { // & is needed here 87 if (isset($to_correct[$ec_entry['code']])) { 88 if ($new_action == '') { 89 if (!pwg_query(' 90 UPDATE `'.EVNTCATS_TABLE.'` 91 SET `forced` = "false" 92 WHERE `id` = '.$ec_entry['id'] 93 )) die('Could not fix a "_f_pb"'); 94 $ec_entry['forced'] = 'false'; 95 } 96 else $ec_entry['action'] = $new_action; 97 } 98 } 99 } 100 101 /* 34 102 * build_ec_table() 35 103 * builds a table showing the content of the <pwg>_event_cats database table, … … 110 178 // Construction of behaviour 111 179 112 /*113 * ec_inpect()114 * goes through ec_lists['ec_table'] to check errors on (multiple) entries115 * using the same code. Cannot be used elsewhere than here in116 * build_ec_table() .117 *118 * @param119 *120 * @return121 * (no return value)122 */123 function ec_inpect($checked_item, $new_action, $check_ec_nok = true) {124 global $ec_lists;125 $first = array();126 $to_correct = array();127 128 // $to_correct is needed cause following code would not work everywhere :129 /*130 foreach ($table as $value) {131 if ($value == $value_to_check and $value == $problem) {132 foreach ($table as &$value2) { // key index of $table can be reset133 if ($value2 == $value_to_check) {134 $value2 = $better_value;135 }136 }137 }138 }139 // It works with WinAmp Server, but not on Apache server of Free (french140 // Internet provider).141 */142 143 foreach ($ec_lists['ec_table'] as &$ec_entry) { // & is not really needed144 $ec_current_code = $ec_entry['code'];145 if (146 $ec_entry['action'] == 'ec_ok' or147 ($check_ec_nok and $ec_entry['action'] == 'ec_nok')148 ) {149 if (isset($first[$ec_current_code])) {150 // $first[$ec_current_code] is set <=> code has already been met.151 // Checked item MUST be equal to the first item (thus all items) for152 // this code.153 if (154 $first[$ec_current_code] != $ec_entry[$checked_item] or155 ($new_action == '' and $ec_entry[$checked_item] == 'true')156 ) {157 $to_correct[$ec_current_code] = true; // value not used in fact158 } // but using $ec_current_code as a key makes a smaller table159 } // if the error comes back several times160 else {161 $first[$ec_current_code] = $ec_entry[$checked_item];162 }163 }164 }165 foreach ($ec_lists['ec_table'] as &$ec_entry) { // & is needed here166 if (isset($to_correct[$ec_entry['code']])) {167 if ($new_action == '') {168 if (169 pwg_query('170 UPDATE `'.EVNTCATS_TABLE.'`171 SET `forced` = "false"172 WHERE `id` = '.$ec_entry['id']173 ) == null174 ) die('Could not fix a "_f_pb"');175 $ec_entry['forced'] = 'false';176 }177 else $ec_entry['action'] = $new_action;178 }179 }180 }181 182 180 // Multiple action params for a single code check 183 ec_in pect('action', 'ec_nok_action_pb');181 ec_inspect('action', 'ec_nok_action_pb'); 184 182 185 183 // Multiple user_ids for a single code check 186 ec_in pect('user_id', 'ec_nok_userid_pb', false);184 ec_inspect('user_id', 'ec_nok_userid_pb', false); 187 185 188 186 // Multiple "forced" params for a single code check 189 ec_in pect('forced', '');187 ec_inspect('forced', ''); 190 188 191 189 // User id and associated page validities checks … … 226 224 if (array_key_exists($ec_entry['arg1'], $ec_lists['categories'])) { 227 225 if ($a == 3) { // case 3: // Image 228 if (!mysql_fetch_row(pwg_query(' 229 SELECT * 230 FROM `'.IMAGE_CATEGORY_TABLE.'` 231 WHERE `category_id` = '.$ec_entry['arg1'].' 232 AND `image_id` = '.$ec_entry['arg2'] 233 ))) { 226 if (!ec_image_exists($ec_entry['arg1'], $ec_entry['arg2'])) { 234 227 $ec_entry['action'].= '_img_pb'; 235 228 } … … 242 235 break; 243 236 } 237 } 238 } 239 240 /* 241 * build_ec_duplicable_codes() 242 * 243 * 244 * @param 245 * no parameter passed, the main material on which works the function, is 246 * the global array variable $ec_lists. 247 * @return 248 * (no return value) 249 */ 250 function build_ec_duplicable_codes() { 251 global $ec_lists; 252 $ec_lists['duplicable_codes'] = array(); 253 $t = array(); 254 foreach ($ec_lists['ec_table'] as $ec_entry) { 255 if ( 256 is_in($ec_entry['action'], 'ec_ok') and 257 $ec_entry['forced'] == 'false' 258 ) { 259 $t[$ec_entry['id']] = $ec_entry['code']; 260 $ec_lists['duplicable_codes']['codes'][$ec_entry['code']]['id'] = 261 $ec_entry['id']; 262 $ec_lists['duplicable_codes']['codes'][$ec_entry['code']]['user_id'] = 263 $ec_entry['user_id']; 264 } 265 } 266 foreach ($t as $ec_id => $ec_code) { 267 $ec_lists['duplicable_codes']['ids'][$ec_id] = 268 $ec_lists['duplicable_codes']['codes'][$ec_code]['id']; 244 269 } 245 270 } … … 332 357 */ 333 358 function ec_duplicate_entry_OK() { 334 global $page; 335 $page['errors'][] = 'Y\'a sûrement eu une erreur...'; 359 global $page, $ec_lists; 360 361 build_ec_duplicable_codes(); 362 if (array_key_exists($_POST['ec_entry_sel'], 363 $ec_lists['duplicable_codes']['ids'])) { 364 $arg1 = ''; $arg2 = ''; 365 switch ($_POST['ec_input_action']) { 366 case 'add_p': 367 if (array_key_exists($_POST['ec_in_up_aps'], $ec_lists['add_pages'])) { 368 $arg2 = $_POST['ec_in_up_aps']; } 369 else { 370 $page['errors'][] = 371 l10n('ec_bad_argument1'). 372 '$_POST[\'ec_in_up_aps\'] = '. 373 $_POST['ec_in_up_aps'] 374 ; 375 return false; 376 } 377 case 'home': 378 break; 379 case 'img': 380 case 'cat': 381 if (array_key_exists($_POST['ec_in_up_cat'], 382 $ec_lists['categories'])) { 383 if ($_POST['ec_input_action'] == 'img') { 384 if ( 385 ec_image_exists($_POST['ec_in_up_cat'], $_POST['ec_in_up_img']) 386 ) $arg2 = $_POST['ec_in_up_img']; 387 else { 388 $page['errors'][] = 389 l10n('ec_bad_argument1'). 390 '$_POST[\'ec_in_up_img\'] = '. 391 $_POST['ec_in_up_img'] 392 ; 393 return false; 394 } 395 } 396 $arg1 = $_POST['ec_in_up_cat']; 397 } 398 else { 399 $page['errors'][] = 400 l10n('ec_bad_argument1'). 401 '$_POST[\'ec_in_up_cat\'] = '. 402 $_POST['ec_in_up_cat'] 403 ; 404 return false; 405 } 406 break; 407 default: 408 $page['errors'][] = 409 l10n('ec_bad_argument1'). 410 '$_POST[\'ec_input_action\'] = '. 411 $_POST['ec_input_action'] 412 ; 413 return false; 414 } 415 if (pwg_query(" 416 INSERT INTO `".EVNTCATS_TABLE."` 417 (`code`, `user_id`, `action`, `arg1`, `arg2`) 418 VALUES ( 419 '".$ec_lists['ec_table'][$_POST['ec_entry_sel']]['code']."', 420 '".$ec_lists['ec_table'][$_POST['ec_entry_sel']]['user_id']."', 421 'ec_ok', 422 '".$arg1."', 423 '".$arg2."' 424 ); 425 ")) { 426 $page['infos'][] = 427 l10n('ec_entry_dup_ok_pre'). 428 $_POST['ec_entry_sel'].' ('. 429 $ec_lists['ec_table'][$_POST['ec_entry_sel']]['code'].')'. 430 l10n('ec_entry_dup_ok_end') 431 ; 432 build_ec_table(); 433 return true; 434 } 435 else { 436 $page['errors'][] = 437 l10n('ec_entry_dup_nok_pre1'). 438 $_POST['ec_entry_sel']. 439 l10n('ec_entry_dup_nok_end1'). 440 'MySQL error '.mysql_errno().', "'.mysql_error().'"' 441 ; 442 return false; 443 } 444 } 445 else { 446 $page['errors'][] = 447 l10n('ec_bad_argument1'). 448 '$_POST[\'ec_entry_sel\'] = '. 449 $_POST['ec_entry_sel'] 450 ; 451 return false; 452 } 453 $page['errors'][] = '?!'; 336 454 return false; 337 455 } … … 351 469 $page['errors'][] = 'Y\'a pas eu une erreur ?...'; 352 470 return false; 471 } 472 473 /* 474 * ec_delete_entry() 475 * tries to delete an existing entry which # is given by 476 * $_POST['ec_entry_sel']. 477 * 478 * @param 479 * no param 480 * @return 481 * no return value : modifies $page['errors'] or $page['infos'] 482 */ 483 function ec_delete_entry() { 484 global $page, $ec_lists; 485 if (array_key_exists($_POST['ec_entry_sel'], $ec_lists['ec_table'])) { 486 if (!pwg_query(' 487 DELETE FROM `'.EVNTCATS_TABLE.'` 488 WHERE `id` = '.$_POST['ec_entry_sel'] 489 )) { 490 $page['errors'][] = 491 l10n('ec_entry_del_nok_pre'). 492 $_POST['ec_entry_sel']. 493 l10n('ec_entry_del_nok_end'). 494 'MySQL error '.mysql_errno().', "'.mysql_error().'"' 495 ; 496 } 497 else { 498 $page['infos'][] = 499 l10n('ec_entry_del_ok_pre'). 500 $_POST['ec_entry_sel']. 501 l10n('ec_entry_del_ok_end'); 502 build_ec_table(); 503 } 504 } 505 else { 506 $page['errors'][] = 507 l10n('ec_bad_argument1'). 508 '$_POST[\'ec_entry_sel\'] = '. 509 $_POST['ec_entry_sel'] 510 ; 511 } 512 } 513 514 /* 515 * ec_image_exists($cat, $img) 516 * returns true or false whether the image is associated with the category. 517 * 518 * @param 519 * $cat : the category 520 * $img : the image 521 * @return 522 * treu or false whether the image is associated with the category. 523 */ 524 function ec_image_exists($cat, $img) { 525 return (mysql_fetch_row(pwg_query(' 526 SELECT * 527 FROM `'.IMAGE_CATEGORY_TABLE.'` 528 WHERE `category_id` = '.$cat.' 529 AND `image_id` = '.$img 530 )) !== false); 353 531 } 354 532
Note: See TracChangeset
for help on using the changeset viewer.