×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
2
Language: PHP
Posted by: user1f787
Added: Sep 4, 2019 8:08 AM
Views: 4026
Tags: no tags
  1. <?php
  2.  
  3. function get_currency() {
  4.     $ci = &get_instance();
  5.     $ci->load->model("Currency_settings_Model");
  6.     $currency_settings = $ci->Currency_settings_Model->get_currency_settings();
  7.     return !empty($currency_settings->currency_symbol) ? $currency_settings->currency_symbol : '';
  8. }
  9.  
  10. function get_time_zone() {
  11.     return date_default_timezone_set("Asia/Dhaka");
  12. }
  13.  
  14. function get_current_date_and_time($date = NULL) {
  15.     get_time_zone();
  16.     if ($date == NULL) {
  17.         return $current_date_time = date('Y-m-d H:i:s');
  18.     } else {
  19.         return $current_date_time = date($date . ' H:i:s');
  20.     }
  21. }
  22.  
  23. function get_current_date() {
  24.     get_time_zone();
  25.     return $current_date = date('Y-m-d');
  26. }
  27.  
  28. function get_current_time() {
  29.     get_time_zone();
  30.     return $time = date('G:i:s');
  31. }
  32.  
  33. function get_string_to_date_fromat($date) {
  34.     return $result = date("d-m-Y", strtotime($date));
  35. }
  36.  
  37. function get_string_to_time_fromat($time) {
  38.     return $result = date('g:i a', strtotime($time));
  39. }
  40.  
  41. function get_current_year() {
  42.     get_time_zone();
  43.     return $current_year = date("Y");
  44. }
  45.  
  46. function get_current_month_name() {
  47.     get_time_zone();
  48.     return $current_month_name = date("F");
  49. }
  50.  
  51. function convert_number_to_words($number) {
  52.     $hyphen = '-';
  53.     $conjunction = ' and ';
  54.     $separator = ', ';
  55.     $negative = 'negative ';
  56.     $decimal = ' point ';
  57.     $dictionary = array(
  58.         0 => 'zero',
  59.         1 => 'one',
  60.         2 => 'two',
  61.         3 => 'three',
  62.         4 => 'four',
  63.         5 => 'five',
  64.         6 => 'six',
  65.         7 => 'seven',
  66.         8 => 'eight',
  67.         9 => 'nine',
  68.         10 => 'ten',
  69.         11 => 'eleven',
  70.         12 => 'twelve',
  71.         13 => 'thirteen',
  72.         14 => 'fourteen',
  73.         15 => 'fifteen',
  74.         16 => 'sixteen',
  75.         17 => 'seventeen',
  76.         18 => 'eighteen',
  77.         19 => 'nineteen',
  78.         20 => 'twenty',
  79.         30 => 'thirty',
  80.         40 => 'fourty',
  81.         50 => 'fifty',
  82.         60 => 'sixty',
  83.         70 => 'seventy',
  84.         80 => 'eighty',
  85.         90 => 'ninety',
  86.         100 => 'hundred',
  87.         1000 => 'thousand',
  88.         1000000 => 'million',
  89.         1000000000 => 'billion',
  90.         1000000000000 => 'trillion',
  91.         1000000000000000 => 'quadrillion',
  92.         1000000000000000000 => 'quintillion'
  93.     );
  94.     if (!is_numeric($number)) {
  95.         return false;
  96.     }
  97.     if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) {
  98.         // overflow
  99.         trigger_error(
  100.                 'convert_number_to_words only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX, E_USER_WARNING
  101.         );
  102.         return false;
  103.     }
  104.     if ($number < 0) {
  105.         return $negative . convert_number_to_words(abs($number));
  106.     }
  107.     $string = $fraction = null;
  108.     if (strpos($number, '.') !== false) {
  109.         list($number, $fraction) = explode('.', $number);
  110.     }
  111.     switch (true) {
  112.         case $number < 21:
  113.             $string = $dictionary[$number];
  114.             break;
  115.         case $number < 100:
  116.             $tens = ((int) ($number / 10)) * 10;
  117.             $units = $number % 10;
  118.             $string = $dictionary[$tens];
  119.             if ($units) {
  120.                 $string .= $hyphen . $dictionary[$units];
  121.             }
  122.             break;
  123.         case $number < 1000:
  124.             $hundreds = $number / 100;
  125.             $remainder = $number % 100;
  126.             $string = $dictionary[$hundreds] . ' ' . $dictionary[100];
  127.             if ($remainder) {
  128.                 $string .= $conjunction . convert_number_to_words($remainder);
  129.             }
  130.             break;
  131.         default:
  132.             $baseUnit = pow(1000, floor(log($number, 1000)));
  133.             $numBaseUnits = (int) ($number / $baseUnit);
  134.             $remainder = $number % $baseUnit;
  135.             $string = convert_number_to_words($numBaseUnits) . ' ' . $dictionary[$baseUnit];
  136.             if ($remainder) {
  137.                 $string .= $remainder < 100 ? $conjunction : $separator;
  138.                 $string .= convert_number_to_words($remainder);
  139.             }
  140.             break;
  141.     }
  142.     if (null !== $fraction && is_numeric($fraction)) {
  143.         $string .= $decimal;
  144.         $words = array();
  145.         foreach (str_split((string) $fraction) as $number) {
  146.             $words[] = $dictionary[$number];
  147.         }
  148.         $string .= implode(' ', $words);
  149.     }
  150.     return $string;
  151. }
  152.  
  153. function valid_numeric_number_check($amount) {
  154.     if (empty($amount) || (!is_numeric($amount))) {
  155.         return FALSE;
  156.     }
  157.     return TRUE;
  158. }
  159.  
  160. function get_floating_point_number($number = 0, $thousands_separator = FALSE) {
  161.     if ($thousands_separator == FALSE) {
  162.         $result = number_format((double) $number, 2, '.', '');
  163.     } else {
  164.         $result = number_format((double) $number, 2);
  165.     }
  166.     return $result;
  167. }
  168.  
  169. function get_date_interval($start_date, $end_date) {
  170.     $datetime1 = new DateTime($start_date);
  171.     $datetime2 = new DateTime($end_date);
  172.     $interval = $datetime1->diff($datetime2);
  173.     $result = $interval->format('%a');
  174.     return $result = (int) $result + 1;
  175. }
  176.  
  177. function get_days_name_list() {
  178.     $timestamp = strtotime('next Sunday');
  179.     $days = array();
  180.     for ($i = 0; $i < 7; $i++) {
  181.         $days[] = strftime('%A', $timestamp);
  182.         $timestamp = strtotime('+1 day', $timestamp);
  183.     }
  184.     return $days;
  185. }
  186.  
  187. function get_start_year_to_current_year_array() {
  188.     $years = array();
  189.     $start_Year = '2016';
  190.     $current_year = get_current_year();
  191.     $diff = ($current_year - $start_Year);
  192.     $lastYear = ($start_Year + $diff);
  193.     if ($start_Year == $current_year) {
  194.         array_push($years, $current_year);
  195.     } else {
  196.         for ($i = $start_Year; $i <= $lastYear; $i++) {
  197.             array_push($years, $i);
  198.         }
  199.     }
  200.     return $years;
  201. }
  202.  
  203. function get_months_name_array() {
  204.     $months_name = array();
  205.     for ($m = 1; $m <= 12; ++$m) {
  206.         array_push($months_name, date('F', mktime(0, 0, 0, $m, 1)));
  207.     }
  208.     return $months_name;
  209. }
  210.  
  211. function get_user_ip_address() {
  212.     $client = @$_SERVER['HTTP_CLIENT_IP'];
  213.     $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
  214.     $remote = $_SERVER['REMOTE_ADDR'];
  215.     if (filter_var($client, FILTER_VALIDATE_IP)) {
  216.         $ip = $client;
  217.     } elseif (filter_var($forward, FILTER_VALIDATE_IP)) {
  218.         $ip = $forward;
  219.     } else {
  220.         $ip = $remote;
  221.     }
  222.     return $ip;
  223. }
  224.  
  225. function get_user_server_information() {
  226.     return $_SERVER;
  227. }
  228.  
  229. function get_ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) {
  230.     $output = NULL;
  231.     if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) {
  232.         $ip = get_user_ip_address();
  233.         if ($deep_detect) {
  234.             if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP))
  235.                 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  236.             if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP))
  237.                 $ip = $_SERVER['HTTP_CLIENT_IP'];
  238.         }
  239.     }
  240.     $purpose = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose)));
  241.     $support = array("country", "countrycode", "state", "region", "city", "location", "address");
  242.     $continents = array(
  243.         "AF" => "Africa",
  244.         "AN" => "Antarctica",
  245.         "AS" => "Asia",
  246.         "EU" => "Europe",
  247.         "OC" => "Australia (Oceania)",
  248.         "NA" => "North America",
  249.         "SA" => "South America"
  250.     );
  251.     if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) {
  252.         //$ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip));
  253.         $url = "http://www.geoplugin.net/json.gp?ip=" . $ip;
  254.         $ch = curl_init();
  255.         curl_setopt($ch, CURLOPT_URL, $url);
  256.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  257.         $ipdat = curl_exec($ch);
  258.         $ipdat = json_decode($ipdat);
  259.         curl_close($ch);
  260.         if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) {
  261.             switch ($purpose) {
  262.                 case "location":
  263.                     $output = array(
  264.                         "ip" => $ip,
  265.                         "city" => @$ipdat->geoplugin_city,
  266.                         "state" => @$ipdat->geoplugin_regionName,
  267.                         "country" => @$ipdat->geoplugin_countryName,
  268.                         "country_code" => @$ipdat->geoplugin_countryCode,
  269.                         "continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)],
  270.                         "continent_code" => @$ipdat->geoplugin_continentCode,
  271.                         "latitude" => @$ipdat->geoplugin_latitude,
  272.                         "longitude" => @$ipdat->geoplugin_longitude
  273.                     );
  274.                     break;
  275.                 case "address":
  276.                     $address = array($ipdat->geoplugin_countryName);
  277.                     if (@strlen($ipdat->geoplugin_regionName) >= 1)
  278.                         $address[] = $ipdat->geoplugin_regionName;
  279.                     if (@strlen($ipdat->geoplugin_city) >= 1)
  280.                         $address[] = $ipdat->geoplugin_city;
  281.                     $output = implode(", ", array_reverse($address));
  282.                     break;
  283.                 case "city":
  284.                     $output = @$ipdat->geoplugin_city;
  285.                     break;
  286.                 case "state":
  287.                     $output = @$ipdat->geoplugin_regionName;
  288.                     break;
  289.                 case "region":
  290.                     $output = @$ipdat->geoplugin_regionName;
  291.                     break;
  292.                 case "country":
  293.                     $output = @$ipdat->geoplugin_countryName;
  294.                     break;
  295.                 case "countrycode":
  296.                     $output = @$ipdat->geoplugin_countryCode;
  297.                     break;
  298.             }
  299.         }
  300.     }
  301.     return $output;
  302. }
  303.  
  304. function is_valid_user_check_by_user_country() {
  305.     $access_country_array = get_valid_user_country();
  306.     $ip_info = get_ip_info();
  307.     $ip_address = get_user_ip_address();
  308.     $user_country = $ip_info['country'];
  309.     if ($ip_address == '::1') {
  310.         return TRUE;
  311.     }
  312.     if (!empty($ip_address) || $ip_address != NULL) {
  313.         if ((!empty($user_country)) || ($user_country != NULL)) {
  314.             if (in_array(strtolower($user_country), $access_country_array)) {
  315.                 return TRUE;
  316.             }
  317.             return FALSE;
  318.         }
  319.         return FALSE;
  320.     }
  321.     return FALSE;
  322. }
  323.  
  324. function is_valid_user_ip() {
  325.     $access_ip_address_array = get_valid_user_ip_address();
  326.     $ip_address = get_user_ip_address();
  327.     if (in_array(strtolower($ip_address), $access_ip_address_array)) {
  328.         return TRUE;
  329.     }
  330.     return FALSE;
  331. }
  332.  
  333. function get_valid_user_country() {
  334.     $access_country_array = array("bangladesh"); //N.B: provide a full country name in lower case ;
  335.     return $access_country_array;
  336. }
  337.  
  338. function get_valid_user_ip_address() {
  339.     $access_ip_address_array = array("202.4.107.210", "180.234.79.190", "103.35.168.22");
  340.     return $access_ip_address_array;
  341. }
  342.  
  343. function get_new_leave_application_count() {
  344.     $ci = &get_instance();
  345.     $ci->load->model("Leave_application_Model");
  346.     get_time_zone();
  347.     $is_show_status = FALSE;
  348.     $leave_application_by_is_show = $ci->Leave_application_Model->get_leave_application_by_is_show($is_show_status);
  349.     return !empty($leave_application_by_is_show) ? count($leave_application_by_is_show) : 0;
  350. }
  351.  
  352. function get_employee_image($employee_id) {
  353.     $ci = &get_instance();
  354.     $ci->load->model("Employee_Model");
  355.     $employee = $ci->Employee_Model->get_employee($employee_id);
  356.     return !empty($employee->employee_image) ? base_url($employee->employee_image) : get_default_employee_image();
  357. }
  358.  
  359. function get_company_logo() {
  360.     $ci = &get_instance();
  361.     $ci->load->model("Company_Model");
  362.     $company = $ci->Company_Model->get_company();
  363.     return !empty($company->company_logo) ? base_url($company->company_logo) : get_default_company_logo();
  364. }
  365.  
  366. function get_default_employee_image() {
  367.     return $default_employee_image = base_url('assets/uploads/employee_images/no_employee_image.jpg');
  368. }
  369.  
  370. function get_default_company_logo() {
  371.     return $default_company_logo = base_url('assets/uploads/company_logo/no_company_logo.png');
  372. }
  373.  
  374. function get_total_start_date($start_date) {
  375.     return $start_date = $start_date . ' 00:00:00';
  376. }
  377.  
  378. function get_total_end_date($end_date) {
  379.     return $end_date = $end_date . ' 23:59:59';
  380. }
  381.  
  382. function get_print_r($expression = NULL) {
  383.     echo '<pre>';
  384.     print_r($expression);
  385.     echo '</pre>';
  386.     exit;
  387. }