Overview

Packages

  • Admin
  • Archive
  • Common
  • DB
  • Express
  • Form
  • Layout
  • Mailer
  • None
  • OpenHomeoDB
  • PDF
    • MC
  • Process
  • Rep
  • RevRep
  • SaveReps
  • Search
  • Session
  • SymRem
  • TreeView
  • UserDB

Classes

  • TreeView
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * treeview_class.php
  5:  *
  6:  * PHP version 8
  7:  *
  8:  * LICENSE: This program is free software: you can redistribute it and/or modify
  9:  * it under the terms of the GNU Affero General Public License as
 10:  * published by the Free Software Foundation, either version 3 of the
 11:  * License, or (at your option) any later version.
 12:  * This program is distributed in the hope that it will be useful,
 13:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15:  * GNU Affero General Public License for more details.
 16:  * You should have received a copy of the GNU Affero General Public License
 17:  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 18:  *
 19:  * @category  Homeopathy
 20:  * @package   TreeView
 21:  * @author    Henri Schumacher <henri.hulski@gazeta.pl>
 22:  * @copyright 2007-2014 Henri Schumacher
 23:  * @license   http://www.gnu.org/licenses/agpl.html GNU Affero General Public License v3
 24:  * @version   1.0
 25:  * @link      https://research.openhomeo.info/download/OpenHomeopath_1.0.2.tar.gz
 26:  */
 27: 
 28: /**
 29:  * The TreeView class is responsible for builing the html symptom tree for symptoms presentation and selection
 30:  *
 31:  * @category  Homeopathy
 32:  * @package   TreeView
 33:  * @author    Henri Schumacher <henri.hulski@gazeta.pl>
 34:  * @copyright 2007-2014 Henri Schumacher
 35:  * @license   http://www.gnu.org/licenses/agpl.html GNU Affero General Public License v3
 36:  */
 37: class TreeView {
 38: 
 39:     /**
 40:      * Symptoms table
 41:      * @var string
 42:      * @access public
 43:      */
 44:     public $symptoms_tbl;
 45:     
 46:     
 47:     /**
 48:      * Symptom-remedy-relations table
 49:      * @var string
 50:      * @access public
 51:      */
 52:     public $sym_rem_tbl;
 53:     
 54:     
 55:     /**
 56:      * Main rubric id for which we're building the treeview. If we build for all main rubrics it has the value -1.
 57:      * @var integer
 58:      * @access protected
 59:      */
 60:     protected $rubric_id;
 61:     
 62:     
 63:     /**
 64:      * Symptoms table to build the tree from
 65:      * @var string
 66:      * @access protected
 67:      */
 68:     protected $tree_symptoms_tbl = "";
 69:     
 70:     
 71:     /**
 72:      * Remedy ID to use for the reversed repertorization in other cases 0
 73:      * @var integer
 74:      * @access public
 75:      */
 76:     public $rem_id = 0;
 77:     
 78:     /**
 79:      * Class constructor
 80:      *
 81:      * @param integer $rubric_id         Main rubric id for which we're building the treeview. If we build for all main rubrics it has the value -1.
 82:      * @param string  $tree_symptoms_tbl Symptoms table to build the tree from.
 83:      * @return TreeView
 84:      * @access public
 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:      * build_symptomtree returns the html formatted symptom tree
 96:      *
 97:      * @param boolean $static_tree if false we're building a tree that will be dynamically expanded, if true we build a static tree
 98:      * @return string
 99:      * @access public
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:      * get_treeview returns an array with the symptoms prepared for the treeview.
150:      *
151:      * @param integer $pid ID of the parents symptom, 0 if there is no parent
152:      * @return array
153:      * @access public
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:      * generate_child returns the recursively generated child nodes for the html symptom tree
209:      *
210:      * @param string $output_id   id of the parent div, in which to put the child nodes
211:      * @param array  $symptoms_ar array that contains the symptoms
212:      * @param boolean $rep_select if true you can select the symptoms for repertorization, false otherwise
213:      * @return string
214:      * @access public
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: 
OpenHomeopath PHP code documentation API documentation generated by ApiGen 2.8.0