Location: PHPKode > projects > Time Recording System > index2.php
<?
/*
	################################################################
	# >>> Time Recording System											#
	################################################################
	# > Authors:  Lucian Pricop and David Sturtevant					#
	# > E-mail:  hide@address.com						#
	# > Date: 	 17 April 2007											#
	#																			#
	# This web application allows your staff to submit their time	#
	# sheets on line 														#
	################################################################
	#	Copyright (C) 2007  Oxford Archaeology							#
	#																			#
	# This program is free software; you can redistribute 			#
	# it and/or modify it under the terms of the GNU General 		#
	# Public License as published by the Free Software 				#
	# Foundation; either version 2 of the License, or (at your	 	#
	# option) any later version.											#
	#																			#
	# 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., 59 Temple Place - 			#
	# Suite 330, Boston, MA  02111-1307, USA.							#
	################################################################
*/

	require("header.php");
//VALUES NEEDED FROM THE db: basicRate, otDay, otSun, minHours
//values that the user can edit but they have an implicit value taken from the DB: resolution, showWeekendDays, startTime, stopTime
//values always inputed by the user: weekEndingDate
	function __autoload($class_name) {
		require_once $class_name . '.php';
	}
		
	class Timesheet
	{
		public $refid;
		public $startDate;// an int obtained from strtotime
		public $lastName;//owner details
		public $firstName;
		public $entries = array(); //an array of entries
	}
	class Entry
	{
		public $refid;
		public $invoiceCode;
		public $taskCode;
	}

	$dbconn = new dbcontrol();
	$connectionStatus = $dbconn->connectdb();
	$queryString="SELECT * FROM tbl_office_time_sheet WHERE submitted = 'f' AND staffrefid = ".$_SESSION["refid".$privateKey]." ORDER BY startdate DESC";
	$queryResult = $dbconn->sendquery2($queryString);
	$rowNr=pg_num_rows($queryResult);
