<?php 
require 'dao/Profile.php';

if (isset($_POST['email'])) {
	$email = $_POST['email'];
	$data = array("email"=>$email);
	$success = $profile->update($data,$_SESSION['staff_id']);
}
if (isset($_POST['first_name'])) {
	$first_name = $_POST['first_name'];
	$data = array("first_name"=>$first_name);
	$success = $profile->update($data,$_SESSION['staff_id']);
}

if (isset($_POST['sex'])) {
	$sex = $_POST['sex'];
	if ($sex==1) {
		$sex="Male";
	}else if ($sex==2) {
		$sex="Female";
	}
	$data = array("sex"=>$sex);
	$success = $profile->update($data,$_SESSION['staff_id']);
}

if (isset($_POST['first_name'])) {
	$first_name = $_POST['first_name'];
	$data = array("first_name"=>$first_name);
	$success = $profile->update($data,$_SESSION['staff_id']);
}
if (isset($_GET['dob'])) {
	$dob = $_GET['dob'];
	$data = array("dob"=>$dob);
	$success = $profile->update($data,$_SESSION['staff_id']);
	echo $dob;
}
if (isset($_POST['phone'])) {
	$phone = $_POST['phone'];
	for ($i=0; $i < sizeof($phone) ; $i++) { 
		if ($i==sizeof($phone)-1) {
			$single2 = $phone['phone3'];
		}else{
			$single = $phone['phone1'].','.$phone['phone2'].',';
		}
		
	}
	$data = array("phone"=>$single.$single2);
	$success = $profile->update($data,$_SESSION['staff_id']);
	
}
if (isset($_POST['last_name'])) {
	$last_name = $_POST['last_name'];
	$data = array("last_name"=>$last_name);
	$success = $profile->update($data,$_SESSION['staff_id']);
}

//if (isset($_GET['pic'])) {
	if (isset($_FILES['pic'])) {
		$generated_name_1 = '';
		  $ext_1 = explode('.', basename($_FILES["pic"]["name"])); //explode file name from dot(.) 
                $file_extension_1 = end($ext_1); //store extensions in the variable
                $generated_name_1 .= md5(uniqid()) . "." . $ext_1[count($ext_1) - 1];
                move_uploaded_file($_FILES["pic"]["tmp_name"], "../userImage/".$generated_name_1);
                $data = array("picture"=>$generated_name_1);
                $profile->update($data,$_SESSION['staff_id']);
	}
//}

$get_staff_detail = "";
$get_staff_detail = $profile->get_staff_detail($_SESSION['staff_id']);

 ?>