Mercurial > hg > fapweb
annotate usrajax.php @ 211:5bae42020034
Factorize some code into msitegen.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 17 Nov 2013 20:51:03 +0200 |
parents | 8df523e6326a |
children | bcc3c4696b3e |
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 | |
161 | 47 if (stExecSQL($sql) === false) |
48 return FALSE; | |
49 else | |
50 return TRUE; | |
93 | 51 } |
52 | |
53 | |
165 | 54 // |
55 // Initialize | |
56 // | |
93 | 57 if (!stUserSessionAuth()) |
58 { | |
59 stSetupCacheControl(); | |
60 | |
61 stSessionEnd(SESS_USER); | |
62 | |
123
5837b9333964
Add new "about" page, and setting for default page.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
63 header("Location: ".stGetSetting("defaultPage")); |
93 | 64 exit; |
65 } | |
66 | |
67 stSetupCacheControl(); | |
68 | |
69 if (!stConnectSQLDB()) | |
70 die("Could not connect to SQL database."); | |
71 | |
72 stReloadSettings(); | |
73 | |
74 | |
161 | 75 // |
76 // Handle the request | |
77 // | |
93 | 78 $action = "ERROR"; |
79 if (stChkRequestItem("action") && stChkRequestItem("type")) | |
80 { | |
81 $action = $_REQUEST["action"]; | |
82 $type = $_REQUEST["type"]; | |
83 } | |
84 | |
85 switch ($action) | |
86 { | |
87 case "get": | |
88 // | |
89 // Get specific data | |
90 // | |
91 switch ($type) | |
92 { | |
93 case "votes": | |
94 $sql = "SELECT * FROM votes ORDER BY utime DESC"; | |
95 break; | |
96 } | |
97 | |
98 // | |
99 // Perform query if we need to, output results | |
100 // | |
101 if (isset($sql) && ($res = stExecSQLCond($sql, "")) !== FALSE) | |
102 { | |
103 if ($type == "votes") | |
104 { | |
105 } | |
106 } | |
107 break; | |
108 | |
109 case "set": | |
110 // | |
153
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
111 // Set vote, if voting is enabled |
93 | 112 // |
153
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
113 if ($type == "votes" && stChkSetting("allowVoting") && |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
114 stChkRequestItem("votekey") && |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
115 stChkRequestItem("entry_id") && |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
116 stChkRequestItem("vote")) |
93 | 117 { |
153
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
118 // 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
|
119 $entry_id = stGetRequestItem("entry_id"); |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
120 |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
121 $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
|
122 if (($votekey = stFetchSQLColumn($sql)) !== false) |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
123 { |
aecf145e7c70
Some work on the voting backend.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
124 } |
93 | 125 } |
126 else | |
127 stSetStatus(902, "No data."); | |
128 break; | |
129 | |
130 default: | |
131 stSetStatus(404, "Not Found"); | |
132 break; | |
133 } | |
134 | |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
135 stDumpAJAXStatusErrors(); |
93 | 136 ?> |