@@ -43,453 +43,453 @@ |
||
43 | 43 | |
44 | 44 | abstract class PENSRequest extends PENSMessage { |
45 | 45 | |
46 | - /** |
|
47 | - * PENS Version to be used. Currently, the only valid value is 1.0.0. Required. |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - protected $_pens_version = null; |
|
51 | - |
|
52 | - /** |
|
53 | - * Command being used. The only valid values are collect, alert and receipt.Required |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - protected $_command = null; |
|
57 | - |
|
58 | - /** |
|
59 | - * Package type being used. The only valid values are aicc-pkg, scorm-pif, ims-qti. Required |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - protected $_package_type = null; |
|
63 | - |
|
64 | - /** |
|
65 | - * Package type version. Required |
|
66 | - * @var string |
|
67 | - */ |
|
68 | - protected $_package_type_version = null; |
|
69 | - |
|
70 | - /** |
|
71 | - * Package format. The only valid values are zip, url, jar, war and xml. Required |
|
72 | - * @var string |
|
73 | - */ |
|
74 | - protected $_package_format = null; |
|
75 | - |
|
76 | - /** |
|
77 | - * Package id. Requires a valid URI according to RFC 2396. Required |
|
78 | - * @var string |
|
79 | - */ |
|
80 | - protected $_package_id = null; |
|
81 | - |
|
82 | - /** |
|
83 | - * Package url. Requires a valid, fully qualified URL including transport protocol and filename extension. Required |
|
84 | - * @var string |
|
85 | - */ |
|
86 | - protected $_package_url = null; |
|
87 | - |
|
88 | - /** |
|
89 | - * User id required for system to retrieve package from URL. Optional. |
|
90 | - * @var string |
|
91 | - */ |
|
92 | - protected $_package_url_user_id = null; |
|
93 | - |
|
94 | - /** |
|
95 | - * Account required for system to retrieve package from URL. Optional. |
|
96 | - * @var string |
|
97 | - */ |
|
98 | - protected $_package_url_account = null; |
|
99 | - |
|
100 | - /** |
|
101 | - * Password required for system to retrieve package from URL. Optional. |
|
102 | - * @var string |
|
103 | - */ |
|
104 | - protected $_package_url_password = null; |
|
105 | - |
|
106 | - /** |
|
107 | - * Expiry date for package URL. ISO 8601 format expressed as UTC. Will be transformed into a PHP DateTime object during construction. Required |
|
108 | - * @var DateTime |
|
109 | - */ |
|
110 | - protected $_package_url_expiry = null; |
|
111 | - |
|
112 | - /** |
|
113 | - * Name or ID for client submitting the content package to the target system. Required. |
|
114 | - * @var string |
|
115 | - */ |
|
116 | - protected $_client = null; |
|
117 | - |
|
118 | - /** |
|
119 | - * User-id or sign-on for target system. Optional |
|
120 | - * @var string |
|
121 | - */ |
|
122 | - protected $_system_user_id = null; |
|
123 | - |
|
124 | - /** |
|
125 | - * Either a URL-encoded password token or the null string. If the |
|
126 | - * target system requires a password and the null string value is |
|
127 | - * passed, then the target system is responsible for prompting for a |
|
128 | - * password for target system. Optional |
|
129 | - * @var string |
|
130 | - */ |
|
131 | - protected $_system_password = null; |
|
132 | - |
|
133 | - /** |
|
134 | - * URL to send acknowledgement receipt after collecting a package. Any URL, including mailto (as per RFC 2368 and RFC 2822). Required. |
|
135 | - * @var string |
|
136 | - */ |
|
137 | - protected $_receipt = null; |
|
138 | - |
|
139 | - /** |
|
140 | - * URL to send alerts to while processing the package. Any URL, including mailto (as per RFC 2368 and RFC 2822). Optional. |
|
141 | - * @var string |
|
142 | - */ |
|
143 | - protected $_alerts = null; |
|
144 | - |
|
145 | - /** |
|
146 | - * Unstructured character string that may be used to transfer vendor-specific data such as processing hints or deployment information. Optional. |
|
147 | - * @var string |
|
148 | - */ |
|
149 | - protected $_vendor_data = null; |
|
150 | - |
|
151 | - /** |
|
152 | - * Constructor |
|
153 | - * |
|
154 | - * Constructs a PENSRequest based class using the arguments given |
|
155 | - * |
|
156 | - * @param array Arguments |
|
157 | - */ |
|
158 | - public function __construct($arguments) { |
|
159 | - $this->setPensVersion($arguments["pens-version"]); |
|
160 | - $this->setPackageType($arguments["package-type"]); |
|
161 | - $this->setPackageTypeVersion($arguments["package-type-version"]); |
|
162 | - $this->setPackageFormat($arguments["package-format"]); |
|
163 | - $this->setPackageId($arguments["package-id"]); |
|
164 | - $this->setPackageUrl($arguments["package-url"]); |
|
165 | - $this->setPackageUrlUserId($arguments["package-url-user-id"]); |
|
166 | - $this->setPackageUrlAccount($arguments["package-url-account"]); |
|
167 | - $this->setPackageUrlPassword($arguments["package-url-password"]); |
|
168 | - $this->setPackageUrlExpiry($arguments["package-url-expiry"]); |
|
169 | - $this->setClient($arguments["client"]); |
|
170 | - $this->setSystemUserId($arguments["system-user-id"]); |
|
171 | - $this->setSystemPassword($arguments["system-password"]); |
|
172 | - $this->setReceipt($arguments["receipt"]); |
|
173 | - $this->setAlerts($arguments["alerts"]); |
|
174 | - $this->setVendorData($arguments["vendor-data"]); |
|
175 | - } |
|
176 | - |
|
177 | - public function getPensVersion() { |
|
178 | - return $this->_pens_version; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Sets the PENS version |
|
183 | - * |
|
184 | - * @param string PENS version |
|
185 | - * |
|
186 | - * @throws PENSException with code 2001 if invalid |
|
187 | - */ |
|
188 | - public function setPensVersion($pens_version) { |
|
189 | - if($pens_version == PENSConfig::$version) { |
|
190 | - $this->_pens_version = $pens_version; |
|
191 | - } else { |
|
192 | - throw new PENSException(2001); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - public function getCommand() { |
|
197 | - return $this->_command; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Sets the command |
|
202 | - * |
|
203 | - * @param string command |
|
204 | - * |
|
205 | - * @throws PENSException with code 2002 if invalid |
|
206 | - */ |
|
207 | - protected function setCommand($command) { |
|
208 | - if(in_array($command, PENSConfig::$allowed_commands)) { |
|
209 | - $this->_command = $command; |
|
210 | - } else { |
|
211 | - throw new PENSException(2002); |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - public function getPackageType() { |
|
216 | - return $this->_package_type; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Sets the package type |
|
221 | - * |
|
222 | - * @param string package type |
|
223 | - * |
|
224 | - * @throws PENSException with code 2003 if invalid |
|
225 | - */ |
|
226 | - public function setPackageType($package_type) { |
|
227 | - if(in_array($package_type, PENSConfig::$allowed_package_types)) { |
|
228 | - $this->_package_type = $package_type; |
|
229 | - } else { |
|
230 | - throw new PENSException(2003); |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - public function getPackageTypeVersion() { |
|
235 | - return $this->_package_type_version; |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Sets the package type version |
|
240 | - * |
|
241 | - * @param string package type version |
|
242 | - * |
|
243 | - * @throws PENSException with code 2004 if invalid |
|
244 | - */ |
|
245 | - public function setPackageTypeVersion($package_type_version) { |
|
246 | - if(empty($package_type_version)) { |
|
247 | - throw new PENSException(2004); |
|
248 | - } else { |
|
249 | - $this->_package_type_version = $package_type_version; |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - public function getPackageFormat() { |
|
254 | - return $this->_package_format; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Sets the package format |
|
259 | - * |
|
260 | - * @param string package format |
|
261 | - * |
|
262 | - * @throws PENSException with code 2005 if invalid |
|
263 | - */ |
|
264 | - public function setPackageFormat($package_format) { |
|
265 | - if(in_array($package_format, PENSConfig::$allowed_package_formats)) { |
|
266 | - $this->_package_format = $package_format; |
|
267 | - } else { |
|
268 | - throw new PENSException(2005); |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - public function getPackageId() { |
|
273 | - return $this->_package_id; |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Sets the package Id |
|
278 | - * |
|
279 | - * @param string package Id |
|
280 | - * |
|
281 | - * @throws PENSException with code 2007 if invalid |
|
282 | - */ |
|
283 | - public function setPackageId($package_id) { |
|
284 | - if (preg_match('/'.ABSOLUTEURI_2396.'/', $package_id)) { |
|
285 | - $this->_package_id = $package_id; |
|
286 | - } else { |
|
287 | - throw new PENSException(2007); |
|
288 | - } |
|
289 | - } |
|
290 | - |
|
291 | - public function getPackageUrl() { |
|
292 | - return $this->_package_url; |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Sets the package url |
|
297 | - * |
|
298 | - * @param string package url |
|
299 | - * |
|
300 | - * @throws PENSException with code 2008 if invalid |
|
301 | - */ |
|
302 | - public function setPackageUrl($package_url) { |
|
303 | - if (preg_match('/'.ABSOLUTEURI_2396.'/', $package_url) && substr($package_url, -4) == ".".$this->_package_format) { |
|
304 | - $this->_package_url = $package_url; |
|
305 | - } else { |
|
306 | - throw new PENSException(2008); |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - public function getFilename() { |
|
311 | - return substr(strrchr($this->_package_url, "/"), 1); |
|
312 | - } |
|
313 | - |
|
314 | - public function getPackageUrlUserId() { |
|
315 | - return $this->_package_url_user_id; |
|
316 | - } |
|
317 | - |
|
318 | - public function setPackageUrlUserId($package_url_user_id) { |
|
319 | - if(!empty($package_url_user_id)) { |
|
320 | - $this->_package_url_user_id = $package_url_user_id; |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - public function getPackageUrlAccount() { |
|
325 | - return $this->_package_url_account; |
|
326 | - } |
|
327 | - |
|
328 | - public function setPackageUrlAccount($package_url_account) { |
|
329 | - if(!empty($package_url_account)) { |
|
330 | - $this->_package_url_account = $package_url_account; |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - public function getPackageUrlPassword() { |
|
335 | - return $this->_package_url_password; |
|
336 | - } |
|
337 | - |
|
338 | - public function setPackageUrlPassword($package_url_password) { |
|
339 | - if(!empty($package_url_password)) { |
|
340 | - $this->_package_url_password = $package_url_password; |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - public function getPackageUrlExpiry() { |
|
345 | - return $this->_package_url_expiry; |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Sets the package url expiry and transforms it into a php DateTime object |
|
350 | - * |
|
351 | - * @param string package url expiry |
|
352 | - * |
|
353 | - * @throws PENSException with code 2009 if invalid |
|
354 | - * @todo Perform a better validation of the date |
|
355 | - */ |
|
356 | - public function setPackageUrlExpiry($package_url_expiry) { |
|
357 | - if(empty($package_url_expiry)) { |
|
358 | - throw new PENSException(2009); |
|
359 | - } else { |
|
360 | - try { |
|
361 | - $expiry = new DateTime($package_url_expiry, new DateTimeZone('UTC')); |
|
362 | - $this->_package_url_expiry = $expiry; |
|
363 | - } catch(Exception $e) { |
|
364 | - throw new PENSException(2009); |
|
365 | - } |
|
366 | - } |
|
367 | - } |
|
368 | - |
|
369 | - public function getClient() { |
|
370 | - return $this->_client; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Sets the client |
|
375 | - * |
|
376 | - * @param string client |
|
377 | - * |
|
378 | - * @throws PENSException with code 2010 if invalid |
|
379 | - */ |
|
380 | - public function setClient($client) { |
|
381 | - if(!empty($client)) { |
|
382 | - $this->_client = $client; |
|
383 | - } else { |
|
384 | - throw new PENSException(2010); |
|
385 | - } |
|
386 | - } |
|
387 | - |
|
388 | - public function getSystemUserId() { |
|
389 | - return $this->_system_user_id; |
|
390 | - } |
|
391 | - |
|
392 | - public function setSystemUserId($system_user_id) { |
|
393 | - if(!empty($system_user_id)) { |
|
394 | - $this->_system_user_id = $system_user_id; |
|
395 | - } |
|
396 | - } |
|
397 | - |
|
398 | - public function getSystemPassword() { |
|
399 | - return $this->_system_password; |
|
400 | - } |
|
401 | - |
|
402 | - public function setSystemPassword($system_password) { |
|
403 | - if(!empty($system_password)) { |
|
404 | - $this->_system_password = $system_password; |
|
405 | - } |
|
406 | - } |
|
407 | - |
|
408 | - public function getReceipt() { |
|
409 | - return $this->_receipt; |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Sets the receipt url |
|
414 | - * |
|
415 | - * @param string receipt url |
|
416 | - * |
|
417 | - * @throws PENSException with code 2011 if invalid |
|
418 | - */ |
|
419 | - public function setReceipt($receipt) { |
|
420 | - if($this instanceof PENSRequestCollect) { |
|
421 | - if (preg_match('/'.ABSOLUTEURI_2396.'/', $receipt)) { |
|
422 | - $this->_receipt = $receipt; |
|
423 | - } else { |
|
424 | - throw new PENSException(2011); |
|
425 | - } |
|
426 | - } |
|
427 | - } |
|
428 | - |
|
429 | - public function getAlerts() { |
|
430 | - return $this->_alerts; |
|
431 | - } |
|
432 | - |
|
433 | - public function setAlerts($alerts) { |
|
434 | - if(!empty($alerts)) { |
|
435 | - if(preg_match('/'.ABSOLUTEURI_2396.'/', $alerts)) { |
|
436 | - $this->_alerts = $alerts; |
|
437 | - } else { |
|
438 | - throw new PENSException(1201); |
|
439 | - } |
|
440 | - } |
|
441 | - } |
|
442 | - |
|
443 | - public function getVendorData() { |
|
444 | - return $this->_vendor_data; |
|
445 | - } |
|
446 | - |
|
447 | - public function setVendorData($vendor_data) { |
|
448 | - if(!empty($vendor_data)) { |
|
449 | - $this->_vendor_data = $vendor_data; |
|
450 | - } |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Returns an associative that contains all the fields needed to send a |
|
455 | - * receipt or an alert to the client |
|
456 | - * |
|
457 | - * @return array Associative array |
|
458 | - */ |
|
459 | - protected function getSendReceiptAlertArray() { |
|
460 | - return array("pens-version" => $this->getPensVersion(), |
|
461 | - "package-type" => $this->getPackageType(), |
|
462 | - "package-type-version" => $this->getPackageTypeVersion(), |
|
463 | - "package-format" => $this->getPackageFormat(), |
|
464 | - "package-id" => $this->getPackageId(), |
|
465 | - "package-url" => $this->getPackageUrl(), |
|
466 | - "package-url-expiry" => $this->getPackageUrlExpiry()->format(DateTime::ISO8601), |
|
467 | - "client" => $this->getClient()); |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * Returns an associative that contains all the fields needed to send a |
|
472 | - * receipt to the client |
|
473 | - * |
|
474 | - * @return array Associative array |
|
475 | - */ |
|
476 | - public function getSendReceiptArray() { |
|
477 | - $receipt = $this->getSendReceiptAlertArray(); |
|
478 | - $receipt["command"] = "receipt"; |
|
479 | - return $receipt; |
|
480 | - } |
|
481 | - |
|
482 | - /** |
|
483 | - * Returns an associative that contains all the fields needed to send an |
|
484 | - * alert to the client |
|
485 | - * |
|
486 | - * @return array Associative array |
|
487 | - */ |
|
488 | - public function getSendAlertArray() { |
|
489 | - $alert = $this->getSendReceiptAlertArray(); |
|
490 | - $alert["command"] = "alert"; |
|
491 | - return $alert; |
|
492 | - } |
|
46 | + /** |
|
47 | + * PENS Version to be used. Currently, the only valid value is 1.0.0. Required. |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + protected $_pens_version = null; |
|
51 | + |
|
52 | + /** |
|
53 | + * Command being used. The only valid values are collect, alert and receipt.Required |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + protected $_command = null; |
|
57 | + |
|
58 | + /** |
|
59 | + * Package type being used. The only valid values are aicc-pkg, scorm-pif, ims-qti. Required |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + protected $_package_type = null; |
|
63 | + |
|
64 | + /** |
|
65 | + * Package type version. Required |
|
66 | + * @var string |
|
67 | + */ |
|
68 | + protected $_package_type_version = null; |
|
69 | + |
|
70 | + /** |
|
71 | + * Package format. The only valid values are zip, url, jar, war and xml. Required |
|
72 | + * @var string |
|
73 | + */ |
|
74 | + protected $_package_format = null; |
|
75 | + |
|
76 | + /** |
|
77 | + * Package id. Requires a valid URI according to RFC 2396. Required |
|
78 | + * @var string |
|
79 | + */ |
|
80 | + protected $_package_id = null; |
|
81 | + |
|
82 | + /** |
|
83 | + * Package url. Requires a valid, fully qualified URL including transport protocol and filename extension. Required |
|
84 | + * @var string |
|
85 | + */ |
|
86 | + protected $_package_url = null; |
|
87 | + |
|
88 | + /** |
|
89 | + * User id required for system to retrieve package from URL. Optional. |
|
90 | + * @var string |
|
91 | + */ |
|
92 | + protected $_package_url_user_id = null; |
|
93 | + |
|
94 | + /** |
|
95 | + * Account required for system to retrieve package from URL. Optional. |
|
96 | + * @var string |
|
97 | + */ |
|
98 | + protected $_package_url_account = null; |
|
99 | + |
|
100 | + /** |
|
101 | + * Password required for system to retrieve package from URL. Optional. |
|
102 | + * @var string |
|
103 | + */ |
|
104 | + protected $_package_url_password = null; |
|
105 | + |
|
106 | + /** |
|
107 | + * Expiry date for package URL. ISO 8601 format expressed as UTC. Will be transformed into a PHP DateTime object during construction. Required |
|
108 | + * @var DateTime |
|
109 | + */ |
|
110 | + protected $_package_url_expiry = null; |
|
111 | + |
|
112 | + /** |
|
113 | + * Name or ID for client submitting the content package to the target system. Required. |
|
114 | + * @var string |
|
115 | + */ |
|
116 | + protected $_client = null; |
|
117 | + |
|
118 | + /** |
|
119 | + * User-id or sign-on for target system. Optional |
|
120 | + * @var string |
|
121 | + */ |
|
122 | + protected $_system_user_id = null; |
|
123 | + |
|
124 | + /** |
|
125 | + * Either a URL-encoded password token or the null string. If the |
|
126 | + * target system requires a password and the null string value is |
|
127 | + * passed, then the target system is responsible for prompting for a |
|
128 | + * password for target system. Optional |
|
129 | + * @var string |
|
130 | + */ |
|
131 | + protected $_system_password = null; |
|
132 | + |
|
133 | + /** |
|
134 | + * URL to send acknowledgement receipt after collecting a package. Any URL, including mailto (as per RFC 2368 and RFC 2822). Required. |
|
135 | + * @var string |
|
136 | + */ |
|
137 | + protected $_receipt = null; |
|
138 | + |
|
139 | + /** |
|
140 | + * URL to send alerts to while processing the package. Any URL, including mailto (as per RFC 2368 and RFC 2822). Optional. |
|
141 | + * @var string |
|
142 | + */ |
|
143 | + protected $_alerts = null; |
|
144 | + |
|
145 | + /** |
|
146 | + * Unstructured character string that may be used to transfer vendor-specific data such as processing hints or deployment information. Optional. |
|
147 | + * @var string |
|
148 | + */ |
|
149 | + protected $_vendor_data = null; |
|
150 | + |
|
151 | + /** |
|
152 | + * Constructor |
|
153 | + * |
|
154 | + * Constructs a PENSRequest based class using the arguments given |
|
155 | + * |
|
156 | + * @param array Arguments |
|
157 | + */ |
|
158 | + public function __construct($arguments) { |
|
159 | + $this->setPensVersion($arguments["pens-version"]); |
|
160 | + $this->setPackageType($arguments["package-type"]); |
|
161 | + $this->setPackageTypeVersion($arguments["package-type-version"]); |
|
162 | + $this->setPackageFormat($arguments["package-format"]); |
|
163 | + $this->setPackageId($arguments["package-id"]); |
|
164 | + $this->setPackageUrl($arguments["package-url"]); |
|
165 | + $this->setPackageUrlUserId($arguments["package-url-user-id"]); |
|
166 | + $this->setPackageUrlAccount($arguments["package-url-account"]); |
|
167 | + $this->setPackageUrlPassword($arguments["package-url-password"]); |
|
168 | + $this->setPackageUrlExpiry($arguments["package-url-expiry"]); |
|
169 | + $this->setClient($arguments["client"]); |
|
170 | + $this->setSystemUserId($arguments["system-user-id"]); |
|
171 | + $this->setSystemPassword($arguments["system-password"]); |
|
172 | + $this->setReceipt($arguments["receipt"]); |
|
173 | + $this->setAlerts($arguments["alerts"]); |
|
174 | + $this->setVendorData($arguments["vendor-data"]); |
|
175 | + } |
|
176 | + |
|
177 | + public function getPensVersion() { |
|
178 | + return $this->_pens_version; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Sets the PENS version |
|
183 | + * |
|
184 | + * @param string PENS version |
|
185 | + * |
|
186 | + * @throws PENSException with code 2001 if invalid |
|
187 | + */ |
|
188 | + public function setPensVersion($pens_version) { |
|
189 | + if($pens_version == PENSConfig::$version) { |
|
190 | + $this->_pens_version = $pens_version; |
|
191 | + } else { |
|
192 | + throw new PENSException(2001); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + public function getCommand() { |
|
197 | + return $this->_command; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Sets the command |
|
202 | + * |
|
203 | + * @param string command |
|
204 | + * |
|
205 | + * @throws PENSException with code 2002 if invalid |
|
206 | + */ |
|
207 | + protected function setCommand($command) { |
|
208 | + if(in_array($command, PENSConfig::$allowed_commands)) { |
|
209 | + $this->_command = $command; |
|
210 | + } else { |
|
211 | + throw new PENSException(2002); |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + public function getPackageType() { |
|
216 | + return $this->_package_type; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Sets the package type |
|
221 | + * |
|
222 | + * @param string package type |
|
223 | + * |
|
224 | + * @throws PENSException with code 2003 if invalid |
|
225 | + */ |
|
226 | + public function setPackageType($package_type) { |
|
227 | + if(in_array($package_type, PENSConfig::$allowed_package_types)) { |
|
228 | + $this->_package_type = $package_type; |
|
229 | + } else { |
|
230 | + throw new PENSException(2003); |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + public function getPackageTypeVersion() { |
|
235 | + return $this->_package_type_version; |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Sets the package type version |
|
240 | + * |
|
241 | + * @param string package type version |
|
242 | + * |
|
243 | + * @throws PENSException with code 2004 if invalid |
|
244 | + */ |
|
245 | + public function setPackageTypeVersion($package_type_version) { |
|
246 | + if(empty($package_type_version)) { |
|
247 | + throw new PENSException(2004); |
|
248 | + } else { |
|
249 | + $this->_package_type_version = $package_type_version; |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + public function getPackageFormat() { |
|
254 | + return $this->_package_format; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Sets the package format |
|
259 | + * |
|
260 | + * @param string package format |
|
261 | + * |
|
262 | + * @throws PENSException with code 2005 if invalid |
|
263 | + */ |
|
264 | + public function setPackageFormat($package_format) { |
|
265 | + if(in_array($package_format, PENSConfig::$allowed_package_formats)) { |
|
266 | + $this->_package_format = $package_format; |
|
267 | + } else { |
|
268 | + throw new PENSException(2005); |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + public function getPackageId() { |
|
273 | + return $this->_package_id; |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Sets the package Id |
|
278 | + * |
|
279 | + * @param string package Id |
|
280 | + * |
|
281 | + * @throws PENSException with code 2007 if invalid |
|
282 | + */ |
|
283 | + public function setPackageId($package_id) { |
|
284 | + if (preg_match('/'.ABSOLUTEURI_2396.'/', $package_id)) { |
|
285 | + $this->_package_id = $package_id; |
|
286 | + } else { |
|
287 | + throw new PENSException(2007); |
|
288 | + } |
|
289 | + } |
|
290 | + |
|
291 | + public function getPackageUrl() { |
|
292 | + return $this->_package_url; |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Sets the package url |
|
297 | + * |
|
298 | + * @param string package url |
|
299 | + * |
|
300 | + * @throws PENSException with code 2008 if invalid |
|
301 | + */ |
|
302 | + public function setPackageUrl($package_url) { |
|
303 | + if (preg_match('/'.ABSOLUTEURI_2396.'/', $package_url) && substr($package_url, -4) == ".".$this->_package_format) { |
|
304 | + $this->_package_url = $package_url; |
|
305 | + } else { |
|
306 | + throw new PENSException(2008); |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + public function getFilename() { |
|
311 | + return substr(strrchr($this->_package_url, "/"), 1); |
|
312 | + } |
|
313 | + |
|
314 | + public function getPackageUrlUserId() { |
|
315 | + return $this->_package_url_user_id; |
|
316 | + } |
|
317 | + |
|
318 | + public function setPackageUrlUserId($package_url_user_id) { |
|
319 | + if(!empty($package_url_user_id)) { |
|
320 | + $this->_package_url_user_id = $package_url_user_id; |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + public function getPackageUrlAccount() { |
|
325 | + return $this->_package_url_account; |
|
326 | + } |
|
327 | + |
|
328 | + public function setPackageUrlAccount($package_url_account) { |
|
329 | + if(!empty($package_url_account)) { |
|
330 | + $this->_package_url_account = $package_url_account; |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + public function getPackageUrlPassword() { |
|
335 | + return $this->_package_url_password; |
|
336 | + } |
|
337 | + |
|
338 | + public function setPackageUrlPassword($package_url_password) { |
|
339 | + if(!empty($package_url_password)) { |
|
340 | + $this->_package_url_password = $package_url_password; |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + public function getPackageUrlExpiry() { |
|
345 | + return $this->_package_url_expiry; |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Sets the package url expiry and transforms it into a php DateTime object |
|
350 | + * |
|
351 | + * @param string package url expiry |
|
352 | + * |
|
353 | + * @throws PENSException with code 2009 if invalid |
|
354 | + * @todo Perform a better validation of the date |
|
355 | + */ |
|
356 | + public function setPackageUrlExpiry($package_url_expiry) { |
|
357 | + if(empty($package_url_expiry)) { |
|
358 | + throw new PENSException(2009); |
|
359 | + } else { |
|
360 | + try { |
|
361 | + $expiry = new DateTime($package_url_expiry, new DateTimeZone('UTC')); |
|
362 | + $this->_package_url_expiry = $expiry; |
|
363 | + } catch(Exception $e) { |
|
364 | + throw new PENSException(2009); |
|
365 | + } |
|
366 | + } |
|
367 | + } |
|
368 | + |
|
369 | + public function getClient() { |
|
370 | + return $this->_client; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Sets the client |
|
375 | + * |
|
376 | + * @param string client |
|
377 | + * |
|
378 | + * @throws PENSException with code 2010 if invalid |
|
379 | + */ |
|
380 | + public function setClient($client) { |
|
381 | + if(!empty($client)) { |
|
382 | + $this->_client = $client; |
|
383 | + } else { |
|
384 | + throw new PENSException(2010); |
|
385 | + } |
|
386 | + } |
|
387 | + |
|
388 | + public function getSystemUserId() { |
|
389 | + return $this->_system_user_id; |
|
390 | + } |
|
391 | + |
|
392 | + public function setSystemUserId($system_user_id) { |
|
393 | + if(!empty($system_user_id)) { |
|
394 | + $this->_system_user_id = $system_user_id; |
|
395 | + } |
|
396 | + } |
|
397 | + |
|
398 | + public function getSystemPassword() { |
|
399 | + return $this->_system_password; |
|
400 | + } |
|
401 | + |
|
402 | + public function setSystemPassword($system_password) { |
|
403 | + if(!empty($system_password)) { |
|
404 | + $this->_system_password = $system_password; |
|
405 | + } |
|
406 | + } |
|
407 | + |
|
408 | + public function getReceipt() { |
|
409 | + return $this->_receipt; |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Sets the receipt url |
|
414 | + * |
|
415 | + * @param string receipt url |
|
416 | + * |
|
417 | + * @throws PENSException with code 2011 if invalid |
|
418 | + */ |
|
419 | + public function setReceipt($receipt) { |
|
420 | + if($this instanceof PENSRequestCollect) { |
|
421 | + if (preg_match('/'.ABSOLUTEURI_2396.'/', $receipt)) { |
|
422 | + $this->_receipt = $receipt; |
|
423 | + } else { |
|
424 | + throw new PENSException(2011); |
|
425 | + } |
|
426 | + } |
|
427 | + } |
|
428 | + |
|
429 | + public function getAlerts() { |
|
430 | + return $this->_alerts; |
|
431 | + } |
|
432 | + |
|
433 | + public function setAlerts($alerts) { |
|
434 | + if(!empty($alerts)) { |
|
435 | + if(preg_match('/'.ABSOLUTEURI_2396.'/', $alerts)) { |
|
436 | + $this->_alerts = $alerts; |
|
437 | + } else { |
|
438 | + throw new PENSException(1201); |
|
439 | + } |
|
440 | + } |
|
441 | + } |
|
442 | + |
|
443 | + public function getVendorData() { |
|
444 | + return $this->_vendor_data; |
|
445 | + } |
|
446 | + |
|
447 | + public function setVendorData($vendor_data) { |
|
448 | + if(!empty($vendor_data)) { |
|
449 | + $this->_vendor_data = $vendor_data; |
|
450 | + } |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * Returns an associative that contains all the fields needed to send a |
|
455 | + * receipt or an alert to the client |
|
456 | + * |
|
457 | + * @return array Associative array |
|
458 | + */ |
|
459 | + protected function getSendReceiptAlertArray() { |
|
460 | + return array("pens-version" => $this->getPensVersion(), |
|
461 | + "package-type" => $this->getPackageType(), |
|
462 | + "package-type-version" => $this->getPackageTypeVersion(), |
|
463 | + "package-format" => $this->getPackageFormat(), |
|
464 | + "package-id" => $this->getPackageId(), |
|
465 | + "package-url" => $this->getPackageUrl(), |
|
466 | + "package-url-expiry" => $this->getPackageUrlExpiry()->format(DateTime::ISO8601), |
|
467 | + "client" => $this->getClient()); |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * Returns an associative that contains all the fields needed to send a |
|
472 | + * receipt to the client |
|
473 | + * |
|
474 | + * @return array Associative array |
|
475 | + */ |
|
476 | + public function getSendReceiptArray() { |
|
477 | + $receipt = $this->getSendReceiptAlertArray(); |
|
478 | + $receipt["command"] = "receipt"; |
|
479 | + return $receipt; |
|
480 | + } |
|
481 | + |
|
482 | + /** |
|
483 | + * Returns an associative that contains all the fields needed to send an |
|
484 | + * alert to the client |
|
485 | + * |
|
486 | + * @return array Associative array |
|
487 | + */ |
|
488 | + public function getSendAlertArray() { |
|
489 | + $alert = $this->getSendReceiptAlertArray(); |
|
490 | + $alert["command"] = "alert"; |
|
491 | + return $alert; |
|
492 | + } |
|
493 | 493 | |
494 | 494 | |
495 | 495 | } |
@@ -16,54 +16,54 @@ |
||
16 | 16 | * along with php-pens. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | */ |
18 | 18 | |
19 | - /** |
|
20 | - * PENSConfig |
|
21 | - * |
|
22 | - * Provides the PENSConfig class |
|
23 | - * |
|
24 | - * @package PENS |
|
25 | - * @author Guillaume Viguier-Just <[email protected]> |
|
26 | - * @licence http://www.gnu.org/licenses/gpl.txt |
|
27 | - */ |
|
19 | + /** |
|
20 | + * PENSConfig |
|
21 | + * |
|
22 | + * Provides the PENSConfig class |
|
23 | + * |
|
24 | + * @package PENS |
|
25 | + * @author Guillaume Viguier-Just <[email protected]> |
|
26 | + * @licence http://www.gnu.org/licenses/gpl.txt |
|
27 | + */ |
|
28 | 28 | |
29 | - /** |
|
30 | - * PENSConfig |
|
31 | - * |
|
32 | - * This class provides different static variables to configure php-pens. |
|
33 | - * |
|
34 | - * @package PENS |
|
35 | - * @author Guillaume Viguier-Just <[email protected]> |
|
36 | - * @licence http://www.gnu.org/licenses/gpl.txt |
|
37 | - */ |
|
29 | + /** |
|
30 | + * PENSConfig |
|
31 | + * |
|
32 | + * This class provides different static variables to configure php-pens. |
|
33 | + * |
|
34 | + * @package PENS |
|
35 | + * @author Guillaume Viguier-Just <[email protected]> |
|
36 | + * @licence http://www.gnu.org/licenses/gpl.txt |
|
37 | + */ |
|
38 | 38 | class PENSConfig { |
39 | 39 | |
40 | - /** |
|
41 | - * PENS version |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - public static $version = "1.0.0"; |
|
40 | + /** |
|
41 | + * PENS version |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + public static $version = "1.0.0"; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Allowed commands |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - public static $allowed_commands = array("collect", "receipt", "alert"); |
|
46 | + /** |
|
47 | + * Allowed commands |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + public static $allowed_commands = array("collect", "receipt", "alert"); |
|
51 | 51 | |
52 | - /** |
|
53 | - * Allowed package types |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - public static $allowed_package_types = array("aicc-pkg", "scorm-pif", "ims-qti"); |
|
52 | + /** |
|
53 | + * Allowed package types |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + public static $allowed_package_types = array("aicc-pkg", "scorm-pif", "ims-qti"); |
|
57 | 57 | |
58 | - /** |
|
59 | - * Allowed package formats |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public static $allowed_package_formats = array("zip", "url", "jar", "war", "xml"); |
|
58 | + /** |
|
59 | + * Allowed package formats |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public static $allowed_package_formats = array("zip", "url", "jar", "war", "xml"); |
|
63 | 63 | |
64 | - /** |
|
65 | - * End of line as specified by the PENS specification |
|
66 | - * @var string |
|
67 | - */ |
|
68 | - public static $eol = "\r\n"; |
|
64 | + /** |
|
65 | + * End of line as specified by the PENS specification |
|
66 | + * @var string |
|
67 | + */ |
|
68 | + public static $eol = "\r\n"; |
|
69 | 69 | } |
@@ -37,62 +37,62 @@ |
||
37 | 37 | */ |
38 | 38 | class PENSException extends Exception { |
39 | 39 | |
40 | - /** |
|
41 | - * Array that provides an association between exception codes and messages |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - protected static $_code_to_messages = array( |
|
45 | - 1101 => "Unable to parse PENS command", |
|
46 | - 1201 => "Attempt to pass an invalid argument", |
|
47 | - 1301 => "Unable to retrieve package", |
|
48 | - 1302 => "Unable to retrieve package via HTTPS", |
|
49 | - 1304 => "Unable to retrieve package via FTP", |
|
50 | - 1306 => "Unable to retrieve package via FTPS", |
|
51 | - 1310 => "Unable to retrieve package at specified URL due to error in URL or lack of response from URL", |
|
52 | - 1312 => "Unable to retrieve package at specified URL due to error with access credential for package URL", |
|
53 | - 1320 => "Expiration date is non-null and in an improper format", |
|
54 | - 1322 => "Current time indicates expiry date has passed", |
|
55 | - 1420 => "PENS version not supported", |
|
56 | - 1421 => "Command not supported", |
|
57 | - 1430 => "Package type not supported", |
|
58 | - // The following error code is not specified in the PENS specification and was added in this implementation |
|
59 | - 1431 => "Package format not supported", |
|
60 | - 1432 => "Internal package error", |
|
61 | - 1440 => "Insufficient host space/storage available", |
|
62 | - 1500 => "Unable to communicate with provided acknowledgement URL", |
|
63 | - 1510 => "Unsupported acknowledgement protocol", |
|
64 | - 1520 => "Unsupported alert protocol", |
|
65 | - 2001 => "PENS version invalid or not specified", |
|
66 | - 2002 => "PENS command invalid or not specified", |
|
67 | - 2003 => "package-type invalid or not specified", |
|
68 | - 2004 => "package-type-version invalid or not specified", |
|
69 | - 2005 => "package-format invalid or not specified", |
|
70 | - 2007 => "package-id invalid or not specified", |
|
71 | - 2008 => "package-url invalid or not specified", |
|
72 | - 2009 => "package-url-expiry date invalid or not specified", |
|
73 | - 2010 => "client submitting package invalid or not specified", |
|
74 | - 2011 => "receipt url invalid or not specified" |
|
75 | - ); |
|
40 | + /** |
|
41 | + * Array that provides an association between exception codes and messages |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + protected static $_code_to_messages = array( |
|
45 | + 1101 => "Unable to parse PENS command", |
|
46 | + 1201 => "Attempt to pass an invalid argument", |
|
47 | + 1301 => "Unable to retrieve package", |
|
48 | + 1302 => "Unable to retrieve package via HTTPS", |
|
49 | + 1304 => "Unable to retrieve package via FTP", |
|
50 | + 1306 => "Unable to retrieve package via FTPS", |
|
51 | + 1310 => "Unable to retrieve package at specified URL due to error in URL or lack of response from URL", |
|
52 | + 1312 => "Unable to retrieve package at specified URL due to error with access credential for package URL", |
|
53 | + 1320 => "Expiration date is non-null and in an improper format", |
|
54 | + 1322 => "Current time indicates expiry date has passed", |
|
55 | + 1420 => "PENS version not supported", |
|
56 | + 1421 => "Command not supported", |
|
57 | + 1430 => "Package type not supported", |
|
58 | + // The following error code is not specified in the PENS specification and was added in this implementation |
|
59 | + 1431 => "Package format not supported", |
|
60 | + 1432 => "Internal package error", |
|
61 | + 1440 => "Insufficient host space/storage available", |
|
62 | + 1500 => "Unable to communicate with provided acknowledgement URL", |
|
63 | + 1510 => "Unsupported acknowledgement protocol", |
|
64 | + 1520 => "Unsupported alert protocol", |
|
65 | + 2001 => "PENS version invalid or not specified", |
|
66 | + 2002 => "PENS command invalid or not specified", |
|
67 | + 2003 => "package-type invalid or not specified", |
|
68 | + 2004 => "package-type-version invalid or not specified", |
|
69 | + 2005 => "package-format invalid or not specified", |
|
70 | + 2007 => "package-id invalid or not specified", |
|
71 | + 2008 => "package-url invalid or not specified", |
|
72 | + 2009 => "package-url-expiry date invalid or not specified", |
|
73 | + 2010 => "client submitting package invalid or not specified", |
|
74 | + 2011 => "receipt url invalid or not specified" |
|
75 | + ); |
|
76 | 76 | |
77 | - /** |
|
78 | - * Redefines the constructor so that code is the first argument |
|
79 | - * |
|
80 | - * @param int Exception code |
|
81 | - * @param string Message to display |
|
82 | - * @return PENSException Exception created |
|
83 | - */ |
|
84 | - public function __construct($code, $message = null) { |
|
85 | - parent::__construct($message, $code); |
|
86 | - $this->setMessageBasedOnCode(); |
|
87 | - } |
|
77 | + /** |
|
78 | + * Redefines the constructor so that code is the first argument |
|
79 | + * |
|
80 | + * @param int Exception code |
|
81 | + * @param string Message to display |
|
82 | + * @return PENSException Exception created |
|
83 | + */ |
|
84 | + public function __construct($code, $message = null) { |
|
85 | + parent::__construct($message, $code); |
|
86 | + $this->setMessageBasedOnCode(); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Sets the message based on the code |
|
91 | - */ |
|
92 | - protected function setMessageBasedOnCode() { |
|
93 | - if(empty($this->message) && !empty(self::$_code_to_messages[$this->code])) { |
|
94 | - $this->message = self::$_code_to_messages[$this->code]; |
|
95 | - } |
|
96 | - } |
|
89 | + /** |
|
90 | + * Sets the message based on the code |
|
91 | + */ |
|
92 | + protected function setMessageBasedOnCode() { |
|
93 | + if(empty($this->message) && !empty(self::$_code_to_messages[$this->code])) { |
|
94 | + $this->message = self::$_code_to_messages[$this->code]; |
|
95 | + } |
|
96 | + } |
|
97 | 97 | |
98 | 98 | } |
@@ -29,19 +29,19 @@ |
||
29 | 29 | require_once __DIR__ . '/chamilo_pens.php'; |
30 | 30 | |
31 | 31 | class ChamiloPackageHandler extends PENSPackageHandler { |
32 | - public function processPackage($request, $path_to_package) { |
|
33 | - $server = PENSServer::singleton(); |
|
34 | - // Moves the package to archive/pens |
|
35 | - $path_to_archives = api_get_path(SYS_ARCHIVE_PATH) . 'pens'; |
|
36 | - if(!is_dir($path_to_archives)) { |
|
37 | - mkdir($path_to_archives, 0777, true); |
|
38 | - } |
|
39 | - rename($path_to_package, $path_to_archives . '/' . $request->getFilename()); |
|
40 | - // Insert the request in the database |
|
41 | - $chamilo_pens = new ChamiloPens($request); |
|
42 | - $chamilo_pens->save(); |
|
43 | - $server->sendAlert($request, new PENSResponse(0, 'Package successfully processed')); |
|
44 | - } |
|
32 | + public function processPackage($request, $path_to_package) { |
|
33 | + $server = PENSServer::singleton(); |
|
34 | + // Moves the package to archive/pens |
|
35 | + $path_to_archives = api_get_path(SYS_ARCHIVE_PATH) . 'pens'; |
|
36 | + if(!is_dir($path_to_archives)) { |
|
37 | + mkdir($path_to_archives, 0777, true); |
|
38 | + } |
|
39 | + rename($path_to_package, $path_to_archives . '/' . $request->getFilename()); |
|
40 | + // Insert the request in the database |
|
41 | + $chamilo_pens = new ChamiloPens($request); |
|
42 | + $chamilo_pens->save(); |
|
43 | + $server->sendAlert($request, new PENSResponse(0, 'Package successfully processed')); |
|
44 | + } |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | $handler = new ChamiloPackageHandler(); |
@@ -14,36 +14,36 @@ discard block |
||
14 | 14 | class BlockStudent extends Block |
15 | 15 | { |
16 | 16 | private $user_id; |
17 | - private $students; |
|
18 | - private $path; |
|
19 | - private $permission = array(DRH); |
|
17 | + private $students; |
|
18 | + private $path; |
|
19 | + private $permission = array(DRH); |
|
20 | 20 | |
21 | - /** |
|
22 | - * Constructor |
|
23 | - */ |
|
21 | + /** |
|
22 | + * Constructor |
|
23 | + */ |
|
24 | 24 | public function __construct ($user_id) |
25 | 25 | { |
26 | - $this->user_id = $user_id; |
|
27 | - $this->path = 'block_student'; |
|
28 | - if ($this->is_block_visible_for_user($user_id)) { |
|
26 | + $this->user_id = $user_id; |
|
27 | + $this->path = 'block_student'; |
|
28 | + if ($this->is_block_visible_for_user($user_id)) { |
|
29 | 29 | $this->students = UserManager::get_users_followed_by_drh($user_id, STUDENT); |
30 | - } |
|
30 | + } |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | - * This method check if a user is allowed to see the block inside dashboard interface |
|
35 | - * @param int User id |
|
36 | - * @return bool Is block visible for user |
|
37 | - */ |
|
34 | + * This method check if a user is allowed to see the block inside dashboard interface |
|
35 | + * @param int User id |
|
36 | + * @return bool Is block visible for user |
|
37 | + */ |
|
38 | 38 | public function is_block_visible_for_user($user_id) |
39 | 39 | { |
40 | - $user_info = api_get_user_info($user_id); |
|
41 | - $user_status = $user_info['status']; |
|
42 | - $is_block_visible_for_user = false; |
|
43 | - if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) { |
|
44 | - $is_block_visible_for_user = true; |
|
45 | - } |
|
46 | - return $is_block_visible_for_user; |
|
40 | + $user_info = api_get_user_info($user_id); |
|
41 | + $user_status = $user_info['status']; |
|
42 | + $is_block_visible_for_user = false; |
|
43 | + if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) { |
|
44 | + $is_block_visible_for_user = true; |
|
45 | + } |
|
46 | + return $is_block_visible_for_user; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function get_block() |
55 | 55 | { |
56 | - global $charset; |
|
57 | - $column = 1; |
|
58 | - $data = array(); |
|
56 | + global $charset; |
|
57 | + $column = 1; |
|
58 | + $data = array(); |
|
59 | 59 | |
60 | 60 | $student_content_html = $this->get_students_content_html_for_drh(); |
61 | - $html = '<div class="panel panel-default" id="intro"> |
|
61 | + $html = '<div class="panel panel-default" id="intro"> |
|
62 | 62 | <div class="panel-heading"> |
63 | 63 | '.get_lang('StudentsInformationsList').' |
64 | 64 | <div class="pull-right"><a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'"> |
@@ -70,24 +70,24 @@ discard block |
||
70 | 70 | '.$student_content_html.' |
71 | 71 | </div> |
72 | 72 | </div>'; |
73 | - $data['column'] = $column; |
|
74 | - $data['content_html'] = $html; |
|
75 | - return $data; |
|
73 | + $data['column'] = $column; |
|
74 | + $data['content_html'] = $html; |
|
75 | + return $data; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * This method return a content html, it's used inside get_block method for showing it inside dashboard interface |
|
80 | - * @return string content html |
|
81 | - */ |
|
79 | + * This method return a content html, it's used inside get_block method for showing it inside dashboard interface |
|
80 | + * @return string content html |
|
81 | + */ |
|
82 | 82 | public function get_students_content_html_for_platform_admin() |
83 | 83 | { |
84 | - $students = $this->students; |
|
85 | - //$content = '<div style="margin:10px;">'; |
|
86 | - $content = '<h4>'.get_lang('YourStudents').'</h4>'; |
|
84 | + $students = $this->students; |
|
85 | + //$content = '<div style="margin:10px;">'; |
|
86 | + $content = '<h4>'.get_lang('YourStudents').'</h4>'; |
|
87 | 87 | $students_table = null; |
88 | - if (count($students) > 0) { |
|
89 | - $students_table .= '<table class="data_table">'; |
|
90 | - $students_table .= '<tr> |
|
88 | + if (count($students) > 0) { |
|
89 | + $students_table .= '<table class="data_table">'; |
|
90 | + $students_table .= '<tr> |
|
91 | 91 | <th width="10%" rowspan="2">'.get_lang('FirstName').'</th> |
92 | 92 | <th width="10%" rowspan="2">'.get_lang('LastName').'</th> |
93 | 93 | <th width="30%" colspan="2">'.get_lang('CourseInformation').'</th> |
@@ -97,146 +97,146 @@ discard block |
||
97 | 97 | <th width="10%">'.get_lang('Time').'</th> |
98 | 98 | </tr>'; |
99 | 99 | |
100 | - $i = 1; |
|
101 | - foreach ($students as $student) { |
|
100 | + $i = 1; |
|
101 | + foreach ($students as $student) { |
|
102 | 102 | |
103 | - $courses_by_user = CourseManager::get_courses_list_by_user_id($student['user_id'], true); |
|
104 | - $count_courses = count($courses_by_user); |
|
105 | - $rowspan = $count_courses?$count_courses+1:2; |
|
103 | + $courses_by_user = CourseManager::get_courses_list_by_user_id($student['user_id'], true); |
|
104 | + $count_courses = count($courses_by_user); |
|
105 | + $rowspan = $count_courses?$count_courses+1:2; |
|
106 | 106 | |
107 | - if ($i%2 == 0) { |
|
107 | + if ($i%2 == 0) { |
|
108 | 108 | $style = ' style="background-color:#F2F2F2" '; |
109 | 109 | } else { |
110 | 110 | $style = ' style="background-color:#FFF" '; |
111 | 111 | } |
112 | 112 | |
113 | - $students_table .= '<tr '.$style.'> |
|
113 | + $students_table .= '<tr '.$style.'> |
|
114 | 114 | <td rowspan="'.$rowspan.'">'.$student['firstname'].'</td> |
115 | 115 | <td rowspan="'.$rowspan.'">'.$student['lastname'].'</td> |
116 | 116 | </tr>'; |
117 | 117 | |
118 | - // courses information about the student |
|
119 | - if (!empty($courses_by_user)) { |
|
120 | - foreach ($courses_by_user as $course) { |
|
121 | - $course_code = $course['code']; |
|
122 | - $courseInfo = api_get_course_info($course_code); |
|
123 | - $courseId = $courseInfo['real_id']; |
|
124 | - $course_title = $course['title']; |
|
125 | - $time = api_time_to_hms(Tracking :: get_time_spent_on_the_course($student['user_id'], $courseId)); |
|
126 | - $students_table .= '<tr '.$style.'> |
|
118 | + // courses information about the student |
|
119 | + if (!empty($courses_by_user)) { |
|
120 | + foreach ($courses_by_user as $course) { |
|
121 | + $course_code = $course['code']; |
|
122 | + $courseInfo = api_get_course_info($course_code); |
|
123 | + $courseId = $courseInfo['real_id']; |
|
124 | + $course_title = $course['title']; |
|
125 | + $time = api_time_to_hms(Tracking :: get_time_spent_on_the_course($student['user_id'], $courseId)); |
|
126 | + $students_table .= '<tr '.$style.'> |
|
127 | 127 | <td align="right">'.$course_title.'</td> |
128 | 128 | <td align="right">'.$time.'</td> |
129 | 129 | </tr>'; |
130 | - } |
|
131 | - } else { |
|
132 | - $students_table .= '<tr '.$style.'> |
|
130 | + } |
|
131 | + } else { |
|
132 | + $students_table .= '<tr '.$style.'> |
|
133 | 133 | <td align="center" colspan="2"><i>'.get_lang('Empty').'</i></td> |
134 | 134 | </tr>'; |
135 | - } |
|
136 | - $i++; |
|
137 | - } |
|
138 | - $students_table .= '</table>'; |
|
139 | - } else { |
|
140 | - $students_table .= get_lang('ThereIsNoInformationAboutYourStudents'); |
|
141 | - } |
|
142 | - |
|
143 | - $content .= $students_table; |
|
144 | - |
|
145 | - if (count($students) > 0) { |
|
146 | - $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=useroverview">'.get_lang('SeeMore').'</a></div>'; |
|
147 | - } |
|
148 | - //$content .= '</div>'; |
|
149 | - |
|
150 | - return $content; |
|
151 | - } |
|
152 | - |
|
153 | - public function get_students_content_html_for_drh() { |
|
154 | - $attendance = new Attendance(); |
|
155 | - $students = $this->students; |
|
156 | - //$content = '<div style="margin:5px;">'; |
|
157 | - $content = '<h4>'.get_lang('YourStudents').'</h4>'; |
|
135 | + } |
|
136 | + $i++; |
|
137 | + } |
|
138 | + $students_table .= '</table>'; |
|
139 | + } else { |
|
140 | + $students_table .= get_lang('ThereIsNoInformationAboutYourStudents'); |
|
141 | + } |
|
142 | + |
|
143 | + $content .= $students_table; |
|
144 | + |
|
145 | + if (count($students) > 0) { |
|
146 | + $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=useroverview">'.get_lang('SeeMore').'</a></div>'; |
|
147 | + } |
|
148 | + //$content .= '</div>'; |
|
149 | + |
|
150 | + return $content; |
|
151 | + } |
|
152 | + |
|
153 | + public function get_students_content_html_for_drh() { |
|
154 | + $attendance = new Attendance(); |
|
155 | + $students = $this->students; |
|
156 | + //$content = '<div style="margin:5px;">'; |
|
157 | + $content = '<h4>'.get_lang('YourStudents').'</h4>'; |
|
158 | 158 | $students_table = null; |
159 | - if (count($students) > 0) { |
|
160 | - $students_table .= '<table class="data_table">'; |
|
161 | - $students_table .= '<tr> |
|
159 | + if (count($students) > 0) { |
|
160 | + $students_table .= '<table class="data_table">'; |
|
161 | + $students_table .= '<tr> |
|
162 | 162 | <th>'.get_lang('User').'</th> |
163 | 163 | <th>'.get_lang('AttendancesFaults').'</th> |
164 | 164 | <th>'.get_lang('Evaluations').'</th> |
165 | 165 | </tr>'; |
166 | - $i = 1; |
|
167 | - foreach ($students as $student) { |
|
168 | - |
|
169 | - $student_id = $student['user_id']; |
|
170 | - $firstname = $student['firstname']; |
|
171 | - $lastname = $student['lastname']; |
|
172 | - $username = $student['username']; |
|
173 | - |
|
174 | - |
|
175 | - // get average of faults in attendances by student |
|
176 | - $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id); |
|
177 | - if (!empty($results_faults_avg)) { |
|
178 | - $attendances_faults_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.$results_faults_avg['faults'].'/'.$results_faults_avg['total'].' ('.$results_faults_avg['porcent'].'%)</a>'; |
|
179 | - } else { |
|
180 | - $attendances_faults_avg = '0%'; |
|
181 | - } |
|
182 | - |
|
183 | - $courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true); |
|
184 | - $evaluations_avg = 0; |
|
185 | - $score = $weight = 0; |
|
186 | - foreach ($courses_by_user as $course) { |
|
187 | - $course_code = $course['code']; |
|
188 | - $cats = Category::load(null, null, $course_code, null, null, null, false); |
|
189 | - $scoretotal = array(); |
|
190 | - if (isset($cats) && isset($cats[0])) { |
|
191 | - $scoretotal= $cats[0]->calc_score($student_id, null, $course_code); |
|
192 | - } |
|
193 | - |
|
194 | - if (!empty($scoretotal)) { |
|
195 | - $score += $scoretotal[0]; |
|
196 | - $weight += $scoretotal[1]; |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - if (!empty($weight)) { |
|
201 | - $evaluations_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.round($score,2).'/'.round($weight,2).'('.round(($score / $weight) * 100,2) . ' %)</a>'; |
|
202 | - } |
|
203 | - |
|
204 | - if ($i%2 == 0) { |
|
166 | + $i = 1; |
|
167 | + foreach ($students as $student) { |
|
168 | + |
|
169 | + $student_id = $student['user_id']; |
|
170 | + $firstname = $student['firstname']; |
|
171 | + $lastname = $student['lastname']; |
|
172 | + $username = $student['username']; |
|
173 | + |
|
174 | + |
|
175 | + // get average of faults in attendances by student |
|
176 | + $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id); |
|
177 | + if (!empty($results_faults_avg)) { |
|
178 | + $attendances_faults_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.$results_faults_avg['faults'].'/'.$results_faults_avg['total'].' ('.$results_faults_avg['porcent'].'%)</a>'; |
|
179 | + } else { |
|
180 | + $attendances_faults_avg = '0%'; |
|
181 | + } |
|
182 | + |
|
183 | + $courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true); |
|
184 | + $evaluations_avg = 0; |
|
185 | + $score = $weight = 0; |
|
186 | + foreach ($courses_by_user as $course) { |
|
187 | + $course_code = $course['code']; |
|
188 | + $cats = Category::load(null, null, $course_code, null, null, null, false); |
|
189 | + $scoretotal = array(); |
|
190 | + if (isset($cats) && isset($cats[0])) { |
|
191 | + $scoretotal= $cats[0]->calc_score($student_id, null, $course_code); |
|
192 | + } |
|
193 | + |
|
194 | + if (!empty($scoretotal)) { |
|
195 | + $score += $scoretotal[0]; |
|
196 | + $weight += $scoretotal[1]; |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + if (!empty($weight)) { |
|
201 | + $evaluations_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.round($score,2).'/'.round($weight,2).'('.round(($score / $weight) * 100,2) . ' %)</a>'; |
|
202 | + } |
|
203 | + |
|
204 | + if ($i%2 == 0) { |
|
205 | 205 | $class_tr = 'row_odd'; |
206 | 206 | } else { |
207 | 207 | $class_tr = 'row_even'; |
208 | 208 | } |
209 | - $students_table .= '<tr class="'.$class_tr.'"> |
|
209 | + $students_table .= '<tr class="'.$class_tr.'"> |
|
210 | 210 | <td>'.api_get_person_name($firstname, $lastname).' ('.$username.')</td> |
211 | 211 | <td>'.$attendances_faults_avg.'</td> |
212 | 212 | <td>'.$evaluations_avg.'</td> |
213 | 213 | </tr>'; |
214 | 214 | |
215 | - $i++; |
|
216 | - } |
|
217 | - $students_table .= '</table>'; |
|
218 | - } else { |
|
219 | - $students_table .= get_lang('ThereIsNoInformationAboutYourStudents'); |
|
220 | - } |
|
215 | + $i++; |
|
216 | + } |
|
217 | + $students_table .= '</table>'; |
|
218 | + } else { |
|
219 | + $students_table .= get_lang('ThereIsNoInformationAboutYourStudents'); |
|
220 | + } |
|
221 | 221 | |
222 | - $content .= $students_table; |
|
222 | + $content .= $students_table; |
|
223 | 223 | |
224 | - if (count($students) > 0) { |
|
225 | - $content .= '<div style="text-align:right;margin-top:10px;"> |
|
224 | + if (count($students) > 0) { |
|
225 | + $content .= '<div style="text-align:right;margin-top:10px;"> |
|
226 | 226 | <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=yourstudents">'.get_lang('SeeMore').'</a> |
227 | 227 | </div>'; |
228 | - } |
|
229 | - //$content .= '</div>'; |
|
228 | + } |
|
229 | + //$content .= '</div>'; |
|
230 | 230 | |
231 | - return $content; |
|
232 | - } |
|
231 | + return $content; |
|
232 | + } |
|
233 | 233 | |
234 | 234 | /** |
235 | - * Get number of students |
|
236 | - * @return int |
|
237 | - */ |
|
238 | - function get_number_of_students() |
|
235 | + * Get number of students |
|
236 | + * @return int |
|
237 | + */ |
|
238 | + function get_number_of_students() |
|
239 | 239 | { |
240 | - return count($this->students); |
|
241 | - } |
|
240 | + return count($this->students); |
|
241 | + } |
|
242 | 242 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | $user_id=$userIdViewed; |
9 | 9 | if ($mainUserInfo['status']==1) |
10 | 10 | { |
11 | - $course_admin=1; |
|
11 | + $course_admin=1; |
|
12 | 12 | } |
13 | 13 | include_once('permissions_functions.inc.php'); |
14 | 14 | include_once('all_permissions.inc.php'); |
@@ -19,26 +19,26 @@ discard block |
||
19 | 19 | // --------------------------------------------------- |
20 | 20 | if ($_POST['StoreUserPermissions'] and $setting_visualisation=='checkbox') |
21 | 21 | { |
22 | - $result_message=store_permissions('user', $user_id); |
|
23 | - if ($result_message) |
|
24 | - { |
|
25 | - Display::display_normal_message($result_message); |
|
26 | - } |
|
22 | + $result_message=store_permissions('user', $user_id); |
|
23 | + if ($result_message) |
|
24 | + { |
|
25 | + Display::display_normal_message($result_message); |
|
26 | + } |
|
27 | 27 | } |
28 | 28 | if (isset($_GET['action'])) |
29 | 29 | { |
30 | - if ( isset($_GET['permission']) AND isset($_GET['tool']) AND ($_GET['action']=='grant' OR $_GET['action']=='revoke')) |
|
31 | - { |
|
32 | - $result_message=store_one_permission('user', $_GET['action'], $user_id, $_GET['tool'], $_GET['permission']); |
|
33 | - } |
|
34 | - if (isset($_GET['role']) AND ($_GET['action']=='grant' OR $_GET['action']=='revoke')) |
|
35 | - { |
|
36 | - $result_message=assign_role('user', $_GET['action'], $user_id, $_GET['role'], $_GET['scope']); |
|
37 | - } |
|
30 | + if ( isset($_GET['permission']) AND isset($_GET['tool']) AND ($_GET['action']=='grant' OR $_GET['action']=='revoke')) |
|
31 | + { |
|
32 | + $result_message=store_one_permission('user', $_GET['action'], $user_id, $_GET['tool'], $_GET['permission']); |
|
33 | + } |
|
34 | + if (isset($_GET['role']) AND ($_GET['action']=='grant' OR $_GET['action']=='revoke')) |
|
35 | + { |
|
36 | + $result_message=assign_role('user', $_GET['action'], $user_id, $_GET['role'], $_GET['scope']); |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | if (isset($result_message)) |
40 | 40 | { |
41 | - Display::display_normal_message($result_message); |
|
41 | + Display::display_normal_message($result_message); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | // --------------------------------------------------- |
@@ -55,43 +55,43 @@ discard block |
||
55 | 55 | $groups_of_user=GroupManager::get_group_ids($_course['real_id'],$user_id); |
56 | 56 | foreach ($groups_of_user as $group) |
57 | 57 | { |
58 | - $this_group_permissions=get_permissions('group',$group); |
|
59 | - foreach ($this_group_permissions as $tool=>$permissions) |
|
60 | - { |
|
61 | - foreach ($permissions as $permission) |
|
62 | - { |
|
63 | - $inherited_group_permissions[$tool][]=$permission; |
|
64 | - } |
|
65 | - } |
|
58 | + $this_group_permissions=get_permissions('group',$group); |
|
59 | + foreach ($this_group_permissions as $tool=>$permissions) |
|
60 | + { |
|
61 | + foreach ($permissions as $permission) |
|
62 | + { |
|
63 | + $inherited_group_permissions[$tool][]=$permission; |
|
64 | + } |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | $inherited_permissions=$inherited_group_permissions; |
68 | 68 | |
69 | 69 | // RETRIEVING THE PERMISSIONS OF THE ROLES OF THE USER |
70 | 70 | if (api_get_setting('user_roles')=='true') { |
71 | - // course roles that are assigned to the user |
|
72 | - $current_user_role_permissions_of_user=get_roles_permissions('user',$user_id); |
|
73 | - $inherited_permissions=permission_array_merge($inherited_permissions,$current_user_role_permissions_of_user); |
|
74 | - // NOTE: deze array moet nog gemerged worden met de $inherited_permissions array |
|
75 | - // (heet momenteel nog $current_group_permissions_of_user omdat voorlopig enkel de |
|
76 | - // groepsge�rfde permissions in beschouwing worden genomen |
|
77 | - // dit moet ook de rol permissies van rollen die toegekend worden aan een gebruiker |
|
78 | - // en de rol permissies van rollen die toegekend worden aan de groepen van een gebruiker |
|
79 | - // omvatten. |
|
80 | - // NOTE: checken als de rollen brol wel degelijk geactiveerd is voordat we dit allemaal |
|
81 | - // ophalen. |
|
82 | - // platform roles that are assigned to the user |
|
83 | - $current_user_role_permissions_of_user=get_roles_permissions('user',$user_id, 'platform'); |
|
84 | - $inherited_permissions=permission_array_merge($inherited_permissions,$current_user_role_permissions_of_user); |
|
71 | + // course roles that are assigned to the user |
|
72 | + $current_user_role_permissions_of_user=get_roles_permissions('user',$user_id); |
|
73 | + $inherited_permissions=permission_array_merge($inherited_permissions,$current_user_role_permissions_of_user); |
|
74 | + // NOTE: deze array moet nog gemerged worden met de $inherited_permissions array |
|
75 | + // (heet momenteel nog $current_group_permissions_of_user omdat voorlopig enkel de |
|
76 | + // groepsge�rfde permissions in beschouwing worden genomen |
|
77 | + // dit moet ook de rol permissies van rollen die toegekend worden aan een gebruiker |
|
78 | + // en de rol permissies van rollen die toegekend worden aan de groepen van een gebruiker |
|
79 | + // omvatten. |
|
80 | + // NOTE: checken als de rollen brol wel degelijk geactiveerd is voordat we dit allemaal |
|
81 | + // ophalen. |
|
82 | + // platform roles that are assigned to the user |
|
83 | + $current_user_role_permissions_of_user=get_roles_permissions('user',$user_id, 'platform'); |
|
84 | + $inherited_permissions=permission_array_merge($inherited_permissions,$current_user_role_permissions_of_user); |
|
85 | 85 | } |
86 | 86 | // RETRIEVING THE PERMISSIONS OF THE ROLES OF THE GROUPS OF THE USER |
87 | 87 | if (api_get_setting('group_roles')=='true') |
88 | 88 | { |
89 | - // NOTE: DIT MOET NOG VERDER UITGEWERKT WORDEN |
|
90 | - foreach ($groups_of_user as $group) |
|
91 | - { |
|
92 | - $this_current_group_role_permissions_of_user=get_roles_permissions('user',$user_id); |
|
93 | - //$inherited_permissions[$tool][]=$permission; |
|
94 | - } |
|
89 | + // NOTE: DIT MOET NOG VERDER UITGEWERKT WORDEN |
|
90 | + foreach ($groups_of_user as $group) |
|
91 | + { |
|
92 | + $this_current_group_role_permissions_of_user=get_roles_permissions('user',$user_id); |
|
93 | + //$inherited_permissions[$tool][]=$permission; |
|
94 | + } |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | // --------------------------------------------------- |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | $inherited_permissions=limited_or_full($inherited_permissions); |
102 | 102 | if (api_get_setting('permissions')=='limited') |
103 | 103 | { |
104 | - $header_array=$rights_limited; |
|
104 | + $header_array=$rights_limited; |
|
105 | 105 | } |
106 | 106 | if (api_get_setting('permissions')=='full') |
107 | 107 | { |
108 | - $header_array=$rights_full; |
|
108 | + $header_array=$rights_full; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | |
@@ -116,12 +116,12 @@ discard block |
||
116 | 116 | // --------------------------------------------------- |
117 | 117 | if (api_get_setting('user_roles')=='true') |
118 | 118 | { |
119 | - // the list of the roles for the user |
|
120 | - echo '<strong>'.get_lang('UserRoles').'</strong><br />'; |
|
121 | - $current_user_course_roles=get_roles('user',$user_id); |
|
122 | - $current_user_platform_roles=get_roles('user',$user_id, 'platform'); |
|
123 | - display_role_list($current_user_course_roles, $current_user_platform_roles); |
|
124 | - echo '<br />'; |
|
119 | + // the list of the roles for the user |
|
120 | + echo '<strong>'.get_lang('UserRoles').'</strong><br />'; |
|
121 | + $current_user_course_roles=get_roles('user',$user_id); |
|
122 | + $current_user_platform_roles=get_roles('user',$user_id, 'platform'); |
|
123 | + display_role_list($current_user_course_roles, $current_user_platform_roles); |
|
124 | + echo '<br />'; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | // --------------------------------------------------- |
@@ -135,59 +135,59 @@ discard block |
||
135 | 135 | echo "\t\t<th>".get_lang('Module')."</th>\n"; |
136 | 136 | foreach ($header_array as $header_key=>$header_value) |
137 | 137 | { |
138 | - echo "\t\t<th>".get_lang($header_value)."</th>\n"; |
|
138 | + echo "\t\t<th>".get_lang($header_value)."</th>\n"; |
|
139 | 139 | } |
140 | 140 | echo "\t</tr>\n"; |
141 | 141 | |
142 | 142 | // the main area with the checkboxes or images |
143 | 143 | foreach ($tool_rights as $tool=>$rights) // $tool_rights contains all the possible tools and their rights |
144 | 144 | { |
145 | - echo "\t<tr>\n"; |
|
146 | - echo "\t\t<td>\n"; |
|
147 | - if (strstr($tool,'BLOG')) |
|
148 | - { |
|
149 | - // Not dealing with a real tool here, get name of this blog |
|
150 | - // Strip blog id |
|
151 | - $tmp = strpos($tool,'_')+1; |
|
152 | - $blog_id = substr($tool,$tmp,strlen($tool)); |
|
153 | - // Get title |
|
154 | - echo get_lang('Blog').": ".Blog::get_blog_title($blog_id); |
|
155 | - } |
|
156 | - else |
|
157 | - { |
|
158 | - echo get_lang($tool); |
|
159 | - } |
|
160 | - |
|
161 | - echo "\t\t</td>\n"; |
|
162 | - |
|
163 | - foreach ($header_array as $key=>$value) |
|
164 | - { |
|
165 | - |
|
166 | - echo "\t\t<td align='center'>\n"; |
|
167 | - if (in_array($value,$rights)) |
|
168 | - { |
|
169 | - if ($setting_visualisation=='checkbox') |
|
170 | - { |
|
171 | - display_checkbox_matrix($current_user_permissions, $tool, $value, $inherited_permissions,$course_admin); |
|
172 | - } |
|
173 | - if ($setting_visualisation=='image') |
|
174 | - { |
|
175 | - display_image_matrix($current_user_permissions, $tool, $value,$inherited_permissions, $course_admin); |
|
176 | - } |
|
177 | - } |
|
178 | - // note: in a later stage this part will be replaced by a function |
|
179 | - // so that we can easily switch between a checkbox approach or an image approach |
|
180 | - // where every click is in fact a change of status. In the checkbox approach you first have to |
|
181 | - // do the changes and then store them by clicking the submit button. |
|
182 | - echo "\t\t</td>\n"; |
|
183 | - } |
|
184 | - echo "\t</tr>\n"; |
|
145 | + echo "\t<tr>\n"; |
|
146 | + echo "\t\t<td>\n"; |
|
147 | + if (strstr($tool,'BLOG')) |
|
148 | + { |
|
149 | + // Not dealing with a real tool here, get name of this blog |
|
150 | + // Strip blog id |
|
151 | + $tmp = strpos($tool,'_')+1; |
|
152 | + $blog_id = substr($tool,$tmp,strlen($tool)); |
|
153 | + // Get title |
|
154 | + echo get_lang('Blog').": ".Blog::get_blog_title($blog_id); |
|
155 | + } |
|
156 | + else |
|
157 | + { |
|
158 | + echo get_lang($tool); |
|
159 | + } |
|
160 | + |
|
161 | + echo "\t\t</td>\n"; |
|
162 | + |
|
163 | + foreach ($header_array as $key=>$value) |
|
164 | + { |
|
165 | + |
|
166 | + echo "\t\t<td align='center'>\n"; |
|
167 | + if (in_array($value,$rights)) |
|
168 | + { |
|
169 | + if ($setting_visualisation=='checkbox') |
|
170 | + { |
|
171 | + display_checkbox_matrix($current_user_permissions, $tool, $value, $inherited_permissions,$course_admin); |
|
172 | + } |
|
173 | + if ($setting_visualisation=='image') |
|
174 | + { |
|
175 | + display_image_matrix($current_user_permissions, $tool, $value,$inherited_permissions, $course_admin); |
|
176 | + } |
|
177 | + } |
|
178 | + // note: in a later stage this part will be replaced by a function |
|
179 | + // so that we can easily switch between a checkbox approach or an image approach |
|
180 | + // where every click is in fact a change of status. In the checkbox approach you first have to |
|
181 | + // do the changes and then store them by clicking the submit button. |
|
182 | + echo "\t\t</td>\n"; |
|
183 | + } |
|
184 | + echo "\t</tr>\n"; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | echo "</table>\n"; |
188 | 188 | if ($setting_visualisation=='checkbox') |
189 | 189 | { |
190 | - echo "<input type=\"Submit\" name=\"StoreUserPermissions\" value=\"".get_lang('StorePermissions')."\">"; |
|
190 | + echo "<input type=\"Submit\" name=\"StoreUserPermissions\" value=\"".get_lang('StorePermissions')."\">"; |
|
191 | 191 | } |
192 | 192 | echo "</form><br />"; |
193 | 193 |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | 'all', |
29 | 29 | '', |
30 | 30 | array( |
31 | - 'name'=>'code' , 'type'=>'xsd:string', |
|
32 | - 'name'=>'title' , 'type'=>'xsd:string', |
|
33 | - 'name'=>'url' , 'type'=>'xsd:string', |
|
34 | - 'name'=>'teacher', 'type'=>'xsd:string', |
|
35 | - 'name'=>'language','type'=>'xsd:string', |
|
31 | + 'name'=>'code' , 'type'=>'xsd:string', |
|
32 | + 'name'=>'title' , 'type'=>'xsd:string', |
|
33 | + 'name'=>'url' , 'type'=>'xsd:string', |
|
34 | + 'name'=>'teacher', 'type'=>'xsd:string', |
|
35 | + 'name'=>'language','type'=>'xsd:string', |
|
36 | 36 | ) |
37 | 37 | ); |
38 | 38 | |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | // Register the method to expose |
54 | 54 | $server->register('WSCourseList', // method name |
55 | 55 | array('username' => 'xsd:string', |
56 | - 'signature' => 'xsd:string', |
|
57 | - 'visibilities' => 'xsd:string'), // input parameters |
|
56 | + 'signature' => 'xsd:string', |
|
57 | + 'visibilities' => 'xsd:string'), // input parameters |
|
58 | 58 | array('return' => 'xsd:Array'), // output parameters |
59 | 59 | 'urn:WSCourseList', // namespace |
60 | 60 | 'urn:WSCourseList#WSCourseList', // soapaction |
@@ -97,19 +97,19 @@ discard block |
||
97 | 97 | |
98 | 98 | $courses_list = array(); |
99 | 99 | |
100 | - if (!is_array($visibilities)) { |
|
101 | - $visibilities = split(',', $visibilities); |
|
102 | - } |
|
103 | - foreach ($visibilities as $visibility) { |
|
104 | - if (!in_array($visibility, array_keys($vis))) { |
|
105 | - return array('error_msg' => 'Security check failed'); |
|
106 | - } |
|
107 | - $courses_list_tmp = CourseManager::get_courses_list(null, null, null, null, $vis[$visibility]); |
|
108 | - foreach ($courses_list_tmp as $index => $course) { |
|
109 | - $course_info = CourseManager::get_course_information($course['code']); |
|
110 | - $courses_list[] = array('code' => $course['code'], 'title' => api_utf8_encode($course_info['title']), 'url' => api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/', 'teacher' => api_utf8_encode($course_info['tutor_name']), 'language' => $course_info['course_language']); |
|
111 | - } |
|
112 | - } |
|
100 | + if (!is_array($visibilities)) { |
|
101 | + $visibilities = split(',', $visibilities); |
|
102 | + } |
|
103 | + foreach ($visibilities as $visibility) { |
|
104 | + if (!in_array($visibility, array_keys($vis))) { |
|
105 | + return array('error_msg' => 'Security check failed'); |
|
106 | + } |
|
107 | + $courses_list_tmp = CourseManager::get_courses_list(null, null, null, null, $vis[$visibility]); |
|
108 | + foreach ($courses_list_tmp as $index => $course) { |
|
109 | + $course_info = CourseManager::get_course_information($course['code']); |
|
110 | + $courses_list[] = array('code' => $course['code'], 'title' => api_utf8_encode($course_info['title']), 'url' => api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/', 'teacher' => api_utf8_encode($course_info['tutor_name']), 'language' => $course_info['course_language']); |
|
111 | + } |
|
112 | + } |
|
113 | 113 | return $courses_list; |
114 | 114 | } |
115 | 115 |
@@ -11,237 +11,237 @@ |
||
11 | 11 | */ |
12 | 12 | class WSError |
13 | 13 | { |
14 | - /** |
|
15 | - * Error handler. This needs to be a class that implements the interface WSErrorHandler |
|
16 | - * |
|
17 | - * @var WSErrorHandler |
|
18 | - */ |
|
19 | - protected static $_handler; |
|
20 | - |
|
21 | - /** |
|
22 | - * Error code |
|
23 | - * |
|
24 | - * @var int |
|
25 | - */ |
|
26 | - public $code; |
|
27 | - |
|
28 | - /** |
|
29 | - * Error message |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - public $message; |
|
34 | - |
|
35 | - /** |
|
36 | - * Constructor |
|
37 | - * |
|
38 | - * @param int Error code |
|
39 | - * @param string Error message |
|
40 | - */ |
|
41 | - public function __construct($code, $message) { |
|
42 | - $this->code = $code; |
|
43 | - $this->message = $message; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Sets the error handler |
|
48 | - * |
|
49 | - * @param WSErrorHandler Error handler |
|
50 | - */ |
|
51 | - public static function setErrorHandler($handler) { |
|
52 | - if($handler instanceof WSErrorHandler) { |
|
53 | - self::$_handler = $handler; |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Returns the error handler |
|
59 | - * |
|
60 | - * @return WSErrorHandler Error handler |
|
61 | - */ |
|
62 | - public static function getErrorHandler() { |
|
63 | - return self::$_handler; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Transforms the error into an array |
|
68 | - * |
|
69 | - * @return array Associative array with code and message |
|
70 | - */ |
|
71 | - public function toArray() { |
|
72 | - return array('code' => $this->code, 'message' => $this->message); |
|
73 | - } |
|
14 | + /** |
|
15 | + * Error handler. This needs to be a class that implements the interface WSErrorHandler |
|
16 | + * |
|
17 | + * @var WSErrorHandler |
|
18 | + */ |
|
19 | + protected static $_handler; |
|
20 | + |
|
21 | + /** |
|
22 | + * Error code |
|
23 | + * |
|
24 | + * @var int |
|
25 | + */ |
|
26 | + public $code; |
|
27 | + |
|
28 | + /** |
|
29 | + * Error message |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + public $message; |
|
34 | + |
|
35 | + /** |
|
36 | + * Constructor |
|
37 | + * |
|
38 | + * @param int Error code |
|
39 | + * @param string Error message |
|
40 | + */ |
|
41 | + public function __construct($code, $message) { |
|
42 | + $this->code = $code; |
|
43 | + $this->message = $message; |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Sets the error handler |
|
48 | + * |
|
49 | + * @param WSErrorHandler Error handler |
|
50 | + */ |
|
51 | + public static function setErrorHandler($handler) { |
|
52 | + if($handler instanceof WSErrorHandler) { |
|
53 | + self::$_handler = $handler; |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Returns the error handler |
|
59 | + * |
|
60 | + * @return WSErrorHandler Error handler |
|
61 | + */ |
|
62 | + public static function getErrorHandler() { |
|
63 | + return self::$_handler; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Transforms the error into an array |
|
68 | + * |
|
69 | + * @return array Associative array with code and message |
|
70 | + */ |
|
71 | + public function toArray() { |
|
72 | + return array('code' => $this->code, 'message' => $this->message); |
|
73 | + } |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | 77 | * Interface that must be implemented by any error handler |
78 | 78 | */ |
79 | 79 | interface WSErrorHandler { |
80 | - /** |
|
81 | - * Handle method |
|
82 | - * |
|
83 | - * @param WSError Error |
|
84 | - */ |
|
85 | - public function handle($error); |
|
80 | + /** |
|
81 | + * Handle method |
|
82 | + * |
|
83 | + * @param WSError Error |
|
84 | + */ |
|
85 | + public function handle($error); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | 89 | * Main class of the webservice. Webservice classes extend this class |
90 | 90 | */ |
91 | 91 | class WS { |
92 | - /** |
|
93 | - * Chamilo configuration |
|
94 | - * |
|
95 | - * @var array |
|
96 | - */ |
|
97 | - protected $_configuration; |
|
98 | - |
|
99 | - /** |
|
100 | - * Constructor |
|
101 | - */ |
|
102 | - public function __construct() { |
|
103 | - $this->_configuration = $GLOBALS['_configuration']; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Verifies the API key |
|
108 | - * |
|
109 | - * @param string Secret key |
|
110 | - * @return mixed WSError in case of failure, null in case of success |
|
111 | - */ |
|
112 | - protected function verifyKey($secret_key) { |
|
113 | - $ip = trim($_SERVER['REMOTE_ADDR']); |
|
114 | - // if we are behind a reverse proxy, assume it will send the |
|
115 | - // HTTP_X_FORWARDED_FOR header and use this IP instead |
|
116 | - if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
117 | - list($ip1,$ip2) = preg_split('/,/',$_SERVER['HTTP_X_FORWARDED_FOR']); |
|
118 | - $ip = trim($ip1); |
|
119 | - } |
|
120 | - $security_key = $ip.$this->_configuration['security_key']; |
|
121 | - |
|
122 | - if(!api_is_valid_secret_key($secret_key, $security_key)) { |
|
123 | - return new WSError(1, "API key is invalid"); |
|
124 | - } else { |
|
125 | - return null; |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Gets the real user id based on the user id field name and value. |
|
131 | - * Note that if the user id field name is "chamilo_user_id", it will use the user id |
|
132 | - * in the system database |
|
133 | - * |
|
134 | - * @param string User id field name |
|
135 | - * @param string User id value |
|
136 | - * @return mixed System user id if the user was found, WSError otherwise |
|
137 | - */ |
|
138 | - protected function getUserId($user_id_field_name, $user_id_value) { |
|
139 | - if($user_id_field_name == "chamilo_user_id") { |
|
140 | - if(UserManager::is_user_id_valid(intval($user_id_value))) { |
|
141 | - return intval($user_id_value); |
|
142 | - } else { |
|
143 | - return new WSError(100, "User not found"); |
|
144 | - } |
|
145 | - } else { |
|
146 | - $user_id = UserManager::get_user_id_from_original_id($user_id_value, $user_id_field_name); |
|
147 | - if($user_id == 0) { |
|
148 | - return new WSError(100, "User not found"); |
|
149 | - } else { |
|
150 | - return $user_id; |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Gets the real course id based on the course id field name and value. |
|
157 | - * Note that if the course id field name is "chamilo_course_id", it will use the course id |
|
158 | - * in the system database |
|
159 | - * |
|
160 | - * @param string Course id field name |
|
161 | - * @param string Course id value |
|
162 | - * @return mixed System course id if the course was found, WSError otherwise |
|
163 | - */ |
|
164 | - protected function getCourseId($course_id_field_name, $course_id_value) |
|
165 | - { |
|
166 | - if ($course_id_field_name == "chamilo_course_id") { |
|
167 | - if (CourseManager::get_course_code_from_course_id( |
|
168 | - intval($course_id_value) |
|
169 | - ) != null |
|
170 | - ) { |
|
171 | - return intval($course_id_value); |
|
172 | - } else { |
|
173 | - return new WSError(200, "Course not found"); |
|
174 | - } |
|
175 | - } else { |
|
176 | - $courseId = CourseManager::get_course_code_from_original_id( |
|
177 | - $course_id_value, |
|
178 | - $course_id_field_name |
|
179 | - ); |
|
180 | - if (!empty($courseId)) { |
|
181 | - return $courseId; |
|
182 | - } else { |
|
183 | - return new WSError(200, "Course not found"); |
|
184 | - } |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Gets the real session id based on the session id field name and value. |
|
190 | - * Note that if the session id field name is "chamilo_session_id", it will use the session id |
|
191 | - * in the system database |
|
192 | - * |
|
193 | - * @param string Session id field name |
|
194 | - * @param string Session id value |
|
195 | - * @return mixed System session id if the session was found, WSError otherwise |
|
196 | - */ |
|
197 | - protected function getSessionId($session_id_field_name, $session_id_value) |
|
198 | - { |
|
199 | - if ($session_id_field_name == "chamilo_session_id") { |
|
200 | - $session = SessionManager::fetch((int)$session_id_value); |
|
201 | - if (!empty($session)) { |
|
202 | - return intval($session_id_value); |
|
203 | - } else { |
|
204 | - return new WSError(300, "Session not found"); |
|
205 | - } |
|
206 | - } else { |
|
207 | - $session_id = SessionManager::getSessionIdFromOriginalId( |
|
208 | - $session_id_value, |
|
209 | - $session_id_field_name |
|
210 | - ); |
|
211 | - if ($session_id == 0) { |
|
212 | - return new WSError(300, "Session not found"); |
|
213 | - } else { |
|
214 | - return $session_id; |
|
215 | - } |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Handles an error by calling the WSError error handler |
|
221 | - * |
|
222 | - * @param WSError Error |
|
223 | - */ |
|
224 | - protected function handleError($error) { |
|
225 | - $handler = WSError::getErrorHandler(); |
|
226 | - $handler->handle($error); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Gets a successful result |
|
231 | - * |
|
232 | - * @return array Array with a code of 0 and a message 'Operation was successful' |
|
233 | - */ |
|
234 | - protected function getSuccessfulResult() { |
|
235 | - return array('code' => 0, 'message' => 'Operation was successful'); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Test function. Returns the string success |
|
240 | - * |
|
241 | - * @return string Success |
|
242 | - */ |
|
243 | - public function test() { |
|
244 | - return "success"; |
|
245 | - } |
|
92 | + /** |
|
93 | + * Chamilo configuration |
|
94 | + * |
|
95 | + * @var array |
|
96 | + */ |
|
97 | + protected $_configuration; |
|
98 | + |
|
99 | + /** |
|
100 | + * Constructor |
|
101 | + */ |
|
102 | + public function __construct() { |
|
103 | + $this->_configuration = $GLOBALS['_configuration']; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Verifies the API key |
|
108 | + * |
|
109 | + * @param string Secret key |
|
110 | + * @return mixed WSError in case of failure, null in case of success |
|
111 | + */ |
|
112 | + protected function verifyKey($secret_key) { |
|
113 | + $ip = trim($_SERVER['REMOTE_ADDR']); |
|
114 | + // if we are behind a reverse proxy, assume it will send the |
|
115 | + // HTTP_X_FORWARDED_FOR header and use this IP instead |
|
116 | + if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
117 | + list($ip1,$ip2) = preg_split('/,/',$_SERVER['HTTP_X_FORWARDED_FOR']); |
|
118 | + $ip = trim($ip1); |
|
119 | + } |
|
120 | + $security_key = $ip.$this->_configuration['security_key']; |
|
121 | + |
|
122 | + if(!api_is_valid_secret_key($secret_key, $security_key)) { |
|
123 | + return new WSError(1, "API key is invalid"); |
|
124 | + } else { |
|
125 | + return null; |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Gets the real user id based on the user id field name and value. |
|
131 | + * Note that if the user id field name is "chamilo_user_id", it will use the user id |
|
132 | + * in the system database |
|
133 | + * |
|
134 | + * @param string User id field name |
|
135 | + * @param string User id value |
|
136 | + * @return mixed System user id if the user was found, WSError otherwise |
|
137 | + */ |
|
138 | + protected function getUserId($user_id_field_name, $user_id_value) { |
|
139 | + if($user_id_field_name == "chamilo_user_id") { |
|
140 | + if(UserManager::is_user_id_valid(intval($user_id_value))) { |
|
141 | + return intval($user_id_value); |
|
142 | + } else { |
|
143 | + return new WSError(100, "User not found"); |
|
144 | + } |
|
145 | + } else { |
|
146 | + $user_id = UserManager::get_user_id_from_original_id($user_id_value, $user_id_field_name); |
|
147 | + if($user_id == 0) { |
|
148 | + return new WSError(100, "User not found"); |
|
149 | + } else { |
|
150 | + return $user_id; |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Gets the real course id based on the course id field name and value. |
|
157 | + * Note that if the course id field name is "chamilo_course_id", it will use the course id |
|
158 | + * in the system database |
|
159 | + * |
|
160 | + * @param string Course id field name |
|
161 | + * @param string Course id value |
|
162 | + * @return mixed System course id if the course was found, WSError otherwise |
|
163 | + */ |
|
164 | + protected function getCourseId($course_id_field_name, $course_id_value) |
|
165 | + { |
|
166 | + if ($course_id_field_name == "chamilo_course_id") { |
|
167 | + if (CourseManager::get_course_code_from_course_id( |
|
168 | + intval($course_id_value) |
|
169 | + ) != null |
|
170 | + ) { |
|
171 | + return intval($course_id_value); |
|
172 | + } else { |
|
173 | + return new WSError(200, "Course not found"); |
|
174 | + } |
|
175 | + } else { |
|
176 | + $courseId = CourseManager::get_course_code_from_original_id( |
|
177 | + $course_id_value, |
|
178 | + $course_id_field_name |
|
179 | + ); |
|
180 | + if (!empty($courseId)) { |
|
181 | + return $courseId; |
|
182 | + } else { |
|
183 | + return new WSError(200, "Course not found"); |
|
184 | + } |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Gets the real session id based on the session id field name and value. |
|
190 | + * Note that if the session id field name is "chamilo_session_id", it will use the session id |
|
191 | + * in the system database |
|
192 | + * |
|
193 | + * @param string Session id field name |
|
194 | + * @param string Session id value |
|
195 | + * @return mixed System session id if the session was found, WSError otherwise |
|
196 | + */ |
|
197 | + protected function getSessionId($session_id_field_name, $session_id_value) |
|
198 | + { |
|
199 | + if ($session_id_field_name == "chamilo_session_id") { |
|
200 | + $session = SessionManager::fetch((int)$session_id_value); |
|
201 | + if (!empty($session)) { |
|
202 | + return intval($session_id_value); |
|
203 | + } else { |
|
204 | + return new WSError(300, "Session not found"); |
|
205 | + } |
|
206 | + } else { |
|
207 | + $session_id = SessionManager::getSessionIdFromOriginalId( |
|
208 | + $session_id_value, |
|
209 | + $session_id_field_name |
|
210 | + ); |
|
211 | + if ($session_id == 0) { |
|
212 | + return new WSError(300, "Session not found"); |
|
213 | + } else { |
|
214 | + return $session_id; |
|
215 | + } |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Handles an error by calling the WSError error handler |
|
221 | + * |
|
222 | + * @param WSError Error |
|
223 | + */ |
|
224 | + protected function handleError($error) { |
|
225 | + $handler = WSError::getErrorHandler(); |
|
226 | + $handler->handle($error); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Gets a successful result |
|
231 | + * |
|
232 | + * @return array Array with a code of 0 and a message 'Operation was successful' |
|
233 | + */ |
|
234 | + protected function getSuccessfulResult() { |
|
235 | + return array('code' => 0, 'message' => 'Operation was successful'); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Test function. Returns the string success |
|
240 | + * |
|
241 | + * @return string Success |
|
242 | + */ |
|
243 | + public function test() { |
|
244 | + return "success"; |
|
245 | + } |
|
246 | 246 | } |
247 | 247 |
@@ -22,32 +22,32 @@ discard block |
||
22 | 22 | */ |
23 | 23 | function courses_list($security_key, $visibilities = 'public') { |
24 | 24 | |
25 | - global $_configuration; |
|
25 | + global $_configuration; |
|
26 | 26 | |
27 | - // Check if this script is launch by server and if security key is ok. |
|
28 | - if ($security_key != $_configuration['security_key']) { |
|
29 | - return array('error_msg' => 'Security check failed'); |
|
30 | - } |
|
27 | + // Check if this script is launch by server and if security key is ok. |
|
28 | + if ($security_key != $_configuration['security_key']) { |
|
29 | + return array('error_msg' => 'Security check failed'); |
|
30 | + } |
|
31 | 31 | |
32 | - $vis = array('public' => '3', 'public-registered' => '2', 'private' => '1', 'closed' => '0'); |
|
32 | + $vis = array('public' => '3', 'public-registered' => '2', 'private' => '1', 'closed' => '0'); |
|
33 | 33 | |
34 | - $courses_list = array(); |
|
34 | + $courses_list = array(); |
|
35 | 35 | |
36 | - if (!is_array($visibilities)) { |
|
37 | - $tmp = $visibilities; |
|
38 | - $visibilities = array($tmp); |
|
39 | - } |
|
40 | - foreach ($visibilities as $visibility) { |
|
41 | - if (!in_array($visibility, array_keys($vis))) { |
|
42 | - return array('error_msg' => 'Security check failed'); |
|
43 | - } |
|
44 | - $courses_list_tmp = CourseManager::get_courses_list(null, null, null, null, $vis[$visibility]); |
|
45 | - foreach ($courses_list_tmp as $index => $course) { |
|
46 | - $course_info = CourseManager::get_course_information($course['code']); |
|
47 | - $courses_list[$course['code']] = array('title' => api_utf8_encode($course_info['title']), 'url' => api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/', 'teacher' => api_utf8_encode($course_info['tutor_name']), 'language' => $course_info['course_language']); |
|
48 | - } |
|
49 | - } |
|
50 | - return $courses_list; |
|
36 | + if (!is_array($visibilities)) { |
|
37 | + $tmp = $visibilities; |
|
38 | + $visibilities = array($tmp); |
|
39 | + } |
|
40 | + foreach ($visibilities as $visibility) { |
|
41 | + if (!in_array($visibility, array_keys($vis))) { |
|
42 | + return array('error_msg' => 'Security check failed'); |
|
43 | + } |
|
44 | + $courses_list_tmp = CourseManager::get_courses_list(null, null, null, null, $vis[$visibility]); |
|
45 | + foreach ($courses_list_tmp as $index => $course) { |
|
46 | + $course_info = CourseManager::get_course_information($course['code']); |
|
47 | + $courses_list[$course['code']] = array('title' => api_utf8_encode($course_info['title']), 'url' => api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/', 'teacher' => api_utf8_encode($course_info['tutor_name']), 'language' => $course_info['course_language']); |
|
48 | + } |
|
49 | + } |
|
50 | + return $courses_list; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | header('Content-Type: text/xml; charset=utf-8'); |
@@ -55,17 +55,17 @@ discard block |
||
55 | 55 | echo '<courseslist>'; |
56 | 56 | |
57 | 57 | if (empty($_POST['security-key']) || empty($_POST['visibility'])) { |
58 | - echo '<errormsg>Invalid parameters, this script expects a security-key and a visibility parameters</errormsg>'; |
|
58 | + echo '<errormsg>Invalid parameters, this script expects a security-key and a visibility parameters</errormsg>'; |
|
59 | 59 | } else { |
60 | - $courses_list = courses_list($_POST['security-key'], $_POST['visibility']); |
|
61 | - foreach ($courses_list as $code => $cd) { |
|
62 | - echo '<course>'; |
|
63 | - echo '<code>' , $code , '</code>'; |
|
64 | - echo '<title>' , $cd['title'] , '</title>'; |
|
65 | - echo '<url>' , $cd['url'] , '</url>'; |
|
66 | - echo '<teacher>' , $cd['teacher'] , '</teacher>'; |
|
67 | - echo '<language>' , $cd['language'] , '</language>'; |
|
68 | - echo '</course>'; |
|
69 | - } |
|
60 | + $courses_list = courses_list($_POST['security-key'], $_POST['visibility']); |
|
61 | + foreach ($courses_list as $code => $cd) { |
|
62 | + echo '<course>'; |
|
63 | + echo '<code>' , $code , '</code>'; |
|
64 | + echo '<title>' , $cd['title'] , '</title>'; |
|
65 | + echo '<url>' , $cd['url'] , '</url>'; |
|
66 | + echo '<teacher>' , $cd['teacher'] , '</teacher>'; |
|
67 | + echo '<language>' , $cd['language'] , '</language>'; |
|
68 | + echo '</course>'; |
|
69 | + } |
|
70 | 70 | } |
71 | 71 | echo '</courseslist>'; |