<?php require_once('../Connections/conn_ama.php'); 
	include("../../../../../../functions/functions.php");    
	    
	if (!isset($_SESSION)) {
	  session_start();
	}

	//$curr_season = $_SESSION['curr_season'];
	//$curr_season = '2019/2020';	
	
//echo $_POST["MM_insert"];

if ((isset($_POST['MM_update'])) && ($_POST['MM_update'] == "update-dept-officer")) {
	
	
	define('MAX_FILE_SIZE',10121200);
		// if(array_key_exists('add_new_team', $_POST))
		// {	
		
			//$newseason = trim(str_replace("/", "-", $curr_season), "'");

			define('UPLOAD_DIR', '../deptofficers/');
			
			$file = trim(str_replace(" ","_",$_FILES['image']['name']));
			
			$kilobytes = MAX_FILE_SIZE/1024;
			$formatted = number_format($kilobytes, 1);
			$max = $formatted."KB";
			$permitted = array('image/gif','image/jpeg','image/pjpeg','image/png','image/tiff');
			$sizeok = false;
			$typeok = false;
			if($_FILES['image']['size'] > 0 && $_FILES['image']['size'] <= MAX_FILE_SIZE)
				{
					$sizeok = true;
				}
				foreach($permitted as $type){
					if($type==$_FILES['image']['type'])
					{
						$typeok = true;
						break;
					}
				 }
			if($sizeok && $typeok)
			{
			  switch($_FILES['image']['error']){
			   case 0:
				 include('update_officer_image.inc.php');
				 break;
				 case 3:
				 $result = "Error uploading $file. Please try again";
				 default:
				 $result = "System error uploading $file. Please contact webmaster";
				}
			}
			elseif($_FILES['image']['error']==4)
			{
			  //$result = "No image selected";	

			  		$insertSQL = sprintf("UPDATE deptofficers SET fname=%s, mname=%s, lname=%s, title=%s, position=%s, officerrank=%s WHERE officerID = %s",
	            
			  				GetSQLValueString($_POST['fname'], "text"),
							GetSQLValueString($_POST['mname'], "text"),
							GetSQLValueString($_POST['lname'], "text"),
							GetSQLValueString($_POST['title'], "text"),
							GetSQLValueString($_POST['position'], "text"),
							GetSQLValueString($_POST['officerrank'], "int"),
							GetSQLValueString($_POST['MM_officerID'], "int"));

				  $Result1 = mysqli_query($conn_ama, $insertSQL) or die(mysqli_error($conn_ama));
				  //$lawyerID = mysqli_insert_id($conn_ama);
				 
	  				if($Result1){

						$result = "datasent";
						echo $result;
	  				}

			}
			else{ $result = "$file cannot be uploaded. Maximum size: $max. Acceptable file type:
			gif, jpeg, png, tiff";}
		//}
		//if(isset($result)){ echo $result;}
		

}
?>