<?php
if (empty($action)) {
	$allsettings =& getAllAccessSettings();
	$colspan = 4;
	print <<<EOT
	<SCRIPT LANGUAGE="JavaScript">
	<!--
	function checkAll(obj)
	{
		var form = obj.form;
		var ele = null;
		for (var i = 0 ; i < form.elements.length ; i++) {
			ele = form.elements[i];
			if ('checkbox' === ele.type.toLowerCase() && ele.name != 'checkall') {
				ele.checked = obj.checked;
			}
		}
	}
	function deleteSelectedSettings(form)
	{
		var ele = null;
		var hasselected = false;
		for (var i = 0 ; i < form.elements.length ; i++) {
			ele = form.elements[i];
			if ('checkbox' === ele.type.toLowerCase() && ele.name != 'checkall') {
				if (true == ele.checked) {
					hasselected = true;
					break;
				}
			}
		}
		if (false == hasselected) {
			alert('{$lang['tpl.str2']}');
			return false;
		}
		return true;
	}
	//-->
	</SCRIPT>
	<table border="0" cellspacing="0" cellpadding="0" align="center" class="tableborder">
	<form action="?action=deletesettings" method="post" onsubmit="return deleteSelectedSettings(this)">
		<tr>
			<td width="100%" class="tdtit" height="25" colspan="{$colspan}" style="text-indent:5px;">{$lang['tpl.str3']}</td>
		</tr>
		<tr>
			<td width="1%" class="forumrow" height="25"style="text-indent:5px;"><input type="checkbox" name="checkall" onclick="checkAll(this)"></td>
			<th width="20%" class="forumrow" height="25"style="text-indent:5px;">{$lang['tpl.str4']}</th>
			<th width="10%" class="forumrow" height="25"style="text-indent:5px;">{$lang['tpl.str5']}</th>
			<td width="*" class="forumrow" height="25"style="text-indent:5px;">&nbsp;</td>
		</tr>
EOT;
	if (!empty($allsettings) AND is_array($allsettings)) {
		foreach ($allsettings AS $index => $dbinfo) {
			$settings = unserialize($dbinfo['setting']);
			$isenable = (true === $settings['isenable'] ? '<font color="green">'.$lang['tpl.str6'].'</font>' :'<font color="red">'.$lang['tpl.str7'].'</font>');
			print <<<EOT
		<tr>
			<td class="forumrow1" height="25"style="text-indent:5px;"><input type="checkbox" name="settingsid[]" value="{$dbinfo['id']}"><input type="hidden" name="settingsname_{$dbinfo['id']}" value="{$settings['settings_name']}"></td>
			<td class="forumrow1" height="25"style="text-indent:5px;"><a href="?action=modify&amp;settingsid={$dbinfo['id']}">{$settings['settings_name']}</a></td>
			<td class="forumrow1" height="25"style="text-indent:5px;">{$isenable}</td>
			<td width="*" class="forumrow1" height="25"style="text-indent:5px;">&nbsp;</td>
		</tr>
EOT;
		}
	}
	print <<<EOT
		<tr>
			<td width="100%" class="forumrow" height="25" colspan="{$colspan}" style="text-indent:5px;text-align:center;"><input type="submit" value="{$lang['tpl.str8']}" class="button"></td>
		</tr>
	</form>
	</table>
EOT;
} elseif ('modify' === $action) {
	if (empty($subaction)) {
		if (is_numeric($settingsid) AND $settingsid > 0) {
			if ($settings =& getSettingsById($settingsid)) {
			} else {
				print <<<EOT
{$lang['tpl.str9']}
EOT;
				exit;
			}
		}
		if (empty($settings)) {
			$settings =& $_DV_FSETTINGS['audit_settings'];
			$settings['settings_name'] = $lang['tpl.str10'].(getSettingsCount()+1);
		}
	} else {
		$settings =& $_POST['submitsettings'];
		//processSubmitSettings($submitsettings);
		processSubmitSettings($settings);
		if ('addusergroup' === $subaction) {
			$settings['grade'][] = $_DV_FSETTINGS['audit_settings']['grade'][0];
		} elseif ('delusergroup' === $subaction) {
			unset($settings['grade']["{$deletegroupposition}"]);
		}
	}
	if (is_numeric($settingsid) AND $settingsid > 0) {
		$deleteauditsettings = ' | <a href="?action=deletesettings&amp;&amp;settingsid[]='.$settingsid.'">'.$lang['tpl.str11'].'</a>';
	} else {
		$deleteauditsettings = '';
	}
	print <<<EOT
	<SCRIPT LANGUAGE="JavaScript">
	<!--
		//?action=modify&amp;addusergroup=1&amp;settingsid={$settingsid}
	function addUserGroup()
	{
		var form = document.forms[0];
		form.elements['action'].value = 'modify';
		form.elements['subaction'].value = 'addusergroup';
		form.submit();
	}
	//?action=modify&amp;delusergroup=1&amp;settingsid={$settingsid}&amp;groupposition=
	function deleteUserGroup(groupposition)
	{
		var form = document.forms[0];
		form.elements['action'].value = 'modify';
		form.elements['subaction'].value = 'delusergroup';
		form.elements['deletegroupposition'].value = groupposition;
		form.submit();
	}
	//-->
	</SCRIPT>
EOT;
	$colspan = 2;
	if (!empty($settings)) {
		$settingsisenable = (true === $settings['isenable'] ? ' checked ' : '');
		$scope_newtopic = (true === $settings['scope']['newtopic'] ? ' checked ' : '');
		$scope_newreply = (true === $settings['scope']['newreply'] ? ' checked ' : '');
		$scope_reedit = (true === $settings['scope']['reedit'] ? ' checked ' : '');
		$formnameprev = 'submitsettings';
		print <<<EOT
	<table border="0" cellspacing="0" cellpadding="0" align="center" class="tableborder">
		<form action="?" method="post">
			<input type="hidden" name="action" value="save">
			<input type="hidden" name="subaction" value="save">
			<input type="hidden" name="settingsid" value="{$settingsid}">
			<input type="hidden" name="deletegroupposition" value="">
		<tr>
			<td width="100%" class="tdtit" height="25" colspan="{$colspan}" style="text-indent:5px;">{$lang['tpl.str10']}</td>
		</tr>
		<tr>
			<td class="forumrow" height="25" colspan="{$colspan}"><a href="javascript:void(addUserGroup())">{$lang['tpl.str13']}</a>{$deleteauditsettings}</td>
		</tr>
		<tr>
			<td class="forumrow" height="25" style="text-align:right;width:12%;"><b>{$lang['tpl.str14']}</b></td>
			<td class="forumrow" style="text-align:left;"><input type="text" name="{$formnameprev}[settings_name]" value="{$settings['settings_name']}" style="margin:3px;" size="45"/>&nbsp;&nbsp;<input type="checkbox" value="1" name="{$formnameprev}[isenable]" style="margin:4px 1px ;" {$settingsisenable}></input> {$lang['tpl.str15']}</td>
		</tr>
		<tr>
			<td class="forumrow" height="25" style="text-align:right;"><b>{$lang['tpl.str16']}</b></td>
			<td class="forumrow" style="text-align:left;">
				<input type="checkbox" value="1" name="{$formnameprev}[scope][newtopic]" {$scope_newtopic}></input>&nbsp;{$lang['tpl.str17']}&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="{$formnameprev}[scope][newreply]" {$scope_newreply}></input>&nbsp;{$lang['tpl.str42']}&nbsp;&nbsp;&nbsp;<input type="checkbox" value="1" name="{$formnameprev}[scope][reedit]" {$scope_reedit}></input>&nbsp;{$lang['tpl.str18']}
			</td>
		</tr>
EOT;
		if (!empty($settings['grade']) AND is_array($settings['grade'])) {
			foreach ($settings['grade'] AS $groupposition => $gradesettings) {
				$currusergroupid = $gradesettings['groupid'];
				$grouplist = getGroupListById($currusergroupid);
				$shield = (true === $gradesettings['shield'] ? ' checked ': '');
				$check_content = (true === $gradesettings['check_content'] ? ' checked ': '');
				$gradeisenable = (true === $gradesettings['isenable'] ? ' checked ' : '');
				print <<<EOT
		<tr>
			<td class="forumrow" height="25" style="text-align:right;"><b>{$lang['tpl.str19']}</b></td>
			<td class="forumrow" style="text-align:left;">
				<div class="li1" style="float:left;">
					<select name="{$formnameprev}[grade][{$groupposition}][groupid]" style="margin:3px;">{$grouplist}</select>
				</div>
				<div style="float:left;"><input type="checkbox" value="1" name="{$formnameprev}[grade][{$groupposition}][isenable]" style="margin:4px 1px ;" {$gradeisenable}></input> 
				</div>
				<div style="float:left; padding: 0px 10px;">{$lang['tpl.str20']}
				</div>
				<div style="float:left; padding: 0px 10px;"><a href="javascript:void(deleteUserGroup({$groupposition}))">{$lang['tpl.str21']}</a>
				</div>
			</td>
		</tr>
		<tr>
			<td class="forumrow" height="25" style="text-align:right;"><b>{$lang['tpl.str22']}</b></td>
			<td class="forumrow" style="text-align:left;">
				<div class="li1" style="float:left;">
					<div style="float:left;width:80px;text-align : right;">{$lang['tpl.str23']}
					</div>
					<div style="float:left;"><input type="text" name="{$formnameprev}[grade][{$groupposition}][topic_lessthan]" value="{$gradesettings['topic_lessthan']}" style="margin:3px;" size="4"/>
					</div>
					<div style="float:left; padding: 0px 10px;">{$lang['tpl.str24']}&nbsp;&nbsp;(<font color="red">{$lang['tpl.str25']}</font>)
					</div>
					<!--
					<div style="float:left;"><input type="checkbox" value="1" name="setting_{$position_1}_checkuser_{position()}_usertopic_use" style="margin:4px 1px ;"><xsl:if test="usertopic/@use=1"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if></input> </div>
					<div style="float:left; padding: 0px 10px;">{$lang['tpl.str20']}
					</div>
					-->
				</div>
			</td>
		</tr>
		<tr>
			<td class="forumrow" height="25" style="text-align:right;">&nbsp;</td>
			<td class="forumrow" style="text-align:left;">
				<div style="float:left;width:80px;text-align : right;">{$lang['tpl.str26']}
				</div>
				<div style="float:left;"><input type="text" name="{$formnameprev}[grade][{$groupposition}][post_lessthan]" value="{$gradesettings['post_lessthan']}" style="margin:3px;" size="4"/>
				</div>
				<div style="float:left; padding: 0px 10px;">{$lang['tpl.str24']}&nbsp;&nbsp;(<font color="red">{$lang['tpl.str25']}</font>)
				</div>
				<!--
				<div style="float:left;"><input type="checkbox" value="1" name="setting_{$position_1}_checkuser_{position()}_userpost_use" style="margin:4px 1px ;"><xsl:if test="userpost/@use=1"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if></input> </div>
				<div style="float:left; padding: 0px 10px;">{$lang['tpl.str20']}
				</div>
				-->
			</td>
		</tr>
		<tr>
			<td class="forumrow" height="25" style="text-align:right;">&nbsp;</td>
			<td class="forumrow" style="text-align:left;">
				<div style="float:left;width:80px;text-align : right;">{$lang['tpl.str27']}
				</div>
				<div style="float:left;"><input type="text" name="{$formnameprev}[grade][{$groupposition}][register_lessthan]" value="{$gradesettings['register_lessthan']}" style="margin:3px;" size="4"/>
				</div>
				<div style="float:left;padding: 0px 10px;">{$lang['tpl.str28']}
				</div>
				<!--
				<div style="float:left;"><input type="checkbox" value="1" name="setting_{$position_1}_checkuser_{position()}_regdate_use" style="margin:4px 1px ;"><xsl:if test="regdate/@use=1"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if></input> </div>
				<div style="float:left; padding: 0px 10px;">{$lang['tpl.str20']}
				</div>
				-->
			</td>
		</tr>
		<tr>
			<td class="forumrow" height="25" style="text-align:right;">&nbsp;</td>
			<td class="forumrow" style="text-align:left;">
				<div class="li1" style="float:left;">
					<div style="float:left;width:80px;text-align : right;">{$lang['tpl.str29']}
					</div>
					<div style="float:left;"><input type="text" name="{$formnameprev}[grade][{$groupposition}][delete_morethan]" value="{$gradesettings['delete_morethan']}" style="margin:3px;" size="4"/>
					</div>
					<div style="float:left; padding: 0px 10px;">{$lang['tpl.str43']}</font>)
					</div>
					<!--
					<div style="float:left;"><input type="checkbox" value="1" name="setting_{$position_1}_checkuser_{position()}_userdel_use" style="margin:4px 1px ;"><xsl:if test="userdel/@use=1"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if></input> </div>
					<div style="float:left; padding: 0px 10px;">{$lang['tpl.str20']}
					</div>
					-->
				</div>
			</td>
		</tr>
		<tr>
			<td class="forumrow" height="25" style="text-align:right;">&nbsp;</td>
			<td class="forumrow" style="text-align:left;">
				<div class="li1" style="float:left;">
					<div style="float:left;width:120px;text-align : right;">{$lang['tpl.str30']}
					</div>
					<div style="float:left;"><input type="checkbox" value="1" name="{$formnameprev}[grade][{$groupposition}][shield]" style="margin:4px 1px ;" {$shield}></input> </div>
					<div style="float:left; padding: 0px 10px;">{$lang['tpl.str20']}</div>
				</div>
			</td>
		</tr>
		<tr>
			<td class="forumrow" height="25" style="text-align:right;">&nbsp;</td>
			<td class="forumrow" style="text-align:left;">
				<div class="li1" style="float:left;">
					<div style="float:left;width:120px;text-align : right;">{$lang['tpl.str31']}
					</div>
					<div style="float:left;"><input type="checkbox" value="1" name="{$formnameprev}[grade][{$groupposition}][check_content]" style="margin:4px 1px ;" {$check_content}></input> </div>
					<div style="float:left; padding: 0px 10px;">{$lang['tpl.str20']}
					</div>
				</div>
			</td>
		</tr>
EOT;
			}
		}
		$pic_audit = (true === $settings['check_content_misc']['pic_audit'] ? ' checked ' : '');
		$link_audit = (true === $settings['check_content_misc']['link_audit'] ? ' checked ' : '');
		$flash_audit = (true === $settings['check_content_misc']['flash_audit'] ? ' checked ' : '');
		$media_audit = (true === $settings['check_content_misc']['media_audit'] ? ' checked ' : '');
		$realplayer_audit = (true === $settings['check_content_misc']['realplayer_audit'] ? ' checked ' : '');
		if (is_array($settings['sensitive_character_list'])) {
			$sensitive_character_list = implode("\r\n", $settings['sensitive_character_list']);
		} else {
			$sensitive_character_list = '';
		}
		if (is_array($settings['exempt_user_list'])) {
			$exempt_user_list = implode("\r\n", $settings['exempt_user_list']);
		} else {
			$exempt_user_list = '';
		}
		print <<<EOT
		<tr>
			<td class="forumrow" height="25" style="text-align:right;"><b>{$lang['tpl.str32']}</b></td>
			<td class="forumrow" style="text-align:left;">
				<div class="li1" style="float:left;width:80px;text-align : right;">{$lang['tpl.str33']}
				</div>
				<div style="float:left;"><input type="checkbox" value="1" name="{$formnameprev}[check_content_misc][pic_audit]" style="margin:4px 1px ;" {$pic_audit}></input> 
				</div>
				<div style="float:left; padding: 0px 10px;">{$lang['tpl.str20']}
				</div>
			</td>
		</tr>
		<tr>
			<td class="forumrow" height="25" style="text-align:right;">&nbsp;</td>
			<td class="forumrow" style="text-align:left;">
				<div class="li1" style="float:left;width:80px;text-align : right;">{$lang['tpl.str34']}
				</div>
				<div style="float:left;"><input type="checkbox" value="1" name="{$formnameprev}[check_content_misc][link_audit]" style="margin:4px 1px ;" {$link_audit}></input> 
				</div>
				<div style="float:left; padding: 0px 10px;">{$lang['tpl.str20']}
				</div>
			</td>
		</tr>
		<tr>
			<td class="forumrow" height="25" style="text-align:right;">&nbsp;</td>
			<td class="forumrow" style="text-align:left;">
				<div class="li1" style="float:left;width:80px;text-align : right;">{$lang['tpl.str35']}
				</div>
				<div style="float:left;"><input type="checkbox" value="1" name="{$formnameprev}[check_content_misc][flash_audit]" style="margin:4px 1px ;" {$flash_audit}></input> 
				</div>
				<div style="float:left; padding: 0px 10px;">{$lang['tpl.str20']}
				</div>
			</td>
		</tr>
		<tr>
			<td class="forumrow" height="25" style="text-align:right;">&nbsp;</td>
			<td class="forumrow" style="text-align:left;">
				<div class="li1" style="float:left;width:80px;text-align : right;">{$lang['tpl.str36']}
				</div>
				<div style="float:left;"><input type="checkbox" value="1" name="{$formnameprev}[check_content_misc][media_audit]" style="margin:4px 1px ;" {$media_audit}></input> 
				</div>
				<div style="float:left; padding: 0px 10px;">{$lang['tpl.str20']}
				</div>
			</td>
		</tr>
		<tr>
			<td class="forumrow" height="25" style="text-align:right;">&nbsp;</td>
			<td class="forumrow" style="text-align:left;">
				<div class="li1" style="float:left;width:110px;text-align : right;">{$lang['tpl.str37']}
				</div>
				<div style="float:left;"><input type="checkbox" value="1" name="{$formnameprev}[check_content_misc][realplayer_audit]" style="margin:4px 1px ;" {$realplayer_audit}></input> 
				</div>
				<div style="float:left; padding: 0px 10px;">{$lang['tpl.str20']}
				</div>
			</td>
		</tr>
		<tr>
			<td valign="top" class="forumrow" height="25" style="text-align:right;"><b>{$lang['tpl.str38']}</b></td>
			<td class="forumrow" style="text-align:left;">
				<div class="li1" style="float:left;text-align : right;height:280px;"><textarea name="{$formnameprev}[sensitive_character_list]" rows="17" cols="60" style="margin:10px;">{$sensitive_character_list}</textarea>
				</div>
			</td>
		</tr>
		<tr>
			<td valign="top" class="forumrow" height="25" style="text-align:right;"><b>{$lang['tpl.str39']}</b></td>
			<td class="forumrow" style="text-align:left;">
				<div class="li1" style="float:left;text-align : right;height:280px;"><textarea name="{$formnameprev}[exempt_user_list]" rows="17" cols="60" style="margin:10px;">{$exempt_user_list}</textarea>
				</div>
			</td>
		</tr>
EOT;
		print <<<EOT
	</table>
EOT;
	}
	print <<<EOT
		<div class="mainbar1" style="line-height:28px;height:28px;text-align:center;">
			<input type="submit" class="button" value="{$lang['tpl.str40']}" style="margin:3px 10px;" />
		</div>
	</form>
