<?php
class contentAction extends baseAction {
    public function content_category(){
		
		$list = M('content_category')->where("fid='0'")->order("listorder asc,id asc")->select();
		// echo M('content_category')->getLastSql();
		foreach($list as $k=>$v){
			$list_1 = M('content_category')->where("fid='". $v['id'] ."'")->order("listorder asc,id asc")->select();//子目录一层
			$data[$k] = $v;
			$data[$k]['list_1'] = $list_1;
			foreach($list_1 as $k1=>$v1){
			$list_2 = M('content_category')->where("fid='". $v1['id'] ."'")->order("listorder asc,id asc")->select();//子目录二层
			$data[$k]['list_1'][$k1]['list_2'] = $list_2;
			}
		}
		// print_r($data);
		$this->assign('data',$data);
		$this->display('content_category');
	}
	public function content_category_add(){
		$c_data = M('content_category')->where("fid='0'")->order("listorder asc,id asc")->select();
		foreach($c_data as $k=>$v){
			$cat_data[$k] = $v;
			$c_data_1 = M('content_category')->where("fid='". $v['id'] ."'")->order("listorder asc,id asc")->select();//第二层分类
			$cat_data[$k]['list_1'] = $c_data_1;
		}
		$this->assign('cat_data',$cat_data);
		$this->assign('fid',$this->_get('fid')?$this->_get('fid'):'');
		$this->display("content_category_add");
	}
	public function category_edit(){
		if($this->_get('id')) {
		$c_data = M('content_category')->where("fid='0'")->order("listorder asc,id asc")->select();
		foreach($c_data as $k=>$v){
			$cat_data[$k] = $v;
			$c_data_1 = M('store_category')->where("fid='". $v['id'] ."'")->order("listorder asc,id asc")->select();//第二层分类
			$cat_data[$k]['list_1'] = $c_data_1;
		}
		$this->assign('cat_data',$cat_data);
		$data = M('content_category')->where("id='". $this->_get('id') ."'")->find();
		$this->assign('data',$data);
		$this->assign('id',$this->_get('id'));
		$this->display("content_category_edit");
		}else{
		exit("<script>window.top.art.dialog({content:'参数错误！',lock:true,width:'200',height:'50',time:1.5},function(){});history.go(-1);</script>");
		}
	}
	public function content_category_delete(){
		if($this->_get('id')) {
			$id = $this->_get('id');
			$did = $id.',';//did所有要删除的分类id
			$data = M('content_category')->where("fid = '" .$id. "'")->select();
			foreach($data as $k=>$v){
			$did .= $v['id'].',';
			}
			$did = substr($did,0,strlen($did)-1);
			$data_1 = M('content_category')->where("fid in(". $did .")")->select();
			foreach($data_1 as $ks=>$vs){
			$del_id .= $vs['id'].',';
			}
			$del_id = $del_id?$id.','.substr($del_id,0,strlen($del_id)-1):$id;
			if(M('content_category')->where("id in(". $del_id .")")->delete()){
				$this->success('删除成功','',2);
			}else{
				$this->error('删除失败','',2);
			}
		}else{
			exit("<script>window.top.art.dialog({content:'参数错误！',lock:true,width:'200',height:'50',time:1.5},function(){});history.go(-1);</script>");
		}
	}
	public function category_insert(){
		$this->show('该版本为试用版本，正版版本请联系QQ：245500339');
	}
	public function category_save(){
		$this->show('该版本为试用版本，正版版本请联系QQ：245500339');
	}
	public function content_list(){
		$data = D('pages');
		$map = " 1=1 and a.status='1' ";
		$order = ' order by a.id desc ';
		$result = $data->content_page(25,$map,$order);
		// print_r($result);
		$this->assign('list',$result['list']);
		$this->assign('page',$result['page']);
		$this->display('content_list');
	}

	public function content_list_check(){
		$this->show('该版本为试用版本，正版版本请联系QQ：245500339');
	}
	public function content_content_add(){
		$category_list = M('content_category')->where("fid='0'")->order("listorder asc,id asc")->select();
		$this->assign("category_list",$category_list);
		$tags = M('tag')->order("number desc,id desc")->limit(20)->select();
        $this->assign('model','add');
        $this->assign('tags',$tags);
		$this->display('content_content_add');
	}
	public function ajax_get_category(){
		$this->show('该版本为试用版本，正版版本请联系QQ：245500339');
	}
	public function content_content_insert(){
        $this->show('该版本为试用版本，正版版本请联系QQ：245500339');
    
	}
	public function content_content_delete(){
		if(I('id')) {
			$Data = D('content_content');
			if($Data->where("id='". I('id') ."'")->delete()){
				$this->success('删除成功');
			}else{
				$this->error('删除失败');
			}
		}
	}

	public function content_content_update(){
		$this->show('该版本为试用版本，正版版本请联系QQ：245500339');
	}
	public function content_content_edit(){
		$data = M('content_content')->where("id = '". I('id') ."'")->find();
		$this->assign('vo',$data);
        $tags = M('tag')->order("number desc,id desc")->limit(20)->select();
        $this->assign('tags',$tags);
		$t_data = M('content_tag')->query("select b.* from ". C('DB_PREFIX') ."content_tag as a left join ". C('DB_PREFIX') ."tag as b on a.tid=b.id where a.cid='". I('id') ."'");
		$tag = '';
		foreach($t_data as $k=>$v){
			$tag .= $v['title'].',';
		}
		$tag = substr($tag,0,strlen($tag)-1);
		$this->assign('tag',$tag);
		$this->display('content_content_edit');
	}
	public function content_content_save(){
		$this->show('该版本为试用版本，正版版本请联系QQ：245500339');
	}
	public function content_form_html($cid){
		$this->show('该版本为试用版本，正版版本请联系QQ：245500339');
	}
}