<?
/** A PHP class to access MySQL database with convenient methods
* in an object oriented way, and with a powerful debug system.\n
* Licence: LGPL \n
* Web site: http://slaout.linux62.org/
* @version 1.0
* @author Sébastien Laoût (slaout@linux62.org)
*/
class DB
{
/** Put this variable to true if you want ALL queries to be debugged by default:
*/
var $defaultDebug = false;
/** INTERNAL: The start time, in miliseconds.
*/
var $mtStart;
/** INTERNAL: The number of executed queries.
*/
var $nbQueries;
/** INTERNAL: The last result ressource of a query().
*/
var $lastResult;
//pagination
var $sql;
var $result;
var $get_var = QS_VAR;
var $rows_on_page = NUM_ROWS;
var $rows_on_musicpage = MUSICNUM_ROWS;
var $rows_on_videopage = VIDEONUM_ROWS;
var $rows_on_communitypage = COMMUNITYNUM_ROWS;
var $rows_on_artistpage = ARTIST_ROWS;
var $rows_on_digitalpage = DIGITAL_ROWS;
var $str_forward = STR_FWD;
var $str_backward = STR_BWD;
var $all_rows;
var $num_rows;
var $page;
var $number_pages;
var $a=1;
/** Connect to a MySQL database to be able to use the methods below.
*/
function DB($base, $server, $user, $pass)
{
$this->mtStart = $this->getMicroTime();
$this->nbQueries = 0;
$this->lastResult = NULL;
mysql_connect($server, $user, $pass) or die('Server connexion not possible.');
mysql_select_db($base) or die('Database connexion not possible.');
}
/** Query the database.
* @param $query The query.
* @param $debug If true, it output the query and the resulting table.
* @return The result of the query, to use with fetchNextObject().
*/
function query($query, $debug = -1)
{
$this->nbQueries++;
$this->lastResult = mysql_query($query) or $this->debugAndDie($query);
$this->debug($debug, $query, $this->lastResult);
return $this->lastResult;
}
/** Do the same as query() but do not return nor store result.\n
* Should be used for INSERT, UPDATE, DELETE...
* @param $query The query.
* @param $debug If true, it output the query and the resulting table.
*/
function execute($query, $debug = -1)
{
$this->nbQueries++;
mysql_query($query) or $this->debugAndDie($query);
$this->debug($debug, $query);
}
/** Convenient method for mysql_fetch_object().
* @param $result The ressource returned by query(). If NULL, the last result returned by query() will be used.
* @return An object representing a data row.
*/
function fetchNextObject($result = NULL)
{
if ($result == NULL)
$result = $this->lastResult;
if ($result == NULL || mysql_num_rows($result) < 1)
return NULL;
else
return mysql_fetch_object($result);
}
/** Get the number of rows of a query.
* @param $result The ressource returned by query(). If NULL, the last result returned by query() will be used.
* @return The number of rows of the query (0 or more).
*/
function numRows($result = NULL)
{
if ($result == NULL)
return mysql_num_rows($this->lastResult);
else
return mysql_num_rows($result);
}
/** Get the result of the query as an object. The query should return a unique row.\n
* Note: no need to add "LIMIT 1" at the end of your query because
* the method will add that (for optimisation purpose).
* @param $query The query.
* @param $debug If true, it output the query and the resulting row.
* @return An object representing a data row (or NULL if result is empty).
*/
function queryUniqueObject($query, $debug = -1)
{
$query = "$query LIMIT 1";
$this->nbQueries++;
$result = mysql_query($query) or $this->debugAndDie($query);
$this->debug($debug, $query, $result);
return mysql_fetch_object($result);
}
/** Get the result of the query as value. The query should return a unique cell.\n
* Note: no need to add "LIMIT 1" at the end of your query because
* the method will add that (for optimisation purpose).
* @param $query The query.
* @param $debug If true, it output the query and the resulting value.
* @return A value representing a data cell (or NULL if result is empty).
*/
function queryUniqueValue($query, $debug = -1)
{
$query = "$query LIMIT 1";
$this->nbQueries++;
$result = mysql_query($query) or $this->debugAndDie($query);
$line = mysql_fetch_row($result);
$this->debug($debug, $query, $result);
return $line[0];
}
/** Get the maximum value of a column in a table, with a condition.
* @param $column The column where to compute the maximum.
* @param $table The table where to compute the maximum.
* @param $where The condition before to compute the maximum.
* @return The maximum value (or NULL if result is empty).
*/
function maxOf($column, $table, $where)
{
return $this->queryUniqueValue("SELECT MAX(`$column`) FROM `$table` WHERE $where");
}
/** Get the maximum value of a column in a table.
* @param $column The column where to compute the maximum.
* @param $table The table where to compute the maximum.
* @return The maximum value (or NULL if result is empty).
*/
function maxOfAll($column, $table)
{
return $this->queryUniqueValue("SELECT MAX(`$column`) FROM `$table`");
}
/** Get the count of rows in a table, with a condition.
* @param $table The table where to compute the number of rows.
* @param $where The condition before to compute the number or rows.
* @return The number of rows (0 or more).
*/
function countOf($table, $where)
{
return $this->queryUniqueValue("SELECT COUNT(*) FROM `$table` WHERE $where");
}
/** Get the count of rows in a table.
* @param $table The table where to compute the number of rows.
* @return The number of rows (0 or more).
*/
function countOfAll($table)
{
return $this->queryUniqueValue("SELECT COUNT(*) FROM `$table`");
}
/** Internal function to debug when MySQL encountered an error,
* even if debug is set to Off.
* @param $query The SQL query to echo before diying.
*/
function debugAndDie($query)
{
$this->debugQuery($query, "Error");
die("<p style=\"margin: 2px;\">".mysql_error()."</p></div>");
}
/** Internal function to debug a MySQL query.\n
* Show the query and output the resulting table if not NULL.
* @param $debug The parameter passed to query() functions. Can be boolean or -1 (default).
* @param $query The SQL query to debug.
* @param $result The resulting table of the query, if available.
*/
function debug($debug, $query, $result = NULL)
{
if ($debug === -1 && $this->defaultDebug === false)
return;
if ($debug === false)
return;
$reason = ($debug === -1 ? "Default Debug" : "Debug");
$this->debugQuery($query, $reason);
if ($result == NULL)
echo "<p style=\"margin: 2px;\">Number of affected rows: ".mysql_affected_rows()."</p></div>";
else
$this->debugResult($result);
}
/** Internal function to output a query for debug purpose.\n
* Should be followed by a call to debugResult() or an echo of "</div>".
* @param $query The SQL query to debug.
* @param $reason The reason why this function is called: "Default Debug", "Debug" or "Error".
*/
function debugQuery($query, $reason = "Debug")
{
$color = ($reason == "Error" ? "red" : "orange");
echo "<div style=\"border: solid $color 1px; margin: 2px;\">".
"<p style=\"margin: 0 0 2px 0; padding: 0; background-color: #DDF;\">".
"<strong style=\"padding: 0 3px; background-color: $color; color: white;\">$reason:</strong> ".
"<span style=\"font-family: monospace;\">".htmlentities($query)."</span></p>";
}
/** Internal function to output a table representing the result of a query, for debug purpose.\n
* Should be preceded by a call to debugQuery().
* @param $result The resulting table of the query.
*/
function debugResult($result)
{
echo "<table border=\"1\" style=\"margin: 2px;\">".
"<thead style=\"font-size: 80%\">";
$numFields = mysql_num_fields($result);
// BEGIN HEADER
$tables = array();
$nbTables = -1;
$lastTable = "";
$fields = array();
$nbFields = -1;
while ($column = mysql_fetch_field($result)) {
if ($column->table != $lastTable) {
$nbTables++;
$tables[$nbTables] = array("name" => $column->table, "count" => 1);
} else
$tables[$nbTables]["count"]++;
$lastTable = $column->table;
$nbFields++;
$fields[$nbFields] = $column->name;
}
for ($i = 0; $i <= $nbTables; $i++)
echo "<th colspan=".$tables[$i]["count"].">".$tables[$i]["name"]."</th>";
echo "</thead>";
echo "<thead style=\"font-size: 80%\">";
for ($i = 0; $i <= $nbFields; $i++)
echo "<th>".$fields[$i]."</th>";
echo "</thead>";
// END HEADER
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
for ($i = 0; $i < $numFields; $i++)
echo "<td>".htmlentities($row[$i])."</td>";
echo "</tr>";
}
echo "</table></div>";
$this->resetFetch($result);
}
/** Get how many time the script took from the begin of this object.
* @return The script execution time in seconds since the
* creation of this object.
*/
function getExecTime()
{
return round(($this->getMicroTime() - $this->mtStart) * 1000) / 1000;
}
/** Get the number of queries executed from the begin of this object.
* @return The number of queries executed on the database server since the
* creation of this object.
*/
function getQueriesCount()
{
return $this->nbQueries;
}
/** Go back to the first element of the result line.
* @param $result The resssource returned by a query() function.
*/
function resetFetch($result)
{
if (mysql_num_rows($result) > 0)
mysql_data_seek($result, 0);
}
/** Get the id of the very last inserted row.
* @return The id of the very last inserted row (in any table).
*/
function lastInsertedId()
{
return mysql_insert_id();
}
/** Close the connexion with the database server.\n
* It's usually unneeded since PHP do it automatically at script end.
*/
function close()
{
mysql_close();
}
/** Internal method to get the current time.
* @return The current time in seconds with microseconds (in float format).
*/
function getMicroTime()
{
list($msec, $sec) = explode(' ', microtime());
return floor($sec / 1000) + $msec;
}
//My additions
function resultsetToArray($result)
{
$returnArray=array();
while($row=mysql_fetch_array($result))
{
array_push($returnArray,$row);
}
return $returnArray;
}
// Pagination
// sets the current page number
function set_page() {
$this->page = (isset($_REQUEST[$this->get_var]) && $_REQUEST[$this->get_var] != "") ? $_REQUEST[$this->get_var] : 0;
return $this->page;
}
// gets the total number of records
function get_total_rows() {
$tmp_result = mysql_query($this->sql);
$this->all_rows = mysql_num_rows($tmp_result);
mysql_free_result($tmp_result);
return $this->all_rows;
}
// get the totale number of result pages
function get_num_pages() {
$this->number_pages = ceil($this->get_total_rows() / $this->rows_on_page);
return $this->number_pages;
}
function get_num_musicpages() {
$this->number_pages = ceil($this->get_total_rows() / $this->rows_on_musicpage);
return $this->number_pages;
}
function get_num_communitypages() {
$this->number_pages = ceil($this->get_total_rows() / $this->rows_on_communitypage);
return $this->number_pages;
}
function get_num_artistpages() {
$this->number_pages = ceil($this->get_total_rows() / $this->rows_on_artistpage);
return $this->number_pages;
}
function get_num_videopages() {
$this->number_pages = ceil($this->get_total_rows() / $this->rows_on_videopage);
return $this->number_pages;
}
function get_num_digitalpages() {
$this->number_pages = ceil($this->get_total_rows() / $this->rows_on_digitalpage);
return $this->number_pages;
}
// returns the records for the current page
function get_page_result() {
$start = $this->set_page() * $this->rows_on_page;
$page_sql = sprintf("%s LIMIT %s, %s", $this->sql, $start, $this->rows_on_page);
//echo $page_sql;
$this->result = mysql_query($page_sql);
return $this->result;
}
function get_musicpage_result() {
$start = $this->set_page() * $this->rows_on_musicpage;
$page_sql = sprintf("%s LIMIT %s, %s", $this->sql, $start, $this->rows_on_musicpage);
//echo $page_sql;
$this->result = mysql_query($page_sql);
return $this->result;
}
function get_communitypage_result() {
$start = $this->set_page() * $this->rows_on_communitypage;
$page_sql = sprintf("%s LIMIT %s, %s", $this->sql, $start, $this->rows_on_communitypage);
//echo $page_sql;
$this->result = mysql_query($page_sql);
return $this->result;
}
function get_artistpage_result() {
$start = $this->set_page() * $this->rows_on_artistpage;
$page_sql = sprintf("%s LIMIT %s, %s", $this->sql, $start, $this->rows_on_artistpage);
//echo $page_sql;
$this->result = mysql_query($page_sql);
return $this->result;
}
function get_videopage_result() {
$start = $this->set_page() * $this->rows_on_videopage;
$page_sql = sprintf("%s LIMIT %s, %s", $this->sql, $start, $this->rows_on_videopage);
//echo $page_sql;
$this->result = mysql_query($page_sql);
return $this->result;
}
function get_digitalpage_result() {
$start = $this->set_page() * $this->rows_on_digitalpage;
$page_sql = sprintf("%s LIMIT %s, %s", $this->sql, $start, $this->rows_on_digitalpage);
//echo $page_sql;
$this->result = mysql_query($page_sql);
return $this->result;
}
function get_page_result_for_search() {
$start = $this->set_page() * $this->rows_on_page;
$page_sql = sprintf("%s LIMIT %s, %s", $this->sql, $start, $this->rows_on_page);
//echo $page_sql;
$this->result = mysql_query($page_sql);
return $this->result;
}
// get the number of rows on the current page
function get_page_num_rows() {
$this->num_rows = mysql_num_rows($this->result);
return $this->num_rows;
}
// free the database result
function free_page_result() {
mysql_free_result($this->result);
}
// function to handle other querystring than the page variable
function rebuild_qs($curr_var) {
if (!empty($_SERVER['QUERY_STRING'])) {
$parts = explode("&", $_SERVER['QUERY_STRING']);
$newParts = array();
foreach ($parts as $val) {
if (stristr($val, $curr_var) == false) {
array_push($newParts, $val);
}
}
if (count($newParts) != 0) {
$qs = "&".implode("&", $newParts);
} else {
return false;
}
return $qs; // this is your new created query string
} else {
return false;
}
}
function navigation_Music($separator = " | ", $css_current = "", $back_forward = false) {
$max_links = NUM_LINKS;
$curr_pages = $this->set_page();
$all_pages = $this->get_num_musicpages() - 1;
$var = $this->get_var;
$navi_string = "";
$condition="";
if (!$back_forward) {
$max_links = ($max_links < 2) ? 2 : $max_links;
}
if ($curr_pages <= $all_pages && $curr_pages >= 0) {
if ($curr_pages > ceil($max_links/2)) {
$start = ($curr_pages - ceil($max_links/2) > 0) ? $curr_pages - ceil($max_links/2) : 1;
$end = $curr_pages + ceil($max_links/2);
if ($end >= $all_pages) {
$end = $all_pages + 1;
$start = ($all_pages - ($max_links - 1) > 0) ? $all_pages - ($max_links - 1) : 1;
}
} else {
$start = 0;
$end = ($all_pages >= $max_links) ? $max_links : $all_pages + 1;
}
if($all_pages >= 1) {
$forward = $curr_pages + 1;
$backward = $curr_pages - 1;
if(isset($_REQUEST["Rent"]))
{
if($_REQUEST["Rent"]!="")
{
$Rent=$_REQUEST["Rent"];
$condition .= "Rent=".$Rent."&";
}
else
{
$Rent="";
$condition .= "Rent=".$Rent."&";
}
}
if(isset($_REQUEST["MinPrice"]))
{
if($_REQUEST["MinPrice"]!="")
{
$MinPrice=$_REQUEST["MinPrice"];
$condition .= "MinPrice=".$MinPrice."&";
}
else
{
$MinPrice="";
$condition .= "MinPrice=".$MinPrice."&";
}
}
if(isset($_REQUEST["MaxPrice"]))
{
if($_REQUEST["MaxPrice"]!="")
{
$MaxPrice=$_REQUEST["MaxPrice"];
$condition .= "MaxPrice=".$MaxPrice."&";
}
else
{
$MaxPrice="";
$condition .= "MaxPrice=".$MaxPrice."&";
}
}
if(isset($_REQUEST["Keyword"]))
{
if($_REQUEST["Keyword"]!="")
{
$Keyword=$_REQUEST["Keyword"];
$condition .= "Keyword=".$Keyword."&";
}
else
{
$Keyword="";
$condition .= "Keyword=".$Keyword."&";
}
}
if(isset($_REQUEST["SubCategory"]))
{
if($_REQUEST["SubCategory"]!="")
{
$SubCategory=$_REQUEST["SubCategory"];
$condition .= "SubCategory=".$SubCategory."&";
}
else
{
$SubCategory="";
$condition .= "SubCategory=".$SubCategory."&";
}
}
if(isset($_REQUEST["Most"]))
{
if($_REQUEST["Most"]==1)
{
$Most=1;
$condition .= "Most=".$Most."&";
}
else
{
$Most=0;
$condition .= "Most=".$Most."&";
}
}
//echo $all_rows."GOV";;
//$navi_string ="<td nowrap=nowrap></td><td>";
if(isset($_REQUEST["Category"]))
{
//echo "Govind 1".$condition;
$navi_string = ($curr_pages > 0) ? "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?Category=".$_REQUEST['Category']."&Keyword=".$_REQUEST["Keyword"]."&".$condition.$var."=".$backward.$this->rebuild_qs($var)."\">".$this->str_backward."</a> " : $this->str_backward." ";
}
else
{
//echo "Govind 2".$condition;
$navi_string = ($curr_pages > 0) ? "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?flag=1&".$condition.$var."=".$backward.$this->rebuild_qs($var)."\">".$this->str_backward."</a> " : $this->str_backward." ";
}
if (!$back_forward) {
for($a = $start + 1; $a <= $end; $a++){
$theNext = $a - 1; // because a array start with 0
if ($theNext != $curr_pages) {
if(isset($_REQUEST["Category"]))
{
//echo "Govind 3";
$navi_string .= "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?Category=".$_REQUEST['Category']."&Keyword=".$_REQUEST["Keyword"]."&".$condition.$var."=".$theNext.$this->rebuild_qs($var)."\">";
}
else
{
//echo "Govind 4";
$navi_string .= "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?flag=1&".$condition.$var."=".$theNext.$this->rebuild_qs($var)."\">";
}
$navi_string .= $a."</a>";
$navi_string .= ($theNext < ($end - 1)) ? $separator : "";
} else {
$navi_string .= ($css_current != "") ? "<span class=\"".$css_current."\">".$a."</span>" : $a;
$navi_string .= ($theNext < ($end - 1)) ? $separator : "";
}
}
}
if(isset($_REQUEST["Category"]))
{
//echo "Govind 5";
$navi_string .= ($curr_pages < $all_pages) ? " <a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?Category=".$_REQUEST['Category']."&Keyword=".$_REQUEST["Keyword"]."&".$condition.$var."=".$forward.$this->rebuild_qs($var)."\">".$this->str_forward."</a>" : " ".$this->str_forward;
}
else
{
//echo "Govind 6".$condition;
$navi_string .= ($curr_pages < $all_pages) ? " <a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?flag=1&".$condition.$var."=".$forward.$this->rebuild_qs($var)."\">".$this->str_forward."</a>" : " ".$this->str_forward;
}
}
}
$navi_string.="</td>";
return $navi_string;
}
function navigation_community($separator = " | ", $css_current = "", $back_forward = false) {
$max_links = NUM_LINKS;
$curr_pages = $this->set_page();
$all_pages = $this->get_num_communitypages() - 1;
$var = $this->get_var;
$navi_string = "";
if (!$back_forward) {
$max_links = ($max_links < 2) ? 2 : $max_links;
}
if ($curr_pages <= $all_pages && $curr_pages >= 0) {
if ($curr_pages > ceil($max_links/2)) {
$start = ($curr_pages - ceil($max_links/2) > 0) ? $curr_pages - ceil($max_links/2) : 1;
$end = $curr_pages + ceil($max_links/2);
if ($end >= $all_pages) {
$end = $all_pages + 1;
$start = ($all_pages - ($max_links - 1) > 0) ? $all_pages - ($max_links - 1) : 1;
}
} else {
$start = 0;
$end = ($all_pages >= $max_links) ? $max_links : $all_pages + 1;
}
if($all_pages >= 1) {
$forward = $curr_pages + 1;
$backward = $curr_pages - 1;
if(isset($_REQUEST["TxtSearch"]))
{
$navi_string = ($curr_pages > 0) ? "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?TxtSearch=".$_REQUEST['TxtSearch']."&CmbSearchCondition=".$_REQUEST['CmbSearchCondition']."&".$var."=".$backward.$this->rebuild_qs($var)."\">".$this->str_backward."</a> " : $this->str_backward." ";
}
else
{
$navi_string = ($curr_pages > 0) ? "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?flag=1&".$var."=".$backward.$this->rebuild_qs($var)."\">".$this->str_backward."</a> " : $this->str_backward." ";
}
if (!$back_forward) {
for($a = $start + 1; $a <= $end; $a++){
$theNext = $a - 1; // because a array start with 0
if ($theNext != $curr_pages) {
if(isset($_REQUEST["TxtSearch"]))
{
$navi_string .= "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?TxtSearch=".$_REQUEST['TxtSearch']."&CmbSearchCondition=".$_REQUEST['CmbSearchCondition']."&".$var."=".$theNext.$this->rebuild_qs($var)."\">";
}
else
{
$navi_string .= "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?flag=1&".$var."=".$theNext.$this->rebuild_qs($var)."\">";
}
$navi_string .= $a."</a>";
$navi_string .= ($theNext < ($end - 1)) ? $separator : "";
} else {
$navi_string .= ($css_current != "") ? "<span class=\"".$css_current."\">".$a."</span>" : $a;
$navi_string .= ($theNext < ($end - 1)) ? $separator : "";
}
}
}
if(isset($_REQUEST["TxtSearch"]))
{
$navi_string .= ($curr_pages < $all_pages) ? " <a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?TxtSearch=".$_REQUEST['TxtSearch']."&CmbSearchCondition=".$_REQUEST['CmbSearchCondition']."&".$var."=".$forward.$this->rebuild_qs($var)."\">".$this->str_forward."</a>" : " ".$this->str_forward;
}
else
{
$navi_string .= ($curr_pages < $all_pages) ? " <a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?flag=1&".$var."=".$forward.$this->rebuild_qs($var)."\">".$this->str_forward."</a>" : " ".$this->str_forward;
}
}
}
return $navi_string;
}
function navigation_artist($separator = " | ", $css_current = "", $back_forward = false) {
$max_links = NUM_LINKS;
$curr_pages = $this->set_page();
$all_pages = $this->get_num_artistpages() - 1;
$var = $this->get_var;
$navi_string = "";
if (!$back_forward) {
$max_links = ($max_links < 2) ? 2 : $max_links;
}
if ($curr_pages <= $all_pages && $curr_pages >= 0) {
if ($curr_pages > ceil($max_links/2)) {
$start = ($curr_pages - ceil($max_links/2) > 0) ? $curr_pages - ceil($max_links/2) : 1;
$end = $curr_pages + ceil($max_links/2);
if ($end >= $all_pages) {
$end = $all_pages + 1;
$start = ($all_pages - ($max_links - 1) > 0) ? $all_pages - ($max_links - 1) : 1;
}
} else {
$start = 0;
$end = ($all_pages >= $max_links) ? $max_links : $all_pages + 1;
}
if($all_pages >= 1) {
$forward = $curr_pages + 1;
$backward = $curr_pages - 1;
if(isset($_REQUEST["TxtSearch"]))
{
$navi_string = ($curr_pages > 0) ? "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?TxtSearch=".$_REQUEST['TxtSearch']."&CmbSearchCondition=".$_REQUEST['CmbSearchCondition']."&".$var."=".$backward.$this->rebuild_qs($var)."\">".$this->str_backward."</a> " : $this->str_backward." ";
}
else
{
$navi_string = ($curr_pages > 0) ? "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$var."=".$backward.$this->rebuild_qs($var)."\">".$this->str_backward."</a> " : $this->str_backward." ";
}
if (!$back_forward) {
for($a = $start + 1; $a <= $end; $a++){
$theNext = $a - 1; // because a array start with 0
if ($theNext != $curr_pages) {
if(isset($_REQUEST["TxtSearch"]))
{
$navi_string .= "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?TxtSearch=".$_REQUEST['TxtSearch']."&CmbSearchCondition=".$_REQUEST['CmbSearchCondition']."&".$var."=".$theNext.$this->rebuild_qs($var)."\">";
}
else
{
$navi_string .= "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$var."=".$theNext.$this->rebuild_qs($var)."\">";
}
$navi_string .= $a."</a>";
$navi_string .= ($theNext < ($end - 1)) ? $separator : "";
} else {
$navi_string .= ($css_current != "") ? "<span class=\"".$css_current."\">".$a."</span>" : $a;
$navi_string .= ($theNext < ($end - 1)) ? $separator : "";
}
}
}
if(isset($_REQUEST["TxtSearch"]))
{
$navi_string .= ($curr_pages < $all_pages) ? " <a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?TxtSearch=".$_REQUEST['TxtSearch']."&CmbSearchCondition=".$_REQUEST['CmbSearchCondition']."&".$var."=".$forward.$this->rebuild_qs($var)."\">".$this->str_forward."</a>" : " ".$this->str_forward;
}
else
{
$navi_string .= ($curr_pages < $all_pages) ? " <a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$var."=".$forward.$this->rebuild_qs($var)."\">".$this->str_forward."</a>" : " ".$this->str_forward;
}
}
}
return $navi_string;
}
////////////////VIDEO/////////////
function navigation_video($separator = " | ", $css_current = "", $back_forward = false) {
$max_links = NUM_LINKS;
$curr_pages = $this->set_page();
$all_pages = $this->get_num_videopages() - 1;
$var = $this->get_var;
$navi_string = "";
if (!$back_forward) {
$max_links = ($max_links < 2) ? 2 : $max_links;
}
if ($curr_pages <= $all_pages && $curr_pages >= 0) {
if ($curr_pages > ceil($max_links/2)) {
$start = ($curr_pages - ceil($max_links/2) > 0) ? $curr_pages - ceil($max_links/2) : 1;
$end = $curr_pages + ceil($max_links/2);
if ($end >= $all_pages) {
$end = $all_pages + 1;
$start = ($all_pages - ($max_links - 1) > 0) ? $all_pages - ($max_links - 1) : 1;
}
} else {
$start = 0;
$end = ($all_pages >= $max_links) ? $max_links : $all_pages + 1;
}
if($all_pages >= 1) {
$forward = $curr_pages + 1;
$backward = $curr_pages - 1;
$navi_string = ($curr_pages > 0) ? "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$var."=".$backward.$this->rebuild_qs($var)."\">".$this->str_backward."</a> " : $this->str_backward." ";
if (!$back_forward) {
for($a = $start + 1; $a <= $end; $a++){
$theNext = $a - 1; // because a array start with 0
if ($theNext != $curr_pages) {
$navi_string .= "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$var."=".$theNext.$this->rebuild_qs($var)."\">";
$navi_string .= $a."</a>";
$navi_string .= ($theNext < ($end - 1)) ? $separator : "";
} else {
$navi_string .= ($css_current != "") ? "<span class=\"".$css_current."\">".$a."</span>" : $a;
$navi_string .= ($theNext < ($end - 1)) ? $separator : "";
}
}
}
$navi_string .= ($curr_pages < $all_pages) ? " <a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$var."=".$forward.$this->rebuild_qs($var)."\">".$this->str_forward."</a>" : " ".$this->str_forward;
}
}
return $navi_string;
}
//////////////////////////DIGITAL///////////////////
function navigation_digital($separator = " | ", $css_current = "", $back_forward = false) {
$max_links = NUM_LINKS;
$curr_pages = $this->set_page();
$all_pages = $this->get_num_digitalpages() - 1;
$var = $this->get_var;
$navi_string = "";
if (!$back_forward) {
$max_links = ($max_links < 2) ? 2 : $max_links;
}
if ($curr_pages <= $all_pages && $curr_pages >= 0) {
if ($curr_pages > ceil($max_links/2)) {
$start = ($curr_pages - ceil($max_links/2) > 0) ? $curr_pages - ceil($max_links/2) : 1;
$end = $curr_pages + ceil($max_links/2);
if ($end >= $all_pages) {
$end = $all_pages + 1;
$start = ($all_pages - ($max_links - 1) > 0) ? $all_pages - ($max_links - 1) : 1;
}
} else {
$start = 0;
$end = ($all_pages >= $max_links) ? $max_links : $all_pages + 1;
}
if($all_pages >= 1) {
$forward = $curr_pages + 1;
$backward = $curr_pages - 1;
$navi_string = ($curr_pages > 0) ? "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?flag=1&".$var."=".$backward.$this->rebuild_qs($var)."\">".$this->str_backward."</a> " : $this->str_backward." ";
if (!$back_forward) {
for($a = $start + 1; $a <= $end; $a++){
$theNext = $a - 1; // because a array start with 0
if ($theNext != $curr_pages) {
$navi_string .= "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?flag=1&".$var."=".$theNext.$this->rebuild_qs($var)."\">";
$navi_string .= $a."</a>";
$navi_string .= ($theNext < ($end - 1)) ? $separator : "";
} else {
$navi_string .= ($css_current != "") ? "<span class=\"".$css_current."\">".$a."</span>" : $a;
$navi_string .= ($theNext < ($end - 1)) ? $separator : "";
}
}
}
$navi_string .= ($curr_pages < $all_pages) ? " <a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?flag=1&".$var."=".$forward.$this->rebuild_qs($var)."\">".$this->str_forward."</a>" : " ".$this->str_forward;
}
}
return $navi_string;
}
// this method will return the navigation links for the conplete recordset
function navigation($separator = " | ", $css_current = "", $back_forward = false) {
$max_links = NUM_LINKS;
$curr_pages = $this->set_page();
$all_pages = $this->get_num_pages() - 1;
$var = $this->get_var;
$navi_string = "";
if (!$back_forward) {
$max_links = ($max_links < 2) ? 2 : $max_links;
}
if ($curr_pages <= $all_pages && $curr_pages >= 0) {
if ($curr_pages > ceil($max_links/2)) {
$start = ($curr_pages - ceil($max_links/2) > 0) ? $curr_pages - ceil($max_links/2) : 1;
$end = $curr_pages + ceil($max_links/2);
if ($end >= $all_pages) {
$end = $all_pages + 1;
$start = ($all_pages - ($max_links - 1) > 0) ? $all_pages - ($max_links - 1) : 1;
}
} else {
$start = 0;
$end = ($all_pages >= $max_links) ? $max_links : $all_pages + 1;
}
if($all_pages >= 1) {
$forward = $curr_pages + 1;
$backward = $curr_pages - 1;
if(isset($_REQUEST["TxtSearch"]))
{
$navi_string = ($curr_pages > 0) ? "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?TxtSearch=".$_REQUEST['TxtSearch']."&CmbSearchCondition=".$_REQUEST['CmbSearchCondition']."&".$var."=".$backward.$this->rebuild_qs($var)."\">".$this->str_backward."</a> " : $this->str_backward." ";
}
else
{
$navi_string = ($curr_pages > 0) ? "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$var."=".$backward.$this->rebuild_qs($var)."\">".$this->str_backward."</a> " : $this->str_backward." ";
}
if (!$back_forward) {
for($a = $start + 1; $a <= $end; $a++){
$theNext = $a - 1; // because a array start with 0
if ($theNext != $curr_pages) {
if(isset($_REQUEST["TxtSearch"]))
{
$navi_string .= "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?TxtSearch=".$_REQUEST['TxtSearch']."&CmbSearchCondition=".$_REQUEST['CmbSearchCondition']."&".$var."=".$theNext.$this->rebuild_qs($var)."\">";
}
else
{
$navi_string .= "<a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$var."=".$theNext.$this->rebuild_qs($var)."\">";
}
$navi_string .= $a."</a>";
$navi_string .= ($theNext < ($end - 1)) ? $separator : "";
} else {
$navi_string .= ($css_current != "") ? "<span class=\"".$css_current."\">".$a."</span>" : $a;
$navi_string .= ($theNext < ($end - 1)) ? $separator : "";
}
}
}
if(isset($_REQUEST["TxtSearch"]))
{
$navi_string .= ($curr_pages < $all_pages) ? " <a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?TxtSearch=".$_REQUEST['TxtSearch']."&CmbSearchCondition=".$_REQUEST['CmbSearchCondition']."&".$var."=".$forward.$this->rebuild_qs($var)."\">".$this->str_forward."</a>" : " ".$this->str_forward;
}
else
{
$navi_string .= ($curr_pages < $all_pages) ? " <a href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$var."=".$forward.$this->rebuild_qs($var)."\">".$this->str_forward."</a>" : " ".$this->str_forward;
}
}
}
return $navi_string;
}
// this info will tell the visitor which number of records are shown on the current page
function page_info($to = "-") {
$first_rec_no = ($this->set_page() * $this->rows_on_page) + 1;
$last_rec_no = $first_rec_no + $this->rows_on_page - 1;
$last_rec_no = ($last_rec_no > $this->get_total_rows()) ? $this->get_total_rows() : $last_rec_no;
$to = trim($to);
$info = $first_rec_no." ".$to." ".$last_rec_no;
return $info;
}
// simple method to show only the page back and forward link.
function back_forward_link() {
$simple_links = $this->navigation(" ", "", true);
return $simple_links;
}
function navigation_classifieds($separator = " | ", $css_current = "", $back_forward = false) {
$max_links = NUM_LINKS;
$curr_pages = $this->set_page();
$all_pages = $this->get_num_pages() - 1;
$var = $this->get_var;
$navi_string = "";
$condition="";
if (!$back_forward) {
$max_links = ($max_links < 2) ? 2 : $max_links;
}
if ($curr_pages <= $all_pages && $curr_pages >= 0) {
if ($curr_pages > ceil($max_links/2)) {
$start = ($curr_pages - ceil($max_links/2) > 0) ? $curr_pages - ceil($max_links/2) : 1;
$end = $curr_pages + ceil($max_links/2);
if ($end >= $all_pages) {
$end = $all_pages + 1;
$start = ($all_pages - ($max_links - 1) > 0) ? $all_pages - ($max_links - 1) : 1;
}
} else {
$start = 0;
$end = ($all_pages >= $max_links) ? $max_links : $all_pages + 1;
}
if($all_pages >= 1) {
$forward = $curr_pages + 1;
$backward = $curr_pages - 1;
if(isset($_REQUEST["Rent"]))
{
if($_REQUEST["Rent"]!="")
{
$Rent=$_REQUEST["Rent"];
$condition .= "Rent=".$Rent."&";
}
else
{
$Rent="";
$condition .= "Rent=".$Rent."&";
}
}
if(isset($_REQUEST["MinPrice"]))
{
if($_REQUEST["MinPrice"]!="")
{
$MinPrice=$_REQUEST["MinPrice"];
$condition .= "MinPrice=".$MinPrice."&";
}
else
{
$MinPrice="";
$condition .= "MinPrice=".$MinPrice."&";
}
}
if(isset($_REQUEST["MaxPrice"]))
{
if($_REQUEST["MaxPrice"]!="")
{
$MaxPrice=$_REQUEST["MaxPrice"];
$condition .= "MaxPrice=".$MaxPrice."&";
}
else
{
$MaxPrice="";
$condition .= "MaxPrice=".$MaxPrice."&";
}
}
if(isset($_REQUEST["Keyword"]))
{
if($_REQUEST["Keyword"]!="")
{
$Keyword=$_REQUEST["Keyword"];
$condition .= "Keyword=".$Keyword."&";
}
else
{
$Keyword="";
//$condition .= "Keyword=".$Keyword."&";
}
}
if(isset($_REQUEST["SubCategory"]))
{
if($_REQUEST["SubCategory"]!="")
{
$SubCategory=$_REQUEST["SubCategory"];
$condition .= "SubCategory=".$SubCategory."&";
}
else
{
$SubCategory="";
$condition .= "SubCategory=".$SubCategory."&";
}
}
if(isset($_REQUEST["Most"]))
{
if($_REQUEST["Most"]==1)
{
$Most=1;
$condition .= "Most=".$Most."&";
}
else
{
$Most=0;
$condition .= "Most=".$Most."&";
}
}
if(isset($_REQUEST["Comments"]))
{
if($_REQUEST["Comments"]==1)
{
$Comments=1;
$condition .= "Comments=".$Comments."&";
}
else
{
$Comments=0;
$condition .= "Comments=".$Comments."&";
}
}
if(isset($_REQUEST["Category"]))
{
if($_REQUEST["Category"]!="")
{
$Category=$_REQUEST["Category"];
$condition .= "Category=".$Category."&";
}
else
{
$Category="";
//$condition .= "Category=".$Category."&";
}
}
//echo $all_rows."GOV";;
//$navi_string ="<td nowrap=nowrap></td><td>";
if(isset($_REQUEST["Category"]))
{
//echo "Govind 1".$condition;
$navi_string = ($curr_pages > 0) ? "<a class=bold href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$condition.$var."=".$backward.$this->rebuild_qs($var)."\">".$this->str_backward."</a> " : $this->str_backward." ";
}
else
{
//echo "Govind 2".$condition;
$navi_string = ($curr_pages > 0) ? "<a class=bold href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$condition.$var."=".$backward.$this->rebuild_qs($var)."\">".$this->str_backward."</a> " : $this->str_backward." ";
}
if (!$back_forward) {
for($a = $start + 1; $a <= $end; $a++){
$theNext = $a - 1; // because a array start with 0
if ($theNext != $curr_pages) {
if(isset($_REQUEST["Category"]))
{
//echo "Govind 3";
$navi_string .= "<a class=bold href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$condition.$var."=".$theNext.$this->rebuild_qs($var)."\">";
}
else
{
//echo "Govind 4";
$navi_string .= "<a class=bold href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$condition.$var."=".$theNext.$this->rebuild_qs($var)."\">";
}
$navi_string .= $a."</a>";
$navi_string .= ($theNext < ($end - 1)) ? $separator : "";
} else {
$navi_string .= ($css_current != "") ? "<span >".$a."</span>" : $a;
$navi_string .= ($theNext < ($end - 1)) ? $separator : "";
}
}
}
if(isset($_REQUEST["Category"]))
{
//echo "Govind 5";
$navi_string .= ($curr_pages < $all_pages) ? " <a class=bold href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$condition.$var."=".$forward.$this->rebuild_qs($var)."\">".$this->str_forward."</a>" : " ".$this->str_forward;
}
else
{
//echo "Govind 6".$condition;
$navi_string .= ($curr_pages < $all_pages) ? " <a class=bold href=\"".preg_replace('/\?(.*)/','',$_SERVER['PHP_SELF'])."?".$condition.$var."=".$forward.$this->rebuild_qs($var)."\">".$this->str_forward."</a>" : " ".$this->str_forward;
}
}
}
$navi_string.="</td>";
return $navi_string;
}
} // class DB
?>
|