Changeset 4157 for extensions/event_cats/include/evntcats_funcs.inc.php
- Timestamp:
- Oct 31, 2009, 4:59:48 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/event_cats/include/evntcats_funcs.inc.php
r4115 r4157 27 27 // *************************************************************************** 28 28 29 global $conf, $ec_conf; 29 // +-----------------------------------------------------------------------+ 30 // | Header | 31 // +-----------------------------------------------------------------------+ 32 33 global $conf; 30 34 31 35 include_once(EVNTCATS_PATH.'include/ec_conf.inc.php'); 36 37 // +-----------------------------------------------------------------------+ 38 // | Utilities functions | 39 // +-----------------------------------------------------------------------+ 40 41 /* 42 * is_in($haystack, $needle) 43 * returns true or false whether $needle is a string found in string $haystack 44 * 45 * @param 46 * $haystack : the string in which to search 47 * $needle : the string looked for 48 * @return 49 * true if $needle is found in $haystack ; false if not 50 */ 51 function is_in($haystack, $needle) { 52 return (strpos($haystack, $needle) !== false); 53 } 54 55 /* 56 * ec_image_exists($cat, $img) 57 * returns true or false whether the image is associated with the category. 58 * 59 * @param 60 * $cat : the category 61 * $img : the image 62 * @return 63 * treu or false whether the image is associated with the category. 64 */ 65 function ec_image_exists($cat, $img) { 66 return (mysql_fetch_row(pwg_query(' 67 SELECT * 68 FROM `'.IMAGE_CATEGORY_TABLE.'` 69 WHERE `category_id` = '.$cat.' 70 AND `image_id` = '.$img 71 )) !== false); 72 } 73 74 /* 75 * str_from_var($var) 76 * returns a string easing array var informations displaying in Piwigo : 77 * _ the string return value starts with"<p align="left">" ; 78 * _ all "TAB" characters (chr(10)) are replaced by "<br>" ; 79 * _ all spaces are replaced by " ". 80 * 81 * @param 82 * $var : variable to display 83 * @return 84 * string easy to display in Piwigo 85 */ 86 function str_from_var($var) { 87 return '<p align="left">'.str_replace(chr(10),'<br>',str_replace(' ',' ', print_r /* var_dump */ ($var,true))).'</p>'; 88 } 32 89 33 90 /* … … 100 157 101 158 /* 159 * ec_end() 160 * Process repetitive task when error in database modifying fucntions. 161 * 162 * @param 163 * $pst : $_POST argument 164 * $msg : message 165 * @return 166 * false as this function is used when there is a problem 167 */ 168 function ec_end($pst, $msg) { 169 global $page; 170 $page['errors'][] = 171 l10n($msg). 172 '$_POST[\''.$pst.'\'] = '. 173 $_POST[$pst] 174 ; 175 return false; 176 } 177 178 // +-----------------------------------------------------------------------+ 179 // | Tables building functions | 180 // +-----------------------------------------------------------------------+ 181 182 /* 102 183 * build_ec_table() 103 184 * builds a table showing the content of the <pwg>_event_cats database table, … … 239 320 240 321 /* 322 * build_ec_lists() 323 * builds the main array variable contaning all informations for the plugin 324 * 325 * @param 326 * no parameter passed, the main material on which works the function, is 327 * the global array variable $ec_lists. 328 * @return 329 * (no return value) 330 */ 331 function build_ec_lists() { 332 333 global $ec_ap_ok, $template, $ec_lists; 334 335 $ec_lists = array(); 336 337 // Construction of $ec_lists['add_pages'] array var 338 $ec_lists['add_pages'] = array(); 339 if ($ec_ap_ok) { 340 $res = pwg_query('SELECT id,title FROM '.ADD_PAGES_TABLE); 341 while ($r = mysql_fetch_assoc($res)) { 342 $c = (is_in($r['title'], '/user_id=')) ? '/user_id=' : '/group_id='; 343 $a = explode($c ,$r['title']); 344 $ec_lists['add_pages'][$r['id']] = $a[0]; 345 } 346 } 347 348 // Construction of $ec_lists['categories'] array var 349 $c = array(); 350 display_select_cat_wrapper(' 351 SELECT id,name,uppercats,global_rank 352 FROM '.CATEGORIES_TABLE, 353 $c, 'category_options', true); 354 $ec_lists['categories'] = $template->smarty->_tpl_vars['category_options']; 355 356 // Construction of $ec_lists['user_ids'] array var 357 $ec_lists['user_ids'] = array(); 358 $q = pwg_query('SELECT id,username FROM '.USERS_TABLE. ' WHERE id > 2'); 359 while ($r = mysql_fetch_assoc($q)) { 360 $ec_lists['user_ids'][$r['id']] = $r['username']; 361 } 362 363 // Construction of $ec_lists['ec_table'] array var 364 build_ec_table(); 365 } 366 367 /* 241 368 * build_ec_duplicable_codes() 242 369 * … … 270 397 } 271 398 272 /* 273 * build_ec_lists() 274 * builds the main array variable contaning all informations for the plugin 275 * 276 * @param 277 * no parameter passed, the main material on which works the function, is 278 * the global array variable $ec_lists. 279 * @return 280 * (no return value) 281 */ 282 function build_ec_lists() { 283 284 global $ec_ap_ok, $template, $ec_lists; 285 286 $ec_lists = array(); 287 288 // Construction of $ec_lists['add_pages'] array var 289 $ec_lists['add_pages'] = array(); 290 if ($ec_ap_ok) { 291 $res = pwg_query('SELECT id,title FROM '.ADD_PAGES_TABLE); 292 while ($r = mysql_fetch_assoc($res)) { 293 $c = (is_in($r['title'], '/user_id=')) ? '/user_id=' : '/group_id='; 294 $a = explode($c ,$r['title']); 295 $ec_lists['add_pages'][$r['id']] = $a[0]; 296 } 297 } 298 299 // Construction of $ec_lists['categories'] array var 300 $c = array(); 301 display_select_cat_wrapper(' 302 SELECT id,name,uppercats,global_rank 303 FROM '.CATEGORIES_TABLE, 304 $c, 'category_options', true); 305 $ec_lists['categories'] = $template->smarty->_tpl_vars['category_options']; 306 307 // Construction of $ec_lists['user_ids'] array var 308 $ec_lists['user_ids'] = array(); 309 $q = pwg_query('SELECT id,username FROM '.USERS_TABLE. ' WHERE id > 2'); 310 while ($r = mysql_fetch_assoc($q)) { 311 $ec_lists['user_ids'][$r['id']] = $r['username']; 312 } 313 314 // Construction of $ec_lists['ec_table'] array var 315 build_ec_table(); 316 } 317 318 /* 319 * is_in($haystack, $needle) 320 * returns true or false whether $needle is a string found in string $haystack 321 * 322 * @param 323 * $haystack : the string in which to search 324 * $needle : the string looked for 325 * @return 326 * true if $needle is found in $haystack ; false if not 327 */ 328 function is_in($haystack, $needle) { 329 return (strpos($haystack, $needle) !== false); 330 } 399 // +-----------------------------------------------------------------------+ 400 // | Database modifying functions | 401 // +-----------------------------------------------------------------------+ 331 402 332 403 /* … … 341 412 */ 342 413 function ec_create_entry_OK() { 343 global $page; 414 global $page, $ec_lists; 415 416 /* foreach ($ec_lists['ec_table'] as $ec_entry) { 417 if ($_POST['ec_in_up_code'] == $ec_entry['code']) 418 return ec_end('ec_in_up_code', 'ec_bad_argument2'); 419 } 420 if ($_POST['ec_sel_user'] == 'new') { 421 if (in_array( 422 $_POST['ec_in_up_usr_txt'], 423 $ec_lists['user_ids'] 424 )) return ec_end('ec_in_up_usr_txt', 'ec_bad_argument3'); 425 else { // New user account creation 426 $page['errors'] = register_user( 427 $_POST['ec_in_up_usr_txt'], $_POST['ec_in_up_psd_txt'], '', false 428 ); 429 } 430 } 431 */ 432 344 433 $page['errors'][] = 'Y\'a p\'têt\' ben eu une erreur...'; 345 return false;346 434 } 347 435 … … 365 453 switch ($_POST['ec_input_action']) { 366 454 case 'add_p': 367 if (array_key_exists($_POST['ec_in_up_aps'], 455 if (array_key_exists($_POST['ec_in_up_aps'],$ec_lists['add_pages'])) { 368 456 $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 } 457 else return ec_end('ec_in_up_aps', 'ec_bad_argument1'); 377 458 case 'home': 378 459 break; … … 385 466 ec_image_exists($_POST['ec_in_up_cat'], $_POST['ec_in_up_img']) 386 467 ) $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 } 468 else return ec_end('ec_in_up_img', 'ec_bad_argument1'); 395 469 } 396 470 $arg1 = $_POST['ec_in_up_cat']; 397 471 } 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 } 472 else return ec_end('ec_in_up_cat', 'ec_bad_argument1'); 406 473 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; 474 default: return ec_end('ec_input_action', 'ec_bad_argument1'); 414 475 } 415 476 if (pwg_query(" … … 443 504 } 444 505 } 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 } 506 else return ec_end('ec_entry_sel', 'ec_bad_argument1'); 453 507 $page['errors'][] = '?!'; 454 508 return false; … … 469 523 $page['errors'][] = 'Y\'a pas eu une erreur ?...'; 470 524 return false; 525 } 526 527 /* 528 * ec_toggle_forced_entry() 529 * Toggles the 'forced' property of an entry, provided it complies to the 530 * rules. 531 * 532 * @param 533 * no param 534 * @return 535 * no return value 536 */ 537 function ec_toggle_forced_entry() { 538 global $page; 539 $page['errors'][] = 'ec_toggle_forced_entry'; 471 540 } 472 541 … … 503 572 } 504 573 } 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); 531 } 532 533 /* 534 * str_from_var($var) 535 * returns a string easing array var informations displaying in Piwigo : 536 * _ the string return value starts with"<p align="left">" ; 537 * _ all "TAB" characters (chr(10)) are replaced by "<br>" ; 538 * _ all spaces are replaced by " ". 539 * 540 * @param 541 * $var : variable to display 542 * @return 543 * string easy to display in Piwigo 544 */ 545 function str_from_var($var) { 546 return '<p align="left">'.str_replace(chr(10),'<br>',str_replace(' ',' ', print_r /* var_dump */ ($var,true))).'</p>'; 574 else ec_end('ec_entry_sel', 'ec_bad_argument1'); 547 575 } 548 576
Note: See TracChangeset
for help on using the changeset viewer.