ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMemberAgreementGUI.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 include_once('Services/Membership/classes/class.ilMemberAgreement.php');
26 include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
27 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
28 
39 {
40  private $ref_id;
41  private $obj_id;
42  private $type;
43 
44  private $db;
45  private $ctrl;
46  private $lng;
47  private $tpl;
48 
49  private $privacy;
50  private $agreement;
51 
58  public function __construct($a_ref_id)
59  {
60  global $ilDB,$ilCtrl,$lng,$tpl,$ilUser,$ilObjDataCache;
61 
62  $this->ref_id = $a_ref_id;
63  $this->obj_id = $ilObjDataCache->lookupObjId($this->ref_id);
64  $this->type = ilObject::_lookupType($this->obj_id);
65  $this->ctrl = $ilCtrl;
66  $this->tpl = $tpl;
67  $this->lng = $lng;
68  $this->lng->loadLanguageModule('ps');
69 
70  $this->privacy = ilPrivacySettings::_getInstance();
71  $this->agreement = new ilMemberAgreement($ilUser->getId(),$this->obj_id);
72  $this->init();
73  }
74 
81  public function executeCommand()
82  {
83  $next_class = $this->ctrl->getNextClass($this);
84  $cmd = $this->ctrl->getCmd();
85 
86  switch($next_class)
87  {
88  default:
89  if(!$cmd or $cmd == 'view')
90  {
91  $cmd = 'showAgreement';
92  }
93  $this->$cmd();
94  break;
95  }
96  }
97 
104  private function showAgreement($send_info = true)
105  {
106 
107  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.crs_user_agreement.html','Modules/Course');
108  $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
109 
110  if($send_info)
111  {
112  $this->sendInfoMessage();
113  }
114  $this->showCourseDefinedFields();
115 
116  include_once('Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php');
117  $fields_info = ilExportFieldsInfo::_getInstanceByType(ilObject::_lookupType($this->obj_id));
118 
119  foreach($fields_info->getExportableFields() as $field)
120  {
121  $this->tpl->setCurrentBlock('field');
122  $this->tpl->setVariable('FIELD_NAME',$this->lng->txt($field));
123  $this->tpl->parseCurrentBlock();
124  }
125 
126  $this->tpl->setVariable('AGREEMENT_HEADER',$this->lng->txt($this->type.'_agreement_header'));
127  $this->tpl->setVariable('TXT_AGREEMENT',$this->lng->txt($this->type.'_user_agreement'));
128  $this->tpl->setVariable('TXT_INFO_AGREEMENT',$this->lng->txt($this->type.'_info_agreement'));
129  if($this->privacy->confirmationRequired($this->type))
130  {
131  $this->tpl->setCurrentBlock('agreement');
132  $this->tpl->setVariable('CHECK_AGREE',ilUtil::formCheckbox(0,'agreed',1));
133  $this->tpl->setVariable('INFO_AGREE',$this->lng->txt($this->type.'_info_agree'));
134  $this->tpl->setVariable('TXT_AGREE',$this->lng->txt($this->type.'_agree'));
135  $this->tpl->parseCurrentBlock();
136  }
137  $this->tpl->setVariable('TXT_SAVE',$this->lng->txt('save'));
138  }
139 
147  private function save()
148  {
149  if(!$this->checkCourseDefinedFields())
150  {
151  ilUtil::sendFailure($this->lng->txt('fill_out_all_required_fields'));
152  $this->showAgreement(false);
153  return false;
154  }
155  if(!$this->checkAgreement())
156  {
157  ilUtil::sendFailure($this->lng->txt($this->type.'_agreement_required'));
158  $this->showAgreement(false);
159  return false;
160  }
161  $this->agreement->setAccepted(true);
162  $this->agreement->setAcceptanceTime(time());
163  $this->agreement->save();
164 
165  $this->ctrl->returnToParent($this);
166  }
167 
168  private function showCourseDefinedFields()
169  {
170  global $ilUser;
171 
172  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
173  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
174 
175  if(!count($cdf_fields = ilCourseDefinedFieldDefinition::_getFields($this->obj_id)))
176  {
177  return true;
178  }
179 
180  foreach($cdf_fields as $field_obj)
181  {
182  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
183 
184  switch($field_obj->getType())
185  {
186  case IL_CDF_TYPE_SELECT:
187  $this->tpl->setCurrentBlock('sel_row');
188 
189  // Workaround for mantis 9868
190  $options = array();
191  $options[0] = $this->lng->txt('links_select_one');
192  foreach($field_obj->getValues() as $value)
193  {
194  $options[$field_obj->getId().'_'.$value] = $value;
195  }
196  $this->tpl->setVariable('SEL_SELECT',ilUtil::formSelect($field_obj->getId().'_'.$course_user_data->getValue(),
197  'cdf['.$field_obj->getId().']',
198  $options,
199  false,
200  true));
201  break;
202  case IL_CDF_TYPE_TEXT:
203  $this->tpl->setCurrentBlock('txt_row');
204  $this->tpl->setVariable('TXT_ROW_NAME',$field_obj->getId());
205  $this->tpl->setVariable('TXT_ROW_VALUE',$course_user_data->getValue());
206  break;
207  }
208  if($field_obj->isRequired())
209  {
210  $this->show_required_info = true;
211  $this->tpl->touchBlock('cdf_required');
212  }
213 
214  $this->tpl->setCurrentBlock('cdf_row');
215  $this->tpl->setVariable('CDF_FIELD_NAME',$field_obj->getName());
216  $this->tpl->parseCurrentBlock();
217  }
218  $this->tpl->setCurrentBlock('cdf');
219  $this->tpl->setVariable('CDF_TXT',$this->lng->txt($this->type.'_ps_cdf_info'));
220  $this->tpl->parseCurrentBlock();
221  }
222 
229  private function checkCourseDefinedFields()
230  {
231  global $ilUser;
232 
233  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
234  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
235 
236  $all_required = true;
237  foreach(ilCourseDefinedFieldDefinition::_getFields($this->obj_id) as $field_obj)
238  {
239  $required_given = false;
240  switch($field_obj->getType())
241  {
242  case IL_CDF_TYPE_SELECT:
243  $tmp_values = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
244  $tmp_values = explode('_', $tmp_values,2);
245 
246 
247  if(isset($tmp_values[1]))
248  {
249  $tmp_value = isset($tmp_values[1]) ? $tmp_values[1] : '';
250  $value = '';
251  foreach((array) $field_obj->getValues() as $v)
252  {
253  if($v == $tmp_value)
254  {
255  $value = $tmp_value;
256  $required_given = true;
257  break;
258  }
259  }
260  }
261  break;
262 
263  case IL_CDF_TYPE_TEXT:
264  $value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
265  if(trim($value) != "") // #14220
266  {
267  $required_given = true;
268  }
269  break;
270  }
271  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
272  $course_user_data->setValue($value);
273  $course_user_data->update();
274 
275  if($field_obj->isRequired() and !$required_given)
276  {
277  $all_required = false;
278  }
279  }
280  return $all_required;
281  }
282 
283 
290  private function checkAgreement()
291  {
292  global $ilUser;
293 
294  if($_POST['agreed'])
295  {
296  return true;
297  }
298  if($this->privacy->confirmationRequired($this->type))
299  {
300  return false;
301  }
302  return true;
303  }
304 
305 
306 
314  private function init()
315  {
316  global $ilUser;
317 
318  $this->required_fullfilled = ilCourseUserData::_checkRequired($ilUser->getId(),$this->obj_id);
319  $this->agreement_required = $this->agreement->agreementRequired();
320  }
321 
327  private function sendInfoMessage()
328  {
329  $message = '';
330  if($this->agreement_required)
331  {
332  $message = $this->lng->txt($this->type.'_ps_agreement_req_info');
333  }
334  if(!$this->required_fullfilled)
335  {
336  if(strlen($message))
337  {
338  $message .= '<br />';
339  }
340  $message .= $this->lng->txt($this->type.'_ps_required_info');
341  }
342 
343  if(strlen($message))
344  {
345  ilUtil::sendFailure($message);
346  }
347  }
348 }
349 
350 
351 ?>