Fantasia Posted October 10, 2008 Share Posted October 10, 2008 I have issues with my calendar:Actually it works allright biside that Ones I am forwarding the date the specific user who should get his specific info highlight in the calendar desapears, as far as I know it because of the update of Ajax, the page doesnt get the $req_user = $_GET['user']; as it supposted to do. The code is the follow first you fing the database and then the Calendar.php (Please HELP :'(): Database: CREATE DATABASE IF NOT EXISTS southwinds; USE southwinds; -- -- Definition of table `calendar` -- DROP TABLE IF EXISTS `calendar`; CREATE TABLE `calendar` ( `id` int(10) unsigned zerofill NOT NULL auto_increment, `day` varchar(2) collate latin1_general_ci NOT NULL, `month` varchar(2) collate latin1_general_ci NOT NULL, `year` varchar(4) collate latin1_general_ci NOT NULL, `link` varchar(255) collate latin1_general_ci NOT NULL, `desc` text collate latin1_general_ci NOT NULL, `username` varchar(30) collate latin1_general_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; -- -- Dumping data for table `calendar` -- /*!40000 ALTER TABLE `calendar` DISABLE KEYS */; INSERT INTO `calendar` (`id`,`day`,`month`,`year`,`link`,`desc`,`username`) VALUES (0000000001,'29','09','2008','www.google.com','hello','admin'), (0000000002,'06','10','2008','introduction.php','hi','admin'), (0000000003,'10','10','2008','www.google.com','haha','lea'), (0000000004,'09','10','2008','www.google.com','ll','admin'), (0000000005,'10','11','2008','www.isk.kth.se','55','admin'); /*!40000 ALTER TABLE `calendar` ENABLE KEYS */; -- -- Definition of table `users` -- DROP TABLE IF EXISTS `users`; CREATE TABLE `users` ( `username` varchar(30) collate latin1_general_ci NOT NULL default '', `password` varchar(32) collate latin1_general_ci default NULL, `userid` varchar(32) collate latin1_general_ci NOT NULL, `userlevel` tinyint(1) unsigned NOT NULL, `email` varchar(50) collate latin1_general_ci default NULL, `timestamp` int(11) unsigned NOT NULL, `name` varchar(45) collate latin1_general_ci NOT NULL, PRIMARY KEY (`userid`) ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; -- -- Dumping data for table `users` -- /*!40000 ALTER TABLE `users` DISABLE KEYS */; INSERT INTO `users` (`username`,`password`,`userid`,`userlevel`,`email`,`timestamp`,`name`) VALUES ('admin','233b47c75b7eb974cd10a4df3c838b9f','e7b326e466db55935d1f9fda6843c41a',1,'[email protected]',1223679511,''), ('aaaaaa','670b14728ad9902aecba32e22fa4f6bd','2',1,'[email protected]',1222318857,'fff'), ('fdfdfd','1d283bf95ee42cd40c6da74b7196a049','3',1,'[email protected]',1222319017,'fd'); /*!40000 ALTER TABLE `users` ENABLE KEYS */; Calendar.php: <?php // This year $y = date('Y'); // This month $m = date('n'); // This Day $d = date('j'); $today = array('day'=>$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 = 'root'; $dbpass = ''; $database = "southwinds"; $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 = '/calendar.php'; // END OF CONFIGURATION. YOU CAN CHANGE THE CSS. THE OTHER CODES CAN BE KEPT AS DEFAULT IF YOU WANT. $req_user = $_GET['user']; $sql = "SELECT * FROM $tableName WHERE username = '".mysql_escape_string($_REQUEST['user'])."' AND (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('username'=>$username, 'day'=>$day, 'month'=>$month, 'year'=>$year, 'link'=>$link, 'desc'=>$desc); } ?> <?php // if called via ajax, dont display style sheet and javascript again if (!isset($_GET['ran'])) { $req_user = $_GET['user']; $username = $_GET['user']; ?> <STYLE type="text/css"> .calendar { /** configure the width 202020 **/ width:220px; background-color: #272727; border: 1px solid #000000; font-family: verdana; font-size: 12px; margin:0px; padding:0px; text-align:center; } .calendar th { background-color: #FFCC00; font-weight: bold; height: 20px; color: #272727; } .calendar .header { background-color: #202020; font-weight: bold; height: 24px; color: #FFFFFF; } .calendar .footer { background-color: #202020; font-weight: bold; font-size:0.8em; color: #FFFFFF; width:100%; } .calendar td { width: 22px; height: 20px; text-align: center; font-size:0.9em; padding: 2px; } .calendar .today { width: 18px; height: 16px; background-color: #333333; color: #ffffff; font-weight: bold; padding: 2px; } .calendar .link { width: 18px; height: 16px; background-color: #000000; color: #000000; font-weight: bold; padding: 2px; border: 1px solid #202020; } .calendar a, .calendar a:link, .calendar a:hover { font-weight: bold; text-decoration: underline; color: #ffffff; } .calendar a.headerNav, .calendar a:link.headerNav, .calendar a:hover.headerNav { background-color: #202020; color: #ffffff; } .calendar a.footerNav, .calendar a:link.footerNav, .calendar a:hover.footerNav { width: 100%; background-color: #202020; color: #ffffff; } </style> <script language="javascript"> function createQCObject() { var req; if(window.XMLHttpRequest){ // Firefox, Safari, Opera... req = new XMLHttpRequest(); } else if(window.ActiveXObject) { // Internet Explorer 5+ req = new ActiveXObject("Microsoft.XMLHTTP"); } else { alert('Problem creating the XMLHttpRequest object'); } return req; } // Make the XMLHttpRequest object var http = createQCObject(); function displayQCalendar(m,y) { var ran_no=(Math.round((Math.random()*9999))); var username= '<php $req_user ?>'; http.open('get', 'calendar.php?m='+m+'&y='+y+'&ran='+ran_no+'&user='+username); http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200) { var response = http.responseText; if(response) { document.getElementById("quickCalender").innerHTML = http.responseText; } } } http.send(null); } </script> <?php } ?> <?php class CreateQCalendarArray { var $daysInMonth; var $weeksInMonth; var $firstDay; var $week; var $month; var $year; function CreateQCalendarArray($month, $year) { $this->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 = "<table cellspacing='0' cellpadding='0' class='$this->css'> <tr> <th class='header'> <a href=\"javascript:;\" onclick=\"displayQCalendar('$this->month','".($this->year-1)."')\" class='headerNav' title='Prev Year'><<</a></th> <th class='header'> <a href=\"javascript:;\" onclick=\"displayQCalendar('$prevMonth','$pYear')\" class='headerNav' title='Prev Month'><</a></th> <th colspan='3' class='header'>$header</th> <th class='header'><a href=\"javascript:;\" onclick=\"displayQCalendar('$nextMonth','$lYear')\" class='headerNav' title='Next Month'>></a> </th> <th class='header'> <a href=\"javascript:;\" onclick=\"displayQCalendar('$this->month','".($this->year+1)."')\" class='headerNav' title='Next Year'>>></a></th> </tr>"; } function createBody(){ // start rendering table $this->html.= "<tr><th>S</th><th>M</th><th>T</th><th>W</th><th>Th</th><th>F</th><th>S</th></tr>"; for($j=0;$j<$this->weeksInMonth;$j++) { $this->html.= "<tr>"; 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 = "<div class='today'>$cellValue</div>"; } // 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 = "<div class='link'><a href=\"{$val['link']}\" title='{$val['desc']}'>$cellValue</a></div>"; break; } } $this->html.= "<td>$cell</td>"; } $this->html.= "</tr>"; } } function createFooter() { $this->html .= "<tr><td colspan='7' class='footer'><a href=\"javascript:;\" onclick=\"displayQCalendar('{$this->today['month']}','{$this->today['year']}')\" class='footerNav'>Today is {$this->today['day']} ".date('M', mktime(0,0,0,$this->today['month'],1,$this->today['year']))." {$this->today['year']}</a></td></tr></table>"; } function render() { echo $this->html; } } ?> <?php // render calendar now $cArray = &new CreateQCalendarArray($m, $y); $cal = &new QCalendar($cArray, $today, $links, $css); if (!isset($_GET['ran'])) { echo "<div id='quickCalender'>".$req_user; } $cal->render(); if (!isset($_GET['ran'])) { echo "</div>"; } ?> Link to comment https://forums.phpfreaks.com/topic/127927-issues-with-my-ajax-calendar-phpmysqlajax/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.