ILIAS  Release_4_2_x_branch Revision 61807
 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  $next_class = $this->ctrl->getNextClass($this);
65  switch($next_class)
66  {
67  default:
68  $cmd = $this->ctrl->getCmd("show");
69  $this->$cmd();
70  break;
71  }
72  return true;
73  }
74 
81  protected function getFormTitle()
82  {
83  global $ilUser;
84 
85  if($this->getWaitingList()->isOnList($ilUser->getId()))
86  {
87  return $this->lng->txt('member_status');
88  }
89  return $this->lng->txt('crs_registration');
90  }
91 
99  protected function fillInformations()
100  {
101  if($this->container->getImportantInformation())
102  {
103  $imp = new ilNonEditableValueGUI($this->lng->txt('crs_important_info'), "", true);
104  $value = nl2br(ilUtil::makeClickable($this->container->getImportantInformation(), true));
105  $imp->setValue($value);
106  $this->form->addItem($imp);
107  }
108 
109  if($this->container->getSyllabus())
110  {
111  $syl = new ilNonEditableValueGUI($this->lng->txt('crs_syllabus'), "", true);
112  $value = nl2br(ilUtil::makeClickable ($this->container->getSyllabus(), true));
113  $syl->setValue($value);
114  $this->form->addItem($syl);
115  }
116  }
117 
123  protected function fillRegistrationPeriod()
124  {
125  include_once('./Services/Calendar/classes/class.ilDateTime.php');
126  $now = new ilDateTime(time(),IL_CAL_UNIX,'UTC');
127 
128  if($this->container->getSubscriptionUnlimitedStatus())
129  {
130  $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_period'));
131  $reg->setValue($this->lng->txt('mem_unlimited'));
132  $this->form->addItem($reg);
133  return true;
134  }
135  elseif($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
136  {
137  return true;
138  }
139 
140  $start = new ilDateTime($this->container->getSubscriptionStart(),IL_CAL_UNIX,'UTC');
141  $end = new ilDateTime($this->container->getSubscriptionEnd(),IL_CAL_UNIX,'UTC');
142 
143  if(ilDateTime::_before($now,$start))
144  {
145  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
146  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_start'));
147  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($start));
148 
149  $tpl->setVariable('TXT_END',$this->lng->txt('mem_end'));
150  $tpl->setVariable('END',ilDatePresentation::formatDate($end));
151 
152  $warning = $this->lng->txt('mem_reg_not_started');
153  }
154  elseif(ilDateTime::_after($now,$end))
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 
164  $warning = $this->lng->txt('mem_reg_expired');
165  }
166  else
167  {
168  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
169  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_end'));
170  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($end));
171  }
172 
173  $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
174  $reg->setHtml($tpl->get());
175  if(strlen($warning))
176  {
177  // Disable registration
178  $this->enableRegistration(false);
179  ilUtil::sendFailure($warning);
180  #$reg->setAlert($warning);
181  }
182  $this->form->addItem($reg);
183  return true;
184  }
185 
186 
194  protected function fillMaxMembers()
195  {
196  global $ilUser;
197 
198  if(!$this->container->isSubscriptionMembershipLimited())
199  {
200  return true;
201  }
202  $tpl = new ilTemplate('tpl.max_members_form.html',true,true,'Services/Membership');
203  $tpl->setVariable('TXT_MAX',$this->lng->txt('mem_max_users'));
204  $tpl->setVariable('NUM_MAX',$this->container->getSubscriptionMaxMembers());
205 
206  $tpl->setVariable('TXT_FREE',$this->lng->txt('mem_free_places').":");
207  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
208 
209  if($free)
210  $tpl->setVariable('NUM_FREE',$free);
211  else
212  $tpl->setVariable('WARN_FREE',$free);
213 
214 
215  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
216  $waiting_list = new ilCourseWaitingList($this->container->getId());
217  if(
218  $this->container->isSubscriptionMembershipLimited() and
219  $this->container->enabledWaitingList() and
220  (!$free or $waiting_list->getCountUsers()))
221  {
222  if($waiting_list->isOnList($ilUser->getId()))
223  {
224  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list_position'));
225  $tpl->setVariable('NUM_WAIT',$waiting_list->getPosition($ilUser->getId()));
226 
227  }
228  else
229  {
230  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list'));
231  if($free and $waiting_list->getCountUsers())
232  $tpl->setVariable('WARN_WAIT',$waiting_list->getCountUsers());
233  else
234  $tpl->setVariable('NUM_WAIT',$waiting_list->getCountUsers());
235  }
236  }
237 
238  $alert = '';
239  if(
240  !$free and
241  !$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(
249  $this->container->enabledWaitingList() and
250  $this->container->isSubscriptionMembershipLimited() and
251  $waiting_list->isOnList($ilUser->getId())
252  )
253  {
254  // Disable registration
255  $this->enableRegistration(false);
256  }
257  elseif(
258  !$free and
259  $this->container->enabledWaitingList() and
260  $this->container->isSubscriptionMembershipLimited())
261 
262  {
263  ilUtil::sendFailure($this->lng->txt('crs_warn_no_max_set_on_waiting_list'));
264  #$alert = $this->lng->txt('crs_warn_no_max_set_on_waiting_list');
265  }
266  elseif(
267  $free and
268  $this->container->enabledWaitingList() and
269  $this->container->isSubscriptionMembershipLimited() and
270  $this->getWaitingList()->getCountUsers())
271  {
272  ilUtil::sendFailure($this->lng->txt('crs_warn_wl_set_on_waiting_list'));
273  #$alert = $this->lng->txt('crs_warn_wl_set_on_waiting_list');
274  }
275 
276  $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
277  $max->setHtml($tpl->get());
278  if(strlen($alert))
279  {
280  $max->setAlert($alert);
281  }
282  $this->form->addItem($max);
283  return true;
284  }
285 
292  protected function fillRegistrationType()
293  {
294  global $ilUser;
295 
296  if($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
297  {
298  $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_type'));
299  #$reg->setHtml($this->lng->txt('crs_info_reg_deactivated'));
300  $reg->setAlert($this->lng->txt('crs_info_reg_deactivated'));
301  #ilUtil::sendFailure($this->lng->txt('crs_info_reg_deactivated'));
302  #$reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
303  #$reg->setValue($this->lng->txt('crs_info_reg_deactivated'));
304  #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
305  $this->form->addItem($reg);
306 
307  // Disable registration
308  $this->enableRegistration(false);
309  return true;
310  }
311 
312  switch($this->container->getSubscriptionType())
313  {
315 
316  // no "request" info if waiting list is active
317  if($this->isWaitingListActive())
318  return true;
319 
320  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
321  $txt->setValue($this->lng->txt('crs_info_reg_direct'));
322 
323  $this->form->addItem($txt);
324  break;
325 
327  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
328  $txt->setValue($this->lng->txt('crs_subscription_options_password'));
329 
330 
331  $pass = new ilTextInputGUI($this->lng->txt('passwd'),'grp_passw');
332  $pass->setInputType('password');
333  $pass->setSize(12);
334  $pass->setMaxLength(32);
335  #$pass->setRequired(true);
336  $pass->setInfo($this->lng->txt('crs_info_reg_password'));
337 
338  $txt->addSubItem($pass);
339  $this->form->addItem($txt);
340  break;
341 
343 
344  // no "request" info if waiting list is active
345  if($this->isWaitingListActive())
346  return true;
347 
348  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
349  $txt->setValue($this->lng->txt('crs_subscription_options_confirmation'));
350 
351  $sub = new ilTextAreaInputGUI($this->lng->txt('crs_reg_subject'),'subject');
352  $sub->setValue($_POST['subject']);
353  $sub->setInfo($this->lng->txt('crs_info_reg_confirmation'));
354  $sub->setCols(40);
355  $sub->setRows(5);
356  if($this->participants->isSubscriber($ilUser->getId()))
357  {
358  $sub_data = $this->participants->getSubscriberData($ilUser->getId());
359  $sub->setValue($sub_data['subject']);
360  $sub->setInfo('');
361  ilUtil::sendFailure($this->lng->txt('crs_reg_user_already_subscribed'));
362  $this->enableRegistration(false);
363  }
364  $txt->addSubItem($sub);
365  $this->form->addItem($txt);
366  break;
367 
368 
369  default:
370  return true;
371  }
372 
373  return true;
374  }
375 
380  protected function addCommandButtons()
381  {
382  global $ilUser;
383 
385 
386 
387  switch($this->container->getSubscriptionType())
388  {
390  if($this->participants->isSubscriber($ilUser->getId()))
391  {
392  $this->form->clearCommandButtons();
393  $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('crs_update_subscr_request'));
394  $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('crs_cancel_subscr_request'));
395  }
396  elseif($this->isRegistrationPossible())
397  {
398  $this->form->clearCommandButtons();
399  $this->form->addCommandButton('join', $this->lng->txt('crs_join_request'));
400  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
401  }
402  break;
403  }
404  if(!$this->isRegistrationPossible())
405  {
406  return false;
407  }
408 
409  return true;
410  }
411 
419  protected function validate()
420  {
421  global $ilUser;
422 
423  if($ilUser->getId() == ANONYMOUS_USER_ID)
424  {
425  $this->join_error = $this->lng->txt('permission_denied');
426  return false;
427  }
428 
429  // Set aggrement to not accepted
430  $this->setAccepted(false);
431 
432  if(!$this->isRegistrationPossible())
433  {
434  $this->join_error = $this->lng->txt('mem_error_preconditions');
435  return false;
436  }
437  if($this->container->getSubscriptionType() == IL_CRS_SUBSCRIPTION_PASSWORD)
438  {
439  if(!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw'])))
440  {
441  $this->join_error = $this->lng->txt('crs_password_required');
442  return false;
443  }
444  if(strcmp($pass,$this->container->getSubscriptionPassword()) !== 0)
445  {
446  $this->join_error = $this->lng->txt('crs_password_not_valid');
447  return false;
448  }
449  }
450  if(!$this->validateCustomFields())
451  {
452  $this->join_error = $this->lng->txt('fill_out_all_required_fields');
453  return false;
454  }
455  if(!$this->validateAgreement())
456  {
457  $this->join_error = $this->lng->txt('crs_agreement_required');
458  return false;
459  }
460 
461  return true;
462  }
463 
471  protected function add()
472  {
473  global $ilUser,$tree;
474 
475  // TODO: language vars
476 
477  // set aggreement accepted
478  $this->setAccepted(true);
479 
480  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
481  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
482  $waiting_list = new ilCourseWaitingList($this->container->getId());
483  if($this->container->isSubscriptionMembershipLimited() and $this->container->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
484  {
485  $waiting_list->addToList($ilUser->getId());
486  $info = sprintf($this->lng->txt('crs_added_to_list'),
487  $waiting_list->getPosition($ilUser->getId()));
488  ilUtil::sendSuccess($info,true);
489 
490  $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST,$ilUser->getId());
491  $this->participants->sendNotification($this->participants->NOTIFY_WAITING_LIST,$ilUser->getId());
492  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
493  }
494 
495  switch($this->container->getSubscriptionType())
496  {
498  $this->participants->addSubscriber($ilUser->getId());
499  $this->participants->updateSubscriptionTime($ilUser->getId(),time());
500  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['subject']));
501  $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST,$ilUser->getId());
502 
503  ilUtil::sendSuccess($this->lng->txt("application_completed"),true);
504  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
505  break;
506 
507  default:
508  $this->participants->add($ilUser->getId(),IL_CRS_MEMBER);
509  $this->participants->sendNotification($this->participants->NOTIFY_ADMINS,$ilUser->getId());
510  $this->participants->sendNotification($this->participants->NOTIFY_REGISTERED,$ilUser->getId());
511 
512  include_once './Modules/Forum/classes/class.ilForumNotification.php';
513  ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $ilUser->getId());
514 
515  ilUtil::sendSuccess($this->lng->txt("crs_subscription_successful"),true);
516  $this->ctrl->returnToParent($this);
517  break;
518  }
519  }
520 
521 
522 
523 
529  protected function initParticipants()
530  {
531  include_once('./Modules/Course/classes/class.ilCourseParticipants.php');
532  $this->participants = ilCourseParticipants::_getInstanceByObjId($this->obj_id);
533  }
534 
535 
540  protected function initWaitingList()
541  {
542  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
543  $this->waiting_list = new ilCourseWaitingList($this->container->getId());
544  }
545 
549  protected function isWaitingListActive()
550  {
551  global $ilUser;
552  static $active = null;
553 
554  if($active !== null)
555  {
556  return $active;
557  }
558  if(!$this->container->enabledWaitingList() or !$this->container->isSubscriptionMembershipLimited())
559  {
560  return $active = false;
561  }
562  if(!$this->container->getSubscriptionMaxMembers())
563  {
564  return $active = false;
565  }
566 
567  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
568  return $active = (!$free or $this->getWaitingList()->getCountUsers());
569  }
570 }
571 ?>