ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRoleTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Table/classes/class.ilTable2GUI.php';
5 
15 {
16  const TYPE_GLOBAL_AU = 1;
17  const TYPE_GLOBAL_UD = 2;
18  const TYPE_LOCAL_AU = 3;
19  const TYPE_LOCAL_UD = 4;
20  const TYPE_ROLT_AU = 5;
21  const TYPE_ROLT_UD = 6;
22 
23 
24  const TYPE_VIEW = 1;
25  const TYPE_SEARCH = 2;
26 
27  private $path_gui = null;
28 
30  private $role_title_filter = '';
31 
37  public function __construct($a_parent_gui,$a_parent_cmd)
38  {
39  global $ilCtrl;
40 
41  $this->ctrl = $ilCtrl;
42 
43  $this->setId('rolf_role_tbl');
44 
45  parent::__construct($a_parent_gui, $a_parent_cmd);
46  $this->lng->loadLanguageModule('rbac');
47  $this->lng->loadLanguageModule('search');
48  }
49 
54  public function setType($a_type)
55  {
56  $this->type = $a_type;
57  }
58 
63  public function setRoleTitleFilter($a_filter)
64  {
65  $this->role_title_filter = $a_filter;
66  }
67 
72  public function getRoleTitleFilter()
73  {
75  }
76 
80  public function getType()
81  {
82  return $this->type;
83  }
84 
89  protected function getPathGUI()
90  {
91  return $this->path_gui;
92  }
93 
94 
95 
99  public function init()
100  {
101  $this->addColumn('','f','1px');
102 
103  switch($this->getType())
104  {
105  case self::TYPE_VIEW:
106  $this->setShowRowsSelector(true);
107  $this->setDefaultOrderField('title');
108  $this->setDefaultOrderDirection('asc');
109  //$this->setId('rolf_role_tbl');
110  $this->addColumn($this->lng->txt('search_title_description'),'title','30%');
111  $this->addColumn($this->lng->txt('type'),'rtype','20%');
112  $this->addColumn($this->lng->txt('context'),'','40%');
113  $this->addColumn($this->lng->txt('actions'),'','10%');
114  $this->setTitle($this->lng->txt('objs_role'));
115  $this->addMultiCommand('confirmDelete',$this->lng->txt('delete'));
116  break;
117 
118  case self::TYPE_SEARCH:
119  $this->setShowRowsSelector(false);
120  $this->disable('sort');
121  //$this->setId('rolf_role_search_tbl');
122  $this->addColumn($this->lng->txt('search_title_description'),'title','30%');
123  $this->addColumn($this->lng->txt('type'),'rtype','20%');
124  $this->addColumn($this->lng->txt('context'),'','50%');
125  $this->setTitle($this->lng->txt('rbac_role_rights_copy'));
126  $this->addMultiCommand('chooseCopyBehaviour',$this->lng->txt('btn_next'));
127  $this->addCommandButton('roleSearch', $this->lng->txt('btn_previous'));
128  break;
129  }
130 
131 
132  $this->setRowTemplate('tpl.role_row.html','Services/AccessControl');
133  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject()));
134  $this->setSelectAllCheckbox('roles');
135 
136  include_once './Services/Tree/classes/class.ilPathGUI.php';
137  $this->path_gui = new ilPathGUI();
138  $this->getPathGUI()->enableTextOnly(false);
139 
140 
141  // Filter initialisation
142 
143  if($this->getType() == self::TYPE_VIEW)
144  {
145  $this->initFilter();
146  }
147  }
148 
152  public function initFilter()
153  {
154  $this->setDisableFilterHiding(true);
155 
156  switch($this->getType())
157  {
158  case self::TYPE_VIEW:
159  $action[ilRbacReview::FILTER_ALL] = $this->lng->txt('all_roles');
160  $action[ilRbacReview::FILTER_ALL_GLOBAL] = $this->lng->txt('all_global_roles');
161  $action[ilRbacReview::FILTER_ALL_LOCAL] = $this->lng->txt('all_local_roles');
162  $action[ilRbacReview::FILTER_INTERNAL] = $this->lng->txt('internal_local_roles_only');
163  $action[ilRbacReview::FILTER_NOT_INTERNAL] = $this->lng->txt('non_internal_local_roles_only');
164  $action[ilRbacReview::FILTER_TEMPLATES] = $this->lng->txt('role_templates_only');
165  break;
166 
167  case self::TYPE_SEARCH:
168  $action[ilRbacReview::FILTER_ALL] = $this->lng->txt('all_roles');
169  $action[ilRbacReview::FILTER_ALL_GLOBAL] = $this->lng->txt('all_global_roles');
170  $action[ilRbacReview::FILTER_ALL_LOCAL] = $this->lng->txt('all_local_roles');
171  $action[ilRbacReview::FILTER_INTERNAL] = $this->lng->txt('internal_local_roles_only');
172  $action[ilRbacReview::FILTER_NOT_INTERNAL] = $this->lng->txt('non_internal_local_roles_only');
173  break;
174  }
175 
176  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
177  $roles = new ilSelectInputGUI($this->lng->txt('rbac_role_selection'), 'role_type');
178 
179  $roles->setOptions($action);
180 
181  $this->addFilterItem($roles);
182 
183  $roles->readFromSession();
184  if(!$roles->getValue())
185  {
186  $roles->setValue(ilRbacReview::FILTER_ALL_GLOBAL);
187  }
188 
189  // title filter
190  include_once './Services/Form/classes/class.ilTextInputGUI.php';
191  $title = new ilTextInputGUI($this->lng->txt('title'), 'role_title');
192  $title->setSize(16);
193  $title->setMaxLength(64);
194 
195  $this->addFilterItem($title);
196  $title->readFromSession();
197 
198  $this->filter['role_type'] = $roles->getValue();
199  $this->filter['role_title'] = $title->getValue();
200  }
201 
206  public function fillRow($set)
207  {
208  global $rbacreview,$tree;
209 
210  if($set['type'] == 'role')
211  {
212  if($set['parent'] != ROLE_FOLDER_ID)
213  {
214  $this->ctrl->setParameterByClass(
215  "ilobjrolegui",
216  "rolf_ref_id",
217  $set['parent']
218  );
219  }
220 
221  $this->ctrl->setParameterByClass("ilobjrolegui", "obj_id", $set["obj_id"]);
222  $link = $this->ctrl->getLinkTargetByClass("ilobjrolegui", "perm");
223  $this->ctrl->setParameterByClass("ilobjrolegui", "rolf_ref_id", "");
224  }
225  else
226  {
227  $this->ctrl->setParameterByClass("ilobjroletemplategui", "obj_id", $set["obj_id"]);
228  $link = $this->ctrl->getLinkTargetByClass("ilobjroletemplategui", "perm");
229  }
230 
231  switch($set['rtype'])
232  {
233  case self::TYPE_GLOBAL_AU:
234  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_global'));
235  break;
236  case self::TYPE_GLOBAL_UD:
237  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_ud_global'));
238  break;
239  case self::TYPE_LOCAL_AU:
240  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_local'));
241  break;
242  case self::TYPE_LOCAL_UD:
243  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_ud_local'));
244  break;
245  case self::TYPE_ROLT_AU:
246  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_rolt'));
247  break;
248  case self::TYPE_ROLT_UD:
249  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_ud_rolt'));
250  break;
251  }
252 
253 
254 
255  if(
256  ($set['obj_id'] != ANONYMOUS_ROLE_ID and
257  $set['obj_id'] != SYSTEM_ROLE_ID and
258  substr($set['title_orig'],0,3) != 'il_') or
259  $this->getType() == self::TYPE_SEARCH)
260  {
261  $this->tpl->setVariable('VAL_ID', $set['obj_id']);
262  }
263  $this->tpl->setVariable('VAL_TITLE_LINKED', $set['title']);
264  $this->tpl->setVariable('VAL_LINK', $link);
265  if(strlen($set['description']))
266  {
267  $this->tpl->setVariable('VAL_DESC', $set['description']);
268  }
269 
277  $ref = $set['parent'];
278  if($ref == ROLE_FOLDER_ID)
279  {
280  $this->tpl->setVariable('CONTEXT', $this->lng->txt('rbac_context_global'));
281  }
282  else
283  {
284  $this->tpl->setVariable(
285  'CONTEXT',
286  (string) $this->getPathGUI()->getPath(ROOT_FOLDER_ID,$ref)
287  );
288  }
289 
290  if($this->getType() == self::TYPE_VIEW)
291  {
292  // Copy role
293  $this->tpl->setVariable('COPY_TEXT',$this->lng->txt('rbac_role_rights_copy'));
294  $this->ctrl->setParameter($this->getParentObject(), "copy_source", $set["obj_id"]);
295  $link = $this->ctrl->getLinkTarget($this->getParentObject(),'roleSearch');
296  $this->tpl->setVariable(
297  'COPY_LINK',
298  $link
299  );
300  }
301 
302  }
303 
308  public function parse($role_folder_id)
309  {
310  global $rbacreview,$ilUser;
311 
312  include_once './Services/AccessControl/classes/class.ilObjRole.php';
313 
314  if($this->getType() == self::TYPE_VIEW)
315  {
316  $filter_orig = $filter = $this->getFilterItemByPostVar('role_title')->getValue();
317  $type = $this->getFilterItemByPostVar('role_type')->getValue();
318  }
319  else
320  {
321  $filter_orig = $filter = $this->getRoleTitleFilter();
323  }
324 
325 
326  // the translation must be filtered
328  {
329  // roles like il_crs_... are filtered manually
330  $filter = '';
331  }
332 
333  $role_list = $rbacreview->getRolesByFilter(
334  $type,
335  0,
336  $filter
337  );
338 
339  $counter = 0;
340  $rows = array();
341  foreach((array) $role_list as $role)
342  {
343  if($role['parent'] and $GLOBALS['tree']->isDeleted($role['parent']))
344  {
345  continue;
346  }
347 
348  $title = ilObjRole::_getTranslation($role['title']);
350  {
351  if(strlen($filter_orig))
352  {
353  if(stristr($title, $filter_orig) == FALSE)
354  {
355  continue;
356  }
357  }
358  }
359 
360 
361  $rows[$counter]['title_orig'] = $role['title'];
362  $rows[$counter]['title'] = $title;
363  $rows[$counter]['description'] = $role['description'];
364  $rows[$counter]['obj_id'] = $role['obj_id'];
365  $rows[$counter]['parent'] = $role['parent'];
366  $rows[$counter]['type'] = $role['type'];
367 
368  $auto = (substr($role['title'], 0, 3) == 'il_' ? true : false);
369 
370 
371  // Role templates
372  if($role['type'] == 'rolt')
373  {
374  $rows[$counter]['rtype'] = $auto ? self::TYPE_ROLT_AU : self::TYPE_ROLT_UD;
375  }
376  else
377  {
378  // Roles
379  if($role['parent'] == ROLE_FOLDER_ID)
380  {
381  if($role['obj_id'] == ANONYMOUS_ROLE_ID or $role['obj_id'] == SYSTEM_ROLE_ID)
382  {
383  $rows[$counter]['rtype'] = self::TYPE_GLOBAL_AU;
384  }
385  else
386  {
387  $rows[$counter]['rtype'] = self::TYPE_GLOBAL_UD;
388  }
389  }
390  else
391  {
392  $rows[$counter]['rtype'] = $auto ? self::TYPE_LOCAL_AU : self::TYPE_LOCAL_UD;
393  }
394  }
395 
396  ++$counter;
397  }
398  $this->setMaxCount(count($rows));
399  $this->setData($rows);
400  }
401 }
402 
403 ?>