<?php
!defined('EMLOG_ROOT') && exit('出错了！！！!');

function plugin_setting_view() {
    require_once 'niuwa_jiazai_config.php';
    ?>
    <div class="card">
        <div class="card-header">
            <h3 class="card-title">配置文件</h3>
            <?php if (isset($_GET['setting'])): ?>
                <div class="alert alert-success" role="alert">
                    设置保存成功!
                </div>
            <?php endif; ?>
        </div>
        <div class="card-body">
            <form action="plugin.php?plugin=niuwa_jiazai&action=setting" method="post">
                <div class="form-group">
                    <label>是否加载jQuery</label>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="off" value="yes" id="jqueryYes" <?php if ($config["off"] == 'yes')
                            echo 'checked'; ?>>
                        <label class="form-check-label" for="jqueryYes">加载</label>
                    </div>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="off" value="no" id="jqueryNo" <?php if ($config["off"] == 'no')
                            echo 'checked'; ?>>
                        <label class="form-check-label" for="jqueryNo">不加载</label>
                    </div>
                    <small class="form-text text-muted">如果模板或其他插件已经加载过jQuery，必须选择不加载，否则出错</small>
                </div>

                <div class="form-group">
                    <label>请选择加载条颜色</label>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="color" value="blue" id="colorBlue" <?php if ($config["color"] == 'blue')
                            echo 'checked'; ?>>
                        <label class="form-check-label" for="colorBlue">
                            <span style="display: inline-block; width: 24px; height: 15px; background-color:#19B5FE;"></span>
                        </label>
                    </div>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="color" value="red" id="colorRed" <?php if ($config["color"] == 'red')
                            echo 'checked'; ?>>
                        <label class="form-check-label" for="colorRed">
                            <span style="display: inline-block; width: 24px; height: 15px; background-color:#ED5565;"></span>
                        </label>
                    </div>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="color" value="pink" id="colorPink" <?php if ($config["color"] == 'pink')
                            echo 'checked'; ?>>
                        <label class="form-check-label" for="colorPink">
                            <span style="display: inline-block; width: 24px; height: 15px; background-color:#FFFF00;"></span>
                        </label>
                    </div>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="color" value="purple" id="colorPurple" <?php if ($config["color"] == 'purple')
                            echo 'checked'; ?>>
                        <label class="form-check-label" for="colorPurple">
                            <span style="display: inline-block; width: 24px; height: 15px; background-color:#BF55EC;"></span>
                        </label>
                    </div>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="color" value="grass" id="colorGrass" <?php if ($config["color"] == 'grass')
                            echo 'checked'; ?>>
                        <label class="form-check-label" for="colorGrass">
                            <span style="display: inline-block; width: 24px; height: 15px; background-color:#A0D468;"></span>
                        </label>
                    </div>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="color" value="heise" id="colorHeise" <?php if ($config["color"] == 'heise')
                            echo 'checked'; ?>>
                        <label class="form-check-label" for="colorHeise">
                            <span style="display: inline-block; width: 24px; height: 15px; background-color:#000000;"></span>
                        </label>
                    </div>
                </div>

                <div class="form-group">
                    <label>右上角加载圈</label>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="off1" value="yes" id="loadCircleYes" <?php if ($config["off1"] == 'yes')
                            echo 'checked'; ?>>
                        <label class="form-check-label" for="loadCircleYes">开启</label>
                    </div>
                    <div class="form-check">
                        <input class="form-check-input" type="radio" name="off1" value="no" id="loadCircleNo" <?php if ($config["off1"] == 'no')
                            echo 'checked'; ?>>
                        <label class="form-check-label" for="loadCircleNo">关闭</label>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary">保存设置</button>
            </form>
        </div>
    </div>
<?php } ?>

<?php
function plugin_setting() {
    require_once 'niuwa_jiazai_config.php';
    $color = $_POST["color"] == "" ? "blue" : $_POST["color"];
    $off = $_POST["off"] == "" ? "no" : $_POST["off"];
    $off1 = $_POST["off1"] == "" ? "yes" : $_POST["off1"];
    $newConfig = '<?php
$config = array(
    "color" => "' . $color . '",
    "off" => "' . $off . '",
    "off1" => "' . $off1 . '",
);';
    @file_put_contents(EMLOG_ROOT . '/content/plugins/niuwa_jiazai/niuwa_jiazai_config.php', $newConfig);
}
