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


if(isset($_REQUEST['edit']))
{
    $h_end_id = base64_decode($_REQUEST['edit']);
    $ex = $obj->get_h_end_id($h_end_id);
    $row = mysqli_fetch_array($ex);
}
if(isset($_POST['update']))
{   
  $end_to_end_info['h_end_id'] = $_POST['h_end_id'];
  $end_to_end_info['h_end_title'] = $_POST['h_end_title'];
  //$end_to_end_info['h_end_icon'] = $_POST['h_end_icon'];

   $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/home/';
        
        if(!empty($_FILES['h_end_icon']['name']))
        {            
            $tempname = $_FILES['h_end_icon']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['h_end_icon']['name'];
            move_uploaded_file($tempname,$upload_name);
            $end_to_end_info['h_end_icon'] = $server_url."/".$upload_name;
        }
        else
        {
           $end_to_end_info['h_end_icon'] =$_POST['h_end_icon1'];
        }

  $end_to_end_info['h_end_number'] = $_POST['h_end_number'];
  $end_to_end_info['h_end_desc'] = $_POST['h_end_desc'];

  
     
    $ex = $obj->update_end_to_end_info($end_to_end_info);
    echo '<script>window.location="home_end_to_end.php"</script>';
}

if(isset($_POST['submit']))
{
  $end_to_end_info['h_end_title'] = $_POST['h_end_title'];
  //$end_to_end_info['h_end_icon'] = $_POST['h_end_icon'];
  $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
            $upload_dir = '../uploads/home/';
        
        if(!empty($_FILES['h_end_icon']['name']))
        {            
            $tempname = $_FILES['h_end_icon']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['hs_simg']['name'];
            move_uploaded_file($tempname,$upload_name);
            $homeservice_info['h_end_icon'] = $server_url."/".$upload_name;
        }
        
  $end_to_end_info['h_end_number'] = $_POST['h_end_number'];
  $end_to_end_info['h_end_desc'] = $_POST['h_end_desc'];
  
    $ex = $obj->insert_end_to_end_info($end_to_end_info);
    echo '<script>window.location="home_end_to_end.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 End To End Section
                <a href="home_end_to_end.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="h_end_id" value="<?php echo $row['h_end_id'];?>">
                    
                  <div class="form-group">
                  <label>Title</label>
                    <input type="text" class="form-control" name="h_end_title" value="<?php echo $row['h_end_title'];?>">
                  </div>  

                 <!--  <div class="form-group">
                  <label>Icon</label>
                   <input type="text" class="form-control" name="h_end_icon" value="<?php echo $row['h_end_icon'];?>">
                  </div> -->
                  <div class="form-group">
                        <label>Icon</label><br>
                  <img src="<?php echo $row['h_end_icon'];?>" style="width:100px;">
                        <input class="form-control" type="hidden" name="h_end_icon1" value="<?php echo $row['h_end_icon'];?>"> 
                        <input class="form-control" type="file"  name="h_end_icon" value="<?php echo $row['h_end_icon'];?>" >
                     </div>
                  <div class="form-group">
                  <label>Number</label>
                   <input type="text" class="form-control" name="h_end_number" value="<?php echo $row['h_end_number'];?>">
                  </div>

                   <div class="form-group">
                  <label>Description</label>
                   <textarea  name="h_end_desc" rows="6" cols="50" class="form-control"><?php echo $row['h_end_desc'];?></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 = "home_end_to_end.php";
</script>

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

