<html>
<head>
<title>Persona Homes Project Management System</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="style.css">
<script language="JavaScript" type="text/javascript" src="../js/print.js"></script>
</head>
<body>
<!-- #include file="includes/top.asp" -->
<table align="center" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td height="400" bgcolor="#FFFFFF" valign="top"><table border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td width="10"></td>
				<td><div id="areaToPrint"><table border="0" cellpadding="0" cellspacing="0">
<%            
On Error Resume Next
Response.Expires = 0
Dim objConn, objRS, strQuery
Dim strConnection
Dim tID

if Session("Admin") <> -1 then
	Response.Write "<tr><td width=""780"" height=""80""></td></tr>"
  	Response.Write "<tr><td width=""780"" height=""25"" align=""center"" class=""h2"">You are not authorized to view this page.</td></tr>"
    Response.Write "<tr><td width=""780"" height=""20""></td></tr>"
    Response.Write "<tr><td width=""780"" height=""25"" align=""center""><input TYPE=""button"" NAME=""Login"" value=""Login"" class=""submit"" ONCLICK=""JavaScript:window.open('index.asp', target='_self');""></td></tr>"
else
%>
    				<tr>
      					<td width="780" height="25" align="center" class="head">Hi <%= Session("Login") %>!</td>
					</tr>
    				<tr>
                    	<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
                        	<tr height="25">
                            	<td class="h2"><%= Day(Date) & "/" & Month(Date) & "/" & Year(Date) & " " & Time%></td>
                                <td align="right"><table border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td height="25"><a href="javascript:printPage('areaToPrint');" class="h2">Print</a></td>
                                        <td width="20" height="25"></td>
                                        <td height="25"><a href="home.asp" class="h2">Back to Home</a></td>
                                        <td width="20" height="25"></td>
                                        <td height="25"><a href="logout.asp" class="h2">Logout</a></td>
                                    </tr>
                                </table></td>
                            </tr>
                        </table></td>
					</tr>
    				<tr>
      					<td width="780" height="10"></td>
					</tr>
    				<tr>
      					<td width="780" height="25" align="center" class="h1">Time Report</td>
					</tr>
    				<tr>
      					<td width="780" height="10"></td>
					</tr>
<%					
    Set objConn = Server.CreateObject("ADODB.Connection")
    strConnection = "DSN=personahomes;Database=WebDB.mdb;"
  
    objConn.Open strConnection
	
	tID = Request.Form("ID")
	
	strQuery = "SELECT DISTINCT UserID FROM ProjectTime WHERE ProjectID = " & tID
    Set objRS = objConn.Execute(strQuery)

    if objRS.EOF then
  	  Response.Write "<tr><td width=""780"" height=""25"" align=""center"" class=""h2"">There is currently no time recorded for this project.</td></tr>"
	else

		PstrQuery = "SELECT * FROM Project WHERE ID = " & tID
		Set PobjRS = objConn.Execute(PstrQuery)
%>
    				<tr>
      					<td align="center"><table border="0" cellpadding="0" cellspacing="0">
                            <tr height="30">
								<td align="right" class="p">Project:</td>
                                <td width="10"></td>
								<td class="p"><%= tID & " - " & PobjRS("FirstName") & " " & PobjRS("LastName") %></td>
							</tr>
                        </table></td>
                    </tr>
			<tr>
				<td align="center"><table border="2" bordercolor="CCCCCC" cellpadding="0" cellspacing="0">
			   		<tr height="25">
						<td width="180" class="h2">Name</td>
						<td width="60" class="h2">Minutes</td>
						<td width="60" class="h2">Rate</td>
						<td width="80" class="h2">Cost</td>
      				</tr>
<%
		tTotalTime = 0
		tTotalCost = 0
		
        Do While not objRS.EOF

			UstrQuery = "SELECT * FROM Admin WHERE ID = " & objRS("UserID")
			Set UobjRS = objConn.Execute(UstrQuery)
	
			PTstrQuery = "SELECT SUM(TaskTime) AS TotalTime, SUM(Amount) AS TotalAmount FROM ProjectTime WHERE ProjectID = " & tID & " AND UserID = " & objRS("UserID")
			Set PTobjRS = objConn.Execute(PTstrQuery)
			
					Response.Write "<tr height=""25"">"
					Response.Write "<td><a href=""reportProjectTimeUser.asp?pid=" & tID & "&uid=" & objRS("UserID") & """ target=""_blank"" class=""p"">" & UobjRS("FirstName") & " " & UobjRS("LastName") & "</a></td>"
					Response.Write "<td align=""right"" class=""p"">" & PTobjRS("TotalTime") & "</td>"
					Response.Write "<td align=""right"" class=""p"">" & FormatCurrency(UobjRS("Rate"),2) & "</td>"
					Response.Write "<td align=""right"" class=""p"">" & FormatCurrency(PTobjRS("TotalAmount"),2) & "</td>"
					Response.Write "</tr>"
					
					tTotalTime = tTotalTime + PTobjRS("TotalTime")
					tTotalCost = tTotalCost + PTobjRS("TotalAmount")
				
          	objRS.MoveNext
        Loop
		
		tHour = Int(tTotalTime/60)
		tMin = tTotalTime mod 60
		
		tTTime = ""
		
		if tHour > 0 then
			tTTime = tTTime & tHour & "h"
		end if
		
		if tMin > 0 then
			tTTime = tTTime & tMin & "m"
		end if
%>
				</table></td>
            </tr>
            <tr>
            	<td height="20"></td>
            </tr>
            <tr>
            	<td height="20" align="center" class="p4">Total Time: <%= tTTime %></td>
            </tr>
            <tr>
            	<td height="20" align="center" class="p4">Total Cost: <%= FormatCurrency(tTotalCost,2) %></td>
            </tr>
<%
    end if
%>
            <tr>
            	<td height="20"></td>
            </tr>
            <tr>
            	<td align="center"><input type="button" name="close" value="Close" class="submit" onClick="javascript:window.close()" /></td>
            </tr>
<%	
	objRS.close
    objConn.close
    Set objRS = Nothing
    Set objConn = Nothing
end if  
%>
				</table></div></td>
				<td width="10"></td>
			</tr>
		</table></td>
	</tr>
<!-- #include file="includes/bottom.asp" -->
</table>
</body>
</html>