ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseRegistrationGUI.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 
25 include_once('Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
26 include_once('./Services/Membership/classes/class.ilRegistrationGUI.php');
27 
39 {
40  protected $privacy = null;
41 
48  public function __construct($a_container)
49  {
50  parent::__construct($a_container);
51 
52  $this->privacy = ilPrivacySettings::_getInstance();
53  }
54 
60  public function executeCommand()
61  {
62  global $ilTabs,$ilUser;
63 
64  if($this->getWaitingList()->isOnList($ilUser->getId()))
65  {
66  $ilTabs->activateTab('leave');
67  }
68 
69  $next_class = $this->ctrl->getNextClass($this);
70  switch($next_class)
71  {
72  default:
73  $cmd = $this->ctrl->getCmd("show");
74  $this->$cmd();
75  break;
76  }
77  return true;
78  }
79 
86  protected function getFormTitle()
87  {
88  global $ilUser;
89 
90  if($this->getWaitingList()->isOnList($ilUser->getId()))
91  {
92  return $this->lng->txt('member_status');
93  }
94  return $this->lng->txt('crs_registration');
95  }
96 
104  protected function fillInformations()
105  {
106  if($this->container->getImportantInformation())
107  {
108  $imp = new ilNonEditableValueGUI($this->lng->txt('crs_important_info'));
109  $value = nl2br(ilUtil::makeClickable($this->container->getImportantInformation(), true));
110  $imp->setValue($value);
111  $this->form->addItem($imp);
112  }
113 
114  if($this->container->getSyllabus())
115  {
116  $syl = new ilNonEditableValueGUI($this->lng->txt('crs_syllabus'));
117  $value = nl2br(ilUtil::makeClickable ($this->container->getSyllabus(), true));
118  $syl->setValue($value);
119  $this->form->addItem($syl);
120  }
121  }
122 
128  protected function fillRegistrationPeriod()
129  {
130  include_once('./Services/Calendar/classes/class.ilDateTime.php');
131  $now = new ilDateTime(time(),IL_CAL_UNIX,'UTC');
132 
133  if($this->container->getSubscriptionUnlimitedStatus())
134  {
135  $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_period'));
136  $reg->setValue($this->lng->txt('mem_unlimited'));
137  $this->form->addItem($reg);
138  return true;
139  }
140  elseif($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
141  {
142  return true;
143  }
144 
145  $start = new ilDateTime($this->container->getSubscriptionStart(),IL_CAL_UNIX,'UTC');
146  $end = new ilDateTime($this->container->getSubscriptionEnd(),IL_CAL_UNIX,'UTC');
147 
148  if(ilDateTime::_before($now,$start))
149  {
150  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
151  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_start'));
152  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($start));
153 
154  $tpl->setVariable('TXT_END',$this->lng->txt('mem_end'));
155  $tpl->setVariable('END',ilDatePresentation::formatDate($end));
156 
157  $warning = $this->lng->txt('mem_reg_not_started');
158  }
159  elseif(ilDateTime::_after($now,$end))
160  {
161  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
162  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_start'));
163  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($start));
164 
165  $tpl->setVariable('TXT_END',$this->lng->txt('mem_end'));
166  $tpl->setVariable('END',ilDatePresentation::formatDate($end));
167 
168 
169  $warning = $this->lng->txt('mem_reg_expired');
170  }
171  else
172  {
173  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
174  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_end'));
175  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($end));
176  }
177 
178  $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
179  $reg->setHtml($tpl->get());
180  if(strlen($warning))
181  {
182  // Disable registration
183  $this->enableRegistration(false);
184  ilUtil::sendFailure($warning);
185  #$reg->setAlert($warning);
186  }
187  $this->form->addItem($reg);
188  return true;
189  }
190 
191 
199  protected function fillMaxMembers()
200  {
201  global $ilUser;
202 
203  if(!$this->container->isSubscriptionMembershipLimited())
204  {
205  return true;
206  }
207  $tpl = new ilTemplate('tpl.max_members_form.html',true,true,'Services/Membership');
208  $tpl->setVariable('TXT_MAX',$this->lng->txt('mem_max_users'));
209  $tpl->setVariable('NUM_MAX',$this->container->getSubscriptionMaxMembers());
210 
211  $tpl->setVariable('TXT_FREE',$this->lng->txt('mem_free_places').":");
212  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
213 
214  if($free)
215  $tpl->setVariable('NUM_FREE',$free);
216  else
217  $tpl->setVariable('WARN_FREE',$free);
218 
219 
220  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
221  $waiting_list = new ilCourseWaitingList($this->container->getId());
222  if($this->container->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
223  {
224  if($waiting_list->isOnList($ilUser->getId()))
225  {
226  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list_position'));
227  $tpl->setVariable('NUM_WAIT',$waiting_list->getPosition($ilUser->getId()));
228 
229  }
230  else
231  {
232  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list'));
233  if($free and $waiting_list->getCountUsers())
234  $tpl->setVariable('WARN_WAIT',$waiting_list->getCountUsers());
235  else
236  $tpl->setVariable('NUM_WAIT',$waiting_list->getCountUsers());
237  }
238  }
239 
240  $alert = '';
241  if(!$free and !$this->container->enabledWaitingList())
242  {
243  // Disable registration
244  $this->enableRegistration(false);
245  ilUtil::sendFailure($this->lng->txt('mem_alert_no_places'));
246  #$alert = $this->lng->txt('mem_alert_no_places');
247  }
248  elseif($this->container->enabledWaitingList() and $waiting_list->isOnList($ilUser->getId()))
249  {
250  // Disable registration
251  $this->enableRegistration(false);
252  }
253  elseif(!$free and $this->container->enabledWaitingList())
254  {
255  ilUtil::sendFailure($this->lng->txt('crs_warn_no_max_set_on_waiting_list'));
256  #$alert = $this->lng->txt('crs_warn_no_max_set_on_waiting_list');
257  }
258  elseif($free and $this->container->enabledWaitingList() and $this->getWaitingList()->getCountUsers())
259  {
260  ilUtil::sendFailure($this->lng->txt('crs_warn_wl_set_on_waiting_list'));
261  #$alert = $this->lng->txt('crs_warn_wl_set_on_waiting_list');
262  }
263 
264  $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
265  $max->setHtml($tpl->get());
266  if(strlen($alert))
267  {
268  $max->setAlert($alert);
269  }
270  $this->form->addItem($max);
271  return true;
272  }
273 
280  protected function fillRegistrationType()
281  {
282  global $ilUser;
283 
284  if($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
285  {
286  $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_type'));
287  #$reg->setHtml($this->lng->txt('crs_info_reg_deactivated'));
288  $reg->setAlert($this->lng->txt('crs_info_reg_deactivated'));
289  #ilUtil::sendFailure($this->lng->txt('crs_info_reg_deactivated'));
290  #$reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
291  #$reg->setValue($this->lng->txt('crs_info_reg_deactivated'));
292  #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
293  $this->form->addItem($reg);
294 
295  // Disable registration
296  $this->enableRegistration(false);
297  return true;
298  }
299 
300  switch($this->container->getSubscriptionType())
301  {
303 
304  // no "request" info if waiting list is active
305  if($this->isWaitingListActive())
306  return true;
307 
308  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
309  $txt->setValue($this->lng->txt('crs_info_reg_direct'));
310 
311  $this->form->addItem($txt);
312  break;
313 
315  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
316  $txt->setValue($this->lng->txt('crs_subscription_options_password'));
317 
318 
319  $pass = new ilTextInputGUI($this->lng->txt('passwd'),'grp_passw');
320  $pass->setInputType('password');
321  $pass->setSize(12);
322  $pass->setMaxLength(32);
323  #$pass->setRequired(true);
324  $pass->setInfo($this->lng->txt('crs_info_reg_password'));
325 
326  $txt->addSubItem($pass);
327  $this->form->addItem($txt);
328  break;
329 
331 
332  // no "request" info if waiting list is active
333  if($this->isWaitingListActive())
334  return true;
335 
336  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
337  $txt->setValue($this->lng->txt('crs_subscription_options_confirmation'));
338 
339  $sub = new ilTextAreaInputGUI($this->lng->txt('crs_reg_subject'),'subject');
340  $sub->setValue($_POST['subject']);
341  $sub->setInfo($this->lng->txt('crs_info_reg_confirmation'));
342  $sub->setCols(40);
343  $sub->setRows(5);
344  if($this->participants->isSubscriber($ilUser->getId()))
345  {
346  $sub_data = $this->participants->getSubscriberData($ilUser->getId());
347  $sub->setValue($sub_data['subject']);
348  $sub->setInfo('');
349  ilUtil::sendFailure($this->lng->txt('crs_reg_user_already_subscribed'));
350  $this->enableRegistration(false);
351  }
352  $txt->addSubItem($sub);
353  $this->form->addItem($txt);
354  break;
355 
356 
357  default:
358  return true;
359  }
360 
361  return true;
362  }
363 
368  protected function addCommandButtons()
369  {
370  global $ilUser;
371 
373 
374  if(!$this->isRegistrationPossible())
375  {
376  return false;
377  }
378 
379  switch($this->container->getSubscriptionType())
380  {
382  if($this->participants->isSubscriber($ilUser->getId()))
383  {
384  $this->form->clearCommandButtons();
385  $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('crs_update_subscr_request'));
386  $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('crs_cancel_subscr_request'));
387  }
388  else
389  {
390  $this->form->clearCommandButtons();
391  $this->form->addCommandButton('join', $this->lng->txt('crs_join_request'));
392  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
393  }
394  break;
395  }
396  return true;
397  }
398 
405  protected function fillAgreement()
406  {
407  global $ilUser;
408 
409  if(!$this->isRegistrationPossible())
410  {
411  return true;
412  }
413 
414 
415  $this->privacy = ilPrivacySettings::_getInstance();
416  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
417  if(!$this->privacy->confirmationRequired() and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId()))
418  {
419  return true;
420  }
421 
422  $this->lng->loadLanguageModule('ps');
423 
424  include_once('Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php');
425  $fields_info = ilExportFieldsInfo::_getInstance();
426 
427  if(!count($fields_info->getExportableFields()))
428  {
429  return true;
430  }
431 
433  $section->setTitle($this->lng->txt('usr_agreement'));
434  $this->form->addItem($section);
435 
436  $fields = new ilCustomInputGUI($this->lng->txt('crs_user_agreement'),'');
437  $tpl = new ilTemplate('tpl.agreement_form.html',true,true,'Services/Membership');
438  $tpl->setVariable('TXT_INFO_AGREEMENT',$this->lng->txt('crs_info_agreement'));
439  foreach($fields_info->getExportableFields() as $field)
440  {
441  $tpl->setCurrentBlock('field_item');
442  $tpl->setVariable('FIELD_NAME',$this->lng->txt($field));
443  $tpl->parseCurrentBlock();
444  }
445  $fields->setHtml($tpl->get());
446  $this->form->addItem($fields);
447 
448  $this->showCourseDefinedFields();
449 
450  // Checkbox agreement
451  $agreement = new ilCheckboxInputGUI($this->lng->txt('crs_agree'),'agreement');
452  $agreement->setRequired(true);
453  $agreement->setOptionTitle($this->lng->txt('crs_info_agree'));
454  $agreement->setValue(1);
455  $this->form->addItem($agreement);
456 
457 
458  return true;
459  }
460 
466  protected function showCourseDefinedFields()
467  {
468  global $ilUser;
469 
470  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
471  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
472 
473  if(!count($cdf_fields = ilCourseDefinedFieldDefinition::_getFields($this->container->getId())))
474  {
475  return true;
476  }
477 
478  $cdf = new ilNonEditableValueGUI($this->lng->txt('ps_crs_user_fields'));
479  $cdf->setValue($this->lng->txt('ps_cdf_info'));
480  $cdf->setRequired(true);
481 
482  foreach($cdf_fields as $field_obj)
483  {
484  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
485 
486  switch($field_obj->getType())
487  {
488  case IL_CDF_TYPE_SELECT:
489  $select = new ilSelectInputGUI($field_obj->getName(),'cdf['.$field_obj->getId().']');
490  $select->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
491  $select->setOptions($field_obj->prepareSelectBox());
492  if($field_obj->isRequired())
493  {
494  $select->setRequired(true);
495  }
496 
497  $cdf->addSubItem($select);
498 
499 
500  break;
501 
502  case IL_CDF_TYPE_TEXT:
503  $text = new ilTextInputGUI($field_obj->getName(),'cdf['.$field_obj->getId().']');
504  $text->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
505  $text->setSize(32);
506  $text->setMaxLength(255);
507  if($field_obj->isRequired())
508  {
509  $text->setRequired(true);
510  }
511  $cdf->addSubItem($text);
512  break;
513  }
514  }
515  $this->form->addItem($cdf);
516  return true;
517  }
518 
519 
520 
528  protected function validate()
529  {
530  global $ilUser;
531 
532  if($ilUser->getId() == ANONYMOUS_USER_ID)
533  {
534  $this->join_error = $this->lng->txt('permission_denied');
535  return false;
536  }
537 
538  // Set aggrement to not accepted
539  $this->setAccepted(false);
540 
541  if(!$this->isRegistrationPossible())
542  {
543  $this->join_error = $this->lng->txt('mem_error_preconditions');
544  return false;
545  }
546  if($this->container->getSubscriptionType() == IL_CRS_SUBSCRIPTION_PASSWORD)
547  {
548  if(!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw'])))
549  {
550  $this->join_error = $this->lng->txt('crs_password_required');
551  return false;
552  }
553  if(strcmp($pass,$this->container->getSubscriptionPassword()) !== 0)
554  {
555  $this->join_error = $this->lng->txt('crs_password_not_valid');
556  return false;
557  }
558  }
559  if(!$this->validateCourseDefinedFields())
560  {
561  $this->join_error = $this->lng->txt('fill_out_all_required_fields');
562  return false;
563  }
564  if(!$this->validateAgreement())
565  {
566  $this->join_error = $this->lng->txt('crs_agreement_required');
567  return false;
568  }
569 
570  return true;
571  }
572 
579  private function validateAgreement()
580  {
581  global $ilUser;
582 
583  if($_POST['agreement'])
584  {
585  return true;
586  }
587  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
588  if(!$this->privacy->confirmationRequired() and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId()))
589  {
590  return true;
591  }
592  return false;
593  }
594 
601  private function validateCourseDefinedFields()
602  {
603  global $ilUser;
604 
605  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
606  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
607 
608  $all_required = true;
609  foreach(ilCourseDefinedFieldDefinition::_getFields($this->container->getId()) as $field_obj)
610  {
611  switch($field_obj->getType())
612  {
613  case IL_CDF_TYPE_SELECT:
614  $tmp_value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
615  $value = '';
616  foreach((array) $field_obj->getValues() as $v)
617  {
618  if($v == $tmp_value)
619  {
620  $value = $tmp_value;
621  break;
622  }
623  }
624  break;
625 
626  case IL_CDF_TYPE_TEXT:
627  $value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
628  break;
629  }
630  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
631  $course_user_data->setValue($value);
632  $course_user_data->update();
633 
634  if($field_obj->isRequired() and (!strlen($value) or $value == -1))
635  {
636  $all_required = false;
637  }
638  }
639  return $all_required;
640  }
641 
642 
643 
651  protected function add()
652  {
653  global $ilUser,$tree;
654 
655  // TODO: language vars
656 
657  // set aggreement accepted
658  $this->setAccepted(true);
659 
660  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
661  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
662  $waiting_list = new ilCourseWaitingList($this->container->getId());
663  if($this->container->isSubscriptionMembershipLimited() and $this->container->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
664  {
665  $waiting_list->addToList($ilUser->getId());
666  $info = sprintf($this->lng->txt('crs_added_to_list'),
667  $waiting_list->getPosition($ilUser->getId()));
668  ilUtil::sendSuccess($info,true);
669 
670  $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST,$ilUser->getId());
671  $this->participants->sendNotification($this->participants->NOTIFY_WAITING_LIST,$ilUser->getId());
672  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
673  }
674 
675 
676  switch($this->container->getSubscriptionType())
677  {
679  $this->participants->addSubscriber($ilUser->getId());
680  $this->participants->updateSubscriptionTime($ilUser->getId(),time());
681  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['subject']));
682  $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST,$ilUser->getId());
683 
684  ilUtil::sendSuccess($this->lng->txt("application_completed"),true);
685  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
686  break;
687 
688  default:
689  $this->participants->add($ilUser->getId(),IL_CRS_MEMBER);
690  $this->participants->sendNotification($this->participants->NOTIFY_ADMINS,$ilUser->getId());
691  $this->participants->sendNotification($this->participants->NOTIFY_REGISTERED,$ilUser->getId());
692  ilUtil::sendSuccess($this->lng->txt("crs_subscription_successful"),true);
693  $this->ctrl->returnToParent($this);
694  break;
695  }
696  }
697 
704  private function setAccepted($a_status)
705  {
706  global $ilUser;
707 
708  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
709  if(!$this->privacy->confirmationRequired() and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId()))
710  {
711  return true;
712  }
713 
714  include_once('Modules/Course/classes/class.ilCourseAgreement.php');
715  $this->agreement = new ilCourseAgreement($ilUser->getId(),$this->container->getId());
716  $this->agreement->setAccepted($a_status);
717  $this->agreement->setAcceptanceTime(time());
718  $this->agreement->save();
719  }
720 
721 
722 
728  protected function initParticipants()
729  {
730  include_once('./Modules/Course/classes/class.ilCourseParticipants.php');
731  $this->participants = ilCourseParticipants::_getInstanceByObjId($this->obj_id);
732  }
733 
734 
739  protected function initWaitingList()
740  {
741  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
742  $this->waiting_list = new ilCourseWaitingList($this->container->getId());
743  }
744 
748  protected function isWaitingListActive()
749  {
750  global $ilUser;
751  static $active = null;
752 
753  if($active !== null)
754  {
755  return $active;
756  }
757  if(!$this->container->enabledWaitingList())
758  {
759  return $active = false;
760  }
761  if(!$this->container->getSubscriptionMaxMembers())
762  {
763  return $active = false;
764  }
765 
766  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
767  return $active = (!$free or $this->getWaitingList()->getCountUsers());
768  }
769 }
770 ?>