Location: PHPKode > projects > Silicon Fodder > SiliconFodder/DocumentRoot/diary/months.php
<? require_once("../common/nocache.php"); ?>
<? require_once("../common/appobjects.php"); ?>
<? require_once("../common/db.php"); ?>
<? require_once("../common/checkIsLoggedIn.php"); ?>
<? require_once("../admin/util.php"); ?>
<? require_once("../diary/util.php"); ?>
<?
// Viewing multiple people?
if($HTTP_GET_VARS["mulview"] != "") {
	$mulview = $HTTP_GET_VARS["mulview"];
	$HTTP_SESSION_VARS["mulview"] = $mulview;
} elseif($HTTP_SESSION_VARS["mulview"] != "") {
	$mulview = $HTTP_SESSION_VARS["mulview"];
}

// Are we viewing a certain event type?
if($HTTP_GET_VARS["eventType"] != "") {
	$eventType = $HTTP_GET_VARS["eventType"];
	$HTTP_SESSION_VARS["eventType"] = $eventType;
} elseif($HTTP_SESSION_VARS["eventType"] != "") {
	$eventType = $HTTP_SESSION_VARS["eventType"];
}

// Get starting month/year (i.e. month to show at top of list)
if($HTTP_GET_VARS["sm"] != "") {
	$startMonth  = $HTTP_GET_VARS["sm"];
	$startYear   = $HTTP_GET_VARS["sy"];
	$HTTP_SESSION_VARS["sm"] = $HTTP_GET_VARS["sm"];
	$HTTP_SESSION_VARS["sy"] = $HTTP_GET_VARS["sy"];
} elseif($HTTP_SESSION_VARS["sm"] != "" || $HTTP_SESSION_VARS["sm"] === 0) {
	$startMonth  = $HTTP_SESSION_VARS["sm"];
	$startYear   = $HTTP_SESSION_VARS["sy"];
} else {
	$startMonth = date("n") - 1;    // 0 -> 11
	$startYear  = date("Y");
}

// This does the move forward/backward through the months
if($HTTP_GET_VARS["csm"] == "l") {
	$startMonth = $startMonth - 1;
	if($startMonth == -1) {
		$startMonth = 11;
		$startYear = $startYear - 1;
	}
	$HTTP_SESSION_VARS["sm"] = $startMonth;
	$HTTP_SESSION_VARS["sy"] = $startYear;
} elseif($HTTP_GET_VARS["csm"] == "r") {
	$startMonth = $startMonth + 1;
	if($startMonth == 12) {
		$startMonth = 0;
		$startYear = $startYear + 1;
	}
	$HTTP_SESSION_VARS["sm"] = $startMonth;
	$HTTP_SESSION_VARS["sy"] = $startYear;
}

// Get current week/month/year (i.e. the one highlighted)
if($HTTP_GET_VARS["cw"] != "") {
	$currentDay   = $HTTP_GET_VARS["cd"];
	$currentWeek  = $HTTP_GET_VARS["cw"];
	$currentMonth = $HTTP_GET_VARS["cm"];
	$currentYear  = $HTTP_GET_VARS["cy"];
	$HTTP_SESSION_VARS["cd"] = $HTTP_GET_VARS["cd"];
	$HTTP_SESSION_VARS["cw"] = $HTTP_GET_VARS["cw"];
	$HTTP_SESSION_VARS["cm"] = $HTTP_GET_VARS["cm"];
	$HTTP_SESSION_VARS["cy"] = $HTTP_GET_VARS["cy"];
} elseif($HTTP_SESSION_VARS["cw"] != "") {
	$currentDay   = $HTTP_SESSION_VARS["cd"];
	$currentWeek  = $HTTP_SESSION_VARS["cw"];
	$currentMonth = $HTTP_SESSION_VARS["cm"];
	$currentYear  = $HTTP_SESSION_VARS["cy"];
} else {
	// Get correct week for today
	$currentWeek = 1;
	$currentDay  = date("w", strtotime($arrMonths[$startMonth]." 1, ".$startYear));
	if($currentDay == 0) $currentDay = 7;
	for($i = 1; $i < date("j"); $i++) {
		$currentDay++;
		if($currentDay == 8) {
			$currentDay = 1;
			$currentWeek++;
		}
	}
	$currentMonth = $startMonth;
	$currentYear  = $startYear;
}

// Week or day view? (viewing multiple people, assume day view
if($mulview == "true") {
	$daysToView = 1;
} elseif($HTTP_GET_VARS["dtv"] != "") {
	$daysToView = $HTTP_GET_VARS["dtv"];
	$HTTP_SESSION_VARS["dtv"] = $HTTP_GET_VARS["dtv"];
} elseif($HTTP_SESSION_VARS["dtv"] != "") {
	$daysToView = $HTTP_SESSION_VARS["dtv"];
} else {
	$daysToView = 7;
}

