function category_table()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $webfilter = new webfilter_rules();
    $t = $_GET["t"];
    $new_group = $tpl->javascript_parse_text("{new_group}");
    $groups = $tpl->_ENGINE_parse_body("{groups2}");
    $TimeSpace = $webfilter->TimeToText(unserialize(base64_decode($ligne["TimeSpace"])));
    $EnableWebProxyStatsAppliance = $sock->GET_INFO("EnableWebProxyStatsAppliance");
    if (!is_numeric($EnableWebProxyStatsAppliance)) {
        $EnableWebProxyStatsAppliance = 0;
    }
    $groups = $tpl->_ENGINE_parse_body("{groups}");
    $categories = $tpl->_ENGINE_parse_body("{categories}");
    $whitelists = $tpl->_ENGINE_parse_body("{whitelists}");
    $delete = $tpl->_ENGINE_parse_body("{delete}");
    $action_delete_group = $tpl->javascript_parse_text("{action_delete_group}");
    $compile_rules = $tpl->_ENGINE_parse_body("{compile_rules}");
    $service_events = $tpl->_ENGINE_parse_body("{service_events}");
    $global_parameters = $tpl->_ENGINE_parse_body("{global_parameters}");
    $ldap_parameters = $tpl->_ENGINE_parse_body("{ldap_parameters2}");
    $config_file = $tpl->_ENGINE_parse_body("{config_file}");
    $categories_group = $tpl->_ENGINE_parse_body("{categories_groups}");
    $enabled = $tpl->javascript_parse_text("{enabled}");
    $tSource = $_GET["tSource"];
    $tt = time();
    $error_ldap = null;
    $MainRuleID = $_GET["RULEID"];
    $title = null;
    if (is_numeric($MainRuleID) > 0) {
        $name = "{default}";
        $white = $tpl->_ENGINE_parse_body("{blacklist}");
        if ($_GET["modeblk"] == 1) {
            $white = $tpl->_ENGINE_parse_body("{whitelist}");
        }
        if ($MainRuleID > 0) {
            $q = new mysql_squid_builder();
            $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT groupname FROM webfilter_rules WHERE ID={$MainRuleID}"));
            $title = $tpl->javascript_parse_text("{rule}") . " " . utf8_encode($ligne["groupname"]) . " | " . $tpl->javascript_parse_text("{$white}");
        }
    }
    $table_size = 670;
    $group_size = 445;
    if (is_numeric($_GET["table-size"])) {
        $table_size = $_GET["table-size"];
    }
    if (is_numeric($_GET["group-size"])) {
        $group_size = $_GET["group-size"];
    }
    $buttons = "\n\tbuttons : [\n\t{name: '{$new_group}', bclass: 'add', onpress : AddCategoryGroup{$tt}},\n\t{name: '{$compile_rules}', bclass: 'Reconf', onpress : CompileUfdbGuardRules},\n\t{name: 'Sync', bclass: 'Reload', onpress : Sync{$t}},\n\t],";
    //{display: ' ', name : 'dup', width :31, sortable : false, align: 'center'},
    $html = "\n<div>\n{$error_ldap}\n<table class='flexRT{$tt}' style='display: none' id='flexRT{$tt}' style='width:100%'></table>\n</div>\n<script>\nvar rowid{$tt}='';\n\$(document).ready(function(){\n\t\$('#flexRT{$tt}').flexigrid({\n\t\turl: '{$page}?groups-table-list=yes&t={$tt}&tSource={$_GET["tSource"]}&RULEID={$_GET["RULEID"]}&modeblk={$_GET["modeblk"]}',\n\t\tdataType: 'json',\n\t\tcolModel : [\n\t\t{display: '{$groups}', name : 'groupname', width : {$group_size}, sortable : true, align: 'left'},\n\t\t{display: '{$categories}', name : 'none', width :87, sortable : false, align: 'center'},\n\t\t{display: '{$enabled}', name : 'enabled', width : 31, sortable : false, align: 'center'},\n\t\t{display: '{$delete}', name : 'delete', width : 31, sortable : false, align: 'center'},\n\t\t],\n\t\t{$buttons}\n\t\tsearchitems : [\n\t\t{display: '{$groups}', name : 'groupname'},\n\t\t],\n\t\tsortname: 'groupname',\n\t\tsortorder: 'asc',\n\t\tusepager: true,\n\t\ttitle: '{$title}',\n\t\tuseRp: true,\n\t\trp: 100,\n\t\tshowTableToggleBtn: false,\n\t\twidth: {$table_size},\n\t\theight: 450,\n\t\tsingleSelect: true,\n\t\trpOptions: [10, 20, 30, 50,100,200,500,1000]\n\t});\n});\n\nvar xAddCategoryGroup{$tt}= function (obj) {\n\tvar res=obj.responseText;\n\tif(res.length>3){alert(res);}\n\t\$('#flexRT{$_GET["t"]}').flexReload();\n\t\$('#flexRT{$tt}').flexReload();\n\t\$('#flexRT{$tSource}').flexReload();\n\tExecuteByClassName('SearchFunction');\n\t\n\t\n}\n\nfunction AddCategoryGroup{$tt}(){\n\tvar groupname=prompt('{$new_group}','New category group');\n\tif(!groupname){return;}\n\tvar XHR = new XHRConnection();\n\tXHR.appendData('new-category-group', groupname);\n\tXHR.sendAndLoad('{$page}', 'POST',xAddCategoryGroup{$tt});\t\n\t\t\n\t\n}\n\nfunction Sync{$t}(){\n      var XHR = new XHRConnection();\n      XHR.appendData('SyncTable','yes');\n      XHR.sendAndLoad('{$page}', 'POST',xAddCategoryGroup{$tt});\n}\n\nfunction CategoryGroupEnable{$tt}(ID){\n\tvar XHR = new XHRConnection();\n\tXHR.appendData('enable-category-group', ID);\n\tXHR.sendAndLoad('{$page}', 'POST',xAddCategoryGroup{$tt});\n}\nfunction CategoryRuleGroupEnable{$tt}(ID,ruleid){\n\tvar XHR = new XHRConnection();\n\tXHR.appendData('enable-category-rule', ID);\n\tXHR.appendData('ruleid', ruleid);\n\tXHR.appendData('modeblk', '{$_GET["modeblk"]}');\n\tXHR.sendAndLoad('{$page}', 'POST',xAddCategoryGroup{$tt});\n}\n\n\n\nvar xCategoryGroupDelete{$tt}= function (obj) {\n\tvar res=obj.responseText;\n\tif (res.length>3){alert(res);return;}\n\t\$('#row'+rowid{$tt}).remove();\n\t\$('#flexRT{$tt}').flexReload();\n\t\$('#flexRT{$_GET["t"]}').flexReload();\n\t\$('#flexRT{$tSource}').flexReload();\t\n\tExecuteByClassName('SearchFunction');\n}\n\nfunction CategoryGroupDelete{$tt}(ID,md){\n\trowid{$tt}=md;\n\tif(confirm('{$action_delete_group}')){\n\t\tvar XHR = new XHRConnection();\n\t\tXHR.appendData('delete-category-group', ID);\n\t\tXHR.sendAndLoad('{$page}', 'POST',xCategoryGroupDelete{$tt});\n\t}\n}\n</script>\n\n\t\t";
    echo $html;
}
function DefaultRule()
{
    $t = $_GET["t"];
    $sock = new sockets();
    $webfilter = new webfilter_rules();
    $tpl = new templates();
    $tmplate = $tpl->_ENGINE_parse_body("{template}");
    $color = "black";
    $ligne = unserialize(base64_decode($sock->GET_INFO("DansGuardianDefaultMainRule")));
    $EnableGoogleSafeSearch = $sock->GET_INFO("EnableGoogleSafeSearch");
    if (!is_numeric($EnableGoogleSafeSearch)) {
        $EnableGoogleSafeSearch = 1;
    }
    if (!is_numeric($ligne["groupmode"])) {
        $ligne["groupmode"] = 1;
    }
    $endofrule_TEXTS["any"] = "<i style='color:#000000;margin-top:8px;font-weight:bold;font-size:16px'>" . $tpl->_ENGINE_parse_body("{ufdb_explain_any}") . "</i>";
    $endofrule_TEXTS["none"] = "<i style='color:#d32d2d;margin-top:8px;font-weight:bold;font-size:16px'>" . $tpl->_ENGINE_parse_body("{ufdb_explain_none}") . "</i>";
    if ($ligne["endofrule"] == null) {
        $ligne["endofrule"] = "any";
    }
    $endofrule_text = null;
    $CountDeBlack = intval($webfilter->COUNTDEGBLKS(0));
    $CountDewhite = intval($webfilter->COUNTDEGBWLS(0));
    $CountDeAll = intval($CountDeBlack + $CountDewhite);
    if ($CountDeAll == 0) {
        $color = "#d32d2d";
        $MAINTR[] = $tpl->_ENGINE_parse_body("<i style='color:#d32d2d;margin-top:8px;font-weight:bold;font-size:16px'>{no_category_has_been_added}</i>");
    }
    $MAINTR[] = "<i style='color:{$color};margin-top:8px;font-weight:bold;font-size:16px'>{ufdb_explain_default_rule}</i>";
    if ($EnableGoogleSafeSearch == 0) {
        if ($ligne["GoogleSafeSearch"] == 1) {
            $EnableGoogleSafeSearch_text = $tpl->javascript_parse_text("<i style='color:#00A940;margin-top:8px;font-weight:bold;font-size:16px'>{EnableGoogleSafeSearch}</i>");
        }
    }
    if ($ligne["groupmode"] == 0) {
        $MAINTR[] = "<i style='color:#d32d2d;margin-top:8px;font-weight:bold;font-size:16px'>{all_websites_are_banned}</span>";
    }
    if ($ligne["groupmode"] == 2) {
        $MAINTR[] = "<i style='color:#46a346;margin-top:8px;font-weight:bold;font-size:16px'>{everything_is_allowed}</span>";
    }
    $js = "DansGuardianEditRule('0','default')";
    $jsblack = "<a href=\"javascript:blur();\"\n\tOnClick=\"javascript:document.getElementById('anim-img-0').innerHTML='<img src=img/wait.gif>';Loadjs('dansguardian2.edit.php?js-blacklist-list=yes&RULEID=0&modeblk=0&group=&TimeID=&t={$t}');\"\n\tstyle='text-decoration:underline;font-weight:bold;color:{$color}'>";
    $jswhite = "<a href=\"javascript:blur();\"\n\tOnClick=\"javascript:document.getElementById('anim-img-0').innerHTML='<img src=img/wait.gif>';Loadjs('dansguardian2.edit.php?js-blacklist-list=yes&RULEID=0&modeblk=1&group=&TimeID=&t={$t}');\"\n\tstyle='text-decoration:underline;font-weight:bold;color:{$color}'>";
    $delete = "&nbsp;";
    $duplicate = imgsimple("duplicate-32.png", null, "Loadjs('dansguardian2.duplicate.php?default-rule=yes&t={$t}')");
    $ligne = unserialize(base64_decode($sock->GET_INFO("DansGuardianDefaultMainRule")));
    if ($GLOBALS["VERBOSE"]) {
        echo "<HR>webfilter->rule_time_list_from_ruleid(0)<HR><br>\n";
    }
    $TimeSpace = $webfilter->rule_time_list_explain($ligne["TimeSpace"], 0, $t);
    $TimeSpace = str_replace('\\n\\n', "<br>", $TimeSpace);
    if ($GLOBALS["VERBOSE"]) {
        echo "<HR>{$TimeSpace}<HR><br>\n";
    }
    $MAINTR[] = $endofrule_TEXTS[$ligne["endofrule"]];
    if ($EnableGoogleSafeSearch_text != null) {
        $MAINTR[] = $EnableGoogleSafeSearch_text;
    }
    if ($TimeSpace != null) {
        $MAINTR[] = $TimeSpace;
    }
    $MAINTRTEXT = $tpl->_ENGINE_parse_body(@implode("<br>", $MAINTR));
    return array('id' => 0, 'cell' => array("<span id='anim-img-0'></span><a href=\"javascript:blur();\" OnClick=\"javascript:{$js}\"\n\t\t\t\t\t\tstyle='font-size:22px;text-decoration:underline;color:{$color}'>Default</a>\n\t\t\t\t\t\t<br>{$MAINTRTEXT}\n\t\n\t\t\t\t\t\t", "<center style='font-size:22px;color:{$color}'>*</center>", "<span style='font-size:22px;color:{$color}'>&laquo;&nbsp;{$jsblack}{$CountDeBlack}</a>&nbsp;&raquo;</span>", "<span style='font-size:22px';color:{$color}>&laquo;&nbsp;{$jswhite}{$CountDewhite}</a>&nbsp;&raquo;</span>", "", "<center>{$duplicate}</center>", "<center>{$delete}</center>"));
}
function ipconfig_routes(){
	$page=CurrentPageName();
	$tpl=new templates();
	$sock=new sockets();
	$webfilter=new webfilter_rules();
	$t=time();
	$new_route=$tpl->_ENGINE_parse_body("{new_route}");
	$rule_text=$tpl->_ENGINE_parse_body("{rule}");
	$TimeSpace=$webfilter->TimeToText(unserialize(base64_decode($ligne["TimeSpace"])));
	$EnableWebProxyStatsAppliance=$sock->GET_INFO("EnableWebProxyStatsAppliance");
	if(!is_numeric($EnableWebProxyStatsAppliance)){$EnableWebProxyStatsAppliance=0;}
	$groups=$tpl->_ENGINE_parse_body("{groups}");
	$gateway=$tpl->_ENGINE_parse_body("{gateway}");
	$whitelists=$tpl->_ENGINE_parse_body("{whitelists}");
	$delete=$tpl->_ENGINE_parse_body("{delete}");
	$action_delete_rule=$tpl->javascript_parse_text("{action_delete_rule}");
	$from_ip_address=$tpl->_ENGINE_parse_body("{from_ip_address}");
	$service_events=$tpl->_ENGINE_parse_body("{service_events}");
	$global_parameters=$tpl->_ENGINE_parse_body("{global_parameters}");
	$ldap_parameters=$tpl->_ENGINE_parse_body("{ldap_parameters2}");
	$config_file=$tpl->_ENGINE_parse_body("{config_file}");
	$categories_group=$tpl->_ENGINE_parse_body("{categories_groups}");
	
	$error_ldap=null;
	$buttons="
	buttons : [
	{name: '<strong style=font-size:12px;>$new_route</strong>', bclass: 'add', onpress : NewRoute$t},
	
	
	],";
	
	
	
	$html="
	<table class='flexRT$t' style='display: none' id='flexRT$t' style='width:100%'></table>
	</div>
	<script>
var rowid$t=0;
function flexRTStart$t(){
	$('#flexRT$t').flexigrid({
		url: '$page?ifconfig-route-list=yes&t=$t&nic={$_GET["nic"]}',
		dataType: 'json',
		colModel : [
		{display: '$from_ip_address', name : 'from_ip_address', width : 221, sortable : false, align: 'left'},
		{display: '$gateway', name : 'gateway', width :115, sortable : false, align: 'left'},
		{display: '$delete', name : 'delete', width : 31, sortable : false, align: 'center'},
		],
		$buttons
		searchitems : [
		{display: '$from_ip_address', name : 'from_ip_address'},
		],
		sortname: 'zOrder',
		sortorder: 'asc',
		usepager: true,
		title: '',
		useRp: true,
		rp: 50,
		showTableToggleBtn: false,
		width: 430,
		height: 300,
		singleSelect: true,
		rpOptions: [10, 20, 30, 50,100,200]
		});
}
	
	
	function NewRoute$t(){
		Loadjs('$page?ifconfig-route-add-js=yes&t=$t&nic={$_GET["nic"]}');
	}
	

var xDeleteRoute$t= function (obj) {
		var res=obj.responseText;
		if (res.length>3){alert(res);}
		$('#row'+rowid$t).remove();
	}
	
function DeleteRoute$t(ip,id){
	rowid$t=id;
	if(confirm('$delete '+ip)){
		var XHR = new XHRConnection();		
		XHR.appendData('del-routes','yes');
		XHR.appendData('nic','{$_GET["nic"]}');
		XHR.appendData('IP',ip);
		XHR.sendAndLoad('$page', 'GET',xDeleteRoute$t);	
	}
}
	
setTimeout('flexRTStart$t()',800);
</script>
	
	";
	
	echo $html;
	
	}
