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


if(isset($_REQUEST['edit']))
{
    $web_id = base64_decode($_REQUEST['edit']);
    $ex = $obj->get_webinfo_id($web_id);
    $row = mysqli_fetch_array($ex);
}
if(isset($_POST['update']))
{   
  $update_webinfo['web_id'] = $_POST['web_id'];
  $update_webinfo['web_service_id'] = $_POST['web_service_id'];
  $update_webinfo['web_title'] = $_POST['web_title'];
  $update_webinfo['web_desc'] = $_POST['web_desc'];
  if(!empty($_FILES['web_icon']['name']))
        {      
            $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
            $upload_dir = '../uploads/service/';      
            $tempname = $_FILES['web_icon']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['web_icon']['name'];
            move_uploaded_file($tempname,$upload_name);
            $update_webinfo['web_icon'] = $server_url."/".$upload_name;
        }
        else
        {
            $update_webinfo['web_icon'] =$_POST['web_icon1'];
        }
     
    $ex = $obj->update_webinfo($update_webinfo);
    echo '<script>window.location="services_inner_services.php"</script>';
}

if(isset($_POST['submit']))
{

 
  $web_info['web_service_id'] = $_POST['web_service_id'];
  $web_info['web_title'] = $_POST['web_title'];
  $web_info['web_desc'] = $_POST['web_desc'];

  $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/service/';
        
        if(!empty($_FILES['web_icon']['name']))
        {            
            $tempname = $_FILES['web_icon']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['web_icon']['name'];
            move_uploaded_file($tempname,$upload_name);
            $web_info['web_icon'] = $server_url."/".$upload_name;
        }
  
  
    $ex = $obj->insert_webinfo($web_info);
    echo '<script>window.location="services_inner_services.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>Inner Service
                <a href="services_inner_services.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="web_id" value="<?php echo $row['web_id'];?>">
                    
                    
                    <div class="form-group">
                        <select name="web_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>Title</label>
                  <input type="text" class="form-control" name="web_title" value="<?php echo $row['web_title'];?>">
               </div>

          <div class="form-group">
                        <label>Description</label>
                        <textarea name="web_desc" rows="6" cols="50" class="form-control"><?php echo $row['web_desc'];?></textarea>
           </div>
          
          
          
         <!--  <div class="form-group">
                        <label>Web Icon </label><br>
            
                       <input type="file" class="" name="web_icon" value="<?php echo $row['web_icon'];?>">
                       <input type="hidden" name="web_icon1" value="<?php echo $row['web_icon'];?>">
                       <img src="<?php echo $row['web_icon'];?>"  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 = "services_inner_services.php";
</script>

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

