ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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 
190  $tpl = new ilTemplate('tpl.max_members_form.html',true,true,'Services/Membership');
191 
192  if($this->container->getMinMembers())
193  {
194  $tpl->setVariable('TXT_MIN',$this->lng->txt('mem_min_users'));
195  $tpl->setVariable('NUM_MIN',$this->container->getMinMembers());
196  }
197 
198  if($this->container->getMaxMembers())
199  {
200  $tpl->setVariable('TXT_MAX',$this->lng->txt('mem_max_users'));
201  $tpl->setVariable('NUM_MAX',$this->container->getMaxMembers());
202 
203  include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
204  $reg_info = ilObjGroupAccess::lookupRegistrationInfo($this->getContainer()->getId());
205  $free = $reg_info['reg_info_free_places'];
206 
207  $tpl->setVariable('TXT_FREE',$this->lng->txt('mem_free_places'));
208  if($free)
209  {
210  $tpl->setVariable('NUM_FREE',$free);
211  }
212  else
213  {
214  $tpl->setVariable('WARN_FREE',$free);
215  }
216 
217  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
218  $waiting_list = new ilGroupWaitingList($this->container->getId());
219 
220  if(
221  $this->container->isWaitingListEnabled() and
222  $this->container->isMembershipLimited() and
223  (!$free or $waiting_list->getCountUsers()))
224  {
225  if($waiting_list->isOnList($ilUser->getId()))
226  {
227  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list_position'));
228  $tpl->setVariable('NUM_WAIT',$waiting_list->getPosition($ilUser->getId()));
229 
230  }
231  else
232  {
233  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list'));
234  if($free and $waiting_list->getCountUsers())
235  $tpl->setVariable('WARN_WAIT',$waiting_list->getCountUsers());
236  else
237  $tpl->setVariable('NUM_WAIT',$waiting_list->getCountUsers());
238 
239  }
240  }
241 
242  $alert = '';
243  if(
244  !$free and
245  !$this->container->isWaitingListEnabled())
246  {
247  // Disable registration
248  $this->enableRegistration(false);
249  $alert = $this->lng->txt('mem_alert_no_places');
250  }
251  elseif(
252  $this->container->isWaitingListEnabled() and
253  $this->container->isMembershipLimited() and
254  $waiting_list->isOnList($ilUser->getId()))
255  {
256  // Disable registration
257  $this->enableRegistration(false);
258  }
259  elseif(
260  !$free and
261  $this->container->isWaitingListEnabled() and
262  $this->container->isMembershipLimited())
263  {
264  $alert = $this->lng->txt('grp_warn_no_max_set_on_waiting_list');
265  }
266  elseif(
267  $free and
268  $this->container->isWaitingListEnabled() and
269  $this->container->isMembershipLimited() and
270  $this->getWaitingList()->getCountUsers())
271  {
272  $alert = $this->lng->txt('grp_warn_wl_set_on_waiting_list');
273  }
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  ilUtil::sendFailure($alert);
282  }
283  $this->form->addItem($max);
284  }
285 
293  protected function fillRegistrationType()
294  {
295  global $ilUser;
296 
297  if($this->getWaitingList()->isOnList($ilUser->getId()))
298  {
299  return true;
300  }
301 
302  switch($this->container->getRegistrationType())
303  {
305  $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
306  $reg->setValue($this->lng->txt('grp_reg_disabled'));
307  #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
308  $this->form->addItem($reg);
309 
310  // Disable registration
311  $this->enableRegistration(false);
312 
313  break;
314 
316  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
317  $txt->setValue($this->lng->txt('grp_pass_request'));
318 
319 
320  $pass = new ilTextInputGUI($this->lng->txt('passwd'),'grp_passw');
321  $pass->setInputType('password');
322  $pass->setSize(12);
323  $pass->setMaxLength(32);
324  #$pass->setRequired(true);
325  $pass->setInfo($this->lng->txt('group_password_registration_msg'));
326 
327  $txt->addSubItem($pass);
328  $this->form->addItem($txt);
329  break;
330 
332 
333  // no "request" info if waiting list is active
334  if($this->isWaitingListActive())
335  return true;
336 
337  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
338  $txt->setValue($this->lng->txt('grp_reg_request'));
339 
340  $sub = new ilTextAreaInputGUI($this->lng->txt('grp_reg_subject'),'subject');
341  $sub->setValue($_POST['subject']);
342  $sub->setInfo($this->lng->txt('group_req_registration_msg'));
343  $sub->setCols(40);
344  $sub->setRows(5);
345  if($this->participants->isSubscriber($ilUser->getId()))
346  {
347  $sub_data = $this->participants->getSubscriberData($ilUser->getId());
348  $sub->setValue($sub_data['subject']);
349  $sub->setInfo('');
350  ilUtil::sendFailure($this->lng->txt('grp_already_assigned'));
351  $this->enableRegistration(false);
352  }
353  $txt->addSubItem($sub);
354  $this->form->addItem($txt);
355  break;
356 
358 
359  // no "direct registration" info if waiting list is active
360  if($this->isWaitingListActive())
361  return true;
362 
363  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
364  $txt->setValue($this->lng->txt('group_req_direct'));
365 
366  $this->form->addItem($txt);
367  break;
368 
369  default:
370  return true;
371  }
372 
373  return true;
374  }
375 
380  protected function addCommandButtons()
381  {
382  global $ilUser;
383 
384  parent::addCommandButtons();
385 
386 
387  switch($this->container->getRegistrationType())
388  {
390  if($this->participants->isSubscriber($ilUser->getId()))
391  {
392  $this->form->clearCommandButtons();
393  $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('grp_update_subscr_request'));
394  $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('grp_cancel_subscr_request'));
395  }
396  else
397  {
398  if(!$this->isRegistrationPossible())
399  {
400  return false;
401  }
402  $this->form->clearCommandButtons();
403  $this->form->addCommandButton('join', $this->lng->txt('grp_join_request'));
404  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
405  }
406  break;
407  }
408  return true;
409  }
410 
411 
418  protected function validate()
419  {
420  global $ilUser;
421 
422  if($ilUser->getId() == ANONYMOUS_USER_ID)
423  {
424  $this->join_error = $this->lng->txt('permission_denied');
425  return false;
426  }
427 
428  if(!$this->isRegistrationPossible())
429  {
430  $this->join_error = $this->lng->txt('mem_error_preconditions');
431  return false;
432  }
433  if($this->container->getRegistrationType() == GRP_REGISTRATION_PASSWORD)
434  {
435  if(!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw'])))
436  {
437  $this->join_error = $this->lng->txt('err_wrong_password');
438  return false;
439  }
440  if(strcmp($pass,$this->container->getPassword()) !== 0)
441  {
442  $this->join_error = $this->lng->txt('err_wrong_password');
443  return false;
444  }
445  }
446  if(!$this->validateCustomFields())
447  {
448  $this->join_error = $this->lng->txt('fill_out_all_required_fields');
449  return false;
450  }
451  if(!$this->validateAgreement())
452  {
453  $this->join_error = $this->lng->txt($this->type.'_agreement_required');
454  return false;
455  }
456 
457  return true;
458  }
459 
467  protected function add()
468  {
469  global $ilUser,$tree, $rbacreview, $lng, $ilCtrl;
470 
471  // set aggreement accepted
472  $this->setAccepted(true);
473 
474  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
475  $free = max(0,$this->container->getMaxMembers() - $this->participants->getCountMembers());
476  $waiting_list = new ilGroupWaitingList($this->container->getId());
477  if(
478  $this->container->isMembershipLimited() and
479  $this->container->isWaitingListEnabled() and
480  (!$free or $waiting_list->getCountUsers()))
481  {
482  $waiting_list->addToList($ilUser->getId());
483  $info = sprintf($this->lng->txt('grp_added_to_list'),
484  $this->container->getTitle(),
485  $waiting_list->getPosition($ilUser->getId()));
486 
487  $this->participants->sendNotification(
489  $ilUser->getId()
490  );
492  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
493  $tree->getParentId($this->container->getRefId()));
494  $ilCtrl->redirectByClass("ilrepositorygui", "");
495  }
496 
497 
498  switch($this->container->getRegistrationType())
499  {
501 
502  $this->participants->addSubscriber($ilUser->getId());
503  $this->participants->updateSubscriptionTime($ilUser->getId(),time());
504  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['subject']));
505 
506  $this->participants->sendNotification(
508  $ilUser->getId()
509  );
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 
519  $this->participants->add($ilUser->getId(),IL_GRP_MEMBER);
520  $this->participants->sendNotification(
522  $ilUser->getId()
523  );
524  $this->participants->sendNotification(
526  $ilUser->getId()
527  );
528 
529  include_once './Modules/Forum/classes/class.ilForumNotification.php';
530  ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $ilUser->getId());
531 
532  if(!$_SESSION["pending_goto"])
533  {
534  ilUtil::sendSuccess($this->lng->txt("grp_registration_completed"),true);
535  $this->ctrl->returnToParent($this);
536  }
537  else
538  {
539  $tgt = $_SESSION["pending_goto"];
540  unset($_SESSION["pending_goto"]);
541  ilUtil::redirect($tgt);
542  }
543  break;
544  }
545  }
546 
547 
553  protected function initParticipants()
554  {
555  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
556  $this->participants = ilGroupParticipants::_getInstanceByObjId($this->obj_id);
557  }
558 
563  protected function initWaitingList()
564  {
565  include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
566  $this->waiting_list = new ilGroupWaitingList($this->container->getId());
567  }
568 
572  protected function isWaitingListActive()
573  {
574  global $ilUser;
575  static $active = null;
576 
577  if($active !== null)
578  {
579  return $active;
580  }
581  if(!$this->container->getMaxMembers())
582  {
583  return $active = false;
584  }
585  if(
586  !$this->container->isWaitingListEnabled() or
587  !$this->container->isMembershipLimited())
588  {
589  return $active = false;
590  }
591 
592  $free = max(0,$this->container->getMaxMembers() - $this->participants->getCountMembers());
593  return $active = (!$free or $this->getWaitingList()->getCountUsers());
594  }
595 }
596 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
fillRegistrationType()
fill registration procedure
setHtml($a_html)
Set Html.
$_POST['username']
Definition: cron.php:12
addToList($a_usr_id)
Add to waiting list and raise event.
$_SESSION["AccountId"]
const GRP_REGISTRATION_DEACTIVATED
static _after(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
getWaitingList()
Get waiting list object.
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
$cmd
Definition: sahs_server.php:35
setValue($a_value)
Set Value.
Base class for Course and Group registration.
const IL_CAL_UNIX
const IL_GRP_MEMBER
const GRP_REGISTRATION_PASSWORD
const GRP_REGISTRATION_REQUEST
global $ilCtrl
Definition: ilias.php:18
validateAgreement()
Check Agreement.
setAccepted($a_status)
Set Agreement accepted.
$info
Definition: example_052.php:80
static lookupRegistrationInfo($a_obj_id)
Lookup registration info ilDB $ilDB ilObjUser $ilUser ilLanguage $lng.
addCommandButtons()
Add group specific command buttons.
enableRegistration($a_status)
set registration disabled
fillRegistrationPeriod()
show informations about the registration period
static makeClickable($a_text, $detectGotoLinks=false)
makeClickable In Texten enthaltene URLs und Mail-Adressen klickbar machen
special template class to simplify handling of ITX/PEAR
isRegistrationPossible()
check if registration is possible
This class represents a text property in a property form.
static formatDate(ilDateTime $date)
Format a date public.
Waiting list for groups.
Date and time handling
validateCustomFields()
Check required course fields.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$txt
Definition: error.php:12
GUI class for group registrations.
initParticipants()
Init course participants.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
__construct($a_container)
Constructor.
fillMaxMembers()
fill max member informations
This class represents a custom property in a property form.
This class represents a non editable value in a property form.
global $ilUser
Definition: imgupload.php:15
This class represents a text area property in a property form.
static checkForumsExistsInsert($ref_id, $user_id=0)
getContainer()
Parent object.
static redirect($a_script)
http redirect to other script
const GRP_REGISTRATION_DIRECT