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


if(isset($_REQUEST['edit']))
{
    $of_id = base64_decode($_REQUEST['edit']);
    $ex = $obj->get_of_id($of_id);
    $row = mysqli_fetch_array($ex);
}
if(isset($_POST['update']))
{   
  
      $update_info['of_id'] = $_POST['of_id'];
      //$update_info['of_image'] = $_POST['of_image'];
    $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/home/';
        
        if(!empty($_FILES['of_image']['name']))
        {            
            $tempname = $_FILES['of_image']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['of_image']['name'];
            move_uploaded_file($tempname,$upload_name);
            $update_info['of_image'] = $server_url."/".$upload_name;
        }
        else
        {
            $update_info['of_image'] =$_POST['of_image1'];
        }

   
  $update_info['of_title'] = $_POST['of_title'];
     
    $ex = $obj->update_homeourfacility_info($update_info);
 
    echo '<script>window.location="homeourfacility.php"</script>';
}

if(isset($_POST['submit']))
{
          //$homeourfacility_info['of_image'] = $_POST['of_image'];
          $homeourfacility_info['of_title'] = $_POST['of_title'];

            $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
            $upload_dir = '../uploads/home/';
        
        if(!empty($_FILES['of_image']['name']))
        {            
            $tempname = $_FILES['of_image']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['of_image']['name'];
            move_uploaded_file($tempname,$upload_name);
            $homeourfacility_info['of_image'] = $server_url."/".$upload_name;
        }
        
         $ex = $obj->add_homeourfacility_info($homeourfacility_info);
        
    echo '<script>window.location="homeourfacility.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> Home Our Facility Section 
                <a href="homeourfacility.php" class="btn btn-primary btn-sm float-right">Back</a>
            </div>
            <div class="card-body">
                <form method="post" id="users" enctype="multipart/form-data">
                   <input type="hidden" name="of_id" value="<?php echo $row['of_id'];?>">
              
         
             <div class="form-group">
                        <label>Image</label><br>
             <img src="<?php echo $row['of_image'];?>" style="width:100px;">
                        <input class="form-control" type="hidden" name="of_image1" value="<?php echo $row['of_image'];?>"> 
                        <input class="form-control" type="file"  name="of_image" value="<?php echo $row['of_image'];?>" >
                     </div>
               <div class="form-group">
                  <label>Title</label>
                  <input type="text" class="form-control" name="of_title" value="<?php echo $row['of_title'];?>">
               </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 = "homeourfacility.php";
</script>
<?php require_once("footer.php");?>

