<!--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>On 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 = 'uwfinaid.ovid.u.washington.edu:3798';
		$db_user = 'root';
		$db_pwd = '03798';
		$database = 'workstudy';
		$table = 'onCampus';
	
		$con = ($GLOBALS["___mysqli_ston"] = mysqli_connect($db_host,  $db_user,  $db_pwd));
		
		if (!$con)
			die("Can't connect to database");
			
		((bool)mysqli_query( $con, "USE " . $database));
		
		$current = trim($_GET['id']);
		
		if(isset($_GET['status'])) {
			$currentStatus = $_GET['status'];
			if($currentStatus == 'Open'){
				$currentStatus = 'Closed';
			}
			else{
				$currentStatus = 'Open';
			}
			$sql = "UPDATE onCampus SET status = '$currentStatus' 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)));
			}
		}
		
		if(isset($_POST['update']) || isset($_POST['email'])) {
			echo '<div id="update">
					<p>Row ' . $current . ' updated</p> 
				</div>';
	
			$jobType = sanitizeMySQL($_POST["jobType"]);
			$jobTitle = sanitizeMySQL($_POST["jobTitle"]);
			$orgName = sanitizeMySQL($_POST["orgName"]);
			$location = sanitizeMySQL($_POST["location"]);
			$website = sanitizeMySQL($_POST["website"]);
			$min = sanitizeMySQL($_POST['min']);
			$max = sanitizeMySQL($_POST['max']);
			$employmentPeriod = $_POST["employmentPeriod"];
			$hoursPerWeek = $_POST['hoursPerWeek'];
			$status = sanitizeMySQL($_POST['status']);
			$contactFName = sanitizeMySQL($_POST['contactFName']);
			$contactLName = sanitizeMySQL($_POST['contactLName']);
			$phoneNumber = $_POST['phoneNumber'];
			$emailAddress = sanitizeMySQL($_POST['emailAddress']);
			$boxNumber = sanitizeMySQL($_POST['boxNumber']);
			$nature = sanitizeMySQL($_POST['nature']);
			$duties = sanitizeMySQL($_POST['duties']);
			$qualifications = sanitizeMySQL($_POST['qualifications']);
			$benefits = sanitizeMySQL($_POST['benefits']);
			$apply = sanitizeMySQL($_POST['apply']);
			$jobNumber = sanitizeMySQL($_POST['jobNumber']);
			$category = sanitizeMySQL($_POST['category']);
			$jobClass = sanitizeMySQL($_POST['jobClass']);
			$program = sanitizeMySQL($_POST['program']);
			$classified = sanitizeMySQL($_POST['classified']);
			$date = date('l F dS Y h:i:s A');
	
			if (!($employmentPeriod == '' || $hoursPerWeek == '')) {
				$periodString = sanitizeMySQL(implode(', ', $employmentPeriod));
				$hoursString = sanitizeMySQL(implode(', ', $hoursPerWeek));
			}else{
				$periodString = $employmentPeriod;
				$hoursString = $hoursPerWeek;
			}
					
			$sql="UPDATE onCampus
				SET jobTitle = '$jobTitle', orgName = '$orgName', location = '$location', website = '$website', min = '$min', 
				max = '$max', employmentPeriod = '$periodString', hoursPerWeek = '$hoursString', status = '$status', contactFName = '$contactFName', 
				phoneNumber = '$phoneNumber', emailAddress = '$emailAddress', nature = '$nature', jobClass = '$jobClass', boxNumber = '$boxNumber',
				duties = '$duties', qualifications = '$qualifications', benefits = '$benefits', apply = '$apply', 
				jobNumber = '$jobNumber', category = '$category', program = '$program', classified = '$classified'
				WHERE ID = '$current'";
	
			if(isset($_POST['email'])){	
				$to = $emailAddress;
				$subject = '[WS Job] ' . $jobTitle . ' job description';
				$message = 
				$date . "\n
			Thank you for submitting your job description for $jobTitle.  
			The position description has been approved and will be posted on our website.  
			Please notify our office when the position has been filled so we can remove it from our listing.  
			You can view your listing at:  
				
			http://finaid.uw.edu/ugaid/uw.workstudy.positions.html
				
			Job title:  $jobTitle
			Job number:  $jobNumber
			Job class code: $jobClass
			Status:  $status
			Program:  $program
				
			For additional information about the Work Study hiring and payment process please review our web pages.
			http://www.washington.edu/students/osfa/ugaid/employer.info.html";
								
				$from = "uwfinaid";
				$headers = "From:" . $from;
				mail($to,$subject,$message,$headers);
				echo "Email sent to employer from $from to $emailAddress.";
			}
				
			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)));
			}
			
		}
		
		function sanitizeMySQL($var){
			$var = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $var) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
			$var = sanitizeString($var);
			return $var;
		}
	
		function sanitizeString($var)
		{
			$var = htmlentities($var);
			$var = strip_tags($var);
			return $var;
		}
   
if(isset($_GET['delete'])) {
	$current = trim($_GET['id']);
	removeRow($current, $table);
}

/*if(isset($_GET['allOpen'])) {
	$sql = "UPDATE onCampus SET status = 'Open";
	$con = mysql_connect("ovid01.u.washington.edu:3798","root","03798");
	if (!mysql_query($sql,$con)) {
		die('Error: ' . mysql_error());
	}
else if(isset($_GET['allClose'])) {
	$sql = "UPDATE onCampus SET status = 'Open";
	$con = mysql_connect("ovid01.u.washington.edu:3798","root","03798");
	if (!mysql_query($sql,$con)){
		die('Error: ' . mysql_error());
	}
}*/

function sendmail($cat, $user)
{ 
    require_once "Mail.php"; 
    $elist = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT emailAddress FROM $table"); 

    $from = "EMAIL ADDRESS"; 
    $subject = "SUBJECT"; 
    $body = "BODY"; 

    $host = "smtp.domain.com"; 
    $username = "USERNAME"; 
    $password = "PASSWORD"; 

        if(mysqli_num_rows($elist) > 0)
        {
            while($elist_result = mysqli_fetch_array($elist))
            {
            $headers = array ('From' => $from, 
            'To' => $elist_result['emailAddress'], 
            'Subject' => $subject); 
            $smtp = Mail::factory('smtp', 
            array ('host' => $host, 
            'auth' => true, 
            'username' => $username, 
            'password' => $password)); 

            $mail = $smtp->send($to, $headers, $body); 
            }
        }
 } 


/*$emailResult = mysql_query("SELECT emailAddress FROM $table");
if (!$emailResult) {
    die("Query to show fields from table failed");
}

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

$result = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id, jobNumber, jobTitle, orgName, 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>On 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</th>";
		echo "<th>Job Title</th>";
		echo "<th>Department</th>";
		echo "<th>Contact Name</th>";
		echo "<th id='modify'>Last Modified</a>";
		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>";
		$changed = false;
		foreach($row as $cell){
			if($cell == $row[4] && $cell == $row[5]){
				if($changed == false){
					echo "<td>$cell $cell</td>";
					$changed = true;
				}
			}
			else if($cell == $row[4]){
				echo"<td>$cell ";
			}
			else if($cell == $row[5]){
				echo"$cell</td>";
			}
			else if($cell == $row[7]){
				echo "<td><form name='statusForm' action='' method='get'>";
				echo "<input type='hidden' name='id' value='$row[0]'/>";
				echo "<input type='submit' name='status' value='$cell'/>";
				echo "</form></td>";
			}
			else{
				echo "<td>$cell</td>";
			}
		}		
		
		
		echo "<td><form name='updateForm' action='on_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='on.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='viewRerport' action='../report.php' method='get'>";
		echo "<input type='hidden' name='id' value='$row[0]'/>";
		echo "<input type='hidden' name='table' value='onCampus'/>";
		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>
