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


if(isset($_REQUEST['edit']))
{
    $qp_id = base64_decode($_REQUEST['edit']);
    $ex = $obj->get_qp_id($qp_id);
    $row = mysqli_fetch_array($ex);
}
if(isset($_POST['update']))
{   
  $qp_info['qp_id'] = $_POST['qp_id'];

  $qp_info['qp_desc'] = str_replace("'","\'", $_POST['qp_desc']);
    
    $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/about/';
        
        if(!empty($_FILES['qp_img']['name']))
        {            
            $tempname = $_FILES['qp_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['qp_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $qp_info['qp_img'] = $server_url."/".$upload_name;
        }
        else
        {
            $qp_info['qp_img'] =$_POST['qp_img1'];
        }

       
    $ex = $obj->update_qp_info($qp_info);
    echo '<script>window.location="quality_policy.php"</script>';
}

if(isset($_POST['submit']))
{


  $qp_info['qp_desc'] = str_replace("'","\'", $_POST['qp_desc']);
  
    $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/about/';
        
        if(!empty($_FILES['qp_img']['name']))
        {            
            $tempname = $_FILES['qp_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['qp_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $qp_info['qp_img'] = $server_url."/".$upload_name;
        }

        
   $ex = $obj->insert_qp_info($qp_info);
    echo '<script>window.location="quality_policy.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>Quality Policy
                <a href="quality_policy.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="qp_id" value="<?php echo $row['qp_id'];?>">
                    
                   <div class="form-group">
                  <label>Description</label>
                  <textarea id="w3review" name="qp_desc" rows="6" cols="50" class="tinymce"><?php echo $row['qp_desc'];?></textarea>
                  </div>
                 <div class="form-group">
                     <label>Image</label><br>
                     <input type="file" class="" name="qp_img" value="<?php echo $row['qp_img'];?>">
                       <input type="hidden" name="qp_img1" value="<?php echo $row['qp_img'];?>">
                       <img src="<?php echo $row['qp_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 = "quality_policy.php";
</script>

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