// 	$status = "&nbsp;";
// 	if(isset($_GET["status"]))
// 		$status = pg_escape_string(htmlspecialchars(trim($_GET["status"])));

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <title>Time Recording System</title>	
		<link href="favicon.ico" type="image/x-icon" rel="shortcut icon"/> 
		<link rel='stylesheet' type='text/css' href='timesheets.css' />
		<script type="text/javascript" src="ajaxRequestModule.js"></script>
		<script type="text/javascript" >
			
			function viewTimesheet(evt)
			{
				window.location = "timesheetView.php?refid="+ evt.target.getAttribute("refid");
			}
			function editTimesheet(evt)
			{
				window.location = "timesheetEdit.php?refid="+evt.target.getAttribute("refid");
			}
			function manageInvoiceCode(evt)
			{
				window.location = "manageInvoice.php?invoicecode="+encodeURIComponent(evt.target.getAttribute("invoice"));
			}
			function addTimesheet(evt)
			{
				window.location = "newTimesheet.php";
			}
			function deleteTimesheet(evt)
			{
				if(confirm("Are you sure you want to discard all the data related to this timesheet?"))
				{
					var request = "<\?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
					request += "<REQUEST OBJECT=\"deleteTimesheet\">\n";
					request += "\t<REFID>" + evt.target.getAttribute("refid")+ "</REFID>\n";
					request += "</REQUEST>\n";
					ajaxSendXMLtoPHP("parseResponse.php",request,function(neimportant){window.location.reload(true);});
				}
			}
		</script>
	</head>
	<body>
		<div id="doc" class="yui-t1">
			<div id="hd">
				<h1>Time Recording System</h1>
			</div>
			<?require("mainMenu.php");?>
		<!--	<div id="infoSection">
			</div> -->
			<div id="bd">
				<div id="yui-main">
					<div id='content'>
						<div id="mainFormContainer">
							<table class="FormTable">
								<tr>
									<td class="mainFormText" colspan="3"><h4>What would you like to do?</h4></td>
								</tr>
								<tr>
									<td class="mainFormTextLink" colspan="3" onclick="addTimesheet()">Add a new time sheet</td>
								</tr>
								<tr>
									<td class="mainFormTextMenu" colspan="3">Edit previous saved time sheets</td>
								</tr>
								<?
								if($rowNr == 0)
								{
									echo "\t\t\t\t\t\t\t\t<tr>\n";
									echo "\t\t\t\t\t\t\t\t\t<td class=\"mainFormTextLabel\" colspan=\"3\">no saved items</td>\n";
									echo "\t\t\t\t\t\t\t\t</tr>\n";
								}
								else
								{
									for($i=0;$i<$rowNr;++$i)
									{
										$rowarray = pg_fetch_array($queryResult,null,PGSQL_ASSOC);
										$refid = $rowarray["refid"];
										$timeSheetWeek = date("d M",strtotime("-6 day",strtotime($rowarray["startdate"])))." - ".date("d M",strtotime($rowarray["startdate"]));
// 										$startdate = date("d/m/Y",strtotime($rowarray["startdate"]));
										$startTime = $rowarray["starttime"];
										$stopTime = $rowarray["stoptime"];
										$displayString = $timeSheetWeek." (".$startTime." - ".$stopTime.") ";
										echo "\t\t\t\t\t\t\t\t<tr>\n";
										echo "\t\t\t\t\t\t\t\t\t<td class=\"mainFormTextLabel\">".$displayString."</td>";
										echo "<td class=\"mainFormTextLink\" refid=\"".$refid."\" onclick=\"editTimesheet(event)\">edit</td>\n";
										echo "<td class=\"mainFormTextLink\" refid=\"".$refid."\" onclick=\"deleteTimesheet(event)\">discard</td>\n";
										echo "\t\t\t\t\t\t\t\t</tr>\n";
									}
								}
								?>
								
								<!-- project manager section -->
								
								<?
								$queryString = "SELECT * FROM tbl_invoice_code_lookup WHERE projectmanager = ".$_SESSION["refid".$privateKey]." AND completed = false ORDER BY department ASC ,invoicecode ASC";
								$queryResult = $dbconn->sendquery2($queryString);
								$rowNr = pg_num_rows($queryResult);
								if($rowNr != 0)
								{
								?>
								<tr>
									<td class="mainFormTextMenu" colspan="3">Your managed invoice code list</td>
								</tr>
								<?
									for($i=0;$i<$rowNr;++$i)
									{
										$rowarray = pg_fetch_array($queryResult,null,PGSQL_ASSOC);
										$invoiceCode = htmlspecialchars(stripslashes($rowarray["invoicecode"]));
										$projectName = htmlspecialchars(stripslashes($rowarray["projectname"]));
										$department = htmlspecialchars(stripslashes($rowarray["department"]));
										$displayString = "";
										if(strcmp($department,"")!=0)
											$displayString .= $department." : ";
										if(strcmp($projectName,"")!=0)
											$displayString .= ucfirst($projectName);
										$displayString .= " ( <span class=\"highlightGreen\">".$invoiceCode."</span> ) ";
										echo "\t\t\t\t\t\t\t\t<tr>\n";
										echo "\t\t\t\t\t\t\t\t\t<td colspan=\"2\" class=\"mainFormTextLabel\">".$displayString."</td>";
										echo "<td class=\"mainFormTextLink\" invoice=\"".$invoiceCode."\" onclick=\"manageInvoiceCode(event)\">manage</td>\n";
										echo "\t\t\t\t\t\t\t\t</tr>\n";
									}
								}
								?>
								
								<!-- section for line managers that chose to autorize their subordinates' timesheets-->
								
								<?
								if(strcmp($_SESSION["authorizes".$privateKey],"t")==0)
								{
// 									$queryString = "SELECT a.refid AS timesheetrefid,a.startdate,c.fname,c.lname FROM tbl_office_time_sheet AS a, tbl_office_time_sheet_transfer_status AS b,tbl_staff_lookup AS c WHERE a.staffrefid IN (SELECT refid FROM tbl_staff_lookup WHERE employed = true AND linemanager = ".$_SESSION["refid".$privateKey]." AND refid <> linemanager) AND a.submitted = true AND a.refid = b.refid AND b.authorized = false AND c.refid = a.staffrefid ORDER BY a.startdate ASC,c.fname ASC,c.lname ASC";
									$queryString = "SELECT a.refid AS timesheetrefid,a.startdate,c.fname,c.lname FROM tbl_office_time_sheet AS a,tbl_staff_lookup AS c WHERE a.staffrefid IN (SELECT refid FROM tbl_staff_lookup WHERE employed = true AND linemanager = ".$_SESSION["refid".$privateKey]." AND refid <> linemanager) AND a.submitted = true AND c.refid = a.staffrefid ORDER BY a.startdate DESC,c.fname ASC,c.lname ASC";
									$queryResult = $dbconn->sendquery2($queryString);
									$rowNr = pg_num_rows($queryResult);
									if($rowNr != 0)
									{
									
								?>
								 <tr>
									<td class="mainFormTextMenu" colspan="3">Authorize your subordinates' time sheets</td>
								</tr>
								<?
										$refidList = "";
										$timesheetArray = array();
										for($i=0;$i<$rowNr;++$i)
										{
											$rowarray = pg_fetch_array($queryResult,null,PGSQL_ASSOC);
											$timesheet = new Timesheet();
											$timesheet->refid = $rowarray["timesheetrefid"];
											$timesheet->startDate = strtotime($rowarray["startdate"]);
											$timesheet->firstName = $rowarray["fname"];
											$timesheet->lastName = $rowarray["lname"];
											array_push($timesheetArray,$timesheet);
											$refidList .= $rowarray["timesheetrefid"].",";
										}
										$refidList = substr($refidList,0,strlen($refidList)-1);
										foreach($timesheetArray as $timesheet)
										{
											$displayString = date("d/m/Y",$timesheet->startDate)." - ".htmlspecialchars(stripslashes($timesheet->firstName))."  ".htmlspecialchars(stripslashes($timesheet->lastName));
											echo "\t\t\t\t\t\t\t\t<tr>\n";
											echo "\t\t\t\t\t\t\t\t\t<td colspan=\"2\" class=\"mainFormTextLabel\">".$displayString."</td>";
											echo "<td class=\"mainFormTextLink\" refid=\"".$timesheet->refid."\" onclick=\"viewTimesheet(event)\">view</td>\n";
											echo "\t\t\t\t\t\t\t\t</tr>\n";
										}
									}
								}
								?>
								
								<!-- section for project managers that chose to autorize their workers' timesheets-->

								<?
								if(isset($refidList))
									$queryString = "SELECT a.refid AS timesheetrefid,c.fname,c.lname,a.startdate,b.refid AS invoicerefid,b.invoicecoderefid,b.taskcoderefid FROM tbl_office_time_sheet AS a, tbl_office_time_sheet_entry AS b, tbl_staff_lookup AS c, tbl_office_time_sheet_transfer_status AS d WHERE a.refid NOT IN (".$refidList.") AND a.staffrefid <> ".$_SESSION["refid".$privateKey]." AND d.refid = a.refid AND d.authorized = false AND c.refid = a.staffrefid AND a.refid = b.officetimesheetrefid AND a.submitted = true AND b.authorized = false AND b.invoicecoderefid IN (SELECT invoicecode FROM tbl_invoice_code_lookup WHERE requiresauthorization = true AND projectmanager = ".$_SESSION["refid".$privateKey]." ) ORDER BY a.startdate DESC,c.fname ASC,c.lname ASC";
								else
									$queryString = "SELECT a.refid AS timesheetrefid,c.fname,c.lname,a.startdate,b.refid AS invoicerefid,b.invoicecoderefid,b.taskcoderefid FROM tbl_office_time_sheet AS a, tbl_office_time_sheet_entry AS b, tbl_staff_lookup AS c, tbl_office_time_sheet_transfer_status AS d WHERE a.staffrefid <> ".$_SESSION["refid".$privateKey]." AND d.refid = a.refid AND d.authorized = false AND c.refid = a.staffrefid AND a.refid = b.officetimesheetrefid AND a.submitted = true AND b.authorized = false AND b.invoicecoderefid IN (SELECT invoicecode FROM tbl_invoice_code_lookup WHERE requiresauthorization = true AND projectmanager = ".$_SESSION["refid".$privateKey]." ) ORDER BY a.startdate DESC,c.fname ASC,c.lname ASC";
								$queryResult = $dbconn->sendquery2($queryString);
								$rowNr = pg_num_rows($queryResult);
								if($rowNr != 0)
								{
								?>
								 <tr>
									<td class="mainFormTextMenu" colspan="3">Authorize time sheets</td>
								</tr>
								<?
								    $timesheetArray = array();
									$timesheet = null;
									$currentRefid = -1;
									for($i=0;$i<$rowNr;++$i)
									{
										$rowarray = pg_fetch_array($queryResult,null,PGSQL_ASSOC);
										if($currentRefid != intval($rowarray["timesheetrefid"]))
										{
											$currentRefid = intval($rowarray["timesheetrefid"]);
											if($timesheet != null)
												array_push($timesheetArray,$timesheet);
											$timesheet = new Timesheet();
											$timesheet->refid = $rowarray["timesheetrefid"];
											$timesheet->startDate = strtotime($rowarray["startdate"]);
											$timesheet->firstName = $rowarray["fname"];
											$timesheet->lastName = $rowarray["lname"];
										}
										$entry = new Entry();
										$entry->refid = intval($rowarray["invoicerefid"]);
										$entry->invoiceCode = $rowarray["invoicecoderefid"];
										$entry->taskCode = $rowarray["taskcoderefid"];
										array_push($timesheet->entries,$entry);	
									}
									array_push($timesheetArray,$timesheet);
									foreach($timesheetArray as $timesheet)
									{
										$displayString = date("d/m/Y",$timesheet->startDate)." - ".htmlspecialchars(stripslashes($timesheet->firstName))."  ".htmlspecialchars(stripslashes($timesheet->lastName));
										echo "\t\t\t\t\t\t\t\t<tr>\n";
										echo "\t\t\t\t\t\t\t\t\t<td colspan=\"2\" class=\"mainFormTextLabel\">".$displayString."</td>";
										echo "<td class=\"mainFormTextLink\" refid=\"".$timesheet->refid."\" onclick=\"viewTimesheet(event)\">view</td>\n";
										echo "\t\t\t\t\t\t\t\t</tr>\n";
										foreach($timesheet->entries as $entry)
										{
											$displayString2 = htmlspecialchars(stripslashes($entry->invoiceCode))." - ".htmlspecialchars(stripslashes($entry->taskCode));
											echo "\t\t\t\t\t\t\t\t<tr>\n";
											echo "\t\t\t\t\t\t\t\t\t<td colspan=\"3\" class=\"mainFormTextLabelIndent\">".$displayString2."</td>";
											echo "\t\t\t\t\t\t\t\t</tr>\n";
										}
									}
								}
								?>
								
								
								<tr>
									<td class="mainFormText" colspan="3">&nbsp;</td>
								</tr>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
		<?require("footer.php");?>
	</body>
</html>
Return current item: Time Recording System