ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
24 include_once('Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
25 
35 abstract 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 
176  $message = sprintf($this->lng->txt($this->container->getType().'_removed_from_waiting_list'),
177  $this->container->getTitle());
178  ilUtil::sendSuccess($message,true);
179 
180  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $parent);
181  $ilCtrl->redirectByClass("ilrepositorygui", "");
182  }
183 
190  abstract protected function getFormTitle();
191 
198  abstract protected function fillInformations();
199 
205  abstract protected function fillRegistrationPeriod();
206 
214  abstract protected function fillMaxMembers();
215 
216 
223  abstract protected function fillRegistrationType();
224 
231  protected function fillMembershipLimitation()
232  {
233  global $ilAccess, $ilCtrl;
234 
235  include_once('Modules/Course/classes/class.ilObjCourseGrouping.php');
236  if(!$items = ilObjCourseGrouping::_getGroupingItems($this->container))
237  {
238  return true;
239  }
240 
241  $mem = new ilCustomInputGUI($this->lng->txt('groupings'));
242 
243  $tpl = new ilTemplate('tpl.membership_limitation_form.html',true,true,'Services/Membership');
244  $tpl->setVariable('LIMIT_INTRO',$this->lng->txt($this->type.'_grp_info_reg'));
245 
246  foreach($items as $ref_id)
247  {
248  $obj_id = ilObject::_lookupObjId($ref_id);
251 
252  if($ilAccess->checkAccess('visible','',$ref_id,$type))
253  {
254  include_once('./Services/Link/classes/class.ilLink.php');
255  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $ref_id);
256  $tpl->setVariable('LINK_ITEM',
257  $ilCtrl->getLinkTargetByClass("ilrepositorygui", ""));
258  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
259  $tpl->setVariable('ITEM_LINKED_TITLE',$title);
260  }
261  else
262  {
263  $tpl->setVariable('ITEM_TITLE');
264  }
265  $tpl->setCurrentBlock('items');
266  $tpl->setVariable('TYPE_ICON',ilObject::_getIcon($obj_id,tiny,$type));
267  $tpl->setVariable('ALT_ICON',$this->lng->txt('obj_'.$type));
268  $tpl->parseCurrentBlock();
269  }
270 
271  $mem->setHtml($tpl->get());
272 
273 
275  {
276  $mem->setAlert($this->container->getMessage());
277  $this->enableRegistration(false);
278  }
279  $this->form->addItem($mem);
280  }
281 
288  protected function fillAgreement()
289  {
290  global $ilUser;
291 
292  if(!$this->isRegistrationPossible())
293  {
294  return true;
295  }
296 
297  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
298  if(!$this->privacy->confirmationRequired($this->type) and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId()))
299  {
300  return true;
301  }
302 
303  $this->lng->loadLanguageModule('ps');
304 
305  include_once('Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php');
306  $fields_info = ilExportFieldsInfo::_getInstanceByType(ilObject::_lookupType($this->container->getId()));
307 
308  if(!count($fields_info->getExportableFields()))
309  {
310  return true;
311  }
312 
314  $section->setTitle($this->lng->txt($this->type.'_usr_agreement'));
315  $this->form->addItem($section);
316 
317  include_once './Services/Membership/classes/class.ilMemberAgreementGUI.php';
318  ilMemberAgreementGUI::addExportFieldInfo($this->form, $this->obj_id, $this->type);
319 
320 
321  ilMemberAgreementGUI::addCustomFields($this->form, $this->obj_id, $this->type);
322 
323  // Checkbox agreement
324  if($this->privacy->confirmationRequired($this->type))
325  {
326  ilMemberAgreementGUI::addAgreement($this->form, $this->obj_id, $this->type);
327  }
328  return true;
329  }
330 
336  protected function showCustomFields()
337  {
338  global $ilUser;
339 
340  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
341  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
342 
343  if(!count($cdf_fields = ilCourseDefinedFieldDefinition::_getFields($this->container->getId())))
344  {
345  return true;
346  }
347 
348  $cdf = new ilNonEditableValueGUI($this->lng->txt('ps_crs_user_fields'));
349  $cdf->setValue($this->lng->txt($this->type.'_ps_cdf_info'));
350  $cdf->setRequired(true);
351 
352  foreach($cdf_fields as $field_obj)
353  {
354  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
355 
356  switch($field_obj->getType())
357  {
358  case IL_CDF_TYPE_SELECT:
359  $select = new ilSelectInputGUI($field_obj->getName(),'cdf['.$field_obj->getId().']');
360  $select->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
361  $select->setOptions($field_obj->prepareSelectBox());
362  if($field_obj->isRequired())
363  {
364  $select->setRequired(true);
365  }
366 
367  $cdf->addSubItem($select);
368 
369 
370  break;
371 
372  case IL_CDF_TYPE_TEXT:
373  $text = new ilTextInputGUI($field_obj->getName(),'cdf['.$field_obj->getId().']');
374  $text->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
375  $text->setSize(32);
376  $text->setMaxLength(255);
377  if($field_obj->isRequired())
378  {
379  $text->setRequired(true);
380  }
381  $cdf->addSubItem($text);
382  break;
383  }
384  }
385  $this->form->addItem($cdf);
386  return true;
387  }
388 
395  protected function validateAgreement()
396  {
397  global $ilUser;
398 
399  if($_POST['agreement'])
400  {
401  return true;
402  }
403  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
404  if(!$this->privacy->confirmationRequired($this->type))
405  {
406  return true;
407  }
408  return false;
409  }
410 
417  protected function validateCustomFields()
418  {
419  global $ilUser;
420 
421 
422  $required_fullfilled = true;
423  foreach(ilCourseDefinedFieldDefinition::_getFields($this->container->getId()) as $field_obj)
424  {
425  switch($field_obj->getType())
426  {
427  case IL_CDF_TYPE_SELECT:
428 
429  // Split value id from post
430  list($field_id,$option_id) = explode('_', $_POST['cdf_'.$field_obj->getId()]);
431 
432  #$GLOBALS['ilLog']->write(__METHOD__.': '.print_r($field_id,TRUE).' '.print_r($option_id,TRUE).' '.print_r($_POST,TRUE));
433 
434  $open_answer_indexes = (array) $field_obj->getValueOptions();
435  if(in_array($option_id, $open_answer_indexes))
436  {
437  $value = $_POST['cdf_oa_'.$field_obj->getId().'_'.$option_id];
438  }
439  else
440  {
441  $value = $field_obj->getValueById($option_id);
442  }
443  break;
444 
445  case IL_CDF_TYPE_TEXT:
446  $value = $_POST['cdf_'.$field_obj->getId()];
447  break;
448  }
449 
450  $GLOBALS['ilLog']->write(__METHOD__.': new value '. $value);
451 
452 
453  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
454  $course_user_data->setValue($value);
455  $course_user_data->update();
456 
457  // #14220
458  if($field_obj->isRequired() and $value == "")
459  {
460  $required_fullfilled = false;
461  }
462  }
463 
464  return $required_fullfilled;
465  }
466 
473  protected function setAccepted($a_status)
474  {
475  global $ilUser;
476 
477  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
478  if(!$this->privacy->confirmationRequired($this->type) and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId()))
479  {
480  return true;
481  }
482 
483  include_once('Services/Membership/classes/class.ilMemberAgreement.php');
484  $this->agreement = new ilMemberAgreement($ilUser->getId(),$this->container->getId());
485  $this->agreement->setAccepted($a_status);
486  $this->agreement->setAcceptanceTime(time());
487  $this->agreement->save();
488  }
489 
495  public function cancel()
496  {
497  global $tree, $ilCtrl;
498 
499  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
500  $tree->getParentId($this->container->getRefId()));
501  $ilCtrl->redirectByClass("ilrepositorygui", "");
502  }
503 
511  public function show()
512  {
513  $this->initForm();
514 
515  if($_SESSION["pending_goto"])
516  {
517  ilUtil::sendInfo($this->lng->txt("reg_goto_parent_membership_info"));
518  }
519 
520  $this->tpl->setContent($this->form->getHTML());
521  }
522 
530  public function join()
531  {
532  $this->initForm();
533 
534  if(!$this->validate())
535  {
536  ilUtil::sendFailure($this->join_error);
537  $this->show();
538  return false;
539  }
540 
541  $this->add();
542  }
543 
544 
551  protected function validate()
552  {
553  return true;
554  }
555 
562  protected function initForm()
563  {
564  global $ilUser;
565 
566  if(is_object($this->form))
567  {
568  return true;
569  }
570 
571  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
572  $this->form = new ilPropertyFormGUI();
573  $this->form->setFormAction($this->ctrl->getFormAction($this,'join'));
574  $this->form->setTitle($this->getFormTitle());
575 
576  $this->fillInformations();
577  $this->fillMembershipLimitation();
578  if($this->isRegistrationPossible())
579  {
580  $this->fillRegistrationPeriod();
581  }
582  if($this->isRegistrationPossible() || $this->participants->isSubscriber($ilUser->getId()))
583  {
584  $this->fillRegistrationType();
585  }
586  if($this->isRegistrationPossible())
587  {
588  $this->fillMaxMembers();
589  }
590  if($this->isRegistrationPossible())
591  {
592  $this->fillAgreement();
593  }
594  $this->addCommandButtons();
595  }
596 
601  protected function addCommandButtons()
602  {
603  global $ilUser;
604 
605  if($this->isRegistrationPossible() and $this->isWaitingListActive() and !$this->getWaitingList()->isOnList($ilUser->getId()))
606  {
607  $this->form->addCommandButton('join',$this->lng->txt('mem_add_to_wl'));
608  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
609  }
610  elseif($this->isRegistrationPossible() and !$this->getWaitingList()->isOnList($ilUser->getId()))
611  {
612  $this->form->addCommandButton('join',$this->lng->txt('join'));
613  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
614  }
615  if($this->getWaitingList()->isOnList($ilUser->getId()))
616  {
618  sprintf($this->lng->txt($this->container->getType().'_cancel_waiting_list'),
619  $this->container->getTitle())
620  );
621  $this->form->addCommandButton('leaveWaitingList', $this->lng->txt('leave_waiting_list'));
622  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
623  }
624  }
625 
630  protected function updateSubscriptionRequest()
631  {
632  global $ilUser, $tree, $ilCtrl;
633 
634  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['subject']));
635  ilUtil::sendSuccess($this->lng->txt('sub_request_saved'),true);
636  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
637  $tree->getParentId($this->container->getRefId()));
638  $ilCtrl->redirectByClass("ilrepositorygui", "");
639 
640  }
641 
642  protected function cancelSubscriptionRequest()
643  {
644  global $ilUser, $tree, $ilCtrl;
645 
646  $this->participants->deleteSubscriber($ilUser->getId());
647  ilUtil::sendSuccess($this->lng->txt('sub_request_deleted'),true);
648 
649  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
650  $tree->getParentId($this->container->getRefId()));
651  $ilCtrl->redirectByClass("ilrepositorygui", "");
652  }
653 }
654 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
fillAgreement()
Show user agreement.
setHtml($a_html)
Set Html.
$_POST['username']
Definition: cron.php:12
$_SESSION["AccountId"]
This class represents a selection list property in a property form.
This class represents a property form user interface.
static addExportFieldInfo($form, $a_obj_id, $a_type)
Add export field info to form type $lng.
$_GET["client_id"]
This class represents a section header in a property form.
initForm()
init registration form
getWaitingList()
Get waiting list object.
fillRegistrationPeriod()
show informations about the registration period
fillRegistrationType()
show informations about registration procedure
updateSubscriptionRequest()
Update subscription message.
static _lookupTitle($a_id)
lookup object title
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.
Base class for Course and Group registration.
static addCustomFields($form, $a_obj_id, $a_type, $a_mode='user')
Add custom course fields.
showCustomFields()
Show course defined fields.
global $ilCtrl
Definition: ilias.php:18
setAccepted($a_status)
set accepted
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
validateAgreement()
Check Agreement.
$section
Definition: Utf8Test.php:84
setAccepted($a_status)
Set Agreement accepted.
initWaitingList()
Init waiting list (course or group waiting list)
enableRegistration($a_status)
set registration disabled
static _getInstanceByType($a_type)
Get Singleton Instance.
validate()
validate join request
static _lookupObjId($a_id)
special template class to simplify handling of ITX/PEAR
isRegistrationPossible()
check if registration is possible
static addAgreement($form, $a_obj_id, $a_type)
Add agreement to form.
This class represents a text property in a property form.
validateCustomFields()
Check required course fields.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _hasFields($a_container_id)
Check if there are any define fields.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
_checkGroupingDependencies(&$container_obj, $a_user_id=null)
This class represents a custom property in a property form.
cancel()
cancel subscription
show()
show registration form
This class represents a non editable value in a property form.
global $ilUser
Definition: imgupload.php:15
fillMembershipLimitation()
Show membership limitations.
fillInformations()
fill informations
addCommandButtons()
Add command buttons.
_getGroupingItems($container_obj)
Get courses/groups that are assigned to the same membership limitation.
$text
fillMaxMembers()
show informations about the maximum number of user.
__construct($a_container)
Constructor.
static _getInstance()
Get instance of ilPrivacySettings.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
getContainer()
Parent object.
initParticipants()
Init participants object (course or group participants)
static _getFields($a_container_id, $a_sort=IL_CDF_SORT_NAME)
Get all fields of a container.