<?php
(!defined('M_COM') || !defined('M_ADMIN')) && exit('No Permission');
if(!submitcheck('bmtagadd') && !submitcheck('bmtagsdetail') && !submitcheck('bmtagcode')){
	templatebox(lang('tagtemplate'),'mtagnew[template]',empty($mtag['template']) ? '' : $mtag['template'],10,110);
	trbasic(lang('arr_pre'),'mtagnew[setting][val]',empty($mtag['setting']['val']) ? 'v' : $mtag['setting']['val'],'text',lang('agarr_pre'));
	trbasic(lang('list_result'),'mtagnew[setting][limits]',empty($mtag['setting']['limits']) ? 10 : $mtag['setting']['limits']);
	tabfooter();

	tabheader(lang('filter0_set'));
	foreach($grouptypes as $gtid => $grouptype){
		$ugidsarr = array('0' => lang('nolimitusergroup')) + ugidsarr($grouptype['gtid']);
		trbasic("$grouptype[cname]".lang('filter0'),'mtagnew[setting][ugid'.$gtid.']',makeoption($ugidsarr,empty($mtag['setting']['ugid'.$gtid]) ? 0 : $mtag['setting']['ugid'.$gtid]),'select');
	}
	$chsourcearr = array('0' => lang('nolimitchannel'),'1' => lang('active_channel'),'2' => lang('handpoint'),);
	sourcemodule(lang('member_channel_limited'),
				'mtagnew[setting][chsource]',
				$chsourcearr,
				empty($mtag['setting']['chsource']) ? '' : $mtag['setting']['chsource'],
				'2',
				'mtagnew[setting][chids][]',
				mchidsarr(),
				!empty($mtag['setting']['chids']) ? explode(',',$mtag['setting']['chids']) : array()
				);
	tabfooter();

	tabheader(lang('catas_relate_setting')."&nbsp;&nbsp;&nbsp;&nbsp;<input class=\"checkbox\" type=\"checkbox\" name=\"viewdetail\" value=\"1\" onclick=\"alterview('catasfilter')\">".lang('view'));
	echo "<tbody id=\"catasfilter\" style=\"display: none;\">";
	$sourcearr = array('0' => lang('nolimitcatas'),'1' => lang('handpoint'),'2' => lang('activecatas'),);
	$catalogs = &$acatalogs;
	sourcemodule(lang('relate_catalog_limited')."&nbsp;&nbsp;&nbsp;<input class=\"checkbox\" type=\"checkbox\" name=\"mtagnew[setting][caidson]\" value=\"1\"".(empty($mtag['setting']['caidson']) ? "" : " checked").">".lang('include_son'),
		'mtagnew[setting][casource]',
		$sourcearr,
		empty($mtag['setting']['casource']) ? '0' : $mtag['setting']['casource'],
		'1',
		'mtagnew[setting][caids][]',
		caidsarr(),
		empty($mtag['setting']['caids']) ? array() : explode(',',$mtag['setting']['caids'])
		);
	foreach($cotypes as $k => $cotype){
		if(!$cotype['self_reg']){
			sourcemodule(lang('colasslimit')."-$cotype[cname]"."&nbsp;&nbsp;&nbsp;<input class=\"checkbox\" type=\"checkbox\" name=\"mtagnew[setting][ccidson$k]\" value=\"1\"".(empty($mtag['setting']['ccidson'.$k]) ? "" : " checked").">".lang('include_son'),
			"mtagnew[setting][cosource$k]",
			$sourcearr,
			empty($mtag['setting']['cosource'.$k]) ? '0' : $mtag['setting']['cosource'.$k],
			'1',
			"mtagnew[setting][ccids$k][]",
			ccidsarr($k),
			empty($mtag['setting']['ccids'.$k]) ? array() : explode(',',$mtag['setting']['ccids'.$k])
			);
		}
	}
	echo "</tbody>";
	tabfooter();

	$orderbyarr = array(
		'' => lang('default_order'),
		'm.regdate_desc' => lang('register_time_desc1'),
		'm.regdate_asc' => lang('register_time_asc1'),
		'm.onlinetime_desc' => lang('online_time_desc1'),
		'm.clicks_desc' => lang('clicks_desc1'),
		's.msclicks_desc' => lang('msclicks_desc1'),
		's.checks_desc' => lang('issue_archive_amount_desc1'),
		's.comments_desc' => lang('comments_desc1'),
		's.purchases_desc' => lang('purchase_amount_desc1'),
		's.answers_desc' => lang('answer_amount_desc1'),
		's.credits_desc' => lang('credit_desc1'),
	);
	tabheader(lang('list_order')."&nbsp;&nbsp;&nbsp;&nbsp;<input class=\"checkbox\" type=\"checkbox\" name=\"viewdetail\" value=\"1\" onclick=\"alterview('ordersetting')\">".lang('view'));
	echo "<tbody id=\"ordersetting\" style=\"display: none;\">";
	trbasic(lang('order'),'mtagnew[setting][orderby]',makeoption($orderbyarr,empty($mtag['setting']['orderby']) ? '' : $mtag['setting']['orderby']),'select');
	$createurl = "&nbsp; >><a href=\"?entry=liststr&tclass=members\" target=\"_blank\">".lang('create_str')."</a>";
	trbasic(lang('order_str').$createurl,'mtagnew[setting][orderstr]',empty($mtag['setting']['orderstr']) ? '' : stripslashes($mtag['setting']['orderstr']),'textarea');
	echo "</tbody>";
	tabfooter();

	tabheader(lang('adv_options')."&nbsp; <input class=\"checkbox\" type=\"checkbox\" name=\"viewdetail\" value=\"1\" onclick=\"alterview('advancedfilter')\">".lang('view'));
	echo "<tbody id=\"advancedfilter\" style=\"display: none;\">";
	trbasic(lang('view_ch_field'),'mtagnew[setting][detail]',empty($mtag['setting']['detail']) ? 0 : $mtag['setting']['detail'],'radio',lang('agtagdetail_yes'));
	trbasic(lang('clicks_gt'),'mtagnew[setting][clicks]',!isset($mtag['setting']['clicks']) ? '' : $mtag['setting']['clicks']);
	trbasic(lang('online_time'),'mtagnew[setting][onlinetime]',!isset($mtag['setting']['onlinetime']) ? '' : $mtag['setting']['onlinetime']);
	trbasic(lang('msclicks1'),'mtagnew[setting][msclicks]',!isset($mtag['setting']['msclicks']) ? '' : $mtag['setting']['msclicks']);
	trbasic(lang('issue_archive_amount'),'mtagnew[setting][checks]',!isset($mtag['setting']['checks']) ? '' : $mtag['setting']['checks']);
	trbasic(lang('comments_gt'),'mtagnew[setting][comments]',!isset($mtag['setting']['comments']) ? '' : $mtag['setting']['comments']);
	trbasic(lang('purchase_goods_amount'),'mtagnew[setting][purchases]',!isset($mtag['setting']['purchases']) ? '' : $mtag['setting']['purchases']);
	trbasic(lang('answer_amount'),'mtagnew[setting][answers]',!isset($mtag['setting']['answers']) ? '' : $mtag['setting']['answers']);
	trbasic(lang('answer_credit'),'mtagnew[setting][credits]',!isset($mtag['setting']['credits']) ? '' : $mtag['setting']['credits']);
	trbasic(lang('indays'),'mtagnew[setting][indays]',!isset($mtag['setting']['indays']) ? '' : $mtag['setting']['indays']);
	trbasic(lang('outdays'),'mtagnew[setting][outdays]',!isset($mtag['setting']['outdays']) ? '' : $mtag['setting']['outdays']);
	$createurl = "&nbsp; >><a href=\"?entry=liststr&tclass=members\" target=\"_blank\">".lang('create_str')."</a>";
	trbasic(lang('filter_sql_str').$createurl,'mtagnew[setting][wherestr]',empty($mtag['setting']['wherestr']) ? '' : $mtag['setting']['wherestr'],'textarea');
	trbasic(lang('tagjspick'),'mtagnew[setting][js]',empty($mtag['setting']['js']) ? 0 : $mtag['setting']['js'],'radio');
	echo "</tbody>";
	tabfooter();
}else{
	if(empty($mtagnew['template'])){
		if(!submitcheck('bmtagcode')){
			amessage('input_tag_tpl',M_REFERER); 
		}else $errormsg = lang('input_tag_tpl');//生成代码出错的提示信息
	}
	$mtagnew['setting']['limits'] = empty($mtagnew['setting']['limits']) ? 10 : max(0,intval($mtagnew['setting']['limits']));
	$mtagnew['setting']['orderstr'] = empty($mtagnew['setting']['orderstr']) ? '' : trim($mtagnew['setting']['orderstr']);
	$mtagnew['setting']['wherestr'] = empty($mtagnew['setting']['wherestr']) ? '' : stripslashes(trim($mtagnew['setting']['wherestr']));

	//数组参数的处理
	$idvars = array('chids','caids',);
	foreach($cotypes as $k => $cotype) if(!$cotype['self_reg']) $idvars[] = 'ccids'.$k;
	foreach($idvars as $k){
		if(empty($mtagnew['setting'][$k])){
			unset($mtagnew['setting'][$k]);
		}else $mtagnew['setting'][$k] = implode(',',$mtagnew['setting'][$k]);
	}

	foreach(array('clicks','comments','indays','outdays','onlinetime','msclicks','checks','purchases','answers','credits',) as $k){
		$mtagnew['setting'][$k] = trim($mtagnew['setting'][$k]);
		if($mtagnew['setting'][$k] == ''){
			unset($mtagnew['setting'][$k]);
		}else{
			$mtagnew['setting'][$k] = max(0,intval($mtagnew['setting'][$k]));
		}
	}
}
?>
