$give_to .= '</select>'; $template->assign_vars(array("GIVE_TO" => $give_to, "L_ITEM_DONATION" => sprintf($lang['Adr_items_donation'], '<br />' . $items_name), "L_GIVE_TO" => $lang['Adr_items_give_to'], "L_SUBMIT" => $lang['Submit'], "S_MODE_ACTION" => append_sid("admin_adr_give_users_spells.{$phpEx}"), "S_HIDDEN_FIELDS" => $s_hidden_fields)); break; case 'give_item': $quantity = $_POST['quantity'] ? intval($_POST['quantity']) : 1; $to_user_id = !empty($_POST['give_to']) ? $_POST['give_to'] : $_GET['give_to']; $sql = "SELECT * FROM " . ADR_SHOPS_SPELLS_TABLE . " \r\n\t\t\t\tWHERE spell_owner_id = 1 "; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, $lang['Adr_shop_items_failure_deleted']); } $items = $db->sql_fetchrowset($result); while (list(, $item) = @each($items)) { if (isset($_POST[$item['spell_id']])) { $item_id = $item['spell_id']; for ($j = 0; $j < $quantity; $j++) { adr_spell_add_new($item_id, $to_user_id, 'admin_adr_give_users_spells'); } } } adr_previous(Adr_spells_give_spell_success, admin_adr_give_users_spells, ''); break; } } else { adr_template_file('admin/config_adr_give_user_spells_body.tpl'); $template->assign_block_vars('view_store', array()); if (isset($_GET['mode2']) || isset($_POST['mode2'])) { $mode2 = isset($_POST['mode2']) ? htmlspecialchars($_POST['mode2']) : htmlspecialchars($_GET['mode2']); } else { $mode2 = 'itemname'; } if (isset($_POST['order'])) {
function adr_learn_spell($recipe_id, $user_id) { global $db; // Fix the values $recipe_id = intval($recipe_id); $user_id = intval($user_id); //get info of the owners recipe $sql_owner = "SELECT item_name, item_owner_id, item_id FROM " . ADR_SHOPS_ITEMS_TABLE . "\r\n\t\tWHERE item_owner_id = {$user_id}\r\n\t\tAND item_id = {$recipe_id}"; $result_owner = $db->sql_query($sql_owner); if (!$result_owner) { message_die(GENERAL_ERROR, 'Could not obtain owners recipes information', "", __LINE__, __FILE__, $sql_owner); } $owner_recipe = $db->sql_fetchrow($result_owner); $item_name = $owner_recipe['item_name']; //get info of the original recipe $sql_original = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\r\n\t\tWHERE item_owner_id = 1\r\n\t\tAND item_name = '{$item_name}'"; $result_original = $db->sql_query($sql_original); if (!$result_original) { message_die(GENERAL_ERROR, 'Could not obtain original recipe information', "", __LINE__, __FILE__, $sql_owner); } $admin_recipe = $db->sql_fetchrow($result_original); //get now all info of the up-to-date spell in the spell shop (id 1) (Admin might have changed or deleted it) $sql_admin = "SELECT spell_id, spell_owner_id, spell_linked_item FROM " . ADR_SHOPS_SPELLS_TABLE . "\r\n\t\tWHERE spell_owner_id = 1\r\n\t\tAND spell_linked_item = " . $admin_recipe['item_id']; $result_admin = $db->sql_query($sql_admin); if (!$result_admin) { message_die(GENERAL_ERROR, 'Could not obtain original spell information', "", __LINE__, __FILE__, $sql_owner); } $admin_spell = $db->sql_fetchrow($result_admin); $spell_id = $admin_spell['spell_id']; if (!$spell_id) { //recipe deleted return 2; } else { adr_spell_add_new($spell_id, $user_id, 'adr_character_inventory'); //delete the just used recipe $sql = "DELETE FROM " . ADR_SHOPS_ITEMS_TABLE . "\r\n\t\t\tWHERE item_id = " . $recipe_id . "\r\n\t\t\tAND item_owner_id = {$user_id}"; $result = $db->sql_query($sql); if (!$result) { message_die(GENERAL_ERROR, "Couldn't delete owners recipe", "", __LINE__, __FILE__, $sql); } return 1; } }