• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilObjectGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00034 class ilObjectGUI
00035 {
00041         var $ilias;
00042 
00048         var $objDefinition;
00049 
00055         var $tpl;
00056 
00062         var $tree;
00063 
00069         var $lng;
00070 
00076         var $data;
00077 
00083         var $object;
00084         var $ref_id;
00085         var $obj_id;
00086         var $maxcount;                  // contains number of child objects
00087         var $formaction;                // special formation (array "cmd" => "formaction")
00088         var $return_location;   // special return location (array "cmd" => "location")
00089         var $target_frame;      // special target frame (array "cmd" => "location")
00090 
00091         var $tab_target_script;
00092         var $actions;
00093         var $sub_objects;
00094 
00102         function ilObjectGUI($a_data, $a_id = 0, $a_call_by_reference = true, $a_prepare_output = true)
00103         {
00104                 global $ilias, $objDefinition, $tpl, $tree, $ilCtrl, $ilErr, $lng;
00105 
00106                 if (!isset($ilErr))
00107                 {
00108                         $ilErr = new ilErrorHandling();
00109                         $ilErr->setErrorHandling(PEAR_ERROR_CALLBACK,array($ilErr,'errorHandler'));
00110                 }
00111                 else
00112                 {
00113                         $this->ilErr =& $ilErr;
00114                 }
00115 
00116                 $this->ilias =& $ilias;
00117                 $this->objDefinition =& $objDefinition;
00118                 $this->tpl =& $tpl;
00119 
00120                 $this->ctrl =& $ilCtrl;
00121 
00122                 $params = array("ref_id");
00123 
00124                 if (!$a_call_by_reference)
00125                 {
00126                         $params = array("ref_id","obj_id");
00127                 }
00128 
00129                 $this->ctrl->saveParameter($this, $params);
00130 
00131                 $this->lng =& $lng;
00132                 $this->tree =& $tree;
00133                 $this->formaction = array();
00134                 $this->return_location = array();
00135                 $this->target_frame = array();
00136                 $this->tab_target_script = "adm_object.php";
00137                 $this->actions = "";
00138                 $this->sub_objects = "";
00139 
00140                 $this->data = $a_data;
00141                 $this->id = $a_id;
00142                 $this->call_by_reference = $a_call_by_reference;
00143                 $this->prepare_output = $a_prepare_output;
00144 
00145                 $this->ref_id = ($this->call_by_reference) ? $this->id : $_GET["ref_id"];
00146                 $this->obj_id = ($this->call_by_reference) ? $_GET["obj_id"] : $this->id;
00147 
00148                 if ($this->id != 0)
00149                 {
00150                         $this->link_params = "ref_id=".$this->ref_id;
00151                 }
00152 
00153                 // get the object
00154                 $this->assignObject();
00155 
00156                 // use global $lng instead, when creating new objects object is not available
00157                 //$this->lng =& $this->object->lng;
00158 
00159                 //prepare output
00160                 if ($a_prepare_output)
00161                 {
00162                         $this->prepareOutput();
00163                 }
00164 
00165                 // set default sort column
00166                 if (empty($_GET["sort_by"]))
00167                 {
00168                         // TODO: init sort_by better in obj class?
00169                         if ($this->object->getType() == "usrf"
00170                                 or $this->object->getType() == "rolf")
00171                         {
00172                                 $_GET["sort_by"] = "name";
00173                         }
00174                         elseif ($this->object->getType() == "typ")
00175                         {
00176                                 $_GET["sort_by"] = "operation";
00177                         }
00178                         elseif ($this->object->getType() == "lngf")
00179                         {
00180                                 $_GET["sort_by"] = "language";
00181                         }
00182                         else
00183                         {
00184                                 $_GET["sort_by"] = "title";
00185                         }
00186                 }
00187         }
00188         
00189         
00193         function &executeCommand()
00194         {
00195                 global $rbacsystem;
00196 
00197                 $next_class = $this->ctrl->getNextClass($this);
00198                 $cmd = $this->ctrl->getCmd();
00199                 switch($next_class)
00200                 {
00201                         default:
00202                                 if(!$cmd)
00203                                 {
00204                                         $cmd = "view";
00205                                 }
00206                                 $cmd .= "Object";
00207                                 $this->$cmd();
00208                                         
00209                                 break;
00210                 }
00211                 return true;
00212         }
00213 
00214 
00218         function withReferences()
00219         {
00220                 return $this->call_by_reference;
00221         }
00222 
00223         function assignObject()
00224         {
00225                 // TODO: it seems that we always have to pass only the ref_id
00226 //echo "assign:".get_class($this).":".$this->id.":<br>";
00227                 if ($this->id != 0)
00228                 {
00229                         if ($this->call_by_reference)
00230                         {
00231                                 $this->object =& $this->ilias->obj_factory->getInstanceByRefId($this->id);
00232                         }
00233                         else
00234                         {
00235                                 $this->object =& $this->ilias->obj_factory->getInstanceByObjId($this->id);
00236                         }
00237                 }
00238         }
00239 
00240         function prepareOutput()
00241         {
00242                 $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
00243                 $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
00244                 $title = $this->object->getTitle();
00245 
00246                 // catch feedback message
00247                 sendInfo();
00248 
00249                 if (!empty($title))
00250                 {
00251                         $this->tpl->setVariable("HEADER", $title);
00252                 }
00253 
00254                 $this->setAdminTabs($_POST["new_type"]);
00255                 $this->setLocator();
00256 
00257         }
00258 
00263         function setAdminTabs($a_new_type = 0)
00264         {
00265                 // temp. for groups and systemfolder
00266                 // TODO: use this style for all objects
00267                 if ($this->object->getType() == "grp" or $this->object->getType() == "adm")
00268                 {
00269                         include_once "./classes/class.ilTabsGUI.php";
00270                         $tabs_gui =& new ilTabsGUI();
00271                         $this->getTabs($tabs_gui);
00272 
00273                         // output tabs
00274                         $this->tpl->setVariable("TABS", $tabs_gui->getHTML());
00275                 }
00276                 else
00277                 {
00278                         global $rbacsystem;
00279         
00280                         $tabs = array();
00281                         $this->tpl->addBlockFile("TABS", "tabs", "tpl.tabs.html");
00282         
00283                         // for new objects display properties of parent object
00284                         if ($a_new_type)
00285                         {
00286                                 $d = $this->objDefinition->getProperties($this->object->getType());
00287                         }
00288                         else
00289                         {
00290                                 $d = $this->objDefinition->getProperties($this->type);
00291                         }
00292         
00293                         foreach ($d as $key => $row)
00294                         {
00295                                 $tabs[] = array($row["lng"], $row["name"]);
00296                         }
00297         
00298                         // check for call_by_reference too to avoid hacking
00299                         if (isset($_GET["obj_id"]) and $this->call_by_reference === false)
00300                         {
00301                                 $object_link = "&obj_id=".$_GET["obj_id"];
00302                         }
00303         
00304                         foreach ($tabs as $row)
00305                         {
00306                                 $i++;
00307         
00308                                 if ($row[1] == $_GET["cmd"])
00309                                 {
00310                                         $tabtype = "tabactive";
00311                                         $tab = $tabtype;
00312                                 }
00313                                 else
00314                                 {
00315                                         $tabtype = "tabinactive";
00316                                         $tab = "tab";
00317                                 }
00318         
00319                                 $show = true;
00320         
00321                                 // only check permissions for tabs if object is a permission object
00322                                 // TODO: automize checks by using objects.xml definitions!!
00323                                 if (true)
00324                                 //if ($this->call_by_reference)
00325                                 {
00326                                         // only show tab when the corresponding permission is granted
00327                                         switch ($row[1])
00328                                         {
00329                                                 case 'view':
00330                                                         if (!$rbacsystem->checkAccess('visible',$this->ref_id))
00331                                                         {
00332                                                                 $show = false;
00333                                                         }
00334                                                         break;
00335         
00336                                                 case 'edit':
00337                                                         if (!$rbacsystem->checkAccess('write',$this->ref_id))
00338                                                         {
00339                                                                 $show = false;
00340                                                         }
00341                                                         break;
00342         
00343                                                 case 'perm':
00344                                                         if (!$rbacsystem->checkAccess('edit_permission',$this->ref_id))
00345                                                         {
00346                                                                 $show = false;
00347                                                         }
00348                                                         break;
00349         
00350                                                 case 'trash':
00351                                                         if (!$this->tree->getSavedNodeData($this->ref_id))
00352                                                         {
00353                                                                 $show = false;
00354                                                         }
00355                                                         break;
00356         
00357                                                 // user object only
00358                                                 case 'roleassignment':
00359                                                         if (!$rbacsystem->checkAccess('edit_roleassignment',$this->ref_id))
00360                                                         {
00361                                                                 $show = false;
00362                                                         }
00363                                                         break;
00364         
00365                                                 // role object only
00366                                                 case 'userassignment':
00367                                                         if (!$rbacsystem->checkAccess('edit_userassignment',$this->ref_id))
00368                                                         {
00369                                                                 $show = false;
00370                                                         }
00371                                                         break;
00372                                         } //switch
00373                                 }
00374         
00375                                 if (!$show)
00376                                 {
00377                                         continue;
00378                                 }
00379         
00380                                 $this->tpl->setCurrentBlock("tab");
00381                                 $this->tpl->setVariable("TAB_TYPE", $tabtype);
00382                                 $this->tpl->setVariable("TAB_TYPE2", $tab);
00383                                 $this->tpl->setVariable("IMG_LEFT", ilUtil::getImagePath("eck_l.gif"));
00384                                 $this->tpl->setVariable("IMG_RIGHT", ilUtil::getImagePath("eck_r.gif"));
00385                                 $this->tpl->setVariable("TAB_LINK", $this->tab_target_script."?ref_id=".$_GET["ref_id"].$object_link."&cmd=".$row[1]);
00386                                 $this->tpl->setVariable("TAB_TEXT", $this->lng->txt($row[0]));
00387                                 $this->tpl->parseCurrentBlock();
00388                         }
00389                 }
00390         }
00391 
00392         function setTabTargetScript($a_script = "adm_object.php")
00393         {
00394                 $this->tab_target_script = $a_script;
00395         }
00396 
00397         function getTabTargetScript()
00398         {
00399                 return $this->tab_target_script;
00400         }
00401 
00408         function setActions($a_actions = "")
00409         {
00410                 if (is_array($a_actions))
00411                 {
00412                         foreach ($a_actions as $name => $lng)
00413                         {
00414                                 $this->actions[$name] = array("name" => $name, "lng" => $lng);
00415                         }
00416                 }
00417                 else
00418                 {
00419                         $this->actions = "";
00420                 }
00421         }
00422 
00429         function setSubObjects($a_sub_objects = "")
00430         {
00431                 if (is_array($a_sub_objects))
00432                 {
00433                         foreach ($a_sub_objects as $name => $options)
00434                         {
00435                                 $this->sub_objects[$name] = array("name" => $name, "max" => $options["max"]);
00436                         }
00437                 }
00438                 else
00439                 {
00440                         $this->sub_objects = "";
00441                 }
00442         }
00443 
00452         function setLocator($a_tree = "", $a_id = "", $scriptname="adm_object.php",
00453                 $a_child_param = "ref_id", $a_output_obj = true, $a_root_title = "")
00454         {
00455                 global $ilias_locator;
00456 
00457                 if (!is_object($a_tree))
00458                 {
00459                         $a_tree =& $this->tree;
00460                 }
00461 
00462                 if (!($a_id))
00463                 {
00464                         $a_id = $_GET["ref_id"];
00465                 }
00466 
00467                 $this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html");
00468 
00469                 $path = $a_tree->getPathFull($a_id);
00470 
00471         //check if object isn't in tree, this is the case if parent_parent is set
00472                 // TODO: parent_parent no longer exist. need another marker
00473                 if ($a_parent_parent)
00474                 {
00475                         //$subObj = getObject($a_ref_id);
00476                         $subObj =& $this->ilias->obj_factory->getInstanceByRefId($a_ref_id);
00477 
00478                         $path[] = array(
00479                                 "id"     => $a_ref_id,
00480                                 "title"  => $this->lng->txt($subObj->getTitle())
00481                                 );
00482                 }
00483 
00484                 // this is a stupid workaround for a bug in PEAR:IT
00485                 $modifier = 1;
00486 
00487                 if (isset($_GET["obj_id"]) && $a_output_obj)
00488                 {
00489                         $modifier = 0;
00490                 }
00491 
00492                 // ### AA 03.11.10 added new locator GUI class ###
00493                 $i = 1;
00494 
00495                 foreach ($path as $key => $row)
00496                 {
00497                         if ($key < count($path)-$modifier)
00498                         {
00499                                 $this->tpl->touchBlock("locator_separator");
00500                         }
00501 
00502                         $this->tpl->setCurrentBlock("locator_item");
00503 
00504                         if ($a_root_title != "" && ($row["child"] == $a_tree->getRootId()))
00505                         {
00506                                 $title = $a_root_title;
00507                         }
00508                         else
00509                         {
00510                                 $title = $row["title"];
00511                         }
00512 
00513                         $this->tpl->setVariable("ITEM", $title);
00514 
00515                         $this->tpl->setVariable("LINK_ITEM",
00516                                 ilUtil::appendUrlParameterString($scriptname, $a_child_param."=".$row["child"]));
00517                         $this->tpl->parseCurrentBlock();
00518 
00519                         // ### AA 03.11.10 added new locator GUI class ###
00520                         // navigate locator
00521                         $ilias_locator->navigate($i++,$title,
00522                                 ilUtil::appendUrlParameterString($scriptname, $a_child_param."=".$row["child"]),"bottom");
00523                 }
00524 
00525                 if (($_GET["obj_id"] != "") && $a_output_obj)
00526                 {
00527                         $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($_GET["obj_id"]);
00528 
00529                         $this->tpl->setCurrentBlock("locator_item");
00530                         $this->tpl->setVariable("ITEM", $obj_data->getTitle());
00531 
00532                         $this->tpl->setVariable("LINK_ITEM",
00533                                 ilUtil::appendUrlParameterString($scriptname, "ref_id=".$_GET["ref_id"]."&obj_id=".$_GET["obj_id"]));
00534                         $this->tpl->parseCurrentBlock();
00535 
00536                         // ### AA 03.11.10 added new locator GUI class ###
00537                         // navigate locator
00538                         $ilias_locator->navigate($i++,$obj_data->getTitle(),
00539                                 ilUtil::appendUrlParameterString($scriptname, "ref_id=".$_GET["ref_id"]."&obj_id=".$_GET["obj_id"]),"bottom");
00540                 }
00541 
00542                 $this->tpl->setCurrentBlock("locator");
00543 
00544                 if (DEBUG)
00545                 {
00546                         $debug = "DEBUG: <font color=\"red\">".$this->type."::".$this->id."::".$_GET["cmd"]."</font><br/>";
00547                 }
00548 
00549                 $prop_name = $this->objDefinition->getPropertyName($_GET["cmd"],$this->type);
00550 
00551                 if ($_GET["cmd"] == "confirmDeleteAdm")
00552                 {
00553                         $prop_name = "delete_object";
00554                 }
00555 
00556                 $this->tpl->setVariable("TXT_LOCATOR",$debug.$this->lng->txt("locator"));
00557                 $this->tpl->parseCurrentBlock();
00558 
00559         }
00560 
00566         function copyObject()
00567         {
00568                 global $rbacsystem;
00569 
00570                 if (!isset($_POST["id"]))
00571                 {
00572                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00573                 }
00574 
00575                 // FOR ALL OBJECTS THAT SHOULD BE COPIED
00576                 foreach ($_POST["id"] as $ref_id)
00577                 {
00578                         // GET COMPLETE NODE_DATA OF ALL SUBTREE NODES
00579                         $node_data = $this->tree->getNodeData($ref_id);
00580                         $subtree_nodes = $this->tree->getSubTree($node_data);
00581 
00582                         $all_node_data[] = $node_data;
00583                         $all_subtree_nodes[] = $subtree_nodes;
00584 
00585                         // CHECK READ PERMISSION OF ALL OBJECTS IN ACTUAL SUBTREE
00586                         foreach ($subtree_nodes as $node)
00587                         {
00588                                 if (!$rbacsystem->checkAccess('read',$node["ref_id"]))
00589                                 {
00590                                         $no_copy[] = $node["ref_id"];
00591                                 }
00592                         }
00593                 }
00594                 // IF THERE IS ANY OBJECT WITH NO PERMISSION TO 'read'
00595                 if (count($no_copy))
00596                 {
00597                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_copy")." ".implode(',',$this->getTitlesByRefId($no_copy)),
00598                                                                          $this->ilias->error_obj->MESSAGE);
00599                 }
00600 
00601                 $_SESSION["clipboard"]["parent"] = $_GET["ref_id"];
00602                 $_SESSION["clipboard"]["cmd"] = key($_POST["cmd"]);
00603                 $_SESSION["clipboard"]["ref_ids"] = $_POST["id"];
00604 
00605                 sendinfo($this->lng->txt("msg_copy_clipboard"),true);
00606 
00607                 ilUtil::redirect($this->getReturnLocation("copy","adm_object.php?ref_id=".$_GET["ref_id"]));
00608         }
00609 
00616         function pasteObject()
00617         {
00618                 global $rbacsystem, $rbacadmin, $rbacreview, $log;
00619                 
00620                 if ($this->ctrl->getTargetScript() == "repository.php")
00621                 {
00622                         $_SESSION["clipboard"] = "";
00623                         $_SESSION["clipboard"]["parent"] = $_GET["ref_id"];
00624                         $_SESSION["clipboard"]["cmd"] = $_SESSION["il_rep_clipboard"][0]["act"];
00625                         $_SESSION["clipboard"]["ref_ids"] = array($_SESSION["il_rep_clipboard"][0]["ref_id"]);
00626                         //var_dump("rep",$_SESSION["clipboard"]);exit;
00627                 }
00628 //var_dump("adm",$_SESSION["clipboard"]);exit;
00629                 if (!in_array($_SESSION["clipboard"]["cmd"],array("cut","link","copy")))
00630                 {
00631                         $message = get_class($this)."::pasteObject(): cmd was neither 'cut','link' or 'copy'; may be a hack attempt!";
00632                         $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00633                 }
00634                 
00635                 // this loop does all checks
00636                 foreach ($_SESSION["clipboard"]["ref_ids"] as $ref_id)
00637                 {
00638                         $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($ref_id);
00639                         
00640                         // CHECK ACCESS
00641                         if (!$rbacsystem->checkAccess('create', $_GET["ref_id"], $obj_data->getType()))
00642                         {
00643                                 $no_paste[] = $ref_id;
00644                         }
00645 
00646                         // CHECK IF REFERENCE ALREADY EXISTS
00647                         if ($_GET["ref_id"] == $this->tree->getParentId($obj_data->getRefId()))
00648                         {
00649                                 $exists[] = $ref_id;
00650                                 break;
00651                         }
00652 
00653                         // CHECK IF PASTE OBJECT SHALL BE CHILD OF ITSELF
00654                         if ($this->tree->isGrandChild($ref_id,$_GET["ref_id"]))
00655                         {
00656                                 $is_child[] = $ref_id;
00657                         }                       
00658 
00659                         // CHECK IF OBJECT IS ALLOWED TO CONTAIN PASTED OBJECT AS SUBOBJECT
00660                         $obj_type = $obj_data->getType();
00661 
00662                         if (!in_array($obj_type, array_keys($this->objDefinition->getSubObjects($this->object->getType()))))
00663                         {
00664                                 $not_allowed_subobject[] = $obj_data->getType();
00665                         }
00666                 }
00667 
00669                 // process checking results
00670                 if (count($exists))
00671                 {
00672                         $this->ilias->raiseError($this->lng->txt("msg_obj_exists"),$this->ilias->error_obj->MESSAGE);
00673                 }
00674 
00675                 if (count($is_child))
00676                 {
00677                         $this->ilias->raiseError($this->lng->txt("msg_not_in_itself")." ".implode(',',$is_child),
00678                                                                          $this->ilias->error_obj->MESSAGE);
00679                 }
00680 
00681                 if (count($not_allowed_subobject))
00682                 {
00683                         $this->ilias->raiseError($this->lng->txt("msg_may_not_contain")." ".implode(',',$not_allowed_subobject),
00684                                                                          $this->ilias->error_obj->MESSAGE);
00685                 }
00686 
00687                 if (count($no_paste))
00688                 {
00689                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_paste")." ".
00690                                                                          implode(',',$no_paste),$this->ilias->error_obj->MESSAGE);
00691                 }
00692                 
00693                 // log pasteObject call
00694                 $log->write("ilObjectGUI::pasteObject(), cmd: ".$_SESSION["clipboard"]["cmd"]);
00695 
00697                 // everything ok: now paste the objects to new location
00698                 
00699                 // to prevent multiple actions via back/reload button
00700                 $ref_ids = $_SESSION["clipboard"]["ref_ids"];
00701                 unset($_SESSION["clipboard"]["ref_ids"]);
00702 
00703                 // process COPY command
00704                 if ($_SESSION["clipboard"]["cmd"] == "copy")
00705                 {
00706                         // CALL PRIVATE CLONE METHOD
00707                         $this->cloneObject($ref_ids);
00708                 }
00709 
00710                 // process CUT command
00711                 if ($_SESSION["clipboard"]["cmd"] == "cut")
00712                 {
00713                         // get subtrees
00714                         foreach($ref_ids as $ref_id)
00715                         {
00716                                 // get node data
00717                                 $top_node = $this->tree->getNodeData($ref_id);
00718 
00719                                 // get subnodes of top nodes
00720                                 $subnodes[$ref_id] = $this->tree->getSubtree($top_node);
00721                         }
00722                         
00723                         // STEP 1: Move all subtrees to trash
00724                         $log->write("ilObjectGUI::pasteObject(), (1/3) move subtrees to trash");
00725                         
00726                         foreach($ref_ids as $ref_id)
00727                         {
00728                                 $tnodes = $this->tree->getSubtree($this->tree->getNodeData($ref_id));
00729                                 
00730                                 foreach ($tnodes as $tnode)
00731                                 {
00732                                         $rbacadmin->revokePermission($tnode["child"]);
00733                                         $affected_users = ilUtil::removeItemFromDesktops($tnode["child"]);
00734                                 }
00735 
00736                                 $this->tree->saveSubTree($ref_id);
00737                                 $this->tree->deleteTree($this->tree->getNodeData($ref_id));
00738                         }
00739                         
00740         
00741                         // STEP 2: Move all subtrees to new location
00742                         $log->write("ilObjectGUI::pasteObject(), (2/3) move subtrees to new location");
00743 
00744                         // TODO: this whole put in place again stuff needs revision. Permission settings get lost.
00745                         foreach ($subnodes as $key => $subnode)
00746                         {
00747                                 // first paste top_node ...
00748                                 $rbacadmin->revokePermission($key);
00749                                 $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($key);
00750                                 $obj_data->putInTree($_GET["ref_id"]);
00751                                 $obj_data->setPermissions($_GET["ref_id"]);
00752 
00753                                 // log entry
00754                                 $log->write("ilObjectGUI::pasteObject(), inserted top node. ref_id: $key,".
00755                                         " rgt: ".$subnode[0]["rgt"].", lft: ".$subnode[0]["lft"].", parent: ".$subnode[0]["parent"].",".
00756                                         " obj_id: ".$obj_data->getId().", type: ".$obj_data->getType().
00757                                         ", title: ".$obj_data->getTitle());
00758 
00759                                 // ... remove top_node from list ...
00760                                 array_shift($subnode);
00761 
00762                                 // ... insert subtree of top_node if any subnodes exist
00763                                 if (count($subnode) > 0)
00764                                 {
00765                                         foreach ($subnode as $node)
00766                                         {
00767                                                 $rbacadmin->revokePermission($node["child"]);
00768                                                 $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($node["child"]);
00769                                                 $obj_data->putInTree($node["parent"]);
00770                                                 $obj_data->setPermissions($node["parent"]);
00771                                                 
00772                                                 // log entry
00773                                                 $log->write("ilObjectGUI::pasteObject(), inserted subnode. ref_id: ".$node["child"].",".
00774                                                         " rgt: ".$node["rgt"].", lft: ".$node["lft"].", parent: ".$node["parent"].",".
00775                                                         " obj_id: ".$obj_data->getId().", type: ".$obj_data->getType().
00776                                                         ", title: ".$obj_data->getTitle());
00777                                         }
00778                                 }
00779                         }
00780                         
00781                         // STEP 3: Remove trashed objects from system
00782                         $log->write("ilObjectGUI::pasteObject(), (3/3) remove trashed subtrees from system");
00783 
00784                         foreach ($ref_ids as $ref_id)
00785                         {
00786                                 // GET COMPLETE NODE_DATA OF ALL SUBTREE NODES
00787                                 $saved_tree = new ilTree(-(int)$ref_id);
00788                                 $node_data = $saved_tree->getNodeData($ref_id);
00789                                 $subtree_nodes = $saved_tree->getSubTree($node_data);
00790         
00791                                 // remember already checked deleted node_ids
00792                                 $checked[] = -(int) $ref_id;
00793         
00794                                 // dive in recursive manner in each already deleted subtrees and remove these objects too
00795                                 $this->removeDeletedNodes($ref_id, $checked, false);
00796                 
00797                                 // delete save tree
00798                                 $this->tree->deleteTree($node_data);
00799                                 
00800                                 // write log entry
00801                                 $log->write("ilObjectGUI::pasteObject(), deleted tree, tree_id: ".$node_data["tree"].
00802                                         ", child: ".$node_data["child"]);
00803                         }
00804 
00805                         
00806                         $log->write("ilObjectGUI::pasteObject(), cut finished");
00807                         
00808                         // inform other objects in hierarchy about paste operation
00809                         //$this->object->notify("paste",$this->object->getRefId(),$_SESSION["clipboard"]["parent_non_rbac_id"],$this->object->getRefId(),$subnodes);
00810 
00811                         // inform other objects in hierarchy about cut operation
00812                         // the parent object where cut occured
00813                         $tmp_object = $this->ilias->obj_factory->getInstanceByRefId($_SESSION["clipboard"]["parent"]);
00814                         //$tmp_object->notify("cut", $tmp_object->getRefId(),$_SESSION["clipboard"]["parent_non_rbac_id"],$tmp_object->getRefId(),$ref_ids);
00815                         unset($tmp_object);
00816                 } // END CUT
00817 
00818                 // process LINK command
00819                 if ($_SESSION["clipboard"]["cmd"] == "link")
00820                 {
00821                         foreach ($ref_ids as $ref_id)
00822                         {
00823                                 // get node data
00824                                 $top_node = $this->tree->getNodeData($ref_id);
00825                 
00826                                 // get subnodes of top nodes
00827                                 $subnodes[$ref_id] = $this->tree->getSubtree($top_node);
00828                         }
00829 
00830                         // now move all subtrees to new location
00831                         foreach ($subnodes as $key => $subnode)
00832                         {
00833                                 // first paste top_node....
00834                                 $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($key);
00835                                 $new_ref_id = $obj_data->createReference();
00836                                 $obj_data->putInTree($_GET["ref_id"]);
00837                                 $obj_data->setPermissions($_GET["ref_id"]);
00838 
00839                                 // ... remove top_node from list ...
00840                                 array_shift($subnode);
00841                                 
00842                                 // ... store mapping of old ref_id => new_ref_id in hash array ...
00843                                 $mapping[$new_ref_id] = $key;
00844 
00845                                 // save old ref_id & create rolefolder if applicable
00846                                 $old_ref_id = $obj_data->getRefId();
00847                                 $obj_data->setRefId($new_ref_id);
00848                                 $obj_data->initDefaultRoles();
00849                                 $rolf_data = $rbacreview->getRoleFolderOfObject($obj_data->getRefId());
00850                                 
00851                                 if (isset($rolf_data["child"]))
00852                                 {
00853                                         // a role folder was created, so map it to old role folder
00854                                         $rolf_data_old = $rbacreview->getRoleFolderOfObject($old_ref_id);
00855                                         
00856                                         // ... use mapping array to find out the correct new parent node where to put in the node...
00857                                         //$new_parent = array_search($node["parent"],$mapping);
00858                                         // ... append node to mapping for further possible subnodes ...
00859                                         $mapping[$rolf_data["child"]] = (int) $rolf_data_old["child"];
00860                                         
00861                                         // log creation of role folder
00862                                         $log->write("ilObjectGUI::pasteObject(), created role folder (ref_id): ".$rolf_data["child"].
00863                                                 ", for object ref_id:".$obj_data->getRefId().", obj_id: ".$obj_data->getId().
00864                                                 ", type: ".$obj_data->getType().", title: ".$obj_data->getTitle());
00865 
00866                                 }
00867 
00868                                 // ... insert subtree of top_node if any subnodes exist ...
00869                                 if (count($subnode) > 0)
00870                                 {
00871                                         foreach ($subnode as $node)
00872                                         {
00873                                                 if ($node["type"] != 'rolf')
00874                                                 {
00875                                                         $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($node["child"]);
00876                                                         $new_ref_id = $obj_data->createReference();
00877                                                 
00878                                                         // ... use mapping array to find out the correct new parent node where to put in the node...
00879                                                         $new_parent = array_search($node["parent"],$mapping);
00880                                                         // ... append node to mapping for further possible subnodes ...
00881                                                         $mapping[$new_ref_id] = (int) $node["child"];
00882 
00883                                                         $obj_data->putInTree($new_parent);
00884                                                         $obj_data->setPermissions($new_parent);
00885                                                         
00886                                                         // save old ref_id & create rolefolder if applicable
00887                                                         $old_ref_id = $obj_data->getRefId();
00888                                                         $obj_data->setRefId($new_ref_id);
00889                                                         $obj_data->initDefaultRoles();
00890                                                         $rolf_data = $rbacreview->getRoleFolderOfObject($obj_data->getRefId());
00891                                                         
00892                                                         if (isset($rolf_data["child"]))
00893                                                         {
00894                                                                 // a role folder was created, so map it to old role folder
00895                                                                 $rolf_data_old = $rbacreview->getRoleFolderOfObject($old_ref_id);
00896 
00897                                                                 // ... use mapping array to find out the correct new parent node where to put in the node...
00898                                                                 //$new_parent = array_search($node["parent"],$mapping);
00899                                                                 // ... append node to mapping for further possible subnodes ...
00900                                                                 $mapping[$rolf_data["child"]] = (int) $rolf_data_old["child"];
00901                                                                 
00902                                                                 // log creation of role folder
00903                                                                 $log->write("ilObjectGUI::pasteObject(), created role folder (ref_id): ".$rolf_data["child"].
00904                                                                         ", for object ref_id:".$obj_data->getRefId().", obj_id: ".$obj_data->getId().
00905                                                                         ", type: ".$obj_data->getType().", title: ".$obj_data->getTitle());
00906 
00907                                                         }
00908                                                 }
00909                                                 
00910                                                 // re-map $subnodes
00911                                                 foreach ($subnodes as $old_ref => $subnode)
00912                                                 {
00913                                                         $new_ref = array_search($old_ref,$mapping);
00914                                                         
00915                                                         foreach ($subnode as $node)
00916                                                         {
00917                                                                 $node["child"] = array_search($node["child"],$mapping);
00918                                                                 $node["parent"] = array_search($node["parent"],$mapping);
00919                                                                 $new_subnodes[$ref_id][] = $node; 
00920                                                         }
00921                                                 }
00922                                                 
00923                                         }
00924                                 }
00925                         }
00926                         
00927                         $log->write("ilObjectGUI::pasteObject(), link finished");
00928                         
00929                         // inform other objects in hierarchy about link operation
00930                         //$this->object->notify("link",$this->object->getRefId(),$_SESSION["clipboard"]["parent_non_rbac_id"],$this->object->getRefId(),$subnodes);
00931                 } // END LINK
00932 
00933                 // save cmd for correct message output after clearing the clipboard
00934                 $last_cmd = $_SESSION["clipboard"]["cmd"];
00935                 
00936                 
00937                 // clear clipboard
00938                 $this->clearObject();
00939                 
00940                 if ($last_cmd == "cut")
00941                 {
00942                         sendInfo($this->lng->txt("msg_cut_copied"),true);
00943                 }
00944                 else
00945                 {
00946                         sendInfo($this->lng->txt("msg_linked"),true);           
00947                 }
00948                 
00949                 ilUtil::redirect($this->getReturnLocation("paste",$this->ctrl->getLinkTarget($this)),get_class($this));
00950                 //ilUtil::redirect($this->getReturnLocation("paste","adm_object.php?ref_id=".$_GET["ref_id"]));
00951 
00952         } // END PASTE
00953 
00959         function clearObject()
00960         {       
00961                 unset($_SESSION["clipboard"]);
00962                 unset($_SESSION["il_rep_clipboard"]);
00963                 //var_dump($this->getReturnLocation("clear",$this->ctrl->getLinkTarget($this)),get_class($this));
00964 
00965                 // only redirect if clipboard was cleared
00966                 if (isset($_POST["cmd"]["clear"]))
00967                 {
00968                         sendinfo($this->lng->txt("msg_clear_clipboard"),true);
00969 
00970                         //ilUtil::redirect($this->getReturnLocation("clear","adm_object.php?ref_id=".$_GET["ref_id"]));
00971                         ilUtil::redirect($this->getReturnLocation("clear",$this->ctrl->getLinkTarget($this)),get_class($this));
00972                 }
00973         }
00974 
00980         function cutObject()
00981         {
00982                 global $rbacsystem;
00983 //echo $_SESSION["referer"];
00984                 if (!isset($_POST["id"]))
00985                 {
00986                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00987                 }
00988 
00989                 // FOR ALL OBJECTS THAT SHOULD BE COPIED
00990                 foreach ($_POST["id"] as $ref_id)
00991                 {
00992                         // GET COMPLETE NODE_DATA OF ALL SUBTREE NODES
00993                         $node_data = $this->tree->getNodeData($ref_id);
00994                         $subtree_nodes = $this->tree->getSubTree($node_data);
00995 
00996                         $all_node_data[] = $node_data;
00997                         $all_subtree_nodes[] = $subtree_nodes;
00998 
00999                         // CHECK DELETE PERMISSION OF ALL OBJECTS IN ACTUAL SUBTREE
01000                         foreach ($subtree_nodes as $node)
01001                         {
01002                                 if (!$rbacsystem->checkAccess('delete',$node["ref_id"]))
01003                                 {
01004                                         $no_cut[] = $node["ref_id"];
01005                                 }
01006                         }
01007                 }
01008                 // IF THERE IS ANY OBJECT WITH NO PERMISSION TO 'delete'
01009                 if (count($no_cut))
01010                 {
01011                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_cut")." ".implode(',',$this->getTitlesByRefId($no_cut)),
01012                                                                          $this->ilias->error_obj->MESSAGE);
01013                 }
01014                 //echo "GET";var_dump($_GET);echo "POST";var_dump($_POST);
01015                 $_SESSION["clipboard"]["parent"] = $_GET["ref_id"];
01016                 $_SESSION["clipboard"]["cmd"] = key($_POST["cmd"]);
01017                 $_SESSION["clipboard"]["ref_ids"] = $_POST["id"];
01018                 
01019                 sendinfo($this->lng->txt("msg_cut_clipboard"),true);
01020 
01021                 ilUtil::redirect($this->getReturnLocation("cut","adm_object.php?ref_id=".$_GET["ref_id"]));
01022 
01023         } // END CUT
01024 
01031         function linkObject()
01032         {
01033                 global $clipboard, $rbacsystem, $rbacadmin;
01034 
01035                 if (!isset($_POST["id"]))
01036                 {
01037                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
01038                 }
01039 
01040                 // CHECK ACCESS
01041                 foreach ($_POST["id"] as $ref_id)
01042                 {
01043                         if (!$rbacsystem->checkAccess('delete',$ref_id))
01044                         {
01045                                 $no_cut[] = $ref_id;
01046                         }
01047 
01048                         $object =& $this->ilias->obj_factory->getInstanceByRefId($ref_id);
01049 
01050                         if (!$this->objDefinition->allowLink($object->getType()))
01051                         {
01052                                 $no_link[] = $object->getType();
01053                         }
01054                 }
01055 
01056                 // NO ACCESS
01057                 if (count($no_cut))
01058                 {
01059                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_link")." ".
01060                                                                          implode(',',$no_cut),$this->ilias->error_obj->MESSAGE);
01061                 }
01062 
01063                 if (count($no_link))
01064                 {
01065                         $no_link = array_unique($no_link);
01066 
01067                         foreach ($no_link as $type)
01068                         {
01069                                 $txt_objs[] = $this->lng->txt("objs_".$type);
01070                         }
01071 
01072                         $this->ilias->raiseError(implode(', ',$txt_objs)." ".$this->lng->txt("msg_obj_no_link"),$this->ilias->error_obj->MESSAGE);
01073 
01074                         //$this->ilias->raiseError($this->lng->txt("msg_not_possible_link")." ".
01075                         //                                               implode(',',$no_link),$this->ilias->error_obj->MESSAGE);
01076                 }
01077 
01078                 // WRITE TO CLIPBOARD
01079                 $clipboard["parent"] = $_GET["ref_id"];
01080                 $clipboard["cmd"] = key($_POST["cmd"]);
01081                 
01082                 foreach ($_POST["id"] as $ref_id)
01083                 {
01084                         $clipboard["ref_ids"][] = $ref_id;
01085                 }
01086 
01087                 $_SESSION["clipboard"] = $clipboard;
01088         
01089                 sendinfo($this->lng->txt("msg_link_clipboard"),true);
01090 
01091                 ilUtil::redirect($this->getReturnLocation("link","adm_object.php?ref_id=".$_GET["ref_id"]));
01092 
01093         } // END LINK
01094 
01100         function cloneObject($a_ref_ids)
01101         {
01102                 global $rbacsystem;
01103 
01104                 if(!is_array($a_ref_ids))
01105                 {
01106                         $this->ilias->raiseError($this->lng->txt("msg_error_copy"),$this->ilias->error_obj->MESSAGE);
01107                 }
01108                 
01109                 // NOW CLONE ALL OBJECTS
01110                 // THEREFORE THE CLONE METHOD OF ALL OBJECTS IS CALLED
01111                 foreach ($a_ref_ids as $id)
01112                 {
01113                         $this->cloneNodes($id,$this->ref_id,$mapping);
01114                 }
01115                 
01116                 // inform other objects in hierarchy about copy operation
01117                 //$this->object->notify("copy",$_SESSION["clipboard"]["parent"],$_SESSION["clipboard"]["parent_non_rbac_id"],$_GET["ref_id"],$mapping);
01118  
01119                 $this->clearObject();
01120 
01121                 sendinfo($this->lng->txt("msg_cloned"),true);
01122                 ilUtil::redirect($this->getReturnLocation("paste","adm_object.php?ref_id=".$_GET["ref_id"]));
01123 
01124         } // END CLONE
01125 
01136         function cloneNodes($a_source_id,$a_dest_id,&$mapping)
01137         {
01138                 if (!$mapping)
01139                 {
01140                         $mapping = array();
01141                 }
01142 
01143                 // FIRST CLONE THE OBJECT (THEREFORE THE CLONE METHOD OF EACH OBJECT IS CALLED)
01144                 $source_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_source_id);
01145                 $new_ref_id = $source_obj->ilClone($a_dest_id);
01146                 unset($source_obj);
01147 
01148                 $mapping[$new_ref_id] = $a_source_id;
01149 
01150                 // GET ALL CHILDS OF SOURCE OBJECT AND CALL THIS METHOD FOR OF THEM
01151                 foreach ($this->tree->getChilds($a_source_id) as $child)
01152                 {
01153                         // STOP IF CHILD OBJECT IS ROLE FOLDER SINCE IT DOESN'T MAKE SENSE TO CLONE LOCAL ROLES
01154                         if ($child["type"] != 'rolf')
01155                         {
01156                                 $this->cloneNodes($child["ref_id"],$new_ref_id,$mapping);
01157                         }
01158                         else
01159                         {
01160                                 if (count($rolf = $this->tree->getChildsByType($new_ref_id,"rolf")))
01161                                 {
01162                                         $mapping[$rolf[0]["ref_id"]] = $child["ref_id"];
01163                                 }
01164                         }
01165                 }
01166 
01167                 return true;
01168         }
01169 
01175         function undeleteObject()
01176         {
01177                 global $rbacsystem, $log;
01178 
01179                 // AT LEAST ONE OBJECT HAS TO BE CHOSEN.
01180                 if (!isset($_POST["trash_id"]))
01181                 {
01182                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
01183                 }
01184 
01185                 foreach ($_POST["trash_id"] as $id)
01186                 {
01187                         $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($id);
01188 
01189                         if (!$rbacsystem->checkAccess('create',$_GET["ref_id"],$obj_data->getType()))
01190                         {
01191                                 $no_create[] = $id;
01192                         }
01193                 }
01194 
01195                 if (count($no_create))
01196                 {
01197                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_paste")." ".
01198                                                                          implode(',',$no_paste),$this->ilias->error_obj->MESSAGE);
01199                 }
01200 
01201                 foreach ($_POST["trash_id"] as $id)
01202                 {
01203                         // INSERT AND SET PERMISSIONS
01204                         $this->insertSavedNodes($id,$_GET["ref_id"],-(int) $id);
01205                         // DELETE SAVED TREE
01206                         $saved_tree = new ilTree(-(int)$id);
01207                         $saved_tree->deleteTree($saved_tree->getNodeData($id));
01208                         
01209                 }
01210 
01211                 //$this->object->notify("undelete", $_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$_POST["trash_id"]);
01212                 
01213                 sendInfo($this->lng->txt("msg_undeleted"),true);
01214                 
01215                 ilUtil::redirect($this->getReturnLocation("undelete","adm_object.php?ref_id=".$_GET["ref_id"]));
01216 
01217         }
01218 
01228         function insertSavedNodes($a_source_id,$a_dest_id,$a_tree_id)
01229         {
01230                 global $rbacadmin, $rbacreview, $log;
01231 
01232                 $this->tree->insertNode($a_source_id,$a_dest_id);
01233                 
01234                 // write log entry
01235                 $log->write("ilObjectGUI::insertSavedNodes(), restored ref_id $a_source_id from trash");
01236 
01237                 // SET PERMISSIONS
01238                 $parentRoles = $rbacreview->getParentRoleIds($a_dest_id);
01239                 $obj =& $this->ilias->obj_factory->getInstanceByRefId($a_source_id);
01240 
01241                 foreach ($parentRoles as $parRol)
01242                 {
01243                         $ops = $rbacreview->getOperationsOfRole($parRol["obj_id"], $obj->getType(), $parRol["parent"]);
01244                         $rbacadmin->grantPermission($parRol["obj_id"],$ops,$a_source_id);
01245                 }
01246 
01247                 $saved_tree = new ilTree($a_tree_id);
01248                 $childs = $saved_tree->getChilds($a_source_id);
01249 
01250                 foreach ($childs as $child)
01251                 {
01252                         $this->insertSavedNodes($child["child"],$a_source_id,$a_tree_id);
01253                 }
01254         }
01255 
01265         function confirmedDeleteObject()
01266         {
01267                 include_once './payment/classes/class.ilPaymentObject.php';
01268 
01269                 global $rbacsystem, $rbacadmin, $log;
01270         
01271                 // TODO: move checkings to deleteObject
01272                 // TODO: cannot distinguish between obj_id from ref_id with the posted IDs.
01273                 // change the form field and use instead of 'id' 'ref_id' and 'obj_id'. Then switch with varname
01274                 
01275                 // AT LEAST ONE OBJECT HAS TO BE CHOSEN.
01276                 if (!isset($_SESSION["saved_post"]))
01277                 {
01278                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
01279                 }
01280 
01281                 // FOR ALL SELECTED OBJECTS
01282                 foreach ($_SESSION["saved_post"] as $id)
01283                 {
01284                         // GET COMPLETE NODE_DATA OF ALL SUBTREE NODES
01285                         $node_data = $this->tree->getNodeData($id);
01286                         $subtree_nodes = $this->tree->getSubTree($node_data);
01287 
01288                         $all_node_data[] = $node_data;
01289                         $all_subtree_nodes[] = $subtree_nodes;
01290 
01291                         // CHECK DELETE PERMISSION OF ALL OBJECTS
01292                         foreach ($subtree_nodes as $node)
01293                         {
01294                                 if($node['type'] == 'rolf')
01295                                 {
01296                                         continue;
01297                                 }
01298                                 if (!$rbacsystem->checkAccess('delete',$node["child"]))
01299                                 {
01300                                         $not_deletable[] = $node["child"];
01301                                         $perform_delete = false;
01302                                 }
01303                                 else if(ilPaymentObject::_isBuyable($node['child']))
01304                                 {
01305                                         $buyable[] = $node['child'];
01306                                         $perform_delete = false;
01307                                 }
01308                         }
01309                 }
01310 
01311                 // IF THERE IS ANY OBJECT WITH NO PERMISSION TO DELETE
01312                 if (count($not_deletable))
01313                 {
01314                         $not_deletable = implode(',',$not_deletable);
01315                         session_unregister("saved_post");
01316                         sendInfo($this->lng->txt("msg_no_perm_delete")." ".$not_deletable."<br/>".$this->lng->txt("msg_cancel"),true);
01317                         ilUtil::redirect($this->getReturnLocation("confirmedDelete","adm_object.php?ref_id=".$_GET["ref_id"]));
01318 
01319 //                      $this->ilias->raiseError($this->lng->txt("msg_no_perm_delete")." ".
01320 //                                                                       $not_deletable,$this->ilias->error_obj->MESSAGE);
01321                 }
01322                 if(count($buyable))
01323                 {
01324                         foreach($buyable as $id)
01325                         {
01326                                 $tmp_object =& ilObjectFactory::getInstanceByRefId($id);
01327 
01328                                 $titles[] = $tmp_object->getTitle();
01329                         }
01330                         $title_str = implode(',',$titles);
01331 
01332                         sendInfo($this->lng->txt('msg_obj_not_deletable_sold').' '.$title_str,true);
01333 
01334                         $_POST['id'] = $_SESSION['saved_post'];
01335                         $this->deleteObject(true);
01336 
01337                         return false;
01338                 }
01339 
01340                 // DELETE THEM
01341                 if (!$all_node_data[0]["type"])
01342                 {
01343                         // OBJECTS ARE NO 'TREE OBJECTS'
01344                         if ($rbacsystem->checkAccess('delete',$_GET["ref_id"]))
01345                         {
01346                                 foreach($_SESSION["saved_post"] as $id)
01347                                 {
01348                                         $obj =& $this->ilias->obj_factory->getInstanceByObjId($id);
01349                                         $obj->delete();
01350                                         
01351                                         // write log entry
01352                                         $log->write("ilObjectGUI::confirmedDeleteObject(), deleted obj_id ".$obj->getId().
01353                                                 ", type: ".$obj->getType().", title: ".$obj->getTitle());
01354                                 }
01355                         }
01356                         else
01357                         {
01358                                 unset($_SESSION["saved_post"]);
01359                                 sendInfo($this->lng->txt("no_perm_delete")."<br/>".$this->lng->txt("msg_cancel"),true);
01360                                 ilUtil::redirect($this->getReturnLocation("confirmedDelete","adm_object.php?ref_id=".$_GET["ref_id"]));
01361                         }
01362                 }
01363                 else
01364                 {
01365                         // SAVE SUBTREE AND DELETE SUBTREE FROM TREE
01366                         foreach ($_SESSION["saved_post"] as $id)
01367                         {
01368                                 // DELETE OLD PERMISSION ENTRIES
01369                                 $subnodes = $this->tree->getSubtree($this->tree->getNodeData($id));
01370                         
01371                                 foreach ($subnodes as $subnode)
01372                                 {
01373                                         $rbacadmin->revokePermission($subnode["child"]);
01374                                         // remove item from all user desktops
01375                                         $affected_users = ilUtil::removeItemFromDesktops($subnode["child"]);
01376                                 
01377                                         // TODO: inform users by mail that object $id was deleted
01378                                         //$mail->sendMail($id,$msg,$affected_users);
01379                                 }
01380 
01381                                 $this->tree->saveSubTree($id);
01382                                 $this->tree->deleteTree($this->tree->getNodeData($id));
01383 
01384                                 // write log entry
01385                                 $log->write("ilObjectGUI::confirmedDeleteObject(), moved ref_id ".$id.
01386                                         " to trash");
01387                                 
01388                                 // remove item from all user desktops
01389                                 $affected_users = ilUtil::removeItemFromDesktops($id);
01390                                 
01391                                 // TODO: inform users by mail that object $id was deleted
01392                                 //$mail->sendMail($id,$msg,$affected_users);
01393                         }
01394                         // inform other objects in hierarchy about paste operation
01395                         //$this->object->notify("confirmedDelete", $_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$_SESSION["saved_post"]);
01396                 }
01397                 
01398                 // Feedback
01399                 sendInfo($this->lng->txt("info_deleted"),true);
01400                 
01401                 ilUtil::redirect($this->getReturnLocation("confirmedDelete","adm_object.php?ref_id=".$_GET["ref_id"]));
01402 
01403         }
01404 
01410         function cancelDeleteObject()
01411         {
01412                 session_unregister("saved_post");
01413 
01414                 sendInfo($this->lng->txt("msg_cancel"),true);
01415                 
01416                 ilUtil::redirect($this->getReturnLocation("cancelDelete","adm_object.php?ref_id=".$_GET["ref_id"]));
01417 
01418         }
01419 
01425         function removeFromSystemObject()
01426         {
01427                 global $rbacsystem, $log;
01428                 
01429                 // AT LEAST ONE OBJECT HAS TO BE CHOSEN.
01430                 if (!isset($_POST["trash_id"]))
01431                 {
01432                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
01433                 }
01434 
01435                 //$this->object->notify("removeFromSystem", $_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$_POST["trash_id"]);
01436 
01437                 // DELETE THEM
01438                 foreach ($_POST["trash_id"] as $id)
01439                 {
01440                         // GET COMPLETE NODE_DATA OF ALL SUBTREE NODES
01441                         $saved_tree = new ilTree(-(int)$id);
01442                         $node_data = $saved_tree->getNodeData($id);
01443                         $subtree_nodes = $saved_tree->getSubTree($node_data);
01444 
01445 
01446                         // remember already checked deleted node_ids
01447                         $checked[] = -(int) $id;
01448 
01449                         // dive in recursive manner in each already deleted subtrees and remove these objects too
01450                         $this->removeDeletedNodes($id,$checked);
01451 
01452                         foreach ($subtree_nodes as $node)
01453                         {
01454                                 $node_obj =& $this->ilias->obj_factory->getInstanceByRefId($node["ref_id"]);
01455                                 
01456                                 // write log entry
01457                                 $log->write("ilObjectGUI::removeFromSystemObject(), delete obj_id: ".$node_obj->getId().
01458                                         ", ref_id: ".$node_obj->getRefId().", type: ".$node_obj->getType().", ".
01459                                         "title: ".$node_obj->getTitle());
01460                                         
01461                                 $node_obj->delete();
01462                         }
01463 
01464                         // FIRST DELETE ALL ENTRIES IN RBAC TREE
01465                         #$this->tree->deleteTree($node_data);
01466                         // Use the saved tree object here (negative tree_id)
01467                         $saved_tree->deleteTree($node_data);
01468                                                 
01469                         // write log entry
01470                         $log->write("ilObjectGUI::removeFromSystemObject(), deleted tree, tree_id: ".$node_data["tree"].
01471                                 ", child: ".$node_data["child"]);
01472 
01473                 }
01474                 
01475                 sendInfo($this->lng->txt("msg_removed"),true);
01476 
01477                 ilUtil::redirect($this->getReturnLocation("removeFromSystem","adm_object.php?ref_id=".$_GET["ref_id"]));
01478 
01479         }
01480 
01489         function removeDeletedNodes($a_node_id, $a_checked, $a_delete_objects = true)
01490         {
01491                 global $log;
01492                 
01493                 $q = "SELECT tree FROM tree WHERE parent='".$a_node_id."' AND tree < 0";
01494                 
01495                 $r = $this->ilias->db->query($q);
01496 
01497                 while($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
01498                 {
01499                         // only continue recursion if fetched node wasn't touched already!
01500                         if (!in_array($row->tree,$a_checked))
01501                         {
01502                                 $deleted_tree = new ilTree($row->tree);
01503                                 $a_checked[] = $row->tree;
01504 
01505                                 $row->tree = $row->tree * (-1);
01506                                 $del_node_data = $deleted_tree->getNodeData($row->tree);
01507                                 $del_subtree_nodes = $deleted_tree->getSubTree($del_node_data);
01508 
01509                                 $this->removeDeletedNodes($row->tree,$a_checked);
01510                         
01511                                 if ($a_delete_objects)
01512                                 {
01513                                         foreach ($del_subtree_nodes as $node)
01514                                         {
01515                                                 $node_obj =& $this->ilias->obj_factory->getInstanceByRefId($node["ref_id"]);
01516                                                 
01517                                                 // write log entry
01518                                                 $log->write("ilObjectGUI::removeDeletedNodes(), delete obj_id: ".$node_obj->getId().
01519                                                         ", ref_id: ".$node_obj->getRefId().", type: ".$node_obj->getType().", ".
01520                                                         "title: ".$node_obj->getTitle());
01521                                                         
01522                                                 $node_obj->delete();
01523                                         }
01524                                 }
01525                         
01526                                 $this->tree->deleteTree($del_node_data);
01527                                 
01528                                 // write log entry
01529                                 $log->write("ilObjectGUI::removeDeletedNodes(), deleted tree, tree_id: ".$del_node_data["tree"].
01530                                         ", child: ".$del_node_data["child"]);
01531                         }
01532                 }
01533                 
01534                 return true;
01535         }
01536 
01542         function createObject()
01543         {
01544                 global $rbacsystem;
01545 
01546                 $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
01547 
01548                 if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
01549                 {
01550                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
01551                 }
01552                 else
01553                 {
01554                         // fill in saved values in case of error
01555                         $data = array();
01556                         $data["fields"] = array();
01557                         $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
01558                         $data["fields"]["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
01559 
01560                         $this->getTemplateFile("edit",$new_type);
01561 
01562                         foreach ($data["fields"] as $key => $val)
01563                         {
01564                                 $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
01565                                 $this->tpl->setVariable(strtoupper($key), $val);
01566 
01567                                 if ($this->prepare_output)
01568                                 {
01569                                         $this->tpl->parseCurrentBlock();
01570                                 }
01571                         }
01572 
01573                         $this->tpl->setVariable("FORMACTION", $this->getFormAction("save","adm_object.php?cmd=gateway&ref_id=".
01574                                                                                                                                            $_GET["ref_id"]."&new_type=".$new_type));
01575                         $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($new_type."_new"));
01576                         $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
01577                         $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($new_type."_add"));
01578                         $this->tpl->setVariable("CMD_SUBMIT", "save");
01579                         $this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
01580                         $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
01581                 }
01582         }
01583 
01589         function cancelObject($in_rep = false)
01590         {
01591                 session_unregister("saved_post");
01592 
01593                 sendInfo($this->lng->txt("msg_cancel"),true);
01594 
01595                 //sendInfo($this->lng->txt("action_aborted"),true);
01596                 $return_location = $_GET["cmd_return_location"];
01597 //echo "-".$_GET["cmd_return_location"]."-".$this->ctrl->getLinkTarget($this,$return_location);
01598                 //ilUtil::redirect($this->ctrl->getLinkTarget($this,$return_location));
01599                 if ($in_rep)
01600                 {
01601                         $this->ctrl->returnToParent($this);
01602                 }
01603                 else
01604                 {
01605                         ilUtil::redirect($this->getReturnLocation("cancel",$this->ctrl->getTargetScript()."?".$this->link_params));
01606                 }
01607         }
01608 
01614         function saveObject()
01615         {
01616                 global $rbacsystem, $objDefinition;
01617 
01618                 $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
01619 
01620                 // create permission is already checked in createObject. This check here is done to prevent hacking attempts
01621                 if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
01622                 {
01623                         $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
01624                 }
01625 
01626                 $module = $objDefinition->getModule($_GET["new_type"]);
01627                 $module_dir = ($module == "")
01628                         ? ""
01629                         : $module."/";
01630 
01631                         // create and insert object in objecttree
01632                 $class_name = "ilObj".$objDefinition->getClassName($_GET["new_type"]);
01633                 include_once($module_dir."classes/class.".$class_name.".php");
01634                 $newObj = new $class_name();
01635                 $newObj->setType($_GET["new_type"]);
01636                 $newObj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
01637                 $newObj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
01638                 $newObj->create();
01639                 $newObj->createReference();
01640                 $newObj->putInTree($_GET["ref_id"]);
01641                 $newObj->setPermissions($_GET["ref_id"]);
01642                 //$newObj->notify("new",$_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$newObj->getRefId());
01643 
01644                 return $newObj;
01645         }
01646 
01647 
01653         function importObject()
01654         {
01655                 global $rbacsystem;
01656                 // CHECK ACCESS 'write' of role folder
01657                 // TODO: new_type will never be checked, if queried operation is not 'create'
01658                 if (!$rbacsystem->checkAccess('write', $_GET["ref_id"], $_POST["new_type"]))
01659                 {
01660                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->WARNING);
01661                 }
01662 
01663                 $imp_obj =$this->objDefinition->getImportObjects($this->object->getType());
01664 
01665                 if (!in_array($_POST["new_type"], $imp_obj))
01666                 {
01667                         $this->ilias->raiseError($this->lng->txt("no_import_available").
01668                                 " ".$this->lng->txt("obj_".$_POST["new_type"]),
01669                                 $this->ilias->error_obj->MESSAGE);
01670                 }
01671                 // no general implementation of this feature, the specialized classes
01672                 // must provide further processing
01673         }
01674 
01675 
01681         function editObject()
01682         {
01683                 global $rbacsystem;
01684 
01685                 if (!$rbacsystem->checkAccess("write", $this->ref_id))
01686                 {
01687                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
01688                 }
01689 
01690                 $fields = array();
01691 
01692                 if ($_SESSION["error_post_vars"])
01693                 {
01694                         // fill in saved values in case of error
01695                         $fields["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
01696                         $fields["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
01697                 }
01698                 else
01699                 {
01700                         $fields["title"] = ilUtil::prepareFormOutput($this->object->getTitle());
01701                         $fields["desc"] = ilUtil::stripSlashes($this->object->getDescription());
01702                 }
01703 
01704                 $this->displayEditForm($fields);
01705         }
01706 
01713         function displayEditForm($fields)
01714         {
01715                 $this->getTemplateFile("edit");
01716 
01717                 foreach ($fields as $key => $val)
01718                 {
01719                         $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
01720                         $this->tpl->setVariable(strtoupper($key), $val);
01721                         $this->tpl->parseCurrentBlock();
01722                 }
01723 
01724                 $obj_str = ($this->call_by_reference) ? "" : "&obj_id=".$this->obj_id;
01725 
01726                 $this->tpl->setVariable("FORMACTION", $this->getFormAction("update",$this->ctrl->getFormAction($this).$obj_str));
01727                 //$this->tpl->setVariable("FORMACTION", $this->getFormAction("update","adm_object.php?cmd=gateway&ref_id=".$this->ref_id.$obj_str));
01728                 $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->object->getType()."_edit"));
01729                 $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
01730                 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
01731                 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
01732                 $this->tpl->setVariable("CMD_SUBMIT", "update");
01733                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
01734 
01735         }
01736 
01737 
01743         function updateObject()
01744         {
01745                 $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
01746                 $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
01747                 $this->update = $this->object->update();
01748 
01749                 sendInfo($this->lng->txt("msg_obj_modified"),true);
01750 
01751                 ilUtil::redirect($this->getReturnLocation("update",$this->ctrl->getLinkTarget($this)));
01752                 //ilUtil::redirect($this->getReturnLocation("update","adm_object.php?ref_id=".$this->ref_id));
01753         }
01754 
01760         function permObject()
01761         {
01762                 global $rbacsystem, $rbacreview;
01763 
01764                 static $num = 0;
01765                 if (!$rbacsystem->checkAccess("edit_permission", $this->object->getRefId()))
01766                 {
01767                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->MESSAGE);
01768                 }
01769 
01770                 // only display superordinate roles; local roles with other scope are not displayed
01771                 $parentRoles = $rbacreview->getParentRoleIds($this->object->getRefId());
01772 
01773                 $data = array();
01774 
01775                 // GET ALL LOCAL ROLE IDS
01776                 $role_folder = $rbacreview->getRoleFolderOfObject($this->object->getRefId());
01777 
01778                 $local_roles = array();
01779 
01780                 if ($role_folder)
01781                 {
01782                         $local_roles = $rbacreview->getRolesOfRoleFolder($role_folder["ref_id"]);
01783                 }
01784 
01785                 foreach ($parentRoles as $key => $r)
01786                 {
01787                         if ($r["obj_id"] == SYSTEM_ROLE_ID)
01788                         {
01789                                 unset($parentRoles[$key]);
01790                                 continue;
01791                         }
01792 
01793                         if (!in_array($r["obj_id"],$local_roles))
01794                         {
01795                                 $data["check_inherit"][] = ilUtil::formCheckBox(0,"stop_inherit[]",$r["obj_id"]);
01796                         }
01797                         else
01798                         {
01799                                 $r["link"] = true;
01800 
01801                                 // don't display a checkbox for local roles AND system role
01802                                 if ($rbacreview->isAssignable($r["obj_id"],$role_folder["ref_id"]))
01803                                 {
01804                                         $data["check_inherit"][] = "&nbsp;";
01805                                 }
01806                                 else
01807                                 {
01808                                         // linked local roles with stopped inheritance
01809                                         $data["check_inherit"][] = ilUtil::formCheckBox(1,"stop_inherit[]",$r["obj_id"]);
01810                                 }
01811                         }
01812 
01813                         $data["roles"][] = $r;
01814                 }
01815                 
01816                 $ope_list = getOperationList($this->object->getType());
01817                 
01818                 // BEGIN TABLE_DATA_OUTER
01819                 foreach ($ope_list as $key => $operation)
01820                 {
01821                         $opdata = array();
01822 
01823                         $opdata["name"] = $operation["operation"];
01824 
01825                         $colspan = count($parentRoles) + 1;
01826 
01827                         foreach ($parentRoles as $role)
01828                         {
01829                                 $checked = $rbacsystem->checkPermission($this->object->getRefId(), $role["obj_id"],$operation["operation"],$_GET["parent"]);
01830                                 $disabled = false;
01831 
01832                                 // Es wird eine 2-dim Post Variable bergeben: perm[rol_id][ops_id]
01833                                 $box = ilUtil::formCheckBox($checked,"perm[".$role["obj_id"]."][]",$operation["ops_id"],$disabled);
01834                                 $opdata["values"][] = $box;
01835                         }
01836 
01837                         $data["permission"][] = $opdata;
01838                 }
01839 
01841                 // START DATA OUTPUT
01843                 $this->getTemplateFile("perm");
01844                 $this->tpl->setCurrentBlock("tableheader");
01845                 $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("permission_settings"));
01846                 $this->tpl->setVariable("COLSPAN", $colspan);
01847                 $this->tpl->setVariable("TXT_OPERATION", $this->lng->txt("operation"));
01848                 $this->tpl->setVariable("TXT_ROLES", $this->lng->txt("roles"));
01849                 $this->tpl->parseCurrentBlock();
01850 
01851                 $num = 0;
01852 
01853                 foreach ($data["roles"] as $role)
01854                 {
01855                         if(0 and $role['role_type'] != 'global' and is_object($this->ctrl))
01856                         {
01857                                 $this->tpl->setCurrentBlock("ROLELINK_OPEN");
01858                                 $this->ctrl->setParameterByClass('ilobjrolegui','obj_id',$role['obj_id']);
01859                                 $this->tpl->setVariable("LINK_ROLE_RULESET",
01860                                                                                 $this->ctrl->getLinkTargetByClass('ilobjrolegui','perm'));
01861                                 $this->tpl->setVariable("TXT_ROLE_RULESET",$this->lng->txt("edit_perm_ruleset"));
01862                                 $this->tpl->parseCurrentBlock();
01863 
01864                                 $this->tpl->touchBlock("ROLELINK_CLOSE");
01865                         }
01866 
01867                         $this->tpl->setCurrentBlock("ROLENAMES");
01868                         $this->tpl->setVariable("ROLE_NAME",$role["title"]);
01869                         $this->tpl->parseCurrentBlock();
01870 
01871                         // BLOCK CHECK INHERIT
01872                         if ($this->objDefinition->stopInheritance($this->type))
01873                         {
01874                                 $this->tpl->setCurrentBLock("CHECK_INHERIT");
01875                                 $this->tpl->setVariable("CHECK_INHERITANCE",$data["check_inherit"][$num]);
01876                                 $this->tpl->parseCurrentBlock();
01877                         }
01878 
01879                         $num++;
01880                 }
01881 
01882                 // save num for required column span and the end of parsing
01883                 $colspan = $num + 1;
01884                 $num = 0;
01885 
01886                 // offer option 'stop inheritance' only to those objects where this option is permitted
01887                 if ($this->objDefinition->stopInheritance($this->type))
01888                 {
01889                         $this->tpl->setCurrentBLock("STOP_INHERIT");
01890                         $this->tpl->setVariable("TXT_STOP_INHERITANCE", $this->lng->txt("stop_inheritance"));
01891                         $this->tpl->parseCurrentBlock();
01892                 }
01893 
01894                 foreach ($data["permission"] as $ar_perm)
01895                 {
01896                         foreach ($ar_perm["values"] as $box)
01897                         {
01898                                 // BEGIN TABLE CHECK PERM
01899                                 $this->tpl->setCurrentBlock("CHECK_PERM");
01900                                 $this->tpl->setVariable("CHECK_PERMISSION",$box);
01901                                 $this->tpl->parseCurrentBlock();
01902                                 // END CHECK PERM
01903                         }
01904 
01905                         // BEGIN TABLE DATA OUTER
01906                         $this->tpl->setCurrentBlock("TABLE_DATA_OUTER");
01907                         $css_row = ilUtil::switchColor($num++, "tblrow1", "tblrow2");
01908                         $this->tpl->setVariable("CSS_ROW",$css_row);
01909                         $this->tpl->setVariable("PERMISSION", $this->lng->txt($this->object->getType()."_".$ar_perm["name"]));
01910                         if (substr($ar_perm["name"], 0, 7) == "create_")
01911                         {
01912                                 if ($this->objDefinition->getDevMode(substr($ar_perm["name"], 7, strlen($ar_perm["name"]) -7)))
01913                                 {
01914                                         $this->tpl->setVariable("TXT_NOT_IMPL", "(".$this->lng->txt("not_implemented_yet").")");
01915                                 }
01916                         }
01917                         $this->tpl->parseCurrentBlock();
01918                         // END TABLE DATA OUTER
01919                 }
01920 
01921                 // ADD LOCAL ROLE
01922                 
01923                 // do not display this option for admin section and root node
01924                 $object_types_exclude = array("adm","root","mail","usrf","objf","lngf","trac","taxf","auth", "assf");
01925 
01926                 if (!in_array($this->object->getType(),$object_types_exclude) and $this->object->getRefId() != ROLE_FOLDER_ID)
01927                 //if ($this->object->getRefId() != ROLE_FOLDER_ID and $rbacsystem->checkAccess('create_role',$this->object->getRefId()))
01928                 {
01929                         $this->tpl->setCurrentBlock("LOCAL_ROLE");
01930 
01931                         // fill in saved values in case of error
01932                         $data = array();
01933                         $data["fields"] = array();
01934                         $data["fields"]["title"] = $_SESSION["error_post_vars"]["Fobject"]["title"];
01935                         $data["fields"]["desc"] = $_SESSION["error_post_vars"]["Fobject"]["desc"];
01936 
01937                         foreach ($data["fields"] as $key => $val)
01938                         {
01939                                 $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
01940                                 $this->tpl->setVariable(strtoupper($key), $val);
01941                         }
01942 
01943                         $this->tpl->setVariable("FORMACTION_LR",$this->getFormAction("addRole", $this->ctrl->getLinkTarget($this, "addRole")));
01944 //                      $this->tpl->setVariable("FORMACTION_LR",$this->getFormAction("addRole", "adm_object.php?ref_id=".$_GET["ref_id"]."&cmd=addRole"));
01945                         $this->tpl->setVariable("TXT_HEADER", $this->lng->txt("you_may_add_local_roles"));
01946                         $this->tpl->setVariable("TXT_ADD_ROLE", $this->lng->txt("role_add_local"));
01947                         $this->tpl->setVariable("TARGET", $this->getTargetFrame("addRole"));
01948                         $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
01949                         $this->tpl->parseCurrentBlock();
01950                 }
01951 //vd($this->link_params);
01952 
01953                 // PARSE BLOCKFILE
01954                 $this->tpl->setCurrentBlock("adm_content");
01955                 $this->tpl->setVariable("FORMACTION",
01956                         $this->getFormAction("permSave",$this->ctrl->getLinkTarget($this,"permSave")));
01957 //              $this->tpl->setVariable("FORMACTION",
01958 //                      $this->getFormAction("permSave","adm_object.php?".$this->link_params."&cmd=permSave"));
01959                 $this->tpl->setVariable("TXT_SAVE", $this->lng->txt("save"));
01960                 $this->tpl->setVariable("COL_ANZ",$colspan);
01961                 $this->tpl->parseCurrentBlock();
01962         }
01963 
01972         function getFormAction($a_cmd, $a_formaction ="")
01973         {
01974                 if ($this->formaction[$a_cmd] != "")
01975                 {
01976                         return $this->formaction[$a_cmd];
01977                 }
01978                 else
01979                 {
01980                         return $a_formaction;
01981                 }
01982         }
01983 
01992         function setFormAction($a_cmd, $a_formaction)
01993         {
01994                 $this->formaction[$a_cmd] = $a_formaction;
01995         }
01996 
02004         function getReturnLocation($a_cmd, $a_location ="")
02005         {
02006                 if ($this->return_location[$a_cmd] != "")
02007                 {
02008                         return $this->return_location[$a_cmd];
02009                 }
02010                 else
02011                 {
02012                         return $a_location;
02013                 }
02014         }
02015 
02023         function setReturnLocation($a_cmd, $a_location)
02024         {
02025                 $this->return_location[$a_cmd] = $a_location;
02026         }
02027 
02035         function getTargetFrame($a_cmd, $a_target_frame = "")
02036         {
02037                 if ($this->target_frame[$a_cmd] != "")
02038                 {
02039                         return $this->target_frame[$a_cmd];
02040                 }
02041                 elseif (!empty($a_target_frame))
02042                 {
02043                         return "target=\"".$a_target_frame."\"";
02044                 }
02045                 else
02046                 {
02047                         return;
02048                 }
02049         }
02050 
02058         function setTargetFrame($a_cmd, $a_target_frame)
02059         {
02060                 $this->target_frame[$a_cmd] = "target=\"".$a_target_frame."\"";
02061         }
02062 
02068         function permSaveObject()
02069         {
02070                 global $rbacsystem, $rbacreview, $rbacadmin;
02071 
02072                 // first save the new permission settings for all roles
02073                 $rbacadmin->revokePermission($this->ref_id);
02074 
02075                 if (is_array($_POST["perm"]))
02076                 {
02077                         foreach ($_POST["perm"] as $key => $new_role_perms)
02078                         {
02079                                 // $key enthaelt die aktuelle Role_Id
02080                                 $rbacadmin->grantPermission($key,$new_role_perms,$this->ref_id);
02081                         }
02082                 }
02083 
02084                 // update object data entry (to update last modification date)
02085                 $this->object->update();
02086 
02087                 // Wenn die Vererbung der Rollen Templates unterbrochen werden soll,
02088                 // muss folgendes geschehen:
02089                 // - existiert kein RoleFolder, wird er angelegt und die Rechte aus den Permission Templates ausgelesen
02090                 // - existiert die Rolle im aktuellen RoleFolder werden die Permission Templates dieser Rolle angezeigt
02091                 // - existiert die Rolle nicht im aktuellen RoleFolder wird sie dort angelegt
02092                 //   und das Permission Template an den Wert des nihst hher gelegenen Permission Templates angepasst
02093 
02094                 // get rolefolder data if a rolefolder already exists
02095                 $rolf_data = $rbacreview->getRoleFolderOfObject($this->ref_id);
02096                 $rolf_id = $rolf_data["child"];
02097 
02098                 if ($_POST["stop_inherit"])
02099                 {
02100                         // rolefolder does not exist, so create one
02101                         if (empty($rolf_id))
02102                         {
02103                                 // create a local role folder
02104                                 $rfoldObj = $this->object->createRoleFolder();
02105 
02106                                 // set rolf_id again from new rolefolder object
02107                                 $rolf_id = $rfoldObj->getRefId();
02108                         }
02109 
02110                         // CHECK ACCESS 'write' of role folder
02111                         if (!$rbacsystem->checkAccess('write',$rolf_id))
02112                         {
02113                                 $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->WARNING);
02114                         }
02115 
02116                         foreach ($_POST["stop_inherit"] as $stop_inherit)
02117                         {
02118                                 $roles_of_folder = $rbacreview->getRolesOfRoleFolder($rolf_id);
02119 
02120                                 // create role entries for roles with stopped inheritance
02121                                 if (!in_array($stop_inherit,$roles_of_folder))
02122                                 {
02123                                         $parentRoles = $rbacreview->getParentRoleIds($rolf_id);
02124                                         $rbacadmin->copyRolePermission($stop_inherit,$parentRoles[$stop_inherit]["parent"],
02125                                                                                                    $rolf_id,$stop_inherit);
02126                                         $rbacadmin->assignRoleToFolder($stop_inherit,$rolf_id,'n');
02127                                 }
02128                         }// END FOREACH
02129                 }// END STOP INHERIT
02130                 elseif  (!empty($rolf_id))
02131                 {
02132                         // TODO: this feature doesn't work at the moment
02133                         // ok. if the rolefolder is not empty, delete the local roles
02134                         //if (!empty($roles_of_folder = $rbacreview->getRolesOfRoleFolder($rolf_data["ref_id"])));
02135                         //{
02136                                 //foreach ($roles_of_folder as $obj_id)
02137                                 //{
02138                                         //$rolfObj =& $this->ilias->obj_factory->getInstanceByRefId($rolf_data["child"]);
02139                                         //$rolfObj->delete();
02140                                         //unset($rolfObj);
02141                                 //}
02142                         //}
02143                 }
02144 
02145                 sendinfo($this->lng->txt("saved_successfully"),true);
02146                 ilUtil::redirect($this->getReturnLocation("permSave",$this->ctrl->getLinkTarget($this,"perm")));
02147         }
02148 
02154         function ownerObject()
02155         {
02156                 $this->getTemplateFile("owner");
02157                 $this->tpl->setVariable("OWNER_NAME", $this->object->getOwnerName());
02158                 $this->tpl->setVariable("TXT_OBJ_OWNER", $this->lng->txt("obj_owner"));
02159                 $this->tpl->setVariable("CMD","update");
02160                 $this->tpl->parseCurrentBlock();
02161         }
02162 
02168         function displayList()
02169         {
02170                 include_once "./classes/class.ilTableGUI.php";
02171 
02172                 // load template for table
02173                 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
02174                 // load template for table content data
02175                 $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.obj_tbl_rows.html");
02176 
02177                 $num = 0;
02178 
02179                 $obj_str = ($this->call_by_reference) ? "" : "&obj_id=".$this->obj_id;
02180                 $this->tpl->setVariable("FORMACTION", "adm_object.php?ref_id=".$this->ref_id."$obj_str&cmd=gateway");
02181 
02182                 // create table
02183                 $tbl = new ilTableGUI();
02184 
02185                 // title & header columns
02186                 $tbl->setTitle($this->object->getTitle(),"icon_".$this->object->getType()."_b.gif",
02187                                            $this->lng->txt("obj_".$this->object->getType()));
02188                 $tbl->setHelp("tbl_help.php","icon_help.gif",$this->lng->txt("help"));
02189 
02190                 foreach ($this->data["cols"] as $val)
02191                 {
02192                         $header_names[] = $this->lng->txt($val);
02193                 }
02194 
02195                 $tbl->setHeaderNames($header_names);
02196 
02197                 $header_params = array("ref_id" => $this->ref_id);
02198                 $tbl->setHeaderVars($this->data["cols"],$header_params);
02199                 $tbl->setColumnWidth(array("15","15","75%","25%"));
02200 
02201                 // control
02202                 $tbl->setOrderColumn($_GET["sort_by"]);
02203                 $tbl->setOrderDirection($_GET["sort_order"]);
02204                 $tbl->setLimit($_GET["limit"]);
02205                 $tbl->setOffset($_GET["offset"]);
02206                 $tbl->setMaxCount($this->maxcount);
02207 
02208                 $this->tpl->setVariable("COLUMN_COUNTS",count($this->data["cols"]));
02209 
02210                 // footer
02211                 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
02212 
02213                 $this->showActions(true);
02214 
02215                 if (!empty($this->data["data"][0]))
02216                 {
02217                         //table cell
02218                         for ($i=0; $i < count($this->data["data"]); $i++)
02219                         {
02220                                 $data = $this->data["data"][$i];
02221                                 $ctrl = $this->data["ctrl"][$i];
02222 
02223                                 // color changing
02224                                 $css_row = ilUtil::switchColor($i+1,"tblrow1","tblrow2");
02225 
02226                                 // surpress checkbox for particular object types AND the system role
02227                                 if (!$this->objDefinition->hasCheckbox($ctrl["type"]) or $ctrl["obj_id"] == SYSTEM_ROLE_ID or $ctrl["obj_id"] == SYSTEM_USER_ID or $ctrl["obj_id"] == ANONYMOUS_ROLE_ID)
02228                                 {
02229                                         $this->tpl->touchBlock("empty_cell");
02230                                 }
02231                                 else
02232                                 {
02233                                         // TODO: this object type depending 'if' could become really a problem!!
02234                                         if ($ctrl["type"] == "usr" or $ctrl["type"] == "role" or $ctrl["type"] == "rolt")
02235                                         {
02236                                                 $link_id = $ctrl["obj_id"];
02237                                         }
02238                                         else
02239                                         {
02240                                                 $link_id = $ctrl["ref_id"];
02241                                         }
02242         
02243                                         $this->tpl->setCurrentBlock("checkbox");
02244                                         $this->tpl->setVariable("CHECKBOX_ID", $link_id);
02245                                         $this->tpl->setVariable("CSS_ROW", $css_row);
02246                                         $this->tpl->parseCurrentBlock();
02247                                 }
02248 
02249                                 $this->tpl->setCurrentBlock("table_cell");
02250                                 $this->tpl->setVariable("CELLSTYLE", "tblrow1");
02251                                 $this->tpl->parseCurrentBlock();
02252 
02253                                 foreach ($data as $key => $val)
02254                                 {
02255                                         //build link
02256                                         $link = "adm_object.php?";
02257 
02258                                         $n = 0;
02259 
02260                                         foreach ($ctrl as $key2 => $val2)
02261                                         {
02262                                                 $link .= $key2."=".$val2;
02263 
02264                                                 if ($n < count($ctrl)-1)
02265                                                 {
02266                                                 $link .= "&";
02267                                                         $n++;
02268                                                 }
02269                                         }
02270 
02271                                         if ($key == "name" || $key == "title")
02272                                         {
02273                                                 $name_field = explode("#separator#",$val);
02274                                         }
02275 
02276                                         if ($key == "title" || $key == "name" || $key == "type")
02277                                         {
02278                                                 $this->tpl->setCurrentBlock("begin_link");
02279                                                 $this->tpl->setVariable("LINK_TARGET", $link);
02280 
02281                                                 $this->tpl->parseCurrentBlock();
02282                                                 $this->tpl->touchBlock("end_link");
02283                                         }
02284 
02285                                         // process clipboard information
02286                                         if (($key == "title" || $key == "name") and isset($_SESSION["clipboard"]))
02287                                         {
02288                                                 // TODO: broken! fix me
02289                                                 if (in_array($ctrl["ref_id"],$_SESSION["clipboard"]["ref_ids"]))
02290                                                 {
02291                             switch($_SESSION["clipboard"]["cmd"])
02292                                                         {
02293                                 case "cut":
02294                                     $name_field[0] = "<del>".$name_field[0]."</del>";
02295                                     break;
02296 
02297                                 case "copy":
02298                                     $name_field[0] = "<font color=\"green\">+</font>  ".$name_field[0];
02299                                     break;
02300                                         
02301                                 case "link":
02302                                     $name_field[0] = "<font color=\"black\"><</font> ".$name_field[0];
02303                                     break;
02304                             }
02305                                         }
02306                                 }
02307 
02308                                         $this->tpl->setCurrentBlock("text");
02309 
02310                                         if ($key == "type")
02311                                         {
02312                                                 $val = ilUtil::getImageTagByType($val,$this->tpl->tplPath);
02313                                         }
02314 
02315                                         if ($key == "name" || $key == "title")
02316                                         {
02317                                                 $this->tpl->setVariable("TEXT_CONTENT", $name_field[0]);
02318                                                 
02319                                                 $this->tpl->setCurrentBlock("subtitle");
02320                                                 $this->tpl->setVariable("DESC", $name_field[1]);
02321                                                 $this->tpl->parseCurrentBlock();
02322                                         }
02323                                         else
02324                                         {
02325                                                 $this->tpl->setVariable("TEXT_CONTENT", $val);
02326                                         }
02327                                         
02328                                         $this->tpl->parseCurrentBlock();
02329 
02330                                         $this->tpl->setCurrentBlock("table_cell");
02331                                         $this->tpl->parseCurrentBlock();
02332 
02333                                 } //foreach
02334 
02335                                 $this->tpl->setCurrentBlock("tbl_content");
02336                                 $this->tpl->setVariable("CSS_ROW", $css_row);
02337                                 $this->tpl->parseCurrentBlock();
02338                         } //for
02339                 } //if is_array
02340                 else
02341                 {
02342             $tbl->disable("header");
02343                         $tbl->disable("footer");
02344                         
02345                         $this->tpl->setCurrentBlock("text");
02346                         $this->tpl->setVariable("TEXT_CONTENT", $this->lng->txt("obj_not_found"));
02347                         $this->tpl->parseCurrentBlock();
02348                 }
02349                 
02350                 // render table
02351                 $tbl->render();
02352         }
02353 
02359         function viewObject()
02360         {
02361                 global $rbacsystem;
02362 
02363                 if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
02364                 {
02365                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
02366                 }
02367 
02368                 //prepare objectlist
02369                 $this->objectList = array();
02370                 $this->data["data"] = array();
02371                 $this->data["ctrl"] = array();
02372                 $this->data["cols"] = array("", "type", "title", "last_change");
02373 
02374                 $childs = $this->tree->getChilds($_GET["ref_id"], $_GET["order"], $_GET["direction"]);
02375 
02376                 foreach ($childs as $key => $val)
02377             {
02378                         // visible
02379                         if (!$rbacsystem->checkAccess("visible",$val["ref_id"]))
02380                         {
02381                                 continue;
02382                         }
02383                         
02384                         // hide object types in devmode
02385                         if ($this->objDefinition->getDevMode($val["type"]))
02386                         {
02387                                 continue;
02388                         }
02389 
02390                         //visible data part
02391                         $this->data["data"][] = array(
02392                                                                                 "type" => $val["type"],
02393                                                                                 "title" => $val["title"]."#separator#".$val["desc"],
02394                                                                                 //"description" => $val["desc"],
02395                                                                                 "last_change" => $val["last_update"],
02396                                                                                 "ref_id" => $val["ref_id"]
02397                                                                                 );
02398 
02399                         //control information is set below
02400 
02401             } //foreach
02402 
02403                 $this->maxcount = count($this->data["data"]);
02404                 // sorting array
02405                 $this->data["data"] = ilUtil::sortArray($this->data["data"],$_GET["sort_by"],$_GET["sort_order"]);
02406                 $this->data["data"] = array_slice($this->data["data"],$_GET["offset"],$_GET["limit"]);
02407 
02408                 // now compute control information
02409                 foreach ($this->data["data"] as $key => $val)
02410                 {
02411                         $this->data["ctrl"][$key] = array(
02412                                                                                         "type" => $val["type"],
02413                                                                                         "ref_id" => $val["ref_id"]
02414                                                                                         );
02415 
02416                         unset($this->data["data"][$key]["ref_id"]);
02417                                                 $this->data["data"][$key]["last_change"] = ilFormat::formatDate($this->data["data"][$key]["last_change"]);
02418                 }
02419 
02420                 $this->displayList();
02421         }
02422 
02430         function deleteObject($a_error = false)
02431         {
02432                 if (!isset($_POST["id"]))
02433                 {
02434                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
02435                 }
02436 
02437                 // SAVE POST VALUES
02438                 $_SESSION["saved_post"] = $_POST["id"];
02439 
02440                 unset($this->data);
02441                 $this->data["cols"] = array("type", "title", "last_change");
02442 
02443                 foreach ($_POST["id"] as $id)
02444                 {
02445                         // TODO: cannot distinguish between obj_id from ref_id with the posted IDs.
02446                         // change the form field and use instead of 'id' 'ref_id' and 'obj_id'. Then switch with varname
02447                         //if ($this->call_by_reference)
02448                         //{
02449                                 $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($id);
02450                         //}
02451                         //else
02452                         //{
02453                         //      $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($id);
02454                         //}
02455 
02456                         $this->data["data"]["$id"] = array(
02457                                                                                                 "type"        => $obj_data->getType(),
02458                                                                                                 "title"       => $obj_data->getTitle()."#separator#".$obj_data->getDescription()." ",   // workaround for empty desc
02459                                                                                                 "last_update" => $obj_data->getLastUpdateDate()
02460                                                                                         );
02461                 }
02462 
02463                 $this->data["buttons"] = array( "confirmedDelete"  => $this->lng->txt("confirm"),
02464                                                                   "cancelDelete"  => $this->lng->txt("cancel"));
02465 
02466                 $this->getTemplateFile("confirm");
02467 
02468                 if(!$a_error)
02469                 {
02470                         sendInfo($this->lng->txt("info_delete_sure"));
02471                 }
02472 
02473                 $this->tpl->setVariable("FORMACTION", $this->getFormAction("delete",
02474                         "adm_object.php?ref_id=".$_GET["ref_id"]."&cmd=gateway"));
02475         
02476                 // BEGIN TABLE HEADER
02477                 foreach ($this->data["cols"] as $key)
02478                 {
02479                         $this->tpl->setCurrentBlock("table_header");
02480                         $this->tpl->setVariable("TEXT",$this->lng->txt($key));
02481                         $this->tpl->parseCurrentBlock();
02482                 }
02483                 // END TABLE HEADER
02484 
02485                 // BEGIN TABLE DATA
02486                 $counter = 0;
02487 
02488                 foreach ($this->data["data"] as $key => $value)
02489                 {
02490                         // BEGIN TABLE CELL
02491                         foreach ($value as $key => $cell_data)
02492                         {
02493                                 $this->tpl->setCurrentBlock("table_cell");
02494 
02495                                 // CREATE TEXT STRING
02496                                 if ($key == "type")
02497                                 {
02498                                         $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($cell_data,$this->tpl->tplPath));
02499                                 }
02500                                 elseif ($key == "title")
02501                                 {
02502                                         $name_field = explode("#separator#",$cell_data);
02503 
02504                                         $this->tpl->setVariable("TEXT_CONTENT", "<b>".$name_field[0]."</b>");
02505                                                 
02506                                         $this->tpl->setCurrentBlock("subtitle");
02507                                         $this->tpl->setVariable("DESC", $name_field[1]);
02508                                         $this->tpl->parseCurrentBlock();
02509                                         $this->tpl->setCurrentBlock("table_cell");
02510                                 }
02511                                 else
02512                                 {
02513                                         $this->tpl->setVariable("TEXT_CONTENT",$cell_data);
02514                                 }
02515 
02516                                 $this->tpl->parseCurrentBlock();
02517                         }
02518 
02519                         $this->tpl->setCurrentBlock("table_row");
02520                         $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
02521                         $this->tpl->parseCurrentBlock();
02522                         // END TABLE CELL
02523                 }
02524                 // END TABLE DATA
02525 
02526                 // BEGIN OPERATION_BTN
02527                 foreach ($this->data["buttons"] as $name => $value)
02528                 {
02529                         $this->tpl->setCurrentBlock("operation_btn");
02530                         $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
02531                         $this->tpl->setVariable("BTN_NAME",$name);
02532                         $this->tpl->setVariable("BTN_VALUE",$value);
02533                         $this->tpl->parseCurrentBlock();
02534                 }
02535         }
02536 
02542         function trashObject()
02543         {
02544                 $objects = $this->tree->getSavedNodeData($_GET["ref_id"]);
02545 
02546                 if (count($objects) == 0)
02547                 {
02548                         sendInfo($this->lng->txt("msg_trash_empty"));
02549                         $this->data["empty"] = true;
02550                 }
02551                 else
02552                 {
02553                         $this->data["empty"] = false;
02554                         $this->data["cols"] = array("","type", "title", "last_change");
02555 
02556                         foreach ($objects as $obj_data)
02557                         {
02558                                 $this->data["data"]["$obj_data[child]"] = array(
02559                                                                                                                         "checkbox"              => "",
02560                                                                                                                         "type"                  => $obj_data["type"],
02561                                                                                                                         "title"                 => $obj_data["title"]."#separator#".$obj_data["desc"],
02562                                                                                                                         "last_update"   => $obj_data["last_update"]
02563                                                                         );
02564                         }
02565 
02566                         $this->data["buttons"] = array( "undelete"  => $this->lng->txt("btn_undelete"),
02567                                                                           "removeFromSystem"  => $this->lng->txt("btn_remove_system"));
02568                 }
02569 
02570                 $this->getTemplateFile("confirm");
02571 
02572                 if ($this->data["empty"] == true)
02573                 {
02574                         return;
02575                 }
02576                 
02577                 /* TODO: fix message display in conjunction with sendInfo & raiseError functionality
02578                 $this->tpl->addBlockfile("MESSAGE", "adm_trash", "tpl.message.html");
02579                 $this->tpl->setCurrentBlock("adm_trash");
02580                 $this->tpl->setVariable("MSG",$this->lng->txt("info_trash"));
02581                 $this->tpl->parseCurrentBlock();
02582                 */
02583                 //sendInfo($this->lng->txt("info_trash"));
02584 
02585                 $this->tpl->setVariable("FORMACTION", "adm_object.php?ref_id=".$_GET["ref_id"]."&cmd=gateway");
02586                 $this->tpl->setVariable("TPLPATH",$this->tpl->tplPath);
02587 
02588                 // BEGIN TABLE HEADER
02589                 foreach ($this->data["cols"] as $key)
02590                 {
02591                         $this->tpl->setCurrentBlock("table_header");
02592                         $this->tpl->setVariable("TEXT",$this->lng->txt($key));
02593                         $this->tpl->parseCurrentBlock();
02594                 }
02595                 // END TABLE HEADER
02596 
02597                 // BEGIN TABLE DATA
02598                 $counter = 0;
02599 
02600                 foreach ($this->data["data"] as $key1 => $value)
02601                 {
02602                         // BEGIN TABLE CELL
02603                         foreach ($value as $key2 => $cell_data)
02604                         {
02605                                 $this->tpl->setCurrentBlock("table_cell");
02606                                 // CREATE CHECKBOX
02607                                 if ($key2 == "checkbox")
02608                                 {
02609                                         $this->tpl->setVariable("TEXT_CONTENT",ilUtil::formCheckBox(0,"trash_id[]",$key1));
02610                                 }
02611                                 // CREATE TEXT STRING
02612                                 elseif ($key2 == "type")
02613                                 {
02614                                         $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($cell_data,$this->tpl->tplPath));
02615                                 }
02616                                 elseif ($key2 == "title")
02617                                 {
02618                                         $name_field = explode("#separator#",$cell_data);
02619 
02620                                         $this->tpl->setVariable("TEXT_CONTENT", "<b>".$name_field[0]."</b>");
02621                                                 
02622                                         $this->tpl->setCurrentBlock("subtitle");
02623                                         $this->tpl->setVariable("DESC", $name_field[1]);
02624                                         $this->tpl->parseCurrentBlock();
02625                                         $this->tpl->setCurrentBlock("table_cell");
02626                                 }
02627                                 else
02628                                 {
02629                                         $this->tpl->setVariable("TEXT_CONTENT",$cell_data);
02630                                 }
02631 
02632                                 $this->tpl->parseCurrentBlock();
02633                         }
02634 
02635                         $this->tpl->setCurrentBlock("table_row");
02636                         $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
02637                         $this->tpl->parseCurrentBlock();
02638                         // END TABLE CELL
02639                 }
02640                 // END TABLE DATA
02641 
02642                 // BEGIN OPERATION_BTN
02643                 foreach ($this->data["buttons"] as $name => $value)
02644                 {
02645                         $this->tpl->setCurrentBlock("operation_btn");
02646                         $this->tpl->setVariable("BTN_NAME",$name);
02647                         $this->tpl->setVariable("BTN_VALUE",$value);
02648                         $this->tpl->parseCurrentBlock();
02649                 }
02650         }
02651 
02659         function addRoleObject()
02660         {
02661                 global $rbacadmin, $rbacreview, $rbacsystem;
02662 
02663                 // first check if role title is unique
02664                 if ($rbacreview->roleExists($_POST["Fobject"]["title"]))
02665                 {
02666                         $this->ilias->raiseError($this->lng->txt("msg_role_exists1")." '".ilUtil::stripSlashes($_POST["Fobject"]["title"])."' ".
02667                                                                          $this->lng->txt("msg_role_exists2"),$this->ilias->error_obj->MESSAGE);
02668                 }
02669 
02670                 // check if role title has il_ prefix
02671                 if (substr($_POST["Fobject"]["title"],0,3) == "il_")
02672                 {
02673                         $this->ilias->raiseError($this->lng->txt("msg_role_reserved_prefix"),$this->ilias->error_obj->MESSAGE);
02674                 }
02675 
02676                 // if the current object is no role folder, create one
02677                 if ($this->object->getType() != "rolf")
02678                 {
02679                         $rolf_data = $rbacreview->getRoleFolderOfObject($this->ref_id);
02680 
02681                         // is there already a rolefolder?
02682                         if (!($rolf_id = $rolf_data["child"]))
02683                         {
02684                                 // can the current object contain a rolefolder?
02685                                 $subobjects = $this->objDefinition->getSubObjects($this->object->getType());
02686 
02687                                 if (!isset($subobjects["rolf"]))
02688                                 {
02689                                         $this->ilias->raiseError($this->lng->txt("msg_no_rolf_allowed1")." '".$this->object->getTitle()."' ".
02690                                                                                         $this->lng->txt("msg_no_rolf_allowed2"),$this->ilias->error_obj->WARNING);
02691                                 }
02692 
02693                                 // CHECK ACCESS 'create' rolefolder
02694                                 if (!$rbacsystem->checkAccess('create',$this->ref_id,'rolf'))
02695                                 {
02696                                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_create_rolf"),$this->ilias->error_obj->WARNING);
02697                                 }
02698 
02699                                 // create a rolefolder
02700                                 $rolfObj = $this->object->createRoleFolder();
02701                                 $rolf_id = $rolfObj->getRefId();
02702                         }
02703                 }
02704                 else
02705                 {
02706                         // Current object is already a rolefolder. To create the role we take its reference id
02707                         $rolf_id = $this->object->getRefId();
02708                 }
02709 
02710                 // CHECK ACCESS 'write' of role folder
02711                 if (!$rbacsystem->checkAccess('write',$rolf_id))
02712                 {
02713                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->WARNING);
02714                 }
02715                 else    // create role
02716                 {
02717                         if ($this->object->getType() == "rolf")
02718                         {
02719                                 $roleObj = $this->object->createRole($_POST["Fobject"]["title"],$_POST["Fobject"]["desc"]);
02720                         }
02721                         else
02722                         {
02723                                 $rfoldObj = $this->ilias->obj_factory->getInstanceByRefId($rolf_id);
02724                                 $roleObj = $rfoldObj->createRole($_POST["Fobject"]["title"],$_POST["Fobject"]["desc"]);
02725                         }
02726                 }
02727 
02728                 sendInfo($this->lng->txt("role_added"),true);
02729                 
02730                 if ($this->ctrl->getTargetScript() != "repository.php")
02731                 {
02732                         $this->ctrl->setParameter($this,"obj_id",$roleObj->getId());
02733                         $this->ctrl->setParameter($this,"ref_id",$rolf_id);
02734                         ilUtil::redirect($this->getReturnLocation("addRole",$this->ctrl->getLinkTarget($this,"perm")));
02735                 }
02736 
02737                 ilUtil::redirect($this->getReturnLocation("addRole",$this->ctrl->getLinkTarget($this,"perm")));
02738         }
02739 
02746         function showActions($with_subobjects = false)
02747         {
02748                 $notoperations = array();
02749                 // NO PASTE AND CLEAR IF CLIPBOARD IS EMPTY
02750                 if (empty($_SESSION["clipboard"]))
02751                 {
02752                         $notoperations[] = "copy";                      // disable copy operation!
02753                         $notoperations[] = "paste";
02754                         $notoperations[] = "clear";
02755                 }
02756                 // CUT COPY PASTE LINK DELETE IS NOT POSSIBLE IF CLIPBOARD IS FILLED
02757                 if ($_SESSION["clipboard"])
02758                 {
02759                         $notoperations[] = "cut";
02760                         $notoperations[] = "copy";
02761                         $notoperations[] = "link";
02762                 }
02763 
02764                 $operations = array();
02765 
02766                 if ($this->actions == "")
02767                 {
02768                         $d = $this->objDefinition->getActions($_GET["type"]);
02769                 }
02770                 else
02771                 {
02772                         $d = $this->actions;
02773                 }
02774 
02775                 foreach ($d as $row)
02776                 {
02777                         if (!in_array($row["name"], $notoperations))
02778                         {
02779                                 $operations[] = $row;
02780                         }
02781                 }
02782 
02783                 if (count($operations) > 0)
02784                 {
02785                         foreach ($operations as $val)
02786                         {
02787                                 $this->tpl->setCurrentBlock("tbl_action_btn");
02788                                 $this->tpl->setVariable("BTN_NAME", $val["name"]);
02789                                 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt($val["lng"]));
02790                                 $this->tpl->parseCurrentBlock();
02791                         }
02792                 }
02793 
02794                 if ($with_subobjects === true)
02795                 {
02796                         $this->showPossibleSubObjects();
02797                 }
02798                 
02799                 $this->tpl->setCurrentBlock("tbl_action_row");
02800                 $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
02801                 $this->tpl->parseCurrentBlock();
02802         }
02803 
02809         function showPossibleSubObjects()
02810         {
02811                 if ($this->sub_objects == "")
02812                 {
02813                         $d = $this->objDefinition->getCreatableSubObjects($_GET["type"]);
02814                 }
02815                 else
02816                 {
02817                         $d = $this->sub_objects;
02818                 }
02819 
02820                 $import = false;
02821 
02822                 if (count($d) > 0)
02823                 {
02824                         foreach ($d as $row)
02825                         {
02826                             $count = 0;
02827 
02828                                 if ($row["max"] > 0)
02829                                 {
02830                                         //how many elements are present?
02831                                         for ($i=0; $i<count($this->data["ctrl"]); $i++)
02832                                         {
02833                                                 if ($this->data["ctrl"][$i]["type"] == $row["name"])
02834                                                 {
02835                                                     $count++;
02836                                                 }
02837                                         }
02838                                 }
02839 
02840                                 if ($row["max"] == "" || $count < $row["max"])
02841                                 {
02842                                         $subobj[] = $row["name"];
02843 
02844                                         if ($row["import"] == "1")      // import allowed?
02845                                         {
02846                                                 $import = true;
02847                                         }
02848                                 }
02849                         }
02850                 }
02851 
02852                 if (is_array($subobj))
02853                 {
02854                         // show import button if at least one
02855                         // object type can be imported
02856                         if ($import)
02857                         {
02858                                 $this->tpl->setCurrentBlock("import_object");
02859                                 $this->tpl->setVariable("BTN_IMP", "import");
02860                                 $this->tpl->setVariable("TXT_IMP", $this->lng->txt("import"));
02861                                 $this->tpl->parseCurrentBlock();
02862                         }
02863 
02864                         //build form
02865                         $opts = ilUtil::formSelect(12,"new_type",$subobj);
02866                         $this->tpl->setCurrentBlock("add_object");
02867                         $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
02868                         $this->tpl->setVariable("BTN_NAME", "create");
02869                         $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
02870                         $this->tpl->parseCurrentBlock();
02871                 }
02872         }
02873 
02882         function getTemplateFile($a_cmd,$a_type = "")
02883         {
02884                 if (!$a_type)
02885                 {
02886                         $a_type = $this->type;
02887                 }
02888 
02889                 $template = "tpl.".$a_type."_".$a_cmd.".html";
02890 
02891                 if (!$this->tpl->fileExists($template))
02892                 {
02893                         $template = "tpl.obj_".$a_cmd.".html";
02894                 }
02895                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", $template,$a_in_module);
02896 
02897         }
02898 
02907         function getTitlesByRefId($a_ref_ids)
02908         {
02909                 foreach ($a_ref_ids as $id)
02910                 {
02911                         // GET OBJECT TITLE
02912                         $tmp_obj =& $this->ilias->obj_factory->getInstanceByRefId($id);
02913                         $title[] = $tmp_obj->getTitle();
02914                         unset($tmp_obj);
02915                 }
02916 
02917                 return $title ? $title : array();
02918         }
02919         
02927         function getTabs(&$tabs_gui)
02928         {
02929                 // please define your tabs here
02930         }
02931 
02932         function __showButton($a_cmd,$a_text,$a_target = '')
02933         {
02934                 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
02935                 
02936                 // display button
02937                 $this->tpl->setCurrentBlock("btn_cell");
02938                 $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,$a_cmd));
02939                 $this->tpl->setVariable("BTN_TXT",$a_text);
02940                 if($a_target)
02941                 {
02942                         $this->tpl->setVariable("BTN_TARGET",$a_target);
02943                 }
02944 
02945                 $this->tpl->parseCurrentBlock();
02946         }
02947 
02948         function hitsperpageObject()
02949         {
02950         $_SESSION["tbl_limit"] = $_POST["hitsperpage"];
02951         $_GET["limit"] = $_POST["hitsperpage"];
02952         }
02953         
02959         function clipboardObject()
02960         {
02961                 global $ilErr,$ilLog;
02962 
02963                 // function should not be called if clipboard is empty
02964                 if (empty($_SESSION['il_rep_clipboard']) or !is_array($_SESSION['il_rep_clipboard']))
02965                 {
02966                         $message = sprintf('%s::clipboardObject(): Illegal access. Clipboard variable is empty!', get_class($this));
02967                         $ilLog->write($message,$ilLog->FATAL);
02968                         $ilErr->raiseError($this->lng->txt("permission_denied"),$ilErr->WARNING);
02969                 }
02970                 
02971                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.rep_clipboard.html");
02972 
02973                 // FORMAT DATA
02974                 $counter = 0;
02975                 $f_result = array();
02976                 
02977                 foreach($_SESSION['il_rep_clipboard'] as $data)
02978                 {
02979                         if(!$tmp_obj = ilObjectFactory::getInstanceByRefId($data['ref_id'],false))
02980                         {
02981                                 continue;
02982                         }
02983 
02984                         //$f_result[$counter][] = ilUtil::formCheckbox(0,"user[]",$user);
02985                         $f_result[$counter][] = $this->lng->txt("obj_".$tmp_obj->getType());
02986                         $f_result[$counter][] = $tmp_obj->getTitle();
02987                         //$f_result[$counter][] = $tmp_obj->getDescription();
02988                         $f_result[$counter][] = ($data['act'] == 'cut') ? $this->lng->txt("move") :$this->lng->txt($data['act']);
02989 
02990                         unset($tmp_obj);
02991                         ++$counter;
02992                 }
02993 
02994                 $this->__showClipboardTable($f_result,"clipboardObject");
02995 
02996                 return true;
02997         }
02998         
02999         function &__initTableGUI()
03000         {
03001                 include_once "./classes/class.ilTableGUI.php";
03002 
03003                 return new ilTableGUI(0,false);
03004         }
03005         
03011         function __setTableGUIBasicData(&$tbl,&$result_set,$a_from = "")
03012         {
03013                 switch ($a_from)
03014                 {
03015                         case "clipboardObject":
03016                                 $offset = $_GET["offset"];
03017                                 $order = $_GET["sort_by"];
03018                                 $direction = $_GET["sort_order"];
03019                                 $tbl->disable("footer");
03020                                 break;
03021 
03022                         default:
03023                                 $offset = $_GET["offset"];
03024                                 $order = $_GET["sort_by"];
03025                                 $direction = $_GET["sort_order"];
03026                                 break;
03027                 }
03028 
03029                 $tbl->setOrderColumn($order);
03030                 $tbl->setOrderDirection($direction);
03031                 $tbl->setOffset($offset);
03032                 $tbl->setLimit($_GET["limit"]);
03033                 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
03034                 $tbl->setData($result_set);
03035         }
03036         
03037         function __showClipboardTable($a_result_set,$a_from = "")
03038         {
03039         $tbl =& $this->__initTableGUI();
03040                 $tpl =& $tbl->getTemplateObject();
03041 
03042                 $tpl->setCurrentBlock("tbl_form_header");
03043                 $tpl->setVariable("FORMACTION",$this->ctrl->getTargetScript()."?".$this->link_params."&cmd=post");
03044                 $tpl->parseCurrentBlock();
03045 
03046                 $tpl->setCurrentBlock("tbl_action_btn");
03047                 $tpl->setVariable("BTN_NAME","paste");
03048                 $tpl->setVariable("BTN_VALUE",$this->lng->txt("insert_object_here"));
03049                 $tpl->parseCurrentBlock();
03050                 
03051                 $tpl->setCurrentBlock("tbl_action_btn");
03052                 $tpl->setVariable("BTN_NAME","clear");
03053                 $tpl->setVariable("BTN_VALUE",$this->lng->txt("clear_clipboard"));
03054                 $tpl->parseCurrentBlock();
03055 
03056                 $tpl->setCurrentBlock("tbl_action_row");
03057                 $tpl->setVariable("COLUMN_COUNTS",3);
03058                 $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("spacer.gif"));
03059                 $tpl->parseCurrentBlock();
03060                 
03061                 $tbl->setTitle($this->lng->txt("clipboard"),"icon_typ_b.gif",$this->lng->txt("clipboard"));
03062                 $tbl->setHeaderNames(array($this->lng->txt('obj_type'),
03063                                                                    $this->lng->txt('title'),
03064                                                                    $this->lng->txt('action')));
03065                 $tbl->setHeaderVars(array('type',
03066                                   'title',
03067                                                                   'act'),
03068                                                         array('ref_id' => $this->object->getRefId(),
03069                                                                   'cmd' => 'clipboard',
03070                                                                   'cmdClass' => $_GET['cmdClass'],
03071                                                                   'cmdNode' => $_GET['cmdNode']));
03072 
03073                 $tbl->setColumnWidth(array("","80%","19%"));
03074 
03075 
03076                 $this->__setTableGUIBasicData($tbl,$a_result_set,$a_from);
03077                 $tbl->render();
03078                 
03079                 $this->tpl->setVariable("RESULT_TABLE",$tbl->tpl->get());
03080 
03081                 return true;
03082         }
03083 } // END class.ilObjectGUI
03084 ?>

Generated on Fri Dec 13 2013 08:00:14 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1