<?php
if(!defined('APP_PATH')||!defined('I_PATH')){exit('Access Denied');}

class ld_special extends controllerBase
{
	function __construct(){
		parent::__construct();
		$this->opers='<a href="?c=ld_special">专题管理</a><a href="?c=ld_special&a=add">添加专题</a>';
		$this->ClassS=syClass('ldi_special');
		$this->auser=syClass('syauser');
		$this->chtml = syClass("syhtml");
		$this->moldsop=syDB('molds')->findAll(array('isshow'=>1));
		$this->Get_c='ld_special';
		$_SESSION['gos']=date("His").mt_rand(1000,9999);
		if($this->sysParams('title',1)){$title=$this->sysParams('title',1);}else{$title=$this->sysParams('name',1);}
		if($this->sysParams('htmldir',1)!='/'){$htmldir=trim($this->sysParams('htmldir',1),'/');}else{$htmldir=$this->sysParams('htmldir',1);}
		$this->newrow = array(
			'molds' => $this->sysParams('molds',1),
			'name' => $this->sysParams('name',1),
			'gourl' => $this->sysParams('gourl',1),
			'litpic' => $this->sysParams('litpic',1),
			'title' => $title,
			'keywords' => $this->sysParams('keywords',1),
			'description' => $this->sysParams('description',1),
			'isindex' => $this->sysParams('isindex'),
			't_index' => $this->sysParams('t_index',1),
			't_list' => $this->sysParams('t_list',1),
			't_listb' => $this->sysParams('t_listb',1),
			'listnum' => $this->sysParams('listnum'),
			'htmldir' => strtolower($htmldir),
			'htmlfile' => strtolower($this->sysParams('htmlfile',1)),
			'orders' => $this->sysParams('orders'),
			'body' => $this->sysParams('body',4),
			'isshow' => $this->sysParams('isshow'),
		);
	}
	function index(){
		$this->toptxt='专题管理';
		$this->lists = $this->ClassS->findAll();
		$this->display("special.html");
	}
	function add(){
		if ($this->sysParams('run')==1){
			$newVerifier=$this->ClassS->syVerifier($this->newrow);
				if(false == $newVerifier){
					if($this->ClassS->create($this->newrow)){
						if(syExt('site_html')==1){
							if($this->newrow['htmldir']==''){ //TODO  site_html_dir
								$c_html_f=$GLOBALS['WWW'].'/s/'.$addnew.'/';
							}else{
								$c_html_f=$this->newrow['htmldir'].'/';
							}
							if($this->newrow['htmlfile']==''){
								$c_html_f.='index'.syExt('site_html_suffix');
							}else{
								$c_html_f.=$this->newrow['htmlfile'].syExt('site_html_suffix');
							}
							$this->chtml->c_special(array('sid'=>$addnew),$c_html_f);
						}
						deleteDir(func_get_iglobal(array('sp_cache')));
						message_a("专题创建成功","?c=".$this->Get_c);
					}else{message_a("专题创建失败，请重新提交");}
				}else{message_b($newVerifier);}
		}
		$this->toptxt='添加专题';
		$this->postgo='add';
		$this->display("special_edit.html");
	}
	function edit(){
		$this->carray=$this->ClassS->find(array('sid'=>$this->sysParams('sid')));
		if ($this->sysParams('run')==1){
			$newVerifier=$this->ClassS->syVerifier($this->newrow);
			if(false == $newVerifier){
				if($this->ClassS->update(array('sid'=>$this->carray['sid']),$this->newrow)){
						if(syExt('site_html')==1){
							if($this->newrow['htmldir']==''){  //TODO  site_html_dir
								$c_html_f=$GLOBALS['WWW'].'/s/'.$this->carray['sid'].'/';
							}else{
								$c_html_f=$this->newrow['htmldir'].'/';
							}
							if($this->newrow['htmlfile']==''){
								$c_html_f.='index'.syExt('site_html_suffix');
							}else{
								$c_html_f.=$this->newrow['htmlfile'].syExt('site_html_suffix');
							}
							$this->chtml->c_special( array('sid'=>$this->carray['sid']),$c_html_f);
						}
					deleteDir(func_get_iglobal(array('sp_cache')));
					message_a("专题修改成功","?c=".$this->Get_c);
				}else{message_a("专题修改失败,请重新提交");}
			}else{message_b($newVerifier);}
		}
		$this->toptxt='修改专题';
		$this->postgo='edit';
		$this->display("special_edit.html");
	}
	function del(){
		$this->toptxt='删除专题';
		$this->d=$this->ClassS->find(array('sid'=>$this->sysParams('sid')));
		$sid=$this->d['sid'];
		if ($this->sysParams('run')==1){
			if($this->ClassS->delete(array('sid'=>$sid))){
				deleteDir(func_get_iglobal(array('sp_cache')));
				message_a("专题删除成功","?c=".$this->Get_c);
			}else{message_a("专题删除失败,请重新提交");}
		}
		$this->msgtitle='确定要删除专题 <strong>['.$this->d['name'].']</strong> 吗？';
		$this->msg='';
		$this->msggo='<a href="?c='.$this->Get_c.'&a=del&run=1&sid='.$sid.'">确定删除</a><a href="?c='.$this->Get_c.'">取消操作</a>';
		$this->display("msg.html");
	}

}	