<?php

/* ========================================================================
 * $Id: setting.php 3330 2020-05-17 12:45:14Z 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;
    
    $form=$this->load('form');
    $bs=$G['this']->data()->open('bs')->one("userid='$G[userid]'");
    if(!$bs){
      $item=array();
      $item['userid']=$G['userid'];
      $G['this']->data()->open('bs')->insert($item);
      $bs=$G['this']->data()->open('bs')->one("userid='$G[userid]'");
    }
    !$bs['sitename'] && $bs['sitename']='佳蓝智能开发';
    $form->init($bs);
    
    $tab='基础';
    $form->add(array('label'=>'主控网站名称','type'=>'text','key'=>'sitename','hint'=>'','notempty'=>'','default'=>'','group'=>'','tip'=>'当前网站的显示名称'),$tab);
    $form->add(array('label'=>'通讯密钥','type'=>'text','key'=>'apikey','hint'=>'','notempty'=>'','default'=>'','group'=>''),$tab);
    if($G['userid']==1 || !defined('IS_ON_ONEZSITE')){
      $form->add(array('label'=>'泛解析域名','type'=>'text','key'=>'pandomain','hint'=>'例：*.onez.site','notempty'=>'','default'=>'','group'=>'','tip'=>''),$tab);
    }
    if($bs['onezuser']){
      if($_SERVER['HTTPS']=='on'){
        $bs['onezuser']['avatar']=str_replace('http://file.onez.cn/cache','https://www.onez.cn/files',$bs['onezuser']['avatar']);
      }
      $form->add(array('label'=>'佳蓝账号','key'=>'onezuser','type'=>'html','value'=>'<pre><img src="'.$bs['onezuser']['avatar'].'" style="width:16px;height:16px;position: relative;top: -2px;" />'.$bs['onezuser']['nickname'].'</pre>'),$tab);
    }else{
      $form->add(array('label'=>'佳蓝账号','key'=>'onezuser','type'=>'html','value'=>'<pre>未绑定</pre>','tip'=>' <button type="button" onclick="onez.link(this)" href="./setting/bind.php" args="width=320&height=230&classname=win-small" class="btn btn-xs btn-info">绑定</button>'),$tab);
    }
    
    $tab='登录设置';
    $form->add(array('label'=>'背景图片','type'=>'image','key'=>'login_bgpic','hint'=>'','notempty'=>'','default'=>'','group'=>''),$tab);
    $form->add(array('label'=>'开启新用户注册','type'=>'switch','key'=>'login_is_register','hint'=>'','notempty'=>'','default'=>'','group'=>''),$tab);
    $form->add(array('label'=>'登录页大标题','type'=>'text','key'=>'login_title','hint'=>'','notempty'=>'','default'=>'佳蓝智能开发','group'=>''),$tab);
    $form->add(array('label'=>'登录页小标题','type'=>'text','key'=>'login_title_small','hint'=>'','notempty'=>'','default'=>'System Management Center','group'=>''),$tab);
    $form->add(array('label'=>'注册链接名称','type'=>'text','key'=>'login_reg_linkname','hint'=>'','notempty'=>'','default'=>'免费注册','group'=>''),$tab);
    
    if($onez=$form->submit()){
      unset($onez['onezuser']);
      if(!$onez['apikey']){
        $onez['apikey']=md5(uniqid());
      }
      $G['this']->data()->open('bs')->update($onez,"id='$bs[id]'");
      $G['this']->siteUpdate();
      return $this->ok('提交成功','reload2');
    }
    $form->output($A);
  }
  return;
}
$this->add(array(
  'type'=>'breadcrumb',
  'name'=>'面包屑导航',
  'data'=>'pagedata',
));
$this->add(array(
  'type'=>'pageform',
  'name'=>'表单',
  'data'=>'form',
));
