00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once "class.ilObjectGUI.php";
00025
00038 class ilObjRoleFolderGUI extends ilObjectGUI
00039 {
00045 var $type;
00046
00051 function ilObjRoleFolderGUI($a_data,$a_id,$a_call_by_reference)
00052 {
00053 $this->type = "rolf";
00054 $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference, false);
00055 }
00056
00057 function &executeCommand()
00058 {
00059 $next_class = $this->ctrl->getNextClass($this);
00060 $cmd = $this->ctrl->getCmd();
00061 $this->prepareOutput();
00062
00063 switch($next_class)
00064 {
00065 case 'ilpermissiongui':
00066 include_once("./classes/class.ilPermissionGUI.php");
00067 $perm_gui =& new ilPermissionGUI($this);
00068 $ret =& $this->ctrl->forwardCommand($perm_gui);
00069 break;
00070
00071 default:
00072 if(!$cmd)
00073 {
00074 $cmd = "view";
00075 }
00076 $cmd .= "Object";
00077 $this->$cmd();
00078
00079 break;
00080 }
00081 return true;
00082 }
00083
00089 function viewObject ()
00090 {
00091 global $rbacreview,$rbacsystem;
00092
00093 if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
00094 {
00095 $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00096 }
00097
00098 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.usr_role_assignment.html');
00099
00100 $assignable = false;
00101
00102 if ($this->object->getId() == ROLE_FOLDER_ID)
00103 {
00104 $assignable = true;
00105
00106 $_SESSION['filtered_roles'] = isset($_POST['filter']) ? $_POST['filter'] : $_SESSION['filtered_roles'];
00107
00108 if ($_SESSION['filtered_roles'] == 0)
00109 {
00110 $_SESSION['filtered_roles'] = 2;
00111 }
00112
00113 $this->tpl->setCurrentBlock("filter");
00114 $this->tpl->setVariable("FILTER_TXT_FILTER",$this->lng->txt('filter'));
00115 $this->tpl->setVariable("SELECT_FILTER",$this->__buildFilterSelect());
00116 $this->tpl->setVariable("FILTER_ACTION",$this->ctrl->getFormAction($this));
00117 $this->tpl->setVariable("FILTER_NAME",'view');
00118 $this->tpl->setVariable("FILTER_VALUE",$this->lng->txt('apply_filter'));
00119 $this->tpl->parseCurrentBlock();
00120
00121
00122
00123 $role_list = $rbacreview->getRolesByFilter($_SESSION["filtered_roles"],$this->object->getId());
00124 }
00125 else
00126 {
00127 $role_list = $rbacreview->getRoleListByObject($_GET["ref_id"],true);
00128 }
00129
00130 $counter = 0;
00131
00132 include_once ('class.ilObjRole.php');
00133
00134 foreach ($role_list as $role)
00135 {
00136
00137 if ($role["type"] == "rolt")
00138 {
00139 $path = $this->lng->txt("obj_rolt");
00140 $rolf = ROLE_FOLDER_ID;
00141 }
00142 else
00143 {
00144
00145 $rolf_list = $rbacreview->getFoldersAssignedToRole($role["obj_id"],$assignable);
00146
00147 if ($this->object->getId() != ROLE_FOLDER_ID)
00148 {
00149 $rolf = $this->object->getRefId();
00150 }
00151 else
00152 {
00153 $rolf = $rolf_list[0];
00154 }
00155
00156
00157 if ($rbacreview->isDeleted($rolf))
00158 {
00159 continue;
00160 }
00161
00162
00163 $path = "";
00164
00165 if ($this->tree->isInTree($rolf))
00166 {
00167 if ($rolf[0] == ROLE_FOLDER_ID)
00168 {
00169 $path = $this->lng->txt("global");
00170 }
00171 else
00172 {
00173 $tmpPath = $this->tree->getPathFull($rolf);
00174 $path = $tmpPath[count($tmpPath)-2]["title"];
00175 }
00176 }
00177 else
00178 {
00179 $path = "<b>Rolefolder ".$rolf." not found in tree! (Role ".$role["obj_id"].")</b>";
00180 }
00181 }
00182
00183 $disabled = false;
00184 $checkbox = ilUtil::formCheckBox(0,"role_id[]",$role["obj_id"],$disabled);
00185
00186
00187 if ($role["role_type"] != 'linked'
00188 && ($role["obj_id"] == SYSTEM_ROLE_ID
00189 or $role["obj_id"] == ANONYMOUS_ROLE_ID
00190 or substr($role["title"],0,3) == "il_"))
00191 {
00192 $disabled = true;
00193 $checkbox = "";
00194 }
00195
00196 if ($_SESSION["filtered_roles"] != 4)
00197 {
00198 $result_set[$counter][] = $checkbox;
00199 $role_ids[$counter] = $role["obj_id"];
00200 }
00201
00202 if (substr($role["title"],0,3) == "il_" and $role['type'] != "rolt")
00203 {
00204 if (!$assignable)
00205 {
00206 $rolf_arr = $rbacreview->getFoldersAssignedToRole($role["obj_id"],true);
00207 $rolf2 = $rolf_arr[0];
00208 }
00209 else
00210 {
00211 $rolf2 = $rolf;
00212 }
00213
00214 $parent_node = $this->tree->getParentNodeData($rolf2);
00215
00216 $role["description"] = $this->lng->txt("obj_".$parent_node["type"])." (#".$parent_node["obj_id"].")";
00217 }
00218
00219 if ($role["type"] == "rolt" and (substr($role["title"],0,3) == "il_"))
00220 {
00221 $role["description"] .= "<br/><i>".$this->lng->txt("predefined_template")." (".$role["title"].")</i>";
00222 }
00223
00224 $result_set[$counter][] = "<img src=\"".ilUtil::getImagePath("icon_".$role["type"].".gif")."\" alt=\"".$this->lng->txt("obj_".$role["type"])."\" title=\"".$this->lng->txt("obj_".$role["type"])."\" border=\"0\" vspace=\"0\"/>";
00225 if ($role["type"] == "role")
00226 {
00227 if (($this->object->getId() == ROLE_FOLDER_ID) &&
00228 ($role["role_type"] == "local"))
00229 {
00230 $this->ctrl->setParameterByClass("ilobjrolegui", "rolf_ref_id", $rolf);
00231 }
00232 $this->ctrl->setParameterByClass("ilobjrolegui", "obj_id", $role["obj_id"]);
00233 $link = $this->ctrl->getLinkTargetByClass("ilobjrolegui", "perm");
00234 $this->ctrl->setParameterByClass("ilobjrolegui", "rolf_ref_id", "");
00235 }
00236 else
00237 {
00238 $this->ctrl->setParameterByClass("ilobjroletemplategui", "obj_id", $role["obj_id"]);
00239 $link = $this->ctrl->getLinkTargetByClass("ilobjroletemplategui", "perm");
00240 }
00241 $result_set[$counter][] = "<a title=\"".ilObjRole::_getTranslation($role["title"])."\" href=\"$link\">".ilObjRole::_getTranslation($role["title"])."</a>";
00242 $result_set[$counter][] = $role["description"];
00243 $result_set[$counter][] = $path." (".$role["role_type"].")";;
00244
00245 ++$counter;
00246 }
00247
00248 return $this->__showRolesTable($result_set,$role_ids);
00249 }
00250
00251
00258 function confirmedDeleteObject()
00259 {
00260 global $rbacsystem,$rbacreview;
00261
00262
00263 if (!$rbacsystem->checkAccess('delete',$this->object->getRefId()))
00264 {
00265 $perform_delete = false;
00266 $this->ilias->raiseError($this->lng->txt("msg_no_perm_delete")." ".
00267 $not_deletable,$this->ilias->error_obj->MESSAGE);
00268 }
00269
00270 $return_loc = $this->tree->getParentId($this->object->getRefId());
00271
00272 $feedback["count"] = count($_SESSION["saved_post"]);
00273
00274
00275 foreach ($_SESSION["saved_post"] as $id)
00276 {
00277
00278 $obj =& $this->ilias->obj_factory->getInstanceByObjId($id);
00279
00280 if ($obj->getType() == "role")
00281 {
00282 $rolf_arr = $rbacreview->getFoldersAssignedToRole($obj->getId(),true);
00283 $obj->setParent($rolf_arr[0]);
00284
00285 $feedback["role"] = true;
00286 }
00287 else
00288 {
00289 $feedback["rolt"] = true;
00290 }
00291
00292 $obj->delete();
00293 unset($obj);
00294 }
00295
00296
00297 $return_loc = ilObject::_exists($this->object->getId()) ? $_GET["ref_id"] : $return_loc;
00298
00299
00300 if ($feedback["count"] > 1)
00301 {
00302 if ($feedback["role"] === true)
00303 {
00304 if ($feedback["rolt"] === true)
00305 {
00306 ilUtil::sendInfo($this->lng->txt("msg_deleted_roles_rolts"),true);
00307 }
00308 else
00309 {
00310 ilUtil::sendInfo($this->lng->txt("msg_deleted_roles"),true);
00311 }
00312 }
00313 else
00314 {
00315 ilUtil::sendInfo($this->lng->txt("msg_deleted_rolts"),true);
00316 }
00317 }
00318 else
00319 {
00320 if ($feedback["role"] === true)
00321 {
00322 ilUtil::sendInfo($this->lng->txt("msg_deleted_role"),true);
00323 }
00324 else
00325 {
00326 ilUtil::sendInfo($this->lng->txt("msg_deleted_rolt"),true);
00327 }
00328 }
00329
00330
00331
00332
00333
00334 #$this->redirectToRefId($return_loc, "view");
00335 $obj_type = ilObject::_lookupType($return_loc,true);
00336 $class_name = $this->objDefinition->getClassName($obj_type);
00337 $class = strtolower("ilObj".$class_name."GUI");
00338 $this->ctrl->setParameterByClass($class,'ref_id',$return_loc);
00339 $this->ctrl->redirectByClass($class,'view');
00340 }
00341
00347 function createObject()
00348 {
00349 $this->object->setTitle($this->lng->txt("obj_".$this->object->getType()."_local"));
00350 $this->object->setDescription("obj_".$this->object->getType()."_local_desc");
00351
00352 $this->saveObject();
00353 }
00354
00360 function deleteObject()
00361 {
00362 if (!isset($_POST["role_id"]))
00363 {
00364 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00365 }
00366
00367
00368 $_SESSION["saved_post"] = $_POST["role_id"];
00369
00370 unset($this->data);
00371 $this->data["cols"] = array("type", "title", "description", "last_change");
00372
00373 foreach($_POST["role_id"] as $id)
00374 {
00375 $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($id);
00376
00377 $this->data["data"]["$id"] = array(
00378 "type" => $obj_data->getType(),
00379 "title" => $obj_data->getTitle(),
00380 "desc" => $obj_data->getDescription(),
00381 "last_update" => $obj_data->getLastUpdateDate());
00382 }
00383
00384 $this->data["buttons"] = array( "cancelDelete" => $this->lng->txt("cancel"),
00385 "confirmedDelete" => $this->lng->txt("confirm"));
00386
00387 $this->getTemplateFile("confirm");
00388
00389 ilUtil::sendInfo($this->lng->txt("info_delete_sure"));
00390
00391 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00392
00393
00394 foreach ($this->data["cols"] as $key)
00395 {
00396 $this->tpl->setCurrentBlock("table_header");
00397 $this->tpl->setVariable("TEXT",$this->lng->txt($key));
00398 $this->tpl->parseCurrentBlock();
00399 }
00400
00401
00402
00403 $counter = 0;
00404
00405 foreach ($this->data["data"] as $key => $value)
00406 {
00407
00408 foreach ($value as $key => $cell_data)
00409 {
00410 $this->tpl->setCurrentBlock("table_cell");
00411
00412
00413 if ($key == "type")
00414 {
00415 $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($cell_data,$this->tpl->tplPath));
00416 }
00417 else
00418 {
00419 $this->tpl->setVariable("TEXT_CONTENT",$cell_data);
00420 }
00421
00422 $this->tpl->parseCurrentBlock();
00423 }
00424
00425 $this->tpl->setCurrentBlock("table_row");
00426 $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
00427 $this->tpl->parseCurrentBlock();
00428
00429 }
00430
00431
00432
00433 foreach ($this->data["buttons"] as $name => $value)
00434 {
00435 $this->tpl->setCurrentBlock("operation_btn");
00436 $this->tpl->setVariable("BTN_NAME",$name);
00437 $this->tpl->setVariable("BTN_VALUE",$value);
00438 $this->tpl->parseCurrentBlock();
00439 }
00440 }
00441
00447 function adoptPermSaveObject()
00448 {
00449 ilUtil::sendInfo($this->lng->txt("saved_successfully"),true);
00450
00451 $this->ctrl->redirect($this, "view");
00452 }
00453
00460 function showPossibleSubObjects($a_tpl)
00461 {
00462 global $rbacsystem;
00463
00464 $d = $this->objDefinition->getCreatableSubObjects($this->object->getType());
00465
00466 if ($this->object->getRefId() != ROLE_FOLDER_ID or !$rbacsystem->checkAccess('create_rolt',ROLE_FOLDER_ID))
00467 {
00468 unset($d["rolt"]);
00469 }
00470
00471 if (!$rbacsystem->checkAccess('create_role',$this->object->getRefId()))
00472 {
00473 unset($d["role"]);
00474 }
00475
00476 if (count($d) > 0)
00477 {
00478 foreach ($d as $row)
00479 {
00480 $count = 0;
00481 if ($row["max"] > 0)
00482 {
00483
00484 for ($i=0; $i<count($this->data["ctrl"]); $i++)
00485 {
00486 if ($this->data["ctrl"][$i]["type"] == $row["name"])
00487 {
00488 $count++;
00489 }
00490 }
00491 }
00492 if ($row["max"] == "" || $count < $row["max"])
00493 {
00494 $subobj[] = $row["name"];
00495 }
00496 }
00497 }
00498
00499 if (is_array($subobj))
00500 {
00501
00502 $opts = ilUtil::formSelect(12,"new_type",$subobj);
00503 $a_tpl->setCurrentBlock("add_object");
00504 $a_tpl->setVariable("SELECT_OBJTYPE", $opts);
00505 $a_tpl->setVariable("BTN_NAME", "create");
00506 $a_tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
00507 $a_tpl->parseCurrentBlock();
00508 }
00509
00510 return $a_tpl;
00511 }
00512
00517 function saveObject()
00518 {
00519 global $rbacadmin;
00520
00521
00522 $_GET["new_type"] = $this->object->getType();
00523 $_POST["Fobject"]["title"] = $this->object->getTitle();
00524 $_POST["Fobject"]["desc"] = $this->object->getDescription();
00525
00526
00527 $newObj = parent::saveObject();
00528
00529
00530
00531
00532 ilUtil::sendInfo($this->lng->txt("rolf_added"),true);
00533
00534 $this->ctrl->redirect($this, "view");
00535 }
00536
00537 function __showRolesTable($a_result_set,$a_role_ids)
00538 {
00539 global $rbacsystem;
00540
00541 $actions = array("delete" => $this->lng->txt("delete"));
00542
00543 $tbl =& $this->__initTableGUI();
00544 $tpl =& $tbl->getTemplateObject();
00545
00546 $tpl->setCurrentBlock("tbl_form_header");
00547 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00548 $tpl->parseCurrentBlock();
00549
00550 $tpl = $this->showPossibleSubObjects($tpl);
00551
00552 $tpl->setCurrentBlock("tbl_action_row");
00553
00554 $tpl->setVariable("COLUMN_COUNTS",($_SESSION["filtered_roles"] == 4) ? 4 : 5);
00555
00556 if ($_SESSION["filtered_roles"] != 4)
00557 {
00558 $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00559
00560 foreach ($actions as $name => $value)
00561 {
00562 $tpl->setCurrentBlock("tbl_action_btn");
00563 $tpl->setVariable("BTN_NAME",$name);
00564 $tpl->setVariable("BTN_VALUE",$value);
00565 $tpl->parseCurrentBlock();
00566 }
00567
00568 if (!empty($a_role_ids))
00569 {
00570
00571
00572 $tpl->setCurrentBlock("tbl_action_toggle_checkboxes");
00573 $tpl->setVariable("JS_VARNAME","role_id");
00574 $tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($a_role_ids));
00575 $tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
00576 $tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
00577 $tpl->parseCurrentBlock();
00578 }
00579 }
00580
00581 $tpl->setVariable("TPLPATH",$this->tpl->tplPath);
00582
00583
00584 $this->ctrl->setParameter($this,"cmd","view");
00585
00586
00587 $tbl->setTitle($this->lng->txt("roles"),"icon_role.gif",$this->lng->txt("roles"));
00588
00589 if ($_SESSION["filtered_roles"] == 4)
00590 {
00591 $tbl->setHeaderNames(array($this->lng->txt("type"),$this->lng->txt("role"),
00592 $this->lng->txt("description"),$this->lng->txt("context")));
00593 $tbl->setHeaderVars(array("type","title","description","context"),$this->ctrl->getParameterArray($this,"",false));
00594 $tbl->setColumnWidth(array("","30%","40%","30%"));
00595 }
00596 else
00597 {
00598 $tbl->setHeaderNames(array("",$this->lng->txt("type"),
00599 $this->lng->txt("role"),
00600 $this->lng->txt("description"),
00601 $this->lng->txt("context")));
00602 $tbl->setHeaderVars(array("","type","title","description","context"),$this->ctrl->getParameterArray($this,"",false));
00603 $tbl->setColumnWidth(array("","","30%","40%","30%"));
00604 }
00605
00606 $this->__setTableGUIBasicData($tbl,$a_result_set,"view");
00607 $tbl->render();
00608 $this->tpl->setVariable("ROLES_TABLE",$tbl->tpl->get());
00609
00610 return true;
00611 }
00612
00613 function &__initTableGUI()
00614 {
00615 include_once "./Services/Table/classes/class.ilTableGUI.php";
00616
00617 return new ilTableGUI(0,false);
00618 }
00619
00620 function __setTableGUIBasicData(&$tbl,&$result_set,$from = "")
00621 {
00622 switch($from)
00623 {
00624 default:
00625 if (!$_GET["sort_by"] or $_GET["sort_by"] == "name")
00626 {
00627 $_GET["sort_by"] = "title";
00628 }
00629
00630 $order = $_GET["sort_by"];
00631 break;
00632 }
00633
00634
00635 $tbl->setOrderColumn($order);
00636 $tbl->setOrderDirection($_GET["sort_order"]);
00637 $tbl->setOffset($_GET["offset"]);
00638 $tbl->setLimit($_GET["limit"]);
00639 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
00640 $tbl->setData($result_set);
00641 }
00642
00643 function __unsetSessionVariables()
00644 {
00645
00646 }
00647
00648 function __buildFilterSelect()
00649 {
00650 $action[1] = $this->lng->txt('all_roles');
00651 $action[2] = $this->lng->txt('all_global_roles');
00652 $action[3] = $this->lng->txt('all_local_roles');
00653 $action[4] = $this->lng->txt('internal_local_roles_only');
00654 $action[5] = $this->lng->txt('non_internal_local_roles_only');
00655 $action[6] = $this->lng->txt('role_templates_only');
00656
00657 return ilUtil::formSelect($_SESSION['filtered_roles'],"filter",$action,false,true);
00658 }
00659
00660 function hitsperpageObject()
00661 {
00662 parent::hitsperpageObject();
00663 $this->viewObject();
00664 }
00665
00671 function getTabs(&$tabs_gui)
00672 {
00673
00674
00675
00676 global $rbacsystem, $tree;
00677
00678
00679 if ($this->object->getRefId() == ROLE_FOLDER_ID)
00680 {
00681 $access = $rbacsystem->checkAccess('visible,write',$this->object->getRefId());
00682 }
00683 else
00684 {
00685 $access = $rbacsystem->checkAccess('edit_permission',$tree->getParentId($this->object->getRefId()));
00686 }
00687
00688 if ($access)
00689 {
00690 $tabs_gui->addTarget("obj_rolf",
00691 $this->ctrl->getLinkTarget($this, "view"), array("view","delete",""), "", "");
00692 }
00693
00694 if ($this->object->getRefId() == ROLE_FOLDER_ID and $rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
00695 {
00696 $tabs_gui->addTarget("perm_settings",
00697 $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
00698 }
00699 }
00700 }
00701 ?>