annotate showajax.js.php @ 1120:b2bca5f6d0ff default tip

Cosmetic cleanup: remove trailing whitespace.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 13 Dec 2020 13:47:13 +0200
parents 76e11ae923a7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1069
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 <?php
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 //
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 // FAPWeb - Simple Web-based Demoparty Management System
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 // Party main screen viewer
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 // (C) Copyright 2012-2017 Tecnic Software productions (TNSP)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 //
1071
76e11ae923a7 Use long tags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1069
diff changeset
7 header("Content-Type: application/javascript");
76e11ae923a7 Use long tags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1069
diff changeset
8 require_once "mconfig.inc.php";
76e11ae923a7 Use long tags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1069
diff changeset
9 require_once "msite.inc.php";
76e11ae923a7 Use long tags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1069
diff changeset
10 require_once "msession.inc.php";
76e11ae923a7 Use long tags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1069
diff changeset
11
1069
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 stCommonAJAX("showajax.php", "show.php");
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 ?>
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 var failCount = 0;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 var lastUpdate = 0;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 var errorView = false;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 function updateView(txt)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 var view = document.getElementById("mainView");
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 if (view && txt != false && txt != "")
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 view.innerHTML = txt;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 function displayError()
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 // Increase failure count
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 if (++failCount >= 3 && !errorView)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 errorView = true;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 updateView("<div class=\"slideHeader\"><div class=\"slideHeaderDiv\"></div></div><div class=\"slideText\"><div class=\"guru\">Software Failure.&nbsp;&nbsp;&nbsp;Press left mouse button to continue.<br />Guru Meditation #00000004.0000AAC0</div></div>");
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 //
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 // Update view when triggered by main tick
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 //
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 function viewChanged()
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 var msuccess2 = function(txt)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 // Successfully fetched new data, initiate view update
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 updateView(txt);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 var msuccess1 = function(txt)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 lastUpdate = txt;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 jsSendPOSTRequest("action=get&type=slide", msuccess2, displayError);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 jsSendPOSTRequest("action=get&type=update", msuccess1, displayError);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 function setTickUpdate(qtime)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 if (!timeOutSet)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 timeOutSet = true;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 setTimeout(function() { tickMain(); }, qtime);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 //
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 // Main tick function, check for updates from server
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 //
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 function tickMain()
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 timeOutSet = false;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 var msuccess = function(txt)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 failCount = 0;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 if (txt == "changed")
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 viewChanged();
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 setTickUpdate(250);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 else
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 if (txt == "reload")
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 location.reload();
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 else
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 setTickUpdate(500);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 }
1120
b2bca5f6d0ff Cosmetic cleanup: remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1071
diff changeset
95
1069
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 var mfail = function(txt)
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 displayError();
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 setTickUpdate(5000);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 jsSendPOSTRequest("action=check&lastUpdate="+lastUpdate, msuccess, mfail);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 }
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 var timeOutSet = false;
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 document.addEventListener("DOMContentLoaded",
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 function ()
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 {
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 setTickUpdate(100);
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 viewChanged();
5f92fa5e683a Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 });