Location: PHPKode > projects > Sound PHP Engine > s-p-e-0.3.0/s-p-e-0.3.0/include/page.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
//
//  page.php
//
//  Abstract: Second column.
//  
//  Revision History:
// 
//	1  2004-03-27 - 2005-07-02  vbt
//	2  2005-07-21  vbt
//	3  2005-08-03  vbt
//	4  2005-09-18  vbt
//	5  2010-06-24  vbt
//	6  2011-01-22  vbt
// 7  2011-05-14  vbt
//
// =====================================================

if((isset($id) == false) && (isset($out) == true))
{
	connect($cfg["host"], $cfg["user"], $cfg["password"], $cfg["database"], $connector);
	
	mysql_query("drop table if exists ".($cfg["prefix"])."tmpoutput", $connector) or die("error #102-1");
	mysql_query("delete from ".($cfg["prefix"])."output", $connector) or die("error #102-2");

	if($out == "news")
	{
		mysql_query("create table ".($cfg["prefix"])."tmpoutput 
			as select concat('".($cfg["prefix"])."',pnid) pointer, num id 
			from ".($cfg["prefix"])."partition 
			where pnid regexp ('^[0-9]{10}$')", $connector) 
			or die("error #102-3");
	}
	if($out == "articles")
	{
		mysql_query("create table ".($cfg["prefix"])."tmpoutput 
			as select concat('".($cfg["prefix"])."',pnid) pointer, num id 
			from ".($cfg["prefix"])."partition 
			where pnid regexp ('^[0-9]{11}$')", $connector) 
			or die("error #102-4");
	}
	if($out == "all")
	{
		mysql_query("create table ".($cfg["prefix"])."tmpoutput 
			as select concat('".($cfg["prefix"])."',pnid) pointer, pnid type, num id 
			from ".($cfg["prefix"])."partition", $connector) 
			or die("error #102-5");
	}
	
	mysql_query("alter table ".($cfg["prefix"])."tmpoutput modify pointer varchar(255)", $connector) 
		or die("error #102-6");
	mysql_query("update ".($cfg["prefix"])."tmpoutput 
		    set pointer=concat('select num, login, mail, theme, intro, date, timer from ',pointer,' 
		    where state is null;')", $connector) 
		    or die("error #102-7");
	$result = mysql_query("select type, id, pointer from ".($cfg["prefix"])."tmpoutput") or die("error #102-8");
	while($row = mysql_fetch_array($result, MYSQL_NUM))
	{
		if(strlen($row[0]) == 10)
		{
			$type = 1;
		}
		if(strlen($row[0]) == 11)
		{
			$type = 2;
		}
		$result1 = mysql_query("".($row[2])."") or die("error #102-9");
		while($row1 = mysql_fetch_array($result1))
		{
			mysql_query("insert into ".($cfg["prefix"])."output 
			(type, id, number, login, mail, theme, intro, date, timer) 
			values ('".($type)."', 
			'".($row[1])."', 
			'".($row1["num"])."', 
			'".($row1["login"])."', 
			'".($row1["mail"])."', 
			'".(addslashes($row1["theme"]))."', 
			'".(addslashes($row1["intro"]))."', 
			'".($row1["date"])."', 
			'".($row1["timer"])."')", $connector) 
			or die("error #102-10");
		}
		mysql_free_result($result1);
	}
	mysql_free_result($result);
	unset($type);
	
	$result = mysql_query("select count(num) from ".($cfg["prefix"])."output", $connector) or die("error #102-11");
	while($row = mysql_fetch_array($result, MYSQL_NUM))
	{
		$total = $row[0];
	}
	mysql_free_result($result);
	
	$pagequantity = ceil($total/$cfg["mainlimit"]);
	
	if(isset($page) == false || ctype_digit($page) == false)
	{
		$page = 1;
	}
	
	$offset = ($page - 1) * $cfg["mainlimit"];
	
	if($cfg["mainlimit"] < $total)
	{
		for($i = 1; $i <= $pagequantity; $i++)
		{
			$pagearray[$i] = $i;
		}
		for($i = 1; isset($pagearray[$i]); $i++)
		{
			if(sizeof($pagearray) == 1)
			{
				$pageline = false;
			} 
			else 
			{
  			  if($i == 1)
			  {
			    $pageline = "| "."<a href='index.php?page=$i&lng=$shortlng'>$pagearray[$i]</a>"." | ";
			  } 
			  else 
			  {
			    $pageline = $pageline."<a href='index.php?page=$i&lng=$shortlng'>$pagearray[$i]</a>"." | ";
			  }
			}
		}
	}
	
	$result = mysql_query("select type, id, number, login, mail, theme, intro, date, timer 
		from ".($cfg["prefix"])."output 
		order by date desc, timer desc 
		limit $offset, ".($cfg["mainlimit"])."", $connector) 
		or die("error #102-12");
	
	mysql_close($connector);
	unset($connector);
	
	while($row = mysql_fetch_array($result, MYSQL_NUM))
	{
		$type = $row[0];
		$id = $row[1];
		echo "<font class='s-normal' id='w-bold'>".$row[5]."</font>";
		echo "<p>
		<font class='s-normal' id='w-normal'>".(_("Published"))."&nbsp;:&nbsp;".$row[7].";&nbsp;".$row[8]."</font>
		</p>";
		echo "<p>
		<font class='s-normal' id='w-normal'>
		".$row[6]."&nbsp;
			<a href='index.php?ins=view&id=$id&rid=".($row[2])."&lng=$shortlng' title='".(_("details"))."'>
			&raquo;&raquo;&raquo;
			</a>
		</font>
		</p>";
		echo "<p>
		<font class='s-normal' id='w-normal'>
		<a href='index.php?ins=com&id=$id&rid=".($row[2])."&lng=$shortlng' title='".(_("comments"))."'>
		<i>".(_("Comments"))."&nbsp;["; 
		echo comments($id, $row[2], $cfg["host"], $cfg["user"], $cfg["password"], $cfg["database"], $cfg["prefix"]); 
		echo "]</i>
		</a>
		</font>
		</p>";
		
		line();
	}
	mysql_free_result($result);
	
	if(isset($pageline))
	{
		echo search_pager($pageline, $page, "index.php?lng=$shortlng&page=", $pagequantity);		
	}
	
	connect($cfg["host"], $cfg["user"], $cfg["password"], $cfg["database"], $connector);
	mysql_query("drop table if exists ".($cfg["prefix"])."tmpoutput", $connector) or die("error #102-13");
	mysql_query("delete from ".($cfg["prefix"])."output", $connector) or die("error #102-14");
	mysql_close($connector);
	
	/*
	if($out == "articles")
	{
		echo "&nbsp;&nbsp;&nbsp;
		<a href='index.php?ins=arc&type=2' title='".(_("articles archive"))."'>
		<font class='s-normal' id='w-normal'>
		".(_("articles archive"))."
		</font>
		</a>";
	}
	if($out == "news")
	{
		echo "&nbsp;&nbsp;&nbsp;<font class='s-normal' id='w-normal'>
		<a href='index.php?ins=arc&type=1' title='".(_("news archive"))."'>
		".(_("news archive"))."
		</a>
		</font>";
	}
	if($out == "all")
	{
		echo "&nbsp;&nbsp;&nbsp;<font class='s-normal' id='w-normal'>
		<a href='index.php?ins=arc&type=1' title='".(_("news archive"))."'>
		".(_("news archive"))."</a>
		</font>";
		echo "<p>
		&nbsp;&nbsp;&nbsp;
		<font class='s-normal' id='w-normal'>
		<a href='index.php?ins=arc&type=2' title='".(_("articles archive"))."'>
		".(_("articles archive"))."
		</a>
		</font>
		</p>";
	}*/
	
	unset($out);
	unset($id);
}

if(isset($pointer) && (isset($ins) == false))
{
	connect($cfg["host"], $cfg["user"], $cfg["password"], $cfg["database"], $connector);
	
	$result = mysql_query("select count(num) from ".($cfg["prefix"].$pointer)."", $connector) or die("error #102-15");
	while($row = mysql_fetch_array($result, MYSQL_NUM))
	{
		$total = $row[0];
	}
	mysql_free_result($result);
	
	$pagequantity = ceil($total/$cfg["partlimit"]);
	
	if(isset($page) == false || ctype_digit($page) == false)
	{
		$page = 1;
	}
	
	$offset = ($page - 1) * $cfg["partlimit"];
	
	if($cfg["partlimit"] < $total)
	{
		for($i = 1; $i <= $pagequantity; $i++)
		{
			$pagearray[$i] = $i;
		}
		for($i = 1; isset($pagearray[$i]); $i++)
		{
			if(sizeof($pagearray) == 1)
			{
				$pageline = false;
			} 
			else 
			{
			  if($i == 1)
			  {
				$pageline = "| "."<a href='index.php?id=$id&lng=$lng&page=$i'>$pagearray[$i]</a>"." | ";
			  } 
			  else 
			  {
				$pageline = $pageline."<a href='index.php?id=$id&lng=$lng&page=$i'>$pagearray[$i]</a>"." | ";
			  }
			}
		}
	}
	
	$result = mysql_query("select num, login, mail, theme, intro, date, text, timer 
		from ".($cfg["prefix"].$pointer)." 
		order by date desc, timer desc limit $offset, ".($cfg["partlimit"])."", $connector) 
		or die("error #102-16");
	if(mysql_num_rows($result) == 0)
	{
		echo "error #101-1";
	}
	mysql_close($connector);
	
	while($row = mysql_fetch_array($result, MYSQL_NUM))
	{
		echo "<font class='s-normal' id='w-bold'>".$row[3]."</font>
		<br>
		<font class='s-normal' id='w-normal'>".(_("Published"))."&nbsp;:&nbsp;".$row[5].";&nbsp;".$row[7]."</font>
		<p>
		<font class='s-normal' id='w-normal'>
			".$row[4]."&nbsp;
			<a href='index.php?ins=view&id=$id&rid=".($row[0])."&lng=$shortlng' title='".(_("details"))."'>
			&raquo;&raquo;&raquo;
			</a>
		</font>
		</p>
		<p>

		<font class='s-normal' id='w-normal'>
	         <a href='index.php?ins=com&id=$id&rid=".($row[0])."&lng=$shortlng' title='".(_("comments"))."'>
	         <i>".(_("Comments"))."&nbsp;
	      ["; comments($id, $row[0], $cfg["host"], $cfg["user"], $cfg["password"], $cfg["database"], $cfg["prefix"]); 
				echo "]</i>
		      </a>
		</font>
		</p>";
		
		line();
	}
	mysql_free_result($result);
	/*
	if(strlen($pointer) == 10)
	{
		echo "&nbsp;&nbsp;&nbsp;
		<a href='index.php?ins=arc&type=1' title='".(_("news archive"))."'>
		<font class='std'>".(_("news archive"))."</font>
		</a>";
	}
	if(strlen($pointer) == 11)
	{
		echo "<br>&nbsp;&nbsp;&nbsp;
		<a href='index.php?ins=arc&type=2' title='".(_("articles archive"))."'>
		<font class='std'>".(_("articles archive"))."</font>
		</a>";
	}*/
	
	if(isset($pageline))
	{
		echo search_pager($pageline, $page, "index.php?id=$id&lng=$lng&page=", $pagequantity);
	}
}
?>
Return current item: Sound PHP Engine