<?php
session_start();
include("config.php");
$sid=session_id();
$date=date("Y-m-d");
$sql="select * from usr where sid='$sid' AND ddate='$date' AND pageno=11";
$q=mysql_query($sql) or die(mysql_error());
$c=mysql_num_rows($q);
$usrcnt=0;
//[red]these make no sense. global only works if it is called from OUTSIDE the global scope[/red]
global $h;
global $w;
$h=0;
$w=0;
if($c<1)
{
$q1=mysql_query("insert into usr (sid,ddate,pageno) values ('$sid','$date',11)") or die (mysql_error());
$q3=mysql_query("select count(*) from usr where pageno=11") or die (mysql_query());
$usrcnt=mysql_result($q3,0,0);
// echo ("No. of Users hit : $r3[0]");
}
else
{
$q2=mysql_query("select count(*) from usr where pageno=11") or die (mysql_error()); //[red]changed[/red]
$usrcnt=mysql_result($q2, 0,0);
//echo ("No. of Users hit : $r2[0]");
}
?>
<?php
$buildquery="";
$hotname="";
$services="";
$selectCountry=0;
$selectRegion=0;
$ratings=0;
if($_SERVER['REQUEST_METHOD']=='POST' ) { $post=$_POST; }
elseif($_SERVER['REQUEST_METHOD']=='GET' ) { $post=$_GET; }
/* [red]this bit is changed to abstract the cleansing of input variables */
$fields = array('hlist', 'hotname', 'selectCountry', 'selectRegion', 'ratings', 'services', 'tem');
foreach ($fields as $field){
${$field} = (isset($post[$field])) ? mysql_escape_string(trim($post[$field])) : NULL;
}
//[/red]
if(isset($post['services']))
{
$tem=$post['services'];
} //[red]
else { $tem = NULL; }//[/red]
$mConQry_Str="";
if($hlist==0){
//[red re use the abstraction layer. you need to encode this too [/red]
foreach ($fields as $field){
if ($field !== "services" && $field !=="tem"){ //ignore the services as it has become $tem
$tmp[] = urlencode($field) ."=".urlencode(${$field});
}
}
} else {
foreach ($fields as $field){
if ($field !== "services" && $field !=="tem"){ //ignore the services as it has become $tem
$tmp[] = urlencode($field) ."=".urlencode(${$field});
}
//add the tem
$tmp[] = urlencode("services") ."=".urlencode($tem);
}
}
//now make the $mConQry_Str
$mConQry_Str = implode("&", $tmp);
//[red] end of altered abstraction code [/red]
switch ($hlist){
case 0:
$buildquery="
select
distinct
t1.Nom_Hot,
t1.Id_Hot as hotel_id,
t1.Nom_Hot as hotel_name ,
t2.Nom_Cat as star_rating ,
t3.Nom_Cntry as country,
t1.Foto1_Hot as foto1 ,
t1.Foto2_Hot as foto2,
t1.Foto3_Hot as foto3,
t1.Foto4_Hot as foto4";
if($selectRegion>0){
$buildquery .= ",
t4.Nom_Rsrt region";
$extra2 = ", tbl_resorts as t4";
$extra = "
and
t1.IdRsrt_Hot='$selectRegion'
and
t1.IdRsrt_Hot=t4.Id_Rsrt"; //we will reuse this later
} else {$extra = $extra2 = '';}
$buildquery .= "
from
tbl_hotels as t1,
tbl_categories as t2,
tbl_countries as t3 $extra2";
$buildquery.= "
where
t1.IdCat_Hot=t2.Id_Cat";
if($ratings>0){
$buildquery.="
and
t2.Id_Cat='$ratings'";
}
if($selectCountry>0){
$buildquery.="
and
t1.IdCntry_Hot='$selectCountry' ";
}
$buildquery .="
and
t1.IdCntry_Hot=t3.Id_Cntry ";
if(strlen($hotname)>0){
$buildquery.="
and
t1.Nom_Hot like '%$hotname%' ";
}
$buildquery.="
AND
t1.Act_Hot=1
$extra
ORDER BY
t1.Rate_Num_Hot DESC";
break;
/*else
{
$buildquery.=" select distinct(t1.Nom_Hot), t1.Id_Hot hotel_id , t1.Nom_Hot hotel_name , t2.Nom_Cat star_rating , t3.Nom_Cntry country, t1.Foto1_Hot foto1 ";
$buildquery.=" ,t1.Foto2_Hot foto2, t1.Foto3_Hot foto3,t1.Foto4_Hot foto4 " ;
if($selectRegion>0){ $buildquery.=" , t4.Nom_Rsrt region "; }
$buildquery.=" from tbl_hotels t1, tbl_categories t2, tbl_countries t3 ";
if($selectRegion>0){ $buildquery.=" , tbl_resorts t4 "; }
$buildquery.=" ,tbl_hotntem t5 where t1.IdCat_Hot=t2.Id_Cat and t1.IdCntry_Hot=t3.Id_Cntry ";
if($ratings>0){ $buildquery.=" and t2.Id_Cat=$ratings "; }
if($selectCountry>0){ $buildquery.=" and t3.Id_Cntry=$selectCountry "; }
if($selectRegion>0){ $buildquery.=" and t1.IdRsrt_Hot=$selectRegion and t1.IdRsrt_Hot=t4.Id_Rsrt "; }
if($tem>0){ $buildquery.=" and t5.Id_Tem=$tem and t5.Id_Hot=t1.Id_Hot"; }
$buildquery.= " AND t1.Act_Hot=1";
$buildquery .= " order by t1.Rate_Num_Hot DESC ";
}*/
/* This is lee's Apartment test code */
case 2:
//[red]this query was totally screwed [/red]
$buildquery ="
select
distinct
t1.Nom_Hot,
t1.Id_Hot as hotel_id ,
t1.Nom_Hot as hotel_name ,
t2.Nom_Cat as star_rating ,
t3.Nom_Cntry as country,
t1.Foto1_Hot as foto1,
t1.Foto2_Hot as foto2,
t1.Foto3_Hot as foto3,
t1.Foto4_Hot as foto4";
if ($selectRegion > 0){
$buildquery .= "
,
t4.Nom_Rsrt region";
$extra = "
,
tbl_resorts as t4";
$extra2 = "
and
t1.IdRsrt_Hot='$selectRegion'
and
t1.IdRsrt_Hot=t4.Id_Rsrt";
} else {$extra = $extra2 = ''; }
$buildquery .= "
from
tbl_hotels as t1,
tbl_categories as t2,
tbl_countries as t3 $extra
where
t1.IdCat_Hot=t2.Id_Cat
AND
t1.IdCntry_Hot=t3.Id_Cntry
AND
t1.Act_Hot=1
$extra2";
if($ratings>0){
$buildquery.="
and
t2.Id_Cat='$ratings'";
}
if($selectCountry>0){
$buildquery.="
and
t1.IdCntry_Hot='$selectCountry' ";
}
if(!empty($hotname)){
$buildquery.="
and
t1.Nom_Hot like '%$hotname%' ";
}
$buildquery .= "
order by
t1.Rate_Num_Hot DESC";
}
/* End of lee test code */
$mQry=$buildquery;
//echo $mQry;
// Page Navigator code
include "PageNavigator.php";
// set default page size
$mPageSize = (!empty($_POST["txtPageSize"]) && intval($_POST['txtPageSize']) > 0)
?
(int) $_POST['txtPageSize']
:
(!empty($_GET["txtPageSize"]) && intval($_GET['txtPageSize']) > 0)
?
(int) $_GET['txtPageSize']
:
9;
//[red]caters for get input as well as post[/red]
$mUrl = $PHP_SELF."?txtPageSize=".$mPageSize."&".$mConQry_Str;
$mAbsolutePage = (!empty($_GET["absolutepage"]) && $_GET['absolutepage'] > 0 )? abs($_GET['absolutepage']) : 1;
$mOffset = ( $mAbsolutePage - 1 ) * $mPageSize ;
$mResult = mysql_query($mQry) or die (mysql_error()."<br/>Query was: $mQry");
$mRecordCount = mysql_num_rows($mResult);
$mPageCount = ceil($mRecordCount / $mPageSize); //not int val
if ($mAbsolutePage>$mPageCount) {
$mAbsolutePage=$mPageCount;
}
$mQry .= "
LIMIT $mPageSize
OFFSET $mOffset "; // Get record set = $mPageSize every time
$mRes = mysql_query($mQry) or die (mysql_error() . "<br/>Query was: $mQry");
echo "debug <br/><pre>";
while ($row = mysql_fetch_assoc($mRes)){
print_r($row);
echo "<hr/>";
}
//[red] this code does not seem to do anything
if ($mAbsolutePage == 1)
{
$mPag1 = $mAbsolutePage;
}
else
{
$mPag1 = (($mAbsolutePage - 1) * $mPageSize) + 1;
}
$mPag2 = $mPag1 + ($mPageSize - 1);
if ($mPag2 > $mRecordCount)
$mPag2 = $mRecordCount;
// Page Navigator code
// [/red]
?>