'phone', 'parent_selector' => '#modal-generic', 'autoPlaceholder' => false, 'preferredCountries' => null, 'utilsScript' => '/js/jquery/intlTelInput.utils.js' ), $p_options ); switch(get_instance()->ion_auth->get_project_id()) { case 2602: $options['preferredCountries'] = array('us','th'); break; case 2612: $options['preferredCountries'] = array('us','id'); break; } $html = '$("input[name='.$options['field_name'].']", "'.$options['parent_selector'].'").intlTelInput({ autoPlaceholder: '.($options['autoPlaceholder'] ? 'true' : 'false').', utilsScript: "' . $options['utilsScript'] .'"'. ($options['preferredCountries'] ? ', preferredCountries: ["' . implode('","', $options['preferredCountries']) . '"]' : '') . ' });'; return $html; } /*NEEDED TO SHOEHORN SOMETHING IN TO MAKE A mysqli FUNCTION WORK IN DEV*/ if(!function_exists("mysql_real_escape_string") && function_exists("mysqli_real_escape_string")) { function mysql_real_escape_string($string, $link_id = NULL) { if(!$link_id) { $link_id = get_instance()->db->conn_id; } return mysqli_real_escape_string($link_id, $string); } } function generate_uuid() { $data = PHP_MAJOR_VERSION < 7 ? openssl_random_pseudo_bytes(16) : random_bytes(16); $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // Set version to 0100 $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // Set bits 6-7 to 10 return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); } function mime2ext($mime){ $all_mimes = '{"png":["image\/png","image\/x-png"],"bmp":["image\/bmp","image\/x-bmp","image\/x-bitmap","image\/x-xbitmap","image\/x-win-bitmap","image\/x-windows-bmp","image\/ms-bmp","image\/x-ms-bmp","application\/bmp","application\/x-bmp","application\/x-win-bitmap"],"gif":["image\/gif"],"jpeg":["image\/jpeg","image\/pjpeg"],"xspf":["application\/xspf+xml"],"vlc":["application\/videolan"],"wmv":["video\/x-ms-wmv","video\/x-ms-asf"],"au":["audio\/x-au"],"ac3":["audio\/ac3"],"flac":["audio\/x-flac"],"ogg":["audio\/ogg","video\/ogg","application\/ogg"],"kmz":["application\/vnd.google-earth.kmz"],"kml":["application\/vnd.google-earth.kml+xml"],"rtx":["text\/richtext"],"rtf":["text\/rtf"],"jar":["application\/java-archive","application\/x-java-application","application\/x-jar"],"zip":["application\/x-zip","application\/zip","application\/x-zip-compressed","application\/s-compressed","multipart\/x-zip"],"7zip":["application\/x-compressed"],"xml":["application\/xml","text\/xml"],"svg":["image\/svg+xml"],"3g2":["video\/3gpp2"],"3gp":["video\/3gp","video\/3gpp"],"mp4":["video\/mp4"],"m4a":["audio\/x-m4a"],"f4v":["video\/x-f4v"],"flv":["video\/x-flv"],"webm":["video\/webm","audio\/webm"],"aac":["audio\/x-acc"],"m4u":["application\/vnd.mpegurl"],"pdf":["application\/pdf","application\/octet-stream"],"pptx":["application\/vnd.openxmlformats-officedocument.presentationml.presentation"],"ppt":["application\/powerpoint","application\/vnd.ms-powerpoint","application\/vnd.ms-office","application\/msword"],"docx":["application\/vnd.openxmlformats-officedocument.wordprocessingml.document"],"xlsx":["application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application\/vnd.ms-excel"],"xl":["application\/excel"],"xls":["application\/msexcel","application\/x-msexcel","application\/x-ms-excel","application\/x-excel","application\/x-dos_ms_excel","application\/xls","application\/x-xls"],"xsl":["text\/xsl"],"mpeg":["video\/mpeg"],"mov":["video\/quicktime"],"avi":["video\/x-msvideo","video\/msvideo","video\/avi","application\/x-troff-msvideo"],"movie":["video\/x-sgi-movie"],"log":["text\/x-log"],"txt":["text\/plain"],"css":["text\/css"],"html":["text\/html"],"wav":["audio\/x-wav","audio\/wave","audio\/wav"],"xhtml":["application\/xhtml+xml"],"tar":["application\/x-tar"],"tgz":["application\/x-gzip-compressed"],"psd":["application\/x-photoshop","image\/vnd.adobe.photoshop"],"exe":["application\/x-msdownload"],"js":["application\/x-javascript"],"mp3":["audio\/mpeg","audio\/mpg","audio\/mpeg3","audio\/mp3"],"rar":["application\/x-rar","application\/rar","application\/x-rar-compressed"],"gzip":["application\/x-gzip"],"hqx":["application\/mac-binhex40","application\/mac-binhex","application\/x-binhex40","application\/x-mac-binhex40"],"cpt":["application\/mac-compactpro"],"bin":["application\/macbinary","application\/mac-binary","application\/x-binary","application\/x-macbinary"],"oda":["application\/oda"],"ai":["application\/postscript"],"smil":["application\/smil"],"mif":["application\/vnd.mif"],"wbxml":["application\/wbxml"],"wmlc":["application\/wmlc"],"dcr":["application\/x-director"],"dvi":["application\/x-dvi"],"gtar":["application\/x-gtar"],"php":["application\/x-httpd-php","application\/php","application\/x-php","text\/php","text\/x-php","application\/x-httpd-php-source"],"swf":["application\/x-shockwave-flash"],"sit":["application\/x-stuffit"],"z":["application\/x-compress"],"mid":["audio\/midi"],"aif":["audio\/x-aiff","audio\/aiff"],"ram":["audio\/x-pn-realaudio"],"rpm":["audio\/x-pn-realaudio-plugin"],"ra":["audio\/x-realaudio"],"rv":["video\/vnd.rn-realvideo"],"jp2":["image\/jp2","video\/mj2","image\/jpx","image\/jpm"],"tiff":["image\/tiff"],"eml":["message\/rfc822"],"pem":["application\/x-x509-user-cert","application\/x-pem-file"],"p10":["application\/x-pkcs10","application\/pkcs10"],"p12":["application\/x-pkcs12"],"p7a":["application\/x-pkcs7-signature"],"p7c":["application\/pkcs7-mime","application\/x-pkcs7-mime"],"p7r":["application\/x-pkcs7-certreqresp"],"p7s":["application\/pkcs7-signature"],"crt":["application\/x-x509-ca-cert","application\/pkix-cert"],"crl":["application\/pkix-crl","application\/pkcs-crl"],"pgp":["application\/pgp"],"gpg":["application\/gpg-keys"],"rsa":["application\/x-pkcs7"],"ics":["text\/calendar"],"zsh":["text\/x-scriptzsh"],"cdr":["application\/cdr","application\/coreldraw","application\/x-cdr","application\/x-coreldraw","image\/cdr","image\/x-cdr","zz-application\/zz-winassoc-cdr"],"wma":["audio\/x-ms-wma"],"vcf":["text\/x-vcard"],"srt":["text\/srt"],"vtt":["text\/vtt"],"ico":["image\/x-icon","image\/x-ico","image\/vnd.microsoft.icon"],"csv":["text\/x-comma-separated-values","text\/comma-separated-values","application\/vnd.msexcel"],"json":["application\/json","text\/json"]}'; $all_mimes = json_decode($all_mimes,true); foreach ($all_mimes as $key => $value) { if(array_search($mime,$value) !== false) return $key; } return false; } function format_s3_path($filename, $prefix = "", $base_path = "upload/full/") { $name = uniqid($prefix, TRUE); $extension = pathinfo($filename, PATHINFO_EXTENSION); return ($base_path . $name . "." . $extension); } //format_s3_path_new($tmpfilename, "media-$meeting_id", "zoom") function format_s3_path_new($filename, $prefix = "", $sub_folder = null, $base_path = "aha-new/") { $name = uniqid($prefix, TRUE); $extension = pathinfo($filename, PATHINFO_EXTENSION); $ci =& get_instance(); $project_id = $ci->ion_auth->get_project_id(); return ($base_path . "study-" . $project_id . "/" . ($sub_folder ? $sub_folder .'/' : '') . $name . "." . $extension); } function force_object($object_or_array, $skip_if_numeric_keys = FALSE) { $object = $object_or_array; if(is_array($object)) { $as_object = TRUE; if($skip_if_numeric_keys) { $as_object = FALSE; foreach($object as $oidx => $obj) { if(!is_numeric($oidx)) { $as_object = TRUE; } } } foreach($object as &$entry) { $entry = force_object($entry, $skip_if_numeric_keys); } unset($entry); if($as_object) { $object = (object)$object; } } return $object; } function make_phone_email_placeholder($phone) { return preg_replace('/[^\+0-9]/', '', $phone) . '@ahaconversations.com'; } function is_email_phone_placeholder($email) { return preg_match('/^[\+0-9]+\@ahaconversations.com$/', $email); } //tmobile is no longer allowing bitly so now we are going to our own function bitly_shorten($long_url, $access_token = BITLY_TOKEN, $domain = NULL) { return aha_shorten($long_url); /* $result = $long_url; $url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$access_token.'&longUrl='.urlencode($long_url).($domain ? '&domain='.$domain : ''); try { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $output = json_decode(curl_exec($ch)); if(isset($output) && isset($output->data) && isset($output->data->url)) { $result = $output->data->url; } else { throw new Exception("Unexpected output"); } } catch (Exception $e) { trigger_error("FAILED TO SHORTEN URL '$long_url': ".$e->getMessage()); } return $result; */ } function aha_shorten($long_url) { $ci =& get_instance(); $ci->load->library('AhaShortener'); return $ci->ahashortener->shorten($long_url); } function valid_phone($phone) { return (format_phone_system($phone) != NULL); } function format_phone_system($phone, $project_id = NULL) { $system_phone = NULL; if($phone) { try { $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance(); //TODO add project/account default country codes $num = $phoneUtil->parse($phone, "US"); $system_phone = $phoneUtil->format($num, \libphonenumber\PhoneNumberFormat::E164); } catch(Exception $e) { } } return $system_phone; } function format_activity_device_list($activity) { $device_list = array(); $ci =& get_instance(); if($activity->enable_device_desktop) { $device_list[] = $ci->lang->line('device-desktop'); } if($activity->enable_device_tablet) { $device_list[] = $ci->lang->line('device-tablet'); } if($activity->enable_device_mobile) { $device_list[] = $ci->lang->line('device-mobile'); } if($activity->enable_device_app) { $device_list[] = $ci->lang->line('device-mobile_app'); } if($activity->enable_device_sms) { $device_list[] = $ci->lang->line('device-mobile_sms'); } return ($device_list ? implode(', ', $device_list) : $ci->lang->line('none')); } function utcdate($time) { return gmdate('Y-m-d\TH:i:s', date_to_time($time)).'.000Z'; } function get_system_tz() { return date_default_timezone_get(); } function get_study_tz($project_id = NULL, $abbr = FALSE) { static $s_project_id = NULL; static $s_study_tz = NULL; if(!$s_study_tz || $project_id != $s_project_id) { $ci =& get_instance(); $ci->load->model('Project_model'); $s_study_tz = $ci->Project_model->get_timezone($project_id); $s_project_id = $project_id; } if($abbr) { $dt = new DateTime(); $dt->setTimeZone(new DateTimeZone($s_study_tz)); return $dt->format('T'); } return $s_study_tz; } function system_time_to_study_time($time = NULL, $study_tz = NULL) { $date = new DateTime(mysql_datetime($time)); try { $study_tz = new DateTimeZone($study_tz ? $study_tz : get_study_tz()); $date->setTimezone($study_tz); } finally { } return strtotime($date->format('Y-m-d H:i:s')); } function study_time_to_system_time($time, $study_tz = NULL) { $date = NULL; try { $study_tz = new DateTimeZone($study_tz ? $study_tz : get_study_tz()); $date = new DateTime(mysql_datetime($time), $study_tz); $date->setTimezone(new DateTimeZone(get_system_tz())); } catch(Exception $e) { $date = new DateTime($time); } return strtotime($date->format('Y-m-d H:i:s')); } function is_url($string) { return (filter_var($string, FILTER_VALIDATE_URL) !== FALSE); } function date_to_time($date) { $time = $date; //If it is not already numeri if(!is_numeric($date)) { $time = strtotime($date); } return $time; } function format_date($date) { $formatted_value = ''; if($date) { $formatted_value = date('m/d/Y', date_to_time($date)); } return $formatted_value; } function format_time($date) { $formatted_value = ''; if($date) { $formatted_value = date('g:ia', date_to_time($date)); } return $formatted_value; } function format_date_time($date) { $formatted_value = ''; if($date) { $formatted_value = date('m/d/Y H:i:s', date_to_time($date)); } return $formatted_value; } function friendly_date_time($date) { $formatted_value = ''; if($date) { $ts = date_to_time($date); try { $dt = format_date($ts); $nw = format_date(time()); if($dt == $nw) { $formatted_value = 'Today at '.date('g:ia', $ts); } else if($dt == format_date(strtotime('tomorrow'))) { $formatted_value = 'Tomorrow at '.date('g:ia', $ts); } else if(date('m', $ts) == date('m', time())) {//$days_diff < 30) { $formatted_value = date('l \t\h\e jS \a\t g:ia', $ts); } } catch(Exception $e) { trigger_error($e->getMessage()); } if(!$formatted_value) { $formatted_value = date('l, M jS \a\t g:ia', $dt); } } return $formatted_value; } function mysql_datetime($date = NULL) { if(!$date) { $date = time(); } if(!is_numeric($date)) { $date = strtotime($date); } return date('Y-m-d H:i:s', $date); } //trim_last to NULL to skip last name function format_name($user, $trim_last = TRUE) { $name = NULL; if($user) { if(is_numeric($user)) { $ci =& get_instance(); $user = $ci->ion_auth->user($user)->row(); } if($user) { $user = force_object($user); if(isset($user->name)) { $name = $user->name; } else { $first = $last = NULL; if(isset($user->first_name)) { $first = $user->first_name; $last = $user->last_name; } else if(isset($user->fname)) { $first = $user->fname; $last = $user->lname; } $name = $first . ($trim_last === NULL ? '' : (($first && $last ? ' ' : '') . ($trim_last ? substr($last, 0, 1) : $last))); } if($user && isset($user->id) && $user->id == 5129) { $name .= " (admin)"; } } } return $name; } if(!function_exists('ordinalize')) { function ordinalize($number) { $ends = ['th','st','nd','rd','th','th','th','th','th','th']; if ((($number % 100) >= 11) && (($number % 100) <= 13)) { return $number. 'th'; } return $number. $ends[$number % 10]; } } ", $nl_str); return $br_str; } if ( ! function_exists('random_string')) { function random_string($type = 'alnum', $len = 8, $friendly = FALSE) { $str = ''; if($len) { switch($type) { case 'basic' : $str = mt_rand(); break; case 'alnum' : case 'numeric' : case 'nozero' : case 'alpha' : switch ($type) { case 'alpha' : $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'numeric' : $pool = '0123456789'; break; case 'nozero' : $pool = '123456789'; break; } $str = ''; for ($i=0; $i < $len; $i++) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } break; case 'unique' : case 'md5' : $str = md5(uniqid(mt_rand())); break; case 'encrypt' : case 'sha1' : $CI =& get_instance(); $CI->load->helper('security'); $str = hash(uniqid(mt_rand(), TRUE), 'sha1'); break; } if($friendly) { do { $str = preg_replace("/[Oo0iIl15SZKk]/", "", $str); $str .= random_string($type, $len - strlen($str), $friendly); } while(strlen($str) < $len); } } return $str; } } function pluralize($num, $base_string, $include_num = TRUE) { //see system plural function for some more advanced checks return (($include_num ? "$num " : '') . $base_string . ($num == 1 ? '' : 's')); } set_header('X-SMTPAPI', '{"unique_args": {"aha-mid": "'.$message_id.'"}}'); } $result = parent::send(FALSE); if ($result) { if($message_id) { $CI =& get_instance(); $CI->load->model('Message_model'); $CI->Message_model->add_email_message_id($message_id, $this->_headers['Message-ID']); } $this->clear(); return TRUE; } else { trigger_error("send_withmessage is returning FALSE (message_id: $message_id)"); return FALSE; } } public function subject($subject) { $prepend = ""; if(defined('ENVIRONMENT_NO_PROD')) { if(ENVIRONMENT_NO_PROD) { $prepend = "[".ENVIRONMENT_NO_PROD."] "; } } $subject = $prepend . $subject; return parent::subject($subject); } } _log(self::EVENT_INFO, $area, $parameters); } public function delete($area, $parameters = NULL) { $this->_log(self::EVENT_DELETE, $area, $parameters); } public function modify($area, $parameters = NULL, $action = NULL) { $this->_log(self::EVENT_MODIFY, $area, $parameters, $action); } public function get_log($options = array()) { $options = array_merge( array( 'min_date' => mysql_datetime(strtotime('-1 day')), ), $options ); return $this->_get($options); } protected function _log($event, $area, $parameters = NULL, $action = NULL) { $user_id = $this->_get_current_user_id(); // $ip_address = $this->_get_current_ip_address(); $url = $this->_get_current_url(); $date = date('Y-m-d H:i:s'); $this->db->insert('event_log', array('url' => $url, 'user_id' => $user_id, /*'ip_address' => $ip_address,*/ 'event' => $event, 'area' => $area, 'parameters' => $parameters, 'action' => $action, 'created' => $date)); } protected function _get_current_user_id() { return $this->ion_auth->get_user_id(); } protected function _get_current_ip_address() { } protected function _get_current_url() { return $this->uri->uri_string(); } protected function _get($options) { $log = array(); $options = array_merge( array( 'min_id' => NULL, 'min_date' => NULL, 'max_date' => NULL, 'events' => NULL ), $options ); $this->db->select('event_log.*, CONCAT(users.first_name, " ", users.last_name) AS user_name, MAX(ug.project_id) AS project_id', FALSE); $this->db->from('event_log'); $this->db->join('users', 'users.id = event_log.user_id', 'left'); $this->db->join('users_groups ug', 'ug.user_id = users.id', 'left'); $this->db->group_by('event_log.id'); $this->db->order_by('event_log.id DESC'); if($options['min_id']) { $this->db->where('event_log.id >', $options['min_id']); } if($options['min_date']) { $this->db->where('event_log.created >', $options['min_date']); } if($options['max_date']) { $this->db->where('event_log.created <', $options['max_date']); } if($options['events']) { $this->db->where_in('event_log.event', $options['events']); } if($options['order_by']) { $this->db->order_by($options['order_by']); } $query = $this->db->get(); foreach($query->result() as $row) { $log[] = $row; } return $log; } }