tell me what you think of this calendar script I made
PHP Code:
<?php include "./src/scripts/top.php"; ?>
<div id="content">
<div id="calendar-logo">Troop 557 Calendar</div>
<?php
date_default_timezone_set('America/Los_Angeles');
if (isset($_GET['day'])){
$day = $_GET['day'];
} else {
$day = date("j");
}
if(isset($_GET['month'])){
$month = $_GET['month'];
} else {
$month = date("n");
}
if(isset($_GET['year'])){
$year = $_GET['year'];
}else{
$year = date("Y");
}
if($month > 12){
$month = 12;
}
if($month < 1){
$month = 1;
}
if(strlen($year) != 4){
$year = date("Y");
}
if($month == 1){
$year_back_button = ($year-1);
$month_back_button = 12;
$back_month = 12;
}else {
$month_back_button = ($month-1);
$year_back_button = $year;
$back_month = ($month-1);
}
if($month == 12){
$year_forward_button = ($year+1);
$month_forward_button = 1;
$next_month = 1;
}else {
$month_forward_button = ($month+1);
$year_forward_button = $year;
$next_month = ($month+1);
}
$currentTimeStamp = strtotime( "$day-$month-$year");
$backTimeStamp = strtotime( "$day-$back_month-$year");
$nextTimeStamp = strtotime( "$day-$next_month-$year");
$backmonthName = date("M", $backTimeStamp);
$nextmonthName = date("M", $nextTimeStamp);
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
$con = mysql_connect("****.com","*****","****") or die(mysql_error());
$db = mysql_select_db("******", $con);
?>
<?php if(isset($_GET['day'])){
$sql = "SELECT * FROM `calendar` WHERE `year_of`='".$year."' AND `month_of`='".$month."' AND `day_of`='".$day."'";
$res = mysql_query($sql) or die(mysql_error());
$sqlcheck = "SELECT count(*) AS amount FROM `calendar` WHERE `year_of`='".$year."' AND `month_of`='".$month."' AND `day_of`='".$day."'";
$rescheck = mysql_query($sqlcheck) or die(mysql_error());
$is_event_counter = 0;
$current_day = date("j", $currentTimeStamp);
$current_month = date("n", $currentTimeStamp);
$current_year = date("Y", $currentTimeStamp);
$rowcheck = mysql_fetch_assoc($rescheck);
if(mysql_num_rows($res) > 0){
echo "There is ".$rowcheck['amount']." Events for this day, ".$current_month."/".$current_day."/".$current_year.".<br /><br />";
while($row = mysql_fetch_assoc($res)){
$type_of_event = $row['type_of_event'];
$day_of = $row['day_of'];
$month_of = $row['month_of'];
$year_of = $row['year_of'];
$event_title = $row['event_title'];
$event_description = $row['event_description'];
$is_event_counter++;
if($day == $day_of){
echo "Event ".$is_event_counter."<br />Title: ".$event_title."<br />Type of Event: ".$type_of_event."<br /><div class=\"description\">Event Description: ".nl2br2($event_description)."</div><br /><br />";
}else {
echo "There are no events for this day, ".$current_month."/".$current_day."/".$current_year.".";
}
}
}else {
echo "There are no events for this day, ".$current_month."/".$current_day."/".$current_year.".";
}
echo "<div id=\"back-to-calendar\"><a href=\"?month=".$month."&year=".$year."\">Go Back?</a></div>";
}else { ?>
<table id="calendar-table" cellspacing="3" cellpadding="3">
<tr id="top-controls">
<th colspan="2" id="back-button"><?php echo "<a href=\"?month=".$month_back_button."&year=".$year_back_button."\">"; ?><span style="font-size: 16px;">«</span> <?php echo $backmonthName; echo " $year_back_button"; ?></a></td>
<th colspan="3"><?php echo $monthName." ".$year; ?></th>
<th colspan="2" id="forward-button"><?php echo "<a href=\"?month=".$month_forward_button."&year=".$year_forward_button."\">"; ?><?php echo $nextmonthName; echo " $year_forward_button"; ?> <span style="font-size: 16px;">»</span></a></th>
</tr>
<tr>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<?php
echo "<tr>";
for($i = 1; $i < $numDays+1; $i++, $counter++){
$monthstring = $month;
$monthlength = strlen($monthstring);
$daystring = $i;
$daylength = strlen($daystring);
$timeStamp = strtotime("$year-$month-$i");
$timeStamp_before = strtotime("$year-$month_before-$i");
$month_before = ($month == 1) ? "12" : $month-1;
$year_before = ($month == 1) ? $year-1 : $year;
if($i == 1) {
$firstDay = date("w", $timeStamp);
$firstDay = ($firstDay > 4) ? $firstDay = 4 : $firstDay;
$days_before = date("j", $timeStamp_before);
$days_before_thisMonth = $days_before - $firstDay;
$days_before_thisMonth = $days_before_thisMonth+1;
for($fd = 0; $fd < $firstDay; $fd++, $counter++, $days_before_thisMonth++) {
echo "<td>";
$month_before_this = $month-1;
$sql = "SELECT * FROM `calendar` WHERE `year_of`='".$year."' AND `month_of`='".$month_before_this."'";
$res = mysql_query($sql) or die(mysql_error());
echo "<a href=\"?day=".$days_before_thisMonth."&month=".$month_before."&year=".$year_before."\" class=\"calendar-link\">".$days_before_thisMonth."</a><br />";
while($row = mysql_fetch_assoc($res)){
$type_of_event = $row['type_of_event'];
$day_of = $row['day_of'];
$month_of = $row['month_of'];
$year_of = $row['year_of'];
$event_title = $row['event_title'];
$event_description = $row['event_description'];
if($days_before_thisMonth == $day_of){
echo "<a href=\"?day=".$day_of."&month=".$month_of."&year=".$year_of."\" class=\"calendar-link\" onMouseover=\"showhint('Event Title: ".$event_title."<br />Type of Event: ".$type_of_event."<br />Description: ".nl2br2($event_description)."', this, event, '300px')\"><img src=\"images/event.gif\" />"; if((strlen($event_title)>10)){ echo "".substr($event_title, 0, 10)."..."; }else echo $event_title; echo "</a><br />";
}
}
echo "</td>";
}
}
if($counter % 7 == 0) {
echo"</tr><tr>";
}
if($monthlength <= 1){
$monthstring = "0".$monthstring;
}
if($daylength <=1){
$daystring = "0".$daystring;
}
$current_month = date("n");
echo "<td";
echo " class=\"months-days\"";
echo ">";
$sql = "SELECT * FROM `calendar` WHERE `year_of`='".$year."' AND `month_of`='".$month."'";
$res = mysql_query($sql) or die(mysql_error());
if($day == $i && $month == $current_month){ echo "<div id=\"current-day\"></div>"; }
echo "<a href=\"?day=".$i."&month=".$month."&year=".$year."\" class=\"calendar-link\">".$i."</a><br />";
while($row = mysql_fetch_assoc($res)){
$type_of_event = $row['type_of_event'];
$day_of = $row['day_of'];
$month_of = $row['month_of'];
$year_of = $row['year_of'];
$event_title = $row['event_title'];
$event_description = $row['event_description'];
if($i == $day_of){
echo "<a href=\"?day=".$day_of."&month=".$month_of."&year=".$year_of."\" class=\"calendar-link\" onMouseover=\"showhint('Event Title: ".$event_title."<br />Type of Event: ".$type_of_event."<br />Description: ".nl2br2($event_description)."', this, event, '300px')\"><img src=\"images/event.gif\" />"; if((strlen($event_title)>10)){ echo "".substr($event_title, 0, 10)."..."; }else echo $event_title; echo "</a><br />";
}
}
echo "</td>";
}
$days_after = $firstDate+$counter;
$days_after_thisMonth = 35 - $days_after;
if($days_after_thisMonth != 0) {
$counter_last_day = 1;
for($ld = 0; $ld < $days_after_thisMonth; $ld++, $counter_last_day++) {
echo "<td>";
$month_after_this = ($month == 12) ? "1" : $month+1;
$year_after_this = ($month == 12) ? $year+1 : $year;
$sql = "SELECT * FROM `calendar` WHERE `year_of`='".$year."' AND `month_of`='".$month_after_this."'";
$res = mysql_query($sql) or die(mysql_error());
echo "<a href=\"?day=".$counter_last_day."&month=".$month_after_this."&year=".$year_after_this."\" class=\"calendar-link\">".$counter_last_day."</a><br />";
while($row = mysql_fetch_assoc($res)){
$type_of_event = $row['type_of_event'];
$day_of = $row['day_of'];
$month_of = $row['month_of'];
$year_of = $row['year_of'];
$event_title = $row['event_title'];
$event_description = $row['event_description'];
if($counter_last_day == $day_of){
echo "<a href=\"?day=".$day_of."&month=".$month_of."&year=".$year_of."\" class=\"calendar-link\" onMouseover=\"showhint('Event Title: ".$event_title."<br />Type of Event: ".$type_of_event."<br />Description: ".nl2br2($event_description)."', this, event, '300px')\"><img src=\"images/event.gif\" />"; if((strlen($event_title)>10)){ echo "".substr($event_title, 0, 10)."..."; }else echo $event_title; echo "</a><br />";
}
}
echo "</td>";
}
}
echo "</tr>";
?>
</table>
<?php } ?>
</div>
<?php include "./src/scripts/bottom.php"; ?>
view it here
http://troop557.vacau.com/calendar.php