ILIAS  Release_5_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/Membership/classes/class.ilRegistrationGUI.php');
26 
38 {
39  private $parent_gui = null;
40 
47  public function __construct($a_container, $a_parent_gui)
48  {
49  parent::__construct($a_container);
50 
51  $this->parent_gui = $a_parent_gui;
52  }
53 
59  public function executeCommand()
60  {
61  global $ilTabs,$ilUser;
62 
63  if($this->getWaitingList()->isOnList($ilUser->getId()))
64  {
65  $ilTabs->activateTab('leave');
66  }
67 
68  if(!$GLOBALS['ilAccess']->checkAccess('join','',$this->getRefId()))
69  {
70  $this->ctrl->setReturn($this->parent_gui,'infoScreen');
71  $this->ctrl->returnToParent($this);
72  return FALSE;
73  }
74 
75  $next_class = $this->ctrl->getNextClass($this);
76  switch($next_class)
77  {
78  default:
79  $cmd = $this->ctrl->getCmd("show");
80  $this->$cmd();
81  break;
82  }
83  return true;
84  }
85 
92  protected function getFormTitle()
93  {
94  global $ilUser;
95 
96  if($this->getWaitingList()->isOnList($ilUser->getId()))
97  {
98  return $this->lng->txt('member_status');
99  }
100  return $this->lng->txt('crs_registration');
101  }
102 
110  protected function fillInformations()
111  {
112  if($this->container->getImportantInformation())
113  {
114  $imp = new ilNonEditableValueGUI($this->lng->txt('crs_important_info'), "", true);
115  $value = nl2br(ilUtil::makeClickable($this->container->getImportantInformation(), true));
116  $imp->setValue($value);
117  $this->form->addItem($imp);
118  }
119 
120  if($this->container->getSyllabus())
121  {
122  $syl = new ilNonEditableValueGUI($this->lng->txt('crs_syllabus'), "", true);
123  $value = nl2br(ilUtil::makeClickable ($this->container->getSyllabus(), true));
124  $syl->setValue($value);
125  $this->form->addItem($syl);
126  }
127  }
128 
134  protected function fillRegistrationPeriod()
135  {
136  include_once('./Services/Calendar/classes/class.ilDateTime.php');
137  $now = new ilDateTime(time(),IL_CAL_UNIX,'UTC');
138 
139  if($this->container->getSubscriptionUnlimitedStatus())
140  {
141  $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_period'));
142  $reg->setValue($this->lng->txt('mem_unlimited'));
143  $this->form->addItem($reg);
144  return true;
145  }
146  elseif($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
147  {
148  return true;
149  }
150 
151  $start = new ilDateTime($this->container->getSubscriptionStart(),IL_CAL_UNIX,'UTC');
152  $end = new ilDateTime($this->container->getSubscriptionEnd(),IL_CAL_UNIX,'UTC');
153 
154  if(ilDateTime::_before($now,$start))
155  {
156  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
157  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_start'));
158  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($start));
159 
160  $tpl->setVariable('TXT_END',$this->lng->txt('mem_end'));
161  $tpl->setVariable('END',ilDatePresentation::formatDate($end));
162 
163  $warning = $this->lng->txt('mem_reg_not_started');
164  }
165  elseif(ilDateTime::_after($now,$end))
166  {
167  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
168  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_start'));
169  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($start));
170 
171  $tpl->setVariable('TXT_END',$this->lng->txt('mem_end'));
172  $tpl->setVariable('END',ilDatePresentation::formatDate($end));
173 
174 
175  $warning = $this->lng->txt('mem_reg_expired');
176  }
177  else
178  {
179  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
180  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_end'));
181  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($end));
182  }
183 
184  $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
185  $reg->setHtml($tpl->get());
186  if(strlen($warning))
187  {
188  // Disable registration
189  $this->enableRegistration(false);
190  ilUtil::sendFailure($warning);
191  #$reg->setAlert($warning);
192  }
193  $this->form->addItem($reg);
194  return true;
195  }
196 
197 
205  protected function fillMaxMembers()
206  {
207  global $ilUser;
208 
209  if(!$this->container->isSubscriptionMembershipLimited())
210  {
211  return true;
212  }
213  $tpl = new ilTemplate('tpl.max_members_form.html',true,true,'Services/Membership');
214  $tpl->setVariable('TXT_MAX',$this->lng->txt('mem_max_users'));
215  $tpl->setVariable('NUM_MAX',$this->container->getSubscriptionMaxMembers());
216 
217  $tpl->setVariable('TXT_FREE',$this->lng->txt('mem_free_places').":");
218  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
219 
220  if($free)
221  $tpl->setVariable('NUM_FREE',$free);
222  else
223  $tpl->setVariable('WARN_FREE',$free);
224 
225 
226  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
227  $waiting_list = new ilCourseWaitingList($this->container->getId());
228  if(
229  $this->container->isSubscriptionMembershipLimited() and
230  $this->container->enabledWaitingList() and
231  (!$free or $waiting_list->getCountUsers()))
232  {
233  if($waiting_list->isOnList($ilUser->getId()))
234  {
235  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list_position'));
236  $tpl->setVariable('NUM_WAIT',$waiting_list->getPosition($ilUser->getId()));
237 
238  }
239  else
240  {
241  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list'));
242  if($free and $waiting_list->getCountUsers())
243  $tpl->setVariable('WARN_WAIT',$waiting_list->getCountUsers());
244  else
245  $tpl->setVariable('NUM_WAIT',$waiting_list->getCountUsers());
246  }
247  }
248 
249  $alert = '';
250  if(
251  !$free and
252  !$this->container->enabledWaitingList())
253  {
254  // Disable registration
255  $this->enableRegistration(false);
256  ilUtil::sendFailure($this->lng->txt('mem_alert_no_places'));
257  #$alert = $this->lng->txt('mem_alert_no_places');
258  }
259  elseif(
260  $this->container->enabledWaitingList() and
261  $this->container->isSubscriptionMembershipLimited() and
262  $waiting_list->isOnList($ilUser->getId())
263  )
264  {
265  // Disable registration
266  $this->enableRegistration(false);
267  }
268  elseif(
269  !$free and
270  $this->container->enabledWaitingList() and
271  $this->container->isSubscriptionMembershipLimited())
272 
273  {
274  ilUtil::sendFailure($this->lng->txt('crs_warn_no_max_set_on_waiting_list'));
275  #$alert = $this->lng->txt('crs_warn_no_max_set_on_waiting_list');
276  }
277  elseif(
278  $free and
279  $this->container->enabledWaitingList() and
280  $this->container->isSubscriptionMembershipLimited() and
281  $this->getWaitingList()->getCountUsers())
282  {
283  ilUtil::sendFailure($this->lng->txt('crs_warn_wl_set_on_waiting_list'));
284  #$alert = $this->lng->txt('crs_warn_wl_set_on_waiting_list');
285  }
286 
287  $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
288  $max->setHtml($tpl->get());
289  if(strlen($alert))
290  {
291  $max->setAlert($alert);
292  }
293  $this->form->addItem($max);
294  return true;
295  }
296 
303  protected function fillRegistrationType()
304  {
305  global $ilUser;
306 
307  if($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
308  {
309  $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_type'));
310  #$reg->setHtml($this->lng->txt('crs_info_reg_deactivated'));
311  $reg->setAlert($this->lng->txt('crs_info_reg_deactivated'));
312  #ilUtil::sendFailure($this->lng->txt('crs_info_reg_deactivated'));
313  #$reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
314  #$reg->setValue($this->lng->txt('crs_info_reg_deactivated'));
315  #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
316  $this->form->addItem($reg);
317 
318  // Disable registration
319  $this->enableRegistration(false);
320  return true;
321  }
322 
323  switch($this->container->getSubscriptionType())
324  {
326 
327  // no "request" info if waiting list is active
328  if($this->isWaitingListActive())
329  return true;
330 
331  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
332  $txt->setValue($this->lng->txt('crs_info_reg_direct'));
333 
334  $this->form->addItem($txt);
335  break;
336 
338  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
339  $txt->setValue($this->lng->txt('crs_subscription_options_password'));
340 
341 
342  $pass = new ilTextInputGUI($this->lng->txt('passwd'),'grp_passw');
343  $pass->setInputType('password');
344  $pass->setSize(12);
345  $pass->setMaxLength(32);
346  #$pass->setRequired(true);
347  $pass->setInfo($this->lng->txt('crs_info_reg_password'));
348 
349  $txt->addSubItem($pass);
350  $this->form->addItem($txt);
351  break;
352 
354 
355  // no "request" info if waiting list is active
356  if($this->isWaitingListActive())
357  return true;
358 
359  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
360  $txt->setValue($this->lng->txt('crs_subscription_options_confirmation'));
361 
362  $sub = new ilTextAreaInputGUI($this->lng->txt('crs_reg_subject'),'subject');
363  $sub->setValue($_POST['subject']);
364  $sub->setInfo($this->lng->txt('crs_info_reg_confirmation'));
365  $sub->setCols(40);
366  $sub->setRows(5);
367  if($this->participants->isSubscriber($ilUser->getId()))
368  {
369  $sub_data = $this->participants->getSubscriberData($ilUser->getId());
370  $sub->setValue($sub_data['subject']);
371  $sub->setInfo('');
372  ilUtil::sendFailure($this->lng->txt('crs_reg_user_already_subscribed'));
373  $this->enableRegistration(false);
374  }
375  $txt->addSubItem($sub);
376  $this->form->addItem($txt);
377  break;
378 
379 
380  default:
381  return true;
382  }
383 
384  return true;
385  }
386 
391  protected function addCommandButtons()
392  {
393  global $ilUser;
394 
396 
397 
398  switch($this->container->getSubscriptionType())
399  {
401  if($this->participants->isSubscriber($ilUser->getId()))
402  {
403  $this->form->clearCommandButtons();
404  $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('crs_update_subscr_request'));
405  $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('crs_cancel_subscr_request'));
406  }
407  elseif($this->isRegistrationPossible())
408  {
409  $this->form->clearCommandButtons();
410  $this->form->addCommandButton('join', $this->lng->txt('crs_join_request'));
411  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
412  }
413  break;
414  }
415  if(!$this->isRegistrationPossible())
416  {
417  return false;
418  }
419 
420  return true;
421  }
422 
430  protected function validate()
431  {
432  global $ilUser;
433 
434  if($ilUser->getId() == ANONYMOUS_USER_ID)
435  {
436  $this->join_error = $this->lng->txt('permission_denied');
437  return false;
438  }
439 
440  // Set aggrement to not accepted
441  $this->setAccepted(false);
442 
443  if(!$this->isRegistrationPossible())
444  {
445  $this->join_error = $this->lng->txt('mem_error_preconditions');
446  return false;
447  }
448  if($this->container->getSubscriptionType() == IL_CRS_SUBSCRIPTION_PASSWORD)
449  {
450  if(!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw'])))
451  {
452  $this->join_error = $this->lng->txt('crs_password_required');
453  return false;
454  }
455  if(strcmp($pass,$this->container->getSubscriptionPassword()) !== 0)
456  {
457  $this->join_error = $this->lng->txt('crs_password_not_valid');
458  return false;
459  }
460  }
461  if(!$this->validateCustomFields())
462  {
463  $this->join_error = $this->lng->txt('fill_out_all_required_fields');
464  return false;
465  }
466  if(!$this->validateAgreement())
467  {
468  $this->join_error = $this->lng->txt('crs_agreement_required');
469  return false;
470  }
471 
472  return true;
473  }
474 
482  protected function add()
483  {
484  global $ilUser,$tree, $ilCtrl;
485 
486  // TODO: language vars
487 
488  // set aggreement accepted
489  $this->setAccepted(true);
490 
491  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
492  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
493  $waiting_list = new ilCourseWaitingList($this->container->getId());
494  if($this->container->isSubscriptionMembershipLimited() and $this->container->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
495  {
496  $waiting_list->addToList($ilUser->getId());
497  $info = sprintf($this->lng->txt('crs_added_to_list'),
498  $waiting_list->getPosition($ilUser->getId()));
499  ilUtil::sendSuccess($info,true);
500 
501  $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST,$ilUser->getId());
502  $this->participants->sendNotification($this->participants->NOTIFY_WAITING_LIST,$ilUser->getId());
503  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
504  $tree->getParentId($this->container->getRefId()));
505  $ilCtrl->redirectByClass("ilrepositorygui", "");
506  }
507 
508  switch($this->container->getSubscriptionType())
509  {
511  $this->participants->addSubscriber($ilUser->getId());
512  $this->participants->updateSubscriptionTime($ilUser->getId(),time());
513  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['subject']));
514  $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST,$ilUser->getId());
515 
516  ilUtil::sendSuccess($this->lng->txt("application_completed"),true);
517  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
518  $tree->getParentId($this->container->getRefId()));
519  $ilCtrl->redirectByClass("ilrepositorygui", "");
520  break;
521 
522  default:
523 
524  if($this->container->isSubscriptionMembershipLimited() && $this->container->getSubscriptionMaxMembers())
525  {
526  $success = $GLOBALS['rbacadmin']->assignUserLimited(
527  ilParticipants::getDefaultMemberRole($this->container->getRefId()),
528  $ilUser->getId(),
529  $this->container->getSubscriptionMaxMembers(),
530  array(ilParticipants::getDefaultMemberRole($this->container->getRefId()))
531  );
532  if(!$success)
533  {
534  ilUtil::sendFailure($this->lng->txt('crs_subscription_failed_limit'));
535  $this->show();
536  return FALSE;
537  }
538  }
539 
540  $this->participants->add($ilUser->getId(),IL_CRS_MEMBER);
541  $this->participants->sendNotification($this->participants->NOTIFY_ADMINS,$ilUser->getId());
542  $this->participants->sendNotification($this->participants->NOTIFY_REGISTERED,$ilUser->getId());
543 
544  include_once './Modules/Forum/classes/class.ilForumNotification.php';
545  ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $ilUser->getId());
546 
547  if($this->container->getType() == "crs")
548  {
549  $this->container->checkLPStatusSync($ilUser->getId());
550  }
551 
552  if(!$_SESSION["pending_goto"])
553  {
554  ilUtil::sendSuccess($this->lng->txt("crs_subscription_successful"),true);
555  $this->ctrl->returnToParent($this);
556  }
557  else
558  {
559  $tgt = $_SESSION["pending_goto"];
560  unset($_SESSION["pending_goto"]);
561  ilUtil::redirect($tgt);
562  }
563  break;
564  }
565  }
566 
567 
568 
569 
575  protected function initParticipants()
576  {
577  include_once('./Modules/Course/classes/class.ilCourseParticipants.php');
578  $this->participants = ilCourseParticipants::_getInstanceByObjId($this->obj_id);
579  }
580 
581 
586  protected function initWaitingList()
587  {
588  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
589  $this->waiting_list = new ilCourseWaitingList($this->container->getId());
590  }
591 
595  protected function isWaitingListActive()
596  {
597  global $ilUser;
598  static $active = null;
599 
600  if($active !== null)
601  {
602  return $active;
603  }
604  if(!$this->container->enabledWaitingList() or !$this->container->isSubscriptionMembershipLimited())
605  {
606  return $active = false;
607  }
608  if(!$this->container->getSubscriptionMaxMembers())
609  {
610  return $active = false;
611  }
612 
613  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
614  return $active = (!$free or $this->getWaitingList()->getCountUsers());
615  }
616 }
617 ?>