Location: PHPKode > projects > Mozart > Mozart-0.0.4/calendar.php
<?
include("connect.inc");
include("reqlogin.inc");

// $NextMon   = next month number (ie, 12)
// $NextYear  = year associated with $NextMon
// $PrevMon   = previous month number (ie, 10)
// $PrevYear  = year associated with $PrevMon
// $Month     = month name (ie, December)
// $Year      = year number (ie, 2001)
// $Day       = Day of month to display (ie, 5)

// get user data
include("userprefs.inc");

//get current date
$current_date = getdate();

// determine which user_id to display

$deleteme = $SearchSys;

if ($ChangeIt) {
    $SearchSys = $ChangeUser;
}
elseif (!($SearchSys)) {
	$SearchSys = $UserID;
}

//load current_date array with proper date
if ($Day) {
	$start_day = date("l", mktime(0,0,0,$Mon,1,$Year));
	$Month     = date("F", mktime(0,0,0,$Mon,1,$Year));
	$Year      = date("Y", mktime(0,0,0,$Mon,1,$Year));
}
elseif ($PrevMon) { 
	$start_day = date("l", mktime(0,0,0,$PrevMon,1,$PrevYear));
	$Month     = date("F", mktime(0,0,0,$PrevMon,1,$PrevYear));	
        $Mon       = $PrevMon;
	$Year      = $PrevYear;
	$Day       = 0;
}
elseif ($NextMon) {
	$start_day = date("l", mktime(0,0,0,$NextMon,1,$NextYear));
	$Month     = date("F", mktime(0,0,0,$NextMon,1,$NextYear));	
	$Mon       = $NextMon;
	$Year      = $NextYear;
	$Day       = 0;
}
else {
//	get day of week (ie, Monday) for first day of current month & year
	$start_day = date("l", mktime(0,0,0,$current_date["mon"],1,$current_date["year"]));
	$Mon       = $current_date["mon"];
	$Month     = $current_date["month"];
	$Year      = $current_date["year"];
	if (!($Day)) {
	   $Day    = $current_date["mday"];
	}
}

//load weekday array; note the zero offset; i don't know of a better way to do this
$weekday[0] = "Sunday";
$weekday[1] = "Monday";
$weekday[2] = "Tuesday";
$weekday[3] = "Wednesday";
$weekday[4] = "Thursday";
$weekday[5] = "Friday";
$weekday[6] = "Saturday";

//determine number of days in displayed month
if ($Month == "January"   OR
    $Month == "March"     OR
    $Month == "May"       OR
    $Month == "July"      OR
    $Month == "August"    OR
    $Month == "October"   OR
    $Month == "December")  {
    $max_days = 31;
}
elseif ($Month == "February") {
//  check for leap year
    if (checkdate(2, 29, $Year)) {
	$max_days = 29;
    }
    else {
	$max_days = 28;
    }
}
else {
    $max_days = 30;
}

include("getusername.inc");
print("<html>");
print("<title>Mozart: Calendar for $FirstName $LastName</title>");
print("<body bgcolor=$bgcolor text=$txtcolor>");
print("<center>");

//get system ids
include("getallusers.inc");

//print SysID
print("<form action=\"calendar.php\" method=\"post\">");
print("View Calendar for: <select name=ChangeUser>");
while ($ownerdata = mysql_fetch_array($OwnerData)) {
	if ($ownerdata["user_id"] == $SearchSys) {
		$selected = " selected";
	}
	else {
		$selected = "";
	}
	printf("<option value=%s %s>%s", $ownerdata["user_id"], $selected, $ownerdata["system_id"]);
}
print("</select>");
print("<input type=submit value=Show name=ChangeIt>");
print("</form>");

//print $Message
print("<br><font color=red>$Message</font><br><br>");

//prepare next and previous month links
$NextMon = $Mon + 1; 
$PrevMon = $Mon - 1;

