<?php self::head(); ?>
<style>
    #log {
        color: #999;
        font-size: 12px;
        line-height: 22px;
    }
</style>

<div class="content" id="<?php echo APP_MAINID; ?>">
    <div class="block">
        <?php if (Patch::$test) { ?>
            <div class="alert alert-warning">测试模式</div>
        <?php } ?>
        <div class="block-content block-content-full">
            <?php if ($upgrade) { ?>
            <div class="alert alert-warning">
                <strong>Warning!</strong>
                本次升级将会执行相关升级程序!
                <hr />
                请勿关闭浏览器,等待程序执行完毕!
            </div>
            <?php } ?>
            <div id="log"></div>
            <?php if ($_GET['do'] == "download") { ?>
            <div class="form-actions">
                <?php if (isset($_GET['git'])) { ?>
                <a class="btn btn-success btn-lg" href="<?php echo APP_URL; ?>&do=install&release=<?php echo Patch::$release; ?>&git=true">
                    <i class="fa fa-fw fa-wrench"></i>
                    开始升级
                </a>
                <?php } else { ?>
                <a class="btn btn-success btn-lg" href="<?php echo APP_URL; ?>&do=install">
                    <i class="fa fa-fw fa-wrench"></i>
                    开始升级
                </a>
                <?php } ?>
            </div>
            <?php } ?>
        </div>
    </div>
</div>
<script type="text/javascript">
    var log = "<?php echo $log; ?>".split('<iCMS>');
    var n = 0,
        timer = 0;
    setIntervals();

    function GoPlay() {
        console.log(log);
        if (n > log.length - 1) {
            n = -1;
            clearIntervals();
        }
        if (n > -1) {
            log_scroll(n);
            n++;
        }
    }

    function log_scroll(n) {
        log_msg(log[n]);
        window.scrollTo(0, $(document.body).outerHeight(true));
    }

    function setIntervals() {
        timer = setInterval('GoPlay()', 100);
    }

    function log_msg(text) {
        text = text.replace('#', '<hr />');
        document.getElementById('log').innerHTML += text + '<br /><a name="last"></a>';
    }

    function clearIntervals() {
        clearInterval(timer);
        <?php if ($upgrade) { ?>
            log_msg('<div class="alert alert-success">源码更新完成!</div>');
            log_msg('<div class="alert">现在开始执行升级程序! >>>></div>');
            window.setTimeout(function() {
                window.location.href = '<?php echo APP_URL; ?>&do=upgrade&iCMS_RELEASE=<?php echo iCMS_RELEASE; ?>&iCMS_GIT_TIME=<?php echo iCMS_GIT_TIME; ?>';
            }, 1000);
        <?php } ?>
    }
</script>
<?php self::foot(); ?>
