Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
I am a php beginner, really working hard to learn, but this time it looks like I am trying to do something beyond my means
This page shows an availability calendar in apartment pages.
It starts showing the current month (so, november now) but if a visitor is interested in March he'll have to click until it reaches March in every new apartment he goes.
I want that once a new month has been selected (so, March in this example), it stays in a Session variable, so that every apartment visited will show the same month.
This is the original code:Code: Select all
<?php
require_once('../include/IncFiles/functions.php');
require_once('../include/IncFiles/Variables.php');
require_once('../include/class.db.php');
//get initial date
$mnow=(isset($HTTP_GET_VARS['month']) && intval($HTTP_GET_VARS['month'])>0 && intval($HTTP_GET_VARS['month'])<13)?intval($HTTP_GET_VARS['month']):date("m");
$ynow=(isset($HTTP_GET_VARS['year']) && intval($HTTP_GET_VARS['year'])>1969 && intval($HTTP_GET_VARS['year'])<2038)?intval($HTTP_GET_VARS['year']):date("Y");
$mtime=mktime(0,0,0,$mnow,date("d"),$ynow); //int mktime(int hour, int minute, int second, int month, int day, int year);
$f=date("w",mktime(0,0,0,$mnow,1,$ynow))-1; //set start date column
// if ($mnow < "10") $mnow="0".$mnow;
$apartmentid=$_GET['apartmentid'];
//query selected month reservations
$datearray1=array();
$datearray2=array();
$arraycount=0;
$startdefault=date("Y-m-d", mktime(0,0,0,$mnow,1,$ynow));
$enddefault=date("Y-m-d", mktime(0,0,0,$mnow,31,$ynow));
$sql="select abtype, intotime, endtime from t_order where apartmentid=$apartmentid order by intotime";
$db->query($sql);
if($db->num_rows())
{
while (($db->next_record()))
{
// Start Do not show requested dates (abtype 2) Luca 21/05/2006 18.29.30
$abtype=$db->f('abtype');
if ($abtype !="2") {
// End Do not show requested dates (abtype 2)
$startdate=$db->f('intotime');
$enddate=$db->f('endtime');
$starty=substr($startdate,0,4);
$startm=substr($startdate,5,2);
$startd=substr($startdate,8,2);
$endy=substr($enddate,0,4);
$endm=substr($enddate,5,2);
$endd=(substr($enddate,8,2));
} // Belongs Do not show requested dates
if (($mnow == $startm) && ($ynow == $starty))
{
$datearray1[$arraycount]=$startd;
if ($endm == $startm)
{
$datearray2[$arraycount]=$endd;
}else
{
$datearray2[$arraycount]=31;
}
$arraycount++;
}else if (($mnow == $endm) && ($ynow == $endy))
{
if ($endm == $startm)
{
$datearray1[$arraycount]=$startd;
}else
{
$datearray1[$arraycount]=1;
}
$datearray2[$arraycount]=$endd;
$arraycount++;
}
}
}
for ($x=0;$x<$arraycount;$x++)
{
//echo "list, from ".$datearray1[$x]." to ".$datearray2[$x]."<br>";
}
$tt="";
//set table
//$tt.="<table id=\"calendar\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\">";
//set title
$tt.="<tr bgcolor=\"CC0000\">
<td colspan=\"4\" align=\"center\" class=\"calendartitle\">
<a href=\"?".($mnow!=date("m")?"month=".intval($mnow)."&":"")."year=".(intval($ynow)==1970?"1970":intval($ynow)-1)."&apartmentid=".$apartmentid."\" class=\"calendartitle\"><- </a>".$ynow."
<a href=\"?".($mnow!=date("m")?"month=".intval($mnow)."&":"")."year=".(intval($ynow)==2037?"2037":intval($ynow)+1)."&apartmentid=".$apartmentid."\" class=\"calendartitle\"> -></a></td>
<td colspan=\"3\" align=\"center\" class=\"calendartitle\">
<a href=\"?month=".(intval($mnow)==1?"12":intval($mnow)-1).($ynow!=date("Y")?"&year=".intval($ynow):"")."&apartmentid=".$apartmentid."\" class=\"calendartitle\"><- </a>".$mnow."
<a href=\"?month=".(intval($mnow)==12?"1":intval($mnow)+1).($ynow!=date("Y")?"&year=".intval($ynow):"")."&apartmentid=".$apartmentid."\" class=\"calendartitle\"> -></a>
</td>
</tr>";
$tt.="<tr bgcolor=\"FF6666\"><td class=\"calendartop\">Sun</td><td class=\"calendartop\">Mon</td><td class=\"calendartop\">Tue</td><td class=\"calendartop\">Wed</td><td class=\"calendartop\">Thu</td><td class=\"calendartop\">Fri</td><td class=\"calendartop\">Sat</td></tr>";
//set date
for($i=0;$i<date("t",$mtime)+$f+1;$i++){
if($i%7==0)echo "<tr>";
$tt.="<td align=center ".(($i-$f==intval(date("d")) && $mnow==date("m") && $ynow==date("Y"))?" id=\"calendartoday\"":"");
$count=0;
for ($x=0;$x<$arraycount;$x++)
{
$cdate=$i-$f;
if ((($cdate>=$datearray1[$x]) && ($cdate<=$datearray2[$x])) && ($count == 0))
{
$tt.=" bgcolor=\"#FFCCCC\">"."<span class=\"system_abtable_reserved\">";
$count=1;
}
//$x=$arraycount;
}
if ($count == 0) $tt.=">";
if($i>$f)
{
$cdate=$i-$f; //hide former blank fields
if ($cdate < 10) $cdate="0".$cdate;
$tt.=$cdate;
if ($count == 1) $tt.="</span>";
}
$tt.="</td>";
if($i%7==6) $tt.="</tr>";
}
//set rest blank fields
if($i%7<6 && $i%7>0)$tt.="<td colspan=\"".(7-$i%7)."\"></td></tr>";
if($i%7==6) $tt.="<td></td></tr>";
//$tt.="</table>";
?>
<html>
<head>
<link href="../css/system.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style></head>
<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center">
<table width="240" border="2" cellpadding="0" cellspacing="2" bordercolor="#CCCCCC" bgcolor="#F4F4F4">
<tr>
<td bgcolor="#CCCCCC"><div align="center" class="article_title">Apartment Availabilities</div></td>
</tr>
<tr>
<td><table width="230" height="200" border="1" align="center" cellpadding="2" cellspacing="1" bordercolor="#EEEEEE" bgcolor="#FFFFFF" class="system_abtable" id="calendar">
<?
echo $tt;
?>
</table></td>
</tr>
</table>
</div></td>
</tr>
</table>
</body>
</html>Thank you !
Luca
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]