ILIAS  Release_3_10_x_branch Revision 61812
 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)
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::sendInfo($this->lng->txt('fill_out_all_required_fields'));
151  $this->showAgreement(false);
152  return false;
153  }
154  if(!$this->checkAgreement())
155  {
156  ilUtil::sendInfo($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  $value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
234  break;
235 
236  case IL_CDF_TYPE_TEXT:
237  $value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
238  break;
239  }
240  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
241  $course_user_data->setValue($value);
242  $course_user_data->update();
243 
244  if($field_obj->isRequired() and !strlen($value))
245  {
246  $all_required = false;
247  }
248  }
249  return $all_required;
250  }
251 
252 
259  private function checkAgreement()
260  {
261  global $ilUser;
262 
263  if($_POST['agreed'])
264  {
265  return true;
266  }
267  if(!$this->privacy->confirmationRequired() and !ilCourseDefinedFieldDefinition::_hasFields($this->obj_id))
268  {
269  return true;
270  }
271  return false;
272  }
273 
274 
275 
283  private function init()
284  {
285  global $ilUser;
286 
287  $this->required_fullfilled = ilCourseUserData::_checkRequired($ilUser->getId(),$this->obj_id);
288  $this->agreement_required = $this->agreement->agreementRequired();
289  }
290 
296  private function sendInfoMessage()
297  {
298  $message = '';
299  if($this->agreement_required)
300  {
301  $message = $this->lng->txt('ps_agreement_req_info');
302  }
303  if(!$this->required_fullfilled)
304  {
305  if(strlen($message))
306  {
307  $message .= '<br />';
308  }
309  $message .= $this->lng->txt('ps_required_info');
310  }
311 
312  if(strlen($message))
313  {
314  ilUtil::sendInfo($message);
315  }
316  }
317 }
318 
319 
320 ?>