Dump from SVN
This commit is contained in:
17
engine/database.sql
Normal file
17
engine/database.sql
Normal file
@ -0,0 +1,17 @@
|
||||
CREATE TABLE `tests`(
|
||||
`id` int(4) UNSIGNED NOT NULL auto_increment,
|
||||
`name` varchar(65) NOT NULL default '',
|
||||
`description` text NOT NULL default '',
|
||||
`quiz` text NOT NULL default '',
|
||||
`tag` varchar(65) NOT NULL default '',
|
||||
`allowed` tinyint(1) UNSIGNED NOT NULL default 0,
|
||||
PRIMARY KEY (`id`)
|
||||
) CHARACTER SET utf8 COLLATE utf8_general_ci;
|
||||
|
||||
CREATE TABLE `results`(
|
||||
`id` int(4) UNSIGNED NOT NULL auto_increment,
|
||||
`submitter` varchar(65) NOT NULL default '',
|
||||
`time` timestamp NOT NULL default current_timestamp,
|
||||
`answered` text NOT NULL default '',
|
||||
PRIMARY KEY (`id`)
|
||||
) CHARACTER SET utf8 COLLATE utf8_general_ci;
|
100
engine/engine.php
Normal file
100
engine/engine.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* /engine/engine.php
|
||||
* @version 1.2
|
||||
* @desc PHP server side engine to serve commonly accessable tests, collect submitted results
|
||||
* @author Fándly Gergő Zoltán (gergo@systemtest.tk, systemtest.tk)
|
||||
* @copy 2017 Fándly Gergő Zoltán
|
||||
* License:
|
||||
sQuiz for creating small jQuery based quizs in an implementable way
|
||||
Copyright (C) 2017 Fándly Gergő Zoltán
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
//config
|
||||
$sql_user="squiz";
|
||||
$sql_passwd="squizuserforgood";
|
||||
$sql_db="squiz";
|
||||
$quiz_tag=0;
|
||||
|
||||
$db=new PDO("mysql:host=localhost;dbname=".$sql_db.";charset=utf8", $sql_user, $sql_passwd);
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
if(isset($_GET['list'])){
|
||||
if($quiz_tag!=0){
|
||||
$sql=$db->prepare("SELECT id, name, description FROM tests WHERE allowed=1 and tag=:tag");
|
||||
$sql->execute(array(":tag"=>$quiz_tag));
|
||||
}
|
||||
else{
|
||||
$sql=$db->prepare("SELECT id, name, description FROM tests WHERE allowed=1");
|
||||
$sql->execute();
|
||||
}
|
||||
|
||||
$obj=array();
|
||||
while($row=$sql->fetch(PDO::FETCH_ASSOC)){
|
||||
array_push($obj, array("name"=>$row['name'], "description"=>$row['description'], "file"=>"//".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."?getQuiz=".$row['id']));
|
||||
}
|
||||
|
||||
header("Content-type: text/json; charset=UTF-8");
|
||||
echo json_encode($obj);
|
||||
die();
|
||||
}
|
||||
|
||||
if(isset($_GET['getQuiz'])){
|
||||
$sql=$db->prepare("SELECT quiz FROM tests WHERE id=:id");
|
||||
$sql->execute(array(":id"=>$_GET['getQuiz']));
|
||||
$res=$sql->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
header("Content-type: text/json; charset=UTF-8");
|
||||
echo $res['quiz'];
|
||||
die();
|
||||
}
|
||||
|
||||
if(isset($_POST['submitResult']) && isset($_POST['submitResult_submitter'])){
|
||||
$sql=$db->prepare("INSERT INTO results (submitter, answered) VALUES (:submitter, :answered)");
|
||||
$sql->execute(array(":submitter"=>$_POST['submitResult_submitter'], ":answered"=>$_POST['submitResult']));
|
||||
$id=$db->lastInsertId();
|
||||
|
||||
echo $id;
|
||||
die();
|
||||
}
|
||||
|
||||
if(isset($_GET['getResult'])){
|
||||
$sql=$db->prepare("SELECT COUNT(id) AS count, submitter, time, answered FROM results WHERE id=:id");
|
||||
$sql->execute(array(":id"=>$_GET['getResult']));
|
||||
$res=$sql->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if($res['count']<1){
|
||||
echo "not found";
|
||||
}
|
||||
else{
|
||||
$obj=array("submitter"=>$res['submitter'], "time"=>$res['time'], "answered"=>$res['answered']);
|
||||
|
||||
header("Content-type: text/json; charset=UTF-8");
|
||||
echo json_encode($obj);
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_POST['submitQuiz']) && isset($_POST['submitQuiz_tag']) && isset($_POST['submitQuiz_name']) && isset($_POST['submitQuiz_description'])){
|
||||
$sql=$db->prepare("INSERT INTO tests (name, description, quiz, tag) VALUES (:name, :desc, :quiz, :tag)");
|
||||
$sql->execute(array(":name"=>$_POST['submitQuiz_name'], ":desc"=>$_POST['submitQuiz_description'], ":quiz"=>$_POST['submitQuiz'], ":tag"=>$_POST['submitQuiz_tag']));
|
||||
$id=$db->lastInsertId();
|
||||
|
||||
$link="https://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."?getQuiz=".$id;
|
||||
|
||||
echo $link;
|
||||
die();
|
||||
}
|
Reference in New Issue
Block a user