<?php  include "header.php";

if(isset($_GET['id'])){
    $ids = $_GET['id'];
    $title = "Update";
    $ajax = "update_business_locations";
    $success = "Updated";
    
    $statement = $pdo->prepare("SELECT * FROM tbl_business_branch e where e.id=".$ids);
    $statement->execute();
    $datas = $statement->fetchAll(PDO::FETCH_ASSOC);
    $totalData = $statement->rowCount();

}else{
    $ids = 0;
    $title = "Create";
    $ajax = "create_business_locations";
    $success = "Created";
}




?>


<div class="content-wrapper">
        <section class="content-header">
            <h1><?=$title?> - Business Locations</h1>
            <ol class="breadcrumb">
                <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active"><?=$title?> - Business Locations</li>            
            </ol>
        </section>


        <div class="col-lg-12 alerts">
            <div id="custom-alerts" style="display:none;">
                <div class="alert alert-dismissable">
                    <div class="custom-msg"></div>
                </div>
            </div>
            
            <?php if ($error)  { ?>
            <div class="alert alert-danger alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-ban"></i> Error</h4>
                <?= $error; ?>
            </div>
            <?php $error=0;} if ($warning) { ?>
            <div class="alert alert-warning alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-warning"></i> Warning</h4>
                <?= $warning; ?>
            </div>
            <?php  $warning=0;} if ($message) { ?>
            <div class="alert alert-success alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4>    <i class="icon fa fa-check"></i> Success</h4>
                <?= $message; ?>
            </div>
            <?php $message=0; } ?>
        </div>
        <div class="clearfix"></div>







<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box box-primary" style="box-shadow: rgba(0, 0, 0, 0.16) 0px 3px 6px, rgba(0, 0, 0, 0.23) 0px 3px 6px;">

                <div class="box-body">
                    
                    <div id="content-div">
                    
                    <div class="col-lg-12">

                        <form id="form_details" autocomplete="off">
                            
                            <input type="hidden" name="ids" value="<?=$ids?>"  class="form-control" id="ids"  required="required" />
                                                                 
                        <div class="row">
                            
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label class="required" for="business_name">Business Name</label>                                    
                                    <input type="text" name="business_name" value="<?php if(isset($datas)){ echo $datas[0]['business_name']; }?>" placeholder="Enter the Business Name" class="form-control" id="business_name"  required="required" />
                                </div>
                            </div>
                            
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label class="required" for="mobile_no">Mobile Number</label>                                   
                                     <input type="number" name="mobile_no" placeholder="Enter the Mobile Number" value="<?php if(isset($datas)){ echo $datas[0]['mobile_no']; }?>"  class="form-control" id="mobile_no"  required="required" />
                                </div>
                            </div>
                            
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label class="optional" for="alter_mobile_no">Alter Mobile Number</label>                                   
                                     <input type="number" name="alter_mobile_no" placeholder="Enter the Alter Mobile Number" value="<?php if(isset($datas)){ echo $datas[0]['alter_mobile_no']; }?>"  class="form-control" id="alter_mobile_no"  />
                                </div>
                            </div>
                            
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label class="required" for="location_name">Location Name</label>                                    
                                    <input type="text" name="location_name" value="<?php if(isset($datas)){ echo $datas[0]['location_name']; }?>" placeholder="Enter the Location Name" class="form-control" id="location_name"  required="required" />
                                </div>
                            </div>
                            
                            
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label class="optional" for="business_email">Email</label>                                    
                                    <input type="email" name="business_email" value="<?php if(isset($datas)){ echo $datas[0]['business_email']; }?>" placeholder="Enter the Email" class="form-control" id="business_email"  />
                                </div>
                            </div>
                            
                            
                            
                            
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label class="optional" for="business_gst">Business GST</label>                                    
                                    <input type="text" name="business_gst" value="<?php if(isset($datas)){ echo $datas[0]['business_gst']; }?>" placeholder="Enter the Business GST" class="form-control" id="business_gst"  />
                                </div>
                            </div>
                            
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label class="required" for="status">Status</label>                                    
                                    <select name="status" class="form-control" id="status" >
                                        <option value="1" <?php if(isset($datas) && $datas[0]['status']==1){ echo "selected"; }?>>Active</option>
                                        <option value="0" <?php if(isset($datas) && $datas[0]['status']==0){ echo "selected"; }?>>In-Active</option>
                                    </select>
                                </div>
                            </div>
                            
                            
                            
                            
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label class="optional" for="business_address">Address</label>                                   
                                    <textarea name="business_address" placeholder="Enter the Address" rows="3" class="form-control" id="address" ><?php if(isset($datas)){ echo $datas[0]['business_address']; }?></textarea>
                                </div>
                            </div>
                            
                            
                        </div>
                        
                        
                        

                        <div class="form-group" style="text-align:center;">
                            <input type="submit"  id="submit" value="Submit" class="btn btn-success" />
                        </div>
                        
                        </form>

                    </div>
                        <div class="form-group" style="text-align:center;">
                            <span onclick="location.reload();"><button class="btn btn-primary" ><i class="fa fa-refresh"></i> Reset Form</button></span>
                            <a href="business_locations_list.php"><button class="btn btn-warning" ><i class="fa fa-chevron-left"></i> Back to List</button></a>
                         </div>
                         
                    </div>   
                    
                    
<div class="container" id="loading-div" style="display: none; margin-top: 40px; margin-bottom: 40px;">
        <center> <img src="img/loading.gif" style="width: 250px;"><br><b class="blinking">Processing Please Wait...</b></center>
</div>
                    
                    
                    
                    
                    <div class="container" id="success-div" style="display: none; margin-top: 40px; margin-bottom: 40px;">
                        <center><b class="blinking" style="font-size:22px;">Business Locations <?=$success?> Successfully...</b><br>
                            <img src="img/success.gif" style="width: 250px;">
                            <br><br>
                            <span onclick="location.reload();"><button class="btn btn-info"><i class="fa fa-refresh"></i> Reset Form</button></span>
                            &nbsp;&nbsp;
                            <a href="business_locations_list.php"><button class="btn btn-warning"><i class="fa fa-chevron-left"></i> Back to List</button></a>
                        </center>
                    </div>
                    
                    
                    
                    
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </div>
</section>



<?php include "footer.php"; ?>


<script>
$(document).ready(function() {
   $('#form_details').on('submit', function(e){
                e.preventDefault();
                $('#loading-div').show();
                $('#content-div').hide();
                $("#submit").prop('disabled', true);
                var formData = new FormData(this);
                formData.append('type', '<?=$ajax?>');
                    $.ajax({
                            url: 'apis/business_locations.php',
                            type: 'post',
                            dataType: 'json',
                            data: formData,
                            cache: false,
                            contentType: false,
                            processData: false,
                            enctype: 'multipart/form-data',
                            success: function (response) {
                                console.log(response);
                                if(response['status']==200){
                                     toastr.success(response['message']);
                                     $('#form_details').trigger("reset");
                                     $("#submit").prop('disabled', false);
                                    //  $('#success-div').show();
                                     $('#loading-div').hide();
                                     setTimeout(function(){ window.location.href="business_locations_list.php"; },1500);
                                }else{
                                    toastr.error(response['message']);
                                    $("#submit").prop('disabled', false);
                                    $('#loading-div').hide();
                                    $('#content-div').show();
                                }
                            }
                        });
   });
});
</script>