<?php
/**
 * @link         http://www.openzc.cn/
 * @author       hexipeng | e-mail:2017412656@qq.com
 * @copyright    Copyright (c) 2020, Openzc, Inc.
 * @license      http://www.openzc.cn/license.txt
 */
class catelistModel{
	function Run(&$atts, &$refObj, &$fields){
		global $GET,$category_class,$product_class,$predata_class,$filter_class;

		$attlist = "cid=,parent=0,row=100,flag=,type=,current=,limit=,imgsizer=,bgcolor=,has_pro=false,has_sub=false";
		FillAtts($atts,$attlist);
		FillFields($atts,$fields,$refObj);
		extract($atts, EXTR_OVERWRITE);
		$line = empty($row) ? 100 : $row;
		
		$categories=$predata_class->getPredata(TABLE_CATEGORIES);

		if($cid=="current"){
			$cid=openzc_get_current_cpath($_GET['cPath']);
		}
		else if(($type=="top" && !$cid) || $cid=="all"){
			$cid=$category_class->get_all_top();
		}
		else if($cid=="parent"){
			$current_id=$cid=openzc_get_current_cpath($GET['cPath']);
			$cid=$categories[$current_id]["parent_id"];
			if(!$cid || $cid==0){$cid="parent";}
		}
		if($type=="son"){
			//$limit="";
			if($cid=="parent"){
				$cid=$category_class->get_all_top();
			}else{
				if($fields['categories_id']){
					$cid=$categories[$fields['categories_id']]['categories_sub_id'];
				}else{
					$cid=$categories[$cid]['categories_sub_id'];
				}
			}
		}
		if($type=="top" && $cid=="current"){
			$current_id=$cid=openzc_get_current_cpath($GET['cPath']);
			$cid=openzc_get_top_id($categories,$current_id);
		}
		$parameter=array('cid'=>$cid,'row'=>$line,"flag"=>$flag,"type"=>$type,"limit"=>$limit,"imgsizer"=>$imgsizer,"has_pro"=>$has_pro,"has_sub"=>$has_sub);
		$categories=$category_class->get_categories_list($_GET,$parameter);
		foreach($categories as $k => $v){
			$allCids[]=$v['categories_id'];
		}
		foreach($categories as $k => $v){
			$categories[$k]['allcids']=join(",",$allCids);
		}
		$atts="";
		
		return $categories;
		
	}
}
