Page 1 of 1

date picker code for hotel web site... assistance required

Posted: Fri Sep 02, 2005 2:44 pm
by kingman65
I hope I can make this understandable and hopefully I posted the right thing to get the assistance I need. I am trying to repair a page that was built by someone else. We no longer have any dealings with the person so I can not go to him for help. I have a site that I maintain at http://www.capecodderresort.com on the right side of the page is a form for checking availability. This has never worked correctly. I have found and repaired the part of the code that handled the date so it works now.

The part that I have not been able to figure out is the section for checking hot deals. When you click on that button it submits the date to a dB and returns any deals that the hotel is offering. The problem I am having is that it returns the calender for 1 year out. So if you go to check the deals you get Sept 2006. It does not seem to be picking up on any date entered in the field above.


The first code snippet below is the code for the box on the page, following that is the check_avail.php file that the code gets submitted to. I hope that I am not including too much code. You can see that I am generating the date with javascript. I think I then need to reference the dateString variable

This is the code that autofills the date. I have removed all the html since that has no real bearing on the codes function. Hopefully this will be clear enough for someone to help me figure it out. Thank you for your time.

Kingman

Code: Select all

<form method=post action=dors_portal.php name=reservation>
   

    <input name="iyear" class="formfield" id="iyear" size="10">
      <script type="text/javascript"><!--
       function getCorrectedYear(year)  {
	   year = year - 0;
	   if (year < 70) return (2000 + year);
	   if (year < 1900) return (1900 + year);
	   return year;}
       var today = new Date();
       var d = today.getDate() + 1;
       var m = today.getMonth() + 1;
       var dateString = y + '-' + m + '-' + d;
       var y = getCorrectedYear(today.getYear());
       this.reservation.iyear.value = y;
       this.reservation.iday.value = d;
       this.reservation.imonth.value = m;
       //--></script>
      </input>

Below is the part of the form for checking hotdeals. I have to get the dateString variable into here I think -->

Code: Select all

<form action=http://ccrsys.getdors.com/check_deals.php method=post name=MForm id="MForm">
<table width="180" border="0" cellpadding="0" cellspacing="0" bgcolor="#E9F0F8">
    <tr> 
      <td align="center" bgcolor="#E9F0F8">
      <a href="http://kiss1.getdors.com/dorsdemo/dorsindex1.php?page=checkdeal&system_id=80&r=&d=&s=&c=&a=">

</form>

Code: Select all

<?
#
# Quick Check -- Not Staying? Forward to View.php !!
#
//$s = stay length
//$a = adults / guest
//$c = unsure, doesn't seem to be used
//$r = unsure, doesn't seem to be used

if(!$s) { $s=1; }
if(!$r) { $r=1; }

// Create Stay Length (From Database?)
$count=0;
$nights_staying_html = "<select name=s>";
while($count < 12) {
	$count++;
	if($s == $count) { $rooms_sel=" selected"; } else { $rooms_sel=""; }
	$nights_staying_html .= "<option value=$count".$rooms_sel.">$count</option>\n";
	}
$nights_staying_html .= "</select>";

// Create Adults (From Database?)
$count=1;
$guests_staying_html = "<select name=guests>";
while($count <= 6) {
	if($guests == $count) { $rooms_sel=" selected"; } else { $rooms_sel=""; }
	$guests_staying_html .= "<option value=$count".$rooms_sel.">$count</option>\n";
	$count++;
	}
$guests_staying_html .= "</select>";
$deals_hidden_vars = "<input type=hidden name=d value='$d'><input type=hidden name=system_id value='$system_id'>";

//include("dbconect.inc");
$avail=0;
#
# Select Available Rooms
#

$opyear = date(Y);

$week_lookup{'Sun'} = 1;
$week_lookup{'Mon'} = 2;
$week_lookup{'Tue'} = 3;
$week_lookup{'Wed'} = 4;
$week_lookup{'Thu'} = 5;
$week_lookup{'Fri'} = 6;
$week_lookup{'Sat'} = 7;

$month_end{'01'} = 31;
if(is_leap($opyear)) { $feb=29; } else { $feb=28; }

$month_end{'02'} = $feb;
$month_end{'03'} = 31;
$month_end{'04'} = 30;
$month_end{'05'} = 31;
$month_end{'06'} = 30;
$month_end{'07'} = 31;
$month_end{'08'} = 31;
$month_end{'09'} = 30;
$month_end{'10'} = 31;
$month_end{'11'} = 30;
$month_end{'12'} = 31;

$count = 0;
$today = date(d);
if($rooms) { $r = $rooms; } else { $rooms = $r; }
if($errors) { $errors = "<li> $errors<br><br>\n"; }

