Location: PHPKode > projects > ConPortal > conportal/inc/meetings/display.php
<?php
/*
 *  ConPortal - Pomona College ITS scheduling appplication
 *  Copyright (C) 2005-2006  Pomona College
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of version 2 of the GNU General Public License
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/*
 * Display the form to set meeting attendance
 */
function printMeetingAttendanceForm ($meetingPid)
{
	// Ensure we've got a valid meeting pid
	$meeting = getMeetingDetails($meetingPid);
	if (!$meeting)
	{
		echo "<p class=\"warn\">$meetingPid: not a valid meeting</p>";
		return;
	}
	
	$users = sortUsersByName(getAllUserDetails());
	$meeting_groups = getGroupsForMeetingType($meeting['type']);
	$attendance = getAttendanceForMeeting($meetingPid);
	$statuses = array("Present", "Absent/Excused", "Absent/Unexcused", "Tardy", "Left Early");
	?>
		<h2>Meeting Attendance</h2>
		<form action="#" method="post">
			<input type="hidden" name="attendance_pid" value="<?= $meetingPid ?>" />
			<table>
				<?php
					foreach($users as $user)
					{
						// Skip this user if they can't see this meeting anyway
						$user_groups = getGroupsForUser($user['pid']);
						$user_groups[] = getPrimaryGroupForUser($user['pid']);
						if (count(array_intersect($meeting_groups, $user_groups)) == 0)
							continue;
					
						if (isset($attendance[$user['pid']]))
							$userStatus = $attendance[$user['pid']];
						elseif (isset($_POST["user{$user['pid']}"]))
							$userStatus = $_POST["user{$user['pid']}"];
						else
							$userStatus = "Present";
						echo "<tr><td>{$user['name']}</td><td><select name=\"user{$user['pid']}\">";
						foreach ($statuses as $status)
						{
							if ($status == $userStatus)
								echo "<option selected='selected'>$status</option>";
							else
								echo "<option>$status</option>";
						}
						echo "</select></td></tr>\n";
					}
				?>
			</table>
			<p>
				<input type="submit" value="Save Changes" />
				<input type="reset" value="Reset" />
				<input type="button" value="Cancel" onclick="window.location = 'meetings.php'" />
			</p>
		</form>
	<?php
}

/*
 * Display the form to create a new meeting, or edit an existing one.
 * Set the parameter to NULL to create a new one.
 */
function printMeetingCreateEditForm ($meetingPid)
{
	// Retrieve data for existing meeting
	if ($meetingPid)
	{
		$meeting = getMeetingDetails($meetingPid);
		if (!$meeting)
		{
			echo "<p class=\"warn\">$meetingPid is not a valid meeting.</p>";
			return;
		}
	}
	elseif (isset($_POST['type']))
	{
		// Re-insert values from old form submission
		$meeting = $_POST;
		$meeting['date'] = mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year']);
	}
	else
	{
		// Insert sane default values
		$meeting = array("type" => 1,
		                 "date" => time(),
		                 "location" => "",
		                 "status" => "Scheduled/Mandatory",
		                 "notes" => "");
	}

	$types = getNamesForAllMeetingTypes();
	$typeOptions = "";
	foreach ($types as $pid => $type)
	{
		if ($pid == $meeting['type'])
			$typeOptions .= "<option value=\"$pid\" selected='selected'>$type</option>\n";
		else
			$typeOptions .= "<option value=\"$pid\">$type</option>\n";
	}
	if ($meetingPid)
		echo "<h1>Edit Meeting</h1>\n";
	else
		echo "<h1>Schedule A New Meeting</h1>\n";
	echo "<form action=\"#\" method=\"post\">\n";
	if ($meetingPid)
		echo "<input type=\"hidden\" name=\"pid\" value=\"$meetingPid\" />\n";
	?>
		<table id="meetingDetails">
			<tr><td style="width:8em"><b>Meeting Type:</b></td>
				<td><select name="type"><?= $typeOptions ?></select></td>
			</tr>
			<tr><td><b>Date:</b></td>
				<td><select name="month"><?php print_month_options(date('n', $meeting['date'])); ?></select>
					<select name="day">  <?php print_day_options(date('j',   $meeting['date'])); ?></select>
					<select name="year"> <?php print_year_options(date('Y',  $meeting['date'])); ?></select>
				</td>
			</tr>
			<tr><td><b>Location:</b></td>
				<td><input name="location" type="text"
					size="30" maxlength="30" value="<?= $meeting['location'] ?>" />
				</td>
			</tr>
			<tr><td><b>Status:</b></td>
				<td>
					<select name="status">
						<?php
							$statuses = array("Scheduled/Mandatory",
											  "Scheduled/Voluntary",
											  "Completed",
											  "Cancelled");
							foreach ($statuses as $status)
							{
								if ($meeting['status'] == $status)
									echo "<option selected='selected'>$status</option>";
								else
									echo "<option>$status</option>";
							}
						?>
					</select>
				</td>
			</tr>
			<tr><td><b>Notes:</b><p class="small">
<?php
			echo MEETINGS_DISPLAY_WARNING;
?>			</p></td>
				<td><textarea name="notes" rows="15" cols="60"><?= $meeting['notes'] ?></textarea></td>
			</tr>
		</table>
		<p>
			<input type="submit" value="Save Changes" />
			<input type="reset" value="Reset" />
			<input type="button" value="Cancel" onclick="window.location = 'meetings.php'" />
		</p>
	<?php
	echo "</form>\n";
}

