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

Generated on Fri Dec 13 2013 09:06:34 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1