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

classes/class.ilObjRoleGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 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 require_once "class.ilObjectGUI.php";
00037 
00038 class ilObjRoleGUI extends ilObjectGUI
00039 {
00045         var $type;
00046 
00052         var $rolf_ref_id;
00053 
00054 
00055         var $ctrl;
00056  
00061         function ilObjRoleGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output = true)
00062         {
00063                 define("USER_FOLDER_ID",7);
00064 
00065                 global $ilCtrl;
00066 
00067                 $this->type = "role";
00068                 $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output);
00069                 $this->rolf_ref_id =& $this->ref_id;
00070 
00071                 $this->ctrl =& $ilCtrl;
00072                 $this->ctrl->saveParameter($this,'obj_id');
00073         }
00074 
00075         function &executeCommand()
00076         {
00077                 global $rbacsystem;
00078 
00079                 if($this->ctrl->getTargetScript() == 'role.php')
00080                 {
00081                         $this->__prepareOutput();
00082                 }
00083 
00084                 $next_class = $this->ctrl->getNextClass($this);
00085 
00086                 $cmd = $this->ctrl->getCmd();
00087                 switch($next_class)
00088                 {
00089                         default:
00090                                 if(!$cmd)
00091                                 {
00092                                         $cmd = "perm";
00093                                 }
00094                                 $cmd .= "Object";
00095                                 $this->$cmd();
00096                                         
00097                                 break;
00098                 }
00099                 return true;
00100         }
00101 
00102         function listDesktopItemsObject()
00103         {
00104                 global $rbacsystem,$rbacreview,$tree;
00105 
00106                 if(!$rbacsystem->checkAccess('edit_permission', $this->rolf_ref_id))
00107                 {
00108                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00109                 }
00110 
00111                 if(!$rbacreview->isAssignable($this->object->getId(),$this->rolf_ref_id))
00112                 {
00113                         sendInfo($this->lng->txt('role_no_users_no_desk_items'));
00114                         return true;
00115                 }
00116 
00117                 include_once './classes/class.ilRoleDesktopItem.php';
00118 
00119                 $role_desk_item_obj =& new ilRoleDesktopItem($this->object->getId());
00120 
00121                 $this->__showButton('selectDesktopItem',$this->lng->txt('role_desk_add'));
00122                 if(!count($items = $role_desk_item_obj->getAll()))
00123                 {
00124                         sendInfo($this->lng->txt('role_desk_none_created'));
00125 
00126                         return true;
00127                 }
00128                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.role_desktop_item_list.html");
00129                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00130                 $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath('icon_role_b.gif'));
00131                 $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->lng->txt('obj_role'));
00132                 $this->tpl->setVariable("TBL_TITLE",$this->lng->txt('role_assigned_desk_items').' ('.$this->object->getTitle().')');
00133                 $this->tpl->setVariable("HEADER_DESC",$this->lng->txt('description'));
00134                 $this->tpl->setVariable("BTN_DELETE",$this->lng->txt('delete'));
00135                 $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath('arrow_downright.gif'));
00136 
00137                 $counter = 0;
00138                 foreach($items as $role_item_id => $item)
00139                 {
00140                         $tmp_obj = ilObjectFactory::getInstanceByRefId($item['item_id']);
00141                         
00142                         if(strlen($desc = $tmp_obj->getDescription()))
00143                         {
00144                                 $this->tpl->setCurrentBlock("description");
00145                                 $this->tpl->setVariable("DESCRIPTION_DESK",$desc);
00146                                 $this->tpl->parseCurrentBlock();
00147                         }
00148                         $this->tpl->setCurrentBlock("desk_row");
00149                         $this->tpl->setVariable("DESK_TITLE",$tmp_obj->getTitle());
00150                         $this->tpl->setVariable("ROW_CLASS",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
00151                         $this->tpl->setVariable("CHECK_DESK",ilUtil::formCheckBox(0,'del_desk_item[]',$role_item_id));
00152                         $this->tpl->setVariable("TXT_PATH",$this->lng->txt('path').':');
00153                         $this->tpl->setVariable("PATH",$this->__formatPath($tree->getPathFull($item['item_id'])));
00154                         $this->tpl->parseCurrentBlock();
00155                 }
00156                         
00157                 return true;
00158         }
00159 
00160         function askDeleteDesktopItemObject()
00161         {
00162                 global $rbacsystem;
00163                 
00164                 if(!$rbacsystem->checkAccess('edit_permission', $this->rolf_ref_id))
00165                 {
00166                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00167                 }
00168                 if(!$rbacsystem->checkAccess('push_desktop_items',USER_FOLDER_ID))
00169                 {
00170                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00171                 }
00172                 if(!count($_POST['del_desk_item']))
00173                 {
00174                         sendInfo($this->lng->txt('role_select_one_item'));
00175 
00176                         $this->listDesktopItemsObject();
00177 
00178                         return true;
00179                 }
00180                 sendInfo($this->lng->txt('role_sure_delete_desk_items'));
00181                 
00182                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.role_ask_delete_desktop_item.html");
00183                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00184                 $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath('icon_role_b.gif'));
00185                 $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->lng->txt('obj_role'));
00186                 $this->tpl->setVariable("TBL_TITLE",$this->lng->txt('role_assigned_desk_items').' ('.$this->object->getTitle().')');
00187                 $this->tpl->setVariable("HEADER_DESC",$this->lng->txt('description'));
00188                 $this->tpl->setVariable("BTN_DELETE",$this->lng->txt('delete'));
00189                 $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt('cancel'));
00190 
00191                 include_once './classes/class.ilRoleDesktopItem.php';
00192 
00193                 $role_desk_item_obj =& new ilRoleDesktopItem($this->object->getId());
00194 
00195                 $counter = 0;
00196                 foreach($_POST['del_desk_item'] as $role_item_id)
00197                 {
00198                         $item_data = $role_desk_item_obj->getItem($role_item_id);
00199                         $tmp_obj =& ilObjectFactory::getInstanceByRefId($item_data['item_id']);
00200 
00201                         if(strlen($desc = $tmp_obj->getDescription()))
00202                         {
00203                                 $this->tpl->setCurrentBlock("description");
00204                                 $this->tpl->setVariable("DESCRIPTION_DESK",$desc);
00205                                 $this->tpl->parseCurrentBlock();
00206                         }
00207                         $this->tpl->setCurrentBlock("desk_row");
00208                         $this->tpl->setVariable("DESK_TITLE",$tmp_obj->getTitle());
00209                         $this->tpl->setVariable("ROW_CLASS",ilUtil::switchColor(++$counter,'tblrow1','tblrow2'));
00210                         $this->tpl->parseCurrentBlock();
00211                 }
00212                 $_SESSION['role_del_desk_items'] = $_POST['del_desk_item'];
00213 
00214                 return true;
00215         }
00216 
00217         function deleteDesktopItemsObject()
00218         {
00219                 global $rbacsystem;
00220                 
00221                 if(!$rbacsystem->checkAccess('edit_permission', $this->rolf_ref_id))
00222                 {
00223                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00224                 }
00225                 if(!$rbacsystem->checkAccess('push_desktop_items',USER_FOLDER_ID))
00226                 {
00227                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00228                 }
00229                 if(!count($_SESSION['role_del_desk_items']))
00230                 {
00231                         sendInfo($this->lng->txt('role_select_one_item'));
00232 
00233                         $this->listDesktopItemsObject();
00234 
00235                         return true;
00236                 }
00237 
00238                 include_once './classes/class.ilRoleDesktopItem.php';
00239 
00240                 $role_desk_item_obj =& new ilRoleDesktopItem($this->object->getId());
00241 
00242                 foreach($_SESSION['role_del_desk_items'] as $role_item_id)
00243                 {
00244                         $role_desk_item_obj->delete($role_item_id);
00245                 }
00246 
00247                 sendInfo($this->lng->txt('role_deleted_desktop_items'));
00248                 $this->listDesktopItemsObject();
00249 
00250                 return true;
00251         }
00252 
00253 
00254         function selectDesktopItemObject()
00255         {
00256                 global $rbacsystem,$tree;
00257 
00258                 include_once './classes/class.ilRoleDesktopItemSelector.php';
00259                 include_once './classes/class.ilRoleDesktopItem.php';
00260                 
00261 
00262                 if(!$rbacsystem->checkAccess('push_desktop_items',USER_FOLDER_ID))
00263                 {
00264                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00265                 }
00266 
00267                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.role_desktop_item_selector.html");
00268                 $this->__showButton('listDesktopItems',$this->lng->txt('back'));
00269 
00270 
00271                 sendInfo($this->lng->txt("role_select_desktop_item"));
00272                 
00273                 $exp = new ilRoleDesktopItemSelector($this->ctrl->getLinkTarget($this,'selectDesktopItem'),
00274                                                                                          new ilRoleDesktopItem($this->object->getId()));
00275                 $exp->setExpand($_GET["role_desk_item_link_expand"] ? $_GET["role_desk_item_link_expand"] : $tree->readRootId());
00276                 $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'selectDesktopItem'));
00277                 
00278                 $exp->setOutput(0);
00279                 
00280                 $this->tpl->setVariable("EXPLORER",$exp->getOutput());
00281 
00282                 return true;
00283         }
00284 
00285         function assignDesktopItemObject()
00286         {
00287                 global $rbacsystem;
00288 
00289                 if(!$rbacsystem->checkAccess('push_desktop_items',USER_FOLDER_ID))
00290                 {
00291                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00292                 }
00293         
00294                 if(!$rbacsystem->checkAccess('edit_permission', $this->rolf_ref_id))
00295                 {
00296                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00297                 }
00298                 if(!isset($_GET['item_id']))
00299                 {
00300                         sendInfo($this->lng->txt('role_no_item_selected'));
00301                         $this->selectDesktopItemObject();
00302 
00303                         return false;
00304                 }
00305                 include_once './classes/class.ilRoleDesktopItem.php';
00306 
00307                 $role_desk_item_obj =& new ilRoleDesktopItem($this->object->getId());
00308                 $role_desk_item_obj->add((int) $_GET['item_id'],ilObject::_lookupType((int) $_GET['item_id'],true));
00309 
00310                 sendInfo($this->lng->txt('role_assigned_desktop_item'));
00311                 $this->listDesktopItemsObject();
00312 
00313                 return true;
00314         }
00315 
00316                 
00317                 
00318 
00322         function createObject()
00323         {
00324                 global $rbacsystem;
00325                 
00326                 if (!$rbacsystem->checkAccess('create_role', $this->rolf_ref_id))
00327                 {
00328                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00329                 }
00330 
00331                 $this->getTemplateFile("edit","role");
00332 
00333                 if ($this->rolf_ref_id == ROLE_FOLDER_ID)
00334                 {
00335                         $this->tpl->setCurrentBlock("allow_register");
00336                         $allow_register = ($_SESSION["error_post_vars"]["Fobject"]["allow_register"]) ? "checked=\"checked\"" : "";
00337                         $this->tpl->setVariable("TXT_ALLOW_REGISTER",$this->lng->txt("allow_register"));
00338                         $this->tpl->setVariable("ALLOW_REGISTER",$allow_register);
00339                         $this->tpl->parseCurrentBlock();
00340 
00341                         $this->tpl->setCurrentBlock("assign_users");
00342                         $assign_users = $_SESSION["error_post_vars"]["Fobject"]["assign_users"] ? "checked=\"checked\"" : "";
00343                         $this->tpl->setVariable("TXT_ASSIGN_USERS",$this->lng->txt("allow_assign_users"));
00344                         $this->tpl->setVariable("ASSIGN_USERS",$assign_users);
00345                         $this->tpl->parseCurrentBlock();
00346                 }
00347 
00348                 // fill in saved values in case of error
00349                 $this->tpl->setVariable("TITLE",ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"]),true);
00350                 $this->tpl->setVariable("DESC",ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]));
00351 
00352                 $this->tpl->setVariable("TXT_TITLE",$this->lng->txt("title"));
00353                 $this->tpl->setVariable("TXT_DESC",$this->lng->txt("desc"));
00354                 $this->tpl->setVariable("FORMACTION", $this->getFormAction("save","adm_object.php?cmd=gateway&ref_id=".$this->rolf_ref_id."&new_type=".$this->type));
00355                 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->type."_new"));
00356                 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00357                 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($this->type."_add"));
00358                 $this->tpl->setVariable("CMD_SUBMIT", "save");
00359                 $this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
00360                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00361         }
00362 
00368         function saveObject()
00369         {
00370                 global $rbacsystem, $rbacadmin, $rbacreview;
00371 
00372                 // check for create role permission
00373                 if (!$rbacsystem->checkAccess("create_role",$this->rolf_ref_id))
00374                 {
00375                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_create_role"),$this->ilias->error_obj->MESSAGE);
00376                 }
00377 
00378                 // check required fields
00379                 if (empty($_POST["Fobject"]["title"]))
00380                 {
00381                         $this->ilias->raiseError($this->lng->txt("fill_out_all_required_fields"),$this->ilias->error_obj->MESSAGE);
00382                 }
00383 
00384                 // check if role title is unique
00385                 if ($rbacreview->roleExists($_POST["Fobject"]["title"]))
00386                 {
00387                         $this->ilias->raiseError($this->lng->txt("msg_role_exists1")." '".ilUtil::stripSlashes($_POST["Fobject"]["title"])."' ".
00388                                                                          $this->lng->txt("msg_role_exists2"),$this->ilias->error_obj->MESSAGE);
00389                 }
00390                 
00391                 // check if role title has il_ prefix
00392                 if (substr($_POST["Fobject"]["title"],0,3) == "il_")
00393                 {
00394                         $this->ilias->raiseError($this->lng->txt("msg_role_reserved_prefix"),$this->ilias->error_obj->MESSAGE);
00395                 }               
00396 
00397                 // save
00398                 include_once("class.ilObjRole.php");
00399                 $roleObj = new ilObjRole();
00400                 //$roleObj->assignData($_POST["Fobject"]);
00401                 $roleObj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00402                 $roleObj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00403                 $roleObj->setAllowRegister($_POST["Fobject"]["allow_register"]);
00404                 $roleObj->toggleAssignUsersStatus($_POST["Fobject"]["assign_users"]);
00405                 $roleObj->create();
00406                 $rbacadmin->assignRoleToFolder($roleObj->getId(), $this->rolf_ref_id,'y');
00407                 
00408                 sendInfo($this->lng->txt("role_added"),true);
00409 
00410                 ilUtil::redirect("adm_object.php?ref_id=".$this->rolf_ref_id);
00411         }
00412 
00418         function permObject()
00419         {
00420                 global $rbacadmin, $rbacreview, $rbacsystem,$objDefinition;
00421 
00422 
00423                 #$to_filter = $objDefinition->getSubobjectsToFilter();
00424 
00425                 if (!$rbacsystem->checkAccess('visible,write',$this->rolf_ref_id))
00426                 {
00427                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->MESSAGE);
00428                         exit();
00429                 }
00430 
00431                 // build array with all rbac object types
00432                 $q = "SELECT ta.typ_id,obj.title,ops.ops_id,ops.operation FROM rbac_ta AS ta ".
00433                          "LEFT JOIN object_data AS obj ON obj.obj_id=ta.typ_id ".
00434                          "LEFT JOIN rbac_operations AS ops ON ops.ops_id=ta.ops_id";
00435                 $r = $this->ilias->db->query($q);
00436 
00437                 while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00438                 {
00439                         // FILTER SUBOJECTS OF adm OBJECT
00440                         #if(in_array($row->title,$to_filter))
00441                         #{
00442                         #       continue;
00443                         #}
00444                         $rbac_objects[$row->typ_id] = array("obj_id"    => $row->typ_id,
00445                                                                                             "type"              => $row->title
00446                                                                                                 );
00447 
00448                         $rbac_operations[$row->typ_id][$row->ops_id] = array(
00449                                                                                                                                 "ops_id"        => $row->ops_id,
00450                                                                                                                                 "title"         => $row->operation,
00451                                                                                                                                 "name"          => $this->lng->txt($row->title."_".$row->operation)
00452                                                                                                                            );
00453                 }
00454                         
00455                 foreach ($rbac_objects as $key => $obj_data)
00456                 {
00457                         $rbac_objects[$key]["name"] = $this->lng->txt("obj_".$obj_data["type"]);
00458                         $rbac_objects[$key]["ops"] = $rbac_operations[$key];
00459                 }
00460 
00461 
00462                 // for local roles display only the permissions settings for allowed subobjects
00463                 if ($this->rolf_ref_id != ROLE_FOLDER_ID)
00464                 {
00465                         // first get object in question (parent of role folder object)
00466                         $parent_data = $this->tree->getParentNodeData($this->rolf_ref_id);
00467                         // get allowed subobject of object
00468                         $subobj_data = $this->objDefinition->getSubObjects($parent_data["type"]);
00469                         
00470                         // remove not allowed object types from array but keep the type definition of object itself
00471                         foreach ($rbac_objects as $key => $obj_data)
00472                         {
00473                                 if (!$subobj_data[$obj_data["type"]] and $parent_data["type"] != $obj_data["type"])
00474                                 {
00475                                         unset($rbac_objects[$key]);
00476                                 }
00477                         }
00478                 } // end if local roles
00479                 
00480                 // now sort computed result
00481                 sort($rbac_objects);
00482                         
00483                 foreach ($rbac_objects as $key => $obj_data)
00484                 {
00485                         sort($rbac_objects[$key]["ops"]);
00486                 }
00487                 
00488                 // sort by (translated) name of object type
00489                 $rbac_objects = ilUtil::sortArray($rbac_objects,"name","asc");
00490 
00491                 // BEGIN CHECK_PERM
00492                 $global_roles_all = $rbacreview->getGlobalRoles();
00493                 $global_roles_user = array_intersect($_SESSION["RoleId"],$global_roles_all);
00494                 
00495                 // is this role a global role?
00496                 if (in_array($this->object->getId(),$global_roles_all))
00497                 {
00498                         $global_role = true;
00499                 }
00500                 else
00501                 {
00502                         $global_role = false;
00503                 }
00504 
00505                 foreach ($rbac_objects as $key => $obj_data)
00506                 {
00507                         $allowed_ops_on_type = array();
00508 
00509                         foreach ($global_roles_user as $role_id)
00510                         {
00511                                 $allowed_ops_on_type = array_merge($allowed_ops_on_type,$rbacreview->getOperationsOfRole($role_id,$obj_data["type"]));
00512                         }
00513                                 
00514                         $allowed_ops_on_type = array_unique($allowed_ops_on_type);
00515                                 
00516                         $arr_selected = $rbacreview->getOperationsOfRole($this->object->getId(), $obj_data["type"], $this->rolf_ref_id);
00517                         $arr_checked = array_intersect($arr_selected,array_keys($rbac_operations[$obj_data["obj_id"]]));
00518 
00519                         foreach ($rbac_operations[$obj_data["obj_id"]] as $operation)
00520                         {
00521                                 // check all boxes for system role
00522                                 if ($this->object->getId() == SYSTEM_ROLE_ID)
00523                                 {
00524                                         $checked = true;
00525                                         $disabled = true;
00526                                 }
00527                                 else
00528                                 {
00529                                         $checked = in_array($operation["ops_id"],$arr_checked);
00530 
00531                                         // for global roles only allow to set those permission the current user is granted himself except SYSTEM_ROLE_ID !!
00532                                         if (!in_array(SYSTEM_ROLE_ID,$_SESSION["RoleId"]) and $global_role == true and 
00533                                                 !in_array($operation["ops_id"],$allowed_ops_on_type))
00534                                         {
00535                                                 $disabled = true;
00536                                         }
00537                                         else
00538                                         {
00539                                                 $disabled = false;
00540                                         }
00541                                 }
00542 
00543                                 // Es wird eine 2-dim Post Variable �bergeben: perm[rol_id][ops_id]
00544                                 $box = ilUtil::formCheckBox($checked,"template_perm[".$obj_data["type"]."][]",$operation["ops_id"],$disabled);
00545                                 $output["perm"][$obj_data["obj_id"]][$operation["ops_id"]] = $box;
00546                         }
00547                 }
00548                 // END CHECK_PERM
00549 
00550                 $output["col_anz"] = count($rbac_objects);
00551                 $output["txt_save"] = $this->lng->txt("save");
00552                 $output["check_bottom"] = ilUtil::formCheckBox(0,"recursive",1);
00553                 $output["message_table"] = $this->lng->txt("change_existing_objects");
00554 
00555 
00556 /************************************/
00557 /*              adopt permissions form          */
00558 /************************************/
00559 
00560                 $output["message_middle"] = $this->lng->txt("adopt_perm_from_template");
00561 
00562                 // send message for system role
00563                 if ($this->object->getId() == SYSTEM_ROLE_ID)
00564                 {
00565                         $output["adopt"] = array();
00566                         $output["sysrole_msg"] = $this->lng->txt("msg_sysrole_not_editable");
00567                 }
00568                 else
00569                 {
00570                         // BEGIN ADOPT_PERMISSIONS
00571                         $parent_role_ids = $rbacreview->getParentRoleIds($this->rolf_ref_id,true);
00572 
00573                         // sort output for correct color changing
00574                         ksort($parent_role_ids);
00575 
00576                         foreach ($parent_role_ids as $key => $par)
00577                         {
00578                                 if ($par["obj_id"] != SYSTEM_ROLE_ID)
00579                                 {
00580                                         $radio = ilUtil::formRadioButton(0,"adopt",$par["obj_id"]);
00581                                         $output["adopt"][$key]["css_row_adopt"] = ilUtil::switchColor($key, "tblrow1", "tblrow2");
00582                                         $output["adopt"][$key]["check_adopt"] = $radio;
00583                                         $output["adopt"][$key]["role_id"] = $par["obj_id"];
00584                                         $output["adopt"][$key]["type"] = ($par["type"] == 'role' ? 'Role' : 'Template');
00585                                         $output["adopt"][$key]["role_name"] = $par["title"];
00586                                 }
00587                         }
00588 
00589                         #$output["formaction_adopt"] = "adm_object.php?cmd=adoptPermSave&ref_id=".$this->rolf_ref_id."&obj_id=".$this->object->getId();
00590                         $output["formaction_adopt"] = $this->ctrl->getFormAction($this,'adoptPermSave');
00591                         // END ADOPT_PERMISSIONS
00592                 }
00593 
00594                 #$output["formaction"] = "adm_object.php?cmd=permSave&ref_id=".$this->rolf_ref_id."&obj_id=".$this->object->getId();
00595                 $output["formaction"] = $this->ctrl->getFormAction($this,'permSave');
00596 
00597                 $this->data = $output;
00598 
00599 
00600 /************************************/
00601 /*                      generate output                 */
00602 /************************************/
00603 
00604 #               $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
00605 #               $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html");
00606                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.adm_perm_role.html");
00607 
00608                 foreach ($rbac_objects as $obj_data)
00609                 {
00610                         // BEGIN object_operations
00611                         $this->tpl->setCurrentBlock("object_operations");
00612 
00613                         $ops_ids = "";
00614 
00615                         foreach ($obj_data["ops"] as $operation)
00616                         {
00617                                 $ops_ids[] = $operation["ops_id"];
00618                                 
00619                                 $css_row = ilUtil::switchColor($key, "tblrow1", "tblrow2");
00620                                 $this->tpl->setVariable("CSS_ROW",$css_row);
00621                                 $this->tpl->setVariable("PERMISSION",$operation["name"]);
00622                                 if (substr($operation["title"], 0, 7) == "create_")
00623                                 {
00624                                         if ($this->objDefinition->getDevMode(substr($operation["title"], 7, strlen($operation["title"]) -7)))
00625                                         {
00626                                                 $this->tpl->setVariable("TXT_NOT_IMPL", "(".$this->lng->txt("not_implemented_yet").")");
00627                                         }
00628                                 }
00629                                 $this->tpl->setVariable("CHECK_PERMISSION",$this->data["perm"][$obj_data["obj_id"]][$operation["ops_id"]]);
00630                                 $this->tpl->setVariable("LABEL_ID","template_perm_".$obj_data["type"]."_".$operation["ops_id"]);
00631                                 $this->tpl->parseCurrentBlock();
00632                         } // END object_operations
00633 
00634                         // BEGIN object_type
00635                         $this->tpl->setCurrentBlock("object_type");
00636                         $this->tpl->setVariable("TXT_OBJ_TYPE",$obj_data["name"]);
00637                         if ($this->objDefinition->getDevMode($obj_data["type"]))
00638                         {
00639                                 $this->tpl->setVariable("TXT_NOT_IMPL", "(".$this->lng->txt("not_implemented_yet").")");
00640                         }
00641 
00642                         // js checkbox toggles
00643                         $this->tpl->setVariable("JS_VARNAME","template_perm_".$obj_data["type"]);
00644                         $this->tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($ops_ids));
00645                         $this->tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
00646                         $this->tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));                      
00647                         
00648                         $this->tpl->parseCurrentBlock();
00649                         // END object_type
00650                 }
00651 
00652                 // don't display adopt permissions form for system role
00653                 if ($this->object->getId() != SYSTEM_ROLE_ID)
00654                 {
00655                         // BEGIN ADOPT PERMISSIONS
00656                         foreach ($this->data["adopt"] as $key => $value)
00657                         {
00658                                 $this->tpl->setCurrentBlock("ADOPT_PERM_ROW");
00659                                 $this->tpl->setVariable("CSS_ROW_ADOPT",$value["css_row_adopt"]);
00660                                 $this->tpl->setVariable("CHECK_ADOPT",$value["check_adopt"]);
00661                                 $this->tpl->setVariable("LABEL_ID",$value["role_id"]);
00662                                 $this->tpl->setVariable("TYPE",$value["type"]);
00663                                 $this->tpl->setVariable("ROLE_NAME",$value["role_name"]);
00664                                 $this->tpl->parseCurrentBlock();
00665                         }
00666                         
00667                         $this->tpl->setCurrentBlock("ADOPT_PERM_FORM");
00668                         $this->tpl->setVariable("MESSAGE_MIDDLE",$this->data["message_middle"]);
00669                         $this->tpl->setVariable("FORMACTION_ADOPT",$this->data["formaction_adopt"]);
00670                         $this->tpl->parseCurrentBlock();
00671                         // END ADOPT PERMISSIONS
00672                 
00673                         $this->tpl->setCurrentBlock("tblfooter_recursive");
00674                         $this->tpl->setVariable("COL_ANZ",3);
00675                         $this->tpl->setVariable("CHECK_BOTTOM",$this->data["check_bottom"]);
00676                         $this->tpl->setVariable("MESSAGE_TABLE",$this->data["message_table"]);
00677                         $this->tpl->parseCurrentBlock();
00678 
00679                         $this->tpl->setCurrentBlock("tblfooter_standard");
00680                         $this->tpl->setVariable("COL_ANZ_PLUS",4);
00681                         $this->tpl->setVariable("TXT_SAVE",$this->data["txt_save"]);
00682                         $this->tpl->parseCurrentBlock();
00683                 }
00684                 else
00685                 {
00686                         // display form buttons not for system role
00687                         $this->tpl->setCurrentBlock("tblfooter_sysrole");
00688                         $this->tpl->setVariable("COL_ANZ_SYS",3);
00689                         $this->tpl->parseCurrentBlock();
00690 
00691                         // display sysrole_msg
00692                         $this->tpl->setCurrentBlock("sysrole_msg");
00693                         $this->tpl->setVariable("TXT_SYSROLE_MSG",$this->data["sysrole_msg"]);
00694                         $this->tpl->parseCurrentBlock();
00695                 }
00696                 
00697                 $this->tpl->setCurrentBlock("adm_content");
00698                 $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath("icon_".$this->object->getType()."_b.gif"));
00699                 $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->lng->txt($this->object->getType()));
00700                 $this->tpl->setVariable("TBL_HELP_IMG",ilUtil::getImagePath("icon_help.gif"));
00701                 $this->tpl->setVariable("TBL_HELP_LINK","tbl_help.php");
00702                 $this->tpl->setVariable("TBL_HELP_IMG_ALT",$this->lng->txt("help"));
00703                 $this->tpl->setVariable("TBL_TITLE",$this->object->getTitle());
00704                         
00705                 $this->tpl->setVariable("TXT_PERMISSION",$this->data["txt_permission"]);
00706                 $this->tpl->setVariable("FORMACTION",$this->data["formaction"]);
00707                 $this->tpl->parseCurrentBlock();
00708         }
00709 
00715         function permSaveObject()
00716         {
00717                 global $rbacsystem, $rbacadmin, $rbacreview,$objDefinition;
00718 
00719                 // SET TEMPLATE PERMISSIONS
00720                 if (!$rbacsystem->checkAccess('write', $this->rolf_ref_id))
00721                 {
00722                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->MESSAGE);
00723                 }
00724 
00725                 #$to_filter = $objDefinition->getSubobjectsToFilter();
00726 
00727                 // first safe permissions that were disabled in HTML form due to missing lack of permissions of user who changed it
00728                 // TODO: move this following if-code into an extra function. this part is also used in $this->permObject !!
00729                 if (!in_array(SYSTEM_ROLE_ID,$_SESSION["RoleId"]))
00730                 {
00731                         // build array with all rbac object types
00732                         $q = "SELECT ta.typ_id,obj.title,ops.ops_id,ops.operation FROM rbac_ta AS ta ".
00733                                  "LEFT JOIN object_data AS obj ON obj.obj_id=ta.typ_id ".
00734                                  "LEFT JOIN rbac_operations AS ops ON ops.ops_id=ta.ops_id";
00735                         $r = $this->ilias->db->query($q);
00736         
00737                         while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00738                         {
00739                                 // FILTER SUBOJECTS OF adm OBJECT
00740                                 #if(in_array($row->title,$to_filter))
00741                                 #{
00742                                 #       continue;
00743                                 #}
00744 
00745                                 $rbac_objects[$row->typ_id] = array("obj_id"    => $row->typ_id,
00746                                                                                                     "type"              => $row->title
00747                                                                                                         );
00748         
00749                                 $rbac_operations[$row->typ_id][$row->ops_id] = array(
00750                                                                                                                                         "ops_id"        => $row->ops_id,
00751                                                                                                                                         "title"         => $row->operation,
00752                                                                                                                                         "name"          => $this->lng->txt($row->title."_".$row->operation)
00753                                                                                                                                    );
00754                         }
00755                                 
00756                         foreach ($rbac_objects as $key => $obj_data)
00757                         {
00758                                 $rbac_objects[$key]["name"] = $this->lng->txt("obj_".$obj_data["type"]);
00759                                 $rbac_objects[$key]["ops"] = $rbac_operations[$key];
00760                         }
00761         
00762                         $global_roles_all = $rbacreview->getGlobalRoles();
00763                         $global_roles_user = array_intersect($_SESSION["RoleId"],$global_roles_all);
00764                         
00765                         foreach ($rbac_objects as $key => $obj_data)
00766                         {
00767                                 $allowed_ops_on_type = array();
00768         
00769                                 foreach ($global_roles_user as $role_id)
00770                                 {
00771                                         $allowed_ops_on_type = array_merge($allowed_ops_on_type,$rbacreview->getOperationsOfRole($role_id,$obj_data["type"]));
00772                                 }
00773                                         
00774                                 $allowed_ops_on_type = array_unique($allowed_ops_on_type);
00775                                         
00776                                 $arr_previous = $rbacreview->getOperationsOfRole($this->object->getId(), $obj_data["type"], $this->rolf_ref_id);
00777                                 $arr_missing = array_diff($arr_previous,$allowed_ops_on_type);
00778                                 
00779                                 $_POST["template_perm"][$obj_data["type"]] = array_merge($_POST["template_perm"][$obj_data["type"]],$arr_missing);
00780                                 
00781                                 // remove empty types
00782                                 if (empty($_POST["template_perm"][$obj_data["type"]]))
00783                                 {
00784                                         unset($_POST["template_perm"][$obj_data["type"]]);
00785                                 }
00786                         }
00787                 } // END TODO: move!!!
00788 
00789                 // delete all template entries
00790                 $rbacadmin->deleteRolePermission($this->object->getId(), $this->rolf_ref_id);
00791 
00792                 if (empty($_POST["template_perm"]))
00793                 {
00794                         $_POST["template_perm"] = array();
00795                 }
00796 
00797                 foreach ($_POST["template_perm"] as $key => $ops_array)
00798                 {
00799                         // sets new template permissions
00800                         $rbacadmin->setRolePermission($this->object->getId(), $key, $ops_array, $this->rolf_ref_id);
00801                 }
00802 
00803                 // update object data entry (to update last modification date)
00804                 $this->object->update();
00805 
00806                 // CHANGE ALL EXISTING OBJECT UNDER PARENT NODE OF ROLE FOLDER
00807                 // BUT DON'T CHANGE PERMISSIONS OF SUBTREE OBJECTS IF INHERITANCE WAS STOPPED
00808                 if ($_POST["recursive"])
00809                 {
00810                         // IF ROLE IS A GLOBAL ROLE START AT ROOT
00811                         if ($this->rolf_ref_id == ROLE_FOLDER_ID)
00812                         {
00813                                 $node_id = ROOT_FOLDER_ID;
00814                         }
00815                         else
00816                         {
00817                                 $node_id = $this->tree->getParentId($this->rolf_ref_id);
00818                         }
00819 
00820                         // GET ALL SUBNODES
00821                         $node_data = $this->tree->getNodeData($node_id);
00822                         $subtree_nodes = $this->tree->getSubTree($node_data);
00823 
00824                         // GET ALL OBJECTS THAT CONTAIN A ROLE FOLDER
00825                         $all_parent_obj_of_rolf = $rbacreview->getObjectsWithStopedInheritance($this->object->getId());
00826 
00827                         // DELETE ACTUAL ROLE FOLDER FROM ARRAY
00828                         if ($this->rolf_ref_id == ROLE_FOLDER_ID)
00829                         {
00830                                 $key = array_keys($all_parent_obj_of_rolf,SYSTEM_FOLDER_ID);
00831                         }
00832                         else
00833                         {
00834                                 $key = array_keys($all_parent_obj_of_rolf,$node_id);
00835                         }
00836 
00837                         unset($all_parent_obj_of_rolf[$key[0]]);
00838 
00839                         $check = false;
00840 
00841                         foreach ($subtree_nodes as $node)
00842                         {
00843                                 if (!$check)
00844                                 {
00845                                         if (in_array($node["child"],$all_parent_obj_of_rolf))
00846                                         {
00847                                                 $lft = $node["lft"];
00848                                                 $rgt = $node["rgt"];
00849                                                 $check = true;
00850                                                 continue;
00851                                         }
00852 
00853                                         $valid_nodes[] = $node;
00854                                 }
00855                                 else
00856                                 {
00857                                         if (($node["lft"] > $lft) && ($node["rgt"] < $rgt))
00858                                         {
00859                                                 continue;
00860                                         }
00861                                         else
00862                                         {
00863                                                 $check = false;
00864                                                 
00865                                                 if (in_array($node["child"],$all_parent_obj_of_rolf))
00866                                                 {
00867                                                         $lft = $node["lft"];
00868                                                         $rgt = $node["rgt"];
00869                                                         $check = true;
00870                                                         continue;
00871                                                 }
00872                                                 
00873                                                 $valid_nodes[] = $node;
00874                                         }
00875                                 }
00876                         }
00877 
00878                         // prepare arrays for permission settings below
00879                         foreach ($valid_nodes as $key => $node)
00880                         {
00881                                 #if(!in_array($node["type"],$to_filter))
00882                                 {
00883                                         $node_ids[] = $node["child"];
00884                                         $valid_nodes[$key]["perms"] = $_POST["template_perm"][$node["type"]];
00885                                 }
00886                         }
00887                         
00888                         // FIRST REVOKE PERMISSIONS FROM ALL VALID OBJECTS
00889                         $rbacadmin->revokePermissionList($node_ids,$this->object->getId());
00890 
00891                         // NOW SET ALL PERMISSIONS
00892                         foreach ($valid_nodes as $node)
00893                         {
00894                                 if (is_array($node["perms"]))
00895                                 {
00896                                         $rbacadmin->grantPermission($this->object->getId(),$node["perms"],$node["child"]);
00897                                 }
00898                         }
00899                 }// END IF RECURSIVE
00900                 
00901 
00902 
00903                 sendInfo($this->lng->txt("saved_successfully"),true);
00904                 if($this->ctrl->getTargetScript() == 'adm_object.php')
00905                 {
00906                         ilUtil::redirect("adm_object.php?ref_id=".$this->rolf_ref_id."&obj_id=".$this->object->getId()."&cmd=perm");
00907                 }
00908                 else
00909                 {
00910                         $this->permObject();
00911                 }
00912         }
00913 
00914 
00920         function adoptPermSaveObject()
00921         {
00922                 global $rbacadmin, $rbacsystem, $rbacreview;
00923 
00924                 if (!$rbacsystem->checkAccess('write',$this->rolf_ref_id))
00925                 {
00926                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->MESSAGE);
00927                 }
00928                 elseif ($this->object->getId() == $_POST["adopt"])
00929                 {
00930                         sendInfo($this->lng->txt("msg_perm_adopted_from_itself"),true);
00931                 }
00932                 else
00933                 {
00934                         $rbacadmin->deleteRolePermission($this->object->getId(), $this->rolf_ref_id);
00935                         $parentRoles = $rbacreview->getParentRoleIds($this->rolf_ref_id,true);
00936                         $rbacadmin->copyRolePermission($_POST["adopt"],$parentRoles[$_POST["adopt"]]["parent"],
00937                                                                                    $this->rolf_ref_id,$this->object->getId());          
00938 
00939                         // update object data entry (to update last modification date)
00940                         $this->object->update();
00941 
00942                         // send info
00943                         $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($_POST["adopt"]);
00944                         sendInfo($this->lng->txt("msg_perm_adopted_from1")." '".$obj_data->getTitle()."'.<br/>".
00945                                          $this->lng->txt("msg_perm_adopted_from2"),true);
00946                 }
00947 
00948                 if($this->ctrl->getTargetScript() == 'adm_object.php')
00949                 {
00950                         ilUtil::redirect("adm_object.php?ref_id=".$this->rolf_ref_id."&obj_id=".$this->object->getId()."&cmd=perm");
00951                 }
00952                 else
00953                 {
00954                         $this->permObject();
00955                 }
00956         }
00957 
00963         function assignSaveObject()
00964         {
00965         $this->assignUserObject();
00966     }
00967 
00973         function assignUserObject()
00974         {
00975         global $rbacsystem, $rbacadmin, $rbacreview;
00976 
00977                 if (!$rbacsystem->checkAccess("edit_userassignment", $this->rolf_ref_id))
00978                 {
00979                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_assign_user_to_role"),$this->ilias->error_obj->MESSAGE);
00980                 }
00981 
00982                 if (!$rbacreview->isAssignable($this->object->getId(),$this->rolf_ref_id))
00983                 {
00984                         $this->ilias->raiseError($this->lng->txt("err_role_not_assignable"),$this->ilias->error_obj->MESSAGE);
00985                 }
00986 
00987                 if (!$rbacsystem->checkAccess('write',$this->rolf_ref_id))
00988                 {
00989                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->MESSAGE);
00990                 }
00991 
00992                 if (!isset($_POST["user"]))
00993                 {
00994                         sendInfo($this->lng->txt("no_checkbox"));
00995                         $this->searchObject();
00996 
00997                         return false;
00998                 }
00999                 
01000                 $selected_users = $_POST["user"];
01001                 $assigned_users_all = $rbacreview->assignedUsers($this->object->getId());
01002                                 
01003                 // users to assign
01004                 $assigned_users_new = array_diff($selected_users,array_intersect($selected_users,$assigned_users_all));
01005                 
01006                 // selected users all already assigned. stop
01007         if (count($assigned_users_new) == 0)
01008                 {
01009                         sendInfo($this->lng->txt("msg_selected_users_already_assigned"));
01010                         $this->searchObject();
01011                         
01012                         return false;
01013                 }
01014 
01015 //      var_dump("<pre>",$assigned_users_all,$selected_users,$assigned_users_new,$online_users_all,$online_affected_users,"</pre>");exit;
01016 
01017                 // assign new users
01018         foreach ($assigned_users_new as $user)
01019                 {
01020                         $rbacadmin->assignUser($this->object->getId(),$user,false);
01021         }
01022         
01023         // update session for newly assigned users online
01024         $this->object->_updateSessionRoles($assigned_users_new);
01025 
01026         // update object data entry (to update last modification date)
01027                 $this->object->update();
01028 
01029                 sendInfo($this->lng->txt("msg_userassignment_changed"),true);
01030 
01031                 if($this->ctrl->getTargetScript() == 'adm_object.php')
01032                 {
01033                         ilUtil::redirect("adm_object.php?ref_id=".$this->rolf_ref_id."&obj_id=".
01034                                                          $this->object->getId()."&cmd=userassignment&sort_by=".$_GET["sort_by"]."&sort_order=".
01035                                                          $_GET["sort_order"]."&offset=".$_GET["offset"]);
01036                 }
01037                 else
01038                 {
01039                         $this->userassignmentObject();
01040                         return true;
01041                 }
01042         }
01043         
01049         function deassignUserObject()
01050         {
01051         global $rbacsystem, $rbacadmin, $rbacreview;
01052 
01053                 if (!$rbacsystem->checkAccess("edit_userassignment", $this->rolf_ref_id))
01054                 {
01055                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_assign_user_to_role"),$this->ilias->error_obj->MESSAGE);
01056                 }
01057 
01058                 if (!$rbacsystem->checkAccess('write',$this->rolf_ref_id))
01059                 {
01060                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->MESSAGE);
01061                 }
01062                 
01063         $selected_users = ($_POST["user_id"]) ? $_POST["user_id"] : array($_GET["user_id"]);
01064 
01065                 if ($selected_users[0]=== NULL)
01066                 {
01067                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
01068                 }
01069 
01070                 // prevent unassignment of system user from system role
01071                 if ($this->object->getId() == SYSTEM_ROLE_ID)
01072                 {
01073             if ($admin = array_search(SYSTEM_USER_ID,$selected_users) !== false)
01074                             unset($selected_users[$admin]);
01075                 }
01076 //var_dump("<pre>",SYSTEM_USER_ID,$admin,$_POST,$_GET,$selected_users,"</pre>");exit;
01077 
01078                 // check for each user if the current role is his last global role before deassigning him
01079                 $last_role = array();
01080                 $global_roles = $rbacreview->getGlobalRoles();
01081                 
01082                 foreach ($selected_users as $user)
01083                 {
01084                         $assigned_roles = $rbacreview->assignedRoles($user);
01085                         $assigned_global_roles = array_intersect($assigned_roles,$global_roles);
01086 
01087                         if (count($assigned_roles) == 1 or (count($assigned_global_roles) == 1 and in_array($this->object->getId(),$assigned_global_roles)))
01088                         {
01089                                 $userObj = $this->ilias->obj_factory->getInstanceByObjId($user);
01090                                 $last_role[$user] = $userObj->getFullName();
01091                                 unset($userObj);
01092                         }
01093                 }
01094 
01095                 // raise error if last role was taken from a user...
01096                 if (count($last_role) > 0)
01097                 {
01098                         $user_list = implode(", ",$last_role);
01099                         $this->ilias->raiseError($this->lng->txt("msg_is_last_role").": ".$user_list."<br/>".$this->lng->txt("msg_min_one_role")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
01100                 }
01101                 
01102                 // ... else perform deassignment
01103                 foreach ($selected_users as $user)
01104         {
01105                         $rbacadmin->deassignUser($this->object->getId(),$user);
01106                 }
01107 
01108         // update session for newly assigned users online
01109         $this->object->_updateSessionRoles($selected_users);
01110 
01111         // update object data entry (to update last modification date)
01112                 $this->object->update();
01113 
01114                 sendInfo($this->lng->txt("msg_userassignment_changed"),true);
01115 
01116                 if($this->ctrl->getTargetScript() == 'adm_object.php')
01117                 {
01118                         ilUtil::redirect("adm_object.php?ref_id=".$this->rolf_ref_id."&obj_id=".
01119                                                          $this->object->getId()."&cmd=userassignment&sort_by=".$_GET["sort_by"]."&sort_order=".
01120                                                          $_GET["sort_order"]."&offset=".$_GET["offset"]);
01121                 }
01122                 else
01123                 {
01124                         $this->userassignmentObject();
01125                         return true;
01126                 }
01127         }
01128         
01134         function updateObject()
01135         {
01136                 global $rbacsystem, $rbacreview;
01137 
01138                 // check write access
01139                 if (!$rbacsystem->checkAccess("write", $this->rolf_ref_id))
01140                 {
01141                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_role"),$this->ilias->error_obj->MESSAGE);
01142                 }
01143 
01144                 if (substr($this->object->getTitle(),0,3) != "il_")
01145                 {
01146                         // check required fields
01147                         if (empty($_POST["Fobject"]["title"]))
01148                         {
01149                                 $this->ilias->raiseError($this->lng->txt("fill_out_all_required_fields"),$this->ilias->error_obj->MESSAGE);
01150                         }
01151         
01152                         // check if role title has il_ prefix
01153                         if (substr($_POST["Fobject"]["title"],0,3) == "il_")
01154                         {
01155                                 $this->ilias->raiseError($this->lng->txt("msg_role_reserved_prefix"),$this->ilias->error_obj->MESSAGE);
01156                         }
01157         
01158                         // check if role title is unique
01159                         if ($rbacreview->roleExists($_POST["Fobject"]["title"],$this->object->getId()))
01160                         {
01161                                 $this->ilias->raiseError($this->lng->txt("msg_role_exists1")." '".ilUtil::stripSlashes($_POST["Fobject"]["title"])."' ".
01162                                                                                  $this->lng->txt("msg_role_exists2"),$this->ilias->error_obj->MESSAGE);
01163                         }
01164 
01165                         // update
01166                         $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
01167                 }
01168 
01169                 $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
01170                 
01171                 // ensure that at least one role is available in the new user register form
01172                 if ($_POST["Fobject"]["allow_register"] == "")
01173                 {
01174                         $roles_allowed = $this->object->_lookupRegisterAllowed();
01175                         if (count($roles_allowed) == 1 and $roles_allowed[0]['id'] == $this->object->getId())
01176                         {
01177                                 $this->ilias->raiseError($this->lng->txt("msg_last_role_for_registration"),$this->ilias->error_obj->MESSAGE);
01178                         }       
01179                 }
01180 
01181                 $this->object->setAllowRegister($_POST["Fobject"]["allow_register"]);
01182                 $this->object->toggleAssignUsersStatus($_POST["Fobject"]["assign_users"]);
01183                 $this->object->update();
01184                 
01185                 sendInfo($this->lng->txt("saved_successfully"),true);
01186 
01187                 if($this->ctrl->getTargetScript() == 'adm_object.php')
01188                 {
01189                         ilUtil::redirect("adm_object.php?ref_id=".$this->rolf_ref_id);
01190                 }
01191                 else
01192                 {
01193                         $this->editObject();
01194                 }
01195                 return true;
01196         }
01197         
01203         function editObject()
01204         {
01205                 global $rbacsystem, $rbacreview;
01206 
01207                 if (!$rbacsystem->checkAccess("write", $this->rolf_ref_id))
01208                 {
01209                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
01210                 }
01211 
01212                 $this->getTemplateFile("edit");
01213 
01214                 if ($_SESSION["error_post_vars"])
01215                 {
01216                         // fill in saved values in case of error
01217                         if (substr($this->object->getTitle(),0,3) != "il_")
01218                         {
01219                                 $this->tpl->setVariable("TITLE",ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"]),true);
01220                         }
01221                 
01222                         $this->tpl->setVariable("DESC",ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]));
01223                         $allow_register = ($_SESSION["error_post_vars"]["Fobject"]["allow_register"]) ? "checked=\"checked\"" : "";
01224                         $assign_users = ($_SESSION["error_post_vars"]["Fobject"]["assign_users"]) ? "checked=\"checked\"" : "";
01225                 }
01226                 else
01227                 {
01228                         if (substr($this->object->getTitle(),0,3) != "il_")
01229                         {
01230                                 $this->tpl->setVariable("TITLE",ilUtil::prepareFormOutput($this->object->getTitle()));
01231                         }
01232 
01233                         $this->tpl->setVariable("DESC",ilUtil::stripSlashes($this->object->getDescription()));
01234                         $allow_register = ($this->object->getAllowRegister()) ? "checked=\"checked\"" : "";
01235                         $assign_users = $this->object->getAssignUsersStatus() ? "checked=\"checked\"" : "";
01236 
01237                 }
01238 
01239                 $obj_str = "&obj_id=".$this->obj_id;
01240 
01241                 $this->tpl->setVariable("TXT_TITLE",$this->lng->txt("title"));
01242                 $this->tpl->setVariable("TXT_DESC",$this->lng->txt("desc"));
01243                 
01244                 // exclude allow register option for anonymous role, system role and all local roles
01245                 $global_roles = $rbacreview->getGlobalRoles();
01246 
01247                 #$this->tpl->setVariable("FORMACTION", $this->getFormAction("update","adm_object.php?cmd=gateway&ref_id=".
01248                 #                                                                                                                  $this->rolf_ref_id.$obj_str));
01249 
01250                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
01251                 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->object->getType()."_edit"));
01252                 $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
01253                 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
01254                 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
01255                 $this->tpl->setVariable("CMD_SUBMIT", "update");
01256                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
01257                 
01258                 if (substr($this->object->getTitle(),0,3) == "il_")
01259                 {
01260                         $this->tpl->setVariable("SHOW_TITLE",$this->object->getTitle());
01261                 }
01262 
01263                 if ($this->object->getId() != ANONYMOUS_ROLE_ID and 
01264                         $this->object->getId() != SYSTEM_ROLE_ID and 
01265                         in_array($this->object->getId(),$global_roles))
01266                 {
01267                         $this->tpl->setCurrentBlock("allow_register");
01268                         $this->tpl->setVariable("TXT_ALLOW_REGISTER",$this->lng->txt("allow_register"));
01269                         $this->tpl->setVariable("ALLOW_REGISTER",$allow_register);
01270                         $this->tpl->parseCurrentBlock();
01271 
01272                         $this->tpl->setCurrentBlock("assign_users");
01273                         $this->tpl->setVariable("TXT_ASSIGN_USERS",$this->lng->txt('allow_assign_users'));
01274                         $this->tpl->setVariable("ASSIGN_USERS",$assign_users);
01275                         $this->tpl->parseCurrentBlock();
01276                 }
01277         }
01278         
01282         function userassignmentObject()
01283         {
01284                 global $rbacreview, $rbacsystem;
01285                 
01286                 if (!$rbacsystem->checkAccess("edit_userassignment", $this->rolf_ref_id))
01287                 {
01288                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_assign_user_to_role"),$this->ilias->error_obj->MESSAGE);
01289                 }
01290 
01291                 $assigned_users = $rbacreview->assignedUsers($this->object->getId(),array("login","firstname","lastname","usr_id"));
01292 
01293                 //if current user is admin he is able to add new members to group
01294                 $val_contact = "<img src=\"".ilUtil::getImagePath("icon_pencil_b.gif")."\" alt=\"".
01295                         $this->lng->txt("role_user_send_mail")."\" title=\"".
01296                         $this->lng->txt("role_user_send_mail")."\" border=\"0\" vspace=\"0\"/>";
01297                 $val_change = "<img src=\"".ilUtil::getImagePath("icon_change_b.gif")."\" alt=\"".
01298                         $this->lng->txt("role_user_edit")."\" title=\"".$this->lng->txt("role_user_edit")."\" border=\"0\" vspace=\"0\"/>";
01299                 $val_leave = "<img src=\"".ilUtil::getImagePath("icon_group_out_b.gif")."\" alt=\"".
01300                         $this->lng->txt("role_user_deassign")."\" title=\"".$this->lng->txt("role_user_deassign")."\" border=\"0\" vspace=\"0\"/>";
01301 
01302                 $counter = 0;
01303 
01304                 foreach ($assigned_users as $user)
01305                 {
01306                         $link_contact = "mail_new.php?type=new&rcp_to=".$user["login"];
01307                         $link_change = "adm_object.php?ref_id=7&obj_id=".$user["usr_id"]."&cmd=edit";
01308                         $link_leave = $this->ctrl->getLinkTarget($this,"deassignUser")."&user_id=".$user["usr_id"];
01309 
01310             $member_functions = "";
01311 
01312             // exclude root/admin role and anon/anon
01313             if ($this->object->getId() != ANONYMOUS_ROLE_ID or $user["usr_id"] != ANONYMOUS_USER_ID)
01314                         {
01315                 //build function
01316                 $member_functions = "<a href=\"".$link_contact."\">".$val_contact."</a>";
01317                                 if($this->ctrl->getTargetScript() == 'adm_object.php')
01318                                 {
01319                                         $member_functions .= "<a href=\"".$link_change."\">".$val_change."</a>";
01320                                 }
01321 
01322                 if ($this->object->getId() != SYSTEM_ROLE_ID or $user["usr_id"] != SYSTEM_USER_ID)
01323                 {
01324                     $member_functions .="<a href=\"".$link_leave."\">".$val_leave."</a>";
01325                 }
01326             }
01327 
01328                         // no check box for root/admin role and anon/anon
01329                         if (($this->object->getId() == SYSTEM_ROLE_ID and $user["usr_id"] == SYSTEM_USER_ID)
01330                 or ($this->object->getId() == ANONYMOUS_ROLE_ID and $user["usr_id"] == ANONYMOUS_USER_ID))
01331                         {
01332                 $result_set[$counter][] = "";
01333             }
01334             else
01335             {
01336                 $result_set[$counter][] = ilUtil::formCheckBox(0,"user_id[]",$user["usr_id"]);
01337             }
01338             
01339             $user_ids[$counter] = $user["usr_id"];
01340 
01341             $result_set[$counter][] = $user["login"];
01342                         $result_set[$counter][] = $user["firstname"];
01343                         $result_set[$counter][] = $user["lastname"];
01344                         $result_set[$counter][] = $member_functions;
01345 
01346                         ++$counter;
01347 
01348                         unset($member_functions);
01349                 }
01350 
01351                 return $this->__showAssignedUsersTable($result_set,$user_ids);
01352     }
01353         
01354         function __showAssignedUsersTable($a_result_set,$a_user_ids = NULL)
01355         {
01356         global $rbacsystem;
01357 
01358                 $actions = array("deassignUser"  => $this->lng->txt("remove"));
01359 
01360         $tbl =& $this->__initTableGUI();
01361                 $tpl =& $tbl->getTemplateObject();
01362 
01363                 $tpl->setCurrentBlock("tbl_form_header");
01364                 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
01365                 $tpl->parseCurrentBlock();
01366 
01367                 $tpl->setCurrentBlock("tbl_action_row");
01368 
01369             $tpl->setCurrentBlock("plain_button");
01370                     $tpl->setVariable("PBTN_NAME","searchUserForm");
01371                     $tpl->setVariable("PBTN_VALUE",$this->lng->txt("role_add_user"));
01372                     $tpl->parseCurrentBlock();
01373                     $tpl->setCurrentBlock("plain_buttons");
01374                     $tpl->parseCurrentBlock();
01375 
01376                         $tpl->setVariable("COLUMN_COUNTS",5);
01377                         $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
01378 
01379             foreach ($actions as $name => $value)
01380                         {
01381                                 $tpl->setCurrentBlock("tbl_action_btn");
01382                                 $tpl->setVariable("BTN_NAME",$name);
01383                                 $tpl->setVariable("BTN_VALUE",$value);
01384                                 $tpl->parseCurrentBlock();
01385                         }
01386                         
01387                         if (!empty($a_user_ids))
01388                         {
01389                                 // set checkbox toggles
01390                                 $tpl->setCurrentBlock("tbl_action_toggle_checkboxes");
01391                                 $tpl->setVariable("JS_VARNAME","user_id");                      
01392                                 $tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($a_user_ids));
01393                                 $tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
01394                                 $tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
01395                                 $tpl->parseCurrentBlock();
01396                         }
01397 
01398             $tpl->setVariable("TPLPATH",$this->tpl->tplPath);
01399 
01400 
01401                 $this->ctrl->setParameter($this,"cmd","userassignment");
01402 
01403 
01404                 // title & header columns
01405                 $tbl->setTitle($this->lng->txt("assigned_users"),"icon_usr_b.gif",$this->lng->txt("users"));
01406 
01407                 //user must be administrator
01408                 $tbl->setHeaderNames(array("",$this->lng->txt("username"),$this->lng->txt("firstname"),
01409                                                                    $this->lng->txt("lastname"),$this->lng->txt("grp_options")));
01410                 $tbl->setHeaderVars(array("","login","firstname","lastname","functions"),$this->ctrl->getParameterArray($this,"",false));
01411                 $tbl->setColumnWidth(array("","30%","30%","30%","10%"));
01412                 
01413                 $this->__setTableGUIBasicData($tbl,$a_result_set,"userassignment");
01414                 $tbl->render();
01415                 $this->tpl->setVariable("ADM_CONTENT",$tbl->tpl->get());
01416 
01417                 return true;
01418         }
01419 
01420         function &__initTableGUI()
01421         {
01422                 include_once "class.ilTableGUI.php";
01423 
01424                 return new ilTableGUI(0,false);
01425         }
01426 
01427         function __setTableGUIBasicData(&$tbl,&$result_set,$from = "")
01428         {
01429         switch($from)
01430                 {
01431                         case "group":
01432                         $order = $_GET["sort_by"] ? $_GET["sort_by"] : "title";
01433                                 break;
01434 
01435                         case "role":
01436                         $order = $_GET["sort_by"] ? $_GET["sort_by"] : "title";
01437                                 break;
01438 
01439                         default:
01440                                 // init sort_by (unfortunatly sort_by is preset with 'title')
01441                         if ($_GET["sort_by"] == "title" or empty($_GET["sort_by"]))
01442                 {
01443                     $_GET["sort_by"] = "login";
01444                 }
01445                 $order = $_GET["sort_by"];
01446                                 break;
01447                 }
01448 
01449                 $tbl->setOrderColumn($order);
01450                 $tbl->setOrderDirection($_GET["sort_order"]);
01451                 $tbl->setOffset($_GET["offset"]);
01452                 $tbl->setLimit($_GET["limit"]);
01453                 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
01454                 $tbl->setData($result_set);
01455         }
01456 
01457         function searchUserFormObject()
01458         {
01459                 global $rbacsystem;
01460 
01461                 if (!$rbacsystem->checkAccess("edit_userassignment", $this->rolf_ref_id))
01462                 {
01463                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_assign_user_to_role"),$this->ilias->error_obj->MESSAGE);
01464                 }
01465 
01466                 $this->lng->loadLanguageModule('search');
01467 
01468                 $this->tpl->addBlockFile("ADM_CONTENT","adm_content","tpl.role_users_search.html");
01469 
01470                 $this->tpl->setVariable("F_ACTION",$this->ctrl->getFormAction($this));
01471                 $this->tpl->setVariable("SEARCH_ASSIGN_USR",$this->lng->txt("role_search_users"));
01472                 $this->tpl->setVariable("SEARCH_SEARCH_TERM",$this->lng->txt("search_search_term"));
01473                 $this->tpl->setVariable("SEARCH_VALUE",$_SESSION["role_search_str"] ? $_SESSION["role_search_str"] : "");
01474                 $this->tpl->setVariable("SEARCH_FOR",$this->lng->txt("exc_search_for"));
01475                 $this->tpl->setVariable("SEARCH_ROW_TXT_USER",$this->lng->txt("exc_users"));
01476                 $this->tpl->setVariable("SEARCH_ROW_TXT_ROLE",$this->lng->txt("exc_roles"));
01477                 $this->tpl->setVariable("SEARCH_ROW_TXT_GROUP",$this->lng->txt("exc_groups"));
01478                 $this->tpl->setVariable("BTN2_VALUE",$this->lng->txt("cancel"));
01479                 $this->tpl->setVariable("BTN1_VALUE",$this->lng->txt("search"));
01480 
01481         $usr = ($_POST["search_for"] == "usr" || $_POST["search_for"] == "") ? 1 : 0;
01482                 $grp = ($_POST["search_for"] == "grp") ? 1 : 0;
01483                 $role = ($_POST["search_for"] == "role") ? 1 : 0;
01484 
01485                 $this->tpl->setVariable("SEARCH_ROW_CHECK_USER",ilUtil::formRadioButton($usr,"search_for","usr"));
01486                 $this->tpl->setVariable("SEARCH_ROW_CHECK_ROLE",ilUtil::formRadioButton($role,"search_for","role"));
01487         $this->tpl->setVariable("SEARCH_ROW_CHECK_GROUP",ilUtil::formRadioButton($grp,"search_for","grp"));
01488 
01489                 $this->__unsetSessionVariables();
01490         }
01491 
01492         function __unsetSessionVariables()
01493         {
01494                 unset($_SESSION["role_delete_member_ids"]);
01495                 unset($_SESSION["role_delete_subscriber_ids"]);
01496                 unset($_SESSION["role_search_str"]);
01497                 unset($_SESSION["role_search_for"]);
01498                 unset($_SESSION["role_role"]);
01499                 unset($_SESSION["role_group"]);
01500                 unset($_SESSION["role_archives"]);
01501         }
01502 
01507         function cancelObject()
01508         {
01509                 if ($_GET["new_type"] != "role")
01510                 {
01511                         $return_location = "userassignment";
01512                 }
01513 
01514                 sendInfo($this->lng->txt("action_aborted"),true);
01515                 ilUtil::redirect($this->ctrl->getLinkTarget($this,$return_location));
01516         }
01517 
01518         function searchObject()
01519         {
01520                 global $rbacsystem, $tree;
01521 
01522                 if (!$rbacsystem->checkAccess("edit_userassignment", $this->rolf_ref_id))
01523                 {
01524                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_assign_user_to_role"),$this->ilias->error_obj->MESSAGE);
01525                 }
01526 
01527                 $_SESSION["role_search_str"] = $_POST["search_str"] = $_POST["search_str"] ? $_POST["search_str"] : $_SESSION["role_search_str"];
01528                 $_SESSION["role_search_for"] = $_POST["search_for"] = $_POST["search_for"] ? $_POST["search_for"] : $_SESSION["role_search_for"];
01529 
01530                 if(!isset($_POST["search_for"]) or !isset($_POST["search_str"]))
01531                 {
01532                         sendInfo($this->lng->txt("role_search_enter_search_string"));
01533                         $this->searchUserFormObject();
01534 
01535                         return false;
01536                 }
01537 
01538                 if(!count($result = $this->__search(ilUtil::stripSlashes($_POST["search_str"]),$_POST["search_for"])))
01539                 {
01540                         sendInfo($this->lng->txt("role_no_results_found"));
01541                         $this->searchUserFormObject();
01542 
01543                         return false;
01544                 }
01545 
01546                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.role_usr_selection.html");
01547                 $this->__showButton("searchUserForm",$this->lng->txt("role_new_search"));
01548 
01549                 $counter = 0;
01550                 $f_result = array();
01551 
01552                 switch($_POST["search_for"])
01553                 {
01554                 case "usr":
01555                                 foreach($result as $user)
01556                                 {
01557                                         if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user["id"],false))
01558                                         {
01559                                                 continue;
01560                                         }
01561                                         
01562                                         $user_ids[$counter] = $user["id"];
01563                                         
01564                                         $f_result[$counter][] = ilUtil::formCheckbox(0,"user[]",$user["id"]);
01565                                         $f_result[$counter][] = $tmp_obj->getLogin();
01566                                         $f_result[$counter][] = $tmp_obj->getFirstname();
01567                                         $f_result[$counter][] = $tmp_obj->getLastname();
01568 
01569                                         unset($tmp_obj);
01570                                         ++$counter;
01571                                 }
01572                                 $this->__showSearchUserTable($f_result,$user_ids);
01573 
01574                                 return true;
01575 
01576                         case "role":
01577                                 foreach($result as $role)
01578                                 {
01579                     // exclude anonymous role
01580                     if ($role["id"] == ANONYMOUS_ROLE_ID)
01581                     {
01582                         continue;
01583                     }
01584 
01585                     if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($role["id"],false))
01586                                         {
01587                                                 continue;
01588                                         }
01589 
01590                                     // exclude roles with no users assigned to
01591                     if ($tmp_obj->getCountMembers() == 0)
01592                     {
01593                         continue;
01594                     }
01595 
01596                                         $role_ids[$counter] = $role["id"];
01597 
01598                                         $f_result[$counter][] = ilUtil::formCheckbox(0,"role[]",$role["id"]);
01599                                         $f_result[$counter][] = array($tmp_obj->getTitle(),$tmp_obj->getDescription());
01600                                         $f_result[$counter][] = $tmp_obj->getCountMembers();
01601 
01602                                         unset($tmp_obj);
01603                                         ++$counter;
01604                                 }
01605 
01606                                 $this->__showSearchRoleTable($f_result,$role_ids);
01607 
01608                                 return true;
01609 
01610                         case "grp":
01611                                 foreach($result as $group)
01612                                 {
01613                                         if(!$tree->isInTree($group["id"]))
01614                                         {
01615                                                 continue;
01616                                         }
01617 
01618                                         if(!$tmp_obj = ilObjectFactory::getInstanceByRefId($group["id"],false))
01619                                         {
01620                                                 continue;
01621                                         }
01622 
01623                     // exclude myself :-)
01624                     if ($tmp_obj->getId() == $this->object->getId())
01625                     {
01626                         continue;
01627                     }
01628 
01629                                         $grp_ids[$counter] = $group["id"];
01630 
01631                                         $f_result[$counter][] = ilUtil::formCheckbox(0,"group[]",$group["id"]);
01632                                         $f_result[$counter][] = array($tmp_obj->getTitle(),$tmp_obj->getDescription());
01633                                         $f_result[$counter][] = $tmp_obj->getCountMembers();
01634 
01635                                         unset($tmp_obj);
01636                                         ++$counter;
01637                                 }
01638                                 $this->__showSearchGroupTable($f_result,$grp_ids);
01639 
01640                                 return true;
01641                 }
01642         }
01643 
01644         function __search($a_search_string,$a_search_for)
01645         {
01646                 include_once("class.ilSearch.php");
01647 
01648                 $this->lng->loadLanguageModule("content");
01649                 $search =& new ilSearch($_SESSION["AccountId"]);
01650                 $search->setPerformUpdate(false);
01651                 $search->setSearchString(ilUtil::stripSlashes($a_search_string));
01652                 $search->setCombination("and");
01653                 $search->setSearchFor(array(0 => $a_search_for));
01654                 $search->setSearchType('new');
01655 
01656                 if($search->validate($message))
01657                 {
01658                         $search->performSearch();
01659                 }
01660                 else
01661                 {
01662                         sendInfo($message,true);
01663                         $this->ctrl->redirect($this,"searchUserForm");
01664                 }
01665 
01666                 return $search->getResultByType($a_search_for);
01667         }
01668 
01669         function __showSearchUserTable($a_result_set,$a_user_ids = NULL,$a_cmd = "search")
01670         {
01671         $return_to  = "searchUserForm";
01672 
01673         if ($a_cmd == "listUsersRole" or $a_cmd == "listUsersGroup")
01674         {
01675             $return_to = "search";
01676         }
01677 
01678                 $tbl =& $this->__initTableGUI();
01679                 $tpl =& $tbl->getTemplateObject();
01680 
01681                 // SET FORMACTION
01682                 $tpl->setCurrentBlock("tbl_form_header");
01683                 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
01684                 $tpl->parseCurrentBlock();
01685 
01686                 $tpl->setCurrentBlock("tbl_action_btn");
01687                 $tpl->setVariable("BTN_NAME",$return_to);
01688                 $tpl->setVariable("BTN_VALUE",$this->lng->txt("back"));
01689                 $tpl->parseCurrentBlock();
01690 
01691                 $tpl->setCurrentBlock("tbl_action_btn");
01692                 $tpl->setVariable("BTN_NAME","assignUser");
01693                 $tpl->setVariable("BTN_VALUE",$this->lng->txt("add"));
01694                 $tpl->parseCurrentBlock();
01695 
01696                 if (!empty($a_user_ids))
01697                 {               
01698                         // set checkbox toggles
01699                         $tpl->setCurrentBlock("tbl_action_toggle_checkboxes");
01700                         $tpl->setVariable("JS_VARNAME","user");                 
01701                         $tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($a_user_ids));
01702                         $tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
01703                         $tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
01704                         $tpl->parseCurrentBlock();
01705                 }
01706 
01707                 $tpl->setCurrentBlock("tbl_action_row");
01708                 $tpl->setVariable("COLUMN_COUNTS",4);
01709                 $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
01710                 $tpl->parseCurrentBlock();
01711 
01712                 $tbl->setTitle($this->lng->txt("role_header_edit_users"),"icon_usr_b.gif",$this->lng->txt("role_header_edit_users"));
01713                 $tbl->setHeaderNames(array("",
01714                                                                    $this->lng->txt("username"),
01715                                                                    $this->lng->txt("firstname"),
01716                                                                    $this->lng->txt("lastname")));
01717                 $tbl->setHeaderVars(array("",
01718                                                                   "login",
01719                                                                   "firstname",
01720                                                                   "lastname"),
01721                                                         array("ref_id" => $this->rolf_ref_id,
01722                                   "obj_id" => $this->object->getId(),
01723                                                                   "cmd" => $a_cmd,
01724                                                                   "cmdClass" => "ilobjrolegui",
01725                                                                   "cmdNode" => $_GET["cmdNode"]));
01726 
01727                 $tbl->setColumnWidth(array("","33%","33%","33%"));
01728 
01729                 $this->__setTableGUIBasicData($tbl,$a_result_set);
01730                 $tbl->render();
01731 
01732                 $this->tpl->setVariable("SEARCH_RESULT_TABLE",$tbl->tpl->get());
01733 
01734                 return true;
01735         }
01736 
01737         function __showSearchRoleTable($a_result_set,$a_role_ids = NULL)
01738         {
01739                 $tbl =& $this->__initTableGUI();
01740                 $tpl =& $tbl->getTemplateObject();
01741 
01742                 $tpl->setCurrentBlock("tbl_form_header");
01743                 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
01744                 $tpl->parseCurrentBlock();
01745 
01746                 $tpl->setCurrentBlock("tbl_action_btn");
01747                 $tpl->setVariable("BTN_NAME","searchUserForm");
01748                 $tpl->setVariable("BTN_VALUE",$this->lng->txt("back"));
01749                 $tpl->parseCurrentBlock();
01750 
01751                 $tpl->setCurrentBlock("tbl_action_btn");
01752                 $tpl->setVariable("BTN_NAME","listUsersRole");
01753                 $tpl->setVariable("BTN_VALUE",$this->lng->txt("role_list_users"));
01754                 $tpl->parseCurrentBlock();
01755                 
01756                 if (!empty($a_role_ids))
01757                 {
01758                         // set checkbox toggles
01759                         $tpl->setCurrentBlock("tbl_action_toggle_checkboxes");
01760                         $tpl->setVariable("JS_VARNAME","role");                 
01761                         $tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($a_role_ids));
01762                         $tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
01763                         $tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
01764                         $tpl->parseCurrentBlock();
01765                 }
01766 
01767                 $tpl->setCurrentBlock("tbl_action_row");
01768                 $tpl->setVariable("COLUMN_COUNTS",4);
01769                 $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
01770                 $tpl->parseCurrentBlock();
01771 
01772                 $tbl->setTitle($this->lng->txt("role_header_edit_users"),"icon_usr_b.gif",$this->lng->txt("role_header_edit_users"));
01773                 $tbl->setHeaderNames(array("",
01774                                                                    $this->lng->txt("obj_role"),
01775                                                                    $this->lng->txt("role_count_users")));
01776                 $tbl->setHeaderVars(array("",
01777                                                                   "title",
01778                                                                   "nr_members"),
01779                                                         array("ref_id" => $this->rolf_ref_id,
01780                                   "obj_id" => $this->object->getId(),
01781                                                                   "cmd" => "search",
01782                                                                   "cmdClass" => "ilobjrolegui",
01783                                                                   "cmdNode" => $_GET["cmdNode"]));
01784 
01785                 $tbl->setColumnWidth(array("","80%","19%"));
01786 
01787 
01788                 $this->__setTableGUIBasicData($tbl,$a_result_set,"role");
01789                 $tbl->render();
01790 
01791                 $this->tpl->setVariable("SEARCH_RESULT_TABLE",$tbl->tpl->get());
01792 
01793                 return true;
01794         }
01795 
01796         function __showSearchGroupTable($a_result_set,$a_grp_ids = NULL)
01797         {
01798         $tbl =& $this->__initTableGUI();
01799                 $tpl =& $tbl->getTemplateObject();
01800 
01801                 $tpl->setCurrentBlock("tbl_form_header");
01802                 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
01803                 $tpl->parseCurrentBlock();
01804 
01805                 $tpl->setCurrentBlock("tbl_action_btn");
01806                 $tpl->setVariable("BTN_NAME","searchUserForm");
01807                 $tpl->setVariable("BTN_VALUE",$this->lng->txt("back"));
01808                 $tpl->parseCurrentBlock();
01809 
01810                 $tpl->setCurrentBlock("tbl_action_btn");
01811                 $tpl->setVariable("BTN_NAME","listUsersGroup");
01812                 $tpl->setVariable("BTN_VALUE",$this->lng->txt("grp_list_users"));
01813                 $tpl->parseCurrentBlock();
01814                 
01815                 if (!empty($a_grp_ids))
01816                 {
01817                         // set checkbox toggles
01818                         $tpl->setCurrentBlock("tbl_action_toggle_checkboxes");
01819                         $tpl->setVariable("JS_VARNAME","group");                        
01820                         $tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($a_grp_ids));
01821                         $tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
01822                         $tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
01823                         $tpl->parseCurrentBlock();
01824                 }
01825 
01826                 $tpl->setCurrentBlock("tbl_action_row");
01827                 $tpl->setVariable("COLUMN_COUNTS",4);
01828                 $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
01829                 $tpl->parseCurrentBlock();
01830 
01831                 $tbl->setTitle($this->lng->txt("grp_header_edit_members"),"icon_usr_b.gif",$this->lng->txt("grp_header_edit_members"));
01832                 $tbl->setHeaderNames(array("",
01833                                                                    $this->lng->txt("obj_grp"),
01834                                                                    $this->lng->txt("grp_count_members")));
01835                 $tbl->setHeaderVars(array("",
01836                                                                   "title",
01837                                                                   "nr_members"),
01838                                                         array("ref_id" => $this->rolf_ref_id,
01839                                   "obj_id" => $this->object->getId(),
01840                                                                   "cmd" => "search",
01841                                                                   "cmdClass" => "ilobjrolegui",
01842                                                                   "cmdNode" => $_GET["cmdNode"]));
01843 
01844                 $tbl->setColumnWidth(array("","80%","19%"));
01845 
01846 
01847                 $this->__setTableGUIBasicData($tbl,$a_result_set,"group");
01848                 $tbl->render();
01849 
01850                 $this->tpl->setVariable("SEARCH_RESULT_TABLE",$tbl->tpl->get());
01851 
01852                 return true;
01853         }
01854 
01855         function listUsersRoleObject()
01856         {
01857                 global $rbacsystem,$rbacreview;
01858 
01859                 $_SESSION["role_role"] = $_POST["role"] = $_POST["role"] ? $_POST["role"] : $_SESSION["role_role"];
01860 
01861                 if(!is_array($_POST["role"]))
01862                 {
01863                         sendInfo($this->lng->txt("role_no_roles_selected"));
01864                         $this->searchObject();
01865 
01866                         return false;
01867                 }
01868 
01869                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.role_usr_selection.html");
01870                 $this->__showButton("searchUserForm",$this->lng->txt("role_new_search"));
01871 
01872                 // GET ALL MEMBERS
01873                 $members = array();
01874                 foreach($_POST["role"] as $role_id)
01875                 {
01876                         $members = array_merge($rbacreview->assignedUsers($role_id),$members);
01877                 }
01878 
01879                 $members = array_unique($members);
01880 
01881                 // FORMAT USER DATA
01882                 $counter = 0;
01883                 $f_result = array();
01884                 foreach($members as $user)
01885                 {
01886                         if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user,false))
01887                         {
01888                                 continue;
01889                         }
01890                         
01891                         $user_ids[$counter] = $user;
01892                         
01893                         // TODO: exclude anonymous user
01894                         $f_result[$counter][] = ilUtil::formCheckbox(0,"user[]",$user);
01895                         $f_result[$counter][] = $tmp_obj->getLogin();
01896                         $f_result[$counter][] = $tmp_obj->getFirstname();
01897                         $f_result[$counter][] = $tmp_obj->getLastname();
01898 
01899                         unset($tmp_obj);
01900                         ++$counter;
01901                 }
01902                 $this->__showSearchUserTable($f_result,$user_ids,"listUsersRole");
01903 
01904                 return true;
01905         }
01906 
01907         function listUsersGroupObject()
01908         {
01909                 global $rbacsystem,$rbacreview,$tree;
01910 
01911                 $_SESSION["role_group"] = $_POST["group"] = $_POST["group"] ? $_POST["group"] : $_SESSION["role_group"];
01912 
01913                 if(!is_array($_POST["group"]))
01914                 {
01915                         sendInfo($this->lng->txt("role_no_groups_selected"));
01916                         $this->searchObject();
01917 
01918                         return false;
01919                 }
01920 
01921                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.role_usr_selection.html");
01922                 $this->__showButton("searchUserForm",$this->lng->txt("role_new_search"));
01923 
01924                 // GET ALL MEMBERS
01925                 $members = array();
01926                 foreach($_POST["group"] as $group_id)
01927                 {
01928                         if (!$tree->isInTree($group_id))
01929                         {
01930                                 continue;
01931                         }
01932                         if (!$tmp_obj = ilObjectFactory::getInstanceByRefId($group_id))
01933                         {
01934                                 continue;
01935                         }
01936 
01937                         $members = array_merge($tmp_obj->getGroupMemberIds(),$members);
01938 
01939                         unset($tmp_obj);
01940                 }
01941 
01942                 $members = array_unique($members);
01943 
01944                 // FORMAT USER DATA
01945                 $counter = 0;
01946                 $f_result = array();
01947                 foreach($members as $user)
01948                 {
01949                         if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user,false))
01950                         {
01951                                 continue;
01952                         }
01953                         
01954                         $user_ids[$counter] = $user;                    
01955 
01956                         $f_result[$counter][] = ilUtil::formCheckbox(0,"user[]",$user);
01957                         $f_result[$counter][] = $tmp_obj->getLogin();
01958                         $f_result[$counter][] = $tmp_obj->getFirstname();
01959                         $f_result[$counter][] = $tmp_obj->getLastname();
01960 
01961                         unset($tmp_obj);
01962                         ++$counter;
01963                 }
01964                 $this->__showSearchUserTable($f_result,$user_ids,"listUsersGroup");
01965 
01966                 return true;
01967         }
01968 
01969 
01970         function __formatPath($a_path_arr)
01971         {
01972                 $counter = 0;
01973                 foreach($a_path_arr as $data)
01974                 {
01975                         if($counter++)
01976                         {
01977                                 $path .= " -> ";
01978                         }
01979                         $path .= $data['title'];
01980                 }
01981                 if(strlen($path) > 50)
01982                 {
01983                         return '...'.substr($path,-50);
01984                 }
01985                 return $path;
01986         }
01987 
01988         function __prepareOutput()
01989         {
01990                 // output objects
01991                 $this->tpl->addBlockFile("CONTENT", "content", "tpl.role.html");
01992                 $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
01993 
01994                 // output locator
01995                 $this->__setLocator();
01996 
01997                 // output message
01998                 if ($this->message)
01999                 {
02000                         sendInfo($this->message);
02001                 }
02002 
02003                 // display infopanel if something happened
02004                 infoPanel();
02005 
02006                 // set header
02007                 $this->__setHeader();
02008         }
02009 
02010         function __setHeader()
02011         {
02012                 include_once './classes/class.ilTabsGUI.php';
02013 
02014                 $this->tpl->setVariable("HEADER",$this->lng->txt('role'));
02015                 $this->tpl->setVariable("H_DESCRIPTION",$this->object->getTitle());
02016 
02017                 $tabs_gui =& new ilTabsGUI();
02018                 $this->getTabs($tabs_gui);
02019 
02020                 // output tabs
02021                 $this->tpl->setVariable("TABS", $tabs_gui->getHTML());
02022         }
02023 
02024         function __setLocator()
02025         {
02026                 global $tree;
02027                 global $ilias_locator;
02028 
02029                 $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html");
02030 
02031                 $counter = 0;
02032                 foreach ($tree->getPathFull($this->rolf_ref_id) as $key => $row)
02033                 {
02034                         if($counter++)
02035                         {
02036                                 $this->tpl->touchBlock('locator_separator_prefix');
02037                         }
02038 
02039                         $this->tpl->setCurrentBlock("locator_item");
02040 
02041                         if($row["type"] == 'rolf')
02042                         {
02043                                 $this->tpl->setVariable("ITEM",$this->object->getTitle());
02044                                 $this->tpl->setVariable("LINK_ITEM",$this->ctrl->getLinkTarget($this));
02045                         }
02046                         elseif ($row["child"] != $tree->getRootId())
02047                         {
02048                                 $this->tpl->setVariable("ITEM", $row["title"]);
02049                                 $this->tpl->setVariable("LINK_ITEM","repository.php?ref_id=".$row["child"]);
02050                         }
02051                         else
02052                         {
02053                                 $this->tpl->setVariable("ITEM", $this->lng->txt("repository"));
02054                                 $this->tpl->setVariable("LINK_ITEM","repository.php?ref_id=".$row["child"]);
02055                         }
02056 
02057                         $this->tpl->parseCurrentBlock();
02058                 }
02059 
02060                 $this->tpl->setVariable("TXT_LOCATOR",$this->lng->txt("locator"));
02061                 $this->tpl->parseCurrentBlock();
02062         }
02063 
02064         function getTabs(&$tabs_gui)
02065         {
02066                 global $rbacsystem,$rbacreview;
02067 
02068                 
02069                 $base_role_folder = $rbacreview->getFoldersAssignedToRole($this->object->getId(),true);
02070                 $real_local_role = in_array($this->rolf_ref_id,$base_role_folder);
02071 
02072                 $this->ctrl->setParameter($this,"ref_id",$this->rolf_ref_id);
02073                 $this->ctrl->setParameter($this,"obj_id",$this->object->getId());
02074                 
02075                 if($rbacsystem->checkAccess('write',$this->rolf_ref_id) and $real_local_role)
02076                 {
02077                         $tabs_gui->addTarget("edit_properties",
02078                                                                  $this->ctrl->getLinkTarget($this, "edit"), "edit", get_class($this));
02079                 }
02080                 if($rbacsystem->checkAccess('write',$this->rolf_ref_id))
02081                 {
02082                         $tabs_gui->addTarget("default_perm_settings",
02083                                                                  $this->ctrl->getLinkTarget($this, "perm"), "perm", get_class($this));
02084                 }
02085                 if($rbacsystem->checkAccess('write',$this->rolf_ref_id) and $real_local_role)
02086                 {
02087                         $tabs_gui->addTarget("user_assignment",
02088                                                                  $this->ctrl->getLinkTarget($this, "userassignment"), "userassignment", get_class($this));
02089                 }
02090                 if($rbacsystem->checkAccess('write',$this->rolf_ref_id) and $real_local_role)
02091                 {
02092                         $tabs_gui->addTarget("desktop_items",
02093                                                                  $this->ctrl->getLinkTarget($this, "listDesktopItems"), "listDesktopItems", get_class($this));
02094                 }
02095 
02096         }
02097 
02098 
02099 
02100 } // END class.ilObjRoleGUI
02101 ?>

Generated on Fri Dec 13 2013 09:06:34 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1