Codeigniter Tutorials
- What is codeigniter?
- Application_Architecture
- MVC Architecture
- HMVC Architecture
- Codeigniter Configuration
- Remove index.php from url in codeigniter
- MVC Concept
- View
- Alternate PHP Syntax for View Files
- Routing
- Codeigniter URL
- Get Current URL
- Previous page URL get
- Seo Friendly URL
- Slug Create in codeigniter
- What is _remap() function
- Remove controller name from url in codeigniter
- Codeigniter Controller Class
- Class Constructor
- GET $ POST method in Codeigniter
- Models
- Basepath, Apppath, FCPATH
- URI Segment
- Page Redirect
- Helper class
- Custom Helper class
- Form Helper
- Common Helper Functions
- Common Function
- Array Problems
- Call controller in Helper
- Add active class to menu using Helper class
- Custom Library
- Custom Library Example
- when to use get_instance()
- Codeigniter Hook
- how to work inline css in codeigniter
- Custom 404 page
- 404 custom error page
- Create custom config file in codeigniter
- How to set and get config item value
- How to Speed Up CodeIgniter App?
- Codeigniter Functions
- Session
- cookies
- How to Set & Get Tempdata in Codeigniter
- flash messages in Codeigniter
- Flashdata
- Encryption and Decryption In CodeIgniter
- Codeigniter security
- csrf token form security
- Password Hashing
- Form Validation
- Custom Validation
- Registration Form with validation
- Server Side Form Validation
- Validate Select Option Field
- Date Format Validation
- Date Format change in codeigniter
- Date Functions
- DOB Validation
- CI CRUD
- User SignUp
- User Login
- User Logout
- Login Account
- Login form with RememberMe
- Login Form with session
- User change password
- Change Password with Callback Validation to Check Old Password
- Forgot password
- Reset password
- Insert data in database
- Fetch data from database
- Update data in database
- Delete data in database
- File Upload
- Image Upload with resize Image
- Upload Multiple file and images
- Upload Multiple images with CRUD
- File and image update
- Upload Image Using Ajax.
- Email Send
- Email Send Using Email library
- Email Send Using SMTP Gmail
- Notification send
- store data in json format in DB
- Json parse
- Fetch data Using Ajax with Json data
- How to Show data Using Ajax with Json parse
- Get JSON Data from PHP Script using jQuery Ajax
- Insert data Using Ajax
- Submit data Using Ajax with form validation
- How to show data Using Ajax in codeigniter
- Insert & Update Using Ajax
- Registration Form With Validation Using Ajax in codeigniter
- Delete data Using Ajax Confirmation
- Delete All data Using checkbox selection
- Ajax CSRF Token
- Ajax Post
- Ajax serverside form validation
- Contact form using AJAX with form validation
- DataTable Using Ajax dynamically
- DataTables pagination using AJAX with Custom filter
- DataTables AJAX Pagination with Search and Sort in codeigniter
- DataTables in Codeigniter using Ajax
- Ajax Custom Serarch
- Ajax Live Data Search using Jquery PHP MySql
- Ajax Custom Serarch and sorting in datatable
- Dynamic Search Using Ajax
- Autocomplete using jquery ajax
- Jquery Ajax Autocomplete Search using Typeahead
- Dynamic Dependent Dropdown Using Ajax
- Dynamic Dependent Dropdown list Using Ajax
- Dynamic Dependent Dropdown in codeigniter using Ajax
- ajax username/email availability check using JQuery
- Check Email Availability Using Ajax
- Data Load on mouse scroll
- Ajax CI Pagination
- Pagination in codeigniter
- Ajax Codeigniter Pagination
- email exists or not using ajax with json
- CRUD using AJAX With Modal popup in CI
- Add / Show Data on modal popup using Ajax
- Modal popup Validation using Ajax
- Data show on Modal popup Using Ajax
- Add / Remove text field dynamically using jquery ajax
- How to Add/Delete Multiple HTML Rows using JavaScript
- Delete Multiple Rows using Checkbox
- Multiple Checkbox value
- Form submit using jquery Example
- REST & SOAP API
- Multi-Language implementation in CodeIgniter
- How to pass multiple array in view
- Captcha
- create zip file and download
- PhpOffice PhpSpreadsheet Library (Export data in excel sheet)
- data export in excel sheet
- Excel File generate in Codeigniter using PHPExcel
- Dompdf library
- tcpdf library
- Html table to Excel & docs download
- CI Database Query
- Database Query
- SQL Injection Prevention
- Auth Model
- Join Mysql
- Tree View in dropdown option list
- OTP Integration in codeigniter
- curl post
- download file using curl
- Sweet Alert
- Sweet alert Delete & Success
- Log Message in Codeigniter
- Menu & Submenu show dynamically
- Set Default value in input box
- Cron Jobs
- Stored Procedure
- Display Loading Image when AJAX call is in Progress
- Send SMS
- IP Address
- Codeigniter Tutorialspoint
- Website Link
- How To Create Dynamic Xml Sitemap In Codeigniter
- Paypal Payment Integration
- Get Latitude and Longitude From Address in Codeigniter Using google map API
- How To Create Simple Bar Chart In Codeigniter Using AmCharts?
- dynamic Highcharts in Codeigniter
- Barcode in Codeigniter
- Codeigniter Interview Questions
- Project
Home » Codeigniter »
Common Helper Functions
File Name :
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
function get_religion_name($id)
{
$result= array();
$ci=& get_instance();
$ci->db->select('*');
$ci->db->from('religion');
$ci->db->where('pki_id',$id);
$query = $ci->db->get();
$result = $query->row_array();
if($result)
{
return $result['religion_name'];
}
else{
return '';
}
}
function get_marital_status($id)
{
$result= array();
$ci=& get_instance();
// $ci->db = $ci->load->database('anotherdb', TRUE);
$ci->db->select('*');
$ci->db->from('marital_status');
$ci->db->where('pki_id',$id);
$query = $ci->db->get();
$result = $query->result();
if($result)
{
return $result[0]->title;
}
else{
return '';
}
}
function get_disability_category($id)
{
$result= array();
$ci=& get_instance();
// $ci->db = $ci->load->database('anotherdb', TRUE);
$ci->db->select('*');
$ci->db->from('disability_category');
$ci->db->where('pki_id',$id);
$query = $ci->db->get();
$result = $query->result();
if($result)
{
return $result[0]->name;
}
else{
return '';
}
}
function get_discipline($id)
{
$result= array();
$ci=& get_instance();
// $ci->db = $ci->load->database('anotherdb', TRUE);
$ci->db->select('*');
$ci->db->from('discipline');
$ci->db->where('pki_id',$id);
$query = $ci->db->get();
// $result = $query->result();
$result = $query->row_array();
if($result)
{
// return $result[0]->name;
//return $result['name'];
$data = array(
'name' => $result['name'],
'code' => $result['dis_code']
);
return $data;
}
else{
return '';
}
}
function get_activity_code($id)
{
$result= array();
$ci=& get_instance();
// $ci->db = $ci->load->database('anotherdb', TRUE);
$ci->db->select('*');
$ci->db->from('activity');
$ci->db->where('pki_id',$id);
$query = $ci->db->get();
// $result = $query->result();
$result = $query->row_array();
if($result)
{
// return $result[0]->name;
//return $result['name'];
$data = array(
'name' => $result['name'],
'code' => $result['activity_code']
);
return $data;
}
else{
return '';
}
}
function get_indian_cityzen($id)
{
if($id == '1')
{
$aa = "Yes";
}
else{
$aa = "No";
}
return $aa;
}
function get_submitted_status($id)
{
if($id == '3')
{
$sta = "Submitted";
}
else{
$sta = "Not Submitted";
}
return $sta;
}
function get_discipline_code($id)
{
$result= array();
$ci=& get_instance();
// $ci->db = $ci->load->database('anotherdb', TRUE);
$ci->db->select('*');
$ci->db->from('discipline');
$ci->db->where('pki_id',$id);
$query = $ci->db->get();
$result = $query->result();
if($result)
{
return $result[0]->dis_code;
}
else{
return '';
}
}
function get_state_name($id)
{
$result= array();
$ci=& get_instance();
$ci->load->database();
$ci->db->select('*');
$ci->db->from('state');
$ci->db->where('id',$id);
$query = $ci->db->get();
$result = $query->result();
if($result)
{
return $result[0]->state_name;
}
else{
return '';
}
}
function get_bis_location($bis_location)
{
$result= array();
$ci=& get_instance();
//$ci->load->database();
$ci->mis_db = $ci->load->database('anotherdb', TRUE);
$ci->mis_db->select('uvc_branch_code');
$ci->mis_db->from('bis_branch');
$ci->mis_db->where('pki_id',$bis_location);
$query = $ci->mis_db->get();
$result = $query->result();
if($result)
{
return $result[0]->uvc_branch_code;
}
else{
return '';
}
}
function get_username($userId)
{
$result= array();
$ci=& get_instance();
//$ci->load->database();
$ci->mis_db = $ci->load->database('anotherdb', TRUE);
$ci->mis_db->select('vc_staff_name');
$ci->mis_db->from('bis_staff');
$ci->mis_db->where('fki_uid',$userId);
$query = $ci->mis_db->get();
$result = $query->result();
if($result)
{
return $result[0]->vc_staff_name;
}
else{
return '';
}
}
function get_paper_code($id)
{
$result= array();
$ci=& get_instance();
$ci->db->select('*');
$ci->db->from('gate_paper_code');
$ci->db->where('pki_id',$id);
$query = $ci->db->get();
$result = $query->result();
if($result)
{
return $result[0]->name;
}
else{
return '';
}
}
//function get_uploaded_doc($id)
function get_uploaded_doc($id,$table,$field)
{
$result= array();
$ci=& get_instance();
$ci->load->database();
$ci->db->select('*');
$ci->db->from($table);
$ci->db->where($field,$id);
//$query = $ci->db->get();
//$result = $query->result();
$result = $ci->db->count_all_results();
if($result)
{
//return $result[0]->doc_file_upload;
return $result;
}
else{
return '';
}
}
if(!function_exists('changeDateFormat'))
{
function changeDateFormat($format = 'd-m-Y', $originalDate)
{
return date($format, strtotime($originalDate));
}
}
if(!function_exists('change_time'))
{
function change_time($originalDate)
{
return date("g:ia", strtotime($originalDate));
}
}
function get_no_of_users($id)
{
$result= array();
$ci=& get_instance();
$ci->load->database();
$ci->db->select('*');
$ci->db->from('training_particepents');
$ci->db->where('training_id_fk',$id);
$result = $ci->db->count_all_results();
if($result)
{
return $result;
}
else{
return '';
}
}
function get_total_no_userss()
{
$result= array();
$ci=& get_instance();
$ci->load->database();
$ci->db->select('*');
$ci->db->from('rti');
$result = $ci->db->count_all_results();
if($result)
{
return $result;
}
else{
return '';
}
}
function get_total_no()
{
$result= array();
$ci=& get_instance();
$ci->load->database();
$ci->db->select('*');
$ci->db->from('audit_para');
$result = $ci->db->count_all_results();
if($result)
{
return $result;
}
else{
return '';
}
}
// #################### Encription & Decription ################
if (! function_exists('encryptor'))
{
function encryptor($action,$string) {
$output = false;
$encrypt_method = "AES-256-CBC";
$secret_key = 'BISIndia';
$secret_iv = 'BISIndia123';
$key = hash('sha256', $secret_key);
$iv = substr(hash('sha256', $secret_iv), 0, 16);
if( $action == 'encrypt' ) {
$output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
$output = base64_encode($output);
}
else if( $action == 'decrypt' ){
$output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
}
return $output;
}
}
// #################### End Encription & Decription ################
/**
* This function is used to print the content of any data
*/
function pre($data)
{
echo "<pre>";
print_r($data);
echo "</pre>";
}
/**
* This function used to get the CI instance
*/
if(!function_exists('get_instance'))
{
function get_instance()
{
$CI = &get_instance();
}
}
/**
* This function used to generate the hashed password
* @param {string} $plainPassword : This is plain text password
*/
if(!function_exists('getHashedPassword'))
{
function getHashedPassword($plainPassword)
{
return password_hash($plainPassword, PASSWORD_DEFAULT);
}
}
/**
* This function used to generate the hashed password
* @param {string} $plainPassword : This is plain text password
* @param {string} $hashedPassword : This is hashed password
*/
if(!function_exists('verifyHashedPassword'))
{
function verifyHashedPassword($plainPassword, $hashedPassword)
{
return password_verify($plainPassword, $hashedPassword) ? true : false;
}
}
/**
* This method used to get current browser agent
*/
if(!function_exists('getBrowserAgent'))
{
function getBrowserAgent()
{
$CI = get_instance();
$CI->load->library('user_agent');
$agent = '';
if ($CI->agent->is_browser())
{
$agent = $CI->agent->browser().' '.$CI->agent->version();
}
else if ($CI->agent->is_robot())
{
$agent = $CI->agent->robot();
}
else if ($CI->agent->is_mobile())
{
$agent = $CI->agent->mobile();
}
else
{
$agent = 'Unidentified User Agent';
}
return $agent;
}
}
if(!function_exists('setProtocol'))
{
function setProtocol()
{
$CI = &get_instance();
$CI->load->library('email');
$config['protocol'] = PROTOCOL;
$config['mailpath'] = MAIL_PATH;
$config['smtp_host'] = SMTP_HOST;
$config['smtp_port'] = SMTP_PORT;
$config['smtp_user'] = SMTP_USER;
$config['smtp_pass'] = SMTP_PASS;
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$CI->email->initialize($config);
return $CI;
}
}
if(!function_exists('emailConfig'))
{
function emailConfig()
{
$CI->load->library('email');
$config['protocol'] = PROTOCOL;
$config['smtp_host'] = SMTP_HOST;
$config['smtp_port'] = SMTP_PORT;
$config['mailpath'] = MAIL_PATH;
$config['charset'] = 'UTF-8';
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
}
}
if(!function_exists('resetPasswordEmail'))
{
function resetPasswordEmail($detail)
{
$data["data"] = $detail;
// pre($detail);
// die;
$CI = setProtocol();
$CI->email->from(EMAIL_FROM, FROM_NAME);
$CI->email->subject("Reset Password");
$CI->email->message($CI->load->view('email/resetPassword', $data, TRUE));
$CI->email->to($detail["email"]);
$status = $CI->email->send();
return $status;
}
}
if(!function_exists('setFlashData'))
{
function setFlashData($status, $flashMsg)
{
$CI = get_instance();
$CI->session->set_flashdata($status, $flashMsg);
}
}
// ######################### File uploading ######################
if (! function_exists('file_uploading')){
function file_uploading($upload_path,$files) {
$CI = get_instance();
$CI->load->library('upload');
$date = date('Y-m-d');
$upload_path_directory = $upload_path;
if (!is_dir($upload_path_directory)) {
$oldmask = umask(0);
mkdir($upload_path_directory,0777,TRUE);
umask($oldmask);
}
if(is_array($files['name'])){
$file_type = 1;
}else{
$file_type = 2;
}
if($file_type==2){
$info = pathinfo($files['name']);
$uploadfile_names = $info['filename'];
$uploadfile_name = str_replace(' ', '_', $uploadfile_names);
$extension = $info['extension'];
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$random_strng = substr(str_shuffle($characters), 0, 4);
$filename = $uploadfile_name.'_'.$random_strng.'_'.$date.'.' . $extension;
$_FILES['file']['name'] = $filename;
$_FILES['file']['type'] = $files['type'];
$_FILES['file']['tmp_name'] = $files['tmp_name'];
$_FILES['file']['size'] = $files['size'];
$config['upload_path'] = $upload_path;
$config['allowed_types'] = 'jpg|jpeg|png|bmp|pdf';
$config['file_name'] = $filename;
$config['max_size'] = '5000';
$CI->load->library('upload', $config);
$CI->upload->initialize($config);
if(!$CI->upload->do_upload('file',$filename)){
return false;
}else{
return $allfiles = $filename;
}
}
else if($file_type==1){
$filesCount = count($files['name']);
for($i = 0; $i < $filesCount; $i++){
$info = pathinfo($files['name'][$i]);
$uploadfile_names = $info['filename'];
$uploadfile_name = str_replace(' ', '_', $uploadfile_names);
$extension = $info['extension'];
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$random_strng = substr(str_shuffle($characters), 0, 4);
$filename = $uploadfile_name .'_'.$random_strng.'_'.$date.'.' . $extension;
$_FILES['file']['name'] = $filename;
$_FILES['file']['type'] = $files['type'][$i];
$_FILES['file']['tmp_name'] = $files['tmp_name'][$i];
$_FILES['file']['size'] = $files['size'][$i];
$config['upload_path'] = $upload_path_directory;
$config['allowed_types'] = 'jpg|jpeg|png|bmp|pdf';
$config['file_name'] = $filename;
$config['max_size'] = '5000';
$CI->load->library('upload', $config);
$CI->upload->initialize($config);
if(!$CI->upload->do_upload('file',$filename)){
return false;
}else{
$allfiles[] = $filename;
}
}
$total_upload_file = count($allfiles);
if($total_upload_file>1){
return $allfiles;
}else{
$files = $allfiles;
return $files;
}
}
}
}
// ########################### End FileUploading #####################
?>
File Name :
File Name :
File Name :
File Name :
File Name :