<?php
/******************************
 * EQdkp
 * Copyright 2002-2005
 * Licensed under the GNU GPL.  See COPYING for full terms.
 * ------------------
 * listallitems.php
 * Began: Sat December 21 2002
 *
 * $Id: listallitems.php 6 2006-05-08 17:11:35Z tsigo $
 *
 ******************************/

define('EQDKP_INC', true);
$eqdkp_root_path = './spdkp/';
include_once($eqdkp_root_path . 'common.php');
// MODIFICATION, ItemStat http://itemstats.free.fr === by Yahourt / Thorkal == EU Elune / Horde =========
include_once($eqdkp_root_path . 'eqdkp_config_itemstats.php');
include_once($eqdkp_root_path . path_itemstats . '/eqdkp_itemstats.php');
//========================================================================================================

$user->check_auth('u_item_list');

//
// Item Purchase History (all items)
//
    $sort_order = array(
        0 => array('item_date desc', 'item_date'),
        1 => array('item_buyer', 'item_buyer desc'),
        2 => array('item_name', 'item_name desc'),
        3 => array('raid_name', 'raid_name desc'),
        4 => array('item_value desc', 'item_value')
    );

    $current_order = switch_order($sort_order);

    $page_title = sprintf($user->lang['title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']).': '.$user->lang['listpurchased_title'];

	$totalraidsql = 'SELECT i.item_id, i.item_name, i.item_buyer, i.item_date, i.raid_id, i.item_value, r.raid_name, c.class_name as member_class, "Sunwell Plateau" as zone, "spdkp" as folder
				FROM spdkp_items i, spdkp_members m, spdkp_classes c, spdkp_raids r
				WHERE r.raid_id=i.raid_id and i.item_buyer=m.member_name and m.member_class_id=c.class_id
				union all
				SELECT i.item_id, i.item_name, i.item_buyer, i.item_date, i.raid_id, i.item_value, r.raid_name, c.class_name as member_class, "Mount Hyjal" as zone, "mhdkp" as folder
				FROM mhdkp_items i, mhdkp_members m, mhdkp_classes c, mhdkp_raids r
				WHERE r.raid_id=i.raid_id and i.item_buyer=m.member_name and m.member_class_id=c.class_id
				union all
				SELECT i.item_id, i.item_name, i.item_buyer, i.item_date, i.raid_id, i.item_value, r.raid_name, c.class_name as member_class, "Black Temple" as zone, "btdkp" as folder
				FROM btdkp_items i, btdkp_members m, btdkp_classes c, btdkp_raids r
				WHERE r.raid_id=i.raid_id and i.item_buyer=m.member_name and m.member_class_id=c.class_id';
			
	$db->query($totalraidsql);
	$total_items = $db->num_rows();

    $start = ( isset($_GET['start']) ) ? $_GET['start'] : 0;

    $sql = 'SELECT i.item_id, i.item_name, i.item_buyer, i.item_date, i.raid_id, i.item_value, r.raid_name, c.class_name as member_class, "Sunwell Plateau" as zone, "spdkp" as folder
			FROM spdkp_items i, spdkp_members m, spdkp_classes c, spdkp_raids r
			WHERE r.raid_id=i.raid_id and i.item_buyer=m.member_name and m.member_class_id=c.class_id
			union all
			SELECT i.item_id, i.item_name, i.item_buyer, i.item_date, i.raid_id, i.item_value, r.raid_name, c.class_name as member_class, "Mount Hyjal" as zone, "mhdkp" as folder
			FROM mhdkp_items i, mhdkp_members m, mhdkp_classes c, mhdkp_raids r
			WHERE r.raid_id=i.raid_id and i.item_buyer=m.member_name and m.member_class_id=c.class_id
			union all
			SELECT i.item_id, i.item_name, i.item_buyer, i.item_date, i.raid_id, i.item_value, r.raid_name, c.class_name as member_class, "Black Temple" as zone, "btdkp" as folder
			FROM btdkp_items i, btdkp_members m, btdkp_classes c, btdkp_raids r
			WHERE r.raid_id=i.raid_id and i.item_buyer=m.member_name and m.member_class_id=c.class_id
            ORDER BY '.$current_order['sql']. '
            LIMIT '.$start.','.$user->data['user_ilimit'];

    $listitems_footcount = sprintf($user->lang['listpurchased_footcount'], $total_items, $user->data['user_ilimit']);
    $pagination = generate_pagination('listallitems.php'.$SID.'&amp;' . URI_PAGE . '=history&amp;o='.$current_order['uri']['current'],
                                       $total_items, $user->data['user_ilimit'], $start);

