3 * GForge Doc Mgr Facility
5 * Copyright 2002 GForge, LLC
12 require_once('pre.php');
13 require_once('note.php');
16 * Wrap many group display related functions
18 class DocumentGroupHTML extends Error {
21 function DocumentGroupHTML(&$Group) {
24 if (!$Group || !is_object($Group)) {
25 $this->setError("DocumentGroupHTML:: Invalid Group");
28 if ($Group->isError()) {
29 $this->setError('DocumentGroupHTML:: '.$Group->getErrorMessage());
32 $this->Group =& $Group;
39 * showTableNestedGroups - Display the tree of document groups
41 * This is a recursive function that is used to display the tree
43 * @param array Array of groups. This array contains information about the groups and their childs.
44 * @param int The number of row that is currently being showed. It is used for formatting purposes
45 * @param int The ID of the parent whose childs are being showed (0 for root groups)
46 * @param int The current level
48 function showTableNestedGroups (&$group_arr, &$rowno, $parent=0, $level=0) {
49 // No childs to display
50 if (!is_array($group_arr) || !array_key_exists("$parent", $group_arr)) return;
52 $child_count = count($group_arr["$parent"]);
53 for ($i = 0; $i < $child_count; $i++) {
55 $doc_group =& $group_arr["$parent"][$i];
57 $margin = str_repeat(" ", $level);
59 $img = "cfolder15.png";
61 // Display the folder icon opened or closed?
62 if (array_key_exists("".$doc_group->getID(),$group_arr)) $img = "ofolder15.png";
63 else $img = "cfolder15.png";
66 echo '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($rowno) .'>'.
67 '<td>'.$doc_group->getID().'</td>'.
68 '<td>'.$margin.html_image('ic/'.$img,"15","13",array("border"=>"0")).' '.
69 '<a href="index.php?editgroup=1&doc_group='.
70 $doc_group->getID().'&group_id='.$doc_group->Group->getID().'">'.
71 $doc_group->getName().'</a></td></tr>';
72 // Show childs (if any)
73 $this->showTableNestedGroups($group_arr, $rowno, $doc_group->getID(), $level+1);
78 * showSelectNestedGroups - Display the tree of document groups inside a <select> tag
80 * @param array Array of groups.
81 * @param string The name that will be assigned to the input
82 * @param bool Allow selection of "None"
83 * @param int The ID of the group that should be selected by default (if any)
84 * @param array Array of IDs of groups that should not be displayed
86 function showSelectNestedGroups (&$group_arr, $select_name, $allow_none=true, $selected_id=0, $dont_display=array()) {
87 // Build arrays for calling html_build_select_box_from_arrays()
89 $text_array = array();
92 // First option to be displayed
94 $text_array[] = "(None)";
97 // Recursively build the document group tree
98 $this->buildArrays($group_arr, $id_array, $text_array, $dont_display);
100 echo html_build_select_box_from_arrays($id_array,$text_array,$select_name,$selected_id,false);
104 * buildArrays - Build the arrays to call html_build_select_box_from_arrays()
106 * @param array Array of groups.
107 * @param array Reference to the array of ids that will be build
108 * @param array Reference to the array of group names
109 * @param array Array of IDs of groups that should not be displayed
110 * @param int The ID of the parent whose childs are being showed (0 for root groups)
111 * @param int The current level
113 function buildArrays(&$group_arr, &$id_array, &$text_array, &$dont_display, $parent=0, $level=0) {
114 if (!is_array($group_arr) || !array_key_exists("$parent", $group_arr)) return;
116 $child_count = count($group_arr["$parent"]);
117 for ($i = 0; $i < $child_count; $i++) {
118 $doc_group =& $group_arr["$parent"][$i];
120 // Should we display this element?
121 if (in_array($doc_group->getID(), $dont_display)) continue;
123 $margin = str_repeat("--", $level);
125 $id_array[] = $doc_group->getID();
126 $text_array[] = $margin.$doc_group->getName();
128 // Show childs (if any)
129 $this->buildArrays($group_arr, $id_array, $text_array, $dont_display, $doc_group->getID(), $level+1);
137 // c-file-style: "bsd"