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


if(isset($_REQUEST['edit']))
{
    $software_id = base64_decode($_REQUEST['edit']);
    $ex = $obj->get_software_id($software_id);
    $row = mysqli_fetch_array($ex);
}
if(isset($_POST['update']))
{   
  $software_info['software_id'] = $_POST['software_id'];
  $software_info['title'] = $_POST['title'];
  $software_info['problem'] = $_POST['problem'];
  $software_info['solution'] = $_POST['solution'];
    
    $ex = $obj->update_software_info($software_info);
    echo '<script>window.location="software.php"</script>';
}

if(isset($_POST['submit']))
{
  
  $software_info['title'] = $_POST['title'];
  $software_info['problem'] = $_POST['problem'];
  $software_info['solution'] = $_POST['solution'];

   $ex = $obj->insert_software_info($software_info);
    echo '<script>window.location="software.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>Softwares
                <a href="software.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="software_id" value="<?php echo $row['software_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>Problem</label>
                     <input type="text" class="form-control" name="problem" value="<?php echo $row['problem'];?>">
                   </div>

                      <div class="form-group">
                        <label>Solution</label>
                        <textarea id="w3review" name="solution" rows="6" cols="50" class="tinymce"><?php echo $row['solution'];?></textarea>
                      </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.php";
</script>

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

