<commit_before><?php
//============================================================================
// (c) 2009-2010, Eolya - All Rights Reserved.
// This source code is the property of Eolya.
// The license applying to this source code is available at :
// http://www.crawl-anywhere.com/licenses/
//============================================================================
require_once("../../init_gpc.inc.php");
require_once("../../init.inc.php");

$action = $_GET["action"];
$limit = $_GET["limit"];
if ($limit=="") $limit="0";

require_once("content.common.ajax.inc.php");

require_once_all('../sources/*.inc.php');

if (!isset($_SESSION["crawl_countries"]))
{
	$handle = fopen("../ressources/code_countries.txt", "rb");
	while (!feof($handle) ) {
		$line = trim(fgets($handle));
		if ($line!="")
		{
			$parts = explode(';', $line);
			$aCountries[trim($parts[1])] = ucwords(strtolower(trim($parts[0])));
		}
	}
	fclose($handle);
	$_SESSION["crawl_countries"] = $aCountries;
}
else
{
	$aCountries = $_SESSION["crawl_countries"];
}

if (!isset($_SESSION["crawl_languages"]))
{
	$handle = fopen("../ressources/code_languages.txt", "rb");
	while (!feof($handle) ) {
		$line = trim(fgets($handle));
		if ($line!="")
		{
			$parts = explode(';', $line);
			$aLanguages[trim($parts[0])] = trim($parts[1]);
		}
	}
	fclose($handle);
	$_SESSION["crawl_languages"] = $aLanguages;
}
else
{
	$aLanguages = $_SESSION["crawl_languages"];
}

if ($action=="showstatus")
{
	$res .= "<center><table>";

	/*
	 $res .= "<tr><td class='head'>Logged as</td><td>";
	$res .= $user->getName();
	if (isset($_SESSION["APP_Parent"]) && $_SESSION["APP_Parent"]!="") {
	$res .= " (" . $_SESSION["APP_Parent"] . ")";
	}
	$res .= "</td></tr>";
	*/
	if (!$_SESSION["mysolrserver_url"]) {
		if ($user->getLevel()==2) {
			$res .= "<tr><td class='head'>Crawler DB</td><td>";
			$res .= $config->get("database.dbname");
			$res .= "</td></tr>";
		}

		$crawler_witness_files_path = $config->get("crawler.witness_files_path");
		if ($crawler_witness_files_path!="")
		{
			// Crawler state
			$res .= "<tr><td class='head'>Crawler state</td><td>";
			//$filecount = count(glob($crawler_witness_files_path . "/crawler*.pid"));
			if (file_exists ($crawler_witness_files_path . "/crawler.pid"))
				//if ($filecount>0)
				$res .= "Crawler is running";
			else
				$res .= "Crawler is not running";
			$res .= "</td></tr>";

			$ndx = 1;
			$monitor = trim($config->get("monitor.process_".$ndx));
			while ($monitor!="" &&  $monitor!="undefined") {
				$aItems = explode("|", $monitor);
				if (count($aItems)==3) {
					$res .= "<tr><td class='head'>" . $aItems[0] . " state</td><td>";
					$filecount = count(glob($aItems[2] . "/j*.xml"));
					if (file_exists ($crawler_witness_files_path . "/" . $aItems[1]))
						$res .= $aItems[0] . " is running - queue size = " . $filecount . " item(s)";
					else
						$res .= $aItems[0] . " is not running - queue size = " . $filecount . " item(s)";
					$res .= "</td></tr>";
				}
				$ndx++;
				$monitor = trim($config->get("monitor.process_".$ndx));
			}
		}
		else
		{
			$res .= "<tr><td class='head'>Crawler state</td><td>";
			$res .= "Unable to provide crawler state";
			$res .= "</td></tr>";
		}
	}

	$mg = mg_connect ($config, "", "", "");
	if ($mg)
	{
		mg_get_value($mg, 'infos', 'value', array("name" => 'version'), $version);
		$res .= "<tr><td class='head'>Version</td><td>";
		$res .= $version;
		$res .= "</td></tr>";
		
		$res .= "<tr><td class='head'>Number of sources</td><td>";
		$res .= mg_row_count($mg, "sources", array('$and' => array(array("deleted" => 0), array("id_account" => intval($id_account_current)))));
		$res .= "</td></tr>";
			
		$res .= "<tr><td class='head'>Number of crawled URLs</td><td>";
		$res .= mg_row_count($mg, "pages", array("id_account" => $id_account_current));
		$res .= "</td></tr>";

		$res .= "<tr><td class='head'>Number of enabled sources</td><td>";
		$res .= mg_row_count($mg, "sources", array('$and' => array(array("enabled" => 1), array("deleted" => 0), array("id_account" => intval($id_account_current)))));				
		$res .= "</td></tr>";

		$res .= "<tr><td class='head'>Number of sources to be crawled</td><td>";
		// TODO: V4 - $stmt->addWhereClause("enabled = 1 and deleted = 0 and (crawl_nexttime is null or crawl_nexttime <= now()) and id_account = " . $id_account_current);
		$res .= mg_row_count($mg, "sources", array('$and' => array(array("enabled" => 1), array("deleted" => 0), array("id_account" => intval($id_account_current)))));				
		$res .= "</td></tr>";

		$res .= "<tr><td class='head'>Number of sources to be crawled for the first time</td><td>";
		// TODO: V4 - $stmt->addWhereClause("enabled = 1 and deleted = 0 and crawl_nexttime is null and id_account = " . $id_account_current);
		$res .= mg_row_count($mg, "sources", array('$and' => array(array("enabled" => 1), array("deleted" => 0), array("id_account" => intval($id_account_current)))));				
		$res .= "</td></tr>";
	}

	$res .= "</table></center>";
	print $res;
	exit();
}


