Overview

Packages

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

Classes

  • RevRep
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * revrep_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   RevRep
 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: require_once("include/classes/treeview_class.php");
 29: 
 30: /**
 31:  * The RevRep class is responsible for the reversed repertorization for a given remedy in the materia medica (materia.php)
 32:  *
 33:  * @category  Homeopathy
 34:  * @package   RevRep
 35:  * @author    Henri Schumacher <henri.hulski@gazeta.pl>
 36:  * @copyright 2007-2014 Henri Schumacher
 37:  * @license   http://www.gnu.org/licenses/agpl.html GNU Affero General Public License v3
 38:  */
 39: class RevRep extends TreeView {
 40: 
 41:     /**
 42:      * Number of found symptoms
 43:      * @var integer
 44:      * @access public
 45:      */
 46:     public $sym_count;
 47:     
 48:     
 49:     /**
 50:      * Ordered array of main rubrics realted to the queried remedy
 51:      * @var array
 52:      * @access private
 53:      */
 54:     private $rubrics_ar = array();
 55:     
 56:     
 57:     /**
 58:      * Grade from which on symptoms will be shown (1|2|3)
 59:      * @var integer
 60:      * @access private
 61:      */
 62:     private $grade = 1;
 63: 
 64:     /**
 65:      * Class constructor
 66:      *
 67:      * @return \RevRep
 68:     @access public
 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:      * get_grade_select returns a radio selection form for the max. desired grade (1|2|3)
 82:      *
 83:      * @return string
 84:      * @access public
 85:      */
 86:     function get_grade_select() {
 87:         $grade_ar= array(1=>_("all"), 2=>"&ge;2", 3=>"&ge;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>&nbsp;</span>";
 95:         }
 96:         return $grade_radio;
 97:     }
 98:         
 99:     /**
100:      * prepare_rem_symptoms retrieves the related remedy-symptom-relations and store them in a temporary table for building the symptom tree.
101:      *
102:      * @param array  $rem_rubrics_ar contains either the requested main rubric or if none an ordered array of main rubrics related with the queried remedy
103:      * @return void
104:      * @access public
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:      * build_symptomtree returns the html formatted symptom tree
199:      *
200:      * @return string
201:      * @access public
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:      * generate_child returns the recursively generated child nodes for the html symptom tree
232:      *
233:      * @param string $output_id   id of the parent div, in which to put the child nodes
234:      * @param array  $symptoms_ar array that contains the symptoms
235:      * @return string
236:      * @access public
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'] . "&amp;rem={$this->rem_id}&amp;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'] . "&amp;rem={$this->rem_id}&amp;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: 
OpenHomeopath PHP code documentation API documentation generated by ApiGen 2.8.0