<?php
ob_start();
include('head.php');
include('header.php'); 
include('sidebar.php'); 
$stmt = $pdo->prepare("SELECT * FROM tblphysicians where isDeleted='N' and id= ? order by id DESC");
$stmt->execute([$_GET['id']]);
$patients = $stmt->fetch();

$stmt8 = $pdo->prepare("SELECT * FROM tblprovince WHERE countryId='1' ORDER BY provinceName ASC");
$stmt8->execute();
$provinces = $stmt8->fetchAll();

$stmt1 = $pdo->prepare("SELECT empId,userName from tbluser WHERE isDeleted='N' and department='R'");
$stmt1->execute();
$employees = $stmt1->fetchAll();
$error='';
if (isset($_POST['btnSubmit'])) {
    $physicianFirstName = $_POST['firstName'];
    $physicianLastName = $_POST['lastName'];
    $hospital = $_POST['hospital'];
    $license = $_POST['license'];
    $primarySpecialty = $_POST['primarySpecialty'];
    $assignedTo = $_POST['assignedTo'];
    $physicianAddress = $_POST['address'];
    $physicianCity = $_POST['city'];
    $physicianProvince = $_POST['physicianProvince'];
    $physicianPostalCode = $_POST['postalCode'];

    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $fax = $_POST['fax'];
    $notes = $_POST['notes'];
    $createdBy = $_SESSION['empId'];

        $sql = "UPDATE tblphysicians set  firstName=?, lastName=?, hospital=?,license=?, primarySpecialty=?, streetAddress=?, city=?, province=?, postalCode=?, phone=?, email=?,fax=?,createdBy=?,assignedTo=?,notes=? where id=?";
        $stmt = $pdo->prepare($sql);
        if ($stmt->execute([$physicianFirstName,$physicianLastName,$hospital,$license,$primarySpecialty,$physicianAddress,$physicianCity,$physicianProvince,$physicianPostalCode, $phone, $email,$fax,$createdBy,$assignedTo,$notes,$_GET['id']])) {      
            header("location:physicians.php"); 
        } else {
            echo "Please try again!";
        }
    
}
?>
<style>
.card-header.mgtop.inlineflex {
    padding: 20px;
}
a.white{
    color:white;
}
.mgtop{
    margin-top:20px;
    margin-bottom:20px;
}
#example_wrapper select:not([size]) {
    width: 10%;
    margin: 10px;
}
.rxtitle{
    font-size:24px;
    font-weight:600;
}
table a.btn {
    /* background: none; */
    height: max-content;
    width: max-content;
    display: inline-flex;
}
.dt-length,.dt-search {
    display: flex;
    vertical-align: middle;
    align-items: center;
}
.customdewidth{
    margin-left: 15%;
    margin-top: 80px;
    width: 85%;
    background-color: whitesmoke;
}
aside{
   width:15%; 
}
.deindexpage .dt-search {
    float: right;
}
.errormessage{
    color: red;
    padding: 10px 0px;
}
body.navigation section .btn-primary{
    background: #9c27b0;
    border-color: #9c27b0;  
    font-weight:600; 
}
body.navigation section .btn-primary:hover {
    background-color: #631470;
    border-color: #631470;
}
body.navigation section .btn-secondary{
    font-weight:600;
    background: #6c757d;
    border-color: #6c757d;   
}
body.navigation section .btn-secondary:hover {
    background-color: #6c757d;
    border-color: #6c757d;
}

</style>

