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->MESSAGE);
00170 exit();
00171 }
00172
00173 $to_filter = $objDefinition->getSubobjectsToFilter();
00174
00175 $tpl_filter = array();
00176 $internal_tpl = false;
00177
00178 if (($internal_tpl = $this->object->isInternalTemplate()))
00179 {
00180 $tpl_filter = $this->object->getFilterOfInternalTemplate();
00181 }
00182
00183
00184 $q = "SELECT ta.typ_id,obj.title,ops.ops_id,ops.operation FROM rbac_ta AS ta ".
00185 "LEFT JOIN object_data AS obj ON obj.obj_id=ta.typ_id ".
00186 "LEFT JOIN rbac_operations AS ops ON ops.ops_id=ta.ops_id";
00187 $r = $this->ilias->db->query($q);
00188
00189 while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00190 {
00191
00192 if(in_array($row->title,$to_filter))
00193 {
00194 continue;
00195 }
00196
00197 if ($internal_tpl and !in_array($row->title,$tpl_filter))
00198 {
00199 continue;
00200 }
00201
00202 $rbac_objects[$row->typ_id] = array("obj_id" => $row->typ_id,
00203 "type" => $row->title
00204 );
00205
00206 $rbac_operations[$row->typ_id][$row->ops_id] = array(
00207 "ops_id" => $row->ops_id,
00208 "title" => $row->operation,
00209 "name" => $this->lng->txt($row->title."_".$row->operation)
00210 );
00211 }
00212
00213 foreach ($rbac_objects as $key => $obj_data)
00214 {
00215 $rbac_objects[$key]["name"] = $this->lng->txt("obj_".$obj_data["type"]);
00216 $rbac_objects[$key]["ops"] = $rbac_operations[$key];
00217 }
00218
00219 sort($rbac_objects);
00220
00221 foreach ($rbac_objects as $key => $obj_data)
00222 {
00223 sort($rbac_objects[$key]["ops"]);
00224 }
00225
00226
00227 $rbac_objects = ilUtil::sortArray($rbac_objects,"name","asc");
00228
00229
00230 foreach ($rbac_objects as $key => $obj_data)
00231 {
00232 $arr_selected = $rbacreview->getOperationsOfRole($this->object->getId(), $obj_data["type"], $this->rolf_ref_id);
00233 $arr_checked = array_intersect($arr_selected,array_keys($rbac_operations[$obj_data["obj_id"]]));
00234
00235 foreach ($rbac_operations[$obj_data["obj_id"]] as $operation)
00236 {
00237 $checked = in_array($operation["ops_id"],$arr_checked);
00238 $disabled = false;
00239
00240
00241 $box = ilUtil::formCheckBox($checked,"template_perm[".$obj_data["type"]."][]",$operation["ops_id"],$disabled);
00242 $output["perm"][$obj_data["obj_id"]][$operation["ops_id"]] = $box;
00243 }
00244 }
00245
00246
00247 $output["col_anz"] = count($rbac_objects);
00248 $output["txt_save"] = $this->lng->txt("save");
00249
00250
00251
00252
00253
00254 $output["message_middle"] = $this->lng->txt("adopt_perm_from_template");
00255
00256
00257 if ($this->object->getId() == SYSTEM_ROLE_ID)
00258 {
00259 $output["adopt"] = array();
00260 sendinfo($this->lng->txt("msg_sysrole_not_editable"));
00261 }
00262 else
00263 {
00264
00265 $parent_role_ids = $rbacreview->getParentRoleIds($this->rolf_ref_id,true);
00266
00267
00268 ksort($parent_role_ids);
00269
00270 foreach ($parent_role_ids as $key => $par)
00271 {
00272 if ($par["obj_id"] != SYSTEM_ROLE_ID)
00273 {
00274 $radio = ilUtil::formRadioButton(0,"adopt",$par["obj_id"]);
00275 $output["adopt"][$key]["css_row_adopt"] = ilUtil::switchColor($key, "tblrow1", "tblrow2");
00276 $output["adopt"][$key]["check_adopt"] = $radio;
00277 $output["adopt"][$key]["type"] = ($par["type"] == 'role' ? 'Role' : 'Template');
00278 $output["adopt"][$key]["role_name"] = $par["title"];
00279 }
00280 }
00281
00282 $output["formaction_adopt"] = "adm_object.php?cmd=adoptPermSave&ref_id=".$this->rolf_ref_id."&obj_id=".$this->object->getId();
00283
00284 }
00285
00286 $output["formaction"] = "adm_object.php?cmd=permSave&ref_id=".$this->rolf_ref_id."&obj_id=".$this->object->getId();
00287
00288 $this->data = $output;
00289
00290
00291
00292
00293
00294
00295 $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
00296 $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html");
00297 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.adm_perm_role.html");
00298
00299 foreach ($rbac_objects as $obj_data)
00300 {
00301
00302 $this->tpl->setCurrentBlock("object_operations");
00303
00304 foreach ($obj_data["ops"] as $operation)
00305 {
00306 $ops_ids[] = $operation["ops_id"];
00307
00308 $css_row = ilUtil::switchColor($key, "tblrow1", "tblrow2");
00309 $this->tpl->setVariable("CSS_ROW",$css_row);
00310 $this->tpl->setVariable("PERMISSION",$operation["name"]);
00311 $this->tpl->setVariable("CHECK_PERMISSION",$this->data["perm"][$obj_data["obj_id"]][$operation["ops_id"]]);
00312 $this->tpl->parseCurrentBlock();
00313 }
00314
00315
00316 $this->tpl->setCurrentBlock("object_type");
00317 $this->tpl->setVariable("TXT_OBJ_TYPE",$obj_data["name"]);
00318
00319
00320 if ($this->objDefinition->getDevMode($obj_data["type"]))
00321 {
00322 $this->tpl->setVariable("TXT_NOT_IMPL", "(".$this->lng->txt("not_implemented_yet").")");
00323 }
00324 else if ($obj_data["type"] == "icrs" and !$this->ilias->getSetting("ilinc_active"))
00325 {
00326 $this->tpl->setVariable("TXT_NOT_IMPL", "(".$this->lng->txt("not_enabled_or_configured").")");
00327 }
00328
00329
00330 $this->tpl->setVariable("JS_VARNAME","template_perm_".$obj_data["type"]);
00331 $this->tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($ops_ids));
00332 $this->tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
00333 $this->tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
00334
00335
00336 $this->tpl->parseCurrentBlock();
00337
00338 }
00339
00340
00341 foreach ($this->data["adopt"] as $key => $value)
00342 {
00343 $this->tpl->setCurrentBlock("ADOPT_PERM_ROW");
00344 $this->tpl->setVariable("CSS_ROW_ADOPT",$value["css_row_adopt"]);
00345 $this->tpl->setVariable("CHECK_ADOPT",$value["check_adopt"]);
00346 $this->tpl->setVariable("TYPE",$value["type"]);
00347 $this->tpl->setVariable("ROLE_NAME",$value["role_name"]);
00348 $this->tpl->parseCurrentBlock();
00349 }
00350
00351 $this->tpl->setCurrentBlock("ADOPT_PERM_FORM");
00352 $this->tpl->setVariable("MESSAGE_MIDDLE",$this->data["message_middle"]);
00353 $this->tpl->setVariable("FORMACTION_ADOPT",$this->data["formaction_adopt"]);
00354 $this->tpl->parseCurrentBlock();
00355
00356
00357 $this->tpl->setCurrentBlock("tblfooter_standard");
00358 $this->tpl->setVariable("COL_ANZ_PLUS",4);
00359 $this->tpl->setVariable("TXT_SAVE",$this->data["txt_save"]);
00360 $this->tpl->parseCurrentBlock();
00361
00362
00363 $this->tpl->setCurrentBlock("adm_content");
00364 $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath("icon_".$this->object->getType()."_b.gif"));
00365 $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->lng->txt($this->object->getType()));
00366 $this->tpl->setVariable("TBL_HELP_IMG",ilUtil::getImagePath("icon_help.gif"));
00367 $this->tpl->setVariable("TBL_HELP_LINK","tbl_help.php");
00368 $this->tpl->setVariable("TBL_HELP_IMG_ALT",$this->lng->txt("help"));
00369
00370
00371 if (substr($this->object->getTitle(),0,3) == "il_")
00372 {
00373 $desc = $this->lng->txt("predefined_template");
00374 }
00375
00376 $description = "<br/> <span class=\"small\">".$desc."</span>";
00377
00378
00379 if (substr($this->object->getTitle(),0,3) == "il_")
00380 {
00381 include_once('class.ilObjRole.php');
00382
00383 $title = ilObjRole::_getTranslation($this->object->getTitle())." (".$this->object->getTitle().")";
00384 }
00385 else
00386 {
00387 $title = $this->object->getTitle();
00388 }
00389
00390 $this->tpl->setVariable("TBL_TITLE",$title.$description);
00391
00392 $this->tpl->setVariable("TXT_PERMISSION",$this->data["txt_permission"]);
00393 $this->tpl->setVariable("FORMACTION",$this->data["formaction"]);
00394 $this->tpl->parseCurrentBlock();
00395 }
00396
00397
00403 function permSaveObject()
00404 {
00405 global $rbacadmin, $rbacsystem, $rbacreview,$objDefinition;
00406
00407 if (!$rbacsystem->checkAccess('write',$this->rolf_ref_id))
00408 {
00409 $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->MESSAGE);
00410 }
00411 else
00412 {
00413
00414 $rbacadmin->deleteRolePermission($this->object->getId(), $this->rolf_ref_id);
00415
00416 foreach ($_POST["template_perm"] as $key => $ops_array)
00417 {
00418
00419 $rbacadmin->setRolePermission($this->object->getId(), $key,$ops_array,$this->rolf_ref_id);
00420 }
00421 }
00422
00423
00424 $this->object->update();
00425
00426 sendinfo($this->lng->txt("saved_successfully"),true);
00427
00428 ilUtil::redirect("adm_object.php?obj_id=".$this->object->getId()."&ref_id=".$this->rolf_ref_id."&cmd=perm");
00429 }
00430
00436 function adoptPermSaveObject()
00437 {
00438 global $rbacadmin, $rbacsystem, $rbacreview;
00439
00440 if (!$rbacsystem->checkAccess('write',$this->rolf_ref_id))
00441 {
00442 $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->WARNING);
00443 }
00444 elseif ($this->obj_id == $_POST["adopt"])
00445 {
00446 sendInfo($this->lng->txt("msg_perm_adopted_from_itself"),true);
00447 }
00448 else
00449 {
00450 $rbacadmin->deleteRolePermission($this->obj_id, $this->rolf_ref_id);
00451 $parentRoles = $rbacreview->getParentRoleIds($this->rolf_ref_id,true);
00452 $rbacadmin->copyRolePermission($_POST["adopt"],$parentRoles[$_POST["adopt"]]["parent"],
00453 $this->rolf_ref_id,$this->obj_id);
00454
00455 $this->object->update();
00456
00457
00458 $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($_POST["adopt"]);
00459 sendInfo($this->lng->txt("msg_perm_adopted_from1")." '".$obj_data->getTitle()."'.<br/>".$this->lng->txt("msg_perm_adopted_from2"),true);
00460 }
00461
00462 ilUtil::redirect("adm_object.php?ref_id=".$this->rolf_ref_id."&obj_id=".$this->obj_id."&cmd=perm");
00463 }
00464
00470 function editObject()
00471 {
00472 global $rbacsystem, $rbacreview;
00473
00474 if (!$rbacsystem->checkAccess("write", $this->rolf_ref_id))
00475 {
00476 $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
00477 }
00478
00479 $this->getTemplateFile("edit","role");
00480
00481 if ($_SESSION["error_post_vars"])
00482 {
00483
00484 if (substr($this->object->getTitle(),0,3) != "il_")
00485 {
00486 $this->tpl->setVariable("TITLE",ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"]),true);
00487 }
00488
00489 $this->tpl->setVariable("DESC",ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]));
00490 }
00491 else
00492 {
00493 if (substr($this->object->getTitle(),0,3) != "il_")
00494 {
00495 $this->tpl->setVariable("TITLE",ilUtil::prepareFormOutput($this->object->getTitle()));
00496 }
00497
00498 $this->tpl->setVariable("DESC",ilUtil::stripSlashes($this->object->getDescription()));
00499 }
00500
00501 $obj_str = "&obj_id=".$this->obj_id;
00502
00503 $this->tpl->setVariable("TXT_TITLE",$this->lng->txt("title"));
00504 $this->tpl->setVariable("TXT_DESC",$this->lng->txt("desc"));
00505
00506 $this->tpl->setVariable("FORMACTION", $this->getFormAction("update","adm_object.php?cmd=gateway&ref_id=".$this->rolf_ref_id.$obj_str));
00507 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->object->getType()."_edit"));
00508 $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
00509 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
00510 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
00511 $this->tpl->setVariable("CMD_SUBMIT", "update");
00512 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00513
00514 if (substr($this->object->getTitle(),0,3) == "il_")
00515 {
00516 $this->tpl->setVariable("SHOW_TITLE",$this->object->getTitle());
00517 }
00518 }
00519
00525 function updateObject()
00526 {
00527 global $rbacsystem, $rbacadmin, $rbacreview;
00528
00529
00530 if (!$rbacsystem->checkAccess("write", $this->rolf_ref_id))
00531 {
00532 $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_rolt"),$this->ilias->error_obj->WARNING);
00533 }
00534
00535 if (substr($this->object->getTitle(),0,3) != "il_")
00536 {
00537
00538 if (empty($_POST["Fobject"]["title"]))
00539 {
00540 $this->ilias->raiseError($this->lng->txt("fill_out_all_required_fields"),$this->ilias->error_obj->MESSAGE);
00541 }
00542
00543
00544 if (substr($_POST["Fobject"]["title"],0,3) == "il_")
00545 {
00546 $this->ilias->raiseError($this->lng->txt("msg_role_reserved_prefix"),$this->ilias->error_obj->MESSAGE);
00547 }
00548
00549
00550 if ($rbacreview->roleExists($_POST["Fobject"]["title"],$this->object->getId()))
00551 {
00552 $this->ilias->raiseError($this->lng->txt("msg_role_exists1")." '".ilUtil::stripSlashes($_POST["Fobject"]["title"])."' ".
00553 $this->lng->txt("msg_role_exists2"),$this->ilias->error_obj->MESSAGE);
00554 }
00555
00556
00557 $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
00558 }
00559
00560 $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
00561 $this->object->update();
00562
00563 sendInfo($this->lng->txt("saved_successfully"),true);
00564
00565 ilUtil::redirect("adm_object.php?ref_id=".$this->rolf_ref_id);
00566 }
00567 }
00568 ?>