|
1
|
|
|
<?php |
|
2
|
|
|
elgg_ws_expose_function( |
|
3
|
|
|
"profile.get", |
|
4
|
|
|
"get_api_profile", |
|
5
|
|
|
array("id" => array('type' => 'string')), |
|
6
|
|
|
'provide user GUID number and all profile information is returned', |
|
7
|
|
|
'GET', |
|
8
|
|
|
false, |
|
9
|
|
|
false |
|
10
|
|
|
); |
|
11
|
|
|
|
|
12
|
|
|
elgg_ws_expose_function( |
|
13
|
|
|
"get.profile", |
|
14
|
|
|
"get_api_profile", |
|
15
|
|
|
array("id" => array('type' => 'string')), |
|
16
|
|
|
'provide user GUID number and all profile information is returned', |
|
17
|
|
|
'GET', |
|
18
|
|
|
false, |
|
19
|
|
|
false |
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
elgg_ws_expose_function( |
|
23
|
|
|
"get.profile.by.gcid", |
|
24
|
|
|
"get_api_profile_gcid", |
|
25
|
|
|
array("gcid" => array('type' => 'string')), |
|
26
|
|
|
'provide user GUID number and all profile information is returned', |
|
27
|
|
|
'GET', |
|
28
|
|
|
false, |
|
29
|
|
|
false |
|
30
|
|
|
); |
|
31
|
|
|
|
|
32
|
|
|
elgg_ws_expose_function( |
|
33
|
|
|
"profile.update", |
|
34
|
|
|
"profileUpdate", |
|
35
|
|
|
array("id" => array('type' => 'string'), "data" => array('type'=>'string')), |
|
36
|
|
|
'update a user profile based on id passed', |
|
37
|
|
|
'POST', |
|
38
|
|
|
true, |
|
39
|
|
|
false |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
elgg_ws_expose_function( |
|
43
|
|
|
"profile.create", |
|
44
|
|
|
"profileCreate", |
|
45
|
|
|
array("data" => array('type'=>'string')), |
|
46
|
|
|
'Create a new user profile, issue a password reset on the newly created profile and pre-populate profile fields based on data passed in. Returns guid of newly created user', |
|
47
|
|
|
'POST', |
|
48
|
|
|
true, |
|
49
|
|
|
false |
|
50
|
|
|
); |
|
51
|
|
|
function get_api_profile_gcid($gcid){ |
|
52
|
|
|
if (!elgg_is_active_plugin('pleio')) { |
|
53
|
|
|
return "pleio mod is not active and there is no openid function"; |
|
54
|
|
|
} |
|
55
|
|
|
$dbprefix = elgg_get_config("dbprefix"); |
|
56
|
|
|
|
|
57
|
|
|
$result = get_data_row("SELECT * FROM {$dbprefix}users_entity WHERE pleio_guid = $gcid"); |
|
58
|
|
|
|
|
59
|
|
|
if ($result) |
|
|
|
|
|
|
60
|
|
|
return get_api_profile($result->guid); |
|
61
|
|
|
else |
|
62
|
|
|
return "no user found"; |
|
63
|
|
|
} |
|
64
|
|
|
function get_api_profile($id) |
|
65
|
|
|
{ |
|
66
|
|
|
$user_entity = getUserFromID($id); |
|
67
|
|
|
if (!$user_entity) { |
|
68
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$dbprefix = elgg_get_config("dbprefix"); |
|
72
|
|
|
|
|
73
|
|
|
$result = get_data_row("SELECT * FROM {$dbprefix}users_entity WHERE guid = $user_entity->guid"); |
|
74
|
|
|
|
|
75
|
|
|
$user['id'] = $user_entity->guid; |
|
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
$user['pleioID'] = $result->pleio_guid; |
|
78
|
|
|
|
|
79
|
|
|
$user['username'] = $user_entity->username; |
|
80
|
|
|
|
|
81
|
|
|
//get and store user display name |
|
82
|
|
|
$user['displayName'] = $user_entity->name; |
|
83
|
|
|
|
|
84
|
|
|
$user['email'] = $user_entity->email; |
|
85
|
|
|
|
|
86
|
|
|
//get and store URL for profile |
|
87
|
|
|
$user['profileURL'] = $user_entity->getURL(); |
|
88
|
|
|
|
|
89
|
|
|
//get and store URL of profile avatar |
|
90
|
|
|
$user['iconURL'] = $user_entity->geticon(); |
|
91
|
|
|
|
|
92
|
|
|
$user['jobTitle'] = $user_entity->job; |
|
93
|
|
|
|
|
94
|
|
|
$user['department'] = $user_entity->department; |
|
95
|
|
|
|
|
96
|
|
|
$user['telephone'] = $user_entity->phone; |
|
97
|
|
|
|
|
98
|
|
|
$user['mobile'] = $user_entity->mobile; |
|
99
|
|
|
|
|
100
|
|
|
$user['Website'] = $user_entity->website; |
|
101
|
|
|
|
|
102
|
|
|
$user['jobTitleFr'] = $user_entity->jobfr; |
|
103
|
|
|
|
|
104
|
|
|
$user['streetAddress'] = $user_entity->streetaddress; |
|
105
|
|
|
|
|
106
|
|
|
$user['city'] = $user_entity->city; |
|
107
|
|
|
|
|
108
|
|
|
$user['province'] = $user_entity->province; |
|
109
|
|
|
|
|
110
|
|
|
$user['postalCode'] = $user_entity->postalcode; |
|
111
|
|
|
|
|
112
|
|
|
$user['country'] = $user_entity->country; |
|
113
|
|
|
|
|
114
|
|
|
if ($user_entity->facebook) { |
|
115
|
|
|
$user['links']['facebook'] = "http://www.facebook.com/".$user_entity->facebook; |
|
116
|
|
|
} |
|
117
|
|
|
if ($user_entity->google) { |
|
118
|
|
|
$user['links']['google'] = "http://www.google.com/".$user_entity->google; |
|
119
|
|
|
} |
|
120
|
|
|
if ($user_entity->github) { |
|
121
|
|
|
$user['links']['github'] = "https://github.com/".$user_entity->github; |
|
122
|
|
|
} |
|
123
|
|
|
if ($user_entity->twitter) { |
|
124
|
|
|
$user['links']['twitter'] = "https://twitter.com/".$user_entity->twitter; |
|
125
|
|
|
} |
|
126
|
|
|
if ($user_entity->linkedin) { |
|
127
|
|
|
$user['links']['linkedin'] = "http://ca.linkedin.com/in/".$user_entity->linkedin; |
|
128
|
|
|
} |
|
129
|
|
|
if ($user_entity->pinterest) { |
|
130
|
|
|
$user['links']['pinterest'] = "http://www.pinterest.com/".$user_entity->pinterest; |
|
131
|
|
|
} |
|
132
|
|
|
if ($user_entity->tumblr) { |
|
133
|
|
|
$user['links']['tumblr'] = "https://www.tumblr.com/blog/".$user_entity->tumblr; |
|
134
|
|
|
} |
|
135
|
|
|
if ($user_entity->instagram) { |
|
136
|
|
|
$user['links']['instagram'] = "http://instagram.com/".$user_entity->instagram; |
|
137
|
|
|
} |
|
138
|
|
|
if ($user_entity->flickr) { |
|
139
|
|
|
$user['links']['flickr'] = "http://flickr.com/".$user_entity->flickr; |
|
140
|
|
|
} |
|
141
|
|
|
if ($user_entity->youtube) { |
|
142
|
|
|
$user['links']['youtube'] = "http://www.youtube.com/".$user_entity->youtube; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
//////////////////////////////////////////////////////////////////////////////////// |
|
146
|
|
|
//about me |
|
147
|
|
|
//////////////////////////////////////////////////////////////////////// |
|
148
|
|
|
$aboutMeMetadata = elgg_get_metadata(array('guids'=>array($user['id']),'limit'=>0,'metadata_names'=>array('description'))); |
|
149
|
|
|
|
|
150
|
|
|
if ($aboutMeMetadata[0]->access_id==2) { |
|
151
|
|
|
$user['about_me'] = $aboutMeMetadata[0]->value; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
///////////////////////////////////////////////////////////////////////////////// |
|
155
|
|
|
//eductation |
|
156
|
|
|
////////////////////////////////////////////////////////////////////// |
|
157
|
|
|
$eductationEntity = elgg_get_entities(array( |
|
158
|
|
|
'owner_guid'=>$user['id'], |
|
159
|
|
|
'subtype'=>'education', |
|
160
|
|
|
'type' => 'object', |
|
161
|
|
|
'limit' => 0 |
|
162
|
|
|
)); |
|
163
|
|
|
$i=0; |
|
164
|
|
|
foreach ($eductationEntity as $school) { |
|
165
|
|
|
if ($school->access_id==2) { |
|
166
|
|
|
$user['education']['item_'.$i]['school_name'] = $school->school; |
|
167
|
|
|
|
|
168
|
|
|
$user['education']['item_'.$i]['start_date'] = buildDate($school->startdate, $school->startyear); |
|
169
|
|
|
|
|
170
|
|
View Code Duplication |
if ($school->ongoing == "false") { |
|
171
|
|
|
$user['education']['item_'.$i]['end_date'] = buildDate($school->enddate, $school->endyear); |
|
172
|
|
|
} else { |
|
173
|
|
|
$user['education']['item_'.$i]['end_date'] = "present/actuel"; |
|
174
|
|
|
} |
|
175
|
|
|
$user['education']['item_'.$i]['degree'] = $school->degree; |
|
176
|
|
|
$user['education']['item_'.$i]['field_of_study'] = $school->field; |
|
177
|
|
|
$i++; |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
//////////////////////////////////////////////////////// |
|
181
|
|
|
//experience |
|
182
|
|
|
////////////////////////////////////// |
|
183
|
|
|
$experienceEntity = elgg_get_entities(array( |
|
184
|
|
|
'owner_guid'=>$user['id'], |
|
185
|
|
|
'subtype'=>'experience', |
|
186
|
|
|
'type' => 'object', |
|
187
|
|
|
'limit' => 0 |
|
188
|
|
|
)); |
|
189
|
|
|
usort($experienceEntity, "sortDate"); |
|
190
|
|
|
$i=0; |
|
191
|
|
|
foreach ($experienceEntity as $job) { |
|
192
|
|
|
if ($job->access_id == 2) { |
|
193
|
|
|
$user['experience']['item_'.$i]['job_title'] = $job->title; |
|
194
|
|
|
$user['experience']['item_'.$i]['organization'] = $job->organization; |
|
195
|
|
|
$user['experience']['item_'.$i]['start_date'] = buildDate($job->startdate, $job->startyear); |
|
196
|
|
View Code Duplication |
if ($job->ongoing == "false") { |
|
197
|
|
|
$user['experience']['item_'.$i]['end_date'] = buildDate($job->enddate, $job->endyear); |
|
198
|
|
|
} else { |
|
199
|
|
|
$user['experience']['item_'.$i]['end_date'] = "present/actuel"; |
|
200
|
|
|
} |
|
201
|
|
|
$user['experience']['item_'.$i]['responsibilities'] = $job->responsibilities; |
|
202
|
|
|
|
|
203
|
|
|
$j = 0; |
|
204
|
|
|
if (is_array($job->colleagues)) { |
|
205
|
|
|
foreach ($job->colleagues as $friend) { |
|
206
|
|
|
$friendEntity = get_user($friend); |
|
207
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["id"] = $friendEntity->guid; |
|
208
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["username"] = $friendEntity->username; |
|
209
|
|
|
|
|
210
|
|
|
//get and store user display name |
|
211
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["displayName"] = $friendEntity->name; |
|
212
|
|
|
|
|
213
|
|
|
//get and store URL for profile |
|
214
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["profileURL"] = $friendEntity->getURL(); |
|
215
|
|
|
|
|
216
|
|
|
//get and store URL of profile avatar |
|
217
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["iconURL"] = $friendEntity->geticon(); |
|
|
|
|
|
|
218
|
|
|
$j++; |
|
219
|
|
|
} |
|
220
|
|
|
} elseif (!is_null($job->colleagues)) { |
|
221
|
|
|
$friendEntity = get_user($job->colleagues); |
|
222
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["id"] = $friendEntity->guid; |
|
223
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["username"] = $friendEntity->username; |
|
224
|
|
|
|
|
225
|
|
|
//get and store user display name |
|
226
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["displayName"] = $friendEntity->name; |
|
227
|
|
|
|
|
228
|
|
|
//get and store URL for profile |
|
229
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["profileURL"] = $friendEntity->getURL(); |
|
230
|
|
|
|
|
231
|
|
|
//get and store URL of profile avatar |
|
232
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["iconURL"] = $friendEntity->geticon(); |
|
|
|
|
|
|
233
|
|
|
} |
|
234
|
|
|
$i++; |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
|
|
///////////////////////////////////////////////////////// |
|
238
|
|
|
//Skills |
|
239
|
|
|
/////////////////////////////////////////////////////// |
|
240
|
|
|
elgg_set_ignore_access(true); |
|
241
|
|
|
if ($user_entity->skill_access == ACCESS_PUBLIC) { |
|
242
|
|
|
$skillsEntity = elgg_get_entities(array( |
|
243
|
|
|
'owner_guid'=>$user['id'], |
|
244
|
|
|
'subtype'=>'MySkill', |
|
245
|
|
|
'type' => 'object', |
|
246
|
|
|
'limit' => 0 |
|
247
|
|
|
)); |
|
248
|
|
|
} |
|
249
|
|
|
$i=0; |
|
250
|
|
View Code Duplication |
foreach ($skillsEntity as $skill) { |
|
|
|
|
|
|
251
|
|
|
$user['skills']['item_'.$i]['skill'] = $skill->title; |
|
252
|
|
|
$j = 0; |
|
253
|
|
|
if (is_array($skill->endorsements)) { |
|
254
|
|
|
foreach ($skill->endorsements as $friend) { |
|
255
|
|
|
$friendEntity = get_user($friend); |
|
256
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["id"] = $friendEntity->guid; |
|
257
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["username"] = $friendEntity->username; |
|
258
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["displayName"] = $friendEntity->name; |
|
259
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["profileURL"] = $friendEntity->getURL(); |
|
260
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["iconURL"] = $friendEntity->geticon(); |
|
|
|
|
|
|
261
|
|
|
$j++; |
|
262
|
|
|
} |
|
263
|
|
|
} elseif (!is_null($skill->endorsements)) { |
|
264
|
|
|
$friendEntity = get_user($skill->endorsements); |
|
265
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["id"] = $friendEntity->guid; |
|
266
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["username"] = $friendEntity->username; |
|
267
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["displayName"] = $friendEntity->name; |
|
268
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["profileURL"] = $friendEntity->getURL(); |
|
269
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["iconURL"] = $friendEntity->geticon(); |
|
|
|
|
|
|
270
|
|
|
} |
|
271
|
|
|
$i++; |
|
272
|
|
|
} |
|
273
|
|
|
elgg_set_ignore_access(false); |
|
274
|
|
|
|
|
275
|
|
|
////////////////////////////////////////////////////////////////////////////////////// |
|
276
|
|
|
//portfolio |
|
277
|
|
|
/////////////////////////////////////////////////////////////////// |
|
278
|
|
|
$portfolioEntity = elgg_get_entities(array( |
|
279
|
|
|
'owner_guid'=>$user['id'], |
|
280
|
|
|
'subtype'=>'portfolio', |
|
281
|
|
|
'type' => 'object', |
|
282
|
|
|
'limit' => 0 |
|
283
|
|
|
)); |
|
284
|
|
|
$i=0; |
|
285
|
|
|
foreach ($portfolioEntity as $portfolio) { |
|
286
|
|
|
if ($portfolio->access_id == 2) { |
|
287
|
|
|
$user['portfolio']['item_'.$i]['title'] = $portfolio->title; |
|
288
|
|
|
$user['portfolio']['item_'.$i]['link'] = $portfolio->link; |
|
289
|
|
View Code Duplication |
if ($portfolio->datestamped == "on") { |
|
290
|
|
|
$user['portfolio']['item_'.$i]['date'] = $portfolio->publishdate; |
|
291
|
|
|
} |
|
292
|
|
|
$user['portfolio']['item_'.$i]['description'] = $portfolio->description; |
|
293
|
|
|
} |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
$user['dateJoined'] = date("Y-m-d H:i:s", $user_entity->time_created); |
|
297
|
|
|
|
|
298
|
|
|
$user['lastActivity'] = date("Y-m-d H:i:s", $user_entity->last_action); |
|
299
|
|
|
|
|
300
|
|
|
$user['lastLogin'] = date("Y-m-d H:i:s", $user_entity->last_login); |
|
301
|
|
|
|
|
302
|
|
|
return $user; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
function profileUpdate($id, $data) |
|
306
|
|
|
{ |
|
307
|
|
|
global $CONFIG; |
|
308
|
|
|
$response['error'] = 0; |
|
|
|
|
|
|
309
|
|
|
$user_entity = getUserFromID($id); |
|
310
|
|
|
if (!$user_entity) { |
|
311
|
|
|
$response['error'] = 1; |
|
312
|
|
|
$response['message'] = 'Invalid user id, username, or email'; |
|
313
|
|
|
return $response; |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
View Code Duplication |
if ($data == '') { |
|
317
|
|
|
$response['error'] = 2; |
|
318
|
|
|
$response['message'] = 'data must be a string representing a JSON object.'; |
|
319
|
|
|
return $response; |
|
320
|
|
|
} |
|
321
|
|
|
$userDataObj = json_decode($data, true); |
|
322
|
|
View Code Duplication |
if (json_last_error() !== 0) { |
|
323
|
|
|
$response['error'] = 2; |
|
324
|
|
|
$response['message'] = 'invalid JSON - data was unable to be parsed'; |
|
325
|
|
|
return $response; |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
foreach ($userDataObj as $field => $value) { |
|
329
|
|
|
switch ($field) { |
|
330
|
|
|
case 'name': |
|
331
|
|
|
elgg_set_ignore_access(true); |
|
332
|
|
|
|
|
333
|
|
|
$nameData = json_decode(json_encode($value), true); |
|
334
|
|
View Code Duplication |
if (!isset($nameData["firstName"])&&!isset($nameData["lastName"])) { |
|
335
|
|
|
$response['error'] = 4; |
|
336
|
|
|
$response['message'] = 'invalid data format - missing first and last name'; |
|
337
|
|
|
return $response; |
|
338
|
|
|
} |
|
339
|
|
View Code Duplication |
if (!isset($nameData["firstName"])||!isset($nameData["lastName"])) { |
|
340
|
|
|
$response['error'] = 4; |
|
341
|
|
|
$response['message'] = 'invalid data format - missing first or last name'; |
|
342
|
|
|
return $response; |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
$name = $nameData["firstName"].' '.$nameData["lastName"]; |
|
346
|
|
View Code Duplication |
if (elgg_strlen($name) > 50) { |
|
347
|
|
|
register_error(elgg_echo('user:name:fail')); |
|
348
|
|
|
} elseif ($user_entity->name != $name) { |
|
349
|
|
|
$user_entity->name= $name; |
|
350
|
|
|
$user_entity->save(); |
|
351
|
|
|
} |
|
352
|
|
|
elgg_set_ignore_access(false); |
|
353
|
|
|
break; |
|
354
|
|
|
case 'title': |
|
355
|
|
|
|
|
356
|
|
|
$titleData = json_decode(json_encode($value), true); |
|
357
|
|
|
if (!isset($titleData['fr'])&&!isset($titleData['en'])) { |
|
358
|
|
|
$response['error'] = 4; |
|
359
|
|
|
$response['message'] = 'invalid data format - missing french and english title'; |
|
360
|
|
|
return $response; |
|
361
|
|
|
} |
|
362
|
|
|
if (!isset($titleData['fr'])||!isset($titleData['en'])) { |
|
363
|
|
|
$response['error'] = 4; |
|
364
|
|
|
$response['message'] = 'invalid data format - missing french or english title'; |
|
365
|
|
|
return $response; |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
if ($user_entity->language === 'fr') { |
|
369
|
|
|
$user_entity->set('job', $titleData['fr'].' / '.$titleData['en']); |
|
370
|
|
|
} else { |
|
371
|
|
|
$user_entity->set('job', $titleData['en'].' / '.$titleData['fr']); |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
break; |
|
375
|
|
View Code Duplication |
case 'classification': |
|
376
|
|
|
$classificationData = json_decode(json_encode($value), true); |
|
377
|
|
|
if (!isset($classificationData['group'])&&!isset($classificationData['level'])) { |
|
378
|
|
|
$response['error'] = 4; |
|
379
|
|
|
$response['message'] = 'invalid data format - missing classification group and level'; |
|
380
|
|
|
return $response; |
|
381
|
|
|
} |
|
382
|
|
|
if (!isset($classificationData['group'])||!isset($classificationData['level'])) { |
|
383
|
|
|
$response['error'] = 4; |
|
384
|
|
|
$response['message'] = 'invalid data format - missing classification group or level'; |
|
385
|
|
|
return $response; |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
$user_entity->set('classification', json_encode($value)); |
|
389
|
|
|
break; |
|
390
|
|
|
case 'department': |
|
391
|
|
|
$deptData = json_decode(json_encode($value), true); |
|
392
|
|
|
if (!isset($deptData['fr'])&&!isset($deptData['en'])) { |
|
393
|
|
|
$response['error'] = 4; |
|
394
|
|
|
$response['message'] = 'invalid data format - department format'; |
|
395
|
|
|
return $response; |
|
396
|
|
|
} |
|
397
|
|
|
if (!isset($deptData['fr'])||!isset($deptData['en'])) { |
|
398
|
|
|
$response['error'] = 4; |
|
399
|
|
|
$response['message'] = 'invalid data format - missing french or english department'; |
|
400
|
|
|
return $response; |
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
$obj = elgg_get_entities(array( |
|
404
|
|
|
'type' => 'object', |
|
405
|
|
|
'subtype' => 'dept_list', |
|
406
|
|
|
'owner_guid' => 0 |
|
407
|
|
|
)); |
|
408
|
|
|
$deptListEn = json_decode($obj[0]->deptsEn, true); |
|
409
|
|
|
$provinces = array(); |
|
410
|
|
|
$provinces['pov-alb'] = 'Government of Alberta'; |
|
411
|
|
|
$provinces['pov-bc'] = 'Government of British Columbia'; |
|
412
|
|
|
$provinces['pov-man'] = 'Government of Manitoba'; |
|
413
|
|
|
$provinces['pov-nb'] = 'Government of New Brunswick'; |
|
414
|
|
|
$provinces['pov-nfl'] = 'Government of Newfoundland and Labrador'; |
|
415
|
|
|
$provinces['pov-ns'] = 'Government of Nova Scotia'; |
|
416
|
|
|
$provinces['pov-nwt'] = 'Government of Northwest Territories'; |
|
417
|
|
|
$provinces['pov-nun'] = 'Government of Nunavut'; |
|
418
|
|
|
$provinces['pov-ont'] = 'Government of Ontario'; |
|
419
|
|
|
$provinces['pov-pei'] = 'Government of Prince Edward Island'; |
|
420
|
|
|
$provinces['pov-que'] = 'Government of Quebec'; |
|
421
|
|
|
$provinces['pov-sask'] = 'Government of Saskatchewan'; |
|
422
|
|
|
$provinces['pov-yuk'] = 'Government of Yukon'; |
|
423
|
|
|
$provinces['CIRNAC-RCAANC'] = 'Crown-Indigenous Relations and Northern Affairs Canada'; |
|
424
|
|
|
$provinces['PPS-SPP'] = 'Parliamentary Protective Service'; |
|
425
|
|
|
$deptAndProvincesEn = array_merge($deptListEn, $provinces); |
|
426
|
|
|
unset($deptAndProvincesEn['ou=INAC-AANC, o=GC, c=CA']); |
|
427
|
|
|
|
|
428
|
|
|
|
|
429
|
|
|
$deptListFr = json_decode($obj[0]->deptsFr, true); |
|
430
|
|
|
$provinces = array(); |
|
431
|
|
|
$provinces['pov-alb'] = "Gouvernement de l'Alberta"; |
|
432
|
|
|
$provinces['pov-bc'] = 'Gouvernement de la Colombie-Britannique'; |
|
433
|
|
|
$provinces['pov-man'] = 'Gouvernement du Manitoba'; |
|
434
|
|
|
$provinces['pov-nb'] = 'Gouvernement du Nouveau-Brunswick'; |
|
435
|
|
|
$provinces['pov-nfl'] = 'Gouvernement de Terre-Neuve-et-Labrador'; |
|
436
|
|
|
$provinces['pov-ns'] = 'Gouvernement de la Nouvelle-Écosse'; |
|
437
|
|
|
$provinces['pov-nwt'] = 'Gouvernement du Territoires du Nord-Ouest'; |
|
438
|
|
|
$provinces['pov-nun'] = 'Gouvernement du Nunavut'; |
|
439
|
|
|
$provinces['pov-ont'] = "Gouvernement de l'Ontario"; |
|
440
|
|
|
$provinces['pov-pei'] = "Gouvernement de l'Île-du-Prince-Édouard"; |
|
441
|
|
|
$provinces['pov-que'] = 'Gouvernement du Québec'; |
|
442
|
|
|
$provinces['pov-sask'] = 'Gouvernement de Saskatchewan'; |
|
443
|
|
|
$provinces['pov-yuk'] = 'Gouvernement du Yukon'; |
|
444
|
|
|
$provinces['CIRNAC-RCAANC'] = 'Relations Couronne-Autochtones et Affaires du Nord Canada'; |
|
445
|
|
|
$provinces['PPS-SPP'] = 'Service de Protection Parlementaire'; |
|
446
|
|
|
$deptAndProvincesFr = array_merge($deptListFr, $provinces); |
|
447
|
|
|
unset($deptAndProvincesFr['ou=INAC-AANC, o=GC, c=CA']); |
|
448
|
|
|
|
|
449
|
|
View Code Duplication |
if (!in_array($deptData['en'], $deptAndProvincesEn)) { |
|
450
|
|
|
$response['error'] = 5; |
|
451
|
|
|
$response['message'] = 'invalid english department name. valid names: '.json_encode($deptAndProvincesEn); |
|
452
|
|
|
return $response; |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
View Code Duplication |
if (!in_array($deptData['fr'], $deptAndProvincesFr)) { |
|
456
|
|
|
$response['error'] = 5; |
|
457
|
|
|
$response['message'] = 'invalid french department name. valid names: '.json_encode($deptAndProvincesFr); |
|
458
|
|
|
return $response; |
|
459
|
|
|
} |
|
460
|
|
|
|
|
461
|
|
|
if ($user_entity->language === 'fr') { |
|
462
|
|
|
$user_entity->set('department', $deptData['fr'].' / '.$deptData['en']); |
|
463
|
|
|
} else { |
|
464
|
|
|
$user_entity->set('department', $deptData['en'].' / '.$deptData['fr']); |
|
465
|
|
|
} |
|
466
|
|
|
break; |
|
467
|
|
View Code Duplication |
case 'branch': |
|
468
|
|
|
$branchData = json_decode(json_encode($value), true); |
|
469
|
|
|
if (!isset($branchData['en'])&&!isset($branchData['fr'])) { |
|
470
|
|
|
$response['error'] = 4; |
|
471
|
|
|
$response['message'] = 'invalid data format - missing english and french branch name'; |
|
472
|
|
|
return $response; |
|
473
|
|
|
} |
|
474
|
|
|
if (!isset($branchData['en'])||!isset($branchData['fr'])) { |
|
475
|
|
|
$response['error'] = 4; |
|
476
|
|
|
$response['message'] = 'invalid data format - missing english or french branch name'; |
|
477
|
|
|
return $response; |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
$user_entity->set('branch', json_encode($value)); |
|
481
|
|
|
break; |
|
482
|
|
View Code Duplication |
case 'sector': |
|
483
|
|
|
$sectorData = json_decode(json_encode($value), true); |
|
484
|
|
|
if (!isset($sectorData['en'])&&!isset($sectorData['fr'])) { |
|
485
|
|
|
$response['error'] = 4; |
|
486
|
|
|
$response['message'] = 'invalid data format - missing english and french sector name'; |
|
487
|
|
|
return $response; |
|
488
|
|
|
} |
|
489
|
|
|
if (!isset($sectorData['en'])||!isset($sectorData['fr'])) { |
|
490
|
|
|
$response['error'] = 4; |
|
491
|
|
|
$response['message'] = 'invalid data format - missing english or french sector name'; |
|
492
|
|
|
return $response; |
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
|
|
$user_entity->set('sector', json_encode($value)); |
|
496
|
|
|
break; |
|
497
|
|
|
case 'location': |
|
498
|
|
View Code Duplication |
if (!isset($value['en'])) { |
|
499
|
|
|
$response['error'] = 4; |
|
500
|
|
|
$response['message'] = 'missing english location data'; |
|
501
|
|
|
return $response; |
|
502
|
|
|
} |
|
503
|
|
|
$locationData = json_decode(json_encode($value['en']), true); |
|
504
|
|
View Code Duplication |
if (!isset($locationData['street'])&&!isset($locationData['city'])&&!isset($locationData['province'])&&!isset($locationData['postalCode'])&&!isset($locationData['country'])&&!isset($locationData['building'])&&!isset($locationData['floor'])&&!isset($locationData['officeNum'])) { |
|
505
|
|
|
$response['error'] = 4; |
|
506
|
|
|
$response['message'] = 'invalid location data'; |
|
507
|
|
|
return $response; |
|
508
|
|
|
} |
|
509
|
|
View Code Duplication |
if (!isset($locationData['street'])||!isset($locationData['city'])||!isset($locationData['province'])||!isset($locationData['postalCode'])||!isset($locationData['country'])||!isset($locationData['building'])||!isset($locationData['floor'])||!isset($locationData['officeNum'])) { |
|
510
|
|
|
$response['error'] = 4; |
|
511
|
|
|
$response['message'] = 'missing location data'; |
|
512
|
|
|
return $response; |
|
513
|
|
|
} |
|
514
|
|
|
|
|
515
|
|
View Code Duplication |
if (!isset($value['fr'])) { |
|
516
|
|
|
$response['error'] = 4; |
|
517
|
|
|
$response['message'] = 'missing french location data'; |
|
518
|
|
|
return $response; |
|
519
|
|
|
} |
|
520
|
|
|
$locationData = json_decode(json_encode($value['fr']), true); |
|
521
|
|
View Code Duplication |
if (!isset($locationData['street'])&&!isset($locationData['city'])&&!isset($locationData['province'])&&!isset($locationData['postalCode'])&&!isset($locationData['country'])&&!isset($locationData['building'])&&!isset($locationData['floor'])&&!isset($locationData['officeNum'])) { |
|
522
|
|
|
$response['error'] = 4; |
|
523
|
|
|
$response['message'] = 'invalid location data'; |
|
524
|
|
|
return $response; |
|
525
|
|
|
} |
|
526
|
|
View Code Duplication |
if (!isset($locationData['street'])||!isset($locationData['city'])||!isset($locationData['province'])||!isset($locationData['postalCode'])||!isset($locationData['country'])||!isset($locationData['building'])||!isset($locationData['floor'])||!isset($locationData['officeNum'])) { |
|
527
|
|
|
$response['error'] = 4; |
|
528
|
|
|
$response['message'] = 'missing location data'; |
|
529
|
|
|
return $response; |
|
530
|
|
|
} |
|
531
|
|
|
|
|
532
|
|
|
$user_entity->set('addressString', json_encode($value["en"])); |
|
533
|
|
|
$user_entity->set('addressStringFr', json_encode($value["fr"])); |
|
534
|
|
|
break; |
|
535
|
|
|
case 'phone': |
|
536
|
|
|
|
|
537
|
|
|
$user_entity->set('phone', $value); |
|
538
|
|
|
break; |
|
539
|
|
|
case 'mobile': |
|
540
|
|
|
|
|
541
|
|
|
$user_entity->set('mobile', $value); |
|
542
|
|
|
break; |
|
543
|
|
|
case 'email': |
|
544
|
|
|
|
|
545
|
|
|
elgg_set_ignore_access(true); |
|
546
|
|
|
$connection = mysqli_connect($CONFIG->dbhost, $CONFIG->dbuser, $CONFIG->dbpass, $CONFIG->dbname)or die(mysqli_error($connection)); |
|
547
|
|
|
mysqli_select_db($connection, $CONFIG->dbname); |
|
548
|
|
|
$emaildomain = explode('@', filter_var($value, FILTER_SANITIZE_EMAIL)); |
|
549
|
|
|
$query = "SELECT count(*) AS num FROM email_extensions WHERE ext ='".$emaildomain[1]."'"; |
|
550
|
|
|
|
|
551
|
|
|
$result = mysqli_query($connection, $query)or die(mysqli_error($connection)); |
|
552
|
|
|
$result = mysqli_fetch_array($result); |
|
553
|
|
|
|
|
554
|
|
|
$emailgc = explode('.', $emaildomain[1]); |
|
555
|
|
|
$gcca = $emailgc[count($emailgc) - 2] .".".$emailgc[count($emailgc) - 1]; |
|
556
|
|
|
|
|
557
|
|
|
mysqli_close($connection); |
|
558
|
|
|
|
|
559
|
|
|
$resulting_error = ""; |
|
560
|
|
|
|
|
561
|
|
View Code Duplication |
if ($result['num'][0] <= 0) { |
|
562
|
|
|
if ($gcca !== 'gc.ca') { |
|
563
|
|
|
$resulting_error .= elgg_echo('gcRegister:invalid_email'); |
|
564
|
|
|
} |
|
565
|
|
|
} |
|
566
|
|
|
|
|
567
|
|
|
|
|
568
|
|
View Code Duplication |
if ($resulting_error !== "") { |
|
569
|
|
|
$response['error'] = 3; |
|
570
|
|
|
$response['message'] = 'invalid email or email domain - must be a valid Government of Canada email address'; |
|
571
|
|
|
return $response; |
|
572
|
|
|
} |
|
573
|
|
|
$user_entity->set('email', $value); |
|
574
|
|
|
$user_entity->save(); |
|
575
|
|
|
|
|
576
|
|
|
elgg_set_ignore_access(false); |
|
577
|
|
|
break; |
|
578
|
|
|
case 'secondLanguage': |
|
579
|
|
|
|
|
580
|
|
|
$user_entity->set('english', $value["ENG"]); |
|
581
|
|
|
$user_entity->set('french', $value["FRA"]); |
|
582
|
|
|
$user_entity->set('officialLanguage', $value["firstLanguage"]); |
|
583
|
|
|
|
|
584
|
|
|
break; |
|
585
|
|
|
} |
|
586
|
|
|
} |
|
587
|
|
|
|
|
588
|
|
|
$user_entity->save(); |
|
589
|
|
|
return 'success'; |
|
590
|
|
|
} |
|
591
|
|
|
|
|
592
|
|
|
function profileCreate($data) |
|
593
|
|
|
{ |
|
594
|
|
|
global $CONFIG; |
|
595
|
|
|
// check email for duplicate |
|
596
|
|
|
// get email and create username |
|
597
|
|
|
// create account |
|
598
|
|
|
// send password reset email |
|
599
|
|
|
// fill in profile data |
|
600
|
|
View Code Duplication |
if ($data == '') { |
|
601
|
|
|
$response['error'] = 2; |
|
|
|
|
|
|
602
|
|
|
$response['message'] = 'data must be a string representing a JSON object.'; |
|
603
|
|
|
return $response; |
|
604
|
|
|
} |
|
605
|
|
|
$userDataObj = json_decode($data, true); |
|
606
|
|
View Code Duplication |
if (json_last_error() !== 0) { |
|
607
|
|
|
$response['error'] = 2; |
|
|
|
|
|
|
608
|
|
|
$response['message'] = 'invalid JSON - data was unable to be parsed'; |
|
609
|
|
|
return $response; |
|
610
|
|
|
} |
|
611
|
|
|
|
|
612
|
|
|
/////////////////////////////////////////////////////////////////// |
|
613
|
|
|
//error check data field |
|
614
|
|
|
/////////////////////////////////////////////////////////////////// |
|
615
|
|
|
foreach ($userDataObj as $field => $value) { |
|
616
|
|
|
switch ($field) { |
|
617
|
|
|
case 'name': |
|
618
|
|
|
$nameData = json_decode(json_encode($value), true); |
|
619
|
|
View Code Duplication |
if (!isset($nameData["firstName"])&&!isset($nameData["lastName"])) { |
|
620
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
621
|
|
|
$response['message'] = 'invalid data format - missing first and last name'; |
|
622
|
|
|
return $response; |
|
623
|
|
|
} |
|
624
|
|
View Code Duplication |
if (!isset($nameData["firstName"])||!isset($nameData["lastName"])) { |
|
625
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
626
|
|
|
$response['message'] = 'invalid data format - missing first or last name'; |
|
627
|
|
|
return $response; |
|
628
|
|
|
} |
|
629
|
|
|
|
|
630
|
|
|
|
|
631
|
|
|
$name = $nameData["firstName"].' '.$nameData["lastName"]; |
|
632
|
|
|
|
|
633
|
|
|
break; |
|
634
|
|
View Code Duplication |
case 'title': |
|
635
|
|
|
|
|
636
|
|
|
$titleData = json_decode(json_encode($value), true); |
|
637
|
|
|
if (!isset($titleData['fr'])&&!isset($titleData['en'])) { |
|
638
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
639
|
|
|
$response['message'] = 'invalid data format - missing french and english title'; |
|
640
|
|
|
return $response; |
|
641
|
|
|
} |
|
642
|
|
|
if (!isset($titleData['fr'])||!isset($titleData['en'])) { |
|
643
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
644
|
|
|
$response['message'] = 'invalid data format - missing french or english title'; |
|
645
|
|
|
return $response; |
|
646
|
|
|
} |
|
647
|
|
|
break; |
|
648
|
|
View Code Duplication |
case 'classification': |
|
649
|
|
|
$classificationData = json_decode(json_encode($value), true); |
|
650
|
|
|
if (!isset($classificationData['group'])&&!isset($classificationData['level'])) { |
|
651
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
652
|
|
|
$response['message'] = 'invalid data format - missing classification group and level'; |
|
653
|
|
|
return $response; |
|
654
|
|
|
} |
|
655
|
|
|
if (!isset($classificationData['group'])||!isset($classificationData['level'])) { |
|
656
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
657
|
|
|
$response['message'] = 'invalid data format - missing classification group or level'; |
|
658
|
|
|
return $response; |
|
659
|
|
|
} |
|
660
|
|
|
|
|
661
|
|
|
break; |
|
662
|
|
|
case 'department': |
|
663
|
|
|
$deptData = json_decode(json_encode($value), true); |
|
664
|
|
|
if (!isset($deptData['fr'])&&!isset($deptData['en'])) { |
|
665
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
666
|
|
|
$response['message'] = 'invalid data format - department format'; |
|
667
|
|
|
return $response; |
|
668
|
|
|
} |
|
669
|
|
|
if (!isset($deptData['fr'])||!isset($deptData['en'])) { |
|
670
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
671
|
|
|
$response['message'] = 'invalid data format - missing french or english department'; |
|
672
|
|
|
return $response; |
|
673
|
|
|
} |
|
674
|
|
|
|
|
675
|
|
|
$obj = elgg_get_entities(array( |
|
676
|
|
|
'type' => 'object', |
|
677
|
|
|
'subtype' => 'dept_list', |
|
678
|
|
|
'owner_guid' => 0 |
|
679
|
|
|
)); |
|
680
|
|
|
$deptListEn = json_decode($obj[0]->deptsEn, true); |
|
681
|
|
|
$provinces = array(); |
|
682
|
|
|
$provinces['pov-alb'] = 'Government of Alberta'; |
|
683
|
|
|
$provinces['pov-bc'] = 'Government of British Columbia'; |
|
684
|
|
|
$provinces['pov-man'] = 'Government of Manitoba'; |
|
685
|
|
|
$provinces['pov-nb'] = 'Government of New Brunswick'; |
|
686
|
|
|
$provinces['pov-nfl'] = 'Government of Newfoundland and Labrador'; |
|
687
|
|
|
$provinces['pov-ns'] = 'Government of Nova Scotia'; |
|
688
|
|
|
$provinces['pov-nwt'] = 'Government of Northwest Territories'; |
|
689
|
|
|
$provinces['pov-nun'] = 'Government of Nunavut'; |
|
690
|
|
|
$provinces['pov-ont'] = 'Government of Ontario'; |
|
691
|
|
|
$provinces['pov-pei'] = 'Government of Prince Edward Island'; |
|
692
|
|
|
$provinces['pov-que'] = 'Government of Quebec'; |
|
693
|
|
|
$provinces['pov-sask'] = 'Government of Saskatchewan'; |
|
694
|
|
|
$provinces['pov-yuk'] = 'Government of Yukon'; |
|
695
|
|
|
$deptAndProvincesEn = array_merge($deptListEn, $provinces); |
|
696
|
|
|
unset($deptAndProvincesEn['ou=INAC-AANC, o=GC, c=CA']); |
|
697
|
|
|
|
|
698
|
|
|
$deptListFr = json_decode($obj[0]->deptsFr, true); |
|
699
|
|
|
$provinces = array(); |
|
700
|
|
|
$provinces['pov-alb'] = "Gouvernement de l'Alberta"; |
|
701
|
|
|
$provinces['pov-bc'] = 'Gouvernement de la Colombie-Britannique'; |
|
702
|
|
|
$provinces['pov-man'] = 'Gouvernement du Manitoba'; |
|
703
|
|
|
$provinces['pov-nb'] = 'Gouvernement du Nouveau-Brunswick'; |
|
704
|
|
|
$provinces['pov-nfl'] = 'Gouvernement de Terre-Neuve-et-Labrador'; |
|
705
|
|
|
$provinces['pov-ns'] = 'Gouvernement de la Nouvelle-Écosse'; |
|
706
|
|
|
$provinces['pov-nwt'] = 'Gouvernement du Territoires du Nord-Ouest'; |
|
707
|
|
|
$provinces['pov-nun'] = 'Gouvernement du Nunavut'; |
|
708
|
|
|
$provinces['pov-ont'] = "Gouvernement de l'Ontario"; |
|
709
|
|
|
$provinces['pov-pei'] = "Gouvernement de l'Île-du-Prince-Édouard"; |
|
710
|
|
|
$provinces['pov-que'] = 'Gouvernement du Québec'; |
|
711
|
|
|
$provinces['pov-sask'] = 'Gouvernement de Saskatchewan'; |
|
712
|
|
|
$provinces['pov-yuk'] = 'Gouvernement du Yukon'; |
|
713
|
|
|
$deptAndProvincesFr = array_merge($deptListFr, $provinces); |
|
714
|
|
|
unset($deptAndProvincesFr['ou=INAC-AANC, o=GC, c=CA']); |
|
715
|
|
|
|
|
716
|
|
|
|
|
717
|
|
View Code Duplication |
if (!in_array($deptData['en'], $deptAndProvincesEn)) { |
|
718
|
|
|
$response['error'] = 5; |
|
|
|
|
|
|
719
|
|
|
$response['message'] = 'invalid english department name. valid names: '.json_encode($deptAndProvincesEn); |
|
720
|
|
|
return $response; |
|
721
|
|
|
} |
|
722
|
|
|
|
|
723
|
|
View Code Duplication |
if (!in_array($deptData['fr'], $deptAndProvincesFr)) { |
|
724
|
|
|
$response['error'] = 5; |
|
|
|
|
|
|
725
|
|
|
$response['message'] = 'invalid french department name. valid names: '.json_encode($deptAndProvincesFr); |
|
726
|
|
|
return $response; |
|
727
|
|
|
} |
|
728
|
|
|
break; |
|
729
|
|
View Code Duplication |
case 'branch': |
|
730
|
|
|
$branchData = json_decode(json_encode($value), true); |
|
731
|
|
|
if (!isset($branchData['en'])&&!isset($branchData['fr'])) { |
|
732
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
733
|
|
|
$response['message'] = 'invalid data format - missing english and french branch name'; |
|
734
|
|
|
return $response; |
|
735
|
|
|
} |
|
736
|
|
|
if (!isset($branchData['en'])||!isset($branchData['fr'])) { |
|
737
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
738
|
|
|
$response['message'] = 'invalid data format - missing english or french branch name'; |
|
739
|
|
|
return $response; |
|
740
|
|
|
} |
|
741
|
|
|
break; |
|
742
|
|
View Code Duplication |
case 'sector': |
|
743
|
|
|
$sectorData = json_decode(json_encode($value), true); |
|
744
|
|
|
if (!isset($sectorData['en'])&&!isset($sectorData['fr'])) { |
|
745
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
746
|
|
|
$response['message'] = 'invalid data format - missing english and french sector name'; |
|
747
|
|
|
return $response; |
|
748
|
|
|
} |
|
749
|
|
|
if (!isset($sectorData['en'])||!isset($sectorData['fr'])) { |
|
750
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
751
|
|
|
$response['message'] = 'invalid data format - missing english or french sector name'; |
|
752
|
|
|
return $response; |
|
753
|
|
|
} |
|
754
|
|
|
break; |
|
755
|
|
|
case 'location': |
|
756
|
|
View Code Duplication |
if (!isset($value['en'])) { |
|
757
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
758
|
|
|
$response['message'] = 'missing english location data'; |
|
759
|
|
|
return $response; |
|
760
|
|
|
} |
|
761
|
|
|
$locationData = json_decode(json_encode($value['en']), true); |
|
762
|
|
View Code Duplication |
if (!isset($locationData['street'])&&!isset($locationData['city'])&&!isset($locationData['province'])&&!isset($locationData['postalCode'])&&!isset($locationData['country'])&&!isset($locationData['building'])&&!isset($locationData['floor'])&&!isset($locationData['officeNum'])) { |
|
763
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
764
|
|
|
$response['message'] = 'invalid location data'; |
|
765
|
|
|
return $response; |
|
766
|
|
|
} |
|
767
|
|
View Code Duplication |
if (!isset($locationData['street'])||!isset($locationData['city'])||!isset($locationData['province'])||!isset($locationData['postalCode'])||!isset($locationData['country'])||!isset($locationData['building'])||!isset($locationData['floor'])||!isset($locationData['officeNum'])) { |
|
768
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
769
|
|
|
$response['message'] = 'missing location data'; |
|
770
|
|
|
return $response; |
|
771
|
|
|
} |
|
772
|
|
|
|
|
773
|
|
View Code Duplication |
if (!isset($value['fr'])) { |
|
774
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
775
|
|
|
$response['message'] = 'missing french location data'; |
|
776
|
|
|
return $response; |
|
777
|
|
|
} |
|
778
|
|
|
$locationData = json_decode(json_encode($value['fr']), true); |
|
779
|
|
View Code Duplication |
if (!isset($locationData['street'])&&!isset($locationData['city'])&&!isset($locationData['province'])&&!isset($locationData['postalCode'])&&!isset($locationData['country'])&&!isset($locationData['building'])&&!isset($locationData['floor'])&&!isset($locationData['officeNum'])) { |
|
780
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
781
|
|
|
$response['message'] = 'invalid location data'; |
|
782
|
|
|
return $response; |
|
783
|
|
|
} |
|
784
|
|
View Code Duplication |
if (!isset($locationData['street'])||!isset($locationData['city'])||!isset($locationData['province'])||!isset($locationData['postalCode'])||!isset($locationData['country'])||!isset($locationData['building'])||!isset($locationData['floor'])||!isset($locationData['officeNum'])) { |
|
785
|
|
|
$response['error'] = 4; |
|
|
|
|
|
|
786
|
|
|
$response['message'] = 'missing location data'; |
|
787
|
|
|
return $response; |
|
788
|
|
|
} |
|
789
|
|
|
break; |
|
790
|
|
|
case 'email': |
|
791
|
|
|
$connection = mysqli_connect($CONFIG->dbhost, $CONFIG->dbuser, $CONFIG->dbpass, $CONFIG->dbname)or die(mysqli_error($connection)); |
|
792
|
|
|
mysqli_select_db($connection, $CONFIG->dbname); |
|
793
|
|
|
$emaildomain = explode('@', filter_var($value, FILTER_SANITIZE_EMAIL)); |
|
794
|
|
|
|
|
795
|
|
|
$query = "SELECT count(*) AS num FROM email_extensions WHERE ext ='".$emaildomain[1]."'"; |
|
796
|
|
|
|
|
797
|
|
|
$result = mysqli_query($connection, $query)or die(mysqli_error($connection)); |
|
798
|
|
|
$result = mysqli_fetch_array($result); |
|
799
|
|
|
|
|
800
|
|
|
$emailgc = explode('.', $emaildomain[1]); |
|
801
|
|
|
$gcca = $emailgc[count($emailgc) - 2] .".".$emailgc[count($emailgc) - 1]; |
|
802
|
|
|
|
|
803
|
|
|
mysqli_close($connection); |
|
804
|
|
|
|
|
805
|
|
|
$resulting_error = ""; |
|
806
|
|
|
|
|
807
|
|
|
// if domain doesn't exist in database, check if it's a gc.ca domain |
|
808
|
|
View Code Duplication |
if ($result['num'][0] <= 0) { |
|
809
|
|
|
if ($gcca !== 'gc.ca') { |
|
810
|
|
|
$resulting_error .= elgg_echo('gcRegister:invalid_email'); |
|
811
|
|
|
} |
|
812
|
|
|
} |
|
813
|
|
|
|
|
814
|
|
View Code Duplication |
if ($resulting_error !== "") { |
|
815
|
|
|
$response['error'] = 3; |
|
|
|
|
|
|
816
|
|
|
$response['message'] = 'invalid email or email domain - must be a valid Government of Canada email address'; |
|
817
|
|
|
return $response; |
|
818
|
|
|
} |
|
819
|
|
|
break; |
|
820
|
|
|
} |
|
821
|
|
|
} |
|
822
|
|
|
|
|
823
|
|
|
//check for existing email |
|
824
|
|
|
$email = $userDataObj['email']; |
|
825
|
|
|
if (get_user_by_email($email)) { |
|
826
|
|
|
$response['error'] = 1; |
|
|
|
|
|
|
827
|
|
|
$response['message'] = 'user with email already exists. please use profile.update call to update existing account'; |
|
828
|
|
|
return $response; |
|
829
|
|
|
} |
|
830
|
|
|
//make usernaem based on email |
|
831
|
|
|
$username = strstr(strtolower($email), '@', true); |
|
832
|
|
|
|
|
833
|
|
|
$username = explode('.', $username); |
|
834
|
|
|
foreach ($username as $u=>$v) { |
|
835
|
|
|
$username[$u] = ucfirst($v); |
|
836
|
|
|
} |
|
837
|
|
|
$username = implode('.', $username); |
|
838
|
|
|
|
|
839
|
|
|
//check system for username. if is a username, append number or add number |
|
840
|
|
|
while (get_user_by_username($username)) { |
|
841
|
|
|
if (is_numeric(substr($username, -1))) { |
|
842
|
|
|
$num = substr($username, -1)+1; |
|
843
|
|
|
$username = substr($username, 0, strlen($username)-1).$num; |
|
844
|
|
|
} else { |
|
845
|
|
|
$username.='2'; |
|
846
|
|
|
} |
|
847
|
|
|
} |
|
848
|
|
|
$tempPass = generateRandomString(); |
|
849
|
|
|
|
|
850
|
|
|
//register user using data passed |
|
851
|
|
|
$userGUID = register_user($username, $tempPass, $name, $userDataObj['email']); |
|
|
|
|
|
|
852
|
|
View Code Duplication |
if ($userGUID==false) { |
|
|
|
|
|
|
853
|
|
|
$response['error'] = 1; |
|
|
|
|
|
|
854
|
|
|
$response['message'] = 'Failed creating account'; |
|
855
|
|
|
return $response; |
|
856
|
|
|
} |
|
857
|
|
|
|
|
858
|
|
|
$user_entity = get_user($userGUID); |
|
859
|
|
|
|
|
860
|
|
|
foreach ($userDataObj as $field => $value) { |
|
861
|
|
|
switch ($field) { |
|
862
|
|
View Code Duplication |
case 'title': |
|
863
|
|
|
$titleData = json_decode(json_encode($value), true); |
|
864
|
|
|
|
|
865
|
|
|
if ($user_entity->language === 'fr') { |
|
866
|
|
|
$user_entity->set('job', $titleData['fr'].' / '.$titleData['en']); |
|
|
|
|
|
|
867
|
|
|
} else { |
|
868
|
|
|
$user_entity->set('job', $titleData['en'].' / '.$titleData['fr']); |
|
|
|
|
|
|
869
|
|
|
} |
|
870
|
|
|
|
|
871
|
|
|
break; |
|
872
|
|
|
case 'classification': |
|
873
|
|
|
$classificationData = json_decode(json_encode($value), true); |
|
874
|
|
|
|
|
875
|
|
|
$user_entity->set('classification', json_encode($value)); |
|
|
|
|
|
|
876
|
|
|
break; |
|
877
|
|
View Code Duplication |
case 'department': |
|
878
|
|
|
$deptData = json_decode(json_encode($value), true); |
|
879
|
|
|
|
|
880
|
|
|
if ($user_entity->language === 'fr') { |
|
881
|
|
|
$user_entity->set('department', $deptData['fr'].' / '.$deptData['en']); |
|
|
|
|
|
|
882
|
|
|
} else { |
|
883
|
|
|
$user_entity->set('department', $deptData['en'].' / '.$deptData['fr']); |
|
|
|
|
|
|
884
|
|
|
} |
|
885
|
|
|
break; |
|
886
|
|
|
case 'branch': |
|
887
|
|
|
$branchData = json_decode(json_encode($value), true); |
|
888
|
|
|
|
|
889
|
|
|
$user_entity->set('branch', json_encode($value)); |
|
|
|
|
|
|
890
|
|
|
break; |
|
891
|
|
|
case 'sector': |
|
892
|
|
|
$sectorData = json_decode(json_encode($value), true); |
|
893
|
|
|
|
|
894
|
|
|
$user_entity->set('sector', json_encode($value)); |
|
|
|
|
|
|
895
|
|
|
break; |
|
896
|
|
|
case 'location': |
|
897
|
|
|
|
|
898
|
|
|
$user_entity->set('addressString', json_encode($value["en"])); |
|
|
|
|
|
|
899
|
|
|
$user_entity->set('addressStringFr', json_encode($value["fr"])); |
|
|
|
|
|
|
900
|
|
|
break; |
|
901
|
|
|
case 'phone': |
|
902
|
|
|
|
|
903
|
|
|
$user_entity->set('phone', $value); |
|
|
|
|
|
|
904
|
|
|
break; |
|
905
|
|
|
case 'mobile': |
|
906
|
|
|
|
|
907
|
|
|
$user_entity->set('mobile', $value); |
|
|
|
|
|
|
908
|
|
|
break; |
|
909
|
|
|
} |
|
910
|
|
|
} |
|
911
|
|
|
//save user |
|
912
|
|
|
$user_entity->save(); |
|
913
|
|
|
//send password reset to user |
|
914
|
|
|
send_new_password_request($userGUID); |
|
915
|
|
|
return array( |
|
916
|
|
|
"guid"=> $userGUID, |
|
917
|
|
|
"message" => "user added" |
|
918
|
|
|
); |
|
919
|
|
|
} |
|
920
|
|
|
function generateRandomString($length = 10) |
|
921
|
|
|
{ |
|
922
|
|
|
return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/strlen($x)))), 1, $length); |
|
923
|
|
|
} |
|
924
|
|
|
|
|
925
|
|
|
function getUserFromID($id) |
|
926
|
|
|
{ |
|
927
|
|
|
if (is_numeric($id)) { |
|
928
|
|
|
$user_entity = get_user($id); |
|
929
|
|
|
} else { |
|
930
|
|
|
if (strpos($id, '@')) { |
|
931
|
|
|
$user_entity = get_user_by_email($id); |
|
932
|
|
|
if (is_array($user_entity)) { |
|
933
|
|
|
if (count($user_entity)>1) { |
|
934
|
|
|
return "Found more than 1 user, please use username or GUID"; |
|
935
|
|
|
} else { |
|
936
|
|
|
$user_entity = $user_entity[0]; |
|
937
|
|
|
} |
|
938
|
|
|
} |
|
939
|
|
|
} else { |
|
940
|
|
|
$user_entity = get_user_by_username($id); |
|
941
|
|
|
} |
|
942
|
|
|
} |
|
943
|
|
|
return $user_entity; |
|
944
|
|
|
} |
|
945
|
|
|
|
|
946
|
|
View Code Duplication |
function buildDate($month, $year) |
|
947
|
|
|
{ |
|
948
|
|
|
switch ($month) { |
|
949
|
|
|
case 1: |
|
950
|
|
|
$string = "01/"; |
|
951
|
|
|
break; |
|
952
|
|
|
case 2: |
|
953
|
|
|
$string = "02/"; |
|
954
|
|
|
break; |
|
955
|
|
|
case 3: |
|
956
|
|
|
$string = "03/"; |
|
957
|
|
|
break; |
|
958
|
|
|
case 4: |
|
959
|
|
|
$string = "04/"; |
|
960
|
|
|
break; |
|
961
|
|
|
case 5: |
|
962
|
|
|
$string = "05/"; |
|
963
|
|
|
break; |
|
964
|
|
|
case 6: |
|
965
|
|
|
$string = "06/"; |
|
966
|
|
|
break; |
|
967
|
|
|
case 7: |
|
968
|
|
|
$string = "07/"; |
|
969
|
|
|
break; |
|
970
|
|
|
case 8: |
|
971
|
|
|
$string = "08/"; |
|
972
|
|
|
break; |
|
973
|
|
|
case 9: |
|
974
|
|
|
$string = "09/"; |
|
975
|
|
|
break; |
|
976
|
|
|
case 10: |
|
977
|
|
|
$string = "10/"; |
|
978
|
|
|
break; |
|
979
|
|
|
case 11: |
|
980
|
|
|
$string = "11/"; |
|
981
|
|
|
break; |
|
982
|
|
|
case 12: |
|
983
|
|
|
$string = "12/"; |
|
984
|
|
|
break; |
|
985
|
|
|
} |
|
986
|
|
|
return $string.$year; |
|
|
|
|
|
|
987
|
|
|
} |
|
988
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.