I am using a calendar in which i am having trouble making the previous dates unavailable. At the moment my calendar ha links for each date and when you click a date it shows the value on another page. However i need all make all the dates that have already passed unavailable. I know it is something to do with the if statement near the end of the code but i can't figure it out. Here is my code
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
?>
<?php
$cMonth = isset($_REQUEST["month"]) ? $_REQUEST["month"] : date("n");
$cYear = isset($_REQUEST["year"]) ? $_REQUEST["year"] : date("Y");
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?><!DOCTYPE html>
<html>
<head>
<title>Hook Up</title>
</head>
<style type="text/css">
table {
border: 1px solid black;
border-collapse: collapse;
}
th {
border: 1px solid black;
padding: 6px;
font-weight: bold;
background: #ccc;
}
td {
border: 1px solid black;
padding: 6px;
vertical-align: top;
width: 100px;
}
</style>
<script type="text/javascript">
function eventWindow(url) {
event_popupWin = window.open(url, 'event',
'resizable=yes, scrollbars=yes, toolbar=no, width=400, height=400);
event_popupWin.opener = self;
}
</script>
<body>
<h1>Select a Night Out</h1>
<table width="200">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="left"> Previous</td>
<td width="50%" align="right">Next </td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
$today = date('j');
$currentmonth = date('n');
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ){
echo "<tr>";
}
if($i < $startday){
echo ("<td class='cell cell_txt'> </td>");
} else {
if (($i - $startday + 1) == $today && $currentmonth == $cMonth){
echo ("<td class='cell_today cell_txt'>".($i-$startday+ 1)."</td>");
} else {
echo ("<td class='cell cell_txt'>".($i - $startday + 1)."</td>");
}
}
if(($i % 7) == 6 ) {
echo "</tr>\n";
}
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>
If anyone can help it would be greatly appreciated. Cheers
if you add following line
$cDay = isset($_REQUEST["day"]) ? $_REQUEST["day"] : date("d");
below this line
$cYear = isset($_REQUEST["year"]) ? $_REQUEST["year"] : date("Y");
and change this line
if (($i - $startday + 1) == $today && $currentmonth == $cMonth){
to:
if ((($i - $startday + 1) == $today && $currentmonth == $cMonth) OR ( (($i - $startday + 1) == $cDay) && ($currentmonth == $cMonth)) ){
That will black out the date that is passed in.
If you want to pass in multiple dates, i.e. pick one date 2013-01-18, the page reloads and blanks out the 18th then want to pick a second date e.g. 2013-01-22 and have the page reload and blank out both the 18th and the 22nd then you will need to change the inputs to arrays and add the previous selected dates into hidden fields to be resubmitted.
If you just want to black out one date then the code changes will work.
Hope this helps.
Update to black out all previous date to the selected:
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
?>
<?php
$sMonth = isset($_REQUEST["smonth"]) ? $_REQUEST["smonth"] : date("n");
$sYear = isset($_REQUEST["syear"]) ? $_REQUEST["syear"] : date("Y");
$cMonth = isset($_REQUEST["month"]) ? $_REQUEST["month"] : '';
$cYear = isset($_REQUEST["year"]) ? $_REQUEST["year"] : '';
$cDay = isset($_REQUEST["day"]) ? $_REQUEST["day"] : '';
//echo __line__." Dates in ".$cDay." ".$cMonth.", ".$cYear."<br>";
$prev_year = $sYear;
$next_year = $sYear;
$prev_month = $sMonth - 1;
$next_month = $sMonth + 1;
if ($prev_month == 0) {
$prev_month = 12;
$prev_year = $sYear - 1;
}
if ($next_month == 13) {
$next_month = 1;
$next_year = $sYear + 1;
}
$nextPrevString = "&month=$cMonth&year=$cYear&day=$cDay";
$selectString = "&smonth=$sMonth&syear=$sYear";
?><!DOCTYPE html>
<html>
<head>
<title>Hook Up</title>
</head>
<style type="text/css">
table {
border: 1px solid black;
border-collapse: collapse;
}
th {
border: 1px solid black;
padding: 6px;
font-weight: bold;
background: #ccc;
}
td {
border: 1px solid black;
padding: 6px;
vertical-align: top;
width: 100px;
}
</style>
<script type="text/javascript">
function eventWindow(url) {
event_popupWin = window.open(url, 'event', resizable=yes, scrollbars=yes, toolbar=no, width=400, height=400);
event_popupWin.opener = self;
}
</script>
<body>
<h1>Select a Night Out</h1>
<table width="200">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="left"> Previous</td>
<td width="50%" align="right">Next </td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$sMonth - 1] . ' ' . $sYear; ?></strong></td>
</tr>
<tr>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
</tr>
<?php
$timestamp = mktime(0, 0, 0, $sMonth, 1, $sYear);
if ($cDay != '') {
$selectedDate = mktime(0, 0, 0, $cMonth, $cDay, $cYear);
} else {
$selectedDate = 0;
}
$maxday = date("t", $timestamp);
$thismonth = getdate($timestamp);
$startday = $thismonth['wday'];
$today = date('j');
$currentmonth = date('n');
for ($i = 0; $i < ($maxday + $startday); $i++) {
if (($i % 7) == 0) {
echo "<tr>";
}
if ($i < $startday) {
echo ("<td class='cell cell_txt'> </td>");
} else {
$testDate = mktime(0, 0, 0, $sMonth, $i - $startday + 1, $sYear);
if ($testDate < $selectedDate) {
echo ("<td class='cell_today cell_txt'>" . ($i - $startday + 1) . "</td>");
} else {
echo ("<td class='cell cell_txt'>" . ($i - $startday + 1) . "</td>");
}
}
if (($i % 7) == 6) {
echo "</tr>\n";
}
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>
<!-----use it will surely work -----!>
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
?>
<?php
if (!isset($_REQUEST["day"])) $_REQUEST["day"] = date("d");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
?>
<?php
$cDay = $_REQUEST["day"];
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth - 1;
$next_month = $cMonth + 1;
if ($prev_month == 0) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<div id="calendar_div" name="calendar_div">
<div class="table-responsive">
<table width="93%" style="border: none">
<tr>
<td> <a
href="<?php echo $_SERVER["PHP_SELF"] . "?month=" . $prev_month . "&year=" . $prev_year; ?>"
style="color:#FFFFFF"> < </a>
<a href="<?php echo $_SERVER["PHP_SELF"] . "?month=" . $next_month . "&year=" . $next_year; ?>"
style="color:#FFFFFF"> > </a></td>
<td style="float: right">
<h3 style="color: #ffffff;"> <?php echo $monthNames[$cMonth - 1] . ' ' . $cYear; ?></strong></h3>
</td>
</tr>
</table>
<table class="table">
<tr>
<td style="color:#FFFFFF;border: none"><strong>Sun</strong></td>
<td style="color:#FFFFFF;border: none"><strong>Mon</strong></td>
<td style="color:#FFFFFF;border: none"><strong>Tue</strong></td>
<td style="color:#FFFFFF;border: none"><strong>Wed</strong></td>
<td style="color:#FFFFFF;border: none"><strong>Thr</strong></td>
<td style="color:#FFFFFF;border: none"><strong>Fri</strong></td>
<td style="color:#FFFFFF;border: none"><strong>Sat</strong></td>
</tr>
<?php
$timestamp = mktime(0, 0, 0, $cMonth, 1, $cYear);
$maxday = date("t", $timestamp);
$thismonth = getdate($timestamp);
$currentmonth = date('n');
$startday = $thismonth['wday'];
for ($i = 0; $i < ($maxday + $startday); $i++) {
if (($i % 7) == 0) echo "<tr>\n";
if ($i < $startday) echo "<td style='border: none'></td>\n";
elseif(($i - $startday + 1) == $cDay && $currentmonth == $cMonth ){
echo "<td style='background-color: #cccccc'>". ($i - $startday + 1) ."</td>";}
else{
echo "<td style='color: #ffffff; border: none'>". ($i - $startday + 1) ."</td></a>";}
if(($i % 7) == 6 ) echo "</tr>";
}
?>
</table>
Related
I have been stuck for days trying to figure out the best method to go about doing what I need done. I have a json url that I am pulling data from that is in an array like below. The date range can be a month to a full years worth of data. I need to do a check if tickets are soldout or not. If soldout equals true it should display soldout on that date in the calendar. If soldout equals false it should display the $url variable in the date in the calendar that matches the date in start.
Array format I am trying to work with
array(3) {
[0]=> object(stdClass)#1 (4) {
["id"]=> string(3) "165"
["start"]=> string(18) "05/02/2020 1:00 PM"
["title"]=> string(19) "Event 1:00 PM"
["alldetails"]=> array(1) {
[0]=> object(stdClass)#2 (1) {
["soldout"]=> bool(false)
}
}
}
[1]=> object(stdClass)#3 (4) {
["id"]=> string(3) "166"
["start"]=> string(18) "07/19/2020 5:00 PM"
["title"]=> string(19) "Event 5:00 PM"
["alldetails"]=> array(1) {
[0]=> object(stdClass)#4 (1) {
["soldout"]=> bool(false)
}
}
}
[2]=> object(stdClass)#5 (4) {
["id"]=> string(3) "167"
["start"]=> string(18) "11/14/2020 9:00 PM"
["title"]=> string(19) "Event 1:00 PM"
["alldetails"]=> array(1) {
[0]=> object(stdClass)#6 (1) {
["soldout"]=> bool(false)
}
}
}
}
Pulling data from json array
<?php
$array = 'https://URL/feed.json?start=2020-05-02&end=2020-11-14';
$obj = json_decode(file_get_contents($array));
foreach ($obj as $key => $value){
$id = $value->id;
$start = $value->start;
$title = $value->title;
$url = ''.$title.'';
$details = $value->alldetails;
foreach($details as $nested){
$nested->soldout; //Outputs 1 or is blank
}
}
?>
Someone else's calendar I have been attempting to insert data into. Not sure if I should use this or try my hand at building my own. Not very good with date formatting in PHP Long way to learn and a lot of refreshers needed.
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<table>
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" cellspacing="0" cellpadding="0" border="1">
<tr>
<td width="50%" align="left">Previous</td>
<td width="50%" align="right">Next</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" cellpadding="2" cellspacing="2" border="1">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<th><strong>S</strong></th>
<th><strong>M</strong></th>
<th><strong>T</strong></th>
<th><strong>W</strong></th>
<th><strong>T</strong></th>
<th><strong>F</strong></th>
<th><strong>S</strong></th>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) echo "<tr>";
if($i < $startday) echo "<td></td>";
else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "</td>";
if(($i % 7) == 6 ) echo "</tr>";
}
?>
</table>
</td>
</tr>
</table>
So to break it down once again, I need to insert $url into the calendar where start date matches the calendars correct date but only if not soldout. If soldout equals true then it should probably just echo "SoldOut"; or leave blank, something to that nature. Any help getting on the right track to get the information in the calendar would be great.
Give this a go and let me know if it's what you want.
I've created an array that holds all the events for the specified date range. Then, when the calendar is being populated, it checks if the current day is in the array. If so, it displays whether it's available or sold out.
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<table>
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" cellspacing="0" cellpadding="0" border="1">
<tr>
<td width="50%" align="left" onclick="changeDate(<?php echo $prev_month .','. $prev_year; ?>);" style="color:#FFFFFF">Previous</a></td>
<td width="50%" align="right" onclick="changeDate(<?php echo $next_month .','. $next_year; ?>);" style="color:#FFFFFF">Next</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" cellpadding="2" cellspacing="2" border="1">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<th><strong>S</strong></th>
<th><strong>M</strong></th>
<th><strong>T</strong></th>
<th><strong>W</strong></th>
<th><strong>T</strong></th>
<th><strong>F</strong></th>
<th><strong>S</strong></th>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
$eventsArray = array();
$array = 'https://URL/feed.json?start='.$cYear.'-'.$cMonth.'-'.$startday.'&end='.$cYear.'-'.$cMonth.'-'.$maxday;
$obj = json_decode(file_get_contents($array));
foreach ($obj as $key => $value) {
$id = $value->id;
$start = $value->start;
$title = $value->title;
$url = ''.$title.'';
$details = $value->alldetails;
$date = new DateTime($value->start);
$day = $date->format('d');
foreach($details as $nested){
$soldOut = $nested->soldout;
array_push($eventsArray, array($day, $soldOut));
}
}
for ($i=0; $i<($maxday+$startday); $i++) {
$currentDay = $i - $startday + 1;
if($i % 7 == 0) {
echo "<tr>";
}
if($i < $startday) {
echo "<td></td>";
}else{
// Check if current day is in array $currentEvents
foreach($eventsArray as $event){
if($event[0] == $currentDay) {
if($event[1] == 1) { // event is soldout
echo "<td align='center' valign='middle' height='20px'><p>".$currentDay."</p><p>Soldout</p></td>";
}else{
echo "<td align='center' valign='middle' height='20px'><p>".$currentDay."</p><p>Available</p></td>";
}
}else{
echo "<td align='center' valign='middle' height='20px'><p>".$currentDay."</p><p>No Event</p></td>";
}
}
}
if($i % 7 == 6) {
echo "</tr>";
}
}
?>
</table>
</td>
</tr>
</table>
I was helped a great deal by #El_Vanja, Taught me a great deal about creating a function that would do exactly what I was looking for. Seems I was going about things the wrong way and he guided me to find the correct answer helping along the way as much as he could while still teaching me to do it myself. Kudos to #Il_Vanja, would make a great PHP teacher.
Here is the working code, Still needs cleaned up a great bit including the if statements for displaying the events but as is it works as expected.
<?php
$array = 'https://feed.json?start=2020-01-01&end=2100-12-31';
$obj = json_decode(file_get_contents($array,true));
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<table>
<tr align="center">
<td>
<table width="100%" cellspacing="0" cellpadding="0" border="1">
<tr>
<td width="50%" align="left"><div class="m_buttons"><a href="<?php echo "?month=". $prev_month . "&year=" . $prev_year; ?>" ><strong>Previous Month</strong></a></div></td>
<td width="50%" align="right"><div class="m_buttons"><a href="<?php echo "?month=". $next_month . "&year=" . $next_year; ?>" ><strong>Next Month</strong></a></div></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" cellpadding="2" cellspacing="2" border="1">
<tr align="center">
<td colspan="7"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<th><strong>Sun</strong></th>
<th><strong>Mon</strong></th>
<th><strong>Tues</strong></th>
<th><strong>Wed</strong></th>
<th><strong>Thurs</strong></th>
<th><strong>Fri</strong></th>
<th><strong>Sat</strong></th>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
function getDateCellContent(array $obj, $d) {
$f_newdate = DateTime::createFromFormat('Y-m-j', $d);
$f_newdate = $f_newdate->format('m/d/Y');
$cellLink = '';
$cellSoldout = '';
foreach ($obj as $key => $value) {
$start = $value->start;
$a_newdate = DateTime::createFromFormat('m/d/Y g:i A', $start);
$a_date = $a_newdate->format('m/d/Y');
$a_time = $a_newdate->format('g:i A');
$id = $value->id;
$title = $value->title;
if($a_date === $f_newdate) {
foreach ($value->alldetails as $details) {
$name = $details->name;
$title = $value->title;
$link1 = '<div class="link1"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link2 = '<div class="link2"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link3 = '<div class="link3"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link4 = '<div class="link4"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link5 = '<div class="link5"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link6 = '<div class="link6"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link7 = '<div class="link7"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link8 = '<div class="link8"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link9 = '<div class="link9"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link10 = '<div class="link10"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
$link11 = '<div class="link11"><strong>'.$name.'<br />'.$a_time.'</strong></div>';
if (!$details->soldout && $title === "Event 1:00 PM") {
$cellLink .= $link1;
}
if (!$details->soldout && $title === "Event 10:00 AM") {
$cellLink .= $link2;
}
if (!$details->soldout && $title === "Event 2:30 PM") {
$cellLink .= $link3;
}
if (!$details->soldout && $title === "Mother's Day Event 1:00 PM") {
$cellLink .= $link4;
}
if (!$details->soldout && $title === "Sunset Event 6:00 PM") {
$cellLink .= $link5;
}
if (!$details->soldout && $title === "Spring Event 10:00 AM") {
$cellLink .= $link6;
}
if (!$details->soldout && $title === "All Day Event 10:00 AM") {
$cellLink .= $link7;
}
if (!$details->soldout && $title === "Winter Event 3:00 PM") {
$cellLink .= $link8;
}
if (!$details->soldout && $title === "Winter Event 5:00 PM") {
$cellLink .= $link9;
}
if (!$details->soldout && $title === "Winter Event 7:00 PM") {
$cellLink .= $link10;
}
if (!$details->soldout && $title === "Father's Day Event 1:00 PM") {
$cellLink .= $link11;
}else{
}
}
}
}
return $cellLink . $cellSoldout;
}
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) echo "<tr>";
if($i < $startday) echo "<td></td>";
else echo "<td align='center' valign='middle' height='20px'>".($i - $startday + 1) ."<br />". getDateCellContent($obj, $cYear.'-'.$cMonth.'-'.($i - $startday + 1)) ."</td>";
if(($i % 7) == 6 ) echo "</tr>";
}
?>
</table>
</td>
</tr>
</table>
After receiving help below #rx2347 everything is working the way it should except one things. I have edited my question to better explain the issue.
I have an json array and I am pulling certain data such as 'id' and 'start' start displays a date and time together. I am comparing the date with the calendars date and trying to insert the correct time in the correct date. Kind of like a matching game.
Currently everything works however inserting is only inserting the very last value in the array and I need it to insert every value. Getting stuck below is what I have now after the help from #rx2347
<?php
$url = 'JSON ARRAY';
$data = file_get_contents($url);
$array = json_decode($data, true);
foreach($array as $your_json_date) {
//convert date and time
$your_date = strftime("%G%m%d", strtotime($your_json_date["start"]));
$your_time = strftime("%I:%M %P",strtotime($your_json_date["start"]));
$your_id = $your_json_date["id"];
$result = ''.$your_time.'';
}
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<table width="200">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" cellspacing="0" cellpadding="0" border="1">
<tr>
<td width="50%" align="left">Previous</td>
<td width="50%" align="right">Next</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" cellpadding="2" cellspacing="2" border="1">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<th><strong>S</strong></th>
<th><strong>M</strong></th>
<th><strong>T</strong></th>
<th><strong>W</strong></th>
<th><strong>T</strong></th>
<th><strong>F</strong></th>
<th><strong>S</strong></th>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++) {
// compare your date and calendar date
$thisdate = strftime("%G%m%d",strtotime($cMonth."/".($i - $startday + 1)."/".$cYear));
if($your_date == $thisdate) $time = $result; else $time = "";
if(($i % 7) == 0 ) echo "<tr>";
if($i < $startday) echo "<td></td>";
else {
echo "<td align='center' valign='middle' height='20px'>";
echo ($i - $startday + 1);
//output time
echo "<br><b>".$time."</b>";
echo "</td>";
}
if(($i % 7) == 6 ) echo "</tr>";
}
?>
</table>
</td>
</tr>
</table>
So, all you need to know is how to compare those two dates, right?
First: Convert both dates to the same format using strtotime and strftime
$date = "05/02/2020 1:00 PM";
echo strftime("%G%m%d",strtotime($date));
This will convert your JSON date to "20200502", no matter what time. Do the same with your PHP date from your calendar and check if they are equal. Done.
I hope I understood you correctly.
This is the altered code:
<?php
//your json date
$your_json_date = "05/02/2020 1:00 PM";
//convert date and time
$your_date = strftime("%G%m%d", strtotime($your_json_date));
$your_time = strftime("%I:%M %P",strtotime($your_json_date));
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<table width="200">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" cellspacing="0" cellpadding="0" border="1">
<tr>
<td width="50%" align="left">Previous</td>
<td width="50%" align="right">Next</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" cellpadding="2" cellspacing="2" border="1">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<th><strong>S</strong></th>
<th><strong>M</strong></th>
<th><strong>T</strong></th>
<th><strong>W</strong></th>
<th><strong>T</strong></th>
<th><strong>F</strong></th>
<th><strong>S</strong></th>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++) {
// compare your date and calendar date
$thisdate = strftime("%G%m%d",strtotime($cMonth."/".($i - $startday + 1)."/".$cYear));
if($your_date == $thisdate) $time = $your_time; else $time = "";
if(($i % 7) == 0 ) echo "<tr>";
if($i < $startday) echo "<td></td>";
else {
echo "<td align='center' valign='middle' height='20px'>";
echo ($i - $startday + 1);
//output time
echo "<br><b>".$time."</b>";
echo "</td>";
}
if(($i % 7) == 6 ) echo "</tr>";
}
?>
</table>
</td>
</tr>
</table>
Check the linked PHP docs for further changes.
I'm trying to make a calendar that shows this month, and then fills in the remaining days on the end rows with the dates from the next and previous months.
I managed to make it show next months dates and the thing is the issue is that I need it to show previous months dates as well.
If someone manages to figure out the issues please add what the problem was as well how you managed to fix it, to help me in the future.
I will add a image of the calendar as well.
The script:
<table cellspacing="0" cellpadding="0" border="0" width="100%" class="view-calendar">
<tr>
<td valign="top" width="14.2857%">Mondag</td>
<td valign="top" width="14.2857%">Tuesday</td>
<td valign="top" width="14.2857%">Wednesday</td>
<td valign="top" width="14.2857%">Thursday</td>
<td valign="top" width="14.2857%">Friday</td>
<td valign="top" width="14.2857%">Saturday</td>
<td valign="top" width="14.2857%">Sunday</td>
</tr>
<?php
// Get current month dates
$days_count = date('t');
$current_day = date('d');
$week_day_first = date('N', mktime(0, 0, 0, date('m'), 1, date('Y')));
// Get previous month dates
// Get next month dates
$next_start = strtotime(date("Y-m-00", strtotime("+1 month")));
$next_dates = array();
for ($w = 1 - $week_day_first + 1; $w <= $days_count; $w = $w + 7){
echo '<tr>';
$counter = 0;
for ($d = $w; $d <= $w + 6; $d++){
if($d < 10){
$current_date = date("Y").date("m").'0'.$d;
}else{
$current_date = date("Y").date("m").$d;
}
echo '<td valign="top" width="14.2857%"'.(($d > 0 ? ($d > $days_count ? ' class="disabled"' : '') : ' class="disabled"')).(($counter > 4 ? ' class="week-day"' : '')).'>';
if($d > 0){
if($d > $days_count){
for($in = 1; $in <= 1; $in++){
echo array_push($next_dates, date('j', strtotime("+ $in day", $next_start)));
}
}else if($current_day == $d){
echo '<div class="current-day"><span class="given-date">'.$d.'</span></div>';
}else{
echo '<span class="given-date">'.$d.'</span>';
}
}else{
//Here comes previous dates
}
echo '</td>';
$counter++;
}
echo '</tr>';
}
?>
</table>
When you calculated $week_day_first, you can save your time calculated from the first day of the month into a variable.
$time_first_day_of_month = mktime(0, 0, 0, date('m'), 1, date('Y'));
Then you can reuse that later to calculate the offset of days before the first of the month.
date('d', strtotime("$offset day",$time_first_day_of_month))
Putting it all together:
<table cellspacing="0" cellpadding="0" border="0" width="100%" class="view-calendar">
<tr>
<td valign="top" width="14.2857%">Mondag</td>
<td valign="top" width="14.2857%">Tuesday</td>
<td valign="top" width="14.2857%">Wednesday</td>
<td valign="top" width="14.2857%">Thursday</td>
<td valign="top" width="14.2857%">Friday</td>
<td valign="top" width="14.2857%">Saturday</td>
<td valign="top" width="14.2857%">Sunday</td>
</tr>
<?php
// Get current month dates
$days_count = date('t');
$current_day = date('d');
// save time of first day for later use
$time_first_day_of_month = mktime(0, 0, 0, date('m'), 1, date('Y'));
$week_day_first = date('N', $time_first_day_of_month);
// Get next month dates
$next_start = strtotime(date("Y-m-00", strtotime("+1 month")));
$next_dates = array();
for ($w = 1 - $week_day_first + 1; $w <= $days_count; $w = $w + 7){
echo '<tr>';
$counter = 0;
for ($d = $w; $d <= $w + 6; $d++){
if($d < 10){
$current_date = date("Y").date("m").'0'.$d;
}else{
$current_date = date("Y").date("m").$d;
}
echo '<td valign="top" width="14.2857%"'.(($d > 0 ? ($d > $days_count ? ' class="disabled"' : '') : ' class="disabled"')).(($counter > 4 ? ' class="week-day"' : '')).'>';
if($d > 0){
// next month's dates
if($d > $days_count){
for($in = 1; $in <= 1; $in++){
echo array_push($next_dates, date('j', strtotime("+ $in day", $next_start)));
}
}
// today
else if($current_day == $d){
echo '<div class="current-day"><span class="given-date">'.$d.'</span></div>';
}
// this month's dates
else{
echo '<span class="given-date">'.$d.'</span>';
}
}
// last month's dates
else{
//Here comes previous dates
$offset = $d - 1;
echo '<span class="given-date">'.date('d', strtotime("$offset day",$time_first_day_of_month)).'</span>';
}
echo '</td>';
$counter++;
}
echo '</tr>';
}
?>
</table>
Results in this output:
<table cellspacing="0" cellpadding="0" border="0" width="100%" class="view-calendar">
<tr>
<td valign="top" width="14.2857%">Mondag</td>
<td valign="top" width="14.2857%">Tuesday</td>
<td valign="top" width="14.2857%">Wednesday</td>
<td valign="top" width="14.2857%">Thursday</td>
<td valign="top" width="14.2857%">Friday</td>
<td valign="top" width="14.2857%">Saturday</td>
<td valign="top" width="14.2857%">Sunday</td>
</tr>
<tr><td valign="top" width="14.2857%" class="disabled"><span class="given-date">30</span></td><td valign="top" width="14.2857%" class="disabled"><span class="given-date">31</span></td><td valign="top" width="14.2857%"><span class="given-date">1</span></td><td valign="top" width="14.2857%"><span class="given-date">2</span></td><td valign="top" width="14.2857%"><span class="given-date">3</span></td><td valign="top" width="14.2857%" class="week-day"><span class="given-date">4</span></td><td valign="top" width="14.2857%" class="week-day"><span class="given-date">5</span></td></tr><tr><td valign="top" width="14.2857%"><span class="given-date">6</span></td><td valign="top" width="14.2857%"><span class="given-date">7</span></td><td valign="top" width="14.2857%"><span class="given-date">8</span></td><td valign="top" width="14.2857%"><span class="given-date">9</span></td><td valign="top" width="14.2857%"><span class="given-date">10</span></td><td valign="top" width="14.2857%" class="week-day"><span class="given-date">11</span></td><td valign="top" width="14.2857%" class="week-day"><span class="given-date">12</span></td></tr><tr><td valign="top" width="14.2857%"><span class="given-date">13</span></td><td valign="top" width="14.2857%"><span class="given-date">14</span></td><td valign="top" width="14.2857%"><span class="given-date">15</span></td><td valign="top" width="14.2857%"><span class="given-date">16</span></td><td valign="top" width="14.2857%"><div class="current-day"><span class="given-date">17</span></div></td><td valign="top" width="14.2857%" class="week-day"><span class="given-date">18</span></td><td valign="top" width="14.2857%" class="week-day"><span class="given-date">19</span></td></tr><tr><td valign="top" width="14.2857%"><span class="given-date">20</span></td><td valign="top" width="14.2857%"><span class="given-date">21</span></td><td valign="top" width="14.2857%"><span class="given-date">22</span></td><td valign="top" width="14.2857%"><span class="given-date">23</span></td><td valign="top" width="14.2857%"><span class="given-date">24</span></td><td valign="top" width="14.2857%" class="week-day"><span class="given-date">25</span></td><td valign="top" width="14.2857%" class="week-day"><span class="given-date">26</span></td></tr><tr><td valign="top" width="14.2857%"><span class="given-date">27</span></td><td valign="top" width="14.2857%"><span class="given-date">28</span></td><td valign="top" width="14.2857%"><span class="given-date">29</span></td><td valign="top" width="14.2857%"><span class="given-date">30</span></td><td valign="top" width="14.2857%" class="disabled">1</td><td valign="top" width="14.2857%" class="disabled" class="week-day">2</td><td valign="top" width="14.2857%" class="disabled" class="week-day">3</td></tr></table>
Here is code using the DateTime class, which makes it quite readable:
$today = new DateTime('today'); // only change this line to test other months
$this_month = $today->format('M');
$date = clone $today;
$date->modify('first day of this month')->modify('+1 day')->modify('last Monday');
do {
echo '<tr>';
for ($weekday = 0; $weekday < 7; $weekday++){
$out = str_replace($this_month, '', $date->format('M'));
$content = "<span class='given-date'>$out {$date->format('d')}</span>";
if ($today == $date) $content = "<div class='current-day'>$content</div>";
$class = ($out ? 'disabled ' : '') . ($weekday > 4 ? 'week-day' : '');
echo "<td valign='top' width='14.2857%' class='$class'>$content</td>";
$date->modify('+1 day');
}
echo '</tr>';
} while ($date->format('M') == $this_month);
Although this is quite old now I found Jeff's solution very useful. I refactored it a little and put it in this Gist, I hope someone finds it useful. Part of it is here:
/**
* Return part of an HTML table containing all the days
* in the current month, plus padd it with next and
* previous months days if needed to fill out the grid
*
*
* #param date $date date object containing month to display
*
* #return string
*/
function get_calendar_days_in_month_html($date) {
$date_format = "Y-m-d";
$days_count = $date->format('t'); //Get number of days in this month
$weeks_count = ceil($days_count / 7); //How many weeks in this month?
$total_cells = $weeks_count * 7;
//clone is used or we literally are modifying the $date variable
$first_date_of_month = clone $date->modify('first day of this month');
$first_day_of_month = $first_date_of_month->format("N"); //returns 1-7 EG Mon-Fri
$first_date_of_grid = $first_date_of_month ->modify('-' . $first_day_of_month . ' days');
$todays_date = new DateTime();
$todays_date_str = $todays_date->format($date_format);
$selected_date_str = $date->format($date_format);
$day_of_week = 1; //FIXME: allow starting with Sunday or whatever
$ht = '<tr>';
for ($cell=1; $cell <= $total_cells ; $cell++) {
$classes = []; //CSS classes
$current_date = $first_date_of_grid->modify("+1 day");
$current_date_str = $current_date->format($date_format);
if($current_date_str == $todays_date_str) $classes[] = "today";
if($selected_date_str == $todays_date_str) $classes[] = "selected-date";
/* if current date is not from this month (EG previous or next month) then give
it a special class, you might want to grey it out or whatever */
if($date->format("m") !== $current_date->format("m")) $classes[] = "grid-filler";
$ht .= '
<td date="' . $current_date_str . '" class="' . implode(" ", $classes) . '">' . $current_date->format("j") . '</td>';
$day_of_week ++;
if($day_of_week == 8) {
$ht .= '</tr>';
if($cell < $total_cells) $ht .= '<tr>';
$day_of_week = 1;
}
}
return $ht;
}
Working with a project, Loading a calender from a php file using ajax call. When i'm try to trigger an event written on the loaded table it seems not working.
Please help me.
$.ajax({
url: 'calender.php',
type: 'GET',
success: function(res){
$("#calender").html(res);
}
});
$("#prev").click(function(){
console.log(this);
});
PHP Code here.
*<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<table width="300">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="left"><a id="prev" title="<?php echo $prev_month."|".$prev_year; ?>" href="javascript:void(0);" style="color:#FFFFFF">Previous</a></td>
<td width="50%" align="right"><a id="next" title="<?php echo $next_month."|".$next_year; ?>" href="javascript:void(0);" style="color:#FFFFFF">Next</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" border="0" cellpadding="5" cellspacing="0" id="calen">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<th align="center" bgcolor="#FFB102" style="color:#FFFFFF">S</th>
<th align="center" bgcolor="#FFB102" style="color:#FFFFFF">M</th>
<th align="center" bgcolor="#FFB102" style="color:#FFFFFF">T</th>
<th align="center" bgcolor="#FFB102" style="color:#FFFFFF">W</th>
<th align="center" bgcolor="#FFB102" style="color:#FFFFFF">T</th>
<th align="center" bgcolor="#FFB102" style="color:#FFFFFF">F</th>
<th align="center" bgcolor="#FFB102" style="color:#FFFFFF">S</th>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) echo "<tr>";
if($i < $startday){
echo "<td></td>";
}else{
$currentDay = date("d");
$presentDay = $i-$startday+1;
if($presentDay == $currentDay){
echo "<td class='current' align='center' valign='middle' height='20px'><a title='".($i - $startday + 1)."' href='javascript:void(0);'>". ($i - $startday + 1) . "</a></td>";
}else if($presentDay < $currentDay){
echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "</td>";
}else{
echo "<td align='center' valign='middle' height='20px'><a title='".($i - $startday + 1)."' href='javascript:void(0);'>". ($i - $startday + 1) . "</a></td>";
}
}
if(($i % 7) == 6 ) echo "</tr>";
}
?>*
What can be the issue ?
Since you are loading the element in dynamically you will need to use delegates instead of binding.
$(document).on('click', '#prev', function(){
console.log(this);
});
Use the following code assuming '#calendar' exists in the dom at the time of execution of the following code. Bind the delegate event handler to the closest DOM element possible.
$("#calender").on('click', '#prev', function(){
console.log(this);
});)
Put your event handler into your success callback of the ajax call should solve this problem. This is because the of the problem stated in the comments to your question: the DOM elements you're binding your handler to are not present when the handler is created. The other solution to bind the handler to the document using "on" is working, too.
EDIT: As stated in the comments to my answer, be careful that you don't create duplicate event handlers, when this ajax call is called more than once.
$.ajax({
url: 'calender.php',
type: 'GET',
success: function(res){
$("#calender").html(res);
$("#prev").click(function(){
console.log(this);
});
}
});
im new to this PHP im trying to develop a code such that when i click launch calendar it ll display calendar and when i choose the date it ll display in the text field but my problem is when i clik launch calendar its not showing feburay month.. i dont no wt the error in my code can anyone pls help me out in this.. thanks in advance.. here is my code what i have developed...
<?php
$day = $_GET["day"];
$month = $_GET["month"];
$year = $_GET["year"];
$sel = $_GET["sel"];
$what = $_GET["what"];
$field = $_GET["field"];
$form = $_GET["form"];
if($day == "") $day = date("j");
if($month == "") $month = date("m");
if($year == "") $year = date("Y");
$currentTimeStamp = strtotime("$year-$month-$day");
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
?>
<html>
<head>
<title>MyCalendar</title>
<link rel="stylesheet" type="text/css" href="calendar.css">
<script language="javascript">
function goLastMonth(month,year,form,field)
{
if(month == 1)
{
--year;
month = 13;
}
document.location.href = 'calendar.php?month='+(month-1)+'&year='+year+'&form='+form+'&field='+field;
}
function goNextMonth(month,year,form,field)
{
if(month == 12)
{
++year;
month = 0;
}
document.location.href = 'calendar.php?month='+(month+1)+'&year='+year+'&form='+form+'&field='+field;
}
function sendToForm(val,field,form)
{
eval("opener.document." + form + "." + field + ".value='" + val + "'");
window.close();
}
</script>
</head>
<body style="margin:0px 0px 0px 0px" class="body">
<table width='175' border='0' cellspacing='0' cellpadding='0' class="body">
<tr>
<td width='25' colspan='1'>
<input type='button' class='button' value=' < ' onClick='<?php echo "goLastMonth($month,$year,\"$form\",\"$field\")"; ?>'>
</td>
<td width='125' align="center" colspan='5'>
<span class='title'><?php echo $monthName . " " . $year; ?></span><br>
</td>
<td width='25' colspan='1' align='right'>
<input type='button' class='button' value=' > ' onClick='<?php echo "goNextMonth($month,$year,\"$form\",\"$field\")"; ?>'>
</td>
</tr>
<tr>
<td class='head' align="center" width='25'>S</td>
<td class='head' align="center" width='25'>M</td>
<td class='head' align="center" width='25'>T</td>
<td class='head' align="center" width='25'>W</td>
<td class='head' align="center" width='25'>T</td>
<td class='head' align="center" width='25'>F</td>
<td class='head' align="center" width='25'>S</td>
</tr>
<tr>
<?php
for($i = 1; $i < $numDays+1; $i++, $counter++)
{
$timeStamp = strtotime("$year-$month-$i");
if($i == 1)
{
$firstDay = date("w", $timeStamp);
for($j = 0; $j < $firstDay; $j++, $counter++)
echo "<td> </td>";
}
if($counter % 7 == 0)
echo "</tr><tr>";
if(date("w", $timeStamp) == 0)
$class = "class='weekend'";
else
if($i == date("d") && $month == date("m") && $year == date("Y"))
$class = "class='today'";
else
$class = "class='normal'";
echo "<td class='tr' bgcolor='#ffffff' align='center' width='25'><a class='buttonbar' href='#' onclick=\"sendToForm('".sprintf("%02d/%02d/%04d", $month, $i, $year)."','$field','$form');\"><font $class>$i</font></a></td>";
}
?>
</tr>
</table>
</body>
</html>
This is not a fix to your script but may be a fix to your problem. Isn't it easier to just use a pre made complete javascript calendar library?
like:
Jscalendar Demo
Or
Jquery Ui Datepicker + Demo
as the calendar is going to run on the client side this task can be done using only client side code. using javascript and pre made library like Jquery - as #RJD22 pointed out.
i think that in general when you can get a task done in client side insted of using server side it is better because server resources are limited.