ILIAS  Release_3_10_x_branch Revision 61812
 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("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  $q = sprintf("SELECT * FROM survey_survey WHERE obj_fi=%s",
144  $ilDB->quote($a_obj_id)
145  );
146  $result = $ilDB->query($q);
147 
148  if ($result->numRows() == 1)
149  {
150  $row = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
151  }
152  if (!$row->complete)
153  {
154  return false;
155  }
156 
157  return true;
158  }
159 
163  function _lookupEvaluationAccess($a_obj_id)
164  {
165  global $ilDB;
166 
167  $q = sprintf("SELECT * FROM survey_survey WHERE obj_fi=%s",
168  $ilDB->quote($a_obj_id)
169  );
170  $result = $ilDB->query($q);
171  if ($result->numRows() == 1)
172  {
173  $row = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
174  }
175 
176  return $row->evaluation_access;
177  }
178 
179  function _isSurveyParticipant($user_id, $survey_id)
180  {
181  global $ilDB;
182 
183  $q = sprintf("SELECT finished_id FROM survey_finished WHERE user_fi = %s AND survey_fi = %s",
184  $ilDB->quote($user_id . ""),
185  $ilDB->quote($survey_id . "")
186  );
187  $result = $ilDB->query($q);
188  if ($result->numRows() == 1)
189  {
190  return true;
191  }
192  else
193  {
194  return false;
195  }
196  }
197 
198  function _lookupAnonymize($a_obj_id)
199  {
200  global $ilDB;
201 
202  $q = sprintf("SELECT anonymize FROM survey_survey WHERE obj_fi = %s",
203  $ilDB->quote($a_obj_id . "")
204  );
205  $result = $ilDB->query($q);
206  if ($result->numRows() == 1)
207  {
208  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
209  return $row["anonymize"];
210  }
211  else
212  {
213  return 0;
214  }
215  }
216 
217  function _hasEvaluationAccess($a_obj_id, $user_id)
218  {
219  $evaluation_access = ilObjSurveyAccess::_lookupEvaluationAccess($a_obj_id);
220  switch ($evaluation_access)
221  {
222  case 0:
223  // no evaluation access
224  return false;
225  break;
226  case 1:
227  // evaluation access for all registered users
228  if (($user_id > 0) && ($user_id != ANONYMOUS_USER_ID))
229  {
230  return true;
231  }
232  else
233  {
234  return false;
235  }
236  break;
237  case 2:
238  // evaluation access for participants
239  // check if the user with the given id is a survey participant
240 
241  // show the evaluation button for anonymized surveys for all users
242  // access is only granted with the survey access code
243  if (ilObjSurveyAccess::_lookupAnonymize($a_obj_id) == 1) return true;
244 
245  global $ilDB;
246  $q = sprintf("SELECT survey_id FROM survey_survey WHERE obj_fi = %s",
247  $ilDB->quote($a_obj_id . "")
248  );
249  $result = $ilDB->query($q);
250  if ($result->numRows() == 1)
251  {
252  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
253  if (ilObjSurveyAccess::_isSurveyParticipant($user_id, $row["survey_id"]))
254  {
255  return true;
256  }
257  }
258  return false;
259  break;
260  }
261  }
262 
266  function _lookupOnline($a_obj_id)
267  {
268  global $ilDB;
269 
270  $q = sprintf("SELECT * FROM survey_survey WHERE obj_fi=%s",
271  $ilDB->quote($a_obj_id)
272  );
273  $result = $ilDB->query($q);
274  if ($result->numRows() == 1) {
275  $row = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
276  }
277 
278  return $row->status;
279  }
280 
286  function _lookupFinished($a_obj_id, $a_user_id = "")
287  {
288  global $ilDB, $ilUser;
289 
290  $finished = "";
291  if (!strlen($a_user_id)) $a_user_id = $ilUser->getId();
292 
293  $q = sprintf("SELECT * FROM survey_survey WHERE obj_fi = %s",
294  $ilDB->quote($a_obj_id)
295  );
296  $result = $ilDB->query($q);
297  if ($result->numRows() == 1)
298  {
299  $row = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
300  if ($row->anonymize == 1)
301  {
302  $q = sprintf("SELECT * FROM survey_finished, survey_anonymous WHERE survey_finished.survey_fi = %s AND survey_finished.survey_fi = survey_anonymous.survey_fi AND survey_anonymous.user_key = %s AND survey_anonymous.survey_key = survey_finished.anonymous_id",
303  $ilDB->quote($row->survey_id),
304  $ilDB->quote(md5($a_user_id) . "")
305  );
306  }
307  else
308  {
309  $q = sprintf("SELECT * FROM survey_finished WHERE survey_fi = %s AND user_fi = %s",
310  $ilDB->quote($row->survey_id),
311  $ilDB->quote($a_user_id)
312  );
313  }
314  $result = $ilDB->query($q);
315  if ($result->numRows() == 1)
316  {
317  $row = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
318  $finished = (int)$row->state;
319  }
320  }
321 
322  return $finished;
323  }
324 
328  function _checkGoto($a_target)
329  {
330  global $ilAccess;
331 
332  $t_arr = explode("_", $a_target);
333 
334  if ($t_arr[0] != "svy" || ((int) $t_arr[1]) <= 0)
335  {
336  return false;
337  }
338 
339  if ($ilAccess->checkAccess("read", "", $t_arr[1]))
340  {
341  return true;
342  }
343  return false;
344  }
345 
346 
347 }
348 
349 ?>