Subversion Repositories ALCASAR

Rev

Rev 1702 | Rev 2112 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
514 richard 1
chilliController.interval = 20;
503 richard 2
chilliController.host = "alcasar";
484 stephane 3
chilliController.port = 3990;
4
chilliController.onUpdate = updateUI ;
5
chilliController.onError  = handleError ;
6
chilliClock.onTick = function () { }
537 stephane 7
 
528 stephane 8
var isloggedout = false;
484 stephane 9
 
10
if (!window.queryObj) {
11
    window.queryObj = new Object();
12
    window.location.search.replace(new RegExp("([^?=&]+)(=([^&]*))?","g"), function($0,$1,$2,$3) { queryObj[$1] = $3; });
13
}
14
 
15
chilliController.queryObj = window.queryObj;
16
 
17
function ie_getElementsByTagName(str) {
18
  if (str=="*") return document.all;
19
  else return document.all.tags(str);
20
}
21
 
22
if (document.all) 
23
  document.getElementsByTagName = ie_getElementsByTagName;
24
 
25
function hidePage(page) { 
26
    var e = document.getElementById(page);
27
    if (e != null) e.style.display='none';
28
}
29
 
30
function showPage(page) { 
31
    var e = document.getElementById(page);
32
    if (e != null) e.style.display='inline';
33
}
34
 
35
function setElementValue(elem, val, forceHTML) {
36
    var e = document.getElementById(elem);
37
    if (e != null) {
38
	var node = e;
39
	if (!forceHTML && node.firstChild) {
40
	    node = node.firstChild;
41
	    node.nodeValue = val;
42
	} else {
43
	    node.innerHTML = val;
44
	}
45
    }
46
}
47
 
48
chilliClock.onChange = function ( newval ) {
49
    setElementValue("sessionTime", chilliController.formatTime(newval));
50
}
51
 
52
function updateUI (cmd ) {
53
    log ( "Update UI is called. chilliController.clientState = " + chilliController.clientState ) ; 
54
 
55
    clearTimeout ( delayTimer );
56
 
57
    if ( chilliController.redir ) {
58
	if (chilliController.redir.originalURL != null &&
59
	    chilliController.redir.originalURL != '') {
60
	    setElementValue('originalURL', '<a target="_blank" href="'+chilliController.redir.originalURL+
61
			    '">'+chilliController.redir.originalURL+'</a>', true);
62
	}
63
	if (chilliController.redir.redirectionURL != null &&
64
	    chilliController.redir.redirectionURL != '') {
65
	    setElementValue('redirectionURL', chilliController.redir.redirectionURL);
66
	}
67
    }
68
 
69
    if ( chilliController.message ) {
70
	setElementValue('logonMessage', chilliController.message);
71
	chilliController.message = null;
72
	chilliController.refresh();
73
    }
74
 
75
    if ( chilliController.location ) {
76
	setElementValue('locationName', chilliController.location.name);
77
	chilliController.location = null;
78
    }
79
 
80
    if ( chilliController.clientState == 0 ) {
81
        showLoggedOutPage();
82
		setTimeout('chilliController.refresh()', 1000*chilliController.interval);//WBR for status page only
83
    }
84
 
85
    if ( chilliController.clientState == 1 ) {
86
        if ( chilliController.statusURL ) {
87
			chilliController.statusWindow = window.open(chilliController.statusURL, "");
88
		} else {
89
			showStatusPage();
90
        }
91
    }
92
 
93
    if (chilliController.redir.redirectionURL) {
94
	//chilliController.nextWindow = window.open(chilliController.redir.redirectionURL,'nextURL');
95
	window.location.href = chilliController.redir.redirectionURL;
96
	chilliController.redir.redirectionURL = null;
97
    }
98
 
99
    if ( chilliController.clientState == 2 ) showWaitPage();
100
}
101
 
102
function handleError( code ) {
103
    clearTimeout(delayTimer);
104
    //showErrorPage(code);
105
}
106
 
107
/* User interface pages update */
108
function showLoggedOutPage() {
528 stephane 109
	isloggedout = true;
484 stephane 110
    showPage("loggedOutPage");
111
    hidePage("statusPage");
112
    hidePage("waitPage");
113
    hidePage("errorPage");
114
    window.setTimeout("closePopup()",1000);
115
}
116
 
