'; $dir_images = "./images/"; $cal_no_day = ' '; // C - for calendar function $lang=array(); $lang["months"] = array("January","February","March","April","May","June","July","August","September","October","November","December"); $lang["days"] = array("Sunday","Monday","Tuesday","Wednesday","Thursay","Friday","Saturday"); $lang["months_short"] = array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); // check the availability table exists in the database if(!mysql_is_table($cal_table)){ echo ' Database table '.$cal_table.' does not exist.
Before you can run this script you need to create the availability table in your data base.

CREATE AVAILABILITY TABLE IN DATABASE '; exit; } // get the POSTED variables - or set to defaults // get booking date if (isset($_POST['book_month']) && is_numeric($_POST['book_month']) && ((int)$_POST['book_month'] >= 1 && (int)$_POST['book_month'] <= 12)) { $book_month = (int)$_POST['book_month']; } else { $book_month = date('n'); } if (isset($_POST['book_year']) && is_numeric($_POST['book_year']) && ((int)$_POST['book_year'] >= 2005 && (int)$_POST['book_year'] <= 2010)) { $book_year = (int)$_POST['book_year']; } else { $book_year = date('Y'); } if (isset($_POST['book_day']) && is_numeric($_POST['book_day']) && ((int)$_POST['book_day'] >= 1 && (int)$_POST['book_day'] <= 31)) { $book_day = (int)$_POST['book_day']; } else { $book_day = date('d'); } if (isset($_POST['book_days']) && is_numeric($_POST['book_days']) && ((int)$_POST['book_days'] >= 1 )) { $book_days = (int)$_POST['book_days']; } else { $book_days = 1; } // set to view up to 13 months $months_to_view = 13; // get current date variables $cur_year = date('Y'); //$cur_month = date('m'); CHANGED TO SEE IF I COULD GET DATE LIMITS TO WORK $cur_month = date('n'); $cur_day = date('d'); // get number of days in the current month $m_days = date('t',time()); // get number of days in the max bookable month $m13_days = date('t',mktime(12,0,0,$cur_month+$months_to_view,$m_days,$cur_year)); //get timestamp for today $now = mktime(12,0,0,$cur_month,$cur_day,$cur_year); //get timestamp for last bookable day $now_plus_mths = mktime(12,0,0,$cur_month+$months_to_view,$m13_days,$cur_year); // formatted booking limits $nowf = strftime('%d %b %y',$now); $now_plus_mthsf = strftime('%d %b %y',$now_plus_mths); // validate booking date // initialise error field with a value of 1 $book_date_error = 1; $book_first_night = mktime(12,0,0,$book_month,$book_day,$book_year); $book_last_morning = mktime(12,0,0,$book_month,$book_day+$book_days,$book_year); $book_last_night = mktime(12,0,0,$book_month,$book_day+$book_days-1,$book_year); $b_start = strftime('%d %b %y',$book_first_night); $b_end = strftime('%d %b %y',$book_last_night); $b_endm = strftime('%d %b %y',$book_last_morning); // uncomment this to view booking parameters //echo 'Booking starts / ends on : '.$b_start.' / '.$b_end; //echo '
Departing morning of : '.$b_endm; // set error field to 0 if the days we want to book fall between the booking parameter limits if ($book_first_night >= $now && $book_last_night <= $now_plus_mths) { $book_date_error = 0; } // loop round each of the rooms to get their availability from the database // and then loop round the months (3) to draw the calendar for each room // putting this calendar into an array called $calendar_months[$id_item] $max_rooms = 6; $id_item=1; for($id_item ==1;$id_item <= $max_rooms;$id_item++){ // get bookings for this month for this room $booked_days = array(); $sql="SELECT the_date FROM ".$cal_table." WHERE id_item=".$id_item.""; if(!$res=mysql_query($sql)) die("ERROR checking id item availability dates"); while($row=mysql_fetch_array($res)){ $booked_days[]=$row["the_date"]; } // show calendar if($cur_month == 12){ $next_month = 1; }else{ $next_month = $cur_month + 1; } if($_POST["sel_ym"] == 0){ $sel_month = $next_month; if ($sel_month == 12) { $sel_year = $cur_year + 1; } else { $sel_year = $cur_year; } $sel_ym = $sel_year*100 + $sel_month; }else{ $sel_month = $_POST["sel_ym"]%100; $sel_year = ($_POST["sel_ym"] - $sel_month)/100 ; $sel_ym = $_POST["sel_ym"]; } $the_months=array(); $total_months_to_show=3; if($sel_month == 1){ $k = 12; $cal_year = $sel_year - 1; } else { $k=$sel_month - 1; $cal_year = $sel_year; } $j=0; while($j<$total_months_to_show){ $this_month=sprintf("%02s",$k); $the_months[$this_month]=array("year"=>$cal_year,"month"=>$this_month); $j++; if($k==12){ // start new year and reset counter to 1 (jan) $cal_year=$cal_year+1; $k=1; }else{ $k++; } } // loop through months to draw calendar $calendar_months[$id_item].=' '; $j=1; foreach($the_months as $key=>$val){ $calendar_months[$id_item].=''; if (($j % 3) == 0)$calendar_months[$id_item].=""; ++$j; } $calendar_months[$id_item].='
'.draw_cal($id_item,$val["month"], $val["year"], $booked_days,0).'
'; } // put the availabilty month selection form into the string $the_form $the_form = draw_form($cur_month,$cur_year,$sel_ym,$sel_month,$months_to_view); // put the booking date selection into the string $the_booking_date $the_booking_date = draw_book_date($book_day,$book_month,$book_year,$book_days); // put the booking button into the string $the_booking_button $the_booking_button = draw_book_button(); // go to the database and get the room details $rooms_table = 'rooms'; //$room_descr=array(); $i = 1; for($i ==1;$i <= $max_rooms;$i++){ $sql="SELECT * FROM ".$rooms_table." WHERE id_item=".$i.""; if(!$res=mysql_query($sql)) die("ERROR getting room description"); while($row=mysql_fetch_array($res)){ $room_descr[$i]=$row["room_desc"]; $room_name[$i]=$row["room_name"]; $room_tariff[$i]=array("single"=>$row["single_occ"],"double"=>$row["double_occ"],"family"=>$row["family_occ"]); } } // for each room call the draw_room and draw_tariff functions that // draw tables containing room description and room tariff $i = 1; for($i ==1;$i <= $max_rooms;$i++){ $room_table[$i] = draw_room($i, $room_name, $room_descr); $tariff_table[$i] = draw_tariff($i, $room_tariff, $room_name); } // START FUNCTIONS function draw_cal($id,$month, $year, $booked_days,$show_link){ global $lang,$dir_images,$cal_no_day; $month_name = $lang["months"][($month-1)]; $td_width = "20"; $cur_year = date('Y'); $cur_month = date('m'); $cur_day = date('d'); $this_month = getDate(mktime(0, 0, 0, $month, 1, $year)); $next_month = getDate(mktime(0, 0, 0, $month + 1, 1, $year)); # needed to draw cal //$last_month = getDate(mktime(0, 0, 0, $month - 1, 1, $year)); //Find out when this month starts and ends. $first_week_day = $this_month["wday"]; $days_in_this_month = round(($next_month[0] - $this_month[0]) / (60 * 60 * 24)); $the_cal=' '; if ($first_week_day == 0){ $first_week_day =7; } for($k=1; $k<=7; $k++){ if($k==7) $weekday = substr($lang["days"][0],0,1); else $weekday = substr($lang["days"][$k],0,1); $the_cal.=''; } $the_cal.=' '; //Fill the first week of the month with the appropriate number of blanks. $j=1; for($week_day = 0; $week_day < ($first_week_day-1); $week_day++){ $the_cal.=''; $j++; } $week_day=$j; $day_of_week=0; for($day_counter = 1; $day_counter <= $days_in_this_month; $day_counter++){ $this_date = $year."-".sprintf("%02s",$month)."-".sprintf("%02s",$day_counter); $date_format = $day_counter."/".$month."/".$year; // check if day is available if(in_Array($this_date,$booked_days)) $day_image='cal_on_'.$day_counter.'.png'; else $day_image='cal_off_'.$day_counter.'.png'; // show ajax link or not if($show_link==1){ $day_link_start =''; $day_link_end =''; }else{ $day_link_start =""; $day_link_end =""; } // highlight current day if( ($day_counter==$cur_day) && ($month==$cur_month) && ($year==$cur_year)) $border='style="border: 1px solid #009900"'; else $border='"style="border: 1px solid #f6f0e0"'; $the_cal .= ' '; // end row if Sunday $week_day %= 7; if($week_day == 0) $the_cal .= ""; $week_day++; } if($week_day > 1){ for($till_day = $week_day; $till_day <=7; $till_day++){ $the_cal .= ''; } } $the_cal.="
'.$month_name.' '.$year.'
'.$weekday.'
'.$cal_no_day.' '.$day_link_start.' '.$lang[ '.$day_link_end.'
'.$cal_no_day.'
"; return $the_cal; } // check table is created function mysql_is_table($tbl){ $tables = array(); $sql="SHOW TABLES"; $res=mysql_query($sql); while ($r = mysql_fetch_array($res)) { $tables[] = $r[0]; } if (in_array($tbl, $tables)) return TRUE; else return FALSE; } // function to draw availabilty month selection form function draw_form($cur_month,$cur_year,$sel_ym,$sel_month,$months){ global $lang, $book_day, $book_month, $book_year, $book_days; $the_form ='
'; return $the_form; } // function to draw booking date form limited to $months_to_view (13) function draw_book_date($book_day,$book_month,$book_year,$book_days){ global $sel_ym, $now_plus_mths, $now, $cur_day, $cur_month, $cur_year; $the_book_date = '
'; $the_book_date .= ''; $the_book_date .= ''; $the_book_date .= ''; $the_book_date .= ' for: '; if ($book_days == 1) { $nights = 'night.'; } else { $nights = 'nights.'; } $the_book_date .= $nights; $the_book_date .= ' '; $the_book_date .= '
'; return $the_book_date; } // function to create booking submission button function draw_book_button(){ global $book_day, $book_month, $book_year, $book_days, $book_date_error, $nowf, $now_plus_mthsf; $the_book_but = '
'; if ($book_date_error == 1) { $the_book_but .= 'Please make sure the dates you have entered fall between '.$nowf.' and '.$now_plus_mthsf; } else { $the_book_but .= ''; } $the_book_but .= '
'; return $the_book_but; } // function to draw room tariff table function draw_tariff($id, $room_tariff, $room_name){ // START FUNCTION global $blank_spacer; $the_tariff_table = ''; if ($room_tariff[$id]['family'] != NULL){ // DO IF FAMILY ROOM $the_tariff_table .= ''; } // END DO IF FAMILY ROOM $the_tariff_table .= '
Room Tariff
'.$blank_spacer.' '.$blank_spacer.' '.$blank_spacer.'
Double '.$blank_spacer.' £'.$room_tariff[$id]['double'].'
'.$blank_spacer.' '.$blank_spacer.' '.$blank_spacer.'
Single '.$blank_spacer.' £'.$room_tariff[$id]['single'].'
'.$blank_spacer.' '.$blank_spacer.' '.$blank_spacer.'
Family '.$blank_spacer.' £'.$room_tariff[$id]['family'].'
'; return $the_tariff_table; } // END FUNCTION // function to draw room description table function draw_room($id, $room_name, $room_descr){ global $blank_spacer; $the_room_table = '
'.$room_name[$id].'
'.$blank_spacer.'
'.$room_descr[$id].'
'; return $the_room_table; } ?>
Step 1 of 7   Show me what is available in:    
   
available: date available   booked: date booked
   
   
   
   
   
   
   
         
Step 2 of 7   I would like to book: