<!--chtml include "//students/incs/sg_breadcrumb.inc"-->
<!--chtml call crumbs(sg_finaid)-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

	<head>
		<title>Off Campus Work Study Jobs - Maintenence</title>
		<link rel="stylesheet" href="/home/home.css" type="text/css">
		<link rel="stylesheet" href="../css/table.css" type="text/css">
		<script src="sorttable.js" type="text/javascript"></script>
	</head>
	<body>
	<!--chtml include "//home/incs/stuheader.inc"-->
		<div id="table">
<?php
$db_host = 'ovid01.u.washington.edu:3798';
$db_user = root;
$db_pwd = '03798';
$database = 'workstudy';
$table = 'offCampus';

if (!($GLOBALS["___mysqli_ston"] = mysqli_connect($db_host,  $db_user,  $db_pwd)))
    die("Can't connect to database");

if (!((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $database)))
    die("Can't select database");
   
if(isset($_GET['delete'])) {
	$current = trim($_GET['id']);
	removeRow($current, $table);
}

$emailResult = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT emailAddress FROM $table");
if (!$emailResult) {
    die("Query to show fields from table failed");
}

while($row = mysqli_fetch_row($emailResult)){
		if($row[0]){
			$emails = $emails ."$row[0], ";
		}
}

$result = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id, jobNumber, jobTitle, orgName, ein, contactFName, contactLName, timeStamp, status FROM {$table} ORDER BY id");

if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = (($___mysqli_tmp = mysqli_num_fields($result)) ? $___mysqli_tmp : false);
echo "<h2>Off Campus</h2>";
echo "<a href='mailto:$emails'>Email All</a></br></br>";
echo "<table class='sortable'>";
	echo "<thead>";
	echo "<tr>";
		echo "<th id='id'>ID</th>";
		echo "<th id='number'>Job Number</td>";
		echo "<th>Job Title</th>";
		echo "<th>Company</th>";
		echo "<th>EIN</th>";
		echo "<th>Contact Name</th>";
		echo "<th id='modify'>Last Modified</th>";
		echo "<th id='status'>Status</th>";
		echo "<th class='sorttable_nosort' id='update'>Update</th>";
		echo "<th class='sorttable_nosort' id='delete'>Delete</th>";
		echo "<th class='sorttable_nosort' id='view'>View Report</th>";
		echo "</tr>\n";
	echo "</thead>";
	echo "<tbody>";
	while($row = mysqli_fetch_row($result)){
		echo "<tr>";
		foreach($row as $cell){
			if($cell == $row[5]){
				echo"<td>$cell ";
			}else if($cell == $row[6]){
				echo"$cell</td>";
			}else{
				echo "<td>$cell</td>";
			}
		}

		echo "<td><form name='updateForm' action='off_update.php' method='get'>";
		echo "<input type='hidden' name='id' value='$row[0]'/>";
		echo "<input type='submit' name='update' value='Update'/>";
		echo "</form></td>";
		echo "<td><form name='deleteForm' action='off.php' method='get'>";
		echo "<input type='hidden' name='id' value='$row[0]'/>";
		echo "<input type='submit' name='delete' value='Delete'/>";
		echo "</form></td>";
		echo "<td><form name='viewReport' action='../report.php' method='get'>";
		echo "<input type='hidden' name='id' value='$row[0]'/>";
		echo "<input type='hidden' name='table' value='offCampus'/>";
		echo "<input type='submit' name='viewReport' value='View Report'/>";
		echo "</form></td>";


		echo "</tr>\n";
	}
echo "</tbody>";
echo "</table>";

((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);

function removeRow($current, $table){
	$sql = "DELETE FROM $table where Id = $current";
	$con = ($GLOBALS["___mysqli_ston"] = mysqli_connect("ovid01.u.washington.edu", "root", "03798", NULL, 3798));
	if (!mysqli_query($con, $sql)) {
		die('Error: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
	}
	echo("Removed row " . $current);
}

?>
		</div>
	
<!-- MAIN PAGE CONTENT -->				

<!-- From FOOTER.INC -->

			</div>
		</div>
	</div>	
	<div id="contentFooter"></div>


<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." 
: "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + 
"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-11922437-1");
pageTracker._trackPageview();
} catch(err) {}</script>


<a href= "#top"> Return to Top of Page</a><br>


<!--chtml include "//home/incs/footer.inc"-->
</BODY>
</HTML>
