Mercurial > hg > fapweb
annotate majax.inc.php @ 1020:2a259e243350
Don't use a HTML table for the votekeys.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 05 Nov 2015 19:22:11 +0200 |
parents | ffacd904fd1f |
children |
rev | line source |
---|---|
126
71c35d5302c2
More work on cleanups, and AJAX modularization.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
1 <? |
136
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
2 // |
571
ce11ea112a65
Change the header blurb a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
3 // FAPWeb - Simple Web-based Demoparty Management System |
136
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
4 // Common AJAX Javascript code module |
1001 | 5 // (C) Copyright 2012-2015 Tecnic Software productions (TNSP) |
136
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
6 // |
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
7 |
aeebfedb5709
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
126
diff
changeset
|
8 |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
727
diff
changeset
|
9 function stCommonAJAX($backend, $failover) |
341
eaf435c99fe4
Add confirmBox() wrapper function as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
10 { |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
727
diff
changeset
|
11 ?> |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
727
diff
changeset
|
12 <script type="text/javascript" src="ajax.js"></script> |
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
727
diff
changeset
|
13 <script type="text/javascript"> |
105
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 |
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 |
342
3175ec252c73
Rename sendPOSTRequest() to jsSendPOSTRequest().
Matti Hamalainen <ccr@tnsp.org>
parents:
341
diff
changeset
|
16 function jsSendPOSTRequest(params, success, failure) |
105
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 { |
359
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
18 <? |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
19 if (($csrfID = stGetSessionItem("csrfID", FALSE)) !== FALSE) |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
20 echo " params += \"&csrfID=".$csrfID."\";\n"; |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
21 ?> |
344
6d50238a2d50
Rename createXMLRequest() to jsCreateXMLRequest().
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
22 var req = jsCreateXMLRequest(); |
126
71c35d5302c2
More work on cleanups, and AJAX modularization.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
23 req.open("POST", "<? echo $backend ?>", true); |
105
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 req.setRequestHeader("Content-length", params.length); |
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 req.setRequestHeader("Connection", "close"); |
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 |
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 req.onreadystatechange = function() |
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 { |
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 if (req.readyState == 4) |
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 { |
686
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
32 switch (req.status) |
105
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 { |
686
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
34 case 404: |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
35 window.location = "<? echo $failover ?>"; |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
36 break; |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
37 |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
38 case 902: |
826
8bee2554d95e
Rename one javascript function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
39 jsStatusMsg(req.statusText); |
686
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
40 jsMessageBox(req.responseText); |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
41 break; |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
42 |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
43 case 903: |
688
2b3c17c7b7f8
Improve admin session expiration handling inform box.
Matti Hamalainen <ccr@tnsp.org>
parents:
686
diff
changeset
|
44 { |
2b3c17c7b7f8
Improve admin session expiration handling inform box.
Matti Hamalainen <ccr@tnsp.org>
parents:
686
diff
changeset
|
45 var nitem = document.getElementById("messageBox"); |
2b3c17c7b7f8
Improve admin session expiration handling inform box.
Matti Hamalainen <ccr@tnsp.org>
parents:
686
diff
changeset
|
46 if (nitem) |
2b3c17c7b7f8
Improve admin session expiration handling inform box.
Matti Hamalainen <ccr@tnsp.org>
parents:
686
diff
changeset
|
47 { |
2b3c17c7b7f8
Improve admin session expiration handling inform box.
Matti Hamalainen <ccr@tnsp.org>
parents:
686
diff
changeset
|
48 nitem.innerHTML = "<div class='messageBoxInner'>"+ req.responseText + |
2b3c17c7b7f8
Improve admin session expiration handling inform box.
Matti Hamalainen <ccr@tnsp.org>
parents:
686
diff
changeset
|
49 "<div class='messageBoxControls'>"+ |
2b3c17c7b7f8
Improve admin session expiration handling inform box.
Matti Hamalainen <ccr@tnsp.org>
parents:
686
diff
changeset
|
50 "</div></div>"; |
2b3c17c7b7f8
Improve admin session expiration handling inform box.
Matti Hamalainen <ccr@tnsp.org>
parents:
686
diff
changeset
|
51 nitem.style.display = "block"; |
2b3c17c7b7f8
Improve admin session expiration handling inform box.
Matti Hamalainen <ccr@tnsp.org>
parents:
686
diff
changeset
|
52 } |
2b3c17c7b7f8
Improve admin session expiration handling inform box.
Matti Hamalainen <ccr@tnsp.org>
parents:
686
diff
changeset
|
53 } |
686
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
54 break; |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
55 |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
56 case 200: |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
57 if (success) |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
58 success(req.responseText); |
826
8bee2554d95e
Rename one javascript function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
59 jsStatusMsg(req.statusText); |
686
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
60 break; |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
61 |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
62 default: |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
63 if (failure) |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
64 failure(req.status, req.statusText, req.responseText); |
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
65 else |
826
8bee2554d95e
Rename one javascript function.
Matti Hamalainen <ccr@tnsp.org>
parents:
728
diff
changeset
|
66 jsStatusMsg("["+req.status+" - "+req.statusText+"] "+ req.responseText); |
686
8730bffcffd4
Add new return code 903 and handling for it.
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
67 break; |
105
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 } |
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 } |
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 } |
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 req.send(params); |
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 } |
a85f258f6beb
Move some things around and modularize the code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 |
728
8b1abca34033
Move code around, for cleaner structure.
Matti Hamalainen <ccr@tnsp.org>
parents:
727
diff
changeset
|
74 </script> |
126
71c35d5302c2
More work on cleanups, and AJAX modularization.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
75 <? |
71c35d5302c2
More work on cleanups, and AJAX modularization.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
76 } |
71c35d5302c2
More work on cleanups, and AJAX modularization.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
77 ?> |