<?php

include 'load.php';

if(isset($_GET['apid'])){
	$apid=mysqli_real_escape_string($conn,$_GET['apid']);
	$view_qury=mysqli_query($conn,"SELECT * FROM mobileappointment WHERE apid='$apid'");
	$view_result=mysqli_fetch_array($view_qury);
}

else{
	echo "<script>window.location='appointmentlist.php';</script>";
}


	if(isset($_POST['update'])){

			$appno = $_POST['appno'];
			$patient = $_POST['patient'];
			$appdate = $_POST['appdate'];
			$apptime = $_POST['apptime'];
			$species = $_POST['species'];
			$breed = $_POST['breed'];
			$services = $_POST['services'];
			$doctor = $_POST['doctor'];
			$typeofpets = $_POST['typeofpets'];
			$message = $_POST['message'];
			$status = $_POST['status'];

			if(!isset($errMSG)){
			
			$stmt = $DB_con->prepare('UPDATE mobileappointment
			SET appno=:appno,
			patient=:patient,
			appdate=:appdate,
			apptime=:apptime,
			species=:species,
			breed=:breed,
			services=:services,
			doctor=:doctor,
			typeofpets=:typeofpets,
			message=:message,
			status=:status
			WHERE apid=:apid');
			$stmt->bindParam(':appno',$appno);
			$stmt->bindParam(':patient',$patient);
			$stmt->bindParam(':appdate',$appdate);
			$stmt->bindParam(':apptime',$apptime);
			$stmt->bindParam(':species',$species);
			$stmt->bindParam(':breed',$breed);
			$stmt->bindParam(':services',$services);
			$stmt->bindParam(':doctor',$doctor);
			$stmt->bindParam(':typeofpets',$typeofpets);
			$stmt->bindParam(':message',$message);
			$stmt->bindParam(':status',$status);
			$stmt->bindParam(':apid',$apid);
			
			if($stmt->execute()){
		  
			$successMSG = "Appointment Successfully Updated ...";
				
			header("refresh:2;appointmentlist.php"); // redirects imdoctor view pdoctor after 5 seconds.
				
			}else{
				
			$errMSG = "Sorry Data Could Not Updated !";
				
			}
		
    }

}
	
?>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
<meta name="description" content="POS - Payroll | Pos & Invetory System | Dashboard

">
<meta name="keywords" content="Payroll | Pos & Invetory System | Dashboard

">
<meta name="author" content="Payroll | Pos & Invetory System | Dashboard

">
<meta name="robots" content="noindex, nofollow">

<title>Edit Appointment | Payroll | Pos & Invetory System | Dashboard

</title>


<?php
require_once 'headercss.php';
?>
</head>
<body>
<div id="global-loader">
<div class="whirly-loader"> </div>
</div>

<div class="main-wrapper">
<?php
require_once 'header.php';
?>

<?php
require_once 'navbar.php';
?>

<div class="page-wrapper">
<div class="content">
<div class="page-header">
<div class="page-title">
<h4>Edit Appointment</h4>
<h6>Update your Appointment</h6>
</div>
</div>

<div class="card">
<div class="card-body">
<form method="POST" enctype="multipart/form-data">
									<?php

									if(isset($errMSG)){

									?>
									
									<div class="alert alert-danger border-0 bg-danger alert-dismissible fade show py-2">
									<div class="d-flex align-items-center">
										<div class="font-35 text-white"><i class="bx bxs-message-square-x"></i>
										</div>
										<div class="ms-3">
											<h6 class="mb-0 text-white">Error Alerts</h6>
											<div class="text-white"> <?php echo $errMSG; ?>!</div>
										</div>
									</div>
									<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
									</div>
									
									<?php

									}
	
									else if(isset($successMSG)){

									?>
									
									<div class="alert alert-success border-0 bg-success alert-dismissible fade show py-2">
									<div class="d-flex align-items-center">
										<div class="font-35 text-white"><i class="bx bxs-check-circle"></i>
										</div>
										<div class="ms-3">
											<h6 class="mb-0 text-white">Success Alerts</h6>
											<div class="text-white"><?php echo $successMSG; ?>!</div>
										</div>
									</div>
									<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
									</div>
									
									<?php

									}

									?>	
<div class="row">
<div class="col-lg-4 col-sm-6 col-12">
<div class="form-group">
<label>Appointment Number</label>
<input type="text" name="appno" class="form-control" value="<?php echo $view_result['appno']; ?>" placeholder="Enter Appointment Number" readonly>
</div>
</div>
<div class="col-lg-8 col-sm-6 col-12">
<div class="form-group">
<label>Patient</label>
<select name="patient" class="select" id="inputpatient">
<option value="<?php

												$id = $view_result['patient']; 

												$query = $DB_con->prepare('SELECT paid FROM mobilepatient WHERE paid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['paid'];

												?>"><?php

												$id = $view_result['patient'];  

												$query = $DB_con->prepare('SELECT ptno,ptname,phonenumber,address FROM mobilepatient WHERE paid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['ptno']."-". $result['ptname']."-". $result['phonenumber']."-". $result['address'];

												?>
										</option>
<?php

$stmt = $DB_con->prepare('SELECT * FROM mobilepatient where status="1" ORDER BY paid');

$stmt->execute();

if($stmt->rowCount() > 0)

{

while($row=$stmt->fetch(PDO::FETCH_ASSOC))

{

extract($row);

?>
<option value="<?php echo $row['paid']; ?>"><?php echo $row['ptno']; ?>-<?php echo $row['ptname']; ?>-<?php echo $row['phonenumber']; ?>-<?php echo $row['address']; ?></option>
<?php 
} 
}
?>
</select>
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="form-group">
<label>Appointment Date</label>
<input type="date" name="appdate" class="form-control" id="inputappointmentdate" value="<?php echo $view_result['appdate']; ?>" placeholder="Select Appointment Date">
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="form-group">
<label>Appointment Time</label>
<input type="time" name="apptime" class="form-control" id="inputapptime" value="<?php echo $view_result['apptime']; ?>" placeholder="Select Appointment Time">
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="form-group">
<label>Species</label>
<select name="species" class="form-control select" id="inputspecies">
<option value="<?php

												$id = $view_result['species']; 

												$query = $DB_con->prepare('SELECT spid FROM mobilespecies WHERE spid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['spid'];

												?>"><?php

												$id = $view_result['species'];  

												$query = $DB_con->prepare('SELECT spname FROM mobilespecies WHERE spid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['spname'];

												?>
										</option>
<?php

$stmt = $DB_con->prepare('SELECT * FROM mobilespecies ORDER BY spid');

$stmt->execute();

if($stmt->rowCount() > 0)

{

while($row=$stmt->fetch(PDO::FETCH_ASSOC))

{

extract($row);

?>
<option value="<?php echo $row['spid']; ?>"><?php echo $row['spname']; ?></option>
<?php 
} 
}
?>
</select>
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="form-group">
<label>Breed</label>
<select name="breed" class="select" id="inputspecies">
<option value="<?php

												$id = $view_result['breed']; 

												$query = $DB_con->prepare('SELECT brid FROM mobilebreed WHERE brid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['brid'];

												?>"><?php

												$id = $view_result['breed'];  

												$query = $DB_con->prepare('SELECT brname FROM mobilebreed WHERE brid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['brname'];

												?>
										</option>
<?php

$stmt = $DB_con->prepare('SELECT * FROM mobilebreed ORDER BY brid');

$stmt->execute();

if($stmt->rowCount() > 0)

{

while($row=$stmt->fetch(PDO::FETCH_ASSOC))

{

extract($row);

?>
<option value="<?php echo $row['brid']; ?>"><?php echo $row['brname']; ?></option>
<?php 
} 
}
?>
</select>
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="form-group">
<label>Services</label>
<select name="services" class="select" id="inputservices">
<option value="<?php

												$id = $view_result['services']; 

												$query = $DB_con->prepare('SELECT seid FROM mobileservices WHERE seid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['seid'];

												?>"><?php

												$id = $view_result['services'];  

												$query = $DB_con->prepare('SELECT sname FROM mobileservices WHERE seid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['sname'];

												?>
										</option>
<?php

$stmt = $DB_con->prepare('SELECT * FROM mobileservices ORDER BY seid');

$stmt->execute();

if($stmt->rowCount() > 0)

{

while($row=$stmt->fetch(PDO::FETCH_ASSOC))

{

extract($row);

?>
<option value="<?php echo $row['seid']; ?>"><?php echo $row['sname']; ?></option>
<?php 
} 
}
?>
</select>
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="form-group">
<label>Doctor</label>
<select name="doctor" class="select" id="inputdoctor">
<option value="<?php

												$id4 = $view_result['doctor']; 

												$query4 = $DB_con->prepare('SELECT doid FROM mobiledoctors WHERE doid='.$id4);

												$query4->execute();

												$result4 = $query->fetch();

												echo $result4['doid'];

												?>"><?php

												$id4 = $view_result['doctor'];  

												$query4 = $DB_con->prepare('SELECT doname,position FROM mobiledoctors WHERE doid='.$id4);

												$query4->execute();

												$result4 = $query->fetch();

												echo $result4['doname'];

												?> - 
												<?php

											  $id2 = $result['position'];

											  $query2 = $DB_con->prepare('SELECT poid,pname FROM mobileposition WHERE poid='.$id2);

											  $query2->execute();

											  $result2 = $query2->fetch();

											  echo $result2['pname'];

											  ?>
										</option>
<?php

$stmt1 = $DB_con->prepare('SELECT * FROM mobiledoctors where status="1" ORDER BY doid');

$stmt1->execute();

if($stmt1->rowCount() > 0)

{

while($row1=$stmt1->fetch(PDO::FETCH_ASSOC))

{

extract($row1);

?>
<option value="<?php echo $row1['doid']; ?>"><?php echo $row1['doname']; ?> | <?php

											  $id2 = $row1['position'];

											  $query2 = $DB_con->prepare('SELECT poid,pname FROM mobileposition WHERE poid='.$id2);

											  $query2->execute();

											  $result2 = $query2->fetch();

											  echo $result2['pname'];

											  ?></option>
<?php 
} 
}
?>
</select>
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="form-group">
<label>Type Of Pets</label>
<select class="form-control" name="typeofpets" required>
<option value="Cat" <?php if($view_result['typeofpets']=="Cat"){echo "selected";} ?>>Cat</option>
<option value="Dog" <?php if($view_result['typeofpets']=="Dog"){echo "selected";} ?>>Dog</option>
<option value="Other" <?php if($view_result['typeofpets']=="Other"){echo "selected";} ?>>Other</option>
</select>
</div>
</div>
<div class="col-lg-12 col-sm-12 col-12">
<div class="form-group">
<label>Reason For Visit</label>
<textarea name="message" class="form-control" id="inputmessage" placeholder="Enter Reason For Visit"><?php echo $view_result['message']; ?></textarea>
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="form-group">
<label>Status</label>
<select class="form-control" name="status" required>
<option value="1" <?php if($view_result['status']=="1"){echo "selected";} ?>>Active</option>
<option value="0" <?php if($view_result['status']=="0"){echo "selected";} ?>>Deactive</option>
</select>
</div>
</div>
<div class="col-lg-12 col-sm-12 col-12">
<a href="appointmentlist.php" class="btn btn-cancel">Cancel</a>
<button type="submit" name="update" class="btn btn-submit me-2">Update</button>
</div>
</div>
</form>
</div>
</div>

</div>
</div>
</div>


<script src="assets/js/jquery-3.6.0.min.js"></script>

<script src="assets/js/feather.min.js"></script>

<script src="assets/js/jquery.slimscroll.min.js"></script>

<script src="assets/js/jquery.dataTables.min.js"></script>
<script src="assets/js/dataTables.bootstrap4.min.js"></script>

<script src="assets/js/bootstrap.bundle.min.js"></script>

<script src="assets/plugins/select2/js/select2.min.js"></script>

<script src="assets/plugins/sweetalert/sweetalert2.all.min.js"></script>
<script src="assets/plugins/sweetalert/sweetalerts.min.js"></script>

<script src="assets/js/script.js"></script>
</body>
</html>