<?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设置该目录权限");

	$id          = intval( $_POST['id']);
	$type        = intval( $_GET['type']);
	$code_name   = trim( $_POST['code_name']);
	$description = trim( $_POST['description']);
	$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         = "update ".TABLEPRE."js set type='$type', code_name='$code_name', description='$description',  tpl='$tpl', args='$args' where id='$id'";
	qdb::Query( $sql);
	$js = qdb::queryFirst("select * from ".TABLEPRE."js where id ='{$id}' ");
	qbase::writetofile(A_P . "/templates/cache/" . substr($js['file_name'], 0, strpos($js['file_name'], '.')). '.php', stripslashes($tpl));
	qbase::get_object('event', 'js', array('action'=>'edit', 'data'=>$js));
	adminLog("修改JS调用");
	qbase::showmsg( "Js修改成功,转入JS文件生成中","default","system.php?sys=js&channelid={$channelid}&channelselect={$channelselect}&action=cache&id={$id}");
}
else
{
	$id = intval( $_GET[id]);
	$js = qdb::QueryFirst( "select * from ".TABLEPRE."js where id='$id'");
	$type = $js['type'];
	extract( unserialize( $js[args]));
	$strall   = str_replace("value=\"{$cid}-", " selected value=\"{$cid}-", $menuTree);
}
?>