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


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

   
  $update_info['hs_stitle'] = $_POST['hs_stitle'];
  $update_info['hs_sdesc'] = $_POST['hs_sdesc'];
     
    $ex = $obj->update_homeservice_info($update_info);
 
    echo '<script>window.location="homeservice.php"</script>';
}

if(isset($_POST['submit']))
{
          //$homeservice_info['hs_simg'] = $_POST['hs_simg'];
          $homeservice_info['hs_service_id'] = $_POST['hs_service_id'];
          $homeservice_info['hs_stitle'] = $_POST['hs_stitle'];
          $homeservice_info['hs_sdesc'] = $_POST['hs_sdesc'];

            $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
            $upload_dir = '../uploads/home/';
        
        if(!empty($_FILES['hs_simg']['name']))
        {            
            $tempname = $_FILES['hs_simg']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['hs_simg']['name'];
            move_uploaded_file($tempname,$upload_name);
            $homeservice_info['hs_simg'] = $server_url."/".$upload_name;
        }
        
         $ex = $obj->add_homeservice_info($homeservice_info);
        
    echo '<script>window.location="homeservice.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 Service Section 
                <a href="homeservice.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="hs_id" value="<?php echo $row['hs_id'];?>">
                             
             <h5 class="siteconfi">Product Section</h5>
             <div class="form-group">
                        <select name="hs_service_id" class="form-control">
                 <option value="">Select Service Title</option>
                <?php
                $ex = $obj->view_service();
                while($crow=mysqli_fetch_array($ex))
                {
                ?>
               <option <?php echo $row['service_id'] == $crow['service_id'] ? 'selected' : '';?>  value="<?php echo ucwords($crow['service_id']);?>"><?php echo ucwords($crow['service_name']);?></option>
               <?php
                 }
                  ?>
                 </select>
                    </div>
         
             <div class="form-group">
                        <label>Icon</label><br>
             <img src="<?php echo $row['hs_simg'];?>" style="width:100px;">
                        <input class="form-control" type="hidden" name="hs_simg1" value="<?php echo $row['hs_simg'];?>"> 
                        <input class="form-control" type="file"  name="hs_simg" value="<?php echo $row['hs_simg'];?>" >
                     </div>
               <div class="form-group">
                  <label>Title</label>
                  <input type="text" class="form-control" name="hs_stitle" value="<?php echo $row['hs_stitle'];?>">
               </div>
         <!-- <div class="form-group">
                  <label>Description</label>
                  
                  <textarea id="w3review" name="hs_sdesc" rows="4" cols="50" class="form-control"><?php echo $row['hs_sdesc'];?>
                  </textarea>
               </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 = "homeservice.php";
</script>
<?php require_once("footer.php");?>

