ILIAS  Release_4_1_x_branch Revision 61804
 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  $this->tpl->setVariable('SEL_SELECT',ilUtil::formSelect($course_user_data->getValue(),
189  'cdf['.$field_obj->getId().']',
190  $field_obj->prepareSelectBox(),
191  false,
192  true));
193  break;
194  case IL_CDF_TYPE_TEXT:
195  $this->tpl->setCurrentBlock('txt_row');
196  $this->tpl->setVariable('TXT_ROW_NAME',$field_obj->getId());
197  $this->tpl->setVariable('TXT_ROW_VALUE',$course_user_data->getValue());
198  break;
199  }
200  if($field_obj->isRequired())
201  {
202  $this->show_required_info = true;
203  $this->tpl->touchBlock('cdf_required');
204  }
205 
206  $this->tpl->setCurrentBlock('cdf_row');
207  $this->tpl->setVariable('CDF_FIELD_NAME',$field_obj->getName());
208  $this->tpl->parseCurrentBlock();
209  }
210  $this->tpl->setCurrentBlock('cdf');
211  $this->tpl->setVariable('CDF_TXT',$this->lng->txt($this->type.'_ps_cdf_info'));
212  $this->tpl->parseCurrentBlock();
213  }
214 
221  private function checkCourseDefinedFields()
222  {
223  global $ilUser;
224 
225  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
226  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
227 
228  $all_required = true;
229  foreach(ilCourseDefinedFieldDefinition::_getFields($this->obj_id) as $field_obj)
230  {
231  switch($field_obj->getType())
232  {
233  case IL_CDF_TYPE_SELECT:
234  $tmp_value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
235  $value = '';
236  foreach((array) $field_obj->getValues() as $v)
237  {
238  if($v == $tmp_value)
239  {
240  $value = $tmp_value;
241  break;
242  }
243  }
244  break;
245 
246  case IL_CDF_TYPE_TEXT:
247  $value = ilUtil::stripSlashes($_POST['cdf'][$field_obj->getId()]);
248  break;
249  }
250  $course_user_data = new ilCourseUserData($ilUser->getId(),$field_obj->getId());
251  $course_user_data->setValue($value);
252  $course_user_data->update();
253 
254  if($field_obj->isRequired() and !$value)
255  {
256  $all_required = false;
257  }
258  }
259  return $all_required;
260  }
261 
262 
269  private function checkAgreement()
270  {
271  global $ilUser;
272 
273  if($_POST['agreed'])
274  {
275  return true;
276  }
277  if(!$this->privacy->confirmationRequired($this->type) and !ilCourseDefinedFieldDefinition::_hasFields($this->obj_id))
278  {
279  return true;
280  }
281  return false;
282  }
283 
284 
285 
293  private function init()
294  {
295  global $ilUser;
296 
297  $this->required_fullfilled = ilCourseUserData::_checkRequired($ilUser->getId(),$this->obj_id);
298  $this->agreement_required = $this->agreement->agreementRequired();
299  }
300 
306  private function sendInfoMessage()
307  {
308  $message = '';
309  if($this->agreement_required)
310  {
311  $message = $this->lng->txt($this->type.'_ps_agreement_req_info');
312  }
313  if(!$this->required_fullfilled)
314  {
315  if(strlen($message))
316  {
317  $message .= '<br />';
318  }
319  $message .= $this->lng->txt($this->type.'_ps_required_info');
320  }
321 
322  if(strlen($message))
323  {
324  ilUtil::sendFailure($message);
325  }
326  }
327 }
328 
329 
330 ?>