<?php
if(!defined('R_P')) die("access die");
purviewCheck( $channelid, 'channel');
if (isset($_POST['myFormAc']) && $_POST['myFormAc'] == 'update') {

	$temp = qdb::fetchAll("show fields from ".TABLEPRE."{$mod}_{$channelid} ");
	$fields = $fields_type = array();
	foreach($temp as $val){
		$fields[] = $val['Field'];
		$fields_type[$val['Field']] = substr($val['Type'], 0, 3);
	}

	$param = array();
	if($_POST['check_keyword']){
		$param[] = 'check_keyword';
		$rset[]=" keyword='". trim($_POST['keyword'])."'";
	}
	if(intval($_SET['modify_views']) > 0 && $_POST['check_views']){
		$param[] = 'check_views';
		$rset[]=" views='". intval($_POST['views'])."'";
		$rset[]=" dviews='". intval($_POST['dview'])."'";
		$rset[]=" wviews='". intval($_POST['wview'])."'";
		$rset[]=" mviews='". intval($_POST['mview'])."'";
		$rset[]=" viewtime='". $_SERVER['REQUEST_TIME']."'";
	}
	if($_POST['check_stars']){
		$param[] = 'check_stars';
		$rset[]=" stars='". intval($_POST['stars'])."'";
	}
	if($_POST['check_status']){
		$param[] = 'check_status';
		$rset[]=" status='". intval($_POST['status'])."'";
	}
	if($_POST['check_is_comend']){
		$param[] = 'check_is_comend';
		$rset[]=" is_comend='". intval($_POST['is_comend'])."'";
	}
	if($_POST['check_nocoment']){
		$param[] = 'check_nocoment';
		$rset[]=" nocoment='". intval($_POST['nocoment'])."'";
	}
	if($_POST['check_filter']){
		$param[] = 'check_filter';
		if(isset($_POST['filter']) && is_array($_POST['filter'])){
			$temp = implode(',',  $_POST['filter']);
		}else{
			$temp = '0';
		}
		$rset[]=" filter='". $temp."'";
	}
	foreach($_POST as $key=>$val){
		if(substr($key, 0, 6) != 'check_' || in_array($key, $param)) continue;
		$field = substr($key, 6);
		if(!isset($_POST[$field]) || !in_array($field , $fields) || !isset($fields_type[$field])) continue;
		if($fields_type[$field] == 'int') $_POST[$field] = intval($_POST[$field]);
		$rset[]=" {$field}='{$_POST[$field]}'";
	}

	if(count($rset)>0){
		$rset[]=" edit_time = '{$_SERVER['REQUEST_TIME']}' ";
		$rset=implode(",",$rset);
	}else{
		qbase::showmsg("请选择需要批量操作的选项");
	}
	if($_POST['choose']==0){
		if( $_POST['id']){
			if( count($rset) > 0){
				$sql="update ".TABLEPRE."{$mod}_{$channelid} set ".$rset." where id IN(".str_replace("，",",",$_POST['id']).")";
				qdb::Query($sql);
			}
		}else{
			qbase::showmsg("没有添加要设置的{$channeltitle}的ID");
		}
	}else{
		if( is_array($_POST['cid']) && count($_POST['cid']) > 0){
			while(list($key,$val)=each($_POST['cid'])){
				$arrchildid = qdb::QueryAlone("select arrchildid from ".TABLEPRE."acategory where cid='$val'");
				if($arrchildid) qdb::Query("update ".TABLEPRE."{$mod}_{$channelid} set ".$rset." where cid IN(".$arrchildid.")");
			}
		}else{
			qbase::showmsg("没有选择要设置的栏目");
		}
	}
	adminLog("批量修改文档");
	qbase::showmsg("批量设置成功",'default',"system.php?sys=module&mod={$mod}&channelid={$channelid}&action=setvalue");
}else{
	include qbase::template($path . 'setvalue');
}
?>