ILIAS  Release_4_0_x_branch Revision 61816
 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'));
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($this->container->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers()))
206  {
207  if($waiting_list->isOnList($ilUser->getId()))
208  {
209  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list_position'));
210  $tpl->setVariable('NUM_WAIT',$waiting_list->getPosition($ilUser->getId()));
211 
212  }
213  else
214  {
215  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list'));
216  if($free and $waiting_list->getCountUsers())
217  $tpl->setVariable('WARN_WAIT',$waiting_list->getCountUsers());
218  else
219  $tpl->setVariable('NUM_WAIT',$waiting_list->getCountUsers());
220 
221  }
222  }
223 
224  $alert = '';
225  if(!$free and !$this->container->isWaitingListEnabled())
226  {
227  // Disable registration
228  $this->enableRegistration(false);
229  $alert = $this->lng->txt('mem_alert_no_places');
230  }
231  elseif($this->container->isWaitingListEnabled() and $waiting_list->isOnList($ilUser->getId()))
232  {
233  // Disable registration
234  $this->enableRegistration(false);
235  }
236  elseif(!$free and $this->container->isWaitingListEnabled())
237  {
238  $alert = $this->lng->txt('grp_warn_no_max_set_on_waiting_list');
239  }
240  elseif($free and $this->container->isWaitingListEnabled() and $this->getWaitingList()->getCountUsers())
241  {
242  $alert = $this->lng->txt('grp_warn_wl_set_on_waiting_list');
243  }
244 
245  $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
246  $max->setHtml($tpl->get());
247  if(strlen($alert))
248  {
249  #$max->setAlert($alert);
250  ilUtil::sendFailure($alert);
251  }
252  $this->form->addItem($max);
253  }
254 
262  protected function fillRegistrationType()
263  {
264  global $ilUser;
265 
266  if($this->getWaitingList()->isOnList($ilUser->getId()))
267  {
268  return true;
269  }
270 
271  switch($this->container->getRegistrationType())
272  {
274  $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
275  $reg->setValue($this->lng->txt('grp_reg_disabled'));
276  #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
277  $this->form->addItem($reg);
278 
279  // Disable registration
280  $this->enableRegistration(false);
281 
282  break;
283 
285  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
286  $txt->setValue($this->lng->txt('grp_pass_request'));
287 
288 
289  $pass = new ilTextInputGUI($this->lng->txt('passwd'),'grp_passw');
290  $pass->setInputType('password');
291  $pass->setSize(12);
292  $pass->setMaxLength(32);
293  #$pass->setRequired(true);
294  $pass->setInfo($this->lng->txt('group_password_registration_msg'));
295 
296  $txt->addSubItem($pass);
297  $this->form->addItem($txt);
298  break;
299 
301 
302  // no "request" info if waiting list is active
303  if($this->isWaitingListActive())
304  return true;
305 
306  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
307  $txt->setValue($this->lng->txt('grp_reg_request'));
308 
309  $sub = new ilTextAreaInputGUI($this->lng->txt('grp_reg_subject'),'subject');
310  $sub->setValue($_POST['subject']);
311  $sub->setInfo($this->lng->txt('group_req_registration_msg'));
312  $sub->setCols(40);
313  $sub->setRows(5);
314  if($this->participants->isSubscriber($ilUser->getId()))
315  {
316  $sub_data = $this->participants->getSubscriberData($ilUser->getId());
317  $sub->setValue($sub_data['subject']);
318  $sub->setInfo('');
319  ilUtil::sendFailure($this->lng->txt('grp_already_assigned'));
320  $this->enableRegistration(false);
321  }
322  $txt->addSubItem($sub);
323  $this->form->addItem($txt);
324  break;
325 
327 
328  // no "direct registration" info if waiting list is active
329  if($this->isWaitingListActive())
330  return true;
331 
332  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
333  $txt->setValue($this->lng->txt('group_req_direct'));
334 
335  $this->form->addItem($txt);
336  break;
337 
338  default:
339  return true;
340  }
341 
342  return true;
343  }
344 
349  protected function addCommandButtons()
350  {
351  global $ilUser;
352 
354 
355 
356  switch($this->container->getRegistrationType())
357  {
359  if($this->participants->isSubscriber($ilUser->getId()))
360  {
361  $this->form->clearCommandButtons();
362  $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('grp_update_subscr_request'));
363  $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('grp_cancel_subscr_request'));
364  }
365  else
366  {
367  if(!$this->isRegistrationPossible())
368  {
369  return false;
370  }
371  $this->form->clearCommandButtons();
372  $this->form->addCommandButton('join', $this->lng->txt('grp_join_request'));
373  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
374  }
375  break;
376  }
377  return true;
378  }
379 
380 
387  protected function validate()
388  {
389  global $ilUser;
390 
391  if($ilUser->getId() == ANONYMOUS_USER_ID)
392  {
393  $this->join_error = $this->lng->txt('permission_denied');
394  return false;
395  }
396 
397  if(!$this->isRegistrationPossible())
398  {
399  $this->join_error = $this->lng->txt('mem_error_preconditions');
400  return false;
401  }
402  if($this->container->getRegistrationType() == GRP_REGISTRATION_PASSWORD)
403  {
404  if(!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw'])))
405  {
406  $this->join_error = $this->lng->txt('err_wrong_password');
407  return false;
408  }
409  if(strcmp($pass,$this->container->getPassword()) !== 0)
410  {
411  $this->join_error = $this->lng->txt('err_wrong_password');
412  return false;
413  }
414  }
415  return true;
416  }
417 
425  protected function add()
426  {
427  global $ilUser,$tree, $rbacreview, $lng;
428 
429  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
430  $free = max(0,$this->container->getMaxMembers() - $this->participants->getCountMembers());
431  $waiting_list = new ilGroupWaitingList($this->container->getId());
432  if($this->container->isMembershipLimited() and $this->container->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers()))
433  {
434  $waiting_list->addToList($ilUser->getId());
435  $info = sprintf($this->lng->txt('grp_added_to_list'),
436  $this->container->getTitle(),
437  $waiting_list->getPosition($ilUser->getId()));
438 
439  $this->participants->sendNotification(
441  $ilUser->getId()
442  );
443  ilUtil::sendSuccess($info,true);
444  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
445  }
446 
447 
448  switch($this->container->getRegistrationType())
449  {
451 
452  $this->participants->addSubscriber($ilUser->getId());
453  $this->participants->updateSubscriptionTime($ilUser->getId(),time());
454  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['subject']));
455 
456  $this->participants->sendNotification(
458  $ilUser->getId()
459  );
460 
461  ilUtil::sendSuccess($this->lng->txt("application_completed"),true);
462  ilUtil::redirect("repository.php?ref_id=".$tree->getParentId($this->container->getRefId()));
463  break;
464 
465  default:
466 
467  $this->participants->add($ilUser->getId(),IL_GRP_MEMBER);
468  $this->participants->sendNotification(
470  $ilUser->getId()
471  );
472  $this->participants->sendNotification(
474  $ilUser->getId()
475  );
476  ilUtil::sendSuccess($this->lng->txt("grp_registration_completed"),true);
477  $this->ctrl->returnToParent($this);
478  break;
479  }
480  }
481 
482 
488  protected function initParticipants()
489  {
490  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
491  $this->participants = ilGroupParticipants::_getInstanceByObjId($this->obj_id);
492  }
493 
498  protected function initWaitingList()
499  {
500  include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
501  $this->waiting_list = new ilGroupWaitingList($this->container->getId());
502  }
503 
507  protected function isWaitingListActive()
508  {
509  global $ilUser;
510  static $active = null;
511 
512  if($active !== null)
513  {
514  return $active;
515  }
516  if(!$this->container->getMaxMembers())
517  {
518  return $active = false;
519  }
520  if(!$this->container->isWaitingListEnabled())
521  {
522  return $active = false;
523  }
524 
525  $free = max(0,$this->container->getMaxMembers() - $this->participants->getCountMembers());
526  return $active = (!$free or $this->getWaitingList()->getCountUsers());
527  }
528 }
529 ?>