<?php
/**
 * 系统设置控制器
 * @Copyright (C) 2017 汉朝 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author dongziyi <2066207038@qq.com>
 */
namespace Admin\Controller;
class PrintTemplateController extends BaseController
{
    public function _initialize()
    {
        parent::_initialize();
        $this->model = D('PrintTemplate');
        $this->device='';
    }

      public function index()
    {

        $map = array();
        $list = $this->lists('PrintTemplate', $map, 'sort,id');
        $this->assign('list', $list);
        $this->display();
    }

    /**
     * 编辑模版
     */
    public function edit()
    {
        $id = intval(I('get.id'));
        if (empty($id)) {
            $this->error('参数错误！');
        } 
        $map = array();
        $map['id'] = $id;       
        $info = M('PrintTemplate')->field(true)->where($map)->find();
        $this->assign('id',$id);
        // $this->assign('status',$info['status']);
        $this->assign($info);
        $this->display();
    }  

    // /**
    //  * 添加模版
    //  */
    public function _before_update(){
        
    }
    // {
    //     $postdata = I('post.');
    //     _before
    //     $id = intval(I('post.'));
    //     if (empty($id)) {
    //         $this->error('参数错误！');
    //     } 
    //     $map = array();
    //     $map['id'] = $id;       
    //     $info = M('PrintTemplate')->field(true)->where($map)->find();
    //     $this->assign('id',$id);
    //     $this->assign('status',$info['status']);
    //     $this->assign($info);
    //     $this->display();
    // }

    /**
     * 批量保存配置
     */
    public function save($config)
    {
        if ($config && is_array($config)) {
            $vi=array();
            foreach ($config as $name => $value) {
                $map = array('name' => $name);
                if(is_array($value)){
                    foreach($value as $key=>$val){
                         $vi[]=implode(":",$val);
                    }
                    $value = implode(",",$vi);
                }
                $this->model->where($map)->setField('value', $value);
            }
        }
        if ($config['MEMBER_UC'] && $config['MEMBER_UCONFIG']) {//更新ucenter配置
            $con = "<?php\n" . $config['MEMBER_UCONFIG'] . ";\n?>";
            oaofile(APP_PATH . 'Home/Conf/uc.php', $con);
        }
        S('DB_CONFIG_DATA', null);
        $this->success('保存成功！');
    }
}
?>