<?php

/* ========================================================================
 * $Id: setting.php 4259 2020-07-09 00:17:42Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
# edit
#请求数据
if($MODE=='$post'){
  $id=onez()->gp('id');
  $action=onez()->gp('action');
  if($action=='data'){
    
    $data=array();
    $data['title']='系统设置';
    $A['pagedata']=$data;
    
    $site=$G['this']->data()->open('setting')->one("index12='{$G['site']['id']}'");
    if(!$site){
      $item=array();
      $item['name']=$G['site']['name'];
      $item['index12']=$G['site']['id'];
      $G['this']->data()->open('setting')->insert($item);
      $site=$G['this']->data()->open('setting')->one("index12='{$G['site']['id']}'");
    }
    $form=$this->load('form');
    $form->init($site);
    
    $tab='基础';
    $form->add(array('label'=>'网站名称','type'=>'text','key'=>'name','hint'=>'','notempty'=>'网站不能为空','default'=>'','group'=>''),$tab);
    $form->add(array('label'=>'底部版权信息','type'=>'textarea','key'=>'copyright','height'=>'200','notempty'=>'','default'=>'','group'=>''),$tab);
    
    $tab='商品页设置';
    $form->add(array('label'=>'公共头部','ptoken'=>'bs.editor','key'=>'public_header','hint'=>'','notempty'=>'','default'=>'','group'=>''),$tab);
    $form->add(array('label'=>'公共尾部','ptoken'=>'bs.editor','key'=>'public_footer','hint'=>'','notempty'=>'','default'=>'','group'=>''),$tab);
    
    $tab='邮件设置';
    $form->add(array('label'=>'SMTP服务器','type'=>'text','key'=>'mail_host','hint'=>'例：stmp.qq.com','notempty'=>'','default'=>'','group'=>''),$tab);
    $form->add(array('label'=>'SMTP端口','type'=>'text','key'=>'mail_port','hint'=>'例：465','notempty'=>'','default'=>'','group'=>''),$tab);
    $form->add(array('label'=>'SMTP账号','type'=>'text','key'=>'mail_username','hint'=>'例：www@onez.cn','notempty'=>'','default'=>'','group'=>''),$tab);
    $form->add(array('label'=>'SMTP密码','type'=>'text','key'=>'mail_password','hint'=>'QQ邮箱为授权码','notempty'=>'','default'=>'','group'=>''),$tab);
    $form->add(array('label'=>'是否开启SSL','type'=>'switch','key'=>'mail_ssl','hint'=>'','notempty'=>'','default'=>'','group'=>''),$tab);
    $form->add(array('label'=>'发件人邮件地址','type'=>'text','key'=>'mail_from_email','hint'=>'例：www@onez.cn','notempty'=>'','default'=>'','group'=>''),$tab);
    $form->add(array('label'=>'发件人名称','type'=>'text','key'=>'mail_from_name','hint'=>'例：佳蓝科技','notempty'=>'','default'=>'','group'=>''),$tab);
    $form->add(array('label'=>'自动发货标题','type'=>'text','key'=>'mail_title','hint'=>'','notempty'=>'','default'=>'','group'=>''),$tab);
    $form->add(array('label'=>'自动发货内容','type'=>'textarea','key'=>'mail_body','ptoken'=>'bs.editor','notempty'=>'','default'=>'','group'=>''),$tab);
    $html='';
    $html.='<h3>适用于自动发货标题和内容</h3>';
    $html.='<p><span class="name">${name}</span>: 商品名称</p>';
    $html.='<p><span class="name">${nickname}</span>: 当前购买用户昵称</p>';
    $html.='<p><span class="name">${url}</span>: 商品详情页</p>';
    $html.='<p><span class="name">${message}</span>: 发货信息</p>';
    $html.='<p><span class="name">${time}</span>: 发货时间</p>';
    $html.='<p><span class="name">${price}</span>: 商品价格</p>';
    $html.='<p><span class="name">${orderno}</span>: 订单号</p>';
    $form->add(array('label'=>'自动发货变量','type'=>'html','key'=>'mail_body_tip','value'=>$html,'notempty'=>'','default'=>'','group'=>''),$tab);
    
    onez('bs.app.shipments')->slot('/admin/system/setting/form',$form);
    if($onez=$form->submit()){
      $onez['copyright']=$_REQUEST['copyright'];
      $onez['mail_body']=$_REQUEST['mail_body'];
      $onez['public_header']=$_REQUEST['public_header'];
      $onez['public_footer']=$_REQUEST['public_footer'];
      onez('bs.app.shipments')->slot('/admin/system/setting/save',$onez);
      $G['this']->data()->open('setting')->update($onez,"index12='{$G['site']['id']}'");
      return $this->ok('提交成功','reload2');
    }
    $form->output($A);
  }
  return;
}
$this->add(array(
  'type'=>'breadcrumb',
  'name'=>'面包屑导航',
  'data'=>'pagedata',
));

$this->add(array(
  'type'=>'pageform',
  'name'=>'表单',
  'data'=>'form',
));
