Mercurial > hg > fapweb
annotate usrajax.php @ 294:efba5a51f8fa
Fix some 10L's ... durr.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 25 Nov 2013 03:19:58 +0200 |
parents | bb96aef874a9 |
children | 8098b5b80f8c |
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 | |
245
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
71 $userKeyLen = stGetSetting("userKeyLength"); |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
72 $voteMin = stGetSetting("voteMin"); |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
73 $voteMax = stGetSetting("voteMax"); |
93 | 74 |
161 | 75 // |
76 // Handle the request | |
77 // | |
216 | 78 switch (stGetRequestItem("action")) |
93 | 79 { |
80 case "set": | |
81 // | |
153
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
82 // Set vote, if voting is enabled |
93 | 83 // |
245
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
84 if (!stChkSetting("allowVoting")) |
294 | 85 stError("Voting is not enabled."); |
245
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
86 else |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
87 if (stChkRequestItem("entry_id", $entry_id, |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
88 array(CHK_TYPE, VT_INT, "Invalid data.")) && |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
89 stChkRequestItem("vote", $vote, |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
90 array(CHK_TYPE, VT_INT, "Invalid data."), |
294 | 91 array(CHK_RANGE, VT_INT, array($voteMin, $voteMax), "Invalid vote value."))) |
93 | 92 { |
153
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
93 // Check if voting is enabled on the compo and voter is valid |
245
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
94 $sql = stPrepareSQL("SELECT * FROM votekeys WHERE key=%s", stGetSessionItem("key")); |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
95 if (($votekey = stFetchSQL($sql)) !== false) |
153
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
96 { |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
97 } |
245
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
98 else |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
99 stError("Invalid data."); |
93 | 100 } |
245
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
101 break; |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
102 |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
103 case "submit": |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
104 if (!stChkSetting("allowVoting")) |
294 | 105 stError("Voting is not enabled."); |
93 | 106 else |
245
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
107 { |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
108 $sql = stPrepareSQL("SELECT * FROM votekeys WHERE key=%s", stGetSessionItem("key")); |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
109 if (($votekey = stFetchSQL($sql)) !== false) |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
110 { |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
111 } |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
112 else |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
113 stError("Invalid data."); |
bb96aef874a9
Work on the voting backend code.
Matti Hamalainen <ccr@tnsp.org>
parents:
225
diff
changeset
|
114 } |
93 | 115 break; |
116 | |
117 default: | |
118 stSetStatus(404, "Not Found"); | |
119 break; | |
120 } | |
121 | |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
122 stDumpAJAXStatusErrors(); |
93 | 123 ?> |