Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function get_age($birthDate) {
- $birthDate = explode("/", $birthDate);
- //get age from date or birthdate
- $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? ((date("Y") - $birthDate[2]) - 1) : (date("Y") - $birthDate[2]));
- return $age;
- }
- function flash() {
- $ci = & get_instance();
- if ($ci->session->flashdata('msg')) {
- echo
- '<div class="alert alert-info alert-dismissible fade in" role="alert">
- <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>'
- . $ci->session->flashdata('msg') .
- '</div>';
- } else if ($ci->session->flashdata('error_msg')) {
- echo
- '<div class="alert alert-danger alert-dismissible fade in" role="alert">
- <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>'
- . $ci->session->flashdata('error_msg') .
- '</div>';
- }
- }
- function check_user($check_index = 'current_user') {
- $ci = & get_instance();
- return ($ci->session->userdata($check_index)) ? $ci->session->userdata($check_index) : false;
- }
- function check_front_user() {
- $ci = & get_instance();
- return ($ci->session->userdata('front_user')) ? $ci->session->userdata('front_user') : false;
- }
- function get_userdata($index) {
- $ci = & get_instance();
- return $ci->session->userdata($index) ? $ci->session->userdata($index) : false;
- }
- function php_thumb_image($url, $file, $width, $height, $crop = false, $fall_back_image) {
- $filename = $file != '' && file_exists($url . $file) ? $file : $fall_back_image;
- $path = base_url(substr($url, 2) . $filename);
- echo
- '
- <img src="' . base_url() . 'assets/phpthumb/phpThumb.php?src=' . urlencode($path) . '&w=' . $width . '&h=' . $height . '&zc=' . $crop . '">
- ';
- }
- function debug($data) {
- echo "<pre>";
- print_r($data);
- echo "</pre>";
- die;
- }
- function getBrowser() {
- $u_agent = $_SERVER['HTTP_USER_AGENT'];
- $bname = 'Unknown';
- $platform = 'Unknown';
- $version = "";
- //First get the platform?
- if (preg_match('/linux/i', $u_agent)) {
- $platform = 'linux';
- } elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
- $platform = 'mac';
- } elseif (preg_match('/windows|win32/i', $u_agent)) {
- $platform = 'windows';
- }
- // Next get the name of the useragent yes seperately and for good reason
- if (preg_match('/MSIE/i', $u_agent) && !preg_match('/Opera/i', $u_agent)) {
- $bname = 'Internet Explorer';
- $ub = "MSIE";
- } elseif (preg_match('/Firefox/i', $u_agent)) {
- $bname = 'Mozilla Firefox';
- $ub = "Firefox";
- } elseif (preg_match('/Chrome/i', $u_agent)) {
- $bname = 'Google Chrome';
- $ub = "Chrome";
- } elseif (preg_match('/Safari/i', $u_agent)) {
- $bname = 'Apple Safari';
- $ub = "Safari";
- } elseif (preg_match('/Opera/i', $u_agent)) {
- $bname = 'Opera';
- $ub = "Opera";
- } elseif (preg_match('/Netscape/i', $u_agent)) {
- $bname = 'Netscape';
- $ub = "Netscape";
- }
- // finally get the correct version number
- $known = array('Version', $ub, 'other');
- $pattern = '#(?<browser>' . join('|', $known) .
- ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
- if (!preg_match_all($pattern, $u_agent, $matches)) {
- // we have no matching number just continue
- }
- // see how many we have
- $i = count($matches['browser']);
- if ($i != 1) {
- //we will have two since we are not using 'other' argument yet
- //see if version is before or after the name
- if (strripos($u_agent, "Version") < strripos($u_agent, $ub)) {
- $version = $matches['version'][0];
- } else {
- $version = $matches['version'][1];
- }
- } else {
- $version = $matches['version'][0];
- }
- // check if we have a number
- if ($version == null || $version == "") {
- $version = "?";
- }
- return array(
- 'userAgent' => $u_agent,
- 'name' => $bname,
- 'version' => $version,
- 'platform' => $platform,
- 'pattern' => $pattern
- );
- }
- function get_user($id) {
- $ci = & get_instance();
- $q = $ci->db->get_where('tbl_user', array('id' => $id))->result_array();
- if ($q)
- return $q[0];
- else
- return false;
- }
- function segment($seg) {
- $ci = & get_instance();
- return $ci->uri->segment($seg);
- }
- function get_care_detail($care_type) {
- $ci = & get_instance();
- $q = $ci->db->get_where('tbl_care', array('id' => $care_type))->result_array();
- return $q[0];
- }
- function get_care() {
- $ci = & get_instance();
- $ci->db->order_by('service_by ASC');
- $q = $ci->db->get_where('tbl_care')->result_array();
- return $q;
- }
- function get_unread_ticket_count() {
- $ci = & get_instance();
- $ci->db->like('view', '0');
- $ci->db->from('tbl_tickets_history');
- return $ci->db->count_all_results();
- }
- function encrypt_decrypt($action, $string) {
- $output = false;
- $key = '!@#$%^&*';
- // initialization vector
- $iv = md5(md5($key));
- if ($action == 'encrypt') {
- $output = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, $iv);
- $output = base64_encode($output);
- } else if ($action == 'decrypt') {
- $output = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($string), MCRYPT_MODE_CBC, $iv);
- $output = rtrim($output, "");
- }
- return $output;
- }
- function home_flash() {
- $ci = & get_instance();
- if ($ci->session->flashdata('msg')) {
- echo '<script>$.jGrowl("' . $ci->session->flashdata('msg') . '")</script>';
- }
- }
- function set_flash($index, $msg) {
- $ci = & get_instance();
- $ci->session->set_flashdata($index, $msg);
- }
- function generateString() {
- $number = base64_encode(random_string('alnum', 20));
- $newstr = preg_replace('/[^a-zA-Z0-9\']/', '', $number);
- return substr($newstr, 0, 10); // return string of 10 random character
- }
- function swiftsend($param) {
- include_once APPPATH . 'third_party/swiftmailer/swift_required.php';
- $numSent = 0; // Var to store the number of successful email recipients
- if ($_SERVER['HTTP_HOST'] == 'localhost') {
- ini_set("SMTP", "ssl://smtp.gmail.com");
- ini_set("smtp_port", "465");
- $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', '465', 'ssl')
- ->setUsername(SWIFT_EMAIL)
- ->setPassword(SWIFT_PASS);
- } else {
- $transport = Swift_MailTransport::newInstance();
- }
- $mailer = Swift_Mailer::newInstance($transport);
- $message = Swift_Message::newInstance($param['subject'])
- ->setFrom($param['from'])
- ->setReplyTo($param['reply'])
- ->setBody($param['msg'], 'text/html');
- // Sending bulk email such that the people in the list will not be aware of eachother
- foreach ($param['recipients'] as $address => $name) {
- if (is_int($address)) {
- $message->setTo($name);
- } else {
- $message->setTo(array($address => $name));
- }
- $numSent += $mailer->send($message, $failedRecipients);
- }
- $return = array('sent' => $numSent, 'failed' => $failedRecipients);
- return (isset($param['return']) && $param['return']) ? $return : true;
- }
- function uniqueid($prefix, $length = 4, $search_table, $search_column) {
- $ci = &get_instance();
- $id = $prefix . substr(rand(1111111111, 9999999999), 0, $length);
- $checks = $ci->db->get_where($search_table, array($search_column => $id));
- if ($checks->num_rows() > 0)
- uniqueid($prefix, $length, $search_table, $search_column);
- else
- return $id;
- }
- function calDistance($inLatitude, $inLongitude, $outLatitude, $outLongitude, $unit) {
- if (empty($inLatitude) || empty($inLongitude) || empty($outLatitude) || empty($outLongitude))
- return 0;
- $url = "http://maps.googleapis.com/maps/api/directions/json?origin=$inLatitude,$inLongitude&destination=$outLatitude,$outLongitude&alternatives=true";
- $c = curl_init();
- curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($c, CURLOPT_URL, $url);
- $jsonResponse = curl_exec($c);
- curl_close($c);
- $dataset = json_decode($jsonResponse);
- $routes = $dataset->routes;
- if (!$dataset)
- return 0;
- if (!isset($dataset->routes[0]->legs[0]->distance->value))
- return 0;
- //sort the routes based on the distance
- // Code Reference: http://stackoverflow.com/questions/18574496/google-distance-matrix-json-shortest-path-php
- usort($routes, create_function('$a,$b', 'return intval($a->legs[0]->distance->value) - intval($b->legs[0]->distance->value);'));
- $distance = $routes[0]->legs[0]->distance->value;
- if ($unit == "K") {
- return round(($distance / 1000), 2); //kilometer
- } else if ($unit == "M") {
- return round(($distance * 0.000621371), 2); //miles
- } else {
- return round($distance, 2); //meter
- }
- }
- /*
- * Author: TheManish
- */
- function sendRegistrationSuccessEmail($cust_email, $cust_pass) {
- $ci = & get_instance();
- $emailData = array(
- 'email' => $cust_email,
- 'password' => $cust_pass
- );
- $email_template = $ci->load->view('emailer/_emailer_customer_registration', $emailData, true);
- // print($email_template);die;
- $subject = "Registration Confirmation - " . SITE_NAME;
- $param = array(
- 'from' => array(SITE_EMAIL => SITE_NAME),
- 'reply' => array(SITE_EMAIL => SITE_NAME),
- 'recipients' => array($cust_email),
- 'subject' => $subject,
- 'msg' => $email_template
- );
- swiftsend($param);
- }
- function get_page($slug) {
- $ci = & get_instance();
- $page = $ci->common_model->get_where('tbl_pages', array('slug' => $slug));
- if ($page)
- echo $page[0]['desc'];
- else
- echo "Slug Not Found: " . $slug;
- }
- function generateRandomString($length = 10) {
- $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $charactersLength = strlen($characters);
- $randomString = '';
- for ($i = 0; $i < $length; $i++) {
- $randomString .= $characters[rand(0, $charactersLength - 1)];
- }
- return $randomString;
- }
- function getAllCountryCodes() {
- $ci = &get_instance();
- $ci->load->helper('file');
- $json = read_file(APPPATH . 'third_party/country_calling_codes.json');
- $countryCodes = json_decode($json);
- usort($countryCodes, function($a, $b) {
- return $a->code > $b->code;
- });
- return $countryCodes;
- }
- function isAirportOrStation($location) {
- if (
- stripos($location, 'airport') !== false ||
- stripos($location, 'terminal') !== false ||
- stripos($location, 'train') !== false ||
- stripos($location, 'station') !== false) {
- return true;
- } else {
- return false;
- }
- }
- function isAirport($location) {
- if (
- (stripos($location, 'airport') !== false || stripos($location, 'terminal') !== false) &&
- stripos($location, 'station') === false) {
- return true;
- } else {
- return false;
- }
- }
- function isStation($location) {
- if (
- stripos($location, 'train') !== false ||
- stripos($location, 'station') !== false) {
- return true;
- } else {
- return false;
- }
- }
- function doDirectPayment($data) {
- // Set sandbox (test mode) to true/false.
- $sandbox = TRUE;
- // Set PayPal API version and credentials.
- $api_version = '85.0';
- $api_endpoint = $sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
- $api_username = $sandbox ? 'manish-facilitator_api1.digital-designinc.com' : 'LIVE_USERNAME_GOES_HERE';
- $api_password = $sandbox ? '8HX9ZPLN7FP7HZXJ' : 'LIVE_PASSWORD_GOES_HERE';
- $api_signature = $sandbox ? 'AGTq7y9-jRQtnp9vTs0G2WMk.fM9AGrs.oM6Xo.yS1uxhHz8Olnim7na' : 'LIVE_SIGNATURE_GOES_HERE';
- // Store request params in an array
- $request_params = array
- (
- 'METHOD' => 'DoDirectPayment',
- 'USER' => $api_username,
- 'PWD' => $api_password,
- 'SIGNATURE' => $api_signature,
- 'VERSION' => $api_version,
- 'PAYMENTACTION' => 'Sale',
- 'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
- 'CREDITCARDTYPE' => $data['CREDITCARDTYPE'],
- 'ACCT' => $data['ACCT'],
- 'EXPDATE' => $data['EXPDATE'],
- 'CVV2' => $data['CVV2'],
- 'FIRSTNAME' => $data['FIRSTNAME'],
- 'LASTNAME' => $data['LASTNAME'],
- 'STREET' => $data['STREET'],
- 'CITY' => $data['CITY'],
- 'STATE' => $data['STATE'],
- 'COUNTRYCODE' => 'UK',
- 'ZIP' => $data['ZIP'],
- 'AMT' => $data['AMT'],
- 'CURRENCYCODE' => 'GBP',
- 'DESC' => $data['DESC']
- );
- // Loop through $request_params array to generate the NVP string.
- $nvp_string = '';
- foreach ($request_params as $var => $val) {
- $nvp_string .= '&' . $var . '=' . urlencode($val);
- }
- // Send NVP string to PayPal and store response
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_VERBOSE, 1);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($curl, CURLOPT_TIMEOUT, 30);
- curl_setopt($curl, CURLOPT_URL, $api_endpoint);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);
- $result = curl_exec($curl);
- curl_close($curl);
- // Parse the API response
- $nvp_response_array = NVPToArray($result);
- debug($nvp_response_array);
- return $nvp_response_array;
- }
- // Function to convert NTP string to an array
- function NVPToArray($NVPString)
- {
- $proArray = array();
- while(strlen($NVPString))
- {
- // name
- $keypos= strpos($NVPString,'=');
- $keyval = substr($NVPString,0,$keypos);
- // value
- $valuepos = strpos($NVPString,'&') ? strpos($NVPString,'&'): strlen($NVPString);
- $valval = substr($NVPString,$keypos+1,$valuepos-$keypos-1);
- // decoding the respose
- $proArray[$keyval] = urldecode($valval);
- $NVPString = substr($NVPString,$valuepos+1,strlen($NVPString));
- }
- return $proArray;
- }
Add Comment
Please, Sign In to add comment