ILIAS  release_4-3 Revision
 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 {
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($a_user_id, $a_obj_id))
78  {
79  return false;
80  }
81  return true;
82  }
83  break;
84 
85  case 'join':
86 
87  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
88  if(ilCourseWaitingList::_isOnList($a_user_id, $a_obj_id))
89  {
90  return false;
91  }
92  break;
93  }
94 
95  switch ($a_permission)
96  {
97  case 'visible':
98  $visible = null;
99  $active = self::_isActivated($a_obj_id, $visible);
100  $tutor = $rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id);
101  if(!$active)
102  {
103  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
104  }
105  if(!$tutor and !$active && !$visible)
106  {
107  return false;
108  }
109  break;
110 
111  case 'read':
112  $tutor = $rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id);
113  if($tutor)
114  {
115  return true;
116  }
117  $active = self::_isActivated($a_obj_id);
118  if(!$active)
119  {
120  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
121  return false;
122  }
123  if($participants->isBlocked($a_user_id) and $participants->isAssigned($a_user_id))
124  {
125  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("crs_status_blocked"));
126  return false;
127  }
128  break;
129 
130  case 'join':
131  if(!self::_registrationEnabled($a_obj_id))
132  {
133  return false;
134  }
135 
136  if($participants->isAssigned($a_user_id))
137  {
138  return false;
139  }
140  break;
141  }
142  return true;
143  }
144 
157  function _getCommands()
158  {
159  $commands = array();
160  $commands[] = array("permission" => "crs_linked", "cmd" => "", "lang_var" => "view", "default" => true);
161 
162  include_once './Services/WebServices/FileManager/classes/class.ilFMSettings.php';
163  if(ilFMSettings::getInstance()->isEnabled())
164  {
165  $commands[] = array(
166  'permission' => 'read',
167  'cmd' => 'fileManagerLaunch',
168  'lang_var' => 'fm_start',
169  'enable_anonymous' => false
170  );
171  }
172 
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  include_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
183  {
184  include_once './Services/WebDAV/classes/class.ilDAVUtils.php';
185  if(ilDAVUtils::getInstance()->isLocalPasswordInstructionRequired())
186  {
187  $commands[] = array('permission' => 'read', 'cmd' => 'showPasswordInstruction', 'lang_var' => 'mount_webfolder', 'enable_anonymous' => 'false');
188  }
189  else
190  {
191  $commands[] = array("permission" => "read", "cmd" => "mount_webfolder", "lang_var" => "mount_webfolder", "enable_anonymous" => "false");
192  }
193  }
194 
195  $commands[] = array("permission" => "write", "cmd" => "enableAdministrationPanel", "lang_var" => "edit_content");
196  $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "settings");
197  return $commands;
198  }
199 
203  function _checkGoto($a_target)
204  {
205  global $ilAccess,$ilUser;
206 
207  $t_arr = explode("_", $a_target);
208 
209  // registration codes
210  if(substr($t_arr[2],0,5) == 'rcode' and $ilUser->getId() != ANONYMOUS_USER_ID)
211  {
212  return true;
213  }
214 
215 
216  if ($t_arr[0] != "crs" || ((int) $t_arr[1]) <= 0)
217  {
218  return false;
219  }
220 
221  // checking for read results in endless loop, if read is given
222  // but visible is not given (-> see bug 5323)
223  if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
224  $ilAccess->checkAccess("visible", "", $t_arr[1]))
225  //if ($ilAccess->checkAccess("visible", "", $t_arr[1]))
226  {
227  return true;
228  }
229  return false;
230  }
231 
238  function _lookupViewMode($a_id)
239  {
240  global $ilDB;
241 
242  $query = "SELECT view_mode FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
243  $res = $ilDB->query($query);
244  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
245  {
246  return $row->view_mode;
247  }
248  return false;
249  }
250 
257  protected static function _isOnline($a_obj_id)
258  {
259  global $ilDB;
260 
261  $query = "SELECT * FROM crs_settings ".
262  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
263  $res = $ilDB->query($query);
264  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
265  return (bool)$row->activation_type;
266  }
267 
277  public static function _isActivated($a_obj_id, &$a_visible_flag = null, $a_mind_member_view = true)
278  {
279  // #7669
280  if($a_mind_member_view)
281  {
282  include_once './Services/Container/classes/class.ilMemberViewSettings.php';
283  if(ilMemberViewSettings::getInstance()->isActive())
284  {
285  $a_visible_flag = true;
286  return true;
287  }
288  }
289 
290  // offline?
291  if(!self::_isOnline($a_obj_id))
292  {
293  $a_visible_flag = false;
294  return false;
295  }
296 
298  $ref_id = array_pop($ref_id);
299 
300  $a_visible_flag = true;
301 
302  include_once './Services/Object/classes/class.ilObjectActivation.php';
304  switch($item['timing_type'])
305  {
307  if(time() < $item['timing_start'] or
308  time() > $item['timing_end'])
309  {
310  $a_visible_flag = $item['visible'];
311  return false;
312  }
313  // fallthrough
314 
315  default:
316  return true;
317  }
318  }
319 
325  public static function _registrationEnabled($a_obj_id)
326  {
327  global $ilDB;
328 
329  $query = "SELECT * FROM crs_settings ".
330  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
331 
332  $res = $ilDB->query($query);
333  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
334  {
335  $type = $row->sub_limitation_type;
336  $reg_start = $row->sub_start;
337  $reg_end = $row->sub_end;
338  }
339 
340  switch($type)
341  {
343  return true;
344 
346  return false;
347 
349  if(time() > $reg_start and
350  time() < $reg_end)
351  {
352  return true;
353  }
354  default:
355  return false;
356  }
357  return false;
358  }
359 
368  public static function lookupRegistrationInfo($a_obj_id)
369  {
370  global $ilDB, $ilUser, $lng;
371 
372  $query = 'SELECT sub_limitation_type, sub_start, sub_end, sub_mem_limit, sub_max_members FROM crs_settings '.
373  'WHERE obj_id = '.$ilDB->quote($a_obj_id);
374  $res = $ilDB->query($query);
375 
376  $info = array();
377  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
378  {
379  $info['reg_info_start'] = new ilDateTime($row->sub_start, IL_CAL_UNIX);
380  $info['reg_info_end'] = new ilDateTime($row->sub_end, IL_CAL_UNIX);
381  $info['reg_info_type'] = $row->sub_limitation_type;
382  $info['reg_info_max_members'] = $row->sub_max_members;
383  $info['reg_info_mem_limit'] = $row->sub_mem_limit;
384  }
385 
386  $registration_possible = true;
387 
388  // Limited registration
389  if($info['reg_info_type'] == ilCourseConstants::SUBSCRIPTION_LIMITED)
390  {
391  $dt = new ilDateTime(time(),IL_CAL_UNIX);
392  if(ilDateTime::_before($dt, $info['reg_info_start']))
393  {
394  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_start');
395  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_start']);
396  }
397  elseif(ilDateTime::_before($dt, $info['reg_info_end']))
398  {
399  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_end');
400  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_end']);
401  }
402  else
403  {
404  $registration_possible = false;
405  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_period');
406  $info['reg_info_list_prop']['value'] = $lng->txt('crs_list_reg_noreg');
407  }
408  }
409  else if($info['reg_info_type'] == ilCourseConstants::SUBSCRIPTION_UNLIMITED)
410  {
411  $registration_possible = true;
412  }
413  else
414  {
415  $registration_possible = false;
416  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_period');
417  $info['reg_info_list_prop']['value'] = $lng->txt('crs_list_reg_noreg');
418  }
419 
420  if($info['reg_info_mem_limit'] && $registration_possible)
421  {
422  // Check if users are on waiting list
423  // @todo
424 
425 
426  // Check for free places
427  $part = ilCourseParticipant::_getInstanceByObjId($a_obj_id, $ilUser->getId());
428  if($part->getNumberOfMembers() <= $info['reg_info_max_members'])
429  {
430  $info['reg_info_list_prop_limit']['property'] = $lng->txt('crs_list_reg_limit_places');
431  $info['reg_info_list_prop_limit']['value'] = max(
432  0,
433  $info['reg_info_max_members'] - $part->getNumberOfMembers()
434  );
435  }
436  else
437  {
438  $info['reg_info_list_prop_limit']['property'] = '';
439  $info['reg_info_list_prop_limit']['value'] = $lng->txt('crs_list_reg_limit_full');
440  }
441  }
442 
443  return $info;
444  }
445 
454  static function _isOffline($a_obj_id)
455  {
456  $dummy = null;
457  return !self::_isActivated($a_obj_id, $dummy, false);
458  }
459 
465  function _preloadData($a_obj_ids, $a_ref_ids)
466  {
467  global $ilUser;
468 
469  include_once("./Modules/Course/classes/class.ilCourseWaitingList.php");
470  ilCourseWaitingList::_preloadOnListInfo($ilUser->getId(), $a_obj_ids);
471 
472  include_once "./Modules/Course/classes/class.ilCourseCertificateAdapter.php";
473  ilCourseCertificateAdapter::_preloadListData($ilUser->getId(), $a_obj_ids);
474  }
475 
476 }
477 
478 ?>