ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
44 $ilTabs->activateTab('leave');
45 }
46
47 if(!$GLOBALS['ilAccess']->checkAccess('join','',$this->getRefId()))
48 {
49 $this->ctrl->setReturn($this->parent_gui,'infoScreen');
50 $this->ctrl->returnToParent($this);
51 return FALSE;
52 }
53
54 $next_class = $this->ctrl->getNextClass($this);
55 switch($next_class)
56 {
57 default:
58 $cmd = $this->ctrl->getCmd("show");
59 $this->$cmd();
60 break;
61 }
62 return true;
63 }
64
71 protected function getFormTitle()
72 {
73 global $ilUser;
74
75 if($this->getWaitingList()->isOnList($ilUser->getId()))
76 {
77 return $this->lng->txt('member_status');
78 }
79 return $this->lng->txt('crs_registration');
80 }
81
89 protected function fillInformations()
90 {
91 if($this->container->getImportantInformation())
92 {
93 $imp = new ilNonEditableValueGUI($this->lng->txt('crs_important_info'), "", true);
94 $value = nl2br(ilUtil::makeClickable($this->container->getImportantInformation(), true));
95 $imp->setValue($value);
96 $this->form->addItem($imp);
97 }
98
99 if($this->container->getSyllabus())
100 {
101 $syl = new ilNonEditableValueGUI($this->lng->txt('crs_syllabus'), "", true);
102 $value = nl2br(ilUtil::makeClickable ($this->container->getSyllabus(), true));
103 $syl->setValue($value);
104 $this->form->addItem($syl);
105 }
106 }
107
113 protected function fillRegistrationPeriod()
114 {
115 include_once('./Services/Calendar/classes/class.ilDateTime.php');
116 $now = new ilDateTime(time(),IL_CAL_UNIX,'UTC');
117
118 if($this->container->getSubscriptionUnlimitedStatus())
119 {
120 $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_period'));
121 $reg->setValue($this->lng->txt('mem_unlimited'));
122 $this->form->addItem($reg);
123 return true;
124 }
125 elseif($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
126 {
127 return true;
128 }
129
130 $start = new ilDateTime($this->container->getSubscriptionStart(),IL_CAL_UNIX,'UTC');
131 $end = new ilDateTime($this->container->getSubscriptionEnd(),IL_CAL_UNIX,'UTC');
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
154 $warning = $this->lng->txt('mem_reg_expired');
155 }
156 else
157 {
158 $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
159 $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_end'));
160 $tpl->setVariable('FIRST',ilDatePresentation::formatDate($end));
161 }
162
163 $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
164 $reg->setHtml($tpl->get());
165 if(strlen($warning))
166 {
167 // Disable registration
168 $this->enableRegistration(false);
169 ilUtil::sendFailure($warning);
170 #$reg->setAlert($warning);
171 }
172 $this->form->addItem($reg);
173 return true;
174 }
175
176
184 protected function fillMaxMembers()
185 {
186 global $ilUser;
187
188 if(!$this->container->isSubscriptionMembershipLimited())
189 {
190 return true;
191 }
192 $tpl = new ilTemplate('tpl.max_members_form.html',true,true,'Services/Membership');
193
194 if($this->container->getSubscriptionMinMembers())
195 {
196 $tpl->setVariable('TXT_MIN',$this->lng->txt('mem_min_users').':');
197 $tpl->setVariable('NUM_MIN',$this->container->getSubscriptionMinMembers());
198 }
199
200 if($this->container->getSubscriptionMaxMembers())
201 {
202 $tpl->setVariable('TXT_MAX',$this->lng->txt('mem_max_users'));
203 $tpl->setVariable('NUM_MAX',$this->container->getSubscriptionMaxMembers());
204
205 $tpl->setVariable('TXT_FREE',$this->lng->txt('mem_free_places').":");
206 include_once './Modules/Course/classes/class.ilObjCourseAccess.php';
207 $reg_info = ilObjCourseAccess::lookupRegistrationInfo($this->getContainer()->getId());
208 $free = $reg_info['reg_info_free_places'];
209
210 if($free)
211 {
212 $tpl->setVariable('NUM_FREE',$free);
213 }
214 else
215 {
216 $tpl->setVariable('WARN_FREE',$free);
217 }
218
219 include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
220 $waiting_list = new ilCourseWaitingList($this->container->getId());
221 if(
222 $this->container->isSubscriptionMembershipLimited() and
223 $this->container->enabledWaitingList() and
224 (!$free or $waiting_list->getCountUsers()))
225 {
226 if($waiting_list->isOnList($ilUser->getId()))
227 {
228 $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list_position'));
229 $tpl->setVariable('NUM_WAIT',$waiting_list->getPosition($ilUser->getId()));
230
231 }
232 else
233 {
234 $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list'));
235 if($free and $waiting_list->getCountUsers())
236 $tpl->setVariable('WARN_WAIT',$waiting_list->getCountUsers());
237 else
238 $tpl->setVariable('NUM_WAIT',$waiting_list->getCountUsers());
239 }
240 }
241
242 $alert = '';
243 if(
244 !$free and
245 !$this->container->enabledWaitingList())
246 {
247 // Disable registration
248 $this->enableRegistration(false);
249 ilUtil::sendFailure($this->lng->txt('mem_alert_no_places'));
250 #$alert = $this->lng->txt('mem_alert_no_places');
251 }
252 elseif(
253 $this->container->enabledWaitingList() and
254 $this->container->isSubscriptionMembershipLimited() and
255 $waiting_list->isOnList($ilUser->getId())
256 )
257 {
258 // Disable registration
259 $this->enableRegistration(false);
260 }
261 elseif(
262 !$free and
263 $this->container->enabledWaitingList() and
264 $this->container->isSubscriptionMembershipLimited())
265
266 {
267 ilUtil::sendFailure($this->lng->txt('crs_warn_no_max_set_on_waiting_list'));
268 #$alert = $this->lng->txt('crs_warn_no_max_set_on_waiting_list');
269 }
270 elseif(
271 $free and
272 $this->container->enabledWaitingList() and
273 $this->container->isSubscriptionMembershipLimited() and
274 $this->getWaitingList()->getCountUsers())
275 {
276 ilUtil::sendFailure($this->lng->txt('crs_warn_wl_set_on_waiting_list'));
277 #$alert = $this->lng->txt('crs_warn_wl_set_on_waiting_list');
278 }
279 }
280
281 $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
282 $max->setHtml($tpl->get());
283 if(strlen($alert))
284 {
285 $max->setAlert($alert);
286 }
287 $this->form->addItem($max);
288 return true;
289 }
290
297 protected function fillRegistrationType()
298 {
299 global $ilUser;
300
301 if($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
302 {
303 $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_type'));
304 #$reg->setHtml($this->lng->txt('crs_info_reg_deactivated'));
305 $reg->setAlert($this->lng->txt('crs_info_reg_deactivated'));
306 #ilUtil::sendFailure($this->lng->txt('crs_info_reg_deactivated'));
307 #$reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
308 #$reg->setValue($this->lng->txt('crs_info_reg_deactivated'));
309 #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
310 $this->form->addItem($reg);
311
312 // Disable registration
313 $this->enableRegistration(false);
314 return true;
315 }
316
317 switch($this->container->getSubscriptionType())
318 {
320
321 // no "request" info if waiting list is active
322 if($this->isWaitingListActive())
323 {
324 return true;
325 }
326
327 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
328 $txt->setValue($this->lng->txt('crs_info_reg_direct'));
329
330 $this->form->addItem($txt);
331 break;
332
334 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
335 $txt->setValue($this->lng->txt('crs_subscription_options_password'));
336
337
338 $pass = new ilTextInputGUI($this->lng->txt('passwd'),'grp_passw');
339 $pass->setInputType('password');
340 $pass->setSize(12);
341 $pass->setMaxLength(32);
342 #$pass->setRequired(true);
343 $pass->setInfo($this->lng->txt('crs_info_reg_password'));
344
345 $txt->addSubItem($pass);
346 $this->form->addItem($txt);
347 break;
348
350
351 // no "request" info if waiting list is active
352 if($this->isWaitingListActive())
353 {
354 return true;
355 }
356
357 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
358 $txt->setValue($this->lng->txt('crs_subscription_options_confirmation'));
359
360 $sub = new ilTextAreaInputGUI($this->lng->txt('crs_reg_subject'),'subject');
361 $sub->setValue($_POST['subject']);
362 $sub->setInfo($this->lng->txt('crs_info_reg_confirmation'));
363 $sub->setCols(40);
364 $sub->setRows(5);
365 if($this->participants->isSubscriber($ilUser->getId()))
366 {
367 $sub_data = $this->participants->getSubscriberData($ilUser->getId());
368 $sub->setValue($sub_data['subject']);
369 $sub->setInfo('');
370 ilUtil::sendFailure($this->lng->txt('crs_reg_user_already_subscribed'));
371 $this->enableRegistration(false);
372 }
373 $txt->addSubItem($sub);
374 $this->form->addItem($txt);
375 break;
376
377
378 default:
379 return true;
380 }
381
382 return true;
383 }
384
389 protected function addCommandButtons()
390 {
391 global $ilUser;
392
393 parent::addCommandButtons();
394
395
396 switch($this->container->getSubscriptionType())
397 {
399 if($this->participants->isSubscriber($ilUser->getId()))
400 {
401 $this->form->clearCommandButtons();
402 $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('crs_update_subscr_request'));
403 $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('crs_cancel_subscr_request'));
404 }
405 elseif($this->isRegistrationPossible())
406 {
407 $this->form->clearCommandButtons();
408 $this->form->addCommandButton('join', $this->lng->txt('crs_join_request'));
409 $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
410 }
411 break;
412 }
413 if(!$this->isRegistrationPossible())
414 {
415 return false;
416 }
417
418 return true;
419 }
420
428 protected function validate()
429 {
430 global $ilUser;
431
432 if($ilUser->getId() == ANONYMOUS_USER_ID)
433 {
434 $this->join_error = $this->lng->txt('permission_denied');
435 return false;
436 }
437
438 // Set aggrement to not accepted
439 $this->setAccepted(false);
440
441 if(!$this->isRegistrationPossible())
442 {
443 $this->join_error = $this->lng->txt('mem_error_preconditions');
444 return false;
445 }
446 if($this->container->getSubscriptionType() == IL_CRS_SUBSCRIPTION_PASSWORD)
447 {
448 if(!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw'])))
449 {
450 $this->join_error = $this->lng->txt('crs_password_required');
451 return false;
452 }
453 if(strcmp($pass,$this->container->getSubscriptionPassword()) !== 0)
454 {
455 $this->join_error = $this->lng->txt('crs_password_not_valid');
456 return false;
457 }
458 }
459 if(!$this->validateCustomFields())
460 {
461 $this->join_error = $this->lng->txt('fill_out_all_required_fields');
462 return false;
463 }
464 if(!$this->validateAgreement())
465 {
466 $this->join_error = $this->lng->txt('crs_agreement_required');
467 return false;
468 }
469
470 return true;
471 }
472
480 protected function add()
481 {
482 global $ilUser,$tree, $ilCtrl;
483
484 // TODO: language vars
485
486 // set aggreement accepted
487 $this->setAccepted(true);
488
489 include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
490 $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
491 $waiting_list = new ilCourseWaitingList($this->container->getId());
492 if($this->container->isSubscriptionMembershipLimited() and $this->container->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
493 {
494 $waiting_list->addToList($ilUser->getId());
495 $info = sprintf($this->lng->txt('crs_added_to_list'),
496 $waiting_list->getPosition($ilUser->getId()));
498
499 $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST,$ilUser->getId());
500 $this->participants->sendNotification($this->participants->NOTIFY_WAITING_LIST,$ilUser->getId());
501 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
502 $tree->getParentId($this->container->getRefId()));
503 $ilCtrl->redirectByClass("ilrepositorygui", "");
504 }
505
506 switch($this->container->getSubscriptionType())
507 {
509 $this->participants->addSubscriber($ilUser->getId());
510 $this->participants->updateSubscriptionTime($ilUser->getId(),time());
511 $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['subject']));
512 $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST,$ilUser->getId());
513
514 ilUtil::sendSuccess($this->lng->txt("application_completed"),true);
515 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
516 $tree->getParentId($this->container->getRefId()));
517 $ilCtrl->redirectByClass("ilrepositorygui", "");
518 break;
519
520 default:
521
522 if($this->container->isSubscriptionMembershipLimited() && $this->container->getSubscriptionMaxMembers())
523 {
524 $success = $GLOBALS['rbacadmin']->assignUserLimited(
525 ilParticipants::getDefaultMemberRole($this->container->getRefId()),
526 $ilUser->getId(),
527 $this->container->getSubscriptionMaxMembers(),
528 array(ilParticipants::getDefaultMemberRole($this->container->getRefId()))
529 );
530 if(!$success)
531 {
532 ilUtil::sendFailure($this->lng->txt('crs_subscription_failed_limit'));
533 $this->show();
534 return FALSE;
535 }
536 }
537
538 $this->participants->add($ilUser->getId(),IL_CRS_MEMBER);
539 $this->participants->sendNotification($this->participants->NOTIFY_ADMINS,$ilUser->getId());
540 $this->participants->sendNotification($this->participants->NOTIFY_REGISTERED,$ilUser->getId());
541
542 include_once './Modules/Forum/classes/class.ilForumNotification.php';
543 ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $ilUser->getId());
544
545 if($this->container->getType() == "crs")
546 {
547 $this->container->checkLPStatusSync($ilUser->getId());
548 }
549
550 if(!$_SESSION["pending_goto"])
551 {
552 ilUtil::sendSuccess($this->lng->txt("crs_subscription_successful"),true);
553 $this->ctrl->returnToParent($this);
554 }
555 else
556 {
557 $tgt = $_SESSION["pending_goto"];
558 unset($_SESSION["pending_goto"]);
559 ilUtil::redirect($tgt);
560 }
561 break;
562 }
563 }
564
565
566
567
573 protected function initParticipants()
574 {
575 include_once('./Modules/Course/classes/class.ilCourseParticipants.php');
576 $this->participants = ilCourseParticipants::_getInstanceByObjId($this->obj_id);
577 }
578
579
584 protected function initWaitingList()
585 {
586 include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
587 $this->waiting_list = new ilCourseWaitingList($this->container->getId());
588 }
589
593 protected function isWaitingListActive()
594 {
595 global $ilUser;
596 static $active = null;
597
598 if($active !== null)
599 {
600 return $active;
601 }
602 if(!$this->container->enabledWaitingList() or !$this->container->isSubscriptionMembershipLimited())
603 {
604 return $active = false;
605 }
606 if(!$this->container->getSubscriptionMaxMembers())
607 {
608 return $active = false;
609 }
610
611 $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
612 return $active = (!$free or $this->getWaitingList()->getCountUsers());
613 }
614}
615?>
$success
Definition: Utf8Test.php:87
$_SESSION["AccountId"]
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)
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.
show()
show registration form
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.
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)
http redirect to other 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
$_POST['username']
Definition: cron.php:12
$txt
Definition: error.php:12
$info
Definition: example_052.php:80
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
global $ilUser
Definition: imgupload.php:15