<?php include('header.php');

if(isset($_POST['career'])){
        	
$addon = date('Y-m-d h:i:s');

	$target_dir = "assets/uploads/";

	$extension = explode('.', $_FILES['img']['name']);
	$file = 'CV_'.mt_rand(1000,99999) . '.' . $extension[1];
	$target_file = $target_dir . $file;
	$uploadOk = 1;
	$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));



	// Check file size
	if ($_FILES["img"]["size"] > 1048576) {
		$error_message = $error_message . "<b>Warning</b>, your file is too larger than 1 MB";
		$uploadOk = 0;
// 		header('location: a/../../service-list');
// 		exit();
	}

	// Allow certain file formats
	if ($imageFileType != "pdf" && $imageFileType != "doc" && $imageFileType != "PDF" && $imageFileType != "docs" && $imageFileType != "docx") {
		$error_message = $error_message . "<b>Warning</b>, only pdf,docs files are allowed.";
		$uploadOk = 0;
// 		header('location: a/../../service-list');
// 		exit();
	}

	// Check if $uploadOk is set to 0 by an error
	if ($uploadOk == 0) {
		$error_message = $error_message . "<b>Error</b>, your file was not uploaded.";
// 		header('location: a/../../service-list');
// 		exit();
		// if everything is ok, try to upload file
	} else {
		if (move_uploaded_file($_FILES["img"]["tmp_name"], $target_file)) {
// 			$_SESSION['success'] = "The file " . basename($_FILES["img"]["name"]) . " has been uploaded.";
		} else {
			$error_message = $error_message . "<b>Error</b>, there was an error uploading your file.";
		}
	}
	
	
	if($uploadOk==1){

    // saving into the database
    $statement = $pdo->prepare("INSERT INTO  tbl_career (
        name,
        phone,
        email,
        state,
        district,
        cv,
        addon,
        updated,
        status
    ) VALUES (?,?,?,?,?,?,?,?,?)");
    $statement->execute(array(
        strip_tags($_POST['name']),
        strip_tags($_POST['phone']),
        strip_tags($_POST['email']),
        strip_tags($_POST['state']),
        strip_tags($_POST['district']),
        $file,
        $addon,
        $addon,
        1
    ));
        
    $success_message="SUCCESS!! Your Details is submited.";
}  
    
}

?>


  <section class="account-page section-padding">
         <div class="container">
            <div class="row">
               <div class="col-lg-10 mx-auto">
                  <div class="row no-gutters">
                     <div class="col-md-12">
                        <div class="card card-body">
                           <div class="widget">
                              <div class="section-header">
                                 <h5 class="heading-design-h5">
                                    Career
                                 </h5>
                                 <p class=" text-justify">
                                     Fill your details and upload your CV and we shall get back to you within 72 hours and we shall offer you a job "if available" after seeing your CV and telephonic interview. <span>Best Wishes <strong><?=$base_name;?></strong></span>
                                 </p>
                              </div>
                              
                    <form action="<?=base_url('career/enquiry');?>" method="post" enctype='multipart/form-data'>
                                 <div class="row">
                                    <div class="col-sm-6 col-12">
                                       <div class="form-group">
                                          <label class="control-label">Full Name <span class="required">*</span></label>
                                         <input type="text" class="form-control border-form-control" name="name" value="">
                            
									  </div>
                                    </div>
                                    <div class="col-sm-6 col-12">
                                       <div class="form-group">
                                          <label class="control-label">Email Address <span class="required">*</span></label>
                                       <input type="email" class="form-control border-form-control" name="email" value="" >
                            
									  </div>
                                    </div>
                                
                                    <div class="col-sm-6 col-12">
                                       <div class="form-group">
                                          <label class="control-label">Phone <span class="required">*</span></label>
                                         <input type="tel" class="form-control border-form-control" onkeypress="return isNumberKey(event)" maxlength="10" name="phone" value="">
                           
									  </div>
                                    </div>
                                    
                               
                                    <div class="col-sm-6 col-12">
                                       <div class="form-group">
                                          <label class="control-label">State <span class="required">*</span></label>
										    <select onchange="getdt()" id="states" name="state" class="form-control border-form-control" style="width:100%;">
    											<option value=""></option>
                                                <option value="" selected>Select State</option>
                                                <?php  
                                                if(isset($state)){                          
                                                    foreach ($state as $row) {
                                                    ?>
                                                    <option value="<?php echo $row['state']; ?>"><?php echo $row['state']; ?></option>   
                                                    <?php 
                                                    }
                                                }
                                                ?>                         
                                            </select>
                                       </div>
                                    </div>
                                    <div class="col-sm-6 col-12">
                                       <div class="form-group">
                                          <label class="control-label">City <span class="required">*</span></label>
                                          <select name="district" id="district" class="form-control border-form-control"  style="width:100%;">
                                       
                                    </select> 
                                       </div>
                                    </div>
                                
                                    <div class="col-sm-6 col-12">
                                       <div class="form-group">
                                          <label class="control-label">Upload Your CV<span class="required">*</span></label>
                                        <input type="file" class="form-control border-form-control" name="img" value="" accept="application/msword, application/vnd.ms-powerpoint,text/plain, application/pdf">
                           
									  </div>
                                    </div>
                                   
                                 </div>
                                 <!--<div class="row">
                                    <div class="col-sm-12">
                                       <div class="form-group">
                                          <label class="control-label">Address <span class="required">*</span></label>
										       <textarea name="cust_address" class="form-control border-form-control" cols="30" rows="10" style="height:70px;"></textarea>
                           
                                       </div>
                                    </div>
                                 </div>-->
                                 <div class="row">
                                    <div class="col-sm-12 text-right">
                                      <button type="submit" name="career" class="btn btn-success btn-lg"> Submit </button>
                                    </div>
                                 </div>
                              </form>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </section>
      
      
    <script>  
        function getdt(){
            var state = $("#states").val();
            $.ajax({
                url:"<?=base_url('career/get_district');?>",
                type:"POST",
                data:{state:state},
                // dataType: 'json',
                success:function(data)
                {
                    $("#district").html(data);
                }
            })
        }      
    </script> 
     <?php require('footer.php');?>