169 lines
4.9 KiB
PHP
169 lines
4.9 KiB
PHP
<?php
|
|
require_once ('dbutils.php');
|
|
require_once ('utilities/Emailer.php');
|
|
|
|
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.";
|
|
}
|
|
}
|
|
|
|
function isUserAlreadyLoggedInForPhp() {
|
|
if(session_id() == '') {
|
|
session_start();
|
|
}
|
|
if (!isset($_SESSION['angemeldet']) || !$_SESSION['angemeldet']) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
function sqlresult($pdo,$sql,$sqlval) {
|
|
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute();
|
|
$row =$stmt->fetchObject();
|
|
if ($row != null) {
|
|
return($row->$sqlval);
|
|
} 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");
|
|
|
|
$info .= "Fs: $foodjobs\n";
|
|
$info .= "Ds: $drinkjobs\n";
|
|
$info .= "Rs: $payjobs\n\n";
|
|
|
|
// 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();
|
|
$stmt = $pdo->prepare($this->dbutils->resolveTablenamesInSqlString($sql));
|
|
$stmt->execute();
|
|
$result = $stmt->fetchAll();
|
|
$dbInfo = "DB-info:\n";
|
|
|
|
foreach($result as $row) {
|
|
$dbInfo .= "DB '$row[0]', db (MB): $row[1], free (MB): $row[2]\n";
|
|
}
|
|
return $dbInfo;
|
|
}
|
|
|
|
function sendMail($role,$topic,$email,$tel,$allowSendRights,$content) {
|
|
|
|
$rights = "Keine Rechteinformation";
|
|
$version = $this->getGeneralItemFromDb('version');
|
|
|
|
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();
|
|
}
|
|
$server = $_SERVER['HTTP_USER_AGENT'];
|
|
$msg = "\nEmail:$email\nTel.:$tel\nNachricht:$content\nRolle:$role\nRechte:$rights\nServer:$server\n\nVersion:$version\n";
|
|
|
|
$pdo = DbUtils::openDbAndReturnPdoStatic();
|
|
$version = CommonUtils::getConfigValue($pdo, 'version', 'no-version');
|
|
$ok = $this->sendFeedbackToServer($topic, $msg, $version);
|
|
|
|
echo json_encode($ok);
|
|
} else {
|
|
echo json_encode(array("status" => "ERROR","msg" => "Fehler: Benutzer nicht eingeloggt!"));
|
|
}
|
|
|
|
}
|
|
|
|
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");
|
|
}
|
|
}
|
|
|
|
} |