<?php
require_once("header.php");
require_once("menu.php");


if(isset($_REQUEST['edit']))
{
    $office_id = base64_decode($_REQUEST['edit']);
    $ex = $obj->get_office_address_by_id($office_id);
    $row = mysqli_fetch_array($ex);
}
if(isset($_POST['update']))
{  
  $office_info['contact_id'] = $_POST['contact_id']; 
  $office_info['office_address'] = $_POST['office_address'];
  $office_info['office_email'] = $_POST['office_email'];
  $office_info['office_phone'] = $_POST['office_phone'];
  $office_info['office_map'] = $_POST['office_map'];

  if(!empty($_FILES['office_bg_img']['name']))
        {      
            $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
            $upload_dir = '../uploads/home/';      
            $tempname = $_FILES['office_bg_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['office_bg_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $office_info['office_bg_img'] = $server_url."/".$upload_name;
        }
        else
        {
            $office_info['office_bg_img'] =$_POST['office_bg_img1'];
        }
  
  $ex = $obj->update_office_address($office_info);
    echo '<script>window.location="contact.php"</script>';
}

if(isset($_POST['submit']))
{
  $office_info['office_address'] = $_POST['office_address'];
  $office_info['office_email'] = $_POST['office_email'];
  $office_info['office_phone'] = $_POST['office_phone'];
  $office_info['office_map'] = $_POST['office_map'];
    $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/contact/';
        
        if(!empty($_FILES['office_bg_img']['name']))
        {            
            $tempname = $_FILES['office_bg_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['office_bg_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $office_info['office_bg_img'] = $server_url."/".$upload_name;
        }
    $ex = $obj->add_contact_info($office_info);
    echo '<script>window.location="contact.php"</script>';
}

?>

<div id="layoutSidenav_content">
<main class="mt-4">
    <div class="container-fluid">
        
        <div class="card mb-4">
            <div class="card-header">
                <i class="fas fa-check-square mr-1"></i>Office Location
                <a href="contact.php" class="btn btn-primary btn-sm float-right">Back</a>
            </div>
            <div class="card-body">
                <form method="post" name="frm" id="frm" enctype="multipart/form-data">
                   <input type="hidden" name="contact_id" value="<?php echo $row['contact_id'];?>">
                   
                  <div class="form-group">
                  <label>Office Address</label>
				   <textarea id="w3review" name="office_address" rows="6" cols="50" class="tinymce"><?php echo $row['office_address'];?></textarea>
                 </div>

				<div class="form-group">
                  <label>Email</label>
                  <input type="text" class="form-control" name="office_email" value="<?php echo $row['office_email'];?>">
                  </div>

                <div class="form-group">
                  <label>Phone No</label>
                  <input type="text" class="form-control" name="office_phone" value="<?php echo $row['office_phone'];?>">
                  </div>

			  

          <div class="form-group">
                        <label>Map Code</label>
						<textarea name="office_map" rows="6" cols="50" class="form-control"><?php echo $row['office_map'];?></textarea>
           </div>
          
                        <div class="form-group">
                        <label>Office Background Image</label><br>
            
                       <input type="file" class="" name="office_bg_img" value="<?php echo $row['office_bg_img'];?>">
                       <input type="hidden" name="office_bg_img1" value="<?php echo $row['office_bg_img'];?>">
                       <img src="<?php echo $row['office_bg_img'];?>"  style="width: 100px;">
                     </div>
          
                        <!-- <div class="form-group">
                        <label>Slider Image </label><br>
            
                       <input type="file" class="" name="home_slider_img" value="<?php echo $row['home_slider_img'];?>">
                       <input type="hidden" name="home_slider_img1" value="<?php echo $row['home_slider_img'];?>">
                       <img src="<?php echo $row['home_slider_img'];?>"  style="width: 100px;">
                     </div> -->
           
          
          
                    <?php if(isset($_REQUEST['edit']))
                    { ?> 
                        <button type="submit" class="btn btn-primary" name="update">Update</button>
                    <?php } 
                    else
                    { ?>
                        <button type="submit" class="btn btn-primary" name="submit">Submit</button>
                    <?php } ?>
                </form> 
            </div>
        </div>
    </div>
</main>

<script>
    var url = "contact.php";
</script>

<?php require_once("footer.php");?>

