Location: PHPKode > projects > ConPortal > conportal/punch_history.php
<?php
/*
 *  ConPortal - Pomona College ITS scheduling appplication
 *  Copyright (C) 2005-2007  Pomona College and Bucknell University
 *
 *  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
 */
// GOBBLE GOBBLE
require_once('standard.php');
xhtml_header('Punch History'); 

if (isset($_POST['view_for']) && $_POST['view_for'] == 'all')
    echo "<h1 class='center'>Punch History for Everyone</h1>\n";
elseif (isset($_POST['start_month']))
{
	/*get the name for view_for - if it comes back as "unknown user," we know the name wasn't
	picked from the dropdown, and hence, just use the username of the logged in session */
	$uName = getNameForUser($_POST['view_for']);
	if($uName == "Unknown User")
		$uName = getNameForUser($_SESSION['pid']);
		
    echo "<h1 class='center'>Personal Punch History for " . $uName . "</h1>\n";
}
else
    echo "<h1 class='center'>Punch History</h1>\n";

$time = strtotime("-2 weeks");
$start_month = isset($_POST['start_month']) ? $_POST['start_month'] : date('n', $time);
$start_day   = isset($_POST['start_day'])   ? $_POST['start_day']   : date('d', $time);
$start_year  = isset($_POST['start_year'])  ? $_POST['start_year']  : date('Y', $time);

?>

<form method='post' action='punch_history.php'><div>
    Starting on <select name='start_month' style='width: 8em'>
        <? print_month_options($start_month) ?>
    </select>
    <select name='start_day' style='width: 3.5em'>
        <? print_day_options($start_day) ?>
    </select>
    <select name='start_year' style='width: 4.6em'>
        <? print_year_options($start_year) ?>
    </select>
    for <select name='length' style='width: 3.5em'>
<?
    $sel = isset($_POST['length']) ? $_POST['length'] : 15;
    for($i = 1; $i <= 30; ++$i) {
        if ($i == $sel)
            echo "<option selected='selected'>$i</option>\n";
        else
            echo "<option>$i</option>\n";
    }
?>
    </select> days.
<?
    if (checkPerm($_SESSION, 'show_all_punch_history')) {
?>
    View punch history for 
    <select name='view_for'>
<?
    if (isset($_POST['view_for']) && $_POST['view_for'] == 'all')
        echo "<option value='all' selected='selected'>Everyone</option>\n";
    else
        echo "<option value='all'>Everyone</option>\n";
	
	$userList = sortUsersByName(getAllUserDetails());
	foreach($userList as $user)
	{
		$name = $user['first'] . " " . $user['last'];
	?><option value='<? echo $user['pid']; ?>'><? echo $name ?> </option>
<?	} ?>
    </select>
<?
	//otherwise $_SESSION['name'] ends up being the last person in the list
	$_SESSION['name'] = getNameForUser($_SESSION['pid']);
    }
?>
<input type='submit' value='
<?php
	echo DISPLAY_REPORT_SUBMIT;
?>
' />
</div></form>

<hr style='margin-top: 1em' />

<?
if (isset($_POST['start_year'])  and (int)$_POST['start_year']  and
    isset($_POST['start_month']) and (int)$_POST['start_month'] and
    isset($_POST['start_day'])   and (int)$_POST['start_day']   and
    isset($_POST['length'])      and (int)$_POST['length']) {

    $start = mktime(0, 0, 0, (int)$_POST['start_month'],
                    (int)$_POST['start_day'], (int)$_POST['start_year']);
    $end   = strtotime("+".((int)$_POST['length'])." days", $start);
	
    if (checkPerm($_SESSION, 'show_all_punch_history') &&
        isset($_POST['view_for']) && $_POST['view_for'] == 'all')
	{
        print_all_punch_histories($start, $end); 
	}
	else if(isset($_POST['view_for']))
	{
		print_punch_history($_POST['view_for'], $start, $end, FALSE);
	}
    else 
	{
		print_punch_history($_SESSION['pid'], $start, $end, FALSE);
	}
	
	

}

?>

<?
xhtml_footer();
?>
Return current item: ConPortal