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