ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilMemberAgreementGUI.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/PrivacySecurity/classes/class.ilPrivacySettings.php');
5include_once('Services/Membership/classes/class.ilMemberAgreement.php');
6include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
7include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
8
19{
20 private $ref_id;
21 private $obj_id;
22 private $type;
23
24 private $db;
25 private $ctrl;
26 private $lng;
27 private $tpl;
28
29 private $privacy;
30 private $agreement;
31
32 private $required_fullfilled = false;
33 private $agrement_required = false;
34
41 public function __construct($a_ref_id)
42 {
43 global $ilDB,$ilCtrl,$lng,$tpl,$ilUser,$ilObjDataCache;
44
45 $this->ref_id = $a_ref_id;
46 $this->obj_id = $ilObjDataCache->lookupObjId($this->ref_id);
47 $this->type = ilObject::_lookupType($this->obj_id);
48 $this->ctrl = $ilCtrl;
49 $this->tpl = $tpl;
50 $this->lng = $lng;
51 $this->lng->loadLanguageModule('ps');
52
53 $this->privacy = ilPrivacySettings::_getInstance();
54 $this->agreement = new ilMemberAgreement($ilUser->getId(),$this->obj_id);
55 $this->init();
56 }
57
64 public function executeCommand()
65 {
66 $next_class = $this->ctrl->getNextClass($this);
67 $cmd = $this->ctrl->getCmd();
68
69 switch($next_class)
70 {
71 default:
72 if(!$cmd or $cmd == 'view')
73 {
74 $cmd = 'showAgreement';
75 }
76 $this->$cmd();
77 break;
78 }
79 }
80
85 public function getPrivacy()
86 {
87 return $this->privacy;
88 }
89
93 public function getAgreement()
94 {
95 return $this->agreement;
96 }
97
103 protected function showAgreement(ilPropertyFormGUI $form = null)
104 {
105 global $ilUser;
106
107 $form = $this->initFormAgreement($form);
108 self::setCourseDefinedFieldValues($form, $this->obj_id, $ilUser->getId());
109
110 $this->tpl->setContent($form->getHTML());
111 return true;
112 }
113
114
115
116 protected function initFormAgreement()
117 {
118 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
119 $form = new ilPropertyFormGUI();
120 $form->setTitle($this->lng->txt($this->type.'_agreement_header'));
121 $form->setFormAction($GLOBALS['ilCtrl']->getFormAction($this));
122 $form->addCommandButton('save', $this->lng->txt('save'));
123
124 $form = self::addExportFieldInfo($form, $this->obj_id, $this->type);
125 $form = self::addCustomFields($form, $this->obj_id, $this->type);
126
127 if($this->getPrivacy()->confirmationRequired($this->type))
128 {
129 $form = self::addAgreement($form, $this->obj_id, $this->type);
130 }
131
132 return $form;
133 }
134
143 public static function addExportFieldInfo($form,$a_obj_id,$a_type)
144 {
145 global $lng;
146
147 include_once('Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php');
149
150 $fields = new ilCustomInputGUI($lng->txt($a_type.'_user_agreement'),'');
151 $tpl = new ilTemplate('tpl.agreement_form.html',true,true,'Services/Membership');
152 $tpl->setVariable('TXT_INFO_AGREEMENT',$lng->txt($a_type.'_info_agreement'));
153 foreach($fields_info->getExportableFields() as $field)
154 {
155 $tpl->setCurrentBlock('field_item');
156 $tpl->setVariable('FIELD_NAME',$lng->txt($field));
157 $tpl->parseCurrentBlock();
158 }
159 $fields->setHtml($tpl->get());
160 $form->addItem($fields);
161
162 return $form;
163 }
164
171 public static function addAgreement($form, $a_obj_id, $a_type)
172 {
173 global $lng;
174
175 $agreement = new ilCheckboxInputGUI($lng->txt($a_type.'_agree'),'agreement');
176 $agreement->setRequired(true);
177 $agreement->setOptionTitle($lng->txt($a_type.'_info_agree'));
178 $agreement->setValue(1);
179 $form->addItem($agreement);
180
181 return $form;
182 }
183
190 public static function addCustomFields($form, $a_obj_id, $a_type, $a_mode = 'user')
191 {
192 global $lng;
193
194 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
195 include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
196
197 if(!count($cdf_fields = ilCourseDefinedFieldDefinition::_getFields($a_obj_id)))
198 {
199 return $form;
200 }
201
202 if($a_mode == 'user')
203 {
204 $cdf = new ilNonEditableValueGUI($lng->txt('ps_'.$a_type.'_user_fields'));
205 $cdf->setValue($lng->txt($a_type.'_ps_cdf_info'));
206 $cdf->setRequired(true);
207 }
208
209 foreach($cdf_fields as $field_obj)
210 {
211 switch($field_obj->getType())
212 {
214
215 if($field_obj->getValueOptions())
216 {
217 // Show as radio group
218 $option_radios = new ilRadioGroupInputGUI($field_obj->getName(), 'cdf_'.$field_obj->getId());
219 if($field_obj->isRequired())
220 {
221 $option_radios->setRequired(true);
222 }
223
224 $open_answer_indexes = (array) $field_obj->getValueOptions();
225 foreach($field_obj->getValues() as $key => $val)
226 {
227 $option_radio = new ilRadioOption($val,$field_obj->getId().'_'.$key);
228
229 // open answers
230 if(in_array($key, $open_answer_indexes))
231 {
232 $open_answer = new ilTextInputGUI($lng->txt("form_open_answer"), 'cdf_oa_'.$field_obj->getId().'_'.$key);
233 $open_answer->setRequired(true);
234 $option_radio->addSubItem($open_answer);
235 }
236
237 $option_radios->addOption($option_radio);
238 }
239 if($a_mode == 'user')
240 {
241 $cdf->addSubItem($option_radios);
242 }
243 else
244 {
245 $form->addItem($option_radios);
246 }
247 }
248 else
249 {
250 $select = new ilSelectInputGUI($field_obj->getName(),'cdf_'.$field_obj->getId());
251 #$select->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
252 $select->setOptions($field_obj->prepareSelectBox());
253 if($field_obj->isRequired())
254 {
255 $select->setRequired(true);
256 }
257 if($a_mode == 'user')
258 {
259 $cdf->addSubItem($select);
260 }
261 else
262 {
263 $form->addItem($select);
264 }
265 }
266 break;
267
268 case IL_CDF_TYPE_TEXT:
269 $text = new ilTextInputGUI($field_obj->getName(),'cdf_'.$field_obj->getId());
270 #$text->setValue(ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]));
271 $text->setSize(32);
272 $text->setMaxLength(255);
273 if($field_obj->isRequired())
274 {
275 $text->setRequired(true);
276 }
277 if($a_mode == 'user')
278 {
279 $cdf->addSubItem($text);
280 }
281 else
282 {
283 $form->addItem($text);
284 }
285 break;
286 }
287 }
288 if($a_mode == 'user')
289 {
290 $form->addItem($cdf);
291 }
292 return $form;
293
294 }
295
296
297
305 private function save()
306 {
307 global $ilUser;
308
309 $form = $this->initFormAgreement();
310
311 // #14715 - checkInput() does not work for checkboxes
312 if($this->checkAgreement() &&
313 $form->checkInput())
314 {
315 self::saveCourseDefinedFields($form, $this->obj_id);
316
317 $this->getAgreement()->setAccepted(true);
318 $this->getAgreement()->setAcceptanceTime(time());
319 $this->getAgreement()->save();
320
321 include_once './Services/Membership/classes/class.ilObjectCustomUserFieldHistory.php';
322 $history = new ilObjectCustomUserFieldHistory($this->obj_id,$ilUser->getId());
323 $history->setUpdateUser($ilUser->getId());
324 $history->setEditingTime(new ilDateTime(time(),IL_CAL_UNIX));
325 $history->save();
326
327 $this->ctrl->returnToParent($this);
328 }
329 elseif(!$this->checkAgreement())
330 {
331 ilUtil::sendFailure($this->lng->txt($this->type.'_agreement_required'));
332 $form->setValuesByPost();
333 $this->showAgreement($form);
334 return false;
335 }
336 else
337 {
338 ilUtil::sendFailure($this->lng->txt('fill_out_all_required_fields'));
339 $form->setValuesByPost();
340 $this->showAgreement($form);
341 return false;
342 }
343 }
344
345 public static function setCourseDefinedFieldValues(ilPropertyFormGUI $form, $a_obj_id, $a_usr_id = 0)
346 {
347 global $ilUser;
348
349 if(!$a_usr_id)
350 {
351 $a_usr_id = $ilUser->getId();
352 }
353
355
356 foreach(ilCourseDefinedFieldDefinition::_getFields($a_obj_id) as $field_obj)
357 {
358 $current_value = $ud[$a_usr_id][$field_obj->getId()];
359 if(!$current_value)
360 {
361 continue;
362 }
363
364 switch($field_obj->getType())
365 {
367
368 $id = $field_obj->getIdByValue($current_value);
369
370 if($id >= 0)
371 {
372 $item = $form->getItemByPostVar('cdf_'.$field_obj->getId());
373 $item->setValue($field_obj->getId().'_'.$id);
374 }
375 else
376 {
377 // open answer
378 $open_answer_indexes = $field_obj->getValueOptions();
379 $open_answer_index = end($open_answer_indexes);
380 $item = $form->getItemByPostVar('cdf_'.$field_obj->getId());
381 $item->setValue($field_obj->getId().'_'.$open_answer_index);
382 $item_txt = $form->getItemByPostVar('cdf_oa_'.$field_obj->getId().'_'.$open_answer_index);
383 if($item_txt)
384 {
385 $item_txt->setValue($current_value);
386 }
387 }
388 break;
389
390 case IL_CDF_TYPE_TEXT:
391 $item = $form->getItemByPostVar('cdf_'.$field_obj->getId());
392 $item->setValue($current_value);
393 break;
394 }
395 }
396 }
397
398
403 public static function saveCourseDefinedFields(ilPropertyFormGUI $form, $a_obj_id, $a_usr_id = 0)
404 {
405 global $ilUser;
406
407 if(!$a_usr_id)
408 {
409 $a_usr_id = $ilUser->getId();
410 }
411
412 foreach(ilCourseDefinedFieldDefinition::_getFields($a_obj_id) as $field_obj)
413 {
414 switch($field_obj->getType())
415 {
417
418 // Split value id from post
419 list($field_id,$option_id) = explode('_', $form->getInput('cdf_'.$field_obj->getId()));
420 $open_answer_indexes = (array) $field_obj->getValueOptions();
421 if(in_array($option_id, $open_answer_indexes))
422 {
423 $value = $form->getInput('cdf_oa_'.$field_obj->getId().'_'.$option_id);
424 }
425 else
426 {
427 $value = $field_obj->getValueById($option_id);
428 }
429 break;
430
431 case IL_CDF_TYPE_TEXT:
432 $value = $form->getInput('cdf_'.$field_obj->getId());
433 break;
434 }
435
436 $course_user_data = new ilCourseUserData($a_usr_id,$field_obj->getId());
437 $course_user_data->setValue($value);
438 $course_user_data->update();
439 }
440 }
441
442
449 private function checkAgreement()
450 {
451 global $ilUser;
452
453 if($_POST['agreement'])
454 {
455 return true;
456 }
457 if($this->privacy->confirmationRequired($this->type))
458 {
459 return false;
460 }
461 return true;
462 }
463
464
465
472 private function init()
473 {
474 global $ilUser;
475
476 $this->required_fullfilled = ilCourseUserData::_checkRequired($ilUser->getId(),$this->obj_id);
477 $this->agreement_required = $this->getAgreement()->agreementRequired();
478 }
479
485 private function sendInfoMessage()
486 {
487 $message = '';
488 if($this->agreement_required)
489 {
490 $message = $this->lng->txt($this->type.'_ps_agreement_req_info');
491 }
492 if(!$this->required_fullfilled)
493 {
494 if(strlen($message))
495 {
496 $message .= '<br />';
497 }
498 $message .= $this->lng->txt($this->type.'_ps_required_info');
499 }
500
501 if(strlen($message))
502 {
503 ilUtil::sendFailure($message);
504 }
505 }
506}
507
508
509?>
const IL_CAL_UNIX
This class represents a checkbox property in a property form.
static _getFields($a_container_id, $a_sort=IL_CDF_SORT_NAME)
Get all fields of a container.
static _getValuesByObjId($a_obj_id)
Get values by obj_id (for all users)
static _checkRequired($a_usr_id, $a_obj_id)
Check required fields.
This class represents a custom property in a property form.
@classDescription Date and time handling
static _getInstanceByType($a_type)
Get Singleton Instance.
static addExportFieldInfo($form, $a_obj_id, $a_type)
Add export field info to form @global type $lng.
static setCourseDefinedFieldValues(ilPropertyFormGUI $form, $a_obj_id, $a_usr_id=0)
static addCustomFields($form, $a_obj_id, $a_type, $a_mode='user')
Add custom course fields.
static addAgreement($form, $a_obj_id, $a_type)
Add agreement to form.
showAgreement(ilPropertyFormGUI $form=null)
Show agreement form.
__construct($a_ref_id)
Constructor.
sendInfoMessage()
Send info message.
getPrivacy()
Get privycy settings.
static saveCourseDefinedFields(ilPropertyFormGUI $form, $a_obj_id, $a_usr_id=0)
Save course defined fields.
This class represents a non editable value in a property form.
Editing history for object custom user fields.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getInstance()
Get instance of ilPrivacySettings.
This class represents a property form user interface.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
getItemByPostVar($a_post_var)
Get Item by POST variable.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$_POST['username']
Definition: cron.php:12
$GLOBALS['ct_recipient']
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
global $ilDB
global $ilUser
Definition: imgupload.php:15