ILIAS  Release_4_0_x_branch Revision 61816
 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 
153  }
154  return true;
155  }
156 
169  function _getCommands()
170  {
171  $commands = array();
172  $commands[] = array("permission" => "read", "cmd" => "", "lang_var" => "view", "default" => true);
173  $commands[] = array("permission" => "join", "cmd" => "join", "lang_var" => "join");
174 
175  // on waiting list
176  $commands[] = array('permission' => "join", "cmd" => "leave", "lang_var" => "leave_waiting_list");
177 
178  // regualar users
179  $commands[] = array('permission' => "leave", "cmd" => "leave", "lang_var" => "crs_unsubscribe");
180 
181  // BEGIN WebDAV: Mount as webfolder.
182  require_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
184  {
185  $commands[] = array("permission" => "read", "cmd" => "mount_webfolder", "lang_var" => "mount_webfolder", "enable_anonymous" => "false");
186  }
187  // END WebDAV: Mount as webfolder.
188  $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "edit");
189  return $commands;
190  }
191 
195  function _checkGoto($a_target)
196  {
197  global $ilAccess;
198 
199  $t_arr = explode("_", $a_target);
200 
201  if ($t_arr[0] != "crs" || ((int) $t_arr[1]) <= 0)
202  {
203  return false;
204  }
205 
206  // checking for read results in endless loop, if read is given
207  // but visible is not given (-> see bug 5323)
208  //if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
209  // $ilAccess->checkAccess("visible", "", $t_arr[1]))
210  if ($ilAccess->checkAccess("visible", "", $t_arr[1]))
211  {
212  return true;
213  }
214  return false;
215  }
216 
223  function _lookupViewMode($a_id)
224  {
225  global $ilDB;
226 
227  $query = "SELECT view_mode FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
228  $res = $ilDB->query($query);
229  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
230  {
231  return $row->view_mode;
232  }
233  return false;
234  }
235 
242  public static function _isActivated($a_obj_id)
243  {
244  global $ilDB;
245 
246  include_once './Services/Container/classes/class.ilMemberViewSettings.php';
247  if(ilMemberViewSettings::getInstance()->isActive())
248  {
249  return true;
250  }
251 
252  $query = "SELECT * FROM crs_settings ".
253  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
254 
255  $res = $ilDB->query($query);
256  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
257  {
258  $type = $row->activation_type;
259  $start = $row->activation_start;
260  $end = $row->activation_end;
261  }
262  switch($type)
263  {
265  return false;
266 
268  return true;
269 
271  if(time() < $start or
272  time() > $end)
273  {
274  return false;
275  }
276  return true;
277 
278  default:
279  return false;
280  }
281  }
282 
288  public static function _registrationEnabled($a_obj_id)
289  {
290  global $ilDB;
291 
292  $query = "SELECT * FROM crs_settings ".
293  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
294 
295  $res = $ilDB->query($query);
296  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
297  {
298  $type = $row->sub_limitation_type;
299  $reg_start = $row->sub_start;
300  $reg_end = $row->sub_end;
301  }
302 
303  switch($type)
304  {
306  return true;
307 
309  return false;
310 
312  if(time() > $reg_start and
313  time() < $reg_end)
314  {
315  return true;
316  }
317  default:
318  return false;
319  }
320  return false;
321  }
322 }
323 
324 ?>