ILIAS  Release_5_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 /* 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 include_once './Services/AccessControl/interfaces/interface.ilConditionHandling.php';
10 
20 {
21 
22  protected static $using_code = false;
23 
27  public static function getConditionOperators()
28  {
29  include_once './Services/AccessControl/classes/class.ilConditionHandler.php';
30  return array(
32  );
33  }
34 
44  public static function checkCondition($a_obj_id,$a_operator,$a_value,$a_usr_id)
45  {
46  include_once "./Modules/Course/classes/class.ilCourseParticipants.php";
47  include_once './Services/AccessControl/classes/class.ilConditionHandler.php';
48 
49  switch($a_operator)
50  {
52  return ilCourseParticipants::_hasPassed($a_obj_id,$a_usr_id);
53  }
54  return FALSE;
55  }
56 
69  function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
70  {
71  global $ilUser, $lng, $rbacsystem, $ilAccess, $ilias;
72 
73 
74  if ($a_user_id == "")
75  {
76  $a_user_id = $ilUser->getId();
77  }
78 
79  if($ilUser->getId() == $a_user_id)
80  {
81  $participants = ilCourseParticipant::_getInstanceByObjId($a_obj_id,$a_user_id);
82  }
83  else
84  {
85  $participants = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
86  }
87 
88 
89  switch ($a_cmd)
90  {
91  case "view":
92  if($participants->isBlocked($a_user_id) and $participants->isAssigned($a_user_id))
93  {
94  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("crs_status_blocked"));
95  return false;
96  }
97  break;
98 
99  case 'leave':
100 
101  // Regular member
102  if($a_permission == 'leave')
103  {
104  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
105  if(!$participants->isAssigned($a_user_id))
106  {
107  return false;
108  }
109  }
110  // Waiting list
111  if($a_permission == 'join')
112  {
113  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
114  if(!ilCourseWaitingList::_isOnList($a_user_id, $a_obj_id))
115  {
116  return false;
117  }
118  return true;
119  }
120  break;
121 
122  case 'join':
123 
124  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
125  if(ilCourseWaitingList::_isOnList($a_user_id, $a_obj_id))
126  {
127  return false;
128  }
129  break;
130  }
131 
132  switch ($a_permission)
133  {
134  case 'visible':
135  $visible = null;
136  $active = self::_isActivated($a_obj_id, $visible);
137  $tutor = $rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id);
138  if(!$active)
139  {
140  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
141  }
142  if(!$tutor and !$active && !$visible)
143  {
144  return false;
145  }
146  break;
147 
148  case 'read':
149  $tutor = $rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id);
150  if($tutor)
151  {
152  return true;
153  }
154  $active = self::_isActivated($a_obj_id);
155  if(!$active)
156  {
157  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
158  return false;
159  }
160  if($participants->isBlocked($a_user_id) and $participants->isAssigned($a_user_id))
161  {
162  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("crs_status_blocked"));
163  return false;
164  }
165  break;
166 
167  case 'join':
168  if(!self::_registrationEnabled($a_obj_id))
169  {
170  return false;
171  }
172 
173  if($participants->isAssigned($a_user_id))
174  {
175  return false;
176  }
177  break;
178  }
179  return true;
180  }
181 
194  function _getCommands()
195  {
196  $commands = array();
197  $commands[] = array("permission" => "crs_linked", "cmd" => "", "lang_var" => "view", "default" => true);
198 
199  include_once './Services/WebServices/FileManager/classes/class.ilFMSettings.php';
200  if(ilFMSettings::getInstance()->isEnabled())
201  {
202  $commands[] = array(
203  'permission' => 'read',
204  'cmd' => 'fileManagerLaunch',
205  'lang_var' => 'fm_start',
206  'enable_anonymous' => false
207  );
208  }
209 
210  $commands[] = array("permission" => "join", "cmd" => "join", "lang_var" => "join");
211 
212  // on waiting list
213  $commands[] = array('permission' => "join", "cmd" => "leave", "lang_var" => "leave_waiting_list");
214 
215  // regualar users
216  $commands[] = array('permission' => "leave", "cmd" => "leave", "lang_var" => "crs_unsubscribe");
217 
218  include_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
220  {
221  include_once './Services/WebDAV/classes/class.ilDAVUtils.php';
222  if(ilDAVUtils::getInstance()->isLocalPasswordInstructionRequired())
223  {
224  $commands[] = array('permission' => 'read', 'cmd' => 'showPasswordInstruction', 'lang_var' => 'mount_webfolder', 'enable_anonymous' => 'false');
225  }
226  else
227  {
228  $commands[] = array("permission" => "read", "cmd" => "mount_webfolder", "lang_var" => "mount_webfolder", "enable_anonymous" => "false");
229  }
230  }
231 
232  $commands[] = array("permission" => "write", "cmd" => "enableAdministrationPanel", "lang_var" => "edit_content");
233  $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "settings");
234  return $commands;
235  }
236 
240  function _checkGoto($a_target)
241  {
242  global $ilAccess,$ilUser;
243 
244  $t_arr = explode("_", $a_target);
245 
246  // registration codes
247  if(substr($t_arr[2],0,5) == 'rcode' and $ilUser->getId() != ANONYMOUS_USER_ID)
248  {
249  self::$using_code = true;
250  return true;
251  }
252 
253 
254  if ($t_arr[0] != "crs" || ((int) $t_arr[1]) <= 0)
255  {
256  return false;
257  }
258 
259  // checking for read results in endless loop, if read is given
260  // but visible is not given (-> see bug 5323)
261  if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
262  $ilAccess->checkAccess("visible", "", $t_arr[1]))
263  //if ($ilAccess->checkAccess("visible", "", $t_arr[1]))
264  {
265  return true;
266  }
267  return false;
268  }
269 
276  function _lookupViewMode($a_id)
277  {
278  global $ilDB;
279 
280  $query = "SELECT view_mode FROM crs_settings WHERE obj_id = ".$ilDB->quote($a_id ,'integer')." ";
281  $res = $ilDB->query($query);
282  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
283  {
284  return $row->view_mode;
285  }
286  return false;
287  }
288 
295  protected static function _isOnline($a_obj_id)
296  {
297  global $ilDB;
298 
299  $query = "SELECT * FROM crs_settings ".
300  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
301  $res = $ilDB->query($query);
302  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
303  return (bool)$row->activation_type;
304  }
305 
315  public static function _isActivated($a_obj_id, &$a_visible_flag = null, $a_mind_member_view = true)
316  {
317  // #7669
318  if($a_mind_member_view)
319  {
320  include_once './Services/Container/classes/class.ilMemberViewSettings.php';
321  if(ilMemberViewSettings::getInstance()->isActive())
322  {
323  $a_visible_flag = true;
324  return true;
325  }
326  }
327 
328  // offline?
329  if(!self::_isOnline($a_obj_id))
330  {
331  $a_visible_flag = false;
332  return false;
333  }
334 
336  $ref_id = array_pop($ref_id);
337 
338  $a_visible_flag = true;
339 
340  include_once './Services/Object/classes/class.ilObjectActivation.php';
342  switch($item['timing_type'])
343  {
345  if(time() < $item['timing_start'] or
346  time() > $item['timing_end'])
347  {
348  $a_visible_flag = $item['visible'];
349  return false;
350  }
351  // fallthrough
352 
353  default:
354  return true;
355  }
356  }
357 
363  public static function _registrationEnabled($a_obj_id)
364  {
365  global $ilDB;
366 
367  $query = "SELECT * FROM crs_settings ".
368  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
369 
370  $res = $ilDB->query($query);
371  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
372  {
373  $type = $row->sub_limitation_type;
374  $reg_start = $row->sub_start;
375  $reg_end = $row->sub_end;
376  }
377 
378  switch($type)
379  {
381  return true;
382 
384  return false;
385 
387  if(time() > $reg_start and
388  time() < $reg_end)
389  {
390  return true;
391  }
392  default:
393  return false;
394  }
395  return false;
396  }
397 
406  public static function lookupRegistrationInfo($a_obj_id)
407  {
408  global $ilDB, $ilUser, $lng;
409 
410  $query = 'SELECT sub_limitation_type, sub_start, sub_end, sub_mem_limit, sub_max_members FROM crs_settings '.
411  'WHERE obj_id = '.$ilDB->quote($a_obj_id);
412  $res = $ilDB->query($query);
413 
414  $info = array();
415  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
416  {
417  $info['reg_info_start'] = new ilDateTime($row->sub_start, IL_CAL_UNIX);
418  $info['reg_info_end'] = new ilDateTime($row->sub_end, IL_CAL_UNIX);
419  $info['reg_info_type'] = $row->sub_limitation_type;
420  $info['reg_info_max_members'] = $row->sub_max_members;
421  $info['reg_info_mem_limit'] = $row->sub_mem_limit;
422  }
423 
424  $registration_possible = true;
425 
426  // Limited registration
427  if($info['reg_info_type'] == ilCourseConstants::SUBSCRIPTION_LIMITED)
428  {
429  $dt = new ilDateTime(time(),IL_CAL_UNIX);
430  if(ilDateTime::_before($dt, $info['reg_info_start']))
431  {
432  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_start');
433  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_start']);
434  }
435  elseif(ilDateTime::_before($dt, $info['reg_info_end']))
436  {
437  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_end');
438  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_end']);
439  }
440  else
441  {
442  $registration_possible = false;
443  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_period');
444  $info['reg_info_list_prop']['value'] = $lng->txt('crs_list_reg_noreg');
445  }
446  }
447  else if($info['reg_info_type'] == ilCourseConstants::SUBSCRIPTION_UNLIMITED)
448  {
449  $registration_possible = true;
450  }
451  else
452  {
453  $registration_possible = false;
454  $info['reg_info_list_prop']['property'] = $lng->txt('crs_list_reg_period');
455  $info['reg_info_list_prop']['value'] = $lng->txt('crs_list_reg_noreg');
456  }
457 
458  if($info['reg_info_mem_limit'] && $registration_possible)
459  {
460  // Check if users are on waiting list
461  // @todo
462 
463 
464  // Check for free places
465  $part = ilCourseParticipant::_getInstanceByObjId($a_obj_id, $ilUser->getId());
466  if($part->getNumberOfMembers() <= $info['reg_info_max_members'])
467  {
468  $info['reg_info_list_prop_limit']['property'] = $lng->txt('crs_list_reg_limit_places');
469  $info['reg_info_list_prop_limit']['value'] = max(
470  0,
471  $info['reg_info_max_members'] - $part->getNumberOfMembers()
472  );
473  }
474  else
475  {
476  $info['reg_info_list_prop_limit']['property'] = '';
477  $info['reg_info_list_prop_limit']['value'] = $lng->txt('crs_list_reg_limit_full');
478  }
479  }
480 
481  return $info;
482  }
483 
492  static function _isOffline($a_obj_id)
493  {
494  $dummy = null;
495  return !self::_isActivated($a_obj_id, $dummy, false);
496  }
497 
503  function _preloadData($a_obj_ids, $a_ref_ids)
504  {
505  global $ilUser;
506 
507  include_once("./Modules/Course/classes/class.ilCourseWaitingList.php");
508  ilCourseWaitingList::_preloadOnListInfo($ilUser->getId(), $a_obj_ids);
509 
510  include_once "./Modules/Course/classes/class.ilCourseCertificateAdapter.php";
511  ilCourseCertificateAdapter::_preloadListData($ilUser->getId(), $a_obj_ids);
512  }
513 
519  public static function _usingRegistrationCode()
520  {
521  return self::$using_code;
522  }
523 
524 }
525 
526 ?>