ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjCourseAccess.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2009 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/Course/classes/class.ilCourseConstants.php';
26 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
27 
37 {
50  function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
51  {
52  global $ilUser, $lng, $rbacsystem, $ilAccess, $ilias;
53 
54  if ($a_user_id == "")
55  {
56  $a_user_id = $ilUser->getId();
57  }
58 
59  $participants = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
60 
61  switch ($a_cmd)
62  {
63  case "view":
64  if($participants->isBlocked($a_user_id) and $participants->isAssigned($a_user_id))
65  {
66  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("crs_status_blocked"));
67  return false;
68  }
69  break;
70 
71  case 'leave':
72 
73  // Regular member
74  if($a_permission == 'leave')
75  {
76  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
77  if(!$participants->isAssigned($a_user_id) or $participants->isLastAdmin($a_user_id))
78  {
79  return false;
80  }
81  }
82  // Waiting list
83  if($a_permission == 'join')
84  {
85  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
86  if(!ilCourseWaitingList::_isOnList($ilUser->getId(), $a_obj_id))
87  {
88  return false;
89  }
90  return true;
91  }
92  break;
93  }
94 
95  switch ($a_permission)
96  {
97  case "visible":
98  $active = ilObjCourseAccess::_isActivated($a_obj_id);
99  $registration = ilObjCourseAccess::_registrationEnabled($a_obj_id);
100  $tutor = $rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id);
101 
102  if(!$active)
103  {
104  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
105  }
106  if(!$tutor and !$active)
107  {
108  return false;
109  }
110  break;
111 
112  case 'read':
113  $tutor = $rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id);
114  if($tutor)
115  {
116  return true;
117  }
118  $active = ilObjCourseAccess::_isActivated($a_obj_id);
119 
120  if(!$active)
121  {
122  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
123  return false;
124  }
125 
126  if($participants->isBlocked($a_user_id) and $participants->isAssigned($a_user_id))
127  {
128  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("crs_status_blocked"));
129  return false;
130  }
131  break;
132 
133  case 'join':
134 
135  if(!self::_registrationEnabled($a_obj_id))
136  {
137  return false;
138  }
139 
140  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
141  if(ilCourseWaitingList::_isOnList($ilUser->getId(), $a_obj_id))
142  {
143  return false;
144  }
145 
146  if($participants->isAssigned($a_user_id))
147  {
148  return false;
149  }
150  break;
151  }
152  return true;
153  }
154 
167  function _getCommands()
168  {
169  $commands = array();
170  $commands[] = array("permission" => "read", "cmd" => "", "lang_var" => "view", "default" => true);
171  $commands[] = array("permission" => "join", "cmd" => "join", "lang_var" => "join");
172 
173  // on waiting list
174  $commands[] = array('permission' => "join", "cmd" => "leave", "lang_var" => "leave_waiting_list");
175 
176  // regualar users
177  $commands[] = array('permission' => "leave", "cmd" => "leave", "lang_var" => "crs_unsubscribe");
178 
179  include_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
181  {
182  include_once './Services/WebDAV/classes/class.ilDAVUtils.php';
183  if(ilDAVUtils::getInstance()->isLocalPasswordInstructionRequired())
184  {
185  $commands[] = array('permission' => 'read', 'cmd' => 'showPasswordInstruction', 'lang_var' => 'mount_webfolder', 'enable_anonymous' => 'false');
186  }
187  else
188  {
189  $commands[] = array("permission" => "read", "cmd" => "mount_webfolder", "lang_var" => "mount_webfolder", "enable_anonymous" => "false");
190  }
191  }
192 
193  $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "edit");
194  return $commands;
195  }
196 
200  function _checkGoto($a_target)
201  {
202  global $ilAccess,$ilUser;
203 
204  $t_arr = explode("_", $a_target);
205 
206  // registration codes
207  if(substr($t_arr[2],0,5) == 'rcode' and $ilUser->getId() != ANONYMOUS_USER_ID)
208  {
209  return true;
210  }
211 
212 
213  if ($t_arr[0] != "crs" || ((int) $t_arr[1]) <= 0)
214  {
215  return false;
216  }
217 
218  // checking for read results in endless loop, if read is given
219  // but visible is not given (-> see bug 5323)
220  //if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
221  // $ilAccess->checkAccess("visible", "", $t_arr[1]))
222  if ($ilAccess->checkAccess("visible", "", $t_arr[1]))
223  {
224  return true;
225  }
226  return false;
227  }
228 
235  function _lookupViewMode($a_id)
236  {
237  global $ilDB;
238 
239  $query = "SELECT view_mode FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
240  $res = $ilDB->query($query);
241  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
242  {
243  return $row->view_mode;
244  }
245  return false;
246  }
247 
254  public static function _isActivated($a_obj_id)
255  {
256  global $ilDB;
257 
258  include_once './Services/Container/classes/class.ilMemberViewSettings.php';
259  if(ilMemberViewSettings::getInstance()->isActive())
260  {
261  return true;
262  }
263 
264  $query = "SELECT * FROM crs_settings ".
265  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
266 
267  $res = $ilDB->query($query);
268 
269  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
270  {
271  $type = $row->activation_type;
272  $start = $row->activation_start;
273  $end = $row->activation_end;
274  }
275  switch($type)
276  {
278  return false;
279 
281  return true;
282 
284  if(time() < $start or
285  time() > $end)
286  {
287  return false;
288  }
289  return true;
290 
291  default:
292  return false;
293  }
294  }
295 
301  public static function _registrationEnabled($a_obj_id)
302  {
303  global $ilDB;
304 
305  $query = "SELECT * FROM crs_settings ".
306  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
307 
308  $res = $ilDB->query($query);
309  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
310  {
311  $type = $row->sub_limitation_type;
312  $reg_start = $row->sub_start;
313  $reg_end = $row->sub_end;
314  }
315 
316  switch($type)
317  {
319  return true;
320 
322  return false;
323 
325  if(time() > $reg_start and
326  time() < $reg_end)
327  {
328  return true;
329  }
330  default:
331  return false;
332  }
333  return false;
334  }
335 }
336 
337 ?>