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


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

  $update_about_page['title'] = $_POST['title'];
  $update_about_page['subtitle'] = $_POST['subtitle'];
  $update_about_page['about_desc'] = str_replace("'","\'", $_POST['about_desc']);
  $update_about_page['vision'] = str_replace("'","\'", $_POST['vision']);
  $update_about_page['mission'] = str_replace("'","\'", $_POST['mission']);
  $update_about_page['core_values'] = str_replace("'","\'", $_POST['core_values']);
  $update_about_page['director1_tit'] = $_POST['director1_tit'];
  $update_about_page['director1_desc'] = str_replace("'","\'", $_POST['director1_desc']);
  $update_about_page['director2_tit'] = $_POST['director2_tit'];
  $update_about_page['director2_desc'] = str_replace("'","\'", $_POST['director2_desc']);
  $update_about_page['director3_tit'] = $_POST['director3_tit'];
  $update_about_page['director3_desc'] = str_replace("'","\'", $_POST['director3_desc']);
    $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/about/';
        
        if(!empty($_FILES['director1_img']['name']))
        {            
            $tempname = $_FILES['director1_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['director1_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $update_about_page['director1_img'] = $server_url."/".$upload_name;
        }
        else
        {
            $update_about_page['director1_img'] =$_POST['director1_img1'];
        }

        if(!empty($_FILES['director2_img']['name']))
        {            
            $tempname = $_FILES['director2_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['director2_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $update_about_page['director2_img'] = $server_url."/".$upload_name;
        }
        else
        {
            $update_about_page['director2_img'] =$_POST['director2_img1'];
        }
        if(!empty($_FILES['director3_img']['name']))
        {            
            $tempname = $_FILES['director3_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['director3_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $update_about_page['director3_img'] = $server_url."/".$upload_name;
        }
        else
        {
            $update_about_page['director3_img'] =$_POST['director3_img1'];
        }
     
    $ex = $obj->update_about_page($update_about_page);
    echo '<script>window.location="aboutpage.php"</script>';
}

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


  $aboutpage_info['title'] = $_POST['title'];
  $aboutpage_info['subtitle'] = $_POST['subtitle'];
  $aboutpage_info['about_desc'] = $_POST['about_desc'];
  $aboutpage_info['vision'] = str_replace("'","\'", $_POST['vision']);
  $aboutpage_info['mission'] = str_replace("'","\'", $_POST['mission']);
  $aboutpage_info['core_values'] = str_replace("'","\'", $_POST['core_values']);
  $aboutpage_info['director1_tit'] = $_POST['director1_tit'];
  $aboutpage_info['director1_desc'] = $_POST['director1_desc'];
  $aboutpage_info['director2_tit'] = $_POST['director2_tit'];
  $aboutpage_info['director2_desc'] = $_POST['director2_desc'];
  $aboutpage_info['director3_tit'] = $_POST['director3_tit'];
  $aboutpage_info['director3_desc'] = $_POST['director3_desc'];
    $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/about/';
        
        if(!empty($_FILES['director1_img']['name']))
        {            
            $tempname = $_FILES['director1_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['director1_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $aboutpage_info['director1_img'] = $server_url."/".$upload_name;
        }

        if(!empty($_FILES['director2_img']['name']))
        {            
            $tempname = $_FILES['director2_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['director2_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $aboutpage_info['director2_img'] = $server_url."/".$upload_name;
        }

         if(!empty($_FILES['director3_img']['name']))
        {            
            $tempname = $_FILES['director3_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['director3_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $aboutpage_info['director3_img'] = $server_url."/".$upload_name;
        }


   $ex = $obj->insert_about_page($aboutpage_info);
    echo '<script>window.location="aboutpage.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>About Us
                <a href="aboutpage.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="about_page_id" value="<?php echo $row['about_page_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>
                  <input type="text" class="form-control" name="subtitle" value="<?php echo $row['subtitle'];?>">
                  </div>
                  <div class="form-group">
                 <label>About Page Description</label>
                  <textarea id="w3review" name="about_desc" rows="6" cols="50" class="tinymce"><?php echo $row['about_desc'];?></textarea>
               </div>
			    <div class="form-group">
                     <label>About us Image</label><br>
                     <input type="file" class="" name="director1_img" value="<?php echo $row['director1_img'];?>">
                       <input type="hidden" name="director1_img1" value="<?php echo $row['director1_img'];?>">
                       <img src="<?php echo $row['director1_img'];?>"  style="width: 100px;">
                     </div>

               <h5>Vision,Mission And Core Values</h5>
                
				<div class="form-group">
                 <label>Vision</label>
                  <textarea id="w3review" name="vision" rows="6" cols="50" class="tinymce"><?php echo $row['vision'];?></textarea>
               </div>
                <div class="form-group">
                 <label>Mission</label>
                  <textarea id="w3review" name="mission" rows="6" cols="50" class="tinymce"><?php echo $row['mission'];?></textarea>
               </div>
                <div class="form-group">
                 <label>Core Values</label>
                  <textarea id="w3review" name="core_values" rows="6" cols="50" class="tinymce"><?php echo $row['core_values'];?></textarea>
               </div>
              <!-- <div class="form-group">
                  <label>Director 2</label>
                  <input type="text" class="form-control" name="director2_tit" value="<?php echo $row['director2_tit'];?>">
                  </div>

                  <div class="form-group">
                     <label>Founder and Managing Director Image</label><br>
                     <input type="file" class="" name="director2_img" value="<?php echo $row['director2_img'];?>">
                       <input type="hidden" name="director2_img1" value="<?php echo $row['director2_img'];?>">
                       <img src="<?php echo $row['director2_img'];?>"  style="width: 100px;">
                     </div>
                      <div class="form-group">
                 <label>Description</label>
                  <textarea id="w3review" name="director2_desc" rows="6" cols="50" class="tinymce"><?php echo $row['director2_desc'];?></textarea>
               </div>
               <div class="form-group">
                  <label>Director 3</label>
                  <input type="text" class="form-control" name="director3_tit" value="<?php echo $row['director3_tit'];?>">
                  </div>

                  <div class="form-group">
                     <label>Founder and Managing Director Image</label><br>
                     <input type="file" class="" name="director3_img" value="<?php echo $row['director3_img'];?>">
                       <input type="hidden" name="director3_img1" value="<?php echo $row['director3_img'];?>">
                       <img src="<?php echo $row['director3_img'];?>"  style="width: 100px;">
                     </div>
                      <div class="form-group">
                 <label>Description</label>
                  <textarea id="w3review" name="director3_desc" rows="6" cols="50" class="tinymce"><?php echo $row['director3_desc'];?></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 = "aboutpage.php";
</script>

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

