ILIAS  Release_4_2_x_branch Revision 61807
 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) or ilCourseDefinedFieldDefinition::_hasFields($this->obj_id))
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[0] = $this->lng->txt('links_select_one');
191  foreach($field_obj->getValues() as $value)
192  {
193  $options[$field_obj->getId().'_'.$value] = $value;
194  }
195  $this->tpl->setVariable('SEL_SELECT',ilUtil::formSelect($field_obj->getId().'_'.$course_user_data->getValue(),
196  'cdf['.$field_obj->getId().']',
197  $options,
198  false,
199  true));
200  break;
201  case IL_CDF_TYPE_TEXT:
202  $this->tpl->setCurrentBlock('txt_row');
203  $this->tpl->setVariable('TXT_ROW_NAME',$field_obj->getId());
204  $this->tpl->setVariable('TXT_ROW_VALUE',$course_user_data->getValue());
205  break;
206  }
207  if($field_obj->isRequired())
208  {
209  $this->show_required_info = true;
210  $this->tpl->touchBlock('cdf_required');
211  }
212 
213  $this->tpl->setCurrentBlock('cdf_row');
214  $this->tpl->setVariable('CDF_FIELD_NAME',$field_obj->getName());
215  $this->tpl->parseCurrentBlock();
216  }
217  $this->tpl->setCurrentBlock('cdf');
218  $this->tpl->setVariable('CDF_TXT',$this->lng->txt($this->type.'_ps_cdf_info'));
219  $this->tpl->parseCurrentBlock();
220  }
221 
228  private function checkCourseDefinedFields()
229  {
230  global $ilUser;
231 
232  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
233  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
234 
235  $all_required = true;
236  foreach(ilCourseDefinedFieldDefinition::_getFields($this->obj_id) as $field_obj)
237  {
238  $required_given = false;
239  switch($field_obj->getType())
240  {
241  case IL_CDF_TYPE_SELECT:
242  $tmp_values = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
243  $tmp_values = explode('_', $tmp_values,2);
244 
245 
246  if(isset($tmp_values[1]))
247  {
248  $tmp_value = isset($tmp_values[1]) ? $tmp_values[1] : '';
249  $value = '';
250  foreach((array) $field_obj->getValues() as $v)
251  {
252  if($v == $tmp_value)
253  {
254  $value = $tmp_value;
255  $required_given = true;
256  break;
257  }
258  }
259  }
260  break;
261 
262  case IL_CDF_TYPE_TEXT:
263  $value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
264  if($value)
265  {
266  $required_given = true;
267  }
268  break;
269  }
270  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
271  $course_user_data->setValue($value);
272  $course_user_data->update();
273 
274  if($field_obj->isRequired() and !$required_given)
275  {
276  $all_required = false;
277  }
278  }
279  return $all_required;
280  }
281 
282 
289  private function checkAgreement()
290  {
291  global $ilUser;
292 
293  if($_POST['agreed'])
294  {
295  return true;
296  }
297  if(!$this->privacy->confirmationRequired($this->type) and !ilCourseDefinedFieldDefinition::_hasFields($this->obj_id))
298  {
299  return true;
300  }
301  return false;
302  }
303 
304 
305 
313  private function init()
314  {
315  global $ilUser;
316 
317  $this->required_fullfilled = ilCourseUserData::_checkRequired($ilUser->getId(),$this->obj_id);
318  $this->agreement_required = $this->agreement->agreementRequired();
319  }
320 
326  private function sendInfoMessage()
327  {
328  $message = '';
329  if($this->agreement_required)
330  {
331  $message = $this->lng->txt($this->type.'_ps_agreement_req_info');
332  }
333  if(!$this->required_fullfilled)
334  {
335  if(strlen($message))
336  {
337  $message .= '<br />';
338  }
339  $message .= $this->lng->txt($this->type.'_ps_required_info');
340  }
341 
342  if(strlen($message))
343  {
344  ilUtil::sendFailure($message);
345  }
346  }
347 }
348 
349 
350 ?>