ILIAS  eassessment Revision 61809
 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":
67  (!$rbacsystem->checkAccess('write', $a_ref_id)))
68  {
69  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("warning_survey_not_complete"));
70  return false;
71  }
72  break;
73  }
74 
75  switch ($a_cmd)
76  {
77  case "run":
79  || !(ilObjSurveyAccess::_lookupOnline($a_obj_id) == 1))
80  {
81  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("warning_survey_not_complete"));
82  return false;
83  }
84  break;
85 
86  case "evaluation":
88  {
89  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("warning_survey_not_complete"));
90  return false;
91  }
92  if ($rbacsystem->checkAccess("write",$a_ref_id) || ilObjSurveyAccess::_hasEvaluationAccess($a_obj_id, $a_user_id))
93  {
94  return true;
95  }
96  else
97  {
98  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("status_no_permission"));
99  return false;
100  }
101  break;
102  }
103 
104  return true;
105  }
106 
107 
120  function _getCommands()
121  {
122  $commands = array
123  (
124  array("permission" => "read", "cmd" => "infoScreen", "lang_var" => "svy_run", "default" => true),
125  array("permission" => "write", "cmd" => "properties", "lang_var" => "edit"),
126  array("permission" => "read", "cmd" => "evaluation", "lang_var" => "svy_evaluation")
127  );
128 
129  return $commands;
130  }
131 
132  //
133  // object specific access related methods
134  //
135 
139  function _lookupCreationComplete($a_obj_id)
140  {
141  global $ilDB;
142 
143  $result = $ilDB->queryF("SELECT * FROM svy_svy WHERE obj_fi=%s",
144  array('integer'),
145  array($a_obj_id)
146  );
147 
148  if ($result->numRows() == 1)
149  {
150  $row = $ilDB->fetchAssoc($result);
151  }
152  if (!$row["complete"])
153  {
154  return false;
155  }
156  return true;
157  }
158 
162  function _lookupEvaluationAccess($a_obj_id)
163  {
164  global $ilDB;
165 
166  $result = $ilDB->queryF("SELECT * FROM svy_svy WHERE obj_fi=%s",
167  array('integer'),
168  array($a_obj_id)
169  );
170  if ($result->numRows() == 1)
171  {
172  $row = $ilDB->fetchAssoc($result);
173  }
174 
175  return $row["evaluation_access"];
176  }
177 
178  function _isSurveyParticipant($user_id, $survey_id)
179  {
180  global $ilDB;
181 
182  $result = $ilDB->queryF("SELECT finished_id FROM svy_finished WHERE user_fi = %s AND survey_fi = %s",
183  array('integer','integer'),
184  array($user_id, $survey_id)
185  );
186  return ($result->numRows() == 1) ? true : false;
187  }
188 
189  function _lookupAnonymize($a_obj_id)
190  {
191  global $ilDB;
192 
193  $result = $ilDB->queryF("SELECT anonymize FROM svy_svy WHERE obj_fi = %s",
194  array('integer'),
195  array($a_obj_id)
196  );
197  if ($result->numRows() == 1)
198  {
199  $row = $ilDB->fetchAssoc($result);
200  return $row["anonymize"];
201  }
202  else
203  {
204  return 0;
205  }
206  }
207 
208  function _hasEvaluationAccess($a_obj_id, $user_id)
209  {
210  $evaluation_access = ilObjSurveyAccess::_lookupEvaluationAccess($a_obj_id);
211  switch ($evaluation_access)
212  {
213  case 0:
214  // no evaluation access
215  return false;
216  break;
217  case 1:
218  // evaluation access for all registered users
219  if (($user_id > 0) && ($user_id != ANONYMOUS_USER_ID))
220  {
221  return true;
222  }
223  else
224  {
225  return false;
226  }
227  break;
228  case 2:
229  // evaluation access for participants
230  // check if the user with the given id is a survey participant
231 
232  // show the evaluation button for anonymized surveys for all users
233  // access is only granted with the survey access code
234  if (ilObjSurveyAccess::_lookupAnonymize($a_obj_id) == 1) return true;
235 
236  global $ilDB;
237  $result = $ilDB->queryF("SELECT survey_id FROM svy_svy WHERE obj_fi = %s",
238  array('integer'),
239  array($a_obj_id)
240  );
241  if ($result->numRows() == 1)
242  {
243  $row = $ilDB->fetchAssoc($result);
244  if (ilObjSurveyAccess::_isSurveyParticipant($user_id, $row["survey_id"]))
245  {
246  return true;
247  }
248  }
249  return false;
250  break;
251  }
252  }
253 
257  function _lookupOnline($a_obj_id)
258  {
259  global $ilDB;
260 
261  $result = $ilDB->queryF("SELECT * FROM svy_svy WHERE obj_fi=%s",
262  array('integer'),
263  array($a_obj_id)
264  );
265  if ($result->numRows() == 1) {
266  $row = $ilDB->fetchAssoc($result);
267  }
268 
269  return $row["status"];
270  }
271 
277  function _lookupFinished($a_obj_id, $a_user_id = "")
278  {
279  global $ilDB, $ilUser;
280 
281  $finished = "";
282  if (!strlen($a_user_id)) $a_user_id = $ilUser->getId();
283 
284  $result = $ilDB->queryF("SELECT * FROM svy_svy WHERE obj_fi = %s",
285  array('integer'),
286  array($a_obj_id)
287  );
288  if ($result->numRows() == 1)
289  {
290  $row = $ilDB->fetchObject($result);
291  if ($row->anonymize == 1)
292  {
293  $result = $ilDB->queryF("SELECT * FROM svy_finished, svy_anonymous WHERE svy_finished.survey_fi = %s ".
294  "AND svy_finished.survey_fi = svy_anonymous.survey_fi AND svy_anonymous.user_key = %s ".
295  "AND svy_anonymous.survey_key = svy_finished.anonymous_id",
296  array('integer','text'),
297  array($row->survey_id, md5($a_user_id))
298  );
299  }
300  else
301  {
302  $result = $ilDB->queryF("SELECT * FROM svy_finished WHERE survey_fi = %s AND user_fi = %s",
303  array('integer','integer'),
304  array($row->survey_id, $a_user_id)
305  );
306  }
307  if ($result->numRows() == 1)
308  {
309  $foundrow = $ilDB->fetchAssoc($result);
310  $finished = (int)$foundrow["state"];
311  }
312  }
313 
314  return $finished;
315  }
316 
320  function _checkGoto($a_target)
321  {
322  global $ilAccess;
323 
324  $t_arr = explode("_", $a_target);
325 
326  if ($t_arr[0] != "svy" || ((int) $t_arr[1]) <= 0)
327  {
328  return false;
329  }
330 
331  if ($ilAccess->checkAccess("read", "", $t_arr[1]))
332  {
333  return true;
334  }
335  return false;
336  }
337 
338 
339 }
340 
341 ?>