Mercurial > hg > fapweb
annotate usrajax.php @ 225:1bb4f4bcb027
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 18 Nov 2013 04:36:47 +0200 |
parents | bcc3c4696b3e |
children | bb96aef874a9 |
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"; | |
175
8df523e6326a
User require_once instead of require.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
8 require_once "mconfig.inc.php"; |
8df523e6326a
User require_once instead of require.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
9 require_once "msite.inc.php"; |
8df523e6326a
User require_once instead of require.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
10 require_once "msession.inc.php"; |
93 | 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 | |
225 | 47 return stExecSQL($sql); |
93 | 48 } |
49 | |
50 | |
165 | 51 // |
52 // Initialize | |
53 // | |
93 | 54 if (!stUserSessionAuth()) |
55 { | |
56 stSetupCacheControl(); | |
57 | |
58 stSessionEnd(SESS_USER); | |
59 | |
123
5837b9333964
Add new "about" page, and setting for default page.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
60 header("Location: ".stGetSetting("defaultPage")); |
93 | 61 exit; |
62 } | |
63 | |
64 stSetupCacheControl(); | |
65 | |
66 if (!stConnectSQLDB()) | |
67 die("Could not connect to SQL database."); | |
68 | |
69 stReloadSettings(); | |
70 | |
71 | |
161 | 72 // |
73 // Handle the request | |
74 // | |
216 | 75 switch (stGetRequestItem("action")) |
93 | 76 { |
77 case "set": | |
78 // | |
153
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
79 // Set vote, if voting is enabled |
93 | 80 // |
216 | 81 if (stChkSetting("allowVoting") && |
153
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
82 stChkRequestItem("votekey") && |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
83 stChkRequestItem("entry_id") && |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
84 stChkRequestItem("vote")) |
93 | 85 { |
153
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
86 // 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
|
87 $entry_id = stGetRequestItem("entry_id"); |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
88 |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
89 $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
|
90 if (($votekey = stFetchSQLColumn($sql)) !== false) |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
91 { |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
92 } |
93 | 93 } |
94 else | |
95 stSetStatus(902, "No data."); | |
96 break; | |
97 | |
98 default: | |
99 stSetStatus(404, "Not Found"); | |
100 break; | |
101 } | |
102 | |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
103 stDumpAJAXStatusErrors(); |
93 | 104 ?> |