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 sendInfo($this->lng->txt("msg_deleted_roles_rolts"),true);
00307 }
00308 else
00309 {
00310 sendInfo($this->lng->txt("msg_deleted_roles"),true);
00311 }
00312 }
00313 else
00314 {
00315 sendInfo($this->lng->txt("msg_deleted_rolts"),true);
00316 }
00317 }
00318 else
00319 {
00320 if ($feedback["role"] === true)
00321 {
00322 sendInfo($this->lng->txt("msg_deleted_role"),true);
00323 }
00324 else
00325 {
00326 sendInfo($this->lng->txt("msg_deleted_rolt"),true);
00327 }
00328 }
00329
00330
00331
00332 $this->redirectToRefId($return_loc, "view");
00333 }
00334
00340 function createObject()
00341 {
00342 $this->object->setTitle($this->lng->txt("obj_".$this->object->getType()."_local"));
00343 $this->object->setDescription("obj_".$this->object->getType()."_local_desc");
00344
00345 $this->saveObject();
00346 }
00347
00353 function deleteObject()
00354 {
00355 if (!isset($_POST["role_id"]))
00356 {
00357 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00358 }
00359
00360
00361 $_SESSION["saved_post"] = $_POST["role_id"];
00362
00363 unset($this->data);
00364 $this->data["cols"] = array("type", "title", "description", "last_change");
00365
00366 foreach($_POST["role_id"] as $id)
00367 {
00368 $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($id);
00369
00370 $this->data["data"]["$id"] = array(
00371 "type" => $obj_data->getType(),
00372 "title" => $obj_data->getTitle(),
00373 "desc" => $obj_data->getDescription(),
00374 "last_update" => $obj_data->getLastUpdateDate());
00375 }
00376
00377 $this->data["buttons"] = array( "cancelDelete" => $this->lng->txt("cancel"),
00378 "confirmedDelete" => $this->lng->txt("confirm"));
00379
00380 $this->getTemplateFile("confirm");
00381
00382 sendInfo($this->lng->txt("info_delete_sure"));
00383
00384 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00385
00386
00387 foreach ($this->data["cols"] as $key)
00388 {
00389 $this->tpl->setCurrentBlock("table_header");
00390 $this->tpl->setVariable("TEXT",$this->lng->txt($key));
00391 $this->tpl->parseCurrentBlock();
00392 }
00393
00394
00395
00396 $counter = 0;
00397
00398 foreach ($this->data["data"] as $key => $value)
00399 {
00400
00401 foreach ($value as $key => $cell_data)
00402 {
00403 $this->tpl->setCurrentBlock("table_cell");
00404
00405
00406 if ($key == "type")
00407 {
00408 $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($cell_data,$this->tpl->tplPath));
00409 }
00410 else
00411 {
00412 $this->tpl->setVariable("TEXT_CONTENT",$cell_data);
00413 }
00414
00415 $this->tpl->parseCurrentBlock();
00416 }
00417
00418 $this->tpl->setCurrentBlock("table_row");
00419 $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
00420 $this->tpl->parseCurrentBlock();
00421
00422 }
00423
00424
00425
00426 foreach ($this->data["buttons"] as $name => $value)
00427 {
00428 $this->tpl->setCurrentBlock("operation_btn");
00429 $this->tpl->setVariable("BTN_NAME",$name);
00430 $this->tpl->setVariable("BTN_VALUE",$value);
00431 $this->tpl->parseCurrentBlock();
00432 }
00433 }
00434
00440 function adoptPermSaveObject()
00441 {
00442 sendinfo($this->lng->txt("saved_successfully"),true);
00443
00444 $this->ctrl->redirect($this, "view");
00445 }
00446
00453 function showPossibleSubObjects($a_tpl)
00454 {
00455 global $rbacsystem;
00456
00457 $d = $this->objDefinition->getCreatableSubObjects($this->object->getType());
00458
00459 if ($this->object->getRefId() != ROLE_FOLDER_ID or !$rbacsystem->checkAccess('create_rolt',ROLE_FOLDER_ID))
00460 {
00461 unset($d["rolt"]);
00462 }
00463
00464 if (!$rbacsystem->checkAccess('create_role',$this->object->getRefId()))
00465 {
00466 unset($d["role"]);
00467 }
00468
00469 if (count($d) > 0)
00470 {
00471 foreach ($d as $row)
00472 {
00473 $count = 0;
00474 if ($row["max"] > 0)
00475 {
00476
00477 for ($i=0; $i<count($this->data["ctrl"]); $i++)
00478 {
00479 if ($this->data["ctrl"][$i]["type"] == $row["name"])
00480 {
00481 $count++;
00482 }
00483 }
00484 }
00485 if ($row["max"] == "" || $count < $row["max"])
00486 {
00487 $subobj[] = $row["name"];
00488 }
00489 }
00490 }
00491
00492 if (is_array($subobj))
00493 {
00494
00495 $opts = ilUtil::formSelect(12,"new_type",$subobj);
00496 $a_tpl->setCurrentBlock("add_object");
00497 $a_tpl->setVariable("SELECT_OBJTYPE", $opts);
00498 $a_tpl->setVariable("BTN_NAME", "create");
00499 $a_tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
00500 $a_tpl->parseCurrentBlock();
00501 }
00502
00503 return $a_tpl;
00504 }
00505
00510 function saveObject()
00511 {
00512 global $rbacadmin;
00513
00514
00515 $_GET["new_type"] = $this->object->getType();
00516 $_POST["Fobject"]["title"] = $this->object->getTitle();
00517 $_POST["Fobject"]["desc"] = $this->object->getDescription();
00518
00519
00520 $newObj = parent::saveObject();
00521
00522
00523
00524
00525 sendInfo($this->lng->txt("rolf_added"),true);
00526
00527 $this->ctrl->redirect($this, "view");
00528 }
00529
00530 function __showRolesTable($a_result_set,$a_role_ids)
00531 {
00532 global $rbacsystem;
00533
00534 $actions = array("delete" => $this->lng->txt("delete"));
00535
00536 $tbl =& $this->__initTableGUI();
00537 $tpl =& $tbl->getTemplateObject();
00538
00539 $tpl->setCurrentBlock("tbl_form_header");
00540 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00541 $tpl->parseCurrentBlock();
00542
00543 $tpl = $this->showPossibleSubObjects($tpl);
00544
00545 $tpl->setCurrentBlock("tbl_action_row");
00546
00547 $tpl->setVariable("COLUMN_COUNTS",($_SESSION["filtered_roles"] == 4) ? 4 : 5);
00548
00549 if ($_SESSION["filtered_roles"] != 4)
00550 {
00551 $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00552
00553 foreach ($actions as $name => $value)
00554 {
00555 $tpl->setCurrentBlock("tbl_action_btn");
00556 $tpl->setVariable("BTN_NAME",$name);
00557 $tpl->setVariable("BTN_VALUE",$value);
00558 $tpl->parseCurrentBlock();
00559 }
00560
00561 if (!empty($a_role_ids))
00562 {
00563
00564
00565 $tpl->setCurrentBlock("tbl_action_toggle_checkboxes");
00566 $tpl->setVariable("JS_VARNAME","role_id");
00567 $tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($a_role_ids));
00568 $tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
00569 $tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
00570 $tpl->parseCurrentBlock();
00571 }
00572 }
00573
00574 $tpl->setVariable("TPLPATH",$this->tpl->tplPath);
00575
00576
00577 $this->ctrl->setParameter($this,"cmd","view");
00578
00579
00580 $tbl->setTitle($this->lng->txt("roles"),"icon_role.gif",$this->lng->txt("roles"));
00581
00582 if ($_SESSION["filtered_roles"] == 4)
00583 {
00584 $tbl->setHeaderNames(array($this->lng->txt("type"),$this->lng->txt("role"),
00585 $this->lng->txt("description"),$this->lng->txt("context")));
00586 $tbl->setHeaderVars(array("type","title","description","context"),$this->ctrl->getParameterArray($this,"",false));
00587 $tbl->setColumnWidth(array("","30%","40%","30%"));
00588 }
00589 else
00590 {
00591 $tbl->setHeaderNames(array("",$this->lng->txt("type"),
00592 $this->lng->txt("role"),
00593 $this->lng->txt("description"),
00594 $this->lng->txt("context")));
00595 $tbl->setHeaderVars(array("","type","title","description","context"),$this->ctrl->getParameterArray($this,"",false));
00596 $tbl->setColumnWidth(array("","","30%","40%","30%"));
00597 }
00598
00599 $this->__setTableGUIBasicData($tbl,$a_result_set,"view");
00600 $tbl->render();
00601 $this->tpl->setVariable("ROLES_TABLE",$tbl->tpl->get());
00602
00603 return true;
00604 }
00605
00606 function &__initTableGUI()
00607 {
00608 include_once "class.ilTableGUI.php";
00609
00610 return new ilTableGUI(0,false);
00611 }
00612
00613 function __setTableGUIBasicData(&$tbl,&$result_set,$from = "")
00614 {
00615 switch($from)
00616 {
00617 default:
00618 if (!$_GET["sort_by"] or $_GET["sort_by"] == "name")
00619 {
00620 $_GET["sort_by"] = "title";
00621 }
00622
00623 $order = $_GET["sort_by"];
00624 break;
00625 }
00626
00627
00628 $tbl->setOrderColumn($order);
00629 $tbl->setOrderDirection($_GET["sort_order"]);
00630 $tbl->setOffset($_GET["offset"]);
00631 $tbl->setLimit($_GET["limit"]);
00632 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
00633 $tbl->setData($result_set);
00634 }
00635
00636 function __unsetSessionVariables()
00637 {
00638
00639 }
00640
00641 function __buildFilterSelect()
00642 {
00643 $action[1] = $this->lng->txt('all_roles');
00644 $action[2] = $this->lng->txt('all_global_roles');
00645 $action[3] = $this->lng->txt('all_local_roles');
00646 $action[4] = $this->lng->txt('internal_local_roles_only');
00647 $action[5] = $this->lng->txt('non_internal_local_roles_only');
00648 $action[6] = $this->lng->txt('role_templates_only');
00649
00650 return ilUtil::formSelect($_SESSION['filtered_roles'],"filter",$action,false,true);
00651 }
00652
00653 function hitsperpageObject()
00654 {
00655 parent::hitsperpageObject();
00656 $this->viewObject();
00657 }
00658
00664 function getTabs(&$tabs_gui)
00665 {
00666
00667
00668
00669 global $rbacsystem, $tree;
00670
00671
00672 if ($this->object->getRefId() == ROLE_FOLDER_ID)
00673 {
00674 $access = $rbacsystem->checkAccess('visible,write',$this->object->getRefId());
00675 }
00676 else
00677 {
00678 $access = $rbacsystem->checkAccess('edit_permission',$tree->getParentId($this->object->getRefId()));
00679 }
00680
00681 if ($access)
00682 {
00683 $tabs_gui->addTarget("obj_rolf",
00684 $this->ctrl->getLinkTarget($this, "view"), array("view","delete",""), "", "");
00685 }
00686
00687 if ($this->object->getRefId() == ROLE_FOLDER_ID and $rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
00688 {
00689 $tabs_gui->addTarget("perm_settings",
00690 $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
00691 }
00692 }
00693 }
00694 ?>