$d, 'month'=>$m, 'year'=>$y); // If user specify Day, Month and Year, reset the var if (isset($_GET['m'])) { $y = $_GET['y']; $m = $_GET['m']; } // CONFIGURE THE DB ACCESS $dbhost = 'localhost'; $dbuser = 'your_name'; $dbpass = 'your_pass'; $database = "your_db"; $dbConnect = mysql_connect($dbhost, $dbuser, $dbpass); if (!$dbConnect) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db($database, $dbConnect); if (!$db_selected) { die ('db selection error : ' . mysql_error()); } // name of table $tableName = 'calendar'; // name of css $css = 'calendar'; // Location of the calendar script file from the root $ajaxPath = '/quick_calendar.php'; // END OF CONFIGURATION. YOU CAN CHANGE THE CSS. THE OTHER CODES CAN BE KEPT AS DEFAULT IF YOU WANT. $sql = "SELECT * FROM $tableName WHERE (month='$m' AND year='$y') || (month='*' AND year='$y') || (month='$m' AND year='*') || (month='*' AND year='*')"; $rs = mysql_query($sql); $links = array(); while ($rw = mysql_fetch_array($rs)) { extract($rw); $links[] = array('day'=>$day, 'month'=>$month, 'year'=>$year, 'link'=>$link, 'desc'=>$desc); } ?> month = $month; $this->year = $year; $this->week = array(); $this->daysInMonth = date("t",mktime(0,0,0,$month,1,$year)); // get first day of the month $this->firstDay = date("w", mktime(0,0,0,$month,1,$year)); $tempDays = $this->firstDay + $this->daysInMonth; $this->weeksInMonth = ceil($tempDays/7); $this->fillArray(); } function fillArray() { // create a 2-d array for($j=0;$j<$this->weeksInMonth;$j++) { for($i=0;$i<7;$i++) { $counter++; $this->week[$j][$i] = $counter; // offset the days $this->week[$j][$i] -= $this->firstDay; if (($this->week[$j][$i] < 1) || ($this->week[$j][$i] > $this->daysInMonth)) { $this->week[$j][$i] = ""; } } } } } class QCalendar { var $html; var $weeksInMonth; var $week; var $month; var $year; var $today; var $links; var $css; function QCalendar($cArray, $today, &$links, $css='') { $this->month = $cArray->month; $this->year = $cArray->year; $this->weeksInMonth = $cArray->weeksInMonth; $this->week = $cArray->week; $this->today = $today; $this->links = $links; $this->css = $css; $this->createHeader(); $this->createBody(); $this->createFooter(); } function createHeader() { $header = date('M', mktime(0,0,0,$this->month,1,$this->year)).' '.$this->year; $nextMonth = $this->month+1; $prevMonth = $this->month-1; // thanks adam taylor for modifying this part switch($this->month) { case 1: $lYear = $this->year; $pYear = $this->year-1; $nextMonth=2; $prevMonth=12; break; case 12: $lYear = $this->year+1; $pYear = $this->year; $nextMonth=1; $prevMonth=11; break; default: $lYear = $this->year; $pYear = $this->year; break; } // -- $this->html = ""; } function createBody(){ // start rendering table $this->html.= ""; for($j=0;$j<$this->weeksInMonth;$j++) { $this->html.= ""; for ($i=0;$i<7;$i++) { $cellValue = $this->week[$j][$i]; // if today if (($this->today['day'] == $cellValue) && ($this->today['month'] == $this->month) && ($this->today['year'] == $this->year)) { $cell = "
$cellValue
"; } // else normal day else { $cell = "$cellValue"; } // if days with link foreach ($this->links as $val) { if (($val['day'] == $cellValue) && (($val['month'] == $this->month) || ($val['month'] == '*')) && (($val['year'] == $this->year) || ($val['year'] == '*'))) { $cell = ""; break; } } $this->html.= ""; } $this->html.= ""; } } function createFooter() { $this->html .= "
 month','".($this->year-1)."')\" class='headerNav' title='Prev Year'><<  < $header >   month','".($this->year+1)."')\" class='headerNav' title='Next Year'>>>
SMTWThFS
$cell
"; } function render() { echo $this->html; } } ?> "; } $cal->render(); if (!isset($_GET['ran'])) { echo ""; } ?>