ILIAS  Release_3_10_x_branch Revision 61812
 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  $next_class = $this->ctrl->getNextClass($this);
63  switch($next_class)
64  {
65  default:
66  $cmd = $this->ctrl->getCmd("show");
67  $this->$cmd();
68  break;
69  }
70  return true;
71  }
72 
79  protected function getFormTitle()
80  {
81  return $this->lng->txt('crs_registration');
82  }
83 
91  protected function fillInformations()
92  {
93  if($this->container->getImportantInformation())
94  {
95  $imp = new ilNonEditableValueGUI($this->lng->txt('crs_important_info'));
96  $value = nl2br(ilUtil::makeClickable($this->container->getImportantInformation(), true));
97  $imp->setValue($value);
98  $this->form->addItem($imp);
99  }
100 
101  if($this->container->getSyllabus())
102  {
103  $syl = new ilNonEditableValueGUI($this->lng->txt('crs_syllabus'));
104  $value = nl2br(ilUtil::makeClickable ($this->container->getSyllabus(), true));
105  $syl->setValue($value);
106  $this->form->addItem($syl);
107  }
108  }
109 
115  protected function fillRegistrationPeriod()
116  {
117  include_once('./Services/Calendar/classes/class.ilDateTime.php');
118  $now = new ilDateTime(time(),IL_CAL_UNIX,'UTC');
119 
120  if($this->container->getSubscriptionUnlimitedStatus())
121  {
122  $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_period'));
123  $reg->setValue($this->lng->txt('mem_unlimited'));
124  $this->form->addItem($reg);
125  return true;
126  }
127  elseif($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
128  {
129  return true;
130  }
131 
132  $start = new ilDateTime($this->container->getSubscriptionStart(),IL_CAL_UNIX,'UTC');
133  $end = new ilDateTime($this->container->getSubscriptionEnd(),IL_CAL_UNIX,'UTC');
134 
135  if(ilDateTime::_before($now,$start))
136  {
137  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
138  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_start'));
139  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($start));
140 
141  $tpl->setVariable('TXT_END',$this->lng->txt('mem_end'));
142  $tpl->setVariable('END',ilDatePresentation::formatDate($end));
143 
144  $warning = $this->lng->txt('mem_reg_not_started');
145  }
146  elseif(ilDateTime::_after($now,$end))
147  {
148  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
149  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_start'));
150  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($start));
151 
152  $tpl->setVariable('TXT_END',$this->lng->txt('mem_end'));
153  $tpl->setVariable('END',ilDatePresentation::formatDate($end));
154 
155 
156  $warning = $this->lng->txt('mem_reg_expired');
157  }
158  else
159  {
160  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
161  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_end'));
162  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($end));
163  }
164 
165  $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
166  $reg->setHtml($tpl->get());
167  if(strlen($warning))
168  {
169  // Disable registration
170  $this->enableRegistration(false);
171  $reg->setAlert($warning);
172  }
173  $this->form->addItem($reg);
174  return true;
175  }
176 
177 
185  protected function fillMaxMembers()
186  {
187  global $ilUser;
188 
189  if(!$this->container->isSubscriptionMembershipLimited())
190  {
191  return true;
192  }
193  $tpl = new ilTemplate('tpl.max_members_form.html',true,true,'Services/Membership');
194  $tpl->setVariable('TXT_MAX',$this->lng->txt('mem_max_users'));
195  $tpl->setVariable('NUM_MAX',$this->container->getSubscriptionMaxMembers());
196 
197  $tpl->setVariable('TXT_FREE',$this->lng->txt('mem_free_places').":");
198  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
199  $tpl->setVariable('NUM_FREE',$free);
200 
201  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
202  $waiting_list = new ilCourseWaitingList($this->container->getId());
203  if($this->container->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
204  {
205  if($waiting_list->isOnList($ilUser->getId()))
206  {
207  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list_position'));
208  $tpl->setVariable('NUM_WAIT',$waiting_list->getPosition($ilUser->getId()));
209 
210  }
211  else
212  {
213  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list'));
214  $tpl->setVariable('NUM_WAIT',$waiting_list->getCountUsers());
215  }
216  }
217 
218  $alert = '';
219  if(!$free and !$this->container->enabledWaitingList())
220  {
221  // Disable registration
222  $this->enableRegistration(false);
223  $alert = $this->lng->txt('mem_alert_no_places');
224  }
225  elseif($this->container->enabledWaitingList() and $waiting_list->isOnList($ilUser->getId()))
226  {
227  // Disable registration
228  $this->enableRegistration(false);
229  $alert = $this->lng->txt('mem_already_on_list');
230  }
231  elseif(!$free and $this->container->enabledWaitingList())
232  {
233  $alert = $this->lng->txt('crs_set_on_waiting_list');
234  }
235  elseif($waiting_list->getCountUsers() and $this->container->enabledWaitingList())
236  {
237  $alert = $this->lng->txt('crs_set_on_waiting_list');
238  }
239 
240  $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
241  $max->setHtml($tpl->get());
242  if(strlen($alert))
243  {
244  $max->setAlert($alert);
245  }
246  $this->form->addItem($max);
247  return true;
248  }
249 
256  protected function fillRegistrationType()
257  {
258  global $ilUser;
259 
260  if($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
261  {
262  $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_type'));
263  #$reg->setHtml($this->lng->txt('crs_info_reg_deactivated'));
264  $reg->setAlert($this->lng->txt('crs_info_reg_deactivated'));
265 
266  #$reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
267  #$reg->setValue($this->lng->txt('crs_info_reg_deactivated'));
268  #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
269  $this->form->addItem($reg);
270 
271  // Disable registration
272  $this->enableRegistration(false);
273  return true;
274  }
275 
276  switch($this->container->getSubscriptionType())
277  {
279  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
280  $txt->setValue($this->lng->txt('crs_info_reg_direct'));
281 
282  $this->form->addItem($txt);
283  break;
284 
286  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
287  $txt->setValue($this->lng->txt('crs_subscription_options_password'));
288 
289 
290  $pass = new ilTextInputGUI($this->lng->txt('passwd'),'grp_passw');
291  $pass->setInputType('password');
292  $pass->setSize(12);
293  $pass->setMaxLength(32);
294  #$pass->setRequired(true);
295  $pass->setInfo($this->lng->txt('crs_info_reg_password'));
296 
297  $txt->addSubItem($pass);
298  $this->form->addItem($txt);
299  break;
300 
302  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
303  $txt->setValue($this->lng->txt('crs_subscription_options_confirmation'));
304 
305  $sub = new ilTextAreaInputGUI($this->lng->txt('subject'),'grp_subject');
306  $sub->setValue($_POST['grp_subject']);
307  $sub->setInfo($this->lng->txt('crs_info_reg_confirmation'));
308  $sub->setCols(40);
309  $sub->setRows(5);
310  if($this->participants->isSubscriber($ilUser->getId()))
311  {
312  $sub->setAlert($this->lng->txt('crs_reg_user_already_subscribed'));
313  $this->enableRegistration(false);
314  }
315  $txt->addSubItem($sub);
316  $this->form->addItem($txt);
317  break;
318 
319 
320  default:
321  return true;
322  }
323 
324  return true;
325  }
326 
333  protected function fillAgreement()
334  {
335  global $ilUser;
336 
337  if(!$this->isRegistrationPossible())
338  {
339  return true;
340  }
341 
342 
343  $this->privacy = ilPrivacySettings::_getInstance();
344  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
345  if(!$this->privacy->confirmationRequired() and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId()))
346  {
347  return true;
348  }
349 
350  $this->lng->loadLanguageModule('ps');
351 
352  include_once('Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php');
353  $fields_info = ilExportFieldsInfo::_getInstance();
354 
355  if(!count($fields_info->getExportableFields()))
356  {
357  return true;
358  }
359 
361  $section->setTitle($this->lng->txt('usr_agreement'));
362  $this->form->addItem($section);
363 
364  $fields = new ilCustomInputGUI($this->lng->txt('crs_user_agreement'),'');
365  $tpl = new ilTemplate('tpl.agreement_form.html',true,true,'Services/Membership');
366  $tpl->setVariable('TXT_INFO_AGREEMENT',$this->lng->txt('crs_info_agreement'));
367  foreach($fields_info->getExportableFields() as $field)
368  {
369  $tpl->setCurrentBlock('field_item');
370  $tpl->setVariable('FIELD_NAME',$this->lng->txt($field));
371  $tpl->parseCurrentBlock();
372  }
373  $fields->setHtml($tpl->get());
374  $this->form->addItem($fields);
375 
376  $this->showCourseDefinedFields();
377 
378  // Checkbox agreement
379  $agreement = new ilCheckboxInputGUI($this->lng->txt('crs_agree'),'agreement');
380  $agreement->setRequired(true);
381  $agreement->setOptionTitle($this->lng->txt('crs_info_agree'));
382  $agreement->setValue(1);
383  $this->form->addItem($agreement);
384 
385 
386  return true;
387  }
388 
394  protected function showCourseDefinedFields()
395  {
396  global $ilUser;
397 
398  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
399  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
400 
401  if(!count($cdf_fields = ilCourseDefinedFieldDefinition::_getFields($this->container->getId())))
402  {
403  return true;
404  }
405 
406  $cdf = new ilNonEditableValueGUI($this->lng->txt('ps_crs_user_fields'));
407  $cdf->setValue($this->lng->txt('ps_cdf_info'));
408  $cdf->setRequired(true);
409 
410  foreach($cdf_fields as $field_obj)
411  {
412  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
413 
414  switch($field_obj->getType())
415  {
416  case IL_CDF_TYPE_SELECT:
417  $select = new ilSelectInputGUI($field_obj->getName(),'cdf['.$field_obj->getId().']');
418  $select->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
419  $select->setOptions($field_obj->prepareSelectBox());
420  if($field_obj->isRequired())
421  {
422  $select->setRequired(true);
423  }
424 
425  $cdf->addSubItem($select);
426 
427 
428  break;
429 
430  case IL_CDF_TYPE_TEXT:
431  $text = new ilTextInputGUI($field_obj->getName(),'cdf['.$field_obj->getId().']');
432  $text->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
433  $text->setSize(32);
434  $text->setMaxLength(255);
435  if($field_obj->isRequired())
436  {
437  $text->setRequired(true);
438  }
439  $cdf->addSubItem($text);
440  break;
441  }
442  }
443  $this->form->addItem($cdf);
444  return true;
445  }
446 
447 
448 
456  protected function validate()
457  {
458  global $ilUser;
459 
460  if($ilUser->getId() == ANONYMOUS_USER_ID)
461  {
462  $this->join_error = $this->lng->txt('permission_denied');
463  return false;
464  }
465 
466  // Set aggrement to not accepted
467  $this->setAccepted(false);
468 
469  if(!$this->isRegistrationPossible())
470  {
471  $this->join_error = $this->lng->txt('mem_error_preconditions');
472  return false;
473  }
474  if($this->container->getSubscriptionType() == IL_CRS_SUBSCRIPTION_PASSWORD)
475  {
476  if(!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw'])))
477  {
478  $this->join_error = $this->lng->txt('crs_password_required');
479  return false;
480  }
481  if(strcmp($pass,$this->container->getSubscriptionPassword()) !== 0)
482  {
483  $this->join_error = $this->lng->txt('crs_password_not_valid');
484  return false;
485  }
486  }
487  if(!$this->validateCourseDefinedFields())
488  {
489  $this->join_error = $this->lng->txt('fill_out_all_required_fields');
490  return false;
491  }
492  if(!$this->validateAgreement())
493  {
494  $this->join_error = $this->lng->txt('crs_agreement_required');
495  return false;
496  }
497 
498  return true;
499  }
500 
507  private function validateAgreement()
508  {
509  global $ilUser;
510 
511  if($_POST['agreement'])
512  {
513  return true;
514  }
515  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
516  if(!$this->privacy->confirmationRequired() and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId()))
517  {
518  return true;
519  }
520  return false;
521  }
522 
529  private function validateCourseDefinedFields()
530  {
531  global $ilUser;
532 
533  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
534  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
535 
536  $all_required = true;
537  foreach(ilCourseDefinedFieldDefinition::_getFields($this->container->getId()) as $field_obj)
538  {
539  switch($field_obj->getType())
540  {
541  case IL_CDF_TYPE_SELECT:
542  $value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
543  break;
544 
545  case IL_CDF_TYPE_TEXT:
546  $value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
547  break;
548  }
549  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
550  $course_user_data->setValue($value);
551  $course_user_data->update();
552 
553  if($field_obj->isRequired() and (!strlen($value) or $value == -1))
554  {
555  $all_required = false;
556  }
557  }
558  return $all_required;
559  }
560 
561 
562 
570  protected function add()
571  {
572  global $ilUser,$tree;
573 
574  // TODO: language vars
575 
576  // set aggreement accepted
577  $this->setAccepted(true);
578 
579  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
580  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
581  $waiting_list = new ilCourseWaitingList($this->container->getId());
582  if($this->container->isSubscriptionMembershipLimited() and $this->container->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
583  {
584  $waiting_list->addToList($ilUser->getId());
585  $info = sprintf($this->lng->txt('crs_added_to_list'),$waiting_list->getPosition($ilUser->getId()));
586  $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST,$ilUser->getId());
587  ilUtil::sendInfo($info,true);
588  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
589  }
590 
591  switch($this->container->getSubscriptionType())
592  {
594  $this->participants->addSubscriber($ilUser->getId());
595  $this->participants->updateSubscriptionTime($ilUser->getId(),time());
596  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['grp_subject']));
597  $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST,$ilUser->getId());
598 
599  ilUtil::sendInfo($this->lng->txt("application_completed"),true);
600  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
601  break;
602 
603  default:
604  $this->participants->add($ilUser->getId(),IL_CRS_MEMBER);
605  $this->participants->sendNotification($this->participants->NOTIFY_ADMINS,$ilUser->getId());
606  ilUtil::sendInfo($this->lng->txt("crs_subscription_successful"),true);
607  $this->ctrl->returnToParent($this);
608  break;
609  }
610  }
611 
618  private function setAccepted($a_status)
619  {
620  global $ilUser;
621 
622  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
623  if(!$this->privacy->confirmationRequired() and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId()))
624  {
625  return true;
626  }
627 
628  include_once('Modules/Course/classes/class.ilCourseAgreement.php');
629  $this->agreement = new ilCourseAgreement($ilUser->getId(),$this->container->getId());
630  $this->agreement->setAccepted($a_status);
631  $this->agreement->setAcceptanceTime(time());
632  $this->agreement->save();
633  }
634 
635 
636 
642  protected function initParticipants()
643  {
644  include_once('./Modules/Course/classes/class.ilCourseParticipants.php');
645  $this->participants = ilCourseParticipants::_getInstanceByObjId($this->obj_id);
646  }
647 }
648 ?>