ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjGroupAccess.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Object/classes/class.ilObjectAccess.php");
6 
16 {
17  protected static $using_code = false;
30  function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
31  {
32 
33  global $ilUser, $lng, $rbacsystem, $ilAccess;
34 
35  if ($a_user_id == "")
36  {
37  $a_user_id = $ilUser->getId();
38  }
39 
40  switch ($a_cmd)
41  {
42  case "info":
43 
44  include_once './Modules/Group/classes/class.ilGroupParticipants.php';
45  if(ilGroupParticipants::_isParticipant($a_ref_id,$a_user_id))
46  {
47  $ilAccess->addInfoItem(IL_STATUS_MESSAGE, $lng->txt("info_is_member"));
48  }
49  else
50  {
51  $ilAccess->addInfoItem(IL_STATUS_MESSAGE, $lng->txt("info_is_not_member"));
52  }
53  break;
54 
55  case "join":
56 
57  if(!self::_registrationEnabled($a_obj_id))
58  {
59  return false;
60  }
61 
62  include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
63  if(ilGroupWaitingList::_isOnList($ilUser->getId(), $a_obj_id))
64  {
65  return false;
66  }
67 
68  include_once './Modules/Group/classes/class.ilGroupParticipants.php';
69  if(ilGroupParticipants::_isParticipant($a_ref_id,$a_user_id))
70  {
71  return false;
72  }
73  break;
74 
75  case 'leave':
76 
77  // Regular member
78  if($a_permission == 'leave')
79  {
80  include_once './Modules/Group/classes/class.ilGroupParticipants.php';
81  if(!ilGroupParticipants::_isParticipant($a_ref_id, $a_user_id))
82  {
83  return false;
84  }
85  }
86  // Waiting list
87  if($a_permission == 'join')
88  {
89  include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
90  if(!ilGroupWaitingList::_isOnList($ilUser->getId(), $a_obj_id))
91  {
92  return false;
93  }
94  }
95  break;
96 
97  }
98 
99  switch ($a_permission)
100  {
101 
102  }
103  return true;
104  }
105 
118  function _getCommands()
119  {
120  $commands = array();
121  $commands[] = array("permission" => "grp_linked", "cmd" => "", "lang_var" => "show", "default" => true);
122 
123  include_once './Services/WebServices/FileManager/classes/class.ilFMSettings.php';
124  if(ilFMSettings::getInstance()->isEnabled())
125  {
126  $commands[] = array(
127  'permission' => 'read',
128  'cmd' => 'fileManagerLaunch',
129  'lang_var' => 'fm_start',
130  'enable_anonymous' => false
131  );
132  }
133 
134  $commands[] = array("permission" => "join", "cmd" => "join", "lang_var" => "join");
135 
136  // on waiting list
137  $commands[] = array('permission' => "join", "cmd" => "leave", "lang_var" => "leave_waiting_list");
138 
139  // regualar users
140  $commands[] = array('permission' => "leave", "cmd" => "leave", "lang_var" => "grp_btn_unsubscribe");
141 
142  include_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
144  {
145  include_once './Services/WebDAV/classes/class.ilDAVUtils.php';
146  if(ilDAVUtils::getInstance()->isLocalPasswordInstructionRequired())
147  {
148  $commands[] = array('permission' => 'read', 'cmd' => 'showPasswordInstruction', 'lang_var' => 'mount_webfolder', 'enable_anonymous' => 'false');
149  }
150  else
151  {
152  $commands[] = array("permission" => "read", "cmd" => "mount_webfolder", "lang_var" => "mount_webfolder", "enable_anonymous" => "false");
153  }
154  }
155 
156  $commands[] = array("permission" => "write", "cmd" => "enableAdministrationPanel", "lang_var" => "edit_content");
157  $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "settings");
158 
159  return $commands;
160  }
161 
165  function _checkGoto($a_target)
166  {
167  global $ilAccess,$ilUser;
168 
169  $t_arr = explode("_", $a_target);
170  // registration codes
171  if(substr($t_arr[2],0,5) == 'rcode' and $ilUser->getId() != ANONYMOUS_USER_ID)
172  {
173  self::$using_code = true;
174  return true;
175  }
176 
177  if ($t_arr[0] != "grp" || ((int) $t_arr[1]) <= 0)
178  {
179  return false;
180  }
181 
182  if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
183  $ilAccess->checkAccess("visible", "", $t_arr[1]))
184  {
185  return true;
186  }
187  return false;
188  }
189 
195  public static function _registrationEnabled($a_obj_id)
196  {
197  global $ilDB;
198 
199  $query = "SELECT * FROM grp_settings ".
200  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
201 
202  $res = $ilDB->query($query);
203 
204  $enabled = $unlimited = false;
205  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
206  {
207  $enabled = $row->registration_enabled;
208  $unlimited = $row->registration_unlimited;
209  $start = $row->registration_start;
210  $end = $row->registration_end;
211  }
212 
213  if(!$enabled)
214  {
215  return false;
216  }
217  if($unlimited)
218  {
219  return true;
220  }
221 
222  if(!$unlimited)
223  {
224  $start = new ilDateTime($start,IL_CAL_DATETIME);
225  $end = new ilDateTime($end,IL_CAL_DATETIME);
226  $time = new ilDateTime(time(),IL_CAL_UNIX);
227 
228  return ilDateTime::_after($time, $start) and ilDateTime::_before($time,$end);
229  }
230  return false;
231  }
232 
233 
239  function _preloadData($a_obj_ids, $a_ref_ids)
240  {
241  global $ilDB, $ilUser;
242 
243  include_once("./Modules/Group/classes/class.ilGroupWaitingList.php");
244  ilGroupWaitingList::_preloadOnListInfo($ilUser->getId(), $a_obj_ids);
245  }
246 
255  public static function lookupRegistrationInfo($a_obj_id)
256  {
257  global $ilDB, $ilUser, $lng;
258 
259  $query = 'SELECT registration_type, registration_enabled, registration_unlimited, registration_start, '.
260  'registration_end, registration_mem_limit, registration_max_members FROM grp_settings '.
261  'WHERE obj_id = '.$ilDB->quote($a_obj_id);
262  $res = $ilDB->query($query);
263 
264  $info = array();
265  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
266  {
267  $info['reg_info_start'] = new ilDateTime($row->registration_start, IL_CAL_DATETIME);
268  $info['reg_info_end'] = new ilDateTime($row->registration_end, IL_CAL_DATETIME);
269  $info['reg_info_type'] = $row->registration_type;
270  $info['reg_info_max_members'] = $row->registration_max_members;
271  $info['reg_info_mem_limit'] = $row->registration_mem_limit;
272  $info['reg_info_unlimited'] = $row->registration_unlimited;
273 
274  $info['reg_info_max_members'] = 0;
275  if($info['reg_info_mem_limit'])
276  {
277  $info['reg_info_max_members'] = $row->registration_max_members;
278  }
279 
280  $info['reg_info_enabled'] = $row->registration_enabled;
281  }
282 
283  $registration_possible = $info['reg_info_enabled'];
284 
285  // Limited registration (added $registration_possible, see bug 0010157)
286  if(!$info['reg_info_unlimited'] && $registration_possible)
287  {
288  $dt = new ilDateTime(time(),IL_CAL_UNIX);
289  if(ilDateTime::_before($dt, $info['reg_info_start']))
290  {
291  $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_start');
292  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_start']);
293  }
294  elseif(ilDateTime::_before($dt, $info['reg_info_end']))
295  {
296  $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_end');
297  $info['reg_info_list_prop']['value'] = ilDatePresentation::formatDate($info['reg_info_end']);
298  }
299  else
300  {
301  $registration_possible = false;
302  $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_period');
303  $info['reg_info_list_prop']['value'] = $lng->txt('grp_list_reg_noreg');
304  }
305  }
306  else
307  {
308  // added !$registration_possible, see bug 0010157
309  if (!$registration_possible)
310  {
311  $registration_possible = false;
312  $info['reg_info_list_prop']['property'] = $lng->txt('grp_list_reg_period');
313  $info['reg_info_list_prop']['value'] = $lng->txt('grp_list_reg_noreg');
314  }
315  }
316 
317  if($info['reg_info_mem_limit'] && $registration_possible)
318  {
319  // Check if users are on waiting list
320  // @todo
321 
322 
323  // Check for free places
324  include_once './Modules/Group/classes/class.ilGroupParticipants.php';
325  $part = ilGroupParticipants::_getInstanceByObjId($a_obj_id);
326  if($part->getCountMembers() <= $info['reg_info_max_members'])
327  {
328  $info['reg_info_list_prop_limit']['property'] = $lng->txt('grp_list_reg_limit_places');
329  $info['reg_info_list_prop_limit']['value'] = max(
330  0,
331  $info['reg_info_max_members'] - $part->getCountMembers()
332  );
333  }
334  else
335  {
336  $info['reg_info_list_prop_limit']['property'] = '';
337  $info['reg_info_list_prop_limit']['value'] = $lng->txt('grp_list_reg_limit_full');
338  }
339  }
340 
341  return $info;
342  }
343 
349  public static function _usingRegistrationCode()
350  {
351  return self::$using_code;
352  }
353 
354 
355 }
356 ?>