Current File : /home/giriqfky/public_html/Barga/application/helpers//general_helper.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$CI = & get_instance();
function debug($params)
{
echo "<pre>";
print_r($params);
echo "</pre>";
}
function getFileExt($file_name)
{
$nameAr = explode(".",$file_name);
$ext = $nameAr[count($nameAr)-1];
return $ext;
}
function generateSequence($seq_val)
{
return date('d').$seq_val.date('m');
}
function generatePaddingCount($value,$digit_len = 3)
{
return sprintf("%0{$digit_len}d",$value);
}
function addDaysToDate($date, $no_of_days)
{
$today = $date;
$next_date = date('Y-m-d', strtotime($today. ' + '.$no_of_days.' days'));
return $next_date;
}
function dateDiff($start, $end)
{
$start_ts = strtotime($start);
$end_ts = strtotime($end);
$diff = $start_ts - $end_ts;
return round($diff / 86400);
}
function getUserIP()
{
if( array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',')>0) {
$addr = explode(",",$_SERVER['HTTP_X_FORWARDED_FOR']);
return trim($addr[0]);
} else {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
} else {
return $_SERVER['REMOTE_ADDR'];
}
}
function chrReplace($text, $replace_with = "_")
{
return str_replace(" ", $replace_with, strtolower(trim($text)));
}
function checkUserLoggedIn()
{
global $CI;
if($CI->session->userdata('is_login')) return true;
else return false;
}
function userInfo($key)
{
global $CI;
$user_data = $CI->session->userdata('user_info');
return $user_data[$key];
}
function getDateFromDatepicker($date_val)
{
$date_val = explode("/",$date_val);
$c_day = trim($date_val[0]);
$c_month = trim($date_val[1]);
$c_year = trim($date_val[2]);
$ready_date_db = $c_year."-".$c_month."-".$c_day;
return $ready_date_db;
}
function showDate($date_str, $t = 1)
{
$format = getSettingValue('date_format');
if($date_str == '' || $date_str == '0000-00-00' || $date_str == '0000-00-00 00:00:00'){
$date_format = "N/A";
} else {
if($t == 1) $date_format = date($format." h:i:s a", strtotime($date_str));
else $date_format = date($format, strtotime($date_str));
}
return $date_format;
}
function getDateRangeToMysql($data_reg)
{
$date_range = explode("-",$data_reg);
$first_date = getDateFromDatepicker($date_range[0]);
$last_date = getDateFromDatepicker($date_range[1]);
$mysql_date_range = "'".$first_date."'" ." AND ". "'".$last_date."'";
return $mysql_date_range;
}
function yesNo($id)
{
$yes_no = array('1' => 'Yes', '2' => 'No');
if($id > 0) {
$yes_no = $yes_no[$id];
}
return $yes_no;
}
function serviceProviderTypes($service_provider_type_id = 0)
{
$service_provider_types = array(
'1' => 'Industry',
'2' => 'Company',
'3' => 'Shop',
'4' => 'Organisation',
'5' => 'Others'
);
if($service_provider_type_id > 0) {
$service_provider_types = $service_provider_types[$service_provider_type_id];
}
return $service_provider_types;
}
function jobPriority($job_priority_id = 0)
{
$job_priority = array('1' => 'Immediate','2' => 'Standard');
if($job_priority_id > 0) {
$job_priority = $job_priority[$job_priority_id];
}
return $job_priority;
}
function appUserStatus($user_status_id = 0)
{
$app_user_status = array('1' => 'Active', '2' => 'Block');
if($user_status_id > 0) {
$app_user_status = $app_user_status[$user_status_id];
}
return $app_user_status;
}
function appUserDocumentType($document_type_id = 0)
{
$app_user_document_types = array(
'1' => 'Aadhar Card',
'2' => 'Pan Card',
'3' => 'Passport',
'4' => 'Voter ID',
'5' => 'Driving Licence',
'6' => 'GST Certificate',
'7' => 'Trade License',
'8' => 'Bank Information',
'9' => 'Residence Proof',
'10' => 'Others'
);
if($document_type_id > 0) {
$app_user_document_types = $app_user_document_types[$document_type_id];
}
return $app_user_document_types;
}
function supportStatus($msg_status_id = 0)
{
$supportStatus = array('1' => 'New', '2' => 'Closed');
if($msg_status_id > 0) {
$supportStatus = $supportStatus[$msg_status_id];
}
return $supportStatus;
}
function appJobStatus($user_status_id = 0)
{
$app_user_status = array(
'1' => 'Active',
'2' => 'Confirmed Deal',
'3' => 'On the Way',
'4' => 'Completed',
'5' => 'Expired',
'6' => 'Cancelled Deal',
'7' => 'Pending',
'8' => 'In Progress',
'9' => 'Transferred Deal'
);
if($user_status_id > 0) {
$app_user_status = $app_user_status[$user_status_id];
}
return $app_user_status;
}
function appJobExpiryDateRange(){
$job_expiry_date = array('7' => '1 Week', '14' => '2 Week' , '21' => '3 Week');
return $job_expiry_date;
}
function fieldType($field_type_id = 0)
{
$field_type = array('1' => 'Text', '2' => 'Radio');
if($field_type_id > 0) {
$field_type = $field_type[$field_type_id];
}
return $field_type;
}
function jobStatus($job_status_id = 0)
{
$job_status = array('1' => 'Open', '2' => 'Close', '3' => 'Cancelled');
if($job_status_id > 0) {
$job_status = $job_status[$job_status_id];
}
return $job_status;
}
function appUserTypes($app_user_type_id = 0)
{
$app_user_type = array('1' => 'Customer', '2' => 'Service Professionals','3'=>'Business Owners');
if($app_user_type_id > 0) {
$app_user_type = $app_user_type[$app_user_type_id];
}
return $app_user_type;
}
function getMonthList()
{
return array(
'01' => 'January',
'02' => 'February',
'03' => 'March',
'04' => 'April',
'05' => 'May',
'06' => 'June',
'07' => 'July',
'08' => 'August',
'09' => 'September',
'10' => 'October',
'11' => 'November',
'12' => 'December'
);
}
function base64En($num,$val)
{
for($i=0; $i<$num; $i++) {
$val = base64_encode($val);
}
return $val;
}
function base64De($num,$val)
{
for($i=0; $i<$num; $i++) {
$val = base64_decode($val);
}
return $val;
}
function randomStr()
{
$n = rand(10e16, 10e20);
return base_convert($n, 10, 36);
}
function checkEmptyField($required_fields, $fields)
{
$error = true;
foreach($required_fields as $f) {
if($fields[$f] == "") {
@$fields[$f];
$error = false;
break;
}
}
if($error) {
return true;
} else {
return false;
}
}
function isValidId($table_name, $field_name, $field_value)
{
global $CI;
$CI->load->model('Base_model', 'Base');
$row_count = $CI->Base->isValidId($table_name, $field_name, $field_value);
return $row_count;
}
function getMessage($message_code, $message_type)
{
// 1 for app, 2 for frontend, 3 for backend, 4 for push
global $CI;
$CI->load->model('settings/Settings_model', 'Settings');
$message = $CI->Settings->getMessage($message_code, $message_type);
return $message;
}
function getMessageTitle($message_code)
{
global $CI;
$CI->load->model('settings/Settings_model', 'Settings');
$message = $CI->Settings->getMessageTitle($message_code);
return $message;
}
function getSettingValue($setting_name,$select = "setting_value")
{
global $CI;
$CI->load->model('settings/Settings_model', 'Settings');
$setting_value = $CI->Settings->getSettingValue($setting_name,$select);
return $setting_value;
}
function checkModuleAccessByUser($user_role_id, $module_id, $module_action)
{
global $CI;
$CI->load->model('settings/Settings_model', 'Settings');
$access_count = $CI->Settings->checkModuleAccessByUser($user_role_id, $module_id, $module_action);
return $access_count;
}
function getEmailTemplate($email_template_code)
{
global $CI;
$CI->load->model('settings/Settings_model', 'Settings');
$email_tpl_data = $CI->Settings->getEmailTemplate($email_template_code);
return $email_tpl_data;
}
function getSmsTemplate($sms_template_code)
{
global $CI;
$CI->load->model('settings/Settings_model', 'Settings');
$sms_tpl_data = $CI->Settings->getSmsTemplate($sms_template_code);
return $sms_tpl_data;
}
function getLeftMenu($parent_id)
{
global $CI;
$CI->load->model('settings/Settings_model', 'Settings');
$menu_list = $CI->Settings->getLeftMenu($parent_id);
return $menu_list;
}
function IsEmailExist($mobile_no)
{
global $CI;
$CI->load->model('customers/Customers_model', 'Customers');
$mobile_count = $CI->Customers->IsMobileNumberExist($mobile_no);
return $mobile_count;
}
function IsDeviceTypeExist($device_id, $device_token, $device_type)
{
global $CI;
$CI->load->model('customers/Customers_model', 'Customers');
$device_count = $CI->Customers->IsDeviceTypeExist($device_id, $device_token, $device_type);
return $device_count;
}
function insertNotificationResponse($not_id, $fields, $response)
{
global $CI;
if(is_array($not_id) && count($not_id) > 0) {
foreach($not_id as $key => $notification_id) {
$CI->db->insert(TABLE_FIREBASE_NOTIFICATION_RESPONSE, array('notification_id' => $notification_id, 'data' => serialize($fields), 'firebase_response' => $response, 'doc' => date('Y-m-d H:i:s')));
}
} else {
$CI->db->insert(TABLE_FIREBASE_NOTIFICATION_RESPONSE, array('notification_id' => $not_id, 'data' => serialize($fields), 'firebase_response' => $response, 'doc' => date('Y-m-d H:i:s')));
}
}
function getDeviceToken($device_type, $app_user_id)
{
global $CI;
$CI->load->model('customers/Customers_model', 'Customers');
$device_token = $CI->Customers->getDeviceToken($device_type, $app_user_id);
return $device_token;
}
function getNextRankValue($table_name, $rank_field, $parent_id = 0)
{
global $CI;
$CI->load->model('settings/Settings_model', 'Settings');
$rank_next_val = $CI->Settings->getNextRankValue($table_name, $rank_field, $parent_id);
return $rank_next_val;
}
function getParentNextRankValue($table_name, $rank_field, $parent_id, $parent_field)
{
global $CI;
$CI->load->model('settings/Settings_model', 'Settings');
$rank_next_val = $CI->Settings->getParentNextRankValue($table_name, $rank_field, $parent_id, $parent_field);
return $rank_next_val;
}
function getServiceParentDropDown($service_type = 0, $selected_id = array(), $self_id=0, $required = false, $field_name = "service_id")
{
global $CI;
$CI->load->model('services/Services_model', 'Services');
$service_dropdown = $CI->Services->getServiceParentDropDown($service_type, $selected_id, $self_id, $required, $field_name);
return $service_dropdown;
}
function getServiceName($service_id)
{
global $CI;
$CI->load->model('services/Services_model', 'Services');
$service_name = $CI->Services->getServiceName($service_id);
return $service_name;
}
function getServiceProviderDetailsById($service_provider_id)
{
global $CI;
$CI->load->model('services/Services_model', 'Services');
$service_provider_details = $CI->Serviceproviders->getServiceProviderDetailsById($service_provider_id);
return $service_provider_details;
}
function getBannerServiceId($banner_id)
{
global $CI;
$CI->load->model('masters/Masters_model','Masters');
$banner_service_id = $CI->Masters->getBannerServiceId($banner_id);
return $banner_service_id;
}
function getPackageServiceId($package_id)
{
global $CI;
$CI->load->model('masters/Masters_model','Masters');
$package_data = $CI->Masters->getPackageServiceId($package_id);
return $package_data;
}
function getAllMemberShipPackages()
{
global $CI;
$CI->load->model('masters/Masters_model','Masters');
$membership_packages = $CI->Masters->getAllMemberShipPackages();
return $membership_packages;
}
function getModuleNameById($module_id)
{
global $CI;
$CI->load->model('settings/Settings_model', 'Settings');
$module_name = $CI->Settings->getModuleNameById($module_id);
return $module_name;
}
function getAppCmsPageById($page_id)
{
global $CI;
$CI->load->model('cmspages/Cmspages_model', 'CmsPages');
$page_content = $CI->CmsPages->getAppCmsPageById($page_id);
return $page_content;
}
function getServiceNameById($service_id)
{
global $CI;
$CI->load->model('services/Services_model', 'Services');
$service_name = $CI->Services->getServiceNameById($service_id);
return $service_name;
}
function getCurrentCompanyInfo($member_id)
{
global $CI;
$CI->load->model('Base_model', 'Base');
$company_info = $CI->Base->getCurrentCompanyInfo($member_id);
return $company_info;
}
function getCurrentAddressInfo($member_id)
{
global $CI;
$CI->load->model('Base_model', 'Base');
$current_address_info = $CI->Base->getCurrentAddressInfo($member_id);
return $current_address_info;
}
function getRegisteredDeviceCount($app_user_id, $device_type)
{
global $CI;
$CI->load->model('Base_model', 'Base');
$device_count = $CI->Base->getRegisteredDeviceCount($app_user_id, $device_type);
return $device_count;
}
function getApiParams($param_data)
{
$param_html = '<p class="text-muted">';
$param_data = unserialize($param_data);
if(count($param_data) > 0) {
foreach($param_data as $key => $pd) {
if(is_array($pd)) {
$param_html .= '<small><strong>'.$key.' : </strong>'.json_encode($pd).'</small><br/>';
} else {
$param_html .= '<small><strong>'.$key.' : </strong>'.$pd.'</small><br/>';
}
}
} else {
$param_html .= '<small>No parameters found.</small>';
}
$param_html .= '</p>';
return $param_html;
}
function getLatLogByAddress($address)
{
if(!empty($address)) {
//Formatted address
$formattedAddr = str_replace(' ','+',$address);
//Send request and receive json data by address
$geocodeFromAddr = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.$formattedAddr.'&sensor=false');
$output = json_decode($geocodeFromAddr);
//Get latitude and longitute from json data
$data['latitude'] = @$output->results[0]->geometry->location->lat;
$data['longitude'] = @$output->results[0]->geometry->location->lng;
//Return latitude and longitude of the given address
if(!empty($data)) {
return $data;
} else {
return false;
}
} else {
return false;
}
}
function getLocationByPinCode($pin_code)
{
if(!empty($pin_code)) {
$service_url = "https://maps.googleapis.com/maps/api/geocode/json?address=".$pin_code."&key=".GOOGLE_KEY;
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$location_data = curl_exec($curl);
curl_close($curl);
$location_data = json_decode($location_data);
$status = $location_data->status;
if($status == "OK") {
$results = $location_data->results[0];
$city = $results->address_components[2]->long_name;
$state = $results->address_components[3]->long_name;
$response_data = array('city' => $city, 'state' => $state);
} else {
$response_data = array('city' => '', 'state' => '');
}
} else {
$response_data = array('city' => '', 'state' => '');
}
return $response_data;
}
function randomString($length, $type = '')
{
//Select which type of characters you want in your random string
switch($type) {
case 'num':
// Use only numbers
$salt = '1234567890';
break;
case 'alphanum':
// Use only characters and numbers
$salt = 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789';
break;
case 'lower':
// Use only lowercase letters
$salt = 'abcdefghjkmnpqrstuvwxyz23456789';
break;
case 'upper':
// Use only uppercase letters
$salt = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
default:
// Use uppercase, lowercase, numbers, and symbols
$salt = 'abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789';
break;
}
$rand = '';
$i = 0;
while ($i < $length) { // Loop until you have met the length
$num = rand() % strlen($salt);
$tmp = substr($salt, $num, 1);
$rand = $rand . $tmp;
$i++;
}
return $rand; // Return the random string
}
function cryptoRandSecure($min, $max)
{
$range = $max - $min;
if ($range < 1) return $min; // not so random...
$log = ceil(log($range, 2));
$bytes = (int) ($log / 8) + 1; // length in bytes
$bits = (int) $log + 1; // length in bits
$filter = (int) (1 << $bits) - 1; // set all lower bits to 1
do {
$rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes)));
$rnd = $rnd & $filter; // discard irrelevant bits
} while ($rnd > $range);
return $min + $rnd;
}
function getUniqueRandomNumber($length)
{
$token = "";
$codeAlphabet = "ABCDEFGHJKLMNOPQRSTUVWXYZ";
$codeAlphabet.= "abcdefghjkmnpqrstuvwxyz";
$codeAlphabet.= "23456789";
$max = strlen($codeAlphabet);
for ($i=0; $i < $length; $i++) {
$token .= $codeAlphabet[cryptoRandSecure(0, $max-1)];
}
return $token;
}
function numberFormat($amount, $decimal_place = 0)
{
return number_format($amount, $decimal_place, '.', '');
}
function uploadFileCustom($file_path, $file_name, $allowedExts, $file_prefix = "")
{
$fileex = explode(".", $_FILES[$file_name]["name"]);
$extension = strtolower(end($fileex));
if(in_array($extension, $allowedExts)) {
$output_dir = $file_path;
$fileName = $_FILES[$file_name]["name"];
$temp = explode(".", $_FILES[$file_name]["name"]);
$newfilename = $file_prefix."_".round(microtime(true)) . '.' . end($temp);
if(move_uploaded_file($_FILES[$file_name]["tmp_name"],$output_dir.$newfilename)) {
$file_data = array('upload_status' => 1, 'new_file_name' => $newfilename, 'res_msg' => 'Success');
} else {
$file_data = array('upload_status' => 0, 'new_file_name' => '', 'res_msg' => 'Upload Failed');
}
} else {
$file_data = array('upload_status' => 2, 'new_file_name' => '', 'res_msg' => 'File type not allowed');
}
return $file_data;
}
function uploadAppStatusFileCustom($file_path, $file_name, $allowedExts, $file_prefix = "")
{
$fileex = explode(".", $_FILES[$file_name]["name"]);
$extension = end($fileex);
if(in_array($extension, $allowedExts)) {
$output_dir = $file_path;
$fileName = $_FILES[$file_name]["name"];
$temp = explode(".", $_FILES[$file_name]["name"]);
$newfilename = $file_prefix."_".date('d-m-Y')."_".round(microtime(true)) . '.' . end($temp);
move_uploaded_file($_FILES[$file_name]["tmp_name"],$output_dir.$newfilename);
return $newfilename;
} else {
return false;
}
}
function getSMSurl($teid,$phone_no,$message, $route = 4)
{
$sms_url = "";
if(!empty($phone_no)){
$sms_format_msg = str_replace(" ", "%20",$message);
$sms_url = str_replace("{{SMS_MOBILE_NO}}", $phone_no, API_SMS_GATE_WAY);
$sms_url = str_replace("{{SMS_MESSAGE}}",$sms_format_msg,$sms_url);
$sms_url = str_replace("{{SMS_ROUTE}}",$route,$sms_url);
$sms_url = str_replace("{{TE_ID}}",$teid,$sms_url);
$sms_url = str_replace("&", "&", $sms_url);
}
return $sms_url;
}
function sendSMS($teid,$phone_no, $message, $route = 4)
{
$message = htmlentities($message, null, 'utf-8');
$message = str_replace(" ", "", $message);
$message = html_entity_decode($message);
if(SMS_ON == 1){
$phone_no = IS_SYSTEM_LIVE == 1 ? $phone_no : DEMO_MOB;
if(!empty($phone_no)) {
$url = getSMSurl($teid,$phone_no, $message, $route);
global $CI;
$CI->load->model('Base_model', 'Base');
$sms_send_info = $CI->Base->sendSmsByModel($url);
return $sms_send_info;
}
}
}
function sendSMSFunc($params=[])
{
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://control.msg91.com/api/v5/flow/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
// CURLOPT_POSTFIELDS => json_encode([
// 'template_id' => '655a0e64d6fc053d8607c2c2',
// 'recipients' => [
// [
// 'mobiles' => '917278830865',
// 'JOBCODE' => 'FLY001',
// 'JOBSECCODE' => '12345'
// ]
// ]
// ]),
CURLOPT_POSTFIELDS => json_encode($params),
CURLOPT_HTTPHEADER => [
"accept: application/json",
"authkey: 249381AQ6wW1NxH3K5bfe30aa",
"content-type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
return $response;
}
}
function countryCode()
{
return 91;
}
function convertToUpperCase($text_value)
{
return strtoupper(strip_tags(trim($text_value)));
}
function convertToLowerCase($text_value)
{
return strtolower(strip_tags(trim($text_value)));
}
function setDefaultValue($val)
{
$return_val = "";
if($val == "") {
$return_val = "";
} elseif($val == "0000") {
$return_val = "";
} elseif($val == "0000-00-00") {
$return_val = "";
} elseif($val == "0000-00-00 00:00:00") {
$return_val = "N/A";
} else {
$return_val = $val;
}
return $return_val;
}
function displayText($str = '', $case = 'P')//$case can be either of U/L/C/P
{
switch($case){
case 'U': //All uppercase
$str = strtoupper($str);
break;
case 'L': //all lovercase
$str = strtolower($str);
break;
case 'C': //capitalize each word
$str = ucwords(strtolower($str));
break;
case 'P': //capitalize the first character of each sentence
$str = ucfirst(($str));
$str = preg_replace_callback('/[.!?].*?\w/', create_function('$matches', 'return strtoupper($matches[0]);'), $str);
break;
default:
$str;
}
return $str;
}
function getRandomPaymentNumber($lenth = 10)
{
$random_number = randomString($lenth, 'alphanum');
return PAYMENT_NUMBER_FORMAT.$random_number;
}
function getDateDifference($date1="")
{
if(!empty($date1)){
$curr_date = date('Y-m-d H:i:s');
$diff = strtotime($curr_date) - strtotime($date1);
$response = "";
if($diff <= 2592000){
if($diff <= 86400 && $diff >= 60){
if($diff <= 3600){
$minute = $diff / 60;
$response = (int)$minute.' min '.COMMENT_BEFORE_TXT;
} else {
$calHour = $diff / 3600;
$restMin = $diff - ((int)$calHour * 3600);
$minute = $restMin / 60;
$response = (int)$calHour.' h '.COMMENT_BEFORE_TXT;
}
} elseif($diff < 60) {
$response = COMMENT_TIME_BELOW_1_MIN;
} else {
$getDay = $diff / 86400;
if((int)$getDay <= 1){
$response = 'yesterday';
} else {
$response = (int)$getDay.' days '.COMMENT_AGO_TXT;
}
}
} else {
$response = date("M jS, Y", strtotime($date1));
}
return $response;
}
}
function isurlvalid($url)
{
$is_valid = 1;
$pattern = "|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i";
if (!preg_match($pattern, $url)){
$is_valid = 2;
}
return $is_valid;
}
function curl_post_async($url, $params)
{
foreach ($params as $key => &$val) {
if (is_array($val)) $val = implode(',', $val);
$post_params[] = $key.'='.urlencode($val);
}
$post_string = implode('&', $post_params);
$parts=parse_url($url);
$fp = fsockopen($parts['host'],
isset($parts['port'])?$parts['port']:80,
$errno, $errstr, 30);
$out = "POST ".$parts['path']." HTTP/1.1\r\n";
$out.= "Host: ".$parts['host']."\r\n";
$out.= "Authorization: key=".FCM_ACCESS_KEY."\r\n";
$out.= "Content-Type: application/x-www-form-urlencoded\r\n";
$out.= "Content-Length: ".strlen($post_string)."\r\n";
$out.= "Connection: Close\r\n\r\n";
if (isset($post_string)) $out.= $post_string;
fwrite($fp, $out);
fclose($fp);
}
function processTextForHTML($text)
{
$usrstat = nl2br($text);
$re = '/(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/';
preg_match_all($re, strtolower($text), $url_matches, PREG_SET_ORDER, 0);
preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", strtolower($text), $email_matches, PREG_SET_ORDER, 0);
preg_match_all("/((?:\+|00)[17](?: |\-)?|(?:\+|00)[1-9]\d{0,2}(?: |\-)?|(?:\+|00)1\-\d{3}(?: |\-)?)?(0\d|\([0-9]{3}\)|[1-9]{0,3})(?:((?: |\-)[0-9]{2}){4}|((?:[0-9]{2}){4})|((?: |\-)[0-9]{3}(?: |\-)[0-9]{4})|([0-9]{7}))/m", $text, $phone_matches, PREG_SET_ORDER, 0);
$already_replaced = array();
if (is_array($url_matches)) {
foreach ($url_matches as $k => $v) {
if (@$v[0] != '' && !in_array($v[0], $already_replaced)) {
$usrstat = str_ireplace($v[0], '<a href="' . $v[0] . '" target="_blank">' . $v[0] . '</a>', $usrstat);
$already_replaced[] = $v[0];
}
}
}
$already_replaced = array();
if (is_array($email_matches)) {
foreach ($email_matches as $k => $v) {
if (@$v[0] != '' && !in_array($v[0], $already_replaced)) {
$usrstat = str_ireplace($v[0], '<a href="mailto:' . $v[0] . '">' . $v[0] . '</a>', $usrstat);
$already_replaced[] = $v[0];
}
}
}
$already_replaced = array();
if (is_array($phone_matches)) {
foreach ($phone_matches as $k => $v) {
if (@$v[0] != '' && !in_array($v[0], $already_replaced)) {
$usrstat = str_replace($v[0], '<a href="tel:' . $v[0] . '">' . $v[0] . '</a>', $usrstat);
$already_replaced[] = $v[0];
}
}
}
return $usrstat;//array('text' => $text, 'html' => nl2br($usrstat));
}
function getTimeDurationTillNow($datetime)
{
$tstamp = strtotime($datetime);
$timegap = round((time() - $tstamp)/60);
$delay = '';
if($timegap < 1)
{
$delay = 'Just Now';
}
else if($timegap < 60)
{
$delay = $timegap.' Minute'.( ($timegap > 1)?'s':'' ).' Ago';
}
else if($timegap < 1440)
{
$hrs = round(($timegap/60));
$delay = $hrs.' Hour'.( ($hrs > 1)?'s':'' ).' Ago';
}
else if($timegap < 10080)
{
$days = round(($timegap/1440));
$delay = $days.' Day'.( ($days > 1)?'s':'' ).' Ago';
}
else
{
$delay = date('d-M', $tstamp);
}
return $delay;
}
function curlfunc($url)
{
$service_url = $url;
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$location_data = curl_exec($curl);
curl_close($curl);
return $location_data;
}
function encrypt($pure_string,$key) {
$dirty = array("+", "/", "=");
$clean = array("_PLUS_", "_SLASH_", "_EQUALS_");
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
$_SESSION['iv'] = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$encrypted_string = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, utf8_encode($pure_string), MCRYPT_MODE_ECB, $_SESSION['iv']);
$encrypted_string = base64_encode($encrypted_string);
return str_replace($dirty, $clean, $encrypted_string);
}
function decrypt($encrypted_string,$key) {
$dirty = array("+", "/", "=");
$clean = array("_PLUS_", "_SLASH_", "_EQUALS_");
$string = base64_decode(str_replace($clean, $dirty, $encrypted_string));
$decrypted_string = mcrypt_decrypt(MCRYPT_BLOWFISH, $key,$string, MCRYPT_MODE_ECB, @$_SESSION['iv']);
return $decrypted_string;
}
function getAPIKey()
{
$CI = & get_instance();
$CI->load->model('Settings/Settings_model');
$api = $CI->Settings_model->getApiKey(1);
return $api;
}
function patchCurl($data, $url)
{
$headers = array('Content-Type: application/json');
$curl = curl_init ();
curl_setopt ( $curl, CURLOPT_URL, $url );
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $curl, CURLOPT_CUSTOMREQUEST, 'PATCH' );
curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
curl_setopt ( $curl, CURLOPT_HTTPHEADER, $headers );
$response = curl_exec ( $curl );
curl_close ( $curl );
return $response;
}
function post_data_curl($data, $url)
{
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain') );
$jsonResponse = curl_exec ( $ch );
if (curl_errno ( $ch )) {
echo 'Curl error: ' . curl_error ( $ch );
}
curl_close ( $ch );
}
function get_curldata($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function curl_del($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $result;
}
function getChildServiceCount($service_id)
{
global $CI;
$CI->load->model('Services_model', 'Services');
$child_service_count = $CI->Services->getChildServiceCount($service_id);
return $child_service_count;
}
function getRatingStarReview($rating){
$star = "";
if($rating == 1){
$star .= '<small><i class="fa fa-star"></i></small>';
}else if($rating == 2){
$star .= '<small><i class="fa fa-star"></i></small>';
$star .= '<small><i class="fa fa-star"></i></small>';
}else if($rating == 3){
$star .= '<small><i class="fa fa-star"></i></small>';
$star .= '<small><i class="fa fa-star"></i></small>';
$star .= '<small><i class="fa fa-star"></i></small>';
}else if($rating == 4){
$star .= '<small><i class="fa fa-star"></i></small>';
$star .= '<small><i class="fa fa-star"></i></small>';
$star .='<small><i class="fa fa-star"></i></small>';
$star .='<small><i class="fa fa-star"></i></small>';
}else if($rating == 5){
$star .= '<small><i class="fa fa-star"></i></small>';
$star .= '<small><i class="fa fa-star"></i></small>';
$star .= '<small><i class="fa fa-star"></i></small>';
$star .= '<small><i class="fa fa-star"></i></small>';
$star .= '<small><i class="fa fa-star"></i></small>';
}
echo $star;
}
function getPackageDetails($package_id)
{
global $CI;
$CI->load->model('Masters_model', 'Masters');
$package_detail = $CI->Masters->getPackageData($package_id);
return $package_detail;
}
function getUserType($id)
{
global $CI;
$CI->load->model('Webservices_model', 'Webservices');
$user_type = $CI->Webservices->getUserType($id);
return $user_type;
}
function chkCategoryTypeRecursively($service_id)
{
global $CI;
$CI->load->model('Webservices/Webservices_model', 'Webservices');
$chkCategory = $CI->Webservices->checkCategoryType($service_id);
if($chkCategory->parent_id > 0) {
return chkCategoryTypeRecursively($chkCategory->parent_id);
} else {
return $chkCategory->service_id;
}
}
function getUserDetailsById($app_user_id)
{
global $CI;
$CI->load->model('Jobs/Jobs_model', 'Jobs');
$getUserDetailsById = $CI->Jobs->getUserDetailsById($app_user_id);
return $getUserDetailsById;
}
function getAddressDetails($app_address_id)
{
global $CI;
$CI->load->model('Jobs/Jobs_model', 'Jobs');
$getAddressDetails = $CI->Jobs->getAddressDetails($app_address_id);
return $getAddressDetails;
}
function getPaymentDetailsById($job_post_id)
{
global $CI;
$CI->load->model('Jobs/Jobs_model', 'Jobs');
$getPaymentDetailsById = $CI->Jobs->getPaymentDetailsById($job_post_id);
return $getPaymentDetailsById;
}
function paymentMode($payment_mode)
{
if($payment_mode == 1) {
$payment = "Cash";
} elseif ($payment_mode == 2) {
$payment = "Paytm";
}
return $payment;
}
function getJobCompletionActivity($job_post_id)
{
global $CI;
$CI->load->model('Jobs/Jobs_model', 'Jobs');
$getJobCompletionActivity = $CI->Jobs->getJobCompletionActivity($job_post_id);
return $getJobCompletionActivity;
}
function getJobTransferDetails($job_post_id)
{
global $CI;
$CI->load->model('Jobs/Jobs_model', 'Jobs');
$getJobTransferDetails = $CI->Jobs->getJobTransferDetails($job_post_id);
return $getJobTransferDetails;
}
function generateJobCodeCount($value,$digit_len)
{
return sprintf("%0{$digit_len}d",$value);
}
function getQuestionsAnsByJobId($job_post_id)
{
global $CI;
$CI->load->model('Jobs/Jobs_model', 'Jobs');
$getQuestionsAnsByJobId = $CI->Jobs->getQuestionsAnsByJobId($job_post_id);
return $getQuestionsAnsByJobId;
}
function getQuestionByQstnId($questionnaire_id)
{
global $CI;
$CI->load->model('Jobs/Jobs_model', 'Jobs');
$getQuestionByQstnId = $CI->Jobs->getQuestionByQstnId($questionnaire_id);
return $getQuestionByQstnId;
}
function getLatLongByCity($city_name)
{
global $CI;
$CI->load->model('Jobs/Jobs_model', 'Jobs');
$getLatLongByCity = $CI->Jobs->getLatLongByCity($city_name);
return $getLatLongByCity;
}
function serviceDetailsByServiceId($service_id)
{
global $CI;
$CI->load->model('Jobs/Jobs_model', 'Jobs');
$serviceDetailsByServiceId = $CI->Jobs->serviceDetailsByServiceId($service_id);
return $serviceDetailsByServiceId;
}
function getJobApplicationCount($job_post_id)
{
global $CI;
$CI->load->model('Jobs/Jobs_model', 'Jobs');
$getJobApplicationCount = $CI->Jobs->getJobApplicationCount($job_post_id);
return $getJobApplicationCount;
}
function getJobStatusStyle($job_post_status)
{
$label = appJobStatus($job_post_status);
$style = "";
if($job_post_status == 1){
$style = "<span class = 'label label-info'>".$label."</span>";
}
else if($job_post_status == 2){
$style = "<span class = 'label label-success'>".$label."</span>";
}
else if($job_post_status == 3){
$style = "<span class = 'label label-warning'>".$label."</span>";
}
else if($job_post_status == 4){
$style = "<span class = 'label label-success'>".$label."</span>";
}
else if($job_post_status == 5){
$style = "<span class = 'label label-danger'>".$label."</span>";
}
else if($job_post_status == 6){
$style = "<span class = 'label label-info'>".$label."</span>";
}
else if($job_post_status == 7){
$style = "<span class = 'label label-warning'>".$label."</span>";
}else if($job_post_status == 8){
$style = "<span class = 'label label-warning'>".$label."</span>";
}
else if($job_post_status == 9){
$style = "<span class = 'label label-warning'>".$label."</span>";
}
return $style;
}
function getJobMsgCount($job_post_id, $action_taken_id, $job_owner_id)
{
global $CI;
$CI->load->model('Jobs/Jobs_model', 'Jobs');
$getJobMsgCount = $CI->Jobs->getJobMsgCount($job_post_id, $action_taken_id, $job_owner_id);
return $getJobMsgCount;
}
function apiUriLog($file_name)
{
$name = explode("/",$file_name);
$ext1 = $name[0];
$ext2 = $name[1];
$uri = $ext1.'/'. $ext2;
return $uri;
}
function getDocumentDetails($app_user_id)
{
global $CI;
$CI->load->model('Serviceproviders/Serviceproviders_model', 'Serviceproviders');
$getDocumentDetails = $CI->Serviceproviders->getDocumentDetails($app_user_id);
return $getDocumentDetails;
}
function service_provider_services($app_user_id)
{
global $CI;
$CI->load->model('Serviceproviders/Serviceproviders_model', 'Serviceproviders');
$service_provider_services = $CI->Serviceproviders->service_provider_services($app_user_id);
return $service_provider_services;
}
function appBannerTypes($type)
{
$arr = array('1' => 'Top Banner', '2' => 'Small Banner');
return @$arr[$type];
}
function getDatesArray($d1, $d2)
{
$d2 = date('Y-m-d', strtotime($d2.' + 1 day'));
$dates = array();
$period = new DatePeriod(
new DateTime($d1),
new DateInterval('P1D'),
new DateTime($d2)
);
foreach ($period as $key => $value) {
$dates[] = $value->format('Y-m-d') ;
}
return $dates;
}
function testlog($text)
{
global $CI;
$CI->db->insert('aa_test', array('value' => $text));
}
function getCompanyDetails()
{
global $CI;
$CI->db->select('id,profile_photo,favicon,logo,login_page_logo,login_page_bg_logo');
$CI->db->from(TABLE_COMPANY_INFO);
$query = $CI->db->get();
$company_data = $query->row();
// $data = array('company_data' => $company_data);
return $company_data;
}
function displaywords($number){
$no = round($number);
$point = round($number - $no, 2) * 100;
$hundred = null;
$digits_1 = strlen($no);
$i = 0;
$str = array();
$words = array('0' => '', '1' => 'one', '2' => 'two',
'3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six',
'7' => 'seven', '8' => 'eight', '9' => 'nine',
'10' => 'ten', '11' => 'eleven', '12' => 'twelve',
'13' => 'thirteen', '14' => 'fourteen',
'15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen',
'18' => 'eighteen', '19' =>'nineteen', '20' => 'twenty',
'30' => 'thirty', '40' => 'forty', '50' => 'fifty',
'60' => 'sixty', '70' => 'seventy',
'80' => 'eighty', '90' => 'ninety');
$digits = array('', 'hundred', 'thousand', 'lakh', 'crore');
while ($i < $digits_1) {
$divider = ($i == 2) ? 10 : 100;
$number = floor($no % $divider);
$no = floor($no / $divider);
$i += ($divider == 10) ? 1 : 2;
if ($number) {
$plural = (($counter = count($str)) && $number > 9) ? 's' : null;
$hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
$str [] = ($number < 21) ? $words[$number] .
" " . $digits[$counter] . $plural . " " . $hundred
:
$words[floor($number / 10) * 10]
. " " . $words[$number % 10] . " "
. $digits[$counter] . $plural . " " . $hundred;
} else $str[] = null;
}
$str = array_reverse($str);
$result = implode('', $str);
$points = ($point) ? "" . $words[$point / 10] . " " . $words[$point = $point % 10] : '';
if($points != ''){
return $result . "Rupees " . $points . " Paise Only";
} else {
return $result . "Rupees Only";
}
}
function currentOrderId()
{
global $CI;
$CI->load->model('order/Product_model', 'product');
$orderId = $CI->product->currentOrderId();
return RESTAURANTS_CODE.$orderId;
}
function productActualPrice($total,$gst)
{
$actualPrice = 0;
$gstAmount = 0;
// $total = 100;//User Entry Total Amount
// $gst = 5;//User Entry GST Tax %
$calculateTax = 100+$gst;
$calculateAmount = $total*100;
$actualPrice = $calculateAmount/$calculateTax;
$gstAmount = round($total-$actualPrice,2);
$cgst = $gstAmount/2;
$sgst = $gstAmount/2;
$data = array('actualPrice' => round($actualPrice,2), 'cgstAmount' =>$cgst, 'sgstAmount' => $sgst,'gstAmount' => $gstAmount);
return $data;
}