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


if(isset($_REQUEST['edit']))
{
    $home_slider_id = base64_decode($_REQUEST['edit']);
    $ex = $obj->get_home_slider_id($home_slider_id);
    $row = mysqli_fetch_array($ex);
}
if(isset($_POST['update']))
{   
  $update_home_slider['home_slider_id'] = $_POST['home_slider_id'];
  $update_home_slider['title'] = $_POST['title'];
  $update_home_slider['subtitle'] = $_POST['subtitle'];
  $update_home_slider['home_slider_text'] = $_POST['home_slider_text'];

  if(!empty($_FILES['home_slider_bg']['name']))
        {      
            $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
            $upload_dir = '../uploads/home/';      
            $tempname = $_FILES['home_slider_bg']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['home_slider_bg']['name'];
            move_uploaded_file($tempname,$upload_name);
            $update_home_slider['home_slider_bg'] = $server_url."/".$upload_name;
        }
        else
        {
            $update_home_slider['home_slider_bg'] =$_POST['home_slider_bg1'];
        }
  
        
        if(!empty($_FILES['home_slider_img']['name']))
        {      
            $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
            $upload_dir = '../uploads/home/';      
            $tempname = $_FILES['home_slider_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['home_slider_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $update_home_slider['home_slider_img'] = $server_url."/".$upload_name;
        }
        else
        {
            $update_home_slider['home_slider_img'] =$_POST['home_slider_img1'];
        }
     
    $ex = $obj->update_home_slider($update_home_slider);
    echo '<script>window.location="home_slider.php"</script>';
}

if(isset($_POST['submit']))
{
  $homeslider_info['title'] = $_POST['title'];
  $homeslider_info['subtitle'] = $_POST['subtitle'];
  $homeslider_info['home_slider_text'] = $_POST['home_slider_text'];
  $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/home/';
        
        if(!empty($_FILES['home_slider_bg']['name']))
        {            
            $tempname = $_FILES['home_slider_bg']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['home_slider_bg']['name'];
            move_uploaded_file($tempname,$upload_name);
            $homeslider_info['home_slider_bg'] = $server_url."/".$upload_name;
        }
  $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/slider/';
        
        if(!empty($_FILES['home_slider_img']['name']))
        {            
            $tempname = $_FILES['home_slider_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['home_slider_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $homeslider_info['home_slider_img'] = $server_url."/".$upload_name;
        }
  
  
    $ex = $obj->insert_home_slider($homeslider_info);
    echo '<script>window.location="home_slider.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 Slider
                <a href="home_slider.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="home_slider_id" value="<?php echo $row['home_slider_id'];?>">
                   <div class="form-group">
                  <label>Title</label>
                  <input type="text" class="form-control" name="title" value="<?php echo $row['title'];?>">
                  </div>
                  <div class="form-group">
                  <label>Sub Title</label>
                   <textarea name="subtitle" rows="6" cols="50" class="form-control"><?php echo $row['subtitle'];?></textarea>
               </div>                    

          <div class="form-group">
                        <label>Slider Text</label>
                        <textarea name="home_slider_text" rows="6" cols="50" class="form-control"><?php echo $row['home_slider_text'];?></textarea>
           </div>
          
                        <div class="form-group">
                        <label>Slider Background </label><br>
            
                       <input type="file" class="" name="home_slider_bg" value="<?php echo $row['home_slider_bg'];?>">
                       <input type="hidden" name="home_slider_bg1" value="<?php echo $row['home_slider_bg'];?>">
                       <img src="<?php echo $row['home_slider_bg'];?>"  style="width: 100px;">
                     </div>
          
                        <!-- <div class="form-group">
                        <label>Slider Image </label><br>
            
                       <input type="file" class="" name="home_slider_img" value="<?php echo $row['home_slider_img'];?>">
                       <input type="hidden" name="home_slider_img1" value="<?php echo $row['home_slider_img'];?>">
                       <img src="<?php echo $row['home_slider_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 = "home_slider.php";
</script>

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