$result = mysql_query("select delay from system where id=".$system_id);
$DELAY=mysql_fetch_assoc($result);
$DayDelay=$DELAY[delay];

if(!$guests) { $guests = 1; }
$total_guests = $guests;
$a = $guests;

#############################
##
## Grab Hot Dates
##
#############################

$hotdates = array();
//echo $test="select datavars.bigdata from datavars, rooms_pkg where datavars.tid='hotdates' and datavars.system_id=".$system_id." and rooms_pkg.delflag=0 and datavars.sid = rooms_pkg.id";

//$result = mysql_query("select bigdata from datavars where tid='hotdates' and system_id=".$system_id);
//$result = mysql_query("select datavars.bigdata from datavars, rooms_pkg where datavars.tid='hotdates' and datavars.system_id=".$system_id." and rooms_pkg.delflag=0 and datavars.sid = rooms_pkg.id");
//while($dealrow = mysql_fetch_array($result)){
	//$array_mess = split(":", $dealrow[bigdata]);
	//foreach($array_mess as $hotyd){
		//array_push($hotdates, $hotyd);
	//}#end_each_hotyd
//}#end_while
//echo "<BR>";
//print_r($hotdates);
#############################



//echo "<BR>";
//echo 'SELECT hotdates.roomid, hotdates.hotdates FROM hotdates, rooms WHERE hotdates.system_id='.$system_id.' and hotdates.roomid = rooms.id and hotdates.system_id = rooms.system_id';
//$result = mysql_query('SELECT hotdates.roomid, hotdates.hotdates FROM hotdates, rooms WHERE hotdates.system_id='.$system_id.' and hotdates.roomid = rooms.id and hotdates.system_id = rooms.system_id');
//while($dealrow = mysql_fetch_array($result)){
	//array_push($hotdates, $dealrow['hotdates']);
//}


//echo "<BR>*****************";
//print_r($hotdates);

// Only Display Where Guest Counts Are Allowed
//echo"<BR>";
//echo $tquery="select id,avail from rooms where max >= ".$total_guests." and system_id=".$system_id;
$result = mysql_query("select id,avail from rooms where max >= '$total_guests' and system_id=".$system_id);
if($result) {
	while ( $row = mysql_fetch_array($result) ) {
		$avail = $row['avail'] + $avail;
		$temp_roomid = $row[id];
		$typesql .= "roomid='$temp_roomid' or ";
	}
}

// If typesql -- Delete Last or Off typesql
if($typesql){
	$typesql = preg_replace("/ or $/", "", $typesql);
	$typesql = " and (".$typesql.")";
}#end_typesql

// Parse $d
if($d) {
	list ($year, $month, $day) = split ('[-]', $d);
}

$loop=0;
$hotdealsago=0;
$hotdealcount=0;

if($year && (!$month)) { $month = 1; }
if($year or $month) {
	$hotdealsago=1;
	$newyear = $year;
	$newmonth = $month;
}#end_year_and_month

if(!$year) { $year = date(Y); }
if(!$month) { $month = date(m); }#end_no_month

while($hotdealsago != 1) {
	$newmonth = date ("m", mktime (0,0,0,$month+$hotdealcount,1,$year));
	$newyear = date ("Y", mktime (0,0,0,$month+$hotdealcount,1,$year));
	$yearmonth = $newyear."-".$newmonth;

		// Find Starting Hot Deals Month
		foreach($hotdates as $hotyd) {
			$hotyearmonth = substr($hotyd, 0, 7);
			##DEBUG##echo $hotyearmonth."|".$yearmonth."<br>\n";
			if($hotyearmonth == $yearmonth) { $hotdealsago=1; }
		}#end_foreach_hotdate

	$hotdealcount++;
	if($hotdealcount > 12) {
		$nohotdeals = 1;
		break;
	}#end_hotdealcount
}#end_while_hotdealsago

if($nohotdeals) {
	header("Location: dorsindex1.php?page=view&system_id=".$system_id."&errors=Currently there is No Availability for any Hot Deals.");
	exit;
}#end_hot_deals

$year = $newyear;
$month = $newmonth;

$monthonet = $month;

// Grab Current Year-Month-Day string
$cur_aday = date("Y-m-d");

// Create Prev and Next months
$prev_link = "<a href='dorsindex1.php?page=checkdeal&system_id=$system_id&r=$r&s=$s&c=$c&a=$a&d=".date ("Y-m-d", mktime (0,0,0,$month-4,1,$year))."'>Previous</a>";
$next_link = "<a href='dorsindex1.php?page=checkdeal&system_id=$system_id&r=$r&s=$s&c=$c&a=$a&d=".date ("Y-m-d", mktime (0,0,0,$month+4,1,$year))."'>Next</a>";


