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 SymRem {
38:
39: 40: 41: 42: 43:
44: private $rems_ar = array();
45:
46:
47: 48: 49: 50: 51:
52: public $rem_count;
53:
54:
55: 56: 57: 58: 59:
60: public $sym_id;
61:
62:
63: 64: 65: 66: 67:
68: private $grade;
69:
70:
71: 72: 73: 74: 75:
76: private $sort;
77:
78:
79: 80: 81: 82: 83:
84: private $sym_rem_tbl;
85:
86:
87: 88: 89: 90: 91: 92:
93: function __construct() {
94: global $db;
95: $this->sym_id = (empty($_REQUEST['sym'])) ? 0 : $_REQUEST['sym'];
96: $this->sort = (isset($_REQUEST['sort'])) ? $_REQUEST['sort'] : 'grade';
97: $this->grade = (isset($_REQUEST['grade'])) ? $_REQUEST['grade'] : 1;
98: $this->sym_rem_tbl = $db->get_custom_table("sym_rem");
99: $this->set_sym_rems();
100: }
101:
102: 103: 104: 105: 106: 107:
108: private function set_sym_rems() {
109: global $db;
110: $query = "SELECT remedies.rem_id, remedies.rem_short, remedies.rem_name, {$this->sym_rem_tbl}.grade, {$this->sym_rem_tbl}.src_id FROM remedies, {$this->sym_rem_tbl} WHERE {$this->sym_rem_tbl}.sym_id = {$this->sym_id} AND {$this->sym_rem_tbl}.rem_id = remedies.rem_id ";
111: if ($this->grade > 1) {
112: $query .= "AND {$this->sym_rem_tbl}.grade >= {$this->grade} ";
113: }
114: switch ($this->sort) {
115: case 'grade':
116: $query .= "ORDER BY {$this->sym_rem_tbl}.grade DESC, remedies.rem_name ASC";
117: break;
118: case 'remname':
119: $query .= "ORDER BY remedies.rem_name";
120: break;
121: case 'shortname':
122: $query .= "ORDER BY remedies.rem_short";
123: break;
124: }
125: $db->send_query($query);
126: $this->rem_count = $db->db_num_rows();
127: if ($this->rem_count > 0) {
128: while (list($rem_id, $rem_short, $rem_name, $grade, $src_id) = $db->db_fetch_row()) {
129: if (empty($this->rems_ar[$rem_id])) {
130: $this->rems_ar[$rem_id] = array('shortname' => $rem_short, 'remname' => $rem_name, 'max_grade' => $grade, 'source' => array($src_id => $grade));
131: } elseif (empty($this->rems_ar[$rem_id]['source'][$src_id])) {
132: $this->rems_ar[$rem_id]['source'][$src_id] = $grade;
133: if ($grade > $this->rems_ar[$rem_id]['max_grade']) {
134: $this->rems_ar[$rem_id]['max_grade'] = $grade;
135: }
136: }
137: }
138: }
139: $db->free_result();
140: }
141:
142: 143: 144: 145: 146: 147: 148:
149: function get_grade_select($name = 'remgrade') {
150: $grade_ar= array(1=>_("all"), 2=>"≥2", 3=>"≥3");
151: $grade_radio = "";
152: foreach ($grade_ar as $key => $value) {
153: $grade_radio .= "<span class='nobr'><input type='radio' class='button' name='$name' id='$name$key' value='$key'";
154: if($this->grade == $key){
155: $grade_radio .= " checked='checked'";
156: }
157: $grade_radio .= " onchange= \"getSymRems('remgrade')\"> <label for='$name$key'><span class='grade_$key'>$value</span></label> </span>";
158: }
159: return $grade_radio;
160: }
161:
162: 163: 164: 165: 166: 167:
168: function get_sort_select() {
169: $sort_ar= array('grade'=>_("Grade"), 'remname'=>_("Remedy name"), 'shortname'=>_(" Abbreviation"));
170: $sort_select = "<select class='drop-down' id='sort' size='1' onchange= \"getSymRems('remgrade')\">\n";
171: foreach ($sort_ar as $key => $value) {
172: $sort_select .= " <option value='$key'";
173:
174: if($this->sort == $key){
175: $sort_select .= " selected='selected'";
176: }
177: $sort_select .= ">$value</option>\n";
178: }
179: $sort_select .= "</select>\n";
180: return $sort_select;
181: }
182:
183: 184: 185: 186: 187: 188:
189: function get_rems_list() {
190: $rems_list = "";
191: foreach ($this->rems_ar as $rem_id => $rem_ar) {
192: $sources_ar = array();
193: foreach ($rem_ar['source'] as $source => $grade) {
194: if ($grade != $rem_ar['max_grade']) {
195: $source .= "($grade" . _("-gr.") . ")";
196: }
197: $sources_ar[] = $source;
198: }
199: $title = $rem_ar['max_grade'] . _("-gr.") . ": " . implode("/", $sources_ar);
200: $text = $rem_ar['remname'] . " (" . $rem_ar['shortname'] . ")";
201: $tag = "div";
202: $class = "";
203: if ($this->sort == 'shortname') {
204: $title = $rem_ar['remname'] . " (" . $rem_ar['max_grade'] . _("-gr.") . "): " . implode("/", $sources_ar);
205: $text = $rem_ar['shortname'];
206: end($this->rems_ar);
207: if ($rem_id !== key($this->rems_ar)) {
208: $text .= ",<span style='white-space:normal;'> </span>";
209: }
210: $tag = "span";
211: $class = " class='nobr'";
212: }
213: if (isset($_REQUEST['tab'])) {
214: $materia_url = "javascript:tabOpen(\"materia.php?rem=\", $rem_id, \"GET\", 2)";
215: } else {
216: $materia_url = "materia.php?rem=$rem_id";
217: }
218: $rems_list .= "<$tag$class><a href='$materia_url' title='" . _("Materia Medica") . "'> <img src='skins/original/img/materia.png' alt='Materia Medica' width='12' height='12'> </a><a href=\"javascript:popup_url('details.php?sym={$this->sym_id}&rem=$rem_id&sym_rem_tbl={$this->sym_rem_tbl}',540,380)\" title='$title' class='grade_" . $rem_ar['max_grade'] . "'>$text</a></$tag>";
219: }
220: return $rems_list;
221: }
222: }
223: