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
00035 require_once "class.ilObjectGUI.php";
00036
00037 class ilObjRoleFolderGUI extends ilObjectGUI
00038 {
00044 var $type;
00045
00050 function ilObjRoleFolderGUI($a_data,$a_id,$a_call_by_reference)
00051 {
00052 global $ilCtrl;
00053
00054 $this->ctrl =& $ilCtrl;
00055 $this->ctrl->saveParameter($this,array("ref_id","cmdClass"));
00056
00057 $this->type = "rolf";
00058 $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference);
00059 }
00060
00061 function &executeCommand()
00062 {
00063 global $rbacsystem;
00064
00065 $next_class = $this->ctrl->getNextClass($this);
00066 $cmd = $this->ctrl->getCmd();
00067
00068 switch($next_class)
00069 {
00070 default:
00071 if(!$cmd)
00072 {
00073 $cmd = "view";
00074 }
00075 $cmd .= "Object";
00076 $this->$cmd();
00077
00078 break;
00079 }
00080 return true;
00081 }
00082
00088 function viewObject ()
00089 {
00090 global $rbacreview,$rbacsystem;
00091
00092 if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
00093 {
00094 $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00095 }
00096
00097 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.usr_role_assignment.html');
00098
00099 $assignable = false;
00100
00101 if ($this->object->getId() == ROLE_FOLDER_ID)
00102 {
00103 $assignable = true;
00104
00105 $_SESSION['filtered_roles'] = isset($_POST['filter']) ? $_POST['filter'] : $_SESSION['filtered_roles'];
00106
00107 if ($_SESSION['filtered_roles'] == 0)
00108 {
00109 $_SESSION['filtered_roles'] = 1;
00110 }
00111
00112 $this->tpl->setCurrentBlock("filter");
00113 $this->tpl->setVariable("FILTER_TXT_FILTER",$this->lng->txt('filter'));
00114 $this->tpl->setVariable("SELECT_FILTER",$this->__buildFilterSelect());
00115 $this->tpl->setVariable("FILTER_ACTION",$this->ctrl->getFormAction($this));
00116 $this->tpl->setVariable("FILTER_NAME",'view');
00117 $this->tpl->setVariable("FILTER_VALUE",$this->lng->txt('apply_filter'));
00118 $this->tpl->parseCurrentBlock();
00119
00120
00121
00122 $role_list = $rbacreview->getRolesByFilter($_SESSION["filtered_roles"],$this->object->getId());
00123 }
00124 else
00125 {
00126 $role_list = $rbacreview->getRoleListByObject($_GET["ref_id"],true);
00127 }
00128
00129 $rbacreview->setRoleType($role_list);
00130
00131 $counter = 0;
00132
00133 foreach ($role_list as $role)
00134 {
00135
00136 if ($role["type"] == "rolt")
00137 {
00138 $path = $this->lng->txt("obj_rolt");
00139 $rolf = ROLE_FOLDER_ID;
00140 }
00141 else
00142 {
00143
00144 $rolf_list = $rbacreview->getFoldersAssignedToRole($role["obj_id"],$assignable);
00145
00146 if ($this->object->getId() != ROLE_FOLDER_ID)
00147 {
00148 $rolf = $this->object->getRefId();
00149 }
00150 else
00151 {
00152 $rolf = $rolf_list[0];
00153 }
00154
00155
00156 if ($rbacreview->isDeleted($rolf))
00157 {
00158 continue;
00159 }
00160
00161
00162 $path = "";
00163
00164 if ($this->tree->isInTree($rolf))
00165 {
00166 if ($rolf[0] == ROLE_FOLDER_ID)
00167 {
00168 $path = $this->lng->txt("global");
00169 }
00170 else
00171 {
00172 $tmpPath = $this->tree->getPathFull($rolf);
00173 $path = $tmpPath[count($tmpPath)-2]["title"];
00174 }
00175 }
00176 else
00177 {
00178 $path = "<b>Rolefolder ".$rolf." not found in tree! (Role ".$role["obj_id"].")</b>";
00179 }
00180 }
00181
00182 $disabled = false;
00183 $checkbox = ilUtil::formCheckBox(0,"role_id[]",$role["obj_id"],$disabled);
00184
00185
00186 if ($role["role_type"] != 'linked'
00187 && ($role["obj_id"] == SYSTEM_ROLE_ID
00188 or $role["obj_id"] == ANONYMOUS_ROLE_ID
00189 or substr($role["title"],0,3) == "il_"))
00190 {
00191 $disabled = true;
00192 $checkbox = "";
00193 }
00194
00195 if ($_SESSION["filtered_roles"] != 4)
00196 {
00197 $result_set[$counter][] = $checkbox;
00198 }
00199
00200 $result_set[$counter][] = "<img src=\"".ilUtil::getImagePath("icon_".$role["type"]."_b.gif")."\" alt=\"".$this->lng->txt("obj_".$role["type"])."\" title=\"".$this->lng->txt("obj_".$role["type"])."\" border=\"0\" vspace=\"0\"/>";
00201 $result_set[$counter][] = "<a href=\"adm_object.php?ref_id=".$rolf."&obj_id=".$role["obj_id"]."&cmd=perm\">".$role["title"]."</a>";
00202 $result_set[$counter][] = $role["description"];
00203 $result_set[$counter][] = $path." (".$role["role_type"].")";;
00204
00205 ++$counter;
00206 }
00207
00208 return $this->__showRolesTable($result_set);
00209 }
00210
00211
00218 function confirmedDeleteObject()
00219 {
00220 global $rbacsystem,$rbacreview;
00221
00222
00223 if (!$rbacsystem->checkAccess('delete',$this->object->getRefId()))
00224 {
00225 $perform_delete = false;
00226 $this->ilias->raiseError($this->lng->txt("msg_no_perm_delete")." ".
00227 $not_deletable,$this->ilias->error_obj->MESSAGE);
00228 }
00229
00230 $return_loc = $this->tree->getParentId($this->object->getRefId());
00231
00232 $feedback["count"] = count($_SESSION["saved_post"]);
00233
00234
00235 foreach ($_SESSION["saved_post"] as $id)
00236 {
00237
00238 $obj =& $this->ilias->obj_factory->getInstanceByObjId($id);
00239
00240 if ($obj->getType() == "role")
00241 {
00242 $obj->setParent($this->object->getRefId());
00243 $feedback["role"] = true;
00244 }
00245 else
00246 {
00247 $feedback["rolt"] = true;
00248 }
00249 $obj->delete();
00250 unset($obj);
00251 }
00252
00253
00254 $return_loc = ilObject::_exists($this->object->getId()) ? $_GET["ref_id"] : $return_loc;
00255
00256
00257 if ($feedback["count"] > 1)
00258 {
00259 if ($feedback["role"] === true)
00260 {
00261 if ($feedback["rolt"] === true)
00262 {
00263 sendInfo($this->lng->txt("msg_deleted_roles_rolts"),true);
00264 }
00265 else
00266 {
00267 sendInfo($this->lng->txt("msg_deleted_roles"),true);
00268 }
00269 }
00270 else
00271 {
00272 sendInfo($this->lng->txt("msg_deleted_rolts"),true);
00273 }
00274 }
00275 else
00276 {
00277 if ($feedback["role"] === true)
00278 {
00279 sendInfo($this->lng->txt("msg_deleted_role"),true);
00280 }
00281 else
00282 {
00283 sendInfo($this->lng->txt("msg_deleted_rolt"),true);
00284 }
00285 }
00286
00287 ilUtil::redirect("adm_object.php?ref_id=".$return_loc);
00288 }
00289
00295 function createObject()
00296 {
00297 $this->object->setTitle($this->lng->txt("obj_".$this->object->getType()."_local"));
00298 $this->object->setDescription("obj_".$this->object->getType()."_local_desc");
00299
00300 $this->saveObject();
00301 }
00302
00308 function deleteObject()
00309 {
00310 if(!isset($_POST["role_id"]))
00311 {
00312 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00313 }
00314
00315 $_SESSION["saved_post"] = $_POST["role_id"];
00316
00317 unset($this->data);
00318 $this->data["cols"] = array("type", "title", "description", "last_change");
00319
00320 foreach($_POST["role_id"] as $id)
00321 {
00322 $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($id);
00323
00324 $this->data["data"]["$id"] = array(
00325 "type" => $obj_data->getType(),
00326 "title" => $obj_data->getTitle(),
00327 "desc" => $obj_data->getDescription(),
00328 "last_update" => $obj_data->getLastUpdateDate());
00329 }
00330
00331 $this->data["buttons"] = array( "cancelDelete" => $this->lng->txt("cancel"),
00332 "confirmedDelete" => $this->lng->txt("confirm"));
00333
00334 $this->getTemplateFile("confirm");
00335
00336 sendInfo($this->lng->txt("info_delete_sure"));
00337
00338 $this->tpl->setVariable("FORMACTION", "adm_object.php?ref_id=".$_GET["ref_id"]."&cmd=gateway");
00339
00340
00341 foreach ($this->data["cols"] as $key)
00342 {
00343 $this->tpl->setCurrentBlock("table_header");
00344 $this->tpl->setVariable("TEXT",$this->lng->txt($key));
00345 $this->tpl->parseCurrentBlock();
00346 }
00347
00348
00349
00350 $counter = 0;
00351
00352 foreach ($this->data["data"] as $key => $value)
00353 {
00354
00355 foreach ($value as $key => $cell_data)
00356 {
00357 $this->tpl->setCurrentBlock("table_cell");
00358
00359
00360 if ($key == "type")
00361 {
00362 $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($cell_data,$this->tpl->tplPath));
00363 }
00364 else
00365 {
00366 $this->tpl->setVariable("TEXT_CONTENT",$cell_data);
00367 }
00368
00369 $this->tpl->parseCurrentBlock();
00370 }
00371
00372 $this->tpl->setCurrentBlock("table_row");
00373 $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
00374 $this->tpl->parseCurrentBlock();
00375
00376 }
00377
00378
00379
00380 foreach ($this->data["buttons"] as $name => $value)
00381 {
00382 $this->tpl->setCurrentBlock("operation_btn");
00383 $this->tpl->setVariable("BTN_NAME",$name);
00384 $this->tpl->setVariable("BTN_VALUE",$value);
00385 $this->tpl->parseCurrentBlock();
00386 }
00387 }
00388
00394 function adoptPermSaveObject()
00395 {
00396 sendinfo($this->lng->txt("saved_successfully"),true);
00397
00398 ilUtil::redirect("adm_object.php?ref_id=".$_GET["ref_id"]."&cmd=perm");
00399 }
00400
00407 function showPossibleSubObjects($a_tpl)
00408 {
00409 global $rbacsystem;
00410
00411 $d = $this->objDefinition->getCreatableSubObjects($this->object->getType());
00412
00413 if ($this->object->getRefId() != ROLE_FOLDER_ID or !$rbacsystem->checkAccess('create_rolt',ROLE_FOLDER_ID))
00414 {
00415 unset($d["rolt"]);
00416 }
00417
00418 if (!$rbacsystem->checkAccess('create_role',$this->object->getRefId()))
00419 {
00420 unset($d["role"]);
00421 }
00422
00423 if (count($d) > 0)
00424 {
00425 foreach ($d as $row)
00426 {
00427 $count = 0;
00428 if ($row["max"] > 0)
00429 {
00430
00431 for ($i=0; $i<count($this->data["ctrl"]); $i++)
00432 {
00433 if ($this->data["ctrl"][$i]["type"] == $row["name"])
00434 {
00435 $count++;
00436 }
00437 }
00438 }
00439 if ($row["max"] == "" || $count < $row["max"])
00440 {
00441 $subobj[] = $row["name"];
00442 }
00443 }
00444 }
00445
00446 if (is_array($subobj))
00447 {
00448
00449 $opts = ilUtil::formSelect(12,"new_type",$subobj);
00450 $a_tpl->setCurrentBlock("add_object");
00451 $a_tpl->setVariable("SELECT_OBJTYPE", $opts);
00452 $a_tpl->setVariable("BTN_NAME", "create");
00453 $a_tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
00454 $a_tpl->parseCurrentBlock();
00455 }
00456
00457 return $a_tpl;
00458 }
00459
00464 function saveObject()
00465 {
00466 global $rbacadmin;
00467
00468
00469 $_GET["new_type"] = $this->object->getType();
00470 $_POST["Fobject"]["title"] = $this->object->getTitle();
00471 $_POST["Fobject"]["desc"] = $this->object->getDescription();
00472
00473
00474 $newObj = parent::saveObject();
00475
00476
00477
00478
00479 sendInfo($this->lng->txt("rolf_added"),true);
00480
00481 ilUtil::redirect($this->getReturnLocation("save","adm_object.php?".$this->link_params));
00482 }
00483
00484 function __showRolesTable($a_result_set)
00485 {
00486 global $rbacsystem;
00487
00488 $actions = array("delete" => $this->lng->txt("delete"));
00489
00490 $tbl =& $this->__initTableGUI();
00491 $tpl =& $tbl->getTemplateObject();
00492
00493 $tpl->setCurrentBlock("tbl_form_header");
00494 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00495 $tpl->parseCurrentBlock();
00496
00497 $tpl = $this->showPossibleSubObjects($tpl);
00498
00499 $tpl->setCurrentBlock("tbl_action_row");
00500
00501 $tpl->setVariable("COLUMN_COUNTS",($_SESSION["filtered_roles"] == 4) ? 4 : 5);
00502
00503 if ($_SESSION["filtered_roles"] != 4)
00504 {
00505 $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00506
00507
00508 foreach ($actions as $name => $value)
00509 {
00510 $tpl->setCurrentBlock("tbl_action_btn");
00511 $tpl->setVariable("BTN_NAME",$name);
00512 $tpl->setVariable("BTN_VALUE",$value);
00513 $tpl->parseCurrentBlock();
00514 }
00515 }
00516
00517 $tpl->setVariable("TPLPATH",$this->tpl->tplPath);
00518
00519
00520 $this->ctrl->setParameter($this,"cmd","view");
00521
00522
00523 $tbl->setTitle($this->lng->txt("roles"),"icon_role_b.gif",$this->lng->txt("roles"));
00524
00525 if ($_SESSION["filtered_roles"] == 4)
00526 {
00527 $tbl->setHeaderNames(array($this->lng->txt("type"),$this->lng->txt("role"),
00528 $this->lng->txt("description"),$this->lng->txt("context")));
00529 $tbl->setHeaderVars(array("type","title","description","context"),$this->ctrl->getParameterArray($this,"",false));
00530 $tbl->setColumnWidth(array("","30%","40%","30%"));
00531 }
00532 else
00533 {
00534 $tbl->setHeaderNames(array("",$this->lng->txt("type"),
00535 $this->lng->txt("role"),
00536 $this->lng->txt("description"),
00537 $this->lng->txt("context")));
00538 $tbl->setHeaderVars(array("","type","title","description","context"),$this->ctrl->getParameterArray($this,"",false));
00539 $tbl->setColumnWidth(array("","","30%","40%","30%"));
00540 }
00541
00542 $this->__setTableGUIBasicData($tbl,$a_result_set,"view");
00543 $tbl->render();
00544 $this->tpl->setVariable("ROLES_TABLE",$tbl->tpl->get());
00545
00546 return true;
00547 }
00548
00549 function &__initTableGUI()
00550 {
00551 include_once "class.ilTableGUI.php";
00552
00553 return new ilTableGUI(0,false);
00554 }
00555
00556 function __setTableGUIBasicData(&$tbl,&$result_set,$from = "")
00557 {
00558 switch($from)
00559 {
00560 default:
00561 if (!$_GET["sort_by"] or $_GET["sort_by"] == "name")
00562 {
00563 $_GET["sort_by"] = "title";
00564 }
00565
00566 $order = $_GET["sort_by"];
00567 break;
00568 }
00569
00570
00571 $tbl->setOrderColumn($order);
00572 $tbl->setOrderDirection($_GET["sort_order"]);
00573 $tbl->setOffset($_GET["offset"]);
00574 $tbl->setLimit($_GET["limit"]);
00575 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
00576 $tbl->setData($result_set);
00577 }
00578
00579 function __unsetSessionVariables()
00580 {
00581
00582 }
00583
00584 function __buildFilterSelect()
00585 {
00586 $action[1] = $this->lng->txt('all_roles');
00587 $action[2] = $this->lng->txt('all_global_roles');
00588 $action[3] = $this->lng->txt('all_local_roles');
00589 $action[4] = $this->lng->txt('internal_local_roles_only');
00590 $action[5] = $this->lng->txt('non_internal_local_roles_only');
00591 $action[6] = $this->lng->txt('role_templates_only');
00592
00593 return ilUtil::formSelect($_SESSION['filtered_roles'],"filter",$action,false,true);
00594 }
00595
00596 function hitsperpageObject()
00597 {
00598 parent::hitsperpageObject();
00599 $this->viewObject();
00600 }
00601 }
00602 ?>