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

class ld_labelcus extends controllerBase
{
	function __construct(){
		parent::__construct();
		$this->Class=syClass('ldi_labelcus');
		$this->custom_Class=syClass('ldi_custom');
		$this->newrow = array(
			'name' => $this->sysParams('name',1),
			'body' => $this->sysParams('body',4),
			'type' => $this->sysParams('type'),
		);
	}
	function index(){
		$this->toptxt='自定义模板标签管理';
		$this->lists = $this->Class->findAll(null,null,'id,name');
		$this->display("labelcus.html");
	}
	function add(){
		if ($this->sysParams('run')==1){
			$newVerifier=$this->Class->syVerifier($this->newrow);
			if(false == $newVerifier){
				if($this->Class->create($this->newrow)){
					message_a("自定义模板标签创建成功","?c=ld_labelcus");
				}else{message_a("自定义模板标签创建失败，请重新提交");}
			}else{message_b($newVerifier);}
		}
		$this->toptxt='添加自定义模板标签';
		$this->postgo='add';
		$this->display("labelcus.html");
	}
	function edit(){
		$this->d=$this->Class->find(array('id'=>$this->sysParams('id')));
		if ($this->sysParams('run')==1){
			$newVerifier=$this->Class->syVerifier($this->newrow);
			if(false == $newVerifier){
				deleteDir(func_get_iglobal(array('sp_cache')));
				if($this->Class->update(array('id'=>$this->sysParams('id')),$this->newrow)){
					$this->Class->syCache(-1)->find(array('id'=>$this->sysParams('id')));
					message_a("自定义模板标签修改成功","?c=ld_labelcus");
				}else{message_a("自定义模板标签修改失败,请重新提交");}
			}else{message_b($newVerifier);}
		}
		$this->toptxt='修改自定义模板标签';
		$this->postgo='edit';
		$this->display("labelcus.html");
	}
	function del(){
		$this->toptxt='删除自定义模板标签';
		$this->d=$this->Class->find(array('id'=>$this->sysParams('id')));
		if ($this->sysParams('run')==1){
			deleteDir(func_get_iglobal(array('sp_cache')));
			if($this->Class->delete(array('id'=>$this->sysParams('id'))))
			{message_a("自定义模板标签删除成功","?c=ld_labelcus");}else{message_a("自定义模板标签删除失败,请重新提交");}
		}
		$this->msgtitle='确定要删除自定义模板标签 <strong>['.$this->d['name'].']</strong> 吗？';
		$this->msg='';
		$this->msggo='<a href="?c=ld_labelcus&a=del&run=1&id='.$this->d['id'].'">确定删除</a><a href="?c=ld_labelcus">取消操作</a>';
		$this->display("msg.html");
	}
	function custom_index(){
		$this->toptxt='自定义页面管理';
		$this->lists = syDB('custom')->findAll();
		$this->display("custom.html");
	}
	function custom_add(){
		if ($this->sysParams('run')==1){
			$this->newr = array(
				'name' => $this->sysParams('name',1),
				'dir' => $this->sysParams('dir',1),
				'template' => $this->sysParams('template',1),
				'file' => $this->sysParams('file',1),
			);
			$newVerifier=$this->custom_Class->syVerifier($this->newr);
			if(false == $newVerifier){
				if($this->custom_Class->create($this->newr)){
					message_a("自定义页面创建成功","?c=ld_labelcus&a=custom_index");
				}else{message_a("自定义页面创建失败，请重新提交");}
			}else{message_b($newVerifier);}
		}
		$this->toptxt='添加自定义页面';
		$this->postgo='custom_add';
		$this->display("custom.html");
	}
	function custom_edit(){
		$this->d=$this->custom_Class->find(array('id'=>$this->sysParams('id')));
		if ($this->sysParams('run')==1){
			$this->newr = array(
				'name' => $this->sysParams('name',1),
				'dir' => $this->sysParams('dir',1),
				'template' => $this->sysParams('template',1),
				'file' => $this->sysParams('file',1),
			);
			$newVerifier=$this->custom_Class->syVerifier($this->newr);
			if(false == $newVerifier){
				if($this->custom_Class->update(array('id'=>$this->sysParams('id')),$this->newr)){
					$this->custom_Class->syCache(-1)->find(array('id'=>$this->sysParams('id')));
					message_a("自定义页面修改成功","?c=ld_labelcus&a=custom_index");
				}else{message_a("自定义页面修改失败,请重新提交");}
			}else{message_b($newVerifier);}
		}
		$this->toptxt='修改自定义页面';
		$this->postgo='custom_edit';
		$this->display("custom.html");
	}
	function custom_del(){
		$this->toptxt='删除自定义页面';
		$this->d=$this->custom_Class->find(array('id'=>$this->sysParams('id')));
		if ($this->sysParams('run')==1){
			if($this->custom_Class->delete(array('id'=>$this->sysParams('id'))))
			{message_a("自定义页面删除成功","?c=ld_labelcus&a=custom_index");}else{message_a("自定义页面删除失败,请重新提交");}
		}
		$this->msgtitle='确定要删除自定义页面 <strong>['.$this->d['name'].']</strong> 吗？';
		$this->msg='';
		$this->msggo='<a href="?c=ld_labelcus&a=custom_del&run=1&id='.$this->d['id'].'">确定删除</a><a href="?c=ld_labelcu&a=custom_index">取消操作</a>';
		$this->display("msg.html");
	}
}	