-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessQuizEntry.php
More file actions
65 lines (44 loc) · 2.11 KB
/
processQuizEntry.php
File metadata and controls
65 lines (44 loc) · 2.11 KB
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
<?php header('Access-Control-Allow-Origin: *');
function InsertQuestion($quizname, $body, $canswer, $type,$tolerance,$imagename,$panswerid,$modelanswer) {
$connectionString = "host=ec2-54-225-101-64.compute-1.amazonaws.com port=5432 dbname=d1nigmib60rp1v user=jykiewmddlbjft password=kRqkD183znoOpPNTlDq6f_Xs29";
$dbconnection = pg_connect($connectionString);
//Insert Question values into DB
if($panswerid == -1){
$result = pg_query($dbconnection,"INSERT INTO question (body,canswer,type,tolerance,quizname,imagename,panswerid,modelanswer) VALUES ('$body', '$canswer', '$type', '$tolerance','$quizname','$imagename',NULL,'$modelanswer');");
}else{
$result = pg_query($dbconnection,"INSERT INTO question (body,canswer,type,tolerance,quizname,imagename,panswerid,modelanswer) VALUES ('$body', '$canswer', '$type', '$tolerance', '$quizname', '$imagename','$panswerid','$modelanswer');");
}
if (!$result) {
return"fail";
}else{
return"success";
}
}
function InsertQuiz($name, $coursecode) {
$connectionString = "host=ec2-54-225-101-64.compute-1.amazonaws.com port=5432 dbname=d1nigmib60rp1v user=jykiewmddlbjft password=kRqkD183znoOpPNTlDq6f_Xs29";
$dbconnection = pg_connect($connectionString);
//insert course into db
$result = pg_query($dbconnection,"INSERT INTO course VALUES ('$coursecode','made up quizname');");
//give elf rights
$result = pg_query($dbconnection,"INSERT INTO coursestaken VALUES ('$coursecode',3);");
//clear all questions
$result = pg_query($dbconnection,"DELETE FROM question WHERE quizname='$name';");
//re add them all
$result = pg_query($dbconnection,"INSERT INTO quiz (name, coursecode) VALUES ('$name', '$coursecode');");
if (!$result) {
return"fail";
}else{
return"success";
}
}
if (isset ( $_POST ['funcName'] )) {
switch ($_POST ['funcName']) {
case 'InsertQuestion' :
echo (InsertQuestion ( $_POST ['quizname'], $_POST ['body'],$_POST ['canswer'],$_POST ['type'],$_POST ['tolerance'],$_POST ['imagename'],$_POST['panswerid'],$_POST['modelanswer']));
break;
case 'InsertQuiz' :
echo (InsertQuiz ( $_POST ['quizname'], $_POST ['coursecode']));
break;
}
}
?>