Location: PHPKode > projects > ConPortal > conportal/nagscript.php
<?php
/*
 *  ConPortal - Pomona College ITS / Bucknell University ISR scheduling appplication
 *  Copyright (C) 2005-2007  Pomona College& 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
 */
 
include_once('standard.php'); 
//this code is (mostly) shamelessly lifted from index_people_on_duty from
//the file /inc/index/display.php 
$punched_in_now = getPunchedIn();
$shifts_now = sortShiftsByTime(getShiftDetailsForArray(getShiftsForTime(time())));

//find people who should be punched in, but aren't.
//note that we always build the messages, but only conditionally send them.  
//Being straightforward is sometimes better than being really super-clever... 
$num_shifts = count($shifts_now);
if ($num_shifts > 0)
	{
		$summary = "";
		$count = 1; //number of shifts we've gone through
		$missing = 0; //number of people who are missing
		$email_flag = FALSE; //if we're sending an unclaimed temp drop or slacker alert
		$perm_open = 0; //number of perm open shifts; if all shifts are perm open, we got problems!
		foreach ($shifts_now as $row)
		{
			//get the data for the current shift and then the people on that shift
			$status = getShiftStaffingStatus($row['pid']);
			switch ($status)
			{
				case STATUS_PERM_OPEN	:
					// if the shift is permanently open, do nothing.  No one's scheduled to be here. 		
					$summary = $summary . "Shift " . $count . " is perm-open.\n";
					$count++;
					$perm_open++;
					$missing++;
					break;
				
				case STATUS_TEMP_OPEN:
					// the shift is temporarily open, but hasn't been covered.  
					$temp_dropper = getNameForUser($row['dropper']);
					
					$body = "Hello! \n  A temporarily dropped shift from " . 
					date("g:ia", $row['start_time']) . " to " . date("g:ia", $row['end_time']) .
					" and belonging to " . $temp_dropper . " has not been claimed by anyone.";
					
					$subject = "ALERT!  Temp dropped shift has not been taken!";
					
					$userinfo = getUserDetails($row['dropper']);
					
					$to = SUPERS . ", " . $userinfo['username'] . EMAIL_DOMAIN;
					if(TEMP_DROP_ALERT_ENABLED)
					{
						send_email($body, $subject, $to);
					}
					$summary = $summary . "Shift " . $count . ": " . $temp_dropper . " unclaimed drop\n";
					$email_flag = TRUE;
					$count++;
					$missing++;
					
					break;
				
				default:
					//check to see if the owner is punched in.  If not, send an email.
					
					$slacker = getNameForUser($row['owner']);
					if(!(isPunchedIn($row['owner'])))
					{
						
					
						$body = "Hello! \n  The shift from " . 
						date("g:ia", $row['start_time']) . " to " . date("g:ia", $row['end_time']) .
						" belongs to " . $slacker . ", but that slacker has not punched in!";
						$subject = "ALERT!  SLACKER DETECTED!";
						
						$userinfo = getUserDetails($row['owner']);
						
						$to = SUPERS . ", " . $userinfo['username'] . EMAIL_DOMAIN;
						if(SLACKER_ALERT_ENABLED)
						{
							send_email($body, $subject, $to);
						}
						$summary = $summary . "Shift " . $count . ": " . $slacker . " - NOT punched in!\n";
						$email_flag = TRUE;
						$missing++;

					}
					else
					{
						$summary = $summary . "Shift " . $count . ": " . $slacker . " punched in.\n";	
					}

					$count++;
					break;
			}
		}
	//Has email been sent, or are all the shifts perm-open?  Send the summary!
	if(($email_flag) || ($num_shifts == $perm_open))
	{
		$summary = GROUPNAME . "\n". $summary;
		if(SITUATION_REPORT_ENABLED)
		{
			send_email($summary, "Situation Report", SUPERS);
		}

		if(($missing == $num_shifts) && EMERGENCY_SITUATION_REPORT_ENABLED) //if NO ONE is there...
			send_email($summary, "", EMERGENCY);				
	}	


	}






?>
Return current item: ConPortal