/
install.php
426 lines (360 loc) · 10.8 KB
/
install.php
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<html>
<head><title>Admin Control Panel</title>
<style type="text/css">
<!--
A:link {text-decoration: none;}
A:visited {text-decoration: none;}
-->
</style>
</head>
<body link="#FF0000" vlink="#FF0000" alink="#FF0000">
<center>
<table border="3" cellpadding="2" cellspacing="6" width=600 bgcolor="#FFFFFF">
<tr>
<td bgcolor="#004080" align="left"><font
color="#FFFFFF" size="2" face="Verdana"><strong>Installation</strong></font>
</td>
</tr>
<tr>
<td align="center"><table border="0" width=550>
<tr>
<td valign="top" width=50%><br>
<font size="2" face="Verdana">
<!-- #### HTML #### -->
<?php
$admin_password = $_POST['admin_password'];
$host = $_POST['host'];
$database = $_POST['database'];
$login = $_POST['login'];
$password = $_POST['password'];
$email_required = $_POST['email_required'];
$create_database = $_POST['create_database'];
#- first check for config.php status
print "<font color=red>";
/*
if(!is_writable("config.php")){
print "Please set \"config.php\" file as writablable(chmod 766), to begin installation!";
exit;
}
require "config.php"; */
if($host != "" && $login != ""){
$dbh = @$db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base);_connect($host, $login, $password)
or $dberr=1;
if($dberr){
print("Cannot connect to database with the information provided. Please check your host/login/password entries.");
}else{
@$db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base);_select_db($database) or $dberr=1;
if($dberr){
if($create_database && $database != ""){
print "<font color=navy><b>Creating $database:";
if ($db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base);_create_db($database)) {
print ("Database created successfully\n");
$dberr = 0;
} else {
printf ("<font color=red>Error creating database: %s\n</font>", $db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base);_error ());
}
print "</b></font>";
}else{
print("Cannot connect to the database. Please check your \"$db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base); database name\" entry!");
}
} else {
print("The database allready exists. Please select a new \"$db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base); database name\" !");
$dberr = 1;
}
}
if($result = @mysqli_query($db_connect,"SELECT NOW()") && !$dberr,$db_connect){
$connected = 1;
}
}
print "</font>";
#- ask for $db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base); installation
?>
<?
print "<p>$db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base); status: ";
if($connected){
print "<b><font color=green>connected</font></b>";
if($admin_password != ""){
// write_config();
if(create_tables() == -1){
print "<p>Cannot create tables!";
}else{
print "<p><b>INSTALLATION COMPLETE!</b>";
$done = 1;
}
}
}else{
print "<b><font color=blue>not connected</font></b>";
}
if(!$done){
?>
<p>
<form action=install.php method=post>
<table border=0>
<tr><td>
<font size="2" face="Verdana">
$db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base); hostname:
</td><td>
<input type=text size=20 name=host value="<? if($host != "") print $host; else print "localhost" ?>">
</td></tr>
<tr><td>
<font size="2" face="Verdana">
$db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base); database name:
</td><td>
<input type=text size=20 name=database value="<? if($database != "") print $database; ?>">
</td><td>
<font size="2" face="Verdana">
<input type=checkbox name=create_database>Create new!
</td></tr>
<tr><td>
<font size="2" face="Verdana">
$db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base); login:
</td><td>
<input type=text size=20 name=login value="<? if($login != "") print $login; ?>">
</td></tr>
<tr><td>
<font size="2" face="Verdana">
$db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base); password:
</td><td>
<input type=password size=20 name=password value="<? if($password != "") print $password; ?>">
</td></tr>
<tr><td>
<font size="2" face="Verdana">
Admin password:
</td><td>
<input type=password size=20 name=admin_password value="<? if($admin_password != "") print $admin_password; ?>">
</td></tr>
</table>
<p>
<input type=submit name=submit value="Install!">
</form>
<?
}
function write_config()
{
/* global $admin_password, $host, $database, $login, $password, $email_required;
$out = "<";
$out .= "?php
\$admin_pass = \"$admin_password\";
\$db_host = \"$host\";
\$db_name = \"$database\";
\$db_user = \"$login\";
\$db_password = \"$password\";
\$tempz[form] = \"templates/quiz_form_template.html\";
";
if($email_required == "no")
$out .= " \$email_not_required = 1; ";
else
$out .= " \$email_not_required = 0; ";
$out .= "
\n?";
$out .= ">";
$fp = fopen("config.php","w");
fwrite($fp, $out);
fclose($fp); */
}
function create_tables()
{
global $database;
global $dbh;
$baseconnect = $db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base);
$query = "
CREATE TABLE question(
questionid int(11) NOT NULL auto_increment,
question text,
choice1 mediumtext,
choice2 mediumtext,
choice3 mediumtext,
choice4 mediumtext,
choice5 mediumtext,
choice6 mediumtext,
answer text,
date date,
feedback mediumtext,
category varchar(50) default \'None\',
reference varchar(50),
examid int(11) NOT NULL,
type mediumtext,
used tinyint(2) NOT NULL DEFAULT 1,
weight tinyint(4) NOT NULL DEFAULT 1,
PRIMARY KEY (questionid)
)
";
$dbc = mysqli_query($db_connect,$query);
$query = "
CREATE TABLE exam (
examid int(11) NOT NULL auto_increment,
title mediumtext NOT NULL,
id varchar(50) DEFAULT '0' NOT NULL,
version varchar(50) DEFAULT '0' NOT NULL,
instructions text,
date date,
questions tinyint(3) DEFAULT '0' NOT NULL,
startDate date DEFAULT '0' NOT NULL,
endDate date DEFAULT '0' NOT NULL,
time tinyint(4) DEFAULT '0' NOT NULL,
passingScore tinyint(3) DEFAULT '0' NOT NULL,
active varchar(5) DEFAULT 'No',
groupid int(11) NOT NULL default '0',
PRIMARY KEY (examid)
)
";
$dbc = mysqli_query($db_connect,$query);
$query = "
CREATE TABLE candidate (
candidateID int(11) DEFAULT '0' NOT NULL auto_increment,
userName varchar(20),
userPassword varchar(20),
firstName tinytext,
lastName tinytext,
email varchar(50),
address tinytext,
city tinytext,
state tinytext,
postCode varchar(20),
country tinytext,
homePhone varchar(30),
workPhone varchar(30),
mobilePhone varchar(30),
fax varchar(30),
company tinytext,
title tinytext,
date date,
admin tinyint(4) DEFAULT '0' NOT NULL,
editGroup tinyint(4) DEFAULT '0' NOT NULL,
editExam tinyint(4) DEFAULT '0' NOT NULL,
PRIMARY KEY (candidateID)
)
";
$dbc = mysqli_query($db_connect,$query);
$query = "
CREATE TABLE scores (
scoreid int(11) DEFAULT '0' NOT NULL auto_increment,
candidateID int(11) NOT NULL,
examid int(11) NOT NULL,
marks int(5) DEFAULT '0' NOT NULL,
date date,
time time,
timetaken time,
maxMarks int(11) default 0,
PRIMARY KEY (scoreid)
)
";
$dbc = mysqli_query($db_connect,$query);
$query = "
CREATE TABLE test (
scoreid int(11) NOT NULL,
questionid int(11) NOT NULL,
marks int(3) DEFAULT '0',
answer text,
markQuestion varchar(5),
PRIMARY KEY (scoreid,questionid)
)
";
$dbc = mysqli_query($db_connect,$query);
$query = "
CREATE TABLE temp (
sno int(11) DEFAULT '0' NOT NULL auto_increment,
scoreid int(11) NOT NULL,
questionid int(11) NOT NULL,
answer text,
markQuestion varchar(5),
marks int(2) default 0,
PRIMARY KEY (sno)
)
";
$dbc = mysqli_query($db_connect,$query);
$query = "
CREATE TABLE groups (
groupid int(11) DEFAULT '0' NOT NULL auto_increment,
groupName varchar(50) default 'visitor' NOT NULL,
PRIMARY KEY (groupid)
)
";
$dbc = mysqli_query($db_connect,$query);
$query = "
CREATE TABLE groupPermissions (
groupPermissionid int(11) NOT NULL auto_increment,
candidateID int(11) NOT NULL default '0',
groupid int(11) NOT NULL default '0',
PRIMARY KEY (groupPermissionid)
)
";
$dbc = mysqli_query($db_connect,$query);
$query = "
CREATE TABLE examPermissions (
examPermissionid int(11) NOT NULL auto_increment,
candidateID int(11) NOT NULL default '0',
examid int(11) NOT NULL default '0',
PRIMARY KEY (examPermissionid)
)
";
$dbc = mysqli_query($db_connect,$query);
$query = "
CREATE TABLE candidateGroup (
candidateGroupid int(11) NOT NULL auto_increment,
candidateID int(11) NOT NULL default '0',
groupid int(11) NOT NULL default '0',
PRIMARY KEY (candidateGroupid)
)
";
$dbc = mysqli_query($db_connect,$query);
$query = "
CREATE TABLE images (
imageid int(11) NOT NULL auto_increment,
questionid int(11) NOT NULL default '0',
description varchar(255) NOT NULL default '',
filename varchar(255) NOT NULL default '',
filesize int(11) NOT NULL default '0',
width smallint(6) NOT NULL default '0',
height smallint(6) NOT NULL default '0',
filetype varchar(15) NOT NULL default '',
data blob NOT NULL,
PRIMARY KEY (imageid)
)
";
$dbc = mysqli_query($db_connect,$query);
$query = "
CREATE TABLE imageshow (
imageid int(11) NOT NULL auto_increment,
description varchar(255) NOT NULL default '',
filename varchar(255) NOT NULL default '',
filesize int(11) NOT NULL default '0',
width smallint(6) NOT NULL default '0',
height smallint(6) NOT NULL default '0',
filetype varchar(15) NOT NULL default '',
data blob NOT NULL,
PRIMARY KEY (imageid)
)
";
$dbc = mysqli_query($db_connect,$query);
$query = "
CREATE TABLE dragdrop (
scoreid int(11) NOT NULL,
questionid int(11) NOT NULL,
choice1 mediumtext,
choice2 mediumtext,
choice3 mediumtext,
choice4 mediumtext,
choice5 mediumtext,
choice6 mediumtext,
PRIMARY KEY (scoreid,questionid)
)
";
$dbc = mysqli_query($db_connect,$query);
$result = $db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base);_list_tables($database);
if( $db_connect = mysqli_connect($datahost, $datauser, $datapasswd, $base);_num_rows($result) != 12 ){
return -1;
}
return 1;
}
?>
<p><br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</body>
</html>