function query(){
	
	
	$tpl=new templates();
	$also=$tpl->_ENGINE_parse_body("{also}");
	$MyPage=CurrentPageName();
	$q=new mysql_squid_builder();
	$nowebsites=$tpl->_ENGINE_parse_body("{no_saved_web_site_catz}");
	$category=null;
	
	if($category==null){if($_GET["category"]<>null){$category=$_GET["category"];$_POST["qtype"]="pattern";}}
	if($category==null){if($_POST["qtype"]<>null){$category=$_POST["qtype"];$_POST["qtype"]="pattern";}}	
	writelogs("Category:$category",__FUNCTION__,__FILE__,__LINE__);
	
	if($_POST["query"]<>null){if($_GET["website"]<>null){$_POST["query"]=$_GET["website"];}}
	if($category==null){json_error_show("Please select a category first");}
	if($_POST["sortname"]=="sitename"){$_POST["sortname"]="zDate";$_POST["sortorder"]="desc";}
	
	writelogs("Category:$category",__FUNCTION__,__FILE__,__LINE__);
	$table="category_".$q->category_transform_name($category);
	$search='%';
	$page=1;
	$COUNT_ROWS=$q->COUNT_ROWS($table);
	
	if($COUNT_ROWS==0){json_error_show("category:$category ,Table: $table, $nowebsites",1);}
	
	if(isset($_POST["sortname"])){if($_POST["sortname"]<>null){$ORDER="ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";}}	
	if (isset($_POST['page'])) {$page = $_POST['page'];}
	
	$_POST["query"]=trim($_POST["query"]);
	
	
	$searchstring=string_to_flexquery();
	
	
	
	
	if($searchstring<>null){
		$orgQuery=$_POST["query"];
		$sql="SELECT COUNT(zmd5) as TCOUNT FROM `$table` WHERE 1 $searchstring";
		$ligne=mysql_fetch_array($q->QUERY_SQL($sql,"artica_backup"));
		$total = $ligne["TCOUNT"];
		
	}else{
		$total = $q->COUNT_ROWS($table);
	}
	
	if (isset($_POST['rp'])) {$rp = $_POST['rp'];}	
	

	
	$pageStart = ($page-1)*$rp;
	$limitSql = "LIMIT $pageStart, $rp";
	
	$sql="SELECT zDate,zmd5,pattern,enabled  FROM `$table` WHERE 1 $searchstring $ORDER $limitSql";	
	writelogs($sql,__FUNCTION__,__FILE__,__LINE__);
	$results = $q->QUERY_SQL($sql);
	if(!$q->ok){json_error_show($q->mysql_error,1);}
	if(mysql_num_rows($results)==0){json_error_show("$nowebsites",1);}
	$disabled_text=$tpl->_ENGINE_parse_body("{disabled}");
	$CategoriesCheckRightsWrite=CategoriesCheckRightsWrite();
	
	$data = array();
	$data['page'] = $page;
	$data['total'] = $total;
	$data['rows'] = array();
	
	if($orgQuery<>null){$moveAll=imgtootltip("arrow-multiple-right-24.png","{move}","MoveAllCategorizedWebsite2('$category','$table','$orgQuery')");}
	
	while ($ligne = mysql_fetch_assoc($results)) {
		$delete=imgtootltip("delete-24.png","{delete}","DeleteCategorizedWebsite('{$ligne["zmd5"]}','$table')");
		$move=imgtootltip("arrow-right-24.png","{move}","MoveCategorizedWebsite('{$ligne["zmd5"]}','{$ligne["pattern"]}','$category','$table')");
		
		
		$added=null;
		/*$categories=$q->GET_CATEGORIES($ligne["pattern"],true,true,true);
		writelogs("{$ligne["pattern"]}= $categories ",__FUNCTION__,__FILE__,__LINE__);
		$categories=str_replace($category, "", $categories);
		$ff=explode(",",$categories);
		$tt=array();
		while (list ($a, $b) = each ($ff) ){if(trim($b)==null){continue;}$tt[]=	$b;}
		if(count($tt)>0){
			$added="<div><i style='font-size:11px'>$also: ".@implode(", ", $tt)."</i></div>";
		}
		*/
		$enabled=$ligne["enabled"];
		$color="color:black";
		if($enabled==0){
			$color="color:#B6ACAC";
			$added=$added."<div><i style='font-size:11px'>$disabled_text</i></div>";
			$moveAll="&nbsp;";
			$move="&nbsp;";
			$delete=imgtootltip("delete-24.png","{delete}","ReallyDeleteCategorizedWebsite('{$ligne["zmd5"]}','$table')");
		}
		
$jscat="<a href=\"javascript:blur();\" 
		OnClick=\"javascript:Loadjs('squid.categorize.php?www={$ligne["pattern"]}');\"
		style='font-size:14px;text-decoration:underline;$color'>";	


if(!$CategoriesCheckRightsWrite){
	$jscat=null;
	$moveAll=null;
	$move=null;
	$delete=null;
}
		
	$data['rows'][] = array(
		'id' => $ligne['zmd5'],
		'cell' => array("
		<span style='font-size:16px;$color'>{$ligne['zDate']}</span>",
		"<span style='font-size:16px;$color'>$jscat{$ligne['pattern']}</a></span>$added",$moveAll,
		$move,$delete)
		);
	}
	
	
echo json_encode($data);	
	return;
	$page=CurrentPageName();
	$tpl=new templates();	
	$category=$_GET["category"];
	
	if($category==null){return;}
	$q=new mysql_squid_builder();
	$tableN="category_".$q->category_transform_name($category);
	$strictSearch=$_GET["strictSearch"];
	if(!is_numeric($strictSearch)){$strictSearch=0;}
	$searchOrg=$_GET["search"];
	if($_GET["search"]<>null){
		$search=$_GET["search"];
		if($strictSearch==0){$search="*$search*";}
		$search=str_replace("**", "*", $search);
		$search=str_replace("**", "*", $search);
		$search=str_replace("*", "%", $search);
		$search=" AND pattern LIKE '$search'";
	}
	
	$sql="SELECT * FROM $tableN WHERE enabled=1 $search ORDER BY pattern LIMIT 0,25 ";
	
	$table="<center>
<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:350px'>
<thead class='thead'>
	<tr>
	<th width=1%>{website} $category</th>
	<th>{date}</th>
	<th>$moveall</th>
	<th>&nbsp;</th>
	</tr>
</thead>
<tbody>";
	
	$results=$q->QUERY_SQL($sql);
	
	$number=mysql_num_rows($results);
	if($number==0){
		if($searchOrg<>null){
			if(strpos($searchOrg, "*")==0){
		$html="
		<center style='margin:30px'>
		<div style='font-size:16px;margin-bottom:15px'><code>&laquo;http://$searchOrg&raquo; {in} &laquo;$category&raquo;</code></div>
		<div style='font-size:14px'><a href=\"javascript:blur();\" 
		OnClick=\"javascript:Loadjs('squid.visited.php?add-www=yes&websitetoadd=$searchOrg')\"
		style='font-size:14px;font-weight:bold;text-decoration:underline'
		>{webiste_notfound_additask}</a>
		</div>
		</center>
		<script>LoadAjaxTiny('subtitles-categories','$page?subtitles-categories=yes');</script>
		";
		echo $tpl->_ENGINE_parse_body($html);
		return;
		}
		
		}
		
	}
	
	
	
	
	if(!$q->ok){echo "<H2>$q->mysql_error</H2><center style='font-size:11px'><code>$sql</code></center>";}		
	while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
		if($classtr=="oddRow"){$classtr=null;}else{$classtr="oddRow";}
		if($ligne["pattern"]==null){$q->QUERY_SQL("DELETE FROM $tableN WHERE zmd5='{$ligne["zmd5"]}'");continue;}
		

		
		$jscat="<a href=\"javascript:blur();\" 
		OnClick=\"javascript:Loadjs('squid.categorize.php?www={$ligne["pattern"]}');\"
		style='font-size:14px;text-decoration:underline'>";
		$table=$table."
		<tr class=$classtr>
		<td style='width:1%;font-size:14px' nowrap>{$ligne["zDate"]}</td>
		<td style='width:1%;font-size:14px' nowrap>$jscat{$ligne["pattern"]}</a></td>
		<td>$move</td>
		<td>$delete</td>
		</tr>
		";
		
	}
	$table=$table."</tbody></table>
	<script>
	
	

	

	
	LoadAjaxTiny('subtitles-categories','$page?subtitles-categories=yes');
	
