2020-11-19 22:44:19 +01:00
|
|
|
<?php
|
|
|
|
require_once ('dbutils.php');
|
2020-11-19 22:47:44 +01:00
|
|
|
require_once ('utilities/Emailer.php');
|
2020-11-19 22:44:19 +01:00
|
|
|
|
|
|
|
class Feedback {
|
|
|
|
var $dbutils;
|
|
|
|
function __construct() {
|
|
|
|
$this->dbutils = new DbUtils();
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleCommand($command) {
|
|
|
|
if ($command == 'sendMail') {
|
|
|
|
$this->sendMail($_POST['role'],$_POST['topic'],$_POST['email'],$_POST['tel'],$_POST['allowSendRights'],$_POST['content']);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo "Kommando nicht unterstuetzt.";
|
2020-11-19 23:10:26 +01:00
|
|
|
}
|
2020-11-19 22:44:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function isUserAlreadyLoggedInForPhp() {
|
2020-11-19 23:10:26 +01:00
|
|
|
if(session_id() == '') {
|
|
|
|
session_start();
|
|
|
|
}
|
2020-11-19 22:44:19 +01:00
|
|
|
if (!isset($_SESSION['angemeldet']) || !$_SESSION['angemeldet']) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-11-19 22:47:44 +01:00
|
|
|
|
2020-11-19 23:10:26 +01:00
|
|
|
private function getGeneralItemFromDb($field) {
|
|
|
|
$pdo = $this->dbutils->openDbAndReturnPdo();
|
|
|
|
|
|
|
|
$aValue="";
|
|
|
|
$sql = "SELECT setting FROM %config% where name='$field'";
|
|
|
|
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
|
|
|
|
$stmt->execute();
|
|
|
|
$row =$stmt->fetchObject();
|
|
|
|
if ($row != null) {
|
|
|
|
$aValue = $row->setting;
|
|
|
|
}
|
|
|
|
return $aValue;
|
2020-11-19 22:44:19 +01:00
|
|
|
}
|
|
|
|
|
2020-11-19 23:10:26 +01:00
|
|
|
function spamcheck($field) {
|
|
|
|
// Sanitize e-mail address
|
|
|
|
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
|
|
|
|
// Validate e-mail address
|
|
|
|
if(filter_var($field, FILTER_VALIDATE_EMAIL)) {
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-11-19 22:44:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function sqlresult($pdo,$sql,$sqlval) {
|
2020-11-19 23:10:26 +01:00
|
|
|
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
|
|
|
|
$stmt->execute();
|
|
|
|
$row =$stmt->fetchObject();
|
|
|
|
if ($row != null) {
|
|
|
|
return($row->$sqlval);
|
2020-11-19 22:44:19 +01:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function getdbinfo() {
|
|
|
|
$pdo = $this->dbutils->openDbAndReturnPdo();
|
|
|
|
|
|
|
|
$info = "\n\nWaiting print jobs:\n";
|
|
|
|
// workprintjobswaiting
|
|
|
|
$foodjobs = $this->sqlresult($pdo,"select count(id) as number from %printjobs% where type=1","number");
|
|
|
|
$drinkjobs = $this->sqlresult($pdo,"select count(id) as number from %printjobs% where type=2","number");
|
|
|
|
$payjobs = $this->sqlresult($pdo,"select count(id) as number from %printjobs% where type=3","number");
|
|
|
|
|
2020-11-19 23:10:26 +01:00
|
|
|
$info .= "Fs: $foodjobs\n";
|
|
|
|
$info .= "Ds: $drinkjobs\n";
|
|
|
|
$info .= "Rs: $payjobs\n\n";
|
2020-11-19 22:44:19 +01:00
|
|
|
|
|
|
|
// db sizes
|
|
|
|
$info .= $this->getDatabaseSizes($pdo);
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDatabaseSizes($pdo) {
|
|
|
|
$sql = 'SELECT table_schema "Data Base Name",
|
|
|
|
sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",
|
|
|
|
sum( data_free )/ 1024 / 1024 "Free Space in MB"
|
|
|
|
FROM information_schema.TABLES
|
|
|
|
GROUP BY table_schema';
|
|
|
|
$pdo = $this->dbutils->openDbAndReturnPdo();
|
2020-11-19 23:10:26 +01:00
|
|
|
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
|
|
|
|
$stmt->execute();
|
|
|
|
$result = $stmt->fetchAll();
|
|
|
|
$dbInfo = "DB-info:\n";
|
|
|
|
|
2020-11-19 22:44:19 +01:00
|
|
|
foreach($result as $row) {
|
2020-11-19 23:10:26 +01:00
|
|
|
$dbInfo .= "DB '$row[0]', db (MB): $row[1], free (MB): $row[2]\n";
|
2020-11-19 22:44:19 +01:00
|
|
|
}
|
|
|
|
return $dbInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendMail($role,$topic,$email,$tel,$allowSendRights,$content) {
|
2020-11-19 22:47:44 +01:00
|
|
|
|
2020-11-19 22:44:19 +01:00
|
|
|
$rights = "Keine Rechteinformation";
|
2020-11-19 22:47:44 +01:00
|
|
|
$version = $this->getGeneralItemFromDb('version');
|
2020-11-19 22:44:19 +01:00
|
|
|
|
2020-11-19 23:10:26 +01:00
|
|
|
if ($this->isUserAlreadyLoggedInForPhp()) {
|
|
|
|
if ($allowSendRights) {
|
|
|
|
$rights = "UID=" . $_SESSION['userid'] . "\n";
|
|
|
|
$rights .= "UN=" . $_SESSION['currentuser'] . "\n";
|
|
|
|
$rights .= " RA=" . ($_SESSION['is_admin'] ? "1" : "0") . "\n";
|
|
|
|
$rights .= " RW=" . ($_SESSION['right_waiter'] ? "1" : "0") . "\n";
|
|
|
|
$rights .= " RPay=" . ($_SESSION['right_paydesk'] ? "1" : "0") . "\n";
|
|
|
|
$rights .= " RB=" . ($_SESSION['right_bill'] ? "1" : "0") . "\n";
|
|
|
|
$rights .= " RProd = " . ($_SESSION['right_products'] ? "1" : "0") . "\n";
|
|
|
|
$rights .= " RM=" . ($_SESSION['right_manager'] ? "1" : "0");
|
|
|
|
$rights .= $this->getdbinfo();
|
2020-11-19 22:44:19 +01:00
|
|
|
}
|
2020-11-19 23:10:26 +01:00
|
|
|
$server = $_SERVER['HTTP_USER_AGENT'];
|
|
|
|
$msg = "Rolle:$role\nEmail:$email\nTel.:$tel\nRechte:$rights\nServer:$server\n\nVersion:$version\n\nNachricht:\n$content";
|
|
|
|
|
|
|
|
$pdo = DbUtils::openDbAndReturnPdoStatic();
|
|
|
|
$version = CommonUtils::getConfigValue($pdo, 'version', 'no-version');
|
|
|
|
$ok = $this->sendFeedbackToServer($topic, $msg, $version);
|
|
|
|
|
|
|
|
echo json_encode($ok);
|
2020-11-19 22:44:19 +01:00
|
|
|
} else {
|
2020-11-19 23:10:26 +01:00
|
|
|
echo json_encode(array("status" => "ERROR","msg" => "Fehler: Benutzer nicht eingeloggt!"));
|
2020-11-19 22:44:19 +01:00
|
|
|
}
|
2020-11-19 23:10:26 +01:00
|
|
|
|
2020-11-19 22:44:19 +01:00
|
|
|
}
|
2020-11-19 23:10:26 +01:00
|
|
|
|
|
|
|
function sendFeedbackToServer($topic, $msg, $version) {
|
|
|
|
$cmd = '';
|
|
|
|
$fct = 'Feedback-Form';
|
|
|
|
$xhr = $msg;
|
|
|
|
$errormsg = $topic;
|
|
|
|
$status = '';
|
|
|
|
$phpversion = phpversion();
|
|
|
|
|
|
|
|
$arr = array("cmd" => $cmd, "fct" => $fct, "xhr" => $xhr, "errormsg" => $errormsg, "status" => $status, "version" => $version, "phpversion" => $phpversion);
|
|
|
|
|
|
|
|
$url = "http://www.ordersprinter.de/debug/save.php?cmd=save";
|
|
|
|
|
|
|
|
$ch = curl_init();
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL,$url);
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
|
|
|
$query = http_build_query($arr);
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
|
|
|
$server_output = curl_exec ($ch);
|
|
|
|
|
|
|
|
if($server_output === false)
|
|
|
|
{
|
|
|
|
$msg = 'Curl-Fehler: ' . curl_error($ch);
|
|
|
|
curl_close ($ch);
|
|
|
|
return array("status" => "ERROR","msg" => $msg);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
curl_close ($ch);
|
|
|
|
return array("status" => "OK");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|