ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSurveyAccess.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 "./classes/class.ilObjectAccess.php";
25 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
26 
38 {
54  function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
55  {
56  global $ilUser, $lng, $rbacsystem, $ilAccess;
57 
58  if ($a_user_id == "")
59  {
60  $a_user_id = $ilUser->getId();
61  }
62 
63  switch ($a_permission)
64  {
65  case "visible":
66  $active = ilObjSurveyAccess::_lookupOnline($a_obj_id);
67  $admin = $rbacsystem->checkAccessOfUser($a_user_id,"write",$a_ref_id);
68 
69  if (!$admin &&
71  {
72  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("warning_survey_not_complete"));
73  return false;
74  }
75 
76  if(!$active)
77  {
78  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
79  }
80  if (!$active && !$admin)
81  {
82  return false;
83  }
84  break;
85 
86  case "read":
87  if($rbacsystem->checkAccessOfUser($a_user_id,"write",$a_ref_id))
88  {
89  return true;
90  }
91  if(!ilObjSurveyAccess::_lookupOnline($a_obj_id))
92  {
93  return false;
94  }
95  break;
96  }
97 
98  switch ($a_cmd)
99  {
100  case "run":
102  || !(ilObjSurveyAccess::_lookupOnline($a_obj_id) == 1))
103  {
104  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("warning_survey_not_complete"));
105  return false;
106  }
107  break;
108 
109  case "evaluation":
111  {
112  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("warning_survey_not_complete"));
113  return false;
114  }
115  if ($rbacsystem->checkAccess("write",$a_ref_id) || ilObjSurveyAccess::_hasEvaluationAccess($a_obj_id, $a_user_id))
116  {
117  return true;
118  }
119  else
120  {
121  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("status_no_permission"));
122  return false;
123  }
124  break;
125  }
126 
127  return true;
128  }
129 
130 
143  function _getCommands()
144  {
145  $commands = array
146  (
147  array("permission" => "read", "cmd" => "infoScreen", "lang_var" => "svy_run", "default" => true),
148  array("permission" => "write", "cmd" => "questionsrepo", "lang_var" => "edit_questions"),
149  array("permission" => "write", "cmd" => "properties", "lang_var" => "settings"),
150  array("permission" => "read", "cmd" => "evaluation", "lang_var" => "svy_evaluation")
151  );
152 
153  return $commands;
154  }
155 
156  //
157  // object specific access related methods
158  //
159 
163  function _lookupCreationComplete($a_obj_id)
164  {
165  global $ilDB;
166 
167  $result = $ilDB->queryF("SELECT * FROM svy_svy WHERE obj_fi=%s",
168  array('integer'),
169  array($a_obj_id)
170  );
171 
172  if ($result->numRows() == 1)
173  {
174  $row = $ilDB->fetchAssoc($result);
175  }
176  if (!$row["complete"])
177  {
178  return false;
179  }
180  return true;
181  }
182 
186  function _lookupEvaluationAccess($a_obj_id)
187  {
188  global $ilDB;
189 
190  $result = $ilDB->queryF("SELECT * FROM svy_svy WHERE obj_fi=%s",
191  array('integer'),
192  array($a_obj_id)
193  );
194  if ($result->numRows() == 1)
195  {
196  $row = $ilDB->fetchAssoc($result);
197  }
198 
199  return $row["evaluation_access"];
200  }
201 
202  function _isSurveyParticipant($user_id, $survey_id)
203  {
204  global $ilDB;
205 
206  $result = $ilDB->queryF("SELECT finished_id FROM svy_finished WHERE user_fi = %s AND survey_fi = %s",
207  array('integer','integer'),
208  array($user_id, $survey_id)
209  );
210  return ($result->numRows() == 1) ? true : false;
211  }
212 
213  function _lookupAnonymize($a_obj_id)
214  {
215  global $ilDB;
216 
217  $result = $ilDB->queryF("SELECT anonymize FROM svy_svy WHERE obj_fi = %s",
218  array('integer'),
219  array($a_obj_id)
220  );
221  if ($result->numRows() == 1)
222  {
223  $row = $ilDB->fetchAssoc($result);
224  return $row["anonymize"];
225  }
226  else
227  {
228  return 0;
229  }
230  }
231 
232  function _hasEvaluationAccess($a_obj_id, $user_id)
233  {
234  $evaluation_access = ilObjSurveyAccess::_lookupEvaluationAccess($a_obj_id);
235  switch ($evaluation_access)
236  {
237  case 0:
238  // no evaluation access
239  return false;
240  break;
241  case 1:
242  // evaluation access for all registered users
243  if (($user_id > 0) && ($user_id != ANONYMOUS_USER_ID))
244  {
245  return true;
246  }
247  else
248  {
249  return false;
250  }
251  break;
252  case 2:
253  // evaluation access for participants
254  // check if the user with the given id is a survey participant
255 
256  // show the evaluation button for anonymized surveys for all users
257  // access is only granted with the survey access code
258  if (ilObjSurveyAccess::_lookupAnonymize($a_obj_id) == 1) return true;
259 
260  global $ilDB;
261  $result = $ilDB->queryF("SELECT survey_id FROM svy_svy WHERE obj_fi = %s",
262  array('integer'),
263  array($a_obj_id)
264  );
265  if ($result->numRows() == 1)
266  {
267  $row = $ilDB->fetchAssoc($result);
268  if (ilObjSurveyAccess::_isSurveyParticipant($user_id, $row["survey_id"]))
269  {
270  return true;
271  }
272  }
273  return false;
274  break;
275  }
276  }
277 
281  function _lookupOnline($a_obj_id)
282  {
283  global $ilDB;
284 
285  $result = $ilDB->queryF("SELECT * FROM svy_svy WHERE obj_fi=%s",
286  array('integer'),
287  array($a_obj_id)
288  );
289  if ($result->numRows() == 1) {
290  $row = $ilDB->fetchAssoc($result);
291  }
292 
293  return $row["status"];
294  }
295 
301  function _lookupFinished($a_obj_id, $a_user_id = "")
302  {
303  global $ilDB, $ilUser;
304 
305  $finished = "";
306  if (!strlen($a_user_id)) $a_user_id = $ilUser->getId();
307 
308  $result = $ilDB->queryF("SELECT * FROM svy_svy WHERE obj_fi = %s",
309  array('integer'),
310  array($a_obj_id)
311  );
312  if ($result->numRows() == 1)
313  {
314  $row = $ilDB->fetchObject($result);
315  if ($row->anonymize == 1)
316  {
317  $result = $ilDB->queryF("SELECT * FROM svy_finished, svy_anonymous WHERE svy_finished.survey_fi = %s ".
318  "AND svy_finished.survey_fi = svy_anonymous.survey_fi AND svy_anonymous.user_key = %s ".
319  "AND svy_anonymous.survey_key = svy_finished.anonymous_id",
320  array('integer','text'),
321  array($row->survey_id, md5($a_user_id))
322  );
323  }
324  else
325  {
326  $result = $ilDB->queryF("SELECT * FROM svy_finished WHERE survey_fi = %s AND user_fi = %s",
327  array('integer','integer'),
328  array($row->survey_id, $a_user_id)
329  );
330  }
331  if ($result->numRows() == 1)
332  {
333  $foundrow = $ilDB->fetchAssoc($result);
334  $finished = (int)$foundrow["state"];
335  }
336  }
337 
338  return $finished;
339  }
340 
344  function _checkGoto($a_target)
345  {
346  global $ilAccess;
347 
348  $t_arr = explode("_", $a_target);
349 
350  if ($t_arr[0] != "svy" || ((int) $t_arr[1]) <= 0)
351  {
352  return false;
353  }
354 
355  if ($ilAccess->checkAccess("read", "", $t_arr[1]))
356  {
357  return true;
358  }
359  return false;
360  }
361 
362 
363 }
364 
365 ?>