117
function showStatusPage() {
528 stephane 118
	isloggedout = false;
484 stephane 119
    hidePage("loggedOutPage");
120
    showPage("statusPage");
121
    hidePage("waitPage");
122
    hidePage("errorPage");
123
 
2097 raphael.pi 124
    //For no compliant browser with these javascript functions : onbeforeunload and unload, to disconnect users whose close status.php window. Now, we check if user is still connected while he is joinning 'still_connected.php'
125
    var xhttp = new XMLHttpRequest();
126
    xhttp.open('GET','still_connected.php',true);
127
    xhttp.send();
128
 
484 stephane 129
    // Update message
130
    if ( chilliController.message ) { 
131
	setElementValue("statusMessage", chilliController.message);
132
    }
133
 
134
    // Update session
135
    setElementValue("sessionId",
136
		    chilliController.session.sessionId ?
137
		    chilliController.session.sessionId :
138
		    "Not available");
139
 
140
	setElementValue("userName",
141
		    chilliController.session.userName ?
142
		    chilliController.session.userName :
143
		    "Not available");
144
 
145
    setElementValue("startTime",
146
		    chilliController.session.startTime ?
147
		    chilliController.session.startTime.toLocaleString() :
148
		    "Not available");
149
 
150
    setElementValue("sessionTimeout",
151
		    chilliController.formatTime(chilliController.session.sessionTimeout, 'unlimited'));
152
 
153
    setElementValue("idleTimeout",
154
		    chilliController.formatTime(chilliController.session.idleTimeout, 'unlimited'));
155
 
156
    setElementValue("maxInputOctets",
157
		    chilliController.formatBytes(chilliController.session.maxInputOctets));
158
    setElementValue("maxOutputOctets",
159
		    chilliController.formatBytes(chilliController.session.maxOutputOctets));
160
    setElementValue("maxTotalOctets",
161
		    chilliController.formatBytes(chilliController.session.maxTotalOctets));
162
 
163
    // Update accounting
164
    setElementValue("sessionTime",
165
		    chilliController.formatTime(chilliController.accounting.sessionTime));
166
 
167
    setElementValue("idleTime",
168
		    chilliController.formatTime(chilliController.accounting.idleTime));
169
 
170
    setElementValue("inputOctets" , chilliController.formatBytes(chilliController.accounting.inputOctets));
171
    setElementValue("outputOctets", chilliController.formatBytes(chilliController.accounting.outputOctets));
172
 
173
    chilliClock.resync (chilliController.accounting.sessionTime);
174
}
175
 
176
function showWaitPage(delay) {
177
    /* Wait for delay  */
178
    clearTimeout(delayTimer);	
179
    if (typeof(delay) == 'number' && (delay > 10)) {
180
	delayTimer= setTimeout('showWaitPage(0)' , delay);
181
	return;
182
    }
183
 
184
    /* show the waitPage */
185
    hidePage("loggedOutPage");
186
    hidePage("statusPage");
187
    showPage("waitPage");
188
    hidePage("errorPage");
189
}
190
 
191
function showErrorPage( str )  {
192
    setTimeout('chilliController.refresh()', 15000);
193
 
194
    hidePage("loggedOutPage");
195
    hidePage("statusPage");
196
    hidePage("waitPage");
197
    showPage("errorPage");
198
    setElementValue("errorMessage", str);
199
}
200
 
537 stephane 201
function closePopup(){
202
	this.focus();
203
	self.opener=this;
204
	self.close();
205
}
206
function alcasarLogoff(){
207
	if (isloggedout == false){
208
  		chilliClock.stop();
209
		chilliController.logoff();
210
	}
211
	showWaitPage(1000);
212
	isloggedout = true;
213
}
214
function logout() {
215
	alcasarLogoff();
216
	window.setTimeout("closePopup()",1000);
217
}
218
function logoutWithConfirmation(msg) {
219
	if (confirm(msg)) {
220
		logout();
221
	}
222
return false;
223
}
224
 
484 stephane 225
var chillijsWindowOnLoad = window.onload;
226
var delayTimer; // global reference to delayTimer
227
 
228
window.onload = function() {
229
    if (chillijsWindowOnLoad) 
230
	chillijsWindowOnLoad();
231
 
232
    var head = document.getElementsByTagName("head")[0];
233
    if (head == null) head = document.body;
234
 
235
    showWaitPage(); 
764 stephane 236
    setTimeout('chilliController.refresh()', 1500);
537 stephane 237
}
238
 
239
// The event window.onbeforeunload doesn't work with some browsers like 'opera' or 'Safari'.
240
// In the next version of alcasar, 30' without the status window do an automatic logout.
788 stephane 241
/*
537 stephane 242
var alcasarOnbeforeUnload = window.onbeforeunload;
243
 
244
window.onbeforeunload = function(){
245
	if (alcasarOnbeforeUnload)
246
		alcasarOnbeforeUnload();
247
	alcasarLogoff();
248
}
788 stephane 249
*/
250
 
251
// The event window.onbeforeunload doesn't work with some browsers like 'opera' or 'Safari'.
252
window.onbeforeunload = function(){
253
	alcasarLogoff();
254
	//on annule la fonction alcasarLogoff pour ne pas avoir une deuxième requette sur onunload
255
	alcasarLogoff = function(){}
256
}
1702 richard 257
// Opera doesn't fire the unload event when you navigate Back and Forward or close the window. It does when you click on a link.
788 stephane 258
window.onunload = function(){
259
	//la fonction quelque chose uniquement si onbeforeunload n'est pas executée
260
	alcasarLogoff();
261
}