ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjectGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
34 {
36 
42  var $ilias;
43 
50 
56  var $tpl;
57 
63  var $tree;
64 
70  var $lng;
71 
77  var $data;
78 
84  var $object;
85  var $ref_id;
86  var $obj_id;
87  var $maxcount; // contains number of child objects
88  var $formaction; // special formation (array "cmd" => "formaction")
89  var $return_location; // special return location (array "cmd" => "location")
90  var $target_frame; // special target frame (array "cmd" => "location")
91 
93  var $actions;
95  var $omit_locator = false;
96 
104  function ilObjectGUI($a_data, $a_id = 0, $a_call_by_reference = true, $a_prepare_output = true)
105  {
106  global $ilias, $objDefinition, $tpl, $tree, $ilCtrl, $ilErr, $lng, $ilTabs;
107 
108  $this->tabs_gui =& $ilTabs;
109 
110  if (!isset($ilErr))
111  {
112  $ilErr = new ilErrorHandling();
113  $ilErr->setErrorHandling(PEAR_ERROR_CALLBACK,array($ilErr,'errorHandler'));
114  }
115  else
116  {
117  $this->ilErr =& $ilErr;
118  }
119 
120  $this->ilias =& $ilias;
121  $this->objDefinition =& $objDefinition;
122  $this->tpl =& $tpl;
123  $this->html = "";
124  $this->ctrl =& $ilCtrl;
125 
126  $params = array("ref_id");
127 
128  if (!$a_call_by_reference)
129  {
130  $params = array("ref_id","obj_id");
131  }
132 
133  $this->ctrl->saveParameter($this, $params);
134 
135  $this->lng =& $lng;
136  $this->tree =& $tree;
137  $this->formaction = array();
138  $this->return_location = array();
139  $this->target_frame = array();
140  $this->actions = "";
141  $this->sub_objects = "";
142 
143  $this->data = $a_data;
144  $this->id = $a_id;
145  $this->call_by_reference = $a_call_by_reference;
146  $this->prepare_output = $a_prepare_output;
147  $this->creation_mode = false;
148 
149  $this->ref_id = ($this->call_by_reference) ? $this->id : $_GET["ref_id"];
150  $this->obj_id = ($this->call_by_reference) ? $_GET["obj_id"] : $this->id;
151 
152  if ($this->id != 0)
153  {
154  $this->link_params = "ref_id=".$this->ref_id;
155  }
156 
157  // get the object
158  $this->assignObject();
159 
160  // set context
161  if (is_object($this->object))
162  {
163  if ($this->call_by_reference && $this->ref_id = $_GET["ref_id"])
164  {
165  $this->ctrl->setContext($this->object->getId(),
166  $this->object->getType());
167  }
168  }
169 
170  // use global $lng instead, when creating new objects object is not available
171  //$this->lng =& $this->object->lng;
172 
173  //prepare output
174  if ($a_prepare_output)
175  {
176  $this->prepareOutput();
177  }
178  }
179 
180 
184  function &executeCommand()
185  {
186  global $rbacsystem;
187 
188  $next_class = $this->ctrl->getNextClass($this);
189  $cmd = $this->ctrl->getCmd();
190 
191  switch($next_class)
192  {
193  default:
194  $this->prepareOutput();
195  if(!$cmd)
196  {
197  $cmd = "view";
198  }
199  $cmd .= "Object";
200  $this->$cmd();
201 
202  break;
203  }
204 
205  return true;
206  }
207 
208 
212  function withReferences()
213  {
214  return $this->call_by_reference;
215  }
216 
223  function setCreationMode($a_mode = true)
224  {
225  $this->creation_mode = $a_mode;
226  }
227 
231  function getCreationMode()
232  {
233  return $this->creation_mode;
234  }
235 
236  function assignObject()
237  {
238  // TODO: it seems that we always have to pass only the ref_id
239 //echo "<br>ilObjectGUIassign:".get_class($this).":".$this->id.":<br>";
240  if ($this->id != 0)
241  {
242  if ($this->call_by_reference)
243  {
244  $this->object =& $this->ilias->obj_factory->getInstanceByRefId($this->id);
245  }
246  else
247  {
248  $this->object =& $this->ilias->obj_factory->getInstanceByObjId($this->id);
249  }
250  }
251  }
252 
256  function prepareOutput()
257  {
258  global $ilLocator, $tpl;
259 
260  $this->tpl->getStandardTemplate();
261  // administration prepare output
262  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
263  {
264  $this->addAdminLocatorItems();
265  $tpl->setLocator();
266 
269 
270  $this->setTitleAndDescription();
271 
272  if ($this->getCreationMode() != true)
273  {
274  $this->setAdminTabs();
275  $this->showUpperIcon();
276  }
277 
278  return false;
279  }
280  // set locator
281  $this->setLocator();
282  // catch feedback message
285 
286  // in creation mode (parent) object and gui object
287  // do not fit
288  if ($this->getCreationMode() == true)
289  {
290  // get gui class of parent and call their title and description method
291  $obj_type = ilObject::_lookupType($_GET["ref_id"],true);
292  $class_name = $this->objDefinition->getClassName($obj_type);
293  $class = strtolower("ilObj".$class_name."GUI");
294  $class_path = $this->ctrl->lookupClassPath($class);
295  include_once($class_path);
296  $class_name = $this->ctrl->getClassForClasspath($class_path);
297 //echo "<br>instantiating parent for title and description";
298  $this->parent_gui_obj = new $class_name("", $_GET["ref_id"], true, false);
299  $this->parent_gui_obj->setTitleAndDescription();
300  }
301  else
302  {
303  // set title and description and title icon
304  $this->setTitleAndDescription();
305 
306  // set tabs
307  $this->setTabs();
308  $this->showUpperIcon();
309 
310  // BEGIN WebDAV: Display Mount Webfolder icon.
311  require_once 'Services/WebDAV/classes/class.ilDAVServer.php';
312  if (ilDAVServer::_isActive() &&
313  $this->ilias->account->getId() != ANONYMOUS_USER_ID)
314  {
315  $this->showMountWebfolderIcon();
316  }
317  // END WebDAV: Display Mount Webfolder icon.
318  }
319 
320  return true;
321  }
322 
323 
328  {
329  $this->tpl->setTitle($this->object->getPresentationTitle());
330  $this->tpl->setDescription($this->object->getLongDescription());
331  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_".$this->object->getType()."_b.gif"), $this->lng->txt("obj_" . $this->object->getType()));
332  }
333 
334  function showUpperIcon()
335  {
336  global $tree, $tpl, $objDefinition;
337 
338  if ($this->object->getRefId() == "")
339  {
340  return;
341  }
342 
343  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
344  {
345  if ($this->object->getRefId() != ROOT_FOLDER_ID &&
346  $this->object->getRefId() != SYSTEM_FOLDER_ID)
347  {
348  $par_id = $tree->getParentId($this->object->getRefId());
349  $obj_type = ilObject::_lookupType($par_id,true);
350  $class_name = $objDefinition->getClassName($obj_type);
351  $class = strtolower("ilObj".$class_name."GUI");
352  $this->ctrl->setParameterByClass($class, "ref_id", $par_id);
353  $tpl->setUpperIcon($this->ctrl->getLinkTargetByClass($class, "view"));
354  $this->ctrl->clearParametersByClass($class);
355  }
356  // link repository admin to admin settings
357  else if ($this->object->getRefId() == ROOT_FOLDER_ID)
358  {
359  $this->ctrl->setParameterByClass("iladministrationgui", "ref_id", "");
360  $this->ctrl->setParameterByClass("iladministrationgui", "admin_mode", "settings");
361  $tpl->setUpperIcon($this->ctrl->getLinkTargetByClass("iladministrationgui", "frameset"),
362  ilFrameTargetInfo::_getFrame("MainContent"));
363  $this->ctrl->clearParametersByClass("iladministrationgui");
364  }
365  }
366  else
367  {
368  if ($this->object->getRefId() != ROOT_FOLDER_ID &&
369  $this->object->getRefId() != SYSTEM_FOLDER_ID &&
370  $_GET["obj_id"] == "")
371  {
372  if (defined("ILIAS_MODULE"))
373  {
374  $prefix = "../";
375  }
376  $par_id = $tree->getParentId($this->object->getRefId());
377  $tpl->setUpperIcon($prefix."repository.php?cmd=frameset&ref_id=".$par_id,
378  ilFrameTargetInfo::_getFrame("MainContent"));
379  }
380  }
381  }
382  // BEGIN WebDAV: Show Mount Webfolder Icon.
384  {
385  global $tree, $tpl, $objDefinition;
386 
387  if ($this->object->getRefId() == "")
388  {
389  return;
390  }
391 
392  $tpl->setMountWebfolderIcon($this->object->getRefId());
393  }
394  // END WebDAV: Show Mount Webfolder Icon.
395 
396 
401  function setTabs()
402  {
403  $this->getTabs($this->tabs_gui);
404  }
405 
410  function setAdminTabs()
411  {
412  $this->getAdminTabs($this->tabs_gui);
413  }
414 
418  function getAdminTabs(&$tabs_gui)
419  {
420  global $rbacsystem;
421 
422  if ($_GET["admin_mode"] == "repository")
423  {
424  $this->ctrl->setParameterByClass("iladministrationgui", "admin_mode", "settings");
425  $tabs_gui->setBackTarget($this->lng->txt("administration"),
426  $this->ctrl->getLinkTargetByClass("iladministrationgui", "frameset"),
427  ilFrameTargetInfo::_getFrame("MainContent"));
428  $this->ctrl->setParameterByClass("iladministrationgui", "admin_mode", "repository");
429  }
430 
431  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
432  {
433  $tabs_gui->addTarget("view",
434  $this->ctrl->getLinkTarget($this, "view"), array("", "view"), get_class($this));
435  }
436 
437  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
438  {
439  $tabs_gui->addTarget("perm_settings",
440  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), "", "ilpermissiongui");
441  }
442 
443  if ($this->tree->getSavedNodeData($this->object->getRefId()))
444  {
445  $tabs_gui->addTarget("trash",
446  $this->ctrl->getLinkTarget($this, "trash"), "trash", get_class($this));
447  }
448  }
449 
450 
451  function getHTML()
452  {
453  return $this->html;
454  }
455 
456 
463  function setActions($a_actions = "")
464  {
465  if (is_array($a_actions))
466  {
467  foreach ($a_actions as $name => $lng)
468  {
469  $this->actions[$name] = array("name" => $name, "lng" => $lng);
470  }
471  }
472  else
473  {
474  $this->actions = "";
475  }
476  }
477 
484  function setSubObjects($a_sub_objects = "")
485  {
486  if (is_array($a_sub_objects))
487  {
488  foreach ($a_sub_objects as $name => $options)
489  {
490  $this->sub_objects[$name] = array("name" => $name, "max" => $options["max"]);
491  }
492  }
493  else
494  {
495  $this->sub_objects = "";
496  }
497  }
498 
507  function setLocator()
508  {
509  global $ilLocator, $tpl;
510 
511  if ($this->omit_locator)
512  {
513  return;
514  }
515 
516  // todo: admin workaround
517  // in the future, objectgui classes should not be called in
518  // admin section anymore (rbac/trash handling in own classes)
519  $ref_id = ($_GET["ref_id"] != "")
520  ? $_GET["ref_id"]
521  : $this->object->getRefId();
522  $ilLocator->addRepositoryItems($ref_id);
523 
524  if(!$this->creation_mode)
525  {
526  $this->addLocatorItems();
527  }
528 
529  // not so nice workaround: todo: handle $ilLocator as tabs in ilTemplate
530  if ($_GET["admin_mode"] == "" &&
531  strtolower($this->ctrl->getCmdClass()) == "ilobjrolegui")
532  {
533  $this->ctrl->setParameterByClass("ilobjrolegui",
534  "rolf_ref_id", $_GET["rolf_ref_id"]);
535  $this->ctrl->setParameterByClass("ilobjrolegui",
536  "obj_id", $_GET["obj_id"]);
537  $ilLocator->addItem($this->lng->txt("role"),
538  $this->ctrl->getLinkTargetByClass(array("ilpermissiongui",
539  "ilobjrolegui"), "perm"));
540  }
541 
542  $tpl->setLocator();
543  }
544 
549  function addLocatorItems()
550  {
551  }
552 
553  function omitLocator($a_omit = true)
554  {
555  $this->omit_locator = $a_omit;
556  }
557 
563  {
564  global $ilLocator;
565 
566  if ($_GET["admin_mode"] == "settings") // system settings
567  {
568  $ilLocator->addItem($this->lng->txt("administration"),
569  $this->ctrl->getLinkTargetByClass("iladministrationgui", "frameset"),
570  ilFrameTargetInfo::_getFrame("MainContent"));
571  if ($this->object->getRefId() != SYSTEM_FOLDER_ID)
572  {
573  $ilLocator->addItem($this->object->getTitle(),
574  $this->ctrl->getLinkTarget($this, "view"));
575  }
576  }
577  else // repository administration
578  {
579  $this->ctrl->setParameterByClass("iladministrationgui",
580  "ref_id", "");
581  $this->ctrl->setParameterByClass("iladministrationgui",
582  "admin_mode", "settings");
583  //$ilLocator->addItem($this->lng->txt("administration"),
584  // $this->ctrl->getLinkTargetByClass("iladministrationgui", "frameset"),
585  // ilFrameTargetInfo::_getFrame("MainContent"));
586  $this->ctrl->clearParametersByClass("iladministrationgui");
587  $ilLocator->addAdministrationItems();
588  }
589 
590  }
591 
597  function undeleteObject()
598  {
599  global $rbacsystem, $log, $ilAppEventHandler;
600 
601  // AT LEAST ONE OBJECT HAS TO BE CHOSEN.
602  if (!isset($_POST["trash_id"]))
603  {
604  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
605  }
606 
607  foreach ($_POST["trash_id"] as $id)
608  {
609  $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($id);
610 
611  if (!$rbacsystem->checkAccess('create',$_GET["ref_id"],$obj_data->getType()))
612  {
613  $no_create[] = $id;
614  }
615  }
616 
617  if (count($no_create))
618  {
619  $this->ilias->raiseError($this->lng->txt("msg_no_perm_paste")." ".
620  implode(',',$no_create),$this->ilias->error_obj->MESSAGE);
621  }
622 
623  $affected_ids = array();
624 
625  foreach ($_POST["trash_id"] as $id)
626  {
627  $affected_ids[$id] = $id;
628 
629  // INSERT AND SET PERMISSIONS
630  $this->insertSavedNodes($id,$_GET["ref_id"],-(int) $id, $affected_ids);
631  // DELETE SAVED TREE
632  $saved_tree = new ilTree(-(int)$id);
633  $saved_tree->deleteTree($saved_tree->getNodeData($id));
634 
635  // BEGIN ChangeEvent: Record undelete.
636  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
638  {
639  global $ilUser, $tree;
640 
641  $node_data = $saved_tree->getNodeData($id);
642  $saved_tree->deleteTree($node_data);
643 
644  // Record undelete event
645  $node_data = $tree->getNodeData($id);
646  $parent_data = $tree->getParentNodeData($node_data['ref_id']);
647  ilChangeEvent::_recordWriteEvent($node_data['obj_id'], $ilUser->getId(), 'undelete',
648  $parent_data['obj_id']);
649  ilChangeEvent::_catchupWriteEvents($this->object->getId(), $ilUser->getId());
650  }
651  // END PATCH ChangeEvent: Record undelete.
652 
653  }
654 
655  // send events
656  foreach ($affected_ids as $id)
657  {
658  // send global event
659  $ilAppEventHandler->raise("Services/Object", "undelete",
660  array("obj_id" => ilObject::_lookupObjId($id), "ref_id" => $id));
661  }
662 
663  //$this->object->notify("undelete", $_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$_POST["trash_id"]);
664 
665  ilUtil::sendInfo($this->lng->txt("msg_undeleted"),true);
666 
667  $this->ctrl->redirect($this, "view");
668  }
669 
679  function insertSavedNodes($a_source_id,$a_dest_id,$a_tree_id, &$a_affected_ids)
680  {
681  global $rbacadmin, $rbacreview, $log;
682 
683  $this->tree->insertNode($a_source_id,$a_dest_id, IL_LAST_NODE, true);
684  $a_affected_ids[$a_source_id] = $a_source_id;
685 
686  // write log entry
687  $log->write("ilObjectGUI::insertSavedNodes(), restored ref_id $a_source_id from trash");
688 
689  // SET PERMISSIONS
690  $parentRoles = $rbacreview->getParentRoleIds($a_dest_id);
691  $obj =& $this->ilias->obj_factory->getInstanceByRefId($a_source_id);
692 
693  foreach ($parentRoles as $parRol)
694  {
695  $ops = $rbacreview->getOperationsOfRole($parRol["obj_id"], $obj->getType(), $parRol["parent"]);
696  $rbacadmin->grantPermission($parRol["obj_id"],$ops,$a_source_id);
697  }
698 
699  $saved_tree = new ilTree($a_tree_id);
700  $childs = $saved_tree->getChilds($a_source_id);
701 
702  foreach ($childs as $child)
703  {
704  $this->insertSavedNodes($child["child"],$a_source_id,$a_tree_id,$a_affected_ids);
705  }
706  }
707 
718  {
719  global $ilAppEventHandler;
720 
721  include_once './payment/classes/class.ilPaymentObject.php';
722 
723  global $rbacsystem, $rbacadmin, $log;
724  global $ilUser, $tree;
725 
726  // TODO: move checkings to deleteObject
727  // TODO: cannot distinguish between obj_id from ref_id with the posted IDs.
728  // change the form field and use instead of 'id' 'ref_id' and 'obj_id'. Then switch with varname
729 
730  // AT LEAST ONE OBJECT HAS TO BE CHOSEN.
731  if (!isset($_SESSION["saved_post"]))
732  {
733  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
734  }
735 
736  // FOR ALL SELECTED OBJECTS
737  foreach ($_SESSION["saved_post"] as $id)
738  {
739  if($this->tree->isDeleted($id))
740  {
741  $log->write(__METHOD__.': Object with ref_id: '.$id.' already deleted.');
742  ilUtil::sendInfo('Object already deleted.',true);
743  $this->ctrl->returnToParent($this);
744  }
745 
746  // GET COMPLETE NODE_DATA OF ALL SUBTREE NODES
747  $node_data = $this->tree->getNodeData($id);
748  $subtree_nodes = $this->tree->getSubTree($node_data);
749 
750  $all_node_data[] = $node_data;
751  $all_subtree_nodes[] = $subtree_nodes;
752 
753  // CHECK DELETE PERMISSION OF ALL OBJECTS
754  foreach ($subtree_nodes as $node)
755  {
756  if($node['type'] == 'rolf')
757  {
758  continue;
759  }
760  if (!$rbacsystem->checkAccess('delete',$node["child"]))
761  {
762  $not_deletable[] = $node["child"];
763  $perform_delete = false;
764  }
765  else if(ilPaymentObject::_isBuyable($node['child']))
766  {
767  $buyable[] = $node['child'];
768  $perform_delete = false;
769  }
770  }
771  }
772 
773  // IF THERE IS ANY OBJECT WITH NO PERMISSION TO DELETE
774  if (count($not_deletable))
775  {
776  $not_deletable = implode(',',$not_deletable);
777  session_unregister("saved_post");
778  ilUtil::sendInfo($this->lng->txt("msg_no_perm_delete")." ".$not_deletable."<br/>".$this->lng->txt("msg_cancel"),true);
779 
780  $this->ctrl->returnToParent($this);
781  }
782 
783  if(count($buyable))
784  {
785  foreach($buyable as $id)
786  {
787  $tmp_object =& ilObjectFactory::getInstanceByRefId($id);
788 
789  $titles[] = $tmp_object->getTitle();
790  }
791  $title_str = implode(',',$titles);
792 
793  ilUtil::sendInfo($this->lng->txt('msg_obj_not_deletable_sold').' '.$title_str,true);
794 
795  $_POST['id'] = $_SESSION['saved_post'];
796  $this->deleteObject(true);
797 
798  return false;
799  }
800 
801  // DELETE THEM
802  if (!$all_node_data[0]["type"])
803  {
804  // OBJECTS ARE NO 'TREE OBJECTS'
805  if ($rbacsystem->checkAccess('delete',$_GET["ref_id"]))
806  {
807  foreach($_SESSION["saved_post"] as $id)
808  {
809  $obj =& $this->ilias->obj_factory->getInstanceByObjId($id);
810  $obj->delete();
811 
812  // write log entry
813  $log->write("ilObjectGUI::confirmedDeleteObject(), deleted obj_id ".$obj->getId().
814  ", type: ".$obj->getType().", title: ".$obj->getTitle());
815  }
816  }
817  else
818  {
819  unset($_SESSION["saved_post"]);
820  ilUtil::sendInfo($this->lng->txt("no_perm_delete")."<br/>".$this->lng->txt("msg_cancel"),true);
821  $this->ctrl->returnToParent($this);
822  }
823  }
824  else
825  {
826  // SAVE SUBTREE AND DELETE SUBTREE FROM TREE
827  $affected_ids = array();
828  foreach ($_SESSION["saved_post"] as $id)
829  {
830  if($this->tree->isDeleted($id))
831  {
832  $log->write(__METHOD__.': Object with ref_id: '.$id.' already deleted.');
833  ilUtil::sendInfo('Object already deleted.',true);
834  $this->ctrl->returnToParent($this);
835  }
836 
837  // DELETE OLD PERMISSION ENTRIES
838  $subnodes = $this->tree->getSubtree($this->tree->getNodeData($id));
839 
840  foreach ($subnodes as $subnode)
841  {
842  $rbacadmin->revokePermission($subnode["child"]);
843  // remove item from all user desktops
844  $affected_users = ilUtil::removeItemFromDesktops($subnode["child"]);
845 
846  $affected_ids[$subnode["child"]] = $subnode["child"];
847 
848  // TODO: inform users by mail that object $id was deleted
849  //$mail->sendMail($id,$msg,$affected_users);
850  // should go to appevents at the end
851  }
852 
853  // TODO: needs other handling
854  // This class shouldn't have to know anything about ECS
855  include_once('./Services/WebServices/ECS/classes/class.ilECSContentWriter.php');
857 
858  if(!$this->tree->saveSubTree($id, true))
859  {
860  $log->write(__METHOD__.': Object with ref_id: '.$id.' already deleted.');
861  ilUtil::sendInfo('Object already deleted.',true);
862  $this->ctrl->returnToParent($this);
863  }
864 
865  // write log entry
866  $log->write("ilObjectGUI::confirmedDeleteObject(), moved ref_id ".$id.
867  " to trash");
868 
869  // remove item from all user desktops
870  $affected_users = ilUtil::removeItemFromDesktops($id);
871 
872  $affected_ids[$id] = $id;
873 
874  // TODO: inform users by mail that object $id was deleted
875  //$mail->sendMail($id,$msg,$affected_users);
876  }
877 
878  // send global events
879  foreach ($affected_ids as $aid)
880  {
881  $ilAppEventHandler->raise("Services/Object", "toTrash",
882  array("obj_id" => ilObject::_lookupObjId($aid),
883  "ref_id" => $aid));
884  }
885  // inform other objects in hierarchy about paste operation
886  //$this->object->notify("confirmedDelete", $_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$_SESSION["saved_post"]);
887  }
888 
889  if ($this->ilias->getSetting('enable_trash'))
890  {
891  // Feedback
892  ilUtil::sendInfo($this->lng->txt("info_deleted"),true);
893 
894  $this->ctrl->returnToParent($this);
895  }
896  else // skip trash if 'enable_trash' is 0
897  {
898  $_POST["trash_id"] = $_SESSION["saved_post"];
899 
900  $this->removeFromSystemObject();
901  }
902  }
903 
910  {
911  session_unregister("saved_post");
912 
913  ilUtil::sendInfo($this->lng->txt("msg_cancel"),true);
914 
915  $this->ctrl->returnToParent($this);
916 
917  }
918 
925  {
926  global $rbacsystem, $log, $ilAppEventHandler;
927 
928  // AT LEAST ONE OBJECT HAS TO BE CHOSEN.
929  if (!isset($_POST["trash_id"]))
930  {
931  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
932  }
933 
934  //$this->object->notify("removeFromSystem", $_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$_POST["trash_id"]);
935  $affected_ids = array();
936 
937  // DELETE THEM
938  foreach ($_POST["trash_id"] as $id)
939  {
940  // GET COMPLETE NODE_DATA OF ALL SUBTREE NODES
941  $saved_tree = new ilTree(-(int)$id);
942  $node_data = $saved_tree->getNodeData($id);
943  $subtree_nodes = $saved_tree->getSubTree($node_data);
944 
945  // BEGIN ChangeEvent: Record remove from system.
946  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
948  {
949  // Record write event
950  global $ilUser, $tree;
951  $parent_data = $tree->getParentNodeData($node_data['ref_id']);
952  ilChangeEvent::_recordWriteEvent($node_data['obj_id'], $ilUser->getId(), 'purge',
953  $parent_data['obj_id']);
954  }
955  // END ChangeEvent: Record remove from system.
956 
957  // remember already checked deleted node_ids
958  $checked[] = -(int) $id;
959 
960  // dive in recursive manner in each already deleted subtrees and remove these objects too
961  $this->removeDeletedNodes($id,$checked, true, $affected_ids);
962 
963  foreach ($subtree_nodes as $node)
964  {
965  if(!$node_obj =& $this->ilias->obj_factory->getInstanceByRefId($node["ref_id"],false))
966  {
967  continue;
968  }
969 
970  // write log entry
971  $log->write("ilObjectGUI::removeFromSystemObject(), delete obj_id: ".$node_obj->getId().
972  ", ref_id: ".$node_obj->getRefId().", type: ".$node_obj->getType().", ".
973  "title: ".$node_obj->getTitle());
974  $affected_ids[$node["ref_id"]] = array("ref_id" => $node["ref_id"],
975  "obj_id" => $node_obj->getId(), "type" => $node_obj->getType());
976 
977  $node_obj->delete();
978 
979  }
980 
981  // FIRST DELETE ALL ENTRIES IN RBAC TREE
982  #$this->tree->deleteTree($node_data);
983  // Use the saved tree object here (negative tree_id)
984  $saved_tree->deleteTree($node_data);
985 
986  // write log entry
987  $log->write("ilObjectGUI::removeFromSystemObject(), deleted tree, tree_id: ".$node_data["tree"].
988  ", child: ".$node_data["child"]);
989 
990  }
991 
992  // send global events
993  foreach ($affected_ids as $aid)
994  {
995  $ilAppEventHandler->raise("Services/Object", "delete",
996  array("obj_id" => $aid["obj_id"],
997  "ref_id" => $aid["ref_id"],
998  "type" => $aid["type"]));
999  }
1000 
1001  ilUtil::sendInfo($this->lng->txt("msg_removed"),true);
1002 
1003  $this->ctrl->returnToParent($this);
1004  }
1005 
1014  function removeDeletedNodes($a_node_id, $a_checked, $a_delete_objects,
1015  &$a_affected_ids)
1016  {
1017  global $log, $ilDB;
1018 
1019  // @todo: belongs to app
1020 
1021  $q = "SELECT tree FROM tree WHERE parent= ".
1022  $ilDB->quote($a_node_id)." AND tree < 0";
1023 
1024  $r = $this->ilias->db->query($q);
1025 
1026  while($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
1027  {
1028  // only continue recursion if fetched node wasn't touched already!
1029  if (!in_array($row->tree,$a_checked))
1030  {
1031  $deleted_tree = new ilTree($row->tree);
1032  $a_checked[] = $row->tree;
1033 
1034  $row->tree = $row->tree * (-1);
1035  $del_node_data = $deleted_tree->getNodeData($row->tree);
1036  $del_subtree_nodes = $deleted_tree->getSubTree($del_node_data);
1037 
1038  $this->removeDeletedNodes($row->tree,$a_checked, $a_delete_objects, $a_affected_ids);
1039 
1040  if ($a_delete_objects)
1041  {
1042  foreach ($del_subtree_nodes as $node)
1043  {
1044  $node_obj =& $this->ilias->obj_factory->getInstanceByRefId($node["ref_id"]);
1045 
1046  // write log entry
1047  $log->write("ilObjectGUI::removeDeletedNodes(), delete obj_id: ".$node_obj->getId().
1048  ", ref_id: ".$node_obj->getRefId().", type: ".$node_obj->getType().", ".
1049  "title: ".$node_obj->getTitle());
1050  $a_affected_ids[$node["ref_id"]] = array("ref_id" => $node["ref_id"],
1051  "obj_id" => $node_obj->getId(), "type" => $node_obj->getType());
1052 
1053  $node_obj->delete();
1054 
1055  }
1056  }
1057 
1058  $this->tree->deleteTree($del_node_data);
1059 
1060  // write log entry
1061  $log->write("ilObjectGUI::removeDeletedNodes(), deleted tree, tree_id: ".$del_node_data["tree"].
1062  ", child: ".$del_node_data["child"]);
1063  }
1064  }
1065 
1066  return true;
1067  }
1068 
1074  function createObject()
1075  {
1076  global $rbacsystem;
1077 
1078  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
1079 
1080  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
1081  {
1082  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
1083  }
1084  else
1085  {
1086  // fill in saved values in case of error
1087  $data = array();
1088  $data["fields"] = array();
1089  $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
1090  $data["fields"]["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
1091 
1092  $this->getTemplateFile("edit",$new_type);
1093 
1094  // show obj type image
1095  $this->tpl->setCurrentBlock("img");
1096  $this->tpl->setVariable("TYPE_IMG",
1097  ilUtil::getImagePath("icon_".$new_type.".gif"));
1098  $this->tpl->setVariable("ALT_IMG",
1099  $this->lng->txt("obj_".$new_type));
1100  $this->tpl->parseCurrentBlock();
1101 
1102  foreach ($data["fields"] as $key => $val)
1103  {
1104  $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
1105  $this->tpl->setVariable(strtoupper($key), $val);
1106 
1107  if ($this->prepare_output)
1108  {
1109  $this->tpl->parseCurrentBlock();
1110  }
1111  }
1112  $this->ctrl->setParameter($this, "new_type", $new_type);
1113  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "save"));
1114  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($new_type."_new"));
1115  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
1116  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($new_type."_add"));
1117  $this->tpl->setVariable("CMD_SUBMIT", "save");
1118  $this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
1119  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
1120  }
1121  }
1122 
1123 
1129  function cancelObject($in_rep = false)
1130  {
1131  session_unregister("saved_post");
1132 
1133  ilUtil::sendInfo($this->lng->txt("msg_cancel"),true);
1134 
1135  //ilUtil::sendInfo($this->lng->txt("action_aborted"),true);
1136  $return_location = $_GET["cmd_return_location"];
1137 //echo "-".$_GET["cmd_return_location"]."-".$this->ctrl->getLinkTarget($this,$return_location);
1138  //ilUtil::redirect($this->ctrl->getLinkTarget($this,$return_location));
1139 //echo "1";
1140  //if ($in_rep)
1141  //{
1142  $this->ctrl->returnToParent($this);
1143  //}
1144  //else
1145  //{
1146 //echo "3";
1147  // ilUtil::redirect($this->getReturnLocation("cancel",$this->ctrl->getTargetScript()."?".$this->link_params));
1148  //}
1149  }
1150 
1156  function saveObject()
1157  {
1158  global $rbacsystem, $objDefinition;
1159 
1160  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
1161 
1162  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
1163  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
1164  {
1165  $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
1166  }
1167 //echo ":".$_GET["new_type"].":".$_POST["new_type"].":";
1168  $location = $objDefinition->getLocation($new_type);
1169 
1170  // create and insert object in objecttree
1171  $class_name = "ilObj".$objDefinition->getClassName($new_type);
1172  include_once($location."/class.".$class_name.".php");
1173  $newObj = new $class_name();
1174  $newObj->setType($new_type);
1175  $newObj->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
1176  $newObj->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
1177  $newObj->create();
1178  $newObj->createReference();
1179  $newObj->putInTree($_GET["ref_id"]);
1180  $newObj->setPermissions($_GET["ref_id"]);
1181  //$newObj->notify("new",$_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$newObj->getRefId());
1182 
1183  return $newObj;
1184  }
1185 
1186 
1192  function importObject()
1193  {
1194  global $rbacsystem;
1195  // CHECK ACCESS 'write' of role folder
1196  // TODO: new_type will never be checked, if queried operation is not 'create'
1197  if (!$rbacsystem->checkAccess('write', $_GET["ref_id"], $_POST["new_type"]))
1198  {
1199  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->WARNING);
1200  }
1201 
1202 /* Deprecated
1203 // $imp_obj =$this->objDefinition->getImportObjects($this->object->getType());
1204 
1205  if (!in_array($_POST["new_type"], $imp_obj))
1206  {
1207  $this->ilias->raiseError($this->lng->txt("no_import_available").
1208  " ".$this->lng->txt("obj_".$_POST["new_type"]),
1209  $this->ilias->error_obj->MESSAGE);
1210  }
1211 */
1212  // no general implementation of this feature, the specialized classes
1213  // must provide further processing
1214  }
1215 
1216 
1222  function editObject()
1223  {
1224  global $rbacsystem;
1225 
1226  if (!$rbacsystem->checkAccess("write", $this->ref_id))
1227  {
1228  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
1229  }
1230 
1231  $fields = array();
1232 
1233  if ($_SESSION["error_post_vars"])
1234  {
1235  // fill in saved values in case of error
1236  $fields["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
1237  $fields["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
1238  }
1239  else
1240  {
1241  $fields["title"] = ilUtil::prepareFormOutput($this->object->getTitle());
1242  $fields["desc"] = ilUtil::stripSlashes($this->object->getLongDescription());
1243  }
1244 
1245  $this->displayEditForm($fields);
1246  }
1247 
1254  function displayEditForm($fields)
1255  {
1256  $this->getTemplateFile("edit");
1257 
1258  foreach ($fields as $key => $val)
1259  {
1260  $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
1261  $this->tpl->setVariable(strtoupper($key), $val);
1262 // $this->tpl->parseCurrentBlock();
1263  }
1264 
1265  //$obj_str = ($this->call_by_reference) ? "" : "&obj_id=".$this->obj_id;
1266  if (!$this->call_by_reference)
1267  {
1268  $this->ctrl->setParameter($this, "obj_id", $this->obj_id);
1269  }
1270 
1271  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "update"));
1272  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->object->getType()."_edit"));
1273  $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
1274  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
1275  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
1276  $this->tpl->setVariable("CMD_SUBMIT", "update");
1277  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
1278 
1279  }
1280 
1281 
1287  function updateObject()
1288  {
1289  $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
1290  $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
1291  $this->update = $this->object->update();
1292 
1293  ilUtil::sendInfo($this->lng->txt("msg_obj_modified"),true);
1294 
1295  $this->afterUpdate();
1296  }
1297 
1298  function afterUpdate()
1299  {
1300  $this->ctrl->redirect($this);
1301  }
1302 
1308  function permObject()
1309  {
1310  include_once './classes/class.ilPermissionGUI.php';
1311  $perm_gui =& new ilPermissionGUI($this);
1312 
1313  // dirty work around to forward command in admin panel
1314  $this->ctrl->current_node = 1;
1315  $this->ctrl->setCmd('perm');
1316  $ret =& $this->ctrl->forwardCommand($perm_gui);
1317 
1318  return true;
1319  }
1320 
1329  function getFormAction($a_cmd, $a_formaction ="")
1330  {
1331  if ($this->formaction[$a_cmd] != "")
1332  {
1333  return $this->formaction[$a_cmd];
1334  }
1335  else
1336  {
1337  return $a_formaction;
1338  }
1339  }
1340 
1349  function setFormAction($a_cmd, $a_formaction)
1350  {
1351  $this->formaction[$a_cmd] = $a_formaction;
1352  }
1353 
1361  function getReturnLocation($a_cmd, $a_location ="")
1362  {
1363  if ($this->return_location[$a_cmd] != "")
1364  {
1365  return $this->return_location[$a_cmd];
1366  }
1367  else
1368  {
1369  return $a_location;
1370  }
1371  }
1372 
1380  function setReturnLocation($a_cmd, $a_location)
1381  {
1382 //echo "-".$a_cmd."-".$a_location."-";
1383  $this->return_location[$a_cmd] = $a_location;
1384  }
1385 
1393  function getTargetFrame($a_cmd, $a_target_frame = "")
1394  {
1395  if ($this->target_frame[$a_cmd] != "")
1396  {
1397  return $this->target_frame[$a_cmd];
1398  }
1399  elseif (!empty($a_target_frame))
1400  {
1401  return "target=\"".$a_target_frame."\"";
1402  }
1403  else
1404  {
1405  return;
1406  }
1407  }
1408 
1416  function setTargetFrame($a_cmd, $a_target_frame)
1417  {
1418  $this->target_frame[$a_cmd] = "target=\"".$a_target_frame."\"";
1419  }
1420 
1426  function permSaveObject()
1427  {
1428  include_once './classes/class.ilPermissionGUI.php';
1429  $perm_gui =& new ilPermissionGUI($this);
1430 
1431  // dirty work around to forward command in admin panel
1432  $this->ctrl->current_node = 1;
1433  $this->ctrl->setCmd('permSave');
1434  $ret =& $this->ctrl->forwardCommand($perm_gui);
1435 
1436  return true;
1437  }
1438 
1439  // BEGIN Security: Hide objects which aren't accessible by the user.
1440  function isVisible($a_ref_id,$a_type)
1441  {
1442  global $rbacsystem, $ilBench;
1443 
1444  $ilBench->start("Explorer", "setOutput_isVisible");
1445  $visible = $rbacsystem->checkAccess('visible,read',$a_ref_id);
1446 
1447  if ($visible && $a_type == 'crs') {
1448  global $tree;
1449  if($crs_id = $tree->checkForParentType($a_ref_id,'crs'))
1450  {
1451  if(!$rbacsystem->checkAccess('write',$crs_id))
1452  {
1453  // Show only activated courses
1454  $tmp_obj =& ilObjectFactory::getInstanceByRefId($crs_id,false);
1455 
1456  if(!$tmp_obj->isActivated())
1457  {
1458  unset($tmp_obj);
1459  $visible = false;
1460  }
1461  if(($crs_id != $a_ref_id) and $tmp_obj->isArchived())
1462  {
1463  $visible = false;
1464  }
1465  // Show only activated course items
1466  include_once "./course/classes/class.ilCourseItems.php";
1467 
1468  if(($crs_id != $a_ref_id) and (!ilCourseItems::_isActivated($a_ref_id)))
1469  {
1470  $visible = false;
1471  }
1472  }
1473  }
1474  }
1475 
1476  $ilBench->stop("Explorer", "setOutput_isVisible");
1477 
1478  return $visible;
1479  }
1480  // END Security: Hide objects which aren't accessible by the user.
1481 
1487  function displayList()
1488  {
1489  include_once "./Services/Table/classes/class.ilTableGUI.php";
1490 
1491  // load template for table
1492  $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
1493  // load template for table content data
1494  $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.obj_tbl_rows.html");
1495 
1496  $num = 0;
1497 
1498  if (!$this->call_by_reference)
1499  {
1500  $this->ctrl->setParameter($this, "obj_id", $this->obj_id);
1501  }
1502  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
1503 
1504  // create table
1505  $tbl = new ilTableGUI();
1506 
1507  // title & header columns
1508  $tbl->setTitle($this->object->getTitle(),"icon_".$this->object->getType().".gif",
1509  $this->lng->txt("obj_".$this->object->getType()));
1510  $tbl->setHelp("tbl_help.php","icon_help.gif",$this->lng->txt("help"));
1511 
1512  foreach ($this->data["cols"] as $val)
1513  {
1514  $header_names[] = $this->lng->txt($val);
1515  }
1516 
1517  $tbl->setHeaderNames($header_names);
1518 
1519  //$header_params = array("ref_id" => $this->ref_id);
1520  //$header_params = array("ref_id" => $this->ref_id);
1521  $header_params = $this->ctrl->getParameterArray($this, "view");
1522  $tbl->setHeaderVars($this->data["cols"],$header_params);
1523  $tbl->setColumnWidth(array("15","15","75%","25%"));
1524 
1525  // control
1526  $tbl->setOrderColumn($_GET["sort_by"]);
1527  $tbl->setOrderDirection($_GET["sort_order"]);
1528  $tbl->setLimit($_GET["limit"]);
1529  $tbl->setOffset($_GET["offset"]);
1530  $tbl->setMaxCount($this->maxcount);
1531 
1532  $this->tpl->setVariable("COLUMN_COUNTS",count($this->data["cols"]));
1533 
1534  // footer
1535  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
1536 
1537  if (!empty($this->data["data"][0]))
1538  {
1539  // BEGIN Security: only show objects which are visible to the user
1540  $count = 0;
1541  // END Security: only show objects which are visible to the user
1542 
1543  //table cell
1544  for ($i=0; $i < count($this->data["data"]); $i++)
1545  {
1546  $data = $this->data["data"][$i];
1547  $ctrl = $this->data["ctrl"][$i];
1548 
1549  // BEGIN Security: only show objects which are visible to the user
1550  if (! $this->isVisible($ctrl['ref_id'], $data['type']))
1551  {
1552  continue;
1553  }
1554  // END Security: only show objects which are visible to the user
1555 
1556  // color changing
1557  // BEGIN Security only show objects which are visible to the user
1558  $count++;
1559  $css_row = ilUtil::switchColor($count,"tblrow2","tblrow1");
1560  // END Security only show objects that are visible to the user
1561 
1562  // surpress checkbox for particular object types AND the system role
1563  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)
1564  {
1565  $this->tpl->touchBlock("empty_cell");
1566  }
1567  else
1568  {
1569  // TODO: this object type depending 'if' could become really a problem!!
1570  if ($ctrl["type"] == "usr" or $ctrl["type"] == "role" or $ctrl["type"] == "rolt")
1571  {
1572  $link_id = $ctrl["obj_id"];
1573  }
1574  else
1575  {
1576  $link_id = $ctrl["ref_id"];
1577  }
1578 
1579  // dirty workaround to have ids for function showActions (checkbox toggle option)
1580  $this->ids[] = $link_id;
1581 
1582  $this->tpl->setCurrentBlock("checkbox");
1583  $this->tpl->setVariable("CHECKBOX_ID", $link_id);
1584  $this->tpl->setVariable("CSS_ROW", $css_row);
1585  $this->tpl->parseCurrentBlock();
1586  }
1587 
1588  $this->tpl->setCurrentBlock("table_cell");
1589  $this->tpl->setVariable("CELLSTYLE", "tblrow1");
1590  $this->tpl->parseCurrentBlock();
1591 
1592  foreach ($data as $key => $val)
1593  {
1594  //build link
1595  $obj_type = ilObject::_lookupType($ctrl["ref_id"],true);
1596  $class_name = $this->objDefinition->getClassName($obj_type);
1597  $class = strtolower("ilObj".$class_name."GUI");
1598  $this->ctrl->setParameterByClass($class, "ref_id", $ctrl["ref_id"]);
1599  $this->ctrl->setParameterByClass($class, "obj_id", $ctrl["obj_id"]);
1600  $link = $this->ctrl->getLinkTargetByClass($class, "view");
1601 
1602  /*
1603  $n = 0;
1604 
1605  foreach ($ctrl as $key2 => $val2)
1606  {
1607  $link .= $key2."=".$val2;
1608 
1609  if ($n < count($ctrl)-1)
1610  {
1611  $link .= "&";
1612  $n++;
1613  }
1614  }*/
1615 
1616  if ($key == "name" || $key == "title")
1617  {
1618  $name_field = explode("#separator#",$val);
1619  }
1620 
1621  if ($key == "title" || $key == "name" || $key == "type")
1622  {
1623  $this->tpl->setCurrentBlock("begin_link");
1624  $this->tpl->setVariable("LINK_TARGET", $link);
1625 
1626  $this->tpl->parseCurrentBlock();
1627  $this->tpl->touchBlock("end_link");
1628  }
1629 
1630  // process clipboard information
1631  if (($key == "title" || $key == "name") and is_array(($_SESSION["clipboard"])))
1632  {
1633  // TODO: broken! fix me
1634  if (in_array($ctrl["ref_id"],$_SESSION["clipboard"]["ref_ids"]))
1635  {
1636  switch($_SESSION["clipboard"]["cmd"])
1637  {
1638  case "cut":
1639  $name_field[0] = "<del>".$name_field[0]."</del>";
1640  break;
1641 
1642  case "copy":
1643  $name_field[0] = "<font color=\"green\">+</font> ".$name_field[0];
1644  break;
1645 
1646  case "link":
1647  $name_field[0] = "<font color=\"black\"><</font> ".$name_field[0];
1648  break;
1649  }
1650  }
1651  }
1652 
1653  $this->tpl->setCurrentBlock("text");
1654 
1655  if ($key == "type")
1656  {
1657  $val = ilUtil::getImageTagByType($val,$this->tpl->tplPath);
1658  }
1659 
1660  if ($key == "name" || $key == "title")
1661  {
1662  $this->tpl->setVariable("TEXT_CONTENT", $name_field[0]);
1663 
1664  $this->tpl->setCurrentBlock("subtitle");
1665  $this->tpl->setVariable("DESC", ilUtil::shortenText($name_field[1],MAXLENGTH_OBJ_DESC,true));
1666  $this->tpl->parseCurrentBlock();
1667  }
1668  else
1669  {
1670  $this->tpl->setVariable("TEXT_CONTENT", $val);
1671  }
1672 
1673  $this->tpl->parseCurrentBlock();
1674 
1675  $this->tpl->setCurrentBlock("table_cell");
1676  $this->tpl->parseCurrentBlock();
1677 
1678  } //foreach
1679 
1680  $this->tpl->setCurrentBlock("tbl_content");
1681  $this->tpl->setVariable("CSS_ROW", $css_row);
1682  $this->tpl->parseCurrentBlock();
1683  } //for
1684  } //if is_array
1685  else
1686  {
1687  $tbl->disable("header");
1688  $tbl->disable("footer");
1689 
1690  $this->tpl->setCurrentBlock("text");
1691 
1692  // do not display an "error message" here
1693  // this confuses people in administratino
1694  //$this->tpl->setVariable("TEXT_CONTENT",
1695  // $this->lng->txt("obj_not_found"));
1696  $this->tpl->setVariable("CSS_ROW", "tblrow1");
1697  $this->tpl->setVariable("TEXT_CONTENT",
1698  "&nbsp;");
1699  $this->tpl->parseCurrentBlock();
1700  }
1701 
1702  $this->showActions(true);
1703 
1704  // render table
1705  $tbl->render();
1706  }
1707 
1713  function viewObject()
1714  {
1715  global $rbacsystem;
1716 
1717  if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
1718  {
1719  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
1720  }
1721  // BEGIN ChangeEvent: record read event.
1722  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
1724  {
1725  global $ilUser;
1726  ilChangeEvent::_recordReadEvent($this->object->getId(), $ilUser->getId());
1727  }
1728  // END ChangeEvent: record read event.
1729 
1730  //prepare objectlist
1731  $this->objectList = array();
1732  $this->data["data"] = array();
1733  $this->data["ctrl"] = array();
1734  $this->data["cols"] = array("", "type", "title", "last_change");
1735 
1736  $childs = $this->tree->getChilds($_GET["ref_id"], $_GET["order"], $_GET["direction"]);
1737 
1738  foreach ($childs as $key => $val)
1739  {
1740  // visible
1741  if (!$rbacsystem->checkAccess("visible",$val["ref_id"]))
1742  {
1743  continue;
1744  }
1745 
1746  // hide object types in devmode
1747  if ($this->objDefinition->getDevMode($val["type"]))
1748  {
1749  continue;
1750  }
1751 
1752  // don't show administration in root node list
1753  if ($val["type"] == "adm")
1754  {
1755  continue;
1756  }
1757 
1758  //visible data part
1759  $this->data["data"][] = array(
1760  "type" => $val["type"],
1761  "title" => $val["title"]."#separator#".$val["desc"],
1762  //"description" => $val["desc"],
1763  "last_change" => $val["last_update"],
1764  "ref_id" => $val["ref_id"]
1765  );
1766 
1767  //control information is set below
1768 
1769  } //foreach
1770 
1771  $this->maxcount = count($this->data["data"]);
1772  // sorting array
1773  $this->data["data"] = ilUtil::sortArray($this->data["data"],$_GET["sort_by"],$_GET["sort_order"]);
1774  $this->data["data"] = array_slice($this->data["data"],$_GET["offset"],$_GET["limit"]);
1775 
1776  // now compute control information
1777  foreach ($this->data["data"] as $key => $val)
1778  {
1779  $this->data["ctrl"][$key] = array(
1780  "type" => $val["type"],
1781  "ref_id" => $val["ref_id"]
1782  );
1783 
1784  unset($this->data["data"][$key]["ref_id"]);
1785  $this->data["data"][$key]["last_change"] = ilFormat::formatDate($this->data["data"][$key]["last_change"]);
1786  }
1787 
1788  $this->displayList();
1789  }
1790 
1798  function deleteObject($a_error = false)
1799  {
1800  if ($_GET["item_ref_id"] != "")
1801  {
1802  $_POST["id"] = array($_GET["item_ref_id"]);
1803  }
1804 
1805  if (!isset($_POST["id"]))
1806  {
1807  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
1808  }
1809 
1810  // SAVE POST VALUES
1811  $_SESSION["saved_post"] = $_POST["id"];
1812 
1813  unset($this->data);
1814  $this->data["cols"] = array("type", "title", "last_change");
1815 
1816  foreach ($_POST["id"] as $id)
1817  {
1818  // TODO: cannot distinguish between obj_id from ref_id with the posted IDs.
1819  // change the form field and use instead of 'id' 'ref_id' and 'obj_id'. Then switch with varname
1820  //if ($this->call_by_reference)
1821  //{
1822  $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($id);
1823  //}
1824  //else
1825  //{
1826  // $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($id);
1827  //}
1828 
1829  $this->data["data"]["$id"] = array(
1830  "type" => $obj_data->getType(),
1831  "title" => $obj_data->getTitle()."#separator#".$obj_data->getDescription()." ", // workaround for empty desc
1832  "last_update" => $obj_data->getLastUpdateDate()
1833  );
1834  }
1835 
1836  $this->data["buttons"] = array( "confirmedDelete" => $this->lng->txt("confirm"),
1837  "cancelDelete" => $this->lng->txt("cancel"));
1838 
1839  $this->getTemplateFile("confirm");
1840 
1841  if(!$a_error)
1842  {
1843  $msg = $this->lng->txt("info_delete_sure");
1844 
1845  if (!$this->ilias->getSetting('enable_trash'))
1846  {
1847  $msg .= "<br/>".$this->lng->txt("info_delete_warning_no_trash");
1848  }
1849 
1850  ilUtil::sendInfo($msg);
1851  }
1852 
1853  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
1854 
1855  // BEGIN TABLE HEADER
1856  foreach ($this->data["cols"] as $key)
1857  {
1858  $this->tpl->setCurrentBlock("table_header");
1859  $this->tpl->setVariable("TEXT",$this->lng->txt($key));
1860  $this->tpl->parseCurrentBlock();
1861  }
1862  // END TABLE HEADER
1863 
1864  // BEGIN TABLE DATA
1865  $counter = 0;
1866 
1867  foreach ($this->data["data"] as $key => $value)
1868  {
1869  // BEGIN TABLE CELL
1870  foreach ($value as $key => $cell_data)
1871  {
1872  $this->tpl->setCurrentBlock("table_cell");
1873 
1874  // CREATE TEXT STRING
1875  if ($key == "type")
1876  {
1877  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($cell_data,$this->tpl->tplPath));
1878  }
1879  elseif ($key == "title")
1880  {
1881  $name_field = explode("#separator#",$cell_data);
1882 
1883  $this->tpl->setVariable("TEXT_CONTENT", "<b>".$name_field[0]."</b>");
1884 
1885  $this->tpl->setCurrentBlock("subtitle");
1886  $this->tpl->setVariable("DESC", $name_field[1]);
1887  $this->tpl->parseCurrentBlock();
1888  $this->tpl->setCurrentBlock("table_cell");
1889  }
1890  else
1891  {
1892  $this->tpl->setVariable("TEXT_CONTENT",$cell_data);
1893  }
1894 
1895  $this->tpl->parseCurrentBlock();
1896  }
1897 
1898  $this->tpl->setCurrentBlock("table_row");
1899  $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
1900  $this->tpl->parseCurrentBlock();
1901  // END TABLE CELL
1902  }
1903  // END TABLE DATA
1904 
1905  // BEGIN OPERATION_BTN
1906  foreach ($this->data["buttons"] as $name => $value)
1907  {
1908  $this->tpl->setCurrentBlock("operation_btn");
1909  $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
1910  $this->tpl->setVariable("BTN_NAME",$name);
1911  $this->tpl->setVariable("BTN_VALUE",$value);
1912  $this->tpl->parseCurrentBlock();
1913  }
1914  }
1915 
1921  function trashObject()
1922  {
1923  $objects = $this->tree->getSavedNodeData($_GET["ref_id"]);
1924 
1925  if (count($objects) == 0)
1926  {
1927  ilUtil::sendInfo($this->lng->txt("msg_trash_empty"));
1928  $this->data["empty"] = true;
1929  }
1930  else
1931  {
1932  $this->data["empty"] = false;
1933  $this->data["cols"] = array("","type", "title", "last_change");
1934 
1935  foreach ($objects as $obj_data)
1936  {
1937  $this->data["data"]["$obj_data[child]"] = array(
1938  "checkbox" => "",
1939  "type" => $obj_data["type"],
1940  "title" => $obj_data["title"]."#separator#".$obj_data["desc"],
1941  "last_update" => $obj_data["last_update"]
1942  );
1943  }
1944 
1945  $this->data["buttons"] = array( "undelete" => $this->lng->txt("btn_undelete"),
1946  "removeFromSystem" => $this->lng->txt("btn_remove_system"));
1947  }
1948 
1949  $this->getTemplateFile("confirm");
1950 
1951  if ($this->data["empty"] == true)
1952  {
1953  return;
1954  }
1955 
1956  /* TODO: fix message display in conjunction with ilUtil::sendInfo & raiseError functionality
1957  $this->tpl->addBlockfile("MESSAGE", "adm_trash", "tpl.message.html");
1958  $this->tpl->setCurrentBlock("adm_trash");
1959  $this->tpl->setVariable("MSG",$this->lng->txt("info_trash"));
1960  $this->tpl->parseCurrentBlock();
1961  */
1962  //ilUtil::sendInfo($this->lng->txt("info_trash"));
1963  $this->tpl->setVariable("FORMACTION",
1964  $this->ctrl->getFormAction($this));
1965  $this->tpl->setVariable("TPLPATH",$this->tpl->tplPath);
1966  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
1967 
1968  // BEGIN TABLE HEADER
1969  foreach ($this->data["cols"] as $key)
1970  {
1971  $this->tpl->setCurrentBlock("table_header");
1972  $this->tpl->setVariable("TEXT",$this->lng->txt($key));
1973  $this->tpl->parseCurrentBlock();
1974  }
1975  // END TABLE HEADER
1976 
1977  // BEGIN TABLE DATA
1978  $counter = 0;
1979 
1980  foreach ($this->data["data"] as $key1 => $value)
1981  {
1982  // BEGIN TABLE CELL
1983  foreach ($value as $key2 => $cell_data)
1984  {
1985  $this->tpl->setCurrentBlock("table_cell");
1986  // CREATE CHECKBOX
1987  if ($key2 == "checkbox")
1988  {
1989  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::formCheckBox(0,"trash_id[]",$key1));
1990  }
1991  // CREATE TEXT STRING
1992  elseif ($key2 == "type")
1993  {
1994  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($cell_data,$this->tpl->tplPath));
1995  }
1996  elseif ($key2 == "title")
1997  {
1998  $name_field = explode("#separator#",$cell_data);
1999 
2000  $this->tpl->setVariable("TEXT_CONTENT", "<b>".$name_field[0]."</b>");
2001 
2002  $this->tpl->setCurrentBlock("subtitle");
2003  $this->tpl->setVariable("DESC", $name_field[1]);
2004  $this->tpl->parseCurrentBlock();
2005  $this->tpl->setCurrentBlock("table_cell");
2006  }
2007  else
2008  {
2009  $this->tpl->setVariable("TEXT_CONTENT",$cell_data);
2010  }
2011 
2012  $this->tpl->parseCurrentBlock();
2013  }
2014 
2015  $this->tpl->setCurrentBlock("table_row");
2016  $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
2017  $this->tpl->parseCurrentBlock();
2018  // END TABLE CELL
2019  }
2020  // END TABLE DATA
2021 
2022  // BEGIN OPERATION_BTN
2023  foreach ($this->data["buttons"] as $name => $value)
2024  {
2025  $this->tpl->setCurrentBlock("operation_btn");
2026  $this->tpl->setVariable("BTN_NAME",$name);
2027  $this->tpl->setVariable("BTN_VALUE",$value);
2028  $this->tpl->parseCurrentBlock();
2029  }
2030  }
2031 
2039  function addRoleObject()
2040  {
2041  include_once './classes/class.ilPermissionGUI.php';
2042  $perm_gui =& new ilPermissionGUI($this);
2043 
2044  // dirty work around to forward command in admin panel
2045  $this->ctrl->current_node = 1;
2046  $this->ctrl->setCmd('addRole');
2047  $ret =& $this->ctrl->forwardCommand($perm_gui);
2048 
2049  return true;
2050  }
2051 
2058  function showActions($with_subobjects = false)
2059  {
2060  $notoperations = array();
2061  // NO PASTE AND CLEAR IF CLIPBOARD IS EMPTY
2062  if (empty($_SESSION["clipboard"]))
2063  {
2064  $notoperations[] = "copy"; // disable copy operation!
2065  $notoperations[] = "paste";
2066  $notoperations[] = "clear";
2067  }
2068  // CUT COPY PASTE LINK DELETE IS NOT POSSIBLE IF CLIPBOARD IS FILLED
2069  if ($_SESSION["clipboard"])
2070  {
2071  $notoperations[] = "cut";
2072  $notoperations[] = "copy";
2073  $notoperations[] = "link";
2074  }
2075 
2076  $operations = array();
2077 
2078  if ($this->actions == "")
2079  {
2080  $d = $this->getActions();
2081  //$d = $this->objDefinition->getActions($_GET["type"]);
2082  }
2083  else
2084  {
2085  $d = $this->actions;
2086  }
2087 
2088  foreach ($d as $row)
2089  {
2090  if (!in_array($row["name"], $notoperations))
2091  {
2092  $operations[] = $row;
2093  }
2094  }
2095 
2096  if (count($operations) > 0)
2097  {
2098  foreach ($operations as $val)
2099  {
2100  $this->tpl->setCurrentBlock("tbl_action_btn");
2101  $this->tpl->setVariable("BTN_NAME", $val["name"]);
2102  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt($val["lng"]));
2103  $this->tpl->parseCurrentBlock();
2104  }
2105  }
2106 
2107  if ($with_subobjects === true)
2108  {
2109  //$this->showPossibleSubObjects();
2110  }
2111 
2112  if (!empty($this->ids) && count($operations) > 0)
2113  {
2114  // set checkbox toggles
2115  $this->tpl->setCurrentBlock("tbl_action_toggle_checkboxes");
2116  $this->tpl->setVariable("JS_VARNAME","id");
2117  $this->tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($this->ids));
2118  $this->tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
2119  $this->tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
2120  $this->tpl->parseCurrentBlock();
2121  }
2122 
2123  if (count($operations) > 0)
2124  {
2125  $this->tpl->setCurrentBlock("tbl_action_row");
2126  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
2127  $this->tpl->parseCurrentBlock();
2128  }
2129  }
2130 
2134  function getActions()
2135  {
2136  return array();
2137  }
2138 
2145  {
2146  if ($this->sub_objects == "")
2147  {
2148  $d = $this->objDefinition->getCreatableSubObjects($this->object->getType());
2149  }
2150  else
2151  {
2153  }
2154 
2155  $import = false;
2156 
2157  if (count($d) > 0)
2158  {
2159  foreach ($d as $row)
2160  {
2161  $count = 0;
2162 
2163  if ($row["max"] > 0)
2164  {
2165  //how many elements are present?
2166  for ($i=0; $i<count($this->data["ctrl"]); $i++)
2167  {
2168  if ($this->data["ctrl"][$i]["type"] == $row["name"])
2169  {
2170  $count++;
2171  }
2172  }
2173  }
2174 
2175  if ($row["max"] == "" || $count < $row["max"])
2176  {
2177  $subobj[] = $row["name"];
2178 /* deprecated
2179  if ($row["import"] == "1") // import allowed?
2180  {
2181  $import = true;
2182  }
2183 */
2184  }
2185  }
2186  }
2187 
2188  if (is_array($subobj))
2189  {
2190  // show import button if at least one
2191  // object type can be imported
2192 /* deprecated
2193  if ($import)
2194  {
2195  $this->tpl->setCurrentBlock("import_object");
2196  $this->tpl->setVariable("BTN_IMP", "import");
2197  $this->tpl->setVariable("TXT_IMP", $this->lng->txt("import"));
2198  $this->tpl->parseCurrentBlock();
2199  }
2200 */
2201 
2202  //build form
2203  $opts = ilUtil::formSelect(12,"new_type",$subobj);
2204  $this->tpl->setCurrentBlock("add_object");
2205  $this->tpl->setVariable("SELECT_OBJTYPE", $opts);
2206  $this->tpl->setVariable("BTN_NAME", "create");
2207  $this->tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
2208  $this->tpl->parseCurrentBlock();
2209  }
2210  }
2211 
2220  function getTemplateFile($a_cmd,$a_type = "")
2221  {
2222  if (!$a_type)
2223  {
2224  $a_type = $this->type;
2225  }
2226 
2227  $template = "tpl.".$a_type."_".$a_cmd.".html";
2228 
2229  if (!$this->tpl->fileExists($template) &&
2230  !file_exists("./templates/default/".$template))
2231  {
2232  $template = "tpl.obj_".$a_cmd.".html";
2233  }
2234 
2235  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", $template,$a_in_module);
2236 
2237  }
2238 
2247  function getTitlesByRefId($a_ref_ids)
2248  {
2249  foreach ($a_ref_ids as $id)
2250  {
2251  // GET OBJECT TITLE
2252  $tmp_obj =& $this->ilias->obj_factory->getInstanceByRefId($id);
2253  $title[] = $tmp_obj->getTitle();
2254  unset($tmp_obj);
2255  }
2256 
2257  return $title ? $title : array();
2258  }
2259 
2267  function getTabs(&$tabs_gui)
2268  {
2269  // please define your tabs here
2270 
2271  }
2272 
2273  // PROTECTED
2274  function __showButton($a_cmd,$a_text,$a_target = '')
2275  {
2276  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
2277 
2278  // display button
2279  $this->tpl->setCurrentBlock("btn_cell");
2280  $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,$a_cmd));
2281  $this->tpl->setVariable("BTN_TXT",$a_text);
2282  if($a_target)
2283  {
2284  $this->tpl->setVariable("BTN_TARGET",$a_target);
2285  }
2286 
2287  $this->tpl->parseCurrentBlock();
2288  }
2289 
2291  {
2292  $_SESSION["tbl_limit"] = $_POST["hitsperpage"];
2293  $_GET["limit"] = $_POST["hitsperpage"];
2294  }
2295 
2296 
2297  function &__initTableGUI()
2298  {
2299  include_once "./Services/Table/classes/class.ilTableGUI.php";
2300 
2301  return new ilTableGUI(0,false);
2302  }
2303 
2309  function __setTableGUIBasicData(&$tbl,&$result_set,$a_from = "")
2310  {
2311  switch ($a_from)
2312  {
2313  case "clipboardObject":
2314  $offset = $_GET["offset"];
2315  $order = $_GET["sort_by"];
2316  $direction = $_GET["sort_order"];
2317  $tbl->disable("footer");
2318  break;
2319 
2320  default:
2321  $offset = $_GET["offset"];
2322  $order = $_GET["sort_by"];
2323  $direction = $_GET["sort_order"];
2324  break;
2325  }
2326 
2327  $tbl->setOrderColumn($order);
2328  $tbl->setOrderDirection($direction);
2329  $tbl->setOffset($offset);
2330  $tbl->setLimit($_GET["limit"]);
2331  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
2332  $tbl->setData($result_set);
2333  }
2334 
2335  function __showClipboardTable($a_result_set,$a_from = "")
2336  {
2337  $tbl =& $this->__initTableGUI();
2338  $tpl =& $tbl->getTemplateObject();
2339 
2340  $tpl->setCurrentBlock("tbl_form_header");
2341  $tpl->setVariable("FORMACTION",$this->ctrl->getTargetScript()."?".$this->link_params."&cmd=post");
2342  $tpl->parseCurrentBlock();
2343 
2344  $tpl->setCurrentBlock("tbl_action_btn");
2345  $tpl->setVariable("BTN_NAME","paste");
2346  $tpl->setVariable("BTN_VALUE",$this->lng->txt("insert_object_here"));
2347  $tpl->parseCurrentBlock();
2348 
2349  $tpl->setCurrentBlock("tbl_action_btn");
2350  $tpl->setVariable("BTN_NAME","clear");
2351  $tpl->setVariable("BTN_VALUE",$this->lng->txt("clear_clipboard"));
2352  $tpl->parseCurrentBlock();
2353 
2354  $tpl->setCurrentBlock("tbl_action_row");
2355  $tpl->setVariable("COLUMN_COUNTS",3);
2356  $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("spacer.gif"));
2357  $tpl->parseCurrentBlock();
2358 
2359  $tbl->setTitle($this->lng->txt("clipboard"),"icon_typ_b.gif",$this->lng->txt("clipboard"));
2360  $tbl->setHeaderNames(array($this->lng->txt('obj_type'),
2361  $this->lng->txt('title'),
2362  $this->lng->txt('action')));
2363  $tbl->setHeaderVars(array('type',
2364  'title',
2365  'act'),
2366  array('ref_id' => $this->object->getRefId(),
2367  'cmd' => 'clipboard',
2368  'cmdClass' => $_GET['cmdClass'],
2369  'cmdNode' => $_GET['cmdNode']));
2370 
2371  $tbl->setColumnWidth(array("","80%","19%"));
2372 
2373 
2374  $this->__setTableGUIBasicData($tbl,$a_result_set,$a_from);
2375  $tbl->render();
2376 
2377  $this->tpl->setVariable("RESULT_TABLE",$tbl->tpl->get());
2378 
2379  return true;
2380  }
2381 
2382  function infoObject()
2383  {
2384  include_once './classes/class.ilPermissionGUI.php';
2385  $perm_gui =& new ilPermissionGUI($this);
2386 
2387  // dirty work around to forward command in admin panel
2388  $this->ctrl->current_node = 1;
2389  $this->ctrl->setCmd('info');
2390  $ret =& $this->ctrl->forwardCommand($perm_gui);
2391 
2392  return true;
2393  }
2394 
2396  {
2397  $action[1] = $this->lng->txt('all_roles');
2398  $action[2] = $this->lng->txt('all_global_roles');
2399  $action[3] = $this->lng->txt('all_local_roles');
2400  $action[4] = $this->lng->txt('linked_local_roles');
2401  $action[5] = $this->lng->txt('local_roles_this_object_only');
2402 
2403  return ilUtil::formSelect($_SESSION['perm_filtered_roles'],"filter",$action,false,true);
2404  }
2405 
2406  function __filterRoles($a_roles,$a_filter)
2407  {
2408  global $rbacreview;
2409 
2410  switch ($a_filter)
2411  {
2412  case 1: // all roles
2413  return $a_roles;
2414  break;
2415 
2416  case 2: // all global roles
2417  $arr_global_roles = $rbacreview->getGlobalRoles();
2418  $arr_remove_roles = array_diff(array_keys($a_roles),$arr_global_roles);
2419 
2420  foreach ($arr_remove_roles as $role_id)
2421  {
2422  unset($a_roles[$role_id]);
2423  }
2424 
2425  return $a_roles;
2426  break;
2427 
2428  case 3: // all local roles
2429  $arr_global_roles = $rbacreview->getGlobalRoles();
2430 
2431  foreach ($arr_global_roles as $role_id)
2432  {
2433  unset($a_roles[$role_id]);
2434  }
2435 
2436  return $a_roles;
2437  break;
2438 
2439  case 4: // all roles
2440  return $a_roles;
2441  break;
2442 
2443  case 5: // local role only at this position
2444 
2445  $role_folder = $rbacreview->getRoleFolderOfObject($this->object->getRefId());
2446 
2447  if (!$role_folder)
2448  {
2449  return array();
2450  }
2451 
2452  $arr_local_roles = $rbacreview->getRolesOfRoleFolder($role_folder["ref_id"]);
2453  $arr_remove_roles = array_diff(array_keys($a_roles),$arr_local_roles);
2454 
2455  foreach ($arr_remove_roles as $role_id)
2456  {
2457  unset($a_roles[$role_id]);
2458  }
2459 
2460  return $a_roles;
2461  break;
2462  }
2463 
2464  return $a_roles;
2465  }
2466 
2467  function ownerObject()
2468  {
2469  include_once './classes/class.ilPermissionGUI.php';
2470  $perm_gui =& new ilPermissionGUI($this);
2471 
2472  // dirty work around to forward command in admin panel
2473  $this->ctrl->current_node = 1;
2474  $this->ctrl->setCmd('owner');
2475  $ret =& $this->ctrl->forwardCommand($perm_gui);
2476 
2477  return true;
2478  }
2479 
2481  {
2482  include_once './classes/class.ilPermissionGUI.php';
2483  $perm_gui =& new ilPermissionGUI($this);
2484 
2485  // dirty work around to forward command in admin panel
2486  $this->ctrl->current_node = 1;
2487  $this->ctrl->setCmd('changeOwner');
2488  $ret =& $this->ctrl->forwardCommand($perm_gui);
2489 
2490  return true;
2491  }
2492 
2502  function redirectToRefId($a_ref_id, $a_cmd = "")
2503  {
2504  $obj_type = ilObject::_lookupType($a_ref_id,true);
2505  $class_name = $this->objDefinition->getClassName($obj_type);
2506  $class = strtolower("ilObj".$class_name."GUI");
2507  $this->ctrl->redirectByClass(array("ilrepositorygui", $class), $a_cmd);
2508  }
2509 
2510  // Object Cloning
2520  public function fillCloneTemplate($a_tpl_varname,$a_type)
2521  {
2522  global $objDefinition,$ilUser,$ilSetting;
2523 
2524  $max_entries = $ilSetting->get('search_max_hits',100);
2525 
2526  if(!count($existing_objs = ilUtil::_getObjectsByOperations($a_type,'copy',$ilUser->getId(),$max_entries)))
2527  {
2528  // No Objects with copy permission found
2529  return false;
2530  }
2531 
2532  if(count($existing_objs) >= $max_entries)
2533  {
2534  return $this->fillCloneSearchTemplate($a_tpl_varname,$a_type);
2535  }
2536  unset($_SESSION['wizard_search_title']);
2537  $this->tpl->addBlockFile(strtoupper($a_tpl_varname),strtolower($a_tpl_varname),'tpl.obj_duplicate.html');
2538  $this->ctrl->setParameter($this,'new_type',$a_type);
2539  $this->tpl->setVariable('TYPE_IMG3',ilUtil::getImagePath('icon_'.$a_type.'.gif'));
2540  $this->tpl->setVariable('ALT_IMG3',$this->lng->txt('obj_'.$a_type));
2541  $this->tpl->setVariable('TXT_DUPLICATE',$this->lng->txt('obj_'.$a_type.'_duplicate'));
2542 
2543  $this->tpl->setVariable('WIZARD_TXT_SELECT',$this->lng->txt('obj_'.$a_type));
2544  $this->tpl->setVariable('WIZARD_OBJS',$this->buildCloneSelect($existing_objs));
2545 
2546  if($this->copyWizardHasOptions(self::COPY_WIZARD_NEEDS_PAGE))
2547  {
2548  $this->tpl->setVariable('FORMACTION_CLONE',$this->ctrl->getFormAction($this,'cloneWizardPage'));
2549  $this->tpl->setVariable('BTN_WIZARD',$this->lng->txt('btn_next'));
2550  $this->tpl->setVariable('CMD_WIZARD','cloneWizardPage');
2551  }
2552  else
2553  {
2554  $this->tpl->setVariable('FORMACTION_CLONE',$this->ctrl->getFormAction($this,'cloneAll'));
2555  $this->tpl->setVariable('BTN_WIZARD',$this->lng->txt('obj_'.$a_type.'_duplicate'));
2556  $this->tpl->setVariable('CMD_WIZARD','cloneAll');
2557  }
2558 
2559  $this->tpl->setVariable('WIZARD_TXT_CANCEL',$this->lng->txt('cancel'));
2560  }
2561 
2570  public function fillCloneSearchTemplate($a_tpl_varname,$a_type)
2571  {
2572  unset($_SESSION['wizard_search_title']);
2573 
2574  $this->tpl->addBlockFile(strtoupper($a_tpl_varname),strtolower($a_tpl_varname),'tpl.obj_duplicate_search.html');
2575  $this->ctrl->setParameter($this,'new_type',$a_type);
2576  $this->tpl->setVariable('FORMACTION_CLONE',$this->ctrl->getFormAction($this,'searchCloneSource'));
2577  $this->tpl->setVariable('TYPE_IMG3',ilUtil::getImagePath('icon_'.$a_type.'.gif'));
2578  $this->tpl->setVariable('ALT_IMG3',$this->lng->txt('obj_'.$a_type));
2579  $this->tpl->setVariable('TXT_DUPLICATE',$this->lng->txt('obj_'.$a_type.'_duplicate'));
2580 
2581  $this->tpl->setVariable('WIZARD_TXT_TITLE',$this->lng->txt('title'));
2582  $this->tpl->setVariable('WIZARD_TITLE',ilUtil::prepareFormOutput($_POST['wizard_search_title'],true));
2583  $this->tpl->setVariable('WIZARD_TITLE_INFO',$this->lng->txt('wizard_title_info'));
2584 
2585  $this->tpl->setVariable('BTN_WIZARD',$this->lng->txt('btn_next'));
2586  $this->tpl->setVariable('CMD_WIZARD','searchCloneSource');
2587  $this->tpl->setVariable('WIZARD_TXT_CANCEL',$this->lng->txt('cancel'));
2588  }
2589 
2595  protected function searchCloneSourceObject()
2596  {
2597  global $tree,$ilObjDataCache;
2598 
2599  $this->ctrl->setParameter($this,'new_type',$_REQUEST['new_type']);
2600 
2601  $_SESSION['wizard_search_title'] = ilUtil::stripSlashes($_POST['wizard_search_title']) ?
2602  ilUtil::stripSlashes($_POST['wizard_search_title']) :
2603  $_SESSION['wizard_search_title'];
2604 
2605  $this->lng->loadLanguageModule('search');
2606  include_once './Services/Search/classes/class.ilQueryParser.php';
2607  $query_parser =& new ilQueryParser(ilUtil::stripSlashes($_SESSION['wizard_search_title']));
2608  $query_parser->setMinWordLength(1,true);
2609  $query_parser->setCombination(QP_COMBINATION_AND);
2610  $query_parser->parse();
2611  if(!$query_parser->validate())
2612  {
2613  ilUtil::sendInfo($query_parser->getMessage());
2614  $this->createObject();
2615  return true;
2616  }
2617 
2618  // only like search since fulltext does not support search with less than 3 characters
2619  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
2620  $object_search =& new ilLikeObjectSearch($query_parser);
2621 
2622  $object_search->setFilter(array($_REQUEST['new_type']));
2623  $res = $object_search->performSearch();
2624  $res->setRequiredPermission('copy');
2625 
2626  // Add callback functions to receive only search_max_hits valid results
2627  $res->filter(ROOT_FOLDER_ID,true);
2628 
2629  if(!count($results = $res->getResultsByObjId()))
2630  {
2631  ilUtil::sendInfo($this->lng->txt('search_no_match'));
2632  $this->createObject();
2633  return true;
2634  }
2635 
2636  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.obj_duplicate_search_results.html');
2637 
2638  $num_rows = 0;
2639  foreach($results as $obj_id => $references)
2640  {
2641  foreach($references as $ref_id)
2642  {
2643  $this->tpl->setCurrentBlock('ref_row');
2644  $this->tpl->setVariable('RADIO_REF',ilUtil::formRadioButton(0,'clone_source',$ref_id));
2645  $this->tpl->setVariable('TXT_PATH',$this->lng->txt('path'));
2646 
2647  $path_arr = $tree->getPathFull($ref_id,ROOT_FOLDER_ID);
2648  $counter = 0;
2649  $path = '';
2650  foreach($path_arr as $data)
2651  {
2652  if($counter++)
2653  {
2654  $path .= " -> ";
2655  }
2656  $path .= $data['title'];
2657  }
2658  $this->tpl->setVariable('PATH',$path);
2659  $this->tpl->parseCurrentBlock();
2660  break;
2661  }
2662  if(strlen($desc = $ilObjDataCache->lookupDescription($obj_id)))
2663  {
2664  $this->tpl->setCurrentBlock('desc');
2665  $this->tpl->setVariable('DESCRIPTION',$desc);
2666  $this->tpl->parseCurrentBlock();
2667  }
2668  $this->tpl->setCurrentBlock('res_row');
2669  $this->tpl->setVariable('TBLROW',ilUtil::switchColor($num_rows++,'tblrow1','tblrow2'));
2670  $this->tpl->setVariable('TITLE',$ilObjDataCache->lookupTitle($obj_id));
2671  $this->tpl->setVariable('REFERENCES',$this->lng->txt('pathes'));
2672  $this->tpl->parseCurrentBlock();
2673  }
2674 
2675  $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this,'cancel'));
2676  $this->tpl->setVariable('TYPE_IMG',ilUtil::getImagePath('icon_'.$_REQUEST['new_type'].'.gif'));
2677  $this->tpl->setVariable('ALT_IMG',$this->lng->txt('obj_'.$_REQUEST['new_type']));
2678  $this->tpl->setVariable('TXT_DUPLICATE',$this->lng->txt('obj_'.$_REQUEST['new_type'].'_duplicate'));
2679  $this->tpl->setVariable('INFO_DUPLICATE',$this->lng->txt('wizard_search_list'));
2680  if($this->copyWizardHasOptions(self::COPY_WIZARD_NEEDS_PAGE))
2681  {
2682  $this->tpl->setVariable('BTN_COPY',$this->lng->txt('btn_next'));
2683  $this->tpl->setVariable('CMD_COPY','cloneWizardPage');
2684  }
2685  else
2686  {
2687  $this->tpl->setVariable('BTN_COPY',$this->lng->txt('obj_'.$_REQUEST['new_type'].'_duplicate'));
2688  $this->tpl->setVariable('CMD_COPY','cloneAll');
2689  }
2690  $this->tpl->setVariable('BTN_BACK',$this->lng->txt('btn_back'));
2691  return true;
2692  }
2693 
2700  public function cloneAllObject()
2701  {
2702  include_once('classes/class.ilLink.php');
2703  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
2704 
2705  global $ilAccess,$ilErr,$rbacsystem,$ilUser;
2706 
2707  $new_type = $_REQUEST['new_type'];
2708  if(!$rbacsystem->checkAccess('create',(int) $_GET['ref_id'],$new_type))
2709  {
2710  $ilErr->raiseError($this->lng->txt('permission_denied'));
2711  }
2712  if(!(int) $_REQUEST['clone_source'])
2713  {
2714  ilUtil::sendInfo($this->lng->txt('select_one'));
2715  $this->createObject();
2716  return false;
2717  }
2718  if(!$ilAccess->checkAccess('write','',(int) $_REQUEST['clone_source'],$new_type))
2719  {
2720  $ilErr->raiseError($this->lng->txt('permission_denied'));
2721  }
2722 
2723  // Save wizard options
2725  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
2726  $wizard_options->saveOwner($ilUser->getId());
2727  $wizard_options->saveRoot((int) $_REQUEST['clone_source']);
2728 
2729  $options = $_POST['cp_options'] ? $_POST['cp_options'] : array();
2730  foreach($options as $source_id => $option)
2731  {
2732  $wizard_options->addEntry($source_id,$option);
2733  }
2734  $wizard_options->read();
2735 
2736  $orig = ilObjectFactory::getInstanceByRefId((int) $_REQUEST['clone_source']);
2737  $new_obj = $orig->cloneObject((int) $_GET['ref_id'],$copy_id);
2738 
2739  // Delete wizard options
2740  $wizard_options->deleteAll();
2741 
2742  ilUtil::sendInfo($this->lng->txt("object_duplicated"),true);
2743  ilUtil::redirect(ilLink::_getLink($new_obj->getRefId()));
2744  }
2745 
2753  public function copyWizardHasOptions($a_mode)
2754  {
2755  return false;
2756  }
2757 
2764  protected function buildCloneSelect($existing_objs)
2765  {
2766  $options = ilObject::_prepareCloneSelection($existing_objs,$_REQUEST['new_type']);
2767  return ilUtil::formSelect((int) $_REQUEST['clone_source'],'clone_source',$options,false,true);
2768  }
2769 
2774  {
2775  global $ilCtrl, $ilAccess;
2776 
2777  include_once("Services/Block/classes/class.ilColumnGUI.php");
2778 
2779  $obj_id = ilObject::_lookupObjId($this->object->getRefId());
2780  $obj_type = ilObject::_lookupType($obj_id);
2781 
2782  if ($ilCtrl->getNextClass() != "ilcolumngui")
2783  {
2784  // normal command processing
2785  return $this->getContent();
2786  }
2787  else
2788  {
2789  if (!$ilCtrl->isAsynch())
2790  {
2791  //if ($column_gui->getScreenMode() != IL_SCREEN_SIDE)
2793  {
2794  // right column wants center
2796  {
2797  $column_gui = new ilColumnGUI($obj_type, IL_COL_RIGHT);
2798  $this->setColumnSettings($column_gui);
2799  $this->html = $ilCtrl->forwardCommand($column_gui);
2800  }
2801  // left column wants center
2803  {
2804  $column_gui = new ilColumnGUI($obj_type, IL_COL_LEFT);
2805  $this->setColumnSettings($column_gui);
2806  $this->html = $ilCtrl->forwardCommand($column_gui);
2807  }
2808  }
2809  else
2810  {
2811  // normal command processing
2812  return $this->getContent();
2813  }
2814  }
2815  }
2816  }
2817 
2822  {
2823  global $ilUser, $lng, $ilCtrl, $ilAccess;
2824 
2825  $obj_id = ilObject::_lookupObjId($this->object->getRefId());
2826  $obj_type = ilObject::_lookupType($obj_id);
2827 
2828  include_once("Services/Block/classes/class.ilColumnGUI.php");
2829  $column_gui = new ilColumnGUI($obj_type, IL_COL_RIGHT);
2830 
2831  if ($column_gui->getScreenMode() == IL_SCREEN_FULL)
2832  {
2833  return "";
2834  }
2835 
2836  $this->setColumnSettings($column_gui);
2837 
2838  if ($ilCtrl->getNextClass() == "ilcolumngui" &&
2839  $column_gui->getCmdSide() == IL_COL_RIGHT &&
2840  $column_gui->getScreenMode() == IL_SCREEN_SIDE)
2841  {
2842  $html = $ilCtrl->forwardCommand($column_gui);
2843  }
2844  else
2845  {
2846  if (!$ilCtrl->isAsynch())
2847  {
2848  $html = $ilCtrl->getHTML($column_gui);
2849  }
2850  }
2851 
2852  return $html;
2853  }
2854 
2858  function setColumnSettings($column_gui)
2859  {
2860  global $ilAccess;
2861 
2862  $column_gui->setRepositoryMode(true);
2863  $column_gui->setEnableEdit(false);
2864  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
2865  {
2866  $column_gui->setEnableEdit(true);
2867  }
2868  }
2869 
2870  function checkPermission($a_perm, $a_cmd = "")
2871  {
2872  global $ilAccess, $lng, $PHP_SELF;
2873 
2874  if (!is_object($this->object))
2875  {
2876  return;
2877  }
2878  if (!$ilAccess->checkAccess($a_perm, $a_cmd, $this->object->getRefId()))
2879  {
2880  $_SESSION["il_rep_ref_id"] = "";
2881  ilUtil::sendInfo($lng->txt("permission_denied"), true);
2882 
2883  if (!is_int(strpos($PHP_SELF, "goto.php")))
2884  {
2885  ilUtil::redirect("goto.php?target=".$this->object->getType()."_".
2886  $this->object->getRefId());
2887  }
2888  else // we should never be here
2889  {
2890  die("Permission Denied.");
2891  }
2892  }
2893  }
2894 
2895 } // END class.ilObjectGUI
2896 ?>