EOT;
} elseif ('deletesettings' === $action) {//ÅúÁ¿É¾³ýÉóºËÉèÖÃ
	print <<<EOT
	<table border="0" cellspacing="1" cellpadding="1" align="center" class="tableborder">
		<tr>
			<td width="100%" class="tit1" height="25" colspan="{$colspan}" style="text-indent:5px;"><div style="float:left;text-indent:5px;">{$lang['tpl.str44']}</div>{$lang['tpl.str41']}</td>
		</tr>
EOT;
	foreach ($actionresult AS $result) {
		print <<<EOT
		<tr>
			<td width="100%" class="forumrow" height="25" colspan="{$colspan}" style="text-indent:5px;"><div style="float:left;text-indent:5px;">{$result}</td>
		</tr>
EOT;
	}
	print <<<EOT
	</table>
EOT;
}

function getGroupListById($groupid)
{
	static $grouplist = '';
	if (empty($grouplist)) {
		$allgroups =& getUserGroupInfo(0);
		if (!empty($allgroups) AND is_array($allgroups)) {
			foreach ($allgroups AS $usergroup ) {
				if ($usergroup['usergroupid'] == $groupid) {
					$selected = ' selected="selected" ';
				} else {
					$selected = '';
				}
				$grouplist .= '<option value="'.$usergroup['usergroupid'].'" '.$selected.'>'.$usergroup['usertitle'].'</option>';
			}
		}
	} else {
		$grouplist = str_replace(array(' selected ', 'value="'.$groupid.'"'), array('', 'value="'.$groupid.'" selected '), $grouplist);
	}
	return $grouplist;
}

?>