Mercurial > hg > fapweb
annotate usrajax.php @ 162:cc02c1d6808c
Remove dead code.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 27 Oct 2013 03:21:34 +0200 |
parents | 50032763bc79 |
children | 15182643d672 |
rev | line source |
---|---|
93 | 1 <? |
2 // | |
155
5b92f130ba87
Add copyright header blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
3 // FAPWeb Simple Demoparty System |
5b92f130ba87
Add copyright header blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
4 // User actions page AJAX backend module |
5b92f130ba87
Add copyright header blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
5 // (C) Copyright 2012-2013 Tecnic Software productions (TNSP) |
93 | 6 // |
7 $sessionType = "user"; | |
8 require "mconfig.inc.php"; | |
9 require "msite.inc.php"; | |
10 require "msession.inc.php"; | |
11 | |
12 | |
161 | 13 // |
14 // "Submit" one vote into the database | |
15 // | |
93 | 16 function stSubmitOneVote($voter_id, $entry_id, $vote) |
17 { | |
161 | 18 // Check if the entry_id is actually valid |
19 $sql = stPrepareSQL("SELECT * FROM entries WHERE id=%d", $entry_id); | |
20 if (($entry = stFetchSQL($sql)) === false) | |
21 return FALSE; | |
22 | |
23 // Check if the compo is valid for the entry | |
24 $sql = stPrepareSQL("SELECT * FROM compos WHERE id=%d", $entry["compo_id"]); | |
25 if (($compo = stFetchSQL($sql)) === false || $compo["voting"] == 0) | |
26 return FALSE; | |
27 | |
28 // Check if the vote already exists | |
93 | 29 $sql = stPrepareSQL("SELECT id FROM votes WHERE voter_id=%d AND entry_id=%d", |
30 $voter_id, $entry_id); | |
31 | |
32 if (($res = stFetchSQLColumn($sql)) === false) | |
33 { | |
161 | 34 // Didn't exist, insert it |
93 | 35 $sql = stPrepareSQL( |
36 "INSERT INTO votes (voter_id,entry_id,value) VALUES (%d,%d,%d)", | |
37 $voter_id, $entry_id, $vote); | |
38 } | |
39 else | |
40 { | |
161 | 41 // Existed, thusly update |
93 | 42 $sql = stPrepareSQL( |
43 "UPDATE votes SET value=%d WHERE voter_id=%d AND entry_id=%d", | |
44 $vote, $voter_id, $eid); | |
45 } | |
46 | |
161 | 47 if (stExecSQL($sql) === false) |
48 return FALSE; | |
49 else | |
50 return TRUE; | |
93 | 51 } |
52 | |
53 | |
54 | |
55 // Check if we are allowed to execute | |
56 if (!stUserSessionAuth()) | |
57 { | |
58 stSetupCacheControl(); | |
59 | |
60 stSessionEnd(SESS_USER); | |
61 | |
123
5837b9333964
Add new "about" page, and setting for default page.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
62 header("Location: ".stGetSetting("defaultPage")); |
93 | 63 exit; |
64 } | |
65 | |
161 | 66 // |
67 // Initialize | |
68 // | |
93 | 69 stSetupCacheControl(); |
70 | |
71 if (!stConnectSQLDB()) | |
72 die("Could not connect to SQL database."); | |
73 | |
74 stReloadSettings(); | |
75 | |
76 | |
161 | 77 // |
78 // Handle the request | |
79 // | |
93 | 80 $action = "ERROR"; |
81 if (stChkRequestItem("action") && stChkRequestItem("type")) | |
82 { | |
83 $action = $_REQUEST["action"]; | |
84 $type = $_REQUEST["type"]; | |
85 } | |
86 | |
87 switch ($action) | |
88 { | |
89 case "get": | |
90 // | |
91 // Get specific data | |
92 // | |
93 switch ($type) | |
94 { | |
95 case "votes": | |
96 $sql = "SELECT * FROM votes ORDER BY utime DESC"; | |
97 break; | |
98 } | |
99 | |
100 // | |
101 // Perform query if we need to, output results | |
102 // | |
103 if (isset($sql) && ($res = stExecSQLCond($sql, "")) !== FALSE) | |
104 { | |
105 if ($type == "votes") | |
106 { | |
107 } | |
108 } | |
109 break; | |
110 | |
111 case "set": | |
112 // | |
153
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
113 // Set vote, if voting is enabled |
93 | 114 // |
153
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
115 if ($type == "votes" && stChkSetting("allowVoting") && |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
116 stChkRequestItem("votekey") && |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
117 stChkRequestItem("entry_id") && |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
118 stChkRequestItem("vote")) |
93 | 119 { |
153
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
120 // Check if voting is enabled on the compo and voter is valid |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
121 $entry_id = stGetRequestItem("entry_id"); |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
122 |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
123 $sql = stPrepareSQL("SELECT * FROM votekeys WHERE key=%s", stGetRequestItem("votekey")); |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
124 if (($votekey = stFetchSQLColumn($sql)) !== false) |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
125 { |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
126 } |
93 | 127 } |
128 else | |
129 stSetStatus(902, "No data."); | |
130 break; | |
131 | |
132 default: | |
133 stSetStatus(404, "Not Found"); | |
134 break; | |
135 } | |
136 | |
137 ?> |