ILIAS  Release_4_1_x_branch Revision 61804
 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'));
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'));
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($this->container->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
218  {
219  if($waiting_list->isOnList($ilUser->getId()))
220  {
221  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list_position'));
222  $tpl->setVariable('NUM_WAIT',$waiting_list->getPosition($ilUser->getId()));
223 
224  }
225  else
226  {
227  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list'));
228  if($free and $waiting_list->getCountUsers())
229  $tpl->setVariable('WARN_WAIT',$waiting_list->getCountUsers());
230  else
231  $tpl->setVariable('NUM_WAIT',$waiting_list->getCountUsers());
232  }
233  }
234 
235  $alert = '';
236  if(!$free and !$this->container->enabledWaitingList())
237  {
238  // Disable registration
239  $this->enableRegistration(false);
240  ilUtil::sendFailure($this->lng->txt('mem_alert_no_places'));
241  #$alert = $this->lng->txt('mem_alert_no_places');
242  }
243  elseif($this->container->enabledWaitingList() and $waiting_list->isOnList($ilUser->getId()))
244  {
245  // Disable registration
246  $this->enableRegistration(false);
247  }
248  elseif(!$free and $this->container->enabledWaitingList())
249  {
250  ilUtil::sendFailure($this->lng->txt('crs_warn_no_max_set_on_waiting_list'));
251  #$alert = $this->lng->txt('crs_warn_no_max_set_on_waiting_list');
252  }
253  elseif($free and $this->container->enabledWaitingList() and $this->getWaitingList()->getCountUsers())
254  {
255  ilUtil::sendFailure($this->lng->txt('crs_warn_wl_set_on_waiting_list'));
256  #$alert = $this->lng->txt('crs_warn_wl_set_on_waiting_list');
257  }
258 
259  $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
260  $max->setHtml($tpl->get());
261  if(strlen($alert))
262  {
263  $max->setAlert($alert);
264  }
265  $this->form->addItem($max);
266  return true;
267  }
268 
275  protected function fillRegistrationType()
276  {
277  global $ilUser;
278 
279  if($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
280  {
281  $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_type'));
282  #$reg->setHtml($this->lng->txt('crs_info_reg_deactivated'));
283  $reg->setAlert($this->lng->txt('crs_info_reg_deactivated'));
284  #ilUtil::sendFailure($this->lng->txt('crs_info_reg_deactivated'));
285  #$reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
286  #$reg->setValue($this->lng->txt('crs_info_reg_deactivated'));
287  #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
288  $this->form->addItem($reg);
289 
290  // Disable registration
291  $this->enableRegistration(false);
292  return true;
293  }
294 
295  switch($this->container->getSubscriptionType())
296  {
298 
299  // no "request" info if waiting list is active
300  if($this->isWaitingListActive())
301  return true;
302 
303  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
304  $txt->setValue($this->lng->txt('crs_info_reg_direct'));
305 
306  $this->form->addItem($txt);
307  break;
308 
310  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
311  $txt->setValue($this->lng->txt('crs_subscription_options_password'));
312 
313 
314  $pass = new ilTextInputGUI($this->lng->txt('passwd'),'grp_passw');
315  $pass->setInputType('password');
316  $pass->setSize(12);
317  $pass->setMaxLength(32);
318  #$pass->setRequired(true);
319  $pass->setInfo($this->lng->txt('crs_info_reg_password'));
320 
321  $txt->addSubItem($pass);
322  $this->form->addItem($txt);
323  break;
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_subscription_options_confirmation'));
333 
334  $sub = new ilTextAreaInputGUI($this->lng->txt('crs_reg_subject'),'subject');
335  $sub->setValue($_POST['subject']);
336  $sub->setInfo($this->lng->txt('crs_info_reg_confirmation'));
337  $sub->setCols(40);
338  $sub->setRows(5);
339  if($this->participants->isSubscriber($ilUser->getId()))
340  {
341  $sub_data = $this->participants->getSubscriberData($ilUser->getId());
342  $sub->setValue($sub_data['subject']);
343  $sub->setInfo('');
344  ilUtil::sendFailure($this->lng->txt('crs_reg_user_already_subscribed'));
345  $this->enableRegistration(false);
346  }
347  $txt->addSubItem($sub);
348  $this->form->addItem($txt);
349  break;
350 
351 
352  default:
353  return true;
354  }
355 
356  return true;
357  }
358 
363  protected function addCommandButtons()
364  {
365  global $ilUser;
366 
368 
369  if(!$this->isRegistrationPossible())
370  {
371  return false;
372  }
373 
374  switch($this->container->getSubscriptionType())
375  {
377  if($this->participants->isSubscriber($ilUser->getId()))
378  {
379  $this->form->clearCommandButtons();
380  $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('crs_update_subscr_request'));
381  $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('crs_cancel_subscr_request'));
382  }
383  else
384  {
385  $this->form->clearCommandButtons();
386  $this->form->addCommandButton('join', $this->lng->txt('crs_join_request'));
387  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
388  }
389  break;
390  }
391  return true;
392  }
393 
401  protected function validate()
402  {
403  global $ilUser;
404 
405  if($ilUser->getId() == ANONYMOUS_USER_ID)
406  {
407  $this->join_error = $this->lng->txt('permission_denied');
408  return false;
409  }
410 
411  // Set aggrement to not accepted
412  $this->setAccepted(false);
413 
414  if(!$this->isRegistrationPossible())
415  {
416  $this->join_error = $this->lng->txt('mem_error_preconditions');
417  return false;
418  }
419  if($this->container->getSubscriptionType() == IL_CRS_SUBSCRIPTION_PASSWORD)
420  {
421  if(!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw'])))
422  {
423  $this->join_error = $this->lng->txt('crs_password_required');
424  return false;
425  }
426  if(strcmp($pass,$this->container->getSubscriptionPassword()) !== 0)
427  {
428  $this->join_error = $this->lng->txt('crs_password_not_valid');
429  return false;
430  }
431  }
432  if(!$this->validateCustomFields())
433  {
434  $this->join_error = $this->lng->txt('fill_out_all_required_fields');
435  return false;
436  }
437  if(!$this->validateAgreement())
438  {
439  $this->join_error = $this->lng->txt('crs_agreement_required');
440  return false;
441  }
442 
443  return true;
444  }
445 
453  protected function add()
454  {
455  global $ilUser,$tree;
456 
457  // TODO: language vars
458 
459  // set aggreement accepted
460  $this->setAccepted(true);
461 
462  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
463  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
464  $waiting_list = new ilCourseWaitingList($this->container->getId());
465  if($this->container->isSubscriptionMembershipLimited() and $this->container->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
466  {
467  $waiting_list->addToList($ilUser->getId());
468  $info = sprintf($this->lng->txt('crs_added_to_list'),
469  $waiting_list->getPosition($ilUser->getId()));
470  ilUtil::sendSuccess($info,true);
471 
472  $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST,$ilUser->getId());
473  $this->participants->sendNotification($this->participants->NOTIFY_WAITING_LIST,$ilUser->getId());
474  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
475  }
476 
477  switch($this->container->getSubscriptionType())
478  {
480  $this->participants->addSubscriber($ilUser->getId());
481  $this->participants->updateSubscriptionTime($ilUser->getId(),time());
482  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['subject']));
483  $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST,$ilUser->getId());
484 
485  ilUtil::sendSuccess($this->lng->txt("application_completed"),true);
486  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
487  break;
488 
489  default:
490  $this->participants->add($ilUser->getId(),IL_CRS_MEMBER);
491  $this->participants->sendNotification($this->participants->NOTIFY_ADMINS,$ilUser->getId());
492  $this->participants->sendNotification($this->participants->NOTIFY_REGISTERED,$ilUser->getId());
493 
494  include_once './Modules/Forum/classes/class.ilForumNotification.php';
495  ilForumNotification::checkForumsExistsInsert($this->container->getRefId(). $ilUser->getId());
496 
497  ilUtil::sendSuccess($this->lng->txt("crs_subscription_successful"),true);
498  $this->ctrl->returnToParent($this);
499  break;
500  }
501  }
502 
503 
504 
505 
511  protected function initParticipants()
512  {
513  include_once('./Modules/Course/classes/class.ilCourseParticipants.php');
514  $this->participants = ilCourseParticipants::_getInstanceByObjId($this->obj_id);
515  }
516 
517 
522  protected function initWaitingList()
523  {
524  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
525  $this->waiting_list = new ilCourseWaitingList($this->container->getId());
526  }
527 
531  protected function isWaitingListActive()
532  {
533  global $ilUser;
534  static $active = null;
535 
536  if($active !== null)
537  {
538  return $active;
539  }
540  if(!$this->container->enabledWaitingList())
541  {
542  return $active = false;
543  }
544  if(!$this->container->getSubscriptionMaxMembers())
545  {
546  return $active = false;
547  }
548 
549  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
550  return $active = (!$free or $this->getWaitingList()->getCountUsers());
551  }
552 }
553 ?>