<?php
if (!defined('MOD')) die("access die");
$cms = qbase::get_object('qmecmsAcategory', $channelid);
if ($_POST['myFormAc'] == 'update'){
	$param['channelid'] = $channelid;
	$param['cupid'] = intval($_POST['cupid']);
	$param['title']  = trim($_POST['title']);
	$param['description']  = qbase::substrs(qbase::trimn($_POST['description']), 250);
	$param['keyword']  = qbase::substrs(qbase::trimn($_POST['keyword']), 250);
	$param['dir']  = qbase::trimn($_POST['dir']) ? createCategoryDir(qbase::trimn($_POST['dir'])) : createCategoryDir($param['title']);
	$param['displayorder']  = intval($_POST['displayorder']);
	$param['showphp']     = trim($_POST['showphp']);
	$param['showmessage']     = trim($_POST['showmessage']);
	$param['pic']     = trim($_POST['pic']);
	$param['pur_browse']  = intval( $_POST['pur_browse']);
	$param['pur_usergroup']  = empty($_POST['pur_usergroup']) ? '' : implode(',', $_POST['pur_usergroup']);
	if($param['pur_browse'] == 2 && empty($param['pur_usergroup'])) qbase::showmsg("如果选择了会员栏目，必须选择相应会员组");
	else if($param['pur_browse'] != 2) $param['pur_usergroup'] = '';
	$param['num']         = intval( $_POST['num']);
	$param['c_allow']  = intval( $_POST['c_allow']);
	$param['c_check']  = intval( $_POST['c_check']);
	$param['c_post']  = intval( $_POST['c_post']);
	$param['html']  = intval( $_POST['html']);
	$param['cfilename'] = formatFileName($_POST['cfilename']);
	$param['category_html']  = intval( $_POST['category_html']);

	$more_title = trim($_POST['more_title']);
	if(empty($more_title)){
		if ($param['title']  == "") qbase::showmsg($channeltitle . "分类名不能为空");
		if ($param['dir'] == "") qbase::showmsg($channeltitle . "分类目录没有添加");
		$sql = qbase::createSql(TABLEPRE.'acategory', $param , 'insert');
		$cid = qdb::Query($sql, true);
		$cms->extend_update($cid);
		adminLog("添加栏目分类{$param['title']}");
	}else{
		$more_title = explode("\n", $more_title);
		foreach($more_title as $val){
			$sp = explode('|', $val);
			$param['title'] = trim($sp[0]);
			if(empty($param['title'])) continue;
			$param['dir']  = qbase::trimn($sp[1]) ? createCategoryDir(qbase::trimn($sp[1])) : createCategoryDir($sp[1]);
			if(empty($param['dir'])) continue;
			$sql = qbase::createSql(TABLEPRE.'acategory', $param , 'insert');
			$cid = qdb::Query($sql, true);
			$cms->extend_update($cid);
		}
	}
	qbase::get_object('category', $channelid)->update();
	commonCache();
	qbase::showmsg($channeltitle . "分类添加完成", 'default', "system.php?sys=acategory&channelid=" . $channelid . "&action=add&cid=" . $cupid);
}else{
	$ppcid = intval($_GET['cid']);
	$strall = str_replace("<option value=\"{$ppcid}-", "<option selected value=\"{$ppcid}-", $menuTree);
}
?>