1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27:
28: 29: 30: 31: 32: 33: 34: 35: 36:
37: class TreeView {
38:
39: 40: 41: 42: 43:
44: public $symptoms_tbl;
45:
46:
47: 48: 49: 50: 51:
52: public $sym_rem_tbl;
53:
54:
55: 56: 57: 58: 59:
60: protected $rubric_id;
61:
62:
63: 64: 65: 66: 67:
68: protected $tree_symptoms_tbl = "";
69:
70:
71: 72: 73: 74: 75:
76: public $rem_id = 0;
77:
78: 79: 80: 81: 82: 83: 84: 85:
86: function __construct($rubric_id, $tree_symptoms_tbl = "") {
87: global $db;
88: $this->symptoms_tbl = $db->get_custom_table("symptoms");
89: $this->sym_rem_tbl = $db->get_custom_table("sym_rem");
90: $this->rubric_id = $rubric_id;
91: $this->tree_symptoms_tbl = $tree_symptoms_tbl;
92: }
93:
94: 95: 96: 97: 98: 99: 100:
101: function build_symptomtree($static_tree = false) {
102: global $db, $lang;
103: if ($this->rubric_id == -1) {
104: $query = "SELECT DISTINCT {$this->tree_symptoms_tbl}.rubric_id, main_rubrics.rubric_$lang FROM {$this->tree_symptoms_tbl}, main_rubrics WHERE main_rubrics.rubric_id = {$this->tree_symptoms_tbl}.rubric_id ORDER BY main_rubrics.rubric_$lang";
105: $result = $db->send_query($query);
106: $symptomtree = "";
107: $i = 0;
108: while (list($this->rubric_id, $rubric_name) = $db->db_fetch_row($result)) {
109: $child = "";
110: $expand = "expand('tree1_$i',{$this->rubric_id},0,1,0)";
111: if ($static_tree) {
112: $symptoms_ar = $this->get_treeview();
113: $rep_select = true;
114: $child = $this->generate_child("tree1_$i", $symptoms_ar, $rep_select);
115: $expand = "expand_static('tree1_$i',1,0)";
116: }
117: $symptomtree .= " <div id='tree1-$i' style='padding-left:20px;'>\n";
118: $symptomtree .= " <span id='symbol_tree1-$i'><a href=\"javascript:$expand;\" class='nodecls_main'><img src='skins/original/img/main_folder_arrow.png' width='14' height='14'> <img src='skins/original/img/main_folder.png' width='14' height='14'> </a></span>\n";
119: $symptomtree .= " <span class='nodecls_main'>$rubric_name</span>\n </div>\n";
120: $symptomtree .= " <div id='tree1_$i' style='padding-left:20px;display:none'>\n";
121: $symptomtree .= $child;
122: $symptomtree .= " </div>\n";
123: $i++;
124: }
125: $db->free_result($result);
126: } else {
127: $collapse = "collapse('tree1_0',{$this->rubric_id},0,1,0)";
128: $child = "";
129: if ($static_tree) {
130: $collapse = "collapse_static('tree1_0',1,0)";
131: $symptoms_ar = $this->get_treeview();
132: $child = $this->generate_child("tree1_0", $symptoms_ar, 1);
133: }
134: $query = "SELECT rubric_$lang FROM main_rubrics WHERE rubric_id = {$this->rubric_id}";
135: $db->send_query($query);
136: list ($rubric_name) = $db->db_fetch_row();
137: $db->free_result();
138: $symptomtree = " <div id='tree1-0' style='padding-left:20px;'>\n";
139: $symptomtree .= " <span id='symbol_tree1-0'><a href=\"javascript:;\" class='nodecls_main'><img src='skins/original/img/main_folder_open_arrow.png' alt='Collapse main rubric' width='14' height='14'> <img src='skins/original/img/main_folder_open.png' alt='Main rubric' width='14' height='14'> </a></span>\n";
140: $symptomtree .= " <span class='nodecls_main'>$rubric_name</span>\n </div>\n";
141: $symptomtree .= " <div id='tree1_0' style='padding-left:20px; display:block'>\n";
142: $symptomtree .= $child;
143: $symptomtree .= " </div>\n";
144: }
145: return $symptomtree;
146: }
147:
148: 149: 150: 151: 152: 153: 154:
155: function get_treeview($pid = 0) {
156: global $db;
157: $symptoms_tbl = empty($this->tree_symptoms_tbl) ? $this->symptoms_tbl : $this->tree_symptoms_tbl;
158: $query = "SELECT sym_id, symptom FROM $symptoms_tbl WHERE rubric_id = {$this->rubric_id} AND pid = $pid ORDER BY symptom";
159: $result = $db->send_query($query);
160: $symptoms_ar = array();
161: $i = 0;
162: while (list ($sym_id, $symptom) = $db->db_fetch_row($result)) {
163: if (!empty($pid)) {
164: $query = "SELECT symptom FROM $symptoms_tbl WHERE sym_id = $pid";
165: $db->send_query($query);
166: list($parents_name) = $db->db_fetch_row();
167: $db->free_result();
168: $symptom = substr($symptom, strlen($parents_name) + 3);
169: }
170: $symptoms_ar[$i]['id'] = $sym_id;
171: $symptoms_ar[$i]['name'] = $symptom;
172: $symptoms_ar[$i]['pid'] = $pid;
173: $query = "SELECT pid FROM $symptoms_tbl WHERE pid = $sym_id LIMIT 1";
174: $db->send_query($query);
175: $num_rows = $db->db_num_rows();
176: $db->free_result();
177: $symptoms_ar[$i]['folder'] = $num_rows;
178: if (!empty($this->rem_id)) {
179: $query = "SELECT src_id, grade FROM {$this->sym_rem_tbl} WHERE sym_id = $sym_id AND rem_id = {$this->rem_id} ORDER BY grade DESC, src_id ASC";
180: $db->send_query($query);
181: while (list($src_id, $grade) = $db->db_fetch_row()) {
182: if (empty($symptoms_ar[$i]['max_grade']) || $grade > $symptoms_ar[$i]['max_grade']) {
183: $symptoms_ar[$i]['max_grade'] = $grade;
184: }
185: $symptoms_ar[$i]['sources'][$src_id] = $grade;
186: }
187: $db->free_result();
188: $symptoms_ar[$i]['max_grade'] = (empty($symptoms_ar[$i]['max_grade'])) ? 0 : $symptoms_ar[$i]['max_grade'];
189: $in_use_where = "sym_id = $sym_id AND rem_id = {$this->rem_id}";
190: } else {
191: $in_use_where = "sym_id = $sym_id";
192: }
193: $symptoms_ar[$i]['in_use'] = 1;
194: if ($num_rows > 0) {
195: $query = "SELECT sym_id FROM {$this->sym_rem_tbl} WHERE $in_use_where LIMIT 1";
196: $db->send_query($query);
197: $num_rows = $db->db_num_rows();
198: $db->free_result();
199: $symptoms_ar[$i]['in_use'] = $num_rows;
200: }
201: $i++;
202: }
203: $db->free_result($result);
204: return $symptoms_ar;
205: }
206:
207: 208: 209: 210: 211: 212: 213: 214: 215:
216: function generate_child($output_id, $symptoms_ar, $rep_select = false) {
217: $str = "";
218: $i = 0;
219: $display = 1;
220: $main_id = str_replace('_', '-', $output_id);
221: for($i = 0; $i < count($symptoms_ar); $i++) {
222: $str .= "<div id='" . $main_id . "-" . $i . "' style='padding-left:20px;'>\n";
223: if ($symptoms_ar[$i]['folder'] > 0) {
224: $child_ar = $this->get_treeview($symptoms_ar[$i]['id']);
225: $child = $this->generate_child($output_id . "_" . $i, $child_ar, $rep_select);
226: if ($symptoms_ar[$i]['in_use'] > 0) {
227: $str .= " <span id='symbol_" . $main_id . "-" . $i . "'><a href=\"javascript:expand_static('" . $output_id . "_" . $i . "',0,1);\" class='nodecls'><img src='skins/original/img/folder_arrow.png' width='12' height='12'> <img src='skins/original/img/folder_aeskulap.png' width='12' height='12'> </a></span>\n";
228: if ($rep_select) {
229: $str .= " <a href='javascript:selectSymptom(" . $symptoms_ar[$i]['id'] . ");' class='nodecls'>" . $symptoms_ar[$i]['name']. "</a>\n";
230: } else {
231: $str .= " " . $symptoms_ar[$i]['name']. "\n";
232: }
233: $str .= " <a href='javascript:symptomData(" . $symptoms_ar[$i]['id'] . ");' class='nodecls' title='" . _("Symptom-Info") . "'><img src='skins/original/img/info.gif' width='12' height='12' alt='Info'></a>\n";
234: } else {
235: $str .= " <span id='symbol_" . $main_id . "-" . $i . "'><a href=\"javascript:expand_static('" . $output_id . "_" . $i . "',0,0);\" class='nodecls'><img src='skins/original/img/folder_arrow.png' width='12' height='12'> <img src='skins/original/img/folder.png' width='12' height='12'> </a></span>\n";
236: $str .= " <span class='nodecls'>" . $symptoms_ar[$i]['name']. "</span>\n";
237: }
238: $str .= "</div>\n";
239: $str .= "<div id='" . $output_id . "_" . $i . "' style='padding-left:20px;display:none'>\n";
240: $str .= $child;
241: $str .= "</div>\n";
242: } else {
243: $str .= " <span class='nodecls'><span style='visibility:hidden'><img src='skins/original/img/folder_arrow.png' width='12' height='12'> </span><img src='skins/original/img/aeskulap.png' width='12' height='12'> </span>\n";
244: if ($rep_select) {
245: $str .= " <a href='javascript:selectSymptom(" . $symptoms_ar[$i]['id'] . ");' class='nodecls'>" . $symptoms_ar[$i]['name']. "</a>\n";
246: } else {
247: $str .= " " . $symptoms_ar[$i]['name']. "\n";
248: }
249: $str .= " <a href='javascript:symptomData(" . $symptoms_ar[$i]['id'] . ");' class='nodecls' title='" . _("Symptom-Info") . "'><img src='skins/original/img/info.gif' width='12' height='12' alt='Info'></a>\n";
250: $str .= "</div>\n";
251: }
252: }
253: return $str;
254: }
255: }
256: