-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
executable file
·219 lines (204 loc) · 6.9 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// JavaScript Document
var req;
var displayXML;
function loadXMLDoc(url,val) {
displayXML = document.getElementById('displayXML');
req = false;
// branch for native XMLHttpRequest object
if(window.XMLHttpRequest) {
try {
req = new XMLHttpRequest();
} catch(e) {
req = false;
}
// branch for IE/Windows ActiveX version
} else if(window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
req = false;
}
}
}
if(req) {
if(val) {
switch(val) {
case 'install':
{
sForm = document.forms['installationForm'];
host = sForm.elements['host'];
username = sForm.elements['username'];
password = sForm.elements['password'];
database = sForm.elements['database'];
tablepref = sForm.elements['tablepref'];
institute = sForm.elements['institute'];
if(host.value == "" || username.value == "" || password.value == "" || database.value == "" || tablepref.value == "" || institute.value == "") {
displayXML.innerHTML = "All fields are mandatory. They cannot be left blank.";
return;
}
sParams = "";
sParams = addPostParam(sParams, "host", host.value);
sParams = addPostParam(sParams, "username", username.value);
sParams = addPostParam(sParams, "password", password.value);
sParams = addPostParam(sParams, "database", database.value);
sParams = addPostParam(sParams, "tablepref", tablepref.value);
sParams = addPostParam(sParams, "institute", institute.value);
req.onreadystatechange = processReqChange;
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(sParams);
break;
}
case 'login':
{
sForm = document.forms['loginForm'];
username = sForm.elements['username'];
password = sForm.elements['password'];
if(username.value == "" || password.value == "") {
displayXML.innerHTML = "All fields are mandatory. They cannot be left blank.";
return;
}
sParams = "";
sParams = addPostParam(sParams, "username", username.value);
sParams = addPostParam(sParams, "password", password.value);
req.onreadystatechange = processReqChangeLogin;
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(sParams);
break;
}
case 'register':
{
if(!sForm) { // to get around a bug in IE
sForm = document.forms['sForm'];
}
sName = sForm.elements['sName'];
sFName = sForm.elements['sFName'];
sRelation = sForm.elements['sRelation'];
sTitle = sForm.elements['sTitle'];
sSex = sForm.elements['sSex'];
sRollno = sForm.elements['sRollno'];
sClass = sForm.elements['sClass'];
sHostel = sForm.elements['sHostel'];
sRoom = sForm.elements['sRoom'];
sDate = sForm.elements['sDate'];
sParams = "";
sParams = addPostParam(sParams, "sName", sName.value);
sParams = addPostParam(sParams, "sFName", sFName.value);
sParams = addPostParam(sParams, "sRelation", sRelation.value);
sParams = addPostParam(sParams, "sTitle", sTitle.value);
sParams = addPostParam(sParams, "sSex", sSex.value);
sParams = addPostParam(sParams, "sRollno", sRollno.value);
sParams = addPostParam(sParams, "sClass", sClass.value);
sParams = addPostParam(sParams, "sHostel", sHostel.value);
sParams = addPostParam(sParams, "sRoom", sRoom.value);
sParams = addPostParam(sParams, "sDate", sDate.value);
req.onreadystatechange = processReqChangeLogin;
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(sParams);
break;
}
}
}
else {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send("");
}
}
}
function processReqChange() {
if((req.readyState == 4) && (req.status == 200)) {
document.getElementById('displayXML').innerHTML = req.responseText;
}
}
function processReqChangeLogin() {
if((req.readyState == 4) && (req.status == 200)) {
document.getElementById('displayXML').innerHTML = req.responseText;
if(req.responseText == 'Login successful') {
window.location = './index.php';
}
}
}
function addPostParam(sParams, sParamName, sParamValue) {
if(sParams.length > 0) {
sParams += "&";
}
return sParams + encodeURIComponent(sParamName) + "=" + encodeURIComponent(sParamValue);
}
function validate() {
displayXML = document.getElementById('displayXML');
username = document.getElementById('username');
password = document.getElementById('password');
displayXML.innerHTML = "<img src=\"./images/loading.gif\" align=\"absmiddle\" />Validating...";
if(username.value == "" || password.value == "") {
displayXML.innerHTML = "The username and password fields must not be left blank.";
return false;
}
else {
loadXMLDoc("authenticate.php","login");
if(displayXML.innerHTML == "Login successful") {
return true;
}
else {
return false;
}
}
}
function showHostelCAOption(hostel) {
Hostel = hostel;
List = document.getElementById('hostelList');
L = List.childNodes;
for(i = 0; i < L.length; i++)
for(j=0; j < L[i].childNodes.length; j++)
{
if(L[i].childNodes[j].nodeName == 'DIV') { del = L[i].childNodes[j];
L[i].removeChild(del);}
}
for(i = 0; i < L.length; i++)
if(L[i].childNodes[0].firstChild.nodeValue == hostel)
{
newContainer = L[i];
newDiv = document.createElement('div');
newContainer.appendChild(newDiv);
displaySearch(newDiv);
}
}
function displaySearch(div) {
newElement = document.createTextNode('Enter a room number:');
div.appendChild(newElement);
newElement = document.createElement('input');
newElement.setAttribute('id','searchRoomString');
newElement.setAttribute('type','text');
div.appendChild(newElement);
newElement.focus();
newElement = document.createElement('span');
newElement.setAttribute('id','err_msg');
div.appendChild(newElement);
newElement = document.createElement('input');
newElement.setAttribute('type','button');
newElement.setAttribute('value','Check Availability');
newElement.setAttribute('onClick','checkavailability();');
div.appendChild(newElement);
newElement = document.createElement('div');
newElement.setAttribute('id','displayXML');
div.appendChild(newElement);
displayXML = newElement;
}
function checkavailability() {
room = document.getElementById('searchRoomString');
errDet = room.parentNode.childNodes[2];
if(room.value == '') {
errDet.innerHTML = "Field cannot be left blank";
displayXML.innerHTML = "";
room.focus();
}
else {
errDet.innerHTML = "";
loadXMLDoc("ca.php?hostel=" + Hostel + "&room=" + room.value);
}
}