ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 ($this->getWaitingList()->isOnList($ilUser->getId())) {
64 $ilTabs->activateTab('leave');
65 }
66
67 switch ($next_class) {
68 default:
69 $cmd = $this->ctrl->getCmd("show");
70 $this->$cmd();
71 break;
72 }
73 return true;
74 }
75
76
83 protected function getFormTitle()
84 {
85 global $DIC;
86
87 $ilUser = $DIC['ilUser'];
88
89 if ($this->getWaitingList()->isOnList($ilUser->getId())) {
90 return $this->lng->txt('member_status');
91 }
92 return $this->lng->txt('grp_registration');
93 }
94
102 protected function fillInformations()
103 {
104 if ($this->container->getInformation()) {
105 $imp = new ilNonEditableValueGUI($this->lng->txt('crs_important_info'), '', true);
106 $value = nl2br(ilUtil::makeClickable($this->container->getInformation(), true));
107 $imp->setValue($value);
108 $this->form->addItem($imp);
109 }
110 }
111
117 protected function fillRegistrationPeriod()
118 {
119 include_once('./Services/Calendar/classes/class.ilDateTime.php');
120 $now = new ilDateTime(time(), IL_CAL_UNIX, 'UTC');
121
122 if ($this->container->isRegistrationUnlimited()) {
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 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'Services/Membership');
135 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_start'));
136 $tpl->setVariable('FIRST', ilDatePresentation::formatDate($start));
137
138 $tpl->setVariable('TXT_END', $this->lng->txt('mem_end'));
139 $tpl->setVariable('END', ilDatePresentation::formatDate($end));
140
141 $warning = $this->lng->txt('mem_reg_not_started');
142 } elseif (ilDateTime::_after($now, $end)) {
143 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'Services/Membership');
144 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_start'));
145 $tpl->setVariable('FIRST', ilDatePresentation::formatDate($start));
146
147 $tpl->setVariable('TXT_END', $this->lng->txt('mem_end'));
148 $tpl->setVariable('END', ilDatePresentation::formatDate($end));
149
150 $warning = $this->lng->txt('mem_reg_expired');
151 } else {
152 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'Services/Membership');
153 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_end'));
154 $tpl->setVariable('FIRST', ilDatePresentation::formatDate($end));
155 }
156
157 $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
158 $reg->setHtml($tpl->get());
159 if (strlen($warning)) {
160 // Disable registration
161 $this->enableRegistration(false);
162 #$reg->setAlert($warning);
163 ilUtil::sendFailure($warning);
164 }
165 $this->form->addItem($reg);
166 return true;
167 }
168
175 protected function fillMaxMembers()
176 {
177 global $DIC;
178
179 $ilUser = $DIC['ilUser'];
180
181 if (!$this->container->isMembershipLimited()) {
182 return true;
183 }
184
185 $tpl = new ilTemplate('tpl.max_members_form.html', true, true, 'Services/Membership');
186
187 if ($this->container->getMinMembers()) {
188 $tpl->setVariable('TXT_MIN', $this->lng->txt('mem_min_users'));
189 $tpl->setVariable('NUM_MIN', $this->container->getMinMembers());
190 }
191
192 if ($this->container->getMaxMembers()) {
193 $tpl->setVariable('TXT_MAX', $this->lng->txt('mem_max_users'));
194 $tpl->setVariable('NUM_MAX', $this->container->getMaxMembers());
195
196 include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
197 $reg_info = ilObjGroupAccess::lookupRegistrationInfo($this->getContainer()->getId());
198 $free = $reg_info['reg_info_free_places'];
199
200
201 if ($free) {
202 $tpl->setVariable('NUM_FREE', $free);
203 } else {
204 $tpl->setVariable('WARN_FREE', $free);
205 }
206
207 include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
208 $waiting_list = new ilGroupWaitingList($this->container->getId());
209
210 if (
211 $this->container->isWaitingListEnabled() and
212 $this->container->isMembershipLimited() and
213 (!$free or $waiting_list->getCountUsers())) {
214 if ($waiting_list->isOnList($ilUser->getId())) {
215 $tpl->setVariable('TXT_WAIT', $this->lng->txt('mem_waiting_list_position'));
216 $tpl->setVariable('NUM_WAIT', $waiting_list->getPosition($ilUser->getId()));
217 } else {
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 // Disable registration
232 $this->enableRegistration(false);
233 $alert = $this->lng->txt('mem_alert_no_places');
234 } elseif (
235 $this->container->isWaitingListEnabled() and
236 $this->container->isMembershipLimited() and
237 $waiting_list->isOnList($ilUser->getId())) {
238 // Disable registration
239 $this->enableRegistration(false);
240 } elseif (
241 !$free and
242 $this->container->isWaitingListEnabled() and
243 $this->container->isMembershipLimited()) {
244 $alert = $this->lng->txt('grp_warn_no_max_set_on_waiting_list');
245 } elseif (
246 $free and
247 $this->container->isWaitingListEnabled() and
248 $this->container->isMembershipLimited() and
249 $this->getWaitingList()->getCountUsers()) {
250 $alert = $this->lng->txt('grp_warn_wl_set_on_waiting_list');
251 }
252 }
253
254 $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
255 $max->setHtml($tpl->get());
256 if (strlen($alert)) {
257 #$max->setAlert($alert);
258 ilUtil::sendFailure($alert);
259 }
260 $this->form->addItem($max);
261 }
262
270 protected function fillRegistrationType()
271 {
272 global $DIC;
273
274 $ilUser = $DIC['ilUser'];
275
276 if ($this->getWaitingList()->isOnList($ilUser->getId())) {
277 return true;
278 }
279
280 switch ($this->container->getRegistrationType()) {
282 $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
283 $reg->setValue($this->lng->txt('grp_reg_disabled'));
284 #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
285 $this->form->addItem($reg);
286
287 // Disable registration
288 $this->enableRegistration(false);
289
290 break;
291
293 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
294 $txt->setValue($this->lng->txt('grp_pass_request'));
295
296
297 $pass = new ilTextInputGUI($this->lng->txt('passwd'), 'grp_passw');
298 $pass->setInputType('password');
299 $pass->setSize(12);
300 $pass->setMaxLength(32);
301 #$pass->setRequired(true);
302 $pass->setInfo($this->lng->txt('group_password_registration_msg'));
303
304 $txt->addSubItem($pass);
305 $this->form->addItem($txt);
306 break;
307
309
310 // no "request" info if waiting list is active
311 if ($this->isWaitingListActive()) {
312 return true;
313 }
314
315 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
316 $txt->setValue($this->lng->txt('grp_reg_request'));
317
318 $sub = new ilTextAreaInputGUI($this->lng->txt('grp_reg_subject'), 'subject');
319 $sub->setValue($_POST['subject']);
320 $sub->setInfo($this->lng->txt('group_req_registration_msg'));
321 $sub->setCols(40);
322 $sub->setRows(5);
323 if ($this->participants->isSubscriber($ilUser->getId())) {
324 $sub_data = $this->participants->getSubscriberData($ilUser->getId());
325 $sub->setValue($sub_data['subject']);
326 $sub->setInfo('');
327 ilUtil::sendFailure($this->lng->txt('grp_already_assigned'));
328 $this->enableRegistration(false);
329 }
330 $txt->addSubItem($sub);
331 $this->form->addItem($txt);
332 break;
333
335
336 // no "direct registration" info if waiting list is active
337 if ($this->isWaitingListActive()) {
338 return true;
339 }
340
341 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
342 $txt->setValue($this->lng->txt('group_req_direct'));
343
344 $this->form->addItem($txt);
345 break;
346
347 default:
348 return true;
349 }
350
351 return true;
352 }
353
358 protected function addCommandButtons()
359 {
360 global $DIC;
361
362 $ilUser = $DIC['ilUser'];
363
364 parent::addCommandButtons();
365
366
367 switch ($this->container->getRegistrationType()) {
369 if ($this->participants->isSubscriber($ilUser->getId())) {
370 $this->form->clearCommandButtons();
371 $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('grp_update_subscr_request'));
372 $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('grp_cancel_subscr_request'));
373 } else {
374 if (!$this->isRegistrationPossible()) {
375 return false;
376 }
377 $this->form->clearCommandButtons();
378 $this->form->addCommandButton('join', $this->lng->txt('grp_join_request'));
379 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
380 }
381 break;
382 }
383 return true;
384 }
385
386
393 protected function validate()
394 {
395 global $DIC;
396
397 $ilUser = $DIC['ilUser'];
398
399 if ($ilUser->getId() == ANONYMOUS_USER_ID) {
400 $this->join_error = $this->lng->txt('permission_denied');
401 return false;
402 }
403
404 if (!$this->isRegistrationPossible()) {
405 $this->join_error = $this->lng->txt('mem_error_preconditions');
406 return false;
407 }
408 if ($this->container->getRegistrationType() == GRP_REGISTRATION_PASSWORD) {
409 if (!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw']))) {
410 $this->join_error = $this->lng->txt('err_wrong_password');
411 return false;
412 }
413 if (strcmp($pass, $this->container->getPassword()) !== 0) {
414 $this->join_error = $this->lng->txt('err_wrong_password');
415 return false;
416 }
417 }
418 if (!$this->validateCustomFields()) {
419 $this->join_error = $this->lng->txt('fill_out_all_required_fields');
420 return false;
421 }
422 if (!$this->validateAgreement()) {
423 $this->join_error = $this->lng->txt($this->type . '_agreement_required');
424 return false;
425 }
426
427 return true;
428 }
429
437 protected function add()
438 {
439 global $DIC;
440
441 $ilUser = $DIC['ilUser'];
442 $tree = $DIC['tree'];
443 $rbacreview = $DIC['rbacreview'];
444 $lng = $DIC['lng'];
445 $ilCtrl = $DIC['ilCtrl'];
446
447 // set aggreement accepted
448 $this->setAccepted(true);
449
450 include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
451 $free = max(0, $this->container->getMaxMembers() - $this->participants->getCountMembers());
452 $waiting_list = new ilGroupWaitingList($this->container->getId());
453 if (
454 $this->container->isMembershipLimited() and
455 $this->container->isWaitingListEnabled() and
456 (!$free or $waiting_list->getCountUsers())) {
457 $waiting_list->addToList($ilUser->getId());
458 $info = sprintf(
459 $this->lng->txt('grp_added_to_list'),
460 $this->container->getTitle(),
461 $waiting_list->getPosition($ilUser->getId())
462 );
463
464 $this->participants->sendNotification(
466 $ilUser->getId()
467 );
468 ilUtil::sendSuccess($info, true);
469 $ilCtrl->setParameterByClass(
470 "ilrepositorygui",
471 "ref_id",
472 $tree->getParentId($this->container->getRefId())
473 );
474 $ilCtrl->redirectByClass("ilrepositorygui", "");
475 }
476
477
478 switch ($this->container->getRegistrationType()) {
480
481 $this->participants->addSubscriber($ilUser->getId());
482 $this->participants->updateSubscriptionTime($ilUser->getId(), time());
483 $this->participants->updateSubject($ilUser->getId(), ilUtil::stripSlashes($_POST['subject']));
484
485 $this->participants->sendNotification(
487 $ilUser->getId()
488 );
489
490 ilUtil::sendSuccess($this->lng->txt("application_completed"), true);
491 $ilCtrl->setParameterByClass(
492 "ilrepositorygui",
493 "ref_id",
494 $tree->getParentId($this->container->getRefId())
495 );
496 $ilCtrl->redirectByClass("ilrepositorygui", "");
497 break;
498
499 default:
500
501 $this->participants->add($ilUser->getId(), IL_GRP_MEMBER);
502 $this->participants->sendNotification(
504 $ilUser->getId()
505 );
506 $this->participants->sendNotification(
508 $ilUser->getId()
509 );
510
511 include_once './Modules/Forum/classes/class.ilForumNotification.php';
512 ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $ilUser->getId());
513
514 if (!$_SESSION["pending_goto"]) {
515 ilUtil::sendSuccess($this->lng->txt("grp_registration_completed"), true);
516 $this->ctrl->returnToParent($this);
517 } else {
518 $tgt = $_SESSION["pending_goto"];
519 unset($_SESSION["pending_goto"]);
520 ilUtil::redirect($tgt);
521 }
522 break;
523 }
524 }
525
526
532 protected function initParticipants()
533 {
534 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
535 $this->participants = ilGroupParticipants::_getInstanceByObjId($this->obj_id);
536 }
537
542 protected function initWaitingList()
543 {
544 include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
545 $this->waiting_list = new ilGroupWaitingList($this->container->getId());
546 }
547
551 protected function isWaitingListActive()
552 {
553 global $DIC;
554
555 $ilUser = $DIC['ilUser'];
556 static $active = null;
557
558 if ($active !== null) {
559 return $active;
560 }
561 if (!$this->container->getMaxMembers()) {
562 return $active = false;
563 }
564 if (
565 !$this->container->isWaitingListEnabled() or
566 !$this->container->isMembershipLimited()) {
567 return $active = false;
568 }
569
570 $free = max(0, $this->container->getMaxMembers() - $this->participants->getCountMembers());
571 return $active = (!$free or $this->getWaitingList()->getCountUsers());
572 }
573}
$_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
$txt
Definition: error.php:13
global $ilCtrl
Definition: ilias.php:18
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46