You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
1.9 KiB
PHTML
84 lines
1.9 KiB
PHTML
4 years ago
|
<?php
|
||
|
class database
|
||
|
{
|
||
|
private $db;
|
||
|
|
||
|
function __construct($file){
|
||
|
try {
|
||
|
$this->db = new PDO('sqlite:'.$file);
|
||
|
} catch(PDOException $e) {
|
||
|
error_log($e->getMessage(), 3, 'php://stderr');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function query($sql,$attr){
|
||
|
$stmt = $this->db->prepare($sql);
|
||
|
try {
|
||
|
$stmt->execute($attr);
|
||
|
} catch (PDOException $e) {
|
||
|
echo $e->getMessage();
|
||
|
}
|
||
|
return $stmt;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function createquery($form){
|
||
|
$date = date("Y-m-d H:i:s");
|
||
|
|
||
|
switch($form){
|
||
|
case "skola":
|
||
|
$query = "
|
||
|
insert into skola
|
||
|
(id,datum,instituce,kraj,adresa,jmeno,email,telefon,pocet_skupin,pocet_deti,vek_deti,pece,poznamka)
|
||
|
values (?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||
|
";
|
||
|
$values = [
|
||
|
NULL,
|
||
|
$date,
|
||
|
$_REQUEST["instituce"],
|
||
|
$_REQUEST["kraj"],
|
||
|
$_REQUEST["adresa"],
|
||
|
$_REQUEST["jmeno"],
|
||
|
$_REQUEST["email"],
|
||
|
(empty($_REQUEST["telefon"]) ? "" : $_REQUEST["telefon"]),
|
||
|
$_REQUEST["pocet_skupin"],
|
||
|
$_REQUEST["pocet_deti"],
|
||
|
$_REQUEST["vek_deti"],
|
||
|
$_REQUEST["pece"],
|
||
|
(empty($_REQUEST["poznamka"]) ? "" : $_REQUEST["poznamka"])
|
||
|
];
|
||
|
break;
|
||
|
case "dobrovolnik":
|
||
|
$query = "
|
||
|
insert into dobrovolnik
|
||
|
(id,datum,jmeno,email,telefon,studijni_program,obor,kraj,cas,vek_deti,distancni_vyuka,uznani_praxe,poznamka)
|
||
|
values (?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||
|
";
|
||
|
$values = [
|
||
|
NULL,
|
||
|
$date,
|
||
|
$_REQUEST["jmeno"],
|
||
|
$_REQUEST["email"],
|
||
|
(empty($_REQUEST["telefon"]) ? "" : $_REQUEST["telefon"]),
|
||
|
$_REQUEST["studijni_program"],
|
||
|
$_REQUEST["obor"],
|
||
|
$_REQUEST["kraj"],
|
||
|
$_REQUEST["cas"],
|
||
|
$_REQUEST["vek_deti"],
|
||
|
$_REQUEST["distancni_vyuka"],
|
||
|
$_REQUEST["uznani_praxe"],
|
||
|
(empty($_REQUEST["poznamka"]) ? "" : $_REQUEST["poznamka"])
|
||
|
];
|
||
|
break;
|
||
|
}
|
||
|
return [$query,$values];
|
||
|
}
|
||
|
|
||
|
$db = new database("./db/database.db");
|
||
|
|
||
|
$query = createquery($_REQUEST["form"]);
|
||
|
$db->query("$query[0]",$query[1]);
|
||
|
|
||
|
$refer = (!empty($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "/");
|
||
|
header("Location: ".$refer);
|