Update mfa_totp.php (#6916)
[openemr.git] / interface / practice / address_verify.php
blobe1df234eafb42a07fe36dc1fba35c182cc98c13b
1 <?php
3 /*
4 * Used in demographics edit to check address with USPS Web API
5 * originally under MIT License
6 * https://packagist.org/packages/binarydata/usps-php-api
8 * @package OpenEMR
9 * @link https://www.open-emr.org
10 * @author Vincent Gabriel
11 * @author stephen waite <stephen.waite@cmsvt.com>
12 * @copyright Copyright (c) 2012 Vincent Gabriel
13 * @copyright Copyright (c) 2022 stephen waite <stephen.waite@cmsvt.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once("../globals.php");
19 use OpenEMR\Core\Header;
20 use OpenEMR\USPS\USPSAddress;
21 use OpenEMR\USPS\USPSAddressVerify;
23 // Initiate and set the username provided from usps
24 $verify = new USPSAddressVerify($GLOBALS['usps_webtools_username']);
26 // Create new address object and assign the properties
27 // apparently the order you assign them is important so make sure
28 // to set them as the example below
29 $address = new USPSAddress();
30 //$address->setFirmName('Apartment');
31 $address->setApt($_GET['address1']);
32 $address->setAddress($_GET['address2']);
33 $address->setCity($_GET['city']);
34 $address->setState($_GET['state']);
35 $address->setZip5($_GET['zip5']);
36 $address->setZip4($_GET['zip4']);
38 //print_r($address);
40 // Add the address object to the address verify class
41 $verify->addAddress($address);
43 // Perform the request and return resultFset
44 //print_r($verify->verify());
45 $verify->verify();
47 $response_array = $verify->getArrayResponse();
49 //var_dump($verify->isError());
51 // See if it was successful
53 $output = '<!DOCTYPE html><html>';
54 $output .= Header::setupHeader([], false);
55 $output .= "<body class='text-left'>
56 <div class='container'>
57 <p>";
59 if ($verify->isSuccess()) {
60 $address_array = $response_array['AddressValidateResponse']['Address'];
62 // remove attributes array at end of response address array
63 $removed = array_pop($address_array);
65 // usps Address1 is for apt/suite so need to handle their special response
66 if (!array_key_exists('Address1', $address_array)) {
67 $address_array['Address1'] = $address_array['Address2'];
68 $address_array['Address2'] = '';
71 // sort for decent display except pesky zip4 :)
72 ksort($address_array);
74 foreach ($address_array as $key => $value) {
75 if (($_GET[strtolower($key)] ?? null) != $value) {
76 $output .= "<div class='text-danger'>";
77 } else {
78 $output .= "<div class='text-success'>";
80 $output .= text($key) . ": " . text($value) . "</div>";
82 //$output = var_dump($response_array);
83 } else {
84 $output .= "<div class='text-danger'>";
85 $output .= 'Error: ' . text($verify->getErrorMessage()) . "</div>";
88 $output .= "</div></body></html>";
90 echo $output;