1 |
<?php |
2 |
$limit = 10; |
3 |
include("inc/conn.php"); |
4 |
if ($qa) { |
5 |
function MyConv($str) { return strtr($str, "ðèæÐÈÆ", "¹ðè澩ÐÈÆ®"); } |
6 |
$id2 = $qa; |
7 |
$naslov = ""; |
8 |
while ($id2) { |
9 |
$sql = "SELECT naziv, parent FROM qa_tema WHERE (tema_id = $id2)"; |
10 |
$sth = $dbh->prepare($sql); |
11 |
if (!$sth) error("Cannot prepare query: \"$sql\""); |
12 |
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
13 |
$row = $sth->fetchrow_array(); |
14 |
$sth->finish(); |
15 |
list($naz, $id2) = $row; |
16 |
if ($naz) { |
17 |
if ($naslov) $naslov = " - ".$naslov; |
18 |
$naslov = $naz.$naslov; |
19 |
} |
20 |
} |
21 |
if ($naslov) array_push($PATH, MyUpper($naslov)); |
22 |
$tpl->assign("naslov", $naslov); |
23 |
if (!$offset) $offset = 0; |
24 |
$sql = "SELECT pitanje2, odgovor, gost, date_odgovor FROM qa WHERE (tema = $qa) AND (display) LIMIT ".($limit + 1)." OFFSET $offset"; |
25 |
$sth = $dbh->prepare($sql); |
26 |
if (!$sth) error("Cannot prepare query: \"$sql\""); |
27 |
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
28 |
$qas = array(); |
29 |
while ($row = $sth->fetchrow_array()) { |
30 |
list($p, $o, $g, $d) = $row; |
31 |
array_push($qas, array( |
32 |
"pitanje" => ParseNewline(MyEscape($p), false), |
33 |
"odgovor" => ParseNewline(MyEscape($o), false), |
34 |
"gost" => MyEscape($g), |
35 |
"date" => strftime("%d.%m.%Y.", strtotime($d)) |
36 |
)); |
37 |
} |
38 |
$sth->finish(); |
39 |
$tpl->assign("qas", $qas); |
40 |
$error = 0; |
41 |
if ($salji) { |
42 |
if (!$ime) $error |= 1; |
43 |
if (!$email) $error |= 2; |
44 |
if (!$pitanje) $error |= 4; |
45 |
if (!$error) { |
46 |
$ime2 = MyConv($dbh->quote($ime)); |
47 |
$email2 = MyConv($dbh->quote($email)); |
48 |
$pitanje2 = MyConv($dbh->quote($pitanje)); |
49 |
$sql = "INSERT INTO qa (ime_prezime, email, tema, pitanje, pitanje2, date_pitanje, display) VALUES ($ime2, $email2, $qa, $pitanje2, $pitanje2, NOW(), false)"; |
50 |
$dbh->dbh_do($sql); |
51 |
$sql = "SELECT email FROM qa_email WHERE (tema = $qa)"; |
52 |
$sth = $dbh->prepare($sql); |
53 |
if (!$sth) error("Cannot prepare query: \"$sql\""); |
54 |
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
55 |
$mails = array(); |
56 |
while ($row = $sth->fetchrow_array()) array_push($mails, $row[0]); |
57 |
$sth->finish(); |
58 |
mail(implode(", ", $mails), "PLIVA".($isMed?"med.net":"zdravlje.hr")." - Q&A", "\nIme: $ime\nE-mail: $email\n--------\n$pitanje\n", "From: q-a@pliva".($isMed?"med.net":"zdravlje.hr")."\nCc: darko@plivazdravlje.hr"); |
59 |
#mail($email, "PLIVA".($isMed?"med.net":"zdravlje.hr")." - Q&A", "Po¹tovani,\n\nVa¹e pitanje je primljeno na obradu. Uskoro oèekujte odgovor.\n\nS po¹tovanjem,\nPLIVA".($isMed?"med.net":"zdravlje.hr"), "From: q-a@pliva".($isMed?"med.net":"zdravlje.hr")); |
60 |
} |
61 |
} |
62 |
$tpl->assign("error", $error); |
63 |
$done = (!$salji || $error) ? false : true; |
64 |
if ($done) $ime = $email = $pitanje = ""; |
65 |
$tpl->assign("ime", $ime); |
66 |
$tpl->assign("email", $email); |
67 |
$tpl->assign("pitanje", $pitanje); |
68 |
$tpl->assign("done", $done); |
69 |
$tpl->assign("next", (count($qas) > 10) ? ($offset + 10) : 0); |
70 |
$tpl->assign("prev", $offset ? ($offset - 10) : 0); |
71 |
$tpl->assign("offset", $offset); |
72 |
} else { |
73 |
function MyCmp1($a, $b) { return MyCompare($a["naziv"], $b["naziv"]); } |
74 |
function LoadTeme($id = 0) { |
75 |
global $dbh, $isMed; |
76 |
$sql = "SELECT tema_id, naziv FROM qa_tema WHERE (".($isMed?"":"NOT ")."plivamed) AND (parent = ".($id?$id:"NULL").")"; |
77 |
$sth = $dbh->prepare($sql); |
78 |
if (!$sth) error("Cannot prepare query: \"$sql\""); |
79 |
if (!$sth->execute()) error("Cannot execute query: \"$sql\""); |
80 |
$tema = array(); |
81 |
while ($row = $sth->fetchrow_array()) { |
82 |
list($id2, $naz) = $row; |
83 |
$sql = "SELECT count(qa_id) FROM qa WHERE (tema = $id2) AND (display)"; |
84 |
$sth2 = $dbh->prepare($sql); |
85 |
if (!$sth2) error("Cannot prepare query: \"$sql\""); |
86 |
if (!$sth2->execute()) error("Cannot execute query: \"$sql\""); |
87 |
$row = $sth2->fetchrow_array(); |
88 |
$sth2->finish(); |
89 |
if ($row) $row = array_shift($row); |
90 |
$sub = LoadTeme($id2); |
91 |
if (count($sub) < 0) undef($sub); |
92 |
array_push($tema, array("id" => $id2, "naziv" => MyEscape($naz), "teme" => $sub, "count" => $row)); |
93 |
} |
94 |
$sth->finish(); |
95 |
if ($id) usort($tema, "MyCmp1"); |
96 |
return $tema; |
97 |
} |
98 |
$teme = LoadTeme(); |
99 |
$tpl->assign("teme", $teme); |
100 |
} |
101 |
$tpl->assign("qa", $qa); |
102 |
$dbh->disconnect(); |
103 |
?> |