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