1 |
ravilov |
1.1 |
<?php |
2 |
ravilov |
1.4 |
include("inc/conn.php"); |
3 |
|
|
function mySS($a, $b) { return MyCompare($a["name"], $b["name"]); } |
4 |
|
|
function escape_quote($str) { return str_replace('"', """, $str); } |
5 |
ravilov |
1.1 |
if (!$id) { |
6 |
|
|
$simptomi = array(); |
7 |
ravilov |
1.4 |
$sql = "SELECT simptom_id, naziv FROM simptomi WHERE (simptom_id <> 0) AND (overview != '')"; |
8 |
ravilov |
1.1 |
$sth = $dbh->prepare($sql); |
9 |
|
|
if (!$sth) error("Cannot prepare query: \"$sql\""); |
10 |
|
|
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
11 |
ravilov |
1.4 |
while ($row = $sth->fetchrow_array()) { |
12 |
ravilov |
1.1 |
array_push($simptomi, array("id" => $row[0]."-0", "name" => MyEscape($row[1]))); |
13 |
ravilov |
1.4 |
$sql = "SELECT alias_id, alias FROM simptomi_aliasi WHERE (simptom_id = ".$row[0].")"; |
14 |
|
|
$sth2 = $dbh->prepare($sql); |
15 |
|
|
if (!$sth2) error("Cannot prepare query: \"$sql\""); |
16 |
|
|
if (!$sth2->execute()) error("Cannot execute query: \"$sql\""); |
17 |
|
|
while ($row2 = $sth2->fetchrow_array()) |
18 |
|
|
array_push($simptomi, array("id" => $row[0]."-".$row2[0], "name" => MyEscape($row2[1]))); |
19 |
|
|
$sth2->finish(); |
20 |
|
|
} |
21 |
ravilov |
1.1 |
$sth->finish(); |
22 |
|
|
usort($simptomi, "mySS"); |
23 |
|
|
$slova = array(); |
24 |
|
|
while (list($k, $v) = each($simptomi)) { |
25 |
|
|
$fl = $v["name"][0]; |
26 |
|
|
for ($i = 0; $i < count($slova); $i++) if ($slova[$i]["fl"] == $fl) break; |
27 |
|
|
if (!$slova[$i]) $slova[$i] = array("fl" => $fl, "simptomi" => array()); |
28 |
|
|
array_push($slova[$i]["simptomi"], $v); |
29 |
|
|
} |
30 |
|
|
$tpl->assign("slova", $slova); |
31 |
|
|
} else { |
32 |
|
|
list($sid, $aid) = explode("-", $id); |
33 |
|
|
$sql = "SELECT ".($aid?"simptomi_aliasi.alias":"simptomi.naziv")." FROM simptomi".($aid?", simptomi_aliasi":"")." WHERE (simptomi.simptom_id = $sid)".($aid?" AND (simptomi_aliasi.simptom_id = simptomi.simptom_id) AND (simptomi_aliasi.alias_id = $aid)":""); |
34 |
|
|
$sth = $dbh->prepare($sql); |
35 |
|
|
if (!$sth) error("Cannot prepare query: \"$sql\""); |
36 |
|
|
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
37 |
|
|
$row = $sth->fetchrow_array(); |
38 |
|
|
$sth->finish(); |
39 |
|
|
array_push($PATH, MyUpper($row[0])); |
40 |
|
|
$sql = "SELECT naziv, opis, overview, investigations, red_flags FROM simptomi WHERE (simptomi.simptom_id = $sid)"; |
41 |
|
|
$sth = $dbh->prepare($sql); |
42 |
|
|
if (!$sth) error("Cannot prepare query: \"$sql\""); |
43 |
|
|
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
44 |
|
|
$row = $sth->fetchrow_array(); |
45 |
|
|
$sth->finish(); |
46 |
ravilov |
1.4 |
list($snaziv, $opis, $overview, $invest, $redflags) = $row; |
47 |
|
|
$tpl->assign("symptom", escape_quote($snaziv)); |
48 |
ravilov |
1.3 |
$tpl->assign("opis", escape_quote($opis)); |
49 |
ravilov |
1.1 |
$tpl->assign("overview", escape_quote($overview)); |
50 |
ravilov |
1.3 |
#$tpl->assign("investigations", escape_quote($invest)); |
51 |
|
|
#$tpl->assign("red_flags", escape_quote($redflags)); |
52 |
ravilov |
1.1 |
$sql = "SELECT alias FROM simptomi_aliasi WHERE (simptom_id = $sid) ORDER BY alias"; |
53 |
|
|
$sth = $dbh->prepare($sql); |
54 |
|
|
if (!$sth) error("Cannot prepare query: \"$sql\""); |
55 |
|
|
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
56 |
|
|
$aliasi = array(); |
57 |
|
|
while ($row = $sth->fetchrow_array()) array_push($aliasi, MyEscape($row[0])); |
58 |
|
|
$sth->finish(); |
59 |
|
|
$tpl->assign("aliases", $aliasi); |
60 |
ravilov |
1.5 |
$sql = "SELECT bolesti.bolest_id, bolesti.is_bolest, bolesti.naziv, simptomi_bolesti.vjerojatnost FROM bolesti, simptomi_bolesti WHERE (bolesti.bolest_id = simptomi_bolesti.bolest_id) AND (simptomi_bolesti.simptom_id = $sid) ORDER BY simptomi_bolesti.vjerojatnost, bolesti.naziv"; |
61 |
ravilov |
1.1 |
$sth = $dbh->prepare($sql); |
62 |
|
|
if (!$sth) error("Cannot prepare query: \"$sql\""); |
63 |
|
|
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
64 |
|
|
$bolesti = array(); |
65 |
|
|
$uobicajeno = $povremeno = $rijetko = false; |
66 |
|
|
while ($row = $sth->fetchrow_array()) { |
67 |
ravilov |
1.5 |
list($bid, $is, $naziv, $vjer) = $row; |
68 |
ravilov |
1.1 |
if ($vjer == 1) $uobicajeno = true; |
69 |
|
|
if ($vjer == 2) $povremeno = true; |
70 |
|
|
if ($vjer == 3) $rijetko = true; |
71 |
ravilov |
1.5 |
if ($is[0] == "f" || $is[0] == "F") unset($is); |
72 |
ravilov |
1.1 |
array_push($bolesti, array( |
73 |
|
|
"id" => "$bid-0", |
74 |
ravilov |
1.5 |
"is" => $is ? true : false, |
75 |
ravilov |
1.1 |
"naziv" => escape_quote($naziv), |
76 |
|
|
"vjerojatnost" => $vjer |
77 |
|
|
)); |
78 |
|
|
} |
79 |
|
|
$sth->finish(); |
80 |
|
|
$tpl->assign("bolesti", $bolesti); |
81 |
|
|
$tpl->assign("uobicajeno", $uobicajeno); |
82 |
|
|
$tpl->assign("povremeno", $povremeno); |
83 |
|
|
$tpl->assign("rijetko", $rijetko); |
84 |
|
|
$simptomi = array(); |
85 |
ravilov |
1.4 |
$tmp = array(); |
86 |
|
|
for ($i = 0; $i < count($bolesti); $i++) $tmp[$i] = array("exists" => true, "val" => 1); |
87 |
|
|
array_push($simptomi, array("id" => "$sid-0", "name" => escape_quote($snaziv), "values" => $tmp)); |
88 |
ravilov |
1.1 |
for ($i = 0; $i < count($bolesti); $i++) { |
89 |
|
|
if ($bolesti[$i]["vjerojatnost"] != 1) continue; |
90 |
ravilov |
1.4 |
$sql = "SELECT simptomi.simptom_id, simptomi.naziv, simptomi.overview, sorter.value FROM simptomi, sorter WHERE (sorter.simptom_main_id = $sid) AND (sorter.simptom_id = simptomi.simptom_id) AND (sorter.bolest_id = ".$bolesti[$i]["id"].")"; |
91 |
ravilov |
1.1 |
$sth2 = $dbh->prepare($sql); |
92 |
|
|
if (!$sth2) error("Cannot prepare query: \"$sql\""); |
93 |
|
|
if (!$sth2->execute()) error("Cannot execute query: \"$sql\""); |
94 |
|
|
while ($row = $sth2->fetchrow_array()) { |
95 |
ravilov |
1.4 |
list($id, $simpt, $ov, $val) = $row; |
96 |
ravilov |
1.1 |
$simpt = escape_quote($simpt); |
97 |
|
|
for ($j = 0; $j < count($simptomi); $j++) if ($simptomi[$j]["name"] == $simpt) break; |
98 |
|
|
if (!$simptomi[$j]) { |
99 |
|
|
$tmp = array(); |
100 |
|
|
for ($k = 0; $k < count($bolesti); $k++) array_push($tmp, array("exists" => false)); |
101 |
ravilov |
1.4 |
array_push($simptomi, array("id" => $ov ? "$id-0" : "", "name" => $simpt, "values" => $tmp)); |
102 |
ravilov |
1.1 |
} |
103 |
|
|
$simptomi[$j]["values"][$i]["exists"] = true; |
104 |
|
|
$simptomi[$j]["values"][$i]["val"] = $val; |
105 |
|
|
} |
106 |
|
|
$sth2->finish(); |
107 |
|
|
} |
108 |
|
|
$tpl->assign("simptomi", $simptomi); |
109 |
|
|
} |
110 |
|
|
$dbh->disconnect(); |
111 |
|
|
$tpl->assign("ID", $id); |
112 |
|
|
?> |