-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_address.php
executable file
·174 lines (171 loc) · 8.09 KB
/
update_address.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
if (!isset($_SESSION)) {
session_start();
} //this has to stay or CC/grad/senate, etc won't load right
//not a hotspot request, include the login info
include_once('vars/privateVar.php');
include_once('functions/functions.php');
if (empty($req_type) || $req_type != 'hotspot') {
//SSO integration
//sets $_SESSION['libSession] based on SAML and Alma attributes
//our SAML data does not return an expiration date, so I have used the API to gather that as part of the login process for this and EZProxy
include_once('functions/authenticationFunctions.php'); // Camila, uncomment this when you try to make this live tomorrow (and get rid o functions above??)
include_once('authenticateNew.php');
if (isset($_REQUEST['viewas'])) {
include($_SERVER['DOCUMENT_ROOT'] . '/webFiles/login/viewas.php');
}
} else {
//variables that are pulled from the URL sent by the General Electronic Service are in the parameters file along with other non-secret params
include_once('vars/parameters.php');
//if(!empty($_REQUEST['viewas'])){$pid = $_REQUEST['viewas'];}
?>
<html>
<head>
<style>
body,
p,
div {
font-family: Arial, Helvetica, sans-serif;
font-family: 'Open Sans', sans-serif;
background-color: transparent;
}
</style>
</head>
<body>
<?php
}
if (!empty($_REQUEST['state']) && !empty($states[$_REQUEST['state']])) {
$_REQUEST['state'] = $states[$_REQUEST['state']];
}
//user CURL to get record
$service_url = "https://api-na.hosted.exlibrisgroup.com/almaws/v1/users/{$pid}";
$patronResponse = getAlmaRecord($service_url, $queryParams);
$patronRecord = json_decode($patronResponse);
unset($patronResponse);
//this is all very ugly (done in a hurry). It should be cleaned up.
//we have a new address sent from the form.
if (!empty($_REQUEST['line1'])) {
$newAddress['preferred'] = true;
$newAddress['segment_type'] = "Internal";
for ($x = 1; $x <= 5; $x++) {
$lineName = "line{$x}";
$newAddress[$lineName] = !empty($_REQUEST[$lineName]) ? $_REQUEST[$lineName] : null;
}
$newAddress['city'] = !empty($_REQUEST['city']) ? $_REQUEST['city'] : null;
$newAddress['state_province'] = !empty($_REQUEST['state']) ? $_REQUEST['state'] : null;
$newAddress['postal_code'] = !empty($_REQUEST['zip']) ? $_REQUEST['zip'] : null;
$addressType['value'] = 'home';
$addressType['desc'] = 'Home';
$newAddress['address_type'][] = $addressType;
$newAddress['address_note'] = 'Added by request form.';
$addresses = $patronRecord->contact_info->address;
//$addresses = (array) $addresses;
$addressExists = 'no';
//convert our array to an object
$newAddress = (object) $newAddress;
if (isset($addresses) && is_array($addresses)) {
foreach ($addresses as $k => $v) {
//our Banner data is ...messy. It is quite possible we have a variation of their current address in there. I don't, however, want my match to be too fuzzy, as if they've just changed units within a complex, the 98% match might show as exisiting. Better too many addresses than not enough, right?
if ((strtoupper(preg_replace("/[^A-Za-z0-9 ]/", '', $v->line1)) == strtoupper(preg_replace("/[^A-Za-z0-9 ]/", '', $newAddress->line1))) && (empty($v->line2) || (strtoupper(preg_replace("/[^A-Za-z0-9 ]/", '', $v->line2)) == strtoupper(preg_replace("/[^A-Za-z0-9 ]/", '', $newAddress->line2)))) && (strtoupper(preg_replace("/[^A-Za-z0-9 ]/", '', $newAddress->city)) == strtoupper(preg_replace("/[^A-Za-z0-9 ]/", '', $v->city))) && (strtoupper(preg_replace("/[^A-Za-z0-9 ]/", '', $newAddress->state_province)) == strtoupper(preg_replace("/[^A-Za-z0-9 ]/", '', $v->state_province))) && (strtoupper(preg_replace("/[^A-Za-z0-9 ]/", '', $newAddress->postal_code)) == strtoupper(preg_replace("/[^A-Za-z0-9 ]/", '', $v->postal_code)))) {
unset($addresses[$k]);
$addresses[$k] = $newAddress;
$addressExists = 'yes';
} else {
if ($v->preferred == 1) {
$addresses[$k]->preferred = false;
}
}
unset($v);
}
if ($addressExists == 'no') {
$k = !empty($k) ? $k + 1 : 0;
//add it to the object
$addresses[$k] = $newAddress;
unset($k);
}
} else {
//we didn't have an address for the patron. Better add one.
$addresses[0] = $newAddress;
}
//get rid of the numeric keys on addresses
//$addresses = array_values($addresses);
// add it to the patronRecord object
$patronRecord->contact_info->{"address"} = $addresses;
}
$phNumbers = $patronRecord->contact_info->phone;
$newNumber['preferred'] = true;
$newNumber['preferred_sms'] = true;
$newNumber['segment_type'] = "Internal";
$newNumber['phone_number'] = !empty($_REQUEST['newPhone']) ? preg_replace('/[^0-9]/i', '', $_REQUEST['newPhone']) : null;
if (!empty($_REQUEST['usePhone'])) {
if (empty($newNumber['phone_number'])) {
$usePhoneNo = preg_replace('/[A-za-z ]/i', '', $_REQUEST['usePhone']);
$usePhoneNo = $usePhoneNo - 1;
$newNumber['phone_number'] = $_SESSION['woulib']['phones'][$usePhoneNo]['phone_number'];
}
$phoneType['value'] = 'mobile';
$phoneType['desc'] = 'Mobile';
$newNumber['phone_type'][] = $phoneType;
$numberExists = 'no';
$phones = (array) $phNumbers;
//convert our array to an object
$newNumber = (object) $newNumber;
if (!empty($phNumbers)) {
foreach ($phNumbers as $k => $v) {
if ($v->phone_number == $newNumber->phone_number) {
$phNumbers[$k] = $newNumber;
$numberExists = 'yes';
} else {
if ($v->preferred == 1) {
$phNumbers[$k]->preferred = false;
}
}
unset($v);
}
}
if ($numberExists == 'no') {
$k = !empty($k) ? $k + 1 : 0;
$phNumbers[$k] = $newNumber;
unset($k);
}
} else {
if (!isset($phNumbers)) {
//we didn't have a phone for the patron. Better add one.
$phNumbers[0] = $newNumber;
}
}
$patronRecord->contact_info->{"phone"} = $phNumbers;
//let's just not mess with user roles. By not including them in what we send back, we don't accidentally overwrite something
unset($patronRecord->user_role);
$patronRecord = json_encode($patronRecord);
//now update the record
$curl_response = putPatronRecord($patronRecord, $service_url, $queryParams);
$jsonResult = json_decode($curl_response, true);
unset($curl_response);
print '<div style="padding:2em;padding-bottom:0;">';
if ((empty($jsonResult['errorsExist']) || $jsonResult['errorsExist'] != true) && empty($jsonResult['web_service_result']['errorsExist'])) {
if (!empty($_REQUEST['line1'])) {
print "<strong>Preferred address updated to:</strong><br>";
print $newAddress->line1 . "<br>";
print !empty($newAddress->line2) ? $newAddress->line2 . "<br>" : '';
print $newAddress->city . ", " . $newAddress->state_province . " " . $newAddress->postal_code . "<br>";
}
if (!empty($_REQUEST['usePhone'])) {
print '<p>You will receive messages about this and other requests at the number:<strong>' . $newNumber->phone_number . '</strong></p>';
}
} else {
//bother.
print '<strong>There was an error updating your address or phone number:</strong><br> ';
foreach ($jsonResult['errorList']['error'] as $k => $v) {
print $v['errorMessage'] . '<br>';
unset($k, $v);
}
foreach ($jsonResult['web_service_result']['errorList'] as $k => $v) {
print $v['errorMessage'] . '<br>';
print $v['errorMessage'] . '<br>';
unset($k, $v);
}
}
print '</div>';
//now place the hold - we can do this even if the address update fails
include('placeHold.php');