<section class="bgcolordefault deindexpage editPhysician">
<div class="editWc container-fluid customdewidth">
   
            <div class="row">
                <div class="col-12 customui">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">Edit Physician</h3>
                            <div class="offset-10 col-1">
                                <a href="physicians.php" class="btn btn-block btn-secondary bg-gradient-primary">BACK</a>
                            </div>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body">
                        <!-- /.card-header -->
                        <!-- form start -->
                        <form method="POST">
                            <div class="card-body row">
                                <div class="form-group col-md-4">
                                    <label for="pspName">Physician First Name</label>
                                    <input type="text" class="form-control" name="firstName" value="<?=$patients['firstName'];?>" placeholder="Enter Physician First Name">
                                </div>
                                <div class="form-group col-md-4">
                                    <label for="pspName">Physician Last Name</label>
                                    <input type="text" class="form-control" name="lastName" value="<?=$patients['lastName'];?>" placeholder="Enter Physician Last Name">
                                </div>
                                <div class="clearfix"></div>
                                <div class="form-group col-md-4">
                                    <label for="pspName">Email</label>
                                    <input type="email" class="form-control" name="email" value="<?=$patients['email'];?>" placeholder="Enter Email">
                                </div>
                                <div class="form-group col-md-4">
                                    <label for="pspName">Fax</label>
                                    <input type="text" class="form-control" name="fax" value="<?=$patients['fax'];?>" placeholder="Enter Fax">
                                </div>
                                <div class="clearfix"></div>
                                <div class="form-group col-md-4">
                                    <label for="pspName">Phone</label>
                                    <input type="text" class="form-control" name="phone" value="<?=$patients['phone'];?>" placeholder="Enter Phone"  data-inputmask="&quot;mask&quot;: &quot;(999) 999-9999&quot;"
                                    data-mask="" inputmode="text">
                                </div>
                                <div class="clearfix"></div>
                                <div class="form-group col-md-4">
                                    <label for="pspName">Address</label>
                                    <input type="text" class="form-control" name="address" value="<?=$patients['streetAddress'];?>" placeholder="Enter Street Address">
                                </div>
                              
                                <div class="form-group col-md-4">
                                    <label for="pspName">City</label>
                                    <input type="text" class="form-control" name="city" value="<?=$patients['city'];?>" placeholder="Enter City">
                                </div>
                                <div class="clearfix"></div>
                                <div class="form-group col-md-4">
                                    <label for="pspName">Province</label>
                                    <select class="form-control" name='physicianProvince' required id="physicianProvince">
                                             <option>Select Province</option>
                                             <?php foreach ($provinces as $province) { ?>
                                                <option  <?php if (isset($patients['province'])) {
                                                   if ($patients['province'] == $province['provinceName']) {
                                                      echo 'selected';
                                                   }
                                                } ?> value="<?php echo $province['provinceName']; ?>">
                                                   <?php echo $province['provinceName']; ?></option>
                                             <?php } ?>
                                          </select>
                                </div>
                              
                                <div class="form-group col-md-4">
                                    <label for="pspName">Postal Code</label>
                                    <input type="text" class="form-control" name="postalCode" value="<?=$patients['postalCode'];?>" placeholder="Enter Postal Code">
                                </div>
                                <div class="clearfix"></div>
                                <div class="form-group col-md-4">
                                    <label for="pspName">Physician Hospital/Site :</label>
                                    <input type="text" class="form-control" name="hospital" value="<?=$patients['hospital'];?>" placeholder="Enter Hospital">
                                </div>
                                 <div class="form-group col-md-4">
                                    <label for="pspName">License</label>
                                    <input type="text" class="form-control" name="license" value="<?=$patients['license'];?>">
                                </div>
                                 <div class='clearfix'></div>
                               
                                <div class="form-group col-md-4">
                                    <label for="pspName">Physician Primary Specialty:</label>
                                    <input type="text" class="form-control" name="primarySpecialty" value="<?=$patients['primarySpecialty'];?>" placeholder="Enter Primary Specialty">
                                </div>
                                <div class='clearfix'></div>
                                <div class="form-group col-md-4">
                                    <label for="pspName">Assigned To:</label>
                                   
                                          <div class="fixselect">
                                             <select class="form-control select2bs4" id="assignedTo" name="assignedTo">
                                                <option value="" <?= ($patients['assignedTo'] == "") ? 'selected' : '' ?>></option>
                                                <?php foreach ($employees as $emp) { ?>

                                                   <option value="<?= $emp['empId']; ?>"
                                                      <?= ($patients['assignedTo'] == $emp['empId']) ? 'selected' : '' ?>><?= $emp['userName']; ?></option>

                                                <?php } ?>
                                             </select>
                                          </div>
                                </div>
                                <div class='clearfix'></div>
                                <div class="form-group col-md-4">
                                    <label for="pspName">Physician Notes :</label>
                                    <textarea class="form-control" name="notes"><?=$patients['notes'];?></textarea>
                                </div>

                                
                                
                            <!-- /.card-body -->
                            <div class="card-footer">
                                <input type="submit" class="btn btn-primary" name="btnSubmit" value="Submit">
                               
                                <p class="errormessage"><?=$error;?>
                            </div>
                        </form>
                    </div>
                    <!-- /.card -->
                </div>
            </div>
            <!-- /.container-fluid -->
        </div>



</div>
                                        </section>
<script>
    $('#example').dataTable( {
    "order": [],
    // Your other options here...
} );
   
</script>
<?php
 include('footer.php'); 
ob_flush();