ILIAS  release_4-3 Revision
 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 {
29  function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
30  {
31 
32  global $ilUser, $lng, $rbacsystem, $ilAccess;
33 
34  if ($a_user_id == "")
35  {
36  $a_user_id = $ilUser->getId();
37  }
38 
39  switch ($a_cmd)
40  {
41  case "info":
42 
43  include_once './Modules/Group/classes/class.ilGroupParticipants.php';
44  if(ilGroupParticipants::_isParticipant($a_ref_id,$a_user_id))
45  {
46  $ilAccess->addInfoItem(IL_STATUS_MESSAGE, $lng->txt("info_is_member"));
47  }
48  else
49  {
50  $ilAccess->addInfoItem(IL_STATUS_MESSAGE, $lng->txt("info_is_not_member"));
51  }
52  break;
53 
54  case "join":
55 
56  if(!self::_registrationEnabled($a_obj_id))
57  {
58  return false;
59  }
60 
61  include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
62  if(ilGroupWaitingList::_isOnList($ilUser->getId(), $a_obj_id))
63  {
64  return false;
65  }
66 
67  include_once './Modules/Group/classes/class.ilGroupParticipants.php';
68  if(ilGroupParticipants::_isParticipant($a_ref_id,$a_user_id))
69  {
70  return false;
71  }
72  break;
73 
74  case 'leave':
75 
76  // Regular member
77  if($a_permission == 'leave')
78  {
79  include_once './Modules/Group/classes/class.ilGroupParticipants.php';
80  if(!ilGroupParticipants::_isParticipant($a_ref_id, $a_user_id))
81  {
82  return false;
83  }
84  }
85  // Waiting list
86  if($a_permission == 'join')
87  {
88  include_once './Modules/Group/classes/class.ilGroupWaitingList.php';
89  if(!ilGroupWaitingList::_isOnList($ilUser->getId(), $a_obj_id))
90  {
91  return false;
92  }
93  }
94  break;
95 
96  }
97 
98  switch ($a_permission)
99  {
100 
101  }
102  return true;
103  }
104 
117  function _getCommands()
118  {
119  $commands = array();
120  $commands[] = array("permission" => "grp_linked", "cmd" => "", "lang_var" => "show", "default" => true);
121 
122  include_once './Services/WebServices/FileManager/classes/class.ilFMSettings.php';
123  if(ilFMSettings::getInstance()->isEnabled())
124  {
125  $commands[] = array(
126  'permission' => 'read',
127  'cmd' => 'fileManagerLaunch',
128  'lang_var' => 'fm_start',
129  'enable_anonymous' => false
130  );
131  }
132 
133  $commands[] = array("permission" => "join", "cmd" => "join", "lang_var" => "join");
134 
135  // on waiting list
136  $commands[] = array('permission' => "join", "cmd" => "leave", "lang_var" => "leave_waiting_list");
137 
138  // regualar users
139  $commands[] = array('permission' => "leave", "cmd" => "leave", "lang_var" => "grp_btn_unsubscribe");
140 
141  include_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
143  {
144  include_once './Services/WebDAV/classes/class.ilDAVUtils.php';
145  if(ilDAVUtils::getInstance()->isLocalPasswordInstructionRequired())
146  {
147  $commands[] = array('permission' => 'read', 'cmd' => 'showPasswordInstruction', 'lang_var' => 'mount_webfolder', 'enable_anonymous' => 'false');
148  }
149  else
150  {
151  $commands[] = array("permission" => "read", "cmd" => "mount_webfolder", "lang_var" => "mount_webfolder", "enable_anonymous" => "false");
152  }
153  }
154 
155  $commands[] = array("permission" => "write", "cmd" => "enableAdministrationPanel", "lang_var" => "edit_content");
156  $commands[] = array("permission" => "write", "cmd" => "edit", "lang_var" => "settings");
157 
158  return $commands;
159  }
160 
164  function _checkGoto($a_target)
165  {
166  global $ilAccess,$ilUser;
167 
168  // registration codes
169  if(substr($t_arr[2],0,5) == 'rcode' and $ilUser->getId() != ANONYMOUS_USER_ID)
170  {
171  return true;
172  }
173 
174 
175  $t_arr = explode("_", $a_target);
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 
344 
345 }
346 ?>