Location: PHPKode > projects > Sound PHP Engine > s-p-e-0.3.0/s-p-e-0.3.0/data/parc.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
//
//  parc.php
//
//  Abstract: Managing the archives.
//  
//  Revision History:
// 
//	1  2004-03-27 - 2005-07-02  vbt
//	2  2005-07-22  vbt
//	3  2005-10-30  vbt
//	4  2010-06-24  vbt
//	5  2011-01-22  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")
{
	echo "<html>
	<head>
	<link rel='stylesheet' type='text/css' href='../skin/".($cfg["skin"])."/style.css'>	
	</head>
	<body>";	
	language($cfg["deflangadmin"]);
	
	if(isset($_POST["id"]))
	{
		$id = base64_decode($_POST["id"]);
	}
	if(isset($_POST["num"]))
	{
		$num = base64_decode($_POST["num"]);
	}
	if(isset($_POST["partname"]))
	{
		$partname = base64_decode($_POST["partname"]);
	}
	
	if(isset($partname) && ctype_digit($id) && ctype_digit($num))
	{
		connect($cfg["host"], $cfg["user"], $cfg["password"], $cfg["database"], $connector);
		$result = mysql_query("select pnid 
			from ".($cfg["prefix"])."partition 
			where num='$id' 
			and partname='$partname'", $connector) 
			or die("error #102-1");
		while($row = mysql_fetch_array($result))
		{
			$pointer = $row["pnid"];
		}
		mysql_free_result($result);
		$result = mysql_query("select num, login, mail, theme, intro, text, date, timer 
			from ".($cfg["prefix"].$pointer)." 
			where num='$num'", $connector) 
			or die("error #102-2");
		if(mysql_num_rows($result) != 0)
		{
			while($row = mysql_fetch_array($result))
			{
				$login = $row["login"];
				$mail = $row["mail"];
				$theme = $row["theme"];
				$intro = $row["intro"];
				$text = $row["text"];
				$date = $row["date"];
				$timer = $row["timer"];
				$number = $row["num"];
			}
			mysql_free_result($result);

			$rcheck = mysql_query("select num, archiveid 
				from ".($cfg["prefix"])."archive
				where partname='$partname' 
				and pnid='$pointer'", $connector) 
				or die("error #102-3");

			if(mysql_num_rows($rcheck) == 0)
			{
				$srcpid = "".mt_rand(11111, 99999).strftime("%j").strftime("%m").strftime("%d")."";
				
				mysql_query("insert into ".($cfg["prefix"])."archive (partname, archiveid, pnid, timer) 
					values ('$partname', '$srcpid', '$pointer', now())", $connector) 
					or die("error #102-4");	
				
				mysql_query("create table ".($cfg["prefix"].$srcpid)." 
					(num integer auto_increment, 
					login varchar(10) not null, 
					mail varchar(35) not null, 
					theme varchar(255) not null, 
					intro text not null, 
					text text not null, 
					date date not null, 
					timer time not null, 
					key(num))", $connector) 
					or die("error #102-5");
				
				echo "<font class='positive'>".(_("Stage 1 finished successfully."))."</font>";
				
				mysql_query("insert into ".($cfg["prefix"].$srcpid)." 
				(login, mail, theme, intro, text, date, timer) 
				values ('$login', '$mail', '$theme', '$intro', '$text', '$date', '$timer')", $connector) 
				or die("error #102-6");
				
				echo "<br>
				<font class='positive'>".(_("Stage 2 finished successfully."))."</font>";
				
				mysql_query("delete 
					from ".($cfg["prefix"].$pointer)." 
					where num='$num'", $connector) 
					or die("error #102-7");
				
				mysql_query("delete 
					from ".($cfg["prefix"])."comment 
					where recid='$num' 
					and partid='$id'", $connector) 
					or die("error #102-8");
				
				echo "<br>
				<font class='positive'>".(_("Archivation process finished successfully."))."</font>";
			
			} 
			else 
			{
				
				echo "<font class='negative'>".(_("Archive"))."</font>
				&nbsp;$partname&nbsp;
				<font class='negative'>".(_("already exists."))."</font>";
				
				while($row = mysql_fetch_array($rcheck, MYSQL_NUM))
				{
					$archiveid = $row[1];
				}
				
				mysql_query("insert into ".($cfg["prefix"].$archiveid)." 
					(login, mail, theme, intro, text, date, timer) 
					values ('$login', 
					'$mail', 
					'".(addslashes($theme))."', 
					'".(addslashes($intro))."', 
					'".(addslashes($text))."', 
					'$date', 
					'$timer')", $connector) 
					or die("error #102-9");
				
				echo "<br><font class='positive'>".(_("Stage 2 finished successfully."))."</font>";
				
				mysql_query("delete 
					from ".($cfg["prefix"].$pointer)." 
					where num='$num'", $connector) 
					or die("error #102-10");
				
				mysql_query("delete 
					from ".($cfg["prefix"])."comment 
					where recid='$num' 
					and partid='$id'", $connector) 
					or die("error #102-11");
				
				echo "<br>
				<font class='positive'>".(_("Archivation process finished successfully."))."
				</font>";
			}
			mysql_free_result($rcheck);
		}
		mysql_close($connector);
	}
	if(isset($_POST['drop']))
	{
		$drop = $_POST['drop'];
	}
	if(isset($drop))
	{
		$narc = $_POST['narc'];
		$arcn = $_POST['arcn'];
		if($arcn == 0)
		{
			$integer = 10;
		}
		if($arcn == 1)
		{
			$integer = 11;
		}
		if($narc)
		{
			$narc = space($narc);
			
			connect($cfg["host"], $cfg["user"], $cfg["password"], $cfg["database"], $connector);
			$result = mysql_query("select archiveid 
				from ".($cfg["prefix"])."archive 
				where partname='$narc' 
				and pnid regexp '^[0-9]{".$integer."}$'", $connector) 
				or die("error #102-12");
			if(mysql_num_rows($result) == 0)
			{
				echo "<font class='negative'>".(_("No archives with the name"))."</font>
				&nbsp;$narc!";
			} 
			else 
			{
				while($row = mysql_fetch_array($result, MYSQL_NUM))
				{
					$pointer = $row[0];
				}
				mysql_free_result($result);
				
				mysql_query("drop table ".($cfg["prefix"].$pointer)."", $connector) or die("error #102");
				
				mysql_query("delete 
					from ".($cfg["prefix"])."archive 
					where partname='$narc' 
					and pnid regexp '^[0-9]{".$integer."}$'", $connector) 
					or die("error #102-13");
				
				echo "<font class='positive'>".(_("Archive"))."</font>
				&nbsp;$narc&nbsp;
				<font class='positive'>".(_("removed successfully."))."</font>";
				
				mysql_close($connector);
			}
		} 
		else 
		{
			echo "<font class='negative'>".(_("Please, specify the name of the archive."))."</font>";
		}
	}
	echo "<p>
	<font class='s-normal'>
	".(_("Back to the"))." <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