/*
 * Display a page of more detailed information about a meeting
 */
function printMeetingDetails ($meetingPid)
{
	$meeting = getMeetingDetails($meetingPid);
	if (!$meeting)
	{
		echo("<p class=\"warn\">$meetingPid is not a valid meeting id.</p>");
		return;
	}
	$type = getNameForMeetingType($meeting['type']);
	?>
		<h2>Meeting Details</h2>
		<?php
			if (checkPerm($_SESSION, "manage_meetings"))
				echo "<p><a href=\"meetings.php?edit=$meetingPid\">Edit This Meeting</a></p>\n";
		?>
		<table id="meetingDetails">
			<tr><td style="width:8em"><b>Meeting Type:</b></td><td><?= $type ?></td></tr>
			<tr><td><b>Date:</b></td>    <td><?= timestamp_to_prettydate($meeting['date']) ?></td></tr>
			<tr><td><b>Location:</b></td><td><?= $meeting['location'] ?></td></tr>
			<tr><td><b>Status:</b></td>  <td><?= $meeting['status'] ?></td></tr>
			<tr><td><b>Notes:</b></td>   <td><?= $meeting['notes'] ?></td></tr>
		</table>
		<p><a href="meetings.php">Back to Meetings</a></p>
	<?php
	if (checkPerm($_SESSION, "view_meeting_attendance"))
	{
		// Show attendance information too
		// FIXME: only retrieve users who should be attending, based on their groups
		$users = sortUsersByName(getAllUserDetails());
		$attendance = getAttendanceForMeeting($meetingPid);
		$meeting_groups = getGroupsForMeetingType($meeting['type']);
		?>
			<br /><hr /><br />
			<h2>Meeting Attendance</h2>
			<?php
				if (checkPerm($_SESSION, "manage_meetings"))
					echo "<p><a href=\"meetings.php?attendance=$meetingPid\">Edit Attendance</a></p>\n";
			?>
			<table>
				<?php
					foreach ($users as $user)
					{
						// Skip this user if they can't see this meeting anyway
						$user_groups = getGroupsForUser($user['pid']);
						$user_groups[] = getPrimaryGroupForUser($user['pid']);
						if (count(array_intersect($meeting_groups, $user_groups)) == 0)
							continue;

						if (isset($attendance[$user['pid']]))
							$status = $attendance[$user['pid']];
						else
							$status = "Present";
						echo "<tr><td>{$user['name']}</td><td>$status</td></tr>\n";
					}
				?>
			</table>
		<?php
	}
}

/*
 * Display main tables of meetings
 */
function printMeetingsTable ()
{
	$types = getNamesForAllMeetingTypes();
	$upcomingMeetings = getUpcomingMeetingDetails();
	$pastMeetings = getPastMeetingDetails();
	$displayEdits = checkPerm($_SESSION, "manage_meetings");
	
	?>
		<div class="center">
			<h1>Upcoming Meetings</h1>
	<?php 
	if (count($upcomingMeetings) > 0)
	{
		?>
			<table class="meetingsTable">
				<tr><th>Type</th><th>Date</th><th>Location</th><th>Status</th><th><!-- links --></th></tr>
				<?php
					$i = 0;
					foreach ($upcomingMeetings as $meeting)
					{
						echo "<tr class=\"d" . ($i++ % 2) . "\">" .
							"<td>" . $types[$meeting['type']] . "</td>" .
							"<td>" . date("l n/j/Y", $meeting['date']) . "</td>" .
							"<td>" . $meeting['location'] . "</td>" .
							"<td>" . $meeting['status'] . "</td>";
						if ($displayEdits)
							echo "<td><a href=\"meetings.php?edit=" . $meeting['pid'] . "\">edit</a>" .
								"/<a href=\"meetings.php?attendance=" . $meeting['pid'] . "\">attendance</a>";
						echo "</tr>\n";
					}
				?>
			</table>
		<?php
	}
	else
	{
		echo "<p>No upcoming meetings.</p>";
	}
	if (checkPerm($_SESSION, "manage_meetings"))
		echo "<p><a href=\"meetings.php?create=1\">Schedule a new meeting</a></p>\n";
	?>
		</div>
		<br /><hr /><br />
		<div class="center">
			<h1>Past Meetings</h1>
	<?php
	if (count($pastMeetings) > 0)
	{
		?>
			<table class="meetingsTable">
				<tr><th>Type</th><th>Date</th><th>Location</th><th>Status</th><th><!-- links --></th></tr>
				<?php
					$i = 0;
					foreach ($pastMeetings as $meeting)
					{
						echo "<tr class=\"d" . ($i++ % 2) . "\">" .
							"<td>" . $types[$meeting['type']] . "</td>" .
							"<td>" . date("l n/j/Y", $meeting['date']) . "</td>" .
							"<td>" . $meeting['location'] . "</td>" .
							"<td>" . $meeting['status'] . "</td>" .
							"<td><a href=\"meetings.php?notes=" . $meeting['pid'] . "\">notes</a>";
						if ($displayEdits)
							echo "/<a href=\"meetings.php?edit=" . $meeting['pid'] . "\">edit</a>" .
								"/<a href=\"meetings.php?attendance=" . $meeting['pid'] . "\">attendance</a>";
						echo "</td></tr>\n";
					}
				?>
			</table>
		<?php
	}
	else
	{
		echo "<p>No past meetings.</p>";
	}
	?>
		</div>
	<?php
}

?>
Return current item: ConPortal