ILIAS  Release_5_0_x_branch Revision 61816
 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(true);
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  $this->getPathGUI()->enableHideLeaf(FALSE);
140 
141 
142  // Filter initialisation
143 
144  if($this->getType() == self::TYPE_VIEW)
145  {
146  $this->initFilter();
147  }
148  }
149 
153  public function initFilter()
154  {
155  $this->setDisableFilterHiding(true);
156 
157  switch($this->getType())
158  {
159  case self::TYPE_VIEW:
160  $action[ilRbacReview::FILTER_ALL] = $this->lng->txt('all_roles');
161  $action[ilRbacReview::FILTER_ALL_GLOBAL] = $this->lng->txt('all_global_roles');
162  $action[ilRbacReview::FILTER_ALL_LOCAL] = $this->lng->txt('all_local_roles');
163  $action[ilRbacReview::FILTER_INTERNAL] = $this->lng->txt('internal_local_roles_only');
164  $action[ilRbacReview::FILTER_NOT_INTERNAL] = $this->lng->txt('non_internal_local_roles_only');
165  $action[ilRbacReview::FILTER_TEMPLATES] = $this->lng->txt('role_templates_only');
166  break;
167 
168  case self::TYPE_SEARCH:
169  $action[ilRbacReview::FILTER_ALL] = $this->lng->txt('all_roles');
170  $action[ilRbacReview::FILTER_ALL_GLOBAL] = $this->lng->txt('all_global_roles');
171  $action[ilRbacReview::FILTER_ALL_LOCAL] = $this->lng->txt('all_local_roles');
172  $action[ilRbacReview::FILTER_INTERNAL] = $this->lng->txt('internal_local_roles_only');
173  $action[ilRbacReview::FILTER_NOT_INTERNAL] = $this->lng->txt('non_internal_local_roles_only');
174  break;
175  }
176 
177  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
178  $roles = new ilSelectInputGUI($this->lng->txt('rbac_role_selection'), 'role_type');
179 
180  $roles->setOptions($action);
181 
182  $this->addFilterItem($roles);
183 
184  $roles->readFromSession();
185  if(!$roles->getValue())
186  {
187  $roles->setValue(ilRbacReview::FILTER_ALL_GLOBAL);
188  }
189 
190  // title filter
191  include_once './Services/Form/classes/class.ilTextInputGUI.php';
192  $title = new ilTextInputGUI($this->lng->txt('title'), 'role_title');
193  $title->setSize(16);
194  $title->setMaxLength(64);
195 
196  $this->addFilterItem($title);
197  $title->readFromSession();
198 
199  $this->filter['role_type'] = $roles->getValue();
200  $this->filter['role_title'] = $title->getValue();
201  }
202 
207  public function fillRow($set)
208  {
209  global $rbacreview,$tree;
210 
211  if($set['type'] == 'role')
212  {
213  if($set['parent'] != ROLE_FOLDER_ID)
214  {
215  $this->ctrl->setParameterByClass(
216  "ilobjrolegui",
217  "rolf_ref_id",
218  $set['parent']
219  );
220  }
221 
222  $this->ctrl->setParameterByClass("ilobjrolegui", "obj_id", $set["obj_id"]);
223  $link = $this->ctrl->getLinkTargetByClass("ilobjrolegui", "perm");
224  $this->ctrl->setParameterByClass("ilobjrolegui", "rolf_ref_id", "");
225  }
226  else
227  {
228  $this->ctrl->setParameterByClass("ilobjroletemplategui", "obj_id", $set["obj_id"]);
229  $link = $this->ctrl->getLinkTargetByClass("ilobjroletemplategui", "perm");
230  }
231 
232  switch($set['rtype'])
233  {
234  case self::TYPE_GLOBAL_AU:
235  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_global'));
236  break;
237  case self::TYPE_GLOBAL_UD:
238  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_ud_global'));
239  break;
240  case self::TYPE_LOCAL_AU:
241  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_local'));
242  break;
243  case self::TYPE_LOCAL_UD:
244  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_ud_local'));
245  break;
246  case self::TYPE_ROLT_AU:
247  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_rolt'));
248  break;
249  case self::TYPE_ROLT_UD:
250  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_ud_rolt'));
251  break;
252  }
253 
254 
255 
256  if(
257  ($set['obj_id'] != ANONYMOUS_ROLE_ID and
258  $set['obj_id'] != SYSTEM_ROLE_ID and
259  substr($set['title_orig'],0,3) != 'il_') or
260  $this->getType() == self::TYPE_SEARCH)
261  {
262  $this->tpl->setVariable('VAL_ID', $set['obj_id']);
263  }
264  $this->tpl->setVariable('VAL_TITLE_LINKED', $set['title']);
265  $this->tpl->setVariable('VAL_LINK', $link);
266  if(strlen($set['description']))
267  {
268  $this->tpl->setVariable('VAL_DESC', $set['description']);
269  }
270 
278  $ref = $set['parent'];
279  if($ref == ROLE_FOLDER_ID)
280  {
281  $this->tpl->setVariable('CONTEXT', $this->lng->txt('rbac_context_global'));
282  }
283  else
284  {
285  $this->tpl->setVariable(
286  'CONTEXT',
287  (string) $this->getPathGUI()->getPath(ROOT_FOLDER_ID,$ref)
288  );
289  }
290 
291  if($this->getType() == self::TYPE_VIEW and $set['obj_id'] != SYSTEM_ROLE_ID)
292  {
293  // Copy role
294  $this->tpl->setVariable('COPY_TEXT',$this->lng->txt('rbac_role_rights_copy'));
295  $this->ctrl->setParameter($this->getParentObject(), "copy_source", $set["obj_id"]);
296  $link = $this->ctrl->getLinkTarget($this->getParentObject(),'roleSearch');
297  $this->tpl->setVariable(
298  'COPY_LINK',
299  $link
300  );
301  }
302 
303  }
304 
309  public function parse($role_folder_id)
310  {
311  global $rbacreview,$ilUser;
312 
313  include_once './Services/AccessControl/classes/class.ilObjRole.php';
314 
315  if($this->getType() == self::TYPE_VIEW)
316  {
317  $filter_orig = $filter = $this->getFilterItemByPostVar('role_title')->getValue();
318  $type = $this->getFilterItemByPostVar('role_type')->getValue();
319  }
320  else
321  {
322  $filter_orig = $filter = $this->getRoleTitleFilter();
324  }
325 
326 
327  // the translation must be filtered
329  {
330  // roles like il_crs_... are filtered manually
331  $filter = '';
332  }
333 
334  $role_list = $rbacreview->getRolesByFilter(
335  $type,
336  0,
337  $filter
338  );
339 
340  $counter = 0;
341  $rows = array();
342  foreach((array) $role_list as $role)
343  {
344  if(
345  $role['parent'] and
346  (
347  $GLOBALS['tree']->isDeleted($role['parent']) or
348  !$GLOBALS['tree']->isInTree($role['parent'])
349  )
350  )
351  {
352  continue;
353  }
354 
355  $title = ilObjRole::_getTranslation($role['title']);
357  {
358  if(strlen($filter_orig))
359  {
360  if(stristr($title, $filter_orig) == FALSE)
361  {
362  continue;
363  }
364  }
365  }
366 
367 
368  $rows[$counter]['title_orig'] = $role['title'];
369  $rows[$counter]['title'] = $title;
370  $rows[$counter]['description'] = $role['description'];
371  $rows[$counter]['obj_id'] = $role['obj_id'];
372  $rows[$counter]['parent'] = $role['parent'];
373  $rows[$counter]['type'] = $role['type'];
374 
375  $auto = (substr($role['title'], 0, 3) == 'il_' ? true : false);
376 
377 
378  // Role templates
379  if($role['type'] == 'rolt')
380  {
381  $rows[$counter]['rtype'] = $auto ? self::TYPE_ROLT_AU : self::TYPE_ROLT_UD;
382  }
383  else
384  {
385  // Roles
386  if($role['parent'] == ROLE_FOLDER_ID)
387  {
388  if($role['obj_id'] == ANONYMOUS_ROLE_ID or $role['obj_id'] == SYSTEM_ROLE_ID)
389  {
390  $rows[$counter]['rtype'] = self::TYPE_GLOBAL_AU;
391  }
392  else
393  {
394  $rows[$counter]['rtype'] = self::TYPE_GLOBAL_UD;
395  }
396  }
397  else
398  {
399  $rows[$counter]['rtype'] = $auto ? self::TYPE_LOCAL_AU : self::TYPE_LOCAL_UD;
400  }
401  }
402 
403  ++$counter;
404  }
405  $this->setMaxCount(count($rows));
406  $this->setData($rows);
407  }
408 }
409 
410 ?>