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 ilObjRoleTemplateGUI extends ilObjectGUI
00038 {
00044 var $type;
00045
00051 var $rolf_ref_id;
00057 function ilObjRoleTemplateGUI($a_data,$a_id,$a_call_by_reference)
00058 {
00059 $this->type = "rolt";
00060 $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference);
00061 $this->rolf_ref_id =& $this->ref_id;
00062 }
00063
00069 function createObject()
00070 {
00071 global $rbacsystem;
00072
00073 if (!$rbacsystem->checkAccess("create_rolt", $this->rolf_ref_id))
00074 {
00075 $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
00076 }
00077 else
00078 {
00079
00080 $data = array();
00081 $data["fields"] = array();
00082 $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
00083 $data["fields"]["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
00084
00085 $this->getTemplateFile("edit",$this->type);
00086
00087 foreach ($data["fields"] as $key => $val)
00088 {
00089 $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
00090 $this->tpl->setVariable(strtoupper($key), $val);
00091
00092 if ($this->prepare_output)
00093 {
00094 $this->tpl->parseCurrentBlock();
00095 }
00096 }
00097
00098 $this->tpl->setVariable("FORMACTION", $this->getFormAction("save","adm_object.php?cmd=gateway&ref_id=".
00099 $this->rolf_ref_id."&new_type=".$this->type));
00100 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->type."_new"));
00101 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00102 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($this->type."_add"));
00103 $this->tpl->setVariable("CMD_SUBMIT", "save");
00104 $this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
00105 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00106 }
00107 }
00108
00109
00115 function saveObject()
00116 {
00117 global $rbacsystem,$rbacadmin, $rbacreview;
00118
00119
00120
00121 if (!$rbacsystem->checkAccess("create_rolt",$this->rolf_ref_id))
00122 {
00123 $this->ilias->raiseError($this->lng->txt("msg_no_perm_create_rolt"),$this->ilias->error_obj->WARNING);
00124 }
00125
00126
00127 if (empty($_POST["Fobject"]["title"]))
00128 {
00129 $this->ilias->raiseError($this->lng->txt("fill_out_all_required_fields"),$this->ilias->error_obj->MESSAGE);
00130 }
00131
00132
00133 if ($rbacreview->roleExists($_POST["Fobject"]["title"]))
00134 {
00135 $this->ilias->raiseError($this->lng->txt("msg_role_exists1")." '".ilUtil::stripSlashes($_POST["Fobject"]["title"])."' ".
00136 $this->lng->txt("msg_role_exists2"),$this->ilias->error_obj->MESSAGE);
00137 }
00138
00139
00140 if (substr($_POST["Fobject"]["title"],0,3) == "il_")
00141 {
00142 $this->ilias->raiseError($this->lng->txt("msg_role_reserved_prefix"),$this->ilias->error_obj->MESSAGE);
00143 }
00144
00145
00146 include_once("./classes/class.ilObjRoleTemplate.php");
00147 $roltObj = new ilObjRoleTemplate();
00148 $roltObj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00149 $roltObj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00150 $roltObj->create();
00151 $rbacadmin->assignRoleToFolder($roltObj->getId(), $this->rolf_ref_id,'n');
00152
00153 sendInfo($this->lng->txt("rolt_added"),true);
00154
00155 ilUtil::redirect("adm_object.php?ref_id=".$this->rolf_ref_id);
00156 }
00157
00163 function permObject()
00164 {
00165 global $rbacadmin, $rbacreview, $rbacsystem,$objDefinition;
00166
00167 if (!$rbacsystem->checkAccess('write',$this->rolf_ref_id))
00168 {
00169 $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->WARNING);
00170 exit();
00171 }
00172
00173 $to_filter = $objDefinition->getSubobjectsToFilter();
00174
00175
00176 $q = "SELECT ta.typ_id,obj.title,ops.ops_id,ops.operation FROM rbac_ta AS ta ".
00177 "LEFT JOIN object_data AS obj ON obj.obj_id=ta.typ_id ".
00178 "LEFT JOIN rbac_operations AS ops ON ops.ops_id=ta.ops_id";
00179 $r = $this->ilias->db->query($q);
00180
00181 while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00182 {
00183
00184 if(in_array($row->title,$to_filter))
00185 {
00186 continue;
00187 }
00188 $rbac_objects[$row->typ_id] = array("obj_id" => $row->typ_id,
00189 "type" => $row->title
00190 );
00191
00192 $rbac_operations[$row->typ_id][$row->ops_id] = array(
00193 "ops_id" => $row->ops_id,
00194 "title" => $row->operation,
00195 "name" => $this->lng->txt($row->title."_".$row->operation)
00196 );
00197 }
00198
00199 foreach ($rbac_objects as $key => $obj_data)
00200 {
00201 $rbac_objects[$key]["name"] = $this->lng->txt("obj_".$obj_data["type"]);
00202 $rbac_objects[$key]["ops"] = $rbac_operations[$key];
00203 }
00204
00205 sort($rbac_objects);
00206
00207 foreach ($rbac_objects as $key => $obj_data)
00208 {
00209 sort($rbac_objects[$key]["ops"]);
00210 }
00211
00212
00213 $rbac_objects = ilUtil::sortArray($rbac_objects,"name","asc");
00214
00215
00216 foreach ($rbac_objects as $key => $obj_data)
00217 {
00218 $arr_selected = $rbacreview->getOperationsOfRole($this->object->getId(), $obj_data["type"], $this->rolf_ref_id);
00219 $arr_checked = array_intersect($arr_selected,array_keys($rbac_operations[$obj_data["obj_id"]]));
00220
00221 foreach ($rbac_operations[$obj_data["obj_id"]] as $operation)
00222 {
00223 $checked = in_array($operation["ops_id"],$arr_checked);
00224 $disabled = false;
00225
00226
00227 $box = ilUtil::formCheckBox($checked,"template_perm[".$obj_data["type"]."][]",$operation["ops_id"],$disabled);
00228 $output["perm"][$obj_data["obj_id"]][$operation["ops_id"]] = $box;
00229 }
00230 }
00231
00232
00233 $output["col_anz"] = count($rbac_objects);
00234 $output["txt_save"] = $this->lng->txt("save");
00235
00236
00237
00238
00239
00240 $output["message_middle"] = $this->lng->txt("adopt_perm_from_template");
00241
00242
00243 if ($this->object->getId() == SYSTEM_ROLE_ID)
00244 {
00245 $output["adopt"] = array();
00246 sendinfo($this->lng->txt("msg_sysrole_not_editable"));
00247 }
00248 else
00249 {
00250
00251 $parent_role_ids = $rbacreview->getParentRoleIds($this->rolf_ref_id,true);
00252
00253
00254 ksort($parent_role_ids);
00255
00256 foreach ($parent_role_ids as $key => $par)
00257 {
00258 if ($par["obj_id"] != SYSTEM_ROLE_ID)
00259 {
00260 $radio = ilUtil::formRadioButton(0,"adopt",$par["obj_id"]);
00261 $output["adopt"][$key]["css_row_adopt"] = ilUtil::switchColor($key, "tblrow1", "tblrow2");
00262 $output["adopt"][$key]["check_adopt"] = $radio;
00263 $output["adopt"][$key]["type"] = ($par["type"] == 'role' ? 'Role' : 'Template');
00264 $output["adopt"][$key]["role_name"] = $par["title"];
00265 }
00266 }
00267
00268 $output["formaction_adopt"] = "adm_object.php?cmd=adoptPermSave&ref_id=".$this->rolf_ref_id."&obj_id=".$this->object->getId();
00269
00270 }
00271
00272 $output["formaction"] = "adm_object.php?cmd=permSave&ref_id=".$this->rolf_ref_id."&obj_id=".$this->object->getId();
00273
00274 $this->data = $output;
00275
00276
00277
00278
00279
00280
00281 $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
00282 $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html");
00283 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.adm_perm_role.html");
00284
00285 foreach ($rbac_objects as $obj_data)
00286 {
00287
00288 $this->tpl->setCurrentBlock("object_operations");
00289
00290 foreach ($obj_data["ops"] as $operation)
00291 {
00292 $ops_ids[] = $operation["ops_id"];
00293
00294 $css_row = ilUtil::switchColor($key, "tblrow1", "tblrow2");
00295 $this->tpl->setVariable("CSS_ROW",$css_row);
00296 $this->tpl->setVariable("PERMISSION",$operation["name"]);
00297 $this->tpl->setVariable("CHECK_PERMISSION",$this->data["perm"][$obj_data["obj_id"]][$operation["ops_id"]]);
00298 $this->tpl->parseCurrentBlock();
00299 }
00300
00301
00302 $this->tpl->setCurrentBlock("object_type");
00303 $this->tpl->setVariable("TXT_OBJ_TYPE",$obj_data["name"]);
00304
00305
00306 $this->tpl->setVariable("JS_VARNAME","template_perm_".$obj_data["type"]);
00307 $this->tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($ops_ids));
00308 $this->tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
00309 $this->tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
00310
00311
00312 $this->tpl->parseCurrentBlock();
00313
00314 }
00315
00316
00317 foreach ($this->data["adopt"] as $key => $value)
00318 {
00319 $this->tpl->setCurrentBlock("ADOPT_PERM_ROW");
00320 $this->tpl->setVariable("CSS_ROW_ADOPT",$value["css_row_adopt"]);
00321 $this->tpl->setVariable("CHECK_ADOPT",$value["check_adopt"]);
00322 $this->tpl->setVariable("TYPE",$value["type"]);
00323 $this->tpl->setVariable("ROLE_NAME",$value["role_name"]);
00324 $this->tpl->parseCurrentBlock();
00325 }
00326
00327 $this->tpl->setCurrentBlock("ADOPT_PERM_FORM");
00328 $this->tpl->setVariable("MESSAGE_MIDDLE",$this->data["message_middle"]);
00329 $this->tpl->setVariable("FORMACTION_ADOPT",$this->data["formaction_adopt"]);
00330 $this->tpl->parseCurrentBlock();
00331
00332
00333 $this->tpl->setCurrentBlock("tblfooter_standard");
00334 $this->tpl->setVariable("COL_ANZ_PLUS",4);
00335 $this->tpl->setVariable("TXT_SAVE",$this->data["txt_save"]);
00336 $this->tpl->parseCurrentBlock();
00337
00338
00339 $this->tpl->setCurrentBlock("adm_content");
00340 $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath("icon_".$this->object->getType()."_b.gif"));
00341 $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->lng->txt($this->object->getType()));
00342 $this->tpl->setVariable("TBL_HELP_IMG",ilUtil::getImagePath("icon_help.gif"));
00343 $this->tpl->setVariable("TBL_HELP_LINK","tbl_help.php");
00344 $this->tpl->setVariable("TBL_HELP_IMG_ALT",$this->lng->txt("help"));
00345 $this->tpl->setVariable("TBL_TITLE",$this->object->getTitle());
00346
00347 $this->tpl->setVariable("TXT_PERMISSION",$this->data["txt_permission"]);
00348 $this->tpl->setVariable("FORMACTION",$this->data["formaction"]);
00349 $this->tpl->parseCurrentBlock();
00350 }
00351
00352
00358 function permSaveObject()
00359 {
00360 global $rbacadmin, $rbacsystem, $rbacreview,$objDefinition;
00361
00362 if (!$rbacsystem->checkAccess('write',$this->rolf_ref_id))
00363 {
00364 $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->WARNING);
00365 }
00366 else
00367 {
00368
00369 $rbacadmin->deleteRolePermission($this->object->getId(), $this->rolf_ref_id);
00370
00371 foreach ($_POST["template_perm"] as $key => $ops_array)
00372 {
00373
00374 $rbacadmin->setRolePermission($this->object->getId(), $key,$ops_array,$this->rolf_ref_id);
00375 }
00376 }
00377
00378
00379 $this->object->update();
00380
00381 sendinfo($this->lng->txt("saved_successfully"),true);
00382
00383 ilUtil::redirect("adm_object.php?obj_id=".$this->object->getId()."&ref_id=".$this->rolf_ref_id."&cmd=perm");
00384 }
00385
00391 function adoptPermSaveObject()
00392 {
00393 global $rbacadmin, $rbacsystem, $rbacreview;
00394
00395 if (!$rbacsystem->checkAccess('write',$this->rolf_ref_id))
00396 {
00397 $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->WARNING);
00398 }
00399 elseif ($this->obj_id == $_POST["adopt"])
00400 {
00401 sendInfo($this->lng->txt("msg_perm_adopted_from_itself"),true);
00402 }
00403 else
00404 {
00405 $rbacadmin->deleteRolePermission($this->obj_id, $this->rolf_ref_id);
00406 $parentRoles = $rbacreview->getParentRoleIds($this->rolf_ref_id,true);
00407 $rbacadmin->copyRolePermission($_POST["adopt"],$parentRoles[$_POST["adopt"]]["parent"],
00408 $this->rolf_ref_id,$this->obj_id);
00409
00410 $this->object->update();
00411
00412
00413 $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($_POST["adopt"]);
00414 sendInfo($this->lng->txt("msg_perm_adopted_from1")." '".$obj_data->getTitle()."'.<br/>".$this->lng->txt("msg_perm_adopted_from2"),true);
00415 }
00416
00417 ilUtil::redirect("adm_object.php?ref_id=".$this->rolf_ref_id."&obj_id=".$this->obj_id."&cmd=perm");
00418 }
00419
00425 function editObject()
00426 {
00427 global $rbacsystem, $rbacreview;
00428
00429 if (!$rbacsystem->checkAccess("write", $this->rolf_ref_id))
00430 {
00431 $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
00432 }
00433
00434 $this->getTemplateFile("edit","role");
00435
00436 if ($_SESSION["error_post_vars"])
00437 {
00438
00439 if (substr($this->object->getTitle(),0,3) != "il_")
00440 {
00441 $this->tpl->setVariable("TITLE",ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"]),true);
00442 }
00443
00444 $this->tpl->setVariable("DESC",ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]));
00445 }
00446 else
00447 {
00448 if (substr($this->object->getTitle(),0,3) != "il_")
00449 {
00450 $this->tpl->setVariable("TITLE",ilUtil::prepareFormOutput($this->object->getTitle()));
00451 }
00452
00453 $this->tpl->setVariable("DESC",ilUtil::stripSlashes($this->object->getDescription()));
00454 }
00455
00456 $obj_str = "&obj_id=".$this->obj_id;
00457
00458 $this->tpl->setVariable("TXT_TITLE",$this->lng->txt("title"));
00459 $this->tpl->setVariable("TXT_DESC",$this->lng->txt("desc"));
00460
00461 $this->tpl->setVariable("FORMACTION", $this->getFormAction("update","adm_object.php?cmd=gateway&ref_id=".$this->rolf_ref_id.$obj_str));
00462 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->object->getType()."_edit"));
00463 $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
00464 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00465 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
00466 $this->tpl->setVariable("CMD_SUBMIT", "update");
00467 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00468
00469 if (substr($this->object->getTitle(),0,3) == "il_")
00470 {
00471 $this->tpl->setVariable("SHOW_TITLE",$this->object->getTitle());
00472 }
00473 }
00474
00480 function updateObject()
00481 {
00482 global $rbacsystem, $rbacadmin, $rbacreview;
00483
00484
00485 if (!$rbacsystem->checkAccess("write", $this->rolf_ref_id))
00486 {
00487 $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_rolt"),$this->ilias->error_obj->WARNING);
00488 }
00489
00490 if (substr($this->object->getTitle(),0,3) != "il_")
00491 {
00492
00493 if (empty($_POST["Fobject"]["title"]))
00494 {
00495 $this->ilias->raiseError($this->lng->txt("fill_out_all_required_fields"),$this->ilias->error_obj->MESSAGE);
00496 }
00497
00498
00499 if (substr($_POST["Fobject"]["title"],0,3) == "il_")
00500 {
00501 $this->ilias->raiseError($this->lng->txt("msg_role_reserved_prefix"),$this->ilias->error_obj->MESSAGE);
00502 }
00503
00504
00505 if ($rbacreview->roleExists($_POST["Fobject"]["title"],$this->object->getId()))
00506 {
00507 $this->ilias->raiseError($this->lng->txt("msg_role_exists1")." '".ilUtil::stripSlashes($_POST["Fobject"]["title"])."' ".
00508 $this->lng->txt("msg_role_exists2"),$this->ilias->error_obj->MESSAGE);
00509 }
00510
00511
00512 $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00513 }
00514
00515 $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00516 $this->object->update();
00517
00518 sendInfo($this->lng->txt("saved_successfully"),true);
00519
00520 ilUtil::redirect("adm_object.php?ref_id=".$this->rolf_ref_id);
00521 }
00522 }
00523 ?>