ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilCourseRegistrationGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once('./Services/Membership/classes/class.ilRegistrationGUI.php');
5
17{
18 private $parent_gui = null;
19
26 public function __construct($a_container, $a_parent_gui)
27 {
28 parent::__construct($a_container);
29
30 $this->parent_gui = $a_parent_gui;
31 }
32
38 public function executeCommand()
39 {
40 global $ilTabs,$ilUser;
41
42 if ($this->getWaitingList()->isOnList($ilUser->getId())) {
43 $ilTabs->activateTab('leave');
44 }
45
46 if (!$GLOBALS['ilAccess']->checkAccess('join', '', $this->getRefId())) {
47 $this->ctrl->setReturn($this->parent_gui, 'infoScreen');
48 $this->ctrl->returnToParent($this);
49 return false;
50 }
51
52 $next_class = $this->ctrl->getNextClass($this);
53 switch ($next_class) {
54 default:
55 $cmd = $this->ctrl->getCmd("show");
56 $this->$cmd();
57 break;
58 }
59 return true;
60 }
61
68 protected function getFormTitle()
69 {
70 global $ilUser;
71
72 if ($this->getWaitingList()->isOnList($ilUser->getId())) {
73 return $this->lng->txt('member_status');
74 }
75 return $this->lng->txt('crs_registration');
76 }
77
85 protected function fillInformations()
86 {
87 if ($this->container->getImportantInformation()) {
88 $imp = new ilNonEditableValueGUI($this->lng->txt('crs_important_info'), "", true);
89 $value = nl2br(ilUtil::makeClickable($this->container->getImportantInformation(), true));
90 $imp->setValue($value);
91 $this->form->addItem($imp);
92 }
93
94 if ($this->container->getSyllabus()) {
95 $syl = new ilNonEditableValueGUI($this->lng->txt('crs_syllabus'), "", true);
96 $value = nl2br(ilUtil::makeClickable($this->container->getSyllabus(), true));
97 $syl->setValue($value);
98 $this->form->addItem($syl);
99 }
100 }
101
107 protected function fillRegistrationPeriod()
108 {
109 include_once('./Services/Calendar/classes/class.ilDateTime.php');
110 $now = new ilDateTime(time(), IL_CAL_UNIX, 'UTC');
111
112 if ($this->container->getSubscriptionUnlimitedStatus()) {
113 $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_period'));
114 $reg->setValue($this->lng->txt('mem_unlimited'));
115 $this->form->addItem($reg);
116 return true;
117 } elseif ($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED) {
118 return true;
119 }
120
121 $start = new ilDateTime($this->container->getSubscriptionStart(), IL_CAL_UNIX, 'UTC');
122 $end = new ilDateTime($this->container->getSubscriptionEnd(), IL_CAL_UNIX, 'UTC');
123
124 if (ilDateTime::_before($now, $start)) {
125 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'Services/Membership');
126 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_start'));
127 $tpl->setVariable('FIRST', ilDatePresentation::formatDate($start));
128
129 $tpl->setVariable('TXT_END', $this->lng->txt('mem_end'));
130 $tpl->setVariable('END', ilDatePresentation::formatDate($end));
131
132 $warning = $this->lng->txt('mem_reg_not_started');
133 } elseif (ilDateTime::_after($now, $end)) {
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
142 $warning = $this->lng->txt('mem_reg_expired');
143 } else {
144 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'Services/Membership');
145 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_end'));
146 $tpl->setVariable('FIRST', ilDatePresentation::formatDate($end));
147 }
148
149 $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
150 $reg->setHtml($tpl->get());
151 if (strlen($warning)) {
152 // Disable registration
153 $this->enableRegistration(false);
155 #$reg->setAlert($warning);
156 }
157 $this->form->addItem($reg);
158 return true;
159 }
160
161
169 protected function fillMaxMembers()
170 {
171 global $ilUser;
172
173 if (!$this->container->isSubscriptionMembershipLimited()) {
174 return true;
175 }
176 $tpl = new ilTemplate('tpl.max_members_form.html', true, true, 'Services/Membership');
177
178 if ($this->container->getSubscriptionMinMembers()) {
179 $tpl->setVariable('TXT_MIN', $this->lng->txt('mem_min_users') . ':');
180 $tpl->setVariable('NUM_MIN', $this->container->getSubscriptionMinMembers());
181 }
182
183 if ($this->container->getSubscriptionMaxMembers()) {
184 $tpl->setVariable('TXT_MAX', $this->lng->txt('mem_max_users'));
185 $tpl->setVariable('NUM_MAX', $this->container->getSubscriptionMaxMembers());
186
187 $tpl->setVariable('TXT_FREE', $this->lng->txt('mem_free_places') . ":");
188 include_once './Modules/Course/classes/class.ilObjCourseAccess.php';
189 $reg_info = ilObjCourseAccess::lookupRegistrationInfo($this->getContainer()->getId());
190 $free = $reg_info['reg_info_free_places'];
191
192 if ($free) {
193 $tpl->setVariable('NUM_FREE', $free);
194 } else {
195 $tpl->setVariable('WARN_FREE', $free);
196 }
197
198 include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
199 $waiting_list = new ilCourseWaitingList($this->container->getId());
200 if (
201 $this->container->isSubscriptionMembershipLimited() and
202 $this->container->enabledWaitingList() and
203 (!$free or $waiting_list->getCountUsers())) {
204 if ($waiting_list->isOnList($ilUser->getId())) {
205 $tpl->setVariable('TXT_WAIT', $this->lng->txt('mem_waiting_list_position'));
206 $tpl->setVariable('NUM_WAIT', $waiting_list->getPosition($ilUser->getId()));
207 } else {
208 $tpl->setVariable('TXT_WAIT', $this->lng->txt('mem_waiting_list'));
209 if ($free and $waiting_list->getCountUsers()) {
210 $tpl->setVariable('WARN_WAIT', $waiting_list->getCountUsers());
211 } else {
212 $tpl->setVariable('NUM_WAIT', $waiting_list->getCountUsers());
213 }
214 }
215 }
216
217 $alert = '';
218 if (
219 !$free and
220 !$this->container->enabledWaitingList()) {
221 // Disable registration
222 $this->enableRegistration(false);
223 ilUtil::sendFailure($this->lng->txt('mem_alert_no_places'));
224 #$alert = $this->lng->txt('mem_alert_no_places');
225 } elseif (
226 $this->container->enabledWaitingList() and
227 $this->container->isSubscriptionMembershipLimited() and
228 $waiting_list->isOnList($ilUser->getId())
229 ) {
230 // Disable registration
231 $this->enableRegistration(false);
232 } elseif (
233 !$free and
234 $this->container->enabledWaitingList() and
235 $this->container->isSubscriptionMembershipLimited()) {
236 ilUtil::sendFailure($this->lng->txt('crs_warn_no_max_set_on_waiting_list'));
237 #$alert = $this->lng->txt('crs_warn_no_max_set_on_waiting_list');
238 } elseif (
239 $free and
240 $this->container->enabledWaitingList() and
241 $this->container->isSubscriptionMembershipLimited() and
242 $this->getWaitingList()->getCountUsers()) {
243 ilUtil::sendFailure($this->lng->txt('crs_warn_wl_set_on_waiting_list'));
244 #$alert = $this->lng->txt('crs_warn_wl_set_on_waiting_list');
245 }
246 }
247
248 $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
249 $max->setHtml($tpl->get());
250 if (strlen($alert)) {
251 $max->setAlert($alert);
252 }
253 $this->form->addItem($max);
254 return true;
255 }
256
263 protected function fillRegistrationType()
264 {
265 global $ilUser;
266
267 if ($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED) {
268 $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_type'));
269 #$reg->setHtml($this->lng->txt('crs_info_reg_deactivated'));
270 $reg->setAlert($this->lng->txt('crs_info_reg_deactivated'));
271 #ilUtil::sendFailure($this->lng->txt('crs_info_reg_deactivated'));
272 #$reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
273 #$reg->setValue($this->lng->txt('crs_info_reg_deactivated'));
274 #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
275 $this->form->addItem($reg);
276
277 // Disable registration
278 $this->enableRegistration(false);
279 return true;
280 }
281
282 switch ($this->container->getSubscriptionType()) {
284
285 // no "request" info if waiting list is active
286 if ($this->isWaitingListActive()) {
287 return true;
288 }
289
290 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
291 $txt->setValue($this->lng->txt('crs_info_reg_direct'));
292
293 $this->form->addItem($txt);
294 break;
295
297 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
298 $txt->setValue($this->lng->txt('crs_subscription_options_password'));
299
300
301 $pass = new ilTextInputGUI($this->lng->txt('passwd'), 'grp_passw');
302 $pass->setInputType('password');
303 $pass->setSize(12);
304 $pass->setMaxLength(32);
305 #$pass->setRequired(true);
306 $pass->setInfo($this->lng->txt('crs_info_reg_password'));
307
308 $txt->addSubItem($pass);
309 $this->form->addItem($txt);
310 break;
311
313
314 // no "request" info if waiting list is active
315 if ($this->isWaitingListActive()) {
316 return true;
317 }
318
319 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
320 $txt->setValue($this->lng->txt('crs_subscription_options_confirmation'));
321
322 $sub = new ilTextAreaInputGUI($this->lng->txt('crs_reg_subject'), 'subject');
323 $sub->setValue($_POST['subject']);
324 $sub->setInfo($this->lng->txt('crs_info_reg_confirmation'));
325 $sub->setCols(40);
326 $sub->setRows(5);
327 if ($this->participants->isSubscriber($ilUser->getId())) {
328 $sub_data = $this->participants->getSubscriberData($ilUser->getId());
329 $sub->setValue($sub_data['subject']);
330 $sub->setInfo('');
331 ilUtil::sendFailure($this->lng->txt('crs_reg_user_already_subscribed'));
332 $this->enableRegistration(false);
333 }
334 $txt->addSubItem($sub);
335 $this->form->addItem($txt);
336 break;
337
338
339 default:
340 return true;
341 }
342
343 return true;
344 }
345
350 protected function addCommandButtons()
351 {
352 global $ilUser;
353
354 parent::addCommandButtons();
355
356
357 switch ($this->container->getSubscriptionType()) {
359 if ($this->participants->isSubscriber($ilUser->getId())) {
360 $this->form->clearCommandButtons();
361 $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('crs_update_subscr_request'));
362 $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('crs_cancel_subscr_request'));
363 } elseif ($this->isRegistrationPossible()) {
364 $this->form->clearCommandButtons();
365 $this->form->addCommandButton('join', $this->lng->txt('crs_join_request'));
366 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
367 }
368 break;
369 }
370 if (!$this->isRegistrationPossible()) {
371 return false;
372 }
373
374 return true;
375 }
376
384 protected function validate()
385 {
386 global $ilUser;
387
388 if ($ilUser->getId() == ANONYMOUS_USER_ID) {
389 $this->join_error = $this->lng->txt('permission_denied');
390 return false;
391 }
392
393 // Set aggrement to not accepted
394 $this->setAccepted(false);
395
396 if (!$this->isRegistrationPossible()) {
397 $this->join_error = $this->lng->txt('mem_error_preconditions');
398 return false;
399 }
400 if ($this->container->getSubscriptionType() == IL_CRS_SUBSCRIPTION_PASSWORD) {
401 if (!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw']))) {
402 $this->join_error = $this->lng->txt('crs_password_required');
403 return false;
404 }
405 if (strcmp($pass, $this->container->getSubscriptionPassword()) !== 0) {
406 $this->join_error = $this->lng->txt('crs_password_not_valid');
407 return false;
408 }
409 }
410 if (!$this->validateCustomFields()) {
411 $this->join_error = $this->lng->txt('fill_out_all_required_fields');
412 return false;
413 }
414 if (!$this->validateAgreement()) {
415 $this->join_error = $this->lng->txt('crs_agreement_required');
416 return false;
417 }
418
419 return true;
420 }
421
429 protected function add()
430 {
431 global $ilUser,$tree, $ilCtrl;
432
433 // TODO: language vars
434
435 // set aggreement accepted
436 $this->setAccepted(true);
437
438 include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
439 $free = max(0, $this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
440 $waiting_list = new ilCourseWaitingList($this->container->getId());
441 if ($this->container->isSubscriptionMembershipLimited() and $this->container->enabledWaitingList() and (!$free or $waiting_list->getCountUsers())) {
442 $waiting_list->addToList($ilUser->getId());
443 $info = sprintf(
444 $this->lng->txt('crs_added_to_list'),
445 $waiting_list->getPosition($ilUser->getId())
446 );
448
449 $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST, $ilUser->getId());
450 $this->participants->sendNotification($this->participants->NOTIFY_WAITING_LIST, $ilUser->getId());
451 $ilCtrl->setParameterByClass(
452 "ilrepositorygui",
453 "ref_id",
454 $tree->getParentId($this->container->getRefId())
455 );
456 $ilCtrl->redirectByClass("ilrepositorygui", "");
457 }
458
459 switch ($this->container->getSubscriptionType()) {
461 $this->participants->addSubscriber($ilUser->getId());
462 $this->participants->updateSubscriptionTime($ilUser->getId(), time());
463 $this->participants->updateSubject($ilUser->getId(), ilUtil::stripSlashes($_POST['subject']));
464 $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST, $ilUser->getId());
465
466 ilUtil::sendSuccess($this->lng->txt("application_completed"), true);
467 $ilCtrl->setParameterByClass(
468 "ilrepositorygui",
469 "ref_id",
470 $tree->getParentId($this->container->getRefId())
471 );
472 $ilCtrl->redirectByClass("ilrepositorygui", "");
473 break;
474
475 default:
476
477 if ($this->container->isSubscriptionMembershipLimited() && $this->container->getSubscriptionMaxMembers()) {
478 $success = $GLOBALS['rbacadmin']->assignUserLimited(
479 ilParticipants::getDefaultMemberRole($this->container->getRefId()),
480 $ilUser->getId(),
481 $this->container->getSubscriptionMaxMembers(),
482 array(ilParticipants::getDefaultMemberRole($this->container->getRefId()))
483 );
484 if (!$success) {
485 ilUtil::sendFailure($this->lng->txt('crs_subscription_failed_limit'));
486 $this->show();
487 return false;
488 }
489 }
490
491 $this->participants->add($ilUser->getId(), IL_CRS_MEMBER);
492 $this->participants->sendNotification($this->participants->NOTIFY_ADMINS, $ilUser->getId());
493 $this->participants->sendNotification($this->participants->NOTIFY_REGISTERED, $ilUser->getId());
494
495 include_once './Modules/Forum/classes/class.ilForumNotification.php';
496 ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $ilUser->getId());
497
498 if ($this->container->getType() == "crs") {
499 $this->container->checkLPStatusSync($ilUser->getId());
500 }
501
502 if (!$_SESSION["pending_goto"]) {
503 ilUtil::sendSuccess($this->lng->txt("crs_subscription_successful"), true);
504 $this->ctrl->returnToParent($this);
505 } else {
506 $tgt = $_SESSION["pending_goto"];
507 unset($_SESSION["pending_goto"]);
508 ilUtil::redirect($tgt);
509 }
510 break;
511 }
512 }
513
514
515
516
522 protected function initParticipants()
523 {
524 include_once('./Modules/Course/classes/class.ilCourseParticipants.php');
525 $this->participants = ilCourseParticipants::_getInstanceByObjId($this->obj_id);
526 }
527
528
533 protected function initWaitingList()
534 {
535 include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
536 $this->waiting_list = new ilCourseWaitingList($this->container->getId());
537 }
538
542 protected function isWaitingListActive()
543 {
544 global $ilUser;
545 static $active = null;
546
547 if ($active !== null) {
548 return $active;
549 }
550 if (!$this->container->enabledWaitingList() or !$this->container->isSubscriptionMembershipLimited()) {
551 return $active = false;
552 }
553 if (!$this->container->getSubscriptionMaxMembers()) {
554 return $active = false;
555 }
556
557 $free = max(0, $this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
558 return $active = (!$free or $this->getWaitingList()->getCountUsers());
559 }
560}
sprintf('%.4f', $callTime)
$success
Definition: Utf8Test.php:86
$warning
Definition: X509warning.php:13
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CRS_SUBSCRIPTION_PASSWORD
const IL_CRS_SUBSCRIPTION_CONFIRMATION
const IL_CRS_SUBSCRIPTION_DEACTIVATED
const IL_CRS_SUBSCRIPTION_DIRECT
const IL_CAL_UNIX
const IL_CRS_MEMBER
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
GUI class for course registrations.
initParticipants()
Init course participants.
fillRegistrationPeriod()
show informations about the registration period
validate()
Validate subscription request.
addCommandButtons()
Add group specific command buttons.
__construct($a_container, $a_parent_gui)
Constructor.
fillRegistrationType()
fill registration type
This class represents a custom property in a property form.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=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)
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.
static getDefaultMemberRole($a_ref_id)
Base class for Course and Group registration.
getContainer()
Parent object.
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.
show(ilPropertyFormGUI $form=null)
show registration form
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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:11
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilCtrl
Definition: ilias.php:18
$end
Definition: saml1-acs.php:18
$info
Definition: index.php:5
$ilUser
Definition: imgupload.php:18