ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
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 
195  include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
196  $reg_info = ilObjGroupAccess::lookupRegistrationInfo($this->getContainer()->getId());
197  $free = $reg_info['reg_info_free_places'];
198 
199 
200  if($free)
201  {
202  $tpl->setVariable('NUM_FREE',$free);
203  }
204  else
205  {
206  $tpl->setVariable('WARN_FREE',$free);
207  }
208 
209  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
210  $waiting_list = new ilGroupWaitingList($this->container->getId());
211 
212  if(
213  $this->container->isWaitingListEnabled() and
214  $this->container->isMembershipLimited() and
215  (!$free or $waiting_list->getCountUsers()))
216  {
217  if($waiting_list->isOnList($ilUser->getId()))
218  {
219  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list_position'));
220  $tpl->setVariable('NUM_WAIT',$waiting_list->getPosition($ilUser->getId()));
221 
222  }
223  else
224  {
225  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list'));
226  if($free and $waiting_list->getCountUsers())
227  $tpl->setVariable('WARN_WAIT',$waiting_list->getCountUsers());
228  else
229  $tpl->setVariable('NUM_WAIT',$waiting_list->getCountUsers());
230 
231  }
232  }
233 
234  $alert = '';
235  if(
236  !$free and
237  !$this->container->isWaitingListEnabled())
238  {
239  // Disable registration
240  $this->enableRegistration(false);
241  $alert = $this->lng->txt('mem_alert_no_places');
242  }
243  elseif(
244  $this->container->isWaitingListEnabled() and
245  $this->container->isMembershipLimited() and
246  $waiting_list->isOnList($ilUser->getId()))
247  {
248  // Disable registration
249  $this->enableRegistration(false);
250  }
251  elseif(
252  !$free and
253  $this->container->isWaitingListEnabled() and
254  $this->container->isMembershipLimited())
255  {
256  $alert = $this->lng->txt('grp_warn_no_max_set_on_waiting_list');
257  }
258  elseif(
259  $free and
260  $this->container->isWaitingListEnabled() and
261  $this->container->isMembershipLimited() and
262  $this->getWaitingList()->getCountUsers())
263  {
264  $alert = $this->lng->txt('grp_warn_wl_set_on_waiting_list');
265  }
266 
267  $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
268  $max->setHtml($tpl->get());
269  if(strlen($alert))
270  {
271  #$max->setAlert($alert);
272  ilUtil::sendFailure($alert);
273  }
274  $this->form->addItem($max);
275  }
276 
284  protected function fillRegistrationType()
285  {
286  global $ilUser;
287 
288  if($this->getWaitingList()->isOnList($ilUser->getId()))
289  {
290  return true;
291  }
292 
293  switch($this->container->getRegistrationType())
294  {
296  $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
297  $reg->setValue($this->lng->txt('grp_reg_disabled'));
298  #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
299  $this->form->addItem($reg);
300 
301  // Disable registration
302  $this->enableRegistration(false);
303 
304  break;
305 
307  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
308  $txt->setValue($this->lng->txt('grp_pass_request'));
309 
310 
311  $pass = new ilTextInputGUI($this->lng->txt('passwd'),'grp_passw');
312  $pass->setInputType('password');
313  $pass->setSize(12);
314  $pass->setMaxLength(32);
315  #$pass->setRequired(true);
316  $pass->setInfo($this->lng->txt('group_password_registration_msg'));
317 
318  $txt->addSubItem($pass);
319  $this->form->addItem($txt);
320  break;
321 
323 
324  // no "request" info if waiting list is active
325  if($this->isWaitingListActive())
326  return true;
327 
328  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
329  $txt->setValue($this->lng->txt('grp_reg_request'));
330 
331  $sub = new ilTextAreaInputGUI($this->lng->txt('grp_reg_subject'),'subject');
332  $sub->setValue($_POST['subject']);
333  $sub->setInfo($this->lng->txt('group_req_registration_msg'));
334  $sub->setCols(40);
335  $sub->setRows(5);
336  if($this->participants->isSubscriber($ilUser->getId()))
337  {
338  $sub_data = $this->participants->getSubscriberData($ilUser->getId());
339  $sub->setValue($sub_data['subject']);
340  $sub->setInfo('');
341  ilUtil::sendFailure($this->lng->txt('grp_already_assigned'));
342  $this->enableRegistration(false);
343  }
344  $txt->addSubItem($sub);
345  $this->form->addItem($txt);
346  break;
347 
349 
350  // no "direct registration" info if waiting list is active
351  if($this->isWaitingListActive())
352  return true;
353 
354  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
355  $txt->setValue($this->lng->txt('group_req_direct'));
356 
357  $this->form->addItem($txt);
358  break;
359 
360  default:
361  return true;
362  }
363 
364  return true;
365  }
366 
371  protected function addCommandButtons()
372  {
373  global $ilUser;
374 
375  parent::addCommandButtons();
376 
377 
378  switch($this->container->getRegistrationType())
379  {
381  if($this->participants->isSubscriber($ilUser->getId()))
382  {
383  $this->form->clearCommandButtons();
384  $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('grp_update_subscr_request'));
385  $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('grp_cancel_subscr_request'));
386  }
387  else
388  {
389  if(!$this->isRegistrationPossible())
390  {
391  return false;
392  }
393  $this->form->clearCommandButtons();
394  $this->form->addCommandButton('join', $this->lng->txt('grp_join_request'));
395  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
396  }
397  break;
398  }
399  return true;
400  }
401 
402 
409  protected function validate()
410  {
411  global $ilUser;
412 
413  if($ilUser->getId() == ANONYMOUS_USER_ID)
414  {
415  $this->join_error = $this->lng->txt('permission_denied');
416  return false;
417  }
418 
419  if(!$this->isRegistrationPossible())
420  {
421  $this->join_error = $this->lng->txt('mem_error_preconditions');
422  return false;
423  }
424  if($this->container->getRegistrationType() == GRP_REGISTRATION_PASSWORD)
425  {
426  if(!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw'])))
427  {
428  $this->join_error = $this->lng->txt('err_wrong_password');
429  return false;
430  }
431  if(strcmp($pass,$this->container->getPassword()) !== 0)
432  {
433  $this->join_error = $this->lng->txt('err_wrong_password');
434  return false;
435  }
436  }
437  if(!$this->validateCustomFields())
438  {
439  $this->join_error = $this->lng->txt('fill_out_all_required_fields');
440  return false;
441  }
442  if(!$this->validateAgreement())
443  {
444  $this->join_error = $this->lng->txt($this->type.'_agreement_required');
445  return false;
446  }
447 
448  return true;
449  }
450 
458  protected function add()
459  {
460  global $ilUser,$tree, $rbacreview, $lng, $ilCtrl;
461 
462  // set aggreement accepted
463  $this->setAccepted(true);
464 
465  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
466  $free = max(0,$this->container->getMaxMembers() - $this->participants->getCountMembers());
467  $waiting_list = new ilGroupWaitingList($this->container->getId());
468  if(
469  $this->container->isMembershipLimited() and
470  $this->container->isWaitingListEnabled() and
471  (!$free or $waiting_list->getCountUsers()))
472  {
473  $waiting_list->addToList($ilUser->getId());
474  $info = sprintf($this->lng->txt('grp_added_to_list'),
475  $this->container->getTitle(),
476  $waiting_list->getPosition($ilUser->getId()));
477 
478  $this->participants->sendNotification(
480  $ilUser->getId()
481  );
482  ilUtil::sendSuccess($info,true);
483  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
484  $tree->getParentId($this->container->getRefId()));
485  $ilCtrl->redirectByClass("ilrepositorygui", "");
486  }
487 
488 
489  switch($this->container->getRegistrationType())
490  {
492 
493  $this->participants->addSubscriber($ilUser->getId());
494  $this->participants->updateSubscriptionTime($ilUser->getId(),time());
495  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['subject']));
496 
497  $this->participants->sendNotification(
499  $ilUser->getId()
500  );
501 
502  ilUtil::sendSuccess($this->lng->txt("application_completed"),true);
503  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
504  $tree->getParentId($this->container->getRefId()));
505  $ilCtrl->redirectByClass("ilrepositorygui", "");
506  break;
507 
508  default:
509 
510  $this->participants->add($ilUser->getId(),IL_GRP_MEMBER);
511  $this->participants->sendNotification(
513  $ilUser->getId()
514  );
515  $this->participants->sendNotification(
517  $ilUser->getId()
518  );
519 
520  include_once './Modules/Forum/classes/class.ilForumNotification.php';
521  ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $ilUser->getId());
522 
523  if(!$_SESSION["pending_goto"])
524  {
525  ilUtil::sendSuccess($this->lng->txt("grp_registration_completed"),true);
526  $this->ctrl->returnToParent($this);
527  }
528  else
529  {
530  $tgt = $_SESSION["pending_goto"];
531  unset($_SESSION["pending_goto"]);
532  ilUtil::redirect($tgt);
533  }
534  break;
535  }
536  }
537 
538 
544  protected function initParticipants()
545  {
546  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
547  $this->participants = ilGroupParticipants::_getInstanceByObjId($this->obj_id);
548  }
549 
554  protected function initWaitingList()
555  {
556  include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
557  $this->waiting_list = new ilGroupWaitingList($this->container->getId());
558  }
559 
563  protected function isWaitingListActive()
564  {
565  global $ilUser;
566  static $active = null;
567 
568  if($active !== null)
569  {
570  return $active;
571  }
572  if(!$this->container->getMaxMembers())
573  {
574  return $active = false;
575  }
576  if(
577  !$this->container->isWaitingListEnabled() or
578  !$this->container->isMembershipLimited())
579  {
580  return $active = false;
581  }
582 
583  $free = max(0,$this->container->getMaxMembers() - $this->participants->getCountMembers());
584  return $active = (!$free or $this->getWaitingList()->getCountUsers());
585  }
586 }
587 ?>
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
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.
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.
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:10
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