1 |
<?php |
2 |
include("inc/conn.php"); |
3 |
function myComp($a, $b) { return MyCompare($a["name"], $b["name"]); } |
4 |
function escape_quote($str) { return str_replace('"', """, $str); } |
5 |
$tpl->assign("ID", $gid); |
6 |
if ($gid) { |
7 |
$grupe = array(); |
8 |
$sql = "SELECT naziv FROM grupe_bolesti WHERE (grupa_b_id = $gid)"; |
9 |
$sth = $dbh->prepare($sql); |
10 |
if (!$sth) error("Cannot prepare query: \"$sql\""); |
11 |
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
12 |
$grupa = $sth->fetchrow_array(); |
13 |
$sth->finish(); |
14 |
if ($grupa) $grupa = array_shift($grupa); |
15 |
array_push($PATH, MyUpper($grupa)); |
16 |
$tpl->assign("naslov", $grupa); |
17 |
$grupe = array(); |
18 |
$sql = "SELECT bolest_id, naziv FROM bolesti WHERE (grupa_bolesti_id = $gid) AND (is_bolest)"; |
19 |
$sth = $dbh->prepare($sql); |
20 |
if (!$sth) error("Cannot prepare query: \"$sql\""); |
21 |
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
22 |
while ($row = $sth->fetchrow_array()) { |
23 |
array_push($grupe, array("id" => $row[0]."-0", "name" => MyEscape($row[1]))); |
24 |
$sql = "SELECT alias_id, alias FROM bolesti_aliasi WHERE (bolest_id = ".$row[0].")"; |
25 |
$sth2 = $dbh->prepare($sql); |
26 |
if (!$sth2) error("Cannot prepare query: \"$sql\""); |
27 |
if (!$sth2->execute()) error("Cannot execute query: \"$sql\""); |
28 |
while ($row2 = $sth2->fetchrow_array()) |
29 |
array_push($grupe, array("id" => $row[0]."-".$row2[0], "name" => MyEscape($row2[1]))); |
30 |
$sth2->finish(); |
31 |
} |
32 |
$sth->finish(); |
33 |
usort($grupe, "myComp"); |
34 |
$slova = array(); |
35 |
while (list($k, $v) = each($grupe)) { |
36 |
$fl = $v["name"][0]; |
37 |
for ($i = 0; $i < count($slova); $i++) if ($slova[$i]["fl"] == $fl) break; |
38 |
if (!$slova[$i]) $slova[$i] = array("fl" => $fl, "grupe" => array()); |
39 |
array_push($slova[$i]["grupe"], $v); |
40 |
} |
41 |
$tpl->assign("slova", $slova); |
42 |
} else { |
43 |
$tpl->assign("naslov", "Grupe bolesti"); |
44 |
$grupe = array(); |
45 |
$sql = "SELECT grupa_b_id, naziv FROM grupe_bolesti WHERE (grupa_b_id <> 0) AND (NOT plivamed)"; |
46 |
$sth = $dbh->prepare($sql); |
47 |
if (!$sth) error("Cannot prepare query: \"$sql\""); |
48 |
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
49 |
while ($row = $sth->fetchrow_array()) |
50 |
array_push($grupe, array("id" => $row[0], "name" => MyEscape($row[1]))); |
51 |
$sth->finish(); |
52 |
usort($grupe, "myComp"); |
53 |
$slova = array(); |
54 |
while (list($k, $v) = each($grupe)) { |
55 |
$fl = $v["name"][0]; |
56 |
for ($i = 0; $i < count($slova); $i++) if ($slova[$i]["fl"] == $fl) break; |
57 |
if (!$slova[$i]) $slova[$i] = array("fl" => $fl, "grupe" => array()); |
58 |
array_push($slova[$i]["grupe"], $v); |
59 |
} |
60 |
$tpl->assign("slova", $slova); |
61 |
} |
62 |
$dbh->disconnect(); |
63 |
?> |