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

$action=$_GET["action"];
if($action=="save"){

  $C_title=$_POST["C_title"];
  $C_keyword=$_POST["C_keyword"];
  $C_description=$_POST["C_description"];
  $C_logo=$_POST["C_logo"];
  $C_ico=$_POST["C_ico"];
  $C_code=$_POST["C_code"];
  $C_copyright=$_POST["C_copyright"];
  $C_qq=$_POST["C_qq"];


  $C_beian=$_POST["C_beian"];
  $C_adprice1=$_POST["C_adprice1"];
  $C_adprice2=$_POST["C_adprice2"];
  $C_adprice3=$_POST["C_adprice3"];
  $C_urlprice=$_POST["C_urlprice"];
  $C_day=$_POST["C_day"];

  $C_admin=$_POST["C_admin"];
  $C_pwd=$_POST["C_pwd"];

  if($C_title==""){
    die("请填全信息");
  }else{
    mysqli_query($conn,"update sl_config set
    C_title='$C_title',
    C_keyword='$C_keyword',
    C_description='$C_description',
    C_logo='$C_logo',
    C_ico='$C_ico',
    C_code='$C_code',
    C_copyright='$C_copyright',
    C_qq='$C_qq',
    C_beian='$C_beian',
    C_adprice1=$C_adprice1,
    C_adprice2=$C_adprice2,
    C_adprice3=$C_adprice3,
    C_urlprice=$C_urlprice,
    C_day=$C_day,
    C_admin='$C_admin'");
    
    if($C_pwd!=""){
      mysqli_query($conn,"update sl_config set C_pwd='".md5($C_pwd)."'");
    }
    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_title" value="<?php echo $C_title?>">
                    </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_keyword" value="<?php echo $C_keyword?>">
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">网站描述</label>
                    <div class="col-xs-12">
                      <textarea class="form-control" name="C_description"><?php echo $C_description?></textarea>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">网站logo</label>
                    <div class="col-xs-12">
                      <div class="row">
                      <div class="col-xs-3">
                      <img src="../media/<?php echo $C_logo?>" id="C_logox" class="showpic" onClick="showUpload('C_logo','C_logo','../media',1,null,'','');">
                    </div>
                    <div class="col-xs-9">
                            <div class="input-group">
                              <input type="text" id="C_logo" name="C_logo" class="form-control" value="<?php echo $C_logo?>">
                              <span class="input-group-btn">
                                      <button class="btn btn-primary m-b-5 m-t-5" type="button" onClick="showUpload('C_logo','C_logo','../media',1,null,'','');">上传</button>
                              </span>
                      </div>
                    </div>
                  </div>
                    </div>
                  </div>

                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">网站ico图标</label>
                    <div class="col-xs-12">
                      <div class="row">
                      <div class="col-xs-3">
                      <img src="../media/<?php echo $C_ico?>" id="C_icox" class="showpic" onClick="showUpload('C_ico','C_ico','../media',1,null,'','');">
                    </div>
                     <div class="col-xs-9">
                            <div class="input-group">
                              <input type="text" id="C_ico" name="C_ico" class="form-control" value="<?php echo $C_ico?>">
                              <span class="input-group-btn">
                                      <button class="btn btn-primary m-b-5 m-t-5" type="button" onClick="showUpload('C_ico','C_ico','../media',1,null,'','');">上传</button>
                              </span>
                      </div>
                    </div>
                    </div>
                  </div>
                  </div>


                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">QQ客服</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" name="C_qq" value="<?php echo $C_qq?>">
                    </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_beian" value="<?php echo $C_beian?>" placeholder="可留空">
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">版权文字</label>
                    <div class="col-xs-12">
                      <textarea class="form-control" name="C_copyright"><?php echo $C_copyright?></textarea>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">统计代码</label>
                    <div class="col-xs-12">
                      <textarea class="form-control" name="C_code"><?php echo $C_code?></textarea>
                    </div>
                  </div>
              </div>
            </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">首页文字广告</label>
                    <div class="col-xs-12">
                      <div class="input-group">
                          <input class="form-control" type="text" name="C_adprice1" value="<?php echo $C_adprice1?>">
                          <span class="input-group-addon">元/月</span>
                      </div>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">首页图片广告</label>
                    <div class="col-xs-12">
                      <div class="input-group">
                          <input class="form-control" type="text" name="C_adprice2" value="<?php echo $C_adprice2?>">
                          <span class="input-group-addon">元/月</span>
                      </div>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">跳转页广告</label>
                    <div class="col-xs-12">
                      <div class="input-group">
                          <input class="form-control" type="text" name="C_adprice3" value="<?php echo $C_adprice3?>">
                          <span class="input-group-addon">元/月</span>
                      </div>
                      <div style="font-size: 12px;margin-top: 10px;color: #33cabb">*广告价格填0则不开启该广告</div>
                    </div>
                  </div>
                  <hr>
                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">临时短网址升级永久</label>
                    <div class="col-xs-12">
                      <div class="input-group">
                          <input class="form-control" type="text" name="C_urlprice" value="<?php echo $C_urlprice?>">
                          <span class="input-group-addon">元/个</span>
                      </div>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="col-xs-12" for="example-email-input">临时短网址有效期</label>
                    <div class="col-xs-12">
                      <div class="input-group">
                          <input class="form-control" type="text" name="C_day" value="<?php echo $C_day?>">
                          <span class="input-group-addon">天</span>
                      </div>
                      <div style="font-size: 12px;margin-top: 10px;color: #33cabb">*填0则永久有效</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">
                      <input class="form-control" type="text" name="C_admin" value="<?php echo $C_admin?>">
                    </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_pwd" placeholder="已加密保存，留空则不修改">
                    </div>
                  </div>
              </div>
            </div>
            <button type="button" onClick="save()" class="btn btn-primary">保存</button>
          </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 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>