<?php
if(!defined('MOD'))  die("access die");
if( $_POST['insert'] == 1)
{
	$template_dir = A_P . "/templates/cache/";
	if(!is_dir($template_dir)) qbase::createdir($template_dir);
	clearstatcache();
	if(!is_dir($template_dir) || !qbase::writeable($template_dir)) qbase::showmsg($template_dir . "目录不可写，请先通过FTP设置该目录权限");
	$type        = intval( $_GET['type']);
	$code_name   = trim( $_POST['code_name']);
	$description = trim( $_POST['description']);
	$file_name   = trim( $_POST['file_name']) . ".js";
	$tpl   = trim( $_POST['tpl']);
	$dateline    = $_SERVER['REQUEST_TIME'];
	
	/*
	*接受参数
	*/
	$args = array();
	$args['num']          =  intval( $_POST['num']);
	$args['cid']          =  intval( $_POST['cid']);
	$args['is_comend']    =  intval( $_POST['is_comend']);
	$args['order_type']   =  intval( $_POST['order_type']);
	$args['filter']       =  intval( $_POST['filter']);
	$args['thumb']        =  intval( $_POST['thumb']);
	$args               =  serialize( $args);	

	$sql = "insert into ".TABLEPRE."js (channelid, type, code_name, description, file_name, args, tpl, dateline) values ('$channelid', '$type', '$code_name', '$description', '$file_name','$args', '{$tpl}', '$dateline')";
	$id = qdb::Query( $sql, true);
	$js = qdb::queryFirst("select * from ".TABLEPRE."js where id = '{$id}' ");
	qbase::writetofile(A_P . "/templates/cache/" . substr($file_name, 0, strpos($file_name, '.')). '.php', stripslashes($tpl));
	qbase::get_object('event', 'js', array('action'=>'add', 'data'=>$js));
	adminLog("添加JS调用");
	qbase::showmsg( "Js添加成功","default","system.php?sys=js&channelid={$channelid}&channelselect={$channelselect}&action=manage"); 
}

$tpl = '<div class="rbox"><ul>
<!--{loop $_obj $val}-->
<li><a title="{$val[\'subject\']}" href="{$val[\'url\']}"><!--{echo qbase::substrs($val[\'subject\'], 30)}--></a></li>
<!--{/loop}-->
</ul></div>';
?>