<?php
/**
 * [LJCMS] (C)2012-2099 LJdev,Inc.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2014.04.03
*/

class control extends salebase {

    
    public function action_run(){
        $searchsql = "";

        $searchsql .= " AND v.treeid='".intval(2)."'";

        $scatid=$_REQUEST['catid'];
        $sname=$_REQUEST['title'];
        if ($scatid>0) {
            $m = parent::model('category', 'am');
            $childs = $m->getChildIDs($scatid);
            if (!empty($childs)) {
                $searchsql .= " AND v.catid IN (".$childs.$scatid.")";
            }
            else {
                $searchsql .= " AND v.catid='".$scatid."'";
            }
            unset($m);
        }
        if (!empty($sname)) {
            $searchsql .= " AND lower(v.productname) LIKE '%".strtolower($sname)."%'";
        }


        $model = parent::model('product', 'am');
        list($total, $data) = $model->getList(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql, 'limit'=>'stock'));

        $url = XRequest::getPhpSelf();
        $url .= '?c=Inventory';
        parent::loadLib('mod');
        $category_select = XMod::selectNodeEnableChilds($this->tid, $this->scatid ,'scatid', '所有分类');
        $var_array = array(
            'page'=>$this->page,
            'nextpage'=>$this->page+1,
            'prepage'=>$this->page-1,
            'pagecount'=>ceil($total/$this->pagesize),
            'pagesize'=>$this->pagesize,
            'total'=>$total,
            'showpage'=>XPage::sale($total, $this->pagesize, $this->page, $url, 10),
            'urlitem'=>$this->_urlitem,
            'comeurl'=>$this->_comeurl,
            'tid'=>$this->tid,
            'sname'=>$this->sname,
            'product'=>$data,
            'category_select'=>$category_select,
            'modtitle'=>$this->modtitle,
            'sname'=>$sname,
            'scatid'=>$scatid,
        );
        unset($model);
        TPL::assign($var_array);
        
        TPL::display($this->cptpl.'inventory/index.tpl');
    }

}