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


if(isset($_REQUEST['edit']))
{
    $cw_id = base64_decode($_REQUEST['edit']);
    $ex = $obj->get_careerwork_id($cw_id);
    $row = mysqli_fetch_array($ex);
}
if(isset($_POST['update']))
{   
  
      $cw_info['cw_id'] = $_POST['cw_id'];
      $cw_info['cw_sec_title'] = $_POST['cw_sec_title'];
      $cw_info['cw_title'] = $_POST['cw_title'];
       if(!empty($_FILES['cw_img']['name']))
        {      
            $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
            $upload_dir = '../uploads/service/';      
            $tempname = $_FILES['cw_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['cw_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $cw_info['cw_img'] = $server_url."/".$upload_name;
        }
        else
        {
            $cw_info['cw_img'] =$_POST['cw_img1'];
        }
     
    $ex = $obj->update_careerwork_info($cw_info);
 
    echo '<script>window.location="career_works.php"</script>';
}

if(isset($_POST['submit']))
{
          $cw_info['cw_sec_title'] = $_POST['cw_sec_title'];
          $cw_info['cw_title'] = $_POST['cw_title'];
          $server_url = '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $upload_dir = '../uploads/service/';
        
        if(!empty($_FILES['cw_img']['name']))
        {            
            $tempname = $_FILES['cw_img']['tmp_name'];
            $upload_name = $upload_dir.$_FILES['cw_img']['name'];
            move_uploaded_file($tempname,$upload_name);
            $cw_info['cw_img'] = $server_url."/".$upload_name;
        }
          $ex = $obj->add_careerwork_info($cw_info);
        
    echo '<script>window.location="career_works.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>Career Work
                <a href="career_works.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="cw_id" value="<?php echo $row['cw_id'];?>">
                             
              <div class="form-group">
                  <label>Section Title</label>
                  <input type="text" class="form-control" name="cw_sec_title" value="<?php echo $row['cw_sec_title'];?>">
               </div>  
               <div class="form-group">
                  <label>Title</label>
                  <input type="text" class="form-control" name="cw_title" value="<?php echo $row['cw_title'];?>">
               </div>    
               <div class="form-group">
                        <label>Icon Image </label><br>
            
                       <input type="file" class="" name="cw_img" value="<?php echo $row['cw_img'];?>">
                       <input type="hidden" name="cw_img1" value="<?php echo $row['cw_img'];?>">
                       <img src="<?php echo $row['cw_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 = "career_works.php";
</script>
<?php require_once("footer.php");?>