</script>	
	";
	echo $tpl->_ENGINE_parse_body($table);
	
}
function query(){
	
	$category=null;
	$tpl=new templates();
	$also=$tpl->_ENGINE_parse_body("{also}");
	$MyPage=CurrentPageName();
	$q=new mysql_squid_builder();
	$nowebsites=$tpl->_ENGINE_parse_body("{no_saved_web_site_catz}");
	
	writelogs("Category:$category",__FUNCTION__,__FILE__,__LINE__);
	if($category==null){if($_GET["category"]<>null){$category=$_GET["category"];}}
	if($category==null){if($_POST["qtype"]<>null){$category=$_POST["qtype"];}}	
	
	
	if($_POST["query"]<>null){if($_GET["website"]<>null){$_POST["query"]=$_GET["website"];}}
	if($category==null){json_error_show("Please select a category first");}
	if($_POST["sortname"]=="sitename"){$_POST["sortname"]="zDate";$_POST["sortorder"]="desc";}
	
	writelogs("Category:$category",__FUNCTION__,__FILE__,__LINE__);
	$table="categoryuris_".$q->category_transform_name($category);
	$CategoriesCheckRightsWrite=CategoriesCheckRightsWrite();
	$q->CreateCategoryUrisTable(null,$table);
	$search='%';
	$page=1;
	$COUNT_ROWS=$q->COUNT_ROWS($table);
	
	if($COUNT_ROWS==0){json_error_show("no data",1);}
	
	if(isset($_POST["sortname"])){if($_POST["sortname"]<>null){$ORDER="ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";}}	
	if (isset($_POST['page'])) {$page = $_POST['page'];}
	
	$searchstring=string_to_flexquery();
	
	
	if($searchstring<>null){
		$sql="SELECT COUNT(zmd5) as TCOUNT FROM `$table` WHERE 1 $searchstring";
		$ligne=mysql_fetch_array($q->QUERY_SQL($sql,"artica_backup"));
		$total = $ligne["TCOUNT"];
		
	}else{
		$total = $q->COUNT_ROWS($table);
	}
	
	if (isset($_POST['rp'])) {$rp = $_POST['rp'];}	
	

	
	$pageStart = ($page-1)*$rp;
	$limitSql = "LIMIT $pageStart, $rp";
	
	$sql="SELECT zDate,zmd5,pattern,enabled  FROM `$table` WHERE 1 $searchstring $ORDER $limitSql";	
	$results = $q->QUERY_SQL($sql);
	if(!$q->ok){json_error_show($q->mysql_error,1);}
	if(mysql_num_rows($results)==0){json_error_show("$nowebsites",1);}
	$disabled_text=$tpl->_ENGINE_parse_body("{disabled}");
	
	$data = array();
	$data['page'] = $page;
	$data['total'] = $total;
	$data['rows'] = array();
	
	
	
	while ($ligne = mysql_fetch_assoc($results)) {
		$delete=imgtootltip("delete-24.png","{delete}","DeleteCategorizedURI('{$ligne["zmd5"]}','$table')");

		$enabled=$ligne["enabled"];
		$color="color:black";
		if($enabled==0){
			$color="color:#B6ACAC";
			$added=$added."<div><i style='font-size:11px'>$disabled_text</i></div>";
			$moveAll="&nbsp;";
			$move="&nbsp;";
			
		}
		
$jscat="<a href=\"javascript:blur();\" 
		OnClick=\"javascript:Loadjs('squid.categorize.php?www={$ligne["pattern"]}');\"
		style='font-size:14px;text-decoration:underline;$color'>";	

if(!$CategoriesCheckRightsWrite){
	$jscat=null;
	$delete=null;
}
		
	$data['rows'][] = array(
		'id' => $ligne['zmd5'],
		'cell' => array("
		<span style='font-size:14px;$color'>{$ligne['zDate']}</span>",
		"<span style='font-size:14px;$color'>$jscat{$ligne['pattern']}</a></span>$added",$delete)
		);
	}
	
	
echo json_encode($data);	

	
}
function categories_search()
{
    $MyPage = CurrentPageName();
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql_squid_builder();
    $dans = new dansguardian_rules();
    $EnableWebProxyStatsAppliance = $sock->GET_INFO("EnableWebProxyStatsAppliance");
    if (!is_numeric($EnableWebProxyStatsAppliance)) {
        $EnableWebProxyStatsAppliance = 0;
    }
    $t = $_GET["t"];
    $OnlyPersonal = 0;
    $rp = 200;
    if (isset($_GET["artica"])) {
        $artica = true;
    }
    if (!$q->BD_CONNECT()) {
        json_error_show("Testing connection to MySQL server failed...", 1);
    }
    $sql = "SELECT * FROM personal_categories WHERE `PublicMode`=1";
    $table = "personal_categories";
    $searchstring = string_to_flexquery();
    $page = 1;
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($searchstring != null) {
        $sql = "SELECT COUNT( * ) AS tcount FROM {$table} WHERE PublicMode=1 {$searchstring}";
        writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: {$q->mysql_error}.<br>{$sql}", 1);
        }
        $total = $ligne["tcount"];
    } else {
        $sql = "SELECT COUNT( * ) AS tcount FROM {$table} WHERE PublicMode=1";
        writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: {$q->mysql_error}.<br>{$sql}", 1);
        }
        $total = $ligne["tcount"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT * FROM {$table} WHERE PublicMode=1 {$searchstring} {$ORDER} {$limitSql} ";
    writelogs("{$q->mysql_admin}:{$q->mysql_password}:{$sql}", __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        if ($q->mysql_error != null) {
            json_error_show(date("H:i:s") . "<br>SORT:{$_POST["sortname"]}:<br>Mysql Error [L." . __LINE__ . "]: {$q->mysql_error}<br>{$sql}", 1);
        }
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("Not found...", 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $enc = new mysql_catz();
    $field = "category";
    $field_description = "category_description";
    $CATZ_ARRAY = unserialize(@file_get_contents("/home/artica/categories_databases/CATZ_ARRAY"));
    $CategoriesCheckRightsWrite = CategoriesCheckRightsWrite();
    $TransArray = $enc->TransArray();
    while (list($tablename, $items) = each($CATZ_ARRAY)) {
        if (!isset($TransArray[$tablename])) {
            continue;
        }
        $CATZ_ARRAY2[$TransArray[$tablename]] = $items;
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $color = "black";
        $categorykey = $ligne["category"];
        if ($categorykey == null) {
            $categorykey = "UnkNown";
        }
        //Array ( [category] => [category_description] => Ma catégorie [master_category] => [sended] => 1 )
        if ($GLOBALS["VERBOSE"]) {
            echo "Found  {$field}:{$categorykey}<br>\n";
        }
        $categoryname = $categorykey;
        $text_category = null;
        $table = $q->cat_totablename($categorykey);
        if ($GLOBALS["VERBOSE"]) {
            echo "Scanning table {$table}<br>\n";
        }
        $itemsEncTxt = null;
        $items = $q->COUNT_ROWS($table);
        if (!preg_match("#^category_(.+)#", $table, $re)) {
            continue;
        }
        $compile = imgsimple("compile-distri-32.png", "{saveToDisk}", "DansGuardianCompileDB('{$categoryname}')");
        if ($dans->array_pics[$categoryname] != null) {
            $pic = "<img src='img/{$dans->array_pics[$categoryname]}'>";
        } else {
            $pic = "&nbsp;";
        }
        $sizedb_org = $q->TABLE_SIZE($table);
        $sizedb = FormatBytes($sizedb_org / 1024);
        $linkcat = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('squid.categories.php?category={$categoryname}&t={$t}',true)\"\n\t\t\tstyle='font-size:18px;font-weight:bold;color:{$color};text-decoration:underline'>";
        $text_category = $tpl->_ENGINE_parse_body(utf8_decode($ligne[$field_description]));
        $text_category = trim($text_category);
        $linkcat = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('{$MyPage}?add-perso-cat-js=yes&cat={$categoryname}&t={$t}',true)\"\n\t\t\tstyle='font-size:18px;font-weight:bold;color:{$color};text-decoration:underline'>";
        $viewDB = imgsimple("mysql-browse-database-32.png", null, "javascript:Loadjs('squid.categories.php?category={$categoryname}',true)");
        $text_category = utf8_encode($text_category);
        $categoryname_text = utf8_encode($categoryname);
        $categoryText = $tpl->_ENGINE_parse_body("<span style='font-size:26px';font-weight:bold'>{$linkcat}{$categoryname_text}</div>\n\t\t\t\t\t</a><br><span style='font-size:18px;width:100%;font-weight:normal'>{$text_category}</div>");
        $itemsEncTxt = "<span style='font-size:32px;font-weight:bold'>" . numberFormat($items, 0, "", " ");
        "</span>";
        $compile = imgsimple("compile-distri-48.png", null, "DansGuardianCompileDB('{$categoryname}')");
        $delete = imgsimple("dustbin-48.png", null, "TableCategoryPurge('{$table}')");
        if ($categoryname == "UnkNown") {
            $linkcat = null;
            $delete = imgsimple("delete-48.png", null, "TableCategoryPurge('')");
        }
        if (!$CategoriesCheckRightsWrite) {
            $compile = null;
        }
        $cell = array();
        $cell[] = $categoryText;
        $cell[] = $itemsEncTxt;
        $cell[] = $compile;
        $data['rows'][] = array('id' => $ligne['ID'], 'cell' => $cell);
    }
    echo json_encode($data);
}
function popup()
{
    $tpl = new templates();
    $TB_WIDTH = 915;
    $users = new usersMenus();
    $page = CurrentPageName();
    $t = time();
    $uri = $tpl->_ENGINE_parse_body("{url}");
    $date = $tpl->_ENGINE_parse_body("{date}");
    $movetext = $tpl->_ENGINE_parse_body("{move}");
    $moveall = $tpl->_ENGINE_parse_body("{move} {all}");
    $select = $tpl->_ENGINE_parse_body("{select}");
    $add_websites = $tpl->_ENGINE_parse_body("{add_urls}");
    $category = $_GET["category"];
    $q = new mysql_meta();
    $searchitem = null;
    $category_text = $tpl->_ENGINE_parse_body("{category}");
    $removedAll = $tpl->javascript_parse_text("{delete_all}");
    $removedisabled_warn = $tpl->javascript_parse_text("{remove_disabled_items_warn}");
    $CategoriesCheckRightsWrite = CategoriesCheckRightsWrite();
    $export = $tpl->javascript_parse_text("{export}");
    $xls = "{name: '<strong style=font-size:18px>{$export}:CSV</strong>', bclass: 'xls', onpress : xls{$t}},";
    $RemoveEnabled = "{name: '<strong style=font-size:18px>{$removedAll}</strong>', bclass: 'Delz', onpress : DeleteAll{$t}},";
    $BUTTON_ADD = "{name: '<strong style=font-size:18px>{$add_websites}</strong>', bclass: 'Add', onpress : AddWebSites{$t}},";
    $xls = null;
    if (!$CategoriesCheckRightsWrite) {
        $RemoveEnabled = null;
        $BUTTON_ADD = null;
    }
    $buttons = "buttons : [\n\t\t\t{$RemoveEnabled}\n\t\t\t\t],\t";
    if ($_GET["middlesize"] == "yes") {
        $TB_WIDTH = 915;
    }
    if ($_GET["category"] != null) {
        $table_title = "{$category_text}::{$category}";
        $buttons = "buttons : [\n\t\t\t{$BUTTON_ADD}\n\t\t\t{$RemoveEnabled} {$xls}\n\t\t\t\t],";
        $searchitem = "\tsearchitems : [\n\t\t{display: '{$uri}', name : 'pattern'}\n\t\t],";
    }
    $rowebsite = 461;
    if (isset($_GET["rowebsite"])) {
        $rowebsite = $_GET["rowebsite"];
        $rowebsite = $rowebsite - 40;
    }
    echo "\n\n<div style='margin-left:-15px'>\n\t<table class='{$t}' style='display: none' id='{$t}' style='width:99%;'></table>\n</div>\n<script>\nvar MEMMD{$t}='';\n\$(document).ready(function(){\n\$('#{$t}').flexigrid({\n\turl: '{$page}?query=yes&category={$_GET["category"]}&website={$_GET["website"]}',\n\tdataType: 'json',\n\tcolModel : [\n\t\t\t{display: '<span style=font-size:18px>{$date}</span>', name : 'zDate', width : 179, sortable : true, align: 'left'},\t\n\t\t\t{display: '<span style=font-size:18px>{$uri}</span>', name : 'pattern', width :665, sortable : true, align: 'left'},\n\t\t\t{display: '&nbsp;', name : 'none2', width : 40, sortable : false, align: 'left'},\n\t\t\n\t],\n{$buttons}\n{$searchitem}\n\tsortname: 'zDate',\n\tsortorder: 'desc',\n\tusepager: true,\n\ttitle: '<strong style=font-size:22px>{$table_title}</strong>',\n\tuseRp: true,\n\trp: 15,\n\tshowTableToggleBtn: false,\n\twidth: '99%',\n\theight: 300,\n\tsingleSelect: true\n\t\n\t});   \n});\n\nfunction xls{$t}(){\n\tLoadjs('squid.categories.url.export.php?category={$_GET["category"]}&t={$t}');\n}\n\n\tfunction AddWebSites{$t}(){\n\t\tLoadjs('{$page}?add-uris-js=yes&category={$_GET["category"]}&t={$t}');\n\t}\n\n\tfunction MoveCategorizedWebsite(zmd5,website,category,category_table){\n\t\tYahooWinBrowse(550,'{$page}?move-category-popup=yes&YahooWin=YahooWinBrowse&website='+website+'&zmd5='+zmd5+'&category-source='+category+'&table-source='+category_table,'{$movetext}::'+website);\n\t}\n\n\tfunction MoveAllCategorizedWebsite(){\n\t\tYahooWinBrowse(550,'{$page}?move-category-popup=yes&YahooWin=YahooWinBrowse&website=&zmd5=&category-source={$_GET["category"]}&table-source={$table}&bysearch={$_GET["search"]}','{$movetext}::{$_GET["search"]}');\n\t\t\n\t}\n\t\n\tfunction MoveAllCategorizedWebsite2(category,table,search){\n\t\tYahooWinBrowse(550,'{$page}?move-category-popup=yes&YahooWin=YahooWinBrowse&website=&zmd5=&category-source='+category+'&table-source='+table+'&bysearch='+search+'&t={$t}','{$movetext}::'+search);\n\t\t\n\t}\n\n\tvar x_DeleteAll{$t}= function (obj) {\n\t\tvar results=obj.responseText;\n\t\tif(results.length>0){alert(results);return;}\n\t\t\$('#{$t}').flexReload();\n\t}\t\t\n\t\n\tfunction DeleteAll{$t}(){\n\t\tvar categoryZ = '{$_GET["category"]}'\n\t\tif(confirm('{$removedAll}:'+categoryZ)){\n\t\t\tvar XHR = new XHRConnection();\n\t\t\tXHR.appendData('RemoveAll',categoryZ);\n\t\t\tXHR.sendAndLoad('{$page}', 'POST',x_DeleteAll{$t});\n\t\t}\n\t}\n\t\n\t\n\tvar x_DeleteCategorizedWebsite{$t}= function (obj) {\n\t\tvar results=obj.responseText;\n\t\tif(results.length>0){alert(results);return;}\n\t\t\$('#row'+MEMMD{$t}).remove();\n\t}\t\n\n\n\t\n\n\t\n\tfunction DeleteCategorizedURI(zmd5,table){\n\t\tMEMMD{$t}=zmd5;\n\t\tvar XHR = new XHRConnection();\n\t\tXHR.appendData('DeleteCategorizedURI',zmd5);\n\t\tXHR.appendData('catz','{$_GET["category"]}');\n\t\tXHR.appendData('TABLE',table);\n\t\tXHR.sendAndLoad('{$page}', 'POST',x_DeleteCategorizedWebsite{$t});\t\n\t}\t\n\n</script>\n";
}
function query()
{
    $tpl = new templates();
    $also = $tpl->_ENGINE_parse_body("{also}");
    $MyPage = CurrentPageName();
    $q = new mysql_meta();
    $nowebsites = $tpl->_ENGINE_parse_body("{no_saved_web_site_catz}");
    $category = null;
    if ($category == null) {
        if ($_GET["category"] != null) {
            $category = $_GET["category"];
            $_POST["qtype"] = "pattern";
        }
    }
    if ($category == null) {
        if ($_POST["qtype"] != null) {
            $category = $_POST["qtype"];
            $_POST["qtype"] = "pattern";
        }
    }
    if ($_POST["query"] != null) {
        if ($_GET["website"] != null) {
            $_POST["query"] = $_GET["website"];
        }
    }
    if ($category == null) {
        json_error_show("Please select a category first");
    }
    if ($_POST["sortname"] == "sitename") {
        $_POST["sortname"] = "zDate";
        $_POST["sortorder"] = "desc";
    }
    $search = '%';
    $page = 1;
    $COUNT_ROWS = $q->COUNT_ROWS("webfiltering_categories_items");
    if ($COUNT_ROWS == 0) {
        json_error_show("category/COUNT_ROWS:{$category} ,{$nowebsites}", 1);
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $_POST["query"] = trim($_POST["query"]);
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $orgQuery = $_POST["query"];
        $sql = "SELECT COUNT(zmd5) as TCOUNT FROM `webfiltering_categories_items` WHERE category='{$category}' {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT zDate,zmd5,pattern,enabled  FROM `webfiltering_categories_items` WHERE 1 {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        json_error_show($q->mysql_error, 1);
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("{$nowebsites}", 1);
    }
    $disabled_text = $tpl->_ENGINE_parse_body("{disabled}");
    $CategoriesCheckRightsWrite = CategoriesCheckRightsWrite();
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if ($orgQuery != null) {
        $moveAll = imgtootltip("arrow-multiple-right-24.png", "{move}", "MoveAllCategorizedWebsite2('{$category}','{$table}','{$orgQuery}')");
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $delete = imgtootltip("delete-24.png", "{delete}", "DeleteCategorizedWebsite('{$ligne["zmd5"]}','{$table}')");
        $move = imgtootltip("arrow-right-24.png", "{move}", "MoveCategorizedWebsite('{$ligne["zmd5"]}','{$ligne["pattern"]}','{$category}','{$table}')");
        $added = null;
        $enabled = $ligne["enabled"];
        $color = "color:black";
        $moveAll = "&nbsp;";
        $move = "&nbsp;";
        $delete = imgtootltip("delete-24.png", "{delete}", "ReallyDeleteCategorizedWebsite('{$ligne["zmd5"]}')");
        $jscat = "<a href=\"javascript:blur();\" \n\t\tOnClick=\"javascript:Loadjs('squid.categorize.php?www={$ligne["pattern"]}');\"\n\t\tstyle='font-size:14px;text-decoration:underline;{$color}'>";
        if (!$CategoriesCheckRightsWrite) {
            $jscat = null;
            $moveAll = null;
            $move = null;
            $delete = null;
        }
        $data['rows'][] = array('id' => $ligne['zmd5'], 'cell' => array("\n\t\t<span style='font-size:18px;{$color}'>{$ligne['zDate']}</span>", "<span style='font-size:18px;{$color}'>{$ligne['pattern']}</a></span>", "<center>{$delete}</center>"));
    }
    echo json_encode($data);
    return;
    $page = CurrentPageName();
    $tpl = new templates();
    $category = $_GET["category"];
    if ($category == null) {
        return;
    }
    $q = new mysql_squid_builder();
    $tableN = "category_" . $q->category_transform_name($category);
    $strictSearch = $_GET["strictSearch"];
    if (!is_numeric($strictSearch)) {
        $strictSearch = 0;
    }
    $searchOrg = $_GET["search"];
    if ($_GET["search"] != null) {
        $search = $_GET["search"];
        if ($strictSearch == 0) {
            $search = "*{$search}*";
        }
        $search = str_replace("**", "*", $search);
        $search = str_replace("**", "*", $search);
        $search = str_replace("*", "%", $search);
        $search = " AND pattern LIKE '{$search}'";
    }
    $sql = "SELECT * FROM {$tableN} WHERE enabled=1 {$search} ORDER BY pattern LIMIT 0,25 ";
    $table = "<center>\n<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:350px'>\n<thead class='thead'>\n\t<tr>\n\t<th width=1%>{website} {$category}</th>\n\t<th>{date}</th>\n\t<th>{$moveall}</th>\n\t<th>&nbsp;</th>\n\t</tr>\n</thead>\n<tbody>";
    $results = $q->QUERY_SQL($sql);
    $number = mysql_num_rows($results);
    if ($number == 0) {
        if ($searchOrg != null) {
            if (strpos($searchOrg, "*") == 0) {
                $html = "\n\t\t<center style='margin:30px'>\n\t\t<div style='font-size:16px;margin-bottom:15px'><code>&laquo;http://{$searchOrg}&raquo; {in} &laquo;{$category}&raquo;</code></div>\n\t\t<div style='font-size:14px'><a href=\"javascript:blur();\" \n\t\tOnClick=\"javascript:Loadjs('squid.visited.php?add-www=yes&websitetoadd={$searchOrg}')\"\n\t\tstyle='font-size:14px;font-weight:bold;text-decoration:underline'\n\t\t>{webiste_notfound_additask}</a>\n\t\t</div>\n\t\t</center>\n\t\t<script>LoadAjaxTiny('subtitles-categories','{$page}?subtitles-categories=yes');</script>\n\t\t";
                echo $tpl->_ENGINE_parse_body($html);
                return;
            }
        }
    }
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2><center style='font-size:11px'><code>{$sql}</code></center>";
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($classtr == "oddRow") {
            $classtr = null;
        } else {
            $classtr = "oddRow";
        }
        if ($ligne["pattern"] == null) {
            $q->QUERY_SQL("DELETE FROM {$tableN} WHERE zmd5='{$ligne["zmd5"]}'");
            continue;
        }
        $jscat = "<a href=\"javascript:blur();\" \n\t\tOnClick=\"javascript:Loadjs('squid.categorize.php?www={$ligne["pattern"]}');\"\n\t\tstyle='font-size:14px;text-decoration:underline'>";
        $table = $table . "\n\t\t<tr class={$classtr}>\n\t\t<td style='width:1%;font-size:14px' nowrap>{$ligne["zDate"]}</td>\n\t\t<td style='width:1%;font-size:14px' nowrap>{$jscat}{$ligne["pattern"]}</a></td>\n\t\t<td>{$move}</td>\n\t\t<td>{$delete}</td>\n\t\t</tr>\n\t\t";
    }
    $table = $table . "</tbody></table>\n\t<script>\n\t\n\t\n\n\t\n\n\t\n\tLoadAjaxTiny('subtitles-categories','{$page}?subtitles-categories=yes');\n\t\n</script>\t\n\t";
    echo $tpl->_ENGINE_parse_body($table);
}