// Create Hidden Variables
$hidden_variables = "
              <input type=hidden name=month value='$month'>
              <input type=hidden name=c value='$c'>
              <input type=hidden name=a value='$a'>
              <input type=hidden name=s value='$s'>
";


// Create Rooms Select
$roomcount=0;
while($roomcount < 10) {
	$roomcount++;
	if($r == $roomcount) { $selected = "selected"; } else { $selected = ""; }
	$rooms_select .= "<option value='$roomcount'$selected>$roomcount room";
	if($roomcount>1) { $rooms_select .= "s"; }
	$rooms_select .= "</option>";
}


// Year Select
while($count < 5) {
	if($opyear == $year) { $selected = "selected"; }
	$year_select .= "<option value='$opyear' $selected>Year - $opyear</option>";
	$selected="";
	$count++; $opyear++;
}

//Include Header file

/*if(!empty($template))
{
	include("theme/".$template."/check_deals_header.inc");
}
else
{
	include("html/check_deals_header.inc");
}*/

if(strtolower($template) != 'default'){
	eval("echo \$html_header;");
}
else{
	include_once("html/rooms_header_roomdors.inc");
}

if(strtolower($template) != 'default'){
	if(!empty($html_left)){
		eval("echo \$html_left;");
	}
}

include("theme/defaultbody/checkdeals_body1.inc");

