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


if(isset($_REQUEST['edit']))
{
    $faq_menu_id = base64_decode($_REQUEST['edit']);
    $ex = $obj->get_faqmenu_id($faq_menu_id);
    $row = mysqli_fetch_array($ex);
}
if(isset($_POST['update']))
{   
  
      $faq_info['faq_menu_id'] = $_POST['faq_menu_id'];
      $faq_info['faq_menu_name'] = $_POST['faq_menu_name'];
       if(!empty($_FILES['faq_menu_img']['name']))
        {      
            $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
            $upload_dir = '../uploads/service/';      
            $tempname = $_FILES['faq_menu_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['faq_menu_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $faq_info['faq_menu_img'] = $server_url."/".$upload_name;
        }
        else
        {
            $faq_info['faq_menu_img'] =$_POST['faq_menu_img1'];
        }
     
    $ex = $obj->update_faqmenu_info($faq_info);
 
    echo '<script>window.location="faq_menu.php"</script>';
}

if(isset($_POST['submit']))
{
          $faq_info['faq_menu_name'] = $_POST['faq_menu_name'];
          $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/service/';
        
        if(!empty($_FILES['faq_menu_img']['name']))
        {            
            $tempname = $_FILES['faq_menu_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['faq_menu_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $faq_info['faq_menu_img'] = $server_url."/".$upload_name;
        }
          $ex = $obj->add_faqmenu_info($faq_info);
        
    echo '<script>window.location="faq_menu.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> Faq Section 
                <a href="faq_menu.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="faq_menu_id" value="<?php echo $row['faq_menu_id'];?>">
                             
             <h5 class="siteconfi">Faq Title Section</h5>
              
               <div class="form-group">
                  <label>Title</label>
                  <input type="text" class="form-control" name="faq_menu_name" value="<?php echo $row['faq_menu_name'];?>">
               </div>    
               <div class="form-group">
                        <label>Background Image </label><br>
            
                       <input type="file" class="" name="faq_menu_img" value="<?php echo $row['faq_menu_img'];?>">
                       <input type="hidden" name="faq_menu_img1" value="<?php echo $row['faq_menu_img'];?>">
                       <img src="<?php echo $row['faq_menu_img'];?>"  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 = "faq_menu.php";
</script>
<?php require_once("footer.php");?>