if ($action=="showrunning")
{
	$mg = mg_connect ($config, "", "", "");
	if ($mg)
	{
		$stmt = new mg_stmt_select($mg, "sources");
		//$query_status = array('$or' => array(array(crawl_process_status => "1"), array(crawl_process_status => "2"), array(crawl_process_status => "3"), array(crawl_process_status => "4")));
		//$query = array('$and' => array(array(enabled => "1"), array(deleted => "0"), array(id_account => $id_account_current), array(id_account => $id_account_current), $query_status));
		//TODO: V4
		/*
		 $stmt->setWhereClause("<commit_msg>#41 - Crawler status no correct in Web Admin UI<commit_after><?php
//============================================================================
// (c) 2009-2010, Eolya - All Rights Reserved.
// This source code is the property of Eolya.
// The license applying to this source code is available at :
// http://www.crawl-anywhere.com/licenses/
//============================================================================
require_once("../../init_gpc.inc.php");
require_once("../../init.inc.php");

$action = $_GET["action"];
$limit = $_GET["limit"];
if ($limit=="") $limit="0";

require_once("content.common.ajax.inc.php");

require_once_all('../sources/*.inc.php');

if (!isset($_SESSION["crawl_countries"]))
{
	$handle = fopen("../ressources/code_countries.txt", "rb");
	while (!feof($handle) ) {
		$line = trim(fgets($handle));
		if ($line!="")
		{
			$parts = explode(';', $line);
			$aCountries[trim($parts[1])] = ucwords(strtolower(trim($parts[0])));
		}
	}
	fclose($handle);
	$_SESSION["crawl_countries"] = $aCountries;
}
else
{
	$aCountries = $_SESSION["crawl_countries"];
}

if (!isset($_SESSION["crawl_languages"]))
{
	$handle = fopen("../ressources/code_languages.txt", "rb");
	while (!feof($handle) ) {
		$line = trim(fgets($handle));
		if ($line!="")
		{
			$parts = explode(';', $line);
			$aLanguages[trim($parts[0])] = trim($parts[1]);
		}
	}
	fclose($handle);
	$_SESSION["crawl_languages"] = $aLanguages;
}
else
{
	$aLanguages = $_SESSION["crawl_languages"];
}

if ($action=="showstatus")
{
	$res .= "<center><table>";

	/*
	 $res .= "<tr><td class='head'>Logged as</td><td>";
	$res .= $user->getName();
	if (isset($_SESSION["APP_Parent"]) && $_SESSION["APP_Parent"]!="") {
	$res .= " (" . $_SESSION["APP_Parent"] . ")";
	}
	$res .= "</td></tr>";
	*/
	if (!$_SESSION["mysolrserver_url"]) {
		if ($user->getLevel()==2) {
			$res .= "<tr><td class='head'>Crawler DB</td><td>";
			$res .= $config->get("database.dbname");
			$res .= "</td></tr>";
		}

		$crawler_witness_files_path = $config->get("crawler.witness_files_path");
		if ($crawler_witness_files_path!="")
		{
			// Crawler state
			$res .= "<tr><td class='head'>Crawler state</td><td>";
			//$filecount = count(glob($crawler_witness_files_path . "/crawler*.pid"));
			if (file_exists ($crawler_witness_files_path . "/crawler.pid"))
				//if ($filecount>0)
				$res .= "Crawler is running";
			else
				$res .= "Crawler is not running";
			$res .= "</td></tr>";

			$ndx = 1;
			$monitor = trim($config->get("monitor.process_".$ndx));
			while ($monitor!="" &&  $monitor!="undefined") {
				$aItems = explode("|", $monitor);
				if (count($aItems)==3) {
					$res .= "<tr><td class='head'>" . $aItems[0] . " state</td><td>";
					$filecount = count(glob($aItems[2] . "/j*.xml"));
					if (file_exists ($crawler_witness_files_path . "/" . $aItems[1]))
						$res .= $aItems[0] . " is running - queue size = " . $filecount . " item(s)";
					else
						$res .= $aItems[0] . " is not running - queue size = " . $filecount . " item(s)";
					$res .= "</td></tr>";
				}
				$ndx++;
				$monitor = trim($config->get("monitor.process_".$ndx));
			}
		}
		else
		{
			$res .= "<tr><td class='head'>Crawler state</td><td>";
			$res .= "Unable to provide crawler state";
			$res .= "</td></tr>";
		}
	}

	$mg = mg_connect ($config, "", "", "");
	if ($mg)
	{
		mg_get_value($mg, 'infos', 'value', array("name" => 'version'), $version);
		$res .= "<tr><td class='head'>Version</td><td>";
		$res .= $version;
		$res .= "</td></tr>";
		
		$res .= "<tr><td class='head'>Number of sources</td><td>";
		$res .= mg_row_count($mg, "sources", array('$and' => array(array("deleted" => "0"), array("id_account" => intval($id_account_current)))));
		$res .= "</td></tr>";
			
		// TODO : pages collection do not exists anymore
		//$res .= "<tr><td class='head'>Number of crawled URLs</td><td>";
		//$res .= mg_row_count($mg, "pages", array("id_account" => $id_account_current));
		//$res .= "</td></tr>";

		$res .= "<tr><td class='head'>Number of enabled sources</td><td>";
		$res .= mg_row_count($mg, "sources", array('$and' => array(array("enabled" => "1"), array("deleted" => "0"), array("id_account" => intval($id_account_current)))));				
		$res .= "</td></tr>";

		$res .= "<tr><td class='head'>Number of sources to be crawled</td><td>";
		// TODO: V4 - $stmt->addWhereClause("enabled = 1 and deleted = 0 and (crawl_nexttime is null or crawl_nexttime <= now()) and id_account = " . $id_account_current);
		$res .= mg_row_count($mg, "sources", array('$and' => array(array("enabled" => "1"), array("deleted" => "0"), array("id_account" => intval($id_account_current)))));				
		$res .= "</td></tr>";

		$res .= "<tr><td class='head'>Number of sources to be crawled for the first time</td><td>";
		// TODO: V4 - $stmt->addWhereClause("enabled = 1 and deleted = 0 and crawl_nexttime is null and id_account = " . $id_account_current);
		$res .= mg_row_count($mg, "sources", array('$and' => array(array("enabled" => "1"), array("deleted" => "0"), array("id_account" => intval($id_account_current)))));				
		$res .= "</td></tr>";
	}

	$res .= "</table></center>";
	print $res;
	exit();
}


if ($action=="showrunning")
{
	$mg = mg_connect ($config, "", "", "");
	if ($mg)
	{
		$stmt = new mg_stmt_select($mg, "sources");
		//$query_status = array('$or' => array(array(crawl_process_status => "1"), array(crawl_process_status => "2"), array(crawl_process_status => "3"), array(crawl_process_status => "4")));
		//$query = array('$and' => array(array(enabled => "1"), array(deleted => "0"), array(id_account => $id_account_current), array(id_account => $id_account_current), $query_status));
		//TODO: V4
		/*
		 $stmt->setWhereClause("
{'fraction_non_alphanumeric': 0.27366273396611374, 'fraction_numerical': 0.007628847689168811, 'mean_word_length': 4.2682242990654204, 'pattern_counts': {'":': 0, '<': 147, '<?xml version=': 0, '>': 217, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3829174', 'n_tokens_mistral': 4441, 'n_tokens_neox': 4041, 'n_words': 774}