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