ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilRegistrationGUI.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24include_once('Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
25
35abstract class ilRegistrationGUI
36{
37 protected $privacy = null;
38
39 protected $container = null;
40 protected $ref_id;
41 protected $obj_id;
42
46 protected $participants;
47 protected $waiting_list = null;
48 protected $form;
49
50 protected $registration_possible = true;
51 protected $join_error = '';
52
53
54 protected $tpl;
55 protected $lng;
56 protected $ctrl;
57
65 public function __construct($a_container)
66 {
67 global $lng,$ilCtrl,$tpl;
68
69 $this->lng = $lng;
70 $this->lng->loadLanguageModule('crs');
71 $this->lng->loadLanguageModule('grp');
72 $this->lng->loadLanguageModule('ps');
73 $this->lng->loadLanguageModule('membership');
74
75 $this->ctrl = $ilCtrl;
76 $this->tpl = $tpl;
77
78 $this->container = $a_container;
79 $this->ref_id = $this->container->getRefId();
80 $this->obj_id = ilObject::_lookupObjId($this->ref_id);
81 $this->type = ilObject::_lookupType($this->obj_id);
82
83 // Init participants
84 $this->initParticipants();
85
86 // Init waiting list
87 $this->initWaitingList();
88
89 $this->privacy = ilPrivacySettings::_getInstance();
90 }
91
96 public function getContainer()
97 {
98 return $this->container;
99 }
100
105 public function getRefId()
106 {
107 return $this->ref_id;
108 }
109
116 protected function isRegistrationPossible()
117 {
118 return (bool) $this->registration_possible;
119 }
120
128 protected function enableRegistration($a_status)
129 {
130 $this->registration_possible = $a_status;
131 }
132
133
140 abstract protected function initParticipants();
141
149 abstract protected function initWaitingList();
150
157 abstract protected function isWaitingListActive();
158
164 protected function getWaitingList()
165 {
166 return $this->waiting_list;
167 }
168
169 protected function leaveWaitingList()
170 {
171 global $ilUser,$tree,$ilCtrl;
172
173 $this->getWaitingList()->removeFromList($ilUser->getId());
174 $parent = $tree->getParentId($this->container->getRefId());
175
177 $this->lng->txt($this->container->getType() . '_removed_from_waiting_list'),
178 $this->container->getTitle()
179 );
181
182 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $parent);
183 $ilCtrl->redirectByClass("ilrepositorygui", "");
184 }
185
192 abstract protected function getFormTitle();
193
200 abstract protected function fillInformations();
201
207 abstract protected function fillRegistrationPeriod();
208
216 abstract protected function fillMaxMembers();
217
218
225 abstract protected function fillRegistrationType();
226
233 protected function fillMembershipLimitation()
234 {
235 global $ilAccess, $ilCtrl;
236
237 include_once('Modules/Course/classes/class.ilObjCourseGrouping.php');
238 if (!$items = ilObjCourseGrouping::_getGroupingItems($this->container)) {
239 return true;
240 }
241
242 $mem = new ilCustomInputGUI($this->lng->txt('groupings'));
243
244 $tpl = new ilTemplate('tpl.membership_limitation_form.html', true, true, 'Services/Membership');
245 $tpl->setVariable('LIMIT_INTRO', $this->lng->txt($this->type . '_grp_info_reg'));
246
247 foreach ($items as $ref_id) {
251
252 if ($ilAccess->checkAccess('visible', '', $ref_id, $type)) {
253 include_once('./Services/Link/classes/class.ilLink.php');
254 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $ref_id);
255 $tpl->setVariable(
256 'LINK_ITEM',
257 $ilCtrl->getLinkTargetByClass("ilrepositorygui", "")
258 );
259 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
260 $tpl->setVariable('ITEM_LINKED_TITLE', $title);
261 } else {
262 $tpl->setVariable('ITEM_TITLE');
263 }
264 $tpl->setCurrentBlock('items');
265 $tpl->setVariable('TYPE_ICON', ilObject::_getIcon($obj_id, 'tiny', $type));
266 $tpl->setVariable('ALT_ICON', $this->lng->txt('obj_' . $type));
267 $tpl->parseCurrentBlock();
268 }
269
270 $mem->setHtml($tpl->get());
271
272
274 $mem->setAlert($this->container->getMessage());
275 $this->enableRegistration(false);
276 }
277 $this->form->addItem($mem);
278 }
279
286 protected function fillAgreement()
287 {
288 global $ilUser;
289
290 if (!$this->isRegistrationPossible()) {
291 return true;
292 }
293
294 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
295 if (!$this->privacy->confirmationRequired($this->type) and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId())) {
296 return true;
297 }
298
299 $this->lng->loadLanguageModule('ps');
300
301 include_once('Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php');
302 $fields_info = ilExportFieldsInfo::_getInstanceByType(ilObject::_lookupType($this->container->getId()));
303
304 if (!count($fields_info->getExportableFields())) {
305 return true;
306 }
307
309 $section->setTitle($this->lng->txt($this->type . '_usr_agreement'));
310 $this->form->addItem($section);
311
312 include_once './Services/Membership/classes/class.ilMemberAgreementGUI.php';
313 ilMemberAgreementGUI::addExportFieldInfo($this->form, $this->obj_id, $this->type);
314
315
316 ilMemberAgreementGUI::addCustomFields($this->form, $this->obj_id, $this->type);
317
318 // Checkbox agreement
319 if ($this->privacy->confirmationRequired($this->type)) {
320 ilMemberAgreementGUI::addAgreement($this->form, $this->obj_id, $this->type);
321 }
322 return true;
323 }
324
330 protected function showCustomFields()
331 {
332 global $ilUser;
333
334 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
335 include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
336
337 if (!count($cdf_fields = ilCourseDefinedFieldDefinition::_getFields($this->container->getId()))) {
338 return true;
339 }
340
341 $cdf = new ilNonEditableValueGUI($this->lng->txt('ps_crs_user_fields'));
342 $cdf->setValue($this->lng->txt($this->type . '_ps_cdf_info'));
343 $cdf->setRequired(true);
344
345 foreach ($cdf_fields as $field_obj) {
346 $course_user_data = new ilCourseUserData($ilUser->getId(), $field_obj->getId());
347
348 switch ($field_obj->getType()) {
350 $select = new ilSelectInputGUI($field_obj->getName(), 'cdf[' . $field_obj->getId() . ']');
351 $select->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
352 $select->setOptions($field_obj->prepareSelectBox());
353 if ($field_obj->isRequired()) {
354 $select->setRequired(true);
355 }
356
357 $cdf->addSubItem($select);
358
359
360 break;
361
362 case IL_CDF_TYPE_TEXT:
363 $text = new ilTextInputGUI($field_obj->getName(), 'cdf[' . $field_obj->getId() . ']');
364 $text->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
365 $text->setSize(32);
366 $text->setMaxLength(255);
367 if ($field_obj->isRequired()) {
368 $text->setRequired(true);
369 }
370 $cdf->addSubItem($text);
371 break;
372 }
373 }
374 $this->form->addItem($cdf);
375 return true;
376 }
377
384 protected function validateAgreement()
385 {
386 global $ilUser;
387
388 if ($_POST['agreement']) {
389 return true;
390 }
391 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
392 if (!$this->privacy->confirmationRequired($this->type)) {
393 return true;
394 }
395 return false;
396 }
397
404 protected function validateCustomFields()
405 {
406 global $ilUser;
407
408
409 $required_fullfilled = true;
410 foreach (ilCourseDefinedFieldDefinition::_getFields($this->container->getId()) as $field_obj) {
411 switch ($field_obj->getType()) {
413
414 // Split value id from post
415 list($field_id, $option_id) = explode('_', $_POST['cdf_' . $field_obj->getId()]);
416
417 #$GLOBALS['ilLog']->write(__METHOD__.': '.print_r($field_id,TRUE).' '.print_r($option_id,TRUE).' '.print_r($_POST,TRUE));
418
419 $open_answer_indexes = (array) $field_obj->getValueOptions();
420 if (in_array($option_id, $open_answer_indexes)) {
421 $value = $_POST['cdf_oa_' . $field_obj->getId() . '_' . $option_id];
422 } else {
423 $value = $field_obj->getValueById($option_id);
424 }
425 break;
426
427 case IL_CDF_TYPE_TEXT:
428 $value = $_POST['cdf_' . $field_obj->getId()];
429 break;
430 }
431
432 $GLOBALS['ilLog']->write(__METHOD__ . ': new value ' . $value);
433
434
435 $course_user_data = new ilCourseUserData($ilUser->getId(), $field_obj->getId());
436 $course_user_data->setValue($value);
437 $course_user_data->update();
438
439 // #14220
440 if ($field_obj->isRequired() and $value == "") {
441 $required_fullfilled = false;
442 }
443 }
444
445 return $required_fullfilled;
446 }
447
454 protected function setAccepted($a_status)
455 {
456 global $ilUser;
457
458 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
459 if (!$this->privacy->confirmationRequired($this->type) and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId())) {
460 return true;
461 }
462
463 include_once('Services/Membership/classes/class.ilMemberAgreement.php');
464 $this->agreement = new ilMemberAgreement($ilUser->getId(), $this->container->getId());
465 $this->agreement->setAccepted($a_status);
466 $this->agreement->setAcceptanceTime(time());
467 $this->agreement->save();
468 }
469
475 public function cancel()
476 {
477 global $tree, $ilCtrl;
478
479 $ilCtrl->setParameterByClass(
480 "ilrepositorygui",
481 "ref_id",
482 $tree->getParentId($this->container->getRefId())
483 );
484 $ilCtrl->redirectByClass("ilrepositorygui", "");
485 }
486
494 public function show(ilPropertyFormGUI $form = null)
495 {
496 if (!$form instanceof ilPropertyFormGUI) {
497 $this->initForm();
498 }
499
500 if ($_SESSION["pending_goto"]) {
501 ilUtil::sendInfo($this->lng->txt("reg_goto_parent_membership_info"));
502 }
503
504 $this->tpl->setContent($this->form->getHTML());
505 }
506
514 public function join()
515 {
516 $form = $this->initForm();
517
518 if (!$form->checkInput() || !$this->validate()) {
519 $form->setValuesByPost();
520 if ($this->join_error) {
521 ilUtil::sendFailure($this->join_error);
522 } else {
523 ilUtil::sendFailure($this->lng->txt('err_check_input'));
524 }
525 $this->show($form);
526 return false;
527 }
528
529 $this->add();
530 }
531
532
539 protected function validate()
540 {
541 return true;
542 }
543
550 protected function initForm()
551 {
552 global $ilUser;
553
554 if (is_object($this->form)) {
555 return true;
556 }
557
558 include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
559 $this->form = new ilPropertyFormGUI();
560 $this->form->setFormAction($this->ctrl->getFormAction($this, 'join'));
561 $this->form->setTitle($this->getFormTitle());
562
563 $this->fillInformations();
565 if ($this->isRegistrationPossible()) {
566 $this->fillRegistrationPeriod();
567 }
568 if ($this->isRegistrationPossible() || $this->participants->isSubscriber($ilUser->getId())) {
569 $this->fillRegistrationType();
570 }
571 if ($this->isRegistrationPossible()) {
572 $this->fillMaxMembers();
573 }
574 if ($this->isRegistrationPossible()) {
575 $this->fillAgreement();
576 }
577 $this->addCommandButtons();
578 return $this->form;
579 }
580
585 protected function addCommandButtons()
586 {
587 global $ilUser;
588
589 if ($this->isRegistrationPossible() and $this->isWaitingListActive() and !$this->getWaitingList()->isOnList($ilUser->getId())) {
590 $this->form->addCommandButton('join', $this->lng->txt('mem_add_to_wl'));
591 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
592 } elseif ($this->isRegistrationPossible() and !$this->getWaitingList()->isOnList($ilUser->getId())) {
593 $this->form->addCommandButton('join', $this->lng->txt('join'));
594 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
595 }
596 if ($this->getWaitingList()->isOnList($ilUser->getId())) {
598 sprintf(
599 $this->lng->txt($this->container->getType() . '_cancel_waiting_list'),
600 $this->container->getTitle()
601 )
602 );
603 $this->form->addCommandButton('leaveWaitingList', $this->lng->txt('leave_waiting_list'));
604 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
605 }
606 }
607
612 protected function updateSubscriptionRequest()
613 {
614 global $ilUser, $tree, $ilCtrl;
615
616 $this->participants->updateSubject($ilUser->getId(), ilUtil::stripSlashes($_POST['subject']));
617 ilUtil::sendSuccess($this->lng->txt('sub_request_saved'), true);
618 $ilCtrl->setParameterByClass(
619 "ilrepositorygui",
620 "ref_id",
621 $tree->getParentId($this->container->getRefId())
622 );
623 $ilCtrl->redirectByClass("ilrepositorygui", "");
624 }
625
626 protected function cancelSubscriptionRequest()
627 {
628 global $ilUser, $tree, $ilCtrl;
629
630 $this->participants->deleteSubscriber($ilUser->getId());
631 ilUtil::sendSuccess($this->lng->txt('sub_request_deleted'), true);
632
633 $ilCtrl->setParameterByClass(
634 "ilrepositorygui",
635 "ref_id",
636 $tree->getParentId($this->container->getRefId())
637 );
638 $ilCtrl->redirectByClass("ilrepositorygui", "");
639 }
640}
sprintf('%.4f', $callTime)
$section
Definition: Utf8Test.php:83
add()
Definition: add.php:2
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
static _getFields($a_container_id, $a_sort=IL_CDF_SORT_NAME)
Get all fields of a container.
static _hasFields($a_container_id)
Check if there are any define fields.
This class represents a custom property in a property form.
static _getInstanceByType($a_type)
Get Singleton Instance.
This class represents a section header in a property form.
static addExportFieldInfo($form, $a_obj_id, $a_type)
Add export field info to form @global type $lng.
static addCustomFields($form, $a_obj_id, $a_type, $a_mode='user')
Add custom course fields.
static addAgreement($form, $a_obj_id, $a_type)
Add agreement to form.
This class represents a non editable value in a property form.
static _checkGroupingDependencies(&$container_obj, $a_user_id=null)
static _getGroupingItems($container_obj)
Get courses/groups that are assigned to the same membership limitation.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getInstance()
Get instance of ilPrivacySettings.
This class represents a property form user interface.
Base class for Course and Group registration.
showCustomFields()
Show course defined fields.
fillRegistrationType()
show informations about registration procedure
getContainer()
Parent object.
initParticipants()
Init participants object (course or group participants)
isWaitingListActive()
Check if the waiting list is active Maximum of members exceeded or any user on the waiting list.
getFormTitle()
Get title for property form.
updateSubscriptionRequest()
Update subscription message.
fillRegistrationPeriod()
show informations about the registration period
fillAgreement()
Show user agreement.
addCommandButtons()
Add command buttons.
__construct($a_container)
Constructor.
validateAgreement()
Check Agreement.
setAccepted($a_status)
Set Agreement accepted.
cancel()
cancel subscription
validateCustomFields()
Check required course fields.
fillInformations()
fill informations
enableRegistration($a_status)
set registration disabled
initForm()
init registration form
validate()
validate join request
fillMembershipLimitation()
Show membership limitations.
getWaitingList()
Get waiting list object.
show(ilPropertyFormGUI $form=null)
show registration form
initWaitingList()
Init waiting list (course or group waiting list)
isRegistrationPossible()
check if registration is possible
fillMaxMembers()
show informations about the maximum number of user.
This class represents a selection list property in a property form.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilCtrl
Definition: ilias.php:18
catch(Exception $e) $message
$type
$ilUser
Definition: imgupload.php:18
$text
Definition: errorreport.php:18