<?php
namespace admin\Controller;
use Think\Controller;
class SmsController extends CommonController {

	public function _initialize(){
		//$config = M('Config')->fetchSql(true)->select();
		$config = D('Config')->get_config();
		$this->assign('show',$config);
	}
	public function config(){
		$this->display();
	}
	public function edit(){
	
		if(IS_POST)
		{
				$data = M('Config');
				$config=I('post.');
				//$intval_array=array('UU_GOLD_SEND_MB','UU_GOLD_QUANTIFIER_ANONYMOUS','UU_MAP_ZOOM');
				foreach ($config as $key =>$v)
				{ 
					$where['name'] = "{$key}";
					$savev['value'] ="{$v}";
					if ($where['name']=='UU_SITE_DOMAIN'){
					$savev['value']=rtrim($savev['value'],'/');
					}
					if ($where['name']=='UU_GOLD_SEND_MB'){
						$savev['value']=intval($savev['value'])<0?0:intval($savev['value']);
					}
					if ($where['name']=='UU_GOLD_QUANTIFIER_ANONYMOUS'){
						$savev['value']=intval($savev['value'])<0?0:intval($savev['value']);
					}
			 
					 
				 	$data->where($where)->save($savev);
				}
				if(!uu_refresh_cache('config')){
				$this->error('生成缓存失败！');
				}
				$this->success('保存完成');
		}
		else
		{
				$this->error('参数错误');
		}
	}
	public function tpl(){
		$list=M('SmsTpl')->select();
		$this->assign('list',$list);
		$this->display();
	}
	public function tpl_save(){
		$id = I('post.id');
        $tpl = I('post.tpl');
		$tplid = I('post.tplid');
		$num = 0;
		$data = M("SmsTpl");
		if (is_array($id) && count($id)>0)
        {
            foreach($id as $k=>$v)
            {
                unset($map);
                $map['id'] = intval($v);
                $map['tpl']=trim($tpl[$k]);
                $map['tplid']=trim($tplid[$k]);
				$data->save($map);
                $num++;
         
            }
        }
		if($num>0){
            $this->success('成功保存'.$num.'个模板！');
        }else{
            $this->error('未保存任何分类！');
        }
	}
 
}
?>