This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
anketa_jsx.php
53 lines (52 loc) · 1.61 KB
/
anketa_jsx.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
session_start();
if (isset($_SESSION["uid"]) && isset($_GET['anketa']) && isset($_GET['volba'])) {
$anketa = addslashes(intval($_GET['anketa']));
$volba = addslashes(intval($_GET['volba']));
$moznosti = "";
include "./db/conn.php";
$jeAnketa = mysql_query("SELECT * FROM 3_ankety WHERE id = '$anketa' AND aktiv = '1'");
if (mysql_num_rows($jeAnketa)>0) {
$anketaO = mysql_fetch_object($jeAnketa);
mysql_free_result($jeAnketa);
$moznosti = explode(">", $anketaO->odpoved);
$hlasoval = mysql_fetch_row(mysql_query("SELECT count(*) FROM 3_ankety_data WHERE uid = '$_SESSION[uid]' AND ank_id = $anketaO->id"));
if ($hlasoval[0]==0) {
if (isSet($moznosti[$volba]) && $volba != "" && ctype_digit($volba)) {
mysql_query("INSERT INTO 3_ankety_data (uid,hlas,ank_id) VALUES ('$_SESSION[uid]','$volba','$anketaO->id')");
}
}
}
else {
$anketa = 0;
}
}else {
$anketa = 0;
}
header("Content-Type: text/xml");
echo "<anketa>\n";
if ($anketa > 0) {
$pocty = mysql_query("SELECT count(*) AS pocet, hlas FROM 3_ankety_data WHERE ank_id = '$anketa' GROUP BY hlas ORDER BY hlas ASC");
$hlasy = array_fill(0, 20, 0);
$hlasyAll = 0;
if (mysql_num_rows($pocty)>0) {
while ($hlasOne = mysql_fetch_object($pocty)) {
$hlasy[$hlasOne->hlas] = $hlasOne->pocet;
$hlasyAll += $hlasOne->pocet;
}
mysql_free_result($pocty);
for ($i=0;$i<count($moznosti);$i++) {
echo "<odpoved id='pocet$i'>$hlasy[$i]</odpoved>\n";
}
}
$konc = "ů";
if ($hlasyAll == 1) {
$konc = "";
}
elseif ($hlasyAll > 1 && $hlasyAll < 5) {
$konc = "y";
}
echo "<odpovedelo>$hlasyAll hlas$konc</odpovedelo>\n";
}
echo "</anketa>\n";
?>