4 include_once(
"./Services/Form/classes/class.ilFormGUI.php");
26 $this->multi_commands = array();
27 $this->commands = array();
28 $this->drag_target[] = array();
29 $this->drag_content[] = array();
30 $lng->loadLanguageModule(
"form");
33 $this->help_items = array();
35 include_once(
"./Services/YUI/classes/class.ilYuiUtil.php");
37 $tpl->addJavascript(
"./Services/Form/js/ServiceFormHierarchyForm.js");
47 $this->parent_obj = $a_parent_obj;
48 $this->parent_cmd = $a_parent_cmd;
58 return $this->parent_obj;
68 return $this->parent_cmd;
78 die(
"ilHierarchyFormGUI does currently not support multiple forms (multiple IDs). ID is always hform.");
98 $this->tree = $a_tree;
118 $this->currenttopnodeid = $a_currenttopnodeid;
128 return $this->currenttopnodeid;
138 $this->title = $a_title;
158 $this->icon = $a_icon;
178 $this->checkboxname = $a_checkboxname;
188 return $this->checkboxname;
198 $this->dragicon = $a_dragicon;
208 return $this->dragicon;
218 $this->maxdepth = $a_maxdepth;
228 return $this->maxdepth;
238 $this->exp_frame = $a_exp_frame;
239 $this->exp_id = $a_exp_id;
240 $this->exp_target_script = $a_exp_target_script;
250 $this->triggered_update_command = $a_triggered_update_command;
258 $this->help_items[] = array(
"text" => $a_text,
259 "image" => $a_image);
267 return $this->help_items;
276 function makeDragTarget($a_id, $a_group, $a_first_child_drop_area =
false, $a_as_subitem =
false, $a_diss_text =
"")
278 if ($a_first_child_drop_area ==
true)
280 $a_as_subitem =
true;
285 if ($a_first_child_drop_area)
290 $this->drag_target[] = array(
"id" => $a_id,
"group" => $a_group);
291 $this->diss_menues[$a_id][$a_group][] = array(
"subitem" => $a_as_subitem,
"text" => $a_diss_text);
305 $this->drag_content[] = array(
"id" => $a_id,
"group" => $a_group);
317 $this->multi_commands[] = array(
"text" => $a_txt,
"cmd" => $a_cmd);
328 $this->commands[] = array(
"text" => $a_txt,
"cmd" => $a_cmd);
338 $this->highlighted_nodes = $a_val;
348 return $this->highlighted_nodes;
358 $this->focus_id = $a_val;
368 return $this->focus_id;
378 $this->expand_variable = $a_val;
388 return $this->expand_variable;
398 $this->expanded = $a_val;
408 return $this->expanded;
431 if (
$_POST[
"il_hform_expand"] !=
"")
433 $node_id =
$_POST[
"il_hform_expand"];
435 if (
$_GET[$ev] !=
"")
437 $node_id =
$_GET[$ev];
441 if ($node_id > 0 && !in_array($node_id,
$_SESSION[$ev]))
448 $key = array_keys(
$_SESSION[$ev],-(
int) $node_id);
460 if ($a_node_id ==
false)
465 $tree_childs = $this->
getTree()->getChilds($a_node_id);
467 foreach($tree_childs as $tree_child)
469 $childs[] = array(
"node_id" => $tree_child[
"child"],
470 "title" => $tree_child[
"title"],
471 "type" => $tree_child[
"type"]);
489 $ttpl =
new ilTemplate(
"tpl.hierarchy_form.html",
true,
true,
"Services/Form");
491 $top_node = array(
"node_id" => $top_node_data[
"child"],
492 "title" => $top_node_data[
"title"],
493 "type" => $top_node_data[
"type"]);
496 $nodes_html = $this->
getLevelHTML($top_node, 0, $childs);
501 $ttpl->setCurrentBlock(
"icon");
502 $ttpl->setVariable(
"SRC_ICON", $this->
getIcon());
503 $ttpl->parseCurrentBlock();
507 $secs = array(
"1",
"2");
508 foreach ($secs as $sec)
510 reset($this->commands);
511 reset($this->multi_commands);
512 if (count($this->multi_commands) > 0 || count($this->commands) > 0)
514 if (count($childs) > 0)
517 foreach($this->commands as
$cmd)
519 $ttpl->setCurrentBlock(
"cmd".$sec);
520 $ttpl->setVariable(
"CMD", $cmd[
"cmd"]);
521 $ttpl->setVariable(
"CMD_TXT", $cmd[
"text"]);
522 $ttpl->parseCurrentBlock();
527 foreach($this->multi_commands as $cmd)
529 $ttpl->setCurrentBlock(
"multi_cmd".$sec);
530 $ttpl->setVariable(
"MULTI_CMD", $cmd[
"cmd"]);
531 $ttpl->setVariable(
"MULTI_CMD_TXT", $cmd[
"text"]);
532 $ttpl->parseCurrentBlock();
537 $ttpl->setCurrentBlock(
"multi_cmds".$sec);
538 $ttpl->setVariable(
"MCMD_ALT", $lng->txt(
"commands"));
547 $ttpl->parseCurrentBlock();
551 if ($single || $multi)
553 $ttpl->setCurrentBlock(
"commands".$sec);
554 $ttpl->parseCurrentBlock();
561 if ($this->exp_frame !=
"")
563 $ttpl->setCurrentBlock(
"updater");
564 $ttpl->setVariable(
"UPDATER_FRAME", $this->exp_frame);
565 $ttpl->setVariable(
"EXP_ID_UPDATER", $this->exp_id);
566 $ttpl->setVariable(
"HREF_UPDATER", $this->exp_target_script);
567 $ttpl->parseCurrentBlock();
571 foreach($this->drag_target as $drag_target)
573 $ttpl->setCurrentBlock(
"dragtarget");
574 $ttpl->setVariable(
"EL_ID", $drag_target[
"id"]);
575 $ttpl->setVariable(
"GROUP", $drag_target[
"group"]);
576 $ttpl->parseCurrentBlock();
578 foreach($this->drag_content as $drag_content)
580 $ttpl->setCurrentBlock(
"dragcontent");
581 $ttpl->setVariable(
"EL_ID", $drag_content[
"id"]);
582 $ttpl->setVariable(
"GROUP", $drag_content[
"group"]);
583 $ttpl->parseCurrentBlock();
587 if (is_array($this->diss_menues))
589 foreach($this->diss_menues as $node_id => $d_menu)
591 foreach($d_menu as $group => $menu)
593 if (count($menu) > 1)
595 foreach($menu as $menu_item)
597 $ttpl->setCurrentBlock(
"dmenu_cmd");
598 $ttpl->setVariable(
"SUBITEM", (
int) $menu_item[
"subitem"]);
599 $ttpl->setVariable(
"TXT_MENU_CMD", $menu_item[
"text"]);
600 $ttpl->parseCurrentBlock();
603 $ttpl->setCurrentBlock(
"disambiguation_menu");
604 $ttpl->setVariable(
"DNODE_ID", $node_id);
605 $ttpl->setVariable(
"GRP", $group);
606 $ttpl->parseCurrentBlock();
608 else if (count($menu) == 1)
611 $ttpl->setCurrentBlock(
"as_subitem_flag");
612 $ttpl->setVariable(
"SI_NODE_ID", $node_id);
613 $ttpl->setVariable(
"SI_GRP", $group);
614 $ttpl->setVariable(
"SI_SI", (
int) $menu[0][
"subitem"]);
615 $ttpl->parseCurrentBlock();
621 $this->diss_menues[$a_id][$a_group][] = array(
"type" => $a_type,
"text" => $a_diss_text);
624 $ttpl->setCurrentBlock(
"help_img");
626 $ttpl->parseCurrentBlock();
627 $ttpl->setCurrentBlock(
"help_section");
628 $ttpl->setVariable(
"TXT_HELP",
629 $lng->txt(
"form_hierarchy_add_elements"));
630 $ttpl->parseCurrentBlock();
634 $ttpl->setCurrentBlock(
"help_img");
635 $ttpl->setVariable(
"IMG_HELP", $this->
getDragIcon());
636 $ttpl->parseCurrentBlock();
637 $ttpl->setCurrentBlock(
"help_img");
638 $ttpl->setVariable(
"IMG_HELP",
640 $ttpl->parseCurrentBlock();
641 $ttpl->setCurrentBlock(
"help_section");
642 $ttpl->setVariable(
"TXT_HELP",
643 $lng->txt(
"form_hierarchy_drag_drop_help"));
644 $ttpl->parseCurrentBlock();
650 if ($help[
"image"] !=
"")
652 $ttpl->setCurrentBlock(
"help_img");
653 $ttpl->setVariable(
"IMG_HELP", $help[
"image"]);
654 $ttpl->parseCurrentBlock();
656 $ttpl->setCurrentBlock(
"help_section");
657 $ttpl->setVariable(
"TXT_HELP", $help[
"text"]);
658 $ttpl->parseCurrentBlock();
661 if ($this->triggered_update_command !=
"")
663 $ttpl->setCurrentBlock(
"tr_update");
664 $ttpl->setVariable(
"UPDATE_CMD", $this->triggered_update_command);
665 $ttpl->parseCurrentBlock();
669 if (is_array($this->diss_menues))
671 foreach($this->diss_menues as $node_id => $d_menu)
673 foreach($d_menu as $group => $menu)
675 if (count($menu) > 1)
677 foreach($menu as $menu_item)
679 $ttpl->setCurrentBlock(
"dmenu_cmd");
680 $ttpl->setVariable(
"SUBITEM", (
int) $menu_item[
"subitem"]);
681 $ttpl->setVariable(
"TXT_MENU_CMD", $menu_item[
"text"]);
682 $ttpl->parseCurrentBlock();
685 $ttpl->setCurrentBlock(
"disambiguation_menu");
686 $ttpl->setVariable(
"DNODE_ID", $node_id);
687 $ttpl->setVariable(
"GRP", $group);
688 $ttpl->parseCurrentBlock();
690 else if (count($menu) == 1)
693 $ttpl->setCurrentBlock(
"as_subitem_flag");
694 $ttpl->setVariable(
"SI_NODE_ID", $node_id);
695 $ttpl->setVariable(
"SI_GRP", $group);
696 $ttpl->setVariable(
"SI_SI", (
int) $menu[0][
"subitem"]);
697 $ttpl->parseCurrentBlock();
703 $this->diss_menues[$a_id][$a_group][] = array(
"type" => $a_type,
"text" => $a_diss_text);
706 $ttpl->setVariable(
"NODES", $nodes_html);
710 $ttpl->setVariable(
"TITLE", $this->
getTitle());
726 $childs = $this->
getChilds($a_par_node[
"node_id"]);
730 $ttpl =
new ilTemplate(
"tpl.hierarchy_form_nodes.html",
true,
true,
"Services/Form");
733 if ($this->
nodeAllowsChilds($a_par_node) && (count($childs) > 0 || $a_depth == 0))
735 $ttpl->setCurrentBlock(
"drop_area");
736 $ttpl->setVariable(
"DNODE_ID", $a_par_node[
"node_id"].
"fc");
738 $ttpl->parseCurrentBlock();
742 $menu_items = $this->
getMenuItems($a_par_node, $a_depth,
true, null, $childs);
744 if (count($menu_items) > 0)
748 foreach($menu_items as $menu_item)
750 if ($menu_item[
"multi"] > $max)
752 $max = $menu_item[
"multi"];
758 foreach($menu_items as $menu_item)
760 if ($menu_item[
"multi"] > 1)
762 for($i = 1; $i <= $menu_item[
"multi"]; $i++)
764 $ttpl->setCurrentBlock(
"multi_add");
765 $ttpl->setVariable(
"MA_NUM", $i);
766 $ttpl->setVariable(
"MENU_CMD", $menu_item[
"cmd"]);
767 $ttpl->setVariable(
"FC",
"1");
768 $ttpl->setVariable(
"CMD_NODE", $a_par_node[
"node_id"]);
769 $ttpl->setVariable(
"MCNT", $mcnt.
"fc");
770 $ttpl->parseCurrentBlock();
775 if ($max > $menu_item[
"multi"])
777 $ttpl->setCurrentBlock(
"multi_buffer");
778 $ttpl->setVariable(
"BUF_SPAN", $max - $menu_item[
"multi"]);
779 $ttpl->parseCurrentBlock();
781 $ttpl->setCurrentBlock(
"menu_cmd");
782 $ttpl->setVariable(
"TXT_MENU_CMD", $menu_item[
"text"]);
783 $ttpl->setVariable(
"MENU_CMD", $menu_item[
"cmd"]);
784 $ttpl->setVariable(
"CMD_NODE", $a_par_node[
"node_id"]);
785 $ttpl->setVariable(
"FC",
"1");
786 $ttpl->setVariable(
"MCNT", $mcnt.
"fc");
787 $ttpl->parseCurrentBlock();
790 $ttpl->setCurrentBlock(
"drop_area_menu");
791 $ttpl->setVariable(
"MNODE_ID", $a_par_node[
"node_id"].
"fc");
792 $ttpl->parseCurrentBlock();
794 $ttpl->setCurrentBlock(
"element");
795 $ttpl->parseCurrentBlock();
800 if (count($childs) > 0)
802 for($i = 0; $i < count($childs); $i++)
804 $next_sibling = ($i < (count($childs) - 1))
805 ? $next_sibling = $childs[$i+1]
807 $this->
renderChild($ttpl, $childs[$i], $a_depth, $next_sibling);
808 $last_child = $child;
812 $html = $ttpl->get();
821 function renderChild($a_tpl, $a_child, $a_depth, $next_sibling = null)
826 $a_tpl->setCurrentBlock(
"img");
827 $a_tpl->setVariable(
"IMGPATH", $this->
getChildIcon($a_child));
829 $a_tpl->setVariable(
"IMG_NODE", $a_child[
"node_id"]);
830 $a_tpl->setVariable(
"NODE_ID", $a_child[
"node_id"]);
831 $a_tpl->setVariable(
"TYPE", $a_child[
"type"]);
832 $a_tpl->parseCurrentBlock();
835 $a_tpl->setCurrentBlock(
"cbox");
836 $a_tpl->setVariable(
"CNODE_ID", $a_child[
"node_id"]);
838 $a_tpl->parseCurrentBlock();
842 if (is_array($child_commands))
844 foreach($child_commands as
$command)
846 $a_tpl->setCurrentBlock(
"node_cmd");
847 $a_tpl->setVariable(
"HREF_NODE_CMD", $command[
"link"]);
848 $a_tpl->setVariable(
"TXT_NODE_CMD", $command[
"text"]);
849 $a_tpl->parseCurrentBlock();
854 $a_tpl->setCurrentBlock(
"text");
856 if (is_array($hl) && in_array($a_child[
"node_id"], $hl))
858 $a_tpl->setVariable(
"CLASS",
' class="ilHFormHighlighted" ');
861 $a_tpl->setVariable(
"TNODE_ID", $a_child[
"node_id"]);
862 $a_tpl->parseCurrentBlock();
864 $grandchilds_html = $this->
getLevelHTML($a_child, $a_depth + 1, $grandchilds);
867 if ($this->
getFocusId() == $a_child[
"node_id"])
869 $a_tpl->setCurrentBlock(
"focus");
870 $a_tpl->setVariable(
"FNODE_ID", $a_child[
"node_id"]);
871 $a_tpl->parseCurrentBlock();
877 $a_tpl->setCurrentBlock(
"expand_icon");
878 if (!is_null($grandchilds) && count($grandchilds) > 0)
880 if (!in_array($a_child[
"node_id"],$this->
getExpanded()))
884 $a_tpl->setVariable(
"HREF_NAME",
"n".$a_child[
"node_id"]);
885 $a_tpl->setVariable(
"HREF_EXPAND",
886 $ilCtrl->getLinkTarget($this->getParentObject(), $this->
getParentCommand(),
"n".$a_child[
"node_id"]));
887 $grandchilds_html =
"";
893 $a_tpl->setVariable(
"HREF_NAME",
"n".$a_child[
"node_id"]);
894 $a_tpl->setVariable(
"HREF_EXPAND",
895 $ilCtrl->getLinkTarget($this->getParentObject(), $this->
getParentCommand(),
"n".$a_child[
"node_id"]));
903 $a_tpl->parseCurrentBlock();
907 $a_tpl->setCurrentBlock(
"list_item");
908 $a_tpl->setVariable(
"CHILDS", $grandchilds_html);
909 $a_tpl->parseCurrentBlock();
911 $a_tpl->setCurrentBlock(
"element");
912 $a_tpl->parseCurrentBlock();
915 $a_tpl->setCurrentBlock(
"drop_area");
916 $a_tpl->setVariable(
"DNODE_ID", $a_child[
"node_id"]);
918 $a_tpl->parseCurrentBlock();
921 $this->
manageDragAndDrop($a_child, $a_depth,
false, $next_sibling, $grandchilds);
924 $menu_items = $this->
getMenuItems($a_child, $a_depth,
false, $next_sibling, $grandchilds);
925 if (count($menu_items) > 0)
929 foreach($menu_items as $menu_item)
931 if ($menu_item[
"multi"] > $max)
933 $max = $menu_item[
"multi"];
939 foreach($menu_items as $menu_item)
941 if ($menu_item[
"multi"] > 1 )
943 for($i = 1; $i <= $menu_item[
"multi"]; $i++)
945 $a_tpl->setCurrentBlock(
"multi_add");
946 $a_tpl->setVariable(
"MA_NUM", $i);
947 $a_tpl->setVariable(
"MENU_CMD", $menu_item[
"cmd"]);
948 if ($menu_item[
"as_subitem"])
950 $a_tpl->setVariable(
"FC",
"1");
951 $a_tpl->setVariable(
"MCNT", $mcnt.
"fc");
955 $a_tpl->setVariable(
"FC",
"0");
956 $a_tpl->setVariable(
"MCNT", $mcnt);
958 $a_tpl->setVariable(
"CMD_NODE", $a_child[
"node_id"]);
959 $a_tpl->parseCurrentBlock();
964 if ($max > $menu_item[
"multi"])
966 $a_tpl->setCurrentBlock(
"multi_buffer");
967 $a_tpl->setVariable(
"BUF_SPAN", $max - $menu_item[
"multi"]);
968 $a_tpl->parseCurrentBlock();
971 $a_tpl->setCurrentBlock(
"menu_cmd");
972 $a_tpl->setVariable(
"TXT_MENU_CMD", $menu_item[
"text"]);
973 $a_tpl->setVariable(
"MENU_CMD", $menu_item[
"cmd"]);
974 if ($menu_item[
"as_subitem"])
976 $a_tpl->setVariable(
"FC",
"1");
977 $a_tpl->setVariable(
"MCNT", $mcnt.
"fc");
981 $a_tpl->setVariable(
"FC",
"0");
982 $a_tpl->setVariable(
"MCNT", $mcnt);
984 $a_tpl->setVariable(
"CMD_NODE", $a_child[
"node_id"]);
985 $a_tpl->parseCurrentBlock();
988 $a_tpl->setCurrentBlock(
"drop_area_menu");
989 $a_tpl->setVariable(
"MNODE_ID", $a_child[
"node_id"]);
990 $a_tpl->parseCurrentBlock();
993 $a_tpl->setCurrentBlock(
"element");
994 $a_tpl->parseCurrentBlock();
1018 return $lng->txt($a_item[
"type"]);
1044 function getMenuItems($a_node, $a_depth, $a_first_child =
false, $a_next_sibling = null, $a_childs = null)
1064 function manageDragAndDrop($a_node, $a_depth, $a_first_child =
false, $a_next_sibling = null, $a_childs = null)
1075 return (
int) (
$_POST[
"il_hform_multi"] > 1
1076 ?
$_POST[
"il_hform_multi"]
1085 return $_POST[
"il_hform_node"];
1093 return (((
int)
$_POST[
"il_hform_fc"]) == 1);