<?php
require '../conn/conn.php';
require '../conn/function.php';
require 'admin_check.php';

$action=$_GET["action"];
if($action=="save"){
	$C_dwzon=$_POST["C_dwzon"];
  $extra=$_POST["extra"];
  $jump=$_POST["jump"];

	if($C_dwzon!=""){
		for ($i=0;$i<count($C_dwzon);$i++){
			$C_dwzonx=$C_dwzonx.$C_dwzon[$i].",";
		}
		$C_dwzonx=substr($C_dwzonx,0,strlen($C_dwzonx)-1);
	}

  if($extra!=""){
    for ($i=0;$i<count($extra);$i++){
      $C_extra=$C_extra.$extra[$i].",";
    }
    $C_extra=substr($C_extra,0,strlen($C_extra)-1);
  }

  foreach ($_POST as $x=>$value) {
    if(splitx($x,"_",0)=="show"){
      mysqli_query($conn,"update sl_domain set D_show=".intval($_POST[$x])." where D_id=".intval(splitx($x,"_",1)));
    }
  }

	if($_POST["C_pid"]==""){
		die("请填全信息");
	}else{
    	$_POST["C_dwzonx"]=$C_dwzonx;
		  mysqli_query($conn,admin("api",$_POST));
      mysqli_query($conn,"update sl_config set C_jump=$jump,C_extra='$C_extra',C_payurl='".t($_POST["C_payurl"])."',C_alipayon=".intval($_POST["C_alipayon"]).",C_wxpayon=".intval($_POST["C_wxpayon"]));
		  die("success");
	}
}
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>接口设置 - 后台管理</title>
<link rel="icon" href="../media/<?php echo $C_ico?>" type="image/ico">
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/materialdesignicons.min.css" rel="stylesheet">
<link href="../css/style.min.css" rel="stylesheet">
<script type="text/javascript" src="../upload/upload.js"></script>
<style type="text/css">
.showpic{height: 60px;border: solid 1px #DDDDDD;padding: 5px;}
</style>
</head>
  
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
  <?php require 'nav.php';?>
    <main class="lyear-layout-content">
      
      <div class="container-fluid">
        
        <div class="row">
          <form class="form-horizontal" id="form">
          <div class="col-md-6">
            
            <div class="card">
              <div class="card-header"><h4>收款设置</h4></div>
              <div class="card-body">
                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">易支付网关</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" name="C_payurl" value="<?php echo $C_payurl?>">
                    </div>
                  </div>

                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">易支付商户ID</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" name="C_pid" value="<?php echo $C_pid?>">
                    </div>
                  </div>

                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">易支付商户密钥</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" name="C_pkey" value="<?php echo $C_pkey?>">
                      <div style="font-size: 12px;margin-top: 10px;color: #33cabb">推荐使用<a href="https://7-pay.cn" target="_blank"><u>7支付官网</u></a>申请收款接口 <a href="https://dwz.s-cms.cn/newsdetail.php?id=2" class="btn btn-xs btn-success" target="_blank">帮助文档</a></div>
                    </div>
                  </div>
                  <hr>

                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">收款方式</label>
                    <div class="col-xs-12">
                      <label><input type="checkbox" name="C_alipayon" value="1" <?php if($C_alipayon=="1"){echo "checked='checked'";}?>> 支付宝</label>
                      <label><input type="checkbox" name="C_wxpayon" value="1" <?php if($C_wxpayon=="1"){echo "checked='checked'";}?>> 微信支付</label>
                    </div>
                  </div>
              </div>
            </div>
            <div class="col-md-12">
        <button class="btn btn-primary" onclick="save()" type="button">保存</button>
      </div>
          </div>

          <div class="col-md-6">
            <div class="card">
              <div class="card-header"><h4>短链接接口设置</h4></div>
              <div class="card-body">
                  
                
                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">短链接API接口开关</label>
                    <div class="col-xs-12">
                    本站域名：<label><input type="checkbox" name="C_dwzon[]" value="-2" <?php if(strpos($C_dwzon,"-2")!==false){echo "checked='checked'";}?>> <?php echo $_SERVER["HTTP_HOST"]?></label><br>
自定义域名：<?php
                    $sql="select D_id,D_domain,D_show from sl_domain";
                    $result = mysqli_query($conn,  $sql);
                    if (mysqli_num_rows($result) > 0) {
                      while($row = mysqli_fetch_assoc($result)) {
                          if($row["D_show"]==1){
                            $checked="checked='checked'";
                          }else{
                            $checked="";
                          }
                            echo "<label><input type=\"hidden\" name=\"show_".$row["D_id"]."\" value=\"0\"><input type=\"checkbox\" name=\"show_".$row["D_id"]."\" value=\"1\" $checked> ".$row["D_domain"]."</label> ";
                        }
                    }
                    ?> <a href="domain.php" class="btn btn-xs btn-primary">新增</a><hr>
                    接口TOKEN：<input type="text" name="C_swkey" value="<?php echo $C_swkey?>" style="width: 400px;"><br>
                    外部API接口：
                            <label><input type="checkbox" name="extra[]" value="1" <?php if(strpos($C_extra,"1")!==false){echo "checked='checked'";}?>> 微信随机通道</label>
                            <label><input type="checkbox" name="extra[]" value="2" <?php if(strpos($C_extra,"2")!==false){echo "checked='checked'";}?>> QQ随机通道</label><br>
                            跳转方式：<label><input type="radio" name="jump" value="0" <?php if($C_jump==0){echo "checked='checked'";}?>> 直接跳转</label> <label><input type="radio" name="jump" value="1" <?php if($C_jump==1){echo "checked='checked'";}?>> 间接跳转</label>

                            
                      <div style="font-size: 12px;margin-top: 10px;color: #33cabb">说明：外部接口需要额外购买套餐才能使用 <a href="https://dwz.s-cms.cn/newsdetail.php?id=5" class="btn btn-xs btn-success" target="_blank">帮助文档</a></div>
                    </div>
                  </div>
              </div>
            </div>
            

            <div class="card">
              <div class="card-header"><h4>伪静态设置</h4></div>
              <div class="card-body">
                  
                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">开启伪静态</label>
                    <div class="col-xs-12">
                      <label><input type="radio" name="C_rewrite" value="1" <?php if($C_rewrite==1){echo "checked='checked'";}?>>开启</label>
                      <label><input type="radio" name="C_rewrite" value="0" <?php if($C_rewrite==0){echo "checked='checked'";}?>>关闭</label>
                      <div style="font-size: 12px;margin-top: 10px;color: #33cabb">开启伪静态 短链以<b>http://abc.com/123</b>的格式显示；关闭伪静态 短链以<b>http://abc.com?123</b>的格式显示 <a href="https://dwz.s-cms.cn/newsdetail.php?id=1" class="btn btn-xs btn-success" target="_blank">帮助文档</a></div>

                    </div>
     
              </div>
            </div>
          </div>
        </form>
        </div>
        
      </div>
      
    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="../js/main.min.js"></script>

<script src="../js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="../js/lightyear.js"></script>
<script src="../js/jqPaginator.min.js" type="text/javascript"></script>
<script src="../js/help.js" type="text/javascript"></script>
<script src="../js/jconfirm/jquery-confirm.min.js"></script>

<script type="text/javascript">
    function save(){
      lightyear.loading('show');
        $.ajax({
                url:'?action=save',
                type:'post',
                data:$("#form").serialize(),
                success:function (data) {
                lightyear.loading('hide');
                if(data=="success"){
                  lightyear.notify("保存成功", 'success', 100);
                }else{
                  lightyear.notify(data, 'danger', 100);
                }
                }
              });
      }

  var path=window.location.pathname;
  $("a").each(function(){
    if(path.indexOf($(this).attr("href"))!=-1){
      console.log($(this).attr("href"));
      $(this).parent("li").addClass("active");
      $(this).parent("li").parent("ul").parent("li").addClass("open active");
    }
  });
</script>
</body>
</html>