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


if(isset($_REQUEST['edit']))
{
    $id = base64_decode($_REQUEST['edit']);
    $ex = $obj->view_service_content($id);
    $row = mysqli_fetch_array($ex);
}
if(isset($_POST['update']))
{   
  $update_ser_page['ser_page_id'] = $_POST['ser_page_id'];
  $update_ser_page['ser_page_service_id'] = $_POST['ser_page_service_id'];
  $update_ser_page['ser_sub_title'] = $_POST['ser_sub_title'];
  $update_ser_page['ser_page_desc'] = str_replace("'","\'", $_POST['ser_page_desc']);
  
        
        if(!empty($_FILES['ser_page_image']['name']))
        {      
            $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
            $upload_dir = '../uploads/service/';      
            $tempname = $_FILES['ser_page_image']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['ser_page_image']['name'];
            move_uploaded_file($tempname,$upload_name);
            $update_ser_page['ser_page_image'] = $server_url."/".$upload_name;
        }
        else
        {
            $update_ser_page['ser_page_image'] =$_POST['ser_page_image1'];
        }
     
    $ex = $obj->update_ser_page($update_ser_page);
    echo '<script>window.location="service.php"</script>';
}

if(isset($_POST['submit']))
{
$servicepage_info['ser_page_service_id'] = $_POST['ser_page_service_id'];
  $servicepage_info['ser_sub_title'] = $_POST['ser_sub_title'];
  $servicepage_info['ser_page_desc'] = str_replace("'","\'", $_POST['ser_page_desc']);

  $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/service/';
        
        if(!empty($_FILES['ser_page_image']['name']))
        {            
            $tempname = $_FILES['ser_page_image']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['ser_page_image']['name'];
            move_uploaded_file($tempname,$upload_name);
            $servicepage_info['ser_page_image'] = $server_url."/".$upload_name;
        }
  
  
    $ex = $obj->insert_service_page($servicepage_info);
    echo '<script>window.location="service.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>Service Page Content
                <a href="service.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="ser_page_id" value="<?php echo $row['ser_page_id'];?>">
                   <div class="form-group">
                        <select name="ser_page_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>Sub Title</label>
                  <input type="text" class="form-control" name="ser_sub_title" value="<?php echo $row['ser_page_title'];?>">
               </div>

          <div class="form-group">
                        <label>Service Page Description</label>
                        <textarea id="w3review" name="ser_page_desc" rows="6" cols="50" class="tinymce"><?php echo $row['ser_page_desc'];?></textarea>
           </div>
          
          
          
          <div class="form-group">
                        <label>Service Page Image </label><br>
            
                       <input type="file" class="" name="ser_page_image" value="<?php echo $row['ser_page_image'];?>">
                       <input type="hidden" name="ser_page_image1" value="<?php echo $row['ser_page_image'];?>">
                       <img src="<?php echo $row['ser_page_image'];?>"  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 = "service.php";
</script>

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

