c3lf-system-3/ajax.php

78 lines
3 KiB
PHP
Raw Normal View History

2018-12-28 19:05:34 +00:00
<?php
/**
* Created by PhpStorm.
* User: jedi
* Date: 12/28/18
* Time: 6:13 PM
2018-12-29 19:17:54 +00:00
*/
include "backend.php";
function hasval($var){
return isset($var) && !empty($var);
}
switch($_GET["action"]) {
case "add_featurerequest":
if (hasval($_POST["title"]) && hasval($_POST["desc"])) {
/* Prepared statement, stage 1: prepare */
2018-12-30 11:50:42 +00:00
if (!($stmt = $mysqli->prepare("INSERT INTO feature_request(title, `desc`) VALUES (?, ?)"))) {
$errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}else
if (!$stmt->bind_param("ss", $_POST["title"], $_POST["desc"])) {
$errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}else
if (!$stmt->execute()) {
$errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
}else{
$errormsg = "all values have to be set";
}
break;
case "insert":
if (hasval($_POST["was"]) && hasval($_POST["wann"]) && hasval($_POST["wo"])) {
/* Prepared statement, stage 1: prepare */
if (!($stmt = $mysqli->prepare("INSERT INTO items(was, wann, wo) VALUES (?, ?, ?)"))) {
$errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
2018-12-29 19:17:54 +00:00
}
if (!$stmt->bind_param("sss", $_POST["was"], $_POST["wann"], $_POST["wo"])) {
2018-12-30 11:50:42 +00:00
$errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
2018-12-29 19:17:54 +00:00
}
if (!$stmt->execute()) {
2018-12-30 11:50:42 +00:00
$errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
2018-12-29 19:17:54 +00:00
}
2018-12-30 11:50:42 +00:00
}else{
$errormsg = "all values have to be set";
2018-12-29 19:17:54 +00:00
}
2018-12-30 11:50:42 +00:00
break;
case "add_lost":
if (hasval($_POST["was"]) && hasval($_POST["wann"]) && hasval($_POST["wo"]) && hasval($_POST["contact"])) {
/* Prepared statement, stage 1: prepare */
if (!($stmt = $mysqli->prepare("INSERT INTO lost(was, wann, wo, contact) VALUES (?, ?, ?, ?)"))) {
$errormsg = "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!$stmt->bind_param("ssss", $_POST["was"], $_POST["wann"], $_POST["wo"], $_POST["contact"])) {
$errormsg = "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->execute()) {
$errormsg = "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
}else{
$errormsg = "all values have to be set";
}
break;
case "get_stats";
echo json_encode(array("status"=>"ok","stats"=>get_stats()));
break;
default:
$errormsg = "action unknown";
2018-12-29 19:17:54 +00:00
break;
}
2018-12-30 11:50:42 +00:00
if(empty($errormsg))
echo json_encode(array("get"=>$_GET,"post"=>$_POST,"status"=>"ok","message"=>"added one item"));
else
echo json_encode(array("get"=>$_GET,"post"=>$_POST,"status"=>"error","message"=>$errormsg));
2018-12-29 19:17:54 +00:00
?>