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 $css_row = ilUtil::switchColor($key, "tblrow1", "tblrow2");
00293 $this->tpl->setVariable("CSS_ROW",$css_row);
00294 $this->tpl->setVariable("PERMISSION",$operation["name"]);
00295 $this->tpl->setVariable("CHECK_PERMISSION",$this->data["perm"][$obj_data["obj_id"]][$operation["ops_id"]]);
00296 $this->tpl->parseCurrentBlock();
00297 }
00298
00299
00300 $this->tpl->setCurrentBlock("object_type");
00301 $this->tpl->setVariable("TXT_OBJ_TYPE",$obj_data["name"]);
00302 $this->tpl->parseCurrentBlock();
00303
00304 }
00305
00306
00307 foreach ($this->data["adopt"] as $key => $value)
00308 {
00309 $this->tpl->setCurrentBlock("ADOPT_PERM_ROW");
00310 $this->tpl->setVariable("CSS_ROW_ADOPT",$value["css_row_adopt"]);
00311 $this->tpl->setVariable("CHECK_ADOPT",$value["check_adopt"]);
00312 $this->tpl->setVariable("TYPE",$value["type"]);
00313 $this->tpl->setVariable("ROLE_NAME",$value["role_name"]);
00314 $this->tpl->parseCurrentBlock();
00315 }
00316
00317 $this->tpl->setCurrentBlock("ADOPT_PERM_FORM");
00318 $this->tpl->setVariable("MESSAGE_MIDDLE",$this->data["message_middle"]);
00319 $this->tpl->setVariable("FORMACTION_ADOPT",$this->data["formaction_adopt"]);
00320 $this->tpl->parseCurrentBlock();
00321
00322
00323 $this->tpl->setCurrentBlock("tblfooter_standard");
00324 $this->tpl->setVariable("COL_ANZ_PLUS",4);
00325 $this->tpl->setVariable("TXT_SAVE",$this->data["txt_save"]);
00326 $this->tpl->parseCurrentBlock();
00327
00328
00329 $this->tpl->setCurrentBlock("adm_content");
00330 $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath("icon_".$this->object->getType()."_b.gif"));
00331 $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->lng->txt($this->object->getType()));
00332 $this->tpl->setVariable("TBL_HELP_IMG",ilUtil::getImagePath("icon_help.gif"));
00333 $this->tpl->setVariable("TBL_HELP_LINK","tbl_help.php");
00334 $this->tpl->setVariable("TBL_HELP_IMG_ALT",$this->lng->txt("help"));
00335 $this->tpl->setVariable("TBL_TITLE",$this->object->getTitle());
00336
00337 $this->tpl->setVariable("TXT_PERMISSION",$this->data["txt_permission"]);
00338 $this->tpl->setVariable("FORMACTION",$this->data["formaction"]);
00339 $this->tpl->parseCurrentBlock();
00340 }
00341
00342
00348 function permSaveObject()
00349 {
00350 global $rbacadmin, $rbacsystem, $rbacreview,$objDefinition;
00351
00352 if (!$rbacsystem->checkAccess('write',$this->rolf_ref_id))
00353 {
00354 $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->WARNING);
00355 }
00356 else
00357 {
00358
00359 $rbacadmin->deleteRolePermission($this->object->getId(), $this->rolf_ref_id);
00360
00361 foreach ($_POST["template_perm"] as $key => $ops_array)
00362 {
00363
00364 $rbacadmin->setRolePermission($this->object->getId(), $key,$ops_array,$this->rolf_ref_id);
00365 }
00366 }
00367
00368
00369 $this->object->update();
00370
00371 sendinfo($this->lng->txt("saved_successfully"),true);
00372
00373 ilUtil::redirect("adm_object.php?obj_id=".$this->object->getId()."&ref_id=".$this->rolf_ref_id."&cmd=perm");
00374 }
00375
00381 function adoptPermSaveObject()
00382 {
00383 global $rbacadmin, $rbacsystem, $rbacreview;
00384
00385 if (!$rbacsystem->checkAccess('write',$this->rolf_ref_id))
00386 {
00387 $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->WARNING);
00388 }
00389 elseif ($this->obj_id == $_POST["adopt"])
00390 {
00391 sendInfo($this->lng->txt("msg_perm_adopted_from_itself"),true);
00392 }
00393 else
00394 {
00395 $rbacadmin->deleteRolePermission($this->obj_id, $this->rolf_ref_id);
00396 $parentRoles = $rbacreview->getParentRoleIds($this->rolf_ref_id,true);
00397 $rbacadmin->copyRolePermission($_POST["adopt"],$parentRoles[$_POST["adopt"]]["parent"],
00398 $this->rolf_ref_id,$this->obj_id);
00399
00400 $this->object->update();
00401
00402
00403 $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($_POST["adopt"]);
00404 sendInfo($this->lng->txt("msg_perm_adopted_from1")." '".$obj_data->getTitle()."'.<br/>".$this->lng->txt("msg_perm_adopted_from2"),true);
00405 }
00406
00407 ilUtil::redirect("adm_object.php?ref_id=".$this->rolf_ref_id."&obj_id=".$this->obj_id."&cmd=perm");
00408 }
00409
00415 function editObject()
00416 {
00417 global $rbacsystem, $rbacreview;
00418
00419 if (!$rbacsystem->checkAccess("write", $this->rolf_ref_id))
00420 {
00421 $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
00422 }
00423
00424 $this->getTemplateFile("edit","role");
00425
00426 if ($_SESSION["error_post_vars"])
00427 {
00428
00429 if (substr($this->object->getTitle(),0,3) != "il_")
00430 {
00431 $this->tpl->setVariable("TITLE",ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"]),true);
00432 }
00433
00434 $this->tpl->setVariable("DESC",ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]));
00435 }
00436 else
00437 {
00438 if (substr($this->object->getTitle(),0,3) != "il_")
00439 {
00440 $this->tpl->setVariable("TITLE",ilUtil::prepareFormOutput($this->object->getTitle()));
00441 }
00442
00443 $this->tpl->setVariable("DESC",ilUtil::stripSlashes($this->object->getDescription()));
00444 }
00445
00446 $obj_str = "&obj_id=".$this->obj_id;
00447
00448 $this->tpl->setVariable("TXT_TITLE",$this->lng->txt("title"));
00449 $this->tpl->setVariable("TXT_DESC",$this->lng->txt("desc"));
00450
00451 $this->tpl->setVariable("FORMACTION", $this->getFormAction("update","adm_object.php?cmd=gateway&ref_id=".$this->rolf_ref_id.$obj_str));
00452 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->object->getType()."_edit"));
00453 $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
00454 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00455 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
00456 $this->tpl->setVariable("CMD_SUBMIT", "update");
00457 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00458
00459 if (substr($this->object->getTitle(),0,3) == "il_")
00460 {
00461 $this->tpl->setVariable("SHOW_TITLE",$this->object->getTitle());
00462 }
00463 }
00464
00470 function updateObject()
00471 {
00472 global $rbacsystem, $rbacadmin, $rbacreview;
00473
00474
00475 if (!$rbacsystem->checkAccess("write", $this->rolf_ref_id))
00476 {
00477 $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_rolt"),$this->ilias->error_obj->WARNING);
00478 }
00479
00480 if (substr($this->object->getTitle(),0,3) != "il_")
00481 {
00482
00483 if (empty($_POST["Fobject"]["title"]))
00484 {
00485 $this->ilias->raiseError($this->lng->txt("fill_out_all_required_fields"),$this->ilias->error_obj->MESSAGE);
00486 }
00487
00488
00489 if (substr($_POST["Fobject"]["title"],0,3) == "il_")
00490 {
00491 $this->ilias->raiseError($this->lng->txt("msg_role_reserved_prefix"),$this->ilias->error_obj->MESSAGE);
00492 }
00493
00494
00495 if ($rbacreview->roleExists($_POST["Fobject"]["title"],$this->object->getId()))
00496 {
00497 $this->ilias->raiseError($this->lng->txt("msg_role_exists1")." '".ilUtil::stripSlashes($_POST["Fobject"]["title"])."' ".
00498 $this->lng->txt("msg_role_exists2"),$this->ilias->error_obj->MESSAGE);
00499 }
00500
00501
00502 $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00503 }
00504
00505 $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00506 $this->object->update();
00507
00508 sendInfo($this->lng->txt("saved_successfully"),true);
00509
00510 ilUtil::redirect("adm_object.php?ref_id=".$this->rolf_ref_id);
00511 }
00512 }
00513 ?>