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


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

  $integration_info['integration_id'] = $_POST['integration_id'];
  $integration_info['integration_top'] = str_replace("'","\'", $_POST['integration_top']);
  $integration_info['integration_bottom'] = str_replace("'","\'", $_POST['integration_bottom']);
  $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/about/';
        
        if(!empty($_FILES['integration_img']['name']))
        {            
            $tempname = $_FILES['integration_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['integration_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $integration_info['integration_img'] = $server_url."/".$upload_name;
        }
        else
        {
            $integration_info['integration_img'] =$_POST['integration_img1'];
        }
        
       
    $ex = $obj->update_integration($integration_info);
    echo '<script>window.location="integration.php"</script>';
}

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

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

  $ex = $obj->insert_integration($integration_info);
    echo '<script>window.location="integration.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>Integration Page Content
                <a href="inegration.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="integration_id" value="<?php echo $row['integration_id'];?>">
                   <div class="form-group">
                     <label>Image</label><br>
                     <input type="file" class="" name="integration_img" value="<?php echo $row['integration_img'];?>">
                       <input type="hidden" name="integration_img1" value="<?php echo $row['integration_img'];?>">
                       <img src="<?php echo $row['integration_img'];?>"  style="width: 100px;">
                     </div>

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

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

