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


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

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

if(isset($_POST['submit']))
{
          //$homeourfacility_info['home_we_deploy_icon'] = $_POST['home_we_deploy_icon'];
          $homewedeploy_info['home_we_deploy_title'] = $_POST['home_we_deploy_title'];

            $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
            $upload_dir = '../uploads/home/';
        
        if(!empty($_FILES['home_we_deploy_icon']['name']))
        {            
            $tempname = $_FILES['home_we_deploy_icon']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['home_we_deploy_icon']['name'];
            move_uploaded_file($tempname,$upload_name);
            $homewedeploy_info['home_we_deploy_icon'] = $server_url."/".$upload_name;
        }
        
         $ex = $obj->add_homewedeploy_info($homewedeploy_info);
        
    echo '<script>window.location="homewedeploy.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 We Deploy Section 
                <a href="homewedeploy.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="home_we_deploy_id" value="<?php echo $row['home_we_deploy_id'];?>">
              
         
             <div class="form-group">
                        <label>Image</label><br>
             <img src="<?php echo $row['home_we_deploy_icon'];?>" style="width:100px;">
                        <input class="form-control" type="hidden" name="home_we_deploy_icon1" value="<?php echo $row['home_we_deploy_icon'];?>"> 
                        <input class="form-control" type="file"  name="home_we_deploy_icon" value="<?php echo $row['home_we_deploy_icon'];?>" >
                     </div>
               <div class="form-group">
                  <label>Title</label>
                  <input type="text" class="form-control" name="home_we_deploy_title" value="<?php echo $row['home_we_deploy_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 = "homewedeploy.php";
</script>
<?php require_once("footer.php");?>

