Please Help.
This calendar is exactly what I was looking for. The only problem is that I don't manage to have the week starting on monday instead of sunday.
I tried for ages. Any ideas?
Here is the code:
<?php
if($_POST['sel_year'] && $_POST['sel_month']) {
$tmpd = getdate(mktime(0, 0, 0, $_POST['sel_month'], 1, $_POST['sel_year']));
$month = $tmpd["mon"];
$fwday= $tmpd["wday"];
$year = $tmpd["year"];
$month_textual = $tmpd["month"];
echo "<font face=Arial, Helvetica color = red><b>";
}
if($_GET['sel_year'] && $_GET['sel_month']) {
$tmpd = getdate(mktime(0, 0, 0, $_GET['sel_month'], 1, $_GET['sel_year']));
$month = $tmpd["mon"];
$fwday= $tmpd["wday"];
$year = $tmpd["year"];
$month_textual = $tmpd["month"];
echo "<font face=Arial, Helvetica color = red><b>";
}
if(!isset($tmpd) ) {
$tmpd = getdate(mktime(0, 0, 0, date("m"), 1, date("Y")));
$month = $tmpd["mon"];
$fwday= $tmpd["wday"];
$year = $tmpd["year"];
$month_textual = $tmpd["month"];
echo "<font face=Arial, Helvetica color = red><b>";
}
if($month == 2) {
if(($year%4) == 0) {
$no_days = 29;
}
else {
$no_days = 28;
}
}
elseif(($month == 1) || ($month == 3) || ($month == 5) ||
($month == 7) || ($month == 8) || ($month == 10) || ($month == 12)) {
$no_days = 31;
}
else {
$no_days = 30;
}
$next_mon = getdate(mktime(0, 0, 0, ($month + 1), 1, $tmpd["year"]));
$prev_mon = getdate(mktime(0, 0, 0, ($month - 1), 1, $tmpd["year"]));
$next_mon_txt = $next_mon["mon"];
$next_yr_txt = $next_mon["year"];
/* Get all dates with events as an array */
require('GetDatesWithEvents_DS.php');
$getDatesWithEvents = new GetDatesWithEvents_DS();
$conn = $getDatesWithEvents->openConnection();
$dlist = $getDatesWithEvents->getDates($month, $year, $uid, $conn);
$getDatesWithEvents->closeConnection($conn);
echo "<TABLE BORDER=0 cellpadding=5 cellspacing=0 width=100% bordercolor=#9999FF>";
echo "<tr></tr><td>";
echo "<table BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100% BGCOLOR=#FAEBD7>
<tr>
<td align=right>
<a href=calender.php?sel_month=$prev_mon[mon]&sel_year=$prev_mon[year] style=\"color: black;\"><</a>
</td>
<td colspan=5 align=center><b>$month_textual $year</b></td>
<td align=left>
<a href=calender.php?sel_month=$next_mon_txt&sel_year=$next_yr_txt style=\"color: black\">></a>
</td>
</tr><tr bgcolor=#C0C0C0>";
echo"<td width=14%>So</td><td width=14%>Mo</td><td width=14%>Di</td><td width=14%>Mi</td>
<td width=14%>Do</td><td width=14%>Fr</td><td width=14%>Sa</td>";
echo"</tr><tr>";
$firstday = date("l", mktime(0, 0, 0, 7, 1, 2001));
if($fwday == 0) {
$index = 1;
}
if($fwday == 1) {
$index = 2;
}
if($fwday == 2) {
$index = 3;
}
if($fwday == 3) {
$index = 4;
}
if($fwday == 4) {
$index = 5;
}
if($fwday == 5) {
$index = 6;
}
if($fwday == 6) {
$index = 7;
}
for($a = 1; $a <= $fwday; $a++) {
echo"<td></td>";
}
for($i = 1; $i <= (7 - $fwday) ; $i++) {
if($i == $dlist[$i]) {
$color = "red";
}
else {
$color = "#000000";
}
echo"<td align=center width=30 height=30>
<a href=ViewDate.php?date=$i&month=$month&year=$year target=ViewDate>
<font color=$color size=-1><b>$i</b></font><a></td>";
$count++;
}
echo"</tr>";
echo"<tr>";
for($j = $i; $j <= ($i + 6); $j++) {
if($j == $dlist[$j]) {
$color = "red";
}
else {
$color = "#000000";
}
echo"<td align=center width=30 height=30><b>
<a href=ViewDate.php?date=$j&month=$month&year=$year target=ViewDate><font color=$color size=-1>
<font color=$color size=-1><b>$j</b></font></td>";
}
echo"</tr>";
echo"<tr>";
for($k = $j; $k <= ($j + 6); $k++) {
if($k == $dlist[$k]) {
$color = "red";
}
else {
$color = "#000000";
}
echo"<td align=center width=30 height=30><b>
<a href=ViewDate.php?date=$k&month=$month&year=$year target=ViewDate><font color=$color size=-1>
<font color=$color size=-1><b>$k</b></font></td>";
}
echo"</tr>";
echo"<tr>";
for($l = $k; $l <= ($k + 6); $l++) {
if($l == $dlist[$l]) {
$color = "red";
}
else {
$color = "#000000";
}
echo"<td align=center width=30 height=30><b>
<a href=ViewDate.php?date=$l&month=$month&year=$year target=ViewDate>
<font color=$color size=-1><b>$l</font></b></td>";
}
echo"</tr>";
echo"<tr>";
if(($no_days - $l) >= 7) {
$roll_over = $l + 6;
}
for($m = $l; $m <= $roll_over; $m++) {
if($m == $dlist[$m]) {
$color = "red";
}
else {
$color = "#000000";
}
echo"<td align=center width=30 height=30><b>
<a href=ViewDate.php?date=$m&month=$month&year=$year target=ViewDate>
<font color=$color size=-1><b>$m</b></font></td>";
}
echo"</tr>";
echo"<tr>";
for($n = $m; $n <= $no_days; $n++) {
if($n == $dlist[$n]) {
$color = "red";
}
else {
$color = "#000000";
}
echo"<td align=center width=30 height=30><b>
<a href=ViewDate.php?date=$n&month=$month&year=$year target=ViewDate>
<font color=$color size=-1><b>$n</b></font>";
}
echo"</tr>";
echo"</table></td></tr></table>";
?>
<b><font color="black">View Month</font></b>
<table>
<tr>
<td>
<select name="sel_year" class="TextField">
<?php
$tyear = date("Y");
for($i = $tyear; $i < ($tyear+10); $i++)
echo"<option value=$i>$i";
?>
</select>
</td>
<td>
<select name="sel_month" class="TextField">
<?php
$tmonth = date("m");
for($j = 1; $j <= 12; $j++)
echo"<option value=$j>$j";
?>
</select>
</td>
<td><input type=submit name=submit value=Go class="TextField"></td>
</tr>
<tr>
<td><font size=-1>(year/month)</font></td>
</tr>
</table>
</form>
</font>
</center>
</div>
</body>
</html>