<?php
/*
 * @author: CloudZA(云之安) <2922619853@qq.com>
 * @hitokoto: 一场秋雨一场凉，秋心酌满泪为霜。
 * Copyright (c) 2022 by CloudZA, All Rights Reserved.
 */

include_once 'common.php';
if ( !isset($islogin)) header("Location: /");//非法访问
$title = '网站信息';
include_once 'partials/head.php';
$row = Db::table('app_web')->find();
?>
<div id="pjax-container">
<!--导航-->
<div class="bg-body-light">
  <div class="content content-full">
    <div class="d-flex flex-column flex-sm-row justify-content-sm-between align-items-sm-center py-2">
      <div class="flex-grow-1">
        <h1 class="h3 fw-bold mb-2">
          网站信息
        </h1>
      </div>
      <nav class="flex-shrink-0 mt-3 mt-sm-0 ms-sm-3" aria-label="breadcrumb">
        <ol class="breadcrumb breadcrumb-alt">
          <li class="breadcrumb-item">
            <a class="link-fx" href="javascript:void(0)">网站设置</a>
          </li>
          <li class="breadcrumb-item" aria-current="page">
            <?php echo $title ?>
          </li>
        </ol>
      </nav>
    </div>
  </div>
</div>
<!--导航结束-->
<!--内容-->
<div class="content animated fadeIn">
    <div class="block block-rounded">
    <div class="block-header block-header-default">
        <h3 class="block-title"> 网站设置 </h3>
    </div>
     <div class="block-content">
        <form action="" method="POST" onsubmit="return false;">
            <h2 class="content-heading border-bottom mb-2 pb-1 text-dark" style="padding: 0">基本设置</h2>
            <div class="form-group mb-2">
                <label class="form-label fs-sm text-muted" for="sitename">网站名称</label>
                <input type="text" name="sitename" id="sitename" value="<?php echo $row['site_name'] ?>" class="form-control" placeholder="网站名称" required />
            </div>
            <div class="form-group mb-2">
                <label class="form-label fs-sm text-muted" for="web_title">网站标题</label>
                <input type="text" name="web_title" id="web_title" value="<?php echo $row['site_title'] ?>" class="form-control" placeholder="网站标题" required />
            </div>
             <div class="form-group mb-2">
                <label class="form-label fs-sm text-muted" for="web_des">网站描述</label>
                <input type="text" name="web_des" id="web_des" value="<?php echo $row['site_desc'] ?>" class="form-control" required placeholder="网站描述" />
            </div>
            <div class="form-group mb-2">
                <label class="form-label fs-sm text-muted" for="web_key">关键词<small>(多个用英文逗号隔开)</small></label>
                <input type="text" name="web_key" id="web_key" value="<?php echo $row['site_keywords'] ?>" class="form-control" required placeholder="关键词，用英文都好分开" />
            </div>
            <div class="form-group mb-2">
                <label class="form-label fs-sm text-muted" for="web_footer">底部版权</small></label>
                <input type="text" name="web_footer" id="web_footer" value="<?php echo $row['footer'] ?>" class="form-control" required placeholder="网站底部版权" />
            </div>
            <div role="separator" class="div"></div>
            <div class="form-group mb-2">
                <label class="form-label fs-sm text-muted" for="web_page_nums">每页条数</label>
                <input type="text" name="web_page_nums" id="web_page_nums" value="<?php echo $row['site_item_num'] ?>" class="form-control" required placeholder="最低10条" />
            </div>
            <h2 class="content-heading border-bottom mb-2 pb-1 text-dark" style="padding: 0">Redis设置</h2>
            <div class="form-group mb-2">
                <label class="form-label fs-sm text-muted" for="redis_host">Redis地址</label>
                <input type="text" name="redis_host" id="redis_host" value="<?php echo $row['redis_address'] ?>" class="form-control" required placeholder="127.0.0.1" />
            </div>
            <div class="form-group mb-2">
                <label class="form-label fs-sm text-muted" for="redis_port">Redis端口</label>
                <input type="text" name="redis_port" id="redis_port" value="<?php echo $row['redis_port'] ?>" class="form-control" required placeholder="6379" />
            </div>
            <div class="form-group mb-2">
                <label class="form-label fs-sm text-muted" for="redis_pass">Redis密码</label>
                <input type="text" name="redis_pass" id="redis_pass" value="<?php echo $row['redis_password'] ?>" class="form-control" placeholder="没有请留空" />
            </div>
            <h2 class="content-heading border-bottom mb-2 pb-1 text-dark" style="padding: 0">接口限制<small>（敏感接口的安全防护）</small></h2>
            <div class="form-group mb-2">
                <label class="form-label fs-sm text-muted" for="redis_limit">允许的请求次数</label>
                <input type="text" name="redis_limit" id="redis_limit" value="<?php echo $row['api_request_limit'] ?>" class="form-control" required placeholder="60" />
            </div>
            <div class="form-group mb-2">
                <label class="form-label fs-sm text-muted" for="redis_interval">速率限制的时间间隔<small>（单位：秒）</small></label>
                <input type="text" name="redis_interval" id="redis_interval" value="<?php echo $row['api_request_interval'] ?>" class="form-control" required placeholder="300" />
            </div>
            <h2 class="content-heading border-bottom mb-2 pb-1 text-dark" style="padding: 0">验证码设置</h2>
            <div class="form-group mb-2">
                <label class="form-label fs-sm text-muted" for="code_ref">验证码前缀</label>
                <input type="text" name="code_ref" id="code_ref" value="<?php echo $row['code_prefix'] ?>" class="form-control" required placeholder="例如：AU-" />
            </div>
            <div class="form-group mb-2">
                <label class="form-label fs-sm text-muted" for="code_len">验证码长度</label>
                <input type="text" name="code_len" id="code_len" value="<?php echo $row['code_length'] ?>" class="form-control" required placeholder="6" />
            </div>
            <div class="form-group mb-2">
                <label class="form-label fs-sm text-muted" for="code_exp">过期时间<small>(单位：秒)</small></label>
                <input type="text" name="code_exp" id="code_exp" value="<?php echo $row['code_exp_time'] ?>" class="form-control" required placeholder="300" />
            </div>
            <div class="row mb-4">
                <div class="col-xl-12 mt-2">
                    <input type="submit" name="submit" id="submit" value="保存" class="btn btn-sm btn-alt-primary form-control" />
                </div>
            </div>
        </form>
    </div>
</div>
    <script>
    $('#submit').click( () => {
        app.ajax('ajax.php?act=web_set',{
            site_name: app.getval('#sitename'),
            site_title:app.getval('#web_title'),
            site_keywords:app.getval('#web_key'),
            site_desc:app.getval('#web_des'),
            site_item_num:app.getval('#web_page_nums'),
            redis_address:app.getval('#redis_host'),
            redis_port:app.getval('#redis_port'),
            api_request_limit:app.getval('#redis_limit'),
            api_request_interval:app.getval('#redis_interval'),
            redis_password:app.getval('#redis_pass'),
            code_prefix:app.getval('#code_ref'),
            code_length:app.getval('#code_len'),
            code_exp_time:app.getval('#code_exp'),
            footer:app.getval('#web_footer')
        },res=>{
            if(res.code === 200){
                app.notify(res.msg, 'success')
                setTimeout(()=>{
                    app.pjax('set.php');
                }, 1000);
            } else {
                app.notify(res.msg,'warning')
            }
        })
    });
</script>
</div>
<!--内容结束-->
<?php include_once 'partials/foot.php';?>

