ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCourseRegistrationGUI.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 
25 include_once('./Services/Membership/classes/class.ilRegistrationGUI.php');
26 
38 {
39  private $parent_gui = null;
40 
47  public function __construct($a_container, $a_parent_gui)
48  {
49  parent::__construct($a_container);
50 
51  $this->parent_gui = $a_parent_gui;
52  }
53 
59  public function executeCommand()
60  {
61  global $ilTabs,$ilUser;
62 
63  if($this->getWaitingList()->isOnList($ilUser->getId()))
64  {
65  $ilTabs->activateTab('leave');
66  }
67 
68  if(!$GLOBALS['ilAccess']->checkAccess('join','',$this->getRefId()))
69  {
70  $this->ctrl->setReturn($this->parent_gui,'infoScreen');
71  $this->ctrl->returnToParent($this);
72  return FALSE;
73  }
74 
75  $next_class = $this->ctrl->getNextClass($this);
76  switch($next_class)
77  {
78  default:
79  $cmd = $this->ctrl->getCmd("show");
80  $this->$cmd();
81  break;
82  }
83  return true;
84  }
85 
92  protected function getFormTitle()
93  {
94  global $ilUser;
95 
96  if($this->getWaitingList()->isOnList($ilUser->getId()))
97  {
98  return $this->lng->txt('member_status');
99  }
100  return $this->lng->txt('crs_registration');
101  }
102 
110  protected function fillInformations()
111  {
112  if($this->container->getImportantInformation())
113  {
114  $imp = new ilNonEditableValueGUI($this->lng->txt('crs_important_info'), "", true);
115  $value = nl2br(ilUtil::makeClickable($this->container->getImportantInformation(), true));
116  $imp->setValue($value);
117  $this->form->addItem($imp);
118  }
119 
120  if($this->container->getSyllabus())
121  {
122  $syl = new ilNonEditableValueGUI($this->lng->txt('crs_syllabus'), "", true);
123  $value = nl2br(ilUtil::makeClickable ($this->container->getSyllabus(), true));
124  $syl->setValue($value);
125  $this->form->addItem($syl);
126  }
127  }
128 
134  protected function fillRegistrationPeriod()
135  {
136  include_once('./Services/Calendar/classes/class.ilDateTime.php');
137  $now = new ilDateTime(time(),IL_CAL_UNIX,'UTC');
138 
139  if($this->container->getSubscriptionUnlimitedStatus())
140  {
141  $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_period'));
142  $reg->setValue($this->lng->txt('mem_unlimited'));
143  $this->form->addItem($reg);
144  return true;
145  }
146  elseif($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
147  {
148  return true;
149  }
150 
151  $start = new ilDateTime($this->container->getSubscriptionStart(),IL_CAL_UNIX,'UTC');
152  $end = new ilDateTime($this->container->getSubscriptionEnd(),IL_CAL_UNIX,'UTC');
153 
154  if(ilDateTime::_before($now,$start))
155  {
156  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
157  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_start'));
158  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($start));
159 
160  $tpl->setVariable('TXT_END',$this->lng->txt('mem_end'));
161  $tpl->setVariable('END',ilDatePresentation::formatDate($end));
162 
163  $warning = $this->lng->txt('mem_reg_not_started');
164  }
165  elseif(ilDateTime::_after($now,$end))
166  {
167  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
168  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_start'));
169  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($start));
170 
171  $tpl->setVariable('TXT_END',$this->lng->txt('mem_end'));
172  $tpl->setVariable('END',ilDatePresentation::formatDate($end));
173 
174 
175  $warning = $this->lng->txt('mem_reg_expired');
176  }
177  else
178  {
179  $tpl = new ilTemplate('tpl.registration_period_form.html',true,true,'Services/Membership');
180  $tpl->setVariable('TXT_FIRST',$this->lng->txt('mem_end'));
181  $tpl->setVariable('FIRST',ilDatePresentation::formatDate($end));
182  }
183 
184  $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
185  $reg->setHtml($tpl->get());
186  if(strlen($warning))
187  {
188  // Disable registration
189  $this->enableRegistration(false);
190  ilUtil::sendFailure($warning);
191  #$reg->setAlert($warning);
192  }
193  $this->form->addItem($reg);
194  return true;
195  }
196 
197 
205  protected function fillMaxMembers()
206  {
207  global $ilUser;
208 
209  if(!$this->container->isSubscriptionMembershipLimited())
210  {
211  return true;
212  }
213  $tpl = new ilTemplate('tpl.max_members_form.html',true,true,'Services/Membership');
214  $tpl->setVariable('TXT_MAX',$this->lng->txt('mem_max_users'));
215  $tpl->setVariable('NUM_MAX',$this->container->getSubscriptionMaxMembers());
216 
217  $tpl->setVariable('TXT_FREE',$this->lng->txt('mem_free_places').":");
218 
219  include_once './Modules/Course/classes/class.ilObjCourseAccess.php';
220  $reg_info = ilObjCourseAccess::lookupRegistrationInfo($this->getContainer()->getId());
221  $free = $reg_info['reg_info_free_places'];
222 
223  if($free)
224  {
225  $tpl->setVariable('NUM_FREE',$free);
226  }
227  else
228  {
229  $tpl->setVariable('WARN_FREE',$free);
230  }
231 
232  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
233  $waiting_list = new ilCourseWaitingList($this->container->getId());
234  if(
235  $this->container->isSubscriptionMembershipLimited() and
236  $this->container->enabledWaitingList() and
237  (!$free or $waiting_list->getCountUsers()))
238  {
239  if($waiting_list->isOnList($ilUser->getId()))
240  {
241  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list_position'));
242  $tpl->setVariable('NUM_WAIT',$waiting_list->getPosition($ilUser->getId()));
243 
244  }
245  else
246  {
247  $tpl->setVariable('TXT_WAIT',$this->lng->txt('mem_waiting_list'));
248  if($free and $waiting_list->getCountUsers())
249  $tpl->setVariable('WARN_WAIT',$waiting_list->getCountUsers());
250  else
251  $tpl->setVariable('NUM_WAIT',$waiting_list->getCountUsers());
252  }
253  }
254 
255  $alert = '';
256  if(
257  !$free and
258  !$this->container->enabledWaitingList())
259  {
260  // Disable registration
261  $this->enableRegistration(false);
262  ilUtil::sendFailure($this->lng->txt('mem_alert_no_places'));
263  #$alert = $this->lng->txt('mem_alert_no_places');
264  }
265  elseif(
266  $this->container->enabledWaitingList() and
267  $this->container->isSubscriptionMembershipLimited() and
268  $waiting_list->isOnList($ilUser->getId())
269  )
270  {
271  // Disable registration
272  $this->enableRegistration(false);
273  }
274  elseif(
275  !$free and
276  $this->container->enabledWaitingList() and
277  $this->container->isSubscriptionMembershipLimited())
278 
279  {
280  ilUtil::sendFailure($this->lng->txt('crs_warn_no_max_set_on_waiting_list'));
281  #$alert = $this->lng->txt('crs_warn_no_max_set_on_waiting_list');
282  }
283  elseif(
284  $free and
285  $this->container->enabledWaitingList() and
286  $this->container->isSubscriptionMembershipLimited() and
287  $this->getWaitingList()->getCountUsers())
288  {
289  ilUtil::sendFailure($this->lng->txt('crs_warn_wl_set_on_waiting_list'));
290  #$alert = $this->lng->txt('crs_warn_wl_set_on_waiting_list');
291  }
292 
293  $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
294  $max->setHtml($tpl->get());
295  if(strlen($alert))
296  {
297  $max->setAlert($alert);
298  }
299  $this->form->addItem($max);
300  return true;
301  }
302 
309  protected function fillRegistrationType()
310  {
311  global $ilUser;
312 
313  if($this->container->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
314  {
315  $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_type'));
316  #$reg->setHtml($this->lng->txt('crs_info_reg_deactivated'));
317  $reg->setAlert($this->lng->txt('crs_info_reg_deactivated'));
318  #ilUtil::sendFailure($this->lng->txt('crs_info_reg_deactivated'));
319  #$reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
320  #$reg->setValue($this->lng->txt('crs_info_reg_deactivated'));
321  #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
322  $this->form->addItem($reg);
323 
324  // Disable registration
325  $this->enableRegistration(false);
326  return true;
327  }
328 
329  switch($this->container->getSubscriptionType())
330  {
332 
333  // no "request" info if waiting list is active
334  if($this->isWaitingListActive())
335  return true;
336 
337  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
338  $txt->setValue($this->lng->txt('crs_info_reg_direct'));
339 
340  $this->form->addItem($txt);
341  break;
342 
344  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
345  $txt->setValue($this->lng->txt('crs_subscription_options_password'));
346 
347 
348  $pass = new ilTextInputGUI($this->lng->txt('passwd'),'grp_passw');
349  $pass->setInputType('password');
350  $pass->setSize(12);
351  $pass->setMaxLength(32);
352  #$pass->setRequired(true);
353  $pass->setInfo($this->lng->txt('crs_info_reg_password'));
354 
355  $txt->addSubItem($pass);
356  $this->form->addItem($txt);
357  break;
358 
360 
361  // no "request" info if waiting list is active
362  if($this->isWaitingListActive())
363  return true;
364 
365  $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
366  $txt->setValue($this->lng->txt('crs_subscription_options_confirmation'));
367 
368  $sub = new ilTextAreaInputGUI($this->lng->txt('crs_reg_subject'),'subject');
369  $sub->setValue($_POST['subject']);
370  $sub->setInfo($this->lng->txt('crs_info_reg_confirmation'));
371  $sub->setCols(40);
372  $sub->setRows(5);
373  if($this->participants->isSubscriber($ilUser->getId()))
374  {
375  $sub_data = $this->participants->getSubscriberData($ilUser->getId());
376  $sub->setValue($sub_data['subject']);
377  $sub->setInfo('');
378  ilUtil::sendFailure($this->lng->txt('crs_reg_user_already_subscribed'));
379  $this->enableRegistration(false);
380  }
381  $txt->addSubItem($sub);
382  $this->form->addItem($txt);
383  break;
384 
385 
386  default:
387  return true;
388  }
389 
390  return true;
391  }
392 
397  protected function addCommandButtons()
398  {
399  global $ilUser;
400 
401  parent::addCommandButtons();
402 
403 
404  switch($this->container->getSubscriptionType())
405  {
407  if($this->participants->isSubscriber($ilUser->getId()))
408  {
409  $this->form->clearCommandButtons();
410  $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('crs_update_subscr_request'));
411  $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('crs_cancel_subscr_request'));
412  }
413  elseif($this->isRegistrationPossible())
414  {
415  $this->form->clearCommandButtons();
416  $this->form->addCommandButton('join', $this->lng->txt('crs_join_request'));
417  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
418  }
419  break;
420  }
421  if(!$this->isRegistrationPossible())
422  {
423  return false;
424  }
425 
426  return true;
427  }
428 
436  protected function validate()
437  {
438  global $ilUser;
439 
440  if($ilUser->getId() == ANONYMOUS_USER_ID)
441  {
442  $this->join_error = $this->lng->txt('permission_denied');
443  return false;
444  }
445 
446  // Set aggrement to not accepted
447  $this->setAccepted(false);
448 
449  if(!$this->isRegistrationPossible())
450  {
451  $this->join_error = $this->lng->txt('mem_error_preconditions');
452  return false;
453  }
454  if($this->container->getSubscriptionType() == IL_CRS_SUBSCRIPTION_PASSWORD)
455  {
456  if(!strlen($pass = ilUtil::stripSlashes($_POST['grp_passw'])))
457  {
458  $this->join_error = $this->lng->txt('crs_password_required');
459  return false;
460  }
461  if(strcmp($pass,$this->container->getSubscriptionPassword()) !== 0)
462  {
463  $this->join_error = $this->lng->txt('crs_password_not_valid');
464  return false;
465  }
466  }
467  if(!$this->validateCustomFields())
468  {
469  $this->join_error = $this->lng->txt('fill_out_all_required_fields');
470  return false;
471  }
472  if(!$this->validateAgreement())
473  {
474  $this->join_error = $this->lng->txt('crs_agreement_required');
475  return false;
476  }
477 
478  return true;
479  }
480 
488  protected function add()
489  {
490  global $ilUser,$tree, $ilCtrl;
491 
492  // TODO: language vars
493 
494  // set aggreement accepted
495  $this->setAccepted(true);
496 
497  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
498  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
499  $waiting_list = new ilCourseWaitingList($this->container->getId());
500  if($this->container->isSubscriptionMembershipLimited() and $this->container->enabledWaitingList() and (!$free or $waiting_list->getCountUsers()))
501  {
502  $waiting_list->addToList($ilUser->getId());
503  $info = sprintf($this->lng->txt('crs_added_to_list'),
504  $waiting_list->getPosition($ilUser->getId()));
505  ilUtil::sendSuccess($info,true);
506 
507  $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST,$ilUser->getId());
508  $this->participants->sendNotification($this->participants->NOTIFY_WAITING_LIST,$ilUser->getId());
509  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
510  $tree->getParentId($this->container->getRefId()));
511  $ilCtrl->redirectByClass("ilrepositorygui", "");
512  }
513 
514  switch($this->container->getSubscriptionType())
515  {
517  $this->participants->addSubscriber($ilUser->getId());
518  $this->participants->updateSubscriptionTime($ilUser->getId(),time());
519  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['subject']));
520  $this->participants->sendNotification($this->participants->NOTIFY_SUBSCRIPTION_REQUEST,$ilUser->getId());
521 
522  ilUtil::sendSuccess($this->lng->txt("application_completed"),true);
523  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
524  $tree->getParentId($this->container->getRefId()));
525  $ilCtrl->redirectByClass("ilrepositorygui", "");
526  break;
527 
528  default:
529 
530  if($this->container->isSubscriptionMembershipLimited() && $this->container->getSubscriptionMaxMembers())
531  {
532  $success = $GLOBALS['rbacadmin']->assignUserLimited(
533  ilParticipants::getDefaultMemberRole($this->container->getRefId()),
534  $ilUser->getId(),
535  $this->container->getSubscriptionMaxMembers(),
536  array(ilParticipants::getDefaultMemberRole($this->container->getRefId()))
537  );
538  if(!$success)
539  {
540  ilUtil::sendFailure($this->lng->txt('crs_subscription_failed_limit'));
541  $this->show();
542  return FALSE;
543  }
544  }
545 
546  $this->participants->add($ilUser->getId(),IL_CRS_MEMBER);
547  $this->participants->sendNotification($this->participants->NOTIFY_ADMINS,$ilUser->getId());
548  $this->participants->sendNotification($this->participants->NOTIFY_REGISTERED,$ilUser->getId());
549 
550  include_once './Modules/Forum/classes/class.ilForumNotification.php';
551  ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $ilUser->getId());
552 
553  if($this->container->getType() == "crs")
554  {
555  $this->container->checkLPStatusSync($ilUser->getId());
556  }
557 
558  if(!$_SESSION["pending_goto"])
559  {
560  ilUtil::sendSuccess($this->lng->txt("crs_subscription_successful"),true);
561  $this->ctrl->returnToParent($this);
562  }
563  else
564  {
565  $tgt = $_SESSION["pending_goto"];
566  unset($_SESSION["pending_goto"]);
567  ilUtil::redirect($tgt);
568  }
569  break;
570  }
571  }
572 
573 
574 
575 
581  protected function initParticipants()
582  {
583  include_once('./Modules/Course/classes/class.ilCourseParticipants.php');
584  $this->participants = ilCourseParticipants::_getInstanceByObjId($this->obj_id);
585  }
586 
587 
592  protected function initWaitingList()
593  {
594  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
595  $this->waiting_list = new ilCourseWaitingList($this->container->getId());
596  }
597 
601  protected function isWaitingListActive()
602  {
603  global $ilUser;
604  static $active = null;
605 
606  if($active !== null)
607  {
608  return $active;
609  }
610  if(!$this->container->enabledWaitingList() or !$this->container->isSubscriptionMembershipLimited())
611  {
612  return $active = false;
613  }
614  if(!$this->container->getSubscriptionMaxMembers())
615  {
616  return $active = false;
617  }
618 
619  $free = max(0,$this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
620  return $active = (!$free or $this->getWaitingList()->getCountUsers());
621  }
622 }
623 ?>
< 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.
setHtml($a_html)
Set Html.
$_POST['username']
Definition: cron.php:12
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
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
setValue($a_value)
Set Value.
__construct($a_container, $a_parent_gui)
Constructor.
static getDefaultMemberRole($a_ref_id)
const IL_CRS_SUBSCRIPTION_CONFIRMATION
Base class for Course and Group registration.
const IL_CAL_UNIX
fillRegistrationType()
fill registration type
addToList($a_usr_id)
Add to waiting list and raise event.
setAlert($a_alert)
Set Alert Text.
global $ilCtrl
Definition: ilias.php:18
const IL_CRS_MEMBER
validateAgreement()
Check Agreement.
setAccepted($a_status)
Set Agreement accepted.
const IL_CRS_SUBSCRIPTION_PASSWORD
fillRegistrationPeriod()
show informations about the registration period
$success
Definition: Utf8Test.php:87
$GLOBALS['ct_recipient']
enableRegistration($a_status)
set registration disabled
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.
static lookupRegistrationInfo($a_obj_id)
Lookup registration info ilDB $ilDB ilObjUser $ilUser ilLanguage $lng.
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
validate()
Validate subscription request.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
GUI class for course registrations.
This class represents a custom property in a property form.
show()
show registration 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.
const IL_CRS_SUBSCRIPTION_DIRECT
addCommandButtons()
Add group specific command buttons.
static checkForumsExistsInsert($ref_id, $user_id=0)
getContainer()
Parent object.
static redirect($a_script)
http redirect to other script
const IL_CRS_SUBSCRIPTION_DEACTIVATED
initParticipants()
Init course participants.