<?php

require_once(dirname(dirname(__FILE__)) . '/app.php');
need_login();


$condition1 = "";
if($_GET){  
    if($_GET['item_number']){
        $item_number = str_replace("\r\n","",$_GET['item_number']);
        $item_number = explode(',',$item_number);
        $condition['item_number'] = $item_number;
        $condition1 .= "and a.item_number in ('".join('\',\'',$item_number)."') ";
    }
    if($_GET['size']){
        $size = explode(',',$_GET['size']);
        $condition['size'] = $size;
        $condition1 .= "and a.size in ('".join('\',\'',$size)."') ";
    }
    if($_GET['season']){
        $season = explode(',',$_GET['season']);
        $condition['season'] = $season;
        $condition1 .= "and a.season in ('".join('\',\'',$season)."') ";
    }
    if($_GET['provider']){
        $condition['provider_id'] = $_GET['provider'];
        $condition1 .= "and a.provider_id=".$_GET['provider']." ";
    }
    if($_GET['category']){
        $condition['category_id'] = $_GET['category'];
        $condition1 .= "and a.category_id=".$_GET['category']." ";
    }
}

$count = Table::Count('item', $condition);
list($pagesize, $offset, $pagestring) = pagestring($count, 20);
if($count==0){
    Session::Set('error','没有查询到符合条件的产品，请检查查询条件，重新查询！');
}else{
    if($_GET)Session::Set('success','查询完成！');
}

$sql = "SELECT a . * , b.name as provider_name, c.zone,c.name
        FROM item AS a, provider AS b,category as c
        WHERE a.provider_id = b.id and a.category_id = c.id ".$condition1."
        LIMIT ".$offset.",".$pagesize;

$item = DB::GetQueryResult($sql,false);
$provider = DB::LimitQuery('provider');
$category = DB::LimitQuery('category');


include template('item_index');?>