// Regardless of which listitem page they're on, we're essentially
// outputting the same stuff. Purchase History just has a buyer column.
if ( !($items_result = $db->query($sql)) )
{
    message_die('Could not obtain item information', '', __FILE__, __LINE__, $sql);
}

while ( $item = $db->fetch_record($items_result) )
{
	
	$itemvalue =  $item['item_value'];

// MODIFICATION, ItemStat http://itemstats.free.fr === by Yahourt / Thorkal == EU Elune / Horde =========
    if (function_exists('itemstats_decorate_name'))
    {
        $tpl->assign_block_vars('items_row', array(
            'ROW_CLASS' => $eqdkp->switch_row_class(),
            'DATE' => ( !empty($item['item_date']) ) ? date($user->style['date_notime_short'], $item['item_date']) : '&nbsp;',
            'BUYER' => ( !empty($item['item_buyer']) ) ? $item['item_buyer'] : '&lt;<i>Not Found</i>&gt;',
            'BUYER_CLASS'  => $item['member_class'],
            'U_VIEW_BUYER' => '/' . 'viewmemberall.php'.$SID.'&amp;' . URI_NAME . '='.$item['item_buyer'],
            'NAME' => itemstats_decorate_name(stripslashes($item['item_name'])),
            'U_VIEW_ITEM' => '/' . $item['folder'] . '/' . 'viewitem.php'.$SID.'&amp;' . URI_ITEM . '='.$item['item_id'],
            'RAID' => ( !empty($item['raid_name']) ) ? stripslashes($item['raid_name']) : '&lt;<i>Not Found</i>&gt;',
			'U_VIEW_ZONE' => '/' . $item['folder'] . '/',
			'U_VIEW_RAID' => '/' . $item['folder'] . '/' . 'viewraid.php'.$SID.'&amp;' . URI_RAID . '='.$item['raid_id'],
            'VALUE' => $itemvalue)
            );
    }
//========================================================================================================
    else
	{
		$tpl->assign_block_vars('items_row', array(
				'ROW_CLASS' => $eqdkp->switch_row_class(),
				'DATE' => ( !empty($item['item_date']) ) ? date($user->style['date_notime_short'], $item['item_date']) : '&nbsp;',
				'BUYER' => ( !empty($item['item_buyer']) ) ? $item['item_buyer'] : '&lt;<i>Not Found</i>&gt;',
				'BUYER_CLASS'  => $item['member_class'],
				'U_VIEW_BUYER' => 'viewmemberall.php'.$SID.'&amp;' . URI_NAME . '='.$item['item_buyer'],
				'NAME' => stripslashes($item['item_name']),
				'U_VIEW_ITEM' => 'viewitem.php'.$SID.'&amp;' . URI_ITEM . '='.$item['item_id'],
				'RAID' => ( !empty($item['raid_name']) ) ? stripslashes($item['raid_name']) : '&lt;<i>Not Found</i>&gt;',
				'U_VIEW_RAID' => 'viewraid.php'.$SID.'&amp;' . URI_RAID . '='.$item['raid_id'],
				'VALUE' => $itemvalue)
		);
	}
}

$db->free_result($items_result);


$tpl->assign_vars(array(
    'L_DATE' => $user->lang['date'],
    'L_BUYER' => $user->lang['buyer'],
    'L_ITEM' => $user->lang['item'],
    'L_RAID' => $user->lang['raid'],
    'L_VALUE' => $user->lang['value'],

    'O_DATE' => $current_order['uri'][0],
    'O_BUYER' => $current_order['uri'][1],
    'O_NAME' => $current_order['uri'][2],
    'O_RAID' => $current_order['uri'][3],
    'O_VALUE' => $current_order['uri'][4],

    'U_LIST_ITEMS' => "listallitems.php?",

    'START' => $start,
    'S_HISTORY' => $s_history,
    'LISTITEMS_FOOTCOUNT' => $listitems_footcount,
    'ITEM_PAGINATION' => $pagination)
);

$eqdkp->set_vars(array(
    'page_title'    => $page_title,
    'template_file' => 'listallitems.html',
    'display'       => true)
);
?>
