Location: PHPKode > projects > Sound PHP Engine > s-p-e-0.3.0/s-p-e-0.3.0/data/robot.php
<?php
// ===================================================== 
// 
// s-p-e - Content management system. 
// Copyright (C) 2004, 2005, 2010, 2011 Vladimir B. Tsarkov
// 
// This file is part of s-p-e. 
// 
// s-p-e is free software; you can redistribute it and/or modify 
// it under the terms of the GNU General Public License as published by 
// the Free Software Foundation, either version 3 of the License, or 
// (at your option) any later version. 
// 
// s-p-e is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
// GNU General Public License for more details. 
// 
// You should have received a copy of the GNU General Public License 
// along with s-p-e. If not, see <http://www.gnu.org/licenses/>.
//
// ------
//
//  You can contact me via e-mail: lipetsk-gnu-lug at bk period ru
//
//  robot.php
//
//  Abstract: Robot that indexes the data to be searched over.
//  
//  Revision History:
// 
//	1  2005-09-03  vbt
//	2  2010-06-24  vbt
//	3  2011-11-15  vbt
// 4  2011-12-23  vbt
//
// =====================================================
header("Content-Type: text/html; charset=UTF-8");

include("configure/specfg.php"); 
include("../include/functions.php");

cache();

session_set_save_handler("open", "close", "read", "write", "destroy", "gc");
session_start();

gc();

redirect(read(session_id()));

if(read(session_id()) == "administrator")
{
	language($cfg["deflangadmin"]);	
	echo "<html>
	<head>

	<title>".(_("s-p-e Administrator's Panel"))."</title>"; 
	echo "<LINK rel='stylesheet' type='text/css' href='../skin/".($cfg["skin"])."/style.css'>
	</head>

	<body class='admin'>
	<fieldset>
	<legend><font class='s-normal' id='w-bold'>".(_("Robot"))."</font></legend>
	<font class='s-normal' id='w-normal'>
	".(_("To make the search engine work effectively, you should index your data regularly."))."
	</font>
	<br><br>
	<form action='robot.php' method='post'>
	<input type='submit' name='robot' value='".(_("Start Indexing Process"))."'></form>";
	

   if(isset($_POST["robot"]))
   {

	connect($cfg["host"], $cfg["user"], $cfg["password"], $cfg["database"], $connector);
	
	mysql_query("drop table if exists ".($cfg["prefix"])."tmpsearch", $connector) or die("error #102-1");
		
	mysql_query("create table ".($cfg["prefix"])."tmpsearch 
		as select concat('".($cfg["prefix"])."',pnid) pointer, 
		pnid type, 
		concat('".($cfg["prefix"])."',pnid) rpointer, 
		num id from ".($cfg["prefix"])."partition where robot is null", $connector) 
		or die("error #102-2");

	mysql_query("alter table ".($cfg["prefix"])."tmpsearch modify pointer text", $connector) or die("error #102-3");

	mysql_query("update ".($cfg["prefix"])."tmpsearch 
		set pointer=concat('select num, theme, intro, date, timer 
		from ',pointer,' 
		order by date desc, 
		timer desc;')", $connector) 
		or die("error #102-4");

	mysql_query("alter table ".($cfg["prefix"])."tmpsearch modify rpointer text", $connector) or die("error #102-5");

	mysql_query("update ".($cfg["prefix"])."tmpsearch 
		set rpointer=concat('update ',rpointer,' 
		set robot=1 
		where robot is null;')", $connector) 
		or die("error #102-6");
		
	$result = mysql_query("select num, pnid, partname, date, timer 
		  	       from ".($cfg["prefix"])."partition where robot is null") 
			       or die("error #102-7");
	while($row = mysql_fetch_array($result))
	{
		if(strlen($row["pnid"]) == 10)
		{
			$type = 1;
		}
		if(strlen($row["pnid"]) == 11)
		{
			$type = 2;
		}
			
		mysql_query("insert into ".($cfg["prefix"])."search 
			(type, id, number, theme, intro, date, timer) 
			values ('".($type)."', 
			'".($row["num"])."', 
			'0', 
			'".(addslashes($row["partname"]))."', 
			'0', 
			'".($row["date"])."', 
			'".($row["timer"])."')", $connector) 
			or die("error #102-8");
		mysql_query("update ".($cfg["prefix"])."partition 
			set robot=1 
			where robot is null 
			and num='".($row["num"])."'");
	}
	mysql_free_result($result);
		
	$result = mysql_query("select type, id, pointer, rpointer 
		from ".($cfg["prefix"])."tmpsearch") 
		or die("error #102-9");
	while($row = mysql_fetch_array($result))
	{
		if(strlen($row["type"]) == 10)
		{
			$type = 1;
		}
		if(strlen($row["type"]) == 11)
		{
			$type = 2;
		}
		$result1 = mysql_query("".($row["pointer"])."") or die("error #102-10");
		while($row1 = mysql_fetch_array($result1))
		{
			mysql_query("insert into ".($cfg["prefix"])."search 
				(type, id, number, theme, intro, date, timer) 
				values ('".($type)."', 
				'".($row["id"])."', 
				'".($row1["num"])."', 
				'".(addslashes($row1["theme"]))."', 
				'".(addslashes($row1["intro"]))."', 
				'".($row1["date"])."', 
				'".($row1["timer"])."')", $connector) 
				or die("error #102-11");
		}
		mysql_free_result($result1);
		mysql_query("".($row["rpointer"])."") or die("error #102-12");
	}
	mysql_free_result($result);
	mysql_close($connector);
		
	connect($cfg["host"], $cfg["user"], $cfg["password"], $cfg["database"], $connector);
	$indexCheck = mysql_query("SHOW INDEX FROM se_search") or die("error #102-13");
	if(mysql_num_rows($indexCheck) != 0)
		mysql_query("DROP INDEX sindex on ".($cfg["prefix"])."search") or die("error #102-14");
		
	mysql_query("create index sindex on ".($cfg["prefix"])."search 
		(theme, intro(10), date, timer)", $connector) 
		or die("error #102-15");
	mysql_query("drop table if exists ".($cfg["prefix"])."tmpsearch", $connector) or die("error #102-16");
	mysql_close($connector);
		
	echo "<font class='s-normal' color='white'>".(_("Indexing process finished successfully")).".</font>";
  }
  echo "</fieldset>
  <p>
  <font class='s-normal'>
  ".(_("Back to the"))."&nbsp;<a href='admin.php'>".(_("s-p-e Administrator's Page"))."</a>.
  </font>
  </p>
  </body>
  </html>";
} 
else 
{
	echo _("Access denied.");
}
?>
Return current item: Sound PHP Engine