ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
43  protected $participants;
44  protected $waiting_list = null;
45  protected $form;
46 
47  protected $registration_possible = true;
48  protected $join_error = '';
49 
50 
51  protected $tpl;
52  protected $lng;
53  protected $ctrl;
54 
62  public function __construct($a_container)
63  {
64  global $lng,$ilCtrl,$tpl;
65 
66  $this->lng = $lng;
67  $this->lng->loadLanguageModule('crs');
68  $this->lng->loadLanguageModule('grp');
69  $this->lng->loadLanguageModule('ps');
70 
71  $this->ctrl = $ilCtrl;
72  $this->tpl = $tpl;
73 
74  $this->container = $a_container;
75  $this->ref_id = $this->container->getRefId();
76  $this->obj_id = ilObject::_lookupObjId($this->ref_id);
77  $this->type = ilObject::_lookupType($this->obj_id);
78 
79  // Init participants
80  $this->initParticipants();
81 
82  // Init waiting list
83  $this->initWaitingList();
84 
85  $this->privacy = ilPrivacySettings::_getInstance();
86  }
87 
92  public function getContainer()
93  {
94  return $this->container;
95  }
96 
101  public function getRefId()
102  {
103  return $this->ref_id;
104  }
105 
112  protected function isRegistrationPossible()
113  {
114  return (bool) $this->registration_possible;
115  }
116 
124  protected function enableRegistration($a_status)
125  {
126  $this->registration_possible = $a_status;
127  }
128 
129 
136  abstract protected function initParticipants();
137 
145  abstract protected function initWaitingList();
146 
153  abstract protected function isWaitingListActive();
154 
160  protected function getWaitingList()
161  {
162  return $this->waiting_list;
163  }
164 
165  protected function leaveWaitingList()
166  {
167  global $ilUser,$tree,$ilCtrl;
168 
169  $this->getWaitingList()->removeFromList($ilUser->getId());
170  $parent = $tree->getParentId($this->container->getRefId());
171 
172  $message = sprintf($this->lng->txt($this->container->getType().'_removed_from_waiting_list'),
173  $this->container->getTitle());
174  ilUtil::sendSuccess($message,true);
175 
176  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $parent);
177  $ilCtrl->redirectByClass("ilrepositorygui", "");
178  }
179 
186  abstract protected function getFormTitle();
187 
194  abstract protected function fillInformations();
195 
201  abstract protected function fillRegistrationPeriod();
202 
210  abstract protected function fillMaxMembers();
211 
212 
219  abstract protected function fillRegistrationType();
220 
227  protected function fillMembershipLimitation()
228  {
229  global $ilAccess, $ilCtrl;
230 
231  include_once('Modules/Course/classes/class.ilObjCourseGrouping.php');
232  if(!$items = ilObjCourseGrouping::_getGroupingItems($this->container))
233  {
234  return true;
235  }
236 
237  $mem = new ilCustomInputGUI($this->lng->txt('groupings'));
238 
239  $tpl = new ilTemplate('tpl.membership_limitation_form.html',true,true,'Services/Membership');
240  $tpl->setVariable('LIMIT_INTRO',$this->lng->txt($this->type.'_grp_info_reg'));
241 
242  foreach($items as $ref_id)
243  {
244  $obj_id = ilObject::_lookupObjId($ref_id);
247 
248  if($ilAccess->checkAccess('visible','',$ref_id,$type))
249  {
250  include_once('./Services/Link/classes/class.ilLink.php');
251  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $ref_id);
252  $tpl->setVariable('LINK_ITEM',
253  $ilCtrl->getLinkTargetByClass("ilrepositorygui", ""));
254  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
255  $tpl->setVariable('ITEM_LINKED_TITLE',$title);
256  }
257  else
258  {
259  $tpl->setVariable('ITEM_TITLE');
260  }
261  $tpl->setCurrentBlock('items');
262  $tpl->setVariable('TYPE_ICON',ilUtil::getTypeIconPath($type,$obj_id,'tiny'));
263  $tpl->setVariable('ALT_ICON',$this->lng->txt('obj_'.$type));
264  $tpl->parseCurrentBlock();
265  }
266 
267  $mem->setHtml($tpl->get());
268 
269 
271  {
272  $mem->setAlert($this->container->getMessage());
273  $this->enableRegistration(false);
274  }
275  $this->form->addItem($mem);
276  }
277 
284  protected function fillAgreement()
285  {
286  global $ilUser;
287 
288  if(!$this->isRegistrationPossible())
289  {
290  return true;
291  }
292 
293  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
294  if(!$this->privacy->confirmationRequired($this->type) and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId()))
295  {
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  {
306  return true;
307  }
308 
310  $section->setTitle($this->lng->txt('usr_agreement'));
311  $this->form->addItem($section);
312 
313  $fields = new ilCustomInputGUI($this->lng->txt($this->type.'_user_agreement'),'');
314  $tpl = new ilTemplate('tpl.agreement_form.html',true,true,'Services/Membership');
315  $tpl->setVariable('TXT_INFO_AGREEMENT',$this->lng->txt($this->type.'_info_agreement'));
316  foreach($fields_info->getExportableFields() as $field)
317  {
318  $tpl->setCurrentBlock('field_item');
319  $tpl->setVariable('FIELD_NAME',$this->lng->txt($field));
320  $tpl->parseCurrentBlock();
321  }
322  $fields->setHtml($tpl->get());
323  $this->form->addItem($fields);
324 
325  $this->showCustomFields();
326 
327  // Checkbox agreement
328  if($this->privacy->confirmationRequired($this->type))
329  {
330  $agreement = new ilCheckboxInputGUI($this->lng->txt($this->type.'_agree'),'agreement');
331  $agreement->setRequired(true);
332  $agreement->setOptionTitle($this->lng->txt($this->type.'_info_agree'));
333  $agreement->setValue(1);
334  $this->form->addItem($agreement);
335  }
336 
337  return true;
338  }
339 
345  protected function showCustomFields()
346  {
347  global $ilUser;
348 
349  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
350  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
351 
352  if(!count($cdf_fields = ilCourseDefinedFieldDefinition::_getFields($this->container->getId())))
353  {
354  return true;
355  }
356 
357  $cdf = new ilNonEditableValueGUI($this->lng->txt('ps_crs_user_fields'));
358  $cdf->setValue($this->lng->txt($this->type.'_ps_cdf_info'));
359  $cdf->setRequired(true);
360 
361  foreach($cdf_fields as $field_obj)
362  {
363  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
364 
365  switch($field_obj->getType())
366  {
367  case IL_CDF_TYPE_SELECT:
368  $select = new ilSelectInputGUI($field_obj->getName(),'cdf['.$field_obj->getId().']');
369  $select->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
370  $select->setOptions($field_obj->prepareSelectBox());
371  if($field_obj->isRequired())
372  {
373  $select->setRequired(true);
374  }
375 
376  $cdf->addSubItem($select);
377 
378 
379  break;
380 
381  case IL_CDF_TYPE_TEXT:
382  $text = new ilTextInputGUI($field_obj->getName(),'cdf['.$field_obj->getId().']');
383  $text->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
384  $text->setSize(32);
385  $text->setMaxLength(255);
386  if($field_obj->isRequired())
387  {
388  $text->setRequired(true);
389  }
390  $cdf->addSubItem($text);
391  break;
392  }
393  }
394  $this->form->addItem($cdf);
395  return true;
396  }
397 
404  protected function validateAgreement()
405  {
406  global $ilUser;
407 
408  if($_POST['agreement'])
409  {
410  return true;
411  }
412  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
413  if(!$this->privacy->confirmationRequired($this->type))
414  {
415  return true;
416  }
417  return false;
418  }
419 
426  protected function validateCustomFields()
427  {
428  global $ilUser;
429 
430  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
431  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
432 
433  $all_required = true;
434  foreach(ilCourseDefinedFieldDefinition::_getFields($this->container->getId()) as $field_obj)
435  {
436  switch($field_obj->getType())
437  {
438  case IL_CDF_TYPE_SELECT:
439  $tmp_value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
440  $value = '';
441  foreach((array) $field_obj->getValues() as $v)
442  {
443  if($v == $tmp_value)
444  {
445  $value = $tmp_value;
446  break;
447  }
448  }
449  break;
450 
451  case IL_CDF_TYPE_TEXT:
452  $value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
453  break;
454  }
455  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
456  $course_user_data->setValue($value);
457  $course_user_data->update();
458 
459  if($field_obj->isRequired() and (!strlen($value) or $value == -1))
460  {
461  $all_required = false;
462  }
463  }
464  return $all_required;
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())
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 ?>