if ($NextMon == 13) {
	$NextYear = $Year + 1;
	$NextMon = 1;
}
else {
	$NextYear = $Year;
}
if ($PrevMon == 0) {
	$PrevYear = $Year - 1;
	$PrevMon = 12;
}
else {
	$PrevYear = $Year;
}
include("links.inc");
?>
<table border=1 cellspacing=1 cellpadding=10>
<? print("<caption align=center>$Month $Year</caption>"); ?>
<tr bgcolor=<? echo $bordercolor ?>>
<td>Sunday</td>
<td>Monday</td>
<td>Tuesday</td>
<td>Wednesday</td>
<td>Thursday</td>
<td>Friday</td>
<td>Saturday</td>
</tr>
<tr>
<?
$x = 0;
$day_count = 1;
$started = "no";
while ($day_count <= $max_days) {
//	place first day of month on proper weekday (ie, 2 on Tuesday, for example)
	if ($start_day == $weekday[$x] AND
            $started = "no") {
		if ($day_count == $Day) {
			$bgcolor = " bgcolor=\"#FFFF33\"";
		}
		else {
			$bgcolor = "";
		}
		printf("<td%s><a href=\"calendar.php?Day=%s&Mon=%s&Year=%s&SearchSys=%s\">%s</a></td>", $bgcolor, $day_count, $Mon, $Year, $SearchSys, $day_count);
		$started = "yes";
		$day_count = $day_count + 1;
	}
//	first day is positioned, so print the rest and highlight the day being displayed
	elseif ($started == "yes") {
		if ($day_count == $Day) {
			$bgcolor = " bgcolor=\"#FFFF33\"";
		}
		else {
			$bgcolor = "";
		}
		printf("<td%s><a href=\"calendar.php?Day=%s&Mon=%s&Year=%s&SearchSys=%s\">%s</a></td>", $bgcolor, $day_count, $Mon, $Year, $SearchSys, $day_count);
		$day_count = $day_count + 1;
	}
//	this will print when IF is false
	else {
		print("<td></td>");
	}
	$x         = $x + 1;
//	Saturday just printed, so start new row
	if ($x == 7  or
	    $x == 14 or
	    $x == 21 or
	    $x == 28 or
	    $x == 35) {
		print("</tr><tr>");
	}
}
?>
</tr>
</table>
<?
$AppointmentSQL = "SELECT appt_id, time, information FROM appointment WHERE month = '$Mon' AND day = '$Day' AND year = '$Year' AND owner = '$SearchSys' ORDER BY time";
$AppointmentData = mysql_query($AppointmentSQL);
?>
<table border=0 cellspacing=0 cellpadding=0>
<tr><td>
<table border=1 cellspacing=1 cellpadding=0>
<tr bgcolor=<?echo $bordercolor ?>>
<td>Time</td>
<td>Appointment</td>
<td><a href="addappt.php?Mon=<?echo $Mon?>&Day=<?echo $Day?>&Year=<?echo $Year?>&SearchSys=<?echo $SearchSys?>">Add Appt</a></td>
</tr>
<?
while ($Appointment = mysql_fetch_array($AppointmentData)) {
	printf("<tr><td>%s</td>", $Appointment["time"]);
	printf("<td>%s</td>", $Appointment["information"]);
	printf("<td><a href=\"updappt.php?id=%s&Mon=%s&Day=%s&Year=%s\">Update</td>", $Appointment["appt_id"], $Mon, $Day, $Year);
	printf("<td><a href=\"delappt.php?id=%s&Mon=%s&Day=%s&Year=%s\">Delete</td>", $Appointment["appt_id"], $Mon, $Day, $Year);
	print("</tr>");
}
printf("<tr><td></td><td><a href=\"addappt.php?Mon=%s&Day=%s&Year=%s&SearchSys=%s\">Add Appt</a></td></tr>", $Mon, $Day, $Year, $SearchSys);
?>
</table>
</td><td>
<?
//this pulls all UNCOMPLETED to-do items
$ToDoSQL = "SELECT todo_id, priority, information FROM todo WHERE year <= '$Year' AND owner = '$SearchSys' AND complete = ' ' ORDER BY priority, information";
$ToDoData = mysql_query($ToDoSQL);
//this pulls all COMPLETED to-do items
$DoneToDoSQL = "SELECT information FROM todo WHERE owner = '$SearchSys' AND completed_mon = '$Mon' AND completed_day = '$Day' AND completed_year = '$Year' AND complete != ' '";
$DoneToDoData = mysql_query($DoneToDoSQL);
?>
<table border=1 cellspacing=1 cellpadding=0>
<tr bgcolor=<? echo $bordercolor ?>>
<td>Priority</td>
<td>To Do</td>
<?printf("<td><a href=\"addtodo.php?Mon=%s&Day=%s&Year=%s&SearchSys=%s\">Add To Do</a></td>", $Mon, $Day, $Year, $SearchSys);?>
</tr>
<?
//print active todo items
while ($ToDo = mysql_fetch_array($ToDoData)) {
	printf("<tr><td>%s</td><td>%s</td>", $ToDo["priority"], $ToDo["information"]);
	printf("<td><a href=\"updtodo.php?id=%s&Mon=%s&Day=%s&Year=%s\">Update</a></td>", $ToDo["todo_id"], $Mon, $Day, $Year);
	printf("<td><a href=\"deltodo.php?id=%s&Mon=%s&Day=%s&Year=%s\">Delete</a></td>", $ToDo["todo_id"], $Mon, $Day, $Year);
	printf("<td><a href=\"updtodo.php?id=%s&Update=Y&Complete=Y&Mon=%s&Day=%s&Year=%s\">Complete</a></td></tr>", $ToDo["todo_id"], $Mon, $Day, $Year);
}
//print done todo items
while ($DoneToDo = mysql_fetch_array($DoneToDoData)) {
	printf("<tr><td></td><td>%s</td></tr>", $DoneToDo["information"]);
}
printf("<tr><td></td><td><a href=\"addtodo.php?Mon=%s&Day=%s&Year=%s&SearchSys=%s\">Add To Do</a></td></tr>", $Mon, $Day, $Year, $SearchSys);
?>
<br>
</table>
</table>
<?
include("links.inc");
?>
</body>
</html>
Return current item: Mozart