ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilGroupRegistrationGUI.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 include_once('./Services/Membership/classes/class.ilRegistrationGUI.php');
25 include_once './Modules/Group/classes/class.ilGroupMembershipMailNotification.php';
26 
37 {
44  public function __construct($a_container)
45  {
46  parent::__construct($a_container);
47  }
48 
54  public function executeCommand()
55  {
56  global $ilUser,$ilTabs;
57 
58  $next_class = $this->ctrl->getNextClass($this);
59 
60  if($this->getWaitingList()->isOnList($ilUser->getId()))
61  {
62  $ilTabs->activateTab('leave');
63  }
64 
65  switch($next_class)
66  {
67  default:
68  $cmd = $this->ctrl->getCmd("show");
69  $this->$cmd();
70  break;
71  }
72  return true;
73  }
74 
75 
82  protected function getFormTitle()
83  {
84  global $ilUser;
85 
86  if($this->getWaitingList()->isOnList($ilUser->getId()))
87  {
88  return $this->lng->txt('member_status');
89  }
90  return $this->lng->txt('grp_registration');
91  }
92 
100  protected function fillInformations()
101  {
102  if($this->container->getInformation())
103  {
104  $imp = new ilNonEditableValueGUI($this->lng->txt('crs_important_info'),'',true);
105  $value = nl2br(ilUtil::makeClickable($this->container->getInformation(), true));
106  $imp->setValue($value);
107  $this->form->addItem($imp);
108  }
109  }
110 
116  protected function fillRegistrationPeriod()
117  {
118  include_once('./Services/Calendar/classes/class.ilDateTime.php');
119  $now = new ilDateTime(time(),IL_CAL_UNIX,'UTC');
120 
121  if($this->container->isRegistrationUnlimited())
122  {
123  $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_period'));
124  $reg->setValue($this->lng->txt('mem_unlimited'));
125  $this->form->addItem($reg);
126  return true;
127  }
128 
129  $start = $this->container->getRegistrationStart();
130  $end = $this->container->getRegistrationEnd();
131 
132 
133  if(ilDateTime::_before($now,$start))
134  {
135  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
136  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_start'));
137  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($start));
138 
139  $tpl->setVariable('TXT_END',$this->lng->txt('mem_end'));
140  $tpl->setVariable('END',ilDatePresentation::formatDate($end));
141 
142  $warning = $this->lng->txt('mem_reg_not_started');
143  }
144  elseif(ilDateTime::_after($now,$end))
145  {
146  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
147  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_start'));
148  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($start));
149 
150  $tpl->setVariable('TXT_END',$this->lng->txt('mem_end'));
151  $tpl->setVariable('END',ilDatePresentation::formatDate($end));
152 
153  $warning = $this->lng->txt('mem_reg_expired');
154  }
155  else
156  {
157  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
158  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_end'));
159  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($end));
160  }
161 
162  $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
163  $reg->setHtml($tpl->get());
164  if(strlen($warning))
165  {
166  // Disable registration
167  $this->enableRegistration(false);
168  #$reg->setAlert($warning);
169  ilUtil::sendFailure($warning);
170  }
171  $this->form->addItem($reg);
172  return true;
173  }
174 
181  protected function fillMaxMembers()
182  {
183  global $ilUser;
184 
185  if(!$this->container->isMembershipLimited())
186  {
187  return true;
188  }
189  $tpl = new ilTemplate('tpl.max_members_form.html',true,true,'Services/Membership');
190  $tpl->setVariable('TXT_MAX',$this->lng->txt('mem_max_users'));
191  $tpl->setVariable('NUM_MAX',$this->container->getMaxMembers());
192 
193  $tpl->setVariable('TXT_FREE',$this->lng->txt('mem_free_places').":");
194  $free = max(0,$this->container->getMaxMembers() - $this->participants->getCountMembers());
195 
196  if($free)
197  $tpl->setVariable('NUM_FREE',$free);
198  else
199  $tpl->setVariable('WARN_FREE',$free);
200 
201 
202  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
203  $waiting_list = new ilGroupWaitingList($this->container->getId());
204 
205  if(
206  $this->container->isWaitingListEnabled() and
207  $this->container->isMembershipLimited() and
208  (!$free or $waiting_list->getCountUsers()))
209  {
210  if($waiting_list->isOnList($ilUser->getId()))
211  {
212  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list_position'));
213  $tpl->setVariable('NUM_WAIT',$waiting_list->getPosition($ilUser->getId()));
214 
215  }
216  else
217  {
218  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list'));
219  if($free and $waiting_list->getCountUsers())
220  $tpl->setVariable('WARN_WAIT',$waiting_list->getCountUsers());
221  else
222  $tpl->setVariable('NUM_WAIT',$waiting_list->getCountUsers());
223 
224  }
225  }
226 
227  $alert = '';
228  if(
229  !$free and
230  !$this->container->isWaitingListEnabled())
231  {
232  // Disable registration
233  $this->enableRegistration(false);
234  $alert = $this->lng->txt('mem_alert_no_places');
235  }
236  elseif(
237  $this->container->isWaitingListEnabled() and
238  $this->container->isMembershipLimited() and
239  $waiting_list->isOnList($ilUser->getId()))
240  {
241  // Disable registration
242  $this->enableRegistration(false);
243  }
244  elseif(
245  !$free and
246  $this->container->isWaitingListEnabled() and
247  $this->container->isMembershipLimited())
248  {
249  $alert = $this->lng->txt('grp_warn_no_max_set_on_waiting_list');
250  }
251  elseif(
252  $free and
253  $this->container->isWaitingListEnabled() and
254  $this->container->isMembershipLimited() and
255  $this->getWaitingList()->getCountUsers())
256  {
257  $alert = $this->lng->txt('grp_warn_wl_set_on_waiting_list');
258  }
259 
260  $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
261  $max->setHtml($tpl->get());
262  if(strlen($alert))
263  {
264  #$max->setAlert($alert);
265  ilUtil::sendFailure($alert);
266  }
267  $this->form->addItem($max);
268  }
269 
277  protected function fillRegistrationType()
278  {
279  global $ilUser;
280 
281  if($this->getWaitingList()->isOnList($ilUser->getId()))
282  {
283  return true;
284  }
285 
286  switch($this->container->getRegistrationType())
287  {
289  $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
290  $reg->setValue($this->lng->txt('grp_reg_disabled'));
291  #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
292  $this->form->addItem($reg);
293 
294  // Disable registration
295  $this->enableRegistration(false);
296 
297  break;
298 
300  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
301  $txt->setValue($this->lng->txt('grp_pass_request'));
302 
303 
304  $pass = new ilTextInputGUI($this->lng->txt('passwd'),'grp_passw');
305  $pass->setInputType('password');
306  $pass->setSize(12);
307  $pass->setMaxLength(32);
308  #$pass->setRequired(true);
309  $pass->setInfo($this->lng->txt('group_password_registration_msg'));
310 
311  $txt->addSubItem($pass);
312  $this->form->addItem($txt);
313  break;
314 
316 
317  // no "request" info if waiting list is active
318  if($this->isWaitingListActive())
319  return true;
320 
321  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
322  $txt->setValue($this->lng->txt('grp_reg_request'));
323 
324  $sub = new ilTextAreaInputGUI($this->lng->txt('grp_reg_subject'),'subject');
325  $sub->setValue($_POST['subject']);
326  $sub->setInfo($this->lng->txt('group_req_registration_msg'));
327  $sub->setCols(40);
328  $sub->setRows(5);
329  if($this->participants->isSubscriber($ilUser->getId()))
330  {
331  $sub_data = $this->participants->getSubscriberData($ilUser->getId());
332  $sub->setValue($sub_data['subject']);
333  $sub->setInfo('');
334  ilUtil::sendFailure($this->lng->txt('grp_already_assigned'));
335  $this->enableRegistration(false);
336  }
337  $txt->addSubItem($sub);
338  $this->form->addItem($txt);
339  break;
340 
342 
343  // no "direct registration" info if waiting list is active
344  if($this->isWaitingListActive())
345  return true;
346 
347  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
348  $txt->setValue($this->lng->txt('group_req_direct'));
349 
350  $this->form->addItem($txt);
351  break;
352 
353  default:
354  return true;
355  }
356 
357  return true;
358  }
359 
364  protected function addCommandButtons()
365  {
366  global $ilUser;
367 
369 
370 
371  switch($this->container->getRegistrationType())
372  {
374  if($this->participants->isSubscriber($ilUser->getId()))
375  {
376  $this->form->clearCommandButtons();
377  $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('grp_update_subscr_request'));
378  $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('grp_cancel_subscr_request'));
379  }
380  else
381  {
382  if(!$this->isRegistrationPossible())
383  {
384  return false;
385  }
386  $this->form->clearCommandButtons();
387  $this->form->addCommandButton('join', $this->lng->txt('grp_join_request'));
388  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
389  }
390  break;
391  }
392  return true;
393  }
394 
395 
402  protected function validate()
403  {
404  global $ilUser;
405 
406  if($ilUser->getId() == ANONYMOUS_USER_ID)
407  {
408  $this->join_error = $this->lng->txt('permission_denied');
409  return false;
410  }
411 
412  if(!$this->isRegistrationPossible())
413  {
414  $this->join_error = $this->lng->txt('mem_error_preconditions');
415  return false;
416  }
417  if($this->container->getRegistrationType() == GRP_REGISTRATION_PASSWORD)
418  {
419  if(!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw'])))
420  {
421  $this->join_error = $this->lng->txt('err_wrong_password');
422  return false;
423  }
424  if(strcmp($pass,$this->container->getPassword()) !== 0)
425  {
426  $this->join_error = $this->lng->txt('err_wrong_password');
427  return false;
428  }
429  }
430  if(!$this->validateCustomFields())
431  {
432  $this->join_error = $this->lng->txt('fill_out_all_required_fields');
433  return false;
434  }
435  if(!$this->validateAgreement())
436  {
437  $this->join_error = $this->lng->txt($this->type.'_agreement_required');
438  return false;
439  }
440 
441  return true;
442  }
443 
451  protected function add()
452  {
453  global $ilUser,$tree, $rbacreview, $lng, $ilCtrl;
454 
455  // set aggreement accepted
456  $this->setAccepted(true);
457 
458  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
459  $free = max(0,$this->container->getMaxMembers() - $this->participants->getCountMembers());
460  $waiting_list = new ilGroupWaitingList($this->container->getId());
461  if(
462  $this->container->isMembershipLimited() and
463  $this->container->isWaitingListEnabled() and
464  (!$free or $waiting_list->getCountUsers()))
465  {
466  $waiting_list->addToList($ilUser->getId());
467  $info = sprintf($this->lng->txt('grp_added_to_list'),
468  $this->container->getTitle(),
469  $waiting_list->getPosition($ilUser->getId()));
470 
471  $this->participants->sendNotification(
473  $ilUser->getId()
474  );
475  ilUtil::sendSuccess($info,true);
476  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
477  $tree->getParentId($this->container->getRefId()));
478  $ilCtrl->redirectByClass("ilrepositorygui", "");
479  }
480 
481 
482  switch($this->container->getRegistrationType())
483  {
485 
486  $this->participants->addSubscriber($ilUser->getId());
487  $this->participants->updateSubscriptionTime($ilUser->getId(),time());
488  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['subject']));
489 
490  $this->participants->sendNotification(
492  $ilUser->getId()
493  );
494 
495  ilUtil::sendSuccess($this->lng->txt("application_completed"),true);
496  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
497  $tree->getParentId($this->container->getRefId()));
498  $ilCtrl->redirectByClass("ilrepositorygui", "");
499  break;
500 
501  default:
502 
503  $this->participants->add($ilUser->getId(),IL_GRP_MEMBER);
504  $this->participants->sendNotification(
506  $ilUser->getId()
507  );
508  $this->participants->sendNotification(
510  $ilUser->getId()
511  );
512 
513  include_once './Modules/Forum/classes/class.ilForumNotification.php';
514  ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $ilUser->getId());
515 
516  if(!$_SESSION["pending_goto"])
517  {
518  ilUtil::sendSuccess($this->lng->txt("grp_registration_completed"),true);
519  $this->ctrl->returnToParent($this);
520  }
521  else
522  {
523  $tgt = $_SESSION["pending_goto"];
524  unset($_SESSION["pending_goto"]);
525  ilUtil::redirect($tgt);
526  }
527  break;
528  }
529  }
530 
531 
537  protected function initParticipants()
538  {
539  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
540  $this->participants = ilGroupParticipants::_getInstanceByObjId($this->obj_id);
541  }
542 
547  protected function initWaitingList()
548  {
549  include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
550  $this->waiting_list = new ilGroupWaitingList($this->container->getId());
551  }
552 
556  protected function isWaitingListActive()
557  {
558  global $ilUser;
559  static $active = null;
560 
561  if($active !== null)
562  {
563  return $active;
564  }
565  if(!$this->container->getMaxMembers())
566  {
567  return $active = false;
568  }
569  if(
570  !$this->container->isWaitingListEnabled() or
571  !$this->container->isMembershipLimited())
572  {
573  return $active = false;
574  }
575 
576  $free = max(0,$this->container->getMaxMembers() - $this->participants->getCountMembers());
577  return $active = (!$free or $this->getWaitingList()->getCountUsers());
578  }
579 }
580 ?>