--- inc/pgLinkovi.php 2001/09/28 23:34:37 1.1 +++ inc/pgLinkovi.php 2001/10/05 15:10:53 1.2 @@ -1,11 +1,52 @@ prepare($sql); - if (!$sth) error("Cannot prepare query: \"$sql\""); - if (!$sth->execute()) error("Cannot execute query: \"$sql\""); - $linkovi = array(); - while ($row = $sth->fetchrow_array()) - array_push($linkovi, array("url" => MyEscape($row[0]), "naslov" => MyEscape($row[1]), "opis" => MyEscape($row[2]))); - $sth->finish(); - $tpl->assign("linkovi", $linkovi); + function myCmp($a, $b) { return MyCompare($a["naslov"], $b["naslov"]); } + function myCmp2($a, $b) { return MyCompare($a["naziv"], $b["naziv"]); } + $naslov = ""; + if ($grupa) { + $sql = "SELECT opis FROM specijalizacije WHERE (link) AND (spec_id = $grupa)"; + $sth = $dbh->prepare($sql); + if (!$sth) error("Cannot prepare query: \"$sql\""); + if (!$sth->execute()) error("Cannot execute query: \"$sql\""); + $row = $sth->fetchrow_array(); + $sth->finish(); + if ($row) $row = array_shift($row); + if ($row) $naslov = $row; + $sql = "SELECT url, naslov, opis FROM linkovi, link_spec".($spec?", link_spec":"")." WHERE (linkovi.link_id = link_spec.link_id) AND (link_spec.spec_id = $grupa)".($spec?" AND (link_spec.spec_id = $spec)":""); + $sth = $dbh->prepare($sql); + if (!$sth) error("Cannot prepare query: \"$sql\""); + if (!$sth->execute()) error("Cannot execute query: \"$sql\""); + $linkovi = array(); + while ($row = $sth->fetchrow_array()) + array_push($linkovi, array("url" => MyEscape($row[0]), "naslov" => MyEscape($row[1]), "opis" => MyEscape($row[2]))); + $sth->finish(); + usort($linkovi, "myCmp"); + $tpl->assign("linkovi", $linkovi); + } else { + $sql = "SELECT spec_id, opis FROM specijalizacije WHERE (link)"; + $sth = $dbh->prepare($sql); + if (!$sth) error("Cannot prepare query: \"$sql\""); + if (!$sth->execute()) error("Cannot execute query: \"$sql\""); + $grupe = array(); + while ($row = $sth->fetchrow_array()) + array_push($grupe, array("id" => $row[0], "naziv" => MyEscape($row[1]))); + $sth->finish(); + usort($grupe, "myCmp2"); + $tpl->assign("grupe", $grupe); + } + if ($spec) { + $sql = "SELECT opis FROM specijalizacije WHERE spec_id = $spec"; + $sth = $dbh->prepare($sql); + if (!$sth) error("Cannot prepare query: \"$sql\""); + if (!$sth->execute()) error("Cannot execute query: \"$sql\""); + $row = $sth->fetchrow_array(); + $sth->finish(); + if ($row) $row = array_shift($row); + if ($row) { + if ($naslov) $naslov .= " - "; + $naslov .= $row; + } + } + $tpl->assign("grupa", $grupa); + $tpl->assign("naslov", $naslov); + $dbh->disconnect(); ?>