<?php
$title='框架初始配置';
include __DIR__ . '/head.php';
?>

<div class="p-4 md:p-6">
    <div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
        <div class="p-4 md:p-6 border-b border-gray-200">
            <h2 class="text-base md:text-lg font-semibold text-gray-800">框架初始配置</h2>
        </div>
        <div class="p-4 md:p-6">
            <form onsubmit="saveSetting(this);return false;" method="post" class="space-y-6">
                <div class="grid grid-cols-1 md:grid-cols-4 gap-4 items-center">
                    <label class="text-xs md:text-sm font-medium text-gray-700">通讯密钥</label>
                    <div class="md:col-span-3">
                        <input type="text" class="w-full px-3 md:px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm" name="httpkey" value="<?php echo $conf['httpkey']?>">
                    </div>
                </div>
                <div class="grid grid-cols-1 md:grid-cols-4 gap-4 items-start">
                    <label class="text-xs md:text-sm font-medium text-gray-700">取状态超时</label>
                    <div class="md:col-span-3">
                        <input type="number" class="w-full px-3 md:px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm" name="get_status_timeout" value="<?php echo isset($conf_frame['get_status_timeout']) ? intval($conf_frame['get_status_timeout']) : '5'; ?>" min="1" max="120">
                        <p class="mt-1 text-xs text-gray-500">获取QQ状态、列表、下线等请求的超时时间（秒）建议5</p>
                    </div>
                </div>
                <div class="grid grid-cols-1 md:grid-cols-4 gap-4 items-start">
                    <label class="text-xs md:text-sm font-medium text-gray-700">登录超时</label>
                    <div class="md:col-span-3">
                        <input type="number" class="w-full px-3 md:px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm" name="login_timeout" value="<?php echo isset($conf_frame['login_timeout']) ? intval($conf_frame['login_timeout']) : '15'; ?>" min="1" max="300">
                        <p class="mt-1 text-xs text-gray-500">登录、扫码、验证码等请求的超时时间（秒）建议30</p>
                    </div>
                </div>
                <div class="grid grid-cols-1 md:grid-cols-4 gap-4 items-start">
                    <label class="text-xs md:text-sm font-medium text-gray-700">QQ与登录接口绑定</label>
                    <div class="md:col-span-3">
                        <select class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm" name="login_bangding" default="<?php echo $conf_frame['login_bangding']?>">
                            <option value="0">不绑定</option>
                            <option value="1">绑定</option>
                        </select>
                        <p class="mt-1 text-xs text-gray-500">绑定后QQ不能使用其他的接口登录，特殊功能非必要不建议开启</p>
                    </div>
                </div>
                <div class="grid grid-cols-1 md:grid-cols-4 gap-4 items-start">
                    <label class="text-xs md:text-sm font-medium text-gray-700">登录前是否删除QQ</label>
                    <div class="md:col-span-3">
                        <select class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm" name="login_del_before" default="<?php echo isset($conf_frame['login_del_before']) ? $conf_frame['login_del_before'] : '0'; ?>">
                            <option value="0">否</option>
                            <option value="1">是</option>
                        </select>
                        <p class="mt-1 text-xs text-gray-500">登录前先在目标节点删除该QQ（默认否）</p>
                    </div>
                </div>
                <div class="grid grid-cols-1 md:grid-cols-4 gap-4 items-start">
                    <label class="text-xs md:text-sm font-medium text-gray-700">QQ登录接口与原来不一样时</label>
                    <div class="md:col-span-3">
                        <select class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm" name="del_frame_qq" default="<?php echo $conf_frame['del_frame_qq']?>">
                            <option value="0">下线_原来框架QQ</option>
                            <option value="1">删除_原来框架QQ</option>
                            <option value="2">不做任何处理_可能会把框架无限挤线</option>
                        </select>
                        <p class="mt-1 text-xs text-gray-500">下线_原来框架QQ：原框架必须在线且通讯正常才能发送下线指令</p>
                    </div>
                </div>
                <div class="grid grid-cols-1 md:grid-cols-4 gap-4 items-start">
                    <label class="text-xs md:text-sm font-medium text-gray-700">到期QQ是否自动下线</label>
                    <div class="md:col-span-3">
                        <select class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm" name="is_dropline" default="<?php echo $conf_frame['is_dropline']?>">
                            <option value="0">否</option>
                            <option value="1">是</option>
                        </select>
                    </div>
                </div>
                <div class="grid grid-cols-1 md:grid-cols-4 gap-4 items-start">
                    <label class="text-xs md:text-sm font-medium text-gray-700">检查QQ掉线重登</label>
                    <div class="md:col-span-3">
                        <select class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm" name="dropline" default="<?php echo $conf_frame['dropline']?>">
                            <option value="0">否</option>
                            <option value="1">是</option>
                        </select>
                        <p class="mt-1 text-xs text-gray-500">检查QQ掉线重登：用户也需要开启掉线重登才会执行，且二次登录数据没失效才会执行</p>
                    </div>
                </div>
                <div class="grid grid-cols-1 md:grid-cols-4 gap-4 items-start">
                    <label class="text-xs md:text-sm font-medium text-gray-700">全局_掉线重登</label>
                    <div class="md:col-span-3">
                        <select class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm" name="dropline_user" default="<?php echo $conf['dropline_user']?>">
                            <option value="0">新增QQ _ 关闭 掉线重登</option>
                            <option value="1">新增QQ _ 开启 掉线重登</option>
                        </select>
                        <p class="mt-1 text-xs text-gray-500">仅对新增的QQ号生效！</p>
                    </div>
                </div>

                <div class="grid grid-cols-1 md:grid-cols-4 gap-4 items-center">
                    <label class="text-xs md:text-sm font-medium text-gray-700">过期多少天后自动删除</label>
                    <div class="md:col-span-3 flex items-center gap-2">
                        <input type="number" class="flex-1 px-3 py-2 border border-gray-300 rounded-lg text-sm" name="qq_end_day" value="<?php echo $conf_frame['qq_end_day']?>">
                        <span class="text-sm text-gray-600">天</span>
                    </div>
                </div>
                <p class="text-xs text-gray-500 md:col-start-2 md:col-span-3">填写0不删除，删除框架QQ+网站QQ(大部分的框架删除QQ时有几率崩这是框架的问题，手动删除也是有几率崩的)</p>
                <div class="grid grid-cols-1 md:grid-cols-4 gap-4 items-start">
                    <label class="text-xs md:text-sm font-medium text-gray-700">QQ号过期后删除</label>
                    <div class="md:col-span-3">
                        <select class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm" name="del_qq_type" default="<?php echo $conf['del_qq_type']?>">
                            <option value="0">框架QQ+网站QQ</option>
                            <option value="1">网站QQ</option>
                            <option value="2">框架QQ</option>
                        </select>
                    </div>
                </div>
                <div class="md:col-start-1 md:col-span-4 pt-4 border-t border-gray-200">
                    <button type="submit" class="w-full md:w-auto px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg transition text-sm">
                        保存/修改
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<?php include 'foot.php'; ?>

<script type="text/javascript">
	var items = $("select[default]");
	for (i = 0; i < items.length; i++) {
		$(items[i]).val($(items[i]).attr("default")||0);
	}
	function saveSetting(obj){
		showLoading();
		$.ajax({
			type : 'POST',
			url : 'ajax.php?act=frame_conf',
			data : $(obj).serialize(),
			dataType : 'json',
			success : function(data) {
				hideLoading();
				if(data.code == 1){
					showToast(data.msg, 'success');
					setTimeout(function() {
						window.location.reload();
					}, 1000);
				}else{
					showToast(data.msg, 'error');
				}
			},
			error:function(data){
				hideLoading();
				showToast('服务器错误', 'error');
				return false;
			}
		});
	}
</script>
