1
|
|
|
/** |
2
|
|
|
* @file upgrade.js |
3
|
|
|
* @author Nils Laumaillé <[email protected]> |
4
|
|
|
* @version 2.1.27 |
5
|
|
|
* @copyright (c) 2009-2011 Nils Laumaillé |
6
|
|
|
* @license GNU GPL-3.0 |
7
|
|
|
* @link https://www.teampass.net |
8
|
|
|
* |
9
|
|
|
* This library is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
// Function - do a pause during javascript execution |
15
|
|
|
function pauseInExecution(millis) |
16
|
|
|
{ |
17
|
|
|
var date = new Date(); |
18
|
|
|
var curDate = null; |
|
|
|
|
19
|
|
|
|
20
|
|
|
do { |
21
|
|
|
curDate = new Date(); |
22
|
|
|
} while(curDate-date < millis); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Execute a file |
27
|
|
|
* @param {[type]} file [description] |
28
|
|
|
* @param {[type]} data [description] |
29
|
|
|
* @param {[type]} type [description] |
30
|
|
|
* @return {[type]} [description] |
31
|
|
|
*/ |
32
|
|
|
function httpRequest(file, data, type) { |
33
|
|
|
var xhrObject = null; |
34
|
|
|
var isChrome = navigator.userAgent.toLowerCase().indexOf("chrome") > -1; |
35
|
|
|
|
36
|
|
|
if (document.getElementById("menu_action") !== null) { |
37
|
|
|
document.getElementById("menu_action").value = "action"; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if(window.XMLHttpRequest) { |
41
|
|
|
// Firefox |
42
|
|
|
xhrObject = new XMLHttpRequest(); |
43
|
|
|
} else if(window.ActiveXObject) { |
44
|
|
|
// Internet Explorer |
45
|
|
|
xhrObject = new ActiveXObject("Microsoft.XMLHTTP"); |
46
|
|
|
} else { |
47
|
|
|
// XMLHttpRequest not supported by browser |
48
|
|
|
alert("Your browser does not support XMLHTTPRequest objects ..."); |
|
|
|
|
49
|
|
|
return; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if (type === "GET") { |
53
|
|
|
xhrObject.open("GET", file + "?" + data, true); |
54
|
|
|
xhrObject.send(null); |
55
|
|
|
} else { |
56
|
|
|
xhrObject.open("POST", file, true); |
57
|
|
|
xhrObject.onreadystatechange = function() { |
58
|
|
|
if(xhrObject.readyState === 4) { |
59
|
|
|
eval(xhrObject.responseText); |
|
|
|
|
60
|
|
|
//Check if query is for user identification. If yes, then reload page. |
61
|
|
|
if (data !== "" && data !== undefined && data.indexOf("ype=identify_user") > 0 ) { |
62
|
|
|
if (isChrome === true ) { |
63
|
|
|
// Needed pause for Chrome |
64
|
|
|
pauseInExecution(100); |
65
|
|
|
} |
66
|
|
|
if (type === "") { |
67
|
|
|
if (document.getElementById("erreur_connexion").style.display === "") { |
68
|
|
|
//rise an error in url. This in order to display the eror after refreshing |
69
|
|
|
window.location.href = encodeURI("index.php?error=rised"); |
70
|
|
|
} else { |
71
|
|
|
window.location.href = encodeURI("index.php"); |
72
|
|
|
} |
73
|
|
|
} else { |
74
|
|
|
if (type === "?error=rised") { |
75
|
|
|
if (document.getElementById("erreur_connexion").style.display === "none") { |
76
|
|
|
// Clean error in url |
77
|
|
|
type = ""; |
78
|
|
|
} else { |
79
|
|
|
// Maintain the ERROR |
80
|
|
|
type = "?error=rised"; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
// Redirection |
84
|
|
|
window.location.href = encodeURI("index.php" + type); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
xhrObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8"); |
90
|
|
|
xhrObject.send(data); |
91
|
|
|
} |
92
|
|
|
} |