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: require_once("include/classes/treeview_class.php");
29:
30: 31: 32: 33: 34: 35: 36: 37: 38:
39: class RevRep extends TreeView {
40:
41: 42: 43: 44: 45:
46: public $sym_count;
47:
48:
49: 50: 51: 52: 53:
54: private $rubrics_ar = array();
55:
56:
57: 58: 59: 60: 61:
62: private $grade = 1;
63:
64: 65: 66: 67: 68: 69:
70: function __construct() {
71: global $db;
72: $this->rem_id = (empty($_REQUEST['rem'])) ? 0 : $_REQUEST['rem'];
73: $this->grade = (isset($_REQUEST['grade'])) ? $_REQUEST['grade'] : 1;
74: $this->sym_rem_tbl = $db->get_custom_table("sym_rem");
75: $this->symptoms_tbl = $db->get_custom_table("symptoms");
76: $this->tree_symptoms_tbl = 'rem_symptoms';
77: }
78:
79:
80: 81: 82: 83: 84: 85:
86: function get_grade_select() {
87: $grade_ar= array(1=>_("all"), 2=>"≥2", 3=>"≥3");
88: $grade_radio = "";
89: foreach ($grade_ar as $key => $value) {
90: $grade_radio .= "<span class='nobr'><input type='radio' class='button' name='grade' id='grade$key' value='$key'";
91: if($this->grade == $key){
92: $grade_radio .= " checked='checked'";
93: }
94: $grade_radio .= "> <label for='grade$key'><span class='grade_$key'>$value</span></label> </span>";
95: }
96: return $grade_radio;
97: }
98:
99: 100: 101: 102: 103: 104: 105:
106: function prepare_rem_symptoms($rem_rubrics_ar) {
107: global $db;
108: $query = "SELECT DISTINCT {$this->symptoms_tbl}.sym_id, {$this->symptoms_tbl}.symptom, {$this->symptoms_tbl}.pid, {$this->symptoms_tbl}.rubric_id FROM {$this->sym_rem_tbl}, {$this->symptoms_tbl} WHERE {$this->sym_rem_tbl}.rem_id = {$this->rem_id} ";
109: if ($this->grade > 1) {
110: $query .= "AND {$this->sym_rem_tbl}.grade >= {$this->grade} ";
111: }
112: $query .= "AND {$this->sym_rem_tbl}.sym_id = {$this->symptoms_tbl}.sym_id ";
113: if (count($rem_rubrics_ar) == 1) {
114: list($rubric_id) = array_keys($rem_rubrics_ar);
115: $query .= "AND {$this->symptoms_tbl}.rubric_id = $rubric_id";
116: }
117: $result = $db->send_query($query);
118: $this->sym_count = $db->db_num_rows($result);
119: $new_rubrics_ar = array();
120: if ($this->sym_count > 0) {
121: $query = "DROP TEMPORARY TABLE IF EXISTS {$this->tree_symptoms_tbl}";
122: $db->send_query($query);
123: $query = "CREATE TEMPORARY TABLE {$this->tree_symptoms_tbl} (
124: sym_id mediumint(8) unsigned NOT NULL,
125: symptom varchar(510) NOT NULL,
126: pid mediumint(8) unsigned NOT NULL,
127: rubric_id tinyint(3) unsigned NOT NULL,
128: PRIMARY KEY(sym_id),
129: KEY pid (pid)
130: ) ENGINE=MyISAM DEFAULT CHARSET=utf8";
131: $db->send_query($query);
132: $query = "CREATE TEMPORARY TABLE rem_sym__1 (
133: sym_id mediumint(8) unsigned NOT NULL,
134: PRIMARY KEY(sym_id)
135: ) ENGINE=MyISAM DEFAULT CHARSET=utf8";
136: $db->send_query($query);
137: $query = "CREATE TEMPORARY TABLE rem_sym__2 (
138: sym_id mediumint(8) unsigned NOT NULL,
139: pid mediumint(8) unsigned NOT NULL,
140: PRIMARY KEY(sym_id),
141: KEY pid (pid)
142: ) ENGINE=MyISAM DEFAULT CHARSET=utf8";
143: $db->send_query($query);
144: while (list($sym_id, $symptom, $pid, $rubric_id) = $db->db_fetch_row($result)) {
145: $query = "INSERT INTO {$this->tree_symptoms_tbl} SET sym_id = $sym_id, symptom = '" . $db->escape_string($symptom) . "', pid = $pid, rubric_id = $rubric_id";
146: $db->send_query($query);
147: $query = "INSERT INTO rem_sym__1 SET sym_id = $sym_id";
148: $db->send_query($query);
149: $query = "INSERT INTO rem_sym__2 SET sym_id = $sym_id, pid = $pid";
150: $db->send_query($query);
151: if (!isset($new_rubrics_ar[$rubric_id])) {
152: $new_rubrics_ar[$rubric_id] = true;
153: }
154: }
155: do {
156: $query = "SELECT DISTINCT pid FROM {$this->tree_symptoms_tbl} WHERE pid != 0 AND NOT EXISTS (SELECT 1 FROM rem_sym__1 WHERE rem_sym__1.sym_id = {$this->tree_symptoms_tbl}.pid) AND EXISTS (SELECT 1 FROM rem_sym__2 WHERE rem_sym__2.pid = {$this->tree_symptoms_tbl}.pid AND rem_sym__2.sym_id != {$this->tree_symptoms_tbl}.sym_id)";
157: $sub_result = $db->send_query($query);
158: $num_rows = $db->db_num_rows($sub_result);
159: if ($num_rows > 0) {
160: $parents_symptoms_table = $this->symptoms_tbl;
161: if ($sym_lang = $db->get_lang_only_symptom_table()) {
162: $parents_symptoms_table = "sym__" . $sym_lang['id'];
163: }
164: while (list ($missing_pid) = $db->db_fetch_row($sub_result)) {
165: $query = "SELECT sym_id, symptom, pid, rubric_id FROM $parents_symptoms_table WHERE sym_id = $missing_pid";
166: $sub_result2 = $db->send_query($query);
167: $symptom = $db->db_fetch_row($sub_result2);
168: $db->free_result($sub_result2);
169: $query = "INSERT INTO {$this->tree_symptoms_tbl} SET sym_id = $symptom[0], symptom = '" . $db->escape_string($symptom[1]) . "', pid = $symptom[2], rubric_id = $symptom[3]";
170: $db->send_query($query);
171: $query = "INSERT INTO rem_sym__1 SET sym_id = $symptom[0]";
172: $db->send_query($query);
173: $query = "INSERT INTO rem_sym__2 SET sym_id = $symptom[0], pid = $symptom[2]";
174: $db->send_query($query);
175: }
176: }
177: $db->free_result($sub_result);
178: } while ($num_rows > 0);
179: $query = "UPDATE {$this->tree_symptoms_tbl} SET pid = 0 WHERE NOT EXISTS (SELECT 1 FROM rem_sym__1 WHERE rem_sym__1.sym_id = {$this->tree_symptoms_tbl}.pid)";
180: $db->send_query($query);
181: $query = "DROP TEMPORARY TABLE IF EXISTS rem_sym__1";
182: $db->send_query($query);
183: $query = "DROP TEMPORARY TABLE IF EXISTS rem_sym__2";
184: $db->send_query($query);
185: }
186: $db->free_result($result);
187: $ordered_rubrics_ar = array();
188: foreach ($rem_rubrics_ar as $rubric_id => $rubric_name) {
189: if (!empty($new_rubrics_ar[$rubric_id])) {
190: $ordered_rubrics_ar[$rubric_id] = $rubric_name;
191: }
192: }
193: $this->rubrics_ar = $ordered_rubrics_ar;
194: }
195:
196:
197: 198: 199: 200: 201: 202:
203: function build_symptomtree() {
204: global $db;
205: $expand = "collapse";
206: $open = "_open";
207: $display_child = "block";
208: if (count($this->rubrics_ar) != 1) {
209: $expand = "expand";
210: $open = "";
211: $display_child = "none";
212: }
213: $symptomtree = "";
214: $i = 0;
215: foreach ($this->rubrics_ar as $this->rubric_id => $rubric_name) {
216: $symptoms_ar = $this->get_treeview();
217: $child = $this->generate_child("tree2_$i", $symptoms_ar);
218: $symptomtree .= " <div id='tree2-$i' style='padding-left:20px;'>\n";
219: $symptomtree .= " <span id='symbol_tree2-$i'><a href=\"javascript:" . $expand . "_static('tree2_$i',1,0);\" class='nodecls_main'><img src='skins/original/img/main_folder" . $open . "_arrow.png' alt='Expand 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";
220: $symptomtree .= " <span class='nodecls_main'>$rubric_name</span>\n </div>\n";
221: $symptomtree .= " <div id='tree2_$i' style='padding-left:20px; display:$display_child'>\n";
222: $symptomtree .= $child;
223: $symptomtree .= " </div>\n";
224: $i++;
225: }
226: return $symptomtree;
227: }
228:
229:
230: 231: 232: 233: 234: 235: 236: 237:
238: function generate_child($output_id, $symptoms_ar) {
239: $str = "";
240: $i = 0;
241: $display = 1;
242: $main_id = str_replace('_', '-', $output_id);
243: for($i = 0; $i < count($symptoms_ar); $i++) {
244: $class = "grade_" . $symptoms_ar[$i]['max_grade'];
245: if (!empty($symptoms_ar[$i]['sources'])) {
246: $sources_ar = array();
247: foreach ($symptoms_ar[$i]['sources'] as $src_id => $grade) {
248: $source = "$src_id";
249: if ($grade != $symptoms_ar[$i]['max_grade']) {
250: $source .= "($grade" . _("-gr.") . ")";
251: }
252: $sources_ar[] = $source;
253: }
254: $sources = implode("/", $sources_ar);
255: }
256: $str .= "<div id='" . $main_id . "-" . $i . "' style='padding-left:20px;'>\n";
257: if ($symptoms_ar[$i]['folder'] > 0) {
258: $child_ar = $this->get_treeview($symptoms_ar[$i]['id']);
259: $child = $this->generate_child($output_id . "_" . $i, $child_ar);
260: if ($symptoms_ar[$i]['in_use'] > 0) {
261: $str .= " <span id='symbol_" . $main_id . "-" . $i . "'><a href=\"javascript:expand_static('" . $output_id . "_" . $i . "',0,1);\"><img src='skins/original/img/folder_arrow.png' alt='Expand rubric' width='12' height='12'> <img src='skins/original/img/folder_aeskulap.png' alt='Symptom rubric' width='12' height='12'> </a></span>\n";
262: $str .= " <a href=\"javascript:popup_url('details.php?sym=" . $symptoms_ar[$i]['id'] . "&rem={$this->rem_id}&sym_rem_tbl={$this->sym_rem_tbl}',540,380)\" title='" . $symptoms_ar[$i]['max_grade'] . _("-gr.") . ": $sources' class='$class'>" . $symptoms_ar[$i]['name'] . "</a>\n";
263: $str .= " <a href='javascript:symptomData(" . $symptoms_ar[$i]['id'] . ");' title='" . _("Symptom-Info") . "'><img src='skins/original/img/info.gif' width='12' height='12' alt='Info'></a>\n";
264: } else {
265: $str .= " <span id='symbol_" . $main_id . "-" . $i . "'><a href=\"javascript:expand_static('" . $output_id . "_" . $i . "',0,0);\"><img src='skins/original/img/folder_arrow.png' alt='Expand rubric' width='12' height='12'> <img src='skins/original/img/folder.png' alt='Rubric' width='12' height='12'> </a></span>\n";
266: $str .= " <span class='$class'>" . $symptoms_ar[$i]['name'] . "</span>\n";
267: }
268: $str .= "</div>\n";
269: $str .= "<div id='" . $output_id . "_" . $i . "' style='padding-left:20px;display:none'>\n";
270: $str .= $child;
271: $str .= "</div>\n";
272: } else {
273: $str .= " <span class='nodecls'><span style='visibility:hidden'><img src='skins/original/img/folder_arrow.png' alt='Expand rubric' width='12' height='12'> </span><img src='skins/original/img/aeskulap.png' alt='Symptom' width='12' height='12'> </span>\n";
274: $str .= " <a href=\"javascript:popup_url('details.php?sym=" . $symptoms_ar[$i]['id'] . "&rem={$this->rem_id}&sym_rem_tbl={$this->sym_rem_tbl}',540,380)\" title='" . $symptoms_ar[$i]['max_grade'] . _("-gr.") . ": $sources' class='$class'>" . $symptoms_ar[$i]['name'] . "</a>\n";
275: $str .= " <a href='javascript:symptomData(" . $symptoms_ar[$i]['id'] . ");' title='" . _("Symptom-Info") . "'><img src='skins/original/img/info.gif' width='12' height='12' alt='Info'></a>\n";
276: $str .= "</div>\n";
277: }
278: }
279: return $str;
280: }
281: }
282: