Location: PHPKode > projects > ConPortal > conportal/inc/menu/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
 */

function menu($title) {
    switch ($title) {
        case "main":
            main_menu();
            break;
  //session variables used: shiftgroup, day.
  //post variables used: none.
        case "shifts":
            shift_menu('redirects/change_shifts.php');
            break;
        case "shift_history":
            shift_history_menu();
            break;
        case "admin_footer":
            admin_menu();
            break;
    }
}

function shift_menu($redirect)
{
	// Locate (midnight on) the first day of the month that shift_timestamp is in
	$dateArray = getdate($_SESSION['shift_timestamp']);
    $firstOfMonth = mktime(0, 0, 0, $dateArray['mon'],     1, $dateArray['year']);
	// a hack: day zero of the next month equates to the last day of this month
    $lastOfMonth  = mktime(0, 0, 0, $dateArray['mon'] + 1, 0, $dateArray['year']);
  ?>
<div id="right_menu">
    <h4>
        <a href='<?= $redirect ?>?timestamp=<?=
            strtotime("-1 month", $firstOfMonth) ?>'>&larr;</a>
        <?= date('F Y', $_SESSION['shift_timestamp']) ?>
        <a href='<?= $redirect ?>?timestamp=<?=
            strtotime("+1 month", $firstOfMonth) ?>'>&rarr;</a>
        <br /><a style='font-size:85%' href='<?= $redirect ?>?timestamp=<?= strtotime('12AM') ?>'>Jump to today</a>
    </h4>
    <table>
        <tr><td>S</td><td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td></tr>
        <tr>
<?php
    $dayOfWeek = date("w", $firstOfMonth);
    $start = strtotime("-$dayOfWeek days", $firstOfMonth);
    $end   = strtotime("+1 month -1 day", $firstOfMonth);
    $timestamp = $start;
    $i = 0;
    while ($timestamp <= $end) {
        if ($i && $i % 7 == 0)
            echo "</tr>\n<tr>\n";

        if ($timestamp < $firstOfMonth)
            echo "<td class='prevMonth'><a href='$redirect?timestamp=$timestamp'>".
                 date('j', $timestamp)."</a></td>\n";
        elseif ($timestamp == $_SESSION['shift_timestamp'])
            echo "<td class='highlighted'>".date('j', $timestamp)."</td>\n";
        elseif ($timestamp == strtotime('12AM'))
            echo "<td class='today'><a href='$redirect?timestamp=$timestamp'>".
                 date('j', $timestamp) . "</a></td>\n";
        else
            echo "<td><a href='$redirect?timestamp=$timestamp'>".
                 date("j", $timestamp)."</a></td>\n";
        ++$i;
        $timestamp = strtotime("+1 day", $timestamp);
    }

    while ($i % 7 != 0) {
        echo "<td class='nextMonth'><a href='$redirect?timestamp=$timestamp'>".
             date('j', $timestamp)."</a></td>\n";
        ++$i;
        $timestamp = strtotime("+1 days", $timestamp);
    }

?>
        </tr>
    </table>
</div>
<?
}

function shift_history_menu()
{
    shift_menu('a');
    shift_menu('b');

}

function main_menu() {
  ?>
  <div class="menu">
    <ul><?php
      $result = mysql_query("select name, href from menu order by sort");
      for ($i = 0; $i < mysql_num_rows($result); $i++) {
        $row = mysql_fetch_assoc($result);
        //Old code; doesn't play nice if you're down in /redirects/; it mangles all the URLs to include /redirects
	// which of course breaks EVERYTHING
	//echo '<li><a href="' . $row['href'] . '">' . $row['name'] . '</a></li>'; 
	echo '<li><a href="' . BASE_URL . $row['href'] . '">' . $row['name'] . '</a></li>';
	
      }
      ?>

    </ul>
  </div>
<?php
    mysql_free_result($result);
}

function admin_menu()
{
	?>
		<div class="menu" style="position: fixed; bottom: 0px;">
			<ul style="text-align: center;">
	<?php

	if (checkPerm($_SESSION, "edit_prefs"))
	{
		echo "<li><a href=\"" . BASE_URL . "edit_prefs.php\">Edit Preferences</a></li>\n";
	}

	if (checkPerm($_SESSION, "manage_users"))
		echo "<li><a href=\"" . BASE_URL . "display_users.php\">Manage Users</a></li>\n";

	if (checkPerm($_SESSION, "manage_shifts"))
	{
		echo "<li><a href=\"" . BASE_URL . "edit_shifts.php\">Manage Shifts</a></li>\n";
	}

	if (checkPerm($_SESSION, "manage_perms"))
		echo "<li><a href=\"" . BASE_URL . "permissions.php\">Manage Groups and Permissions</a></li>\n";
	
	/*if (checkPerm($_SESSION, "manage_checkout"))
		echo "<li><a href=\"checkout_items.php\">Manage Checkout 
Items</a></li>\n"; */

	if (checkPerm($_SESSION, "manage_announcements"))
		echo "<li><a href=\"" . BASE_URL . "announcements.php\">Manage Announcements</a></li>\n";


	if (checkPerm($_SESSION, "punch_tracking"))
    {
        echo "<li><a href=\"" . BASE_URL . "punch_tracking.php\">Punch Editing & Tracking</a></li>\n";
    }
            

	if (isset($_SESSION['impersonatingUser']))
		echo "<li><a href=\"" . BASE_URL . "impersonate.php?end=1\">End Impersonation</a></li>\n";
	elseif (checkPerm($_SESSION, "impersonate"))
		echo "<li><a href=\"" . BASE_URL . "impersonate.php\">Impersonate User</a></li>\n";
		
	?>
			</ul>
		</div>
	<?php
}

?>
Return current item: ConPortal