<?php 
    include 'inc/header.php'; 
    include("functions.php");
    ini_set('display_errors', '1');
    ini_set('display_startup_errors', '1');
    error_reporting(E_ALL);
    $update = true;
    $branch = "";

    $imgLink = "";
    $required = "";

    $company_data = get_company_data();
    // if($update == true){
      $location = "../".$company_data['location'];
      $img = explode(',', $company_data['logo']);
      $imgLink = 'feedback/'.$location.'/'.$img[0];
   // }
?>

    <!--== BODY CONTNAINER ==-->
    <div class="container-fluid sb2">
        <div class="row">
            <?php include 'inc/sidebar.php';?>
            <div class="sb2-2">
                <div class="sb2-2-2">
                    <ul>
                        <li><a href="#"><i class="fa fa-home" aria-hidden="true"></i> Home</a>
                        </li>
                        <li class="active-bre"><a href="#"> Update Logo</a>
                        </li>
                    </ul>
                </div>
                <div class="sb2-2-3">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="box-inn-sp">
                                <div class="inn-title">
                                    <h4>Add Logo</h4>
                                </div>
                                <div class="tab-inn">
                                    <form id="companyForm" action="ajax-request.php" method="POST">
                                        <div class="row">
                                            <div class="input-field col s6">
                                              <img src="<?php echo (($update === true) ? ($imgLink) : ""); ?>" alt="Image"  width='100px'><br>
                                                <input class="form-control" type="file" 
                                                  name="company_logo[]" id="company_logo" accept="image/gif, image/jpeg, image/png, image/jpg, image/webp" multiple >
                                                  <p class="small mb-0 mt-2">Leave Blank to stay same images</p>
                                                  <p class="small mb-0 mt-2"><b>Note:</b> Only JPG, JPEG, and PNG. Our suggested dimensions are 600px * 450px. The larger image will be cropped to 4:3 to fit our thumbnails/previews.
                                                  </p>
                                            </div>
                                        </div>

                                       

                                        
                                        <div class="row">
                                            <div class="input-field col s12">
                                          <?php if($update == false){ ?>
                                                <input type="submit" class="waves-effect waves-light btn-large" value="Add Now">
                                          <?php }else{?>
                                                <input type="submit" class="waves-effect waves-light btn-large" value="Update Now">
                                          <?php }?>
                                            </div>
                                        </div>
                                        
                                        <?php
                                            if($update == false){
                                        ?>
                                           <input type="hidden" name="branch_id" id="branch_id" value="">
                                           <input type="hidden" name="add-company-request" id="add-company-request" value="1">
                                        <?php
                                        }else{?>
                                           
                                           <input type="hidden" name="company_id" id="company_id" value="<?=$company_data['id'];?>">
                                           <input type="hidden" name="admin-update-company-request" id="admin-update-company-request" value="1">
                                        <?php }
                                        ?>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php include 'inc/footer.php';?>
<script type="text/javascript">
   $(document).ready(function() {

  $("#companyForm").on('submit', (function(e) {

    console.log('yes clicked form')
   e.preventDefault();
    $.ajax({
      url: $(this).attr('action'),
      type: "POST",
      data: new FormData(this),
      dataType: "json",
      contentType: false,
      cache: false,
      processData: false,

      success: function(data) {
        if(data.success == 1){
            promptMsg(1,data.msg);
            location.reload();
        }
        else{
            promptMsg(0,data.msg);
        }
              
      },
      error: function(e) {
        console.log(e);
      }
    });

  }));

  });

</script>