<?php
if(!defined('MOD'))  die("access die");
if($admin_info['groupid'] > 3 ) qbase::purviewCheckDie();
if(empty($channel[$channelid])) qbase::showmsg("error request");
purviewCheck( $channelid, 'channel');
if($_POST['update']==1)
{
	$param = array();
	$param['channelname']=clearSpecialChars(trim($_POST['channelname']));
	$param['channeltitle']=clearSpecialChars(trim($_POST['channeltitle']));
	$param['channelitem']=clearSpecialChars(trim($_POST['channelitem']));
	$param['channeldir']   = clearSpecialChars(trim($_POST['channeldir']));
	$param['show']=intval($_POST['show']);
	$param['url']=trim($_POST['url']);
	$param['is_html']=intval($_POST['is_html']);
	$param['close_index']         = intval($_POST['close_index']);
	$param['is_html_content']=intval($_POST['is_html_content']);
	$param['is_auto']=intval($_POST['is_auto']);
	$param['html_size']=intval($_POST['html_size']);
	$param['CidCacheTime']=intval($_POST['CidCacheTime']);
	$param['ShowCacheTime']=intval($_POST['ShowCacheTime']);
	$param['html_date_path']=intval($_POST['html_date_path']);
	$param['upload_date_path']=intval($_POST['upload_date_path']);
	$param['html_type']=trim($_POST['html_type']);
	$param['html_pre']=trim($_POST['html_pre']);
	$param['allow_upload']=intval($_POST['allow_upload']);
	$param['upload_size']=intval($_POST['upload_size']);
	$param['upload_type']=trim($_POST['upload_type']);
	$param['coment_pass']=intval($_POST['coment_pass']);
	$param['pic_width']=intval($_POST['pic_width']);
	$param['pic_height']=intval($_POST['pic_height']);
	$param['pic_cut']=intval($_POST['pic_cut']);
	$param['water']=intval($_POST['water']);
	$param['water_position']=intval($_POST['water_position']);
	$param['water_size']=intval($_POST['water_size']);
	$param['water_color']=trim($_POST['water_color']);
	$param['water_word']=trim($_POST['water_word']);
	$param['target']=trim($_POST['target']);
	$param['description']=trim($_POST['description']);
	$param['skin']=trim($_POST['skin']);
	$param['index_template']	=	trim($_POST['index_template']);
	$param['displayorder']=intval($_POST['displayorder']);
	$param['domain']=trim($_POST['domain']);

	$param['show_special']=intval($_POST['show_special']);
	$param['show_vote']=intval($_POST['show_vote']);
	$param['show_money']=intval($_POST['show_money']);
	$param['show_related']=intval($_POST['show_related']);

	$is_channeliname=qdb::QueryAlone("select channelname from ".TABLEPRE."channel where channelname='{$param['channelname']}' and channelid != '{$channelid}' ");
	$is_channeldir=qdb::QueryAlone("select channeldir from ".TABLEPRE."channel where channeldir='{$param['channeldir']}' and channelid != '{$channelid}' ");

	if($channel[$channelid]['link']){
		$item = array();
		$field = array('channelname','displayorder','show','link','url','target');
		foreach($field as $val){
			$item[$val] = $param[$val];
		}
		$sql = qbase::createSql(TABLEPRE.'Channel', $item, 'update') . " where channelid = {$channelid} ";
		qdb::Query($sql);
	}else{
		if($is_channeliname || $is_channeldir) {
			qbase::showmsg('修改失败：与现有频道的名称或者目录重合');
		}
		if($param['index_tempalte'] && !is_file(R_P . '/templates/' . $param['index_tempalte'])) qbase::showmsg("出错了，频道首页模板不存在");
		$sql = qbase::createSql(TABLEPRE.'channel', $param, 'update') . " where channelid = {$channelid} ";
		qdb::Query($sql);
	}

	commonCache();
	$wait = 5;

	qbase::showmsg("频道修改成功<script>parent.document.getElementById('menu').src = \"index.php?action=left&d=\" + (new Date()).toString();</script>",'default',"system.php?sys=channel&action=edit&channelid={$channelid}");
}
else
{
	TemplateSelect();
	unset($_MODULE);
	$result = qdb::Query("select * from ".TABLEPRE."module");
	while( $l = qdb::fetchArray($result))
	{
		$_MODULE[] = $l;
	}
	$channel=qdb::QueryFirst("select * from ".TABLEPRE."channel where channelid='".intval($_GET[channelid])."'");

}
?>
