ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjCourseAccess.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("classes/class.ilObjectAccess.php");
6 include_once './Modules/Course/classes/class.ilCourseConstants.php';
7 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
8 include_once 'Modules/Course/classes/class.ilCourseParticipant.php';
9 
19 {
32  function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
33  {
34  global $ilUser, $lng, $rbacsystem, $ilAccess, $ilias;
35 
36 
37  if ($a_user_id == "")
38  {
39  $a_user_id = $ilUser->getId();
40  }
41 
42  if($ilUser->getId() == $a_user_id)
43  {
44  $participants = ilCourseParticipant::_getInstanceByObjId($a_obj_id,$a_user_id);
45  }
46  else
47  {
48  $participants = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
49  }
50 
51 
52  switch ($a_cmd)
53  {
54  case "view":
55  if($participants->isBlocked($a_user_id) and $participants->isAssigned($a_user_id))
56  {
57  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("crs_status_blocked"));
58  return false;
59  }
60  break;
61 
62  case 'leave':
63 
64  // Regular member
65  if($a_permission == 'leave')
66  {
67  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
68  if(!$participants->isAssigned($a_user_id))
69  {
70  return false;
71  }
72  }
73  // Waiting list
74  if($a_permission == 'join')
75  {
76  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
77  if(!ilCourseWaitingList::_isOnList($ilUser->getId(), $a_obj_id))
78  {
79  return false;
80  }
81  return true;
82  }
83  break;
84  }
85 
86  switch ($a_permission)
87  {
88  case "visible":
89  $active = ilObjCourseAccess::_isActivated($a_obj_id);
90  $registration = ilObjCourseAccess::_registrationEnabled($a_obj_id);
91  $tutor = $rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id);
92 
93  if(!$active)
94  {
95  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
96  }
97  if(!$tutor and !$active)
98  {
99  return false;
100  }
101  break;
102 
103  case 'read':
104  $tutor = $rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id);
105  if($tutor)
106  {
107  return true;
108  }
109  $active = ilObjCourseAccess::_isActivated($a_obj_id);
110 
111  if(!$active)
112  {
113  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
114  return false;
115  }
116 
117  if($participants->isBlocked($a_user_id) and $participants->isAssigned($a_user_id))
118  {
119  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("crs_status_blocked"));
120  return false;
121  }
122  break;
123 
124  case 'join':
125 
126  if(!self::_registrationEnabled($a_obj_id))
127  {
128  return false;
129  }
130 
131  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
132  if(ilCourseWaitingList::_isOnList($ilUser->getId(), $a_obj_id))
133  {
134  return false;
135  }
136 
137  if($participants->isAssigned($a_user_id))
138  {
139  return false;
140  }
141  break;
142  }
143  return true;
144  }
145 
158  function _getCommands()
159  {
160  $commands = array();
161  $commands[] = array("permission" => "read", "cmd" => "", "lang_var" => "view", "default" => true);
162  $commands[] = array("permission" => "join", "cmd" => "join", "lang_var" => "join");
163 
164  // on waiting list
165  $commands[] = array('permission' => "join", "cmd" => "leave", "lang_var" => "leave_waiting_list");
166 
167  // regualar users
168  $commands[] = array('permission' => "leave", "cmd" => "leave", "lang_var" => "crs_unsubscribe");
169 
170  include_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
172  {
173  include_once './Services/WebDAV/classes/class.ilDAVUtils.php';
174  if(ilDAVUtils::getInstance()->isLocalPasswordInstructionRequired())
175  {
176  $commands[] = array('permission' => 'read', 'cmd' => 'showPasswordInstruction', 'lang_var' => 'mount_webfolder', 'enable_anonymous' => 'false');
177  }
178  else
179  {
180  $commands[] = array("permission" => "read", "cmd" => "mount_webfolder", "lang_var" => "mount_webfolder", "enable_anonymous" => "false");
181  }
182  }
183 
184  $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "edit");
185  return $commands;
186  }
187 
191  function _checkGoto($a_target)
192  {
193  global $ilAccess,$ilUser;
194 
195  $t_arr = explode("_", $a_target);
196 
197  // registration codes
198  if(substr($t_arr[2],0,5) == 'rcode' and $ilUser->getId() != ANONYMOUS_USER_ID)
199  {
200  return true;
201  }
202 
203 
204  if ($t_arr[0] != "crs" || ((int) $t_arr[1]) <= 0)
205  {
206  return false;
207  }
208 
209  // checking for read results in endless loop, if read is given
210  // but visible is not given (-> see bug 5323)
211  //if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
212  // $ilAccess->checkAccess("visible", "", $t_arr[1]))
213  if ($ilAccess->checkAccess("visible", "", $t_arr[1]))
214  {
215  return true;
216  }
217  return false;
218  }
219 
226  function _lookupViewMode($a_id)
227  {
228  global $ilDB;
229 
230  $query = "SELECT view_mode FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
231  $res = $ilDB->query($query);
232  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
233  {
234  return $row->view_mode;
235  }
236  return false;
237  }
238 
246  public static function _isActivated($a_obj_id, $a_mind_member_view = true)
247  {
248  global $ilDB;
249 
250  // #7669
251  if($a_mind_member_view)
252  {
253  include_once './Services/Container/classes/class.ilMemberViewSettings.php';
254  if(ilMemberViewSettings::getInstance()->isActive())
255  {
256  return true;
257  }
258  }
259 
260  $query = "SELECT * FROM crs_settings ".
261  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
262 
263  $res = $ilDB->query($query);
264 
265  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
266  {
267  $type = $row->activation_type;
268  $start = $row->activation_start;
269  $end = $row->activation_end;
270  }
271  switch($type)
272  {
274  return false;
275 
277  return true;
278 
280  if(time() < $start or
281  time() > $end)
282  {
283  return false;
284  }
285  return true;
286 
287  default:
288  return false;
289  }
290  }
291 
297  public static function _registrationEnabled($a_obj_id)
298  {
299  global $ilDB;
300 
301  $query = "SELECT * FROM crs_settings ".
302  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
303 
304  $res = $ilDB->query($query);
305  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
306  {
307  $type = $row->sub_limitation_type;
308  $reg_start = $row->sub_start;
309  $reg_end = $row->sub_end;
310  }
311 
312  switch($type)
313  {
315  return true;
316 
318  return false;
319 
321  if(time() > $reg_start and
322  time() < $reg_end)
323  {
324  return true;
325  }
326  default:
327  return false;
328  }
329  return false;
330  }
331 
340  static function _isOffline($a_obj_id)
341  {
342  return !self::_isActivated($a_obj_id, false);
343  }
344 
350  function _preloadData($a_obj_ids, $a_ref_ids)
351  {
352  global $ilDB, $ilUser;
353 
354  include_once("./Modules/Course/classes/class.ilCourseWaitingList.php");
355  ilCourseWaitingList::_preloadOnListInfo($ilUser->getId(), $a_obj_ids);
356  }
357 
358 }
359 
360 ?>