12 function Match_Phone_Regex($phone) {
28 $regexPhone =
'/(?:[2-9]\d{2}|\([2-9]\d{2}\))[ -]?[2-9]\d{2}[ -]?\d{4}/';
30 if (preg_match($regexPhone, $phone)) {
48 function Format_Phone_Dashes($phone) {
50 $phone = preg_replace(
"/[^0-9]/",
"", $phone);
51 $length = strlen($phone);
55 return preg_replace(
"/([0-9]{3})([0-9]{4})/",
"$1-$2", $phone);
58 return preg_replace(
"/([0-9]{3})([0-9]{3})([0-9]{4})/",
"$1-$2-$3", $phone);
79 function Date_In_Range($datechk, $datefmt =
'Y-m-d', $mindate =
'12/13/1901', $maxdate =
'') {
81 # set a timezone for strtotime 82 # validate chkdate is set, is convertable by strtotime, is within given range 83 date_default_timezone_set(
'UTC');
85 $mindate = (!empty($mindate) && ($st = strtotime($mindate)) ? $st : strtotime(
'1901-12-31')); #
default 12/31/1901
86 $maxdate = (!empty($maxdate) && ($st = strtotime($maxdate)) ? $st : time()); #
default now
89 if (!empty($datechk) && ($st = strtotime($datechk)) && $st > $mindate && $st < $maxdate) {
90 return date($datefmt, $st);
126 function FormatMIR($MIR, $Ml, $reqMIR, $datefmt =
'Y-m-d', $phones =
'flat', $noEmpty =
false, $BizFNdot =
'') {
151 $rmlist = array(
"#",
"&",
"/",
"%",
",",
":",
"=",
"?",
"'");
153 # prefer HCU email, as it tends to be kept more current than core 154 $MIR[
'email'] = validateEmail($Ml) ? $Ml : HCU_array_key_value(
'email', $MIR);
160 $MIR[
'email'] = str_replace($rmlist,
"", $MIR[
'email']);
162 if (!(HCU_array_key_value(
"email", $MIR) && ($MIR[
"email"] = preg_replace(
'/\s/',
'', $MIR[
"email"])) &&
163 validateEmail($MIR[
"email"]) )) {
164 unset($MIR[
"email"]);
179 foreach ($scrubs as $key) {
180 $MIR[$key] = str_replace($rmlist,
"", HCU_array_key_value($key, $MIR));
182 # default country code to US. Assume CU will specify for other countries 183 if (trim($MIR[
'cc']) ==
'') {
187 if (trim($MIR[
'class']) ==
'') {
188 # Assume business class if lastname w/o firstname 189 # Some cores send business name as lastname w/empty firstname 190 # but can't (or don't) send class. 192 # GetMemberInfo / _RetrieveMemberInfo sets default class 193 # to empty string if it is not set by the core. 194 if (trim($MIR[
'firstname']) ==
'' && trim($MIR[
'lastname']) <>
'') {
197 $MIR[
'class'] =
'P'; #
default to personal account
200 switch (strtolower($BizFNdot)) {
202 # Some SSO partners require firstname / lastname even for business. 203 # If this is a business account with first name empty, lastname present 204 # and BizFNdot =='dot', fill firstname with a dot so we can connect 205 if (empty($MIR[
'firstname']) && !empty($MIR[
'lastname']) &&
206 in_array ( $MIR[
'class'] , array (
'B',
'T') ) ) {
207 $MIR[
'firstname'] =
'.';
211 # Some SSO allow empty firstname for business. 212 # If this is a business account with first name empty, lastname present 213 # and BizFNdot == 'pass', clear firstname from the 'required values' list 214 if (empty($MIR[
'firstname']) && !empty($MIR[
'lastname']) &&
215 in_array ( $MIR[
'class'] , array (
'B',
'T') ) ) {
216 unset($reqMIR[
'firstname']);
223 if (! (HCU_array_key_value(
"state", $MIR) && ctype_alpha($MIR[
"state"]))) {
227 if (!(HCU_array_key_value(
"zip", $MIR) && ($MIR[
"zip"] = str_replace([
" ",
"-"],
'', $MIR[
"zip"])) &&
228 ctype_digit($MIR[
"zip"]) && in_array(strlen($MIR[
"zip"]),[5,9])) ) {
232 if (! (HCU_array_key_value(
"ssn", $MIR) &&
233 ($MIR[
"ssn"] = str_replace([
" ",
"-"],
'', $MIR[
"ssn"])) && ctype_digit($MIR[
"ssn"]) && strlen($MIR[
'ssn']) == 9) ){
237 if ( ! HCU_array_key_value(
'dob', $MIR) ) {
240 $MIR[
'dob'] = Date_In_Range(HCU_array_key_value(
'dob', $MIR),
'Y-m-d',
'12/31/1901', time());
245 'homephone' =>
'HomePhone',
246 'cellphone' =>
'CellPhone',
247 'workphone' =>
'WorkPhone',
251 foreach ($phoneorder as $key => $name) {
252 # Warning... Match_Phone_Regex requires length 10 253 # not sure if this will be a problem or not 254 # leaving the length 7 code in place until we determine 255 # it is safe to remove 256 if (!(HCU_array_key_value($key, $MIR) && ($MIR[$key] = preg_replace(
'/\D/',
'', $MIR[$key])) &&
257 in_array(strlen($MIR[$key]),[7,10]) && Match_Phone_Regex($MIR[$key])) ) {
262 # fax included in the cleansing above, 263 # but not formatted or used to set a contact phone below 264 unset($phoneorder[
'fax']);
266 if ($phones ==
'flat') {
267 foreach($phoneorder as $key => $name) {
268 $MIR[
'phone'] = HCU_array_key_value($key, $MIR); # digits only
269 if (trim($MIR[
'phone']) !=
'') {
273 } elseif ($phones ==
'split') {
274 foreach($phoneorder as $key => $name) {
275 switch (strlen(HCU_array_key_value($key, $MIR))) {
278 'area' => substr($MIR[$key], 0, 3),
279 'pre' => substr($MIR[$key], 3, 3),
280 'num' => substr($MIR[$key], 6, 4)];
284 'pre' => substr($MIR[$key], 0, 3),
285 'num' => substr($MIR[$key], 3, 4)];
292 } elseif ($phones ==
'named') {
294 'homephone' =>
'Home',
295 'cellphone' =>
'Cell',
296 'workphone' =>
'Work' 298 $MIR[
'phonenumbers'] = [];
300 foreach ($phoneorder as $key => $name) {
301 switch (strlen(HCU_array_key_value($key, $MIR))) {
304 $MIR[
'phonenumbers'][] = [
305 'number' => Format_Phone_Dashes($MIR[$key]),
315 } elseif ($phones ==
'shortname') {
316 # shortname setting is for Allied 317 # shorter names, include isTextCapable, unset phonenumbers array if empty 319 'homephone' => [
'phname' =>
'Home',
'isTextCapable' =>
false],
320 'cellphone' => [
'phname' =>
'Cell',
'isTextCapable' =>
true],
321 'workphone' => [
'phname' =>
'Work',
'isTextCapable' =>
false]
324 $MIR[
'phonenumbers'] = [];
326 foreach ($phoneorder as $key => $settings) {
327 switch (strlen(HCU_array_key_value($key, $MIR))) {
330 $MIR[
'phonenumbers'][] = [
331 'number' => $MIR[$key],
332 'name' => $settings[
'phname'],
333 'isTextCapable' => $settings[
'isTextCapable']
342 if (!count($MIR[
'phonenumbers'])) {
343 unset($MIR[
'phonenumbers']);
350 foreach(array_keys($MIR) as $key) {
351 if ( (is_array($MIR[$key]) && !count($MIR[$key])) ||
352 ( !is_array($MIR[$key]) && trim($MIR[$key]) ==
false) ) {
358 $missing = array_diff_key($reqMIR, $MIR);
359 if (
sizeof($missing)) {
360 throw new Exception(
"Incomplete Member Info (" . join(
", ", array_keys($missing)) .
")");
362 $return[
'status'][
'response'] =
true;
363 $return[
'status'][
'message'] =
'Success';
364 $return[
'data'] = $MIR;
365 }
catch (Exception $e) {
366 $return[
'status'][
'response'] =
false;
367 $return[
'status'][
'message'] = $e->getMessage();
368 $return[
'data'] = array();