$ec_code) { $ec_lists['duplicable_codes']['ids'][$ec_id] = $ec_lists['duplicable_codes']['codes'][$ec_code]['id']; } // Builds a category list displayed a best way build_ec_categories(false); } // +-----------------------------------------------------------------------+ // | Database modifying functions | // +-----------------------------------------------------------------------+ /* * ec_create_entry_OK() * returns true or false whether the creation of a new entry described by * $_POST was OK or not. * * @param * no param * @return * true if creation was OK ; false if not */ function ec_create_entry_OK() { global $page, $ec_lists; // $_POST validity checks : creation prevented in case of bad arguments if ( !isset($_POST['ec_in_up_code']) or !ereg('^[a-zA-Z0-9_-]{4,32}$', $_POST['ec_in_up_code']) ) return ec_end1('ec_in_up_code', 'ec_bad_argument7'); foreach ($ec_lists['ec_table'] as $ec_entry) if ($_POST['ec_in_up_code'] == $ec_entry['code']) return ec_end1('ec_in_up_code', 'ec_bad_argument2'); if ( !isset($_POST['ec_sel_user']) or ( $_POST['ec_sel_user'] != 'new' and $_POST['ec_sel_user'] != 'old' ) ) return ec_end1('ec_sel_user', 'ec_bad_argument1'); if ($_POST['ec_sel_user'] == 'new') { if ( !isset($_POST['login']) or $_POST['login'] == '' ) return ec_end1('login', 'ec_bad_argument1'); if (in_array($_POST['login'], $ec_lists['user_ids'])) return ec_end1('login', 'ec_bad_argument3'); } else { if (!isset($_POST['ec_in_up_usr_list'])) return ec_end1('login', 'ec_bad_argument1'); $ec_user_id = $_POST['ec_in_up_usr_list']; if (!array_key_exists($ec_user_id, $ec_lists['user_ids'])) return ec_end1('ec_in_up_usr_list', 'ec_bad_argument6'); } // code and user_id (if needed) are OK, creation can be done // User and eventually group creation, if needed if ($_POST['ec_sel_user'] == 'new') if (!($ec_user_id = ec_create_user_OK())) return false; // Preparation of $arg1, $arg2 and $forced $arg1 = ''; $arg2 = ''; if (isset($_POST['ec_input_action'])) switch ($_POST['ec_input_action']) { // case 'home': // Home : nothing to do : "arg"s are '' case 'add_p': // Additional Page if (isset($_POST['ec_in_up_aps'])) $arg2 = $_POST['ec_in_up_aps']; else ec_end1('ec_in_up_aps', 'ec_bad_argument1'); break; case 'cat': // Category case 'img': // Image if (isset($_POST['ec_in_up_cat'])) { $arg1 = $_POST['ec_in_up_cat']; if ($_POST['ec_input_action'] == 'img') { if (isset($_POST['ec_in_up_img'])) $arg2 = $_POST['ec_in_up_img']; else ec_end1('ec_in_up_img', 'ec_bad_argument1'); } } else ec_end1('ec_in_up_cat', 'ec_bad_argument1'); break; default: ec_end1('ec_input_action', 'ec_bad_argument1'); } else ec_end1('ec_input_action', 'ec_bad_argument1'); $forced = (isset($_POST['ec_in_up_forced'])) ? 'true' : 'false'; // Now we have the code, the user_id, arg1, arg2, and forced arguments if ( pwg_query(" INSERT INTO `".EVNTCATS_TABLE."` ( `code`, `user_id`, `action`, `arg1`, `arg2`, `forced` ) VALUES ( '".$_POST['ec_in_up_code']."', '".$ec_user_id."', 'ec_ok', '".$arg1."', '".$arg2."', '".$forced."' ); ") === false ) { $page['errors'][] = l10n('ec_entry_create_pb'). 'MySQL error '.mysql_errno().', "'.mysql_error().'"' ; return false; } else { build_ec_lists(); $forced = ($forced == 'false') ? '' : l10n('ec_cnfrm_forced'); $page['infos'][] = l10n('ec_entry_create_OK').mysql_insert_id().' : '. $_POST['ec_in_up_code'].' => '. $ec_lists['user_ids'][$ec_user_id].$forced ; return true; } } /* * ec_duplicate_entry_OK() * returns true or false whether the duplication of an existing entry which # * is given by $_POST['ec_entry_sel'] was OK or not. * * @param * no param * @return * true if creation was OK ; false if not */ function ec_duplicate_entry_OK() { global $page, $ec_lists; build_ec_duplicable_codes(); if (array_key_exists($_POST['ec_entry_sel'], $ec_lists['duplicable_codes']['ids'])) { $arg1 = ''; $arg2 = ''; switch ($_POST['ec_input_action']) { // case 'home': // Home : nothing to do : "arg"s are '' case 'add_p': if (array_key_exists($_POST['ec_in_up_aps'],$ec_lists['add_pages'])) { $arg2 = $_POST['ec_in_up_aps']; } else return ec_end1('ec_in_up_aps', 'ec_bad_argument4'); case 'img': case 'cat': if (array_key_exists($_POST['ec_in_up_cat'], $ec_lists['categories'])) { if ($_POST['ec_input_action'] == 'img') { if ( ec_image_exists($_POST['ec_in_up_cat'], $_POST['ec_in_up_img']) ) $arg2 = $_POST['ec_in_up_img']; else return ec_end1('ec_in_up_img', 'ec_bad_argument4'); } $arg1 = $_POST['ec_in_up_cat']; } else return ec_end1('ec_in_up_cat', 'ec_bad_argument4'); break; default: return ec_end1('ec_input_action', 'ec_bad_argument1'); } if ( pwg_query(" INSERT INTO `".EVNTCATS_TABLE."` (`code`, `user_id`, `action`, `arg1`, `arg2`) VALUES ( '".$ec_lists['ec_table'][$_POST['ec_entry_sel']]['code']."', '".$ec_lists['ec_table'][$_POST['ec_entry_sel']]['user_id']."', 'ec_ok', '".$arg1."', '".$arg2."' ); ") === false ) { $page['errors'][] = l10n('ec_entry_dup_nok_pre1'). $_POST['ec_entry_sel']. l10n('ec_entry_dup_nok_end1'). 'MySQL error '.mysql_errno().', "'.mysql_error().'"' ; return false; } else { $page['infos'][] = l10n('ec_entry_dup_ok_pre'). $_POST['ec_entry_sel'].' ('. $ec_lists['ec_table'][$_POST['ec_entry_sel']]['code'].')'. l10n('ec_entry_dup_ok_end') ; build_ec_table(); return true; } } else return ec_end1('ec_entry_sel', 'ec_bad_argument5'); } /* * ec_modify_entry_OK() * returns true or false whether the modification of an existing entry which # * is given by $_POST['ec_entry_sel'] was OK or not. * * @param * no param * @return * true if modification was OK ; false if not */ function ec_modify_entry_OK() { global $page; $page['errors'][] = 'Y\'a pas eu une erreur ?...'; return false; } /* * ec_toggle_forced_entry() * Toggles the 'forced' property of an entry, provided it complies to the * rules. * * @param * no param * @return * no return value */ function ec_toggle_forced_entry() { global $page; $page['errors'][] = 'ec_toggle_forced_entry'; } /* * ec_delete_entry() * tries to delete an existing entry which # is given by * $_POST['ec_entry_sel']. * * @param * no param * @return * no return value : modifies $page['errors'] or $page['infos'] */ function ec_delete_entry() { global $page, $ec_lists; if (array_key_exists($_POST['ec_entry_sel'], $ec_lists['ec_table'])) { if (!pwg_query(' DELETE FROM `'.EVNTCATS_TABLE.'` WHERE `id` = '.$_POST['ec_entry_sel'] )) { $page['errors'][] = l10n('ec_entry_del_nok_pre'). $_POST['ec_entry_sel']. l10n('ec_entry_del_nok_end'). 'MySQL error '.mysql_errno().', "'.mysql_error().'"' ; } else { $page['infos'][] = l10n('ec_entry_del_ok_pre'). $_POST['ec_entry_sel']. l10n('ec_entry_del_ok_end'); build_ec_table(); } } else ec_end1('ec_entry_sel', 'ec_bad_argument1'); } ?>