ILIAS  Release_4_4_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 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Object/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 {
20 
21  protected static $using_code = false;
22 
35  function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
36  {
37  global $ilUser, $lng, $rbacsystem, $ilAccess, $ilias;
38 
39 
40  if ($a_user_id == "")
41  {
42  $a_user_id = $ilUser->getId();
43  }
44 
45  if($ilUser->getId() == $a_user_id)
46  {
47  $participants = ilCourseParticipant::_getInstanceByObjId($a_obj_id,$a_user_id);
48  }
49  else
50  {
51  $participants = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
52  }
53 
54 
55  switch ($a_cmd)
56  {
57  case "view":
58  if($participants->isBlocked($a_user_id) and $participants->isAssigned($a_user_id))
59  {
60  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("crs_status_blocked"));
61  return false;
62  }
63  break;
64 
65  case 'leave':
66 
67  // Regular member
68  if($a_permission == 'leave')
69  {
70  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
71  if(!$participants->isAssigned($a_user_id))
72  {
73  return false;
74  }
75  }
76  // Waiting list
77  if($a_permission == 'join')
78  {
79  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
80  if(!ilCourseWaitingList::_isOnList($a_user_id, $a_obj_id))
81  {
82  return false;
83  }
84  return true;
85  }
86  break;
87 
88  case 'join':
89 
90  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
91  if(ilCourseWaitingList::_isOnList($a_user_id, $a_obj_id))
92  {
93  return false;
94  }
95  break;
96  }
97 
98  switch ($a_permission)
99  {
100  case 'visible':
101  $visible = null;
102  $active = self::_isActivated($a_obj_id, $visible);
103  $tutor = $rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id);
104  if(!$active)
105  {
106  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
107  }
108  if(!$tutor and !$active && !$visible)
109  {
110  return false;
111  }
112  break;
113 
114  case 'read':
115  $tutor = $rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id);
116  if($tutor)
117  {
118  return true;
119  }
120  $active = self::_isActivated($a_obj_id);
121  if(!$active)
122  {
123  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
124  return false;
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  if(!self::_registrationEnabled($a_obj_id))
135  {
136  return false;
137  }
138 
139  if($participants->isAssigned($a_user_id))
140  {
141  return false;
142  }
143  break;
144  }
145  return true;
146  }
147 
160  function _getCommands()
161  {
162  $commands = array();
163  $commands[] = array("permission" => "crs_linked", "cmd" => "", "lang_var" => "view", "default" => true);
164 
165  include_once './Services/WebServices/FileManager/classes/class.ilFMSettings.php';
166  if(ilFMSettings::getInstance()->isEnabled())
167  {
168  $commands[] = array(
169  'permission' => 'read',
170  'cmd' => 'fileManagerLaunch',
171  'lang_var' => 'fm_start',
172  'enable_anonymous' => false
173  );
174  }
175 
176  $commands[] = array("permission" => "join", "cmd" => "join", "lang_var" => "join");
177 
178  // on waiting list
179  $commands[] = array('permission' => "join", "cmd" => "leave", "lang_var" => "leave_waiting_list");
180 
181  // regualar users
182  $commands[] = array('permission' => "leave", "cmd" => "leave", "lang_var" => "crs_unsubscribe");
183 
184  include_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
186  {
187  include_once './Services/WebDAV/classes/class.ilDAVUtils.php';
188  if(ilDAVUtils::getInstance()->isLocalPasswordInstructionRequired())
189  {
190  $commands[] = array('permission' => 'read', 'cmd' => 'showPasswordInstruction', 'lang_var' => 'mount_webfolder', 'enable_anonymous' => 'false');
191  }
192  else
193  {
194  $commands[] = array("permission" => "read", "cmd" => "mount_webfolder", "lang_var" => "mount_webfolder", "enable_anonymous" => "false");
195  }
196  }
197 
198  $commands[] = array("permission" => "write", "cmd" => "enableAdministrationPanel", "lang_var" => "edit_content");
199  $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "settings");
200  return $commands;
201  }
202 
206  function _checkGoto($a_target)
207  {
208  global $ilAccess,$ilUser;
209 
210  $t_arr = explode("_", $a_target);
211 
212  // registration codes
213  if(substr($t_arr[2],0,5) == 'rcode' and $ilUser->getId() != ANONYMOUS_USER_ID)
214  {
215  self::$using_code = true;
216  return true;
217  }
218 
219 
220  if ($t_arr[0] != "crs" || ((int) $t_arr[1]) <= 0)
221  {
222  return false;
223  }
224 
225  // checking for read results in endless loop, if read is given
226  // but visible is not given (-> see bug 5323)
227  if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
228  $ilAccess->checkAccess("visible", "", $t_arr[1]))
229  //if ($ilAccess->checkAccess("visible", "", $t_arr[1]))
230  {
231  return true;
232  }
233  return false;
234  }
235 
242  function _lookupViewMode($a_id)
243  {
244  global $ilDB;
245 
246  $query = "SELECT view_mode FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
247  $res = $ilDB->query($query);
248  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
249  {
250  return $row->view_mode;
251  }
252  return false;
253  }
254 
261  protected static function _isOnline($a_obj_id)
262  {
263  global $ilDB;
264 
265  $query = "SELECT * FROM crs_settings ".
266  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
267  $res = $ilDB->query($query);
268  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
269  return (bool)$row->activation_type;
270  }
271 
281  public static function _isActivated($a_obj_id, &$a_visible_flag = null, $a_mind_member_view = true)
282  {
283  // #7669
284  if($a_mind_member_view)
285  {
286  include_once './Services/Container/classes/class.ilMemberViewSettings.php';
287  if(ilMemberViewSettings::getInstance()->isActive())
288  {
289  $a_visible_flag = true;
290  return true;
291  }
292  }
293 
294  // offline?
295  if(!self::_isOnline($a_obj_id))
296  {
297  $a_visible_flag = false;
298  return false;
299  }
300 
302  $ref_id = array_pop($ref_id);
303 
304  $a_visible_flag = true;
305 
306  include_once './Services/Object/classes/class.ilObjectActivation.php';
308  switch($item['timing_type'])
309  {
311  if(time() < $item['timing_start'] or
312  time() > $item['timing_end'])
313  {
314  $a_visible_flag = $item['visible'];
315  return false;
316  }
317  // fallthrough
318 
319  default:
320  return true;
321  }
322  }
323 
329  public static function _registrationEnabled($a_obj_id)
330  {
331  global $ilDB;
332 
333  $query = "SELECT * FROM crs_settings ".
334  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
335 
336  $res = $ilDB->query($query);
337  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
338  {
339  $type = $row->sub_limitation_type;
340  $reg_start = $row->sub_start;
341  $reg_end = $row->sub_end;
342  }
343 
344  switch($type)
345  {
347  return true;
348 
350  return false;
351 
353  if(time() > $reg_start and
354  time() < $reg_end)
355  {
356  return true;
357  }
358  default:
359  return false;
360  }
361  return false;
362  }
363 
372  public static function lookupRegistrationInfo($a_obj_id)
373  {
374  global $ilDB, $ilUser, $lng;
375 
376  $query = 'SELECT sub_limitation_type, sub_start, sub_end, sub_mem_limit, sub_max_members FROM crs_settings '.
377  'WHERE obj_id = '.$ilDB->quote($a_obj_id);
378  $res = $ilDB->query($query);
379 
380  $info = array();
381  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
382  {
383  $info['reg_info_start'] = new ilDateTime($row->sub_start, IL_CAL_UNIX);
384  $info['reg_info_end'] = new ilDateTime($row->sub_end, IL_CAL_UNIX);
385  $info['reg_info_type'] = $row->sub_limitation_type;
386  $info['reg_info_max_members'] = $row->sub_max_members;
387  $info['reg_info_mem_limit'] = $row->sub_mem_limit;
388  }
389 
390  $registration_possible = true;
391 
392  // Limited registration
393  if($info['reg_info_type'] == ilCourseConstants::SUBSCRIPTION_LIMITED)
394  {
395  $dt = new ilDateTime(time(),IL_CAL_UNIX);
396  if(ilDateTime::_before($dt, $info['reg_info_start']))
397  {
398  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_start');
399  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_start']);
400  }
401  elseif(ilDateTime::_before($dt, $info['reg_info_end']))
402  {
403  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_end');
404  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_end']);
405  }
406  else
407  {
408  $registration_possible = false;
409  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_period');
410  $info['reg_info_list_prop']['value'] = $lng->txt('crs_list_reg_noreg');
411  }
412  }
413  else if($info['reg_info_type'] == ilCourseConstants::SUBSCRIPTION_UNLIMITED)
414  {
415  $registration_possible = true;
416  }
417  else
418  {
419  $registration_possible = false;
420  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_period');
421  $info['reg_info_list_prop']['value'] = $lng->txt('crs_list_reg_noreg');
422  }
423 
424  if($info['reg_info_mem_limit'] && $registration_possible)
425  {
426  // Check if users are on waiting list
427  // @todo
428 
429 
430  // Check for free places
431  $part = ilCourseParticipant::_getInstanceByObjId($a_obj_id, $ilUser->getId());
432  if($part->getNumberOfMembers() <= $info['reg_info_max_members'])
433  {
434  $info['reg_info_list_prop_limit']['property'] = $lng->txt('crs_list_reg_limit_places');
435  $info['reg_info_list_prop_limit']['value'] = max(
436  0,
437  $info['reg_info_max_members'] - $part->getNumberOfMembers()
438  );
439  }
440  else
441  {
442  $info['reg_info_list_prop_limit']['property'] = '';
443  $info['reg_info_list_prop_limit']['value'] = $lng->txt('crs_list_reg_limit_full');
444  }
445  }
446 
447  return $info;
448  }
449 
458  static function _isOffline($a_obj_id)
459  {
460  $dummy = null;
461  return !self::_isActivated($a_obj_id, $dummy, false);
462  }
463 
469  function _preloadData($a_obj_ids, $a_ref_ids)
470  {
471  global $ilUser;
472 
473  include_once("./Modules/Course/classes/class.ilCourseWaitingList.php");
474  ilCourseWaitingList::_preloadOnListInfo($ilUser->getId(), $a_obj_ids);
475 
476  include_once "./Modules/Course/classes/class.ilCourseCertificateAdapter.php";
477  ilCourseCertificateAdapter::_preloadListData($ilUser->getId(), $a_obj_ids);
478  }
479 
485  public static function _usingRegistrationCode()
486  {
487  return self::$using_code;
488  }
489 
490 }
491 
492 ?>