File: /home/cafsindia/hrms_cafsinfotech_in/application/controllers/Qr_code_generation.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Qr_code_generation extends Action_controller{
public function __construct(){
parent::__construct('qr_code_generation');
}
// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
public function index(){
//PAGE INFO FUNCTION
$data = "";
$this->load->view("$this->control_name/manage",$data);
}
//AUTO COMPLETE FUNCTION -> EmpName
public function suggest(){
$search_term = $this->input->post_get('term');
$final_qry = 'select employee_code,emp_name from cw_employees where trans_status = 1 and prime_employees_id !=1 and (employee_code like "'.$search_term.'%" or emp_name like "'.$search_term.'%")';
$final_data = $this->db->query("CALL sp_a_run ('SELECT','$final_qry')");
$final_result = $final_data->result();
$final_data->next_result();
foreach($final_result as $rslt){
$employee_code = $rslt->employee_code;
$emp_name = $rslt->emp_name;
$suggestions[] = array('value' => "$employee_code", 'label' =>"$employee_code - $emp_name");
}
if(empty($suggestions)){
$suggestions[] = array('value' => "0", 'label' => "No data found for this search");
}
echo json_encode($suggestions);
}
public function generate_qr(){
$type = $this->input->post('type');
$private_key = $this->input->post('private_key');
$employee_code = $this->input->post('employee_code');
$enc_string = $this->input->post('enc_string');
$method = "aes128";
$iv = "69kjg23423L@cEv7";
// Store the encryption key
if((int)$type === 1){
//Get Employee Data from DB
$emp_query = 'SELECT emp_name,date_of_joining,aadhar_card_no from cw_employees where employee_code = "'.$employee_code.'"';
$emp_info = $this->db->query("CALL sp_a_run ('SELECT','$emp_query')");
$emp_result = $emp_info->result();
$emp_info->next_result();
if($emp_result){ // if result is there
$emp_name = $emp_result[0]->emp_name;
$date_of_joining = $emp_result[0]->date_of_joining;
$aadhar_card_no = $emp_result[0]->aadhar_card_no;
if($date_of_joining === '' || $date_of_joining === '0000-00-00'){
echo json_encode(array('success' => FALSE,'message' => "Please check the Date of Joining in the Employee Master.."));
}else
if($aadhar_card_no === "" || strlen($aadhar_card_no) !== 12){
echo json_encode(array('success' => FALSE,'message' => "Please check the Aadhaar No in the Employee Master.."));
}else{
$original_string = "$emp_name:$employee_code:$date_of_joining:$aadhar_card_no";
// Use openssl_encrypt() function
$encryption_value = openssl_encrypt($original_string, $method, $private_key, 0, $iv);
$qr_img = $this->generate_qr_code($encryption_value); //generate QR Code
echo json_encode(array('success' => TRUE,'message' => "QR Generated Successfully..",'qr_img'=>$qr_img));
}
}else{
echo json_encode(array('success' => FALSE,'message' => "Please check the Employee Code.."));
}
}else{
// Use openssl_decrypt() function to decrypt the data
$decryption_value = openssl_decrypt($enc_string, $method, $private_key, 0,$iv);
if($decryption_value){
echo json_encode(array('success' => TRUE,'message' => "QR Decrypted Successfully..",'qr_img'=>$decryption_value));
}else{
echo json_encode(array('success' => FALSE,'message' => "QR not Valid.."));
}
}
}
//Generate QR code and return path
public function generate_qr_code($string){
$img_name = 'images/qr.png';
$this->load->library('ciqrcode');
$params['data'] = $string." cafsinfotech.com";
$params['level'] = 'L';
$params['size'] = 10;
$params['savename'] = $img_name;
$this->ciqrcode->generate($params);
$path = base_url().$img_name;
return '<img id="image" src="'.$path.'" alt="No image loaded"/>';
}
}
?>