ILIAS  Release_4_2_x_branch Revision 61807
 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 
94  protected function isRegistrationPossible()
95  {
96  return (bool) $this->registration_possible;
97  }
98 
106  protected function enableRegistration($a_status)
107  {
108  $this->registration_possible = $a_status;
109  }
110 
111 
118  abstract protected function initParticipants();
119 
127  abstract protected function initWaitingList();
128 
135  abstract protected function isWaitingListActive();
136 
142  protected function getWaitingList()
143  {
144  return $this->waiting_list;
145  }
146 
147  protected function leaveWaitingList()
148  {
149  global $ilUser,$tree,$ilCtrl;
150 
151  $this->getWaitingList()->removeFromList($ilUser->getId());
152  $parent = $tree->getParentId($this->container->getRefId());
153 
154  $message = sprintf($this->lng->txt($this->container->getType().'_removed_from_waiting_list'),
155  $this->container->getTitle());
156  ilUtil::sendSuccess($message,true);
157  ilUtil::redirect('repository.php?ref_id='.$parent);
158  }
159 
166  abstract protected function getFormTitle();
167 
174  abstract protected function fillInformations();
175 
181  abstract protected function fillRegistrationPeriod();
182 
190  abstract protected function fillMaxMembers();
191 
192 
199  abstract protected function fillRegistrationType();
200 
207  protected function fillMembershipLimitation()
208  {
209  global $ilAccess;
210 
211  include_once('Modules/Course/classes/class.ilObjCourseGrouping.php');
212  if(!$items = ilObjCourseGrouping::_getGroupingItems($this->container))
213  {
214  return true;
215  }
216 
217  $mem = new ilCustomInputGUI($this->lng->txt('groupings'));
218 
219  $tpl = new ilTemplate('tpl.membership_limitation_form.html',true,true,'Services/Membership');
220  $tpl->setVariable('LIMIT_INTRO',$this->lng->txt($this->type.'_grp_info_reg'));
221 
222  foreach($items as $ref_id)
223  {
224  $obj_id = ilObject::_lookupObjId($ref_id);
227 
228  if($ilAccess->checkAccess('visible','',$ref_id,$type))
229  {
230  include_once('./classes/class.ilLink.php');
231  $tpl->setVariable('LINK_ITEM','repository.php?ref_id='.$ref_id);
232  $tpl->setVariable('ITEM_LINKED_TITLE',$title);
233  }
234  else
235  {
236  $tpl->setVariable('ITEM_TITLE');
237  }
238  $tpl->setCurrentBlock('items');
239  $tpl->setVariable('TYPE_ICON',ilUtil::getTypeIconPath($type,$obj_id,'tiny'));
240  $tpl->setVariable('ALT_ICON',$this->lng->txt('obj_'.$type));
241  $tpl->parseCurrentBlock();
242  }
243 
244  $mem->setHtml($tpl->get());
245 
246 
248  {
249  $mem->setAlert($this->container->getMessage());
250  $this->enableRegistration(false);
251  }
252  $this->form->addItem($mem);
253  }
254 
261  protected function fillAgreement()
262  {
263  global $ilUser;
264 
265  if(!$this->isRegistrationPossible())
266  {
267  return true;
268  }
269 
270  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
271  if(!$this->privacy->confirmationRequired($this->type) and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId()))
272  {
273  return true;
274  }
275 
276  $this->lng->loadLanguageModule('ps');
277 
278  include_once('Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php');
279  $fields_info = ilExportFieldsInfo::_getInstanceByType(ilObject::_lookupType($this->container->getId()));
280 
281  if(!count($fields_info->getExportableFields()))
282  {
283  return true;
284  }
285 
287  $section->setTitle($this->lng->txt('usr_agreement'));
288  $this->form->addItem($section);
289 
290  $fields = new ilCustomInputGUI($this->lng->txt($this->type.'_user_agreement'),'');
291  $tpl = new ilTemplate('tpl.agreement_form.html',true,true,'Services/Membership');
292  $tpl->setVariable('TXT_INFO_AGREEMENT',$this->lng->txt($this->type.'_info_agreement'));
293  foreach($fields_info->getExportableFields() as $field)
294  {
295  $tpl->setCurrentBlock('field_item');
296  $tpl->setVariable('FIELD_NAME',$this->lng->txt($field));
297  $tpl->parseCurrentBlock();
298  }
299  $fields->setHtml($tpl->get());
300  $this->form->addItem($fields);
301 
302  $this->showCustomFields();
303 
304  // Checkbox agreement
305  if($this->privacy->confirmationRequired($this->type))
306  {
307  $agreement = new ilCheckboxInputGUI($this->lng->txt($this->type.'_agree'),'agreement');
308  $agreement->setRequired(true);
309  $agreement->setOptionTitle($this->lng->txt($this->type.'_info_agree'));
310  $agreement->setValue(1);
311  $this->form->addItem($agreement);
312  }
313 
314  return true;
315  }
316 
322  protected function showCustomFields()
323  {
324  global $ilUser;
325 
326  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
327  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
328 
329  if(!count($cdf_fields = ilCourseDefinedFieldDefinition::_getFields($this->container->getId())))
330  {
331  return true;
332  }
333 
334  $cdf = new ilNonEditableValueGUI($this->lng->txt('ps_crs_user_fields'));
335  $cdf->setValue($this->lng->txt($this->type.'_ps_cdf_info'));
336  $cdf->setRequired(true);
337 
338  foreach($cdf_fields as $field_obj)
339  {
340  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
341 
342  switch($field_obj->getType())
343  {
344  case IL_CDF_TYPE_SELECT:
345  $select = new ilSelectInputGUI($field_obj->getName(),'cdf['.$field_obj->getId().']');
346  $select->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
347  $select->setOptions($field_obj->prepareSelectBox());
348  if($field_obj->isRequired())
349  {
350  $select->setRequired(true);
351  }
352 
353  $cdf->addSubItem($select);
354 
355 
356  break;
357 
358  case IL_CDF_TYPE_TEXT:
359  $text = new ilTextInputGUI($field_obj->getName(),'cdf['.$field_obj->getId().']');
360  $text->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
361  $text->setSize(32);
362  $text->setMaxLength(255);
363  if($field_obj->isRequired())
364  {
365  $text->setRequired(true);
366  }
367  $cdf->addSubItem($text);
368  break;
369  }
370  }
371  $this->form->addItem($cdf);
372  return true;
373  }
374 
381  protected function validateAgreement()
382  {
383  global $ilUser;
384 
385  if($_POST['agreement'])
386  {
387  return true;
388  }
389  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
390  if(!$this->privacy->confirmationRequired($this->type))
391  {
392  return true;
393  }
394  return false;
395  }
396 
403  protected function validateCustomFields()
404  {
405  global $ilUser;
406 
407  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
408  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
409 
410  $all_required = true;
411  foreach(ilCourseDefinedFieldDefinition::_getFields($this->container->getId()) as $field_obj)
412  {
413  switch($field_obj->getType())
414  {
415  case IL_CDF_TYPE_SELECT:
416  $tmp_value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
417  $value = '';
418  foreach((array) $field_obj->getValues() as $v)
419  {
420  if($v == $tmp_value)
421  {
422  $value = $tmp_value;
423  break;
424  }
425  }
426  break;
427 
428  case IL_CDF_TYPE_TEXT:
429  $value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
430  break;
431  }
432  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
433  $course_user_data->setValue($value);
434  $course_user_data->update();
435 
436  if($field_obj->isRequired() and (!strlen($value) or $value == -1))
437  {
438  $all_required = false;
439  }
440  }
441  return $all_required;
442  }
443 
450  protected function setAccepted($a_status)
451  {
452  global $ilUser;
453 
454  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
455  if(!$this->privacy->confirmationRequired($this->type) and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId()))
456  {
457  return true;
458  }
459 
460  include_once('Services/Membership/classes/class.ilMemberAgreement.php');
461  $this->agreement = new ilMemberAgreement($ilUser->getId(),$this->container->getId());
462  $this->agreement->setAccepted($a_status);
463  $this->agreement->setAcceptanceTime(time());
464  $this->agreement->save();
465  }
466 
472  public function cancel()
473  {
474  global $tree;
475 
476  ilUtil::redirect('repository.php?ref_id='.
477  $tree->getParentId($this->container->getRefId()));
478  }
479 
487  public function show()
488  {
489  $this->initForm();
490 
491  $this->tpl->setContent($this->form->getHTML());
492  }
493 
501  public function join()
502  {
503  $this->initForm();
504 
505  if(!$this->validate())
506  {
507  ilUtil::sendFailure($this->join_error);
508  $this->show();
509  return false;
510  }
511 
512  $this->add();
513  }
514 
515 
522  protected function validate()
523  {
524  return true;
525  }
526 
533  protected function initForm()
534  {
535  global $ilUser;
536 
537  if(is_object($this->form))
538  {
539  return true;
540  }
541 
542  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
543  $this->form = new ilPropertyFormGUI();
544  $this->form->setFormAction($this->ctrl->getFormAction($this,'join'));
545  $this->form->setTitle($this->getFormTitle());
546 
547  $this->fillInformations();
548  $this->fillMembershipLimitation();
549  if($this->isRegistrationPossible())
550  {
551  $this->fillRegistrationPeriod();
552  }
553  if($this->isRegistrationPossible())
554  {
555  $this->fillRegistrationType();
556  }
557  if($this->isRegistrationPossible())
558  {
559  $this->fillMaxMembers();
560  }
561  if($this->isRegistrationPossible())
562  {
563  $this->fillAgreement();
564  }
565  $this->addCommandButtons();
566  }
567 
572  protected function addCommandButtons()
573  {
574  global $ilUser;
575 
576  if($this->isRegistrationPossible() and $this->isWaitingListActive() and !$this->getWaitingList()->isOnList($ilUser->getId()))
577  {
578  $this->form->addCommandButton('join',$this->lng->txt('mem_add_to_wl'));
579  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
580  }
581  elseif($this->isRegistrationPossible() and !$this->getWaitingList()->isOnList($ilUser->getId()))
582  {
583  $this->form->addCommandButton('join',$this->lng->txt('join'));
584  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
585  }
586  if($this->getWaitingList()->isOnList($ilUser->getId()))
587  {
589  sprintf($this->lng->txt($this->container->getType().'_cancel_waiting_list'),
590  $this->container->getTitle())
591  );
592  $this->form->addCommandButton('leaveWaitingList', $this->lng->txt('leave_waiting_list'));
593  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
594  }
595  }
596 
601  protected function updateSubscriptionRequest()
602  {
603  global $ilUser,$tree;
604 
605  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['subject']));
606  ilUtil::sendSuccess($this->lng->txt('sub_request_saved'),true);
607  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
608  }
609 
610  protected function cancelSubscriptionRequest()
611  {
612  global $ilUser,$tree;
613 
614  $this->participants->deleteSubscriber($ilUser->getId());
615  ilUtil::sendSuccess($this->lng->txt('sub_request_deleted'),true);
616  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
617 
618  }
619 }
620 ?>