// Who are we showing it to? ("me", "all", departmental id)
if($HTTP_GET_VARS["viewFor"] != "") {
	$viewFor = $HTTP_GET_VARS["viewFor"];
	$HTTP_SESSION_VARS["viewFor"] = $HTTP_GET_VARS["viewFor"];
} elseif($HTTP_SESSION_VARS["viewFor"] != "") {
	$viewFor = $HTTP_SESSION_VARS["viewFor"];
} else {
	$viewFor = "me";
}

// Or for another person entirely?
if($HTTP_GET_VARS["p2"] == "0") {
	$p2 = "";
	$HTTP_SESSION_VARS["p2"] = "";
} elseif($HTTP_GET_VARS["p2"] != "") {
	$p2 = $HTTP_GET_VARS["p2"];
	$p2n = $HTTP_GET_VARS["p2n"];
	$HTTP_SESSION_VARS["p2"] = $HTTP_GET_VARS["p2"];
	$HTTP_SESSION_VARS["p2n"] = $HTTP_GET_VARS["p2n"];
} elseif($HTTP_SESSION_VARS["p2"] != "") {
	$p2 = $HTTP_SESSION_VARS["p2"];
	$p2n = $HTTP_SESSION_VARS["p2n"];
} else {
	$p2 = "";
	$p2n = "";
}

if($HTTP_GET_VARS["client"] == "0") {
	$client = "";
	$HTTP_SESSION_VARS["client"] = "";
} elseif($HTTP_GET_VARS["client"] != "") {
	$client = $HTTP_GET_VARS["client"];
	$HTTP_SESSION_VARS["client"] = $HTTP_GET_VARS["client"];
} elseif($HTTP_SESSION_VARS["client"] != "") {
	$client = $HTTP_SESSION_VARS["client"];
} else {
	$client = "";
}

// if we're viewing a list of user ids, save these in session
if($HTTP_GET_VARS["userids"] == "0") {
	$userids = "";
	$HTTP_SESSION_VARS["userids"] = "";
} elseif($HTTP_GET_VARS["userids"] != "") {
	$userids = $HTTP_GET_VARS["userids"];
	$HTTP_SESSION_VARS["userids"] = $userids;
} elseif($HTTP_SESSION_VARS["userids"] != "") {
	$userids = $HTTP_SESSION_VARS["userids"];
} else {
	$userids = "";
}

?>
<html>
<head>
<style>
body {
	background-color: <?=getApplicationObject("SITE_BG_COLOUR")?>;
}
.month {
	background-color: #9EBEF5;
}
.day {
	border-bottom: 1px solid #000000;
}
td {
	text-align: center;
	color: #000000;
	font-size: 8pt;
	font-family: Verdana, Arial, Helvetica;
}
.today {
	border-width: 2px;
	border-style: solid;
	border-color: red;
}
<? if($daysToView == 7 || $daysToView == 31) { ?>
.thisWeek {
	background-color: #FBE694;
	cursor: default;
}
<? } else { ?>
.thisWeek {
	background-color: transparent;
	cursor: pointer;
}
<? } ?>
.thisDay {
	background-color: #FBE694;
	cursor: default;
}
.week {
	cursor: pointer;
}
a {
	color: #000000;
	text-decoration: none;
}
</style>
</head>
<body>
<form name="frm" method="get" action="months.php">
<table width="100%" cellspacing="0" cellpadding="1">
<? if($mulview != "true") { ?>
<tr><td colspan="9" nowrap>
<input onClick="document.frm.submit()" type="radio" value="31" name="dtv"<?if($daysToView==31) echo(" checked")?>> Month
<input onClick="document.frm.submit()" type="radio" value="7" name="dtv"<?if($daysToView==7) echo(" checked")?>> Week
<input onClick="document.frm.submit()" type="radio" value="1" name="dtv"<?if($daysToView==1) echo(" checked")?>> Day
<br>&nbsp;
</td></tr>
<?
}

$thisMonth = $startMonth;
$thisYear  = $startYear;

