$item_img = '';
     }
     if ($row['element_img'] != '' && $row['item_element'] != 0) {
         $element_img = '<img src="adr/images/elements/' . $row['element_img'] . '">';
     } else {
         $element_img = $lang['Adr_store_element_none'];
     }
     $template->assign_vars(array("ROW_CLASS" => $theme['td_class1'], "ROW_CLASS_2" => $theme['td_class2'], "ACTION_SELECT" => $action_select, "ITEM_ID" => $row['item_id'], "ITEM_NAME" => adr_get_lang($row['item_name']), "ITEM_DESC" => adr_get_lang($row['item_desc']), "ITEM_IMG" => $item_img, "ITEM_QUALITY" => $lang[$row['item_quality_lang']], "ITEM_TYPE" => $lang[$row['item_type_lang']], "ITEM_DURA" => $row['item_duration'], "ITEM_DURA_MAX" => $row['item_duration_max'], "ITEM_POWER" => $row['item_power'], "ITEM_PRICE" => $row['item_price'], "ITEM_WEIGHT" => $row['item_weight'], "ITEM_ELEMENT" => $element_img, "ITEM_ADD_POWER" => $row['item_add_power'], "ITEM_MP" => $row['item_mp_use'], "ITEM_POINTS" => $points_name, "SHOP_OWNER_ID" => $store_owner_id, "L_ITEM_INFO" => $lang['Adr_store_item'], "L_ITEM_NAME" => $lang['Adr_store_name'], "L_ITEM_DESC" => $lang['Adr_store_desc'], "L_ITEM_QUALITY" => $lang['Adr_store_quality'], "L_ITEM_POWER" => $lang['Adr_store_power'], "L_ITEM_ADD_POWER" => $lang['Adr_items_dex'], "L_ITEM_MP" => $lang['Adr_items_mp_use'], "L_ITEM_DURA" => $lang['Adr_store_duration'], "L_ITEM_IMG" => $lang['Adr_races_image'], "L_ITEM_PRICE" => $lang['Adr_store_price'], "L_ITEM_TYPE" => $lang['Adr_items_type_use'], "L_ITEM_WEIGHT" => $lang['Adr_store_weight'], "L_ITEM_ELEMENT" => $lang['Adr_store_element'], "L_ACTION" => $lang['Adr_items_action'], "L_SUBMIT" => $lang['Submit']));
     break;
 case 'sell':
     // Define some values
     $items = isset($_POST['item_box']) && is_array($_POST['item_box']) ? $_POST['item_box'] : array();
     // Deny sale if the user is in a battle
     $sql = "SELECT battle_id FROM  " . ADR_BATTLE_LIST_TABLE . "\r\t\t\t\tWHERE battle_challenger_id = '{$user_id}'\r\t\t\t\tAND battle_result = '0'\r\t\t\t\tAND battle_type = '1'";
     if (!($result = $db->sql_query($sql))) {
         message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);
     }
     $bat = $db->sql_fetchrow($result);
     if (is_numeric($bat['battle_id'])) {
         adr_previous('Adr_battle_no_sell_items', 'adr_character_inventory', '');
     }
     $item_id_list = '(' . implode(',', $items) . ',0)';
     $sql = "SELECT i.* FROM " . ADR_SHOPS_ITEMS_TABLE . " i\r\t\t\t\tWHERE i.item_owner_id = {$user_id}\r\t\t\t\tAND i.item_in_shop = 0\r\t\t\t\tAND i.item_duration > 0 \r\t\t\t\tAND i.item_auth = 0 \r\t\t\t\tAND i.item_no_sell = 0 \r\t\t\t\tAND i.item_id IN {$item_id_list} \r\t\t\t\tORDER BY i.item_name ";
     if (!($result = $db->sql_query($sql))) {
         message_die(GENERAL_ERROR, 'Could not obtain items information', "", __LINE__, __FILE__, $sql);
     }
     $items = $db->sql_fetchrowset($result);
     $items_name = '';
     while (list(, $item) = @each($items)) {
         $item_id = $item['item_id'];
         $temp_price = adr_get_item_real_price($item_id, $user_id);
function adr_sell_item($item_id, $user_id)
{
    global $db, $adr_general;
    // Fix the values
    $user_id = intval($user_id);
    $item_id = intval($item_id);
    $sql = "SELECT character_trading_limit FROM " . ADR_CHARACTERS_TABLE . "\n\t\t\tWHERE character_id = {$user_id} ";
    $result = $db->sql_query($sql);
    if (!$result) {
        message_die(GENERAL_ERROR, 'Could not obtain shops items information', "", __LINE__, __FILE__, $sql);
    }
    $trading_limit = $db->sql_fetchrow($result);
    if ($adr_general['Adr_character_limit_enable'] != 0 && $trading_limit['character_trading_limit'] < 1) {
        adr_previous(Adr_trading_limit, adr_shops, '');
    } else {
        adr_trading_limit($user_id);
    }
    // Get the item real price
    $temp_price = adr_get_item_real_price($item_id, $user_id);
    // Apply the trading skill modification
    $price = adr_use_skill_trading($user_id, $temp_price, sell);
    // Delete the item
    $sql = "DELETE FROM " . ADR_SHOPS_ITEMS_TABLE . "\n\t\tWHERE item_owner_id = {$user_id}\n\t\tAND item_id = {$item_id} ";
    $result = $db->sql_query($sql);
    if (!$result) {
        adr_previous(Adr_shop_items_failure_deleted, adr_character_inventory, '');
    }
    // Give points to the seller - has to be done at the end to prevent treacherous users !
    adr_add_points($user_id, $price);
}