ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseAgreementGUI.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('Modules/Course/classes/class.ilCourseAgreement.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 
43  private $db;
44  private $ctrl;
45  private $lng;
46  private $tpl;
47 
48  private $privacy;
49  private $agreement;
50 
57  public function __construct($a_ref_id)
58  {
59  global $ilDB,$ilCtrl,$lng,$tpl,$ilUser,$ilObjDataCache;
60 
61  $this->ref_id = $a_ref_id;
62  $this->obj_id = $ilObjDataCache->lookupObjId($this->ref_id);
63  $this->ctrl = $ilCtrl;
64  $this->tpl = $tpl;
65  $this->lng = $lng;
66  $this->lng->loadLanguageModule('ps');
67 
68  $this->privacy = ilPrivacySettings::_getInstance();
69  $this->agreement = new ilCourseAgreement($ilUser->getId(),$this->obj_id);
70  $this->init();
71  }
72 
79  public function executeCommand()
80  {
81  $next_class = $this->ctrl->getNextClass($this);
82  $cmd = $this->ctrl->getCmd();
83 
84  switch($next_class)
85  {
86  default:
87  if(!$cmd or $cmd == 'view')
88  {
89  $cmd = 'showAgreement';
90  }
91  $this->$cmd();
92  break;
93  }
94  }
95 
102  private function showAgreement($send_info = true)
103  {
104 
105  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.crs_user_agreement.html','Modules/Course');
106  $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
107 
108  if($send_info)
109  {
110  $this->sendInfoMessage();
111  }
112  $this->showCourseDefinedFields();
113 
114  include_once('Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php');
115  $fields_info = ilExportFieldsInfo::_getInstance();
116 
117  foreach($fields_info->getExportableFields() as $field)
118  {
119  $this->tpl->setCurrentBlock('field');
120  $this->tpl->setVariable('FIELD_NAME',$this->lng->txt($field));
121  $this->tpl->parseCurrentBlock();
122  }
123 
124  $this->tpl->setVariable('AGREEMENT_HEADER',$this->lng->txt('crs_agreement_header'));
125  $this->tpl->setVariable('TXT_AGREEMENT',$this->lng->txt('crs_user_agreement'));
126  $this->tpl->setVariable('TXT_INFO_AGREEMENT',$this->lng->txt('crs_info_agreement'));
127 
128  if($this->privacy->confirmationRequired() or ilCourseDefinedFieldDefinition::_hasFields($this->obj_id))
129  {
130  $this->tpl->setCurrentBlock('agreement');
131  $this->tpl->setVariable('CHECK_AGREE',ilUtil::formCheckbox(0,'agreed',1));
132  $this->tpl->setVariable('INFO_AGREE',$this->lng->txt('crs_info_agree'));
133  $this->tpl->setVariable('TXT_AGREE',$this->lng->txt('crs_agree'));
134  $this->tpl->parseCurrentBlock();
135  }
136  $this->tpl->setVariable('TXT_SAVE',$this->lng->txt('save'));
137  }
138 
146  private function save()
147  {
148  if(!$this->checkCourseDefinedFields())
149  {
150  ilUtil::sendFailure($this->lng->txt('fill_out_all_required_fields'));
151  $this->showAgreement(false);
152  return false;
153  }
154  if(!$this->checkAgreement())
155  {
156  ilUtil::sendFailure($this->lng->txt('crs_agreement_required'));
157  $this->showAgreement(false);
158  return false;
159  }
160  $this->agreement->setAccepted(true);
161  $this->agreement->setAcceptanceTime(time());
162  $this->agreement->save();
163 
164  $this->ctrl->returnToParent($this);
165  }
166 
167  private function showCourseDefinedFields()
168  {
169  global $ilUser;
170 
171  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
172  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
173 
174  if(!count($cdf_fields = ilCourseDefinedFieldDefinition::_getFields($this->obj_id)))
175  {
176  return true;
177  }
178 
179  foreach($cdf_fields as $field_obj)
180  {
181  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
182 
183  switch($field_obj->getType())
184  {
185  case IL_CDF_TYPE_SELECT:
186  $this->tpl->setCurrentBlock('sel_row');
187  $this->tpl->setVariable('SEL_SELECT',ilUtil::formSelect($course_user_data->getValue(),
188  'cdf['.$field_obj->getId().']',
189  $field_obj->prepareSelectBox(),
190  false,
191  true));
192  break;
193  case IL_CDF_TYPE_TEXT:
194  $this->tpl->setCurrentBlock('txt_row');
195  $this->tpl->setVariable('TXT_ROW_NAME',$field_obj->getId());
196  $this->tpl->setVariable('TXT_ROW_VALUE',$course_user_data->getValue());
197  break;
198  }
199  if($field_obj->isRequired())
200  {
201  $this->show_required_info = true;
202  $this->tpl->touchBlock('cdf_required');
203  }
204 
205  $this->tpl->setCurrentBlock('cdf_row');
206  $this->tpl->setVariable('CDF_FIELD_NAME',$field_obj->getName());
207  $this->tpl->parseCurrentBlock();
208  }
209  $this->tpl->setCurrentBlock('cdf');
210  $this->tpl->setVariable('CDF_TXT',$this->lng->txt('ps_cdf_info'));
211  $this->tpl->parseCurrentBlock();
212  }
213 
220  private function checkCourseDefinedFields()
221  {
222  global $ilUser;
223 
224  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
225  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
226 
227  $all_required = true;
228  foreach(ilCourseDefinedFieldDefinition::_getFields($this->obj_id) as $field_obj)
229  {
230  switch($field_obj->getType())
231  {
232  case IL_CDF_TYPE_SELECT:
233  $tmp_value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
234  $value = '';
235  foreach((array) $field_obj->getValues() as $v)
236  {
237  if($v == $tmp_value)
238  {
239  $value = $tmp_value;
240  break;
241  }
242  }
243  break;
244  case IL_CDF_TYPE_TEXT:
245  $value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
246  break;
247  }
248  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
249  $course_user_data->setValue($value);
250  $course_user_data->update();
251 
252  if($field_obj->isRequired() and !$value)
253  {
254  $all_required = false;
255  }
256  }
257  return $all_required;
258  }
259 
260 
267  private function checkAgreement()
268  {
269  global $ilUser;
270 
271  if($_POST['agreed'])
272  {
273  return true;
274  }
275  if(!$this->privacy->confirmationRequired() and !ilCourseDefinedFieldDefinition::_hasFields($this->obj_id))
276  {
277  return true;
278  }
279  return false;
280  }
281 
282 
283 
291  private function init()
292  {
293  global $ilUser;
294 
295  $this->required_fullfilled = ilCourseUserData::_checkRequired($ilUser->getId(),$this->obj_id);
296  $this->agreement_required = $this->agreement->agreementRequired();
297  }
298 
304  private function sendInfoMessage()
305  {
306  $message = '';
307  if($this->agreement_required)
308  {
309  $message = $this->lng->txt('ps_agreement_req_info');
310  }
311  if(!$this->required_fullfilled)
312  {
313  if(strlen($message))
314  {
315  $message .= '<br />';
316  }
317  $message .= $this->lng->txt('ps_required_info');
318  }
319 
320  if(strlen($message))
321  {
322  ilUtil::sendFailure($message);
323  }
324  }
325 }
326 
327 
328 ?>