for($i = 0; $i<3; $i++) {
	if($p2 == "") {
		$busyDays = getBusyDays($thisMonth, $thisYear, $viewFor);
	} else {
		$busyDays = getBusyDays($thisMonth, $thisYear, "p2".$p2);
	}
	if($i == 0) {
?>
<tr><td class="month"><a href="months.php?csm=l&client=<?=$client?>"><img width="7" height="11" alt="Previous month" border="0" src="/images/diaryL.gif"></a></td><td colspan="7" class="month"><?=$arrMonths[$thisMonth]?>&nbsp;<?=$thisYear?></td><td class="month"><a href="months.php?csm=r&client=<?=$client?>"><img width="7" height="11" alt="Next month" border="0" src="/images/diaryR.gif"></a></td></tr>
<?
} else {
?>
<tr><td colspan="9" class="month"><?=$arrMonths[$thisMonth]?>&nbsp;<?=$thisYear?></td></tr>
<?
}
?>
<tr><td>&nbsp;</td><td class="day">M</td><td class="day">T</td><td class="day">W</td><td class="day">T</td><td class="day">F</td><td class="day">S</td><td class="day">S</td><td>&nbsp;</td></tr>
<?
	$col = 1;
	$row = 1;
	// display the blanks at start of month
	if(($daysToView == 31 || $currentWeek == $row) && $currentMonth == $thisMonth && $currentYear == $thisYear) {
		echo("<tr class=\"thisWeek\"><td>&nbsp;</td>");
	} else {
		echo("<tr class=\"week\"><td".getOnClick(1).">&nbsp;</td>");
	}
	$firstDayOfMonth = strtotime($arrMonths[$thisMonth]." 1, ".$thisYear);
	$firstDay        = date("w", $firstDayOfMonth) - 1;
	if($firstDay < 0) $firstDay += 7; // 0 - Monday, 1 - Tuesday, 2 - Wednesday, etc.
	for($j = 0; $j<$firstDay; $j++) {
		if($currentWeek == $row && $currentMonth == $thisMonth && $currentYear == $thisYear && $currentDay == $col) {
			echo("<td class=\"thisDay\"".getOnClick($col).">&nbsp;</td>");
		} else {
			echo("<td".getOnClick($col).">&nbsp;</td>");
		}
		$col++;
	}
	// display all days in month
	for($j = 1; $j <= getDaysInMonth($thisMonth, $thisYear); $j++) {
		if($col == 8) {
			$col = 1;
			echo("<td".getOnClick(7).">&nbsp;</td></tr>");
			$row++;
			if(($daysToView == 31 || $currentWeek == $row) && $currentMonth == $thisMonth && $currentYear == $thisYear) {
				echo("<tr class=\"thisWeek\"><td>&nbsp;</td>");
			} else {
				echo("<tr class=\"week\"><td".getOnClick($col).">&nbsp;</td>");
			}
		}
		echo("<td ");
		if($thisYear == date("Y") && $thisMonth == (date("n")-1) && $j == date("d")) {
			echo("style=\"border-width: 2px;border-style: solid;border-color: red;\" ");
		}
		if($currentWeek == $row && $currentMonth == $thisMonth && $currentYear == $thisYear && $currentDay == $col) {
			echo("class=\"thisDay\" ");
		}
		if(strpos($busyDays, ",".$j.",") !== false) {
			echo(" ".getOnClick($col)."><strong>".$j."</strong></td>");
		} else {
			echo(" ".getOnClick($col).">".$j."</td>");
		}
		$col++;
	}
	// trailing blanks
	for($j = $col; $j < 8; $j++) {
		if($currentWeek == $row && $currentMonth == $thisMonth && $currentYear == $thisYear && $currentDay == $j) {
			echo("<td class=\"thisDay\"".getOnClick($j).">&nbsp;</td>");
		} else {
			echo("<td".getOnClick($j).">&nbsp;</td>");
		}
	}
	echo("<td>&nbsp;</td></tr>");
?>
</tr>
<tr><td colspan="9">&nbsp;</td></tr>
<?
	$thisMonth++;
	if($thisMonth == 12) {
		$thisMonth = 0;
		$thisYear++;
	}
}
?>
</table>
</form>
<?
// Do not update main diary frame if the user has only moved backwards/forwards through months
if($HTTP_GET_VARS["csm"] == "") {
?>
<script language="javascript">
parent.diaryMain.location='diary.php?productId=<?=$HTTP_GET_VARS["productId"]?>&myaction=<?=$HTTP_GET_VARS["myaction"]?>&od=<?=$HTTP_GET_VARS["od"]?>&cd=<?=$currentDay?>&dtv=<?=$daysToView?>&cw=<?=$currentWeek?>&cm=<?=$currentMonth?>&cy=<?=$currentYear?>&viewFor=<?=$viewFor?>&p2=<?=$p2?>&p2n=<?=eregi_replace("'", "\\'", $p2n)?>&client=<?=eregi_replace("'", "\\'", $client)?>&mulview=<?=$mulview?>&eventType=<?=$eventType?>&userids=<?=$userids?>';
</script>
<?
}
?>
</body>
</html>
<?
function getOnClick($column) {
	global $row, $thisMonth, $thisYear, $HTTP_GET_VARS;
	return " onClick=\"self.location='months.php?productId=".$HTTP_GET_VARS["productId"]."&myaction=".$HTTP_GET_VARS["myaction"]."&cd=".$column."&cw=".$row."&cm=".$thisMonth."&cy=".$thisYear."'\"";
}
?>
Return current item: Silicon Fodder