1
|
|
|
<?php |
2
|
|
|
/* For licensing terms, see /license.txt */ |
3
|
|
|
|
4
|
|
|
use Chamilo\CoreBundle\Entity\ExtraField as EntityExtraField; |
5
|
|
|
use Chamilo\UserBundle\Entity\User; |
6
|
|
|
|
7
|
|
|
require_once __DIR__.'/../inc/global.inc.php'; |
8
|
|
|
|
9
|
|
|
api_protect_webservices(); |
10
|
|
|
|
11
|
|
|
$debug = true; |
12
|
|
|
|
13
|
|
|
define('WS_ERROR_SECRET_KEY', 1); |
14
|
|
|
define('WS_ERROR_NOT_FOUND_RESULT', 2); |
15
|
|
|
define('WS_ERROR_INVALID_INPUT', 3); |
16
|
|
|
define('WS_ERROR_SETTING', 4); |
17
|
|
|
define('DEFAULT_ADMIN_USER_ID', 1); |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param string $code |
21
|
|
|
* |
22
|
|
|
* @return soap_fault|null |
23
|
|
|
*/ |
24
|
|
|
function returnError($code) |
25
|
|
|
{ |
26
|
|
|
$fault = null; |
27
|
|
|
switch ($code) { |
28
|
|
|
case WS_ERROR_SECRET_KEY: |
29
|
|
|
$fault = new soap_fault( |
30
|
|
|
'Server', |
31
|
|
|
'', |
32
|
|
|
'Secret key is not correct or params are not correctly set' |
33
|
|
|
); |
34
|
|
|
break; |
35
|
|
|
case WS_ERROR_NOT_FOUND_RESULT: |
36
|
|
|
$fault = new soap_fault( |
37
|
|
|
'Server', |
38
|
|
|
'', |
39
|
|
|
'No result was found for this query' |
40
|
|
|
); |
41
|
|
|
break; |
42
|
|
|
case WS_ERROR_INVALID_INPUT: |
43
|
|
|
$fault = new soap_fault( |
44
|
|
|
'Server', |
45
|
|
|
'', |
46
|
|
|
'The input variables are invalid o are not correctly set' |
47
|
|
|
); |
48
|
|
|
break; |
49
|
|
|
case WS_ERROR_SETTING: |
50
|
|
|
$fault = new soap_fault( |
51
|
|
|
'Server', |
52
|
|
|
'', |
53
|
|
|
'Please check the configuration for this webservice' |
54
|
|
|
); |
55
|
|
|
break; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $fault; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param array $params |
63
|
|
|
* |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
|
|
function WSHelperVerifyKey($params) |
67
|
|
|
{ |
68
|
|
|
global $_configuration, $debug; |
69
|
|
|
if (is_array($params)) { |
70
|
|
|
$secret_key = $params['secret_key']; |
71
|
|
|
} else { |
72
|
|
|
$secret_key = $params; |
73
|
|
|
} |
74
|
|
|
//error_log(print_r($params,1)); |
75
|
|
|
$check_ip = false; |
76
|
|
|
$ip_matches = false; |
77
|
|
|
$ip = trim($_SERVER['REMOTE_ADDR']); |
78
|
|
|
// if we are behind a reverse proxy, assume it will send the |
79
|
|
|
// HTTP_X_FORWARDED_FOR header and use this IP instead |
80
|
|
|
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
81
|
|
|
list($ip1) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
82
|
|
|
$ip = trim($ip1); |
83
|
|
|
} |
84
|
|
|
if ($debug) { |
85
|
|
|
error_log("ip: $ip"); |
86
|
|
|
} |
87
|
|
|
// Check if a file that limits access from webservices exists and contains |
88
|
|
|
// the restraining check |
89
|
|
|
if (is_file('webservice-auth-ip.conf.php')) { |
90
|
|
|
include 'webservice-auth-ip.conf.php'; |
91
|
|
|
if ($debug) { |
92
|
|
|
error_log("webservice-auth-ip.conf.php file included"); |
93
|
|
|
} |
94
|
|
|
if (!empty($ws_auth_ip)) { |
95
|
|
|
$check_ip = true; |
96
|
|
|
$ip_matches = api_check_ip_in_range($ip, $ws_auth_ip); |
97
|
|
|
if ($debug) { |
98
|
|
|
error_log("ip_matches: $ip_matches"); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if ($debug) { |
104
|
|
|
error_log("checkip ".intval($check_ip)); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
if ($check_ip) { |
108
|
|
|
$security_key = $_configuration['security_key']; |
109
|
|
|
} else { |
110
|
|
|
$security_key = $ip.$_configuration['security_key']; |
111
|
|
|
//error_log($ip.'-'.$secret_key.'-'.$security_key); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$result = api_is_valid_secret_key($secret_key, $security_key); |
115
|
|
|
|
116
|
|
|
if ($debug) { |
117
|
|
|
error_log('WSHelperVerifyKey result: '.intval($result)); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return $result; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
// Create the server instance |
124
|
|
|
$server = new soap_server(); |
125
|
|
|
|
126
|
|
|
/** @var HookWSRegistration $hook */ |
127
|
|
|
$hook = HookWSRegistration::create(); |
128
|
|
|
if (!empty($hook)) { |
129
|
|
|
$hook->setEventData(['server' => $server]); |
130
|
|
|
$res = $hook->notifyWSRegistration(HOOK_EVENT_TYPE_PRE); |
131
|
|
|
if (!empty($res['server'])) { |
132
|
|
|
$server = $res['server']; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
$server->soap_defencoding = 'UTF-8'; |
137
|
|
|
|
138
|
|
|
// Initialize WSDL support |
139
|
|
|
$server->configureWSDL('WSRegistration', 'urn:WSRegistration'); |
140
|
|
|
|
141
|
|
|
/* Register WSCreateUsers function */ |
142
|
|
|
// Register the data structures used by the service |
143
|
|
|
|
144
|
|
|
// Prepare input params |
145
|
|
|
$server->wsdl->addComplexType( |
146
|
|
|
'extras', |
147
|
|
|
'complexType', |
148
|
|
|
'struct', |
149
|
|
|
'all', |
150
|
|
|
'', |
151
|
|
|
[ |
152
|
|
|
'field_name' => ['name' => 'field_name', 'type' => 'xsd:string'], |
153
|
|
|
'field_value' => ['name' => 'field_value', 'type' => 'xsd:string'], |
154
|
|
|
] |
155
|
|
|
); |
156
|
|
|
|
157
|
|
|
$server->wsdl->addComplexType( |
158
|
|
|
'extrasList', |
159
|
|
|
'complexType', |
160
|
|
|
'array', |
161
|
|
|
'', |
162
|
|
|
'SOAP-ENC:Array', |
163
|
|
|
[], |
164
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:extras[]']], |
165
|
|
|
'tns:extras' |
166
|
|
|
); |
167
|
|
|
|
168
|
|
|
$server->wsdl->addComplexType( |
169
|
|
|
'usersParams', |
170
|
|
|
'complexType', |
171
|
|
|
'struct', |
172
|
|
|
'all', |
173
|
|
|
'', |
174
|
|
|
[ |
175
|
|
|
'firstname' => ['name' => 'firstname', 'type' => 'xsd:string'], |
176
|
|
|
'lastname' => ['name' => 'lastname', 'type' => 'xsd:string'], |
177
|
|
|
'status' => ['name' => 'status', 'type' => 'xsd:string'], |
178
|
|
|
'email' => ['name' => 'email', 'type' => 'xsd:string'], |
179
|
|
|
'loginname' => ['name' => 'loginname', 'type' => 'xsd:string'], |
180
|
|
|
'password' => ['name' => 'password', 'type' => 'xsd:string'], |
181
|
|
|
'language' => ['name' => 'language', 'type' => 'xsd:string'], |
182
|
|
|
'phone' => ['name' => 'phone', 'type' => 'xsd:string'], |
183
|
|
|
'expiration_date' => ['name' => 'expiration_date', 'type' => 'xsd:string'], |
184
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
185
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
186
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:extrasList'], |
187
|
|
|
] |
188
|
|
|
); |
189
|
|
|
|
190
|
|
|
$server->wsdl->addComplexType( |
191
|
|
|
'usersParamsList', |
192
|
|
|
'complexType', |
193
|
|
|
'array', |
194
|
|
|
'', |
195
|
|
|
'SOAP-ENC:Array', |
196
|
|
|
[], |
197
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:usersParams[]']], |
198
|
|
|
'tns:usersParams' |
199
|
|
|
); |
200
|
|
|
|
201
|
|
|
$server->wsdl->addComplexType( |
202
|
|
|
'createUsers', |
203
|
|
|
'complexType', |
204
|
|
|
'struct', |
205
|
|
|
'all', |
206
|
|
|
'', |
207
|
|
|
[ |
208
|
|
|
'users' => ['name' => 'users', 'type' => 'tns:usersParamsList'], |
209
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
210
|
|
|
] |
211
|
|
|
); |
212
|
|
|
|
213
|
|
|
// Prepare output params, in this case will return an array |
214
|
|
|
$server->wsdl->addComplexType( |
215
|
|
|
'result_createUsers', |
216
|
|
|
'complexType', |
217
|
|
|
'struct', |
218
|
|
|
'all', |
219
|
|
|
'', |
220
|
|
|
[ |
221
|
|
|
'original_user_id_value' => [ |
222
|
|
|
'name' => 'original_user_id_value', |
223
|
|
|
'type' => 'xsd:string', |
224
|
|
|
], |
225
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
226
|
|
|
] |
227
|
|
|
); |
228
|
|
|
|
229
|
|
|
$server->wsdl->addComplexType( |
230
|
|
|
'results_createUsers', |
231
|
|
|
'complexType', |
232
|
|
|
'array', |
233
|
|
|
'', |
234
|
|
|
'SOAP-ENC:Array', |
235
|
|
|
[], |
236
|
|
|
[ |
237
|
|
|
[ |
238
|
|
|
'ref' => 'SOAP-ENC:arrayType', |
239
|
|
|
'wsdl:arrayType' => 'tns:result_createUsers[]', |
240
|
|
|
], |
241
|
|
|
], |
242
|
|
|
'tns:result_createUsers' |
243
|
|
|
); |
244
|
|
|
|
245
|
|
|
// Register the method to expose |
246
|
|
|
$server->register( |
247
|
|
|
'WSCreateUsers', // method name |
248
|
|
|
['createUsers' => 'tns:createUsers'], // input parameters |
249
|
|
|
['return' => 'tns:results_createUsers'], // output parameters |
250
|
|
|
'urn:WSRegistration', // namespace |
251
|
|
|
'urn:WSRegistration#WSCreateUsers', // soapaction |
252
|
|
|
'rpc', // style |
253
|
|
|
'encoded', // use |
254
|
|
|
'This service adds a user' // documentation |
255
|
|
|
); |
256
|
|
|
|
257
|
|
|
// Define the method WSCreateUsers |
258
|
|
|
function WSCreateUsers($params) |
259
|
|
|
{ |
260
|
|
|
if (!WSHelperVerifyKey($params)) { |
261
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
$users_params = $params['users']; |
265
|
|
|
$results = []; |
266
|
|
|
$orig_user_id_value = []; |
267
|
|
|
|
268
|
|
|
$userManager = UserManager::getManager(); |
269
|
|
|
$userRepository = UserManager::getRepository(); |
270
|
|
|
|
271
|
|
|
foreach ($users_params as $user_param) { |
272
|
|
|
$firstName = $user_param['firstname']; |
273
|
|
|
$lastName = $user_param['lastname']; |
274
|
|
|
$status = $user_param['status']; |
275
|
|
|
$email = $user_param['email']; |
276
|
|
|
$loginName = $user_param['loginname']; |
277
|
|
|
$password = $user_param['password']; |
278
|
|
|
$official_code = ''; |
279
|
|
|
$language = ''; |
280
|
|
|
$phone = ''; |
281
|
|
|
$picture_uri = ''; |
282
|
|
|
$auth_source = PLATFORM_AUTH_SOURCE; |
283
|
|
|
$expiration_date = ''; |
284
|
|
|
$active = 1; |
285
|
|
|
$hr_dept_id = 0; |
286
|
|
|
$extra = null; |
287
|
|
|
$original_user_id_name = $user_param['original_user_id_name']; |
288
|
|
|
$original_user_id_value = $user_param['original_user_id_value']; |
289
|
|
|
$orig_user_id_value[] = $user_param['original_user_id_value']; |
290
|
|
|
$extra_list = $user_param['extra']; |
291
|
|
|
if (!empty($user_param['language'])) { |
292
|
|
|
$language = $user_param['language']; |
293
|
|
|
} |
294
|
|
|
if (!empty($user_param['phone'])) { |
295
|
|
|
$phone = $user_param['phone']; |
296
|
|
|
} |
297
|
|
|
if (!empty($user_param['expiration_date'])) { |
298
|
|
|
$expiration_date = $user_param['expiration_date']; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
// Check if exits x_user_id into user_field_values table. |
302
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
303
|
|
|
$original_user_id_value, |
304
|
|
|
$original_user_id_name |
305
|
|
|
); |
306
|
|
|
if ($user_id > 0) { |
307
|
|
|
/** @var User $user */ |
308
|
|
|
$user = $userRepository->find($user_id); |
309
|
|
|
|
310
|
|
|
if ($user && $user->isActive() == false) { |
311
|
|
|
if (!is_null($password)) { |
312
|
|
|
$user->setPlainPassword($password); |
313
|
|
|
} |
314
|
|
|
if (!is_null($auth_source)) { |
315
|
|
|
$user->setAuthSource($auth_source); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
if (!empty($user_param['expiration_date'])) { |
319
|
|
|
$expiration_date = new DateTime($user_param['expiration_date']); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
$user->setLastname($lastName) |
323
|
|
|
->setFirstname($firstName) |
324
|
|
|
->setUsername($loginName) |
325
|
|
|
->setEmail($email) |
326
|
|
|
->setStatus($status) |
327
|
|
|
->setOfficialCode($official_code) |
328
|
|
|
->setPhone($phone) |
329
|
|
|
->setExpirationDate($expiration_date) |
330
|
|
|
->setHrDeptId($hr_dept_id) |
331
|
|
|
->setActive(true); |
332
|
|
|
$userManager->updateUser($user, true); |
333
|
|
|
$results[] = $user_id; |
334
|
|
|
continue; |
335
|
|
|
//return $r_check_user[0]; |
336
|
|
|
} else { |
337
|
|
|
$results[] = 0; |
338
|
|
|
continue; |
339
|
|
|
//return 0; |
340
|
|
|
// user id already exits. |
341
|
|
|
} |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
// Default language. |
345
|
|
|
if (empty($language)) { |
346
|
|
|
$language = api_get_setting('platformLanguage'); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
$creatorId = DEFAULT_ADMIN_USER_ID; |
350
|
|
|
|
351
|
|
|
// First check wether the login already exists. |
352
|
|
|
if (!UserManager::is_username_available($loginName)) { |
353
|
|
|
$results[] = 0; |
354
|
|
|
continue; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
$userId = UserManager::create_user( |
358
|
|
|
$firstName, |
359
|
|
|
$lastName, |
360
|
|
|
$status, |
361
|
|
|
$email, |
362
|
|
|
$loginName, |
363
|
|
|
$password, |
364
|
|
|
$official_code, |
365
|
|
|
$language, |
366
|
|
|
$phone, |
367
|
|
|
$picture_uri, |
368
|
|
|
$auth_source, |
369
|
|
|
$expiration_date, |
370
|
|
|
$active, |
371
|
|
|
$hr_dept_id, |
372
|
|
|
[], |
373
|
|
|
'', |
374
|
|
|
false, |
375
|
|
|
false, |
376
|
|
|
'', |
377
|
|
|
false, |
378
|
|
|
null, |
379
|
|
|
$creatorId |
380
|
|
|
); |
381
|
|
|
|
382
|
|
|
if ($userId) { |
383
|
|
|
if (api_is_multiple_url_enabled()) { |
384
|
|
|
if (api_get_current_access_url_id() != -1) { |
385
|
|
|
UrlManager::add_user_to_url( |
386
|
|
|
$userId, |
387
|
|
|
api_get_current_access_url_id() |
388
|
|
|
); |
389
|
|
|
} else { |
390
|
|
|
UrlManager::add_user_to_url($userId, 1); |
391
|
|
|
} |
392
|
|
|
} else { |
393
|
|
|
// We add by default the access_url_user table with access_url_id = 1 |
394
|
|
|
UrlManager::add_user_to_url($userId, 1); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
// Save new field label into user_field table. |
398
|
|
|
UserManager::create_extra_field( |
399
|
|
|
$original_user_id_name, |
400
|
|
|
1, |
401
|
|
|
$original_user_id_name, |
402
|
|
|
'' |
403
|
|
|
); |
404
|
|
|
// Save the external system's id into user_field_value table. |
405
|
|
|
UserManager::update_extra_field_value( |
406
|
|
|
$userId, |
407
|
|
|
$original_user_id_name, |
408
|
|
|
$original_user_id_value |
409
|
|
|
); |
410
|
|
|
|
411
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
412
|
|
|
foreach ($extra_list as $extra) { |
413
|
|
|
$extra_field_name = $extra['field_name']; |
414
|
|
|
$extra_field_value = $extra['field_value']; |
415
|
|
|
// Save new field label into user_field table. |
416
|
|
|
UserManager::create_extra_field( |
417
|
|
|
$extra_field_name, |
418
|
|
|
1, |
419
|
|
|
$extra_field_name, |
420
|
|
|
'' |
421
|
|
|
); |
422
|
|
|
// Save the external system's id into user_field_value table. |
423
|
|
|
UserManager::update_extra_field_value( |
424
|
|
|
$userId, |
425
|
|
|
$extra_field_name, |
426
|
|
|
$extra_field_value |
427
|
|
|
); |
428
|
|
|
} |
429
|
|
|
} |
430
|
|
|
} else { |
431
|
|
|
$results[] = 0; |
432
|
|
|
continue; |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
$results[] = $userId; |
436
|
|
|
} // end principal foreach |
437
|
|
|
|
438
|
|
|
$count_results = count($results); |
439
|
|
|
$output = []; |
440
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
441
|
|
|
$output[] = [ |
442
|
|
|
'original_user_id_value' => $orig_user_id_value[$i], |
443
|
|
|
'result' => $results[$i], |
444
|
|
|
]; |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
return $output; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/* Register WSCreateUser function */ |
451
|
|
|
// Register the data structures used by the service |
452
|
|
|
$server->wsdl->addComplexType( |
453
|
|
|
'createUser', |
454
|
|
|
'complexType', |
455
|
|
|
'struct', |
456
|
|
|
'all', |
457
|
|
|
'', |
458
|
|
|
[ |
459
|
|
|
'firstname' => ['name' => 'firstname', 'type' => 'xsd:string'], |
460
|
|
|
'lastname' => ['name' => 'lastname', 'type' => 'xsd:string'], |
461
|
|
|
'status' => ['name' => 'status', 'type' => 'xsd:string'], |
462
|
|
|
'email' => ['name' => 'email', 'type' => 'xsd:string'], |
463
|
|
|
'loginname' => ['name' => 'loginname', 'type' => 'xsd:string'], |
464
|
|
|
'password' => ['name' => 'password', 'type' => 'xsd:string'], |
465
|
|
|
'language' => ['name' => 'language', 'type' => 'xsd:string'], |
466
|
|
|
'phone' => ['name' => 'phone', 'type' => 'xsd:string'], |
467
|
|
|
'expiration_date' => ['name' => 'expiration_date', 'type' => 'xsd:string'], |
468
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
469
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
470
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:extrasList'], |
471
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
472
|
|
|
'active' => ['name' => 'extra', 'type' => 'xsd:string'], |
473
|
|
|
] |
474
|
|
|
); |
475
|
|
|
|
476
|
|
|
// Register the method to expose |
477
|
|
|
$server->register( |
478
|
|
|
'WSCreateUser', // method name |
479
|
|
|
['createUser' => 'tns:createUser'], // input parameters |
480
|
|
|
['return' => 'xsd:string'], // output parameters |
481
|
|
|
'urn:WSRegistration', // namespace |
482
|
|
|
'urn:WSRegistration#WSCreateUser', // soapaction |
483
|
|
|
'rpc', // style |
484
|
|
|
'encoded', // use |
485
|
|
|
'This service adds a user' // documentation |
486
|
|
|
); |
487
|
|
|
|
488
|
|
|
// Define the method WSCreateUser |
489
|
|
|
function WSCreateUser($params) |
490
|
|
|
{ |
491
|
|
|
global $debug; |
492
|
|
|
|
493
|
|
|
if (!WSHelperVerifyKey($params)) { |
494
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
$firstName = $params['firstname']; |
498
|
|
|
$lastName = $params['lastname']; |
499
|
|
|
$status = $params['status']; |
500
|
|
|
$email = $params['email']; |
501
|
|
|
$loginName = $params['loginname']; |
502
|
|
|
$password = $params['password']; |
503
|
|
|
$official_code = ''; |
504
|
|
|
$language = ''; |
505
|
|
|
$phone = ''; |
506
|
|
|
$picture_uri = ''; |
507
|
|
|
$auth_source = PLATFORM_AUTH_SOURCE; |
508
|
|
|
$expiration_date = null; |
509
|
|
|
$active = !isset($params['active']) || !intval($params['active']) ? 0 : 1; |
510
|
|
|
$hr_dept_id = 0; |
511
|
|
|
$extra = null; |
512
|
|
|
$original_user_id_name = $params['original_user_id_name']; |
513
|
|
|
$original_user_id_value = $params['original_user_id_value']; |
514
|
|
|
$extra_list = $params['extra']; |
515
|
|
|
if (!empty($params['language'])) { |
516
|
|
|
$language = $params['language']; |
517
|
|
|
} |
518
|
|
|
if (!empty($params['phone'])) { |
519
|
|
|
$phone = $params['phone']; |
520
|
|
|
} |
521
|
|
|
if (!empty($params['expiration_date'])) { |
522
|
|
|
$expiration_date = $params['expiration_date']; |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
// check if exits x_user_id into user_field_values table |
526
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
527
|
|
|
$original_user_id_value, |
528
|
|
|
$original_user_id_name |
529
|
|
|
); |
530
|
|
|
|
531
|
|
|
$userManager = UserManager::getManager(); |
532
|
|
|
$userRepository = UserManager::getRepository(); |
533
|
|
|
|
534
|
|
|
if ($user_id > 0) { |
535
|
|
|
/** @var User $user */ |
536
|
|
|
$user = $userRepository->find($user_id); |
537
|
|
|
if ($user && $user->isActive() == false) { |
538
|
|
|
if (!is_null($password)) { |
539
|
|
|
$user->setPlainPassword($password); |
540
|
|
|
} |
541
|
|
|
if (!is_null($auth_source)) { |
542
|
|
|
$user->setAuthSource($auth_source); |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
if (!empty($params['expiration_date'])) { |
546
|
|
|
$expiration_date = new DateTime($params['expiration_date']); |
547
|
|
|
$user->setExpirationDate($expiration_date); |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
$user->setLastname($lastName) |
551
|
|
|
->setFirstname($firstName) |
552
|
|
|
->setUsername($loginName) |
553
|
|
|
->setEmail($email) |
554
|
|
|
->setStatus($status) |
555
|
|
|
->setOfficialCode($official_code) |
556
|
|
|
->setPhone($phone) |
557
|
|
|
->setHrDeptId($hr_dept_id) |
558
|
|
|
->setActive(true); |
559
|
|
|
$userManager->updateUser($user, true); |
560
|
|
|
|
561
|
|
|
return $user_id; |
562
|
|
|
} else { |
563
|
|
|
return 0; |
564
|
|
|
} |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
// Default language |
568
|
|
|
if (empty($language)) { |
569
|
|
|
$language = api_get_setting('platformLanguage'); |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
$creatorId = DEFAULT_ADMIN_USER_ID; |
573
|
|
|
|
574
|
|
|
// First check wether the login already exists |
575
|
|
|
if (!UserManager::is_username_available($loginName)) { |
576
|
|
|
if ($debug) { |
577
|
|
|
error_log("Username $loginName is not available"); |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
return 0; |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
if (isset($original_user_id_name) && isset($original_user_id_value)) { |
584
|
|
|
$_SESSION['ws_'.$original_user_id_name] = $original_user_id_value; |
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
/** @var User $user */ |
588
|
|
|
$userId = UserManager::create_user( |
589
|
|
|
$firstName, |
590
|
|
|
$lastName, |
591
|
|
|
$status, |
592
|
|
|
$email, |
593
|
|
|
$loginName, |
594
|
|
|
$password, |
595
|
|
|
$official_code, |
596
|
|
|
$language, |
597
|
|
|
$phone, |
598
|
|
|
$picture_uri, |
599
|
|
|
$auth_source, |
600
|
|
|
$expiration_date, |
601
|
|
|
$active, |
602
|
|
|
$hr_dept_id, |
603
|
|
|
[], |
604
|
|
|
'', |
605
|
|
|
false, |
606
|
|
|
false, |
607
|
|
|
'', |
608
|
|
|
false, |
609
|
|
|
null, |
610
|
|
|
$creatorId |
611
|
|
|
); |
612
|
|
|
|
613
|
|
|
if ($userId) { |
614
|
|
|
if (api_is_multiple_url_enabled()) { |
615
|
|
|
if (api_get_current_access_url_id() != -1) { |
616
|
|
|
UrlManager::add_user_to_url($userId, api_get_current_access_url_id()); |
617
|
|
|
} else { |
618
|
|
|
UrlManager::add_user_to_url($userId, 1); |
619
|
|
|
} |
620
|
|
|
} else { |
621
|
|
|
// We add by default the access_url_user table with access_url_id = 1 |
622
|
|
|
UrlManager::add_user_to_url($userId, 1); |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
// Save new fieldlabel into user_field table. |
626
|
|
|
UserManager::create_extra_field( |
627
|
|
|
$original_user_id_name, |
628
|
|
|
1, |
629
|
|
|
$original_user_id_name, |
630
|
|
|
'' |
631
|
|
|
); |
632
|
|
|
// Save the external system's id into user_field_value table. |
633
|
|
|
UserManager::update_extra_field_value( |
634
|
|
|
$userId, |
635
|
|
|
$original_user_id_name, |
636
|
|
|
$original_user_id_value |
637
|
|
|
); |
638
|
|
|
|
639
|
|
|
if (isset($original_user_id_name) && isset($original_user_id_value)) { |
640
|
|
|
unset($_SESSION['ws_'.$original_user_id_name]); |
641
|
|
|
} |
642
|
|
|
|
643
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
644
|
|
|
foreach ($extra_list as $extra) { |
645
|
|
|
$extra_field_name = $extra['field_name']; |
646
|
|
|
$extra_field_value = $extra['field_value']; |
647
|
|
|
// Save new field label into user_field table. |
648
|
|
|
UserManager::create_extra_field( |
649
|
|
|
$extra_field_name, |
650
|
|
|
1, |
651
|
|
|
$extra_field_name, |
652
|
|
|
'' |
653
|
|
|
); |
654
|
|
|
// Save the external system's id into user_field_value table. |
655
|
|
|
UserManager::update_extra_field_value( |
656
|
|
|
$userId, |
657
|
|
|
$extra_field_name, |
658
|
|
|
$extra_field_value |
659
|
|
|
); |
660
|
|
|
} |
661
|
|
|
} |
662
|
|
|
} else { |
663
|
|
|
return 0; |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
return $userId; |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
/* Register WSCreateUsersPasswordCrypted function */ |
670
|
|
|
// Register the data structures used by the service |
671
|
|
|
// Prepare input params. |
672
|
|
|
|
673
|
|
|
// Input params for editing users |
674
|
|
|
$server->wsdl->addComplexType( |
675
|
|
|
'createUsersPassEncryptParams', |
676
|
|
|
'complexType', |
677
|
|
|
'struct', |
678
|
|
|
'all', |
679
|
|
|
'', |
680
|
|
|
[ |
681
|
|
|
'firstname' => ['name' => 'firstname', 'type' => 'xsd:string'], |
682
|
|
|
'lastname' => ['name' => 'lastname', 'type' => 'xsd:string'], |
683
|
|
|
'status' => ['name' => 'status', 'type' => 'xsd:string'], |
684
|
|
|
'email' => ['name' => 'email', 'type' => 'xsd:string'], |
685
|
|
|
'loginname' => ['name' => 'loginname', 'type' => 'xsd:string'], |
686
|
|
|
'password' => ['name' => 'password', 'type' => 'xsd:string'], |
687
|
|
|
'encrypt_method' => ['name' => 'encrypt_method', 'type' => 'xsd:string'], |
688
|
|
|
'language' => ['name' => 'language', 'type' => 'xsd:string'], |
689
|
|
|
'phone' => ['name' => 'phone', 'type' => 'xsd:string'], |
690
|
|
|
'expiration_date' => ['name' => 'expiration_date', 'type' => 'xsd:string'], |
691
|
|
|
'official_code' => ['name' => 'official_code', 'type' => 'xsd:string'], |
692
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
693
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
694
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:extrasList'], |
695
|
|
|
] |
696
|
|
|
); |
697
|
|
|
|
698
|
|
|
$server->wsdl->addComplexType( |
699
|
|
|
'createUsersPassEncryptParamsList', |
700
|
|
|
'complexType', |
701
|
|
|
'array', |
702
|
|
|
'', |
703
|
|
|
'SOAP-ENC:Array', |
704
|
|
|
[], |
705
|
|
|
[ |
706
|
|
|
[ |
707
|
|
|
'ref' => 'SOAP-ENC:arrayType', |
708
|
|
|
'wsdl:arrayType' => 'tns:createUsersPassEncryptParams[]', |
709
|
|
|
], |
710
|
|
|
], |
711
|
|
|
'tns:createUsersPassEncryptParams' |
712
|
|
|
); |
713
|
|
|
|
714
|
|
|
// Register the data structures used by the service |
715
|
|
|
$server->wsdl->addComplexType( |
716
|
|
|
'createUsersPasswordCrypted', |
717
|
|
|
'complexType', |
718
|
|
|
'struct', |
719
|
|
|
'all', |
720
|
|
|
'', |
721
|
|
|
[ |
722
|
|
|
'users' => [ |
723
|
|
|
'name' => 'users', |
724
|
|
|
'type' => 'tns:createUsersPassEncryptParamsList', |
725
|
|
|
], |
726
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
727
|
|
|
] |
728
|
|
|
); |
729
|
|
|
|
730
|
|
|
// Prepare output params, in this case will return an array |
731
|
|
|
$server->wsdl->addComplexType( |
732
|
|
|
'result_createUsersPassEncrypt', |
733
|
|
|
'complexType', |
734
|
|
|
'struct', |
735
|
|
|
'all', |
736
|
|
|
'', |
737
|
|
|
[ |
738
|
|
|
'original_user_id_value' => [ |
739
|
|
|
'name' => 'original_user_id_value', |
740
|
|
|
'type' => 'xsd:string', |
741
|
|
|
], |
742
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
743
|
|
|
] |
744
|
|
|
); |
745
|
|
|
|
746
|
|
|
$server->wsdl->addComplexType( |
747
|
|
|
'results_createUsersPassEncrypt', |
748
|
|
|
'complexType', |
749
|
|
|
'array', |
750
|
|
|
'', |
751
|
|
|
'SOAP-ENC:Array', |
752
|
|
|
[], |
753
|
|
|
[ |
754
|
|
|
[ |
755
|
|
|
'ref' => 'SOAP-ENC:arrayType', |
756
|
|
|
'wsdl:arrayType' => 'tns:result_createUsersPassEncrypt[]', |
757
|
|
|
], |
758
|
|
|
], |
759
|
|
|
'tns:result_createUsersPassEncrypt' |
760
|
|
|
); |
761
|
|
|
|
762
|
|
|
// Register the method to expose |
763
|
|
|
$server->register( |
764
|
|
|
'WSCreateUsersPasswordCrypted', // method name |
765
|
|
|
['createUsersPasswordCrypted' => 'tns:createUsersPasswordCrypted'], // input parameters |
766
|
|
|
['return' => 'tns:results_createUsersPassEncrypt'], // output parameters |
767
|
|
|
'urn:WSRegistration', // namespace |
768
|
|
|
'urn:WSRegistration#WSCreateUsersPasswordCrypted', // soapaction |
769
|
|
|
'rpc', // style |
770
|
|
|
'encoded', // use |
771
|
|
|
'This service adds users to the system' // documentation |
772
|
|
|
); |
773
|
|
|
|
774
|
|
|
// Define the method WSCreateUsersPasswordCrypted |
775
|
|
|
function WSCreateUsersPasswordCrypted($params) |
776
|
|
|
{ |
777
|
|
|
global $_configuration; |
778
|
|
|
if (!WSHelperVerifyKey($params)) { |
779
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
780
|
|
|
} |
781
|
|
|
|
782
|
|
|
// database table definition |
783
|
|
|
$table_user = Database::get_main_table(TABLE_MAIN_USER); |
784
|
|
|
$t_uf = Database::get_main_table(TABLE_EXTRA_FIELD); |
785
|
|
|
$t_ufv = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES); |
786
|
|
|
|
787
|
|
|
$users_params = $params['users']; |
788
|
|
|
$results = []; |
789
|
|
|
$orig_user_id_value = []; |
790
|
|
|
|
791
|
|
|
foreach ($users_params as $user_param) { |
792
|
|
|
$password = $user_param['password']; |
793
|
|
|
$encrypt_method = $user_param['encrypt_method']; |
794
|
|
|
$firstName = $user_param['firstname']; |
795
|
|
|
$lastName = $user_param['lastname']; |
796
|
|
|
$status = $user_param['status']; |
797
|
|
|
$email = $user_param['email']; |
798
|
|
|
$loginName = $user_param['loginname']; |
799
|
|
|
$official_code = $user_param['official_code']; |
800
|
|
|
$language = ''; |
801
|
|
|
$phone = ''; |
802
|
|
|
$picture_uri = ''; |
803
|
|
|
$auth_source = PLATFORM_AUTH_SOURCE; |
804
|
|
|
$expiration_date = ''; |
805
|
|
|
$active = 1; |
806
|
|
|
$hr_dept_id = 0; |
807
|
|
|
$extra = null; |
808
|
|
|
$original_user_id_name = Database::escape_string($user_param['original_user_id_name']); |
809
|
|
|
$original_user_id_value = Database::escape_string($user_param['original_user_id_value']); |
810
|
|
|
$orig_user_id_value[] = $user_param['original_user_id_value']; |
811
|
|
|
$extra_list = $user_param['extra']; |
812
|
|
|
$salt = ''; |
813
|
|
|
|
814
|
|
|
if (!empty($_configuration['password_encryption'])) { |
815
|
|
|
if ($_configuration['password_encryption'] === $encrypt_method) { |
816
|
|
|
if ($encrypt_method == 'md5' && !preg_match('/^[A-Fa-f0-9]{32}$/', $password)) { |
817
|
|
|
$msg = "Encryption $encrypt_method is invalid"; |
818
|
|
|
$results[] = $msg; |
819
|
|
|
continue; |
820
|
|
|
} elseif ($encrypt_method == 'sha1' && !preg_match('/^[A-Fa-f0-9]{40}$/', $password)) { |
821
|
|
|
$msg = "Encryption $encrypt_method is invalid"; |
822
|
|
|
$results[] = $msg; |
823
|
|
|
continue; |
824
|
|
|
} |
825
|
|
|
} else { |
826
|
|
|
$msg = "This encryption $encrypt_method is not configured"; |
827
|
|
|
$results[] = $msg; |
828
|
|
|
continue; |
829
|
|
|
} |
830
|
|
|
} else { |
831
|
|
|
$msg = 'The chamilo setting $_configuration["password_encryption"] is not configured'; |
832
|
|
|
$results[] = $msg; |
833
|
|
|
continue; |
834
|
|
|
} |
835
|
|
|
|
836
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
837
|
|
|
foreach ($extra_list as $extra) { |
838
|
|
|
if ($extra['field_name'] == 'salt') { |
839
|
|
|
$salt = $extra['field_value']; |
840
|
|
|
break; |
841
|
|
|
} |
842
|
|
|
} |
843
|
|
|
} |
844
|
|
|
|
845
|
|
|
if (!empty($user_param['language'])) { |
846
|
|
|
$language = $user_param['language']; |
847
|
|
|
} |
848
|
|
|
if (!empty($user_param['phone'])) { |
849
|
|
|
$phone = $user_param['phone']; |
850
|
|
|
} |
851
|
|
|
if (!empty($user_param['expiration_date'])) { |
852
|
|
|
$expiration_date = $user_param['expiration_date']; |
853
|
|
|
} |
854
|
|
|
|
855
|
|
|
$extraFieldType = EntityExtraField::USER_FIELD_TYPE; |
856
|
|
|
|
857
|
|
|
// Check whether x_user_id exists into user_field_values table. |
858
|
|
|
$sql = "SELECT value as field_value,item_id as user_id |
859
|
|
|
FROM $t_uf uf, $t_ufv ufv |
860
|
|
|
WHERE |
861
|
|
|
uf.extra_field_type = $extraFieldType AND |
862
|
|
|
ufv.field_id=uf.id AND |
863
|
|
|
variable='$original_user_id_name' AND |
864
|
|
|
value ='$original_user_id_value'"; |
865
|
|
|
$res = Database::query($sql); |
866
|
|
|
$row = Database::fetch_row($res); |
867
|
|
|
$count_row = Database::num_rows($res); |
868
|
|
|
if ($count_row > 0) { |
869
|
|
|
// Check if user is not active. |
870
|
|
|
$sql = "SELECT user_id FROM $table_user |
871
|
|
|
WHERE user_id ='".$row[1]."' AND active= '0'"; |
872
|
|
|
$resu = Database::query($sql); |
873
|
|
|
$r_check_user = Database::fetch_row($resu); |
874
|
|
|
$count_check_user = Database::num_rows($resu); |
875
|
|
|
if ($count_check_user > 0) { |
876
|
|
|
$sql = "UPDATE $table_user SET |
877
|
|
|
lastname='".Database::escape_string($lastName)."', |
878
|
|
|
firstname='".Database::escape_string($firstName)."', |
879
|
|
|
username='".Database::escape_string($loginName)."',"; |
880
|
|
|
|
881
|
|
|
if (!is_null($auth_source)) { |
882
|
|
|
$sql .= " auth_source='".Database::escape_string($auth_source)."',"; |
883
|
|
|
} |
884
|
|
|
$sql .= " |
885
|
|
|
password='".Database::escape_string($password)."', |
886
|
|
|
email='".Database::escape_string($email)."', |
887
|
|
|
status='".Database::escape_string($status)."', |
888
|
|
|
official_code='".Database::escape_string($official_code)."', |
889
|
|
|
phone='".Database::escape_string($phone)."', |
890
|
|
|
expiration_date='".Database::escape_string($expiration_date)."', |
891
|
|
|
active='1', |
892
|
|
|
hr_dept_id=".intval($hr_dept_id); |
893
|
|
|
|
894
|
|
|
$sql .= " WHERE user_id='".$r_check_user[0]."'"; |
895
|
|
|
Database::query($sql); |
896
|
|
|
|
897
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
898
|
|
|
foreach ($extra_list as $extra) { |
899
|
|
|
$extra_field_name = $extra['field_name']; |
900
|
|
|
$extra_field_value = $extra['field_value']; |
901
|
|
|
// Save the external system's id into user_field_value table. |
902
|
|
|
UserManager::update_extra_field_value( |
903
|
|
|
$r_check_user[0], |
904
|
|
|
$extra_field_name, |
905
|
|
|
$extra_field_value |
906
|
|
|
); |
907
|
|
|
} |
908
|
|
|
} |
909
|
|
|
|
910
|
|
|
$results[] = $r_check_user[0]; |
911
|
|
|
continue; |
912
|
|
|
} else { |
913
|
|
|
$results[] = 0; |
914
|
|
|
continue; // User id already exits. |
915
|
|
|
} |
916
|
|
|
} |
917
|
|
|
|
918
|
|
|
// Default language. |
919
|
|
|
if (empty($language)) { |
920
|
|
|
$language = api_get_setting('platformLanguage'); |
921
|
|
|
} |
922
|
|
|
|
923
|
|
|
$creator_id = DEFAULT_ADMIN_USER_ID; |
924
|
|
|
|
925
|
|
|
// First check wether the login already exists |
926
|
|
|
if (!UserManager::is_username_available($loginName)) { |
927
|
|
|
$results[] = 0; |
928
|
|
|
continue; |
929
|
|
|
} |
930
|
|
|
|
931
|
|
|
$sql = "INSERT INTO $table_user SET |
932
|
|
|
lastname = '".Database::escape_string(trim($lastName))."', |
933
|
|
|
firstname = '".Database::escape_string(trim($firstName))."', |
934
|
|
|
username = '".Database::escape_string(trim($loginName))."', |
935
|
|
|
status = '".Database::escape_string($status)."', |
936
|
|
|
password = '".Database::escape_string($password)."', |
937
|
|
|
email = '".Database::escape_string($email)."', |
938
|
|
|
official_code = '".Database::escape_string($official_code)."', |
939
|
|
|
picture_uri = '".Database::escape_string($picture_uri)."', |
940
|
|
|
creator_id = '".Database::escape_string($creator_id)."', |
941
|
|
|
auth_source = '".Database::escape_string($auth_source)."', |
942
|
|
|
phone = '".Database::escape_string($phone)."', |
943
|
|
|
language = '".Database::escape_string($language)."', |
944
|
|
|
registration_date = now(), |
945
|
|
|
expiration_date = '".Database::escape_string($expiration_date)."', |
946
|
|
|
hr_dept_id = '".Database::escape_string($hr_dept_id)."', |
947
|
|
|
active = '".Database::escape_string($active)."'"; |
948
|
|
|
$result = Database::query($sql); |
949
|
|
|
if ($result) { |
950
|
|
|
//echo "id returned"; |
951
|
|
|
$return = Database::insert_id(); |
952
|
|
|
|
953
|
|
|
$sql = "UPDATE $table_user SET user_id = id WHERE id = $return"; |
954
|
|
|
Database::query($sql); |
955
|
|
|
|
956
|
|
|
if (api_is_multiple_url_enabled()) { |
957
|
|
|
if (api_get_current_access_url_id() != -1) { |
958
|
|
|
UrlManager::add_user_to_url( |
959
|
|
|
$return, |
960
|
|
|
api_get_current_access_url_id() |
961
|
|
|
); |
962
|
|
|
} else { |
963
|
|
|
UrlManager::add_user_to_url($return, 1); |
964
|
|
|
} |
965
|
|
|
} else { |
966
|
|
|
// We add by default the access_url_user table with access_url_id = 1 |
967
|
|
|
UrlManager::add_user_to_url($return, 1); |
968
|
|
|
} |
969
|
|
|
// Save new fieldlabel into user_field table. |
970
|
|
|
UserManager::create_extra_field( |
971
|
|
|
$original_user_id_name, |
972
|
|
|
1, |
973
|
|
|
$original_user_id_name, |
974
|
|
|
'' |
975
|
|
|
); |
976
|
|
|
// Save the remote system's id into user_field_value table. |
977
|
|
|
UserManager::update_extra_field_value( |
978
|
|
|
$return, |
979
|
|
|
$original_user_id_name, |
980
|
|
|
$original_user_id_value |
981
|
|
|
); |
982
|
|
|
|
983
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
984
|
|
|
foreach ($extra_list as $extra) { |
985
|
|
|
$extra_field_name = $extra['field_name']; |
986
|
|
|
$extra_field_value = $extra['field_value']; |
987
|
|
|
// Save new fieldlabel into user_field table. |
988
|
|
|
UserManager::create_extra_field( |
989
|
|
|
$extra_field_name, |
990
|
|
|
1, |
991
|
|
|
$extra_field_name, |
992
|
|
|
'' |
993
|
|
|
); |
994
|
|
|
// Save the external system's id into user_field_value table. |
995
|
|
|
UserManager::update_extra_field_value( |
996
|
|
|
$return, |
997
|
|
|
$extra_field_name, |
998
|
|
|
$extra_field_value |
999
|
|
|
); |
1000
|
|
|
} |
1001
|
|
|
} |
1002
|
|
|
} else { |
1003
|
|
|
$results[] = 0; |
1004
|
|
|
continue; |
1005
|
|
|
} |
1006
|
|
|
$results[] = $return; |
1007
|
|
|
} // end principal foreach |
1008
|
|
|
|
1009
|
|
|
$count_results = count($results); |
1010
|
|
|
$output = []; |
1011
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
1012
|
|
|
$output[] = [ |
1013
|
|
|
'original_user_id_value' => $orig_user_id_value[$i], |
1014
|
|
|
'result' => $results[$i], |
1015
|
|
|
]; |
1016
|
|
|
} |
1017
|
|
|
|
1018
|
|
|
return $output; |
1019
|
|
|
} |
1020
|
|
|
|
1021
|
|
|
// Subscribe / Unsubscribe Teacher to Session Course |
1022
|
|
|
// Prepare Input params for Subscribe Teacher to SC |
1023
|
|
|
$server->wsdl->addComplexType( |
1024
|
|
|
'TeacherToSessionCourse', |
1025
|
|
|
'complexType', |
1026
|
|
|
'struct', |
1027
|
|
|
'all', |
1028
|
|
|
'', |
1029
|
|
|
[ |
1030
|
|
|
'user_id' => ['name' => 'course', 'type' => 'xsd:string'], // Chamilo user Id |
1031
|
|
|
'session_id' => ['name' => 'user_id', 'type' => 'xsd:string'], // Current Session course ID |
1032
|
|
|
'course_id' => ['name' => 'courseId', 'type' => 'xsd:string'], // Course Real Id |
1033
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
1034
|
|
|
// optional |
1035
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
1036
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
1037
|
|
|
'original_course_id_name' => ['name' => 'original_course_id_name', 'type' => 'xsd:string'], |
1038
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
1039
|
|
|
'original_session_id_name' => ['name' => 'original_session_id_name', 'type' => 'xsd:string'], |
1040
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
1041
|
|
|
] |
1042
|
|
|
); |
1043
|
|
|
|
1044
|
|
|
/** |
1045
|
|
|
* @param array $params |
1046
|
|
|
* |
1047
|
|
|
* @return array |
1048
|
|
|
*/ |
1049
|
|
|
function parseCourseSessionUserParams($params) |
1050
|
|
|
{ |
1051
|
|
|
global $debug; |
1052
|
|
|
|
1053
|
|
|
$userId = isset($params['user_id']) ? $params['user_id'] : 0; // Chamilo user Id |
1054
|
|
|
$sessionId = isset($params['session_id']) ? $params['session_id'] : 0; // Current Session course ID |
1055
|
|
|
$courseId = isset($params['course_id']) ? $params['course_id'] : 0; // Course Real Id |
1056
|
|
|
|
1057
|
|
|
if (empty($userId) && empty($sessionId) && empty($courseId)) { |
1058
|
|
|
// try original values |
1059
|
|
|
if ($debug) { |
1060
|
|
|
error_log('try original values'); |
1061
|
|
|
} |
1062
|
|
|
|
1063
|
|
|
$userIdName = isset($params['original_user_id_name']) ? $params['original_user_id_name'] : 0; |
1064
|
|
|
$userIdValue = isset($params['original_user_id_value']) ? $params['original_user_id_value'] : 0; |
1065
|
|
|
$courseIdName = isset($params['original_course_id_name']) ? $params['original_course_id_name'] : 0; |
1066
|
|
|
$courseIdValue = isset($params['original_course_id_value']) ? $params['original_course_id_value'] : 0; |
1067
|
|
|
$sessionIdName = isset($params['original_session_id_name']) ? $params['original_session_id_name'] : 0; |
1068
|
|
|
$sessionIdValue = isset($params['original_session_id_value']) ? $params['original_session_id_value'] : 0; |
1069
|
|
|
|
1070
|
|
|
// Check if exits x_user_id into user_field_values table. |
1071
|
|
|
$userId = UserManager::get_user_id_from_original_id( |
1072
|
|
|
$userIdValue, |
1073
|
|
|
$userIdName |
1074
|
|
|
); |
1075
|
|
|
|
1076
|
|
|
// Check whether exits $x_course_code into user_field_values table. |
1077
|
|
|
$courseInfo = CourseManager::getCourseInfoFromOriginalId( |
1078
|
|
|
$courseIdValue, |
1079
|
|
|
$courseIdName |
1080
|
|
|
); |
1081
|
|
|
|
1082
|
|
|
$courseId = 0; |
1083
|
|
|
if ($courseInfo) { |
1084
|
|
|
$courseId = $courseInfo['real_id']; |
1085
|
|
|
} |
1086
|
|
|
|
1087
|
|
|
$sessionId = SessionManager::getSessionIdFromOriginalId( |
1088
|
|
|
$sessionIdValue, |
1089
|
|
|
$sessionIdName |
1090
|
|
|
); |
1091
|
|
|
} |
1092
|
|
|
|
1093
|
|
|
if ($debug) { |
1094
|
|
|
error_log('$userId found: '.$userId); |
1095
|
|
|
error_log('$courseId found: '.$courseId); |
1096
|
|
|
error_log('$sessionId found: '.$sessionId); |
1097
|
|
|
} |
1098
|
|
|
|
1099
|
|
|
return [ |
1100
|
|
|
'user_id' => $userId, |
1101
|
|
|
'course_id' => $courseId, |
1102
|
|
|
'session_id' => $sessionId, |
1103
|
|
|
]; |
1104
|
|
|
} |
1105
|
|
|
|
1106
|
|
|
$server->register( |
1107
|
|
|
'WSSubscribeTeacherToSessionCourse', |
1108
|
|
|
['SubscribeTeacherToSessionCourse' => 'tns:TeacherToSessionCourse'], |
1109
|
|
|
['return' => 'xsd:string'], |
1110
|
|
|
'urn:WSRegistration', |
1111
|
|
|
'urn:WSRegistration#WSSubscribeTeacherToSessionCourse', |
1112
|
|
|
'rpc', |
1113
|
|
|
'encoded', |
1114
|
|
|
'This webservice subscribe a teacher to a session course' |
1115
|
|
|
); |
1116
|
|
|
|
1117
|
|
|
/** |
1118
|
|
|
* Subscribe teacher to a session course. |
1119
|
|
|
* |
1120
|
|
|
* @param array $params - WSFunction parameters (include VerifyKey) |
1121
|
|
|
* |
1122
|
|
|
* @return bool|soap_fault|null A simple boolean (true if teacher successful subscribed, false otherwise) |
1123
|
|
|
*/ |
1124
|
|
|
function WSSubscribeTeacherToSessionCourse($params) |
1125
|
|
|
{ |
1126
|
|
|
global $debug; |
1127
|
|
|
if ($debug) { |
1128
|
|
|
error_log('WSSubscribeTeacherToSessionCourse'); |
1129
|
|
|
} |
1130
|
|
|
|
1131
|
|
|
if (!WSHelperVerifyKey($params)) { |
1132
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
1133
|
|
|
} |
1134
|
|
|
|
1135
|
|
|
if ($debug) { |
1136
|
|
|
error_log('Params '.print_r($params, 1)); |
1137
|
|
|
} |
1138
|
|
|
|
1139
|
|
|
$params = parseCourseSessionUserParams($params); |
1140
|
|
|
|
1141
|
|
|
$userId = $params['user_id']; |
1142
|
|
|
$courseId = $params['course_id']; |
1143
|
|
|
$sessionId = $params['session_id']; |
1144
|
|
|
SessionManager::set_coach_to_course_session($userId, $sessionId, $courseId); |
1145
|
|
|
$coaches = SessionManager::getCoachesByCourseSession($sessionId, $courseId); |
1146
|
|
|
|
1147
|
|
|
$result = 0; |
1148
|
|
|
|
1149
|
|
|
if (!empty($coaches)) { |
1150
|
|
|
if ($debug) { |
1151
|
|
|
error_log('Coaches: '.print_r($coaches, 1)); |
1152
|
|
|
} |
1153
|
|
|
if (in_array($userId, $coaches)) { |
1154
|
|
|
$result = 1; |
1155
|
|
|
} |
1156
|
|
|
} |
1157
|
|
|
|
1158
|
|
|
if ($debug) { |
1159
|
|
|
error_log('Result: '.$result); |
1160
|
|
|
} |
1161
|
|
|
|
1162
|
|
|
return $result; |
1163
|
|
|
} |
1164
|
|
|
|
1165
|
|
|
$server->register( |
1166
|
|
|
'WSUnsubscribeTeacherFromSessionCourse', |
1167
|
|
|
['UnsubscribeTeacherFromSessionCourse' => 'tns:TeacherToSessionCourse'], |
1168
|
|
|
['return' => 'xsd:string'], |
1169
|
|
|
'urn:WSRegistration', |
1170
|
|
|
'urn:WSRegistration#WSUnsubscribeTeacherFromSessionCourse', |
1171
|
|
|
'rpc', |
1172
|
|
|
'encoded', |
1173
|
|
|
'This webservice unsubscribe a teacher from a session course' |
1174
|
|
|
); |
1175
|
|
|
|
1176
|
|
|
/** |
1177
|
|
|
* Subscribe teacher to a session course. |
1178
|
|
|
* |
1179
|
|
|
* @param array $params - WSFunction parameters (include VerifyKey) |
1180
|
|
|
* |
1181
|
|
|
* @return bool|soap_fault|null A simple boolean (true if teacher successful unsubscribed, false otherwise) |
1182
|
|
|
*/ |
1183
|
|
|
function WSUnsubscribeTeacherFromSessionCourse($params) |
1184
|
|
|
{ |
1185
|
|
|
global $debug; |
1186
|
|
|
|
1187
|
|
|
if ($debug) { |
1188
|
|
|
error_log('WSSubscribeTeacherToSessionCourse'); |
1189
|
|
|
} |
1190
|
|
|
|
1191
|
|
|
if (!WSHelperVerifyKey($params)) { |
1192
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
1193
|
|
|
} |
1194
|
|
|
|
1195
|
|
|
if ($debug) { |
1196
|
|
|
error_log('Params '.print_r($params, 1)); |
1197
|
|
|
} |
1198
|
|
|
|
1199
|
|
|
$params = parseCourseSessionUserParams($params); |
1200
|
|
|
|
1201
|
|
|
$userId = $params['user_id']; |
1202
|
|
|
$courseId = $params['course_id']; |
1203
|
|
|
$sessionId = $params['session_id']; |
1204
|
|
|
|
1205
|
|
|
SessionManager::removeUsersFromCourseSession([$userId], $sessionId, $courseId); |
1206
|
|
|
$coaches = SessionManager::getCoachesByCourseSession($sessionId, $courseId); |
1207
|
|
|
|
1208
|
|
|
$result = 0; |
1209
|
|
|
|
1210
|
|
|
if (!empty($coaches)) { |
1211
|
|
|
if ($debug) { |
1212
|
|
|
error_log('Coaches: '.print_r($coaches, 1)); |
1213
|
|
|
} |
1214
|
|
|
if (!in_array($userId, $coaches)) { |
1215
|
|
|
$result = 1; |
1216
|
|
|
} |
1217
|
|
|
} else { |
1218
|
|
|
$result = 1; |
1219
|
|
|
} |
1220
|
|
|
|
1221
|
|
|
if ($debug) { |
1222
|
|
|
error_log('Final Result: '.$result); |
1223
|
|
|
} |
1224
|
|
|
|
1225
|
|
|
return $result; |
1226
|
|
|
} |
1227
|
|
|
|
1228
|
|
|
/* Register WSCreateUserPasswordCrypted function */ |
1229
|
|
|
// Register the data structures used by the service |
1230
|
|
|
|
1231
|
|
|
//prepare input params |
1232
|
|
|
|
1233
|
|
|
// Input params for editing users |
1234
|
|
|
$server->wsdl->addComplexType( |
1235
|
|
|
'createUserPasswordCrypted', |
1236
|
|
|
'complexType', |
1237
|
|
|
'struct', |
1238
|
|
|
'all', |
1239
|
|
|
'', |
1240
|
|
|
[ |
1241
|
|
|
'firstname' => ['name' => 'firstname', 'type' => 'xsd:string'], |
1242
|
|
|
'lastname' => ['name' => 'lastname', 'type' => 'xsd:string'], |
1243
|
|
|
'status' => ['name' => 'status', 'type' => 'xsd:string'], |
1244
|
|
|
'email' => ['name' => 'email', 'type' => 'xsd:string'], |
1245
|
|
|
'loginname' => ['name' => 'loginname', 'type' => 'xsd:string'], |
1246
|
|
|
'password' => ['name' => 'password', 'type' => 'xsd:string'], //encripted password using the encrypt_method |
1247
|
|
|
'encrypt_method' => ['name' => 'encrypt_method', 'type' => 'xsd:string'], |
1248
|
|
|
'language' => ['name' => 'language', 'type' => 'xsd:string'], |
1249
|
|
|
'phone' => ['name' => 'phone', 'type' => 'xsd:string'], |
1250
|
|
|
'expiration_date' => ['name' => 'expiration_date', 'type' => 'xsd:string'], |
1251
|
|
|
'official_code' => ['name' => 'official_code', 'type' => 'xsd:string'], |
1252
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
1253
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
1254
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:extrasList'], |
1255
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
1256
|
|
|
] |
1257
|
|
|
); |
1258
|
|
|
|
1259
|
|
|
// Register the method to expose |
1260
|
|
|
$server->register( |
1261
|
|
|
'WSCreateUserPasswordCrypted', // method name |
1262
|
|
|
['createUserPasswordCrypted' => 'tns:createUserPasswordCrypted'], // input parameters |
1263
|
|
|
['return' => 'xsd:string'], // output parameters |
1264
|
|
|
'urn:WSRegistration', // namespace |
1265
|
|
|
'urn:WSRegistration#WSCreateUserPasswordCrypted', // soapaction |
1266
|
|
|
'rpc', // style |
1267
|
|
|
'encoded', // use |
1268
|
|
|
'This service adds users' // documentation |
1269
|
|
|
); |
1270
|
|
|
|
1271
|
|
|
// Define the method WSCreateUserPasswordCrypted |
1272
|
|
|
function WSCreateUserPasswordCrypted($params) |
1273
|
|
|
{ |
1274
|
|
|
global $_configuration, $debug; |
1275
|
|
|
$debug = 1; |
1276
|
|
|
if ($debug) { |
1277
|
|
|
error_log('WSCreateUserPasswordCrypted'); |
1278
|
|
|
error_log(print_r($params, 1)); |
1279
|
|
|
} |
1280
|
|
|
if (!WSHelperVerifyKey($params)) { |
1281
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
1282
|
|
|
} |
1283
|
|
|
|
1284
|
|
|
// Database table definition. |
1285
|
|
|
$table_user = Database::get_main_table(TABLE_MAIN_USER); |
1286
|
|
|
$password = $params['password']; |
1287
|
|
|
$encrypt_method = $params['encrypt_method']; |
1288
|
|
|
$firstName = $params['firstname']; |
1289
|
|
|
$lastName = $params['lastname']; |
1290
|
|
|
$status = $params['status']; |
1291
|
|
|
$email = $params['email']; |
1292
|
|
|
$loginName = $params['loginname']; |
1293
|
|
|
$official_code = isset($params['official_code']) ? $params['official_code'] : ''; |
1294
|
|
|
$language = ''; |
1295
|
|
|
$phone = isset($params['phone']) ? $params['phone'] : ''; |
1296
|
|
|
$picture_uri = ''; |
1297
|
|
|
$auth_source = PLATFORM_AUTH_SOURCE; |
1298
|
|
|
$expiration_date = ''; |
1299
|
|
|
$active = 1; |
1300
|
|
|
$hr_dept_id = 0; |
1301
|
|
|
$extra = null; |
1302
|
|
|
$original_user_id_name = $params['original_user_id_name']; |
1303
|
|
|
$original_user_id_value = $params['original_user_id_value']; |
1304
|
|
|
$extra_list = isset($params['extra']) ? $params['extra'] : ''; |
1305
|
|
|
|
1306
|
|
|
if (!empty($_configuration['password_encryption'])) { |
1307
|
|
|
if ($_configuration['password_encryption'] === $encrypt_method) { |
1308
|
|
|
if ($encrypt_method == 'md5' && !preg_match('/^[A-Fa-f0-9]{32}$/', $password)) { |
1309
|
|
|
$msg = "Encryption $encrypt_method is invalid"; |
1310
|
|
|
if ($debug) { |
1311
|
|
|
error_log($msg); |
1312
|
|
|
} |
1313
|
|
|
|
1314
|
|
|
return $msg; |
1315
|
|
|
} elseif ($encrypt_method == 'sha1' && !preg_match('/^[A-Fa-f0-9]{40}$/', $password)) { |
1316
|
|
|
$msg = "Encryption $encrypt_method is invalid"; |
1317
|
|
|
if ($debug) { |
1318
|
|
|
error_log($msg); |
1319
|
|
|
} |
1320
|
|
|
|
1321
|
|
|
return $msg; |
1322
|
|
|
} |
1323
|
|
|
} else { |
1324
|
|
|
$msg = "This encryption $encrypt_method is not configured"; |
1325
|
|
|
if ($debug) { |
1326
|
|
|
error_log($msg); |
1327
|
|
|
} |
1328
|
|
|
|
1329
|
|
|
return $msg; |
1330
|
|
|
} |
1331
|
|
|
} else { |
1332
|
|
|
$msg = 'The chamilo setting $_configuration["password_encryption"] is not configured'; |
1333
|
|
|
if ($debug) { |
1334
|
|
|
error_log($msg); |
1335
|
|
|
} |
1336
|
|
|
|
1337
|
|
|
return $msg; |
1338
|
|
|
} |
1339
|
|
|
|
1340
|
|
|
if (!empty($params['language'])) { |
1341
|
|
|
$language = $params['language']; |
1342
|
|
|
} |
1343
|
|
|
if (!empty($params['phone'])) { |
1344
|
|
|
$phone = $params['phone']; |
1345
|
|
|
} |
1346
|
|
|
if (!empty($params['expiration_date'])) { |
1347
|
|
|
$expiration_date = $params['expiration_date']; |
1348
|
|
|
} |
1349
|
|
|
|
1350
|
|
|
// Check whether x_user_id exists into user_field_values table. |
1351
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
1352
|
|
|
$original_user_id_value, |
1353
|
|
|
$original_user_id_name |
1354
|
|
|
); |
1355
|
|
|
|
1356
|
|
|
if ($debug) { |
1357
|
|
|
error_log('Ready to create user'); |
1358
|
|
|
} |
1359
|
|
|
|
1360
|
|
|
if ($user_id > 0) { |
1361
|
|
|
if ($debug) { |
1362
|
|
|
error_log('User found with id: '.$user_id); |
1363
|
|
|
} |
1364
|
|
|
|
1365
|
|
|
// Check whether user is not active |
1366
|
|
|
//@todo why this condition exists?? |
1367
|
|
|
$sql = "SELECT user_id FROM $table_user |
1368
|
|
|
WHERE user_id ='".$user_id."' AND active= '0' "; |
1369
|
|
|
$resu = Database::query($sql); |
1370
|
|
|
$r_check_user = Database::fetch_row($resu); |
1371
|
|
|
$count_check_user = Database::num_rows($resu); |
1372
|
|
|
if ($count_check_user > 0) { |
1373
|
|
|
if ($debug) { |
1374
|
|
|
error_log('User id: '.$user_id.' exists and is NOT active. Updating user and setting setting active = 1'); |
1375
|
|
|
} |
1376
|
|
|
$sql = "UPDATE $table_user SET |
1377
|
|
|
lastname='".Database::escape_string($lastName)."', |
1378
|
|
|
firstname='".Database::escape_string($firstName)."', |
1379
|
|
|
username='".Database::escape_string($loginName)."',"; |
1380
|
|
|
|
1381
|
|
|
if (!is_null($auth_source)) { |
1382
|
|
|
$sql .= " auth_source='".Database::escape_string($auth_source)."',"; |
1383
|
|
|
} |
1384
|
|
|
$sql .= " |
1385
|
|
|
password='".Database::escape_string($password)."', |
1386
|
|
|
email='".Database::escape_string($email)."', |
1387
|
|
|
status='".Database::escape_string($status)."', |
1388
|
|
|
official_code='".Database::escape_string($official_code)."', |
1389
|
|
|
phone='".Database::escape_string($phone)."', |
1390
|
|
|
expiration_date='".Database::escape_string($expiration_date)."', |
1391
|
|
|
active='1', |
1392
|
|
|
hr_dept_id=".intval($hr_dept_id)." |
1393
|
|
|
WHERE user_id='".$r_check_user[0]."'"; |
1394
|
|
|
|
1395
|
|
|
Database::query($sql); |
1396
|
|
|
|
1397
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
1398
|
|
|
foreach ($extra_list as $extra) { |
1399
|
|
|
$extra_field_name = $extra['field_name']; |
1400
|
|
|
$extra_field_value = $extra['field_value']; |
1401
|
|
|
// Save the external system's id into user_field_value table. |
1402
|
|
|
UserManager::update_extra_field_value( |
1403
|
|
|
$r_check_user[0], |
1404
|
|
|
$extra_field_name, |
1405
|
|
|
$extra_field_value |
1406
|
|
|
); |
1407
|
|
|
} |
1408
|
|
|
} |
1409
|
|
|
|
1410
|
|
|
return $r_check_user[0]; |
1411
|
|
|
} else { |
1412
|
|
|
if ($debug) { |
1413
|
|
|
error_log('User exists but is active. Cant be updated'); |
1414
|
|
|
} |
1415
|
|
|
|
1416
|
|
|
return 0; |
1417
|
|
|
} |
1418
|
|
|
} else { |
1419
|
|
|
if ($debug) { |
1420
|
|
|
error_log( |
1421
|
|
|
"User not found with original_id = $original_user_id_value and original_name = $original_user_id_name" |
1422
|
|
|
); |
1423
|
|
|
} |
1424
|
|
|
} |
1425
|
|
|
|
1426
|
|
|
// Default language. |
1427
|
|
|
if (empty($language)) { |
1428
|
|
|
$language = api_get_setting('platformLanguage'); |
1429
|
|
|
} |
1430
|
|
|
|
1431
|
|
|
$creator_id = DEFAULT_ADMIN_USER_ID; |
1432
|
|
|
|
1433
|
|
|
// First check wether the login already exists |
1434
|
|
|
if (!UserManager::is_username_available($loginName)) { |
1435
|
|
|
if ($debug) { |
1436
|
|
|
error_log("Username $loginName is not available"); |
1437
|
|
|
} |
1438
|
|
|
|
1439
|
|
|
return 0; |
1440
|
|
|
} |
1441
|
|
|
|
1442
|
|
|
$queryExpirationDate = ''; |
1443
|
|
|
if (!empty($params['expiration_date'])) { |
1444
|
|
|
$queryExpirationDate = "expiration_date = '".Database::escape_string($expiration_date)."', "; |
1445
|
|
|
} |
1446
|
|
|
|
1447
|
|
|
$sql = "INSERT INTO $table_user SET |
1448
|
|
|
lastname = '".Database::escape_string(trim($lastName))."', |
1449
|
|
|
firstname = '".Database::escape_string(trim($firstName))."', |
1450
|
|
|
username = '".Database::escape_string(trim($loginName))."', |
1451
|
|
|
username_canonical = '".Database::escape_string(api_strtolower(trim($loginName)))."', |
1452
|
|
|
status = '".Database::escape_string($status)."', |
1453
|
|
|
password = '".Database::escape_string($password)."', |
1454
|
|
|
email = '".Database::escape_string($email)."', |
1455
|
|
|
official_code = '".Database::escape_string($official_code)."', |
1456
|
|
|
picture_uri = '".Database::escape_string($picture_uri)."', |
1457
|
|
|
creator_id = '".Database::escape_string($creator_id)."', |
1458
|
|
|
auth_source = '".Database::escape_string($auth_source)."', |
1459
|
|
|
phone = '".Database::escape_string($phone)."', |
1460
|
|
|
language = '".Database::escape_string($language)."', |
1461
|
|
|
registration_date = '".api_get_utc_datetime()."', |
1462
|
|
|
roles = 'a:0:{}', |
1463
|
|
|
".$queryExpirationDate." |
1464
|
|
|
hr_dept_id = '".Database::escape_string($hr_dept_id)."', |
1465
|
|
|
active = '".Database::escape_string($active)."'"; |
1466
|
|
|
|
1467
|
|
|
Database::query($sql); |
1468
|
|
|
$return = Database::insert_id(); |
1469
|
|
|
if ($return) { |
1470
|
|
|
if ($debug) { |
1471
|
|
|
error_log("New user created. user_id = $return"); |
1472
|
|
|
} |
1473
|
|
|
$sql = "UPDATE $table_user SET user_id = id WHERE id = $return"; |
1474
|
|
|
Database::query($sql); |
1475
|
|
|
|
1476
|
|
|
$url_id = api_get_current_access_url_id(); |
1477
|
|
|
UrlManager::add_user_to_url($return, $url_id); |
1478
|
|
|
if ($debug) { |
1479
|
|
|
error_log("Adding user_id = $return to URL id $url_id "); |
1480
|
|
|
} |
1481
|
|
|
|
1482
|
|
|
// Create extra field for the original_user_id_name |
1483
|
|
|
UserManager::create_extra_field( |
1484
|
|
|
$original_user_id_name, |
1485
|
|
|
1, |
1486
|
|
|
$original_user_id_name, |
1487
|
|
|
'' |
1488
|
|
|
); |
1489
|
|
|
// Save the remote system's id into user_field_value table. |
1490
|
|
|
UserManager::update_extra_field_value( |
1491
|
|
|
$return, |
1492
|
|
|
$original_user_id_name, |
1493
|
|
|
$original_user_id_value |
1494
|
|
|
); |
1495
|
|
|
|
1496
|
|
|
// Create extra fields |
1497
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
1498
|
|
|
foreach ($extra_list as $extra) { |
1499
|
|
|
$extra_field_name = $extra['field_name']; |
1500
|
|
|
$extra_field_value = $extra['field_value']; |
1501
|
|
|
// save new fieldlabel into user_field table |
1502
|
|
|
UserManager::create_extra_field( |
1503
|
|
|
$extra_field_name, |
1504
|
|
|
1, |
1505
|
|
|
$extra_field_name, |
1506
|
|
|
'' |
1507
|
|
|
); |
1508
|
|
|
// save the external system's id into user_field_value table' |
1509
|
|
|
UserManager::update_extra_field_value( |
1510
|
|
|
$return, |
1511
|
|
|
$extra_field_name, |
1512
|
|
|
$extra_field_value |
1513
|
|
|
); |
1514
|
|
|
} |
1515
|
|
|
} |
1516
|
|
|
} else { |
1517
|
|
|
if ($debug) { |
1518
|
|
|
error_log('Error while inserting a user'); |
1519
|
|
|
} |
1520
|
|
|
|
1521
|
|
|
return 0; |
1522
|
|
|
} |
1523
|
|
|
if ($debug) { |
1524
|
|
|
error_log("Return value: $return"); |
1525
|
|
|
} |
1526
|
|
|
|
1527
|
|
|
return $return; |
1528
|
|
|
} |
1529
|
|
|
|
1530
|
|
|
/* Register WSEditUsers function */ |
1531
|
|
|
// Register the data structures used by the service |
1532
|
|
|
$server->wsdl->addComplexType( |
1533
|
|
|
'editUsersParams', |
1534
|
|
|
'complexType', |
1535
|
|
|
'struct', |
1536
|
|
|
'all', |
1537
|
|
|
'', |
1538
|
|
|
[ |
1539
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
1540
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
1541
|
|
|
'firstname' => ['name' => 'firstname', 'type' => 'xsd:string'], |
1542
|
|
|
'lastname' => ['name' => 'lastname', 'type' => 'xsd:string'], |
1543
|
|
|
'username' => ['name' => 'username', 'type' => 'xsd:string'], |
1544
|
|
|
'password' => ['name' => 'password', 'type' => 'xsd:string'], |
1545
|
|
|
'email' => ['name' => 'email', 'type' => 'xsd:string'], |
1546
|
|
|
'status' => ['name' => 'status', 'type' => 'xsd:string'], |
1547
|
|
|
'phone' => ['name' => 'phone', 'type' => 'xsd:string'], |
1548
|
|
|
'expiration_date' => ['name' => 'expiration_date', 'type' => 'xsd:string'], |
1549
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:extrasList'], |
1550
|
|
|
] |
1551
|
|
|
); |
1552
|
|
|
|
1553
|
|
|
$server->wsdl->addComplexType( |
1554
|
|
|
'editUsersParamsList', |
1555
|
|
|
'complexType', |
1556
|
|
|
'array', |
1557
|
|
|
'', |
1558
|
|
|
'SOAP-ENC:Array', |
1559
|
|
|
[], |
1560
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:editUsersParams[]']], |
1561
|
|
|
'tns:editUsersParams' |
1562
|
|
|
); |
1563
|
|
|
|
1564
|
|
|
$server->wsdl->addComplexType( |
1565
|
|
|
'editUsers', |
1566
|
|
|
'complexType', |
1567
|
|
|
'struct', |
1568
|
|
|
'all', |
1569
|
|
|
'', |
1570
|
|
|
[ |
1571
|
|
|
'users' => ['name' => 'users', 'type' => 'tns:editUsersParamsList'], |
1572
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
1573
|
|
|
] |
1574
|
|
|
); |
1575
|
|
|
|
1576
|
|
|
/* Register WSEditUserCredentials function */ |
1577
|
|
|
// Register the data structures used by the service |
1578
|
|
|
$server->wsdl->addComplexType( |
1579
|
|
|
'editUserCredentials', |
1580
|
|
|
'complexType', |
1581
|
|
|
'struct', |
1582
|
|
|
'all', |
1583
|
|
|
'', |
1584
|
|
|
[ |
1585
|
|
|
'username' => ['name' => 'username', 'type' => 'xsd:string'], |
1586
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
1587
|
|
|
'password' => ['name' => 'password', 'type' => 'xsd:string'], |
1588
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
1589
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
1590
|
|
|
] |
1591
|
|
|
); |
1592
|
|
|
|
1593
|
|
|
// Register the method to expose |
1594
|
|
|
$server->register( |
1595
|
|
|
'WSEditUserCredentials', // method name |
1596
|
|
|
['editUserCredentials' => 'tns:editUserCredentials'], // input parameters |
1597
|
|
|
['return' => 'xsd:string'], // output parameters |
1598
|
|
|
'urn:WSRegistration', // namespace |
1599
|
|
|
'urn:WSRegistration#WSEditUserCredentials', // soapaction |
1600
|
|
|
'rpc', // style |
1601
|
|
|
'encoded', // use |
1602
|
|
|
'This service edits the username and password of a user' // documentation |
1603
|
|
|
); |
1604
|
|
|
|
1605
|
|
|
/** |
1606
|
|
|
* Define the method WSEditUser. |
1607
|
|
|
* |
1608
|
|
|
* @param array $params |
1609
|
|
|
* |
1610
|
|
|
* @throws \Doctrine\DBAL\DBALException |
1611
|
|
|
* |
1612
|
|
|
* @return bool|int|soap_fault|null |
1613
|
|
|
*/ |
1614
|
|
|
function WSEditUserCredentials($params) |
1615
|
|
|
{ |
1616
|
|
|
if (!WSHelperVerifyKey($params)) { |
1617
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
1618
|
|
|
} |
1619
|
|
|
|
1620
|
|
|
$userManager = UserManager::getManager(); |
1621
|
|
|
$userRepository = UserManager::getRepository(); |
1622
|
|
|
$table_user = Database::get_main_table(TABLE_MAIN_USER); |
1623
|
|
|
$original_user_id_value = $params['original_user_id_value']; |
1624
|
|
|
$original_user_id_name = $params['original_user_id_name']; |
1625
|
|
|
$username = $params['username']; |
1626
|
|
|
$password = null; |
1627
|
|
|
|
1628
|
|
|
if (!empty($params['password'])) { |
1629
|
|
|
$password = $params['password']; |
1630
|
|
|
} |
1631
|
|
|
|
1632
|
|
|
// Get user id from the other system ID |
1633
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
1634
|
|
|
$original_user_id_value, |
1635
|
|
|
$original_user_id_name |
1636
|
|
|
); |
1637
|
|
|
|
1638
|
|
|
if ($user_id == 0) { |
1639
|
|
|
return 0; |
1640
|
|
|
} else { |
1641
|
|
|
$sql = "SELECT user_id FROM $table_user |
1642
|
|
|
WHERE user_id ='$user_id' AND active= '0'"; |
1643
|
|
|
$resu = Database::query($sql); |
1644
|
|
|
$r_check_user = Database::fetch_row($resu); |
1645
|
|
|
if (!empty($r_check_user[0])) { |
1646
|
|
|
return 0; |
1647
|
|
|
} |
1648
|
|
|
} |
1649
|
|
|
|
1650
|
|
|
// Check whether username already exits. |
1651
|
|
|
$sql = "SELECT username FROM $table_user |
1652
|
|
|
WHERE username = '$username' AND user_id <> '$user_id'"; |
1653
|
|
|
$res_un = Database::query($sql); |
1654
|
|
|
$r_username = Database::fetch_row($res_un); |
1655
|
|
|
|
1656
|
|
|
if (!empty($r_username[0])) { |
1657
|
|
|
return 0; |
1658
|
|
|
} |
1659
|
|
|
|
1660
|
|
|
/** @var User $user */ |
1661
|
|
|
$user = $userRepository->find($user_id); |
1662
|
|
|
if ($user) { |
|
|
|
|
1663
|
|
|
$user->setUsername($username); |
1664
|
|
|
if (!is_null($password)) { |
1665
|
|
|
$user->setPlainPassword($password); |
1666
|
|
|
} |
1667
|
|
|
|
1668
|
|
|
$userManager->updateUser($user, true); |
1669
|
|
|
|
1670
|
|
|
return true; |
1671
|
|
|
} |
1672
|
|
|
|
1673
|
|
|
return false; |
1674
|
|
|
} |
1675
|
|
|
|
1676
|
|
|
// Prepare output params, in this case will return an array |
1677
|
|
|
$server->wsdl->addComplexType( |
1678
|
|
|
'result_editUsers', |
1679
|
|
|
'complexType', |
1680
|
|
|
'struct', |
1681
|
|
|
'all', |
1682
|
|
|
'', |
1683
|
|
|
[ |
1684
|
|
|
'original_user_id_value' => [ |
1685
|
|
|
'name' => 'original_user_id_value', |
1686
|
|
|
'type' => 'xsd:string', |
1687
|
|
|
], |
1688
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
1689
|
|
|
] |
1690
|
|
|
); |
1691
|
|
|
|
1692
|
|
|
$server->wsdl->addComplexType( |
1693
|
|
|
'results_editUsers', |
1694
|
|
|
'complexType', |
1695
|
|
|
'array', |
1696
|
|
|
'', |
1697
|
|
|
'SOAP-ENC:Array', |
1698
|
|
|
[], |
1699
|
|
|
[ |
1700
|
|
|
[ |
1701
|
|
|
'ref' => 'SOAP-ENC:arrayType', |
1702
|
|
|
'wsdl:arrayType' => 'tns:result_editUsers[]', |
1703
|
|
|
], |
1704
|
|
|
], |
1705
|
|
|
'tns:result_editUsers' |
1706
|
|
|
); |
1707
|
|
|
|
1708
|
|
|
// Register the method to expose |
1709
|
|
|
$server->register( |
1710
|
|
|
'WSEditUsers', // method name |
1711
|
|
|
['editUsers' => 'tns:editUsers'], // input parameters |
1712
|
|
|
['return' => 'tns:results_editUsers'], // output parameters |
1713
|
|
|
'urn:WSRegistration', // namespace |
1714
|
|
|
'urn:WSRegistration#WSEditUsers', // soapaction |
1715
|
|
|
'rpc', // style |
1716
|
|
|
'encoded', // use |
1717
|
|
|
'This service edits a user from wiener' // documentation |
1718
|
|
|
); |
1719
|
|
|
|
1720
|
|
|
// Define the method WSEditUsers |
1721
|
|
|
function WSEditUsers($params) |
1722
|
|
|
{ |
1723
|
|
|
if (!WSHelperVerifyKey($params)) { |
1724
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
1725
|
|
|
} |
1726
|
|
|
|
1727
|
|
|
$userManager = UserManager::getManager(); |
1728
|
|
|
$userRepository = UserManager::getRepository(); |
1729
|
|
|
$table_user = Database::get_main_table(TABLE_MAIN_USER); |
1730
|
|
|
|
1731
|
|
|
$users_params = $params['users']; |
1732
|
|
|
$results = []; |
1733
|
|
|
$orig_user_id_value = []; |
1734
|
|
|
|
1735
|
|
|
foreach ($users_params as $user_param) { |
1736
|
|
|
$original_user_id_value = $user_param['original_user_id_value']; |
1737
|
|
|
$original_user_id_name = $user_param['original_user_id_name']; |
1738
|
|
|
$orig_user_id_value[] = $original_user_id_value; |
1739
|
|
|
$firstname = $user_param['firstname']; |
1740
|
|
|
$lastname = $user_param['lastname']; |
1741
|
|
|
$username = $user_param['username']; |
1742
|
|
|
$password = null; |
1743
|
|
|
$auth_source = null; |
1744
|
|
|
$email = $user_param['email']; |
1745
|
|
|
$status = $user_param['status']; |
1746
|
|
|
$official_code = ''; |
1747
|
|
|
$phone = $user_param['phone']; |
1748
|
|
|
$expiration_date = $user_param['expiration_date']; |
1749
|
|
|
$creator_id = null; |
1750
|
|
|
$hr_dept_id = 0; |
1751
|
|
|
$extra = null; |
1752
|
|
|
$extra_list = $user_param['extra']; |
1753
|
|
|
|
1754
|
|
|
if (!empty($user_param['password'])) { |
1755
|
|
|
$password = $user_param['password']; |
1756
|
|
|
} |
1757
|
|
|
|
1758
|
|
|
// Get user id |
1759
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
1760
|
|
|
$original_user_id_value, |
1761
|
|
|
$original_user_id_name |
1762
|
|
|
); |
1763
|
|
|
|
1764
|
|
|
if ($user_id == 0) { |
1765
|
|
|
$results[] = 0; // Original_user_id_value doesn't exist. |
1766
|
|
|
continue; |
1767
|
|
|
} else { |
1768
|
|
|
$sql = "SELECT user_id FROM $table_user |
1769
|
|
|
WHERE user_id ='$user_id' AND active= '0'"; |
1770
|
|
|
$resu = Database::query($sql); |
1771
|
|
|
$r_check_user = Database::fetch_row($resu); |
1772
|
|
|
if (!empty($r_check_user[0])) { |
1773
|
|
|
$results[] = 0; // user_id is not active. |
1774
|
|
|
continue; |
1775
|
|
|
} |
1776
|
|
|
} |
1777
|
|
|
|
1778
|
|
|
// Check whether username already exits. |
1779
|
|
|
$sql = "SELECT username FROM $table_user |
1780
|
|
|
WHERE username = '$username' AND user_id <> '$user_id'"; |
1781
|
|
|
$res_un = Database::query($sql); |
1782
|
|
|
$r_username = Database::fetch_row($res_un); |
1783
|
|
|
|
1784
|
|
|
if (!empty($r_username[0])) { |
1785
|
|
|
$results[] = 0; // username already exits. |
1786
|
|
|
continue; |
1787
|
|
|
} |
1788
|
|
|
// Edit lastname and firstname only if not empty |
1789
|
|
|
|
1790
|
|
|
/** @var User $user */ |
1791
|
|
|
$user = $userRepository->find($user_id); |
1792
|
|
|
|
1793
|
|
|
if (!empty($lastname)) { |
1794
|
|
|
$user->setLastname($lastname); |
1795
|
|
|
} |
1796
|
|
|
if (!empty($firstname)) { |
1797
|
|
|
$user->setFirstname($firstname); |
1798
|
|
|
} |
1799
|
|
|
$user->setUsername($username); |
1800
|
|
|
if (!is_null($password)) { |
1801
|
|
|
$user->setPlainPassword($password); |
1802
|
|
|
} |
1803
|
|
|
if (!is_null($auth_source)) { |
1804
|
|
|
$user->setAuthSource($auth_source); |
1805
|
|
|
} |
1806
|
|
|
|
1807
|
|
|
// Exception for admins in case no status is provided in WS call... |
1808
|
|
|
$t_admin = Database::get_main_table(TABLE_MAIN_ADMIN); |
1809
|
|
|
$sqladmin = "SELECT user_id FROM $t_admin WHERE user_id = ".intval($user_id); |
1810
|
|
|
$resadmin = Database::query($sqladmin); |
1811
|
|
|
$is_admin = Database::num_rows($resadmin); |
1812
|
|
|
|
1813
|
|
|
if (empty($status)) { |
1814
|
|
|
$status = 5; |
1815
|
|
|
} |
1816
|
|
|
|
1817
|
|
|
if ($is_admin) { |
1818
|
|
|
$status = 1; |
1819
|
|
|
} |
1820
|
|
|
|
1821
|
|
|
if (!empty($expiration_date)) { |
1822
|
|
|
$expiration_date = new DateTime($expiration_date); |
1823
|
|
|
} |
1824
|
|
|
|
1825
|
|
|
$user |
1826
|
|
|
->setEmail($email) |
1827
|
|
|
->setStatus($status) |
1828
|
|
|
->setOfficialCode($official_code) |
1829
|
|
|
->setPhone($phone) |
1830
|
|
|
->setExpirationDate($expiration_date) |
1831
|
|
|
->setHrDeptId($hr_dept_id) |
1832
|
|
|
->setActive(true); |
1833
|
|
|
|
1834
|
|
|
if (!is_null($creator_id)) { |
1835
|
|
|
$user->setCreatorId($creator_id); |
1836
|
|
|
} |
1837
|
|
|
|
1838
|
|
|
$userManager->updateUser($user, true); |
1839
|
|
|
|
1840
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
1841
|
|
|
foreach ($extra_list as $extra) { |
1842
|
|
|
$extra_field_name = $extra['field_name']; |
1843
|
|
|
$extra_field_value = $extra['field_value']; |
1844
|
|
|
// Save the external system's id into user_field_value table. |
1845
|
|
|
UserManager::update_extra_field_value( |
1846
|
|
|
$user_id, |
1847
|
|
|
$extra_field_name, |
1848
|
|
|
$extra_field_value |
1849
|
|
|
); |
1850
|
|
|
} |
1851
|
|
|
} |
1852
|
|
|
|
1853
|
|
|
$results[] = $user->getId(); |
1854
|
|
|
continue; |
1855
|
|
|
} |
1856
|
|
|
|
1857
|
|
|
$count_results = count($results); |
1858
|
|
|
$output = []; |
1859
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
1860
|
|
|
$output[] = [ |
1861
|
|
|
'original_user_id_value' => $orig_user_id_value[$i], |
1862
|
|
|
'result' => $results[$i], |
1863
|
|
|
]; |
1864
|
|
|
} |
1865
|
|
|
|
1866
|
|
|
return $output; |
1867
|
|
|
} |
1868
|
|
|
|
1869
|
|
|
/* Register WSEditUser function */ |
1870
|
|
|
// Register the data structures used by the service |
1871
|
|
|
$server->wsdl->addComplexType( |
1872
|
|
|
'editUser', |
1873
|
|
|
'complexType', |
1874
|
|
|
'struct', |
1875
|
|
|
'all', |
1876
|
|
|
'', |
1877
|
|
|
[ |
1878
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
1879
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
1880
|
|
|
'firstname' => ['name' => 'firstname', 'type' => 'xsd:string'], |
1881
|
|
|
'lastname' => ['name' => 'lastname', 'type' => 'xsd:string'], |
1882
|
|
|
'username' => ['name' => 'username', 'type' => 'xsd:string'], |
1883
|
|
|
'password' => ['name' => 'password', 'type' => 'xsd:string'], |
1884
|
|
|
'email' => ['name' => 'email', 'type' => 'xsd:string'], |
1885
|
|
|
'status' => ['name' => 'status', 'type' => 'xsd:string'], |
1886
|
|
|
'phone' => ['name' => 'phone', 'type' => 'xsd:string'], |
1887
|
|
|
'expiration_date' => ['name' => 'expiration_date', 'type' => 'xsd:string'], |
1888
|
|
|
'enable' => ['name' => 'enable', 'type' => 'xsd:boolean'], |
1889
|
|
|
'language' => ['name' => 'language', 'type' => 'xsd:string'], |
1890
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:extrasList'], |
1891
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
1892
|
|
|
] |
1893
|
|
|
); |
1894
|
|
|
|
1895
|
|
|
// Register the method to expose |
1896
|
|
|
$server->register( |
1897
|
|
|
'WSEditUser', // method name |
1898
|
|
|
['editUser' => 'tns:editUser'], // input parameters |
1899
|
|
|
['return' => 'xsd:string'], // output parameters |
1900
|
|
|
'urn:WSRegistration', // namespace |
1901
|
|
|
'urn:WSRegistration#WSEditUser', // soapaction |
1902
|
|
|
'rpc', // style |
1903
|
|
|
'encoded', // use |
1904
|
|
|
'This service edits a user from wiener' // documentation |
1905
|
|
|
); |
1906
|
|
|
|
1907
|
|
|
// Define the method WSEditUser |
1908
|
|
|
function WSEditUser($params) |
1909
|
|
|
{ |
1910
|
|
|
if (!WSHelperVerifyKey($params)) { |
1911
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
1912
|
|
|
} |
1913
|
|
|
|
1914
|
|
|
$userManager = UserManager::getManager(); |
1915
|
|
|
$userRepository = UserManager::getRepository(); |
1916
|
|
|
|
1917
|
|
|
$table_user = Database::get_main_table(TABLE_MAIN_USER); |
1918
|
|
|
|
1919
|
|
|
$original_user_id_value = $params['original_user_id_value']; |
1920
|
|
|
$original_user_id_name = $params['original_user_id_name']; |
1921
|
|
|
$firstname = $params['firstname']; |
1922
|
|
|
$lastname = $params['lastname']; |
1923
|
|
|
$username = $params['username']; |
1924
|
|
|
$password = null; |
1925
|
|
|
$auth_source = null; |
1926
|
|
|
$email = $params['email']; |
1927
|
|
|
$status = $params['status']; |
1928
|
|
|
$official_code = ''; |
1929
|
|
|
$phone = $params['phone']; |
1930
|
|
|
$picture_uri = ''; |
1931
|
|
|
$expiration_date = $params['expiration_date']; |
1932
|
|
|
$enable = $params['enable']; |
1933
|
|
|
$language = $params['language']; |
1934
|
|
|
$creator_id = null; |
1935
|
|
|
$hr_dept_id = 0; |
1936
|
|
|
$extra = null; |
1937
|
|
|
$extra_list = $params['extra']; |
1938
|
|
|
|
1939
|
|
|
if (!empty($params['password'])) { |
1940
|
|
|
$password = $params['password']; |
1941
|
|
|
} |
1942
|
|
|
|
1943
|
|
|
// Get user id from id wiener |
1944
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
1945
|
|
|
$original_user_id_value, |
1946
|
|
|
$original_user_id_name |
1947
|
|
|
); |
1948
|
|
|
|
1949
|
|
|
if ($user_id == 0) { |
1950
|
|
|
return 0; |
1951
|
|
|
} elseif (empty($enable)) { |
1952
|
|
|
$sql = "SELECT user_id FROM $table_user |
1953
|
|
|
WHERE user_id ='$user_id' AND active= '0'"; |
1954
|
|
|
$resu = Database::query($sql); |
1955
|
|
|
$r_check_user = Database::fetch_row($resu); |
1956
|
|
|
if (!empty($r_check_user[0])) { |
1957
|
|
|
return 0; |
1958
|
|
|
} |
1959
|
|
|
} |
1960
|
|
|
|
1961
|
|
|
// Check whether username already exits. |
1962
|
|
|
$sql = "SELECT username FROM $table_user |
1963
|
|
|
WHERE username = '$username' AND user_id <> '$user_id'"; |
1964
|
|
|
$res_un = Database::query($sql); |
1965
|
|
|
$r_username = Database::fetch_row($res_un); |
1966
|
|
|
|
1967
|
|
|
if (!empty($r_username[0])) { |
1968
|
|
|
return 0; |
1969
|
|
|
} |
1970
|
|
|
|
1971
|
|
|
/** @var User $user */ |
1972
|
|
|
$user = $userRepository->find($user_id); |
1973
|
|
|
|
1974
|
|
|
if (!empty($lastname)) { |
1975
|
|
|
$user->setLastname($lastname); |
1976
|
|
|
} |
1977
|
|
|
if (!empty($firstname)) { |
1978
|
|
|
$user->setFirstname($firstname); |
1979
|
|
|
} |
1980
|
|
|
$user->setUsername($username); |
1981
|
|
|
if (!is_null($password)) { |
1982
|
|
|
$user->setPlainPassword($password); |
1983
|
|
|
} |
1984
|
|
|
if (!is_null($auth_source)) { |
1985
|
|
|
$user->setAuthSource($auth_source); |
1986
|
|
|
} |
1987
|
|
|
|
1988
|
|
|
// Exception for admins in case no status is provided in WS call... |
1989
|
|
|
$t_admin = Database::get_main_table(TABLE_MAIN_ADMIN); |
1990
|
|
|
$sqladmin = "SELECT user_id FROM $t_admin WHERE user_id = ".intval($user_id); |
1991
|
|
|
$resadmin = Database::query($sqladmin); |
1992
|
|
|
$is_admin = Database::num_rows($resadmin); |
1993
|
|
|
|
1994
|
|
|
if (empty($status)) { |
1995
|
|
|
$status = 5; |
1996
|
|
|
} |
1997
|
|
|
|
1998
|
|
|
if ($is_admin) { |
1999
|
|
|
$status = 1; |
2000
|
|
|
} |
2001
|
|
|
|
2002
|
|
|
if (!empty($expiration_date)) { |
2003
|
|
|
$expiration_date = new DateTime($expiration_date); |
2004
|
|
|
$user->setExpirationDate($expiration_date); |
2005
|
|
|
} |
2006
|
|
|
if (!empty($language)) { |
2007
|
|
|
$user->setLanguage($language); |
2008
|
|
|
} |
2009
|
|
|
|
2010
|
|
|
$user |
2011
|
|
|
->setEmail($email) |
2012
|
|
|
->setStatus($status) |
2013
|
|
|
->setOfficialCode($official_code) |
2014
|
|
|
->setPhone($phone) |
2015
|
|
|
->setPictureUri($picture_uri) |
2016
|
|
|
->setHrDeptId($hr_dept_id) |
2017
|
|
|
->setActive(true); |
2018
|
|
|
|
2019
|
|
|
if (!is_null($creator_id)) { |
2020
|
|
|
$user->setCreatorId($creator_id); |
2021
|
|
|
} |
2022
|
|
|
|
2023
|
|
|
$userManager->updateUser($user, true); |
2024
|
|
|
|
2025
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
2026
|
|
|
foreach ($extra_list as $extra) { |
2027
|
|
|
$extra_field_name = $extra['field_name']; |
2028
|
|
|
$extra_field_value = $extra['field_value']; |
2029
|
|
|
// Save the external system's id into user_field_value table. |
2030
|
|
|
UserManager::update_extra_field_value( |
2031
|
|
|
$user_id, |
2032
|
|
|
$extra_field_name, |
2033
|
|
|
$extra_field_value |
2034
|
|
|
); |
2035
|
|
|
} |
2036
|
|
|
} |
2037
|
|
|
|
2038
|
|
|
return $user_id; |
2039
|
|
|
} |
2040
|
|
|
|
2041
|
|
|
/* Register WSEditUserWithPicture function */ |
2042
|
|
|
// Register the data structures used by the service |
2043
|
|
|
$server->wsdl->addComplexType( |
2044
|
|
|
'editUserWithPicture', |
2045
|
|
|
'complexType', |
2046
|
|
|
'struct', |
2047
|
|
|
'all', |
2048
|
|
|
'', |
2049
|
|
|
[ |
2050
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
2051
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
2052
|
|
|
'firstname' => ['name' => 'firstname', 'type' => 'xsd:string'], |
2053
|
|
|
'lastname' => ['name' => 'lastname', 'type' => 'xsd:string'], |
2054
|
|
|
'username' => ['name' => 'username', 'type' => 'xsd:string'], |
2055
|
|
|
'password' => ['name' => 'password', 'type' => 'xsd:string'], |
2056
|
|
|
'email' => ['name' => 'email', 'type' => 'xsd:string'], |
2057
|
|
|
'status' => ['name' => 'status', 'type' => 'xsd:string'], |
2058
|
|
|
'phone' => ['name' => 'phone', 'type' => 'xsd:string'], |
2059
|
|
|
'expiration_date' => ['name' => 'expiration_date', 'type' => 'xsd:string'], |
2060
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:extrasList'], |
2061
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
2062
|
|
|
'picture_url' => ['name' => 'picture_url', 'type' => 'xsd:string'], |
2063
|
|
|
] |
2064
|
|
|
); |
2065
|
|
|
|
2066
|
|
|
// Register the method to expose |
2067
|
|
|
$server->register( |
2068
|
|
|
'WSEditUserWithPicture', // method name |
2069
|
|
|
['editUserWithPicture' => 'tns:editUserWithPicture'], // input parameters |
2070
|
|
|
['return' => 'xsd:string'], // output parameters |
2071
|
|
|
'urn:WSRegistration', // namespace |
2072
|
|
|
'urn:WSRegistration#WSEditUserWithPicture', // soapaction |
2073
|
|
|
'rpc', // style |
2074
|
|
|
'encoded', // use |
2075
|
|
|
'This service edits a user from wiener' // documentation |
2076
|
|
|
); |
2077
|
|
|
|
2078
|
|
|
// Define the method WSEditUserWithPicture |
2079
|
|
|
function WSEditUserWithPicture($params) |
2080
|
|
|
{ |
2081
|
|
|
if (ini_get('allow_url_fopen')) { |
2082
|
|
|
return new soap_fault( |
2083
|
|
|
'Server', |
2084
|
|
|
'', |
2085
|
|
|
'WSEditUserWithPicture is disabled because allow_url_fopen is enabled in the server.' |
2086
|
|
|
); |
2087
|
|
|
} |
2088
|
|
|
|
2089
|
|
|
if (!WSHelperVerifyKey($params)) { |
2090
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
2091
|
|
|
} |
2092
|
|
|
|
2093
|
|
|
$userManager = UserManager::getManager(); |
2094
|
|
|
$userRepository = UserManager::getRepository(); |
2095
|
|
|
$table_user = Database::get_main_table(TABLE_MAIN_USER); |
2096
|
|
|
|
2097
|
|
|
$original_user_id_value = $params['original_user_id_value']; |
2098
|
|
|
$original_user_id_name = $params['original_user_id_name']; |
2099
|
|
|
$firstname = $params['firstname']; |
2100
|
|
|
$lastname = $params['lastname']; |
2101
|
|
|
$username = $params['username']; |
2102
|
|
|
$password = null; |
2103
|
|
|
$auth_source = null; |
2104
|
|
|
$email = $params['email']; |
2105
|
|
|
$expiration_date = null; |
2106
|
|
|
$status = $params['status']; |
2107
|
|
|
$phone = $params['phone']; |
2108
|
|
|
$picture_url = $params['picture_url']; |
2109
|
|
|
$pictureUri = ''; |
2110
|
|
|
$creator_id = null; |
2111
|
|
|
$hr_dept_id = 0; |
2112
|
|
|
$extra = null; |
2113
|
|
|
$extra_list = $params['extra']; |
2114
|
|
|
if (!empty($params['expiration_date'])) { |
2115
|
|
|
$expiration_date = $params['expiration_date']; |
2116
|
|
|
} |
2117
|
|
|
|
2118
|
|
|
if (!empty($params['password'])) { |
2119
|
|
|
$password = $params['password']; |
2120
|
|
|
} |
2121
|
|
|
|
2122
|
|
|
// Get user id from external id |
2123
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
2124
|
|
|
$original_user_id_value, |
2125
|
|
|
$original_user_id_name |
2126
|
|
|
); |
2127
|
|
|
|
2128
|
|
|
if (empty($user_id)) { |
2129
|
|
|
return 0; |
2130
|
|
|
} |
2131
|
|
|
|
2132
|
|
|
$sql = "SELECT id FROM $table_user WHERE id =$user_id AND active= 0"; |
2133
|
|
|
$resu = Database::query($sql); |
2134
|
|
|
$r_check_user = Database::fetch_row($resu); |
2135
|
|
|
if (!empty($r_check_user[0])) { |
2136
|
|
|
return 0; |
2137
|
|
|
} |
2138
|
|
|
|
2139
|
|
|
// Check whether username already exits. |
2140
|
|
|
$sql = "SELECT username FROM $table_user |
2141
|
|
|
WHERE username = '$username' AND id <> $user_id"; |
2142
|
|
|
$res_un = Database::query($sql); |
2143
|
|
|
$r_username = Database::fetch_row($res_un); |
2144
|
|
|
|
2145
|
|
|
if (!empty($r_username[0])) { |
2146
|
|
|
return 0; |
2147
|
|
|
} |
2148
|
|
|
|
2149
|
|
|
// Get picture and generate uri. |
2150
|
|
|
$filename = basename($picture_url); |
2151
|
|
|
$tempDir = api_get_path(SYS_ARCHIVE_PATH); |
2152
|
|
|
// Make sure the file download was OK by checking the HTTP headers for OK |
2153
|
|
|
if (strpos(get_headers($picture_url)[0], "OK")) { |
2154
|
|
|
$tempFile = $tempDir.uniqid('user_image', true); |
2155
|
|
|
file_put_contents($tempFile, file_get_contents($picture_url)); |
2156
|
|
|
$pictureUri = UserManager::update_user_picture($user_id, $filename, $tempFile); |
2157
|
|
|
if (file_exists($tempFile)) { |
2158
|
|
|
unlink($tempFile); |
2159
|
|
|
} |
2160
|
|
|
} |
2161
|
|
|
|
2162
|
|
|
/** @var User $user */ |
2163
|
|
|
$user = $userRepository->find($user_id); |
2164
|
|
|
|
2165
|
|
|
if (!empty($lastname)) { |
2166
|
|
|
$user->setLastname($lastname); |
2167
|
|
|
} |
2168
|
|
|
if (!empty($firstname)) { |
2169
|
|
|
$user->setFirstname($firstname); |
2170
|
|
|
} |
2171
|
|
|
$user->setUsername($username); |
2172
|
|
|
if (!is_null($password)) { |
2173
|
|
|
$user->setPlainPassword($password); |
2174
|
|
|
} |
2175
|
|
|
if (!is_null($auth_source)) { |
2176
|
|
|
$user->setAuthSource($auth_source); |
2177
|
|
|
} |
2178
|
|
|
|
2179
|
|
|
// Exception for admins in case no status is provided in WS call... |
2180
|
|
|
$t_admin = Database::get_main_table(TABLE_MAIN_ADMIN); |
2181
|
|
|
$sqladmin = "SELECT user_id FROM $t_admin WHERE user_id = ".intval($user_id); |
2182
|
|
|
$resadmin = Database::query($sqladmin); |
2183
|
|
|
$is_admin = Database::num_rows($resadmin); |
2184
|
|
|
|
2185
|
|
|
if (empty($status)) { |
2186
|
|
|
$status = $user->getStatus(); |
2187
|
|
|
} |
2188
|
|
|
|
2189
|
|
|
if ($is_admin) { |
2190
|
|
|
$status = 1; |
2191
|
|
|
} |
2192
|
|
|
|
2193
|
|
|
if (!empty($expiration_date)) { |
2194
|
|
|
$expiration_date = new DateTime($expiration_date); |
2195
|
|
|
} |
2196
|
|
|
|
2197
|
|
|
$user |
2198
|
|
|
->setEmail($email) |
2199
|
|
|
->setStatus($status) |
2200
|
|
|
->setPhone($phone) |
2201
|
|
|
->setExpirationDate($expiration_date) |
2202
|
|
|
->setHrDeptId($hr_dept_id) |
2203
|
|
|
->setActive(true) |
2204
|
|
|
->setPictureUri($pictureUri) |
2205
|
|
|
; |
2206
|
|
|
|
2207
|
|
|
if (!is_null($creator_id)) { |
2208
|
|
|
$user->setCreatorId($creator_id); |
2209
|
|
|
} |
2210
|
|
|
|
2211
|
|
|
$userManager->updateUser($user, true); |
2212
|
|
|
|
2213
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
2214
|
|
|
foreach ($extra_list as $extra) { |
2215
|
|
|
$extra_field_name = $extra['field_name']; |
2216
|
|
|
$extra_field_value = $extra['field_value']; |
2217
|
|
|
// Save the external system's id into user_field_value table. |
2218
|
|
|
UserManager::update_extra_field_value( |
2219
|
|
|
$user_id, |
2220
|
|
|
$extra_field_name, |
2221
|
|
|
$extra_field_value |
2222
|
|
|
); |
2223
|
|
|
} |
2224
|
|
|
} |
2225
|
|
|
|
2226
|
|
|
return $user_id; |
2227
|
|
|
} |
2228
|
|
|
|
2229
|
|
|
/* Register WSEditUsersPasswordCrypted function */ |
2230
|
|
|
// Register the data structures used by the service |
2231
|
|
|
$server->wsdl->addComplexType( |
2232
|
|
|
'editUsersPasswordCryptedParams', |
2233
|
|
|
'complexType', |
2234
|
|
|
'struct', |
2235
|
|
|
'all', |
2236
|
|
|
'', |
2237
|
|
|
[ |
2238
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
2239
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
2240
|
|
|
'firstname' => ['name' => 'firstname', 'type' => 'xsd:string'], |
2241
|
|
|
'lastname' => ['name' => 'lastname', 'type' => 'xsd:string'], |
2242
|
|
|
'username' => ['name' => 'username', 'type' => 'xsd:string'], |
2243
|
|
|
'password' => ['name' => 'password', 'type' => 'xsd:string'], |
2244
|
|
|
'encrypt_method' => ['name' => 'encrypt_method', 'type' => 'xsd:string'], |
2245
|
|
|
'email' => ['name' => 'email', 'type' => 'xsd:string'], |
2246
|
|
|
'status' => ['name' => 'status', 'type' => 'xsd:string'], |
2247
|
|
|
'phone' => ['name' => 'phone', 'type' => 'xsd:string'], |
2248
|
|
|
'expiration_date' => ['name' => 'expiration_date', 'type' => 'xsd:string'], |
2249
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:extrasList'], |
2250
|
|
|
] |
2251
|
|
|
); |
2252
|
|
|
|
2253
|
|
|
$server->wsdl->addComplexType( |
2254
|
|
|
'editUsersPasswordCryptedParamsList', |
2255
|
|
|
'complexType', |
2256
|
|
|
'array', |
2257
|
|
|
'', |
2258
|
|
|
'SOAP-ENC:Array', |
2259
|
|
|
[], |
2260
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:editUsersPasswordCryptedParams[]']], |
2261
|
|
|
'tns:editUsersPasswordCryptedParams' |
2262
|
|
|
); |
2263
|
|
|
|
2264
|
|
|
$server->wsdl->addComplexType( |
2265
|
|
|
'editUsersPasswordCrypted', |
2266
|
|
|
'complexType', |
2267
|
|
|
'struct', |
2268
|
|
|
'all', |
2269
|
|
|
'', |
2270
|
|
|
[ |
2271
|
|
|
'users' => ['name' => 'users', 'type' => 'tns:editUsersPasswordCryptedParamsList'], |
2272
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
2273
|
|
|
] |
2274
|
|
|
); |
2275
|
|
|
|
2276
|
|
|
// Prepare output params, in this case will return an array |
2277
|
|
|
$server->wsdl->addComplexType( |
2278
|
|
|
'result_editUsersPasswordCrypted', |
2279
|
|
|
'complexType', |
2280
|
|
|
'struct', |
2281
|
|
|
'all', |
2282
|
|
|
'', |
2283
|
|
|
[ |
2284
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
2285
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
2286
|
|
|
] |
2287
|
|
|
); |
2288
|
|
|
|
2289
|
|
|
$server->wsdl->addComplexType( |
2290
|
|
|
'results_editUsersPasswordCrypted', |
2291
|
|
|
'complexType', |
2292
|
|
|
'array', |
2293
|
|
|
'', |
2294
|
|
|
'SOAP-ENC:Array', |
2295
|
|
|
[], |
2296
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_editUsersPasswordCrypted[]']], |
2297
|
|
|
'tns:result_editUsersPasswordCrypted' |
2298
|
|
|
); |
2299
|
|
|
|
2300
|
|
|
// Register the method to expose |
2301
|
|
|
$server->register( |
2302
|
|
|
'WSEditUsersPasswordCrypted', // method name |
2303
|
|
|
['editUsersPasswordCrypted' => 'tns:editUsersPasswordCrypted'], // input parameters |
2304
|
|
|
['return' => 'tns:results_editUsersPasswordCrypted'], // output parameters |
2305
|
|
|
'urn:WSRegistration', // namespace |
2306
|
|
|
'urn:WSRegistration#WSEditUsersPasswordCrypted', // soapaction |
2307
|
|
|
'rpc', // style |
2308
|
|
|
'encoded', // use |
2309
|
|
|
'This service edits a user' // documentation |
2310
|
|
|
); |
2311
|
|
|
|
2312
|
|
|
// Define the method WSEditUsersPasswordCrypted |
2313
|
|
|
function WSEditUsersPasswordCrypted($params) |
2314
|
|
|
{ |
2315
|
|
|
global $_configuration; |
2316
|
|
|
|
2317
|
|
|
if (!WSHelperVerifyKey($params)) { |
2318
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
2319
|
|
|
} |
2320
|
|
|
|
2321
|
|
|
// get user id from id of remote system |
2322
|
|
|
$table_user = Database::get_main_table(TABLE_MAIN_USER); |
2323
|
|
|
$users_params = $params['users']; |
2324
|
|
|
$results = []; |
2325
|
|
|
$orig_user_id_value = []; |
2326
|
|
|
|
2327
|
|
|
foreach ($users_params as $user_param) { |
2328
|
|
|
$original_user_id_value = $user_param['original_user_id_value']; |
2329
|
|
|
$original_user_id_name = $user_param['original_user_id_name']; |
2330
|
|
|
$orig_user_id_value[] = $original_user_id_value; |
2331
|
|
|
$firstname = $user_param['firstname']; |
2332
|
|
|
$lastname = $user_param['lastname']; |
2333
|
|
|
$username = $user_param['username']; |
2334
|
|
|
$password = null; |
2335
|
|
|
$auth_source = null; |
2336
|
|
|
$email = $user_param['email']; |
2337
|
|
|
$status = $user_param['status']; |
2338
|
|
|
$official_code = ''; |
2339
|
|
|
$phone = $user_param['phone']; |
2340
|
|
|
$picture_uri = ''; |
2341
|
|
|
$expiration_date = $user_param['expiration_date']; |
2342
|
|
|
$active = 1; |
2343
|
|
|
$creator_id = null; |
2344
|
|
|
$hr_dept_id = 0; |
2345
|
|
|
$extra = null; |
2346
|
|
|
$extra_list = $user_param['extra']; |
2347
|
|
|
|
2348
|
|
|
if (!empty($user_param['password']) && !empty($user_param['encrypt_method'])) { |
2349
|
|
|
$password = $user_param['password']; |
2350
|
|
|
$encrypt_method = $user_param['encrypt_method']; |
2351
|
|
|
if ($_configuration['password_encryption'] === $encrypt_method) { |
2352
|
|
|
if ($encrypt_method == 'md5' && !preg_match('/^[A-Fa-f0-9]{32}$/', $password)) { |
2353
|
|
|
$msg = "Encryption $encrypt_method is invalid"; |
2354
|
|
|
$results[] = $msg; |
2355
|
|
|
continue; |
2356
|
|
|
} elseif ($encrypt_method == 'sha1' && !preg_match('/^[A-Fa-f0-9]{40}$/', $password)) { |
2357
|
|
|
$msg = "Encryption $encrypt_method is invalid"; |
2358
|
|
|
$results[] = $msg; |
2359
|
|
|
continue; |
2360
|
|
|
} |
2361
|
|
|
} else { |
2362
|
|
|
$msg = "This encryption $encrypt_method is not configured"; |
2363
|
|
|
$results[] = $msg; |
2364
|
|
|
continue; |
2365
|
|
|
} |
2366
|
|
|
} elseif (!empty($user_param['password']) && empty($user_param['encrypt_method'])) { |
2367
|
|
|
$msg = "If password is not empty the encrypt_method param is required "; |
2368
|
|
|
$results[] = $msg; |
2369
|
|
|
continue; |
2370
|
|
|
} elseif (empty($user_param['password']) && !empty($user_param['encrypt_method'])) { |
2371
|
|
|
$msg = "If encrypt_method is not empty the password param is required "; |
2372
|
|
|
$results[] = $msg; |
2373
|
|
|
continue; |
2374
|
|
|
} |
2375
|
|
|
|
2376
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
2377
|
|
|
$original_user_id_value, |
2378
|
|
|
$original_user_id_name |
2379
|
|
|
); |
2380
|
|
|
|
2381
|
|
|
if ($user_id == 0) { |
2382
|
|
|
$results[] = 0; // Original_user_id_value doesn't exist. |
2383
|
|
|
continue; |
2384
|
|
|
} else { |
2385
|
|
|
$sql = "SELECT user_id FROM $table_user |
2386
|
|
|
WHERE user_id ='$user_id' AND active= '0'"; |
2387
|
|
|
$resu = Database::query($sql); |
2388
|
|
|
$r_check_user = Database::fetch_row($resu); |
2389
|
|
|
if (!empty($r_check_user[0])) { |
2390
|
|
|
$results[] = 0; // user_id is not active |
2391
|
|
|
continue; |
2392
|
|
|
} |
2393
|
|
|
} |
2394
|
|
|
|
2395
|
|
|
// Check if username already exits. |
2396
|
|
|
$sql = "SELECT username FROM $table_user |
2397
|
|
|
WHERE username ='$username' AND user_id <> '$user_id'"; |
2398
|
|
|
$res_un = Database::query($sql); |
2399
|
|
|
$r_username = Database::fetch_row($res_un); |
2400
|
|
|
|
2401
|
|
|
if (!empty($r_username[0])) { |
2402
|
|
|
$results[] = 0; |
2403
|
|
|
continue; // username already exits |
2404
|
|
|
} |
2405
|
|
|
|
2406
|
|
|
$sql = "UPDATE $table_user SET "; |
2407
|
|
|
if (!empty($lastname)) { |
2408
|
|
|
$sql .= " lastname='".Database::escape_string($lastname)."', "; |
2409
|
|
|
} |
2410
|
|
|
if (!empty($firstname)) { |
2411
|
|
|
$sql .= " firstname='".Database::escape_string($firstname)."', "; |
2412
|
|
|
} |
2413
|
|
|
$sql .= " username='".Database::escape_string($username)."',"; |
2414
|
|
|
if (!is_null($password)) { |
2415
|
|
|
$sql .= " password='".Database::escape_string($password)."',"; |
2416
|
|
|
} |
2417
|
|
|
if (!is_null($auth_source)) { |
2418
|
|
|
$sql .= " auth_source='".Database::escape_string($auth_source)."',"; |
2419
|
|
|
} |
2420
|
|
|
|
2421
|
|
|
// Exception for admins in case no status is provided in WS call... |
2422
|
|
|
$t_admin = Database::get_main_table(TABLE_MAIN_ADMIN); |
2423
|
|
|
$sqladmin = "SELECT user_id FROM $t_admin WHERE user_id = ".intval($user_id); |
2424
|
|
|
$resadmin = Database::query($sqladmin); |
2425
|
|
|
$is_admin = Database::num_rows($resadmin); |
2426
|
|
|
|
2427
|
|
|
if (empty($status)) { |
2428
|
|
|
$status = 5; |
2429
|
|
|
} |
2430
|
|
|
|
2431
|
|
|
if ($is_admin) { |
2432
|
|
|
$status = 1; |
2433
|
|
|
} |
2434
|
|
|
|
2435
|
|
|
$sql .= " |
2436
|
|
|
email='".Database::escape_string($email)."', |
2437
|
|
|
status='".Database::escape_string($status)."', |
2438
|
|
|
official_code='".Database::escape_string($official_code)."', |
2439
|
|
|
phone='".Database::escape_string($phone)."', |
2440
|
|
|
picture_uri='".Database::escape_string($picture_uri)."', |
2441
|
|
|
expiration_date='".Database::escape_string($expiration_date)."', |
2442
|
|
|
active='".Database::escape_string($active)."', |
2443
|
|
|
hr_dept_id=".intval($hr_dept_id); |
2444
|
|
|
|
2445
|
|
|
if (!is_null($creator_id)) { |
2446
|
|
|
$sql .= ", creator_id='".Database::escape_string($creator_id)."'"; |
2447
|
|
|
} |
2448
|
|
|
$sql .= " WHERE user_id='$user_id'"; |
2449
|
|
|
$return = @Database::query($sql); |
2450
|
|
|
|
2451
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
2452
|
|
|
foreach ($extra_list as $extra) { |
2453
|
|
|
$extra_field_name = $extra['field_name']; |
2454
|
|
|
$extra_field_value = $extra['field_value']; |
2455
|
|
|
// Save the external system's id into user_field_value table. |
2456
|
|
|
UserManager::update_extra_field_value( |
2457
|
|
|
$user_id, |
2458
|
|
|
$extra_field_name, |
2459
|
|
|
$extra_field_value |
2460
|
|
|
); |
2461
|
|
|
} |
2462
|
|
|
} |
2463
|
|
|
|
2464
|
|
|
$results[] = $return; |
2465
|
|
|
continue; |
2466
|
|
|
} //end principal foreach |
2467
|
|
|
|
2468
|
|
|
$count_results = count($results); |
2469
|
|
|
$output = []; |
2470
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
2471
|
|
|
$output[] = [ |
2472
|
|
|
'original_user_id_value' => $orig_user_id_value[$i], |
2473
|
|
|
'result' => $results[$i], |
2474
|
|
|
]; |
2475
|
|
|
} |
2476
|
|
|
|
2477
|
|
|
return $output; |
2478
|
|
|
} |
2479
|
|
|
|
2480
|
|
|
/* Register WSEditUserPasswordCrypted function */ |
2481
|
|
|
// Register the data structures used by the service |
2482
|
|
|
$server->wsdl->addComplexType( |
2483
|
|
|
'editUserPasswordCrypted', |
2484
|
|
|
'complexType', |
2485
|
|
|
'struct', |
2486
|
|
|
'all', |
2487
|
|
|
'', |
2488
|
|
|
[ |
2489
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
2490
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
2491
|
|
|
'firstname' => ['name' => 'firstname', 'type' => 'xsd:string'], |
2492
|
|
|
'lastname' => ['name' => 'lastname', 'type' => 'xsd:string'], |
2493
|
|
|
'username' => ['name' => 'username', 'type' => 'xsd:string'], |
2494
|
|
|
'password' => ['name' => 'password', 'type' => 'xsd:string'], |
2495
|
|
|
'encrypt_method' => ['name' => 'encrypt_method', 'type' => 'xsd:string'], |
2496
|
|
|
'email' => ['name' => 'email', 'type' => 'xsd:string'], |
2497
|
|
|
'status' => ['name' => 'status', 'type' => 'xsd:string'], |
2498
|
|
|
'phone' => ['name' => 'phone', 'type' => 'xsd:string'], |
2499
|
|
|
'expiration_date' => ['name' => 'expiration_date', 'type' => 'xsd:string'], |
2500
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:extrasList'], |
2501
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
2502
|
|
|
] |
2503
|
|
|
); |
2504
|
|
|
|
2505
|
|
|
// Register the method to expose |
2506
|
|
|
$server->register( |
2507
|
|
|
'WSEditUserPasswordCrypted', // method name |
2508
|
|
|
['editUserPasswordCrypted' => 'tns:editUserPasswordCrypted'], // input parameters |
2509
|
|
|
['return' => 'xsd:string'], // output parameters |
2510
|
|
|
'urn:WSRegistration', // namespace |
2511
|
|
|
'urn:WSRegistration#WSEditUserPasswordCrypted', // soapaction |
2512
|
|
|
'rpc', // style |
2513
|
|
|
'encoded', // use |
2514
|
|
|
'This service edits a user' // documentation |
2515
|
|
|
); |
2516
|
|
|
|
2517
|
|
|
// Define the method WSEditUserPasswordCrypted |
2518
|
|
|
function WSEditUserPasswordCrypted($params) |
2519
|
|
|
{ |
2520
|
|
|
global $_configuration, $debug; |
2521
|
|
|
if (!WSHelperVerifyKey($params)) { |
2522
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
2523
|
|
|
} |
2524
|
|
|
|
2525
|
|
|
if ($debug) { |
2526
|
|
|
error_log('WSEditUserPasswordCrypted'); |
2527
|
|
|
} |
2528
|
|
|
|
2529
|
|
|
$table_user = Database::get_main_table(TABLE_MAIN_USER); |
2530
|
|
|
|
2531
|
|
|
$original_user_id_value = $params['original_user_id_value']; |
2532
|
|
|
$original_user_id_name = $params['original_user_id_name']; |
2533
|
|
|
|
2534
|
|
|
$firstname = isset($params['firstname']) ? $params['firstname'] : ''; |
2535
|
|
|
$lastname = isset($params['lastname']) ? $params['lastname'] : ''; |
2536
|
|
|
$username = isset($params['username']) ? $params['username'] : ''; |
2537
|
|
|
$password = null; |
2538
|
|
|
$auth_source = null; |
2539
|
|
|
$email = isset($params['email']) ? $params['email'] : ''; |
2540
|
|
|
$status = isset($params['status']) ? $params['status'] : ''; |
2541
|
|
|
$official_code = ''; |
2542
|
|
|
$phone = isset($params['phone']) ? $params['phone'] : ''; |
2543
|
|
|
$picture_uri = ''; |
2544
|
|
|
$expiration_date = isset($params['expiration_date']) ? $params['expiration_date'] : ''; |
2545
|
|
|
$active = 1; |
2546
|
|
|
$creator_id = null; |
2547
|
|
|
$hr_dept_id = 0; |
2548
|
|
|
$extra = null; |
2549
|
|
|
$extra_list = isset($params['extra']) ? $params['extra'] : ''; |
2550
|
|
|
$params['password'] = isset($params['password']) ? $params['password'] : ''; |
2551
|
|
|
$params['encrypt_method'] = isset($params['encrypt_method']) ? $params['encrypt_method'] : ''; |
2552
|
|
|
|
2553
|
|
|
if (!empty($params['password']) && !empty($params['encrypt_method'])) { |
2554
|
|
|
$password = $params['password']; |
2555
|
|
|
$encrypt_method = $params['encrypt_method']; |
2556
|
|
|
if ($_configuration['password_encryption'] === $encrypt_method) { |
2557
|
|
|
if ($encrypt_method == 'md5' && !preg_match('/^[A-Fa-f0-9]{32}$/', $password)) { |
2558
|
|
|
$msg = "Encryption $encrypt_method is invalid"; |
2559
|
|
|
|
2560
|
|
|
return $msg; |
2561
|
|
|
} elseif ($encrypt_method == 'sha1' && !preg_match('/^[A-Fa-f0-9]{40}$/', $password)) { |
2562
|
|
|
$msg = "Encryption $encrypt_method is invalid"; |
2563
|
|
|
|
2564
|
|
|
return $msg; |
2565
|
|
|
} |
2566
|
|
|
} else { |
2567
|
|
|
$msg = "This encryption $encrypt_method is not configured"; |
2568
|
|
|
|
2569
|
|
|
return $msg; |
2570
|
|
|
} |
2571
|
|
|
} elseif (!empty($params['password']) && empty($params['encrypt_method'])) { |
2572
|
|
|
$msg = "If password is not empty the encrypt_method param is required "; |
2573
|
|
|
|
2574
|
|
|
return $msg; |
2575
|
|
|
} elseif (empty($params['password']) && !empty($params['encrypt_method'])) { |
2576
|
|
|
$msg = "If encrypt_method is not empty the password param is required "; |
2577
|
|
|
|
2578
|
|
|
return $msg; |
2579
|
|
|
} |
2580
|
|
|
|
2581
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
2582
|
|
|
$original_user_id_value, |
2583
|
|
|
$original_user_id_name |
2584
|
|
|
); |
2585
|
|
|
|
2586
|
|
|
if ($debug) { |
2587
|
|
|
error_log("user: $user_id"); |
2588
|
|
|
} |
2589
|
|
|
|
2590
|
|
|
if ($user_id == 0) { |
2591
|
|
|
return 0; |
2592
|
|
|
} else { |
2593
|
|
|
$sql = "SELECT user_id FROM $table_user |
2594
|
|
|
WHERE user_id ='$user_id' AND active= '0'"; |
2595
|
|
|
$resu = Database::query($sql); |
2596
|
|
|
$r_check_user = Database::fetch_row($resu); |
2597
|
|
|
if (!empty($r_check_user[0])) { |
2598
|
|
|
return 0; |
2599
|
|
|
} |
2600
|
|
|
} |
2601
|
|
|
|
2602
|
|
|
// Check whether username already exits. |
2603
|
|
|
$sql = "SELECT username FROM $table_user |
2604
|
|
|
WHERE username ='$username' AND user_id <> '$user_id'"; |
2605
|
|
|
$res_un = Database::query($sql); |
2606
|
|
|
$r_username = Database::fetch_row($res_un); |
2607
|
|
|
|
2608
|
|
|
if (!empty($r_username[0])) { |
2609
|
|
|
return 0; |
2610
|
|
|
} |
2611
|
|
|
// Edit lastname and firstname only if not empty |
2612
|
|
|
$sql = "UPDATE $table_user SET "; |
2613
|
|
|
if (!empty($lastname)) { |
2614
|
|
|
$sql .= " lastname='".Database::escape_string($lastname)."', "; |
2615
|
|
|
} |
2616
|
|
|
if (!empty($firstname)) { |
2617
|
|
|
$sql .= " firstname='".Database::escape_string($firstname)."', "; |
2618
|
|
|
} |
2619
|
|
|
$sql .= " username='".Database::escape_string($username)."',"; |
2620
|
|
|
|
2621
|
|
|
if (!empty($password)) { |
2622
|
|
|
$sql .= " password='".Database::escape_string($password)."',"; |
2623
|
|
|
} |
2624
|
|
|
|
2625
|
|
|
if (!empty($auth_source)) { |
2626
|
|
|
$sql .= " auth_source='".Database::escape_string($auth_source)."',"; |
2627
|
|
|
} |
2628
|
|
|
|
2629
|
|
|
// Exception for admins in case no status is provided in WS call... |
2630
|
|
|
$t_admin = Database::get_main_table(TABLE_MAIN_ADMIN); |
2631
|
|
|
$sqladmin = "SELECT user_id FROM $t_admin WHERE user_id = ".intval($user_id); |
2632
|
|
|
$resadmin = Database::query($sqladmin); |
2633
|
|
|
$is_admin = Database::num_rows($resadmin); |
2634
|
|
|
|
2635
|
|
|
if (empty($status)) { |
2636
|
|
|
$status = 5; |
2637
|
|
|
} |
2638
|
|
|
|
2639
|
|
|
if ($is_admin) { |
2640
|
|
|
$status = 1; |
2641
|
|
|
} |
2642
|
|
|
|
2643
|
|
|
$sql .= " |
2644
|
|
|
email='".Database::escape_string($email)."', |
2645
|
|
|
status='".Database::escape_string($status)."', |
2646
|
|
|
official_code='".Database::escape_string($official_code)."', |
2647
|
|
|
phone='".Database::escape_string($phone)."', |
2648
|
|
|
picture_uri='".Database::escape_string($picture_uri)."', |
2649
|
|
|
expiration_date='".Database::escape_string($expiration_date)."', |
2650
|
|
|
active='".Database::escape_string($active)."', |
2651
|
|
|
hr_dept_id=".intval($hr_dept_id); |
2652
|
|
|
|
2653
|
|
|
if (!is_null($creator_id)) { |
2654
|
|
|
$sql .= ", creator_id='".Database::escape_string($creator_id)."'"; |
2655
|
|
|
} |
2656
|
|
|
|
2657
|
|
|
$sql .= " WHERE user_id='$user_id'"; |
2658
|
|
|
$return = @Database::query($sql); |
2659
|
|
|
|
2660
|
|
|
if ($debug) { |
2661
|
|
|
error_log("SQL: $sql"); |
2662
|
|
|
} |
2663
|
|
|
|
2664
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
2665
|
|
|
foreach ($extra_list as $extra) { |
2666
|
|
|
$extra_field_name = $extra['field_name']; |
2667
|
|
|
$extra_field_value = $extra['field_value']; |
2668
|
|
|
// save the external system's id into user_field_value table' |
2669
|
|
|
UserManager::update_extra_field_value( |
2670
|
|
|
$user_id, |
2671
|
|
|
$extra_field_name, |
2672
|
|
|
$extra_field_value |
2673
|
|
|
); |
2674
|
|
|
} |
2675
|
|
|
} |
2676
|
|
|
|
2677
|
|
|
if ($return) { |
|
|
|
|
2678
|
|
|
return 1; |
2679
|
|
|
} |
2680
|
|
|
|
2681
|
|
|
return 0; |
2682
|
|
|
} |
2683
|
|
|
|
2684
|
|
|
// Prepare output params for actions on users (delete, disable, enable), will return an array |
2685
|
|
|
$server->wsdl->addComplexType( |
2686
|
|
|
'result_actionUsers', |
2687
|
|
|
'complexType', |
2688
|
|
|
'struct', |
2689
|
|
|
'all', |
2690
|
|
|
'', |
2691
|
|
|
[ |
2692
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
2693
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
2694
|
|
|
] |
2695
|
|
|
); |
2696
|
|
|
|
2697
|
|
|
$server->wsdl->addComplexType( |
2698
|
|
|
'results_actionUsers', |
2699
|
|
|
'complexType', |
2700
|
|
|
'array', |
2701
|
|
|
'', |
2702
|
|
|
'SOAP-ENC:Array', |
2703
|
|
|
[], |
2704
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_actionUsers[]']], |
2705
|
|
|
'tns:result_actionUsers' |
2706
|
|
|
); |
2707
|
|
|
|
2708
|
|
|
/** WSDeleteUsers */ |
2709
|
|
|
$server->wsdl->addComplexType( |
2710
|
|
|
'user_id', |
2711
|
|
|
'complexType', |
2712
|
|
|
'struct', |
2713
|
|
|
'all', |
2714
|
|
|
'', |
2715
|
|
|
[ |
2716
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
2717
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
2718
|
|
|
] |
2719
|
|
|
); |
2720
|
|
|
|
2721
|
|
|
$server->wsdl->addComplexType( |
2722
|
|
|
'user_ids_array', |
2723
|
|
|
'complexType', |
2724
|
|
|
'array', |
2725
|
|
|
'', |
2726
|
|
|
'SOAP-ENC:Array', |
2727
|
|
|
[], |
2728
|
|
|
[ |
2729
|
|
|
[ |
2730
|
|
|
'ref' => 'SOAP-ENC:arrayType', |
2731
|
|
|
'wsdl:arrayType' => 'tns:user_id[]', |
2732
|
|
|
], |
2733
|
|
|
], |
2734
|
|
|
'tns:user_id' |
2735
|
|
|
); |
2736
|
|
|
|
2737
|
|
|
$server->wsdl->addComplexType( |
2738
|
|
|
'user_ids', |
2739
|
|
|
'complexType', |
2740
|
|
|
'struct', |
2741
|
|
|
'all', |
2742
|
|
|
'', |
2743
|
|
|
[ |
2744
|
|
|
'ids' => ['name' => 'user_ids', 'type' => 'tns:user_ids_array'], |
2745
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
2746
|
|
|
] |
2747
|
|
|
); |
2748
|
|
|
|
2749
|
|
|
function WSHelperActionOnUsers($params, $type) |
2750
|
|
|
{ |
2751
|
|
|
$debug = 1; |
2752
|
|
|
if ($debug) { |
2753
|
|
|
error_log("WSHelperActionOnUsers"); |
2754
|
|
|
error_log(print_r($params, 1)); |
2755
|
|
|
} |
2756
|
|
|
|
2757
|
|
|
if (!WSHelperVerifyKey($params)) { |
2758
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
2759
|
|
|
} |
2760
|
|
|
|
2761
|
|
|
$results = []; |
2762
|
|
|
$orig_user_id_value = []; |
2763
|
|
|
$original_user_ids = $params['ids']; |
2764
|
|
|
foreach ($original_user_ids as $original_user_id) { |
2765
|
|
|
$result = false; |
2766
|
|
|
$orig_user_id_value[] = $original_user_id['original_user_id_value']; |
2767
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
2768
|
|
|
$original_user_id['original_user_id_value'], |
2769
|
|
|
$original_user_id['original_user_id_name'] |
2770
|
|
|
); |
2771
|
|
|
if ($user_id > 0) { |
2772
|
|
|
if ($debug) { |
2773
|
|
|
error_log("User found: $user_id"); |
2774
|
|
|
} |
2775
|
|
|
if ($type == 'delete') { |
2776
|
|
|
$result = UserManager::delete_user($user_id); |
2777
|
|
|
} elseif ($type == "disable") { |
2778
|
|
|
$result = UserManager::disable($user_id); |
2779
|
|
|
} elseif ($type == "enable") { |
2780
|
|
|
$result = UserManager::enable($user_id); |
2781
|
|
|
} |
2782
|
|
|
} else { |
2783
|
|
|
if ($debug) { |
2784
|
|
|
error_log("User id not found: $user_id"); |
2785
|
|
|
} |
2786
|
|
|
} |
2787
|
|
|
$results[] = $result ? 1 : 0; |
2788
|
|
|
} |
2789
|
|
|
|
2790
|
|
|
$count_results = count($results); |
2791
|
|
|
$output = []; |
2792
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
2793
|
|
|
$output[] = [ |
2794
|
|
|
'original_user_id_value' => $orig_user_id_value[$i], |
2795
|
|
|
'result' => $results[$i], |
2796
|
|
|
]; |
2797
|
|
|
} |
2798
|
|
|
|
2799
|
|
|
return $output; |
2800
|
|
|
} |
2801
|
|
|
|
2802
|
|
|
$server->register( |
2803
|
|
|
'WSDeleteUsers', // method name |
2804
|
|
|
['user_ids' => 'tns:user_ids'], // input parameters |
2805
|
|
|
['return' => 'tns:results_actionUsers'], // output parameters |
2806
|
|
|
'urn:WSRegistration', // namespace |
2807
|
|
|
'urn:WSRegistration#WSDeleteUsers', // soapaction |
2808
|
|
|
'rpc', // style |
2809
|
|
|
'encoded', // use |
2810
|
|
|
'Deletes users provided as parameters from the system' // documentation |
2811
|
|
|
); |
2812
|
|
|
|
2813
|
|
|
function WSDeleteUsers($params) |
2814
|
|
|
{ |
2815
|
|
|
return WSHelperActionOnUsers($params, 'delete'); |
2816
|
|
|
} |
2817
|
|
|
|
2818
|
|
|
/** WSDisableUsers */ |
2819
|
|
|
$server->register( |
2820
|
|
|
'WSDisableUsers', // method name |
2821
|
|
|
['user_ids' => 'tns:user_ids'], // input parameters |
2822
|
|
|
['return' => 'tns:results_actionUsers'], // output parameters |
2823
|
|
|
'urn:WSRegistration', // namespace |
2824
|
|
|
'urn:WSRegistration#WSDisableUsers', // soapaction |
2825
|
|
|
'rpc', // style |
2826
|
|
|
'encoded', // use |
2827
|
|
|
'Disables users provided as parameters from the system' // documentation |
2828
|
|
|
); |
2829
|
|
|
|
2830
|
|
|
function WSDisableUsers($params) |
2831
|
|
|
{ |
2832
|
|
|
return WSHelperActionOnUsers($params, "disable"); |
2833
|
|
|
} |
2834
|
|
|
|
2835
|
|
|
/** WSEnableUsers */ |
2836
|
|
|
$server->register( |
2837
|
|
|
'WSEnableUsers', // method name |
2838
|
|
|
['user_ids' => 'tns:user_ids'], // input parameters |
2839
|
|
|
['return' => 'tns:results_actionUsers'], // output parameters |
2840
|
|
|
'urn:WSRegistration', // namespace |
2841
|
|
|
'urn:WSRegistration#WSEnableUsers', // soapaction |
2842
|
|
|
'rpc', // style |
2843
|
|
|
'encoded', // use |
2844
|
|
|
'Enables users provided as parameters' // documentation |
2845
|
|
|
); |
2846
|
|
|
|
2847
|
|
|
function WSEnableUsers($params) |
2848
|
|
|
{ |
2849
|
|
|
return WSHelperActionOnUsers($params, "enable"); |
2850
|
|
|
} |
2851
|
|
|
|
2852
|
|
|
/* Register WSCreateCourse function */ |
2853
|
|
|
// Register the data structures used by the service |
2854
|
|
|
|
2855
|
|
|
$server->wsdl->addComplexType( |
2856
|
|
|
'course_id', |
2857
|
|
|
'complexType', |
2858
|
|
|
'struct', |
2859
|
|
|
'all', |
2860
|
|
|
'', |
2861
|
|
|
[ |
2862
|
|
|
'original_course_id_name' => ['name' => 'original_course_id_name', 'type' => 'xsd:string'], |
2863
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
2864
|
|
|
] |
2865
|
|
|
); |
2866
|
|
|
|
2867
|
|
|
$server->wsdl->addComplexType( |
2868
|
|
|
'createCourseParams', |
2869
|
|
|
'complexType', |
2870
|
|
|
'struct', |
2871
|
|
|
'all', |
2872
|
|
|
'', |
2873
|
|
|
[ |
2874
|
|
|
'title' => ['name' => 'title', 'type' => 'xsd:string'], |
2875
|
|
|
'category_code' => ['name' => 'category_code', 'type' => 'xsd:string'], |
2876
|
|
|
'wanted_code' => ['name' => 'wanted_code', 'type' => 'xsd:string'], |
2877
|
|
|
'tutor_name' => ['name' => 'tutor_name', 'type' => 'xsd:string'], |
2878
|
|
|
'course_language' => ['name' => 'course_language', 'type' => 'xsd:string'], |
2879
|
|
|
'disk_quota' => ['name' => 'disk_quota', 'type' => 'xsd:string'], // disk_quota in MB |
2880
|
|
|
'subscribe' => ['name' => 'subscribe', 'type' => 'xsd:string'], |
2881
|
|
|
'unsubscribe' => ['name' => 'unsubscribe', 'type' => 'xsd:string'], |
2882
|
|
|
'original_course_id_name' => ['name' => 'original_course_id_name', 'type' => 'xsd:string'], |
2883
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
2884
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:extrasList'], |
2885
|
|
|
] |
2886
|
|
|
); |
2887
|
|
|
|
2888
|
|
|
$server->wsdl->addComplexType( |
2889
|
|
|
'createCourseParamsList', |
2890
|
|
|
'complexType', |
2891
|
|
|
'array', |
2892
|
|
|
'', |
2893
|
|
|
'SOAP-ENC:Array', |
2894
|
|
|
[], |
2895
|
|
|
[ |
2896
|
|
|
[ |
2897
|
|
|
'ref' => 'SOAP-ENC:arrayType', |
2898
|
|
|
'wsdl:arrayType' => 'tns:createCourseParams[]', |
2899
|
|
|
], |
2900
|
|
|
], |
2901
|
|
|
'tns:createCourseParams' |
2902
|
|
|
); |
2903
|
|
|
|
2904
|
|
|
// Register the data structures used by the service |
2905
|
|
|
$server->wsdl->addComplexType( |
2906
|
|
|
'createCourse', |
2907
|
|
|
'complexType', |
2908
|
|
|
'struct', |
2909
|
|
|
'all', |
2910
|
|
|
'', |
2911
|
|
|
[ |
2912
|
|
|
'courses' => ['name' => 'courses', 'type' => 'tns:createCourseParamsList'], |
2913
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
2914
|
|
|
] |
2915
|
|
|
); |
2916
|
|
|
|
2917
|
|
|
// Prepare output params, in this case will return an array |
2918
|
|
|
$server->wsdl->addComplexType( |
2919
|
|
|
'result_createCourse', |
2920
|
|
|
'complexType', |
2921
|
|
|
'struct', |
2922
|
|
|
'all', |
2923
|
|
|
'', |
2924
|
|
|
[ |
2925
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
2926
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
2927
|
|
|
] |
2928
|
|
|
); |
2929
|
|
|
|
2930
|
|
|
$server->wsdl->addComplexType( |
2931
|
|
|
'results_createCourse', |
2932
|
|
|
'complexType', |
2933
|
|
|
'array', |
2934
|
|
|
'', |
2935
|
|
|
'SOAP-ENC:Array', |
2936
|
|
|
[], |
2937
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_createCourse[]']], |
2938
|
|
|
'tns:result_createCourse' |
2939
|
|
|
); |
2940
|
|
|
|
2941
|
|
|
// Register the method to expose |
2942
|
|
|
$server->register( |
2943
|
|
|
'WSCreateCourse', // method name |
2944
|
|
|
['createCourse' => 'tns:createCourse'], // input parameters |
2945
|
|
|
['return' => 'tns:results_createCourse'], // output parameters |
2946
|
|
|
'urn:WSRegistration', // namespace |
2947
|
|
|
'urn:WSRegistration#WSCreateCourse', // soapaction |
2948
|
|
|
'rpc', // style |
2949
|
|
|
'encoded', // use |
2950
|
|
|
'This service adds a course' // documentation |
2951
|
|
|
); |
2952
|
|
|
|
2953
|
|
|
// Define the method WSCreateCourse |
2954
|
|
|
function WSCreateCourse($params) |
2955
|
|
|
{ |
2956
|
|
|
if (!WSHelperVerifyKey($params)) { |
2957
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
2958
|
|
|
} |
2959
|
|
|
$table_course = Database::get_main_table(TABLE_MAIN_COURSE); |
2960
|
|
|
$courses_params = $params['courses']; |
2961
|
|
|
$results = []; |
2962
|
|
|
$sessionAdminId = DEFAULT_ADMIN_USER_ID; |
2963
|
|
|
$orig_course_id_value = []; |
2964
|
|
|
foreach ($courses_params as $course_param) { |
2965
|
|
|
$title = $course_param['title']; |
2966
|
|
|
$category_code = isset($course_param['category_code']) ? $course_param['category_code'] : ''; |
2967
|
|
|
$wanted_code = $course_param['wanted_code']; |
2968
|
|
|
$tutor_name = isset($course_param['tutor_name']) ? $course_param['tutor_name'] : ''; |
2969
|
|
|
$diskQuota = isset($course_param['disk_quota']) ? $course_param['disk_quota'] : '100'; |
2970
|
|
|
// Convert to MB |
2971
|
|
|
$diskQuota = $diskQuota * 1024 * 1024; |
2972
|
|
|
|
2973
|
|
|
$course_language = 'english'; // TODO: A hard-coded value. |
2974
|
|
|
$original_course_id_name = $course_param['original_course_id_name']; |
2975
|
|
|
$original_course_id_value = $course_param['original_course_id_value']; |
2976
|
|
|
$orig_course_id_value[] = $course_param['original_course_id_value']; |
2977
|
|
|
$visibility = null; |
2978
|
|
|
$subscribe = $course_param['subscribe']; |
2979
|
|
|
$unsubscribe = $course_param['unsubscribe']; |
2980
|
|
|
|
2981
|
|
|
if (isset($course_param['visibility'])) { |
2982
|
|
|
if ($course_param['visibility'] && |
2983
|
|
|
$course_param['visibility'] >= 0 && |
2984
|
|
|
$course_param['visibility'] <= 3 |
2985
|
|
|
) { |
2986
|
|
|
$visibility = $course_param['visibility']; |
2987
|
|
|
} |
2988
|
|
|
} |
2989
|
|
|
$extra_list = isset($course_param['extra']) ? $course_param['extra'] : ''; |
2990
|
|
|
|
2991
|
|
|
// Check whether exits $x_course_code into user_field_values table. |
2992
|
|
|
$courseInfo = CourseManager::getCourseInfoFromOriginalId( |
2993
|
|
|
$course_param['original_course_id_value'], |
2994
|
|
|
$course_param['original_course_id_name'] |
2995
|
|
|
); |
2996
|
|
|
|
2997
|
|
|
if (!empty($courseInfo)) { |
2998
|
|
|
if ($courseInfo['visibility'] != 0) { |
2999
|
|
|
$sql = "UPDATE $table_course SET |
3000
|
|
|
course_language='".Database::escape_string($course_language)."', |
3001
|
|
|
title='".Database::escape_string($title)."', |
3002
|
|
|
category_code='".Database::escape_string($category_code)."', |
3003
|
|
|
tutor_name='".Database::escape_string($tutor_name)."', |
3004
|
|
|
visual_code='".Database::escape_string($wanted_code)."'"; |
3005
|
|
|
if ($visibility !== null) { |
3006
|
|
|
$sql .= ", visibility = '$visibility' "; |
3007
|
|
|
} |
3008
|
|
|
$sql .= " WHERE id='".$courseInfo['real_id']."'"; |
3009
|
|
|
Database::query($sql); |
3010
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
3011
|
|
|
foreach ($extra_list as $extra) { |
3012
|
|
|
$extra_field_name = $extra['field_name']; |
3013
|
|
|
$extra_field_value = $extra['field_value']; |
3014
|
|
|
// Save the external system's id into course_field_value table. |
3015
|
|
|
CourseManager::update_course_extra_field_value( |
3016
|
|
|
$courseInfo['code'], |
3017
|
|
|
$extra_field_name, |
3018
|
|
|
$extra_field_value |
3019
|
|
|
); |
3020
|
|
|
} |
3021
|
|
|
} |
3022
|
|
|
$results[] = $courseInfo['code']; |
3023
|
|
|
continue; |
3024
|
|
|
} else { |
3025
|
|
|
$results[] = 0; |
3026
|
|
|
continue; // Original course id already exits. |
3027
|
|
|
} |
3028
|
|
|
} |
3029
|
|
|
|
3030
|
|
|
if (!empty($course_param['course_language'])) { |
3031
|
|
|
$course_language = $course_param['course_language']; |
3032
|
|
|
} |
3033
|
|
|
|
3034
|
|
|
$params = []; |
3035
|
|
|
$params['title'] = $title; |
3036
|
|
|
$params['wanted_code'] = $wanted_code; |
3037
|
|
|
$params['category_code'] = $category_code; |
3038
|
|
|
$params['course_category'] = $category_code; |
3039
|
|
|
$params['tutor_name'] = $tutor_name; |
3040
|
|
|
$params['course_language'] = $course_language; |
3041
|
|
|
$params['user_id'] = $sessionAdminId; |
3042
|
|
|
$params['visibility'] = $visibility; |
3043
|
|
|
$params['disk_quota'] = $diskQuota; |
3044
|
|
|
|
3045
|
|
|
if (isset($subscribe) && $subscribe != '') { // Valid values: 0, 1 |
3046
|
|
|
$params['subscribe'] = $subscribe; |
3047
|
|
|
} |
3048
|
|
|
if (isset($unsubscribe) && $subscribe != '') { // Valid values: 0, 1 |
3049
|
|
|
$params['unsubscribe'] = $unsubscribe; |
3050
|
|
|
} |
3051
|
|
|
|
3052
|
|
|
$course_info = CourseManager::create_course($params, $sessionAdminId); |
3053
|
|
|
|
3054
|
|
|
if (!empty($course_info)) { |
3055
|
|
|
$course_code = $course_info['code']; |
3056
|
|
|
|
3057
|
|
|
// Save new field label into course_field table |
3058
|
|
|
CourseManager::create_course_extra_field( |
3059
|
|
|
$original_course_id_name, |
3060
|
|
|
1, |
3061
|
|
|
$original_course_id_name, |
3062
|
|
|
'' |
3063
|
|
|
); |
3064
|
|
|
|
3065
|
|
|
// Save the external system's id into user_field_value table. |
3066
|
|
|
CourseManager::update_course_extra_field_value( |
3067
|
|
|
$course_code, |
3068
|
|
|
$original_course_id_name, |
3069
|
|
|
$original_course_id_value |
3070
|
|
|
); |
3071
|
|
|
|
3072
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
3073
|
|
|
foreach ($extra_list as $extra) { |
3074
|
|
|
$extra_field_name = $extra['field_name']; |
3075
|
|
|
$extra_field_value = $extra['field_value']; |
3076
|
|
|
// Save new fieldlabel into course_field table. |
3077
|
|
|
CourseManager::create_course_extra_field( |
3078
|
|
|
$extra_field_name, |
3079
|
|
|
1, |
3080
|
|
|
$extra_field_name, |
3081
|
|
|
'' |
3082
|
|
|
); |
3083
|
|
|
// Save the external system's id into course_field_value table. |
3084
|
|
|
CourseManager::update_course_extra_field_value( |
3085
|
|
|
$course_code, |
3086
|
|
|
$extra_field_name, |
3087
|
|
|
$extra_field_value |
3088
|
|
|
); |
3089
|
|
|
} |
3090
|
|
|
} |
3091
|
|
|
$results[] = $course_code; |
3092
|
|
|
} else { |
3093
|
|
|
$results[] = 0; |
3094
|
|
|
} |
3095
|
|
|
} // end principal foreach |
3096
|
|
|
|
3097
|
|
|
$count_results = count($results); |
3098
|
|
|
$output = []; |
3099
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
3100
|
|
|
$output[] = [ |
3101
|
|
|
'original_course_id_value' => $orig_course_id_value[$i], |
3102
|
|
|
'result' => $results[$i], |
3103
|
|
|
]; |
3104
|
|
|
} |
3105
|
|
|
|
3106
|
|
|
return $output; |
3107
|
|
|
} |
3108
|
|
|
|
3109
|
|
|
/* Register WSCreateCourseByTitle function */ |
3110
|
|
|
// Register the data structures used by the service |
3111
|
|
|
$server->wsdl->addComplexType( |
3112
|
|
|
'createCourseByTitleParams', |
3113
|
|
|
'complexType', |
3114
|
|
|
'struct', |
3115
|
|
|
'all', |
3116
|
|
|
'', |
3117
|
|
|
[ |
3118
|
|
|
'title' => ['name' => 'title', 'type' => 'xsd:string'], |
3119
|
|
|
'tutor_name' => ['name' => 'tutor_name', 'type' => 'xsd:string'], |
3120
|
|
|
'original_course_id_name' => ['name' => 'original_course_id_name', 'type' => 'xsd:string'], |
3121
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
3122
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:extrasList'], |
3123
|
|
|
] |
3124
|
|
|
); |
3125
|
|
|
|
3126
|
|
|
$server->wsdl->addComplexType( |
3127
|
|
|
'createCourseByTitleParamsList', |
3128
|
|
|
'complexType', |
3129
|
|
|
'array', |
3130
|
|
|
'', |
3131
|
|
|
'SOAP-ENC:Array', |
3132
|
|
|
[], |
3133
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:createCourseByTitleParams[]']], |
3134
|
|
|
'tns:createCourseByTitleParams' |
3135
|
|
|
); |
3136
|
|
|
|
3137
|
|
|
// Register the data structures used by the service |
3138
|
|
|
$server->wsdl->addComplexType( |
3139
|
|
|
'createCourseByTitle', |
3140
|
|
|
'complexType', |
3141
|
|
|
'struct', |
3142
|
|
|
'all', |
3143
|
|
|
'', |
3144
|
|
|
[ |
3145
|
|
|
'courses' => ['name' => 'courses', 'type' => 'tns:createCourseByTitleParamsList'], |
3146
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
3147
|
|
|
] |
3148
|
|
|
); |
3149
|
|
|
|
3150
|
|
|
// Prepare output params, in this case will return an array |
3151
|
|
|
$server->wsdl->addComplexType( |
3152
|
|
|
'result_createCourseByTitle', |
3153
|
|
|
'complexType', |
3154
|
|
|
'struct', |
3155
|
|
|
'all', |
3156
|
|
|
'', |
3157
|
|
|
[ |
3158
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
3159
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
3160
|
|
|
] |
3161
|
|
|
); |
3162
|
|
|
|
3163
|
|
|
$server->wsdl->addComplexType( |
3164
|
|
|
'results_createCourseByTitle', |
3165
|
|
|
'complexType', |
3166
|
|
|
'array', |
3167
|
|
|
'', |
3168
|
|
|
'SOAP-ENC:Array', |
3169
|
|
|
[], |
3170
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_createCourseByTitle[]']], |
3171
|
|
|
'tns:result_createCourseByTitle' |
3172
|
|
|
); |
3173
|
|
|
|
3174
|
|
|
// Register the method to expose |
3175
|
|
|
$server->register( |
3176
|
|
|
'WSCreateCourseByTitle', // method name |
3177
|
|
|
['createCourseByTitle' => 'tns:createCourseByTitle'], // input parameters |
3178
|
|
|
['return' => 'tns:results_createCourseByTitle'], // output parameters |
3179
|
|
|
'urn:WSRegistration', // namespace |
3180
|
|
|
'urn:WSRegistration#WSCreateCourseByTitle', // soapaction |
3181
|
|
|
'rpc', // style |
3182
|
|
|
'encoded', // use |
3183
|
|
|
'This service adds a course by title' // documentation |
3184
|
|
|
); |
3185
|
|
|
|
3186
|
|
|
// Define the method WSCreateCourseByTitle |
3187
|
|
|
function WSCreateCourseByTitle($params) |
3188
|
|
|
{ |
3189
|
|
|
global $_configuration; |
3190
|
|
|
if (!WSHelperVerifyKey($params)) { |
3191
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
3192
|
|
|
} |
3193
|
|
|
|
3194
|
|
|
$table_course = Database::get_main_table(TABLE_MAIN_COURSE); |
3195
|
|
|
$sessionAdminId = DEFAULT_ADMIN_USER_ID; |
3196
|
|
|
$courses_params = $params['courses']; |
3197
|
|
|
$results = []; |
3198
|
|
|
$orig_course_id_value = []; |
3199
|
|
|
|
3200
|
|
|
foreach ($courses_params as $course_param) { |
3201
|
|
|
$title = $course_param['title']; |
3202
|
|
|
$category_code = 'LANG'; // TODO: A hard-coded value. |
3203
|
|
|
$wanted_code = ''; |
3204
|
|
|
$tutor_firstname = api_get_setting('administratorName'); |
3205
|
|
|
$tutor_lastname = api_get_setting('administratorSurname'); |
3206
|
|
|
$course_language = 'spanish'; // TODO: Incorrect default value, it should 'english'. |
3207
|
|
|
if (!empty($course_param['course_language'])) { |
3208
|
|
|
$course_language = $course_param['course_language']; |
3209
|
|
|
} |
3210
|
|
|
$tutor_name = api_get_person_name($tutor_firstname, $tutor_lastname, null, null, $course_language); |
3211
|
|
|
if (!empty($course_param['tutor_name'])) { |
3212
|
|
|
$tutor_name = $course_param['tutor_name']; |
3213
|
|
|
} |
3214
|
|
|
$original_course_id_name = $course_param['original_course_id_name']; |
3215
|
|
|
$original_course_id_value = $course_param['original_course_id_value']; |
3216
|
|
|
$orig_course_id_value[] = $course_param['original_course_id_value']; |
3217
|
|
|
$extra_list = $course_param['extra']; |
3218
|
|
|
|
3219
|
|
|
// Ensure the database prefix + database name do not get over 40 characters |
3220
|
|
|
$maxlength = 40; |
3221
|
|
|
if (empty($wanted_code)) { |
3222
|
|
|
$wanted_code = CourseManager::generate_course_code(substr($title, 0, $maxlength)); |
3223
|
|
|
} |
3224
|
|
|
|
3225
|
|
|
$courseInfo = CourseManager::getCourseInfoFromOriginalId( |
3226
|
|
|
$original_course_id_value, |
3227
|
|
|
$original_course_id_name |
3228
|
|
|
); |
3229
|
|
|
|
3230
|
|
|
if (!empty($courseInfo)) { |
3231
|
|
|
if ($courseInfo['visibility'] != 0) { |
3232
|
|
|
$sql = "UPDATE $table_course SET |
3233
|
|
|
course_language='".Database::escape_string($course_language)."', |
3234
|
|
|
title='".Database::escape_string($title)."', |
3235
|
|
|
category_code='".Database::escape_string($category_code)."', |
3236
|
|
|
tutor_name='".Database::escape_string($tutor_name)."', |
3237
|
|
|
visual_code='".Database::escape_string($wanted_code)."', |
3238
|
|
|
visibility = '3' |
3239
|
|
|
WHERE id ='".$courseInfo['real_id']."'"; |
3240
|
|
|
Database::query($sql); |
3241
|
|
|
$results[] = $courseInfo['real_id']; |
3242
|
|
|
continue; |
3243
|
|
|
} else { |
3244
|
|
|
$results[] = 0; |
3245
|
|
|
continue; |
3246
|
|
|
} |
3247
|
|
|
} |
3248
|
|
|
|
3249
|
|
|
$values['course_language'] = api_get_setting('platformLanguage'); |
3250
|
|
|
|
3251
|
|
|
$keys = AddCourse::define_course_keys($wanted_code, '', $_configuration['db_prefix']); |
3252
|
|
|
|
3253
|
|
|
$sql_check = sprintf('SELECT * FROM '.$table_course.' WHERE visual_code = "%s"', Database::escape_string($wanted_code)); |
3254
|
|
|
$result_check = Database::query($sql_check); // I don't know why this api function doesn't work... |
3255
|
|
|
if (Database::num_rows($result_check) < 1) { |
3256
|
|
|
$params = []; |
3257
|
|
|
$params['title'] = $title; |
3258
|
|
|
$params['wanted_code'] = $wanted_code; |
3259
|
|
|
$params['category_code'] = $category_code; |
3260
|
|
|
$params['tutor_name'] = $tutor_name; |
3261
|
|
|
$params['course_language'] = $course_language; |
3262
|
|
|
$params['user_id'] = $sessionAdminId; |
3263
|
|
|
$course_info = CourseManager::create_course($params, $sessionAdminId); |
3264
|
|
|
if (!empty($course_info)) { |
3265
|
|
|
$course_code = $course_info['code']; |
3266
|
|
|
|
3267
|
|
|
// Save new fieldlabel into course_field table. |
3268
|
|
|
CourseManager::create_course_extra_field( |
3269
|
|
|
$original_course_id_name, |
3270
|
|
|
1, |
3271
|
|
|
$original_course_id_name, |
3272
|
|
|
'' |
3273
|
|
|
); |
3274
|
|
|
|
3275
|
|
|
// Save the external system's id into user_field_value table. |
3276
|
|
|
CourseManager::update_course_extra_field_value( |
3277
|
|
|
$course_code, |
3278
|
|
|
$original_course_id_name, |
3279
|
|
|
$original_course_id_value |
3280
|
|
|
); |
3281
|
|
|
|
3282
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
3283
|
|
|
foreach ($extra_list as $extra) { |
3284
|
|
|
$extra_field_name = $extra['field_name']; |
3285
|
|
|
$extra_field_value = $extra['field_value']; |
3286
|
|
|
// Save new fieldlabel into course_field table. |
3287
|
|
|
CourseManager::create_course_extra_field( |
3288
|
|
|
$extra_field_name, |
3289
|
|
|
1, |
3290
|
|
|
$extra_field_name, |
3291
|
|
|
'' |
3292
|
|
|
); |
3293
|
|
|
// Save the external system's id into course_field_value table. |
3294
|
|
|
CourseManager::update_course_extra_field_value( |
3295
|
|
|
$course_code, |
3296
|
|
|
$extra_field_name, |
3297
|
|
|
$extra_field_value |
3298
|
|
|
); |
3299
|
|
|
} |
3300
|
|
|
} |
3301
|
|
|
} |
3302
|
|
|
$results[] = $course_code; |
3303
|
|
|
continue; |
3304
|
|
|
} else { |
3305
|
|
|
$results[] = 0; |
3306
|
|
|
continue; |
3307
|
|
|
} |
3308
|
|
|
} // end principal foreach |
3309
|
|
|
|
3310
|
|
|
$count_results = count($results); |
3311
|
|
|
$output = []; |
3312
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
3313
|
|
|
$output[] = [ |
3314
|
|
|
'original_course_id_value' => $orig_course_id_value[$i], |
3315
|
|
|
'result' => $results[$i], |
3316
|
|
|
]; |
3317
|
|
|
} |
3318
|
|
|
|
3319
|
|
|
return $output; |
3320
|
|
|
} |
3321
|
|
|
|
3322
|
|
|
/* Register WSEditCourse function */ |
3323
|
|
|
// Register the data structures used by the service |
3324
|
|
|
|
3325
|
|
|
$server->wsdl->addComplexType( |
3326
|
|
|
'editCourseParams', |
3327
|
|
|
'complexType', |
3328
|
|
|
'struct', |
3329
|
|
|
'all', |
3330
|
|
|
'', |
3331
|
|
|
[ |
3332
|
|
|
'tutor_id' => ['name' => 'tutor_id', 'type' => 'xsd:string'], |
3333
|
|
|
'title' => ['name' => 'title', 'type' => 'xsd:string'], |
3334
|
|
|
'category_code' => ['name' => 'category_code', 'type' => 'xsd:string'], |
3335
|
|
|
'department_name' => ['name' => 'department_name', 'type' => 'xsd:string'], |
3336
|
|
|
'department_url' => ['name' => 'department_url', 'type' => 'xsd:string'], |
3337
|
|
|
'course_language' => ['name' => 'course_language', 'type' => 'xsd:string'], |
3338
|
|
|
'visibility' => ['name' => 'visibility', 'type' => 'xsd:string'], |
3339
|
|
|
'subscribe' => ['name' => 'subscribe', 'type' => 'xsd:string'], |
3340
|
|
|
'unsubscribe' => ['name' => 'unsubscribe', 'type' => 'xsd:string'], |
3341
|
|
|
'visual_code' => ['name' => 'visual_code', 'type' => 'xsd:string'], |
3342
|
|
|
'disk_quota' => ['name' => 'disk_quota', 'type' => 'xsd:string'], // disk_quota in MB |
3343
|
|
|
'original_course_id_name' => ['name' => 'original_course_id_name', 'type' => 'xsd:string'], |
3344
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
3345
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:extrasList'], |
3346
|
|
|
] |
3347
|
|
|
); |
3348
|
|
|
|
3349
|
|
|
$server->wsdl->addComplexType( |
3350
|
|
|
'editCourseParamsList', |
3351
|
|
|
'complexType', |
3352
|
|
|
'array', |
3353
|
|
|
'', |
3354
|
|
|
'SOAP-ENC:Array', |
3355
|
|
|
[], |
3356
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:editCourseParams[]']], |
3357
|
|
|
'tns:editCourseParams' |
3358
|
|
|
); |
3359
|
|
|
|
3360
|
|
|
$server->wsdl->addComplexType( |
3361
|
|
|
'editCourse', |
3362
|
|
|
'complexType', |
3363
|
|
|
'struct', |
3364
|
|
|
'all', |
3365
|
|
|
'', |
3366
|
|
|
[ |
3367
|
|
|
'courses' => ['name' => 'courses', 'type' => 'tns:editCourseParamsList'], |
3368
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
3369
|
|
|
] |
3370
|
|
|
); |
3371
|
|
|
|
3372
|
|
|
// Prepare output params, in this case will return an array |
3373
|
|
|
$server->wsdl->addComplexType( |
3374
|
|
|
'result_editCourse', |
3375
|
|
|
'complexType', |
3376
|
|
|
'struct', |
3377
|
|
|
'all', |
3378
|
|
|
'', |
3379
|
|
|
[ |
3380
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
3381
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
3382
|
|
|
] |
3383
|
|
|
); |
3384
|
|
|
|
3385
|
|
|
$server->wsdl->addComplexType( |
3386
|
|
|
'results_editCourse', |
3387
|
|
|
'complexType', |
3388
|
|
|
'array', |
3389
|
|
|
'', |
3390
|
|
|
'SOAP-ENC:Array', |
3391
|
|
|
[], |
3392
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_editCourse[]']], |
3393
|
|
|
'tns:result_editCourse' |
3394
|
|
|
); |
3395
|
|
|
|
3396
|
|
|
// Register the method to expose |
3397
|
|
|
$server->register( |
3398
|
|
|
'WSEditCourse', // method name |
3399
|
|
|
['editCourse' => 'tns:editCourse'], // input parameters |
3400
|
|
|
['return' => 'tns:results_editCourse'], // output parameters |
3401
|
|
|
'urn:WSRegistration', // namespace |
3402
|
|
|
'urn:WSRegistration#WSEditCourse', // soapaction |
3403
|
|
|
'rpc', // style |
3404
|
|
|
'encoded', // use |
3405
|
|
|
'This service edits a course' // documentation |
3406
|
|
|
); |
3407
|
|
|
|
3408
|
|
|
// Define the method WSEditCourse |
3409
|
|
|
function WSEditCourse($params) |
3410
|
|
|
{ |
3411
|
|
|
global $_configuration; |
3412
|
|
|
if (!WSHelperVerifyKey($params)) { |
3413
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
3414
|
|
|
} |
3415
|
|
|
|
3416
|
|
|
$course_table = Database::get_main_table(TABLE_MAIN_COURSE); |
3417
|
|
|
|
3418
|
|
|
$courses_params = $params['courses']; |
3419
|
|
|
$results = []; |
3420
|
|
|
$orig_course_id_value = []; |
3421
|
|
|
|
3422
|
|
|
foreach ($courses_params as $course_param) { |
3423
|
|
|
$tutor_id = isset($course_param['tutor_id']) ? $course_param['tutor_id'] : ''; |
3424
|
|
|
$title = $course_param['title']; |
3425
|
|
|
$category_code = isset($course_param['category_code']) ? $course_param['category_code'] : ''; |
3426
|
|
|
$department_name = isset($course_param['department_name']) ? $course_param['department_name'] : ''; |
3427
|
|
|
$department_url = isset($course_param['department_url']) ? $course_param['department_url'] : ''; |
3428
|
|
|
$course_language = $course_param['course_language']; |
3429
|
|
|
$visibility = $course_param['visibility']; |
3430
|
|
|
$subscribe = $course_param['subscribe']; |
3431
|
|
|
$unsubscribe = $course_param['unsubscribe']; |
3432
|
|
|
$visual_code = $course_param['visual_code']; |
3433
|
|
|
$diskQuota = isset($course_param['disk_quota']) ? $course_param['disk_quota'] : '100'; |
3434
|
|
|
// Convert to MB |
3435
|
|
|
$diskQuota = $diskQuota * 1024 * 1024; |
3436
|
|
|
|
3437
|
|
|
$original_course_id_name = $course_param['original_course_id_name']; |
3438
|
|
|
$original_course_id_value = $course_param['original_course_id_value']; |
3439
|
|
|
$orig_course_id_value[] = $original_course_id_value; |
3440
|
|
|
$extra_list = isset($course_param['extra']) ? $course_param['extra'] : null; |
3441
|
|
|
|
3442
|
|
|
$courseInfo = CourseManager::getCourseInfoFromOriginalId( |
3443
|
|
|
$original_course_id_value, |
3444
|
|
|
$original_course_id_name |
3445
|
|
|
); |
3446
|
|
|
|
3447
|
|
|
if (empty($courseInfo)) { |
3448
|
|
|
$results[] = 0; // Original_course_id_value doesn't exist. |
3449
|
|
|
continue; |
3450
|
|
|
} |
3451
|
|
|
|
3452
|
|
|
$course_code = $courseInfo['code']; |
3453
|
|
|
$courseId = $courseInfo['real_id']; |
3454
|
|
|
|
3455
|
|
|
$table_user = Database::get_main_table(TABLE_MAIN_USER); |
3456
|
|
|
$sql = "SELECT concat(lastname,'',firstname) as tutor_name |
3457
|
|
|
FROM $table_user WHERE status='1' AND user_id = '$tutor_id' |
3458
|
|
|
ORDER BY lastname,firstname"; |
3459
|
|
|
$res = Database::query($sql); |
3460
|
|
|
$tutor_name = Database::fetch_row($res); |
3461
|
|
|
|
3462
|
|
|
$dbnamelength = strlen($_configuration['db_prefix']); |
3463
|
|
|
$maxlength = 40 - $dbnamelength; |
3464
|
|
|
|
3465
|
|
|
if (empty($visual_code)) { |
3466
|
|
|
$visual_code = CourseManager::generate_course_code(substr($title, 0, $maxlength)); |
3467
|
|
|
} |
3468
|
|
|
$tutor_name = $tutor_name[0]; |
3469
|
|
|
$sql = "UPDATE $course_table SET |
3470
|
|
|
course_language='".Database::escape_string($course_language)."', |
3471
|
|
|
title='".Database::escape_string($title)."', |
3472
|
|
|
category_code='".Database::escape_string($category_code)."', |
3473
|
|
|
tutor_name='".Database::escape_string($tutor_name)."', |
3474
|
|
|
visual_code='".Database::escape_string($visual_code)."', |
3475
|
|
|
department_name='".Database::escape_string($department_name)."', |
3476
|
|
|
department_url='".Database::escape_string($department_url)."', |
3477
|
|
|
visibility = '".Database::escape_string($visibility)."', |
3478
|
|
|
subscribe = '".Database::escape_string($subscribe)."', |
3479
|
|
|
disk_quota='".Database::escape_string($diskQuota)."', |
3480
|
|
|
unsubscribe='".Database::escape_string($unsubscribe)."' |
3481
|
|
|
WHERE id ='".Database::escape_string($courseId)."'"; |
3482
|
|
|
$res = Database::query($sql); |
3483
|
|
|
|
3484
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
3485
|
|
|
foreach ($extra_list as $extra) { |
3486
|
|
|
$extra_field_name = $extra['field_name']; |
3487
|
|
|
$extra_field_value = $extra['field_value']; |
3488
|
|
|
// Save the external system's id into course_field_value table. |
3489
|
|
|
$res = CourseManager::update_course_extra_field_value( |
3490
|
|
|
$course_code, |
3491
|
|
|
$extra_field_name, |
3492
|
|
|
$extra_field_value |
3493
|
|
|
); |
3494
|
|
|
} |
3495
|
|
|
} |
3496
|
|
|
|
3497
|
|
|
if ($res) { |
3498
|
|
|
$results[] = 1; |
3499
|
|
|
continue; |
3500
|
|
|
} else { |
3501
|
|
|
$results[] = 0; |
3502
|
|
|
continue; |
3503
|
|
|
} |
3504
|
|
|
} // end principal foreach |
3505
|
|
|
|
3506
|
|
|
$count_results = count($results); |
3507
|
|
|
$output = []; |
3508
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
3509
|
|
|
$output[] = [ |
3510
|
|
|
'original_course_id_value' => $orig_course_id_value[$i], |
3511
|
|
|
'result' => $results[$i], |
3512
|
|
|
]; |
3513
|
|
|
} |
3514
|
|
|
|
3515
|
|
|
return $output; |
3516
|
|
|
} |
3517
|
|
|
|
3518
|
|
|
/* Register WSCourseDescription function */ |
3519
|
|
|
// Register the data structures used by the service |
3520
|
|
|
|
3521
|
|
|
$server->wsdl->addComplexType( |
3522
|
|
|
'courseDescription', |
3523
|
|
|
'complexType', |
3524
|
|
|
'struct', |
3525
|
|
|
'all', |
3526
|
|
|
'', |
3527
|
|
|
[ |
3528
|
|
|
'original_course_id_name' => ['name' => 'original_course_id_name', 'type' => 'xsd:string'], |
3529
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
3530
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
3531
|
|
|
] |
3532
|
|
|
); |
3533
|
|
|
|
3534
|
|
|
// Prepare output params, in this case will return an array |
3535
|
|
|
$server->wsdl->addComplexType( |
3536
|
|
|
'fields_course_desc', |
3537
|
|
|
'complexType', |
3538
|
|
|
'struct', |
3539
|
|
|
'all', |
3540
|
|
|
'', |
3541
|
|
|
[ |
3542
|
|
|
'course_desc_id' => ['name' => 'course_desc_id', 'type' => 'xsd:string'], |
3543
|
|
|
'course_desc_default_title' => ['name' => 'course_desc_default_title', 'type' => 'xsd:string'], |
3544
|
|
|
'course_desc_title' => ['name' => 'course_desc_title', 'type' => 'xsd:string'], |
3545
|
|
|
'course_desc_content' => ['name' => 'course_desc_content', 'type' => 'xsd:string'], |
3546
|
|
|
] |
3547
|
|
|
); |
3548
|
|
|
|
3549
|
|
|
$server->wsdl->addComplexType( |
3550
|
|
|
'fields_course_desc_list', |
3551
|
|
|
'complexType', |
3552
|
|
|
'array', |
3553
|
|
|
'', |
3554
|
|
|
'SOAP-ENC:Array', |
3555
|
|
|
[], |
3556
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:fields_course_desc[]']], |
3557
|
|
|
'tns:fields_course_desc' |
3558
|
|
|
); |
3559
|
|
|
|
3560
|
|
|
// Register the method to expose |
3561
|
|
|
$server->register( |
3562
|
|
|
'WSCourseDescription', // method name |
3563
|
|
|
['courseDescription' => 'tns:courseDescription'], // input parameters |
3564
|
|
|
['return' => 'tns:fields_course_desc_list'], // output parameters |
3565
|
|
|
'urn:WSRegistration', // namespace |
3566
|
|
|
'urn:WSRegistration#WSCourseDescription', // soapaction |
3567
|
|
|
'rpc', // style |
3568
|
|
|
'encoded', // use |
3569
|
|
|
'This service edits a course description' // documentation |
3570
|
|
|
); |
3571
|
|
|
|
3572
|
|
|
// Define the method WSCourseDescription |
3573
|
|
|
function WSCourseDescription($params) |
3574
|
|
|
{ |
3575
|
|
|
if (!WSHelperVerifyKey($params)) { |
3576
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
3577
|
|
|
} |
3578
|
|
|
|
3579
|
|
|
$array_course_desc_id = []; |
3580
|
|
|
$array_course_desc_title = []; |
3581
|
|
|
$array_course_desc_content = []; |
3582
|
|
|
|
3583
|
|
|
$original_course_id_name = $params['original_course_id_name']; |
3584
|
|
|
$original_course_id_value = $params['original_course_id_value']; |
3585
|
|
|
|
3586
|
|
|
$courseInfo = CourseManager::getCourseInfoFromOriginalId( |
3587
|
|
|
$original_course_id_value, |
3588
|
|
|
$original_course_id_name |
3589
|
|
|
); |
3590
|
|
|
|
3591
|
|
|
if (empty($courseInfo) || (isset($courseInfo) && $courseInfo['visibility'] == 0)) { |
3592
|
|
|
return 0; // Original_course_id_value doesn't exist. |
3593
|
|
|
} |
3594
|
|
|
|
3595
|
|
|
$t_course_desc = Database::get_course_table(TABLE_COURSE_DESCRIPTION); |
3596
|
|
|
$sql = "SELECT * FROM $t_course_desc WHERE c_id = {$courseInfo['real_id']} "; |
3597
|
|
|
$result = Database::query($sql); |
3598
|
|
|
|
3599
|
|
|
$default_titles = [ |
3600
|
|
|
get_lang('GeneralDescription'), |
3601
|
|
|
get_lang('Objectives'), |
3602
|
|
|
get_lang('Topics'), |
3603
|
|
|
get_lang('Methodology'), |
3604
|
|
|
get_lang('CourseMaterial'), |
3605
|
|
|
get_lang('HumanAndTechnicalResources'), |
3606
|
|
|
get_lang('Assessment'), |
3607
|
|
|
get_lang('AddCategory'), |
3608
|
|
|
]; |
3609
|
|
|
|
3610
|
|
|
for ($x = 1; $x < 9; $x++) { |
3611
|
|
|
$array_course_desc_id[$x] = $x; |
3612
|
|
|
$array_course_desc_default_title[$x] = $default_titles[$x - 1]; |
3613
|
|
|
$array_course_desc_title[$x] = ''; |
3614
|
|
|
$array_course_desc_content[$x] = ''; |
3615
|
|
|
} |
3616
|
|
|
|
3617
|
|
|
while ($row = Database::fetch_array($result)) { |
3618
|
|
|
$ind = (int) $row['id']; |
3619
|
|
|
$array_course_desc_title[$ind] = $row['title']; |
3620
|
|
|
$array_course_desc_content[$ind] = $row['content']; |
3621
|
|
|
} |
3622
|
|
|
|
3623
|
|
|
$count_results = count($default_titles); |
3624
|
|
|
$output = []; |
3625
|
|
|
for ($i = 1; $i <= $count_results; $i++) { |
3626
|
|
|
$output[] = [ |
3627
|
|
|
'course_desc_id' => $array_course_desc_id[$i], |
3628
|
|
|
'course_desc_default_title' => $array_course_desc_default_title[$i], |
3629
|
|
|
'course_desc_title' => $array_course_desc_title[$i], |
3630
|
|
|
'course_desc_content' => $array_course_desc_content[$i], |
3631
|
|
|
]; |
3632
|
|
|
} |
3633
|
|
|
|
3634
|
|
|
return $output; |
3635
|
|
|
} |
3636
|
|
|
|
3637
|
|
|
/* Register WSEditCourseDescription function */ |
3638
|
|
|
// Register the data structures used by the service |
3639
|
|
|
|
3640
|
|
|
$server->wsdl->addComplexType( |
3641
|
|
|
'editCourseDescriptionParams', |
3642
|
|
|
'complexType', |
3643
|
|
|
'struct', |
3644
|
|
|
'all', |
3645
|
|
|
'', |
3646
|
|
|
[ |
3647
|
|
|
'course_desc_id' => ['name' => 'course_desc_id', 'type' => 'xsd:string'], |
3648
|
|
|
'course_desc_title' => ['name' => 'course_desc_title', 'type' => 'xsd:string'], |
3649
|
|
|
'course_desc_content' => ['name' => 'course_desc_content', 'type' => 'xsd:string'], |
3650
|
|
|
'original_course_id_name' => ['name' => 'original_course_id_name', 'type' => 'xsd:string'], |
3651
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
3652
|
|
|
] |
3653
|
|
|
); |
3654
|
|
|
|
3655
|
|
|
$server->wsdl->addComplexType( |
3656
|
|
|
'editCourseDescriptionParamsList', |
3657
|
|
|
'complexType', |
3658
|
|
|
'array', |
3659
|
|
|
'', |
3660
|
|
|
'SOAP-ENC:Array', |
3661
|
|
|
[], |
3662
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:editCourseDescriptionParams[]']], |
3663
|
|
|
'tns:editCourseDescriptionParams' |
3664
|
|
|
); |
3665
|
|
|
|
3666
|
|
|
$server->wsdl->addComplexType( |
3667
|
|
|
'editCourseDescription', |
3668
|
|
|
'complexType', |
3669
|
|
|
'struct', |
3670
|
|
|
'all', |
3671
|
|
|
'', |
3672
|
|
|
[ |
3673
|
|
|
'course_desc' => ['name' => 'course_desc', 'type' => 'tns:editCourseDescriptionParamsList'], |
3674
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
3675
|
|
|
] |
3676
|
|
|
); |
3677
|
|
|
|
3678
|
|
|
// Prepare output params, in this case will return an array |
3679
|
|
|
$server->wsdl->addComplexType( |
3680
|
|
|
'result_editCourseDescription', |
3681
|
|
|
'complexType', |
3682
|
|
|
'struct', |
3683
|
|
|
'all', |
3684
|
|
|
'', |
3685
|
|
|
[ |
3686
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
3687
|
|
|
'course_desc_id' => ['name' => 'course_desc_id', 'type' => 'xsd:string'], |
3688
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
3689
|
|
|
] |
3690
|
|
|
); |
3691
|
|
|
|
3692
|
|
|
$server->wsdl->addComplexType( |
3693
|
|
|
'results_editCourseDescription', |
3694
|
|
|
'complexType', |
3695
|
|
|
'array', |
3696
|
|
|
'', |
3697
|
|
|
'SOAP-ENC:Array', |
3698
|
|
|
[], |
3699
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_editCourseDescription[]']], |
3700
|
|
|
'tns:result_editCourseDescription' |
3701
|
|
|
); |
3702
|
|
|
|
3703
|
|
|
// Register the method to expose |
3704
|
|
|
$server->register( |
3705
|
|
|
'WSEditCourseDescription', // method name |
3706
|
|
|
['editCourseDescription' => 'tns:editCourseDescription'], // input parameters |
3707
|
|
|
['return' => 'tns:results_editCourseDescription'], // output parameters |
3708
|
|
|
'urn:WSRegistration', // namespace |
3709
|
|
|
'urn:WSRegistration#WSEditCourseDescription', // soapaction |
3710
|
|
|
'rpc', // style |
3711
|
|
|
'encoded', // use |
3712
|
|
|
'This service edits a course description' // documentation |
3713
|
|
|
); |
3714
|
|
|
|
3715
|
|
|
// Define the method WSEditCourseDescription |
3716
|
|
|
function WSEditCourseDescription($params) |
3717
|
|
|
{ |
3718
|
|
|
if (!WSHelperVerifyKey($params)) { |
3719
|
|
|
return -1; |
3720
|
|
|
} |
3721
|
|
|
|
3722
|
|
|
$courses_params = $params['course_desc']; |
3723
|
|
|
$results = []; |
3724
|
|
|
$orig_course_id_value = []; |
3725
|
|
|
$course_description_id = []; |
3726
|
|
|
|
3727
|
|
|
$courseDescription = new CourseDescription(); |
3728
|
|
|
$defaultDescTitle = $courseDescription->get_default_description_title(); |
3729
|
|
|
|
3730
|
|
|
foreach ($courses_params as $course_param) { |
3731
|
|
|
$original_course_id_name = $course_param['original_course_id_name']; |
3732
|
|
|
$original_course_id_value = $course_param['original_course_id_value']; |
3733
|
|
|
$course_desc_id = $course_param['course_desc_id']; |
3734
|
|
|
$course_desc_title = $course_param['course_desc_title']; |
3735
|
|
|
$course_desc_content = $course_param['course_desc_content']; |
3736
|
|
|
$orig_course_id_value[] = $original_course_id_value; |
3737
|
|
|
$course_description_id[] = $course_desc_id; |
3738
|
|
|
|
3739
|
|
|
$courseInfo = CourseManager::getCourseInfoFromOriginalId( |
3740
|
|
|
$original_course_id_value, |
3741
|
|
|
$original_course_id_name |
3742
|
|
|
); |
3743
|
|
|
|
3744
|
|
|
if (empty($courseInfo) || (isset($courseInfo) && $courseInfo['visibility'] == 0)) { |
3745
|
|
|
$results[] = 0; |
3746
|
|
|
continue; // Original_course_id_value doesn't exist. |
3747
|
|
|
} |
3748
|
|
|
|
3749
|
|
|
$course_desc_id = Database::escape_string($course_desc_id); |
3750
|
|
|
$course_desc_title = Database::escape_string($course_desc_title); |
3751
|
|
|
$course_desc_content = Database::escape_string($course_desc_content); |
3752
|
|
|
|
3753
|
|
|
$course_desc_id = (int) $course_desc_id; |
3754
|
|
|
if ($course_desc_id > 8 && $course_desc_id < 1) { |
3755
|
|
|
$results[] = 0; // course_desc_id invalid. |
3756
|
|
|
continue; |
3757
|
|
|
} |
3758
|
|
|
|
3759
|
|
|
// if title is empty set default title instead |
3760
|
|
|
if (empty($course_desc_title)) { |
3761
|
|
|
$course_desc_title = $defaultDescTitle[$course_desc_id]; |
3762
|
|
|
} |
3763
|
|
|
|
3764
|
|
|
$courseId = $courseInfo['real_id']; |
3765
|
|
|
$courseDescription->set_id(null); |
3766
|
|
|
$courseDescription->set_course_id($courseId); |
3767
|
|
|
$courseDescription->set_session_id(0); |
3768
|
|
|
$courseDescription->set_title($course_desc_title); |
3769
|
|
|
$courseDescription->set_content($course_desc_content); |
3770
|
|
|
$courseDescription->set_description_type($course_desc_id); |
3771
|
|
|
|
3772
|
|
|
$data = $courseDescription->get_data_by_description_type($course_desc_id, $courseId); |
3773
|
|
|
if ($data) { |
3774
|
|
|
// Update existing description |
3775
|
|
|
$courseDescription->set_id($data['id']); |
3776
|
|
|
$result = $courseDescription->update(); |
3777
|
|
|
} else { |
3778
|
|
|
// Insert new description |
3779
|
|
|
$result = $courseDescription->insert(); |
3780
|
|
|
} |
3781
|
|
|
|
3782
|
|
|
$results[] = $result ? 1 : 0; |
3783
|
|
|
} // end principal foreach |
3784
|
|
|
|
3785
|
|
|
$count_results = count($results); |
3786
|
|
|
$output = []; |
3787
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
3788
|
|
|
$output[] = [ |
3789
|
|
|
'original_course_id_value' => $orig_course_id_value[$i], |
3790
|
|
|
'course_desc_id' => $course_description_id[$i], |
3791
|
|
|
'result' => $results[$i], |
3792
|
|
|
]; |
3793
|
|
|
} |
3794
|
|
|
|
3795
|
|
|
return $output; |
3796
|
|
|
} |
3797
|
|
|
|
3798
|
|
|
/* Register WSDeleteCourse function */ |
3799
|
|
|
// Register the data structures used by the service |
3800
|
|
|
$server->wsdl->addComplexType( |
3801
|
|
|
'deleteCourseParams', |
3802
|
|
|
'complexType', |
3803
|
|
|
'struct', |
3804
|
|
|
'all', |
3805
|
|
|
'', |
3806
|
|
|
[ |
3807
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
3808
|
|
|
'original_course_id_name' => ['name' => 'original_course_id_name', 'type' => 'xsd:string'], |
3809
|
|
|
] |
3810
|
|
|
); |
3811
|
|
|
|
3812
|
|
|
$server->wsdl->addComplexType( |
3813
|
|
|
'deleteCourseParamsList', |
3814
|
|
|
'complexType', |
3815
|
|
|
'array', |
3816
|
|
|
'', |
3817
|
|
|
'SOAP-ENC:Array', |
3818
|
|
|
[], |
3819
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:deleteCourseParams[]']], |
3820
|
|
|
'tns:deleteCourseParams' |
3821
|
|
|
); |
3822
|
|
|
|
3823
|
|
|
// Register the data structures used by the service. |
3824
|
|
|
$server->wsdl->addComplexType( |
3825
|
|
|
'deleteCourse', |
3826
|
|
|
'complexType', |
3827
|
|
|
'struct', |
3828
|
|
|
'all', |
3829
|
|
|
'', |
3830
|
|
|
[ |
3831
|
|
|
'courses' => ['name' => 'courses', 'type' => 'tns:deleteCourseParamsList'], |
3832
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
3833
|
|
|
] |
3834
|
|
|
); |
3835
|
|
|
|
3836
|
|
|
// Prepare output params, in this case will return an array. |
3837
|
|
|
$server->wsdl->addComplexType( |
3838
|
|
|
'result_deleteCourse', |
3839
|
|
|
'complexType', |
3840
|
|
|
'struct', |
3841
|
|
|
'all', |
3842
|
|
|
'', |
3843
|
|
|
[ |
3844
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
3845
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
3846
|
|
|
] |
3847
|
|
|
); |
3848
|
|
|
|
3849
|
|
|
$server->wsdl->addComplexType( |
3850
|
|
|
'results_deleteCourse', |
3851
|
|
|
'complexType', |
3852
|
|
|
'array', |
3853
|
|
|
'', |
3854
|
|
|
'SOAP-ENC:Array', |
3855
|
|
|
[], |
3856
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_deleteCourse[]']], |
3857
|
|
|
'tns:result_deleteCourse' |
3858
|
|
|
); |
3859
|
|
|
|
3860
|
|
|
$server->register( |
3861
|
|
|
'WSDeleteCourse', // method name |
3862
|
|
|
['deleteCourse' => 'tns:deleteCourse'], // input parameters |
3863
|
|
|
['return' => 'tns:results_deleteCourse'], // output parameters |
3864
|
|
|
'urn:WSRegistration', // namespace |
3865
|
|
|
'urn:WSRegistration#WSDeleteCourse', // soapaction |
3866
|
|
|
'rpc', // style |
3867
|
|
|
'encoded', // use |
3868
|
|
|
'This service deletes a course ' // documentation |
3869
|
|
|
); |
3870
|
|
|
|
3871
|
|
|
// Define the method WSDeleteCourse |
3872
|
|
|
function WSDeleteCourse($params) |
3873
|
|
|
{ |
3874
|
|
|
if (!WSHelperVerifyKey($params)) { |
3875
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
3876
|
|
|
} |
3877
|
|
|
|
3878
|
|
|
$table_course = Database::get_main_table(TABLE_MAIN_COURSE); |
3879
|
|
|
$courses_params = $params['courses']; |
3880
|
|
|
$results = []; |
3881
|
|
|
$orig_course_id_value = []; |
3882
|
|
|
foreach ($courses_params as $course_param) { |
3883
|
|
|
$original_course_id_value = $course_param['original_course_id_value']; |
3884
|
|
|
$original_course_id_name = $course_param['original_course_id_name']; |
3885
|
|
|
$orig_course_id_value[] = $original_course_id_value; |
3886
|
|
|
|
3887
|
|
|
$courseInfo = CourseManager::getCourseInfoFromOriginalId( |
3888
|
|
|
$original_course_id_value, |
3889
|
|
|
$original_course_id_name |
3890
|
|
|
); |
3891
|
|
|
|
3892
|
|
|
if (empty($courseInfo) || (isset($courseInfo) && $courseInfo['visibility'] == 0)) { |
3893
|
|
|
$results[] = 0; |
3894
|
|
|
continue; // Original_course_id_value doesn't exist. |
3895
|
|
|
} |
3896
|
|
|
|
3897
|
|
|
$courseId = $courseInfo['real_id']; |
3898
|
|
|
$sql = "UPDATE $table_course SET visibility = '0' WHERE id = '$courseId'"; |
3899
|
|
|
$return = Database::query($sql); |
3900
|
|
|
$results[] = $return; |
3901
|
|
|
} |
3902
|
|
|
|
3903
|
|
|
$count_results = count($results); |
3904
|
|
|
$output = []; |
3905
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
3906
|
|
|
$output[] = [ |
3907
|
|
|
'original_course_id_value' => $orig_course_id_value[$i], |
3908
|
|
|
'result' => $results[$i], |
3909
|
|
|
]; |
3910
|
|
|
} |
3911
|
|
|
|
3912
|
|
|
return $output; |
3913
|
|
|
} |
3914
|
|
|
|
3915
|
|
|
/* Register WSCreateSession function */ |
3916
|
|
|
// Register data structures used by the service. |
3917
|
|
|
$server->wsdl->addComplexType( |
3918
|
|
|
'createSessionParam', |
3919
|
|
|
'complexType', |
3920
|
|
|
'struct', |
3921
|
|
|
'all', |
3922
|
|
|
'', |
3923
|
|
|
[ |
3924
|
|
|
'name' => ['name' => 'name', 'type' => 'xsd:string'], |
3925
|
|
|
'year_start' => ['name' => 'year_start', 'type' => 'xsd:string'], |
3926
|
|
|
'month_start' => ['name' => 'month_start', 'type' => 'xsd:string'], |
3927
|
|
|
'day_start' => ['name' => 'day_start', 'type' => 'xsd:string'], |
3928
|
|
|
'year_end' => ['name' => 'year_end', 'type' => 'xsd:string'], |
3929
|
|
|
'month_end' => ['name' => 'month_end', 'type' => 'xsd:string'], |
3930
|
|
|
'day_end' => ['name' => 'day_end', 'type' => 'xsd:string'], |
3931
|
|
|
'nb_days_access_before' => ['name' => 'nb_days_access_before', 'type' => 'xsd:string'], |
3932
|
|
|
'nb_days_access_after' => ['name' => 'nb_days_access_after', 'type' => 'xsd:string'], |
3933
|
|
|
'nolimit' => ['name' => 'nolimit', 'type' => 'xsd:string'], |
3934
|
|
|
'user_id' => ['name' => 'user_id', 'type' => 'xsd:string'], |
3935
|
|
|
'duration' => ['name' => 'duration', 'type' => 'xsd:string'], |
3936
|
|
|
'original_session_id_name' => ['name' => 'original_session_id_name', 'type' => 'xsd:string'], |
3937
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
3938
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:extrasList'], |
3939
|
|
|
] |
3940
|
|
|
); |
3941
|
|
|
|
3942
|
|
|
$server->wsdl->addComplexType( |
3943
|
|
|
'createSessionParamList', |
3944
|
|
|
'complexType', |
3945
|
|
|
'array', |
3946
|
|
|
'', |
3947
|
|
|
'SOAP-ENC:Array', |
3948
|
|
|
[], |
3949
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:createSessionParam[]']], |
3950
|
|
|
'tns:createSessionParamList' |
3951
|
|
|
); |
3952
|
|
|
|
3953
|
|
|
// Register the data structures used by the service |
3954
|
|
|
$server->wsdl->addComplexType( |
3955
|
|
|
'createSession', |
3956
|
|
|
'complexType', |
3957
|
|
|
'struct', |
3958
|
|
|
'all', |
3959
|
|
|
'', |
3960
|
|
|
[ |
3961
|
|
|
'sessions' => ['name' => 'sessions', 'type' => 'tns:createSessionParamList'], |
3962
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
3963
|
|
|
] |
3964
|
|
|
); |
3965
|
|
|
|
3966
|
|
|
// Prepare output params, in this case will return an array |
3967
|
|
|
$server->wsdl->addComplexType( |
3968
|
|
|
'result_createSession', |
3969
|
|
|
'complexType', |
3970
|
|
|
'struct', |
3971
|
|
|
'all', |
3972
|
|
|
'', |
3973
|
|
|
[ |
3974
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
3975
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
3976
|
|
|
] |
3977
|
|
|
); |
3978
|
|
|
|
3979
|
|
|
$server->wsdl->addComplexType( |
3980
|
|
|
'results_createSession', |
3981
|
|
|
'complexType', |
3982
|
|
|
'array', |
3983
|
|
|
'', |
3984
|
|
|
'SOAP-ENC:Array', |
3985
|
|
|
[], |
3986
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_createSession[]']], |
3987
|
|
|
'tns:result_createSession' |
3988
|
|
|
); |
3989
|
|
|
|
3990
|
|
|
// Register the method to expose |
3991
|
|
|
$server->register( |
3992
|
|
|
'WSCreateSession', // method name |
3993
|
|
|
['createSession' => 'tns:createSession'], // input parameters |
3994
|
|
|
['return' => 'tns:results_createSession'], // output parameters |
3995
|
|
|
'urn:WSRegistration', // namespace |
3996
|
|
|
'urn:WSRegistration#WSCreateSession', // soapaction |
3997
|
|
|
'rpc', // style |
3998
|
|
|
'encoded', // use |
3999
|
|
|
'This service edits a session' // documentation |
4000
|
|
|
); |
4001
|
|
|
|
4002
|
|
|
// define the method WSCreateSession |
4003
|
|
|
function WSCreateSession($params) |
4004
|
|
|
{ |
4005
|
|
|
global $debug; |
4006
|
|
|
$sessionAdminId = DEFAULT_ADMIN_USER_ID; |
4007
|
|
|
|
4008
|
|
|
if (!WSHelperVerifyKey($params)) { |
4009
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
4010
|
|
|
} |
4011
|
|
|
|
4012
|
|
|
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); |
4013
|
|
|
error_log(print_r($params, 1)); |
4014
|
|
|
|
4015
|
|
|
$sessions_params = $params['sessions']; |
4016
|
|
|
$results = []; |
4017
|
|
|
$orig_session_id_value = []; |
4018
|
|
|
|
4019
|
|
|
foreach ($sessions_params as $session_param) { |
4020
|
|
|
$name = trim($session_param['name']); |
4021
|
|
|
$year_start = intval($session_param['year_start']); |
4022
|
|
|
$month_start = intval($session_param['month_start']); |
4023
|
|
|
$day_start = intval($session_param['day_start']); |
4024
|
|
|
$year_end = intval($session_param['year_end']); |
4025
|
|
|
$month_end = intval($session_param['month_end']); |
4026
|
|
|
$day_end = intval($session_param['day_end']); |
4027
|
|
|
$nb_days_access_before = intval($session_param['nb_days_access_before']); |
4028
|
|
|
$nb_days_access_after = intval($session_param['nb_days_access_after']); |
4029
|
|
|
$id_coach = $session_param['user_id']; |
4030
|
|
|
$nolimit = $session_param['nolimit']; |
4031
|
|
|
$duration = $session_param['duration']; |
4032
|
|
|
$original_session_id_name = $session_param['original_session_id_name']; |
4033
|
|
|
$original_session_id_value = $session_param['original_session_id_value']; |
4034
|
|
|
$orig_session_id_value[] = $session_param['original_session_id_value']; |
4035
|
|
|
$extra_list = isset($session_param['extra']) ? $session_param['extra'] : ''; |
4036
|
|
|
|
4037
|
|
|
$sessionId = SessionManager::getSessionIdFromOriginalId( |
4038
|
|
|
$original_session_id_value, |
4039
|
|
|
$original_session_id_name |
4040
|
|
|
); |
4041
|
|
|
|
4042
|
|
|
if (!empty($sessionId)) { |
4043
|
|
|
if ($debug) { |
4044
|
|
|
error_log("session with external session id '$original_session_id_value' with '$name' exists"); |
4045
|
|
|
} |
4046
|
|
|
$results[] = 0; |
4047
|
|
|
continue; |
4048
|
|
|
} |
4049
|
|
|
|
4050
|
|
|
if (empty($nolimit)) { |
4051
|
|
|
$date_start = "$year_start-".(($month_start < 10) ? "0$month_start" : $month_start)."-".(($day_start < 10) ? "0$day_start" : $day_start).' 00:00:00'; |
4052
|
|
|
$date_end = "$year_end-".(($month_end < 10) ? "0$month_end" : $month_end)."-".(($day_end < 10) ? "0$day_end" : $day_end).' 23:59:59'; |
4053
|
|
|
} else { |
4054
|
|
|
$date_start = ""; |
4055
|
|
|
$date_end = ""; |
4056
|
|
|
} |
4057
|
|
|
|
4058
|
|
|
if (empty($name)) { |
4059
|
|
|
if ($debug) { |
4060
|
|
|
error_log("session has no name"); |
4061
|
|
|
} |
4062
|
|
|
$results[] = 0; |
4063
|
|
|
continue; |
4064
|
|
|
} elseif (empty($id_coach)) { |
4065
|
|
|
$results[] = 0; |
4066
|
|
|
if ($debug) { |
4067
|
|
|
error_log("Coach id must not be empty"); |
4068
|
|
|
} |
4069
|
|
|
continue; |
4070
|
|
|
} elseif (empty($nolimit) && (!$month_start || !$day_start || !$year_start || !checkdate($month_start, $day_start, $year_start))) { |
4071
|
|
|
if ($debug) { |
4072
|
|
|
error_log("There's an error with the start date: $month_start - $day_start - $year_start"); |
4073
|
|
|
} |
4074
|
|
|
$results[] = 0; |
4075
|
|
|
continue; |
4076
|
|
|
} elseif (empty($nolimit) && (!$month_end || !$day_end || !$year_end || !checkdate($month_end, $day_end, $year_end))) { |
4077
|
|
|
$results[] = 0; |
4078
|
|
|
if ($debug) { |
4079
|
|
|
error_log("There's an error with the end date: $month_end - $day_end - $year_end"); |
4080
|
|
|
} |
4081
|
|
|
continue; |
4082
|
|
|
} elseif (empty($nolimit) && $date_start >= $date_end) { |
4083
|
|
|
$results[] = 0; |
4084
|
|
|
if ($debug) { |
4085
|
|
|
error_log("There's an error with the start and end date"); |
4086
|
|
|
} |
4087
|
|
|
continue; |
4088
|
|
|
} else { |
4089
|
|
|
$rs = Database::query("SELECT 1 FROM $tbl_session WHERE name='".addslashes($name)."'"); |
4090
|
|
|
if (Database::num_rows($rs)) { |
4091
|
|
|
if ($debug) { |
4092
|
|
|
error_log("Session with name '$name' already exists"); |
4093
|
|
|
} |
4094
|
|
|
$results[] = 0; |
4095
|
|
|
continue; |
4096
|
|
|
} else { |
4097
|
|
|
$coachStartDate = ''; |
4098
|
|
|
if ($date_start) { |
4099
|
|
|
$startDate = new DateTime($date_start); |
4100
|
|
|
$diffStart = new DateInterval("P".$nb_days_access_before."D"); |
4101
|
|
|
$coachStartDate = $startDate->sub($diffStart); |
4102
|
|
|
$coachStartDate = $coachStartDate->format('Y-m-d H:i:s'); |
4103
|
|
|
} |
4104
|
|
|
$coachEndDate = ''; |
4105
|
|
|
if ($date_end) { |
4106
|
|
|
$endDate = new DateTime($date_end); |
4107
|
|
|
$diffEnd = new DateInterval("P".$nb_days_access_after."D"); |
4108
|
|
|
$coachEndDate = $endDate->add($diffEnd); |
4109
|
|
|
$coachEndDate = $coachEndDate->format('Y-m-d H:i:s'); |
4110
|
|
|
} |
4111
|
|
|
$id_session = SessionManager::create_session( |
4112
|
|
|
$name, |
4113
|
|
|
$date_start, |
4114
|
|
|
$date_end, |
4115
|
|
|
$date_start, |
4116
|
|
|
$date_end, |
4117
|
|
|
$coachStartDate, |
4118
|
|
|
$coachEndDate, |
4119
|
|
|
$id_coach, |
4120
|
|
|
0, |
4121
|
|
|
1, |
4122
|
|
|
false, |
4123
|
|
|
$duration, |
4124
|
|
|
null, |
4125
|
|
|
0, |
4126
|
|
|
[], |
4127
|
|
|
$sessionAdminId |
4128
|
|
|
); |
4129
|
|
|
|
4130
|
|
|
if ($id_session) { |
4131
|
|
|
if ($debug) { |
4132
|
|
|
error_log("Session created '$id_session' "); |
4133
|
|
|
} |
4134
|
|
|
// Save new field label into course_field table. |
4135
|
|
|
SessionManager::create_session_extra_field( |
4136
|
|
|
$original_session_id_name, |
4137
|
|
|
1, |
4138
|
|
|
$original_session_id_name |
4139
|
|
|
); |
4140
|
|
|
|
4141
|
|
|
// Save the external system's id into user_field_value table. |
4142
|
|
|
SessionManager::update_session_extra_field_value( |
4143
|
|
|
$id_session, |
4144
|
|
|
$original_session_id_name, |
4145
|
|
|
$original_session_id_value |
4146
|
|
|
); |
4147
|
|
|
|
4148
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
4149
|
|
|
foreach ($extra_list as $extra) { |
4150
|
|
|
$extra_field_name = $extra['field_name']; |
4151
|
|
|
$extra_field_value = $extra['field_value']; |
4152
|
|
|
// Save new fieldlabel into course_field table. |
4153
|
|
|
SessionManager::create_session_extra_field( |
4154
|
|
|
$extra_field_name, |
4155
|
|
|
1, |
4156
|
|
|
$extra_field_name |
4157
|
|
|
); |
4158
|
|
|
// Save the external system's id into course_field_value table. |
4159
|
|
|
SessionManager::update_session_extra_field_value( |
4160
|
|
|
$id_session, |
4161
|
|
|
$extra_field_name, |
4162
|
|
|
$extra_field_value |
4163
|
|
|
); |
4164
|
|
|
} |
4165
|
|
|
} |
4166
|
|
|
$results[] = $id_session; |
4167
|
|
|
} else { |
4168
|
|
|
if ($debug) { |
4169
|
|
|
error_log("There was an error when trying to save session with name $name"); |
4170
|
|
|
} |
4171
|
|
|
} |
4172
|
|
|
} |
4173
|
|
|
} |
4174
|
|
|
} // end principal foreach |
4175
|
|
|
|
4176
|
|
|
$count_results = count($results); |
4177
|
|
|
$output = []; |
4178
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
4179
|
|
|
$output[] = [ |
4180
|
|
|
'original_session_id_value' => $orig_session_id_value[$i], |
4181
|
|
|
'result' => $results[$i], |
4182
|
|
|
]; |
4183
|
|
|
} |
4184
|
|
|
|
4185
|
|
|
return $output; |
4186
|
|
|
} |
4187
|
|
|
|
4188
|
|
|
/* Register WSEditSession function */ |
4189
|
|
|
// Register the data structures used by the service |
4190
|
|
|
$server->wsdl->addComplexType( |
4191
|
|
|
'editSessionParams', |
4192
|
|
|
'complexType', |
4193
|
|
|
'struct', |
4194
|
|
|
'all', |
4195
|
|
|
'', |
4196
|
|
|
[ |
4197
|
|
|
'name' => ['name' => 'name', 'type' => 'xsd:string'], |
4198
|
|
|
'year_start' => ['name' => 'year_start', 'type' => 'xsd:string'], |
4199
|
|
|
'month_start' => ['name' => 'month_start', 'type' => 'xsd:string'], |
4200
|
|
|
'day_start' => ['name' => 'day_start', 'type' => 'xsd:string'], |
4201
|
|
|
'year_end' => ['name' => 'year_end', 'type' => 'xsd:string'], |
4202
|
|
|
'month_end' => ['name' => 'month_end', 'type' => 'xsd:string'], |
4203
|
|
|
'day_end' => ['name' => 'day_end', 'type' => 'xsd:string'], |
4204
|
|
|
'nb_days_access_before' => ['name' => 'nb_days_access_before', 'type' => 'xsd:string'], |
4205
|
|
|
'nb_days_access_after' => ['name' => 'nb_days_access_after', 'type' => 'xsd:string'], |
4206
|
|
|
'nolimit' => ['name' => 'nolimit', 'type' => 'xsd:string'], |
4207
|
|
|
'user_id' => ['name' => 'user_id', 'type' => 'xsd:string'], |
4208
|
|
|
'duration' => ['name' => 'duration', 'type' => 'xsd:string'], |
4209
|
|
|
'original_session_id_name' => ['name' => 'original_session_id_name', 'type' => 'xsd:string'], |
4210
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
4211
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:extrasList'], |
4212
|
|
|
] |
4213
|
|
|
); |
4214
|
|
|
|
4215
|
|
|
$server->wsdl->addComplexType( |
4216
|
|
|
'editSessionParamsList', |
4217
|
|
|
'complexType', |
4218
|
|
|
'array', |
4219
|
|
|
'', |
4220
|
|
|
'SOAP-ENC:Array', |
4221
|
|
|
[], |
4222
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:editSessionParams[]']], |
4223
|
|
|
'tns:editSessionParams' |
4224
|
|
|
); |
4225
|
|
|
|
4226
|
|
|
$server->wsdl->addComplexType( |
4227
|
|
|
'editSession', |
4228
|
|
|
'complexType', |
4229
|
|
|
'struct', |
4230
|
|
|
'all', |
4231
|
|
|
'', |
4232
|
|
|
[ |
4233
|
|
|
'sessions' => ['name' => 'sessions', 'type' => 'tns:editSessionParamsList'], |
4234
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
4235
|
|
|
] |
4236
|
|
|
); |
4237
|
|
|
|
4238
|
|
|
// Prepare output params, in this case will return an array |
4239
|
|
|
$server->wsdl->addComplexType( |
4240
|
|
|
'result_editSession', |
4241
|
|
|
'complexType', |
4242
|
|
|
'struct', |
4243
|
|
|
'all', |
4244
|
|
|
'', |
4245
|
|
|
[ |
4246
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
4247
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
4248
|
|
|
] |
4249
|
|
|
); |
4250
|
|
|
|
4251
|
|
|
$server->wsdl->addComplexType( |
4252
|
|
|
'results_editSession', |
4253
|
|
|
'complexType', |
4254
|
|
|
'array', |
4255
|
|
|
'', |
4256
|
|
|
'SOAP-ENC:Array', |
4257
|
|
|
[], |
4258
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_editSession[]']], |
4259
|
|
|
'tns:result_editSession' |
4260
|
|
|
); |
4261
|
|
|
|
4262
|
|
|
// Register the method to expose |
4263
|
|
|
$server->register( |
4264
|
|
|
'WSEditSession', // method name |
4265
|
|
|
['editSession' => 'tns:editSession'], // input parameters |
4266
|
|
|
['return' => 'tns:results_editSession'], // output parameters |
4267
|
|
|
'urn:WSRegistration', // namespace |
4268
|
|
|
'urn:WSRegistration#WSEditSession', // soapaction |
4269
|
|
|
'rpc', // style |
4270
|
|
|
'encoded', // use |
4271
|
|
|
'This service edits a session' // documentation |
4272
|
|
|
); |
4273
|
|
|
|
4274
|
|
|
// define the method WSEditSession |
4275
|
|
|
function WSEditSession($params) |
4276
|
|
|
{ |
4277
|
|
|
if (!WSHelperVerifyKey($params)) { |
4278
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
4279
|
|
|
} |
4280
|
|
|
|
4281
|
|
|
$sessions_params = $params['sessions']; |
4282
|
|
|
$results = []; |
4283
|
|
|
$orig_session_id_value = []; |
4284
|
|
|
foreach ($sessions_params as $session_param) { |
4285
|
|
|
$name = trim($session_param['name']); |
4286
|
|
|
$year_start = intval($session_param['year_start']); |
4287
|
|
|
$month_start = intval($session_param['month_start']); |
4288
|
|
|
$day_start = intval($session_param['day_start']); |
4289
|
|
|
$year_end = intval($session_param['year_end']); |
4290
|
|
|
$month_end = intval($session_param['month_end']); |
4291
|
|
|
$day_end = intval($session_param['day_end']); |
4292
|
|
|
$nb_days_access_before = intval($session_param['nb_days_access_before']); |
4293
|
|
|
$nb_days_access_after = intval($session_param['nb_days_access_after']); |
4294
|
|
|
$original_session_id_value = $session_param['original_session_id_value']; |
4295
|
|
|
$original_session_id_name = $session_param['original_session_id_name']; |
4296
|
|
|
$orig_session_id_value[] = $original_session_id_value; |
4297
|
|
|
$coach_username = $session_param['coach_username']; |
4298
|
|
|
$nolimit = $session_param['nolimit']; |
4299
|
|
|
$id_coach = $session_param['user_id']; |
4300
|
|
|
$duration = intval($session_param['duration']); |
4301
|
|
|
$extra_list = $session_param['extra']; |
4302
|
|
|
|
4303
|
|
|
$id = SessionManager::getSessionIdFromOriginalId( |
4304
|
|
|
$original_session_id_value, |
4305
|
|
|
$original_session_id_name |
4306
|
|
|
); |
4307
|
|
|
|
4308
|
|
|
if (empty($id)) { |
4309
|
|
|
$results[] = 0; |
4310
|
|
|
continue; |
4311
|
|
|
} |
4312
|
|
|
|
4313
|
|
|
if (empty($nolimit)) { |
4314
|
|
|
$date_start = "$year_start-".(($month_start < 10) ? "0$month_start" : $month_start)."-".(($day_start < 10) ? "0$day_start" : $day_start).' 00:00:00'; |
4315
|
|
|
$date_end = "$year_end-".(($month_end < 10) ? "0$month_end" : $month_end)."-".(($day_end < 10) ? "0$day_end" : $day_end).' 23:59:59'; |
4316
|
|
|
} else { |
4317
|
|
|
$date_start = ''; |
4318
|
|
|
$date_end = ''; |
4319
|
|
|
} |
4320
|
|
|
if (empty($name)) { |
4321
|
|
|
$results[] = 0; //SessionNameIsRequired |
4322
|
|
|
continue; |
4323
|
|
|
} elseif (empty($id_coach)) { // Session must have coach |
4324
|
|
|
$results[] = 0; |
4325
|
|
|
continue; |
4326
|
|
|
} elseif (empty($nolimit) && (!$month_start || !$day_start || !$year_start || !checkdate($month_start, $day_start, $year_start))) { |
4327
|
|
|
$results[] = 0; //InvalidStartDate |
4328
|
|
|
continue; |
4329
|
|
|
} elseif (empty($nolimit) && (!$month_end || !$day_end || !$year_end || !checkdate($month_end, $day_end, $year_end))) { |
4330
|
|
|
$results[] = 0; //InvalidEndDate |
4331
|
|
|
continue; |
4332
|
|
|
} elseif (empty($nolimit) && $date_start >= $date_end) { |
4333
|
|
|
$results[] = 0; //StartDateShouldBeBeforeEndDate |
4334
|
|
|
continue; |
4335
|
|
|
} else { |
4336
|
|
|
$coachStartDate = ''; |
4337
|
|
|
if ($date_start) { |
4338
|
|
|
$startDate = new DateTime($date_start); |
4339
|
|
|
$diffStart = new DateInterval("P".$nb_days_access_before."D"); |
4340
|
|
|
$coachStartDate = $startDate->sub($diffStart); |
4341
|
|
|
$coachStartDate = $coachStartDate->format('Y-m-d H:i:s'); |
4342
|
|
|
} |
4343
|
|
|
$coachEndDate = ''; |
4344
|
|
|
if ($date_end) { |
4345
|
|
|
$endDate = new DateTime($date_end); |
4346
|
|
|
$diffEnd = new DateInterval("P".$nb_days_access_after."D"); |
4347
|
|
|
$coachEndDate = $endDate->add($diffEnd); |
4348
|
|
|
$coachEndDate = $coachEndDate->format('Y-m-d H:i:s'); |
4349
|
|
|
} |
4350
|
|
|
$sessionInfo = api_get_session_info($id); |
4351
|
|
|
|
4352
|
|
|
$editResult = SessionManager::edit_session( |
4353
|
|
|
$id, |
4354
|
|
|
$name, |
4355
|
|
|
$date_start, |
4356
|
|
|
$date_end, |
4357
|
|
|
$date_start, |
4358
|
|
|
$date_end, |
4359
|
|
|
$coachStartDate, |
4360
|
|
|
$coachEndDate, |
4361
|
|
|
$id_coach, |
4362
|
|
|
$sessionInfo['session_category_id'], |
4363
|
|
|
$sessionInfo['visibility'], |
4364
|
|
|
$sessionInfo['description'], |
4365
|
|
|
$sessionInfo['show_description'], |
4366
|
|
|
$duration, |
4367
|
|
|
null, |
4368
|
|
|
DEFAULT_ADMIN_USER_ID |
4369
|
|
|
); |
4370
|
|
|
|
4371
|
|
|
if (is_array($extra_list) && count($extra_list) > 0) { |
4372
|
|
|
foreach ($extra_list as $extra) { |
4373
|
|
|
$extra_field_name = $extra['field_name']; |
4374
|
|
|
$extra_field_value = $extra['field_value']; |
4375
|
|
|
// Save the external system's id into session_field_value table. |
4376
|
|
|
SessionManager::update_session_extra_field_value( |
4377
|
|
|
$id, |
4378
|
|
|
$extra_field_name, |
4379
|
|
|
$extra_field_value |
4380
|
|
|
); |
4381
|
|
|
} |
4382
|
|
|
} |
4383
|
|
|
|
4384
|
|
|
$results[] = $editResult ? 1 : 0; |
4385
|
|
|
continue; |
4386
|
|
|
} |
4387
|
|
|
} // end principal foreach |
4388
|
|
|
|
4389
|
|
|
$count_results = count($results); |
4390
|
|
|
$output = []; |
4391
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
4392
|
|
|
$output[] = [ |
4393
|
|
|
'original_session_id_value' => $orig_session_id_value[$i], |
4394
|
|
|
'result' => $results[$i], |
4395
|
|
|
]; |
4396
|
|
|
} |
4397
|
|
|
|
4398
|
|
|
return $output; |
4399
|
|
|
} |
4400
|
|
|
|
4401
|
|
|
/* Register WSDeleteSession function */ |
4402
|
|
|
$server->wsdl->addComplexType( |
4403
|
|
|
'deleteSessionParams', |
4404
|
|
|
'complexType', |
4405
|
|
|
'struct', |
4406
|
|
|
'all', |
4407
|
|
|
'', |
4408
|
|
|
[ |
4409
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
4410
|
|
|
'original_session_id_name' => ['name' => 'original_session_id_name', 'type' => 'xsd:string'], |
4411
|
|
|
] |
4412
|
|
|
); |
4413
|
|
|
|
4414
|
|
|
$server->wsdl->addComplexType( |
4415
|
|
|
'deleteSessionParamsList', |
4416
|
|
|
'complexType', |
4417
|
|
|
'array', |
4418
|
|
|
'', |
4419
|
|
|
'SOAP-ENC:Array', |
4420
|
|
|
[], |
4421
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:deleteSessionParams[]']], |
4422
|
|
|
'tns:deleteSessionParams' |
4423
|
|
|
); |
4424
|
|
|
|
4425
|
|
|
// Register the data structures used by the service |
4426
|
|
|
$server->wsdl->addComplexType( |
4427
|
|
|
'deleteSession', |
4428
|
|
|
'complexType', |
4429
|
|
|
'struct', |
4430
|
|
|
'all', |
4431
|
|
|
'', |
4432
|
|
|
[ |
4433
|
|
|
'sessions' => ['name' => 'sessions', 'type' => 'tns:deleteSessionParamsList'], |
4434
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
4435
|
|
|
] |
4436
|
|
|
); |
4437
|
|
|
|
4438
|
|
|
// Prepare output params, in this case will return an array |
4439
|
|
|
$server->wsdl->addComplexType( |
4440
|
|
|
'result_deleteSession', |
4441
|
|
|
'complexType', |
4442
|
|
|
'struct', |
4443
|
|
|
'all', |
4444
|
|
|
'', |
4445
|
|
|
[ |
4446
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
4447
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
4448
|
|
|
] |
4449
|
|
|
); |
4450
|
|
|
|
4451
|
|
|
$server->wsdl->addComplexType( |
4452
|
|
|
'results_deleteSession', |
4453
|
|
|
'complexType', |
4454
|
|
|
'array', |
4455
|
|
|
'', |
4456
|
|
|
'SOAP-ENC:Array', |
4457
|
|
|
[], |
4458
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_deleteSession[]']], |
4459
|
|
|
'tns:result_deleteSession' |
4460
|
|
|
); |
4461
|
|
|
|
4462
|
|
|
$server->register( |
4463
|
|
|
'WSDeleteSession', // method name |
4464
|
|
|
['deleteSession' => 'tns:deleteSession'], // input parameters |
4465
|
|
|
['return' => 'tns:results_deleteSession'], // output parameters |
4466
|
|
|
'urn:WSRegistration', // namespace |
4467
|
|
|
'urn:WSRegistration#WSDeleteSession', // soapaction |
4468
|
|
|
'rpc', // style |
4469
|
|
|
'encoded', // use |
4470
|
|
|
'This service deletes a session ' // documentation |
4471
|
|
|
); |
4472
|
|
|
|
4473
|
|
|
// define the method WSDeleteSession |
4474
|
|
|
function WSDeleteSession($params) |
4475
|
|
|
{ |
4476
|
|
|
if (!WSHelperVerifyKey($params)) { |
4477
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
4478
|
|
|
} |
4479
|
|
|
|
4480
|
|
|
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); |
4481
|
|
|
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
4482
|
|
|
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); |
4483
|
|
|
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); |
4484
|
|
|
|
4485
|
|
|
$session_params = $params['sessions']; |
4486
|
|
|
$results = []; |
4487
|
|
|
$orig_session_id_value = []; |
4488
|
|
|
|
4489
|
|
|
foreach ($session_params as $session_param) { |
4490
|
|
|
$original_session_id_value = $session_param['original_session_id_value']; |
4491
|
|
|
$original_session_id_name = $session_param['original_session_id_name']; |
4492
|
|
|
$orig_session_id_value[] = $original_session_id_name; |
4493
|
|
|
|
4494
|
|
|
$idChecked = SessionManager::getSessionIdFromOriginalId( |
4495
|
|
|
$original_session_id_value, |
4496
|
|
|
$original_session_id_name |
4497
|
|
|
); |
4498
|
|
|
|
4499
|
|
|
if (empty($idChecked)) { |
4500
|
|
|
$results[] = 0; |
4501
|
|
|
continue; |
4502
|
|
|
} |
4503
|
|
|
|
4504
|
|
|
$session_ids[] = $idChecked; |
4505
|
|
|
|
4506
|
|
|
$sql = "DELETE FROM $tbl_session WHERE id = '$idChecked'"; |
4507
|
|
|
Database::query($sql); |
4508
|
|
|
$sql = "DELETE FROM $tbl_session_rel_course WHERE session_id = '$idChecked'"; |
4509
|
|
|
Database::query($sql); |
4510
|
|
|
$sql = "DELETE FROM $tbl_session_rel_course_rel_user WHERE session_id = '$idChecked'"; |
4511
|
|
|
Database::query($sql); |
4512
|
|
|
$sql = "DELETE FROM $tbl_session_rel_user WHERE session_id = '$idChecked'"; |
4513
|
|
|
Database::query($sql); |
4514
|
|
|
$results[] = 1; |
4515
|
|
|
continue; |
4516
|
|
|
} |
4517
|
|
|
|
4518
|
|
|
$extraFieldValue = new ExtraFieldValue('session'); |
4519
|
|
|
|
4520
|
|
|
//delete from table_session_field_value from a given session_id |
4521
|
|
|
foreach ($session_ids as $session_id) { |
4522
|
|
|
$extraFieldValue->deleteValuesByItem($session_id); |
4523
|
|
|
} |
4524
|
|
|
|
4525
|
|
|
// Preparing output. |
4526
|
|
|
$count_results = count($results); |
4527
|
|
|
$output = []; |
4528
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
4529
|
|
|
$output[] = [ |
4530
|
|
|
'original_session_id_value' => $orig_session_id_value[$i], |
4531
|
|
|
'result' => $results[$i], |
4532
|
|
|
]; |
4533
|
|
|
} |
4534
|
|
|
|
4535
|
|
|
return $output; |
4536
|
|
|
} |
4537
|
|
|
|
4538
|
|
|
/** WSSubscribeUserToCourse */ |
4539
|
|
|
// Register the data structures used by the service |
4540
|
|
|
$server->wsdl->addComplexType( |
4541
|
|
|
'user_course_status', |
4542
|
|
|
'complexType', |
4543
|
|
|
'struct', |
4544
|
|
|
'all', |
4545
|
|
|
'', |
4546
|
|
|
[ |
4547
|
|
|
'course_id' => ['name' => 'course_id', 'type' => 'tns:course_id'], |
4548
|
|
|
'user_id' => ['name' => 'user_id', 'type' => 'tns:user_id'], |
4549
|
|
|
'status' => ['name' => 'status', 'type' => 'xsd:int'], |
4550
|
|
|
] |
4551
|
|
|
); |
4552
|
|
|
|
4553
|
|
|
$server->wsdl->addComplexType( |
4554
|
|
|
'subscribeUserToCourse_arg', |
4555
|
|
|
'complexType', |
4556
|
|
|
'struct', |
4557
|
|
|
'all', |
4558
|
|
|
'', |
4559
|
|
|
[ |
4560
|
|
|
'userscourses' => ['name' => 'userscourses', 'type' => 'tns:user_course_status_array'], //removed [] |
4561
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
4562
|
|
|
] |
4563
|
|
|
); |
4564
|
|
|
|
4565
|
|
|
$server->wsdl->addComplexType( |
4566
|
|
|
'user_course_status_array', |
4567
|
|
|
'complexType', |
4568
|
|
|
'array', |
4569
|
|
|
'', |
4570
|
|
|
'SOAP-ENC:Array', |
4571
|
|
|
[], |
4572
|
|
|
[ |
4573
|
|
|
['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:user_course_status[]'], |
4574
|
|
|
], |
4575
|
|
|
'tns:user_course_status' |
4576
|
|
|
); |
4577
|
|
|
|
4578
|
|
|
$server->wsdl->addComplexType( |
4579
|
|
|
'subscribeUserToCourse_return', |
4580
|
|
|
'complexType', |
4581
|
|
|
'struct', |
4582
|
|
|
'all', |
4583
|
|
|
'', |
4584
|
|
|
[ |
4585
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
4586
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
4587
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:int'], |
4588
|
|
|
] |
4589
|
|
|
); |
4590
|
|
|
|
4591
|
|
|
$server->wsdl->addComplexType( |
4592
|
|
|
'subscribeUserToCourse_return_global', |
4593
|
|
|
'complexType', |
4594
|
|
|
'array', |
4595
|
|
|
'', |
4596
|
|
|
'SOAP-ENC:Array', |
4597
|
|
|
[], |
4598
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:subscribeUserToCourse_return[]']], |
4599
|
|
|
'tns:subscribeUserToCourse_return' |
4600
|
|
|
); |
4601
|
|
|
|
4602
|
|
|
// Register the method to expose |
4603
|
|
|
$server->register( |
4604
|
|
|
'WSSubscribeUserToCourse', // method name |
4605
|
|
|
['subscribeUserToCourse' => 'tns:subscribeUserToCourse_arg'], // input parameters |
4606
|
|
|
['return' => 'tns:subscribeUserToCourse_return_global'], |
4607
|
|
|
'urn:WSRegistration', // namespace |
4608
|
|
|
'urn:WSRegistration#WSSubscribeUserToCourse', // soapaction |
4609
|
|
|
'rpc', // style |
4610
|
|
|
'encoded', // use |
4611
|
|
|
'This service subscribes a user to a course' // documentation |
4612
|
|
|
); |
4613
|
|
|
|
4614
|
|
|
// define the method WSSubscribeUserToCourse |
4615
|
|
|
function WSSubscribeUserToCourse($params) |
4616
|
|
|
{ |
4617
|
|
|
global $debug; |
4618
|
|
|
if (!WSHelperVerifyKey($params)) { |
4619
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
4620
|
|
|
} |
4621
|
|
|
if ($debug) { |
4622
|
|
|
error_log('WSSubscribeUserToCourse params: '.print_r($params, 1)); |
4623
|
|
|
} |
4624
|
|
|
|
4625
|
|
|
$results = []; |
4626
|
|
|
$userscourses = $params['userscourses']; |
4627
|
|
|
foreach ($userscourses as $usercourse) { |
4628
|
|
|
$original_course_id = $usercourse['course_id']; |
4629
|
|
|
$original_user_id = $usercourse['user_id']; |
4630
|
|
|
$status = STUDENT; |
4631
|
|
|
if ($usercourse['status']) { |
4632
|
|
|
$status = $usercourse['status']; |
4633
|
|
|
} |
4634
|
|
|
|
4635
|
|
|
$resultValue = 0; |
4636
|
|
|
|
4637
|
|
|
// Get user id |
4638
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
4639
|
|
|
$original_user_id['original_user_id_value'], |
4640
|
|
|
$original_user_id['original_user_id_name'] |
4641
|
|
|
); |
4642
|
|
|
if ($debug) { |
4643
|
|
|
error_log('WSSubscribeUserToCourse user_id: '.$user_id); |
4644
|
|
|
} |
4645
|
|
|
|
4646
|
|
|
if ($user_id == 0) { |
4647
|
|
|
// If user was not found, there was a problem |
4648
|
|
|
$resultValue = 0; |
4649
|
|
|
} else { |
4650
|
|
|
// User was found |
4651
|
|
|
$courseInfo = CourseManager::getCourseInfoFromOriginalId( |
4652
|
|
|
$original_course_id['original_course_id_value'], |
4653
|
|
|
$original_course_id['original_course_id_name'] |
4654
|
|
|
); |
4655
|
|
|
|
4656
|
|
|
$courseCode = isset($courseInfo['code']) ? $courseInfo['code'] : ''; |
4657
|
|
|
|
4658
|
|
|
if (empty($courseCode)) { |
4659
|
|
|
if ($debug) { |
4660
|
|
|
error_log('WSSubscribeUserToCourse course not found'); |
4661
|
|
|
} |
4662
|
|
|
// Course was not found |
4663
|
|
|
$resultValue = 0; |
4664
|
|
|
} else { |
4665
|
|
|
if ($debug) { |
4666
|
|
|
error_log('WSSubscribeUserToCourse courseCode: '.$courseCode); |
4667
|
|
|
} |
4668
|
|
|
$result = CourseManager::subscribeUser($user_id, $courseCode, $status, 0, 0, false); |
4669
|
|
|
if ($result) { |
4670
|
|
|
$resultValue = 1; |
4671
|
|
|
if ($debug) { |
4672
|
|
|
error_log('WSSubscribeUserToCourse subscribed'); |
4673
|
|
|
} |
4674
|
|
|
} else { |
4675
|
|
|
if ($debug) { |
4676
|
|
|
error_log('WSSubscribeUserToCourse NOT subscribed.'); |
4677
|
|
|
} |
4678
|
|
|
} |
4679
|
|
|
} |
4680
|
|
|
} |
4681
|
|
|
|
4682
|
|
|
$results[] = [ |
4683
|
|
|
'original_user_id_value' => $original_user_id['original_user_id_value'], |
4684
|
|
|
'original_course_id_value' => $original_course_id['original_course_id_value'], |
4685
|
|
|
'result' => $resultValue, |
4686
|
|
|
]; |
4687
|
|
|
} |
4688
|
|
|
|
4689
|
|
|
return $results; |
4690
|
|
|
} |
4691
|
|
|
|
4692
|
|
|
/** WSSubscribeUserToCourse */ |
4693
|
|
|
// Register the data structures used by the service |
4694
|
|
|
$server->wsdl->addComplexType( |
4695
|
|
|
'subscribeUserToCourseSimple_arg', |
4696
|
|
|
'complexType', |
4697
|
|
|
'struct', |
4698
|
|
|
'all', |
4699
|
|
|
'', |
4700
|
|
|
[ |
4701
|
|
|
'course' => ['name' => 'course', 'type' => 'xsd:string'], //Course string code |
4702
|
|
|
'user_id' => ['name' => 'user_id', 'type' => 'xsd:string'], //Chamilo user_id |
4703
|
|
|
'status' => ['name' => 'status', 'type' => 'xsd:int'], |
4704
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
4705
|
|
|
] |
4706
|
|
|
); |
4707
|
|
|
|
4708
|
|
|
// Prepare output params, in this case will return an array |
4709
|
|
|
$server->wsdl->addComplexType( |
4710
|
|
|
'Result', |
4711
|
|
|
'complexType', |
4712
|
|
|
'struct', |
4713
|
|
|
'all', |
4714
|
|
|
'', |
4715
|
|
|
['message' => ['name' => 'message', 'type' => 'xsd:string']] |
4716
|
|
|
); |
4717
|
|
|
|
4718
|
|
|
// Register the method to expose |
4719
|
|
|
$server->register( |
4720
|
|
|
'WSSubscribeUserToCourseSimple', // method name |
4721
|
|
|
['subscribeUserToCourseSimple' => 'tns:subscribeUserToCourseSimple_arg'], // input parameters |
4722
|
|
|
['return' => 'xsd:string'], // output parameters |
4723
|
|
|
'urn:WSRegistration', // namespace |
4724
|
|
|
'urn:WSRegistration#WSSubscribeUserToCourseSimple', // soapaction |
4725
|
|
|
'rpc', // style |
4726
|
|
|
'encoded', // use |
4727
|
|
|
'This service subscribes a user to a course in a simple way' // documentation |
4728
|
|
|
); |
4729
|
|
|
|
4730
|
|
|
/** |
4731
|
|
|
* define the method WSSubscribeUserToCourse. |
4732
|
|
|
* |
4733
|
|
|
* @param array $params |
4734
|
|
|
* |
4735
|
|
|
* @return array|int|soap_fault|string|null |
4736
|
|
|
*/ |
4737
|
|
|
function WSSubscribeUserToCourseSimple($params) |
4738
|
|
|
{ |
4739
|
|
|
global $debug; |
4740
|
|
|
|
4741
|
|
|
if ($debug) { |
4742
|
|
|
error_log('WSSubscribeUserToCourseSimple'); |
4743
|
|
|
} |
4744
|
|
|
if ($debug) { |
4745
|
|
|
error_log('Params '.print_r($params, 1)); |
4746
|
|
|
} |
4747
|
|
|
if (!WSHelperVerifyKey($params)) { |
4748
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
4749
|
|
|
} |
4750
|
|
|
$result = []; |
4751
|
|
|
$course_code = $params['course']; //Course code |
4752
|
|
|
$user_id = $params['user_id']; //chamilo user id |
4753
|
|
|
$status = STUDENT; |
4754
|
|
|
|
4755
|
|
|
if (!empty($params['status'])) { |
4756
|
|
|
$status = $params['status']; |
4757
|
|
|
} |
4758
|
|
|
// Get user id |
4759
|
|
|
$user_data = api_get_user_info($user_id); |
4760
|
|
|
|
4761
|
|
|
if (empty($user_data)) { |
4762
|
|
|
// If user was not found, there was a problem |
4763
|
|
|
$result = "User $user_id does not exist"; |
4764
|
|
|
if ($debug) { |
4765
|
|
|
error_log($result); |
4766
|
|
|
} |
4767
|
|
|
|
4768
|
|
|
return $result; |
4769
|
|
|
} |
4770
|
|
|
if (!empty($course_code)) { |
4771
|
|
|
$course_data = api_get_course_info($course_code); |
4772
|
|
|
if (empty($course_data)) { |
4773
|
|
|
// Course was not found |
4774
|
|
|
$result = "Course $course_code does not exist in the platform "; |
4775
|
|
|
if ($debug) { |
4776
|
|
|
error_log($result); |
4777
|
|
|
} |
4778
|
|
|
} else { |
4779
|
|
|
if ($debug) { |
4780
|
|
|
error_log('Try to register: user_id= '.$user_id.' to course: '.$course_data['code']); |
4781
|
|
|
} |
4782
|
|
|
if (!CourseManager::subscribeUser($user_id, $course_data['code'], $status, 0, false, false)) { |
4783
|
|
|
$result = 'User was not registered possible reasons: User already registered to the course, |
4784
|
|
|
Course visibility doesnt allow user subscriptions '; |
4785
|
|
|
if ($debug) { |
4786
|
|
|
error_log($result); |
4787
|
|
|
} |
4788
|
|
|
} else { |
4789
|
|
|
if ($debug) { |
4790
|
|
|
error_log('User registered to the course: '.$course_data['code']); |
4791
|
|
|
} |
4792
|
|
|
$result = 1; |
4793
|
|
|
} |
4794
|
|
|
} |
4795
|
|
|
} |
4796
|
|
|
|
4797
|
|
|
return $result; |
4798
|
|
|
} |
4799
|
|
|
|
4800
|
|
|
/* GetUser */ |
4801
|
|
|
$server->wsdl->addComplexType( |
4802
|
|
|
'GetUserArg', |
4803
|
|
|
'complexType', |
4804
|
|
|
'struct', |
4805
|
|
|
'all', |
4806
|
|
|
'', |
4807
|
|
|
[ |
4808
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
4809
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
4810
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
4811
|
|
|
] |
4812
|
|
|
); |
4813
|
|
|
|
4814
|
|
|
// Prepare output params, in this case will return an array |
4815
|
|
|
$server->wsdl->addComplexType( |
4816
|
|
|
'User', |
4817
|
|
|
'complexType', |
4818
|
|
|
'struct', |
4819
|
|
|
'all', |
4820
|
|
|
'', |
4821
|
|
|
[ |
4822
|
|
|
'user_id' => ['name' => 'user_id', 'type' => 'xsd:string'], |
4823
|
|
|
'firstname' => ['name' => 'firstname', 'type' => 'xsd:string'], |
4824
|
|
|
'lastname' => ['name' => 'lastname', 'type' => 'xsd:string'], |
4825
|
|
|
] |
4826
|
|
|
); |
4827
|
|
|
|
4828
|
|
|
// Register the method to expose |
4829
|
|
|
$server->register( |
4830
|
|
|
'WSGetUser', // method name |
4831
|
|
|
['GetUser' => 'tns:GetUserArg'], // input parameters |
4832
|
|
|
['return' => 'tns:User'], // output parameters |
4833
|
|
|
'urn:WSRegistration', // namespace |
4834
|
|
|
'urn:WSRegistration#WSGetUser', // soapaction |
4835
|
|
|
'rpc', // style |
4836
|
|
|
'encoded', // use |
4837
|
|
|
'This service get user information by id' // documentation |
4838
|
|
|
); |
4839
|
|
|
|
4840
|
|
|
// define the method WSGetUser |
4841
|
|
|
function WSGetUser($params) |
4842
|
|
|
{ |
4843
|
|
|
global $debug; |
4844
|
|
|
if ($debug) { |
4845
|
|
|
error_log('WSGetUser'); |
4846
|
|
|
} |
4847
|
|
|
if ($debug) { |
4848
|
|
|
error_log('$params: '.print_r($params, 1)); |
4849
|
|
|
} |
4850
|
|
|
|
4851
|
|
|
if (!WSHelperVerifyKey($params)) { |
4852
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
4853
|
|
|
} |
4854
|
|
|
|
4855
|
|
|
$result = []; |
4856
|
|
|
|
4857
|
|
|
// Get user id |
4858
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
4859
|
|
|
$params['original_user_id_value'], |
4860
|
|
|
$params['original_user_id_name'] |
4861
|
|
|
); |
4862
|
|
|
$user_data = api_get_user_info($user_id); |
4863
|
|
|
|
4864
|
|
|
if (empty($user_data)) { |
4865
|
|
|
// If user was not found, there was a problem |
4866
|
|
|
$result['user_id'] = ''; |
4867
|
|
|
$result['firstname'] = ''; |
4868
|
|
|
$result['lastname'] = ''; |
4869
|
|
|
} else { |
4870
|
|
|
$result['user_id'] = $user_data['user_id']; |
4871
|
|
|
$result['firstname'] = $user_data['firstname']; |
4872
|
|
|
$result['lastname'] = $user_data['lastname']; |
4873
|
|
|
} |
4874
|
|
|
|
4875
|
|
|
return $result; |
4876
|
|
|
} |
4877
|
|
|
|
4878
|
|
|
$server->wsdl->addComplexType( |
4879
|
|
|
'GetUserArgUsername', |
4880
|
|
|
'complexType', |
4881
|
|
|
'struct', |
4882
|
|
|
'all', |
4883
|
|
|
'', |
4884
|
|
|
[ |
4885
|
|
|
'username' => ['name' => 'username', 'type' => 'xsd:string'], |
4886
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
4887
|
|
|
] |
4888
|
|
|
); |
4889
|
|
|
|
4890
|
|
|
// Prepare output params, in this case will return an array |
4891
|
|
|
$server->wsdl->addComplexType( |
4892
|
|
|
'UserWithExtraFields', |
4893
|
|
|
'complexType', |
4894
|
|
|
'struct', |
4895
|
|
|
'all', |
4896
|
|
|
'', |
4897
|
|
|
[ |
4898
|
|
|
'user_id' => ['name' => 'user_id', 'type' => 'xsd:string'], |
4899
|
|
|
'firstname' => ['name' => 'firstname', 'type' => 'xsd:string'], |
4900
|
|
|
'lastname' => ['name' => 'lastname', 'type' => 'xsd:string'], |
4901
|
|
|
'extra_fields' => ['name' => 'extra_fields', 'type' => 'xsd:string'], |
4902
|
|
|
] |
4903
|
|
|
); |
4904
|
|
|
|
4905
|
|
|
// Register the method to expose |
4906
|
|
|
$server->register( |
4907
|
|
|
'WSGetUserFromUsername', // method name |
4908
|
|
|
['GetUserFromUsername' => 'tns:GetUserArgUsername'], // input params |
4909
|
|
|
['return' => 'tns:UserWithExtraFields'], // output parameters |
4910
|
|
|
'urn:WSRegistration', // namespace |
4911
|
|
|
'urn:WSRegistration#WSGetUserFromUsername', // soapaction |
4912
|
|
|
'rpc', // style |
4913
|
|
|
'encoded', // use |
4914
|
|
|
'This service get user information by username' // documentation |
4915
|
|
|
); |
4916
|
|
|
|
4917
|
|
|
// define the method WSGetUserFromUsername |
4918
|
|
|
function WSGetUserFromUsername($params) |
4919
|
|
|
{ |
4920
|
|
|
global $debug; |
4921
|
|
|
if ($debug) { |
4922
|
|
|
error_log('WSGetUserFromUsername'); |
4923
|
|
|
} |
4924
|
|
|
if ($debug) { |
4925
|
|
|
error_log('$params: '.print_r($params, 1)); |
4926
|
|
|
} |
4927
|
|
|
|
4928
|
|
|
if (!WSHelperVerifyKey($params)) { |
4929
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
4930
|
|
|
} |
4931
|
|
|
|
4932
|
|
|
// Get user id |
4933
|
|
|
$user_data = api_get_user_info_from_username($params['username']); |
4934
|
|
|
|
4935
|
|
|
$result = []; |
4936
|
|
|
$result['user_id'] = ''; |
4937
|
|
|
$result['firstname'] = ''; |
4938
|
|
|
$result['lastname'] = ''; |
4939
|
|
|
$result['extra_fields'] = ''; |
4940
|
|
|
|
4941
|
|
|
if (empty($user_data)) { |
4942
|
|
|
// If user was not found, there was a problem |
4943
|
|
|
if ($debug) { |
4944
|
|
|
error_log('User not found :('); |
4945
|
|
|
} |
4946
|
|
|
} else { |
4947
|
|
|
$result['user_id'] = $user_data['user_id']; |
4948
|
|
|
$result['firstname'] = $user_data['firstname']; |
4949
|
|
|
$result['lastname'] = $user_data['lastname']; |
4950
|
|
|
$result['email'] = $user_data['email']; |
4951
|
|
|
|
4952
|
|
|
// Get extra fields |
4953
|
|
|
$fieldValue = new ExtraFieldValue('user'); |
4954
|
|
|
$extra = $fieldValue->getAllValuesByItem($result['user_id']); |
4955
|
|
|
$result['extra_fields'] = json_encode($extra); |
4956
|
|
|
|
4957
|
|
|
if ($debug) { |
4958
|
|
|
error_log('User found :) return value '.print_r($result, 1)); |
4959
|
|
|
} |
4960
|
|
|
} |
4961
|
|
|
|
4962
|
|
|
return $result; |
4963
|
|
|
} |
4964
|
|
|
|
4965
|
|
|
$server->wsdl->addComplexType( |
4966
|
|
|
'GetUserArgUsernameWithOriginal', |
4967
|
|
|
'complexType', |
4968
|
|
|
'struct', |
4969
|
|
|
'all', |
4970
|
|
|
'', |
4971
|
|
|
[ |
4972
|
|
|
'username' => ['name' => 'username', 'type' => 'xsd:string'], |
4973
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
4974
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
4975
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
4976
|
|
|
] |
4977
|
|
|
); |
4978
|
|
|
// Register the method to expose |
4979
|
|
|
$server->register( |
4980
|
|
|
'WSUpdateUserOriginalIdFromUsername', // method name |
4981
|
|
|
['WSUpdateUserOriginalIdFromUsername' => 'tns:GetUserArgUsernameWithOriginal'], // input params |
4982
|
|
|
['return' => 'tns:User'], // output parameters |
4983
|
|
|
'urn:WSRegistration', // namespace |
4984
|
|
|
'urn:WSRegistration#WSGetUserFromUsername', // soapaction |
4985
|
|
|
'rpc', // style |
4986
|
|
|
'encoded', // use |
4987
|
|
|
'This service get user information by username' // documentation |
4988
|
|
|
); |
4989
|
|
|
|
4990
|
|
|
// define the method WSGetUserFromUsername |
4991
|
|
|
function WSUpdateUserOriginalIdFromUsername($params) |
4992
|
|
|
{ |
4993
|
|
|
global $debug; |
4994
|
|
|
if ($debug) { |
4995
|
|
|
error_log('WSUpdateUserOriginalIdFromUsername'); |
4996
|
|
|
} |
4997
|
|
|
if ($debug) { |
4998
|
|
|
error_log('$params: '.print_r($params, 1)); |
4999
|
|
|
} |
5000
|
|
|
|
5001
|
|
|
if (!WSHelperVerifyKey($params)) { |
5002
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
5003
|
|
|
} |
5004
|
|
|
|
5005
|
|
|
$result = []; |
5006
|
|
|
|
5007
|
|
|
// Get user id |
5008
|
|
|
$user_data = api_get_user_info_from_username($params['username']); |
5009
|
|
|
|
5010
|
|
|
if (empty($user_data)) { |
5011
|
|
|
// If user was not found, there was a problem |
5012
|
|
|
$result['user_id'] = ''; |
5013
|
|
|
$result['firstname'] = ''; |
5014
|
|
|
$result['lastname'] = ''; |
5015
|
|
|
|
5016
|
|
|
if ($debug) { |
5017
|
|
|
error_log('User not found :('); |
5018
|
|
|
} |
5019
|
|
|
} else { |
5020
|
|
|
$result['user_id'] = $user_data['user_id']; |
5021
|
|
|
$result['firstname'] = $user_data['firstname']; |
5022
|
|
|
$result['lastname'] = $user_data['lastname']; |
5023
|
|
|
$result['email'] = $user_data['email']; |
5024
|
|
|
|
5025
|
|
|
$resultUpdate = UserManager::update_extra_field_value( |
5026
|
|
|
$user_data['user_id'], |
5027
|
|
|
$params['original_user_id_name'], |
5028
|
|
|
$params['original_user_id_value'] |
5029
|
|
|
); |
5030
|
|
|
|
5031
|
|
|
$fieldValue = new ExtraFieldValue('user'); |
5032
|
|
|
$extraList = $fieldValue->getAllValuesByItem( |
5033
|
|
|
$result['user_id'] |
5034
|
|
|
); |
5035
|
|
|
|
5036
|
|
|
$result['extra'] = $extraList; |
5037
|
|
|
|
5038
|
|
|
if ($debug) { |
5039
|
|
|
if ($resultUpdate) { |
5040
|
|
|
error_log('User updated :) '); |
5041
|
|
|
} else { |
5042
|
|
|
error_log('User not updated :('); |
5043
|
|
|
} |
5044
|
|
|
error_log('$result: '.print_r($result, 1)); |
5045
|
|
|
} |
5046
|
|
|
} |
5047
|
|
|
|
5048
|
|
|
return $result; |
5049
|
|
|
} |
5050
|
|
|
|
5051
|
|
|
/* Register WSUnsubscribeUserFromCourse function */ |
5052
|
|
|
// Register the data structures used by the service |
5053
|
|
|
$server->wsdl->addComplexType( |
5054
|
|
|
'unsuscribeUserFromCourseParams', |
5055
|
|
|
'complexType', |
5056
|
|
|
'struct', |
5057
|
|
|
'all', |
5058
|
|
|
'', |
5059
|
|
|
[ |
5060
|
|
|
'original_user_id_values' => ['name' => 'original_user_id_values', 'type' => 'tns:originalUsersList'], |
5061
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
5062
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
5063
|
|
|
'original_course_id_name' => ['name' => 'original_course_id_name', 'type' => 'xsd:string'], |
5064
|
|
|
] |
5065
|
|
|
); |
5066
|
|
|
|
5067
|
|
|
$server->wsdl->addComplexType( |
5068
|
|
|
'unsuscribeUserFromCourseParamsList', |
5069
|
|
|
'complexType', |
5070
|
|
|
'array', |
5071
|
|
|
'', |
5072
|
|
|
'SOAP-ENC:Array', |
5073
|
|
|
[], |
5074
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:unsuscribeUserFromCourseParams[]']], |
5075
|
|
|
'tns:unsuscribeUserFromCourseParams' |
5076
|
|
|
); |
5077
|
|
|
|
5078
|
|
|
$server->wsdl->addComplexType( |
5079
|
|
|
'unsuscribeUserFromCourse', |
5080
|
|
|
'complexType', |
5081
|
|
|
'struct', |
5082
|
|
|
'all', |
5083
|
|
|
'', |
5084
|
|
|
[ |
5085
|
|
|
'userscourses' => ['name' => 'userscourses', 'type' => 'tns:unsuscribeUserFromCourseParamsList'], |
5086
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
5087
|
|
|
] |
5088
|
|
|
); |
5089
|
|
|
|
5090
|
|
|
// Prepare output params, in this case will return an array |
5091
|
|
|
$server->wsdl->addComplexType( |
5092
|
|
|
'result_unsuscribeUserFromCourse', |
5093
|
|
|
'complexType', |
5094
|
|
|
'struct', |
5095
|
|
|
'all', |
5096
|
|
|
'', |
5097
|
|
|
[ |
5098
|
|
|
'original_user_id_values' => ['name' => 'original_user_id_values', 'type' => 'xsd:string'], |
5099
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
5100
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
5101
|
|
|
] |
5102
|
|
|
); |
5103
|
|
|
|
5104
|
|
|
$server->wsdl->addComplexType( |
5105
|
|
|
'results_unsuscribeUserFromCourse', |
5106
|
|
|
'complexType', |
5107
|
|
|
'array', |
5108
|
|
|
'', |
5109
|
|
|
'SOAP-ENC:Array', |
5110
|
|
|
[], |
5111
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_unsuscribeUserFromCourse[]']], |
5112
|
|
|
'tns:result_unsuscribeUserFromCourse' |
5113
|
|
|
); |
5114
|
|
|
|
5115
|
|
|
// Register the method to expose |
5116
|
|
|
$server->register( |
5117
|
|
|
'WSUnsubscribeUserFromCourse', // method name |
5118
|
|
|
['unsuscribeUserFromCourse' => 'tns:unsuscribeUserFromCourse'], // input parameters |
5119
|
|
|
['return' => 'tns:results_unsuscribeUserFromCourse'], // output parameters |
5120
|
|
|
'urn:WSRegistration', // namespace |
5121
|
|
|
'urn:WSRegistration#WSUnsubscribeUserFromCourse', // soapaction |
5122
|
|
|
'rpc', // style |
5123
|
|
|
'encoded', // use |
5124
|
|
|
'This service unsubscribes a user from a course' // documentation |
5125
|
|
|
); |
5126
|
|
|
|
5127
|
|
|
// define the method WSUnsubscribeUserFromCourse |
5128
|
|
|
function WSUnsubscribeUserFromCourse($params) |
5129
|
|
|
{ |
5130
|
|
|
if (!WSHelperVerifyKey($params)) { |
5131
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
5132
|
|
|
} |
5133
|
|
|
|
5134
|
|
|
$user_table = Database::get_main_table(TABLE_MAIN_USER); |
5135
|
|
|
$table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); |
5136
|
|
|
|
5137
|
|
|
$userscourses_params = $params['userscourses']; |
5138
|
|
|
$results = []; |
5139
|
|
|
$orig_user_id_value = []; |
5140
|
|
|
$orig_course_id_value = []; |
5141
|
|
|
foreach ($userscourses_params as $usercourse_param) { |
5142
|
|
|
$original_user_id_values = $usercourse_param['original_user_id_values']; |
5143
|
|
|
$original_user_id_name = $usercourse_param['original_user_id_name']; |
5144
|
|
|
$original_course_id_value = $usercourse_param['original_course_id_value']; |
5145
|
|
|
$original_course_id_name = $usercourse_param['original_course_id_name']; |
5146
|
|
|
$orig_course_id_value[] = $original_course_id_value; |
5147
|
|
|
|
5148
|
|
|
// Get user id from original user id |
5149
|
|
|
$usersList = []; |
5150
|
|
|
foreach ($original_user_id_values as $key => $row_original_user_id) { |
5151
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
5152
|
|
|
$original_user_id_values[$key], |
5153
|
|
|
$original_user_id_name[$key] |
5154
|
|
|
); |
5155
|
|
|
if ($user_id == 0) { |
5156
|
|
|
continue; // user_id doesn't exist. |
5157
|
|
|
} else { |
5158
|
|
|
$sql = "SELECT user_id FROM $user_table WHERE user_id ='".$user_id."' AND active= '0'"; |
5159
|
|
|
$resu = Database::query($sql); |
5160
|
|
|
$r_check_user = Database::fetch_row($resu); |
5161
|
|
|
if (!empty($r_check_user[0])) { |
5162
|
|
|
continue; // user_id is not active. |
5163
|
|
|
} |
5164
|
|
|
} |
5165
|
|
|
$usersList[] = $user_id; |
5166
|
|
|
} |
5167
|
|
|
|
5168
|
|
|
$orig_user_id_value[] = implode(',', $usersList); |
5169
|
|
|
|
5170
|
|
|
$courseInfo = CourseManager::getCourseInfoFromOriginalId( |
5171
|
|
|
$original_course_id_value, |
5172
|
|
|
$original_course_id_name |
5173
|
|
|
); |
5174
|
|
|
|
5175
|
|
|
if (empty($courseInfo) || |
5176
|
|
|
(isset($courseInfo) && $courseInfo['visibility'] == 0) |
5177
|
|
|
) { |
5178
|
|
|
$results[] = 0; |
5179
|
|
|
continue; // Original_course_id_value doesn't exist. |
5180
|
|
|
} |
5181
|
|
|
|
5182
|
|
|
$courseId = $courseInfo['real_id']; |
5183
|
|
|
|
5184
|
|
|
if (count($usersList) == 0) { |
5185
|
|
|
$results[] = 0; |
5186
|
|
|
continue; |
5187
|
|
|
} |
5188
|
|
|
|
5189
|
|
|
foreach ($usersList as $user_id) { |
5190
|
|
|
$sql = "DELETE FROM $table_course_user |
5191
|
|
|
WHERE user_id = '$user_id' AND c_id = '".$courseId."'"; |
5192
|
|
|
$result = Database::query($sql); |
5193
|
|
|
Database::affected_rows($result); |
5194
|
|
|
} |
5195
|
|
|
$results[] = 1; |
5196
|
|
|
continue; |
5197
|
|
|
} // end principal foreach |
5198
|
|
|
|
5199
|
|
|
$count_results = count($results); |
5200
|
|
|
$output = []; |
5201
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
5202
|
|
|
$output[] = [ |
5203
|
|
|
'original_user_id_values' => $orig_user_id_value[$i], |
5204
|
|
|
'original_course_id_value' => $orig_course_id_value[$i], |
5205
|
|
|
'result' => $results[$i], |
5206
|
|
|
]; |
5207
|
|
|
} |
5208
|
|
|
|
5209
|
|
|
return $output; |
5210
|
|
|
} |
5211
|
|
|
|
5212
|
|
|
/* Register WSSuscribeUsersToSession function */ |
5213
|
|
|
$server->wsdl->addComplexType( |
5214
|
|
|
'unSubscribeUserFromCourseSimple', |
5215
|
|
|
'complexType', |
5216
|
|
|
'struct', |
5217
|
|
|
'all', |
5218
|
|
|
'', |
5219
|
|
|
[ |
5220
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
5221
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
5222
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
5223
|
|
|
'original_course_id_name' => ['name' => 'original_course_id_name', 'type' => 'xsd:string'], |
5224
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
5225
|
|
|
] |
5226
|
|
|
); |
5227
|
|
|
|
5228
|
|
|
$server->wsdl->addComplexType( |
5229
|
|
|
'unSubscribeUserToCourseSimple_return', |
5230
|
|
|
'complexType', |
5231
|
|
|
'struct', |
5232
|
|
|
'all', |
5233
|
|
|
'', |
5234
|
|
|
[ |
5235
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
5236
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
5237
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:int'], |
5238
|
|
|
] |
5239
|
|
|
); |
5240
|
|
|
|
5241
|
|
|
// Register the method to expose |
5242
|
|
|
$server->register( |
5243
|
|
|
'WSUnSubscribeUserFromCourseSimple', // method name |
5244
|
|
|
['unSubscribeUserFromCourseSimple' => 'tns:unSubscribeUserFromCourseSimple'], // input parameters |
5245
|
|
|
['return' => 'tns:unSubscribeUserToCourseSimple_return'], // output parameters |
5246
|
|
|
'urn:WSRegistration', // namespace |
5247
|
|
|
'urn:WSRegistration#WSUnSubscribeUserFromCourseSimple', // soapaction |
5248
|
|
|
'rpc', // style |
5249
|
|
|
'encoded', // use |
5250
|
|
|
'This service unsubscribe a user from a course' // documentation |
5251
|
|
|
); |
5252
|
|
|
|
5253
|
|
|
/** |
5254
|
|
|
* @param array $params |
5255
|
|
|
* |
5256
|
|
|
* @return array|soap_fault|null |
5257
|
|
|
*/ |
5258
|
|
|
function WSUnSubscribeUserFromCourseSimple($params) |
5259
|
|
|
{ |
5260
|
|
|
global $debug; |
5261
|
|
|
error_log('WSUnSubscribeUserFromCourseSimple'); |
5262
|
|
|
if (!WSHelperVerifyKey($params)) { |
5263
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
5264
|
|
|
} |
5265
|
|
|
|
5266
|
|
|
$original_user_id_value = $params['original_user_id_value']; |
5267
|
|
|
$original_user_id_name = $params['original_user_id_name']; |
5268
|
|
|
$original_course_id_value = $params['original_course_id_value']; |
5269
|
|
|
$original_course_id_name = $params['original_course_id_name']; |
5270
|
|
|
|
5271
|
|
|
$result = []; |
5272
|
|
|
$result['original_user_id_value'] = $original_user_id_value; |
5273
|
|
|
$result['original_course_id_value'] = $original_course_id_value; |
5274
|
|
|
$result['result'] = 0; |
5275
|
|
|
|
5276
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
5277
|
|
|
$original_user_id_value, |
5278
|
|
|
$original_user_id_name |
5279
|
|
|
); |
5280
|
|
|
|
5281
|
|
|
if ($user_id) { |
5282
|
|
|
if ($debug) { |
5283
|
|
|
error_log("User $original_user_id_value, $original_user_id_name found"); |
5284
|
|
|
error_log("Course $original_course_id_value, $original_course_id_name found"); |
5285
|
|
|
} |
5286
|
|
|
|
5287
|
|
|
$courseInfo = CourseManager::getCourseInfoFromOriginalId( |
5288
|
|
|
$original_course_id_value, |
5289
|
|
|
$original_course_id_name |
5290
|
|
|
); |
5291
|
|
|
|
5292
|
|
|
$courseCode = $courseInfo['code']; |
5293
|
|
|
|
5294
|
|
|
if (empty($courseCode)) { |
5295
|
|
|
// Course was not found |
5296
|
|
|
if ($debug) { |
5297
|
|
|
error_log("course not found"); |
5298
|
|
|
} |
5299
|
|
|
} else { |
5300
|
|
|
if ($debug) { |
5301
|
|
|
error_log("Course $courseCode found"); |
5302
|
|
|
} |
5303
|
|
|
CourseManager::unsubscribe_user($user_id, $courseCode, 0); |
5304
|
|
|
$result['result'] = 1; |
5305
|
|
|
} |
5306
|
|
|
} else { |
5307
|
|
|
if ($debug) { |
5308
|
|
|
error_log("User not found"); |
5309
|
|
|
} |
5310
|
|
|
} |
5311
|
|
|
|
5312
|
|
|
return $result; |
5313
|
|
|
} |
5314
|
|
|
|
5315
|
|
|
$server->wsdl->addComplexType( |
5316
|
|
|
'subscribeUserToCourseParams', |
5317
|
|
|
'complexType', |
5318
|
|
|
'struct', |
5319
|
|
|
'all', |
5320
|
|
|
'', |
5321
|
|
|
[ |
5322
|
|
|
'original_user_id_values' => ['name' => 'original_user_id_values', 'type' => 'tns:originalUsersList'], |
5323
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
5324
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
5325
|
|
|
'original_course_id_name' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
5326
|
|
|
] |
5327
|
|
|
); |
5328
|
|
|
|
5329
|
|
|
// Prepare output params, in this case will return an array. |
5330
|
|
|
$server->wsdl->addComplexType( |
5331
|
|
|
'result_subscribeUsersToSession', |
5332
|
|
|
'complexType', |
5333
|
|
|
'struct', |
5334
|
|
|
'all', |
5335
|
|
|
'', |
5336
|
|
|
[ |
5337
|
|
|
'original_user_id_values' => ['name' => 'original_user_id_values', 'type' => 'xsd:string'], |
5338
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
5339
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
5340
|
|
|
] |
5341
|
|
|
); |
5342
|
|
|
|
5343
|
|
|
$server->wsdl->addComplexType( |
5344
|
|
|
'results_subscribeUsersToSession', |
5345
|
|
|
'complexType', |
5346
|
|
|
'array', |
5347
|
|
|
'', |
5348
|
|
|
'SOAP-ENC:Array', |
5349
|
|
|
[], |
5350
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_subscribeUsersToSession[]']], |
5351
|
|
|
'tns:result_subscribeUsersToSession' |
5352
|
|
|
); |
5353
|
|
|
|
5354
|
|
|
$server->wsdl->addComplexType( |
5355
|
|
|
'originalUserItem', |
5356
|
|
|
'complexType', |
5357
|
|
|
'struct', |
5358
|
|
|
'all', |
5359
|
|
|
'', |
5360
|
|
|
[ |
5361
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
5362
|
|
|
] |
5363
|
|
|
); |
5364
|
|
|
|
5365
|
|
|
// Register the data structures used by the service |
5366
|
|
|
$server->wsdl->addComplexType( |
5367
|
|
|
'originalUsersList', |
5368
|
|
|
'complexType', |
5369
|
|
|
'array', |
5370
|
|
|
'', |
5371
|
|
|
'SOAP-ENC:Array', |
5372
|
|
|
[], |
5373
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:originalUserItem[]']], |
5374
|
|
|
'tns:originalUserItem' |
5375
|
|
|
); |
5376
|
|
|
|
5377
|
|
|
/* Register WSSuscribeUsersToSession function */ |
5378
|
|
|
// Register the data structures used by the service |
5379
|
|
|
$server->wsdl->addComplexType( |
5380
|
|
|
'subscribeUsersToSessionParams', |
5381
|
|
|
'complexType', |
5382
|
|
|
'struct', |
5383
|
|
|
'all', |
5384
|
|
|
'', |
5385
|
|
|
[ |
5386
|
|
|
'original_user_id_values' => ['name' => 'original_user_id_values', 'type' => 'tns:originalUsersList'], |
5387
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
5388
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
5389
|
|
|
'original_session_id_name' => ['name' => 'original_session_id_name', 'type' => 'xsd:string'], |
5390
|
|
|
] |
5391
|
|
|
); |
5392
|
|
|
|
5393
|
|
|
$server->wsdl->addComplexType( |
5394
|
|
|
'subscribeUsersToSessionParamsList', |
5395
|
|
|
'complexType', |
5396
|
|
|
'array', |
5397
|
|
|
'', |
5398
|
|
|
'SOAP-ENC:Array', |
5399
|
|
|
[], |
5400
|
|
|
[ |
5401
|
|
|
[ |
5402
|
|
|
'ref' => 'SOAP-ENC:arrayType', |
5403
|
|
|
'wsdl:arrayType' => 'tns:subscribeUsersToSessionParams[]', |
5404
|
|
|
], |
5405
|
|
|
], |
5406
|
|
|
'tns:subscribeUsersToSessionParams' |
5407
|
|
|
); |
5408
|
|
|
|
5409
|
|
|
$server->wsdl->addComplexType( |
5410
|
|
|
'subscribeUsersToSession', |
5411
|
|
|
'complexType', |
5412
|
|
|
'struct', |
5413
|
|
|
'all', |
5414
|
|
|
'', |
5415
|
|
|
[ |
5416
|
|
|
'userssessions' => ['name' => 'userssessions', 'type' => 'tns:subscribeUsersToSessionParamsList'], |
5417
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
5418
|
|
|
] |
5419
|
|
|
); |
5420
|
|
|
|
5421
|
|
|
// Register the method to expose |
5422
|
|
|
$server->register( |
5423
|
|
|
'WSSuscribeUsersToSession', // method name |
5424
|
|
|
['subscribeUsersToSession' => 'tns:subscribeUsersToSession'], // input parameters |
5425
|
|
|
['return' => 'tns:results_subscribeUsersToSession'], // output parameters |
5426
|
|
|
'urn:WSRegistration', // namespace |
5427
|
|
|
'urn:WSRegistration#WSSuscribeUsersToSession', // soapaction |
5428
|
|
|
'rpc', // style |
5429
|
|
|
'encoded', // use |
5430
|
|
|
'This service subscribes a user to a session' // documentation |
5431
|
|
|
); |
5432
|
|
|
|
5433
|
|
|
// define the method WSSuscribeUsersToSession |
5434
|
|
|
function WSSuscribeUsersToSession($params) |
5435
|
|
|
{ |
5436
|
|
|
global $debug; |
5437
|
|
|
|
5438
|
|
|
if (!WSHelperVerifyKey($params)) { |
5439
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
5440
|
|
|
} |
5441
|
|
|
$user_table = Database::get_main_table(TABLE_MAIN_USER); |
5442
|
|
|
$userssessions_params = $params['userssessions']; |
5443
|
|
|
|
5444
|
|
|
if ($debug) { |
5445
|
|
|
error_log('WSSuscribeUsersToSession'); |
5446
|
|
|
error_log(print_r($params, 1)); |
5447
|
|
|
|
5448
|
|
|
if (empty($userssessions_params)) { |
5449
|
|
|
error_log('userssessions is empty'); |
5450
|
|
|
} |
5451
|
|
|
} |
5452
|
|
|
|
5453
|
|
|
$results = []; |
5454
|
|
|
$orig_user_id_value = []; |
5455
|
|
|
$orig_session_id_value = []; |
5456
|
|
|
foreach ($userssessions_params as $usersession_params) { |
5457
|
|
|
$original_session_id_value = $usersession_params['original_session_id_value']; |
5458
|
|
|
$original_session_id_name = $usersession_params['original_session_id_name']; |
5459
|
|
|
$original_user_id_name = $usersession_params['original_user_id_name']; |
5460
|
|
|
$original_user_id_values = $usersession_params['original_user_id_values']; |
5461
|
|
|
|
5462
|
|
|
$sessionId = SessionManager::getSessionIdFromOriginalId( |
5463
|
|
|
$original_session_id_value, |
5464
|
|
|
$original_session_id_name |
5465
|
|
|
); |
5466
|
|
|
|
5467
|
|
|
if (empty($sessionId)) { |
5468
|
|
|
$orig_session_id_value[] = $original_session_id_value; |
5469
|
|
|
$results[] = 0; |
5470
|
|
|
continue; |
5471
|
|
|
} |
5472
|
|
|
|
5473
|
|
|
foreach ($original_user_id_values as $key => $row_original_user_list) { |
5474
|
|
|
$orig_session_id_value[] = $original_session_id_value; |
5475
|
|
|
$orig_user_id_value[] = $row_original_user_list['original_user_id_value']; |
5476
|
|
|
|
5477
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
5478
|
|
|
$row_original_user_list['original_user_id_value'], |
5479
|
|
|
$original_user_id_name |
5480
|
|
|
); |
5481
|
|
|
|
5482
|
|
|
if ($debug) { |
5483
|
|
|
error_log("User to subscribe: $user_id"); |
5484
|
|
|
} |
5485
|
|
|
|
5486
|
|
|
if ($user_id == 0) { |
5487
|
|
|
$results[] = 0; |
5488
|
|
|
continue; // user_id doesn't exist. |
5489
|
|
|
} else { |
5490
|
|
|
$sql = "SELECT user_id FROM $user_table |
5491
|
|
|
WHERE user_id ='".$user_id."' AND active= '0'"; |
5492
|
|
|
$resu = Database::query($sql); |
5493
|
|
|
$r_check_user = Database::fetch_row($resu); |
5494
|
|
|
if (!empty($r_check_user[0])) { |
5495
|
|
|
$results[] = 0; |
5496
|
|
|
continue; // user_id is not active. |
5497
|
|
|
} |
5498
|
|
|
|
5499
|
|
|
SessionManager::subscribeUsersToSession( |
5500
|
|
|
$sessionId, |
5501
|
|
|
[$user_id], |
5502
|
|
|
SESSION_VISIBLE_READ_ONLY, |
5503
|
|
|
false |
5504
|
|
|
); |
5505
|
|
|
$results[] = 1; |
5506
|
|
|
|
5507
|
|
|
if ($debug) { |
5508
|
|
|
error_log("subscribe user:$user_id to session $sessionId"); |
5509
|
|
|
} |
5510
|
|
|
} |
5511
|
|
|
} |
5512
|
|
|
} // end principal foreach |
5513
|
|
|
|
5514
|
|
|
$count_results = count($results); |
5515
|
|
|
$output = []; |
5516
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
5517
|
|
|
$output[] = [ |
5518
|
|
|
'original_user_id_values' => $orig_user_id_value[$i], |
5519
|
|
|
'original_session_id_value' => $orig_session_id_value[$i], |
5520
|
|
|
'result' => $results[$i], |
5521
|
|
|
]; |
5522
|
|
|
} |
5523
|
|
|
|
5524
|
|
|
return $output; |
5525
|
|
|
} |
5526
|
|
|
|
5527
|
|
|
// WSSubscribeUserToSessionSimple |
5528
|
|
|
$server->wsdl->addComplexType( |
5529
|
|
|
'subscribeUserToSessionSimple_arg', |
5530
|
|
|
'complexType', |
5531
|
|
|
'struct', |
5532
|
|
|
'all', |
5533
|
|
|
'', |
5534
|
|
|
[ |
5535
|
|
|
'session' => ['name' => 'session', 'type' => 'xsd:string'], // Session ID |
5536
|
|
|
'user_id' => ['name' => 'user_id', 'type' => 'xsd:string'], // Chamilo user_id |
5537
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
5538
|
|
|
] |
5539
|
|
|
); |
5540
|
|
|
|
5541
|
|
|
$server->register( |
5542
|
|
|
'WSSubscribeUserToSessionSimple', // method name |
5543
|
|
|
['subscribeUserToSessionSimple' => 'tns:subscribeUserToSessionSimple_arg'], // input parameters |
5544
|
|
|
['return' => 'xsd:string'], // output parameters |
5545
|
|
|
'urn:WSRegistration', // namespace |
5546
|
|
|
'urn:WSRegistration#WSSubscribeUserToSessionSimple', // soapaction |
5547
|
|
|
'rpc', // style |
5548
|
|
|
'encoded', // use |
5549
|
|
|
'This service subscribes a user to a session in a simple way' // documentation |
5550
|
|
|
); |
5551
|
|
|
|
5552
|
|
|
/** |
5553
|
|
|
* @param array $params |
5554
|
|
|
* |
5555
|
|
|
* @return int|soap_fault|string|null |
5556
|
|
|
*/ |
5557
|
|
|
function WSSubscribeUserToSessionSimple($params) |
5558
|
|
|
{ |
5559
|
|
|
global $debug; |
5560
|
|
|
|
5561
|
|
|
if ($debug) { |
5562
|
|
|
error_log('WSSubscribeUserToSessionSimple with params=['.serialize($params).']'); |
5563
|
|
|
} |
5564
|
|
|
|
5565
|
|
|
// Check security key |
5566
|
|
|
if (!WSHelperVerifyKey($params)) { |
5567
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
5568
|
|
|
} |
5569
|
|
|
|
5570
|
|
|
// Get input parameters |
5571
|
|
|
$session_id = intval($params['session']); // Session ID |
5572
|
|
|
$user_id = intval($params['user_id']); // Chamilo user id |
5573
|
|
|
|
5574
|
|
|
// Get user id |
5575
|
|
|
$user_data = api_get_user_info($user_id); |
5576
|
|
|
|
5577
|
|
|
// Prepare answer |
5578
|
|
|
$result = 0; |
5579
|
|
|
|
5580
|
|
|
if (empty($user_data)) { |
5581
|
|
|
$result = "User {$user_id} does not exist"; |
5582
|
|
|
if ($debug) { |
5583
|
|
|
error_log($result); |
5584
|
|
|
} |
5585
|
|
|
|
5586
|
|
|
return $result; |
5587
|
|
|
} |
5588
|
|
|
if (!empty($session_id) && is_numeric($session_id)) { |
5589
|
|
|
$session_data = api_get_session_info($session_id); |
5590
|
|
|
if (empty($session_data)) { |
5591
|
|
|
$result = "Session {$session_id} does not exist."; |
5592
|
|
|
if ($debug) { |
5593
|
|
|
error_log($result); |
5594
|
|
|
} |
5595
|
|
|
} else { |
5596
|
|
|
SessionManager::subscribeUsersToSession( |
5597
|
|
|
$session_id, |
5598
|
|
|
[$user_id], |
5599
|
|
|
SESSION_VISIBLE_READ_ONLY, |
5600
|
|
|
false |
5601
|
|
|
); |
5602
|
|
|
if ($debug) { |
5603
|
|
|
error_log('User registered to the course: '.$session_id); |
5604
|
|
|
} |
5605
|
|
|
$result = 1; |
5606
|
|
|
} |
5607
|
|
|
} |
5608
|
|
|
|
5609
|
|
|
return $result; |
5610
|
|
|
} |
5611
|
|
|
|
5612
|
|
|
/* Register WSUnsuscribeUsersFromSession function */ |
5613
|
|
|
// Register the data structures used by the service |
5614
|
|
|
$server->wsdl->addComplexType( |
5615
|
|
|
'unsubscribeUsersFromSessionParams', |
5616
|
|
|
'complexType', |
5617
|
|
|
'struct', |
5618
|
|
|
'all', |
5619
|
|
|
'', |
5620
|
|
|
[ |
5621
|
|
|
'original_user_id_values' => ['name' => 'original_user_id_values', 'type' => 'tns:originalUsersList'], |
5622
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
5623
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
5624
|
|
|
'original_session_id_name' => ['name' => 'original_session_id_name', 'type' => 'xsd:string'], |
5625
|
|
|
] |
5626
|
|
|
); |
5627
|
|
|
|
5628
|
|
|
$server->wsdl->addComplexType( |
5629
|
|
|
'unsubscribeUsersFromSessionParamsList', |
5630
|
|
|
'complexType', |
5631
|
|
|
'array', |
5632
|
|
|
'', |
5633
|
|
|
'SOAP-ENC:Array', |
5634
|
|
|
[], |
5635
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:unsubscribeUsersFromSessionParams[]']], |
5636
|
|
|
'tns:unsubscribeUsersFromSessionParams' |
5637
|
|
|
); |
5638
|
|
|
|
5639
|
|
|
$server->wsdl->addComplexType( |
5640
|
|
|
'unsubscribeUsersFromSession', |
5641
|
|
|
'complexType', |
5642
|
|
|
'struct', |
5643
|
|
|
'all', |
5644
|
|
|
'', |
5645
|
|
|
[ |
5646
|
|
|
'userssessions' => ['name' => 'userssessions', 'type' => 'tns:subscribeUsersToSessionParamsList'], |
5647
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
5648
|
|
|
] |
5649
|
|
|
); |
5650
|
|
|
|
5651
|
|
|
// Prepare output params, in this case will return an array |
5652
|
|
|
$server->wsdl->addComplexType( |
5653
|
|
|
'result_unsubscribeUsersFromSession', |
5654
|
|
|
'complexType', |
5655
|
|
|
'struct', |
5656
|
|
|
'all', |
5657
|
|
|
'', |
5658
|
|
|
[ |
5659
|
|
|
'original_user_id_values' => ['name' => 'original_user_id_values', 'type' => 'xsd:string'], |
5660
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
5661
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
5662
|
|
|
] |
5663
|
|
|
); |
5664
|
|
|
|
5665
|
|
|
$server->wsdl->addComplexType( |
5666
|
|
|
'results_unsubscribeUsersFromSession', |
5667
|
|
|
'complexType', |
5668
|
|
|
'array', |
5669
|
|
|
'', |
5670
|
|
|
'SOAP-ENC:Array', |
5671
|
|
|
[], |
5672
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_unsubscribeUsersFromSession[]']], |
5673
|
|
|
'tns:result_unsubscribeUsersFromSession' |
5674
|
|
|
); |
5675
|
|
|
|
5676
|
|
|
// Register the method to expose |
5677
|
|
|
$server->register( |
5678
|
|
|
'WSUnsuscribeUsersFromSession', // method name |
5679
|
|
|
['unsubscribeUsersFromSession' => 'tns:unsubscribeUsersFromSession'], // input parameters |
5680
|
|
|
['return' => 'tns:results_unsubscribeUsersFromSession'], // output parameters |
5681
|
|
|
'urn:WSRegistration', // namespace |
5682
|
|
|
'urn:WSRegistration#WSUnsuscribeUsersFromSession', // soapaction |
5683
|
|
|
'rpc', // style |
5684
|
|
|
'encoded', // use |
5685
|
|
|
'This service unsubscribes a user to a session' // documentation |
5686
|
|
|
); |
5687
|
|
|
|
5688
|
|
|
// define the method WSUnsuscribeUsersFromSession |
5689
|
|
|
function WSUnsuscribeUsersFromSession($params) |
5690
|
|
|
{ |
5691
|
|
|
if (!WSHelperVerifyKey($params)) { |
5692
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
5693
|
|
|
} |
5694
|
|
|
|
5695
|
|
|
global $debug; |
5696
|
|
|
|
5697
|
|
|
if ($debug) { |
5698
|
|
|
error_log('WSUnsuscribeUsersFromSession with params=['.serialize($params).']'); |
5699
|
|
|
} |
5700
|
|
|
|
5701
|
|
|
$user_table = Database::get_main_table(TABLE_MAIN_USER); |
5702
|
|
|
|
5703
|
|
|
$userssessions_params = $params['userssessions']; |
5704
|
|
|
$results = []; |
5705
|
|
|
$orig_user_id_value = []; |
5706
|
|
|
$orig_session_id_value = []; |
5707
|
|
|
|
5708
|
|
|
foreach ($userssessions_params as $usersession_params) { |
5709
|
|
|
$original_session_id_value = $usersession_params['original_session_id_value']; |
5710
|
|
|
$original_session_id_name = $usersession_params['original_session_id_name']; |
5711
|
|
|
$original_user_id_name = $usersession_params['original_user_id_name']; |
5712
|
|
|
$original_user_id_values = $usersession_params['original_user_id_values']; |
5713
|
|
|
|
5714
|
|
|
$id_session = SessionManager::getSessionIdFromOriginalId( |
5715
|
|
|
$original_session_id_value, |
5716
|
|
|
$original_session_id_name |
5717
|
|
|
); |
5718
|
|
|
|
5719
|
|
|
if (empty($id_session)) { |
5720
|
|
|
$orig_session_id_value[] = $original_session_id_value; |
5721
|
|
|
$results[] = 0; |
5722
|
|
|
continue; |
5723
|
|
|
} |
5724
|
|
|
|
5725
|
|
|
foreach ($original_user_id_values as $key => $row_original_user_list) { |
5726
|
|
|
$orig_session_id_value[] = $original_session_id_value; |
5727
|
|
|
$orig_user_id_value[] = $row_original_user_list['original_user_id_value']; |
5728
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
5729
|
|
|
$row_original_user_list['original_user_id_value'], |
5730
|
|
|
$original_user_id_name |
5731
|
|
|
); |
5732
|
|
|
|
5733
|
|
|
if ($user_id == 0) { |
5734
|
|
|
$results[] = 0; |
5735
|
|
|
continue; // user_id doesn't exist. |
5736
|
|
|
} else { |
5737
|
|
|
$sql = "SELECT user_id FROM $user_table |
5738
|
|
|
WHERE user_id ='".$user_id."' AND active= '0'"; |
5739
|
|
|
$resu = Database::query($sql); |
5740
|
|
|
$r_check_user = Database::fetch_row($resu); |
5741
|
|
|
if (!empty($r_check_user[0])) { |
5742
|
|
|
$results[] = 0; |
5743
|
|
|
continue; // user_id is not active. |
5744
|
|
|
} |
5745
|
|
|
|
5746
|
|
|
SessionManager::unsubscribe_user_from_session( |
5747
|
|
|
$id_session, |
5748
|
|
|
$user_id |
5749
|
|
|
); |
5750
|
|
|
|
5751
|
|
|
$results[] = 1; |
5752
|
|
|
|
5753
|
|
|
if ($debug) { |
5754
|
|
|
error_log("Unsubscribe user:$user_id to session:$id_session"); |
5755
|
|
|
} |
5756
|
|
|
} |
5757
|
|
|
} |
5758
|
|
|
} // end principal foreach |
5759
|
|
|
|
5760
|
|
|
$count_results = count($results); |
5761
|
|
|
$output = []; |
5762
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
5763
|
|
|
$output[] = [ |
5764
|
|
|
'original_user_id_values' => $orig_user_id_value[$i], |
5765
|
|
|
'original_session_id_value' => $orig_session_id_value[$i], |
5766
|
|
|
'result' => $results[$i], |
5767
|
|
|
]; |
5768
|
|
|
} |
5769
|
|
|
|
5770
|
|
|
return $output; |
5771
|
|
|
} |
5772
|
|
|
|
5773
|
|
|
/* Register WSSuscribeCoursesToSession function */ |
5774
|
|
|
// Register the data structures used by the service |
5775
|
|
|
|
5776
|
|
|
/*$server->wsdl->addComplexType( |
5777
|
|
|
'originalCoursesList', |
5778
|
|
|
'complexType', |
5779
|
|
|
'array', |
5780
|
|
|
'', |
5781
|
|
|
'SOAP-ENC:Array', |
5782
|
|
|
array(), |
5783
|
|
|
array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'string[]')), |
5784
|
|
|
'xsd:string' |
5785
|
|
|
);*/ |
5786
|
|
|
$server->wsdl->addComplexType( |
5787
|
|
|
'course_code_type', |
5788
|
|
|
'complexType', |
5789
|
|
|
'struct', |
5790
|
|
|
'all', |
5791
|
|
|
'', |
5792
|
|
|
[ |
5793
|
|
|
'course_code' => ['name' => 'course_code', 'type' => 'xsd:string'], |
5794
|
|
|
] |
5795
|
|
|
); |
5796
|
|
|
|
5797
|
|
|
$server->wsdl->addComplexType( |
5798
|
|
|
'originalCoursesList', |
5799
|
|
|
'complexType', |
5800
|
|
|
'array', |
5801
|
|
|
'', |
5802
|
|
|
'SOAP-ENC:Array', |
5803
|
|
|
[], |
5804
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:course_code_type[]']], |
5805
|
|
|
'tns:course_code_type' |
5806
|
|
|
); |
5807
|
|
|
|
5808
|
|
|
$server->wsdl->addComplexType( |
5809
|
|
|
'subscribeCoursesToSessionParamsList', |
5810
|
|
|
'complexType', |
5811
|
|
|
'array', |
5812
|
|
|
'', |
5813
|
|
|
'SOAP-ENC:Array', |
5814
|
|
|
[], |
5815
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:subscribeCoursesToSessionParams[]']], |
5816
|
|
|
'tns:subscribeCoursesToSessionParams' |
5817
|
|
|
); |
5818
|
|
|
|
5819
|
|
|
$server->wsdl->addComplexType( |
5820
|
|
|
'subscribeCoursesToSessionParams', |
5821
|
|
|
'complexType', |
5822
|
|
|
'struct', |
5823
|
|
|
'all', |
5824
|
|
|
'', |
5825
|
|
|
[ |
5826
|
|
|
'original_course_id_values' => ['name' => 'original_course_id_values', 'type' => 'tns:originalCoursesList'], |
5827
|
|
|
'original_course_id_name' => ['name' => 'original_course_id_name', 'type' => 'xsd:string'], |
5828
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
5829
|
|
|
'original_session_id_name' => ['name' => 'original_session_id_name', 'type' => 'xsd:string'], |
5830
|
|
|
] |
5831
|
|
|
); |
5832
|
|
|
|
5833
|
|
|
$server->wsdl->addComplexType( |
5834
|
|
|
'subscribeCoursesToSessionParamsList', |
5835
|
|
|
'complexType', |
5836
|
|
|
'array', |
5837
|
|
|
'', |
5838
|
|
|
'SOAP-ENC:Array', |
5839
|
|
|
[], |
5840
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:subscribeCoursesToSessionParams[]']], |
5841
|
|
|
'tns:subscribeCoursesToSessionParams' |
5842
|
|
|
); |
5843
|
|
|
|
5844
|
|
|
$server->wsdl->addComplexType( |
5845
|
|
|
'subscribeCoursesToSession', |
5846
|
|
|
'complexType', |
5847
|
|
|
'struct', |
5848
|
|
|
'all', |
5849
|
|
|
'', |
5850
|
|
|
[ |
5851
|
|
|
'coursessessions' => ['name' => 'coursessessions', 'type' => 'tns:subscribeCoursesToSessionParamsList'], |
5852
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
5853
|
|
|
] |
5854
|
|
|
); |
5855
|
|
|
|
5856
|
|
|
// Prepare output params, in this case will return an array |
5857
|
|
|
$server->wsdl->addComplexType( |
5858
|
|
|
'result_subscribeCoursesToSession', |
5859
|
|
|
'complexType', |
5860
|
|
|
'struct', |
5861
|
|
|
'all', |
5862
|
|
|
'', |
5863
|
|
|
[ |
5864
|
|
|
'original_course_id_values' => ['name' => 'original_course_id_values', 'type' => 'xsd:string'], |
5865
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
5866
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
5867
|
|
|
] |
5868
|
|
|
); |
5869
|
|
|
|
5870
|
|
|
$server->wsdl->addComplexType( |
5871
|
|
|
'results_subscribeCoursesToSession', |
5872
|
|
|
'complexType', |
5873
|
|
|
'array', |
5874
|
|
|
'', |
5875
|
|
|
'SOAP-ENC:Array', |
5876
|
|
|
[], |
5877
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_subscribeCoursesToSession[]']], |
5878
|
|
|
'tns:result_subscribeCoursesToSession' |
5879
|
|
|
); |
5880
|
|
|
|
5881
|
|
|
// Register the method to expose |
5882
|
|
|
$server->register( |
5883
|
|
|
'WSSuscribeCoursesToSession', // method name |
5884
|
|
|
['subscribeCoursesToSession' => 'tns:subscribeCoursesToSession'], // input parameters |
5885
|
|
|
['return' => 'tns:results_subscribeCoursesToSession'], // output parameters |
5886
|
|
|
'urn:WSRegistration', // namespace |
5887
|
|
|
'urn:WSRegistration#WSSuscribeCoursesToSession', // soapaction |
5888
|
|
|
'rpc', // style |
5889
|
|
|
'encoded', // use |
5890
|
|
|
'This service subscribes a course to a session' // documentation |
5891
|
|
|
); |
5892
|
|
|
|
5893
|
|
|
// Define the method WSSuscribeCoursesToSession |
5894
|
|
|
function WSSuscribeCoursesToSession($params) |
5895
|
|
|
{ |
5896
|
|
|
global $debug; |
5897
|
|
|
|
5898
|
|
|
if (!WSHelperVerifyKey($params)) { |
5899
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
5900
|
|
|
} |
5901
|
|
|
|
5902
|
|
|
if ($debug) { |
5903
|
|
|
error_log('WSSuscribeCoursesToSession: '.print_r($params, 1)); |
5904
|
|
|
} |
5905
|
|
|
|
5906
|
|
|
$coursessessions_params = $params['coursessessions']; |
5907
|
|
|
$results = []; |
5908
|
|
|
$orig_course_id_value = []; |
5909
|
|
|
$orig_session_id_value = []; |
5910
|
|
|
foreach ($coursessessions_params as $coursesession_param) { |
5911
|
|
|
$original_session_id_value = $coursesession_param['original_session_id_value']; |
5912
|
|
|
$original_session_id_name = $coursesession_param['original_session_id_name']; |
5913
|
|
|
$original_course_id_name = $coursesession_param['original_course_id_name']; |
5914
|
|
|
$original_course_id_values = $coursesession_param['original_course_id_values']; |
5915
|
|
|
|
5916
|
|
|
$sessionId = SessionManager::getSessionIdFromOriginalId( |
5917
|
|
|
$original_session_id_value, |
5918
|
|
|
$original_session_id_name |
5919
|
|
|
); |
5920
|
|
|
|
5921
|
|
|
if (empty($sessionId)) { |
5922
|
|
|
$orig_session_id_value[] = $original_session_id_value; |
5923
|
|
|
$results[] = 0; |
5924
|
|
|
continue; |
5925
|
|
|
} |
5926
|
|
|
|
5927
|
|
|
// Get course list from row_original_course_id_values |
5928
|
|
|
foreach ($original_course_id_values as $row_original_course_list) { |
5929
|
|
|
$orig_session_id_value[] = $original_session_id_value; |
5930
|
|
|
$orig_course_id_value[] = $row_original_course_list['course_code']; |
5931
|
|
|
|
5932
|
|
|
$courseInfo = CourseManager::getCourseInfoFromOriginalId( |
5933
|
|
|
$row_original_course_list['course_code'], |
5934
|
|
|
$original_course_id_name |
5935
|
|
|
); |
5936
|
|
|
|
5937
|
|
|
if (empty($courseInfo) || |
5938
|
|
|
(isset($courseInfo) && $courseInfo['visibility'] == 0) |
5939
|
|
|
) { |
5940
|
|
|
$results[] = 0; |
5941
|
|
|
continue; // Original_course_id_value doesn't exist. |
5942
|
|
|
} else { |
5943
|
|
|
$courseCode = $courseInfo['code']; |
5944
|
|
|
SessionManager::add_courses_to_session( |
5945
|
|
|
$sessionId, |
5946
|
|
|
[$courseInfo['real_id']], |
5947
|
|
|
false |
5948
|
|
|
); |
5949
|
|
|
if ($debug) { |
5950
|
|
|
error_log("add_courses_to_session: course:$courseCode to session:$sessionId"); |
5951
|
|
|
} |
5952
|
|
|
|
5953
|
|
|
$results[] = 1; |
5954
|
|
|
} |
5955
|
|
|
} |
5956
|
|
|
} |
5957
|
|
|
|
5958
|
|
|
$count_results = count($results); |
5959
|
|
|
$output = []; |
5960
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
5961
|
|
|
$output[] = [ |
5962
|
|
|
'original_course_id_values' => $orig_course_id_value[$i], |
5963
|
|
|
'original_session_id_value' => $orig_session_id_value[$i], |
5964
|
|
|
'result' => $results[$i], |
5965
|
|
|
]; |
5966
|
|
|
} |
5967
|
|
|
|
5968
|
|
|
return $output; |
5969
|
|
|
} |
5970
|
|
|
|
5971
|
|
|
/* Register WSUnsuscribeCoursesFromSession function */ |
5972
|
|
|
// Register the data structures used by the service |
5973
|
|
|
$server->wsdl->addComplexType( |
5974
|
|
|
'unsubscribeCoursesFromSessionParams', |
5975
|
|
|
'complexType', |
5976
|
|
|
'struct', |
5977
|
|
|
'all', |
5978
|
|
|
'', |
5979
|
|
|
[ |
5980
|
|
|
'original_course_id_values' => ['name' => 'original_course_id_values', 'type' => 'tns:originalCoursesList'], |
5981
|
|
|
'original_course_id_name' => ['name' => 'original_course_id_name', 'type' => 'xsd:string'], |
5982
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
5983
|
|
|
'original_session_id_name' => ['name' => 'original_session_id_name', 'type' => 'xsd:string'], |
5984
|
|
|
] |
5985
|
|
|
); |
5986
|
|
|
|
5987
|
|
|
$server->wsdl->addComplexType( |
5988
|
|
|
'unsubscribeCoursesFromSessionParamsList', |
5989
|
|
|
'complexType', |
5990
|
|
|
'array', |
5991
|
|
|
'', |
5992
|
|
|
'SOAP-ENC:Array', |
5993
|
|
|
[], |
5994
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:unsubscribeCoursesFromSessionParams[]']], |
5995
|
|
|
'tns:unsubscribeCoursesFromSessionParams' |
5996
|
|
|
); |
5997
|
|
|
|
5998
|
|
|
$server->wsdl->addComplexType( |
5999
|
|
|
'unsubscribeCoursesFromSession', |
6000
|
|
|
'complexType', |
6001
|
|
|
'struct', |
6002
|
|
|
'all', |
6003
|
|
|
'', |
6004
|
|
|
[ |
6005
|
|
|
'coursessessions' => ['name' => 'coursessessions', 'type' => 'tns:unsubscribeCoursesFromSessionParamsList'], |
6006
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
6007
|
|
|
] |
6008
|
|
|
); |
6009
|
|
|
|
6010
|
|
|
// Prepare output params, in this case will return an array |
6011
|
|
|
$server->wsdl->addComplexType( |
6012
|
|
|
'result_unsubscribeCoursesFromSession', |
6013
|
|
|
'complexType', |
6014
|
|
|
'struct', |
6015
|
|
|
'all', |
6016
|
|
|
'', |
6017
|
|
|
[ |
6018
|
|
|
'original_course_id_values' => ['name' => 'original_course_id_values', 'type' => 'xsd:string'], |
6019
|
|
|
'original_session_id_value' => ['name' => 'original_session_id_value', 'type' => 'xsd:string'], |
6020
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:string'], |
6021
|
|
|
] |
6022
|
|
|
); |
6023
|
|
|
|
6024
|
|
|
$server->wsdl->addComplexType( |
6025
|
|
|
'results_unsubscribeCoursesFromSession', |
6026
|
|
|
'complexType', |
6027
|
|
|
'array', |
6028
|
|
|
'', |
6029
|
|
|
'SOAP-ENC:Array', |
6030
|
|
|
[], |
6031
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:result_unsubscribeCoursesFromSession[]']], |
6032
|
|
|
'tns:result_unsubscribeCoursesFromSession' |
6033
|
|
|
); |
6034
|
|
|
|
6035
|
|
|
// Register the method to expose |
6036
|
|
|
$server->register( |
6037
|
|
|
'WSUnsuscribeCoursesFromSession', // method name |
6038
|
|
|
['unsubscribeCoursesFromSession' => 'tns:unsubscribeCoursesFromSession'], // input parameters |
6039
|
|
|
['return' => 'tns:results_unsubscribeCoursesFromSession'], // output parameters |
6040
|
|
|
'urn:WSRegistration', // namespace |
6041
|
|
|
'urn:WSRegistration#WSUnsuscribeCoursesFromSession', // soapaction |
6042
|
|
|
'rpc', // style |
6043
|
|
|
'encoded', // use |
6044
|
|
|
'This service subscribes a course to a session' // documentation |
6045
|
|
|
); |
6046
|
|
|
|
6047
|
|
|
// define the method WSUnsuscribeCoursesFromSession |
6048
|
|
|
function WSUnsuscribeCoursesFromSession($params) |
6049
|
|
|
{ |
6050
|
|
|
if (!WSHelperVerifyKey($params)) { |
6051
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
6052
|
|
|
} |
6053
|
|
|
|
6054
|
|
|
$sessionAdminId = DEFAULT_ADMIN_USER_ID; |
6055
|
|
|
|
6056
|
|
|
// Initialisation |
6057
|
|
|
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); |
6058
|
|
|
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); |
6059
|
|
|
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
6060
|
|
|
$coursessessions_params = $params['coursessessions']; |
6061
|
|
|
$results = []; |
6062
|
|
|
$orig_course_id_value = []; |
6063
|
|
|
$orig_session_id_value = []; |
6064
|
|
|
|
6065
|
|
|
foreach ($coursessessions_params as $coursesession_param) { |
6066
|
|
|
$original_session_id_value = $coursesession_param['original_session_id_value']; |
6067
|
|
|
$original_session_id_name = $coursesession_param['original_session_id_name']; |
6068
|
|
|
$original_course_id_name = $coursesession_param['original_course_id_name']; |
6069
|
|
|
$original_course_id_values = $coursesession_param['original_course_id_values']; |
6070
|
|
|
$orig_session_id_value[] = $original_session_id_value; |
6071
|
|
|
|
6072
|
|
|
$id_session = SessionManager::getSessionIdFromOriginalId( |
6073
|
|
|
$original_session_id_value, |
6074
|
|
|
$original_session_id_name |
6075
|
|
|
); |
6076
|
|
|
|
6077
|
|
|
if (empty($id_session)) { |
6078
|
|
|
$results[] = 0; |
6079
|
|
|
continue; |
6080
|
|
|
} |
6081
|
|
|
|
6082
|
|
|
// Get courses list from row_original_course_id_values |
6083
|
|
|
$course_list = []; |
6084
|
|
|
$courseIdList = []; |
6085
|
|
|
foreach ($original_course_id_values as $row_original_course_list) { |
6086
|
|
|
$course_code = Database::escape_string($row_original_course_list['course_code']); |
6087
|
|
|
|
6088
|
|
|
// Check whether exits $x_course_code into user_field_values table. |
6089
|
|
|
$courseInfo = CourseManager::getCourseInfoFromOriginalId( |
6090
|
|
|
$row_original_course_list['course_code'], |
6091
|
|
|
$original_course_id_name |
6092
|
|
|
); |
6093
|
|
|
|
6094
|
|
|
if (empty($courseInfo) || isset($courseInfo) && |
6095
|
|
|
$courseInfo['visibility'] == 0 |
6096
|
|
|
) { |
6097
|
|
|
continue; // Course_code doesn't exist' |
6098
|
|
|
} |
6099
|
|
|
|
6100
|
|
|
$course_list[] = $courseInfo['code']; |
6101
|
|
|
$courseIdList[] = $courseInfo['real_id']; |
6102
|
|
|
} |
6103
|
|
|
|
6104
|
|
|
if (empty($course_list)) { |
6105
|
|
|
$results[] = 0; |
6106
|
|
|
continue; |
6107
|
|
|
} |
6108
|
|
|
|
6109
|
|
|
$orig_course_id_value[] = implode(',', $course_list); |
6110
|
|
|
|
6111
|
|
|
foreach ($courseIdList as $courseId) { |
6112
|
|
|
$courseId = intval($courseId); |
6113
|
|
|
Database::query("DELETE FROM $tbl_session_rel_course |
6114
|
|
|
WHERE c_id ='$courseId' AND session_id='$id_session'"); |
6115
|
|
|
$result = Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE c_id='$courseId' AND session_id = '$id_session'"); |
6116
|
|
|
|
6117
|
|
|
Event::addEvent( |
6118
|
|
|
LOG_SESSION_DELETE_COURSE, |
6119
|
|
|
LOG_COURSE_ID, |
6120
|
|
|
$courseId, |
6121
|
|
|
api_get_utc_datetime(), |
6122
|
|
|
$sessionAdminId, |
6123
|
|
|
$courseId, |
6124
|
|
|
$id_session |
6125
|
|
|
); |
6126
|
|
|
|
6127
|
|
|
$return = Database::affected_rows($result); |
6128
|
|
|
} |
6129
|
|
|
|
6130
|
|
|
$nbr_courses = 0; |
6131
|
|
|
$sql = "SELECT nbr_courses FROM $tbl_session WHERE id = '$id_session'"; |
6132
|
|
|
$res_nbr_courses = Database::query($sql); |
6133
|
|
|
$row_nbr_courses = Database::fetch_row($res_nbr_courses); |
6134
|
|
|
|
6135
|
|
|
if (Database::num_rows($res_nbr_courses) > 0) { |
6136
|
|
|
$nbr_users = ($row_nbr_courses[0] - $return); |
6137
|
|
|
} |
6138
|
|
|
|
6139
|
|
|
// Update number of users in the session. |
6140
|
|
|
$update_sql = "UPDATE $tbl_session SET nbr_courses= $nbr_courses WHERE id='$id_session' "; |
6141
|
|
|
Database::query($update_sql); |
6142
|
|
|
|
6143
|
|
|
$results[] = 1; |
6144
|
|
|
continue; |
6145
|
|
|
} |
6146
|
|
|
|
6147
|
|
|
$count_results = count($results); |
6148
|
|
|
$output = []; |
6149
|
|
|
for ($i = 0; $i < $count_results; $i++) { |
6150
|
|
|
$output[] = [ |
6151
|
|
|
'original_course_id_values' => $orig_course_id_value[$i], |
6152
|
|
|
'original_session_id_value' => $orig_session_id_value[$i], |
6153
|
|
|
'result' => $results[$i], |
6154
|
|
|
]; |
6155
|
|
|
} |
6156
|
|
|
|
6157
|
|
|
return $output; |
6158
|
|
|
} |
6159
|
|
|
|
6160
|
|
|
/** WSListCourses */ |
6161
|
|
|
$server->wsdl->addComplexType( |
6162
|
|
|
'listCourseInput', |
6163
|
|
|
'complexType', |
6164
|
|
|
'struct', |
6165
|
|
|
'all', |
6166
|
|
|
'', |
6167
|
|
|
[ |
6168
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
6169
|
|
|
'original_course_id_name' => ['name' => 'original_course_id_name', 'type' => 'xsd:string'], |
6170
|
|
|
'from' => ['name' => 'from', 'type' => 'xsd:int'], |
6171
|
|
|
'to' => ['name' => 'to', 'type' => 'xsd:int'], |
6172
|
|
|
] |
6173
|
|
|
); |
6174
|
|
|
|
6175
|
|
|
$server->wsdl->addComplexType( |
6176
|
|
|
'course', |
6177
|
|
|
'complexType', |
6178
|
|
|
'struct', |
6179
|
|
|
'all', |
6180
|
|
|
'', |
6181
|
|
|
[ |
6182
|
|
|
'id' => ['name' => 'id', 'type' => 'xsd:int'], |
6183
|
|
|
'code' => ['name' => 'code', 'type' => 'xsd:string'], |
6184
|
|
|
'external_course_id' => ['name' => 'external_course_id', 'type' => 'xsd:string'], |
6185
|
|
|
'title' => ['name' => 'title', 'type' => 'xsd:string'], |
6186
|
|
|
'language' => ['name' => 'language', 'type' => 'xsd:string'], |
6187
|
|
|
'category_name' => ['name' => 'category_name', 'type' => 'xsd:string'], |
6188
|
|
|
'visibility' => ['name' => 'visibility', 'type' => 'xsd:int'], |
6189
|
|
|
'number_students' => ['name' => 'number_students', 'type' => 'xsd:int'], |
6190
|
|
|
] |
6191
|
|
|
); |
6192
|
|
|
|
6193
|
|
|
$server->wsdl->addComplexType( |
6194
|
|
|
'courses', |
6195
|
|
|
'complexType', |
6196
|
|
|
'array', |
6197
|
|
|
'', |
6198
|
|
|
'SOAP-ENC:Array', |
6199
|
|
|
[], |
6200
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:course[]']], |
6201
|
|
|
'tns:course' |
6202
|
|
|
); |
6203
|
|
|
|
6204
|
|
|
// Register the method to expose |
6205
|
|
|
$server->register( |
6206
|
|
|
'WSListCourses', // method name |
6207
|
|
|
['listCourseInput' => 'tns:listCourseInput'], // input parameters |
6208
|
|
|
['return' => 'tns:courses'], // output parameters |
6209
|
|
|
'urn:WSRegistration', // namespace |
6210
|
|
|
'urn:WSRegistration#WSListCourses', // soapaction |
6211
|
|
|
'rpc', // style |
6212
|
|
|
'encoded', // use |
6213
|
|
|
'This service list courses available on the system' // documentation |
6214
|
|
|
); |
6215
|
|
|
|
6216
|
|
|
// define the method WSListCourses |
6217
|
|
|
function WSListCourses($params) |
6218
|
|
|
{ |
6219
|
|
|
global $debug; |
6220
|
|
|
if (!WSHelperVerifyKey($params)) { |
6221
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
6222
|
|
|
} |
6223
|
|
|
|
6224
|
|
|
$course_field_name = isset($params['original_course_id_name']) ? $params['original_course_id_name'] : ''; |
6225
|
|
|
|
6226
|
|
|
$courses_result = []; |
6227
|
|
|
$category_names = []; |
6228
|
|
|
|
6229
|
|
|
$from = isset($params['from']) ? $params['from'] : null; |
6230
|
|
|
$to = isset($params['to']) ? $params['to'] : null; |
6231
|
|
|
|
6232
|
|
|
if ($debug) { |
6233
|
|
|
error_log(print_r($params, 1)); |
6234
|
|
|
error_log($from); |
6235
|
|
|
error_log($to); |
6236
|
|
|
} |
6237
|
|
|
|
6238
|
|
|
$courses = CourseManager::get_courses_list($from, $to); |
6239
|
|
|
|
6240
|
|
|
foreach ($courses as $course) { |
6241
|
|
|
$course_tmp = []; |
6242
|
|
|
$course_tmp['id'] = $course['id']; |
6243
|
|
|
$course_tmp['code'] = $course['code']; |
6244
|
|
|
$course_tmp['title'] = $course['title']; |
6245
|
|
|
$course_tmp['language'] = $course['course_language']; |
6246
|
|
|
$course_tmp['visibility'] = $course['visibility']; |
6247
|
|
|
$course_tmp['category_name'] = ''; |
6248
|
|
|
|
6249
|
|
|
// Determining category name |
6250
|
|
|
if (!empty($course['category_code']) && |
6251
|
|
|
isset($category_names[$course['category_code']]) |
6252
|
|
|
) { |
6253
|
|
|
$course_tmp['category_name'] = $category_names[$course['category_code']]; |
6254
|
|
|
} else { |
6255
|
|
|
$category = CourseManager::get_course_category($course['category_code']); |
6256
|
|
|
if ($category) { |
6257
|
|
|
$category_names[$course['category_code']] = $category['name']; |
6258
|
|
|
$course_tmp['category_name'] = $category['name']; |
6259
|
|
|
} |
6260
|
|
|
} |
6261
|
|
|
|
6262
|
|
|
// Determining number of students registered in course |
6263
|
|
|
$course_tmp['number_students'] = CourseManager::get_users_count_in_course( |
6264
|
|
|
$course['code'] |
6265
|
|
|
); |
6266
|
|
|
|
6267
|
|
|
// Determining external course id |
6268
|
|
|
$externalCourseId = ''; |
6269
|
|
|
if ($course_field_name) { |
6270
|
|
|
$externalCourseId = CourseManager::get_course_extra_field_value( |
6271
|
|
|
$course_field_name, |
6272
|
|
|
$course['code'] |
6273
|
|
|
); |
6274
|
|
|
} |
6275
|
|
|
|
6276
|
|
|
$course_tmp['external_course_id'] = $externalCourseId; |
6277
|
|
|
$courses_result[] = $course_tmp; |
6278
|
|
|
} |
6279
|
|
|
|
6280
|
|
|
return $courses_result; |
6281
|
|
|
} |
6282
|
|
|
|
6283
|
|
|
/* Get user api key */ |
6284
|
|
|
$server->wsdl->addComplexType( |
6285
|
|
|
'userApiKey', |
6286
|
|
|
'complexType', |
6287
|
|
|
'struct', |
6288
|
|
|
'all', |
6289
|
|
|
'', |
6290
|
|
|
[ |
6291
|
|
|
'original_user_id_name' => ['name' => 'original_user_id_name', 'type' => 'xsd:string'], |
6292
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
6293
|
|
|
'chamilo_username' => ['name' => 'chamilo_username', 'type' => 'xsd:string'], |
6294
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
6295
|
|
|
] |
6296
|
|
|
); |
6297
|
|
|
|
6298
|
|
|
// Register the method to expose |
6299
|
|
|
$server->register( |
6300
|
|
|
'WSUpdateUserApiKey', // method name |
6301
|
|
|
['userApiKey' => 'tns:userApiKey'], // input parameters |
6302
|
|
|
['return' => 'xsd:string'], // output parameters |
6303
|
|
|
'urn:WSRegistration', // namespace |
6304
|
|
|
'urn:WSRegistration#WSListCourses', // soapaction |
6305
|
|
|
'rpc', // style |
6306
|
|
|
'encoded', // use |
6307
|
|
|
'This service return user api key' // documentation |
6308
|
|
|
); |
6309
|
|
|
|
6310
|
|
|
/** |
6311
|
|
|
* @param array $params |
6312
|
|
|
* |
6313
|
|
|
* @return int|soap_fault|null |
6314
|
|
|
*/ |
6315
|
|
|
function WSUpdateUserApiKey($params) |
6316
|
|
|
{ |
6317
|
|
|
if (!WSHelperVerifyKey($params)) { |
6318
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
6319
|
|
|
} |
6320
|
|
|
|
6321
|
|
|
$user_id = UserManager::get_user_id_from_original_id( |
6322
|
|
|
$params['original_user_id_value'], |
6323
|
|
|
$params['original_user_id_name'] |
6324
|
|
|
); |
6325
|
|
|
if (!$user_id) { |
6326
|
|
|
if (!empty($params['chamilo_username'])) { |
6327
|
|
|
$info = api_get_user_info_from_username($params['chamilo_username']); |
6328
|
|
|
$user_id = $info['user_id']; |
6329
|
|
|
// Save new fieldlabel into user_field table. |
6330
|
|
|
UserManager::create_extra_field($params['original_user_id_name'], 1, $params['original_user_id_name'], ''); |
6331
|
|
|
// Save the external system's id into user_field_value table. |
6332
|
|
|
UserManager::update_extra_field_value( |
6333
|
|
|
$user_id, |
6334
|
|
|
$params['original_user_id_name'], |
6335
|
|
|
$params['original_user_id_value'] |
6336
|
|
|
); |
6337
|
|
|
} else { |
6338
|
|
|
return 0; |
6339
|
|
|
} |
6340
|
|
|
} |
6341
|
|
|
|
6342
|
|
|
$list = UserManager::get_api_keys($user_id); |
6343
|
|
|
$key_id = UserManager::get_api_key_id($user_id, 'dokeos'); |
6344
|
|
|
|
6345
|
|
|
if (isset($list[$key_id])) { |
6346
|
|
|
$apikey = $list[$key_id]; |
6347
|
|
|
} else { |
6348
|
|
|
$lastid = UserManager::update_api_key($user_id, 'dokeos'); |
6349
|
|
|
if ($lastid) { |
6350
|
|
|
$apikeys = UserManager::get_api_keys($user_id); |
6351
|
|
|
$apikey = $apikeys[$lastid]; |
6352
|
|
|
} |
6353
|
|
|
} |
6354
|
|
|
|
6355
|
|
|
return $apikey; |
6356
|
|
|
} |
6357
|
|
|
|
6358
|
|
|
/** WSListSessions */ |
6359
|
|
|
$server->wsdl->addComplexType( |
6360
|
|
|
'session_arg', |
6361
|
|
|
'complexType', |
6362
|
|
|
'struct', |
6363
|
|
|
'all', |
6364
|
|
|
'', |
6365
|
|
|
[ |
6366
|
|
|
'from' => ['name' => 'from', 'type' => 'xsd:int'], |
6367
|
|
|
'to' => ['name' => 'to', 'type' => 'xsd:int'], |
6368
|
|
|
'date_start' => ['name' => 'date_start', 'type' => 'xsd:string'], |
6369
|
|
|
'date_end' => ['name' => 'date_end', 'type' => 'xsd:string'], |
6370
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
6371
|
|
|
] |
6372
|
|
|
); |
6373
|
|
|
|
6374
|
|
|
$server->wsdl->addComplexType( |
6375
|
|
|
'session', |
6376
|
|
|
'complexType', |
6377
|
|
|
'struct', |
6378
|
|
|
'all', |
6379
|
|
|
'', |
6380
|
|
|
[ |
6381
|
|
|
'id' => ['name' => 'id', 'type' => 'xsd:int'], |
6382
|
|
|
'title' => ['name' => 'title', 'type' => 'xsd:string'], |
6383
|
|
|
'url' => ['name' => 'url', 'type' => 'xsd:string'], |
6384
|
|
|
'date_start' => ['name' => 'date_start', 'type' => 'xsd:string'], |
6385
|
|
|
'date_end' => ['name' => 'date_end', 'type' => 'xsd:string'], |
6386
|
|
|
] |
6387
|
|
|
); |
6388
|
|
|
|
6389
|
|
|
$server->wsdl->addComplexType( |
6390
|
|
|
'sessions', |
6391
|
|
|
'complexType', |
6392
|
|
|
'array', |
6393
|
|
|
'', |
6394
|
|
|
'SOAP-ENC:Array', |
6395
|
|
|
[], |
6396
|
|
|
[ |
6397
|
|
|
['ref' => 'SOAP-ENC:arrayType', |
6398
|
|
|
'wsdl:arrayType' => 'tns:session[]', ], |
6399
|
|
|
], |
6400
|
|
|
'tns:session' |
6401
|
|
|
); |
6402
|
|
|
|
6403
|
|
|
// Register the method to expose |
6404
|
|
|
$server->register( |
6405
|
|
|
'WSListSessions', // method name |
6406
|
|
|
['input' => 'tns:session_arg'], // input parameters |
6407
|
|
|
['return' => 'tns:sessions'], // output parameters |
6408
|
|
|
'urn:WSRegistration', // namespace |
6409
|
|
|
'urn:WSRegistration#WSListSessions', // soapaction |
6410
|
|
|
'rpc', // style |
6411
|
|
|
'encoded', // use |
6412
|
|
|
'This service returns a list of sessions' // documentation |
6413
|
|
|
); |
6414
|
|
|
|
6415
|
|
|
/** |
6416
|
|
|
* Get a list of sessions (id, title, url, date_start, date_end) and |
6417
|
|
|
* return to caller. Date start can be set to ask only for the sessions |
6418
|
|
|
* starting at or after this date. Date end can be set to ask only for the |
6419
|
|
|
* sessions ending before or at this date. |
6420
|
|
|
* Function registered as service. Returns strings in UTF-8. |
6421
|
|
|
* |
6422
|
|
|
* @param array List of parameters (security key, date_start and date_end) |
6423
|
|
|
* |
6424
|
|
|
* @return array Sessions list (id=>[title=>'title',url='http://...',date_start=>'...',date_end=>'']) |
6425
|
|
|
*/ |
6426
|
|
|
function WSListSessions($params) |
6427
|
|
|
{ |
6428
|
|
|
if (!WSHelperVerifyKey($params)) { |
6429
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
6430
|
|
|
} |
6431
|
|
|
$sql_params = []; |
6432
|
|
|
// Dates should be provided in YYYY-MM-DD format, UTC |
6433
|
|
|
if (!empty($params['date_start'])) { |
6434
|
|
|
$sql_params['s.access_start_date'] = ['operator' => '>=', 'value' => $params['date_start']]; |
6435
|
|
|
} |
6436
|
|
|
if (!empty($params['date_end'])) { |
6437
|
|
|
$sql_params['s.access_end_date'] = ['operator' => '<=', 'value' => $params['date_end']]; |
6438
|
|
|
} |
6439
|
|
|
$from = isset($params['from']) ? $params['from'] : null; |
6440
|
|
|
$to = isset($params['to']) ? $params['to'] : null; |
6441
|
|
|
|
6442
|
|
|
$sessions_list = SessionManager::get_sessions_list($sql_params, null, $from, $to); |
6443
|
|
|
$return_list = []; |
6444
|
|
|
foreach ($sessions_list as $session) { |
6445
|
|
|
$return_list[] = [ |
6446
|
|
|
'id' => $session['id'], |
6447
|
|
|
'title' => $session['name'], |
6448
|
|
|
// something like http://my.chamilo.net/main/session/index.php?session_id=5 |
6449
|
|
|
'url' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session['id'], |
6450
|
|
|
'date_start' => $session['access_start_date'], |
6451
|
|
|
'date_end' => $session['access_end_date'], |
6452
|
|
|
]; |
6453
|
|
|
} |
6454
|
|
|
|
6455
|
|
|
return $return_list; |
6456
|
|
|
} |
6457
|
|
|
|
6458
|
|
|
/* Register WSUserSubscribedInCourse function */ |
6459
|
|
|
// Register the data structures used by the service |
6460
|
|
|
|
6461
|
|
|
//prepare input params |
6462
|
|
|
|
6463
|
|
|
// Input params for editing users |
6464
|
|
|
$server->wsdl->addComplexType( |
6465
|
|
|
'UserSubscribedInCourse', |
6466
|
|
|
'complexType', |
6467
|
|
|
'struct', |
6468
|
|
|
'all', |
6469
|
|
|
'', |
6470
|
|
|
[ |
6471
|
|
|
'course' => ['name' => 'course', 'type' => 'xsd:string'], |
6472
|
|
|
//Course string code |
6473
|
|
|
'user_id' => ['name' => 'user_id', 'type' => 'xsd:string'], |
6474
|
|
|
//Chamilo user_id |
6475
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
6476
|
|
|
] |
6477
|
|
|
); |
6478
|
|
|
|
6479
|
|
|
// Register the method to expose |
6480
|
|
|
$server->register( |
6481
|
|
|
'WSUserSubscribedInCourse', // method name |
6482
|
|
|
['UserSubscribedInCourse' => 'tns:UserSubscribedInCourse'], // input parameters |
6483
|
|
|
['return' => 'xsd:string'], // output parameters |
6484
|
|
|
'urn:WSRegistration', // namespace |
6485
|
|
|
'urn:WSRegistration#WSUserSubscribedInCourse', // soapaction |
6486
|
|
|
'rpc', // style |
6487
|
|
|
'encoded', // use |
6488
|
|
|
'This service checks if user assigned to course' // documentation |
6489
|
|
|
); |
6490
|
|
|
|
6491
|
|
|
/** |
6492
|
|
|
* Web service to tell if a given user is subscribed to the course. |
6493
|
|
|
* |
6494
|
|
|
* @param array $params Array of parameters (course and user_id) |
6495
|
|
|
* |
6496
|
|
|
* @return bool|soap_fault|null A simple boolean (true if user is subscribed, false otherwise) |
6497
|
|
|
*/ |
6498
|
|
|
function WSUserSubscribedInCourse($params) |
6499
|
|
|
{ |
6500
|
|
|
global $debug; |
6501
|
|
|
|
6502
|
|
|
if ($debug) { |
6503
|
|
|
error_log('WSUserSubscribedInCourse'); |
6504
|
|
|
} |
6505
|
|
|
if ($debug) { |
6506
|
|
|
error_log('Params '.print_r($params, 1)); |
6507
|
|
|
} |
6508
|
|
|
if (!WSHelperVerifyKey($params)) { |
6509
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
6510
|
|
|
} |
6511
|
|
|
$courseCode = $params['course']; //Course code |
6512
|
|
|
$userId = $params['user_id']; //chamilo user id |
6513
|
|
|
|
6514
|
|
|
return CourseManager::is_user_subscribed_in_course($userId, $courseCode); |
6515
|
|
|
} |
6516
|
|
|
|
6517
|
|
|
/* Search session Web Service start */ |
6518
|
|
|
|
6519
|
|
|
// Input params for WSSearchSession |
6520
|
|
|
$server->wsdl->addComplexType( |
6521
|
|
|
'SearchSession', |
6522
|
|
|
'complexType', |
6523
|
|
|
'struct', |
6524
|
|
|
'all', |
6525
|
|
|
'', |
6526
|
|
|
[ |
6527
|
|
|
'term' => ['name' => 'term', 'type' => 'xsd:string'], |
6528
|
|
|
'extrafields' => ['name' => 'extrafields', 'type' => 'xsd:string'], |
6529
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
6530
|
|
|
] |
6531
|
|
|
); |
6532
|
|
|
|
6533
|
|
|
//Output params for WSSearchSession |
6534
|
|
|
$server->wsdl->addComplexType( |
6535
|
|
|
'searchedSessionExtra', |
6536
|
|
|
'complexType', |
6537
|
|
|
'struct', |
6538
|
|
|
'all', |
6539
|
|
|
'', |
6540
|
|
|
[ |
6541
|
|
|
'variable' => ['name' => 'variable', 'type' => 'xsd:string'], |
6542
|
|
|
'value' => ['name' => 'value', 'type' => 'xsd:string'], |
6543
|
|
|
] |
6544
|
|
|
); |
6545
|
|
|
|
6546
|
|
|
$server->wsdl->addComplexType( |
6547
|
|
|
'searchedSessionExtras', |
6548
|
|
|
'complexType', |
6549
|
|
|
'array', |
6550
|
|
|
'', |
6551
|
|
|
'SOAP-ENC:Array', |
6552
|
|
|
[], |
6553
|
|
|
[ |
6554
|
|
|
['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:searchedSessionExtra[]'], |
6555
|
|
|
], |
6556
|
|
|
'tns:searchedSessionExtra' |
6557
|
|
|
); |
6558
|
|
|
|
6559
|
|
|
$server->wsdl->addComplexType( |
6560
|
|
|
'searchedSession', |
6561
|
|
|
'complexType', |
6562
|
|
|
'struct', |
6563
|
|
|
'all', |
6564
|
|
|
'', |
6565
|
|
|
[ |
6566
|
|
|
'id' => ['name' => 'id', 'type' => 'xsd:int'], |
6567
|
|
|
'id_coach' => ['name' => 'id_coach', 'type' => 'xsd:int'], |
6568
|
|
|
'name' => ['name' => 'name', 'type' => 'xsd:string'], |
6569
|
|
|
'nbr_courses' => ['name' => 'nbr_courses', 'type' => 'xsd:int'], |
6570
|
|
|
'nbr_users' => ['name' => 'nbr_users', 'type' => 'xsd:int'], |
6571
|
|
|
'nbr_classes' => ['name' => 'nbr_classes', 'type' => 'xsd:int'], |
6572
|
|
|
'date_start' => ['name' => 'date_start', 'type' => 'xsd:string'], |
6573
|
|
|
'date_end' => ['name' => 'date_end', 'type' => 'xsd:string'], |
6574
|
|
|
'nb_days_access_before_beginning' => ['name' => 'nb_days_access_before_beginning', 'type' => 'xsd:int'], |
6575
|
|
|
'nb_days_access_after_end' => ['nb_days_access_after_end' => 'duration', 'type' => 'xsd:int'], |
6576
|
|
|
'session_admin_id' => ['session_admin_id' => 'duration', 'type' => 'xsd:int'], |
6577
|
|
|
'visibility' => ['visibility' => 'duration', 'type' => 'xsd:int'], |
6578
|
|
|
'session_category_id' => ['session_category_id' => 'duration', 'type' => 'xsd:int'], |
6579
|
|
|
'promotion_id' => ['promotion_id' => 'duration', 'type' => 'xsd:int'], |
6580
|
|
|
'description' => ['name' => 'description', 'type' => 'xsd:string'], |
6581
|
|
|
'show_description' => ['name' => 'description', 'type' => 'xsd:int'], |
6582
|
|
|
'duration' => ['name' => 'duration', 'type' => 'xsd:string'], |
6583
|
|
|
'extra' => ['name' => 'extra', 'type' => 'tns:searchedSessionExtras'], |
6584
|
|
|
] |
6585
|
|
|
); |
6586
|
|
|
|
6587
|
|
|
$server->wsdl->addComplexType( |
6588
|
|
|
'searchedSessionList', |
6589
|
|
|
'complexType', |
6590
|
|
|
'array', |
6591
|
|
|
'', |
6592
|
|
|
'SOAP-ENC:Array', |
6593
|
|
|
[], |
6594
|
|
|
[ |
6595
|
|
|
['ref' => 'SOAP-ENC:arrayType', |
6596
|
|
|
'wsdl:arrayType' => 'tns:searchedSession[]', ], |
6597
|
|
|
], |
6598
|
|
|
'tns:searchedSession' |
6599
|
|
|
); |
6600
|
|
|
|
6601
|
|
|
//Reister WSSearchSession |
6602
|
|
|
$server->register( |
6603
|
|
|
'WSSearchSession', |
6604
|
|
|
['SearchSession' => 'tns:SearchSession'], // input parameters |
6605
|
|
|
['return' => 'tns:searchedSessionList'], // output parameters |
6606
|
|
|
'urn:WSRegistration', // namespace |
6607
|
|
|
'urn:WSRegistration#WSSearchSession', // soapaction |
6608
|
|
|
'rpc', // style |
6609
|
|
|
'encoded', // use |
6610
|
|
|
'This service to get a session list filtered by name, description or short description extra field' // documentation |
6611
|
|
|
); |
6612
|
|
|
|
6613
|
|
|
/** |
6614
|
|
|
* Web service to get a session list filtered by name, description or short description extra field. |
6615
|
|
|
* |
6616
|
|
|
* @param array $params Contains the following parameters |
6617
|
|
|
* string $params['term'] Search term |
6618
|
|
|
* string $params['extrafields'] Extrafields to include in request result |
6619
|
|
|
* string $params['secret_key'] Secret key to check |
6620
|
|
|
* |
6621
|
|
|
* @return array The list |
6622
|
|
|
*/ |
6623
|
|
|
function WSSearchSession($params) |
6624
|
|
|
{ |
6625
|
|
|
if (!WSHelperVerifyKey($params['secret_key'])) { |
6626
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
6627
|
|
|
} |
6628
|
|
|
|
6629
|
|
|
$fieldsToInclude = []; |
6630
|
|
|
|
6631
|
|
|
if (!empty($params['extrafields'])) { |
6632
|
|
|
$fieldsToInclude = explode(',', $params['extrafields']); |
6633
|
|
|
foreach ($fieldsToInclude as &$field) { |
6634
|
|
|
if (empty($field)) { |
6635
|
|
|
continue; |
6636
|
|
|
} |
6637
|
|
|
|
6638
|
|
|
$field = trim($field); |
6639
|
|
|
} |
6640
|
|
|
} |
6641
|
|
|
|
6642
|
|
|
return SessionManager::searchSession($params['term'], $fieldsToInclude); |
6643
|
|
|
} |
6644
|
|
|
|
6645
|
|
|
/* Search session Web Service end */ |
6646
|
|
|
/* Fetch session Web Service start */ |
6647
|
|
|
// Input params for WSFetchSession |
6648
|
|
|
$server->wsdl->addComplexType( |
6649
|
|
|
'FetchSession', |
6650
|
|
|
'complexType', |
6651
|
|
|
'struct', |
6652
|
|
|
'all', |
6653
|
|
|
'', |
6654
|
|
|
[ |
6655
|
|
|
'id' => ['name' => 'id', 'type' => 'xsd:int'], |
6656
|
|
|
'extrafields' => ['name' => 'extrafields', 'type' => 'xsd:string'], |
6657
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
6658
|
|
|
] |
6659
|
|
|
); |
6660
|
|
|
|
6661
|
|
|
//Reister WSFetchSession |
6662
|
|
|
$server->register( |
6663
|
|
|
'WSFetchSession', |
6664
|
|
|
['SearchSession' => 'tns:FetchSession'], // input parameters |
6665
|
|
|
['return' => 'tns:searchedSessionList'], // output parameters |
6666
|
|
|
'urn:WSRegistration', // namespace |
6667
|
|
|
'urn:WSRegistration#WSFetchSession', // soapaction |
6668
|
|
|
'rpc', // style |
6669
|
|
|
'encoded', // use |
6670
|
|
|
'This service get a session by its id. Optionally can get its extra fields values' // documentation |
6671
|
|
|
); |
6672
|
|
|
|
6673
|
|
|
/** |
6674
|
|
|
* Web service to get a session by its id. Optionally can get its extra fields values. |
6675
|
|
|
* |
6676
|
|
|
* @param array $params Contains the following parameters: |
6677
|
|
|
* int $params['id'] The session id |
6678
|
|
|
* string $params['extrafields'] Extrafields to include in request result |
6679
|
|
|
* string $params['secret_key'] Secret key to check |
6680
|
|
|
* |
6681
|
|
|
* @return array The session data |
6682
|
|
|
*/ |
6683
|
|
|
function WSFetchSession($params) |
6684
|
|
|
{ |
6685
|
|
|
if (!WSHelperVerifyKey($params['secret_key'])) { |
6686
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
6687
|
|
|
} |
6688
|
|
|
|
6689
|
|
|
$fieldsToInclude = explode(',', $params['extrafields']); |
6690
|
|
|
|
6691
|
|
|
foreach ($fieldsToInclude as &$field) { |
6692
|
|
|
if (empty($field)) { |
6693
|
|
|
continue; |
6694
|
|
|
} |
6695
|
|
|
|
6696
|
|
|
$field = trim($field); |
6697
|
|
|
} |
6698
|
|
|
|
6699
|
|
|
$sessionData = SessionManager::fetch($params['id']); |
6700
|
|
|
|
6701
|
|
|
if ($sessionData === false) { |
6702
|
|
|
return returnError(WS_ERROR_INVALID_INPUT); |
6703
|
|
|
} |
6704
|
|
|
|
6705
|
|
|
if (!empty($extraFields)) { |
6706
|
|
|
$sessionData['extra'] = SessionManager::getFilteredExtraFields($params['id'], $fieldsToInclude); |
6707
|
|
|
} |
6708
|
|
|
|
6709
|
|
|
return [$sessionData]; |
6710
|
|
|
} |
6711
|
|
|
|
6712
|
|
|
/* Fetch session Web Service end */ |
6713
|
|
|
|
6714
|
|
|
/* Register WSCertificatesList function */ |
6715
|
|
|
// Register the data structures used by the service |
6716
|
|
|
$server->wsdl->addComplexType( |
6717
|
|
|
'certificateDetails', |
6718
|
|
|
'complexType', |
6719
|
|
|
'struct', |
6720
|
|
|
'all', |
6721
|
|
|
'', |
6722
|
|
|
[ |
6723
|
|
|
'id' => ['name' => 'id', 'type' => 'xsd:int'], |
6724
|
|
|
'username' => ['name' => 'username', 'type' => 'xsd:string'], |
6725
|
|
|
'course_code' => ['name' => 'course_code', 'type' => 'xsd:string'], |
6726
|
|
|
'session_id' => ['name' => 'session_id', 'type' => 'xsd:int'], |
6727
|
|
|
'cat_id' => ['name' => 'cat_id', 'type' => 'xsd:int'], |
6728
|
|
|
'created_at' => ['name' => 'created_at', 'type' => 'xsd:string'], |
6729
|
|
|
'path_certificate' => ['name' => 'path_certificate', 'type' => 'xsd:string'], |
6730
|
|
|
] |
6731
|
|
|
); |
6732
|
|
|
|
6733
|
|
|
$server->wsdl->addComplexType( |
6734
|
|
|
'certificatesList', |
6735
|
|
|
'complexType', |
6736
|
|
|
'array', |
6737
|
|
|
'', |
6738
|
|
|
'SOAP-ENC:Array', |
6739
|
|
|
[], |
6740
|
|
|
[ |
6741
|
|
|
['ref' => 'SOAP-ENC:arrayType', |
6742
|
|
|
'wsdl:arrayType' => 'tns:certificateDetails[]', ], |
6743
|
|
|
], |
6744
|
|
|
'tns:certificateDetails' |
6745
|
|
|
); |
6746
|
|
|
// Register the method to expose |
6747
|
|
|
$server->register( |
6748
|
|
|
'WSCertificatesList', // method name |
6749
|
|
|
[ |
6750
|
|
|
'startingDate' => 'xsd:string', // input parameters |
6751
|
|
|
'endingDate' => 'xsd:string', |
6752
|
|
|
], |
6753
|
|
|
['return' => 'tns:certificatesList'], // output parameters |
6754
|
|
|
'urn:WSRegistration', // namespace |
6755
|
|
|
'urn:WSRegistration#WSCertificatesList', // soapaction |
6756
|
|
|
'rpc', // style |
6757
|
|
|
'encoded', // use |
6758
|
|
|
'This service returns a list of certificates' // documentation |
6759
|
|
|
); |
6760
|
|
|
|
6761
|
|
|
function WSCertificatesList($startingDate = '', $endingDate = '') |
6762
|
|
|
{ |
6763
|
|
|
$certificatesCron = api_get_setting('add_gradebook_certificates_cron_task_enabled'); |
6764
|
|
|
if ($certificatesCron === 'true') { |
6765
|
|
|
require_once api_get_path(SYS_CODE_PATH).'cron/add_gradebook_certificates.php'; |
6766
|
|
|
} |
6767
|
|
|
$result = []; |
6768
|
|
|
$certificateTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); |
6769
|
|
|
$userTable = Database::get_main_table(TABLE_MAIN_USER); |
6770
|
|
|
$categoryTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); |
6771
|
|
|
|
6772
|
|
|
$conditions = []; |
6773
|
|
|
|
6774
|
|
|
if (!empty($startingDate) && !empty($endingDate)) { |
6775
|
|
|
$conditions['certificate.created_at BETWEEN ? AND ?'] = [$startingDate, $endingDate]; |
6776
|
|
|
} elseif (!empty($startingDate)) { |
6777
|
|
|
$conditions['certificate.created_at >= ?'] = [$startingDate]; |
6778
|
|
|
} elseif (!empty($endingDate)) { |
6779
|
|
|
$conditions['certificate.created_at <= ?'] = [$endingDate]; |
6780
|
|
|
} |
6781
|
|
|
|
6782
|
|
|
$queryResult = Database::select( |
6783
|
|
|
[ |
6784
|
|
|
'certificate.id', |
6785
|
|
|
'user.username', |
6786
|
|
|
'category.course_code', |
6787
|
|
|
'category.session_id', |
6788
|
|
|
'certificate.user_id', |
6789
|
|
|
'certificate.cat_id', |
6790
|
|
|
'certificate.created_at', |
6791
|
|
|
'certificate.path_certificate', |
6792
|
|
|
], |
6793
|
|
|
$certificateTable, |
6794
|
|
|
['where' => $conditions] |
6795
|
|
|
); |
6796
|
|
|
|
6797
|
|
|
foreach ($queryResult as $row) { |
6798
|
|
|
$userPath = USermanager::getUserPathById($row['user_id'], 'web'); |
6799
|
|
|
$row['path_certificate'] = $userPath.'/certificate'.$row['path_certificate']; |
6800
|
|
|
$result[] = $row; |
6801
|
|
|
} |
6802
|
|
|
|
6803
|
|
|
return $result; |
6804
|
|
|
} |
6805
|
|
|
|
6806
|
|
|
/* Create group Web Service start */ |
6807
|
|
|
// Register the data structures used by the service |
6808
|
|
|
|
6809
|
|
|
// Input params for WSCreateGroup |
6810
|
|
|
$server->wsdl->addComplexType( |
6811
|
|
|
'createGroup', |
6812
|
|
|
'complexType', |
6813
|
|
|
'struct', |
6814
|
|
|
'all', |
6815
|
|
|
'', |
6816
|
|
|
[ |
6817
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
6818
|
|
|
'name' => ['name' => 'name', 'type' => 'xsd:string'], |
6819
|
|
|
] |
6820
|
|
|
); |
6821
|
|
|
|
6822
|
|
|
// Register the method to expose |
6823
|
|
|
$server->register( |
6824
|
|
|
'WSCreateGroup', // method name |
6825
|
|
|
['createGroup' => 'tns:createGroup'], // input parameters |
6826
|
|
|
['return' => 'xsd:string'], // output parameters |
6827
|
|
|
'urn:WSRegistration', // namespace |
6828
|
|
|
'urn:WSRegistration#WSCreateGroup', // soapaction |
6829
|
|
|
'rpc', // style |
6830
|
|
|
'encoded', // use |
6831
|
|
|
'This service adds a group' // documentation |
6832
|
|
|
); |
6833
|
|
|
|
6834
|
|
|
// Define the method WSCreateGroup |
6835
|
|
|
function WSCreateGroup($params) |
6836
|
|
|
{ |
6837
|
|
|
if (!WSHelperVerifyKey($params['secret_key'])) { |
6838
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
6839
|
|
|
} |
6840
|
|
|
$userGroup = new UserGroup(); |
6841
|
|
|
$params = [ |
6842
|
|
|
'name' => $params['name'], |
6843
|
|
|
]; |
6844
|
|
|
|
6845
|
|
|
return $userGroup->save($params); |
6846
|
|
|
} |
6847
|
|
|
|
6848
|
|
|
/* Create group Web Service end */ |
6849
|
|
|
|
6850
|
|
|
/* Update group Web Service start */ |
6851
|
|
|
// Register the data structures used by the service |
6852
|
|
|
|
6853
|
|
|
// Input params for WSUpdateGroup |
6854
|
|
|
$server->wsdl->addComplexType( |
6855
|
|
|
'updateGroup', |
6856
|
|
|
'complexType', |
6857
|
|
|
'struct', |
6858
|
|
|
'all', |
6859
|
|
|
'', |
6860
|
|
|
[ |
6861
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
6862
|
|
|
'id' => ['name' => 'id', 'type' => 'xsd:string'], |
6863
|
|
|
'name' => ['name' => 'name', 'type' => 'xsd:string'], |
6864
|
|
|
'description' => ['name' => 'description', 'type' => 'xsd:string'], |
6865
|
|
|
'url' => ['name' => 'url', 'type' => 'xsd:string'], |
6866
|
|
|
'visibility' => ['name' => 'visibility', 'type' => 'xsd:string'], |
6867
|
|
|
'picture_uri' => ['name' => 'picture_uri', 'type' => 'xsd:string'], |
6868
|
|
|
'allow_member_group_to_leave' => ['name' => 'allow_member_group_to_leave', 'type' => 'xsd:string'], |
6869
|
|
|
] |
6870
|
|
|
); |
6871
|
|
|
|
6872
|
|
|
// Register the method to expose |
6873
|
|
|
$server->register( |
6874
|
|
|
'WSUpdateGroup', // method name |
6875
|
|
|
['updateGroup' => 'tns:updateGroup'], // input parameters |
6876
|
|
|
['return' => 'xsd:string'], // output parameters |
6877
|
|
|
'urn:WSRegistration', // namespace |
6878
|
|
|
'urn:WSRegistration#WSUpdateGroup', // soapaction |
6879
|
|
|
'rpc', // style |
6880
|
|
|
'encoded', // use |
6881
|
|
|
'This service updates a group' // documentation |
6882
|
|
|
); |
6883
|
|
|
|
6884
|
|
|
// Define the method WSUpdateGroup |
6885
|
|
|
function WSUpdateGroup($params) |
6886
|
|
|
{ |
6887
|
|
|
if (!WSHelperVerifyKey($params['secret_key'])) { |
6888
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
6889
|
|
|
} |
6890
|
|
|
$params['allow_member_group_to_leave'] = null; |
6891
|
|
|
$userGroup = new UserGroup(); |
6892
|
|
|
|
6893
|
|
|
return $userGroup->update($params); |
6894
|
|
|
} |
6895
|
|
|
|
6896
|
|
|
/* Update group Web Service end */ |
6897
|
|
|
|
6898
|
|
|
/* Delete group Web Service start */ |
6899
|
|
|
// Register the data structures used by the service |
6900
|
|
|
|
6901
|
|
|
// Input params for WSDeleteGroup |
6902
|
|
|
$server->wsdl->addComplexType( |
6903
|
|
|
'deleteGroup', |
6904
|
|
|
'complexType', |
6905
|
|
|
'struct', |
6906
|
|
|
'all', |
6907
|
|
|
'', |
6908
|
|
|
[ |
6909
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
6910
|
|
|
'id' => ['name' => 'id', 'type' => 'xsd:string'], |
6911
|
|
|
] |
6912
|
|
|
); |
6913
|
|
|
|
6914
|
|
|
// Register the method to expose |
6915
|
|
|
$server->register( |
6916
|
|
|
'WSDeleteGroup', // method name |
6917
|
|
|
['deleteGroup' => 'tns:deleteGroup'], // input parameters |
6918
|
|
|
['return' => 'xsd:string'], // output parameters |
6919
|
|
|
'urn:WSRegistration', // namespace |
6920
|
|
|
'urn:WSRegistration#WSDeleteGroup', // soapaction |
6921
|
|
|
'rpc', // style |
6922
|
|
|
'encoded', // use |
6923
|
|
|
'This service deletes a group' // documentation |
6924
|
|
|
); |
6925
|
|
|
|
6926
|
|
|
// Define the method WSDeleteGroup |
6927
|
|
|
function WSDeleteGroup($params) |
6928
|
|
|
{ |
6929
|
|
|
if (!WSHelperVerifyKey($params['secret_key'])) { |
6930
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
6931
|
|
|
} |
6932
|
|
|
$userGroup = new UserGroup(); |
6933
|
|
|
|
6934
|
|
|
return $userGroup->delete($params['id']); |
6935
|
|
|
} |
6936
|
|
|
|
6937
|
|
|
/* Delete group Web Service end */ |
6938
|
|
|
|
6939
|
|
|
/* Bind group to parent Web Service start */ |
6940
|
|
|
// Register the data structures used by the service |
6941
|
|
|
|
6942
|
|
|
// Input params for GroupBindToParent |
6943
|
|
|
$server->wsdl->addComplexType( |
6944
|
|
|
'groupBindToParent', |
6945
|
|
|
'complexType', |
6946
|
|
|
'struct', |
6947
|
|
|
'all', |
6948
|
|
|
'', |
6949
|
|
|
[ |
6950
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
6951
|
|
|
'id' => ['name' => 'id', 'type' => 'xsd:string'], |
6952
|
|
|
'parent_id' => ['name' => 'parent_id', 'type' => 'xsd:string'], |
6953
|
|
|
] |
6954
|
|
|
); |
6955
|
|
|
|
6956
|
|
|
// Register the method to expose |
6957
|
|
|
$server->register( |
6958
|
|
|
'GroupBindToParent', // method name |
6959
|
|
|
['groupBindToParent' => 'tns:groupBindToParent'], // input parameters |
6960
|
|
|
['return' => 'xsd:string'], // output parameters |
6961
|
|
|
'urn:WSRegistration', // namespace |
6962
|
|
|
'urn:WSRegistration#GroupBindToParent', // soapaction |
6963
|
|
|
'rpc', // style |
6964
|
|
|
'encoded', // use |
6965
|
|
|
'This service binds a group to a parent' // documentation |
6966
|
|
|
); |
6967
|
|
|
|
6968
|
|
|
// Define the method GroupBindToParent |
6969
|
|
|
function GroupBindToParent($params) |
6970
|
|
|
{ |
6971
|
|
|
if (!WSHelperVerifyKey($params['secret_key'])) { |
6972
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
6973
|
|
|
} |
6974
|
|
|
$userGroup = new UserGroup(); |
6975
|
|
|
|
6976
|
|
|
return $userGroup->setParentGroup($params['id'], $params['parent_id']); |
6977
|
|
|
} |
6978
|
|
|
|
6979
|
|
|
/* Bind group Web Service end */ |
6980
|
|
|
|
6981
|
|
|
/* Unbind group from parent Web Service start */ |
6982
|
|
|
// Register the data structures used by the service |
6983
|
|
|
|
6984
|
|
|
// Input params for GroupUnbindFromParent |
6985
|
|
|
$server->wsdl->addComplexType( |
6986
|
|
|
'groupUnbindFromParent', |
6987
|
|
|
'complexType', |
6988
|
|
|
'struct', |
6989
|
|
|
'all', |
6990
|
|
|
'', |
6991
|
|
|
[ |
6992
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
6993
|
|
|
'id' => ['name' => 'id', 'type' => 'xsd:string'], |
6994
|
|
|
] |
6995
|
|
|
); |
6996
|
|
|
|
6997
|
|
|
// Register the method to expose |
6998
|
|
|
$server->register( |
6999
|
|
|
'GroupUnbindFromParent', // method name |
7000
|
|
|
['groupUnbindFromParent' => 'tns:groupUnbindFromParent'], // input parameters |
7001
|
|
|
['return' => 'xsd:string'], // output parameters |
7002
|
|
|
'urn:WSRegistration', // namespace |
7003
|
|
|
'urn:WSRegistration#GroupUnbindFromParent', // soapaction |
7004
|
|
|
'rpc', // style |
7005
|
|
|
'encoded', // use |
7006
|
|
|
'This service unbinds a group from its parent' // documentation |
7007
|
|
|
); |
7008
|
|
|
|
7009
|
|
|
// Define the method GroupUnbindFromParent |
7010
|
|
|
function GroupUnbindFromParent($params) |
7011
|
|
|
{ |
7012
|
|
|
if (!WSHelperVerifyKey($params['secret_key'])) { |
7013
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
7014
|
|
|
} |
7015
|
|
|
$userGroup = new UserGroup(); |
7016
|
|
|
|
7017
|
|
|
return $userGroup->setParentGroup($params['id'], 0); |
7018
|
|
|
} |
7019
|
|
|
|
7020
|
|
|
/* Unbind group Web Service end */ |
7021
|
|
|
|
7022
|
|
|
/* Add user to group Web Service start */ |
7023
|
|
|
// Register the data structures used by the service |
7024
|
|
|
|
7025
|
|
|
// Input params for WSAddUserToGroup |
7026
|
|
|
$server->wsdl->addComplexType( |
7027
|
|
|
'addUserToGroup', |
7028
|
|
|
'complexType', |
7029
|
|
|
'struct', |
7030
|
|
|
'all', |
7031
|
|
|
'', |
7032
|
|
|
[ |
7033
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
7034
|
|
|
'user_id' => ['name' => 'user_id', 'type' => 'xsd:string'], |
7035
|
|
|
'group_id' => ['name' => 'group_id', 'type' => 'xsd:string'], |
7036
|
|
|
'relation_type' => ['name' => 'relation_type', 'type' => 'xsd:string'], |
7037
|
|
|
] |
7038
|
|
|
); |
7039
|
|
|
|
7040
|
|
|
// Register the method to expose |
7041
|
|
|
$server->register( |
7042
|
|
|
'WSAddUserToGroup', // method name |
7043
|
|
|
['addUserToGroup' => 'tns:addUserToGroup'], // input parameters |
7044
|
|
|
['return' => 'xsd:string'], // output parameters |
7045
|
|
|
'urn:WSRegistration', // namespace |
7046
|
|
|
'urn:WSRegistration#WSAddUserToGroup', // soapaction |
7047
|
|
|
'rpc', // style |
7048
|
|
|
'encoded', // use |
7049
|
|
|
'This service adds a user to a group' // documentation |
7050
|
|
|
); |
7051
|
|
|
|
7052
|
|
|
// Define the method WSAddUserToGroup |
7053
|
|
|
function WSAddUserToGroup($params) |
7054
|
|
|
{ |
7055
|
|
|
if (!WSHelperVerifyKey($params['secret_key'])) { |
7056
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
7057
|
|
|
} |
7058
|
|
|
|
7059
|
|
|
$userGroup = new UserGroup(); |
7060
|
|
|
|
7061
|
|
|
return $userGroup->subscribe_users_to_usergroup( |
7062
|
|
|
$params['group_id'], |
7063
|
|
|
[0 => $params['user_id']], |
7064
|
|
|
false, |
7065
|
|
|
$params['relation_type'] |
7066
|
|
|
); |
7067
|
|
|
} |
7068
|
|
|
|
7069
|
|
|
/* Add user to group Web Service end */ |
7070
|
|
|
|
7071
|
|
|
/* Update user role in group Web Service start */ |
7072
|
|
|
// Register the data structures used by the service |
7073
|
|
|
|
7074
|
|
|
// Input params for WSUpdateUserRoleInGroup |
7075
|
|
|
$server->wsdl->addComplexType( |
7076
|
|
|
'updateUserRoleInGroup', |
7077
|
|
|
'complexType', |
7078
|
|
|
'struct', |
7079
|
|
|
'all', |
7080
|
|
|
'', |
7081
|
|
|
[ |
7082
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
7083
|
|
|
'user_id' => ['name' => 'user_id', 'type' => 'xsd:string'], |
7084
|
|
|
'group_id' => ['name' => 'group_id', 'type' => 'xsd:string'], |
7085
|
|
|
'relation_type' => ['name' => 'relation_type', 'type' => 'xsd:string'], |
7086
|
|
|
] |
7087
|
|
|
); |
7088
|
|
|
|
7089
|
|
|
// Register the method to expose |
7090
|
|
|
$server->register( |
7091
|
|
|
'WSUpdateUserRoleInGroup', // method name |
7092
|
|
|
['updateUserRoleInGroup' => 'tns:updateUserRoleInGroup'], // input parameters |
7093
|
|
|
['return' => 'xsd:string'], // output parameters |
7094
|
|
|
'urn:WSRegistration', // namespace |
7095
|
|
|
'urn:WSRegistration#WSUpdateUserRoleInGroup', // soapaction |
7096
|
|
|
'rpc', // style |
7097
|
|
|
'encoded', // use |
7098
|
|
|
'This service updates a user role in group' // documentation |
7099
|
|
|
); |
7100
|
|
|
|
7101
|
|
|
// Define the method WSUpdateUserRoleInGroup |
7102
|
|
|
function WSUpdateUserRoleInGroup($params) |
7103
|
|
|
{ |
7104
|
|
|
if (!WSHelperVerifyKey($params['secret_key'])) { |
7105
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
7106
|
|
|
} |
7107
|
|
|
$userGroup = new UserGroup(); |
7108
|
|
|
|
7109
|
|
|
return $userGroup->update_user_role( |
7110
|
|
|
$params['user_id'], |
7111
|
|
|
$params['group_id'], |
7112
|
|
|
$params['relation_type'] |
7113
|
|
|
); |
7114
|
|
|
} |
7115
|
|
|
|
7116
|
|
|
/* Update user role Web Service end */ |
7117
|
|
|
|
7118
|
|
|
/* Delete user from group Web Service start */ |
7119
|
|
|
// Register the data structures used by the service |
7120
|
|
|
|
7121
|
|
|
// Input params for WSDeleteUserFromGroup |
7122
|
|
|
$server->wsdl->addComplexType( |
7123
|
|
|
'deleteUserFromGroup', |
7124
|
|
|
'complexType', |
7125
|
|
|
'struct', |
7126
|
|
|
'all', |
7127
|
|
|
'', |
7128
|
|
|
[ |
7129
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
7130
|
|
|
'user_id' => ['name' => 'user_id', 'type' => 'xsd:string'], |
7131
|
|
|
'group_id' => ['name' => 'group_id', 'type' => 'xsd:string'], |
7132
|
|
|
] |
7133
|
|
|
); |
7134
|
|
|
|
7135
|
|
|
// Register the method to expose |
7136
|
|
|
$server->register( |
7137
|
|
|
'WSDeleteUserFromGroup', // method name |
7138
|
|
|
['deleteUserFromGroup' => 'tns:deleteUserFromGroup'], // input parameters |
7139
|
|
|
['return' => 'xsd:string'], // output parameters |
7140
|
|
|
'urn:WSRegistration', // namespace |
7141
|
|
|
'urn:WSRegistration#WSDeleteUserFromGroup', // soapaction |
7142
|
|
|
'rpc', // style |
7143
|
|
|
'encoded', // use |
7144
|
|
|
'This service deletes a user from a group' // documentation |
7145
|
|
|
); |
7146
|
|
|
|
7147
|
|
|
// Define the method WSDeleteUserFromGroup |
7148
|
|
|
function WSDeleteUserFromGroup($params) |
7149
|
|
|
{ |
7150
|
|
|
if (!WSHelperVerifyKey($params['secret_key'])) { |
7151
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
7152
|
|
|
} |
7153
|
|
|
$userGroup = new UserGroup(); |
7154
|
|
|
|
7155
|
|
|
return $userGroup->delete_user_rel_group( |
7156
|
|
|
$params['user_id'], |
7157
|
|
|
$params['group_id'] |
7158
|
|
|
); |
7159
|
|
|
} |
7160
|
|
|
|
7161
|
|
|
/* Delete user from group Web Service end */ |
7162
|
|
|
|
7163
|
|
|
/** WSRegisterUserVisibilityToCourseCatalogue */ |
7164
|
|
|
// Register the data structures used by the service |
7165
|
|
|
|
7166
|
|
|
$server->wsdl->addComplexType( |
7167
|
|
|
'user_course_visibility', |
7168
|
|
|
'complexType', |
7169
|
|
|
'struct', |
7170
|
|
|
'all', |
7171
|
|
|
'', |
7172
|
|
|
[ |
7173
|
|
|
'course_id' => ['name' => 'course_id', 'type' => 'tns:course_id'], |
7174
|
|
|
'user_id' => ['name' => 'user_id', 'type' => 'tns:user_id'], |
7175
|
|
|
'visible' => ['name' => 'status', 'type' => 'xsd:int'], |
7176
|
|
|
] |
7177
|
|
|
); |
7178
|
|
|
|
7179
|
|
|
$server->wsdl->addComplexType( |
7180
|
|
|
'user_course_visibility_array', |
7181
|
|
|
'complexType', |
7182
|
|
|
'array', |
7183
|
|
|
'', |
7184
|
|
|
'SOAP-ENC:Array', |
7185
|
|
|
[], |
7186
|
|
|
[ |
7187
|
|
|
['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:user_course_visibility[]'], |
7188
|
|
|
], |
7189
|
|
|
'tns:user_course_visibility' |
7190
|
|
|
); |
7191
|
|
|
|
7192
|
|
|
$server->wsdl->addComplexType( |
7193
|
|
|
'registerUserToCourseCatalogue_arg', |
7194
|
|
|
'complexType', |
7195
|
|
|
'struct', |
7196
|
|
|
'all', |
7197
|
|
|
'', |
7198
|
|
|
[ |
7199
|
|
|
'userscourses' => ['name' => 'userscourses', 'type' => 'tns:user_course_visibility_array'], |
7200
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
7201
|
|
|
] |
7202
|
|
|
); |
7203
|
|
|
|
7204
|
|
|
$server->wsdl->addComplexType( |
7205
|
|
|
'registerUserToCourseCatalogue_return', |
7206
|
|
|
'complexType', |
7207
|
|
|
'struct', |
7208
|
|
|
'all', |
7209
|
|
|
'', |
7210
|
|
|
[ |
7211
|
|
|
'original_user_id_value' => ['name' => 'original_user_id_value', 'type' => 'xsd:string'], |
7212
|
|
|
'original_course_id_value' => ['name' => 'original_course_id_value', 'type' => 'xsd:string'], |
7213
|
|
|
'visible' => ['name' => 'visible', 'type' => 'xsd:int'], |
7214
|
|
|
'result' => ['name' => 'result', 'type' => 'xsd:int'], |
7215
|
|
|
] |
7216
|
|
|
); |
7217
|
|
|
|
7218
|
|
|
$server->wsdl->addComplexType( |
7219
|
|
|
'registerUserToCourseCatalogue_return_global', |
7220
|
|
|
'complexType', |
7221
|
|
|
'array', |
7222
|
|
|
'', |
7223
|
|
|
'SOAP-ENC:Array', |
7224
|
|
|
[], |
7225
|
|
|
[['ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:registerUserToCourseCatalogue_return[]']], |
7226
|
|
|
'tns:registerUserToCourseCatalogue_return' |
7227
|
|
|
); |
7228
|
|
|
|
7229
|
|
|
// Register the method to expose |
7230
|
|
|
$server->register( |
7231
|
|
|
'WSAddUserVisibilityToCourseInCatalogue', // method name |
7232
|
|
|
['registerUserToCourseCatalogue' => 'tns:registerUserToCourseCatalogue_arg'], // input parameters |
7233
|
|
|
['return' => 'tns:registerUserToCourseCatalogue_return_global'], |
7234
|
|
|
'urn:WSRegistration', // namespace |
7235
|
|
|
'urn:WSRegistration#WSRegisterUserVisibilityToCourseCatalogue', // soapaction |
7236
|
|
|
'rpc', // style |
7237
|
|
|
'encoded', // use |
7238
|
|
|
'This service registers the visibility of users to course in catalogue' // documentation |
7239
|
|
|
); |
7240
|
|
|
|
7241
|
|
|
// define the method WSRegisterUserVisibilityToCourseInCatalogue |
7242
|
|
|
function WSAddUserVisibilityToCourseInCatalogue($params) |
7243
|
|
|
{ |
7244
|
|
|
global $debug; |
7245
|
|
|
if (!WSHelperVerifyKey($params)) { |
7246
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
7247
|
|
|
} |
7248
|
|
|
if ($debug) { |
7249
|
|
|
error_log('WSAddUserVisibilityToCourseCatalogue params: '.print_r($params, 1)); |
7250
|
|
|
} |
7251
|
|
|
|
7252
|
|
|
$results = []; |
7253
|
|
|
$userscourses = $params['userscourses']; |
7254
|
|
|
foreach ($userscourses as $usercourse) { |
7255
|
|
|
$original_course_id = $usercourse['course_id']; |
7256
|
|
|
$original_user_id = $usercourse['user_id']; |
7257
|
|
|
$visible = $usercourse['visible']; |
7258
|
|
|
|
7259
|
|
|
$resultValue = 0; |
7260
|
|
|
|
7261
|
|
|
// Get user id |
7262
|
|
|
$userId = UserManager::get_user_id_from_original_id( |
7263
|
|
|
$original_user_id['original_user_id_value'], |
7264
|
|
|
$original_user_id['original_user_id_name'] |
7265
|
|
|
); |
7266
|
|
|
if ($debug) { |
7267
|
|
|
error_log('WSAddUserVisibilityToCourseCatalogue userId: '.$userId); |
7268
|
|
|
} |
7269
|
|
|
|
7270
|
|
|
if ($userId == 0) { |
7271
|
|
|
// If user was not found, there was a problem |
7272
|
|
|
$resultValue = 0; |
7273
|
|
|
} else { |
7274
|
|
|
// User was found |
7275
|
|
|
$courseInfo = CourseManager::getCourseInfoFromOriginalId( |
7276
|
|
|
$original_course_id['original_course_id_value'], |
7277
|
|
|
$original_course_id['original_course_id_name'] |
7278
|
|
|
); |
7279
|
|
|
|
7280
|
|
|
$courseCode = $courseInfo['code']; |
7281
|
|
|
if (empty($courseCode)) { |
7282
|
|
|
// Course was not found |
7283
|
|
|
$resultValue = 0; |
7284
|
|
|
} else { |
7285
|
|
|
if ($debug) { |
7286
|
|
|
error_log('WSAddUserVisibilityToCourseCatalogue courseCode: '.$courseCode); |
7287
|
|
|
} |
7288
|
|
|
$result = CourseManager::addUserVisibilityToCourseInCatalogue($userId, $courseCode, $visible); |
7289
|
|
|
if ($result) { |
7290
|
|
|
$resultValue = 1; |
7291
|
|
|
if ($debug) { |
7292
|
|
|
error_log('WSAddUserVisibilityToCourseCatalogue registered'); |
7293
|
|
|
} |
7294
|
|
|
} else { |
7295
|
|
|
if ($debug) { |
7296
|
|
|
error_log('WSAddUserVisibilityToCourseCatalogue NOT registered: '); |
7297
|
|
|
} |
7298
|
|
|
} |
7299
|
|
|
} |
7300
|
|
|
} |
7301
|
|
|
|
7302
|
|
|
$results[] = [ |
7303
|
|
|
'original_user_id_value' => $original_user_id['original_user_id_value'], |
7304
|
|
|
'original_course_id_value' => $original_course_id['original_course_id_value'], |
7305
|
|
|
'visible' => $visible, |
7306
|
|
|
'result' => $resultValue, |
7307
|
|
|
]; |
7308
|
|
|
} |
7309
|
|
|
|
7310
|
|
|
return $results; |
7311
|
|
|
} |
7312
|
|
|
|
7313
|
|
|
// Register the method to expose |
7314
|
|
|
$server->register( |
7315
|
|
|
'WSRemoveUserVisibilityToCourseInCatalogue', // method name |
7316
|
|
|
['registerUserToCourseCatalogue' => 'tns:registerUserToCourseCatalogue_arg'], // input parameters |
7317
|
|
|
['return' => 'tns:registerUserToCourseCatalogue_return_global'], |
7318
|
|
|
'urn:WSRegistration', // namespace |
7319
|
|
|
'urn:WSRegistration#WSRegisterUserVisibilityToCourseCatalogue', // soapaction |
7320
|
|
|
'rpc', // style |
7321
|
|
|
'encoded', // use |
7322
|
|
|
'This service removes the visibility of users to course in catalogue' // documentation |
7323
|
|
|
); |
7324
|
|
|
|
7325
|
|
|
// define the method WSRemoveUserVisibilityToCourseInCatalogue |
7326
|
|
|
function WSRemoveUserVisibilityToCourseInCatalogue($params) |
7327
|
|
|
{ |
7328
|
|
|
global $debug; |
7329
|
|
|
if (!WSHelperVerifyKey($params)) { |
7330
|
|
|
return returnError(WS_ERROR_SECRET_KEY); |
7331
|
|
|
} |
7332
|
|
|
if ($debug) { |
7333
|
|
|
error_log('WSRemoveUserVisibilityToCourseInCatalogue params: '.print_r($params, 1)); |
7334
|
|
|
} |
7335
|
|
|
|
7336
|
|
|
$results = []; |
7337
|
|
|
$userscourses = $params['userscourses']; |
7338
|
|
|
foreach ($userscourses as $usercourse) { |
7339
|
|
|
$original_course_id = $usercourse['course_id']; |
7340
|
|
|
$original_user_id = $usercourse['user_id']; |
7341
|
|
|
$visible = $usercourse['visible']; |
7342
|
|
|
|
7343
|
|
|
$resultValue = 0; |
7344
|
|
|
|
7345
|
|
|
// Get user id |
7346
|
|
|
$userId = UserManager::get_user_id_from_original_id( |
7347
|
|
|
$original_user_id['original_user_id_value'], |
7348
|
|
|
$original_user_id['original_user_id_name'] |
7349
|
|
|
); |
7350
|
|
|
if ($debug) { |
7351
|
|
|
error_log('WSRemoveUserVisibilityToCourseInCatalogue user_id: '.$userId); |
7352
|
|
|
} |
7353
|
|
|
|
7354
|
|
|
if ($userId == 0) { |
7355
|
|
|
// If user was not found, there was a problem |
7356
|
|
|
$resultValue = 0; |
7357
|
|
|
} else { |
7358
|
|
|
// User was found |
7359
|
|
|
$courseInfo = CourseManager::getCourseInfoFromOriginalId( |
7360
|
|
|
$original_course_id['original_course_id_value'], |
7361
|
|
|
$original_course_id['original_course_id_name'] |
7362
|
|
|
); |
7363
|
|
|
|
7364
|
|
|
$courseCode = $courseInfo['code']; |
7365
|
|
|
if (empty($courseCode)) { |
7366
|
|
|
// Course was not found |
7367
|
|
|
$resultValue = 0; |
7368
|
|
|
} else { |
7369
|
|
|
if ($debug) { |
7370
|
|
|
error_log('WSRemoveUserVisibilityToCourseInCatalogue courseCode: '.$courseCode); |
7371
|
|
|
} |
7372
|
|
|
$result = CourseManager::removeUserVisibilityToCourseInCatalogue($userId, $courseCode, $visible); |
7373
|
|
|
if ($result) { |
7374
|
|
|
$resultValue = 1; |
7375
|
|
|
if ($debug) { |
7376
|
|
|
error_log('WSRemoveUserVisibilityToCourseInCatalogue removed'); |
7377
|
|
|
} |
7378
|
|
|
} else { |
7379
|
|
|
if ($debug) { |
7380
|
|
|
error_log('WSRemoveUserVisibilityToCourseInCatalogue NOT removed: '); |
7381
|
|
|
} |
7382
|
|
|
} |
7383
|
|
|
} |
7384
|
|
|
} |
7385
|
|
|
|
7386
|
|
|
$results[] = [ |
7387
|
|
|
'original_user_id_value' => $original_user_id['original_user_id_value'], |
7388
|
|
|
'original_course_id_value' => $original_course_id['original_course_id_value'], |
7389
|
|
|
'visible' => $visible, |
7390
|
|
|
'result' => $resultValue, |
7391
|
|
|
]; |
7392
|
|
|
} |
7393
|
|
|
|
7394
|
|
|
return $results; |
7395
|
|
|
} |
7396
|
|
|
|
7397
|
|
|
// Add more webservices through hooks from plugins |
7398
|
|
|
if (!empty($hook)) { |
7399
|
|
|
$hook->setEventData(['server' => $server]); |
7400
|
|
|
$res = $hook->notifyWSRegistration(HOOK_EVENT_TYPE_POST); |
7401
|
|
|
if (!empty($res['server'])) { |
7402
|
|
|
$server = $res['server']; |
7403
|
|
|
} |
7404
|
|
|
} |
7405
|
|
|
|
7406
|
|
|
// Use the request to (try to) invoke the service |
7407
|
|
|
$GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input'); |
7408
|
|
|
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; |
7409
|
|
|
|
7410
|
|
|
// If you send your data in utf8 then this value must be false. |
7411
|
|
|
$decodeUTF8 = api_get_setting('registration.soap.php.decode_utf8'); |
7412
|
|
|
if ($decodeUTF8 === 'true') { |
7413
|
|
|
$server->decode_utf8 = true; |
7414
|
|
|
} else { |
7415
|
|
|
$server->decode_utf8 = false; |
7416
|
|
|
} |
7417
|
|
|
$server->service($HTTP_RAW_POST_DATA); |
7418
|
|
|
|