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);
461 $this->white_list = $a_val;
471 return $this->white_list;
480 if ($a_node_id ==
false)
485 $tree_childs = $this->
getTree()->getChilds($a_node_id);
487 foreach($tree_childs as $tree_child)
490 if (!is_array($this->white_list) || in_array($tree_child[
"type"], $this->white_list))
492 $childs[] = array(
"node_id" => $tree_child[
"child"],
493 "title" => $tree_child[
"title"],
494 "type" => $tree_child[
"type"],
495 "depth" => $tree_child[
"depth"]
515 $ttpl =
new ilTemplate(
"tpl.hierarchy_form.html",
true,
true,
"Services/Form");
516 $ttpl->setVariable(
"TXT_SAVING", $lng->txt(
"saving"));
518 $top_node = array(
"node_id" => $top_node_data[
"child"],
519 "title" => $top_node_data[
"title"],
520 "type" => $top_node_data[
"type"]);
523 $nodes_html = $this->
getLevelHTML($top_node, 0, $childs);
528 $ttpl->setCurrentBlock(
"icon");
529 $ttpl->setVariable(
"SRC_ICON", $this->
getIcon());
530 $ttpl->parseCurrentBlock();
534 $secs = array(
"1",
"2");
535 foreach ($secs as $sec)
537 reset($this->commands);
538 reset($this->multi_commands);
539 if (count($this->multi_commands) > 0 || count($this->commands) > 0)
541 if (count($childs) > 0)
544 foreach($this->commands as
$cmd)
546 $ttpl->setCurrentBlock(
"cmd".$sec);
547 $ttpl->setVariable(
"CMD", $cmd[
"cmd"]);
548 $ttpl->setVariable(
"CMD_TXT", $cmd[
"text"]);
549 $ttpl->parseCurrentBlock();
554 foreach($this->multi_commands as $cmd)
556 $ttpl->setCurrentBlock(
"multi_cmd".$sec);
557 $ttpl->setVariable(
"MULTI_CMD", $cmd[
"cmd"]);
558 $ttpl->setVariable(
"MULTI_CMD_TXT", $cmd[
"text"]);
559 $ttpl->parseCurrentBlock();
564 $ttpl->setCurrentBlock(
"multi_cmds".$sec);
565 $ttpl->setVariable(
"MCMD_ALT", $lng->txt(
"commands"));
574 $ttpl->parseCurrentBlock();
578 if ($single || $multi)
580 $ttpl->setCurrentBlock(
"commands".$sec);
581 $ttpl->parseCurrentBlock();
588 if ($this->exp_frame !=
"")
590 $ttpl->setCurrentBlock(
"updater");
591 $ttpl->setVariable(
"UPDATER_FRAME", $this->exp_frame);
592 $ttpl->setVariable(
"EXP_ID_UPDATER", $this->exp_id);
593 $ttpl->setVariable(
"HREF_UPDATER", $this->exp_target_script);
594 $ttpl->parseCurrentBlock();
598 foreach($this->drag_target as $drag_target)
600 $ttpl->setCurrentBlock(
"dragtarget");
601 $ttpl->setVariable(
"EL_ID", $drag_target[
"id"]);
602 $ttpl->setVariable(
"GROUP", $drag_target[
"group"]);
603 $ttpl->parseCurrentBlock();
605 foreach($this->drag_content as $drag_content)
607 $ttpl->setCurrentBlock(
"dragcontent");
608 $ttpl->setVariable(
"EL_ID", $drag_content[
"id"]);
609 $ttpl->setVariable(
"GROUP", $drag_content[
"group"]);
610 $ttpl->parseCurrentBlock();
614 if (is_array($this->diss_menues))
616 foreach($this->diss_menues as $node_id => $d_menu)
618 foreach($d_menu as $group => $menu)
620 if (count($menu) > 1)
622 foreach($menu as $menu_item)
624 $ttpl->setCurrentBlock(
"dmenu_cmd");
625 $ttpl->setVariable(
"SUBITEM", (
int) $menu_item[
"subitem"]);
626 $ttpl->setVariable(
"TXT_MENU_CMD", $menu_item[
"text"]);
627 $ttpl->parseCurrentBlock();
630 $ttpl->setCurrentBlock(
"disambiguation_menu");
631 $ttpl->setVariable(
"DNODE_ID", $node_id);
632 $ttpl->setVariable(
"GRP", $group);
633 $ttpl->parseCurrentBlock();
635 else if (count($menu) == 1)
638 $ttpl->setCurrentBlock(
"as_subitem_flag");
639 $ttpl->setVariable(
"SI_NODE_ID", $node_id);
640 $ttpl->setVariable(
"SI_GRP", $group);
641 $ttpl->setVariable(
"SI_SI", (
int) $menu[0][
"subitem"]);
642 $ttpl->parseCurrentBlock();
648 $this->diss_menues[$a_id][$a_group][] = array(
"type" => $a_type,
"text" => $a_diss_text);
651 $ttpl->setCurrentBlock(
"help_img");
653 $ttpl->parseCurrentBlock();
654 $ttpl->setCurrentBlock(
"help_section");
655 $ttpl->setVariable(
"TXT_HELP",
656 $lng->txt(
"form_hierarchy_add_elements"));
657 $ttpl->parseCurrentBlock();
661 $ttpl->setCurrentBlock(
"help_img");
662 $ttpl->setVariable(
"IMG_HELP", $this->
getDragIcon());
663 $ttpl->parseCurrentBlock();
664 $ttpl->setCurrentBlock(
"help_img");
665 $ttpl->setVariable(
"IMG_HELP",
667 $ttpl->parseCurrentBlock();
668 $ttpl->setCurrentBlock(
"help_section");
669 $ttpl->setVariable(
"TXT_HELP",
670 $lng->txt(
"form_hierarchy_drag_drop_help"));
671 $ttpl->parseCurrentBlock();
677 if ($help[
"image"] !=
"")
679 $ttpl->setCurrentBlock(
"help_img");
680 $ttpl->setVariable(
"IMG_HELP", $help[
"image"]);
681 $ttpl->parseCurrentBlock();
683 $ttpl->setCurrentBlock(
"help_section");
684 $ttpl->setVariable(
"TXT_HELP", $help[
"text"]);
685 $ttpl->parseCurrentBlock();
688 if ($this->triggered_update_command !=
"")
690 $ttpl->setCurrentBlock(
"tr_update");
691 $ttpl->setVariable(
"UPDATE_CMD", $this->triggered_update_command);
692 $ttpl->parseCurrentBlock();
696 if (is_array($this->diss_menues))
698 foreach($this->diss_menues as $node_id => $d_menu)
700 foreach($d_menu as $group => $menu)
702 if (count($menu) > 1)
704 foreach($menu as $menu_item)
706 $ttpl->setCurrentBlock(
"dmenu_cmd");
707 $ttpl->setVariable(
"SUBITEM", (
int) $menu_item[
"subitem"]);
708 $ttpl->setVariable(
"TXT_MENU_CMD", $menu_item[
"text"]);
709 $ttpl->parseCurrentBlock();
712 $ttpl->setCurrentBlock(
"disambiguation_menu");
713 $ttpl->setVariable(
"DNODE_ID", $node_id);
714 $ttpl->setVariable(
"GRP", $group);
715 $ttpl->parseCurrentBlock();
717 else if (count($menu) == 1)
720 $ttpl->setCurrentBlock(
"as_subitem_flag");
721 $ttpl->setVariable(
"SI_NODE_ID", $node_id);
722 $ttpl->setVariable(
"SI_GRP", $group);
723 $ttpl->setVariable(
"SI_SI", (
int) $menu[0][
"subitem"]);
724 $ttpl->parseCurrentBlock();
730 $this->diss_menues[$a_id][$a_group][] = array(
"type" => $a_type,
"text" => $a_diss_text);
733 $ttpl->setVariable(
"NODES", $nodes_html);
737 $ttpl->setVariable(
"TITLE", $this->
getTitle());
755 $childs = $this->
getChilds($a_par_node[
"node_id"]);
759 $ttpl =
new ilTemplate(
"tpl.hierarchy_form_nodes.html",
true,
true,
"Services/Form");
762 if ($this->
nodeAllowsChilds($a_par_node) && (count($childs) > 0 || $a_depth == 0))
764 $ttpl->setCurrentBlock(
"drop_area");
765 $ttpl->setVariable(
"DNODE_ID", $a_par_node[
"node_id"].
"fc");
767 $ttpl->parseCurrentBlock();
770 $menu_items = $this->
getMenuItems($a_par_node, $a_depth,
true, null, $childs);
772 if (count($menu_items) > 0)
776 foreach($menu_items as $menu_item)
778 if ($menu_item[
"multi"] > $max)
780 $max = $menu_item[
"multi"];
786 foreach($menu_items as $menu_item)
788 if ($menu_item[
"multi"] > 1)
790 for($i = 1; $i <= $menu_item[
"multi"]; $i++)
792 $ttpl->setCurrentBlock(
"multi_add");
793 $ttpl->setVariable(
"MA_NUM", $i);
794 $ttpl->setVariable(
"MENU_CMD", $menu_item[
"cmd"]);
795 $ttpl->setVariable(
"FC",
"1");
796 $ttpl->setVariable(
"CMD_NODE", $a_par_node[
"node_id"]);
797 $ttpl->setVariable(
"MCNT", $mcnt.
"fc");
798 $ttpl->parseCurrentBlock();
803 if ($max > $menu_item[
"multi"])
805 $ttpl->setCurrentBlock(
"multi_buffer");
806 $ttpl->setVariable(
"BUF_SPAN", $max - $menu_item[
"multi"]);
807 $ttpl->parseCurrentBlock();
809 $ttpl->setCurrentBlock(
"menu_cmd");
810 $ttpl->setVariable(
"TXT_MENU_CMD", $menu_item[
"text"]);
811 $ttpl->setVariable(
"MENU_CMD", $menu_item[
"cmd"]);
812 $ttpl->setVariable(
"CMD_NODE", $a_par_node[
"node_id"]);
813 $ttpl->setVariable(
"FC",
"1");
814 $ttpl->setVariable(
"MCNT", $mcnt.
"fc");
815 $ttpl->parseCurrentBlock();
818 $ttpl->setCurrentBlock(
"drop_area_menu");
819 $ttpl->setVariable(
"MNODE_ID", $a_par_node[
"node_id"].
"fc");
820 $ttpl->parseCurrentBlock();
822 $ttpl->setCurrentBlock(
"element");
823 $ttpl->parseCurrentBlock();
828 if (count($childs) > 0)
830 for($i = 0; $i < count($childs); $i++)
832 $next_sibling = ($i < (count($childs) - 1))
833 ? $next_sibling = $childs[$i+1]
836 $this->
renderChild($ttpl, $childs[$i], $a_depth, $next_sibling);
837 $last_child = $child;
841 $html = $ttpl->get();
850 function renderChild($a_tpl, $a_child, $a_depth, $next_sibling = null)
855 $a_tpl->setCurrentBlock(
"img");
856 $a_tpl->setVariable(
"IMGPATH", $this->
getChildIcon($a_child));
858 $a_tpl->setVariable(
"IMG_NODE", $a_child[
"node_id"]);
859 $a_tpl->setVariable(
"NODE_ID", $a_child[
"node_id"]);
860 $a_tpl->setVariable(
"TYPE", $a_child[
"type"]);
861 $a_tpl->parseCurrentBlock();
864 $a_tpl->setCurrentBlock(
"cbox");
865 $a_tpl->setVariable(
"CNODE_ID", $a_child[
"node_id"]);
867 $a_tpl->parseCurrentBlock();
871 if (is_array($child_commands))
873 foreach($child_commands as $command)
875 $a_tpl->setCurrentBlock(
"node_cmd");
876 $a_tpl->setVariable(
"HREF_NODE_CMD", $command[
"link"]);
877 $a_tpl->setVariable(
"TXT_NODE_CMD", $command[
"text"]);
878 $a_tpl->parseCurrentBlock();
883 $a_tpl->setCurrentBlock(
"text");
885 if (is_array($hl) && in_array($a_child[
"node_id"], $hl))
887 $a_tpl->setVariable(
"CLASS",
' class="ilHFormHighlighted" ');
890 $a_tpl->setVariable(
"TNODE_ID", $a_child[
"node_id"]);
891 $a_tpl->parseCurrentBlock();
893 $grandchilds_html = $this->
getLevelHTML($a_child, $a_depth + 1, $grandchilds);
896 if ($this->
getFocusId() == $a_child[
"node_id"])
898 $a_tpl->setCurrentBlock(
"focus");
899 $a_tpl->setVariable(
"FNODE_ID", $a_child[
"node_id"]);
900 $a_tpl->parseCurrentBlock();
906 $a_tpl->setCurrentBlock(
"expand_icon");
907 if (!is_null($grandchilds) && count($grandchilds) > 0)
909 if (!in_array($a_child[
"node_id"],$this->
getExpanded()))
913 $a_tpl->setVariable(
"HREF_NAME",
"n".$a_child[
"node_id"]);
914 $a_tpl->setVariable(
"HREF_EXPAND",
915 $ilCtrl->getLinkTarget($this->getParentObject(), $this->
getParentCommand(),
"n".$a_child[
"node_id"]));
916 $grandchilds_html =
"";
922 $a_tpl->setVariable(
"HREF_NAME",
"n".$a_child[
"node_id"]);
923 $a_tpl->setVariable(
"HREF_EXPAND",
924 $ilCtrl->getLinkTarget($this->getParentObject(), $this->
getParentCommand(),
"n".$a_child[
"node_id"]));
932 $a_tpl->parseCurrentBlock();
936 $a_tpl->setCurrentBlock(
"list_item");
937 $a_tpl->setVariable(
"CHILDS", $grandchilds_html);
938 $a_tpl->parseCurrentBlock();
940 $a_tpl->setCurrentBlock(
"element");
941 $a_tpl->parseCurrentBlock();
944 $a_tpl->setCurrentBlock(
"drop_area");
945 $a_tpl->setVariable(
"DNODE_ID", $a_child[
"node_id"]);
947 $a_tpl->parseCurrentBlock();
950 $this->
manageDragAndDrop($a_child, $a_depth,
false, $next_sibling, $grandchilds);
953 $menu_items = $this->
getMenuItems($a_child, $a_depth,
false, $next_sibling, $grandchilds);
954 if (count($menu_items) > 0)
958 foreach($menu_items as $menu_item)
960 if ($menu_item[
"multi"] > $max)
962 $max = $menu_item[
"multi"];
968 foreach($menu_items as $menu_item)
970 if ($menu_item[
"multi"] > 1 )
972 for($i = 1; $i <= $menu_item[
"multi"]; $i++)
974 $a_tpl->setCurrentBlock(
"multi_add");
975 $a_tpl->setVariable(
"MA_NUM", $i);
976 $a_tpl->setVariable(
"MENU_CMD", $menu_item[
"cmd"]);
977 if ($menu_item[
"as_subitem"])
979 $a_tpl->setVariable(
"FC",
"1");
980 $a_tpl->setVariable(
"MCNT", $mcnt.
"fc");
984 $a_tpl->setVariable(
"FC",
"0");
985 $a_tpl->setVariable(
"MCNT", $mcnt);
987 $a_tpl->setVariable(
"CMD_NODE", $a_child[
"node_id"]);
988 $a_tpl->parseCurrentBlock();
993 if ($max > $menu_item[
"multi"])
995 $a_tpl->setCurrentBlock(
"multi_buffer");
996 $a_tpl->setVariable(
"BUF_SPAN", $max - $menu_item[
"multi"]);
997 $a_tpl->parseCurrentBlock();
1000 $a_tpl->setCurrentBlock(
"menu_cmd");
1001 $a_tpl->setVariable(
"TXT_MENU_CMD", $menu_item[
"text"]);
1002 $a_tpl->setVariable(
"MENU_CMD", $menu_item[
"cmd"]);
1003 if ($menu_item[
"as_subitem"])
1005 $a_tpl->setVariable(
"FC",
"1");
1006 $a_tpl->setVariable(
"MCNT", $mcnt.
"fc");
1010 $a_tpl->setVariable(
"FC",
"0");
1011 $a_tpl->setVariable(
"MCNT", $mcnt);
1013 $a_tpl->setVariable(
"CMD_NODE", $a_child[
"node_id"]);
1014 $a_tpl->parseCurrentBlock();
1017 $a_tpl->setCurrentBlock(
"drop_area_menu");
1018 $a_tpl->setVariable(
"MNODE_ID", $a_child[
"node_id"]);
1019 $a_tpl->parseCurrentBlock();
1022 $a_tpl->setCurrentBlock(
"element");
1023 $a_tpl->parseCurrentBlock();
1047 return $lng->txt($a_item[
"type"]);
1073 function getMenuItems($a_node, $a_depth, $a_first_child =
false, $a_next_sibling = null, $a_childs = null)
1093 function manageDragAndDrop($a_node, $a_depth, $a_first_child =
false, $a_next_sibling = null, $a_childs = null)
1104 return (
int) (
$_POST[
"il_hform_multi"] > 1
1105 ?
$_POST[
"il_hform_multi"]
1114 return $_POST[
"il_hform_node"];
1122 return (((
int)
$_POST[
"il_hform_fc"]) == 1);