ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjContentObjectAccess.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 
36 {
49  function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
50  {
51  global $ilUser, $lng, $rbacsystem, $ilAccess;
52 
53  if ($a_user_id == "")
54  {
55  $a_user_id = $ilUser->getId();
56  }
57 
58  switch ($a_cmd)
59  {
60  case "view":
61 
63  && !$rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id))
64  {
65  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
66  return false;
67  }
68  break;
69 
70  case "continue":
71 
72  // no continue command for anonymous user
73  if ($ilUser->getId() == ANONYMOUS_USER_ID)
74  {
75  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("lm_no_continue_for_anonym"));
76  return false;
77  }
78 
80  && !$rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id))
81  {
82  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
83  return false;
84  }
85 
86  if (ilObjContentObjectAccess::_getLastAccessedPage($a_ref_id,$a_user_id) <= 0)
87  {
88  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("not_accessed_yet"));
89  return false;
90  }
91  break;
92 
93  // for permission query feature
94  case "info":
96  {
97  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
98  }
99  else
100  {
101  $ilAccess->addInfoItem(IL_STATUS_MESSAGE, $lng->txt("online"));
102  }
103  break;
104 
105  }
106 
107  switch ($a_permission)
108  {
109  case "read":
110  case "visible":
111  if (!ilObjContentObjectAccess::_lookupOnline($a_obj_id) &&
112  (!$rbacsystem->checkAccessOfUser($a_user_id,'write', $a_ref_id)))
113  {
114  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
115  return false;
116  }
117  break;
118  }
119 
120 
121  return true;
122  }
123 
124  //
125  // access relevant methods
126  //
127 
133  function _lookupOnline($a_id)
134  {
135  global $ilDB;
136 
137  $q = "SELECT * FROM content_object WHERE id = ".$ilDB->quote($a_id);
138  $lm_set = $ilDB->query($q);
139  $lm_rec = $lm_set->fetchRow(DB_FETCHMODE_ASSOC);
140 
141  return ilUtil::yn2tf($lm_rec["online"]);
142  }
143 
150  function _getLastAccessedPage($a_ref_id, $a_user_id = "")
151  {
152  global $ilDB, $ilUser;
153 
154  if ($a_user_id == "")
155  {
156  $a_user_id = $ilUser->getId();
157  }
158 
159  $q = "SELECT * FROM lo_access WHERE ".
160  "usr_id = ".$ilDB->quote($a_user_id)." AND ".
161  "lm_id = ".$ilDB->quote($a_ref_id);
162 
163  $lm_id = ilObject::_lookupObjId($a_ref_id);
164 
165  $acc_set = $ilDB->query($q);
166 
167  if ($acc_rec = $acc_set->fetchRow(DB_FETCHMODE_ASSOC))
168  {
169  $mtree = new ilTree($lm_id);
170  $mtree->setTableNames('lm_tree','lm_data');
171  $mtree->setTreeTablePK("lm_id");
172  if ($mtree->isInTree($acc_rec["obj_id"]))
173  {
174  return $acc_rec["obj_id"];
175  }
176  }
177 
178  return 0;
179  }
180 
184  function _checkGoto($a_target)
185  {
186  global $ilAccess;
187 
188  $t_arr = explode("_", $a_target);
189 
190  if (($t_arr[0] != "lm" && $t_arr[0] != "dbk" && $t_arr[0] != "st"
191  && $t_arr[0] != "pg")
192  || ((int) $t_arr[1]) <= 0)
193  {
194  return false;
195  }
196 
197  if ($t_arr[0] == "lm" || $t_arr[0] == "dbk")
198  {
199  if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
200  $ilAccess->checkAccess("visible", "", $t_arr[1]))
201  {
202  return true;
203  }
204  }
205  else
206  {
207  if ($t_arr[2] > 0)
208  {
209  $ref_ids = array($t_arr[2]);
210  }
211  else
212  {
213  // determine learning object
214  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
215  $lm_id = ilLMObject::_lookupContObjID($t_arr[1]);
216  $ref_ids = ilObject::_getAllReferences($lm_id);
217  }
218  // check read permissions
219  foreach ($ref_ids as $ref_id)
220  {
221  // Permission check
222  if ($ilAccess->checkAccess("read", "", $ref_id))
223  {
224  return true;
225  }
226  }
227 
228  }
229  return false;
230  }
231 
232 }
233 
234 ?>