<?php

include 'load.php';

if(isset($_POST['save']))

{		

		$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(empty($patient)){
			$errMSG = "Please Enter Patient Name.";
		}
		else if(empty($appdate)){
			$errMSG = "Please Enter Appointment Date.";
		}
		else if(empty($apptime)){
			$errMSG = "Please Enter Appointment Time.";
		}
		else if(empty($species)){
			$errMSG = "Please Select Species.";
		}
		else if(empty($breed)){
			$errMSG = "Please Select Breed.";
		}
		else if(empty($services)){
			$errMSG = "Please Enter services.";
		}
		else if(empty($doctor)){
			$errMSG = "Please Enter doctor.";
		}
		else if(empty($typeofpets)){
			$errMSG = "Please Select Trype Of Pets.";
		}
		else if(empty($status)){
			$errMSG = "Please Select Active Or Deactive.";
		}
		
		if(!isset($errMSG))

		{

			$stmt = $DB_con->prepare('INSERT INTO mobileappointment(appno,patient,appdate,apptime,species,breed,services,doctor,typeofpets,message,status) VALUES(:appno,:patient,:appdate,:apptime,:species,:breed,:services,:doctor,:typeofpets,:message,:status)');
			$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);
			if($stmt->execute())

			{

				$successMSG = "Successfully! Add Your Appointment....";

				header("refresh:2;appointmentreciept.php?appno='".$appno."'"); // redirects imdoctor view pdoctor after 5 seconds.

			}

			else

			{

				$errMSG = "error while inserting....";

			}

		}

	}

?>


<!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>Add 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>Add Appointment</h4>
<h6>Create new 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>
<?php
$appointmentid = '';
$appno = '';
$stmt = $DB_con->prepare('SELECT IFNULL(MAX(apid)+1,1) AS apid FROM `mobileappointment`');								
$stmt->execute();								
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);			
$appointmentid = $row['apid'];
$appno = "0000$appointmentid";
}
?>
<input type="text" name="appno" class="form-control" placeholder="Enter Appointment Number" value="<?php echo $appno; ?>" 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 selectpicker" id="inputpatient" data-live-search="true" required>
<option selected="selected">Select Patient</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="inputappdate" 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" 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 selected>Select Species</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 selected>Select Breed</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 selected>Select Services</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 selected>Select Doctor</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="select" name="typeofpets" required>
<option value="Cat">Cat</option>
<option value="Dog">Dog</option>
<option value="Other">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"></textarea>
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="form-group">
<label>Status</label>
<select class="select" name="status" required>
<option value="1">Active</option>
<option value="0">Deactive</option>
</select>
</div>
</div>
<div class="col-lg-12 col-sm-12 col-12">
<a href="doctorslist.php" class="btn btn-cancel">Cancel</a>
<button type="submit" name="save" class="btn btn-submit me-2">Save</button>
</div>
</div>
</form>
</div>
</div>

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

<?php
require_once 'footerjs.php';
?>
</body>
</html>