ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilExplorer.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 define("IL_FM_POSITIVE", 1);
5 define("IL_FM_NEGATIVE", 2);
6 
17 {
18  var $id;
19 
25  var $ilias;
26 
32  var $output;
33 
40 
46  var $tree;
47 
53  var $target;
54 
61 
68 
74  var $expanded;
75 
82 
88  var $order_direction = "asc";
89 
96 
103 
104 
111 
118 
125 
132 
138  var $filtered = false;
139 
146 
152  var $expand_all = false;
153 
159  var $root_id = null;
160 
161  var $use_standard_frame = false;
162 
168  function ilExplorer($a_target)
169  {
170  global $ilias, $objDefinition;
171 
172  if (!isset($a_target) or !is_string($a_target))
173  {
174  $this->ilias->raiseError(get_class($this)."::Constructor(): No target given!",$this->ilias->error_obj->WARNING);
175  }
176 
177  // autofilter object types in devmode
178  $devtypes = $objDefinition->getDevModeAll();
179 
180  if (count($devtypes > 0))
181  {
182  // activate filter if objects found in devmode
183  $this->setFiltered(true);
184 
185  foreach ($devtypes as $type)
186  {
187  $this->addFilter($type);
188  }
189  }
190 
191  $this->ilias =& $ilias;
192  $this->output = array();
193  $this->expanded = array();
194  $this->target = $a_target;
195  $this->target_get = 'ref_id';
196  $this->frame_target = "content";
197  $this->order_column = "title";
198  $this->tree = new ilTree(ROOT_FOLDER_ID);
199  $this->tree->initLangCode();
200  $this->expand_target = $_SERVER["PATH_INFO"];
201  $this->rbac_check = true;
202  $this->output_icons = true;
203  $this->expand_variable = "expand";
204  $this->setTitleLength(50);
205  $this->post_sort=true;
207  $this->highlighted = "";
208  $this->show_minus = true;
209  $this->counter = 0;
210  $this->asnch_expanding = false;
211  }
212 
218  function setId($a_val)
219  {
220  $this->id = $a_val;
221  }
222 
228  function getId()
229  {
230  return $this->id;
231  }
232 
238  function setAsynchExpanding($a_val)
239  {
240  $this->asnch_expanding = $a_val;
241  }
242 
249  {
250  return $this->asnch_expanding;
251  }
252 
260  public function initItemCounter($a_number)
261  {
262  $this->counter = $a_number;
263  }
264 
270  function setTitle($a_val)
271  {
272  $this->title = $a_val;
273  }
274 
280  public function setTitleLength($a_length)
281  {
282  $this->textwidth = $a_length;
283  }
284 
289  public function getTitleLength()
290  {
291  return $this->textwidth;
292  }
293 
299  function getTitle()
300  {
301  return $this->title;
302  }
303 
311  public function setRoot($a_root_id)
312  {
313  #$this->tree = new ilTree(ROOT_FOLDER_ID,$a_root_id);
314  $this->root_id = $a_root_id;
315  }
316 
324  public function getRoot()
325  {
326  return $this->root_id == null ?
327  $this->tree->getRootId() :
329  }
330 
336  function setOrderColumn($a_column)
337  {
338  $this->order_column = $a_column;
339  }
340 
346  function setOrderDirection($a_direction)
347  {
348  if ($a_direction == "desc")
349  {
350  $this->order_direction = $a_direction;
351  }
352  else
353  {
354  $this->order_direction = "asc";
355  }
356  }
357 
363  function setTargetGet($a_target_get)
364  {
365  if (!isset($a_target_get) or !is_string($a_target_get))
366  {
367  $this->ilias->raiseError(get_class($this)."::setTargetGet(): No target given!",$this->ilias->error_obj->WARNING);
368  }
369 
370  $this->target_get = $a_target_get;
371  }
372 
378  function setParamsGet($a_params_get)
379  {
380  if (!isset($a_params_get) or !is_array($a_params_get))
381  {
382  $this->ilias->raiseError(get_class($this)."::setTargetGet(): No target given!",$this->ilias->error_obj->WARNING);
383  }
384 
385  foreach ($a_params_get as $key => $val)
386  {
387  $str .= "&".$key."=".$val;
388  }
389 
390  $this->params_get = $str;
391  }
392 
393 
400  function setExpandTarget($a_exp_target)
401  {
402  $this->expand_target = $a_exp_target;
403  }
404 
410  function setFrameUpdater($a_up_frame, $a_up_script, $a_params = "")
411  {
412  $this->up_frame = $a_up_frame;
413  $this->up_script = $a_up_script;
414  $this->up_params = $a_params;
415  }
416 
417 
421  function highlightNode($a_id)
422  {
423  $this->highlighted = $a_id;
424  }
425 
431  function checkPermissions($a_check)
432  {
433  $this->rbac_check = $a_check;
434  }
435 
441  function setSessionExpandVariable($a_var_name = "expand")
442  {
443  $this->expand_variable = $a_var_name;
444  }
445 
451  function outputIcons($a_icons)
452  {
453  $this->output_icons = $a_icons;
454  }
455 
456 
463  function setClickable($a_type, $a_clickable)
464  {
465  if($a_clickable)
466  {
467  $this->is_clickable[$a_type] = "";
468  }
469  else
470  {
471  $this->is_clickable[$a_type] = "n";
472  }
473  }
474 
475  function isVisible($a_ref_id,$a_type)
476  {
477  global $rbacsystem, $ilBench;
478 
479  if (!$this->rbac_check)
480  {
481  return true;
482  }
483 
484  $ilBench->start("Explorer", "setOutput_isVisible");
485  $visible = $rbacsystem->checkAccess('visible',$a_ref_id);
486  $ilBench->stop("Explorer", "setOutput_isVisible");
487 
488  return $visible;
489  }
490 
496  public function setTreeLead($a_val)
497  {
498  $this->tree_lead = $a_val;
499  }
500 
506  public function getTreeLead()
507  {
508  return $this->tree_lead;
509  }
510 
518  function isClickable($a_type, $a_ref_id = 0)
519  {
520  // in this standard implementation
521  // only the type determines, wether an object should be clickable or not
522  // but this method can be overwritten and make $exp->setFilterMode(IL_FM_NEGATIVE);use of the ref id
523  // (this happens e.g. in class ilRepositoryExplorerGUI)
524  if ($this->is_clickable[$a_type] == "n")
525  {
526  return false;
527  }
528  else
529  {
530  return true;
531  }
532  }
533 
538  function setPostSort($a_sort)
539  {
540  $this->post_sort = $a_sort;
541  }
542 
548  function setFilterMode($a_mode = IL_FM_NEGATIVE)
549  {
550  $this->filter_mode = $a_mode;
551  }
552 
558  function getFilterMode()
559  {
560  return $this->filter_mode;
561  }
562 
569  function setUseStandardFrame($a_val)
570  {
571  $this->use_standard_frame = $a_val;
572  }
573 
580  {
582  }
583 
590  function getChildsOfNode($a_parent_id)
591  {
592  return $this->tree->getChilds($a_parent_id, $this->order_column);
593  }
594 
595 
604  function setOutput($a_parent_id, $a_depth = 1,$a_obj_id = 0, $a_highlighted_subtree = false)
605  {
606  global $rbacadmin, $rbacsystem, $ilBench;
607 
608 #echo 'ParentId: '.$a_parent_id.' depth: '.$a_depth.' obj_id: '.$a_obj_id;
609 
610  if (!isset($a_parent_id))
611  {
612  $this->ilias->raiseError(get_class($this)."::setOutput(): No node_id given!",$this->ilias->error_obj->WARNING);
613  }
614 
615  if ($this->showChilds($a_parent_id,$a_obj_id))
616  {
617  $objects = $this->getChildsOfNode($a_parent_id);
618  }
619  else
620  {
621  $objects = array();
622  }
623 
624  $objects = $this->modifyChilds($a_parent_id, $objects);
625 
626  // force expansion (of single nodes)
627  if ($this->forceExpanded($a_parent_id) && !in_array($a_parent_id, $this->expanded))
628  {
629  $this->expanded[] = $a_parent_id;
630  }
631 
632  if (count($objects) > 0)
633  {
634  // Maybe call a lexical sort function for the child objects
635  $tab = ++$a_depth - 2;
636  if ($this->post_sort)
637  {
638  $objects = $this->sortNodes($objects,$a_obj_id);
639  }
640  $skip_rest = false;
641  foreach ($objects as $key => $object)
642  {
643  // skip childs, if parent is not expanded
644  if (!$this->forceExpanded($object["child"]) && $skip_rest)
645  {
646  continue;
647  }
648 //echo "<br>-".$object["child"]."-".$this->forceExpanded($object["child"])."-";
649  //ask for FILTER
650  if ($this->filtered == false or $this->checkFilter($object["type"]) == false)
651  {
652  if ($this->isVisible($object['child'],$object['type']))
653  {
654  $ilBench->start("Explorer", "setOutput_setFormatOptions");
655  #echo 'CHILD getIndex() '.$object['child'].' parent: '.$this->getRoot();
656  if ($object["child"] != $this->getRoot())
657  {
658  $parent_index = $this->getIndex($object);
659  }
660  $this->format_options["$this->counter"]["parent"] = $object["parent"];
661  $this->format_options["$this->counter"]["child"] = $object["child"];
662  $this->format_options["$this->counter"]["title"] = $object["title"];
663  $this->format_options["$this->counter"]["type"] = $object["type"];
664  $this->format_options["$this->counter"]["obj_id"] = $object["obj_id"];
665  $this->format_options["$this->counter"]["desc"] = "obj_".$object["type"];
666  $this->format_options["$this->counter"]["depth"] = $tab;
667  $this->format_options["$this->counter"]["container"] = false;
668  $this->format_options["$this->counter"]["visible"] = true;
669  $this->format_options["$this->counter"]["highlighted_subtree"] = $a_highlighted_subtree;
670 
671  // Create prefix array
672  for ($i = 0; $i < $tab; ++$i)
673  {
674  $this->format_options["$this->counter"]["tab"][] = 'blank';
675  }
676 
677  // fix explorer (sometimes explorer disappears)
678  if ($parent_index == 0)
679  {
680  if (!$this->expand_all and !in_array($object["parent"], $this->expanded))
681  {
682  $this->expanded[] = $object["parent"];
683  }
684  }
685 
686  // only if parent is expanded and visible, object is visible
687  if ($object["child"] != $this->getRoot() and ((!$this->expand_all and !in_array($object["parent"],$this->expanded))
688  or !$this->format_options["$parent_index"]["visible"]))
689  {
690  if (!$this->forceExpanded($object["child"]))
691  {
692  // if parent is not expanded, and one child is
693  // visible we don't need more information and
694  // can skip the rest of the childs
695  if ($this->format_options["$this->counter"]["visible"])
696  {
697 //echo "-setSkipping";
698  $skip_rest = true;
699  }
700  $this->format_options["$this->counter"]["visible"] = false;
701  }
702  }
703 
704  // if object exists parent is container
705  if ($object["child"] != $this->getRoot())
706  {
707  $this->format_options["$parent_index"]["container"] = true;
708 
709  if ($this->expand_all or in_array($object["parent"],$this->expanded))
710  {
711  //echo "<br>-".$object["child"]."-".$this->forceExpanded($object["child"])."-";
712  if ($this->forceExpanded($object["parent"]))
713  {
714  $this->format_options["$parent_index"]["tab"][($tab-2)] = 'forceexp';
715  }
716  else
717  {
718  $this->format_options["$parent_index"]["tab"][($tab-2)] = 'minus';
719  }
720  }
721  else
722  {
723  $this->format_options["$parent_index"]["tab"][($tab-2)] = 'plus';
724  }
725  }
726  //echo "-"."$parent_index"."-";
727  //var_dump($this->format_options["$parent_index"]);
728  ++$this->counter;
729  $ilBench->stop("Explorer", "setOutput_setFormatOptions");
730 
731  // stop recursion if 2. level beyond expanded nodes is reached
732  if ($this->expand_all or in_array($object["parent"],$this->expanded) or ($object["parent"] == 0)
733  or $this->forceExpanded($object["child"]))
734  {
735  $highlighted_subtree = ($a_highlighted_subtree ||
736  ($object["child"] == $this->highlighted))
737  ? true
738  : false;
739 
740  // recursive
741  $this->setOutput($object["child"],$a_depth,$object['obj_id'], $highlighted_subtree);
742  }
743  } //if
744  } //if FILTER
745  } //foreach
746  } //if
747  } //function
748 
749  function modifyChilds($a_parent_id, $a_objects)
750  {
751  return $a_objects;
752  }
753 
759  function showChilds($a_parent_id)
760  {
761  return true;
762  }
763 
767  function forceExpanded($a_obj_id)
768  {
769  return false;
770  }
771 
779  {
780  $this->tree->getMaximumDepth();
781  }
782 
783 
790  function getOutput()
791  {
792  global $ilBench, $tpl, $lng;
793 
794  $ilBench->start("Explorer", "getOutput");
795 
796  $this->format_options[0]["tab"] = array();
797 
798  $depth = $this->getMaximumTreeDepth();
799 
800  for ($i=0;$i<$depth;++$i)
801  {
802  $this->createLines($i);
803  }
804 
805  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
807  $tpl->addJavaScript("./Services/UIComponent/Explorer/js/ilExplorer.js");
808 
809  $tpl->addBlockFile("EXPLORER_TOP", "exp_top", "tpl.explorer_top.html");
810 //echo "hh";
811  // set global body class
812  $tpl->setBodyClass("il_Explorer");
813 
814  $tpl_tree = new ilTemplate("tpl.tree.html", true, true, "Services/UIComponent/Explorer");
815 
816  // updater
817  if (($_GET["ict"] || $_POST["collapseAll"] != "" || $_POST["expandAll"] != "") && $this->up_frame != "")
818  {
819  $tpl_tree->setCurrentBlock("updater");
820  $tpl_tree->setVariable("UPDATE_FRAME", $this->up_frame);
821  $tpl_tree->setVariable("UPDATE_SCRIPT", $this->up_script);
822  if (is_array($this->up_params))
823  {
824  $up_str = $lim = "";
825  foreach ($this->up_params as $p)
826  {
827  $up_str.= $lim."'".$p."'";
828  $lim = ",";
829  }
830  $tpl_tree->setVariable("UPDATE_PARAMS", $up_str);
831  }
832  $tpl_tree->parseCurrentBlock();
833  }
834 
835  $cur_depth = -1;
836  foreach ($this->format_options as $key => $options)
837  {
838 //echo "-".$options["depth"]."-";
839  if (!$options["visible"])
840  {
841  continue;
842  }
843 
844  // end tags
845  $this->handleListEndTags($tpl_tree, $cur_depth, $options["depth"]);
846 
847  // start tags
848  $this->handleListStartTags($tpl_tree, $cur_depth, $options["depth"]);
849 
850  $cur_depth = $options["depth"];
851 
852  if ($options["visible"] and $key != 0)
853  {
854  $this->formatObject($tpl_tree, $options["child"],$options,$options['obj_id']);
855  }
856  if ($key == 0)
857  {
858  $this->formatHeader($tpl_tree, $options["child"],$options);
859  }
860 
861  }
862 //if ($GLOBALS["ilUser"]->getLogin() == "alex") var_dump($this->format_options);
863  $this->handleListEndTags($tpl_tree, $cur_depth, -1);
864 
865  $ilBench->stop("Explorer", "getOutput");
866 
867  $tpl_tree->setVariable("TREE_LEAD", "");
868  if ($this->tree_lead != "")
869  {
870  $tpl_tree->setCurrentBlock("tree_lead");
871  $tpl_tree->setVariable("TREE_LEAD", $this->tree_lead);
872  $tpl_tree->parseCurrentBlock();
873  }
874  if ($this->getId() != "")
875  {
876  $tpl_tree->setVariable("TREE_ID", 'id="'.$this->getId().'_tree"');
877  }
878 
879  $html = $tpl_tree->get();
880 
881  if ($this->getUseStandardFrame())
882  {
883  $mtpl = new ilTemplate("tpl.main.html", true, true);
884  $mtpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
885  $mtpl->setVariable("BODY_CLASS", "il_Explorer");
886  $mtpl->addBlockFile("CONTENT", "content", "tpl.explorer.html");
887  if ($this->getTitle() != "")
888  {
889  $mtpl->setVariable("TXT_EXPLORER_HEADER", $this->getTitle());
890  }
891  if ($this->getId() != "")
892  {
893  $mtpl->setVariable("ID", 'id="'.$this->getId().'"');
894  }
895  $mtpl->setVariable("IMG_SPACE", ilUtil::getImagePath("spacer.png", false));
896  $mtpl->setCurrentBlock("content");
897  $mtpl->setVariable("EXPLORER", $html);
898  $mtpl->setVariable("EXP_REFRESH", $lng->txt("refresh"));
899  $mtpl->parseCurrentBlock();
900  $html = $mtpl->get();
901  }
902 
903  return $html;
904  }
905 
906 
907 
911  function handleListEndTags(&$a_tpl_tree, $a_cur_depth, $a_item_depth)
912  {
913  if ($a_item_depth < $a_cur_depth)
914  {
915  // </li></ul> for ending lists
916  for ($i = 0; $i < ($a_cur_depth - $a_item_depth); $i++)
917  {
918  $a_tpl_tree->touchBlock("end_list_item");
919  $a_tpl_tree->touchBlock("element");
920 
921  $a_tpl_tree->touchBlock("end_list");
922  $a_tpl_tree->touchBlock("element");
923  }
924  }
925  else if ($a_item_depth == $a_cur_depth)
926  {
927  // </li> for ending list items
928  $a_tpl_tree->touchBlock("end_list_item");
929  $a_tpl_tree->touchBlock("element");
930  }
931  }
932 
936  function handleListStartTags(&$a_tpl_tree, $a_cur_depth, $a_item_depth)
937  {
938  // start tags
939  if ($a_item_depth > $a_cur_depth)
940  {
941  // <ul><li> for new lists
942  if ($a_item_depth > 1)
943  {
944  $a_tpl_tree->touchBlock("start_list");
945  }
946  else
947  {
948  $a_tpl_tree->touchBlock("start_list_no_indent");
949  }
950  $a_tpl_tree->touchBlock("element");
951 
952  $a_tpl_tree->touchBlock("start_list_item");
953  $a_tpl_tree->touchBlock("element");
954  }
955  else
956  {
957  // <li> items
958  $a_tpl_tree->touchBlock("start_list_item");
959  $a_tpl_tree->touchBlock("element");
960  }
961  }
962 
971  function formatHeader(&$tpl,$a_obj_id,$a_option)
972  {
973  }
974 
983  function formatObject(&$tpl, $a_node_id,$a_option,$a_obj_id = 0)
984  {
985  global $lng;
986  if (!isset($a_node_id) or !is_array($a_option))
987  {
988  $this->ilias->raiseError(get_class($this)."::formatObject(): Missing parameter or wrong datatype! ".
989  "node_id: ".$a_node_id." options:".var_dump($a_option),$this->ilias->error_obj->WARNING);
990  }
991 
992  $pic = false;
993  foreach ((array) $a_option["tab"] as $picture)
994  {
995  if ($picture == 'plus')
996  {
997  $tpl->setCurrentBlock("exp_desc");
998  $tpl->setVariable("EXP_DESC", $lng->txt("collapsed"));
999  $tpl->parseCurrentBlock();
1000  $tpl->setCurrentBlock("expander");
1001  $tpl->setVariable("LINK_NAME", $a_node_id);
1002  if (!$this->getAsynchExpanding())
1003  {
1004  $target = $this->createTarget('+',$a_node_id, $a_option["highlighted_subtree"]);
1005  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
1006  }
1007  else
1008  {
1009  $target = $this->createTarget('+',$a_node_id, $a_option["highlighted_subtree"], false);
1010  $tpl->setVariable("ONCLICK_TARGET_EXPANDER", " onclick=\"return il.Explorer.refresh('tree_div', '".$target."');\"");
1011  $tpl->setVariable("LINK_TARGET_EXPANDER", "#");
1012  }
1013  $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.png"));
1014  $tpl->parseCurrentBlock();
1015  $pic = true;
1016  }
1017 
1018  if ($picture == 'forceexp')
1019  {
1020  $tpl->setCurrentBlock("exp_desc");
1021  $tpl->setVariable("EXP_DESC", $lng->txt("expanded"));
1022  $tpl->parseCurrentBlock();
1023  $target = $this->createTarget('+',$a_node_id);
1024  $tpl->setCurrentBlock("expander");
1025  $tpl->setVariable("LINK_NAME", $a_node_id);
1026  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
1027  $tpl->setVariable("IMGPATH", $this->getImage("browser/forceexp.png"));
1028  $tpl->parseCurrentBlock();
1029  $pic = true;
1030  }
1031 
1032  if ($picture == 'minus' && $this->show_minus)
1033  {
1034  $tpl->setCurrentBlock("exp_desc");
1035  $tpl->setVariable("EXP_DESC", $lng->txt("expanded"));
1036  $tpl->parseCurrentBlock();
1037  $tpl->setCurrentBlock("expander");
1038  $tpl->setVariable("LINK_NAME", $a_node_id);
1039  if (!$this->getAsynchExpanding())
1040  {
1041  $target = $this->createTarget('-',$a_node_id, $a_option["highlighted_subtree"]);
1042  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
1043  }
1044  else
1045  {
1046  $target = $this->createTarget('-',$a_node_id, $a_option["highlighted_subtree"], false);
1047  $tpl->setVariable("ONCLICK_TARGET_EXPANDER", " onclick=\"return il.Explorer.refresh('tree_div', '".$target."');\"");
1048  $tpl->setVariable("LINK_TARGET_EXPANDER", "#");
1049  }
1050  $tpl->setVariable("IMGPATH", $this->getImage("browser/minus.png"));
1051  $tpl->parseCurrentBlock();
1052  $pic = true;
1053  }
1054 
1055  /*
1056  if ($picture == 'blank' or $picture == 'winkel'
1057  or $picture == 'hoch' or $picture == 'quer' or $picture == 'ecke')
1058  {
1059  $picture = "blank";
1060  $tpl->setCurrentBlock("lines");
1061  $tpl->setVariable("IMGPATH_LINES", $this->getImage("browser/".$picture.".png"));
1062  $tpl->parseCurrentBlock();
1063  }
1064  */
1065  }
1066 
1067  if (!$pic)
1068  {
1069  $tpl->setCurrentBlock("blank");
1070  $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.png"));
1071  $tpl->parseCurrentBlock();
1072  }
1073 
1074  if ($this->output_icons)
1075  {
1076  $tpl->setCurrentBlock("icon");
1077  $tpl->setVariable("ICON_IMAGE" , $this->getImage("icon_".$a_option["type"]."_s.png", $a_option["type"], $a_obj_id));
1078 
1079  $tpl->setVariable("TARGET_ID" , "iconid_".$a_node_id);
1080  $this->iconList[] = "iconid_".$a_node_id;
1081  $tpl->setVariable("TXT_ALT_IMG",
1082  $this->getImageAlt($lng->txt("icon")." ".$lng->txt($a_option["desc"]), $a_option["type"], $a_obj_id));
1083  $tpl->parseCurrentBlock();
1084  }
1085 
1086  if(strlen($sel = $this->buildSelect($a_node_id,$a_option['type'])))
1087  {
1088  $tpl->setCurrentBlock('select');
1089  $tpl->setVariable('OBJ_SEL',$sel);
1090  $tpl->parseCurrentBlock();
1091  }
1092 
1093  if ($this->isClickable($a_option["type"], $a_node_id,$a_obj_id)) // output link
1094  {
1095  $tpl->setCurrentBlock("link");
1096  //$target = (strpos($this->target, "?") === false) ?
1097  // $this->target."?" : $this->target."&";
1098  //$tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
1099  $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
1100 
1101  $style_class = $this->getNodeStyleClass($a_node_id, $a_option["type"]);
1102 
1103  if ($style_class != "")
1104  {
1105  $tpl->setVariable("A_CLASS", ' class="'.$style_class.'" ' );
1106  }
1107 
1108  if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) != "")
1109  {
1110  $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
1111  }
1112 
1113  //$tpl->setVariable("LINK_NAME", $a_node_id);
1114  $tpl->setVariable("TITLE", ilUtil::shortenText(
1115  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]),
1116  $this->textwidth, true));
1117  $tpl->setVariable("DESC", ilUtil::shortenText(
1118  $this->buildDescription($a_option["description"], $a_node_id, $a_option["type"]), $this->textwidth, true));
1119  $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
1120  if ($frame_target != "")
1121  {
1122  $tpl->setVariable("TARGET", " target=\"".$frame_target."\"");
1123  }
1124  $tpl->parseCurrentBlock();
1125  }
1126  else // output text only
1127  {
1128  $tpl->setCurrentBlock("text");
1129  $tpl->setVariable("OBJ_TITLE", ilUtil::shortenText(
1130  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]), $this->textwidth, true));
1131  $tpl->setVariable("OBJ_DESC", ilUtil::shortenText(
1132  $this->buildDescription($a_option["desc"], $a_node_id, $a_option["type"]), $this->textwidth, true));
1133  $tpl->parseCurrentBlock();
1134  }
1135 
1136  $tpl->setCurrentBlock("list_item");
1137  $tpl->parseCurrentBlock();
1138  $tpl->touchBlock("element");
1139  }
1140 
1144  function getImage($a_name, $a_type = "", $a_obj_id = "")
1145  {
1146  return ilUtil::getImagePath($a_name);
1147  }
1148 
1152  function getImageAlt($a_default_text, $a_type = "", $a_obj_id = "")
1153  {
1154  return $a_default_text;
1155  }
1156 
1160  function getNodeStyleClass($a_id, $a_type)
1161  {
1162  if ($a_id == $this->highlighted)
1163  {
1164  return "il_HighlightedNode";
1165  }
1166  return "";
1167  }
1168 
1172  function buildLinkTarget($a_node_id, $a_type)
1173  {
1174  $target = (strpos($this->target, "?") === false)
1175  ? $this->target."?"
1176  : $this->target."&";
1177  return $target.$this->target_get."=".$a_node_id.$this->params_get;
1178  }
1179 
1183  function buildOnClick($a_node_id, $a_type, $a_title)
1184  {
1185  return "";
1186  }
1187 
1191  function buildTitle($a_title, $a_id, $a_type)
1192  {
1193  return $a_title;
1194  }
1195 
1199  function buildDescription($a_desc, $a_id, $a_type)
1200  {
1201  return "";
1202  }
1203 
1207  function buildSelect($a_node_id,$a_type)
1208  {
1209  return "";
1210  }
1211 
1212 
1216  function buildFrameTarget($a_type, $a_child = 0, $a_obj_id = 0)
1217  {
1218  return $this->frame_target;
1219  }
1220 
1221 
1229  function createTarget($a_type,$a_node_id,$a_highlighted_subtree = false, $a_append_anch = true)
1230  {
1231  if (!isset($a_type) or !is_string($a_type) or !isset($a_node_id))
1232  {
1233  $this->ilias->raiseError(get_class($this)."::createTarget(): Missing parameter or wrong datatype! ".
1234  "type: ".$a_type." node_id:".$a_node_id,$this->ilias->error_obj->WARNING);
1235  }
1236 
1237  // SET expand parameter:
1238  // positive if object is expanded
1239  // negative if object is compressed
1240  $a_node_id = $a_type == '+' ? $a_node_id : -(int) $a_node_id;
1241 
1242  $sep = (is_int(strpos($this->expand_target, "?")))
1243  ? "&"
1244  : "?";
1245 
1246  // in current tree flag
1247  $ict_str = ($a_highlighted_subtree || $this->highlighted == "")
1248  ? "&ict=1"
1249  : "";
1250  if ($this->getAsynchExpanding())
1251  {
1252  $ict_str.= "&cmdMode=asynch";
1253  }
1254  if ($a_append_anch)
1255  {
1256  return $this->expand_target.$sep.$this->expand_variable."=".$a_node_id.$this->params_get.$ict_str."#".abs($a_node_id);
1257  }
1258  else
1259  {
1260  return $this->expand_target.$sep.$this->expand_variable."=".$a_node_id.$this->params_get.$ict_str;
1261  }
1262  }
1263 
1270  function setFrameTarget($a_target)
1271  {
1272  $this->frame_target = $a_target;
1273  }
1274 
1280  function createLines($a_depth)
1281  {
1282  for ($i = 0; $i < count($this->format_options); ++$i)
1283  {
1284  if ($this->format_options[$i]["depth"] == $a_depth+1
1285  and !$this->format_options[$i]["container"]
1286  and $this->format_options[$i]["depth"] != 1)
1287  {
1288  $this->format_options[$i]["tab"]["$a_depth"] = "quer";
1289  }
1290 
1291  if ($this->format_options[$i]["depth"] == $a_depth+2)
1292  {
1293  if ($this->is_in_array($i+1,$this->format_options[$i]["depth"]))
1294  {
1295  $this->format_options[$i]["tab"]["$a_depth"] = "winkel";
1296  }
1297  else
1298  {
1299  $this->format_options[$i]["tab"]["$a_depth"] = "ecke";
1300  }
1301  }
1302 
1303  if ($this->format_options[$i]["depth"] > $a_depth+2)
1304  {
1305  if ($this->is_in_array($i+1,$a_depth+2))
1306  {
1307  $this->format_options[$i]["tab"]["$a_depth"] = "hoch";
1308  }
1309  }
1310  }
1311  }
1312 
1320  function is_in_array($a_start,$a_depth)
1321  {
1322  for ($i=$a_start;$i<count($this->format_options);++$i)
1323  {
1324  if ($this->format_options[$i]["depth"] < $a_depth)
1325  {
1326  break;
1327  }
1328 
1329  if ($this->format_options[$i]["depth"] == $a_depth)
1330  {
1331  return true;
1332  }
1333  }
1334  return false;
1335  }
1336 
1343  function getIndex($a_data)
1344  {
1345  if(!is_array($this->format_options))
1346  {
1347  return -1;
1348  }
1349 
1350  foreach ($this->format_options as $key => $value)
1351  {
1352  if (($value["child"] == $a_data["parent"]))
1353  {
1354  return $key;
1355  }
1356  }
1357 
1358  return -1;
1359  // exit on error
1360  #$this->ilias->raiseError(get_class($this)."::getIndex(): Error in tree. No index found!",$this->ilias->error_obj->FATAL);
1361  }
1362 
1369  function addFilter($a_item)
1370  {
1371  $ispresent = 0;
1372 
1373  if (is_array($this->filter))
1374  {
1375  //run through filter
1376  foreach ($this->filter as $item)
1377  {
1378  if ($item == $a_item)
1379  {
1380  $is_present = 1;
1381 
1382  return false;
1383  }
1384  }
1385  }
1386  else
1387  {
1388  $this->filter = array();
1389  }
1390  if ($is_present == 0)
1391  {
1392  $this->filter[] = $a_item;
1393  }
1394 
1395  return true;
1396  }
1397 
1404  function delFilter($a_item)
1405  {
1406  //check if a filter exists
1407  if (is_array($this->filter))
1408  {
1409  //build copy of the existing filter without the given item
1410  $tmp = array();
1411 
1412  foreach ($this->filter as $item)
1413  {
1414  if ($item != $a_item)
1415  {
1416  $tmp[] = $item;
1417  }
1418  else
1419  {
1420  $deleted = 1;
1421  }
1422  }
1423 
1424  $this->filter = $tmp;
1425  }
1426  else
1427  {
1428  return false;
1429  }
1430 
1431  if ($deleted == 1)
1432  {
1433  return true;
1434  }
1435  else
1436  {
1437  return false;
1438  }
1439  }
1440 
1447  function setExpand($a_node_id)
1448  {
1449  // IF ISN'T SET CREATE SESSION VARIABLE
1450  if(!is_array($_SESSION[$this->expand_variable]))
1451  {
1452  $_SESSION[$this->expand_variable] = array($this->getRoot());
1453  }
1454  // IF $_GET["expand"] is positive => expand this node
1455  if ($a_node_id > 0 && !in_array($a_node_id,$_SESSION[$this->expand_variable]))
1456  {
1457  array_push($_SESSION[$this->expand_variable],$a_node_id);
1458  }
1459  // IF $_GET["expand"] is negative => compress this node
1460  if ($a_node_id < 0)
1461  {
1462  $key = array_keys($_SESSION[$this->expand_variable],-(int) $a_node_id);
1463  unset($_SESSION[$this->expand_variable][$key[0]]);
1464  }
1465  $this->expanded = $_SESSION[$this->expand_variable];
1466  }
1467 
1474  function forceExpandAll($a_mode, $a_show_minus = true)
1475  {
1476  $this->expand_all = (bool) $a_mode;
1477  $this->show_minus = $a_show_minus;
1478  }
1479 
1486  function setFiltered($a_bool)
1487  {
1488  $this->filtered = $a_bool;
1489  return true;
1490  }
1491 
1498  function checkFilter($a_item)
1499  {
1500  if (is_array($this->filter))
1501  {
1502  if (in_array($a_item, $this->filter))
1503  {
1504  $ret = true;
1505  }
1506  else
1507  {
1508  $ret = false;
1509  }
1510  }
1511  else
1512  {
1513  $ret = false;
1514  }
1515 
1516  if ($this->getFilterMode() == IL_FM_NEGATIVE )
1517  {
1518  return $ret;
1519  }
1520  else
1521  {
1522  return !$ret;
1523  }
1524  }
1525 
1532  function sortNodes($a_nodes,$a_parent_obj_id)
1533  {
1534  foreach ($a_nodes as $key => $node)
1535  {
1536  if ($node["type"] == "adm")
1537  {
1538  $match = $key;
1539  $adm_node = $node;
1540  break;
1541  }
1542  }
1543 
1544  // cut off adm node
1545  isset($match) ? array_splice($a_nodes,$match,1) : "";
1546 
1547  $a_nodes = ilUtil::sortArray($a_nodes,$this->order_column,$this->order_direction);
1548 
1549  // append adm node to end of list
1550  isset ($match) ? array_push($a_nodes,$adm_node) : "";
1551 
1552  return $a_nodes;
1553  }
1554 } // END class.ilExplorer
1555 ?>