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


if(isset($_REQUEST['edit']))
{
    $soft_top_id = base64_decode($_REQUEST['edit']);
    $ex = $obj->get_soft_top_id($soft_top_id);
    $row = mysqli_fetch_array($ex);
}
if(isset($_POST['update']))
{   
  $soft_top_sec['soft_top_id'] = $_POST['soft_top_id'];

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

       
    $ex = $obj->update_soft_top_sec($soft_top_sec);
    echo '<script>window.location="software_top_section.php"</script>';
}

if(isset($_POST['submit']))
{
  $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/about/';
        
        if(!empty($_FILES['soft_top_img']['name']))
        {            
            $tempname = $_FILES['soft_top_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['soft_top_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $soft_top_sec['soft_top_img'] = $server_url."/".$upload_name;
        }

        
   $ex = $obj->insert_software_top_info($soft_top_sec);
    echo '<script>window.location="software_top_section.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>Software Top Section
                <a href="software_top_section.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="soft_top_id" value="<?php echo $row['soft_top_id'];?>">
                  <div class="form-group">
                     <label>Image</label><br>
                     <input type="file" class="" name="soft_top_img" value="<?php echo $row['soft_top_img'];?>">
                       <input type="hidden" name="soft_top_img1" value="<?php echo $row['soft_top_img'];?>">
                       <img src="<?php echo $row['soft_top_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 = "software_top_section.php";
</script>

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

