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


if(isset($_REQUEST['edit']))
{
    $life_at_ethics_gallery_id = base64_decode($_REQUEST['edit']);
    $ex = $obj->get_life_at_ethics_id_wise_data($life_at_ethics_gallery_id);
    $row = mysqli_fetch_array($ex);
}
if(isset($_POST['update']))
{   
  $update_ethics_gallery['life_at_ethics_gallery_id'] = $_POST['life_at_ethics_gallery_id'];
  $update_ethics_gallery['life_at_ethics_gallery_cate_id'] = $_POST['life_at_ethics_gallery_cate_id'];

    if(!empty($_FILES['life_at_ethics_gallery_img']['name']))
        {      
            $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
            $upload_dir = '../uploads/gallery/';      
            $tempname = $_FILES['life_at_ethics_gallery_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['life_at_ethics_gallery_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $update_ethics_gallery['life_at_ethics_gallery_img'] = $server_url."/".$upload_name;
        }
        else
        {
            $update_ethics_gallery['life_at_ethics_gallery_img'] =$_POST['life_at_ethics_gallery_img1'];
        }
 
    $ex = $obj->update_ethics_gallery($update_ethics_gallery);
  
    echo '<script>window.location="life_at_ethics_gallery.php"</script>';
}

if(isset($_POST['submit']))
{
  $life_at_ethics['life_at_ethics_gallery_cate_id'] = $_POST['life_at_ethics_gallery_cate_id'];

        foreach ($_FILES['life_at_ethics_gallery_img']['name'] as $key => $value) {
           
            $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
            $upload_dir = '../uploads/gallery/';
        
        if(!empty($_FILES['life_at_ethics_gallery_img']['name']))
        {            
            $tempname = $_FILES['life_at_ethics_gallery_img']['tmp_name'][$key];
            $upload_name = $upload_dir.$_FILES['life_at_ethics_gallery_img']['name'][$key];
            move_uploaded_file($tempname,$upload_name);
            $life_at_ethics['life_at_ethics_gallery_img'] = $server_url."/".$upload_name;
        }
        
         $ex = $obj->insert_life_at_ethics_gallery($life_at_ethics);
  }
        
    echo '<script>window.location="life_at_ethics_gallery.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>Life At Ethics Gallery
                <a href="life_at_ethics_gallery.php" class="btn btn-primary btn-sm float-right">Back</a>
            </div>
            <div class="card-body">
                <form method="post" id="users" enctype="multipart/form-data">
                   <input type="hidden" name="life_at_ethics_gallery_id" value="<?php echo $row['life_at_ethics_gallery_id'];?>">
                  
                 
             
         <h5 class="siteconfi">Life At Ethics Gallery</h5>

         <div class="form-group">
                        <select name="life_at_ethics_gallery_cate_id" class="form-control">
                 <option value="">Select Category</option>
                <?php
                            $ex = $obj->view_life_at_ethics_category();
                            while($crow=mysqli_fetch_array($ex))
                            {
                            ?>
                           <option <?php echo $row['life_at_ethics_id'] == $crow['life_at_ethics_id'] ? 'selected' : '';?>  value="<?php echo ucwords($crow['life_at_ethics_id']);?>"><?php echo ucwords($crow['life_at_ethics_title']);?></option>
               <?php
                 }
                  ?>
                 </select>
         </div>
          
             <div class="form-group">
                      
                      <?php if(isset($_REQUEST['edit']))
              { ?>        <img src="<?php echo $row['life_at_ethics_gallery_img'];?>" style="width:100px;">
                         <input type="file" class="form-control"  name="life_at_ethics_gallery_img">
                         <input type="hidden" name="life_at_ethics_gallery_img1" value="<?php echo $row['life_at_ethics_gallery_img'];?>">

             <?php }else{ ?>
                        <input class="form-control" multiple type="file"  name="life_at_ethics_gallery_img[]" value="<?php echo $row['life_at_ethics_gallery_img'];?>" >
                <?php } ?>
             </div>
         
                
                    <?php if(isset($_REQUEST['edit']))
                    { ?> 
                        <button type="submit" class="btn btn-primary" name="update">Update</button>
                    <?php } 
                    else
                    { ?>
                        <!-- <button id='add-user'>Add more fields</button><br><br> -->
                        <button type="submit" class="btn btn-primary" name="submit">Submit</button>
                    <?php } ?>
                </form> 
            </div>
        </div>
    </div>
</main>
<script>
    var url = "life_at_ethics_gallery.php";
</script>

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

