ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilRegistrationGUI.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 include_once('Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
25 
35 abstract class ilRegistrationGUI
36 {
37  protected $privacy = null;
38 
39  protected $container = null;
40  protected $ref_id;
41  protected $obj_id;
42 
43  protected $participants;
44  protected $waiting_list = null;
45  protected $form;
46 
47  protected $registration_possible = true;
48  protected $join_error = '';
49 
50 
51  protected $tpl;
52  protected $lng;
53  protected $ctrl;
54 
62  public function __construct($a_container)
63  {
64  global $lng,$ilCtrl,$tpl;
65 
66  $this->lng = $lng;
67  $this->lng->loadLanguageModule('crs');
68  $this->lng->loadLanguageModule('grp');
69  $this->lng->loadLanguageModule('ps');
70 
71  $this->ctrl = $ilCtrl;
72  $this->tpl = $tpl;
73 
74  $this->container = $a_container;
75  $this->ref_id = $this->container->getRefId();
76  $this->obj_id = ilObject::_lookupObjId($this->ref_id);
77  $this->type = ilObject::_lookupType($this->obj_id);
78 
79  // Init participants
80  $this->initParticipants();
81 
82  // Init waiting list
83  $this->initWaitingList();
84 
85  $this->privacy = ilPrivacySettings::_getInstance();
86  }
87 
92  public function getContainer()
93  {
94  return $this->container;
95  }
96 
101  public function getRefId()
102  {
103  return $this->ref_id;
104  }
105 
112  protected function isRegistrationPossible()
113  {
114  return (bool) $this->registration_possible;
115  }
116 
124  protected function enableRegistration($a_status)
125  {
126  $this->registration_possible = $a_status;
127  }
128 
129 
136  abstract protected function initParticipants();
137 
145  abstract protected function initWaitingList();
146 
153  abstract protected function isWaitingListActive();
154 
160  protected function getWaitingList()
161  {
162  return $this->waiting_list;
163  }
164 
165  protected function leaveWaitingList()
166  {
167  global $ilUser,$tree,$ilCtrl;
168 
169  $this->getWaitingList()->removeFromList($ilUser->getId());
170  $parent = $tree->getParentId($this->container->getRefId());
171 
172  $message = sprintf($this->lng->txt($this->container->getType().'_removed_from_waiting_list'),
173  $this->container->getTitle());
174  ilUtil::sendSuccess($message,true);
175 
176  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $parent);
177  $ilCtrl->redirectByClass("ilrepositorygui", "");
178  }
179 
186  abstract protected function getFormTitle();
187 
194  abstract protected function fillInformations();
195 
201  abstract protected function fillRegistrationPeriod();
202 
210  abstract protected function fillMaxMembers();
211 
212 
219  abstract protected function fillRegistrationType();
220 
227  protected function fillMembershipLimitation()
228  {
229  global $ilAccess, $ilCtrl;
230 
231  include_once('Modules/Course/classes/class.ilObjCourseGrouping.php');
232  if(!$items = ilObjCourseGrouping::_getGroupingItems($this->container))
233  {
234  return true;
235  }
236 
237  $mem = new ilCustomInputGUI($this->lng->txt('groupings'));
238 
239  $tpl = new ilTemplate('tpl.membership_limitation_form.html',true,true,'Services/Membership');
240  $tpl->setVariable('LIMIT_INTRO',$this->lng->txt($this->type.'_grp_info_reg'));
241 
242  foreach($items as $ref_id)
243  {
244  $obj_id = ilObject::_lookupObjId($ref_id);
247 
248  if($ilAccess->checkAccess('visible','',$ref_id,$type))
249  {
250  include_once('./Services/Link/classes/class.ilLink.php');
251  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $ref_id);
252  $tpl->setVariable('LINK_ITEM',
253  $ilCtrl->getLinkTargetByClass("ilrepositorygui", ""));
254  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
255  $tpl->setVariable('ITEM_LINKED_TITLE',$title);
256  }
257  else
258  {
259  $tpl->setVariable('ITEM_TITLE');
260  }
261  $tpl->setCurrentBlock('items');
262  $tpl->setVariable('TYPE_ICON',ilUtil::getTypeIconPath($type,$obj_id,'tiny'));
263  $tpl->setVariable('ALT_ICON',$this->lng->txt('obj_'.$type));
264  $tpl->parseCurrentBlock();
265  }
266 
267  $mem->setHtml($tpl->get());
268 
269 
271  {
272  $mem->setAlert($this->container->getMessage());
273  $this->enableRegistration(false);
274  }
275  $this->form->addItem($mem);
276  }
277 
284  protected function fillAgreement()
285  {
286  global $ilUser;
287 
288  if(!$this->isRegistrationPossible())
289  {
290  return true;
291  }
292 
293  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
294  if(!$this->privacy->confirmationRequired($this->type) and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId()))
295  {
296  return true;
297  }
298 
299  $this->lng->loadLanguageModule('ps');
300 
301  include_once('Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php');
302  $fields_info = ilExportFieldsInfo::_getInstanceByType(ilObject::_lookupType($this->container->getId()));
303 
304  if(!count($fields_info->getExportableFields()))
305  {
306  return true;
307  }
308 
310  $section->setTitle($this->lng->txt('usr_agreement'));
311  $this->form->addItem($section);
312 
313  include_once './Services/Membership/classes/class.ilMemberAgreementGUI.php';
314  ilMemberAgreementGUI::addExportFieldInfo($this->form, $this->obj_id, $this->type);
315 
316 
317  ilMemberAgreementGUI::addCustomFields($this->form, $this->obj_id, $this->type);
318 
319  // Checkbox agreement
320  if($this->privacy->confirmationRequired($this->type))
321  {
322  ilMemberAgreementGUI::addAgreement($this->form, $this->obj_id, $this->type);
323  }
324  return true;
325  }
326 
332  protected function showCustomFields()
333  {
334  global $ilUser;
335 
336  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
337  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
338 
339  if(!count($cdf_fields = ilCourseDefinedFieldDefinition::_getFields($this->container->getId())))
340  {
341  return true;
342  }
343 
344  $cdf = new ilNonEditableValueGUI($this->lng->txt('ps_crs_user_fields'));
345  $cdf->setValue($this->lng->txt($this->type.'_ps_cdf_info'));
346  $cdf->setRequired(true);
347 
348  foreach($cdf_fields as $field_obj)
349  {
350  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
351 
352  switch($field_obj->getType())
353  {
354  case IL_CDF_TYPE_SELECT:
355  $select = new ilSelectInputGUI($field_obj->getName(),'cdf['.$field_obj->getId().']');
356  $select->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
357  $select->setOptions($field_obj->prepareSelectBox());
358  if($field_obj->isRequired())
359  {
360  $select->setRequired(true);
361  }
362 
363  $cdf->addSubItem($select);
364 
365 
366  break;
367 
368  case IL_CDF_TYPE_TEXT:
369  $text = new ilTextInputGUI($field_obj->getName(),'cdf['.$field_obj->getId().']');
370  $text->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
371  $text->setSize(32);
372  $text->setMaxLength(255);
373  if($field_obj->isRequired())
374  {
375  $text->setRequired(true);
376  }
377  $cdf->addSubItem($text);
378  break;
379  }
380  }
381  $this->form->addItem($cdf);
382  return true;
383  }
384 
391  protected function validateAgreement()
392  {
393  global $ilUser;
394 
395  if($_POST['agreement'])
396  {
397  return true;
398  }
399  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
400  if(!$this->privacy->confirmationRequired($this->type))
401  {
402  return true;
403  }
404  return false;
405  }
406 
413  protected function validateCustomFields()
414  {
415  global $ilUser;
416 
417 
418  $required_fullfilled = true;
419  foreach(ilCourseDefinedFieldDefinition::_getFields($this->container->getId()) as $field_obj)
420  {
421  switch($field_obj->getType())
422  {
423  case IL_CDF_TYPE_SELECT:
424 
425  // Split value id from post
426  list($field_id,$option_id) = explode('_', $_POST['cdf_'.$field_obj->getId()]);
427  $open_answer_indexes = (array) $field_obj->getValueOptions();
428  if(in_array($option_id, $open_answer_indexes))
429  {
430  $value = $_POST['cdf_oa_'.$field_obj->getId()];
431  }
432  else
433  {
434  $value = $field_obj->getValueById($option_id);
435  }
436  break;
437 
438  case IL_CDF_TYPE_TEXT:
439  $value = $_POST['cdf_'.$field_obj->getId()];
440  break;
441  }
442 
443  $GLOBALS['ilLog']->write(__METHOD__.': new value '. $value);
444 
445 
446  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
447  $course_user_data->setValue($value);
448  $course_user_data->update();
449 
450  if($field_obj->isRequired() and !$value)
451  {
452  $required_fullfilled = false;
453  }
454  }
455 
456  return $required_fullfilled;
457  }
458 
465  protected function setAccepted($a_status)
466  {
467  global $ilUser;
468 
469  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
470  if(!$this->privacy->confirmationRequired($this->type) and !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId()))
471  {
472  return true;
473  }
474 
475  include_once('Services/Membership/classes/class.ilMemberAgreement.php');
476  $this->agreement = new ilMemberAgreement($ilUser->getId(),$this->container->getId());
477  $this->agreement->setAccepted($a_status);
478  $this->agreement->setAcceptanceTime(time());
479  $this->agreement->save();
480  }
481 
487  public function cancel()
488  {
489  global $tree, $ilCtrl;
490 
491  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
492  $tree->getParentId($this->container->getRefId()));
493  $ilCtrl->redirectByClass("ilrepositorygui", "");
494  }
495 
503  public function show()
504  {
505  $this->initForm();
506 
507  if($_SESSION["pending_goto"])
508  {
509  ilUtil::sendInfo($this->lng->txt("reg_goto_parent_membership_info"));
510  }
511 
512  $this->tpl->setContent($this->form->getHTML());
513  }
514 
522  public function join()
523  {
524  $this->initForm();
525 
526  if(!$this->validate())
527  {
528  ilUtil::sendFailure($this->join_error);
529  $this->show();
530  return false;
531  }
532 
533  $this->add();
534  }
535 
536 
543  protected function validate()
544  {
545  return true;
546  }
547 
554  protected function initForm()
555  {
556  global $ilUser;
557 
558  if(is_object($this->form))
559  {
560  return true;
561  }
562 
563  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
564  $this->form = new ilPropertyFormGUI();
565  $this->form->setFormAction($this->ctrl->getFormAction($this,'join'));
566  $this->form->setTitle($this->getFormTitle());
567 
568  $this->fillInformations();
569  $this->fillMembershipLimitation();
570  if($this->isRegistrationPossible())
571  {
572  $this->fillRegistrationPeriod();
573  }
574  if($this->isRegistrationPossible())
575  {
576  $this->fillRegistrationType();
577  }
578  if($this->isRegistrationPossible())
579  {
580  $this->fillMaxMembers();
581  }
582  if($this->isRegistrationPossible())
583  {
584  $this->fillAgreement();
585  }
586  $this->addCommandButtons();
587  }
588 
593  protected function addCommandButtons()
594  {
595  global $ilUser;
596 
597  if($this->isRegistrationPossible() and $this->isWaitingListActive() and !$this->getWaitingList()->isOnList($ilUser->getId()))
598  {
599  $this->form->addCommandButton('join',$this->lng->txt('mem_add_to_wl'));
600  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
601  }
602  elseif($this->isRegistrationPossible() and !$this->getWaitingList()->isOnList($ilUser->getId()))
603  {
604  $this->form->addCommandButton('join',$this->lng->txt('join'));
605  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
606  }
607  if($this->getWaitingList()->isOnList($ilUser->getId()))
608  {
610  sprintf($this->lng->txt($this->container->getType().'_cancel_waiting_list'),
611  $this->container->getTitle())
612  );
613  $this->form->addCommandButton('leaveWaitingList', $this->lng->txt('leave_waiting_list'));
614  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
615  }
616  }
617 
622  protected function updateSubscriptionRequest()
623  {
624  global $ilUser, $tree, $ilCtrl;
625 
626  $this->participants->updateSubject($ilUser->getId(),ilUtil::stripSlashes($_POST['subject']));
627  ilUtil::sendSuccess($this->lng->txt('sub_request_saved'),true);
628  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
629  $tree->getParentId($this->container->getRefId()));
630  $ilCtrl->redirectByClass("ilrepositorygui", "");
631 
632  }
633 
634  protected function cancelSubscriptionRequest()
635  {
636  global $ilUser, $tree, $ilCtrl;
637 
638  $this->participants->deleteSubscriber($ilUser->getId());
639  ilUtil::sendSuccess($this->lng->txt('sub_request_deleted'),true);
640 
641  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
642  $tree->getParentId($this->container->getRefId()));
643  $ilCtrl->redirectByClass("ilrepositorygui", "");
644  }
645 }
646 ?>
< 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.
fillAgreement()
Show user agreement.
setHtml($a_html)
Set Html.
$_POST['username']
Definition: cron.php:12
This class represents a selection list property in a property form.
This class represents a property form user interface.
static addExportFieldInfo($form, $a_obj_id, $a_type)
Add export field info to form type $lng.
$_GET["client_id"]
This class represents a section header in a property form.
initForm()
init registration form
getWaitingList()
Get waiting list object.
fillRegistrationPeriod()
show informations about the registration period
fillRegistrationType()
show informations about registration procedure
updateSubscriptionRequest()
Update subscription message.
static _lookupTitle($a_id)
lookup object title
isWaitingListActive()
Check if the waiting list is active Maximum of members exceeded or any user on the waiting list...
getFormTitle()
Get title for property form.
Base class for Course and Group registration.
static getTypeIconPath($a_type, $a_obj_id, $a_size='small')
Get type icon path path Return image path for icon_xxx.pngs Or (if enabled) path to custom icon...
showCustomFields()
Show course defined fields.
global $ilCtrl
Definition: ilias.php:18
setAccepted($a_status)
set accepted
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
validateAgreement()
Check Agreement.
$section
Definition: Utf8Test.php:84
setAccepted($a_status)
Set Agreement accepted.
initWaitingList()
Init waiting list (course or group waiting list)
$GLOBALS['ct_recipient']
enableRegistration($a_status)
set registration disabled
static _getInstanceByType($a_type)
Get Singleton Instance.
validate()
validate join request
static _lookupObjId($a_id)
special template class to simplify handling of ITX/PEAR
isRegistrationPossible()
check if registration is possible
static addAgreement($form, $a_obj_id, $a_type)
Add agreement to form.
This class represents a text property in a property form.
static addCustomFields($form, $a_obj_id, $a_type)
Add custom course fields.
validateCustomFields()
Check required course fields.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _hasFields($a_container_id)
Check if there are any define fields.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
_checkGroupingDependencies(&$container_obj, $a_user_id=null)
This class represents a custom property in a property form.
cancel()
cancel subscription
global $ilUser
Definition: imgupload.php:15
show()
show registration form
This class represents a non editable value in a property form.
fillMembershipLimitation()
Show membership limitations.
fillInformations()
fill informations
addCommandButtons()
Add command buttons.
_getGroupingItems($container_obj)
Get courses/groups that are assigned to the same membership limitation.
fillMaxMembers()
show informations about the maximum number of user.
__construct($a_container)
Constructor.
static _getInstance()
Get instance of ilPrivacySettings.
getContainer()
Parent object.
initParticipants()
Init participants object (course or group participants)
static _getFields($a_container_id, $a_sort=IL_CDF_SORT_NAME)
Get all fields of a container.