• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilPermissionGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00036 class ilPermissionGUI
00037 {
00045         function ilPermissionGUI(&$a_gui_obj)
00046         {
00047                 global $ilias, $objDefinition, $tpl, $tree, $ilCtrl, $ilErr, $lng;
00048 
00049                 if (!isset($ilErr))
00050                 {
00051                         $ilErr = new ilErrorHandling();
00052                         $ilErr->setErrorHandling(PEAR_ERROR_CALLBACK,array($ilErr,'errorHandler'));
00053                 }
00054                 else
00055                 {
00056                         $this->ilErr =& $ilErr;
00057                 }
00058 
00059                 $this->ilias =& $ilias;
00060                 $this->objDefinition =& $objDefinition;
00061                 $this->tree =& $tree;
00062                 $this->tpl =& $tpl;
00063                 $this->lng =& $lng;
00064                 $this->lng->loadLanguageModule("rbac");
00065 
00066                 $this->ctrl =& $ilCtrl;
00067 
00068                 $this->gui_obj =& $a_gui_obj;
00069                 
00070                 $this->roles = array();
00071                 $this->num_roles = 0;
00072         }
00073         
00074 
00075         function &executeCommand()
00076         {
00077                 global $rbacsystem, $ilErr;
00078 
00079                 // access to all functions in this class are only allowed if edit_permission is granted
00080                 if (!$rbacsystem->checkAccess("edit_permission",$this->gui_obj->object->getRefId()))
00081                 {
00082                         $ilErr->raiseError($this->lng->txt("permission_denied"),$ilErr->MESSAGE);
00083                 }
00084 
00085                 $next_class = $this->ctrl->getNextClass($this);
00086 
00087                 switch($next_class)
00088                 {
00089                         case "ilobjrolegui":
00090                                 include_once("classes/class.ilObjRoleGUI.php");
00091                                 $this->gui_obj = new ilObjRoleGUI("",(int) $_GET["obj_id"], false, false);
00092                                 $this->gui_obj->setBackTarget($this->lng->txt("perm_settings"),
00093                                         $this->ctrl->getLinkTarget($this, "perm"));
00094                                 $ret =& $this->ctrl->forwardCommand($this->gui_obj);
00095                                 break;
00096                                 
00097                         default:
00098                                 $cmd = $this->ctrl->getCmd();
00099                                 $this->$cmd();
00100                                 break;
00101                 }
00102 
00103                 return true;
00104         }
00105 
00111         function perm()
00112         {
00113                 global $rbacsystem, $rbacreview;
00114 
00115                 $this->getRolesData();
00116 
00118                 // START DATA OUTPUT
00120                 $this->__initSubTabs("perm");
00121 
00122                 $this->gui_obj->getTemplateFile("perm");
00123 
00124                 // render filter form
00125             $this->tpl->setCurrentBlock("filter");
00126             $this->tpl->setVariable("FILTER_TXT_FILTER",$this->lng->txt('filter'));
00127             $this->tpl->setVariable("SELECT_FILTER",$this->__buildRoleFilterSelect());
00128             $this->tpl->setVariable("FILTER_ACTION",$this->ctrl->getFormAction($this)."&cmd=perm");
00129             $this->tpl->setVariable("FILTER_NAME",'view');
00130             $this->tpl->setVariable("FILTER_VALUE",$this->lng->txt('apply_filter'));
00131             $this->tpl->parseCurrentBlock();
00132 
00133                 $this->num_roles = count($this->roles);
00134 
00135                 // don't display table if no role in list
00136                 if ($this->num_roles < 1)
00137                 {
00138                         sendinfo($this->lng->txt("msg_no_roles_of_type"),false);
00139                         $this->__displayAddRoleForm();
00140                         return true;
00141                 }
00142                 
00143                 $this->tpl->addBlockFile("PERM_PERMISSIONS", "permissions", "tpl.obj_perm_permissions.html");
00144                 $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("permission_settings"));
00145                 $this->tpl->setVariable("COLSPAN", $this->num_roles);
00146                 $this->tpl->setVariable("FORMACTION",
00147                         $this->gui_obj->getFormAction("permSave",$this->ctrl->getLinkTarget($this,"permSave")));
00148                 $this->tpl->setVariable("TXT_SAVE", $this->lng->txt("save"));
00149                 
00150                 // needed for display correct role context of global roles
00151                 $global_roles = $rbacreview->getGlobalRoles();
00152 
00153                 foreach ($this->roles as $role)
00154                 {
00155                         $tmp_role_folder = $rbacreview->getRoleFolderOfObject($this->gui_obj->object->getRefId());
00156                         $tmp_local_roles = array();
00157 
00158                         if ($tmp_role_folder)
00159                         {
00160                                 $tmp_local_roles = $rbacreview->getRolesOfRoleFolder($tmp_role_folder["ref_id"]);
00161                         }
00162                                 
00163                         // Is it a real or linked lokal role
00164                         if ($role['protected'] == false and in_array($role['obj_id'],$tmp_local_roles))
00165                         {
00166                                 $role_folder_data = $rbacreview->getRoleFolderOfObject($_GET['ref_id']);
00167                                 $role_folder_id = $role_folder_data['ref_id'];
00168 
00169 
00170                                 $this->tpl->setCurrentBlock("rolelink_open");
00171 
00172                                 $up_path = defined('ILIAS_MODULE') ? "../" : "";
00173                                 $this->ctrl->setParameterByClass("ilobjrolegui", "obj_id",
00174                                         $role['obj_id']);
00175                                 $this->ctrl->setParameterByClass("ilobjrolegui", "rolf_ref_id",
00176                                         $role_folder_id);
00177                                 $this->tpl->setVariable("LINK_ROLE_RULESET",
00178                                         $this->ctrl->getLinkTargetByClass("ilobjrolegui", "perm"));
00179                                 
00180                                 $this->tpl->setVariable("TXT_ROLE_RULESET",$this->lng->txt("edit_perm_ruleset"));
00181                                 $this->tpl->parseCurrentBlock();
00182 
00183                                 $this->tpl->touchBlock("rolelink_close");
00184                         }
00185 
00186                         $this->tpl->setCurrentBlock("role_infos");
00187                         
00188                         // display human readable role names for autogenerated roles
00189                         include_once ('class.ilObjRole.php');
00190                         $this->tpl->setVariable("ROLE_NAME",str_replace(" ","&nbsp;",ilObjRole::_getTranslation($role["title"])));
00191                         //var_dump("<pre>",$role,"</pre>");
00192                         
00193                         // display role context
00194                         if (in_array($role["obj_id"],$global_roles))
00195                         {
00196                                 $this->tpl->setVariable("ROLE_CONTEXT_TYPE","global");
00197                         }
00198                         else
00199                         {
00200                                 $rolf = $rbacreview->getFoldersAssignedToRole($role["obj_id"],true);
00201                                 $parent_node = $this->tree->getParentNodeData($rolf[0]);
00202                                 //$this->tpl->setVariable("ROLE_CONTEXT_TYPE",$this->lng->txt("obj_".$parent_node["type"])."&nbsp;(#".$parent_node["obj_id"].")");
00203                                 //$this->tpl->setVariable("ROLE_CONTEXT",$parent_node["title"]);
00204                                 $this->tpl->setVariable("ROLE_CONTEXT_TYPE",$parent_node["title"]);
00205                         }
00206                         
00207                         $this->tpl->parseCurrentBlock();
00208                 }
00209                 $this->ctrl->clearParametersByClass("ilobjrolegui");
00210                 
00211 // show permission settings
00212 
00213                 // general section
00214                 $this->__showPermissionsGeneralSection();
00215                 
00216                 // object section
00217                 $this->__showPermissionsObjectSection();
00218 
00219                 // rbac section
00220                 $this->__showPermissionsRBACSection();
00221                 
00222                 // create section
00223                 $this->__showPermissionsCreateSection();
00224 
00225                 $this->tpl->setVariable("COLSPAN", $this->num_roles);
00226 
00227                 // ADD LOCAL ROLE               
00228                 $this->__displayAddRoleForm();
00229         }
00230 
00231 
00237         function permSave()
00238         {
00239                 global $rbacreview, $rbacadmin, $rbacsystem;
00240 
00241                 // first save the new permission settings for all roles
00242                 $rbacadmin->revokePermission($this->gui_obj->object->getRefId());
00243 
00244                 if (is_array($_POST["perm"]))
00245                 {
00246                         foreach ($_POST["perm"] as $key => $new_role_perms) // $key enthaelt die aktuelle Role_Id
00247                         {
00248                                 $rbacadmin->grantPermission($key,$new_role_perms,$this->gui_obj->object->getRefId());
00249                         }
00250                 }
00251 
00252                 // update object data entry (to update last modification date)
00253                 $this->gui_obj->object->update();
00254 
00255                 // Wenn die Vererbung der Rollen Templates unterbrochen werden soll,
00256                 // muss folgendes geschehen:
00257                 // - existiert kein RoleFolder, wird er angelegt und die Rechte aus den Permission Templates ausgelesen
00258                 // - existiert die Rolle im aktuellen RoleFolder werden die Permission Templates dieser Rolle angezeigt
00259                 // - existiert die Rolle nicht im aktuellen RoleFolder wird sie dort angelegt
00260                 //   und das Permission Template an den Wert des nihst hher gelegenen Permission Templates angepasst
00261 
00262                 // get rolefolder data if a rolefolder already exists
00263                 $rolf_data = $rbacreview->getRoleFolderOfObject($this->gui_obj->object->getRefId());
00264                 $rolf_id = $rolf_data["child"];
00265                 
00266                 $stop_inherit_roles = $_POST["stop_inherit"] ? $_POST["stop_inherit"] : array();
00267 
00268                 if ($stop_inherit_roles)
00269                 {
00270                         // rolefolder does not exist, so create one
00271                         if (empty($rolf_id))
00272                         {
00273                                 // create a local role folder
00274                                 $rfoldObj = $this->gui_obj->object->createRoleFolder();
00275 
00276                                 // set rolf_id again from new rolefolder object
00277                                 $rolf_id = $rfoldObj->getRefId();
00278                         }
00279 
00280                         $roles_of_folder = $rbacreview->getRolesOfRoleFolder($rolf_id);
00281                         
00282                         foreach ($stop_inherit_roles as $stop_inherit)
00283                         {
00284                                 // create role entries for roles with stopped inheritance
00285                                 if (!in_array($stop_inherit,$roles_of_folder))
00286                                 {
00287                                         $parentRoles = $rbacreview->getParentRoleIds($rolf_id);
00288                                         $rbacadmin->copyRolePermission($stop_inherit,$parentRoles[$stop_inherit]["parent"],
00289                                                                                                    $rolf_id,$stop_inherit);
00290                                         $rbacadmin->assignRoleToFolder($stop_inherit,$rolf_id,'n');
00291                                 }
00292                         }// END FOREACH
00293                 }// END STOP INHERIT
00294                 
00295                 if ($rolf_id  and $rolf_id != ROLE_FOLDER_ID)
00296                 {
00297                         // get roles where inheritance is stopped was cancelled
00298                         $linked_roles = $rbacreview->getLinkedRolesOfRoleFolder($rolf_id);
00299                         $linked_roles_to_remove = array_diff($linked_roles,$stop_inherit_roles);
00300                                 
00301                         // remove roles where stopped inheritance is cancelled and purge rolefolder if empty
00302                         foreach ($linked_roles_to_remove as $role_id)
00303                         {
00304                                 if ($rbacreview->isProtected($rolf_id,$role_id))
00305                                 {
00306                                         continue;
00307                                 }
00308                                 
00309                                 $role_obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
00310                                 $role_obj->setParent($rolf_id);
00311                                 $role_obj->delete();
00312                                 unset($role_obj);
00313                         }
00314                 }
00315                 
00316                 sendinfo($this->lng->txt("saved_successfully"),true);
00317                 
00318                 // redirect to default page if user revokes himself access to the permission panel
00319                 if (!$rbacsystem->checkAccess("edit_permission",$this->gui_obj->object->getRefId()))
00320                 {
00321                         $this->ctrl->redirect($this->gui_obj);
00322                 }
00323                 
00324                 $this->ctrl->redirect($this,'perm');
00325         }
00326 
00327 
00328 
00336         function addRole()
00337         {
00338                 global $rbacadmin, $rbacreview, $rbacsystem;
00339 
00340                 // first check if role title is unique
00341                 if ($rbacreview->roleExists($_POST["Fobject"]["title"]))
00342                 {
00343                         $this->ilias->raiseError($this->lng->txt("msg_role_exists1")." '".ilUtil::stripSlashes($_POST["Fobject"]["title"])."' ".
00344                                                                          $this->lng->txt("msg_role_exists2"),$this->ilias->error_obj->MESSAGE);
00345                 }
00346 
00347                 // check if role title has il_ prefix
00348                 if (substr($_POST["Fobject"]["title"],0,3) == "il_")
00349                 {
00350                         $this->ilias->raiseError($this->lng->txt("msg_role_reserved_prefix"),$this->ilias->error_obj->MESSAGE);
00351                 }
00352 
00353                 // if the current object is no role folder, create one
00354                 if ($this->gui_obj->object->getType() != "rolf")
00355                 {
00356                         $rolf_data = $rbacreview->getRoleFolderOfObject($this->gui_obj->object->getRefId());
00357 
00358                         // is there already a rolefolder?
00359                         if (!($rolf_id = $rolf_data["child"]))
00360                         {
00361                                 // can the current object contain a rolefolder?
00362                                 $subobjects = $this->objDefinition->getSubObjects($this->gui_obj->object->getType());
00363 
00364                                 if (!isset($subobjects["rolf"]))
00365                                 {
00366                                         $this->ilias->raiseError($this->lng->txt("msg_no_rolf_allowed1")." '".$this->gui_obj->object->getTitle()."' ".
00367                                                                                         $this->lng->txt("msg_no_rolf_allowed2"),$this->ilias->error_obj->WARNING);
00368                                 }
00369 
00370                                 // create a rolefolder
00371                                 $rolfObj = $this->gui_obj->object->createRoleFolder();
00372                                 $rolf_id = $rolfObj->getRefId();
00373                         }
00374                 }
00375                 else
00376                 {
00377                         // Current object is already a rolefolder. To create the role we take its reference id
00378                         $rolf_id = $this->gui_obj->object->getRefId();
00379                 }
00380 
00381                 // create role
00382                 if ($this->gui_obj->object->getType() == "rolf")
00383                 {
00384                         $roleObj = $this->gui_obj->object->createRole($_POST["Fobject"]["title"],$_POST["Fobject"]["desc"]);
00385                 }
00386                 else
00387                 {
00388                         $rfoldObj = $this->ilias->obj_factory->getInstanceByRefId($rolf_id);
00389                         $roleObj = $rfoldObj->createRole($_POST["Fobject"]["title"],$_POST["Fobject"]["desc"]);
00390                 }
00391 
00392                 sendInfo($this->lng->txt("role_added"),true);
00393                 
00394                 // in administration jump to deault perm settings screen
00395                 // alex, ILIAS 3.6.5, 1.9.2006: this does not work and leads to errors in
00396                 // a) administration
00397                 //    -> repository trash & permissions -> item -> permissions ->
00398                 //    "you may add role" screen -> save
00399                 // b) other modules like learning modules
00400                 //    -> permissions -> "you may add role" screen
00401                 // deactivated for 3.6.6
00402                 //if ($this->ctrl->getTargetScript() != "repository.php")
00403                 //{
00404                 //      $this->ctrl->setParameter($this,"obj_id",$roleObj->getId());
00405                 //      $this->ctrl->setParameter($this,"ref_id",$rolf_id);
00406                 //      $this->ctrl->redirect($this,'perm');
00407                 //}
00408 
00409                 $this->ctrl->redirect($this,'perm');
00410         }
00411 
00412         function &__initTableGUI()
00413         {
00414                 include_once "./classes/class.ilTableGUI.php";
00415 
00416                 return new ilTableGUI(0,false);
00417         }
00418         
00424         function __setTableGUIBasicData(&$tbl,&$result_set,$a_from = "")
00425         {
00426                 switch ($a_from)
00427                 {
00428                         case "clipboardObject":
00429                                 $offset = $_GET["offset"];
00430                                 $order = $_GET["sort_by"];
00431                                 $direction = $_GET["sort_order"];
00432                                 $tbl->disable("footer");
00433                                 break;
00434 
00435                         default:
00436                                 $offset = $_GET["offset"];
00437                                 $order = $_GET["sort_by"];
00438                                 $direction = $_GET["sort_order"];
00439                                 break;
00440                 }
00441 
00442                 $tbl->setOrderColumn($order);
00443                 $tbl->setOrderDirection($direction);
00444                 $tbl->setOffset($offset);
00445                 $tbl->setLimit($_GET["limit"]);
00446                 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
00447                 $tbl->setData($result_set);
00448         }
00449         
00450 
00451         function __buildRoleFilterSelect()
00452         {
00453                 $action[1] = $this->lng->txt('filter_all_roles');
00454                 $action[2] = $this->lng->txt('filter_global_roles');
00455                 $action[3] = $this->lng->txt('filter_local_roles');
00456                 $action[4] = $this->lng->txt('filter_roles_local_policy');
00457                 $action[5] = $this->lng->txt('filter_local_roles_object');
00458                 
00459                 return ilUtil::formSelect($_SESSION['perm_filtered_roles'],"filter",$action,false,true);
00460         }
00461         
00462         function __filterRoles($a_roles,$a_filter)
00463         {
00464                 global $rbacreview;
00465 
00466                 switch ($a_filter)
00467                 {
00468                         case 1: // all roles in context
00469                                 return $a_roles;
00470                                 break;
00471                         
00472                         case 2: // only global roles
00473                                 $arr_global_roles = $rbacreview->getGlobalRoles();
00474                                 $arr_remove_roles = array_diff(array_keys($a_roles),$arr_global_roles);
00475 
00476                                 foreach ($arr_remove_roles as $role_id)
00477                                 {
00478                                         unset($a_roles[$role_id]);
00479                                 }
00480                                 
00481                                 return $a_roles;
00482                                 break;                  
00483 
00484                         case 3: // only local roles (all local roles in context that are not defined at ROLE_FOLDER_ID)
00485                                 $arr_global_roles = $rbacreview->getGlobalRoles();
00486 
00487                                 foreach ($arr_global_roles as $role_id)
00488                                 {
00489                                         unset($a_roles[$role_id]);
00490                                 }
00491                                 
00492                                 return $a_roles;
00493                                 break;
00494                                 
00495                         case 4: // only roles which use a local policy 
00496                                 $role_folder = $rbacreview->getRoleFolderOfObject($this->gui_obj->object->getRefId());
00497                 
00498                                 if (!$role_folder)
00499                                 {
00500                                         return array();
00501                                 }
00502                                 
00503                                 $arr_local_roles = $rbacreview->getRolesOfRoleFolder($role_folder["ref_id"]);
00504                                 $arr_remove_roles = array_diff(array_keys($a_roles),$arr_local_roles);
00505 
00506                                 foreach ($arr_remove_roles as $role_id)
00507                                 {
00508                                         unset($a_roles[$role_id]);
00509                                 }
00510 
00511                                 return $a_roles;
00512                                 break;
00513                                 
00514                         case 5: // only true local role defined at current position
00515                                 
00516                                 $role_folder = $rbacreview->getRoleFolderOfObject($this->gui_obj->object->getRefId());
00517                 
00518                                 if (!$role_folder)
00519                                 {
00520                                         return array();
00521                                 }
00522                                 
00523                                 $arr_local_roles = $rbacreview->getRolesOfRoleFolder($role_folder["ref_id"],false);
00524                                 $arr_remove_roles = array_diff(array_keys($a_roles),$arr_local_roles);
00525 
00526                                 foreach ($arr_remove_roles as $role_id)
00527                                 {
00528                                         unset($a_roles[$role_id]);
00529                                 }
00530 
00531                                 return $a_roles;
00532                                 break;
00533                 }
00534 
00535                 return $a_roles;
00536         }
00537 
00538         // show owner sub tab
00539         function owner()
00540         {
00541                 global $ilObjDataCache,$ilUser;
00542 
00543                 $this->__initSubTabs("owner");
00544 
00545                 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.obj_owner.html');
00546 
00547                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00548                 $this->tpl->setVariable("USERNAME",ilObjUser::_lookupLogin($this->gui_obj->object->getOwner()));
00549                 $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath('icon_usr.gif'));
00550                 $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->lng->txt('owner'));
00551                 $this->tpl->setVariable("TBL_TITLE",$this->lng->txt('info_owner_of_object'));
00552                 $this->tpl->setVariable("BTN_CHOWN",$this->lng->txt('change_owner'));
00553                 $this->tpl->setVariable("TXT_USERNAME",$this->lng->txt('username'));
00554                 $this->tpl->setVariable("CHOWN_WARNING",$this->lng->txt('chown_warning'));
00555         }
00556         
00557         function changeOwner()
00558         {
00559                 global $rbacsystem,$ilErr,$ilObjDataCache;
00560 
00561                 if(!$user_id = ilObjUser::_lookupId($_POST['owner']))
00562                 {
00563                         sendInfo($this->lng->txt('user_not_known'));
00564                         $this->owner();
00565                         return true;
00566                 }
00567 
00568                 $this->gui_obj->object->setOwner($user_id);
00569                 $this->gui_obj->object->updateOwner();
00570                 $ilObjDataCache->deleteCachedEntry($this->gui_obj->object->getId());
00571                 sendInfo($this->lng->txt('owner_updated'),true);
00572 
00573                 if (!$rbacsystem->checkAccess("edit_permission",$this->gui_obj->object->getRefId()))
00574                 {
00575                         $this->ctrl->redirect($this->gui_obj);
00576                         return true;
00577                 }
00578 
00579                 $this->ctrl->redirect($this,'owner');
00580                 return true;
00581 
00582         }
00583         
00584         // init permission query feature
00585         function info()
00586         {
00587                 $this->__initSubTabs("info");
00588 
00589                 include_once('classes/class.ilObjectStatusGUI.php');
00590                 
00591                 $ilInfo = new ilObjectStatusGUI($this->gui_obj->object);
00592                 
00593                 $this->tpl->setVariable("ADM_CONTENT",$ilInfo->getHTML());
00594         }
00595         
00596         // init sub tabs
00597         function __initSubTabs($a_cmd)
00598         {
00599                 global $ilTabs;
00600 
00601                 $perm = ($a_cmd == 'perm') ? true : false;
00602                 $info = ($a_cmd == 'info') ? true : false;
00603                 $owner = ($a_cmd == 'owner') ? true : false;
00604 
00605                 $ilTabs->addSubTabTarget("permission_settings", $this->ctrl->getLinkTarget($this, "perm"),
00606                                                                  "", "", "", $perm);
00607                 $ilTabs->addSubTabTarget("info_status_info", $this->ctrl->getLinkTarget($this, "info"),
00608                                                                  "", "", "", $info);
00609                 $ilTabs->addSubTabTarget("owner", $this->ctrl->getLinkTarget($this, "owner"),
00610                                                                  "", "", "", $owner);
00611         }
00612         
00613         function getRolesData()
00614         {
00615                 global $rbacsystem, $rbacreview;
00616 
00617                 // first get all roles in
00618                 $roles = $rbacreview->getParentRoleIds($this->gui_obj->object->getRefId());
00619 
00620                 // filter roles
00621                 $_SESSION['perm_filtered_roles'] = isset($_POST['filter']) ? $_POST['filter'] : $_SESSION['perm_filtered_roles'];
00622 
00623                 // set default filter (all roles) if no filter is set
00624                 if ($_SESSION['perm_filtered_roles'] == 0)
00625         {
00626                 $_SESSION['perm_filtered_roles'] = 1;
00627         }
00628         
00629                 // remove filtered roles from array
00630         $roles = $this->__filterRoles($roles,$_SESSION["perm_filtered_roles"]);
00631 
00632                 // determine status of each role (local role, changed policy, protected)
00633 
00634                 $role_folder = $rbacreview->getRoleFolderOfObject($this->gui_obj->object->getRefId());
00635                 
00636                 $local_roles = array();
00637 
00638                 if (!empty($role_folder))
00639                 {
00640                         $local_roles = $rbacreview->getRolesOfRoleFolder($role_folder["ref_id"]);
00641                 }
00642 
00643                 foreach ($roles as $key => $role)
00644                 {
00645                         // exclude system admin role from list
00646                         if ($role["obj_id"] == SYSTEM_ROLE_ID)
00647                         {
00648                                 unset($roles[$key]);
00649                                 continue;
00650                         }
00651                         
00652                         $this->roles[$role['obj_id']] = $role;
00653 
00654                         // don't allow local policies for protected roles
00655                         $this->roles[$role['obj_id']]['keep_protected'] = $rbacreview->isProtected($role['parent'],$role['obj_id']);
00656 
00657                         if (!in_array($role["obj_id"],$local_roles))
00658                         {
00659                                 $this->roles[$role['obj_id']]['local_policy_enabled'] = false;
00660                                 $this->roles[$role['obj_id']]['local_policy_allowed'] = true;
00661                         }
00662                         else
00663                         {
00664                                 // no checkbox for local roles
00665                                 if ($rbacreview->isAssignable($role["obj_id"],$role_folder["ref_id"]))
00666                                 {
00667                                         $this->roles[$role['obj_id']]['local_policy_allowed'] = false;
00668                                 }
00669                                 else
00670                                 {
00671                                         $this->roles[$role['obj_id']]['local_policy_enabled'] = true;
00672                                         $this->roles[$role['obj_id']]['local_policy_allowed'] = true;
00673                                 }
00674                         }
00675 
00676                         // compute permission settings for each role
00677                         $grouped_ops = groupOperationsByClass(getOperationList($this->gui_obj->object->getType()));
00678 
00679                         foreach ($grouped_ops as $ops_group => $ops_data)
00680                         {
00681                                 foreach ($ops_data as $key => $operation)
00682                                 {
00683                                         $grouped_ops[$ops_group][$key]['checked'] = $rbacsystem->checkPermission($this->gui_obj->object->getRefId(), $role['obj_id'], $operation['name']);
00684                                 }
00685                         }
00686                         
00687                         $this->roles[$role['obj_id']]['permissions'] = $grouped_ops;
00688                         unset($grouped_ops);
00689                 }
00690         }
00691         
00692         function __displayAddRoleForm()
00693         {
00694                 // do not display this option for admin section and root node
00695                 $object_types_exclude = array("adm","root","mail","objf","lngf","trac","taxf","auth", "assf",'seas','extt');
00696 
00697                 if (!in_array($this->gui_obj->object->getType(),$object_types_exclude) and $this->gui_obj->object->getRefId() != ROLE_FOLDER_ID)
00698                 {
00699                         $this->tpl->addBlockFile("PERM_ADD_ROLE", "add_local_roles", "tpl.obj_perm_add_role.html");
00700 
00701                         // fill in saved values in case of error
00702                         $data = array();
00703                         $data["fields"] = array();
00704                         $data["fields"]["title"] = $_SESSION["error_post_vars"]["Fobject"]["title"];
00705                         $data["fields"]["desc"] = $_SESSION["error_post_vars"]["Fobject"]["desc"];
00706 
00707                         foreach ($data["fields"] as $key => $val)
00708                         {
00709                                 $this->tpl->setVariable("TXT_LR_".strtoupper($key), $this->lng->txt($key));
00710                                 $this->tpl->setVariable(strtoupper($key), $val);
00711                         }
00712 
00713                         $this->tpl->setVariable("FORMACTION_LR",$this->gui_obj->getFormAction("addRole", $this->ctrl->getLinkTarget($this, "addRole")));
00714                         $this->tpl->setVariable("TXT_LR_HEADER", $this->lng->txt("you_may_add_local_roles"));
00715                         $this->tpl->setVariable("TXT_ADD_ROLE", $this->lng->txt("role_add_local"));
00716                         $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00717                 }
00718         }
00719         
00720         function __showPermissionsGeneralSection()
00721         {
00722                 $this->tpl->setCurrentBlock("perm_subtitle");
00723                 $this->tpl->setVariable("TXT_PERM_CLASS",$this->lng->txt('perm_class_general'));
00724                 $this->tpl->setVariable("TXT_PERM_CLASS_DESC",$this->lng->txt('perm_class_general_desc'));
00725                 $this->tpl->setVariable("COLSPAN", $this->num_roles);
00726                 $this->tpl->parseCurrentBlock();
00727 
00728                 foreach ($this->roles as $role)
00729                 {
00730                         foreach ($role['permissions']['general'] as $perm)
00731                         {
00732                                 // exclude delete permission for all role_folders expect main ROLE_FOLDER_ID
00733                                 if ($perm['name'] == 'delete' and $this->gui_obj->object->getType() == 'rolf' and $this->gui_obj->object->getRefId() != ROLE_FOLDER_ID)
00734                                 {
00735                                         continue;
00736                                 }
00737                                 
00738                                 $box = ilUtil::formCheckBox($perm['checked'],"perm[".$role["obj_id"]."][]",$perm["ops_id"],$role["protected"]);
00739 
00740                                 $this->tpl->setCurrentBlock("perm_item");
00741                                 $this->tpl->setVariable("PERM_CHECKBOX",$box);
00742                                 $this->tpl->setVariable("PERM_NAME",$this->lng->txt($perm['name']));
00743                                 $this->tpl->setVariable("PERM_TOOLTIP",$this->lng->txt($this->gui_obj->object->getType()."_".$perm['name']));
00744                                 $this->tpl->setVariable("PERM_LABEL",'perm_'.$role['obj_id'].'_'.$perm['ops_id']);
00745                                 $this->tpl->parseCurrentBlock();
00746                         }
00747 
00748                         $this->tpl->setCurrentBlock("perm_table");
00749                         $this->tpl->parseCurrentBlock();        
00750                 }
00751 
00752                 $this->tpl->setCurrentBlock("perm_settings");
00753                 $this->tpl->parseCurrentBlock();
00754         }
00755         
00756         function __showPermissionsObjectSection()
00757         {
00758                 // create pointer to first role (only the permission list is needed)
00759                 reset($this->roles);
00760                 $first_role =& current($this->roles);
00761 
00762                 if (count($first_role['permissions']['object'])) // check if object type has special operations
00763                 {
00764                         $this->tpl->setCurrentBlock("perm_subtitle");
00765                         $this->tpl->setVariable("TXT_PERM_CLASS",$this->lng->txt('perm_class_object'));
00766                         $this->tpl->setVariable("TXT_PERM_CLASS_DESC",$this->lng->txt('perm_class_object_desc'));
00767                         $this->tpl->setVariable("COLSPAN", $this->num_roles);
00768                         $this->tpl->parseCurrentBlock();
00769         
00770                         foreach ($this->roles as $role)
00771                         {
00772                                 foreach ($role['permissions']['object'] as $perm)
00773                                 {
00774                                         $box = ilUtil::formCheckBox($perm['checked'],"perm[".$role["obj_id"]."][]",$perm["ops_id"],$role["protected"]);
00775         
00776                                         $this->tpl->setCurrentBlock("perm_item");
00777                                         $this->tpl->setVariable("PERM_CHECKBOX",$box);
00778                                         $this->tpl->setVariable("PERM_NAME",$this->lng->txt($this->gui_obj->object->getType()."_".$perm['name']));
00779                                         $this->tpl->setVariable("PERM_TOOLTIP",$this->lng->txt($this->gui_obj->object->getType()."_".$perm['name']));
00780                                         $this->tpl->setVariable("PERM_LABEL",'perm_'.$role['obj_id'].'_'.$perm['ops_id']);
00781                                         $this->tpl->parseCurrentBlock();
00782                                 }
00783         
00784                                 $this->tpl->setCurrentBlock("perm_table");
00785                                 $this->tpl->parseCurrentBlock();        
00786                         }                                                               
00787         
00788                         $this->tpl->setCurrentBlock("perm_settings");
00789                         $this->tpl->parseCurrentBlock();
00790                 }
00791         }
00792         
00793         function __showPermissionsRBACSection()
00794         {
00795                 $this->tpl->setCurrentBlock("perm_subtitle");
00796                 $this->tpl->setVariable("TXT_PERM_CLASS",$this->lng->txt('perm_class_rbac'));
00797                 $this->tpl->setVariable("TXT_PERM_CLASS_DESC",$this->lng->txt('perm_class_rbac_desc'));
00798                 $this->tpl->setVariable("COLSPAN", $this->num_roles);
00799                 $this->tpl->parseCurrentBlock();
00800 
00801                 foreach ($this->roles as $role)
00802                 {
00803                         foreach ($role['permissions']['rbac'] as $perm)
00804                         {
00805                                 $box = ilUtil::formCheckBox($perm['checked'],"perm[".$role["obj_id"]."][]",$perm["ops_id"],$role["protected"]);
00806 
00807                                 $this->tpl->setCurrentBlock("perm_item");
00808                                 $this->tpl->setVariable("PERM_CHECKBOX",$box);
00809                                 $this->tpl->setVariable("PERM_NAME",$this->lng->txt('perm_administrate'));
00810                                 $this->tpl->setVariable("PERM_TOOLTIP",$this->lng->txt($this->gui_obj->object->getType()."_".$perm['name']));
00811                                 $this->tpl->setVariable("PERM_LABEL",'perm_'.$role['obj_id'].'_'.$perm['ops_id']);
00812                                 $this->tpl->parseCurrentBlock();
00813                         }
00814 
00815                         // use local policy flag
00816                         // offer option 'use local policy' only to those objects where this option is permitted
00817                         if ($this->objDefinition->stopInheritance($this->gui_obj->object->getType()))
00818                         {
00819                                 if ($role['local_policy_allowed'])
00820                                 {
00821                                         $box = ilUtil::formCheckBox($role['local_policy_enabled'],'stop_inherit[]',$role['obj_id'],$role['keep_protected']);
00822                                         $lang = $this->lng->txt("perm_use_local_policy")." (".
00823                                                 $this->lng->txt("stop_inheritance").")";
00824                                         $lang_desc = $this->lng->txt("perm_use_local_policy_desc");
00825                                 }
00826                                 else
00827                                 {
00828                                         $box = '&nbsp;';
00829                                         $lang = $this->lng->txt("perm_local_role");
00830                                         $lang_desc = $this->lng->txt("perm_local_role_desc");
00831                                 }
00832                                 
00833                                 $this->tpl->setCurrentBlock("perm_item");
00834                                 $this->tpl->setVariable("PERM_CHECKBOX",$box);
00835                                 $this->tpl->setVariable("PERM_NAME",$lang);
00836                                 $this->tpl->setVariable("PERM_TOOLTIP",$lang_desc);
00837                                 $this->tpl->setVariable("PERM_LABEL",'stop_inherit_'.$role['obj_id']);
00838                                 $this->tpl->parseCurrentBlock();
00839                         }
00840         
00841                                 $this->tpl->setCurrentBlock("perm_table");
00842                                 $this->tpl->parseCurrentBlock();        
00843                 }
00844 
00845                 $this->tpl->setCurrentBlock("perm_settings");
00846                 $this->tpl->parseCurrentBlock();
00847         }
00848         
00849         function __showPermissionsCreateSection()
00850         {
00851                 // no create operation for roles/role templates in local role folders
00852                 // access is controlled by 'administrate' (change permission settings) only
00853                 if ($this->gui_obj->object->getType() == 'rolf' and $this->gui_obj->object->getRefId() != ROLE_FOLDER_ID)
00854                 {
00855                         return;
00856                 }
00857                 
00858                 // create pointer to first role (only the permission list is needed)
00859                 reset($this->roles);
00860                 $first_role =& current($this->roles);
00861 
00862                 if (count($first_role['permissions']['create'])) // check if object type has create operations
00863                 {
00864                         $this->tpl->setCurrentBlock("perm_subtitle");
00865                         $this->tpl->setVariable("TXT_PERM_CLASS",$this->lng->txt('perm_class_create'));
00866                         $this->tpl->setVariable("TXT_PERM_CLASS_DESC",$this->lng->txt('perm_class_create_desc'));
00867                         $this->tpl->setVariable("COLSPAN", $this->num_roles);
00868                         $this->tpl->parseCurrentBlock();
00869         
00870                         foreach ($this->roles as $role)
00871                         {
00872                                 foreach ($role['permissions']['create'] as $perm)
00873                                 {
00874                                         if (!$this->ilias->getSetting("ilinc_active") and $perm["name"] == "create_icrs")
00875                                         {
00876                                                 continue;
00877                                         }
00878 
00879                                         $box = ilUtil::formCheckBox($perm['checked'],"perm[".$role["obj_id"]."][]",$perm["ops_id"],$role["protected"]);
00880         
00881                                         $this->tpl->setCurrentBlock("perm_item");
00882                                         $this->tpl->setVariable("PERM_CHECKBOX",$box);
00883                                         $this->tpl->setVariable("PERM_NAME",$this->lng->txt("obj".substr($perm['name'],6)));
00884                                         $this->tpl->setVariable("PERM_TOOLTIP",$this->lng->txt($this->gui_obj->object->getType()."_".$perm['name']));
00885                                         $this->tpl->setVariable("PERM_LABEL",'perm_'.$role['obj_id'].'_'.$perm['ops_id']);
00886                                         $this->tpl->parseCurrentBlock();
00887                                 }
00888         
00889                                 $this->tpl->setCurrentBlock("perm_table");
00890                                 $this->tpl->parseCurrentBlock();        
00891                         }
00892         
00893                         $this->tpl->setCurrentBlock("perm_settings");
00894                         $this->tpl->parseCurrentBlock();
00895                 }
00896         }
00897 } // END class.ilPermissionGUI
00898 ?>

Generated on Fri Dec 13 2013 11:57:55 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1