I have a calendar application, and in that calendar application, there is a "mini view" of a calendar. That little widget only displays the days of the currently chosen month and when you click the number it opens a new page and sends GET data to that new page (to display MySQL info, etc.)
The point is: this little mini-calendar doesn't do much at all, and I'm working to turn it into a partial in Zend Framework MVC. We have jQuery as well. I'm wondering if there is any built-in code that will easily do what we are trying to do with our own code.
Our code (done procedurally):
<?php
/***
This script file is the left panel calendar (small)
*/
//Required variables initializion starts (important in the case of create new event, to avoid PHP notices).
$day = "";
$month = "";
$year = "";
$sel = "";
$what = "";
$page = "index.php";
$param = "";
$index = "";
$functionLast = "goLastMonth";
$functionNext = "goNextMonth";
$sendFunction = "sendToForm";
if(isset($_GET['index'])) //if index page
{
$index = $_GET['index'];
}
if(isset($_GET['type'])) //if sype is set
{
$param = "&type=".$_GET['type'];
}
if(isset($_GET['page'])) //if page is set
{
$page = "calendar.php";
$param = '&page=calendar';
$functionLast = "getLastMonth";
$functionNext = "getNextMonth";
$sendFunction = "sendToTextBox";
}
if(!isset($calWidth) && !isset($calHeight)) //cal width /height check
{
$calWidth = CALENDAR_WIDTH;
$calHeight = CALENDAR_HEIGHT;
}
if(isset($_GET["day"])) //if day is set
$day = $_GET["day"]; //get it
if(isset($_GET["month"])) //if month is set
$month = $_GET["month"]; //..
if(isset($_GET["year"])) //..
$year = $_GET["year"]; //
if(isset($_GET["sel"]))
$sel = $_GET["sel"];
if(isset($_GET["what"]))
$what = $_GET["what"];
if(isset($_GET['date']))
{
$date = $_GET['date'];
list($year,$month,$day) = explode("-",$date); //split date into pieces
}
if($day == "") $day = date("j"); //if day is blank, get today
if($month == "") $month = date("m"); //if month is blank, get this month
if($year == "") $year = date("Y"); //if year is blank, get this year
//echo $day."-".$month."-".$year;die;
//echo '<br>';
if(!checkdate($month, $day, $year)) { //if not a valida date
if(isset($_GET["month"])) { //try to get number of days for this month as this seems the last day of the month. for example if today is 31 of August and you are calling ?month=9&year=2009 it gives you wrong results
$day = date("t", strtotime($year . "-" . $month . "-01")); //so give you 30.
}
}
$printabledate = $year."-".$month."-".$day;
$currentTimeStamp = strtotime("$year-$month-$day");
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
?>
<br />
<div id="loading1" class="a_loading1">
<iframe src="<?php echo SITE_URL?>/loading-msg.php" scrolling="no" frameborder="0" class="markup a_position"></iframe>
</div>
<table class="mini-cal-table">
<tr class="tprowbgcolor">
<td class="arrow" colspan='1' align="center"><input type='button' class='buttonleft' onclick='<?php echo "$functionLast($month,$year,\"$page\",\"$index\")"; ?>' onmousedown="this.className='maincalbutton_active_left'" onmouseout="this.className='buttonleft'" /></td>
<td class="title" colspan='5'><span class='title'><?php echo $monthName . " " . $year; ?></span></td>
<td class="arrow" colspan='1' align="center"><input type='button' class='buttonright' onclick='<?php echo "$functionNext($month,$year,\"$page\",\"$index\")"; ?>' onmousedown="this.className='maincalbutton_active_right'" onmouseout="this.className='buttonright'" /></td>
</tr>
<tr>
<td class='wd-titles'>Su</td>
<td class='wd-titles'>Mo</td>
<td class='wd-titles'>Tu</td>
<td class='wd-titles'>We</td>
<td class='wd-titles'>Th</td>
<td class='wd-titles'>Fr</td>
<td class='wd-titles'>Sa</td>
</tr>
<tr>
<?php
for($i = 1; $i < $numDays+1; $i++, $counter++)
{
$timeStamp = strtotime("$year-$month-$i");
if($i == 1)
{
// Workout when the first day of the month is
$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'";
$tdclass = "weekend";
} else {
if($i == date("d") && $month == date("m") && $year == date("Y")) {
//$class = "class='today'";
$tdclass = "today";
}
else {
//$class = "class='normal'";
$tdclass = "normal";
}
}
$zero = "";
if($i < 10 )
{
$zero = "0";
}
$month = round($month);
if($month < 10)
{
$month = "0".$month;
}
$date = $year."-".$month."-".$zero.$i;
?>
<td class="<?php echo $tdclass?>"><?php
if(!isset($_GET['page'])) {
?><a href='<?php echo SITE_URL; ?>/agenda.php?date=<?php echo $year; ?>-<?php echo $month; ?>-<?php echo $zero.$i; ?>'><?php echo $i?></a>
<?php } else {
?>
<a onclick='<?php echo "$sendFunction($i,\"$date\",$numDays,\"$index\",\"$type\")"; ?>'><?php echo $i?></a>
<?php
}
?></td>
<?php
}
?>
</tr>
</table>
<script language="javascript" type="text/javascript">
//<![CDATA[
function goLastMonth(month,year,page,index) {
// If the month is January, decrement the year.
if(month == 1) {
--year;
month = 13;
}
var url =
document.location.href = page+"?month="+(month-1)+"&year="+year+"<?php echo $param?>";
}
function goNextMonth(month,year,page,index)
{
// If the month is December, increment the year.
if(month == 12)
{
++year;
month = 0;
}
document.location.href = page+"?month="+(month+1)+"&year="+year+"<?php echo $param?>";
}
//]]>
</script>