<?php
session_start();
$title = "Staff Birthday Setup";
$group = "staffbday";
$menu = "staffbday";
include('header.php');

$firstname="";
$lastname="";
$othernames="";
$dob = "";
$dept = "";
$pos = "";
$email = "";
if(isset($_GET['id']))
{    
    $sql="select * from staff where id=:id";
    $value=array(':id'=>$_GET['id']);
    $r=$con->select_query($sql,$value);
    foreach($r as $value)
    {
        $firstname=$value['firstname'];
        $lastname=$value['lastname'];
        $othernames=$value['$othernames'];
        $dob = $value['dob'];
        $dept = $value['dept'];
        $pos = $value['position'];
        $email = $value['email'];
    }
}
?>
<script>

function SaveInsert()
{
	var datastring = $("#staffform").serialize();
	var l = $( '.ladda-button-demo1' ).ladda();
	l.ladda( 'start');	
	$.ajax({
	            type: "POST",
	            url: "../include/insert_ajax.php",
	            data: datastring,
	            dataType: 'json',
	            cache: false,
	            success: function(data) {
	            	l.ladda( 'stop' );
	            	if(data.success == 1)
	            	{
	            		setTimeout(function() {
	                        toastr.options = {
	                            closeButton: true,
	                            progressBar: true,
	                            positionClass: "toast-top-full-width",
	                            showMethod: 'slideDown',
	                            timeOut: 4000
	                        };
	                        toastr.success('Staff added successfully');
	                        $("input[type='text'], textarea, input[type='date'], input[type='number']").val("");
	                    }, 1300);
	            	}
	            	else if(data.success == 3)
	            	{
	            		setTimeout(function() {
	                        toastr.options = {
	                            closeButton: true,
	                            progressBar: true,
	                            positionClass: "toast-top-full-width",
	                            showMethod: 'slideDown',
	                            timeOut: 4000
	                        };
	                        toastr.error('Error, please enter required fields');

	                    }, 1300);
	            	}
	            },
	            error: function(){
	                  alert('error handling here');
	                  l.ladda( 'stop' );
	            }
	        });
}

function SaveUpdate()
{
	var datastring = $("#staffform").serialize();
	
	var l = $( '.ladda-button-demo2' ).ladda();
	l.ladda( 'start');
	$.ajax({
	            type: "POST",
	            url: "../include/update_ajax.php",
	            data: datastring,
	            dataType: 'json',
	            cache: false,
	            success: function(data) {
	            	l.ladda( 'stop' );
	            	if(data.success == 1)
	            	{
	            		setTimeout(function() {
	                        toastr.options = {
	                            closeButton: true,
	                            progressBar: true,
	                            positionClass: "toast-top-full-width",
	                            showMethod: 'slideDown',
	                            timeOut: 4000
	                        };
	                        toastr.success('Staff saved successfully');
	                    }, 1300);
	            	}
	            	else if(data.success == 3)
	            	{
	            		setTimeout(function() {
	                        toastr.options = {
	                            closeButton: true,
	                            progressBar: true,
	                            positionClass: "toast-top-full-width",
	                            showMethod: 'slideDown',
	                            timeOut: 4000
	                        };
	                        toastr.error('Error, please enter required fields');

	                    }, 1300);
	            	}
	            	
	            },
	            error: function(){
	                  alert('error handling here');
	                  l.ladda( 'stop' );
	            }
	        });
}
</script>

   <style>
.input-daterange input {
    text-align: left;
}
</style> 

<div class="content-body">
        	<div class="row">
                    <div id="recent-transactions" class="col-12">
                        <div class="card">
                            <div class="card-header">
                                <h4 class="card-title">Staff Birthday Setup</h4>
                            </div>
                            <div class="card-content">
                            	<form method="post" action="staff_birthday_setup" id="staffform" enctype="multipart/form-data">
                                <div class="row row-pad">
                                    <div class="col-md-3">
                                        <label for="name">First Name</label>
                                    </div>
                                    <div class="col-md-6">
                                        <input type="text" name="firstname" class="form-control" value="<?php echo $firstname;?>" required/>
                                    </div>
                                </div>
                                
                                <div class="row row-pad">
                                    <div class="col-md-3">
                                        <label for="name">Last Name</label>
                                    </div>
                                    <div class="col-md-6">
                                        <input type="text" name="lastname" class="form-control" value="<?php echo $lastname;?>" required/>
                                    </div>
                                </div>
                                
                                <div class="row row-pad">
                                    <div class="col-md-3">
                                        <label for="name">Other Names</label>
                                    </div>
                                    <div class="col-md-6">
                                        <input type="text" name="othernames" class="form-control" value="<?php echo $othernames;?>" required/>
                                    </div>
                                </div>

                                <div class="row row-pad">
                                    <div class="col-md-3">
                                        <label for="name">Email</label>
                                    </div>
                                    <div class="col-md-6">
                                        <input type="email" name="email" class="form-control" value="<?php echo $email;?>" required/>
                                    </div>
                                </div>
                                
                                <div class="row row-pad">
                                    <div class="col-md-3">
                                        <label for="name">Department (optional)</label>
                                    </div>
                                    <div class="col-md-6">
                                        <input type="text" name="dept" class="form-control" value="<?php echo $dept;?>"/>
                                    </div>
                                </div>
                                
                                <div class="row row-pad">
                                    <div class="col-md-3">
                                        <label for="name">Position (optional)</label>
                                    </div>
                                    <div class="col-md-6">
                                        <input type="text" name="pos" class="form-control" value="<?php echo $pos;?>"/>
                                    </div>
                                </div>
                                
                                <div class="row row-pad">
                                    <div class="col-md-3">
                                        <label for="name">Date of Birth</label>
                                    </div>
                                    <div class="col-md-6">
                                        <input type="date" name="dob" class="form-control" value="<?php echo $dob;?>" required/>
                                    </div>
                                </div>
                                
                                                              
                                <div class="row row-pad">
                                    <div class="col-md-3">
                                        
                                    </div>
                                    <div class="col-md-6">
                                    <?php 
                                        if(isset($_GET['id'])){
                                            echo '
                                            <input type="hidden" name="update" value="staff_birthday_setup"/>
                                            <input type="hidden" name="id" value="'.$_GET['id'].'"/>
                                            <button type="button" onclick="SaveUpdate()" class="ladda-button ladda-button-demo2 btn btn-primary"  data-style="zoom-in">Update Staff</button>';
                                        } else {
                                            echo '
                                            <input type="hidden" name="insert" value="staff_birthday_setup"/>
                                            <button type="button" onclick="SaveInsert()" class="ladda-button ladda-button-demo1 btn btn-primary"  data-style="zoom-in">Add Staff</button>';
                                        }
                                    ?>
                                        <a href="staff_birthdays" class="btn btn-warning">Cancel</a>
                                    </div>
                                </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                <!--/ Recent Transactions -->

   </div>    
    
    
    <?php include('footer.php');?>

   