function DefaultRule()
{
    $t = $_GET["t"];
    $webfilter = new webfilter_rules();
    $boot = new boostrap_form();
    $styleTD = "style='font-size:16px;font-weight:bold'";
    $styleTDCenter = "style='font-size:16px;font-weight:bold;text-align:center !important'";
    $js = "DansGuardianEditRule('0','default')";
    $jsblack = "<a href=\"javascript:blur();\"\n\t\tOnClick=\"javascript:document.getElementById('anim-img-0').innerHTML='<img src=img/wait.gif>';\"\n\t\tstyle='text-decoration:underline;font-weight:bold'>";
    $delete = "&nbsp;";
    $duplicate = imgsimple("duplicate-24.png", null, "Loadjs('dansguardian2.duplicate.php?default-rule=yes&t={$t}')");
    $sock = new sockets();
    $ligne = unserialize(base64_decode($sock->GET_INFO("DansGuardianDefaultMainRule")));
    $TimeSpace = $webfilter->rule_time_list_explain($ligne["TimeSpace"], 0, $t);
    $link = $boot->trswitch($js);
    $link_blacklist = $boot->trswitch("Loadjs('dansguardian2.edit.php?js-blacklist-list=yes&RULEID=0&modeblk=0&group=&TimeID=&t={$t}');");
    $link_whitelist = $boot->trswitch("Loadjs('dansguardian2.edit.php?js-blacklist-list=yes&RULEID=0&modeblk=1&group=&TimeID=&t={$t}');");
    $templatejs = $boot->trswitch("Loadjs('dansguardian.template.php?js=yes&ID=0')");
    return "\n\t<tr id='0'>\n\t<td {$styleTD} {$link} width=99%><span id='anim-img-0'>Default</span> {$TimeSpace} " . $webfilter->rules_dans_time_rule(0) . "</td>\n\t<td {$styleTDCenter} {$link} width=1% align=center >*</td>\n\t<td {$styleTDCenter} {$link_blacklist} width=1% align=center>" . $webfilter->COUNTDEGBLKS(0) . "</td>\n\t<td {$styleTDCenter} {$link_whitelist} width=1% align=center>" . $webfilter->COUNTDEGBWLS(0) . "</td>\n\t<td>&nbsp;</td>\n\t<td {$styleTDCenter} {$templatejs} width=35px align=center nowrap><img src='img/banned-template-32.png'></td>\n\t<td width=35px align=center {$styleTDCenter}>{$duplicate}</td>\n\t<td>&nbsp;</td>\n\t</tr>";
}
function DefaultRule()
{
    $t = $_GET["t"];
    $sock = new sockets();
    $webfilter = new webfilter_rules();
    $tpl = new templates();
    $tmplate = $tpl->_ENGINE_parse_body("{template}");
    $color = "black";
    $ligne = unserialize(base64_decode($sock->GET_INFO("DansGuardianDefaultMainRule")));
    $EnableGoogleSafeSearch = $sock->GET_INFO("EnableGoogleSafeSearch");
    if (!is_numeric($EnableGoogleSafeSearch)) {
        $EnableGoogleSafeSearch = 1;
    }
    $endofrule_text = null;
    //$color="#E91212";
    if ($EnableGoogleSafeSearch == 0) {
        if ($ligne["GoogleSafeSearch"] == 1) {
            $EnableGoogleSafeSearch_text = $tpl->javascript_parse_text("<br><i style='color:#00A940;margin-top:8px;font-weight:bold'>{EnableGoogleSafeSearch}</i>");
        }
    }
    if ($ligne["groupmode"] == 0) {
        $color = "#E91212";
        $warn = "<div style='float:right'><img src='img/stop-24.png'></div>";
    }
    $js = "DansGuardianEditRule('0','default')";
    $jsblack = "<a href=\"javascript:blur();\"\n\tOnClick=\"javascript:document.getElementById('anim-img-0').innerHTML='<img src=img/wait.gif>';Loadjs('dansguardian2.edit.php?js-blacklist-list=yes&RULEID=0&modeblk=0&group=&TimeID=&t={$t}');\"\n\tstyle='text-decoration:underline;font-weight:bold;color:{$color}'>";
    $jswhite = "<a href=\"javascript:blur();\"\n\tOnClick=\"javascript:document.getElementById('anim-img-0').innerHTML='<img src=img/wait.gif>';Loadjs('dansguardian2.edit.php?js-blacklist-list=yes&RULEID=0&modeblk=1&group=&TimeID=&t={$t}');\"\n\tstyle='text-decoration:underline;font-weight:bold;color:{$color}'>";
    $delete = "&nbsp;";
    $duplicate = imgsimple("duplicate-32.png", null, "Loadjs('dansguardian2.duplicate.php?default-rule=yes&t={$t}')");
    $ligne = unserialize(base64_decode($sock->GET_INFO("DansGuardianDefaultMainRule")));
    if ($GLOBALS["VERBOSE"]) {
        echo "<HR>webfilter->rule_time_list_from_ruleid(0)<HR><br>\n";
    }
    $TimeSpace = $webfilter->rule_time_list_explain($ligne["TimeSpace"], 0, $t);
    $TimeSpace = str_replace('\\n\\n', "<br>", $TimeSpace);
    if ($GLOBALS["VERBOSE"]) {
        echo "<HR>{$TimeSpace}<HR><br>\n";
    }
    $endofrule = $ligne["endofrule"];
    if ($endofrule == "none") {
        $endofrule_text = "<br><i style='color:#DB0000;margin-top:8px;font-weight:bold'>{block_unknown_websites}</i>";
    }
    return array('id' => 0, 'cell' => array("<span id='anim-img-0'></span><a href=\"javascript:blur();\" OnClick=\"javascript:{$js}\"\n\t\t\t\t\t\tstyle='font-size:22px;text-decoration:underline;color:{$color}'>Default</a>\n\t\t\t\t\t\t{$TimeSpace}{$endofrule_text}{$EnableGoogleSafeSearch_text}\n\t\n\t\t\t\t\t\t", "<span style='font-size:22px;color:{$color}'>*</span>", "<span style='font-size:22px;color:{$color}'>&laquo;&nbsp;{$jsblack}" . $webfilter->COUNTDEGBLKS(0) . "</a>&nbsp;&raquo;</span>", "<span style='font-size:22px';color:{$color}>&laquo;&nbsp;{$jswhite}" . $webfilter->COUNTDEGBWLS(0) . "</a>&nbsp;&raquo;</span>", "", "{$duplicate}", $delete));
}