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

classes/class.ilContainerGUI.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 
00038 require_once "class.ilObjectGUI.php";
00039 
00040 class ilContainerGUI extends ilObjectGUI
00041 {
00046         function ilContainerGUI($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
00047         {
00048                 global $rbacsystem;
00049 
00050                 $this->rbacsystem =& $rbacsystem;
00051 
00052                 $this->ilObjectGUI($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
00053         }
00054 
00058         function &executeCommand()
00059         {
00060                 $next_class = $this->ctrl->getNextClass();
00061                 $cmd = $this->ctrl->getCmd("render");
00062 //echo "-".$cmd."-";
00063                 switch($next_class)
00064                 {
00065                         default:
00066                                 $cmd .= "Object";
00067                                 $this->$cmd();
00068 
00069                                 break;
00070                 }
00071                 return true;
00072         }
00073 
00077 /*      This is currently implemented in ilRepositoryGUI for all containers
00078         and a conceptional issue whether it should be moved to this class.
00079         function showTreeObject()
00080         {
00081                 $this->tpl = new ilTemplate("tpl.main.html", true, true);
00082                 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
00083 
00084                 //$this->tpl = new ilTemplate("tpl.explorer.html", false, false);
00085                 $this->tpl->addBlockFile("CONTENT", "content", "tpl.explorer.html");
00086 
00087                 include_once ("classes/class.ilRepositoryExplorer.php");
00088                 $exp = new ilRepositoryExplorer("repository.php?cmd=goto");
00089                 $exp->setExpandTarget("repository.php?cmd=showTree&ref_id=".$this->object->getRefId());
00090                 $exp->setTargetGet("ref_id");
00091 
00092                 if ($_GET["repexpand"] == "")
00093                 {
00094                         $expanded = $this->tree->readRootId();
00095                 }
00096                 else
00097                 {
00098                         $expanded = $_GET["repexpand"];
00099                 }
00100 
00101                 $exp->setExpand($expanded);
00102 
00103                 // build html-output
00104                 $exp->setOutput(0);
00105                 $output = $exp->getOutput();
00106 
00107                 $this->tpl->setCurrentBlock("content");
00108                 $this->tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("repository"));
00109                 $this->tpl->setVariable("EXP_REFRESH", $this->lng->txt("refresh"));
00110                 $this->tpl->setVariable("EXPLORER", $output);
00111                 //$this->tpl->setVariable("ACTION", "repository.php?repexpand=".$_GET["repexpand"]);
00112                 $this->tpl->parseCurrentBlock();
00113                 $this->tpl->show(false);
00114                 exit;
00115         }
00116 */
00117 
00123         function renderObject()
00124         {
00125                 global $ilBench, $tree;
00126                 
00127                 
00128                 // course content interface methods could probably
00129                 // move to this class
00130                 if($this->type != 'icrs' and $tree->checkForParentType($this->ref_id,'crs'))
00131                 {
00132                         $this->initCourseContentInterface();
00133                         $this->cci_obj->cci_setContainer($this);
00134                         $this->cci_obj->cci_view();
00135                         
00136                         return;
00137                 }
00138 
00139 
00140                 $ilBench->start("ilContainerGUI", "0000__renderObject");
00141 
00142                 $tpl = new ilTemplate ("tpl.container_page.html", true, true);
00143                 
00144                 // get all sub items
00145                 $ilBench->start("ilContainerGUI", "0100_getSubItems");
00146                 $this->getSubItems();
00147                 $ilBench->stop("ilContainerGUI", "0100_getSubItems");
00148 
00149                 $ilBench->start("ilContainerGUI", "0200_renderItemList");
00150                 $html = $this->renderItemList();
00151                 $tpl->setVariable("CONTAINER_PAGE_CONTENT", $html);
00152                 $ilBench->stop("ilContainerGUI", "0200_renderItemList");
00153 
00154                 // this has to be more "generalized" (moved out of this method) if
00155                 // more list methods are implemented
00156                 if ($this->isActiveAdministrationPanel())
00157                 {
00158                         $tpl->setCurrentBlock("admin_button_off");
00159                         $tpl->setVariable("ADMIN_MODE_LINK",
00160                                 $this->ctrl->getLinkTarget($this, "disableAdministrationPanel"));
00161                         $tpl->setVariable("TXT_ADMIN_MODE",
00162                                 $this->lng->txt("admin_panel_disable"));
00163                         $tpl->parseCurrentBlock();
00164                         
00165                         // administration panel
00166                         $tpl->setCurrentBlock("admin_panel_cmd");
00167                         $tpl->setVariable("TXT_PANEL_CMD", $this->lng->txt("delete_selected_items"));
00168                         $tpl->setVariable("PANEL_CMD", "delete");
00169                         $tpl->parseCurrentBlock();
00170                         if (!$_SESSION["clipboard"])
00171                         {
00172                                 $tpl->setCurrentBlock("admin_panel_cmd");
00173                                 $tpl->setVariable("TXT_PANEL_CMD", $this->lng->txt("move_selected_items"));
00174                                 $tpl->setVariable("PANEL_CMD", "cut");
00175                                 $tpl->parseCurrentBlock();
00176                                 $tpl->setCurrentBlock("admin_panel_cmd");
00177                                 $tpl->setVariable("TXT_PANEL_CMD", $this->lng->txt("link_selected_items"));
00178                                 $tpl->setVariable("PANEL_CMD", "link");
00179                                 $tpl->parseCurrentBlock();
00180                         }
00181                         else
00182                         {
00183                                 $tpl->setCurrentBlock("admin_panel_cmd");
00184                                 $tpl->setVariable("TXT_PANEL_CMD", $this->lng->txt("paste_clipboard_items"));
00185                                 $tpl->setVariable("PANEL_CMD", "paste");
00186                                 $tpl->parseCurrentBlock();
00187                                 $tpl->setCurrentBlock("admin_panel_cmd");
00188                                 $tpl->setVariable("TXT_PANEL_CMD", $this->lng->txt("clear_clipboard"));
00189                                 $tpl->setVariable("PANEL_CMD", "clear");
00190                                 $tpl->parseCurrentBlock();
00191                         }
00192                         $tpl->setCurrentBlock("admin_panel");
00193                         $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00194                         $tpl->setVariable("TXT_ADMIN_PANEL", $this->lng->txt("admin_panel"));
00195                         $tpl->parseCurrentBlock();
00196                         $this->ctrl->setParameter($this, "type", "");
00197                         $this->ctrl->setParameter($this, "item_ref_id", "");
00198                         $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00199                 }
00200                 else if ($this->adminCommands)
00201                 {
00202                         $tpl->setCurrentBlock("admin_button");
00203                         $tpl->setVariable("ADMIN_MODE_LINK",
00204                                 $this->ctrl->getLinkTarget($this, "enableAdministrationPanel"));
00205                         $tpl->setVariable("TXT_ADMIN_MODE",
00206                                 $this->lng->txt("admin_panel_enable"));
00207                         $tpl->parseCurrentBlock();
00208                 }
00209 
00210                 $this->html = $tpl->get();
00211                 
00212                 $ilBench->stop("ilContainerGUI", "0000__renderObject");
00213         }
00214 
00218         function getSubItems()
00219         {
00220                 global $objDefinition, $ilBench;
00221 
00222                 $objects = $this->tree->getChilds($this->object->getRefId(), "title");
00223 
00224                 $found = false;
00225 
00226                 foreach ($objects as $key => $object)
00227                 {
00228 
00229                         // hide object types in devmode
00230                         if ($objDefinition->getDevMode($object["type"]))
00231                         {
00232                                 continue;
00233                         }
00234 
00235                         // group together types (e.g. ILIAS learning modules
00236                         // and SCORM learning modules to learning materials)
00237                         switch ($object["type"])
00238                         {
00239                                 // learning material
00240                                 case "sahs":
00241                                 case "lm":
00242                                 case "dbk":
00243                                 case "htlm":
00244                                         $type = "lres";
00245                                         break;
00246 
00247                                 default:
00248                                         $type = $object["type"];
00249                                         break;
00250                         }
00251 
00252                         $this->items[$type][$key] = $object;
00253                 }
00254         }
00255 
00256         function renderItemList($a_type = "all")
00257         {
00258                 global $objDefinition, $ilBench;
00259                 
00260                 include_once("classes/class.ilObjectListGUIFactory.php");
00261 
00262                 $html = "";
00263                 $this->adminCommands = false;
00264                 
00265                 switch ($a_type)
00266                 {
00267                         // render all items list
00268                         case "all":
00269 
00270                                 // to do: implement all types
00271                                 /*
00272                                 $type_ordering = array(
00273                                         "cat", "fold", "crs", "grp",
00274                                         "lres", "glo", "chat", "frm",
00275                                         "exc", "file", "mep", "qpl", "tst", "spl", "svy",
00276                                         "icrs", "icla", "webr"
00277                                 );*/
00278 
00279                                 // resource type ordering
00280                                 // (note that resource type is not equal object type,
00281                                 // the resource type "lres" contains the object types
00282                                 // "lm", "dbk", "sahs" and "htlm")
00283                                 $type_ordering = array(
00284                                         "cat", "fold", "crs", "icrs", "icla", "grp", "chat", "frm", "lres",
00285                                         "glo", "webr", "file", "exc",
00286                                         "tst", "svy", "mep", "qpl", "spl");
00287 
00288                                 $cur_obj_type = "";
00289                                 $tpl =& $this->newBlockTemplate();
00290                                 $first = true;
00291                                 foreach ($type_ordering as $type)
00292                                 {
00293                                         $item_html = array();
00294 
00295                                         if (is_array($this->items[$type]))
00296                                         {
00297                                                 foreach($this->items[$type] as $key => $item)
00298                                                 {
00299                                                         // get list gui class for each object type
00300                                                         if ($cur_obj_type != $item["type"])
00301                                                         {
00302                                                                 /*
00303                                                                 $class = $objDefinition->getClassName($item["type"]);
00304                                                                 $location = $objDefinition->getLocation($item["type"]);
00305                                                                 $full_class = "ilObj".$class."ListGUI";
00306                                                                 include_once($location."/class.".$full_class.".php");
00307                                                                 $item_list_gui = new $full_class();*/
00308                                                                 $item_list_gui =& ilObjectListGUIFactory::_getListGUIByType($item["type"]);
00309                                                                 $item_list_gui->setContainerObject($this);
00310                                                         }
00311                                                         // render item row
00312                                                         $ilBench->start("ilContainerGUI", "0210_getListHTML");
00313                                                         if (!$this->isActiveAdministrationPanel())
00314                                                         {
00315                                                                 $item_list_gui->enableDelete(false);
00316                                                                 $item_list_gui->enableLink(false);
00317                                                                 $item_list_gui->enableCut(false);
00318                                                         }
00319                                                         
00320                                                         $html = $item_list_gui->getListItemHTML($item["ref_id"],
00321                                                                 $item["obj_id"], $item["title"], $item["description"]);
00322                                                                 
00323                                                         // check wheter any admin command is allowed for
00324                                                         // the items
00325                                                         if (!$this->adminCommands)
00326                                                         {
00327                                                                 if (!$this->isActiveAdministrationPanel())
00328                                                                 {
00329                                                                         if ($this->rbacsystem->checkAccess("delete", $item["ref_id"]))
00330                                                                         {
00331                                                                                 $this->adminCommands = true;
00332                                                                         }
00333                                                                 }
00334                                                                 else
00335                                                                 {
00336                                                                         $this->adminCommands = $item_list_gui->adminCommandsIncluded();
00337                                                                 }
00338                                                         }
00339                                                         $ilBench->stop("ilContainerGUI", "0210_getListHTML");
00340                                                         if ($html != "")
00341                                                         {
00342                                                                 $item_html[] = array("html" => $html, "item_id" => $item["ref_id"]);
00343                                                         }
00344                                                 }
00345 
00346                                                 // output block for resource type
00347                                                 if (count($item_html) > 0)
00348                                                 {
00349                                                         // separator row
00350                                                         if (!$first)
00351                                                         {
00352                                                                 $this->addSeparatorRow($tpl);
00353                                                         }
00354                                                         $first = false;
00355 
00356                                                         // add a header for each resource type
00357                                                         $this->addHeaderRow($tpl, $type);
00358                                                         $this->resetRowType();
00359 
00360                                                         // content row
00361                                                         foreach($item_html as $item)
00362                                                         {
00363                                                                 $this->addStandardRow($tpl, $item["html"], $item["item_id"]);
00364                                                         }
00365                                                 }
00366                                         }
00367                                 }
00368                                 $html = $tpl->get();
00369                                 
00370                                 break;
00371 
00372                         default:
00373                                 // to do:
00374                                 break;
00375                 }
00376 
00377                 return $html;
00378         }
00379 
00386         function &newBlockTemplate()
00387         {
00388                 $tpl = new ilTemplate ("tpl.container_list_block.html", true, true);
00389                 $this->cur_row_type = "row_type_1";
00390                 return $tpl;
00391         }
00392 
00400         function addHeaderRow(&$a_tpl, $a_type)
00401         {
00402                 if ($a_type != "lres")
00403                 {
00404                         $icon = ilUtil::getImagePath("icon_".$a_type.".gif");
00405                         $title = $this->lng->txt("objs_".$a_type);
00406                 }
00407                 else
00408                 {
00409                         $icon = ilUtil::getImagePath("icon_lm.gif");
00410                         $title = $this->lng->txt("learning_resources");
00411                 }
00412                 $a_tpl->setCurrentBlock("container_header_row");
00413                 $a_tpl->setVariable("HEADER_IMG", $icon);
00414                 $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $title);
00415                 $a_tpl->parseCurrentBlock();
00416                 $a_tpl->touchBlock("container_row");
00417         }
00418 
00426         function addStandardRow(&$a_tpl, $a_html, $a_item_id = "")
00427         {
00428                 $this->cur_row_type = ($this->cur_row_type == "row_type_1")
00429                         ? "row_type_2"
00430                         : "row_type_1";
00431 
00432                 $a_tpl->touchBlock($this->cur_row_type);
00433                 
00434                 if ($this->isActiveAdministrationPanel())
00435                 {
00436                         $a_tpl->setCurrentBlock("block_row_check");
00437                         $a_tpl->setVariable("ITEM_ID", $a_item_id);
00438                         $a_tpl->parseCurrentBlock();
00439                 }
00440                 else
00441                 {
00442                         $a_tpl->setVariable("ROW_NBSP", "&nbsp;");
00443                 }
00444                 $a_tpl->setCurrentBlock("container_standard_row");
00445                 $a_tpl->setVariable("BLOCK_ROW_CONTENT", $a_html);
00446                 $a_tpl->parseCurrentBlock();
00447                 $a_tpl->touchBlock("container_row");
00448         }
00449 
00450         function resetRowType()
00451         {
00452                 $this->cur_row_type = "";
00453         }
00454 
00455         function addSeparatorRow(&$a_tpl)
00456         {
00457                 $a_tpl->touchBlock("separator_row");
00458                 $a_tpl->touchBlock("container_row");
00459         }
00460 
00465         function getTabs(&$tabs_gui)
00466         {
00467                 global $rbacsystem;
00468 
00469                 // edit permissions
00470                 if ($rbacsystem->checkAccess('edit_permission',$this->ref_id))
00471                 {
00472                         $tabs_gui->addTarget("perm_settings",
00473                                 $this->ctrl->getLinkTarget($this, "perm"), "perm", get_class($this));
00474                 }
00475 
00476                 // show clipboard
00477                 if ($this->ctrl->getTargetScript() == "repository.php" and !empty($_SESSION["clipboard"]))
00478                 {
00479                         $tabs_gui->addTarget("clipboard",
00480                                  $this->ctrl->getLinkTarget($this, "clipboard"), "clipboard", get_class($this));
00481                 }
00482 
00483                 if ($this->ctrl->getTargetScript() == "adm_object.php")
00484                 {
00485                         if ($this->tree->getSavedNodeData($this->ref_id))
00486                         {
00487                                 $tabs_gui->addTarget("trash",
00488                                          $this->ctrl->getLinkTarget($this, "trash"), "trash", get_class($this));
00489                         }
00490                 }
00491         }
00492 
00493         //*****************
00494         // COMMON METHODS (may be overwritten in derived classes
00495         // if special handling is necessary)
00496         //*****************
00497 
00501         function enableAdministrationPanelObject()
00502         {
00503                 $_SESSION["il_cont_admin_panel"] = true;
00504                 $this->ctrl->redirect($this, "render");
00505         }
00506 
00510         function disableAdministrationPanelObject()
00511         {
00512                 $_SESSION["il_cont_admin_panel"] = false;
00513                 $this->ctrl->redirect($this, "render");
00514         }
00515         
00519         function addToDeskObject()
00520         {
00521                 if ($_GET["item_ref_id"] and $_GET["type"])
00522                 {
00523                         $this->ilias->account->addDesktopItem($_GET["item_ref_id"], $_GET["type"]);
00524                 }
00525                 else
00526                 {
00527                         if ($_POST["items"])
00528                         {
00529                                 foreach ($_POST["items"] as $item)
00530                                 {
00531                                         $type = ilObject::_lookupType($item, true);
00532                                         $this->ilias->account->addDesktopItem($item, $type);
00533                                         unset($tmp_obj);
00534                                 }
00535                         }
00536                 }
00537                 $this->renderObject();
00538         }
00539 
00543         function removeFromDeskObject()
00544         {
00545                 if ($_GET["item_ref_id"] and $_GET["type"])
00546                 {
00547                         $this->ilias->account->dropDesktopItem($_GET["item_ref_id"], $_GET["type"]);
00548                 }
00549                 else
00550                 {
00551                         if ($_POST["items"])
00552                         {
00553                                 foreach ($_POST["items"] as $item)
00554                                 {
00555                                         $type = ilObject::_lookupType($item, true);
00556                                         $this->ilias->account->dropDesktopItem($item, $type);
00557                                         unset($tmp_obj);
00558                                 }
00559                         }
00560                 }
00561                 $this->renderObject();
00562         }
00563 
00564 
00571         function cutObject()
00572         {
00573                 global $rbacsystem;
00574 //echo "CUT";
00575 //echo $_SESSION["referer"];
00576                 if (!isset($_POST["id"]))
00577                 {
00578                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00579                 }
00580 
00581                 // FOR ALL OBJECTS THAT SHOULD BE COPIED
00582                 foreach ($_POST["id"] as $ref_id)
00583                 {
00584                         // GET COMPLETE NODE_DATA OF ALL SUBTREE NODES
00585                         $node_data = $this->tree->getNodeData($ref_id);
00586                         $subtree_nodes = $this->tree->getSubTree($node_data);
00587 
00588                         $all_node_data[] = $node_data;
00589                         $all_subtree_nodes[] = $subtree_nodes;
00590 
00591                         // CHECK DELETE PERMISSION OF ALL OBJECTS IN ACTUAL SUBTREE
00592                         foreach ($subtree_nodes as $node)
00593                         {
00594                                 if (!$rbacsystem->checkAccess('delete',$node["ref_id"]))
00595                                 {
00596                                         $no_cut[] = $node["ref_id"];
00597                                 }
00598                         }
00599                 }
00600                 // IF THERE IS ANY OBJECT WITH NO PERMISSION TO 'delete'
00601                 if (count($no_cut))
00602                 {
00603                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_cut")." ".implode(',',$this->getTitlesByRefId($no_cut)),
00604                                                                          $this->ilias->error_obj->MESSAGE);
00605                 }
00606                 //echo "GET";var_dump($_GET);echo "POST";var_dump($_POST);
00607                 $_SESSION["clipboard"]["parent"] = $_GET["ref_id"];
00608                 $_SESSION["clipboard"]["cmd"] = key($_POST["cmd"]);
00609                 $_SESSION["clipboard"]["ref_ids"] = $_POST["id"];
00610 //echo "-".$_SESSION["clipboard"]["cmd"]."-";
00611 
00612                 sendinfo($this->lng->txt("msg_cut_clipboard"),true);
00613 
00614                 ilUtil::redirect($this->getReturnLocation("cut","adm_object.php?ref_id=".$_GET["ref_id"]));
00615 
00616         } // END CUT
00617 
00618 
00625         function linkObject()
00626         {
00627                 global $clipboard, $rbacsystem, $rbacadmin;
00628 
00629                 if (!isset($_POST["id"]))
00630                 {
00631                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00632                 }
00633 
00634                 // CHECK ACCESS
00635                 foreach ($_POST["id"] as $ref_id)
00636                 {
00637                         if (!$rbacsystem->checkAccess('delete',$ref_id))
00638                         {
00639                                 $no_cut[] = $ref_id;
00640                         }
00641 
00642                         $object =& $this->ilias->obj_factory->getInstanceByRefId($ref_id);
00643 
00644                         if (!$this->objDefinition->allowLink($object->getType()))
00645                         {
00646                                 $no_link[] = $object->getType();
00647                         }
00648                 }
00649 
00650                 // NO ACCESS
00651                 if (count($no_cut))
00652                 {
00653                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_link")." ".
00654                                                                          implode(',',$no_cut),$this->ilias->error_obj->MESSAGE);
00655                 }
00656 
00657                 if (count($no_link))
00658                 {
00659                         $no_link = array_unique($no_link);
00660 
00661                         foreach ($no_link as $type)
00662                         {
00663                                 $txt_objs[] = $this->lng->txt("objs_".$type);
00664                         }
00665 
00666                         $this->ilias->raiseError(implode(', ',$txt_objs)." ".$this->lng->txt("msg_obj_no_link"),$this->ilias->error_obj->MESSAGE);
00667 
00668                         //$this->ilias->raiseError($this->lng->txt("msg_not_possible_link")." ".
00669                         //                                               implode(',',$no_link),$this->ilias->error_obj->MESSAGE);
00670                 }
00671 
00672                 // WRITE TO CLIPBOARD
00673                 $clipboard["parent"] = $_GET["ref_id"];
00674                 $clipboard["cmd"] = key($_POST["cmd"]);
00675 
00676                 foreach ($_POST["id"] as $ref_id)
00677                 {
00678                         $clipboard["ref_ids"][] = $ref_id;
00679                 }
00680 
00681                 $_SESSION["clipboard"] = $clipboard;
00682 
00683                 sendinfo($this->lng->txt("msg_link_clipboard"),true);
00684 
00685                 ilUtil::redirect($this->getReturnLocation("link","adm_object.php?ref_id=".$_GET["ref_id"]));
00686 
00687         } // END LINK
00688 
00689 
00695         function clearObject()
00696         {
00697                 unset($_SESSION["clipboard"]);
00698                 unset($_SESSION["il_rep_clipboard"]);
00699                 //var_dump($this->getReturnLocation("clear",$this->ctrl->getLinkTarget($this)),get_class($this));
00700 
00701                 // only redirect if clipboard was cleared
00702                 if (isset($_POST["cmd"]["clear"]))
00703                 {
00704                         sendinfo($this->lng->txt("msg_clear_clipboard"),true);
00705 
00706                         //ilUtil::redirect($this->getReturnLocation("clear","adm_object.php?ref_id=".$_GET["ref_id"]));
00707                         ilUtil::redirect($this->getReturnLocation("clear",$this->ctrl->getLinkTarget($this)),get_class($this));
00708                 }
00709         }
00710 
00717         function pasteObject()
00718         {
00719                 global $rbacsystem, $rbacadmin, $rbacreview, $log;
00720 
00721 //var_dump("adm",$_SESSION["clipboard"]);exit;
00722                 if (!in_array($_SESSION["clipboard"]["cmd"],array("cut","link","copy")))
00723                 {
00724                         $message = get_class($this)."::pasteObject(): cmd was neither 'cut','link' or 'copy'; may be a hack attempt!";
00725                         $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00726                 }
00727 
00728                 // this loop does all checks
00729                 foreach ($_SESSION["clipboard"]["ref_ids"] as $ref_id)
00730                 {
00731                         $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($ref_id);
00732 
00733                         // CHECK ACCESS
00734                         if (!$rbacsystem->checkAccess('create', $_GET["ref_id"], $obj_data->getType()))
00735                         {
00736                                 $no_paste[] = $ref_id;
00737                         }
00738 
00739                         // CHECK IF REFERENCE ALREADY EXISTS
00740                         if ($_GET["ref_id"] == $this->tree->getParentId($obj_data->getRefId()))
00741                         {
00742                                 $exists[] = $ref_id;
00743                                 break;
00744                         }
00745 
00746                         // CHECK IF PASTE OBJECT SHALL BE CHILD OF ITSELF
00747                         if ($this->tree->isGrandChild($ref_id,$_GET["ref_id"]))
00748                         {
00749                                 $is_child[] = $ref_id;
00750                         }
00751 
00752                         // CHECK IF OBJECT IS ALLOWED TO CONTAIN PASTED OBJECT AS SUBOBJECT
00753                         $obj_type = $obj_data->getType();
00754 
00755                         if (!in_array($obj_type, array_keys($this->objDefinition->getSubObjects($this->object->getType()))))
00756                         {
00757                                 $not_allowed_subobject[] = $obj_data->getType();
00758                         }
00759                 }
00760 
00762                 // process checking results
00763                 if (count($exists))
00764                 {
00765                         $this->ilias->raiseError($this->lng->txt("msg_obj_exists"),$this->ilias->error_obj->MESSAGE);
00766                 }
00767 
00768                 if (count($is_child))
00769                 {
00770                         $this->ilias->raiseError($this->lng->txt("msg_not_in_itself")." ".implode(',',$is_child),
00771                                                                          $this->ilias->error_obj->MESSAGE);
00772                 }
00773 
00774                 if (count($not_allowed_subobject))
00775                 {
00776                         $this->ilias->raiseError($this->lng->txt("msg_may_not_contain")." ".implode(',',$not_allowed_subobject),
00777                                                                          $this->ilias->error_obj->MESSAGE);
00778                 }
00779 
00780                 if (count($no_paste))
00781                 {
00782                         $this->ilias->raiseError($this->lng->txt("msg_no_perm_paste")." ".
00783                                                                          implode(',',$no_paste),$this->ilias->error_obj->MESSAGE);
00784                 }
00785 
00786                 // log pasteObject call
00787                 $log->write("ilObjectGUI::pasteObject(), cmd: ".$_SESSION["clipboard"]["cmd"]);
00788 
00790                 // everything ok: now paste the objects to new location
00791 
00792                 // to prevent multiple actions via back/reload button
00793                 $ref_ids = $_SESSION["clipboard"]["ref_ids"];
00794                 unset($_SESSION["clipboard"]["ref_ids"]);
00795 
00796                 // process COPY command
00797                 if ($_SESSION["clipboard"]["cmd"] == "copy")
00798                 {
00799                         // CALL PRIVATE CLONE METHOD
00800                         $this->cloneObject($ref_ids);
00801                 }
00802 
00803                 // process CUT command
00804                 if ($_SESSION["clipboard"]["cmd"] == "cut")
00805                 {
00806                         // get subtrees
00807                         foreach($ref_ids as $ref_id)
00808                         {
00809                                 // get node data
00810                                 $top_node = $this->tree->getNodeData($ref_id);
00811 
00812                                 // get subnodes of top nodes
00813                                 $subnodes[$ref_id] = $this->tree->getSubtree($top_node);
00814                         }
00815 
00816                         // STEP 1: Move all subtrees to trash
00817                         $log->write("ilObjectGUI::pasteObject(), (1/3) move subtrees to trash");
00818 
00819                         foreach($ref_ids as $ref_id)
00820                         {
00821                                 $tnodes = $this->tree->getSubtree($this->tree->getNodeData($ref_id));
00822 
00823                                 foreach ($tnodes as $tnode)
00824                                 {
00825                                         $rbacadmin->revokePermission($tnode["child"]);
00826                                         $affected_users = ilUtil::removeItemFromDesktops($tnode["child"]);
00827                                 }
00828 
00829                                 $this->tree->saveSubTree($ref_id);
00830                                 $this->tree->deleteTree($this->tree->getNodeData($ref_id));
00831                         }
00832 
00833 
00834                         // STEP 2: Move all subtrees to new location
00835                         $log->write("ilObjectGUI::pasteObject(), (2/3) move subtrees to new location");
00836 
00837                         // TODO: this whole put in place again stuff needs revision. Permission settings get lost.
00838                         foreach ($subnodes as $key => $subnode)
00839                         {
00840                                 // first paste top_node ...
00841                                 $rbacadmin->revokePermission($key);
00842                                 $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($key);
00843                                 $obj_data->putInTree($_GET["ref_id"]);
00844                                 $obj_data->setPermissions($key);
00845 
00846                                 // log entry
00847                                 $log->write("ilObjectGUI::pasteObject(), inserted top node. ref_id: $key,".
00848                                         " rgt: ".$subnode[0]["rgt"].", lft: ".$subnode[0]["lft"].", parent: ".$subnode[0]["parent"].",".
00849                                         " obj_id: ".$obj_data->getId().", type: ".$obj_data->getType().
00850                                         ", title: ".$obj_data->getTitle());
00851 
00852                                 // ... remove top_node from list ...
00853                                 array_shift($subnode);
00854 
00855                                 // ... insert subtree of top_node if any subnodes exist
00856                                 if (count($subnode) > 0)
00857                                 {
00858                                         foreach ($subnode as $node)
00859                                         {
00860                                                 $rbacadmin->revokePermission($node["child"]);
00861                                                 $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($node["child"]);
00862                                                 $obj_data->putInTree($node["parent"]);
00863                                                 $obj_data->setPermissions($node["parent"]);
00864 
00865                                                 // log entry
00866                                                 $log->write("ilObjectGUI::pasteObject(), inserted subnode. ref_id: ".$node["child"].",".
00867                                                         " rgt: ".$node["rgt"].", lft: ".$node["lft"].", parent: ".$node["parent"].",".
00868                                                         " obj_id: ".$obj_data->getId().", type: ".$obj_data->getType().
00869                                                         ", title: ".$obj_data->getTitle());
00870                                         }
00871                                 }
00872                         }
00873 
00874                         // STEP 3: Remove trashed objects from system
00875                         $log->write("ilObjectGUI::pasteObject(), (3/3) remove trashed subtrees from system");
00876 
00877                         foreach ($ref_ids as $ref_id)
00878                         {
00879                                 // GET COMPLETE NODE_DATA OF ALL SUBTREE NODES
00880                                 $saved_tree = new ilTree(-(int)$ref_id);
00881                                 $node_data = $saved_tree->getNodeData($ref_id);
00882                                 $subtree_nodes = $saved_tree->getSubTree($node_data);
00883 
00884                                 // remember already checked deleted node_ids
00885                                 $checked[] = -(int) $ref_id;
00886 
00887                                 // dive in recursive manner in each already deleted subtrees and remove these objects too
00888                                 $this->removeDeletedNodes($ref_id, $checked, false);
00889 
00890                                 // delete save tree
00891                                 $this->tree->deleteTree($node_data);
00892 
00893                                 // write log entry
00894                                 $log->write("ilObjectGUI::pasteObject(), deleted tree, tree_id: ".$node_data["tree"].
00895                                         ", child: ".$node_data["child"]);
00896                         }
00897 
00898 
00899                         $log->write("ilObjectGUI::pasteObject(), cut finished");
00900 
00901                         // inform other objects in hierarchy about paste operation
00902                         //$this->object->notify("paste",$this->object->getRefId(),$_SESSION["clipboard"]["parent_non_rbac_id"],$this->object->getRefId(),$subnodes);
00903 
00904                         // inform other objects in hierarchy about cut operation
00905                         // the parent object where cut occured
00906                         $tmp_object = $this->ilias->obj_factory->getInstanceByRefId($_SESSION["clipboard"]["parent"]);
00907                         //$tmp_object->notify("cut", $tmp_object->getRefId(),$_SESSION["clipboard"]["parent_non_rbac_id"],$tmp_object->getRefId(),$ref_ids);
00908                         unset($tmp_object);
00909                 } // END CUT
00910 
00911                 // process LINK command
00912                 if ($_SESSION["clipboard"]["cmd"] == "link")
00913                 {
00914                         foreach ($ref_ids as $ref_id)
00915                         {
00916                                 // get node data
00917                                 $top_node = $this->tree->getNodeData($ref_id);
00918 
00919                                 // get subnodes of top nodes
00920                                 $subnodes[$ref_id] = $this->tree->getSubtree($top_node);
00921                         }
00922 
00923                         // now move all subtrees to new location
00924                         foreach ($subnodes as $key => $subnode)
00925                         {
00926                                 // first paste top_node....
00927                                 $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($key);
00928                                 $new_ref_id = $obj_data->createReference();
00929                                 $obj_data->putInTree($_GET["ref_id"]);
00930                                 $obj_data->setPermissions($_GET["ref_id"]);
00931 
00932                                 // ... remove top_node from list ...
00933                                 array_shift($subnode);
00934 
00935                                 // ... store mapping of old ref_id => new_ref_id in hash array ...
00936                                 $mapping[$new_ref_id] = $key;
00937 
00938                                 // save old ref_id & create rolefolder if applicable
00939                                 $old_ref_id = $obj_data->getRefId();
00940                                 $obj_data->setRefId($new_ref_id);
00941                                 $obj_data->initDefaultRoles();
00942                                 $rolf_data = $rbacreview->getRoleFolderOfObject($obj_data->getRefId());
00943 
00944                                 if (isset($rolf_data["child"]))
00945                                 {
00946                                         // a role folder was created, so map it to old role folder
00947                                         $rolf_data_old = $rbacreview->getRoleFolderOfObject($old_ref_id);
00948 
00949                                         // ... use mapping array to find out the correct new parent node where to put in the node...
00950                                         //$new_parent = array_search($node["parent"],$mapping);
00951                                         // ... append node to mapping for further possible subnodes ...
00952                                         $mapping[$rolf_data["child"]] = (int) $rolf_data_old["child"];
00953 
00954                                         // log creation of role folder
00955                                         $log->write("ilObjectGUI::pasteObject(), created role folder (ref_id): ".$rolf_data["child"].
00956                                                 ", for object ref_id:".$obj_data->getRefId().", obj_id: ".$obj_data->getId().
00957                                                 ", type: ".$obj_data->getType().", title: ".$obj_data->getTitle());
00958 
00959                                 }
00960 
00961                                 // ... insert subtree of top_node if any subnodes exist ...
00962                                 if (count($subnode) > 0)
00963                                 {
00964                                         foreach ($subnode as $node)
00965                                         {
00966                                                 if ($node["type"] != 'rolf')
00967                                                 {
00968                                                         $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($node["child"]);
00969                                                         $new_ref_id = $obj_data->createReference();
00970 
00971                                                         // ... use mapping array to find out the correct new parent node where to put in the node...
00972                                                         $new_parent = array_search($node["parent"],$mapping);
00973                                                         // ... append node to mapping for further possible subnodes ...
00974                                                         $mapping[$new_ref_id] = (int) $node["child"];
00975 
00976                                                         $obj_data->putInTree($new_parent);
00977                                                         $obj_data->setPermissions($new_parent);
00978 
00979                                                         // save old ref_id & create rolefolder if applicable
00980                                                         $old_ref_id = $obj_data->getRefId();
00981                                                         $obj_data->setRefId($new_ref_id);
00982                                                         $obj_data->initDefaultRoles();
00983                                                         $rolf_data = $rbacreview->getRoleFolderOfObject($obj_data->getRefId());
00984 
00985                                                         if (isset($rolf_data["child"]))
00986                                                         {
00987                                                                 // a role folder was created, so map it to old role folder
00988                                                                 $rolf_data_old = $rbacreview->getRoleFolderOfObject($old_ref_id);
00989 
00990                                                                 // ... use mapping array to find out the correct new parent node where to put in the node...
00991                                                                 //$new_parent = array_search($node["parent"],$mapping);
00992                                                                 // ... append node to mapping for further possible subnodes ...
00993                                                                 $mapping[$rolf_data["child"]] = (int) $rolf_data_old["child"];
00994 
00995                                                                 // log creation of role folder
00996                                                                 $log->write("ilObjectGUI::pasteObject(), created role folder (ref_id): ".$rolf_data["child"].
00997                                                                         ", for object ref_id:".$obj_data->getRefId().", obj_id: ".$obj_data->getId().
00998                                                                         ", type: ".$obj_data->getType().", title: ".$obj_data->getTitle());
00999 
01000                                                         }
01001                                                 }
01002 
01003                                                 // re-map $subnodes
01004                                                 foreach ($subnodes as $old_ref => $subnode)
01005                                                 {
01006                                                         $new_ref = array_search($old_ref,$mapping);
01007 
01008                                                         foreach ($subnode as $node)
01009                                                         {
01010                                                                 $node["child"] = array_search($node["child"],$mapping);
01011                                                                 $node["parent"] = array_search($node["parent"],$mapping);
01012                                                                 $new_subnodes[$ref_id][] = $node;
01013                                                         }
01014                                                 }
01015 
01016                                         }
01017                                 }
01018                         }
01019 
01020                         $log->write("ilObjectGUI::pasteObject(), link finished");
01021 
01022                         // inform other objects in hierarchy about link operation
01023                         //$this->object->notify("link",$this->object->getRefId(),$_SESSION["clipboard"]["parent_non_rbac_id"],$this->object->getRefId(),$subnodes);
01024                 } // END LINK
01025 
01026                 // save cmd for correct message output after clearing the clipboard
01027                 $last_cmd = $_SESSION["clipboard"]["cmd"];
01028 
01029 
01030                 // clear clipboard
01031                 $this->clearObject();
01032 
01033                 if ($last_cmd == "cut")
01034                 {
01035                         sendInfo($this->lng->txt("msg_cut_copied"),true);
01036                 }
01037                 else
01038                 {
01039                         sendInfo($this->lng->txt("msg_linked"),true);
01040                 }
01041 
01042                 ilUtil::redirect($this->getReturnLocation("paste",$this->ctrl->getLinkTarget($this)),get_class($this));
01043                 //ilUtil::redirect($this->getReturnLocation("paste","adm_object.php?ref_id=".$_GET["ref_id"]));
01044 
01045         } // END PASTE
01046 
01047 
01048 
01052         function clipboardObject()
01053         {
01054                 global $ilErr,$ilLog;
01055 
01056                 // function should not be called if clipboard is empty
01057                 if (empty($_SESSION['clipboard']) or !is_array($_SESSION['clipboard']))
01058                 {
01059                         $message = sprintf('%s::clipboardObject(): Illegal access. Clipboard variable is empty!', get_class($this));
01060                         $ilLog->write($message,$ilLog->FATAL);
01061                         $ilErr->raiseError($this->lng->txt("permission_denied"),$ilErr->WARNING);
01062                 }
01063 
01064                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.rep_clipboard.html");
01065 
01066                 // FORMAT DATA
01067                 $counter = 0;
01068                 $f_result = array();
01069 
01070                 foreach($_SESSION["clipboard"]["ref_ids"] as $ref_id)
01071                 {
01072                         if(!$tmp_obj = ilObjectFactory::getInstanceByRefId($ref_id,false))
01073                         {
01074                                 continue;
01075                         }
01076 
01077                         //$f_result[$counter][] = ilUtil::formCheckbox(0,"user[]",$user);
01078                         $f_result[$counter][] = $this->lng->txt("obj_".$tmp_obj->getType());
01079                         $f_result[$counter][] = $tmp_obj->getTitle();
01080                         //$f_result[$counter][] = $tmp_obj->getDescription();
01081                         $f_result[$counter][] = ($_SESSION["clipboard"]["cmd"] == "cut") ? $this->lng->txt("move") :$this->lng->txt($_SESSION["clipboard"]["cmd"]);
01082 
01083                         unset($tmp_obj);
01084                         ++$counter;
01085                 }
01086 
01087                 $this->__showClipboardTable($f_result, "clipboardObject");
01088 
01089                 return true;
01090         }
01091         
01092         function isActiveAdministrationPanel()
01093         {
01094                 return $_SESSION["il_cont_admin_panel"];
01095         }
01096 }
01097 ?>

Generated on Fri Dec 13 2013 10:18:26 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1