while($loop < 2) {

$month1 = date ("M-Y", mktime (0,0,0,$month,1,$year));
$month++;
$month2 = date ("M-Y", mktime (0,0,0,$month,1,$year));
$month++;

/*if(!empty($template))
{
	include("theme/".$template."/check_month.inc");
}
else
{
	include("html/check_month.inc");
}*/

include("theme/defaultbody/check_month.inc");

#
# Loop Two Month Cycle
#

$loopmonth=0;
while($loopmonth < 2) {
	$monthone = date ("m", mktime (0,0,0,$monthonet,1,$year));

	$startmon=0;
	if($year == date(Y)) {
			if($monthone == date(m)) {
				$startmon = 1;
				}
		}#if_year


#
# Loop Through Calendar Weeks
#

$loopweek=0;
$curday=0;
while($loopweek < 6) {

	if($loopweek==0) {

	/*if(!empty($template))
	{
		include("theme/".$template."/check_week.inc");
	}
	else
	{
		include("html/check_week.inc");
	}*/

	include("theme/defaultbody/check_week.inc");

} #end_week_0

echo "<tr>";

#
# Loops Through Calendar Days
#
$dayloop=1;
$set_day = date ("D", mktime (0,0,0,$monthonet,1,$year));
$set_lookup = date ("Y-m", mktime (0,0,0,$monthonet,1,$year));
if($curday == 0) { $delay = $week_lookup{$set_day};}
$monthdone = $month_end{$monthone};

#
# Make sure you cant link days already passed!
#


while($dayloop <  {

if($dayloop == $delay) { $delay=0; }
if(!$delay) { $curday++; }
$adate_day = $curday;
if($adate_day < 10) { $adate_day = "0".$adate_day; }
$adate = $set_lookup."-".$adate_day;

// Check if $adate is old
if($adate < $cur_aday) { $bad_day = 1; } else { $bad_day = 0; }


$taken=0; $total=0;

#
# Select Taken Rooms
#
//echo "<BR>";
//echo "select avail from availability where system_id=".$system_id." and adate = '$adate'$typesql group by roomid";
$result = mysql_unbuffered_query("select avail from availability where system_id=".$system_id." and adate = '$adate'$typesql group by roomid");
while ( $row = mysql_fetch_array($result, MYSQL_NUM) ) {
	$taken += $row[0];
}

// Hot Deals Hack
$hotdeals_header="";
//if($hotdates){
	// Cycle through the next few dates
	$hotcount=0;
	while($hotcount < $s){
		$hotdeals_header="";
		$hotadate = date ("Y-m-d", mktime (0,0,0,$monthonet,$adate_day+$hotcount,$year));
		//if(in_array($hotadate, $hotdates)){
			//echo "<br>select count(*) as pkgcount from datavars, rooms_pkg where datavars.bigdata LIKE '%".$hotadate."%' and datavars.tid='hotdates' and datavars.system_id=".$system_id." and rooms_pkg.delflag=0 and datavars.sid=rooms_pkg.id AND '".$hotadate."' BETWEEN rooms_pkg.date_start and rooms_pkg.date_end";
			$tresult = mysql_query("select count(*) as pkgcount from datavars, rooms_pkg where datavars.bigdata LIKE '%".$hotadate."%' and datavars.tid='hotdates' and datavars.system_id=".$system_id." and rooms_pkg.delflag=0 and datavars.sid=rooms_pkg.id AND '".$hotadate."' BETWEEN rooms_pkg.date_start and rooms_pkg.date_end");
			$arrtresult = mysql_fetch_array($tresult);

			$result = mysql_query("SELECT count(*) as roomcount FROM hotdates, rooms WHERE hotdates.system_id=".$system_id." and hotdates.roomid = rooms.id and hotdates.system_id = rooms.system_id and hotdates.hotdates = '".$hotadate."'");
			$arrresult = mysql_fetch_array($result);

			if($arrtresult['pkgcount'] > 0 || $arrresult['roomcount'] > 0){
				$hotdeals_header = "<td align=center bgcolor='#FF6600'>\n";
			}
		//}
		else{
			break;
		}
		$hotcount++;
	}
//}#end_hot_dates


// Display Proper Date
$total = $avail - $taken;
if( ($curday == 0) || ($curday > $monthdone) ) {
	echo $global_sys_config['check_day_blank'];
} elseif( (($today > ($curday-$DayDelay)) && ($startmon)) || ($bad_day == 1) ) {
	echo $global_sys_config['check_day_normal']."$curday</font></td>";
} elseif($rooms > $total) {
	echo $global_sys_config['check_day_full']."$curday</td>";
} else {
	if(!$hotdeals_header) { echo $global_sys_config['check_day_avail']; } else { echo $hotdeals_header; }
	echo "<a href='dorsindex1.php?page=rooms&system_id=$system_id&r=$r&d=$adate&s=$s&c=$c&a=$a'>$curday</a></font></td>\n";
}#end_proper_date_display

$dayloop++;
} #end_day_loop

echo "</tr>";

if($curday >= $monthdone) {
	echo "</table></td>";
	$loopweek = 7;
	} #end_week_0

$loopweek++;
} #end_week_loop

$loopmonth++;
$monthonet++;
} #end_month_loop

?>
          </tr>
<?

$loop++;
} #end_main_while_loop


echo "</table>";
/*if(!empty($template))
{
	include("theme/".$template."/check_footer.inc");
}
else
{
	include("html/check_footer.inc");
}*/

echo '<center>'.$prev_link.' &nbsp; | &nbsp; '.$next_link.'</center>';
echo '<br><br>';
if(strtolower($template) != 'default'){
	eval("echo \$html_footer;");
}
else{
	include("html/rooms_footer.inc");
}

function is_leap ($year) { return (!($year % 4) && (($year % 100) || !($year % 400))); }

?>

Posted: Fri Sep 02, 2005 6:14 pm
by Burrito
I'm at a loss as to why you're using js to create the date? Why don't you just use php to grab the current date (on this page: http://kiss1.getdors.com/dorsdemo/dorsi ... dateString) and build out however far you want from there.

there's no sense in creating the date on the first page with js and passing it to the second when it can all be done on the second.

Posted: Fri Sep 02, 2005 11:28 pm
by kingman65
The main reason the date is on the first page is because the viewers need to be able to enter a date to check availability which is the other part of the application. So I need the check availability to be text fields while I need the hot deals to just see the month and year and go to the right part of the calender.

Posted: Sat Sep 03, 2005 10:19 am
by Burrito
there's still no reason to format the date using js like that. If you're dead set on using js to send the date, just send it as a string and then parse it as a date on the action page.

the way I'd do it however, is (assuming you want to keep three separate fields like you've got) send the three post vars to the action page and then concat them together and parse it as a date (the date that you want).

Posted: Sat Sep 03, 2005 11:11 am
by kingman65
Doing it the way you suggest, would I be able to send it to two different handlers? The first submit (check availability) is one form it posts to dors_portal.php and the second one (hot deals) is a second form that posts to check_deals.php. Can I reference those variables from both forms?

Posted: Sat Sep 03, 2005 7:28 pm
by Burrito
just send it to one page and check which button was pressed. Or put two different forms on the same page with different actions.

Posted: Sun Sep 04, 2005 7:25 am
by raghavan20
alright this seems to be the url that is used to show the hot deals in the calendar

Code: Select all

http://kiss1.getdors.com/dorsdemo/dorsindex1.php?page=checkdeal&system_id=80&r=1&s=1&c=&a=1&d=2005-05-01
you see the last part "d=2005-05-01"
somehow when the user clicks on hot deals from the main page; you have to pass the current date

that hot deals button is a gif image...so it shd be

Code: Select all

$currentDate = date("Y-m-d");
<a href="http://kiss1.getdors.com/dorsdemo/dorsindex1.php?page=checkdeal&system_id=80&r=1&s=1&c=&a=1&d={$currentDate}">Get Hot Deals</a>
try this and let me know