Subversion Repositories ALCASAR

Rev

Rev 2097 | Rev 2370 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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