ILIAS  release_7 Revision v7.30-3-g800a261c036
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
24include_once('./Services/Membership/classes/class.ilRegistrationGUI.php');
25include_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 $DIC;
57
58 $ilUser = $DIC['ilUser'];
59 $ilTabs = $DIC['ilTabs'];
60
61 $next_class = $this->ctrl->getNextClass($this);
62
63 if (!$DIC->access()->checkAccess('join', '', $this->getRefId())) {
64 $this->ctrl->redirectByClass(ilObjGroupGUI::class, 'infoScreen');
65 }
66
67 if ($this->getWaitingList()->isOnList($ilUser->getId())) {
68 $ilTabs->activateTab('leave');
69 }
70
71 switch ($next_class) {
72 default:
73 $cmd = $this->ctrl->getCmd("show");
74 $this->$cmd();
75 break;
76 }
77 return true;
78 }
79
80
87 protected function getFormTitle()
88 {
89 global $DIC;
90
91 $ilUser = $DIC['ilUser'];
92
93 if ($this->getWaitingList()->isOnList($ilUser->getId())) {
94 return $this->lng->txt('member_status');
95 }
96 return $this->lng->txt('grp_registration');
97 }
98
106 protected function fillInformations()
107 {
108 if ($this->container->getInformation()) {
109 $imp = new ilNonEditableValueGUI($this->lng->txt('crs_important_info'), '', true);
110 $value = nl2br(ilUtil::makeClickable($this->container->getInformation(), true));
111 $imp->setValue($value);
112 $this->form->addItem($imp);
113 }
114 }
115
121 protected function fillRegistrationPeriod()
122 {
123 include_once('./Services/Calendar/classes/class.ilDateTime.php');
124 $now = new ilDateTime(time(), IL_CAL_UNIX, 'UTC');
125
126 if ($this->container->isRegistrationUnlimited()) {
127 $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_period'));
128 $reg->setValue($this->lng->txt('mem_unlimited'));
129 $this->form->addItem($reg);
130 return true;
131 }
132
133 $start = $this->container->getRegistrationStart();
134 $end = $this->container->getRegistrationEnd();
135
136
137 if (ilDateTime::_before($now, $start)) {
138 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'Services/Membership');
139 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_start'));
140 $tpl->setVariable('FIRST', ilDatePresentation::formatDate($start));
141
142 $tpl->setVariable('TXT_END', $this->lng->txt('mem_end'));
143 $tpl->setVariable('END', ilDatePresentation::formatDate($end));
144
145 $warning = $this->lng->txt('mem_reg_not_started');
146 } elseif (ilDateTime::_after($now, $end)) {
147 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'Services/Membership');
148 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_start'));
149 $tpl->setVariable('FIRST', ilDatePresentation::formatDate($start));
150
151 $tpl->setVariable('TXT_END', $this->lng->txt('mem_end'));
152 $tpl->setVariable('END', ilDatePresentation::formatDate($end));
153
154 $warning = $this->lng->txt('mem_reg_expired');
155 } else {
156 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'Services/Membership');
157 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_end'));
158 $tpl->setVariable('FIRST', ilDatePresentation::formatDate($end));
159 }
160
161 $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
162 $reg->setHtml($tpl->get());
163 if (strlen($warning)) {
164 // Disable registration
165 $this->enableRegistration(false);
166 #$reg->setAlert($warning);
167 ilUtil::sendFailure($warning);
168 }
169 $this->form->addItem($reg);
170 return true;
171 }
172
179 protected function fillMaxMembers()
180 {
181 global $DIC;
182
183 $ilUser = $DIC['ilUser'];
184
185 if (!$this->container->isMembershipLimited()) {
186 return true;
187 }
188
189 $tpl = new ilTemplate('tpl.max_members_form.html', true, true, 'Services/Membership');
190
191 if ($this->container->getMinMembers()) {
192 $tpl->setVariable('TXT_MIN', $this->lng->txt('mem_min_users'));
193 $tpl->setVariable('NUM_MIN', $this->container->getMinMembers());
194 }
195
196 if ($this->container->getMaxMembers()) {
197 $tpl->setVariable('TXT_MAX', $this->lng->txt('mem_max_users'));
198 $tpl->setVariable('NUM_MAX', $this->container->getMaxMembers());
199 $tpl->setVariable('TXT_FREE', $this->lng->txt('mem_free_places') . ":");
200
201 include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
202 $reg_info = ilObjGroupAccess::lookupRegistrationInfo($this->getContainer()->getId());
203 $free = $reg_info['reg_info_free_places'];
204
205
206 if ($free) {
207 $tpl->setVariable('NUM_FREE', $free);
208 } else {
209 $tpl->setVariable('WARN_FREE', $free);
210 }
211
212 include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
213 $waiting_list = new ilGroupWaitingList($this->container->getId());
214
215 if (
216 $this->container->isWaitingListEnabled() and
217 $this->container->isMembershipLimited() and
218 (!$free or $waiting_list->getCountUsers())) {
219 if ($waiting_list->isOnList($ilUser->getId())) {
220 $tpl->setVariable('TXT_WAIT', $this->lng->txt('mem_waiting_list_position'));
221 $tpl->setVariable('NUM_WAIT', $waiting_list->getPosition($ilUser->getId()));
222 } else {
223 $tpl->setVariable('TXT_WAIT', $this->lng->txt('mem_waiting_list'));
224 if ($free and $waiting_list->getCountUsers()) {
225 $tpl->setVariable('WARN_WAIT', $waiting_list->getCountUsers());
226 } else {
227 $tpl->setVariable('NUM_WAIT', $waiting_list->getCountUsers());
228 }
229 }
230 }
231
232 $alert = '';
233 if (
234 !$free and
235 !$this->container->isWaitingListEnabled()) {
236 // Disable registration
237 $this->enableRegistration(false);
238 $alert = $this->lng->txt('mem_alert_no_places');
239 } elseif (
240 $this->container->isWaitingListEnabled() and
241 $this->container->isMembershipLimited() and
242 $waiting_list->isOnList($ilUser->getId())) {
243 // Disable registration
244 $this->enableRegistration(false);
245 } elseif (
246 !$free and
247 $this->container->isWaitingListEnabled() and
248 $this->container->isMembershipLimited()) {
249 $alert = $this->lng->txt('grp_warn_no_max_set_on_waiting_list');
250 } elseif (
251 $free and
252 $this->container->isWaitingListEnabled() and
253 $this->container->isMembershipLimited() and
254 $this->getWaitingList()->getCountUsers()) {
255 $alert = $this->lng->txt('grp_warn_wl_set_on_waiting_list');
256 }
257 }
258
259 $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
260 $max->setHtml($tpl->get());
261 if (strlen($alert)) {
262 #$max->setAlert($alert);
263 ilUtil::sendFailure($alert);
264 }
265 $this->form->addItem($max);
266 }
267
275 protected function fillRegistrationType()
276 {
277 global $DIC;
278
279 $ilUser = $DIC['ilUser'];
280
281 if ($this->getWaitingList()->isOnList($ilUser->getId())) {
282 return true;
283 }
284
285 switch ($this->container->getRegistrationType()) {
287 $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
288 $reg->setValue($this->lng->txt('grp_reg_disabled'));
289 #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
290 $this->form->addItem($reg);
291
292 // Disable registration
293 $this->enableRegistration(false);
294
295 break;
296
298 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
299 $txt->setValue($this->lng->txt('grp_pass_request'));
300
301
302 $pass = new ilTextInputGUI($this->lng->txt('passwd'), 'grp_passw');
303 $pass->setInputType('password');
304 $pass->setSize(12);
305 $pass->setMaxLength(32);
306 #$pass->setRequired(true);
307 $pass->setInfo($this->lng->txt('group_password_registration_msg'));
308
309 $txt->addSubItem($pass);
310 $this->form->addItem($txt);
311 break;
312
314
315 // no "request" info if waiting list is active
316 if ($this->isWaitingListActive()) {
317 return true;
318 }
319
320 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
321 $txt->setValue($this->lng->txt('grp_reg_request'));
322
323 $sub = new ilTextAreaInputGUI($this->lng->txt('grp_reg_subject'), 'subject');
324 $sub->setValue($_POST['subject']);
325 $sub->setInfo($this->lng->txt('group_req_registration_msg'));
326 $sub->setCols(40);
327 $sub->setRows(5);
328 if ($this->participants->isSubscriber($ilUser->getId())) {
329 $sub_data = $this->participants->getSubscriberData($ilUser->getId());
330 $sub->setValue($sub_data['subject']);
331 $sub->setInfo('');
332 ilUtil::sendFailure($this->lng->txt('grp_already_assigned'));
333 $this->enableRegistration(false);
334 }
335 $txt->addSubItem($sub);
336 $this->form->addItem($txt);
337 break;
338
340
341 // no "direct registration" info if waiting list is active
342 if ($this->isWaitingListActive()) {
343 return true;
344 }
345
346 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
347 $txt->setValue($this->lng->txt('group_req_direct'));
348
349 $this->form->addItem($txt);
350 break;
351
352 default:
353 return true;
354 }
355
356 return true;
357 }
358
363 protected function addCommandButtons()
364 {
365 global $DIC;
366
367 $ilUser = $DIC['ilUser'];
368
369 parent::addCommandButtons();
370
371
372 switch ($this->container->getRegistrationType()) {
374 if ($this->participants->isSubscriber($ilUser->getId())) {
375 $this->form->clearCommandButtons();
376 $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('grp_update_subscr_request'));
377 $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('grp_cancel_subscr_request'));
378 } else {
379 if (!$this->isRegistrationPossible()) {
380 return false;
381 }
382 $this->form->clearCommandButtons();
383 $this->form->addCommandButton('join', $this->lng->txt('grp_join_request'));
384 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
385 }
386 break;
387 }
388 return true;
389 }
390
391
398 protected function validate()
399 {
400 global $DIC;
401
402 $ilUser = $DIC['ilUser'];
403
404 if ($ilUser->getId() == ANONYMOUS_USER_ID) {
405 $this->join_error = $this->lng->txt('permission_denied');
406 return false;
407 }
408
409 if (!$this->isRegistrationPossible()) {
410 $this->join_error = $this->lng->txt('mem_error_preconditions');
411 return false;
412 }
413 if ($this->container->getRegistrationType() == GRP_REGISTRATION_PASSWORD) {
414 if (!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw']))) {
415 $this->join_error = $this->lng->txt('err_wrong_password');
416 return false;
417 }
418 if (strcmp($pass, $this->container->getPassword()) !== 0) {
419 $this->join_error = $this->lng->txt('err_wrong_password');
420 return false;
421 }
422 }
423 if (!$this->validateCustomFields()) {
424 $this->join_error = $this->lng->txt('fill_out_all_required_fields');
425 return false;
426 }
427 if (!$this->validateAgreement()) {
428 $this->join_error = $this->lng->txt($this->type . '_agreement_required');
429 return false;
430 }
431
432 return true;
433 }
434
442 protected function add()
443 {
444 global $DIC;
445
446 $ilUser = $DIC['ilUser'];
447 $tree = $DIC['tree'];
448 $rbacreview = $DIC['rbacreview'];
449 $lng = $DIC['lng'];
450 $ilCtrl = $DIC['ilCtrl'];
451
452 // set aggreement accepted
453 $this->setAccepted(true);
454
455 include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
456 $free = max(0, $this->container->getMaxMembers() - $this->participants->getCountMembers());
457 $waiting_list = new ilGroupWaitingList($this->container->getId());
458 if (
459 $this->container->isMembershipLimited() and
460 $this->container->isWaitingListEnabled() and
461 (!$free or $waiting_list->getCountUsers())) {
462 $waiting_list->addToList($ilUser->getId());
463 $info = sprintf(
464 $this->lng->txt('grp_added_to_list'),
465 $this->container->getTitle(),
466 $waiting_list->getPosition($ilUser->getId())
467 );
468
469 $this->participants->sendNotification(
471 $ilUser->getId()
472 );
473 ilUtil::sendSuccess($info, true);
474 $ilCtrl->setParameterByClass(
475 "ilrepositorygui",
476 "ref_id",
477 $tree->getParentId($this->container->getRefId())
478 );
479 $ilCtrl->redirectByClass("ilrepositorygui", "");
480 }
481
482
483 switch ($this->container->getRegistrationType()) {
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(
497 "ilrepositorygui",
498 "ref_id",
499 $tree->getParentId($this->container->getRefId())
500 );
501 $ilCtrl->redirectByClass("ilrepositorygui", "");
502 break;
503
504 default:
505
506 $this->participants->add($ilUser->getId(), IL_GRP_MEMBER);
507 $this->participants->sendNotification(
509 $ilUser->getId()
510 );
511 $this->participants->sendNotification(
513 $ilUser->getId()
514 );
515
516 include_once './Modules/Forum/classes/class.ilForumNotification.php';
517 ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $ilUser->getId());
518
519 if (!$_SESSION["pending_goto"]) {
520 ilUtil::sendSuccess($this->lng->txt("grp_registration_completed"), true);
521 $this->ctrl->returnToParent($this);
522 } else {
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 $DIC;
559
560 $ilUser = $DIC['ilUser'];
561 static $active = null;
562
563 if ($active !== null) {
564 return $active;
565 }
566 if (!$this->container->getMaxMembers()) {
567 return $active = false;
568 }
569 if (
570 !$this->container->isWaitingListEnabled() or
571 !$this->container->isMembershipLimited()) {
572 return $active = false;
573 }
574
575 $free = max(0, $this->container->getMaxMembers() - $this->participants->getCountMembers());
576 return $active = (!$free or $this->getWaitingList()->getCountUsers());
577 }
578}
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const GRP_REGISTRATION_DIRECT
const GRP_REGISTRATION_PASSWORD
const GRP_REGISTRATION_DEACTIVATED
const GRP_REGISTRATION_REQUEST
const IL_GRP_MEMBER
This class represents a custom property in a property form.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
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.
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.
static checkForumsExistsInsert($ref_id, $user_id=0)
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
GUI class for group registrations.
fillRegistrationType()
fill registration procedure
__construct($a_container)
Constructor.
fillMaxMembers()
fill max member informations
addCommandButtons()
Add group specific command buttons.
fillRegistrationPeriod()
show informations about the registration period
initParticipants()
Init course participants.
Waiting list for groups.
This class represents a non editable value in a property form.
static lookupRegistrationInfo($a_obj_id)
Lookup registration info @global ilDB $ilDB @global ilObjUser $ilUser @global ilLanguage $lng.
Base class for Course and Group registration.
validateAgreement()
Check Agreement.
setAccepted($a_status)
Set Agreement accepted.
validateCustomFields()
Check required course fields.
enableRegistration($a_status)
set registration disabled
getWaitingList()
Get waiting list object.
isRegistrationPossible()
check if registration is possible
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
This class represents a text property in a property form.
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static makeClickable($a_text, $detectGotoLinks=false)
makeClickable In Texten enthaltene URLs und Mail-Adressen klickbar machen
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
const ANONYMOUS_USER_ID
Definition: constants.php:25
$txt
Definition: error.php:13
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc