1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
//global $CONFIG; |
4
|
|
|
//error_log($CONFIG->dbhost.' '.$CONFIG->dbuser.' '.$CONFIG->dbpass.' '.$CONFIG->dbname); |
5
|
|
|
|
6
|
|
|
elgg_ws_expose_function("get.profile","get_api_profile", array("id" => array('type' => 'string')), |
7
|
|
|
'provide user GUID number and all profile information is returned', |
8
|
|
|
'GET', false, false); |
9
|
|
|
|
10
|
|
|
elgg_ws_expose_function("profile.update","profileUpdate", array("id" => array('type' => 'string'), "data" => array('type'=>'string')), |
11
|
|
|
'update a user profile based on id passed', |
12
|
|
|
'POST', true, false); |
13
|
|
|
|
14
|
|
|
elgg_ws_expose_function("profile.create","profileCreate", array("data" => array('type'=>'string')), |
15
|
|
|
'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', |
16
|
|
|
'POST', true, false); |
17
|
|
|
|
18
|
|
|
function get_api_profile($id){ |
19
|
|
|
//global $CONFIG; |
20
|
|
|
//$string = "User was not found. Please try a different GUID, username, or email address"; |
21
|
|
|
$user_entity = getUserFromID($id); |
22
|
|
|
if (!$user_entity) |
23
|
|
|
return "User was not found. Please try a different GUID, username, or email address"; |
24
|
|
|
|
25
|
|
|
//$user['test'] = $CONFIG->view_types; |
26
|
|
|
|
27
|
|
|
$user['id'] = $user_entity->guid; |
|
|
|
|
28
|
|
|
|
29
|
|
|
$user['username'] = $user_entity->username; |
30
|
|
|
|
31
|
|
|
//get and store user display name |
32
|
|
|
$user['displayName'] = $user_entity->name; |
33
|
|
|
|
34
|
|
|
$user['email'] = $user_entity->email; |
35
|
|
|
|
36
|
|
|
//get and store URL for profile |
37
|
|
|
$user['profileURL'] = $user_entity->getURL(); |
38
|
|
|
|
39
|
|
|
//get and store URL of profile avatar |
40
|
|
|
$user['iconURL'] = $user_entity->geticon(); |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
$user['jobTitle'] = $user_entity->job; |
44
|
|
|
|
45
|
|
|
$user['department'] = $user_entity->department; |
46
|
|
|
|
47
|
|
|
$user['telephone'] = $user_entity->phone; |
48
|
|
|
|
49
|
|
|
$user['mobile'] = $user_entity->mobile; |
50
|
|
|
|
51
|
|
|
$user['Website'] = $user_entity->website; |
52
|
|
|
|
53
|
|
|
if ($user_entity->facebook) |
54
|
|
|
$user['links']['facebook'] = "http://www.facebook.com/".$user_entity->facebook; |
55
|
|
|
if($user_entity->google) |
56
|
|
|
$user['links']['google'] = "http://www.google.com/".$user_entity->google; |
57
|
|
|
if($user_entity->github) |
58
|
|
|
$user['links']['github'] = "https://github.com/".$user_entity->github; |
59
|
|
|
if($user_entity->twitter) |
60
|
|
|
$user['links']['twitter'] = "https://twitter.com/".$user_entity->twitter; |
61
|
|
|
if($user_entity->linkedin) |
62
|
|
|
$user['links']['linkedin'] = "http://ca.linkedin.com/in/".$user_entity->linkedin; |
63
|
|
|
if($user_entity->pinterest) |
64
|
|
|
$user['links']['pinterest'] = "http://www.pinterest.com/".$user_entity->pinterest; |
65
|
|
|
if($user_entity->tumblr) |
66
|
|
|
$user['links']['tumblr'] = "https://www.tumblr.com/blog/".$user_entity->tumblr; |
67
|
|
|
if($user_entity->instagram) |
68
|
|
|
$user['links']['instagram'] = "http://instagram.com/".$user_entity->instagram; |
69
|
|
|
if($user_entity->flickr) |
70
|
|
|
$user['links']['flickr'] = "http://flickr.com/".$user_entity->flickr; |
71
|
|
|
if($user_entity->youtube) |
72
|
|
|
$user['links']['youtube'] = "http://www.youtube.com/".$user_entity->youtube; |
73
|
|
|
|
74
|
|
|
//////////////////////////////////////////////////////////////////////////////////// |
75
|
|
|
//about me |
76
|
|
|
//////////////////////////////////////////////////////////////////////// |
77
|
|
|
$aboutMeMetadata = elgg_get_metadata(array('guids'=>array($user['id']),'limit'=>0,'metadata_names'=>array('description'))); |
78
|
|
|
|
79
|
|
|
if ($aboutMeMetadata[0]->access_id==2) |
80
|
|
|
$user['about_me'] = $aboutMeMetadata[0]->value; |
81
|
|
|
|
82
|
|
|
///////////////////////////////////////////////////////////////////////////////// |
83
|
|
|
//eductation |
84
|
|
|
////////////////////////////////////////////////////////////////////// |
85
|
|
|
$eductationEntity = elgg_get_entities(array( |
86
|
|
|
'owner_guid'=>$user['id'], |
87
|
|
|
'subtype'=>'education', |
88
|
|
|
'type' => 'object', |
89
|
|
|
'limit' => 0 |
90
|
|
|
)); |
91
|
|
|
$i=0; |
92
|
|
|
foreach ($eductationEntity as $school){ |
|
|
|
|
93
|
|
|
if($school->access_id==2){ |
94
|
|
|
|
95
|
|
|
$user['education']['item_'.$i]['school_name'] = $school->school; |
96
|
|
|
|
97
|
|
|
$user['education']['item_'.$i]['start_date'] = buildDate($school->startdate, $school->startyear); |
98
|
|
|
|
99
|
|
View Code Duplication |
if($school->ongoing == "false"){ |
100
|
|
|
$user['education']['item_'.$i]['end_date'] = buildDate($school->enddate,$school->endyear); |
101
|
|
|
}else{ |
102
|
|
|
$user['education']['item_'.$i]['end_date'] = "present/actuel"; |
103
|
|
|
} |
104
|
|
|
$user['education']['item_'.$i]['degree'] = $school->degree; |
105
|
|
|
$user['education']['item_'.$i]['field_of_study'] = $school->field; |
106
|
|
|
$i++; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
//////////////////////////////////////////////////////// |
110
|
|
|
//experience |
111
|
|
|
////////////////////////////////////// |
112
|
|
|
$experienceEntity = elgg_get_entities(array( |
113
|
|
|
'owner_guid'=>$user['id'], |
114
|
|
|
'subtype'=>'experience', |
115
|
|
|
'type' => 'object', |
116
|
|
|
'limit' => 0 |
117
|
|
|
)); |
118
|
|
|
usort($experienceEntity, "sortDate"); |
119
|
|
|
$i=0; |
120
|
|
|
foreach ($experienceEntity as $job){ |
121
|
|
|
//$user['job'.$i++] = "test"; |
122
|
|
|
if($job->access_id == 2){ |
123
|
|
|
$jobMetadata = elgg_get_metadata(array( |
|
|
|
|
124
|
|
|
'guid' => $job->guid, |
125
|
|
|
'limit' => 0 |
126
|
|
|
)); |
127
|
|
|
//foreach ($jobMetadata as $data) |
128
|
|
|
// $user['job'][$i++][$data->name] = $data->value; |
129
|
|
|
|
130
|
|
|
$user['experience']['item_'.$i]['job_title'] = $job->title; |
131
|
|
|
$user['experience']['item_'.$i]['organization'] = $job->organization; |
132
|
|
|
$user['experience']['item_'.$i]['start_date'] = buildDate($job->startdate, $job->startyear); |
133
|
|
View Code Duplication |
if ($job->ongoing == "false"){ |
134
|
|
|
$user['experience']['item_'.$i]['end_date'] = buildDate($job->enddate, $job->endyear); |
135
|
|
|
}else{ |
136
|
|
|
$user['experience']['item_'.$i]['end_date'] = "present/actuel"; |
137
|
|
|
} |
138
|
|
|
$user['experience']['item_'.$i]['responsibilities'] = $job->responsibilities; |
139
|
|
|
//$user['experience']['item_'.$i]['colleagues'] = $job->colleagues; |
140
|
|
|
$j = 0; |
141
|
|
|
if (is_array($job->colleagues)){ |
142
|
|
|
foreach($job->colleagues as $friend){ |
143
|
|
|
$friendEntity = get_user($friend); |
144
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["id"] = $friendEntity->guid; |
145
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["username"] = $friendEntity->username; |
146
|
|
|
|
147
|
|
|
//get and store user display name |
148
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["displayName"] = $friendEntity->name; |
149
|
|
|
|
150
|
|
|
//get and store URL for profile |
151
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["profileURL"] = $friendEntity->getURL(); |
152
|
|
|
|
153
|
|
|
//get and store URL of profile avatar |
154
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["iconURL"] = $friendEntity->geticon(); |
|
|
|
|
155
|
|
|
$j++; |
156
|
|
|
} |
157
|
|
|
}elseif(!is_null($job->colleagues)){ |
158
|
|
|
$friendEntity = get_user($job->colleagues); |
159
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["id"] = $friendEntity->guid; |
160
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["username"] = $friendEntity->username; |
161
|
|
|
|
162
|
|
|
//get and store user display name |
163
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["displayName"] = $friendEntity->name; |
164
|
|
|
|
165
|
|
|
//get and store URL for profile |
166
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["profileURL"] = $friendEntity->getURL(); |
167
|
|
|
|
168
|
|
|
//get and store URL of profile avatar |
169
|
|
|
$user['experience']['item_'.$i]['colleagues']['colleague_'.$j]["iconURL"] = $friendEntity->geticon(); |
|
|
|
|
170
|
|
|
|
171
|
|
|
} |
172
|
|
|
$i++; |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
///////////////////////////////////////////////////////// |
176
|
|
|
//Skills |
177
|
|
|
/////////////////////////////////////////////////////// |
178
|
|
|
elgg_set_ignore_access(true); |
179
|
|
|
if($user_entity->skill_access == ACCESS_PUBLIC) |
180
|
|
|
$skillsEntity = elgg_get_entities(array( |
181
|
|
|
'owner_guid'=>$user['id'], |
182
|
|
|
'subtype'=>'MySkill', |
183
|
|
|
'type' => 'object', |
184
|
|
|
'limit' => 0 |
185
|
|
|
)); |
186
|
|
|
$i=0; |
187
|
|
View Code Duplication |
foreach($skillsEntity as $skill){ |
|
|
|
|
188
|
|
|
$user['skills']['item_'.$i]['skill'] = $skill->title; |
189
|
|
|
//$user['skills']['item_'.$i]['endorsements'] = $skill->endorsements; |
190
|
|
|
$j = 0; |
191
|
|
|
if(is_array($skill->endorsements)){ |
192
|
|
|
foreach($skill->endorsements as $friend){ |
193
|
|
|
$friendEntity = get_user($friend); |
194
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["id"] = $friendEntity->guid; |
195
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["username"] = $friendEntity->username; |
196
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["displayName"] = $friendEntity->name; |
197
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["profileURL"] = $friendEntity->getURL(); |
198
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["iconURL"] = $friendEntity->geticon(); |
|
|
|
|
199
|
|
|
$j++; |
200
|
|
|
} |
201
|
|
|
}elseif(!is_null($skill->endorsements)){ |
202
|
|
|
$friendEntity = get_user($skill->endorsements); |
203
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["id"] = $friendEntity->guid; |
204
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["username"] = $friendEntity->username; |
205
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["displayName"] = $friendEntity->name; |
206
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["profileURL"] = $friendEntity->getURL(); |
207
|
|
|
$user['skills']['item_'.$i]['endorsements']["user_".$j]["iconURL"] = $friendEntity->geticon(); |
|
|
|
|
208
|
|
|
} |
209
|
|
|
$i++; |
210
|
|
|
} |
211
|
|
|
elgg_set_ignore_access(false); |
212
|
|
|
///////////////////////////////////////////////////////////////////////////////////////// |
213
|
|
|
//Language |
214
|
|
|
//////////////////////////////////////////////////////////////////// |
215
|
|
|
//$user['language']["format"] = "Written Comprehension / Written Expression / Oral Proficiency"; |
216
|
|
|
/*$languageMetadata = elgg_get_metadata(array( |
217
|
|
|
'guid'=>$user['id'], |
218
|
|
|
'limit'=>0, |
219
|
|
|
'metadata_name'=>'english' |
220
|
|
|
)); |
221
|
|
|
if (!is_null($languageMetadata)){ |
222
|
|
|
if($languageMetadata[0]->access_id == 2){ |
223
|
|
|
$user['language']["format"] = "Written Comprehension / Written Expression / Oral Proficiency"; |
224
|
|
|
} |
225
|
|
|
$i = 0; |
226
|
|
|
foreach($languageMetadata as $grade){ |
227
|
|
|
if($grade->access_id == 2){ |
228
|
|
|
|
229
|
|
|
if($i < 3) |
230
|
|
|
$user['language']["english"]['level'] .= $grade->value; |
231
|
|
|
if($i<2){ |
232
|
|
|
$user['language']["english"]['level'].=" / "; |
233
|
|
|
} |
234
|
|
|
if($i == 3) |
235
|
|
|
$user['language']["english"]['expire'] = $grade->value; |
236
|
|
|
} |
237
|
|
|
$i++; |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
$languageMetadata = elgg_get_metadata(array( |
241
|
|
|
'guid'=>$user['id'], |
242
|
|
|
'limit'=>0, |
243
|
|
|
'metadata_name'=>'french' |
244
|
|
|
)); |
245
|
|
|
if (!is_null($languageMetadata)){ |
246
|
|
|
$i = 0; |
247
|
|
|
foreach($languageMetadata as $grade){ |
248
|
|
|
if($grade->access_id == 2){ |
249
|
|
|
if ($i<3) |
250
|
|
|
$user['language']["french"]['level'] .= $grade->value; |
251
|
|
|
if($i<2){ |
252
|
|
|
$user['language']["french"]['level'] .= " / "; |
253
|
|
|
} |
254
|
|
|
if($i == 3) |
255
|
|
|
$user['language']["french"]['expire'] = $grade->value; |
256
|
|
|
} |
257
|
|
|
$i++; |
258
|
|
|
} |
259
|
|
|
}*/ |
260
|
|
|
////////////////////////////////////////////////////////////////////////////////////// |
261
|
|
|
//portfolio |
262
|
|
|
/////////////////////////////////////////////////////////////////// |
263
|
|
|
$portfolioEntity = elgg_get_entities(array( |
264
|
|
|
'owner_guid'=>$user['id'], |
265
|
|
|
'subtype'=>'portfolio', |
266
|
|
|
'type' => 'object', |
267
|
|
|
'limit' => 0 |
268
|
|
|
)); |
269
|
|
|
$i=0; |
270
|
|
|
foreach($portfolioEntity as $portfolio){ |
|
|
|
|
271
|
|
|
if($grade->access_id == 2){ |
|
|
|
|
272
|
|
|
$user['portfolio']['item_'.$i]['title'] = $portfolio->title; |
273
|
|
|
$user['portfolio']['item_'.$i]['link'] = $portfolio->link; |
274
|
|
View Code Duplication |
if($portfolio->datestamped == "on") |
275
|
|
|
$user['portfolio']['item_'.$i]['date'] = $portfolio->publishdate; |
276
|
|
|
$user['portfolio']['item_'.$i]['description'] = $portfolio->description; |
277
|
|
|
} |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
$user['dateJoined'] = date("Y-m-d H:i:s",$user_entity->time_created); |
281
|
|
|
|
282
|
|
|
$user['lastActivity'] = date("Y-m-d H:i:s",$user_entity->last_action); |
283
|
|
|
|
284
|
|
|
$user['lastLogin'] = date("Y-m-d H:i:s",$user_entity->last_login); |
285
|
|
|
|
286
|
|
|
|
287
|
|
|
|
288
|
|
|
return $user; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
function profileUpdate($id, $data){ |
292
|
|
|
global $CONFIG; |
293
|
|
|
$response['error'] = 0; |
|
|
|
|
294
|
|
|
$user_entity = getUserFromID($id); |
295
|
|
|
if (!$user_entity){ |
296
|
|
|
$response['error'] = 1; |
297
|
|
|
$response['message'] = 'Invalid user id, username, or email'; |
298
|
|
|
return $response; |
299
|
|
|
//return "Not a valid user"; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
View Code Duplication |
if ($data == ''){ |
303
|
|
|
$response['error'] = 2; |
304
|
|
|
$response['message'] = 'data must be a string representing a JSON object.'; |
305
|
|
|
return $response; |
306
|
|
|
} |
307
|
|
|
$userDataObj = json_decode($data, true); |
308
|
|
View Code Duplication |
if (json_last_error() !== 0){ |
309
|
|
|
$response['error'] = 2; |
310
|
|
|
$response['message'] = 'invalid JSON - data was unable to be parsed'; |
311
|
|
|
return $response; |
312
|
|
|
//return "invalid JSON format of data"; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
//error_log(json_encode($userDataObj)); |
316
|
|
|
/* |
317
|
|
|
{ |
318
|
|
|
"name": { |
319
|
|
|
"firstName": "Troy", |
320
|
|
|
"lastName": "Lawson" |
321
|
|
|
}, |
322
|
|
|
"title": { |
323
|
|
|
"en": "GCconnex King", |
324
|
|
|
"fr": "le King" |
325
|
|
|
}, |
326
|
|
|
"classification": { |
327
|
|
|
"group": "CS", |
328
|
|
|
"level": "03" |
329
|
|
|
}, |
330
|
|
|
"department":{ |
331
|
|
|
"en": "Treasury Board of Canada Secretariat", |
332
|
|
|
"fr": "Secrétariat Conseil du Trésor du Canada" |
333
|
|
|
}, |
334
|
|
|
"branch":{ |
335
|
|
|
"en": "Information Management and Technology Directorate", |
336
|
|
|
"fr": "Direction générale de la gestion d'information et de la technologie" |
337
|
|
|
}, |
338
|
|
|
"sector":{ |
339
|
|
|
"en": "Corporate Services Sector", |
340
|
|
|
"fr": "Secteur des services ministériels" |
341
|
|
|
}, |
342
|
|
|
"location":{ |
343
|
|
|
"en": { |
344
|
|
|
"street": "140 O'Connor St", |
345
|
|
|
"city": "Ottawa", |
346
|
|
|
"province": "Ontario", |
347
|
|
|
"postalCode": "K1A 0R5", |
348
|
|
|
"country": "Canada", |
349
|
|
|
"building": "L'Esplanade Laurier", |
350
|
|
|
"floor": "6", |
351
|
|
|
"officeNum": "06062" |
352
|
|
|
}, |
353
|
|
|
"fr": { |
354
|
|
|
"street": "140, rue O'Connor", |
355
|
|
|
"city": "Ottawa", |
356
|
|
|
"province": "Ontario", |
357
|
|
|
"postalCode": "K1A 0R5", |
358
|
|
|
"country": "Canada", |
359
|
|
|
"building": "L'Esplanade Laurier", |
360
|
|
|
"floor": "6", |
361
|
|
|
"officeNum": "06062" |
362
|
|
|
} |
363
|
|
|
}, |
364
|
|
|
"phone": "613-979-0315", |
365
|
|
|
"mobile": "613-979-0315", |
366
|
|
|
"email": "[email protected]", |
367
|
|
|
"secondLanguage": { |
368
|
|
|
"firstLang": "en", |
369
|
|
|
"secondLang": { |
370
|
|
|
"lang": "fr", |
371
|
|
|
"writtenComp": { |
372
|
|
|
"level": "B", |
373
|
|
|
"expire": "2016-12-29" |
374
|
|
|
}, |
375
|
|
|
"writtenExpression": { |
376
|
|
|
"level": "C", |
377
|
|
|
"expire": "2016-12-29" |
378
|
|
|
}, |
379
|
|
|
"oral": { |
380
|
|
|
"level": "B", |
381
|
|
|
"expire": "2016-12-29" |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
} |
385
|
|
|
} |
386
|
|
|
} |
387
|
|
|
* |
388
|
|
|
* |
389
|
|
|
*/ |
390
|
|
|
foreach ($userDataObj as $field => $value){ |
391
|
|
|
//error_log('in loop'); |
392
|
|
|
switch($field){ |
393
|
|
|
case 'name': |
394
|
|
|
elgg_set_ignore_access(true); |
395
|
|
|
|
396
|
|
|
//error_log(json_encode($value)); |
397
|
|
|
$nameData = json_decode(json_encode($value), true); |
398
|
|
View Code Duplication |
if (!isset($nameData["firstName"])&&!isset($nameData["lastName"])){ |
399
|
|
|
$response['error'] = 4; |
400
|
|
|
$response['message'] = 'invalid data format - missing first and last name'; |
401
|
|
|
return $response; |
402
|
|
|
|
403
|
|
|
} |
404
|
|
View Code Duplication |
if (!isset($nameData["firstName"])||!isset($nameData["lastName"])){ |
405
|
|
|
$response['error'] = 4; |
406
|
|
|
$response['message'] = 'invalid data format - missing first or last name'; |
407
|
|
|
return $response; |
408
|
|
|
|
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
|
412
|
|
|
$name = $nameData["firstName"].' '.$nameData["lastName"]; |
413
|
|
|
//error_log($name); |
414
|
|
|
//$user_entity->set('name', $name); |
415
|
|
|
//$owner = get_entity($id); |
416
|
|
View Code Duplication |
if (elgg_strlen($name) > 50) { |
417
|
|
|
register_error(elgg_echo('user:name:fail')); |
418
|
|
|
|
419
|
|
|
} elseif ($user_entity->name != $name) { |
420
|
|
|
|
421
|
|
|
//$user=get_user($user_entity->guid); |
422
|
|
|
$user_entity->name= $name; |
423
|
|
|
$user_entity->save(); |
424
|
|
|
|
425
|
|
|
} |
426
|
|
|
elgg_set_ignore_access(false); |
427
|
|
|
break; |
428
|
|
|
case 'title': |
429
|
|
|
|
430
|
|
|
$titleData = json_decode(json_encode($value), true); |
431
|
|
|
if (!isset($titleData['fr'])&&!isset($titleData['en'])){ |
432
|
|
|
$response['error'] = 4; |
433
|
|
|
$response['message'] = 'invalid data format - missing french and english title'; |
434
|
|
|
return $response; |
435
|
|
|
|
436
|
|
|
} |
437
|
|
|
if (!isset($titleData['fr'])||!isset($titleData['en'])){ |
438
|
|
|
$response['error'] = 4; |
439
|
|
|
$response['message'] = 'invalid data format - missing french or english title'; |
440
|
|
|
return $response; |
441
|
|
|
|
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
if ($user_entity->language === 'fr'){ |
445
|
|
|
$user_entity->set('job', $titleData['fr'].' / '.$titleData['en']); |
446
|
|
|
} |
447
|
|
|
else{ |
448
|
|
|
$user_entity->set('job', $titleData['en'].' / '.$titleData['fr']); |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
break; |
452
|
|
View Code Duplication |
case 'classification': |
453
|
|
|
//error_log(json_encode($value)); |
454
|
|
|
$classificationData = json_decode(json_encode($value), true); |
455
|
|
|
if (!isset($classificationData['group'])&&!isset($classificationData['level'])){ |
456
|
|
|
$response['error'] = 4; |
457
|
|
|
$response['message'] = 'invalid data format - missing classification group and level'; |
458
|
|
|
return $response; |
459
|
|
|
|
460
|
|
|
} |
461
|
|
|
if (!isset($classificationData['group'])||!isset($classificationData['level'])){ |
462
|
|
|
$response['error'] = 4; |
463
|
|
|
$response['message'] = 'invalid data format - missing classification group or level'; |
464
|
|
|
return $response; |
465
|
|
|
|
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
$user_entity->set('classification', json_encode($value)); |
469
|
|
|
break; |
470
|
|
|
case 'department': |
471
|
|
|
$deptData = json_decode(json_encode($value), true); |
472
|
|
|
if (!isset($deptData['fr'])&&!isset($deptData['en'])){ |
473
|
|
|
$response['error'] = 4; |
474
|
|
|
$response['message'] = 'invalid data format - department format'; |
475
|
|
|
return $response; |
476
|
|
|
|
477
|
|
|
} |
478
|
|
|
if (!isset($deptData['fr'])||!isset($deptData['en'])){ |
479
|
|
|
$response['error'] = 4; |
480
|
|
|
$response['message'] = 'invalid data format - missing french or english department'; |
481
|
|
|
return $response; |
482
|
|
|
|
483
|
|
|
} |
484
|
|
|
|
485
|
|
|
|
486
|
|
|
$obj = elgg_get_entities(array( |
487
|
|
|
'type' => 'object', |
488
|
|
|
'subtype' => 'dept_list', |
489
|
|
|
'owner_guid' => 0 |
490
|
|
|
)); |
491
|
|
|
$deptListEn = json_decode($obj[0]->deptsEn, true); |
492
|
|
|
$provinces = array(); |
493
|
|
|
$provinces['pov-alb'] = 'Government of Alberta'; |
494
|
|
|
$provinces['pov-bc'] = 'Government of British Columbia'; |
495
|
|
|
$provinces['pov-man'] = 'Government of Manitoba'; |
496
|
|
|
$provinces['pov-nb'] = 'Government of New Brunswick'; |
497
|
|
|
$provinces['pov-nfl'] = 'Government of Newfoundland and Labrador'; |
498
|
|
|
$provinces['pov-ns'] = 'Government of Nova Scotia'; |
499
|
|
|
$provinces['pov-nwt'] = 'Government of Northwest Territories'; |
500
|
|
|
$provinces['pov-nun'] = 'Government of Nunavut'; |
501
|
|
|
$provinces['pov-ont'] = 'Government of Ontario'; |
502
|
|
|
$provinces['pov-pei'] = 'Government of Prince Edward Island'; |
503
|
|
|
$provinces['pov-que'] = 'Government of Quebec'; |
504
|
|
|
$provinces['pov-sask'] = 'Government of Saskatchewan'; |
505
|
|
|
$provinces['pov-yuk'] = 'Government of Yukon'; |
506
|
|
|
$deptAndProvincesEn = array_merge($deptListEn,$provinces); |
507
|
|
|
|
508
|
|
|
|
509
|
|
|
$deptListFr = json_decode($obj[0]->deptsFr, true); |
510
|
|
|
$provinces = array(); |
511
|
|
|
$provinces['pov-alb'] = "Gouvernement de l'Alberta"; |
512
|
|
|
$provinces['pov-bc'] = 'Gouvernement de la Colombie-Britannique'; |
513
|
|
|
$provinces['pov-man'] = 'Gouvernement du Manitoba'; |
514
|
|
|
$provinces['pov-nb'] = 'Gouvernement du Nouveau-Brunswick'; |
515
|
|
|
$provinces['pov-nfl'] = 'Gouvernement de Terre-Neuve-et-Labrador'; |
516
|
|
|
$provinces['pov-ns'] = 'Gouvernement de la Nouvelle-Écosse'; |
517
|
|
|
$provinces['pov-nwt'] = 'Gouvernement du Territoires du Nord-Ouest'; |
518
|
|
|
$provinces['pov-nun'] = 'Gouvernement du Nunavut'; |
519
|
|
|
$provinces['pov-ont'] = "Gouvernement de l'Ontario"; |
520
|
|
|
$provinces['pov-pei'] = "Gouvernement de l'Île-du-Prince-Édouard"; |
521
|
|
|
$provinces['pov-que'] = 'Gouvernement du Québec'; |
522
|
|
|
$provinces['pov-sask'] = 'Gouvernement de Saskatchewan'; |
523
|
|
|
$provinces['pov-yuk'] = 'Gouvernement du Yukon'; |
524
|
|
|
$deptAndProvincesFr = array_merge($deptListFr,$provinces); |
525
|
|
|
|
526
|
|
View Code Duplication |
if(!in_array($deptData['en'], $deptAndProvincesEn)){ |
527
|
|
|
$response['error'] = 5; |
528
|
|
|
$response['message'] = 'invalid english department name. valid names: '.json_encode($deptAndProvincesEn); |
529
|
|
|
return $response; |
530
|
|
|
} |
531
|
|
|
|
532
|
|
View Code Duplication |
if(!in_array($deptData['fr'], $deptAndProvincesFr)){ |
533
|
|
|
$response['error'] = 5; |
534
|
|
|
$response['message'] = 'invalid french department name. valid names: '.json_encode($deptAndProvincesFr); |
535
|
|
|
return $response; |
536
|
|
|
} |
537
|
|
|
//error_log(json_encode($value)); |
538
|
|
|
|
539
|
|
|
if ($user_entity->language === 'fr'){ |
540
|
|
|
$user_entity->set('department', $deptData['fr'].' / '.$deptData['en']); |
541
|
|
|
} |
542
|
|
|
else{ |
543
|
|
|
$user_entity->set('department', $deptData['en'].' / '.$deptData['fr']); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
|
547
|
|
|
break; |
548
|
|
View Code Duplication |
case 'branch': |
549
|
|
|
$branchData = json_decode(json_encode($value), true); |
550
|
|
|
if (!isset($branchData['en'])&&!isset($branchData['fr'])){ |
551
|
|
|
$response['error'] = 4; |
552
|
|
|
$response['message'] = 'invalid data format - missing english and french branch name'; |
553
|
|
|
return $response; |
554
|
|
|
|
555
|
|
|
} |
556
|
|
|
if (!isset($branchData['en'])||!isset($branchData['fr'])){ |
557
|
|
|
$response['error'] = 4; |
558
|
|
|
$response['message'] = 'invalid data format - missing english or french branch name'; |
559
|
|
|
return $response; |
560
|
|
|
|
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
$user_entity->set('branch', json_encode($value)); |
564
|
|
|
break; |
565
|
|
View Code Duplication |
case 'sector': |
566
|
|
|
$sectorData = json_decode(json_encode($value), true); |
567
|
|
|
if (!isset($sectorData['en'])&&!isset($sectorData['fr'])){ |
568
|
|
|
$response['error'] = 4; |
569
|
|
|
$response['message'] = 'invalid data format - missing english and french sector name'; |
570
|
|
|
return $response; |
571
|
|
|
|
572
|
|
|
} |
573
|
|
|
if (!isset($sectorData['en'])||!isset($sectorData['fr'])){ |
574
|
|
|
$response['error'] = 4; |
575
|
|
|
$response['message'] = 'invalid data format - missing english or french sector name'; |
576
|
|
|
return $response; |
577
|
|
|
|
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
$user_entity->set('sector', json_encode($value)); |
581
|
|
|
break; |
582
|
|
|
case 'location': |
583
|
|
View Code Duplication |
if (!isset($value['en'])){ |
584
|
|
|
$response['error'] = 4; |
585
|
|
|
$response['message'] = 'missing english location data'; |
586
|
|
|
return $response; |
587
|
|
|
|
588
|
|
|
} |
589
|
|
|
$locationData = json_decode(json_encode($value['en']), true); |
590
|
|
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'])){ |
591
|
|
|
$response['error'] = 4; |
592
|
|
|
$response['message'] = 'invalid location data'; |
593
|
|
|
return $response; |
594
|
|
|
} |
595
|
|
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'])){ |
596
|
|
|
$response['error'] = 4; |
597
|
|
|
$response['message'] = 'missing location data'; |
598
|
|
|
return $response; |
599
|
|
|
} |
600
|
|
|
|
601
|
|
View Code Duplication |
if (!isset($value['fr'])){ |
602
|
|
|
$response['error'] = 4; |
603
|
|
|
$response['message'] = 'missing french location data'; |
604
|
|
|
return $response; |
605
|
|
|
|
606
|
|
|
} |
607
|
|
|
$locationData = json_decode(json_encode($value['fr']), true); |
608
|
|
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'])){ |
609
|
|
|
$response['error'] = 4; |
610
|
|
|
$response['message'] = 'invalid location data'; |
611
|
|
|
return $response; |
612
|
|
|
} |
613
|
|
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'])){ |
614
|
|
|
$response['error'] = 4; |
615
|
|
|
$response['message'] = 'missing location data'; |
616
|
|
|
return $response; |
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
$user_entity->set('addressString', json_encode($value["en"])); |
620
|
|
|
$user_entity->set('addressStringFr', json_encode($value["fr"])); |
621
|
|
|
break; |
622
|
|
|
case 'phone': |
623
|
|
|
|
624
|
|
|
$user_entity->set('phone', $value); |
625
|
|
|
break; |
626
|
|
|
case 'mobile': |
627
|
|
|
|
628
|
|
|
$user_entity->set('mobile', $value); |
629
|
|
|
break; |
630
|
|
|
case 'email': |
631
|
|
|
|
632
|
|
|
elgg_set_ignore_access(true); |
633
|
|
|
$connection = mysqli_connect($CONFIG->dbhost, $CONFIG->dbuser, $CONFIG->dbpass, $CONFIG->dbname)or die(mysqli_error($connection)); |
|
|
|
|
634
|
|
|
//error_log($CONFIG->dbhost.' '.$CONFIG->dbuser.' '.$CONFIG->dbpass.' '.$CONFIG->dbname); |
635
|
|
|
mysqli_select_db($connection,$CONFIG->dbname); |
636
|
|
|
$emaildomain = explode('@',filter_var($value, FILTER_SANITIZE_EMAIL)); |
637
|
|
|
$query = "SELECT count(*) AS num FROM email_extensions WHERE ext ='".$emaildomain[1]."'"; |
638
|
|
|
|
639
|
|
|
$result = mysqli_query($connection, $query)or die(mysqli_error($connection)); |
|
|
|
|
640
|
|
|
$result = mysqli_fetch_array($result); |
641
|
|
|
|
642
|
|
|
$emailgc = explode('.',$emaildomain[1]); |
643
|
|
|
$gcca = $emailgc[count($emailgc) - 2] .".".$emailgc[count($emailgc) - 1]; |
644
|
|
|
|
645
|
|
|
mysqli_close($connection); |
646
|
|
|
|
647
|
|
|
$resulting_error = ""; |
648
|
|
|
|
649
|
|
|
//if ($toc[0] != 1) |
650
|
|
|
//{ |
651
|
|
|
//throw new RegistrationException(elgg_echo('gcRegister:toc_error')); |
652
|
|
|
// $resulting_error .= elgg_echo('gcRegister:toc_error').'<br/>'; |
653
|
|
|
//} |
654
|
|
|
//error_log('num - '.is_null($result)); |
655
|
|
|
// if domain doesn't exist in database, check if it's a gc.ca domain |
656
|
|
View Code Duplication |
if ($result['num'][0] <= 0) |
657
|
|
|
{ |
658
|
|
|
if ($gcca !== 'gc.ca') |
659
|
|
|
//throw new RegistrationException(elgg_echo('gcRegister:email_error')); |
660
|
|
|
$resulting_error .= elgg_echo('gcRegister:invalid_email'); |
661
|
|
|
|
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
|
665
|
|
View Code Duplication |
if ($resulting_error !== "") |
666
|
|
|
{ |
667
|
|
|
//throw new RegistrationException($resulting_error); |
668
|
|
|
///error_log($resulting_error); |
669
|
|
|
$response['error'] = 3; |
670
|
|
|
$response['message'] = 'invalid email or email domain - must be a valid Government of Canada email address'; |
671
|
|
|
return $response; |
672
|
|
|
} |
673
|
|
|
$user_entity->set('email', $value); |
674
|
|
|
$user_entity->save(); |
675
|
|
|
|
676
|
|
|
elgg_set_ignore_access(false); |
677
|
|
|
break; |
678
|
|
|
case 'secondLanguage': |
679
|
|
|
|
680
|
|
|
$user_entity->set('english', $value["ENG"]); |
681
|
|
|
$user_entity->set('french', $value["FRA"]); |
682
|
|
|
$user_entity->set('officialLanguage', $value["firstLanguage"]); |
683
|
|
|
|
684
|
|
|
break; |
685
|
|
|
} |
686
|
|
|
} |
687
|
|
|
|
688
|
|
|
$user_entity->save(); |
689
|
|
|
return 'success'; |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
function profileCreate($data){ |
693
|
|
|
global $CONFIG; |
694
|
|
|
// check email for duplicate |
695
|
|
|
// get email and create username |
696
|
|
|
// create account |
697
|
|
|
// send password reset email |
698
|
|
|
// fill in profile data |
699
|
|
View Code Duplication |
if ($data == ''){ |
700
|
|
|
$response['error'] = 2; |
|
|
|
|
701
|
|
|
$response['message'] = 'data must be a string representing a JSON object.'; |
702
|
|
|
return $response; |
703
|
|
|
} |
704
|
|
|
$userDataObj = json_decode($data, true); |
705
|
|
View Code Duplication |
if (json_last_error() !== 0){ |
706
|
|
|
$response['error'] = 2; |
|
|
|
|
707
|
|
|
$response['message'] = 'invalid JSON - data was unable to be parsed'; |
708
|
|
|
return $response; |
709
|
|
|
//return "invalid JSON format of data"; |
710
|
|
|
} |
711
|
|
|
|
712
|
|
|
/////////////////////////////////////////////////////////////////// |
713
|
|
|
//error check data field |
714
|
|
|
/////////////////////////////////////////////////////////////////// |
715
|
|
|
foreach ($userDataObj as $field => $value){ |
716
|
|
|
//error_log('in loop'); |
717
|
|
|
switch($field){ |
718
|
|
|
case 'name': |
719
|
|
|
|
720
|
|
|
|
721
|
|
|
//error_log(json_encode($value)); |
722
|
|
|
$nameData = json_decode(json_encode($value), true); |
723
|
|
View Code Duplication |
if (!isset($nameData["firstName"])&&!isset($nameData["lastName"])){ |
724
|
|
|
$response['error'] = 4; |
|
|
|
|
725
|
|
|
$response['message'] = 'invalid data format - missing first and last name'; |
726
|
|
|
return $response; |
727
|
|
|
|
728
|
|
|
} |
729
|
|
View Code Duplication |
if (!isset($nameData["firstName"])||!isset($nameData["lastName"])){ |
730
|
|
|
$response['error'] = 4; |
|
|
|
|
731
|
|
|
$response['message'] = 'invalid data format - missing first or last name'; |
732
|
|
|
return $response; |
733
|
|
|
|
734
|
|
|
} |
735
|
|
|
|
736
|
|
|
|
737
|
|
|
$name = $nameData["firstName"].' '.$nameData["lastName"]; |
738
|
|
|
|
739
|
|
|
break; |
740
|
|
View Code Duplication |
case 'title': |
741
|
|
|
|
742
|
|
|
$titleData = json_decode(json_encode($value), true); |
743
|
|
|
if (!isset($titleData['fr'])&&!isset($titleData['en'])){ |
744
|
|
|
$response['error'] = 4; |
|
|
|
|
745
|
|
|
$response['message'] = 'invalid data format - missing french and english title'; |
746
|
|
|
return $response; |
747
|
|
|
|
748
|
|
|
} |
749
|
|
|
if (!isset($titleData['fr'])||!isset($titleData['en'])){ |
750
|
|
|
$response['error'] = 4; |
|
|
|
|
751
|
|
|
$response['message'] = 'invalid data format - missing french or english title'; |
752
|
|
|
return $response; |
753
|
|
|
|
754
|
|
|
} |
755
|
|
|
|
756
|
|
|
|
757
|
|
|
|
758
|
|
|
break; |
759
|
|
View Code Duplication |
case 'classification': |
760
|
|
|
//error_log(json_encode($value)); |
761
|
|
|
$classificationData = json_decode(json_encode($value), true); |
762
|
|
|
if (!isset($classificationData['group'])&&!isset($classificationData['level'])){ |
763
|
|
|
$response['error'] = 4; |
|
|
|
|
764
|
|
|
$response['message'] = 'invalid data format - missing classification group and level'; |
765
|
|
|
return $response; |
766
|
|
|
|
767
|
|
|
} |
768
|
|
|
if (!isset($classificationData['group'])||!isset($classificationData['level'])){ |
769
|
|
|
$response['error'] = 4; |
|
|
|
|
770
|
|
|
$response['message'] = 'invalid data format - missing classification group or level'; |
771
|
|
|
return $response; |
772
|
|
|
|
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
break; |
776
|
|
|
case 'department': |
777
|
|
|
$deptData = json_decode(json_encode($value), true); |
778
|
|
|
if (!isset($deptData['fr'])&&!isset($deptData['en'])){ |
779
|
|
|
$response['error'] = 4; |
|
|
|
|
780
|
|
|
$response['message'] = 'invalid data format - department format'; |
781
|
|
|
return $response; |
782
|
|
|
|
783
|
|
|
} |
784
|
|
|
if (!isset($deptData['fr'])||!isset($deptData['en'])){ |
785
|
|
|
$response['error'] = 4; |
|
|
|
|
786
|
|
|
$response['message'] = 'invalid data format - missing french or english department'; |
787
|
|
|
return $response; |
788
|
|
|
|
789
|
|
|
} |
790
|
|
|
|
791
|
|
|
|
792
|
|
|
$obj = elgg_get_entities(array( |
793
|
|
|
'type' => 'object', |
794
|
|
|
'subtype' => 'dept_list', |
795
|
|
|
'owner_guid' => 0 |
796
|
|
|
)); |
797
|
|
|
$deptListEn = json_decode($obj[0]->deptsEn, true); |
798
|
|
|
$provinces = array(); |
799
|
|
|
$provinces['pov-alb'] = 'Government of Alberta'; |
800
|
|
|
$provinces['pov-bc'] = 'Government of British Columbia'; |
801
|
|
|
$provinces['pov-man'] = 'Government of Manitoba'; |
802
|
|
|
$provinces['pov-nb'] = 'Government of New Brunswick'; |
803
|
|
|
$provinces['pov-nfl'] = 'Government of Newfoundland and Labrador'; |
804
|
|
|
$provinces['pov-ns'] = 'Government of Nova Scotia'; |
805
|
|
|
$provinces['pov-nwt'] = 'Government of Northwest Territories'; |
806
|
|
|
$provinces['pov-nun'] = 'Government of Nunavut'; |
807
|
|
|
$provinces['pov-ont'] = 'Government of Ontario'; |
808
|
|
|
$provinces['pov-pei'] = 'Government of Prince Edward Island'; |
809
|
|
|
$provinces['pov-que'] = 'Government of Quebec'; |
810
|
|
|
$provinces['pov-sask'] = 'Government of Saskatchewan'; |
811
|
|
|
$provinces['pov-yuk'] = 'Government of Yukon'; |
812
|
|
|
$deptAndProvincesEn = array_merge($deptListEn,$provinces); |
813
|
|
|
|
814
|
|
|
|
815
|
|
|
$deptListFr = json_decode($obj[0]->deptsFr, true); |
816
|
|
|
$provinces = array(); |
817
|
|
|
$provinces['pov-alb'] = "Gouvernement de l'Alberta"; |
818
|
|
|
$provinces['pov-bc'] = 'Gouvernement de la Colombie-Britannique'; |
819
|
|
|
$provinces['pov-man'] = 'Gouvernement du Manitoba'; |
820
|
|
|
$provinces['pov-nb'] = 'Gouvernement du Nouveau-Brunswick'; |
821
|
|
|
$provinces['pov-nfl'] = 'Gouvernement de Terre-Neuve-et-Labrador'; |
822
|
|
|
$provinces['pov-ns'] = 'Gouvernement de la Nouvelle-Écosse'; |
823
|
|
|
$provinces['pov-nwt'] = 'Gouvernement du Territoires du Nord-Ouest'; |
824
|
|
|
$provinces['pov-nun'] = 'Gouvernement du Nunavut'; |
825
|
|
|
$provinces['pov-ont'] = "Gouvernement de l'Ontario"; |
826
|
|
|
$provinces['pov-pei'] = "Gouvernement de l'Île-du-Prince-Édouard"; |
827
|
|
|
$provinces['pov-que'] = 'Gouvernement du Québec'; |
828
|
|
|
$provinces['pov-sask'] = 'Gouvernement de Saskatchewan'; |
829
|
|
|
$provinces['pov-yuk'] = 'Gouvernement du Yukon'; |
830
|
|
|
$deptAndProvincesFr = array_merge($deptListFr,$provinces); |
831
|
|
|
|
832
|
|
View Code Duplication |
if(!in_array($deptData['en'], $deptAndProvincesEn)){ |
833
|
|
|
$response['error'] = 5; |
|
|
|
|
834
|
|
|
$response['message'] = 'invalid english department name. valid names: '.json_encode($deptAndProvincesEn); |
835
|
|
|
return $response; |
836
|
|
|
} |
837
|
|
|
|
838
|
|
View Code Duplication |
if(!in_array($deptData['fr'], $deptAndProvincesFr)){ |
839
|
|
|
$response['error'] = 5; |
|
|
|
|
840
|
|
|
$response['message'] = 'invalid french department name. valid names: '.json_encode($deptAndProvincesFr); |
841
|
|
|
return $response; |
842
|
|
|
} |
843
|
|
|
|
844
|
|
|
|
845
|
|
|
break; |
846
|
|
View Code Duplication |
case 'branch': |
847
|
|
|
$branchData = json_decode(json_encode($value), true); |
848
|
|
|
if (!isset($branchData['en'])&&!isset($branchData['fr'])){ |
849
|
|
|
$response['error'] = 4; |
|
|
|
|
850
|
|
|
$response['message'] = 'invalid data format - missing english and french branch name'; |
851
|
|
|
return $response; |
852
|
|
|
|
853
|
|
|
} |
854
|
|
|
if (!isset($branchData['en'])||!isset($branchData['fr'])){ |
855
|
|
|
$response['error'] = 4; |
|
|
|
|
856
|
|
|
$response['message'] = 'invalid data format - missing english or french branch name'; |
857
|
|
|
return $response; |
858
|
|
|
|
859
|
|
|
} |
860
|
|
|
|
861
|
|
|
|
862
|
|
|
break; |
863
|
|
View Code Duplication |
case 'sector': |
864
|
|
|
$sectorData = json_decode(json_encode($value), true); |
865
|
|
|
if (!isset($sectorData['en'])&&!isset($sectorData['fr'])){ |
866
|
|
|
$response['error'] = 4; |
|
|
|
|
867
|
|
|
$response['message'] = 'invalid data format - missing english and french sector name'; |
868
|
|
|
return $response; |
869
|
|
|
|
870
|
|
|
} |
871
|
|
|
if (!isset($sectorData['en'])||!isset($sectorData['fr'])){ |
872
|
|
|
$response['error'] = 4; |
|
|
|
|
873
|
|
|
$response['message'] = 'invalid data format - missing english or french sector name'; |
874
|
|
|
return $response; |
875
|
|
|
|
876
|
|
|
} |
877
|
|
|
|
878
|
|
|
|
879
|
|
|
break; |
880
|
|
|
case 'location': |
881
|
|
View Code Duplication |
if (!isset($value['en'])){ |
882
|
|
|
$response['error'] = 4; |
|
|
|
|
883
|
|
|
$response['message'] = 'missing english location data'; |
884
|
|
|
return $response; |
885
|
|
|
|
886
|
|
|
} |
887
|
|
|
$locationData = json_decode(json_encode($value['en']), true); |
888
|
|
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'])){ |
889
|
|
|
$response['error'] = 4; |
|
|
|
|
890
|
|
|
$response['message'] = 'invalid location data'; |
891
|
|
|
return $response; |
892
|
|
|
} |
893
|
|
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'])){ |
894
|
|
|
$response['error'] = 4; |
|
|
|
|
895
|
|
|
$response['message'] = 'missing location data'; |
896
|
|
|
return $response; |
897
|
|
|
} |
898
|
|
|
|
899
|
|
View Code Duplication |
if (!isset($value['fr'])){ |
900
|
|
|
$response['error'] = 4; |
|
|
|
|
901
|
|
|
$response['message'] = 'missing french location data'; |
902
|
|
|
return $response; |
903
|
|
|
|
904
|
|
|
} |
905
|
|
|
$locationData = json_decode(json_encode($value['fr']), true); |
906
|
|
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'])){ |
907
|
|
|
$response['error'] = 4; |
|
|
|
|
908
|
|
|
$response['message'] = 'invalid location data'; |
909
|
|
|
return $response; |
910
|
|
|
} |
911
|
|
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'])){ |
912
|
|
|
$response['error'] = 4; |
|
|
|
|
913
|
|
|
$response['message'] = 'missing location data'; |
914
|
|
|
return $response; |
915
|
|
|
} |
916
|
|
|
|
917
|
|
|
|
918
|
|
|
break; |
919
|
|
|
|
920
|
|
|
case 'email': |
921
|
|
|
|
922
|
|
|
|
923
|
|
|
$connection = mysqli_connect($CONFIG->dbhost, $CONFIG->dbuser, $CONFIG->dbpass, $CONFIG->dbname)or die(mysqli_error($connection)); |
|
|
|
|
924
|
|
|
//error_log($CONFIG->dbhost.' '.$CONFIG->dbuser.' '.$CONFIG->dbpass.' '.$CONFIG->dbname); |
925
|
|
|
mysqli_select_db($connection,$CONFIG->dbname); |
926
|
|
|
$emaildomain = explode('@',filter_var($value, FILTER_SANITIZE_EMAIL)); |
927
|
|
|
|
928
|
|
|
$query = "SELECT count(*) AS num FROM email_extensions WHERE ext ='".$emaildomain[1]."'"; |
929
|
|
|
|
930
|
|
|
$result = mysqli_query($connection, $query)or die(mysqli_error($connection)); |
|
|
|
|
931
|
|
|
$result = mysqli_fetch_array($result); |
932
|
|
|
|
933
|
|
|
$emailgc = explode('.',$emaildomain[1]); |
934
|
|
|
$gcca = $emailgc[count($emailgc) - 2] .".".$emailgc[count($emailgc) - 1]; |
935
|
|
|
|
936
|
|
|
mysqli_close($connection); |
937
|
|
|
|
938
|
|
|
$resulting_error = ""; |
939
|
|
|
|
940
|
|
|
|
941
|
|
|
// if domain doesn't exist in database, check if it's a gc.ca domain |
942
|
|
View Code Duplication |
if ($result['num'][0] <= 0) |
943
|
|
|
{ |
944
|
|
|
if ($gcca !== 'gc.ca') |
945
|
|
|
//throw new RegistrationException(elgg_echo('gcRegister:email_error')); |
946
|
|
|
$resulting_error .= elgg_echo('gcRegister:invalid_email'); |
947
|
|
|
|
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
|
951
|
|
View Code Duplication |
if ($resulting_error !== "") |
952
|
|
|
{ |
953
|
|
|
//throw new RegistrationException($resulting_error); |
954
|
|
|
///error_log($resulting_error); |
955
|
|
|
$response['error'] = 3; |
|
|
|
|
956
|
|
|
$response['message'] = 'invalid email or email domain - must be a valid Government of Canada email address'; |
957
|
|
|
return $response; |
958
|
|
|
} |
959
|
|
|
|
960
|
|
|
break; |
961
|
|
|
|
962
|
|
|
} |
963
|
|
|
} |
964
|
|
|
|
965
|
|
|
|
966
|
|
|
//check for existing email |
967
|
|
|
$email = $userDataObj['email']; |
968
|
|
|
if(get_user_by_email($email)){ |
969
|
|
|
$response['error'] = 1; |
|
|
|
|
970
|
|
|
$response['message'] = 'user with email already exists. please use profile.update call to update existing account'; |
971
|
|
|
return $response; |
972
|
|
|
} |
973
|
|
|
//make usernaem based on email |
974
|
|
|
$username = strstr(strtolower($email),'@', true); |
975
|
|
|
|
976
|
|
|
$username = explode('.', $username); |
977
|
|
|
foreach ($username as $u=>$v){ |
978
|
|
|
$username[$u] = ucfirst($v); |
979
|
|
|
//error_log($u); |
980
|
|
|
} |
981
|
|
|
$username = implode('.',$username); |
982
|
|
|
|
983
|
|
|
//check system for username. if is a username, append number or add number |
984
|
|
|
while(get_user_by_username($username)){ |
985
|
|
|
if (is_numeric(substr($username, -1))){ |
986
|
|
|
$num = substr($username, -1)+1; |
987
|
|
|
$username = substr($username, 0,strlen($username)-1).$num; |
988
|
|
|
}else{ |
989
|
|
|
$username.='2'; |
990
|
|
|
} |
991
|
|
|
} |
992
|
|
|
$tempPass = generateRandomString(); |
993
|
|
|
|
994
|
|
|
//check for name data and prepair display name |
995
|
|
|
|
996
|
|
|
|
997
|
|
|
//register user using data passed |
998
|
|
|
$userGUID = register_user($username, $tempPass, $name, $userDataObj['email']); |
|
|
|
|
999
|
|
View Code Duplication |
if ($userGUID==false){ |
|
|
|
|
1000
|
|
|
$response['error'] = 1; |
|
|
|
|
1001
|
|
|
$response['message'] = 'Failed creating account'; |
1002
|
|
|
return $response; |
1003
|
|
|
} |
1004
|
|
|
//error_log($userGUID); |
1005
|
|
|
|
1006
|
|
|
$user_entity = get_user($userGUID); |
1007
|
|
|
|
1008
|
|
|
foreach ($userDataObj as $field => $value){ |
1009
|
|
|
//error_log('in loop'); |
1010
|
|
|
switch($field){ |
1011
|
|
|
|
1012
|
|
View Code Duplication |
case 'title': |
1013
|
|
|
|
1014
|
|
|
$titleData = json_decode(json_encode($value), true); |
1015
|
|
|
|
1016
|
|
|
if ($user_entity->language === 'fr'){ |
1017
|
|
|
$user_entity->set('job', $titleData['fr'].' / '.$titleData['en']); |
|
|
|
|
1018
|
|
|
} |
1019
|
|
|
else{ |
1020
|
|
|
$user_entity->set('job', $titleData['en'].' / '.$titleData['fr']); |
|
|
|
|
1021
|
|
|
} |
1022
|
|
|
|
1023
|
|
|
break; |
1024
|
|
|
case 'classification': |
1025
|
|
|
//error_log(json_encode($value)); |
1026
|
|
|
$classificationData = json_decode(json_encode($value), true); |
|
|
|
|
1027
|
|
|
|
1028
|
|
|
$user_entity->set('classification', json_encode($value)); |
|
|
|
|
1029
|
|
|
break; |
1030
|
|
View Code Duplication |
case 'department': |
1031
|
|
|
$deptData = json_decode(json_encode($value), true); |
1032
|
|
|
|
1033
|
|
|
|
1034
|
|
|
if ($user_entity->language === 'fr'){ |
1035
|
|
|
$user_entity->set('department', $deptData['fr'].' / '.$deptData['en']); |
|
|
|
|
1036
|
|
|
} |
1037
|
|
|
else{ |
1038
|
|
|
$user_entity->set('department', $deptData['en'].' / '.$deptData['fr']); |
|
|
|
|
1039
|
|
|
} |
1040
|
|
|
|
1041
|
|
|
|
1042
|
|
|
break; |
1043
|
|
|
case 'branch': |
1044
|
|
|
$branchData = json_decode(json_encode($value), true); |
|
|
|
|
1045
|
|
|
|
1046
|
|
|
$user_entity->set('branch', json_encode($value)); |
|
|
|
|
1047
|
|
|
break; |
1048
|
|
|
case 'sector': |
1049
|
|
|
$sectorData = json_decode(json_encode($value), true); |
|
|
|
|
1050
|
|
|
|
1051
|
|
|
$user_entity->set('sector', json_encode($value)); |
|
|
|
|
1052
|
|
|
break; |
1053
|
|
|
case 'location': |
1054
|
|
|
|
1055
|
|
|
$user_entity->set('addressString', json_encode($value["en"])); |
|
|
|
|
1056
|
|
|
$user_entity->set('addressStringFr', json_encode($value["fr"])); |
|
|
|
|
1057
|
|
|
break; |
1058
|
|
|
case 'phone': |
1059
|
|
|
|
1060
|
|
|
$user_entity->set('phone', $value); |
|
|
|
|
1061
|
|
|
break; |
1062
|
|
|
case 'mobile': |
1063
|
|
|
|
1064
|
|
|
$user_entity->set('mobile', $value); |
|
|
|
|
1065
|
|
|
break; |
1066
|
|
|
|
1067
|
|
|
|
1068
|
|
|
} |
1069
|
|
|
} |
1070
|
|
|
//save user |
1071
|
|
|
$user_entity->save(); |
1072
|
|
|
//send password reset to user |
1073
|
|
|
send_new_password_request($userGUID); |
1074
|
|
|
return array( |
1075
|
|
|
"guid"=> $userGUID, |
1076
|
|
|
"message" => "user added" |
1077
|
|
|
); |
1078
|
|
|
} |
1079
|
|
|
function generateRandomString($length = 10) { |
1080
|
|
|
return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/strlen($x)) )),1,$length); |
1081
|
|
|
} |
1082
|
|
|
|
1083
|
|
|
function getUserFromID($id){ |
1084
|
|
|
if (is_numeric($id)){ |
1085
|
|
|
$user_entity = get_user($id); |
1086
|
|
|
//$string = $user_entity->username; |
1087
|
|
|
} |
1088
|
|
|
else{ |
1089
|
|
|
if (strpos($id, '@')){ |
1090
|
|
|
$user_entity = get_user_by_email($id); |
1091
|
|
|
if (is_array($user_entity)){ |
1092
|
|
|
if (count($user_entity)>1) |
1093
|
|
|
//$string = "Found more than 1 user, please use username or GUID"; |
1094
|
|
|
return "Found more than 1 user, please use username or GUID"; |
1095
|
|
|
else{ |
1096
|
|
|
$user_entity = $user_entity[0]; |
1097
|
|
|
//$string = $user_entity->username; |
1098
|
|
|
} |
1099
|
|
|
} |
1100
|
|
|
}else{ |
1101
|
|
|
$user_entity = get_user_by_username($id); |
1102
|
|
|
//$string = $user_entity->username; |
1103
|
|
|
} |
1104
|
|
|
|
1105
|
|
|
|
1106
|
|
|
} |
1107
|
|
|
return $user_entity; |
1108
|
|
|
} |
1109
|
|
|
|
1110
|
|
View Code Duplication |
function buildDate($month, $year){ |
|
|
|
|
1111
|
|
|
switch($month){ |
1112
|
|
|
case 1: |
1113
|
|
|
$string = "01/"; |
1114
|
|
|
break; |
1115
|
|
|
case 2: |
1116
|
|
|
$string = "02/"; |
1117
|
|
|
break; |
1118
|
|
|
case 3: |
1119
|
|
|
$string = "03/"; |
1120
|
|
|
break; |
1121
|
|
|
case 4: |
1122
|
|
|
$string = "04/"; |
1123
|
|
|
break; |
1124
|
|
|
case 5: |
1125
|
|
|
$string = "05/"; |
1126
|
|
|
break; |
1127
|
|
|
case 6: |
1128
|
|
|
$string = "06/"; |
1129
|
|
|
break; |
1130
|
|
|
case 7: |
1131
|
|
|
$string = "07/"; |
1132
|
|
|
break; |
1133
|
|
|
case 8: |
1134
|
|
|
$string = "08/"; |
1135
|
|
|
break; |
1136
|
|
|
case 9: |
1137
|
|
|
$string = "09/"; |
1138
|
|
|
break; |
1139
|
|
|
case 10: |
1140
|
|
|
$string = "10/"; |
1141
|
|
|
break; |
1142
|
|
|
case 11: |
1143
|
|
|
$string = "11/"; |
1144
|
|
|
break; |
1145
|
|
|
case 12: |
1146
|
|
|
$string = "12/"; |
1147
|
|
|
break; |
1148
|
|
|
} |
1149
|
|
|
return $string.$year; |
|
|
|
|
1150
|
|
|
|
1151
|
|
|
} |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.