<?php
/**
* 其他设置
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
* @version $Id other.inc.php 1 2008-2-21 22:04 $
*/
(!defined('IN_ADMIN') || !defined('IN_MUDDER')) && exit('Access Denied');

switch($op) {
    case 'create':
        if(!check_submit('jssubmit')) {
            $tplname = 'jstransfer';
            $jssort = $jssort=='review' ? 'review' : 'shop';
        } else {
            if($jssort != 'shop' && $jssort != 'review') {
                cpmsg('未选择JS调用类型。');
            } else {
                $param[] = 'jssort='.$jssort; 
            }
            $panels = $panels && is_array($panels) ? $param[] = 'panels='.implode('_', $panels) : '';
            $sort = isset($sort) && $sort > 0 && $sort < 4 ? $param[] = 'sort='.$sort : 0;
            $num = isset($num) && $num > 0 ? $param[] = 'num='.$num : 0;
            $intercept = isset($intercept) && $intercept > 0 ? $param[] = 'intercept='.$intercept : 0;
            $openwindow = isset($openwindow) && $openwindow > 0 ? $param[] = 'openwindow='.$openwindow : 0;
            $pcdname = isset($pcdname) && $pcdname > 0 ? $param[] = 'pcdname='.$pcdname : 0;

            if(!$sort) cpmsg('未选择调用类型，请返回修改还。');
            if(!$num) cpmsg('显示数量不能小于1，请返回修改还。');

            $jscode = html_special_chars("<script type=\"text/javascript\" charset=\"$charset\" src=\"{$_config['siteurl']}js.php?".implode('&', $param)."\"></script>");

            $tplname = 'jstransfer';
        }
        include cptpl($tplname);
        break;
    default:
        if(!check_submit('jssubmit')) {
            $op = 'config';
            $tplname = 'jstransfer';
            $config = $db->get_one("SELECT value FROM {$dbpre}config WHERE variable='jstransfer'");
            $jstransfer = unserialize($config['value']);
            $jstransfer_enable[0] = !$jstransfer['enable'] ? 'checked="checked"' : '';
            $jstransfer_enable[1] = $jstransfer['enable'] ? 'checked="checked"' : '';
            include cptpl($tplname);
        } else {
            $jstransfer['enable'] = intval($jstransfer['enable']) > 0 ? 1 : 0;
            $jstransfer['cachelife'] = intval($jstransfer['cachelife']);
            (!is_numeric($jstransfer['cachelife']) || $jstransfer['cachelife'] < 0) && cpmsg('您未设置的JS数据缓存时间');
            $jstransfer['access'] = html_special_chars_ex(preg_replace("/\s*(\r\n|\n\r|\n|\r)\s*/", "\r\n", $jstransfer['access']));
            $newconfig['jstransfer'] = addslashes(serialize($jstransfer));
            $db->query("REPLACE INTO {$dbpre}config (variable, value) VALUES ('jstransfer', '".addslashes(serialize($jstransfer))."')");
            cache_config();
            cpmsg('JS调用设置完毕。');
        }
        break;
}
?>
