Xster Posted January 22, 2007 Share Posted January 22, 2007 Hi,Im a newbies in this forum..so,pls teach me as good as u can...Em, lets get in started...1. how to block the calender after the current day...i mean after this day (eg 1,2,3 Jan...and so on)2. how to create a good validation,because the script is always accept even if userdidn't insert any number inside the box (eg Time From : - (none) and Time To : - (none)2. how can i add more features for admin to block the calender to user information before they book the dates with a proper reason (eg : for maintenance, lights broken and so on..)btw, the script is all about facilities..means that user can choose any day to select facility such as tennis court, basketball court etc...p/s: thk u! Quote Link to comment Share on other sites More sharing options...
linuxdream Posted January 22, 2007 Share Posted January 22, 2007 What code do you have so far? Would be helpful to post. Quote Link to comment Share on other sites More sharing options...
Xster Posted January 22, 2007 Author Share Posted January 22, 2007 [quote author=linuxdream link=topic=123436.msg510280#msg510280 date=1169439308]What code do you have so far? Would be helpful to post. [/quote]Post? Ok sir... $d = getdate(time()); $month = $_GET['month']; $year = $_GET['year']; if ($month == "") { $month = $d["mon"]; } if ($year == "") { $year = $d["year"]; } $cal = new MyCalendar; echo $cal->getMonthView($month, $year, $fac_id, $fac_name); class Calendar { function Calendar() { } function getDayNames() { return $this->dayNames; } function setDayNames($names) { $this->dayNames = $names; } function getMonthNames() { return $this->monthNames; } function setMonthNames($names) { $this->monthNames = $names; } function getStartDay() { return $this->startDay; } function setStartDay($day) { $this->startDay = $day; } function getStartMonth() { return $this->startMonth; } function setStartMonth($month) { $this->startMonth = $month; } function getCalendarLink($month, $year, $fac_id, $fac_name) { return "month=$month&year=$year&fac_id=$fac_id&fac_name=$fac_name"; } function getDateLink($day, $month, $year, $fac_id, $fac_name) { $facBooked_date=""; $link = "user_facilitiesTime.php?fac_id=$fac_id&fac_name=$fac_name&facBooked_date=$year-$month-$day"; return $link; } function getCurrentMonthView($fac_id, $fac_name) { $d = getdate(time()); return $this->getMonthView($d["mon"], $d["year"], $fac_id, $fac_name); } function getCurrentYearView() { $d = getdate(time()); return $this->getYearView($d["year"]); } function getMonthView($month, $year, $fac_id, $fac_name) { return $this->getMonthHTML($month, $year,1, $fac_id, $fac_name); } function getYearView($year) { return $this->getYearHTML($year); } function getDaysInMonth($month, $year) { if ($month < 1 || $month > 12) { return 0; } $d = $this->daysInMonth[$month - 1]; if ($month == 2) { if ($year%4 == 0) { if ($year%100 == 0) { if ($year%400 == 0) { $d = 29; } } else { $d = 29; } } } return $d; } function getMonthHTML($m, $y, $showYear = 1, $fac_id, $fac_name) { $s = ""; $a = $this->adjustDate($m, $y); $month = $a[0]; $year = $a[1]; $daysInMonth = $this->getDaysInMonth($month, $year); $date = getdate(mktime(12, 0, 0, $month, 1, $year)); $first = $date["wday"]; $monthName = $this->monthNames[$month - 1]; $prev = $this->adjustDate($month - 1, $year); $next = $this->adjustDate($month + 1, $year); if ($showYear == 1) { $prevMonth = $this->getCalendarLink($prev[0], $prev[1], $fac_id, $fac_name); $nextMonth = $this->getCalendarLink($next[0], $next[1], $fac_id, $fac_name); } else { $prevMonth = ""; $nextMonth = ""; } $header = $monthName . (($showYear > 0) ? " " . $year : ""); //display month and year (<< month >>) $s .= "<table bgcolor=\"#ffffff\" height=\"120px\" width=\"450px\" border=\"1\" bordercolor=\"#FFFFCC\" cellspacing=\"0\" cellpadding=\"5\" align=\"center\" class=\"calendar\">\n"; $s .= "<tr>\n"; $s .= "<td align=\"center\" valign=\"top\" class=\"calendarHeader\">" . (($prevMonth == "") ? " " : "<a href=\"$prevMonth\" class=\"month\"><<</a>") . "</td>\n"; $s .= "<td align=\"center\" valign=\"top\" class=\"calendarMonth\" colspan=\"5\">$header</td>\n"; $s .= "<td align=\"center\" valign=\"top\" class=\"calendarHeader\">" . (($nextMonth == "") ? " " : "<a href=\"$nextMonth\" class=\"month\">>></a>") . "</td>\n"; $s .= "</tr>\n"; //display days(mon, tue,...) $s .= "<tr>\n"; $s .= "<td align=\"center\" valign=\"top\" class=\"calendarHeader\">" . $this->dayNames[($this->startDay)%7] . "</td>\n"; $s .= "<td align=\"center\" valign=\"top\" class=\"calendarHeader\">" . $this->dayNames[($this->startDay+1)%7] . "</td>\n"; $s .= "<td align=\"center\" valign=\"top\" class=\"calendarHeader\">" . $this->dayNames[($this->startDay+2)%7] . "</td>\n"; $s .= "<td align=\"center\" valign=\"top\" class=\"calendarHeader\">" . $this->dayNames[($this->startDay+3)%7] . "</td>\n"; $s .= "<td align=\"center\" valign=\"top\" class=\"calendarHeader\">" . $this->dayNames[($this->startDay+4)%7] . "</td>\n"; $s .= "<td align=\"center\" valign=\"top\" class=\"calendarHeader\">" . $this->dayNames[($this->startDay+5)%7] . "</td>\n"; $s .= "<td align=\"center\" valign=\"top\" class=\"calendarHeader\">" . $this->dayNames[($this->startDay+6)%7] . "</td>\n"; $s .= "</tr>\n"; $d = $this->startDay + 1 - $first; while ($d > 1) { $d -= 7; } $today = getdate(time()); include('../Connections/mConn2.php'); //display day of the month in table while ($d <= $daysInMonth) { $s .= "<tr>\n"; for ($i = 0; $i < 7; $i++) { $class = ($year == $today["year"] && $month == $today["mon"] && $d == $today["mday"]) ? "calendarToday" : "calendar"; $s .= "<td class=\"$class\" align=\"center\" valign=\"middle\" bgcolor=\"#ffffff\">"; if ($d > 0 && $d <= $daysInMonth) { $link = $this->getDateLink($d, $month, $year, $fac_id, $fac_name, $i); $ymd = "$year-$month-$d"; mysql_select_db($database_mConn, $mConn); $query_rsq = "SELECT offDay,reason FROM offday WHERE fac_id='$fac_id' AND offDay='$ymd'"; $rsq = mysql_query($query_rsq, $mConn) or die(mysql_error()); $row_rsq = mysql_fetch_assoc($rsq); $totalRows_rsq = mysql_num_rows($rsq); $reason= $row_rsq['reason']; if ($totalRows_rsq=="0") { //normal work day $s .= (($link == "") ? $d : "<a href=\"$link\" style=\"cursor:hand; text-decoration:none;\" class=\"calendar\">$d</a>"); }else{ //selected off day $s .= (($link == "") ? $d : "<div class=\"offday\" ONMOUSEOVER=\"popup('OFF Day reason due to: ".$reason."','lightblue')\"; ONMOUSEOUT=\"kill()\">$d</div>"); } //mysql_free_result($rsq); } else { $s .= " "; } $s .= "</td>\n"; $d++; } $s .= "</tr>\n"; } $s .= "</table>\n"; return $s; } function getYearHTML($year) { $s = ""; $prev = $this->getCalendarLink(0, $year - 1, $fac_id, $fac_name); $next = $this->getCalendarLink(0, $year + 1, $fac_id, $fac_name); $s .= "<table class=\"calendar\" border=\"0\">\n"; $s .= "<tr>"; $s .= "<td align=\"center\" valign=\"top\" align=\"left\">" . (($prev == "") ? " " : "<a href=\"$prev\"><<</a>") . "</td>\n"; $s .= "<td class=\"calendarHeader\" valign=\"top\" align=\"center\">" . (($this->startMonth > 1) ? $year . " - " . ($year + 1) : $year) ."</td>\n"; $s .= "<td align=\"center\" valign=\"top\" align=\"right\">" . (($next == "") ? " " : "<a href=\"$next\">>></a>") . "</td>\n"; $s .= "</tr>\n"; $s .= "<tr>"; $s .= "<td class=\"calendar\" valign=\"top\">" . $this->getMonthHTML(0 + $this->startMonth, $year, 0, $fac_id, $fac_name) ."</td>\n"; $s .= "<td class=\"calendar\" valign=\"top\">" . $this->getMonthHTML(1 + $this->startMonth, $year, 0, $fac_id, $fc_name) ."</td>\n"; $s .= "<td class=\"calendar\" valign=\"top\">" . $this->getMonthHTML(2 + $this->startMonth, $year, 0, $fac_id, $fac_name) ."</td>\n"; $s .= "</tr>\n"; $s .= "<tr>\n"; $s .= "<td class=\"calendar\" valign=\"top\">" . $this->getMonthHTML(3 + $this->startMonth, $year, 0, $fac_id, $fac_name) ."</td>\n"; $s .= "<td class=\"calendar\" valign=\"top\">" . $this->getMonthHTML(4 + $this->startMonth, $year, 0, $fac_id, $fac_name) ."</td>\n"; $s .= "<td class=\"calendar\" valign=\"top\">" . $this->getMonthHTML(5 + $this->startMonth, $year, 0, $fac_id, $fac_name) ."</td>\n"; $s .= "</tr>\n"; $s .= "<tr>\n"; $s .= "<td class=\"calendar\" valign=\"top\">" . $this->getMonthHTML(6 + $this->startMonth, $year, 0, $fac_id, $fac_name) ."</td>\n"; $s .= "<td class=\"calendar\" valign=\"top\">" . $this->getMonthHTML(7 + $this->startMonth, $year, 0, $fac_id, $fac_name) ."</td>\n"; $s .= "<td class=\"calendar\" valign=\"top\">" . $this->getMonthHTML(8 + $this->startMonth, $year, 0, $fac_id, $fac_name) ."</td>\n"; $s .= "</tr>\n"; $s .= "<tr>\n"; $s .= "<td class=\"calendar\" valign=\"top\">" . $this->getMonthHTML(9 + $this->startMonth, $year, 0, $fac_id, $fac_name) ."</td>\n"; $s .= "<td class=\"calendar\" valign=\"top\">" . $this->getMonthHTML(10 + $this->startMonth, $year, 0, $fac_id, $fac_name) ."</td>\n"; $s .= "<td class=\"calendar\" valign=\"top\">" . $this->getMonthHTML(11 + $this->startMonth, $year, 0, $fac_id, $fac_name) ."</td>\n"; $s .= "</tr>\n"; $s .= "</table>\n"; return $s; } function adjustDate($month, $year) { $a = array(); $a[0] = $month; $a[1] = $year; while ($a[0] > 12) { $a[0] -= 12; $a[1]++; } while ($a[0] <= 0) { $a[0] += 12; $a[1]--; } return $a; } var $startDay = 0; var $startMonth = 1; var $dayNames = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); var $monthNames = array("JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"); var $daysInMonth = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); } class MyCalendar extends Calendar { function getCalendarLink($month, $year, $fac_id, $fac_name) { $s = getenv('SCRIPT_NAME'); return "$s?month=$month&year=$year&fac_id=$fac_id&fac_name=$fac_name"; } } /*$d = getdate(time()); if ($month == "") { $month = $d["mon"]; } if ($year == "") { $year = $d["year"]; } $cal = new MyCalendar; echo $cal->getMonthView($month, $year,$fac_id, $fac_name);*/?> Quote Link to comment Share on other sites More sharing options...
Xster Posted January 22, 2007 Author Share Posted January 22, 2007 Sir...the code that I posted is for 'select date' form.ok... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.