<?php
require_once './config.php';
$mode = $_REQUEST["mode"];
if ($mode == "add_new" ) {
$firmenname = trim($_POST['firmenname']);
$str_nr= trim($_POST['str_nr']);
$plz = trim($_POST['plz']);
$ort = trim($_POST['ort']);
$datum = trim($_POST['datum']);
$telefon = trim($_POST['telefon']);
$ansprechpartner = trim($_POST['ansprechpartner']);
$str_nr2 = trim($_POST['str_nr2']);
$plz2 = trim($_POST['plz2']);
$ort2 = trim($_POST['ort2']);
$ansprechpartner2 = trim($_POST['ansprechpartner2']);
$y1 = trim($_POST['y1']);
$y2 = trim($_POST['y2']);
$y3 = trim($_POST['y3']);
$y4 = trim($_POST['y4']);
$y5 = trim($_POST['y5']);
$y6 = trim($_POST['y6']);
$y7 = trim($_POST['y7']);
$y8 = trim($_POST['y8']);
$y9 = trim($_POST['y9']);
$y10 = trim($_POST['y10']);
$y11 = trim($_POST['y11']);
$y12 = trim($_POST['y12']);
$y13 = trim($_POST['y13']);
$y14 = trim($_POST['y14']);
$y15 = trim($_POST['y15']);
$y16 = trim($_POST['y16']);
$y17 = trim($_POST['y17']);
$a = trim($_POST['a']);
$b = trim($_POST['b']);
$c = trim($_POST['c']);
$d = trim($_POST['d']);
$e = trim($_POST['e']);
$f = trim($_POST['f']);
$g = trim($_POST['g']);
$h = trim($_POST['h']);
$i = trim($_POST['i']);
$j = trim($_POST['j']);
$k = trim($_POST['k']);
$l = trim($_POST['l']);
$m = trim($_POST['m']);
$n = trim($_POST['n']);
$o = trim($_POST['o']);
$p = trim($_POST['p']);
$a0 = trim($_POST['a0']);
$b0 = trim($_POST['b0']);
$c0 = trim($_POST['c0']);
$d0 = trim($_POST['d0']);
$e0 = trim($_POST['e0']);
$f0 = trim($_POST['f0']);
$g0 = trim($_POST['g0']);
$h0 = trim($_POST['h0']);
$i0 = trim($_POST['i0']);
$j0 = trim($_POST['j0']);
$k0 = trim($_POST['k0']);
$l0 = trim($_POST['l0']);
$m0 = trim($_POST['m0']);
$n0 = trim($_POST['n0']);
$o0 = trim($_POST['o0']);
$p0 = trim($_POST['p0']);
$a1 = trim($_POST['a1']);
$b1 = trim($_POST['b1']);
$c1 = trim($_POST['c1']);
$d1 = trim($_POST['d1']);
$e1 = trim($_POST['e1']);
$f1 = trim($_POST['f1']);
$g1 = trim($_POST['g1']);
$h1 = trim($_POST['h1']);
$i1 = trim($_POST['i1']);
$j1 = trim($_POST['j1']);
$k1 = trim($_POST['k1']);
$l1 = trim($_POST['l1']);
$m1 = trim($_POST['m1']);
$n1 = trim($_POST['n1']);
$o1 = trim($_POST['o1']);
$p1 = trim($_POST['p1']);
$filename = "";
$error = FALSE;
if (is_uploaded_file($_FILES["x"]["tmp_name"])) {
$filename = time() + (7 * 24 * 60 * 60) . '_' . $_FILES["x"]["name"];
$filepath = 'bilder/' . $filename;
if (!move_uploaded_file($_FILES["x"]["tmp_name"], $filepath)) {
$error = TRUE;
}
}
$filename2 = "";
$error = FALSE;
if (is_uploaded_file($_FILES["x0"]["tmp_name"])) {
$filename2 = time() . '_' . $_FILES["x0"]["name"];
$filepath = 'bilder/' . $filename2;
if (!move_uploaded_file($_FILES["x0"]["tmp_name"], $filepath)) {
$error = TRUE;
}
}
$filename3 = "";
$error = FALSE;
if (is_uploaded_file($_FILES["x1"]["tmp_name"])) {
$filename3 = time() . '_' . $_FILES["x1"]["name"];
$filepath = 'bilder/' . $filename3;
if (!move_uploaded_file($_FILES["x1"]["tmp_name"], $filepath)) {
$error = TRUE;
}
}
if (!$error) {
$sql = "INSERT INTO `pruefbericht` (`firmenname`, `str_nr`, `plz`, `ort`, `datum`, `telefon`, `ansprechpartner`, `str_nr2`, `plz2`, `ort2`, `ansprechpartner2`, `y1`, `y2`, `y3`, `y4`, `y5`, `y6`, `y7`, `y8`, `y9`, `y10`, `y11`, `y12`, `y13`, `y14`, `y15`, `y16`, `y17`, `a`, `b`, `c`, `d`, `e`, `f`, `g`, `h`, `i`, `j`, `k`, `l`, `m`, `n`, `o`, `p`, `a0`, `b0`, `c0`, `d0`, `e0`, `f0`, `g0`, `h0`, `i0`, `j0`, `k0`, `l0`, `m0`, `n0`, `o0`, `p0`, `a1`, `b1`, `c1`, `d1`, `e1`, `f1`, `g1`, `h1`, `i1`, `j1`, `k1`, `l1`, `m1`, `n1`, `o1`, `p1`, `x`, `x0`, `x1`) VALUES "
. "( :firmenname, :str_nr, :plz, :ort, :datum, :telefon, :ansprechpartner, :str_nr2, :plz2, :ort2, :ansprechpartner2, :y1, :y2, :y3, :y4, :y5, :y6, :y7, :y8, :y9, :y10, :y11, :y12, :y13, :y14, :y15, :y16, :y17, :a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, :l, :m, :n, :o, :p, :a0, :b0, :c0, :d0, :e0, :f0, :g0, :h0, :i0, :j0, :k0, :l0, :m0, :n0, :o0, :p0, :a1, :b1, :c1, :d1, :e1, :f1, :g1, :h1, :i1, :j1, :k1, :l1, :m1, :n1, :o1, :p1, :x, :x0, :x1)";
try {
$stmt = $DB->prepare($sql);
// bind the values
$stmt->bindValue(":firmenname", $firmenname);
$stmt->bindValue(":str_nr", $str_nr);
$stmt->bindValue(":plz", $plz);
$stmt->bindValue(":ort", $ort);
$stmt->bindValue(":datum", $datum);
$stmt->bindValue(":telefon", $telefon);
$stmt->bindValue(":ansprechpartner", $ansprechpartner);
$stmt->bindValue(":str_nr2", $str_nr2);
$stmt->bindValue(":plz2", $plz2);
$stmt->bindValue(":ort2", $ort2);
$stmt->bindValue(":ansprechpartner2", $ansprechpartner2);
$stmt->bindValue(":y1", $y1);
$stmt->bindValue(":y2", $y2);
$stmt->bindValue(":y3", $y3);
$stmt->bindValue(":y4", $y4);
$stmt->bindValue(":y5", $y5);
$stmt->bindValue(":y6", $y6);
$stmt->bindValue(":y7", $y7);
$stmt->bindValue(":y8", $y8);
$stmt->bindValue(":y8", $y8);
$stmt->bindValue(":y9", $y9);
$stmt->bindValue(":y10", $y10);
$stmt->bindValue(":y11", $y11);
$stmt->bindValue(":y12", $y12);
$stmt->bindValue(":y13", $y13);
$stmt->bindValue(":y14", $y14);
$stmt->bindValue(":y15", $y15);
$stmt->bindValue(":y16", $y16);
$stmt->bindValue(":y17", $y17);
$stmt->bindValue(":a", $a);
$stmt->bindValue(":b", $b);
$stmt->bindValue(":c", $c);
$stmt->bindValue(":d", $d);
$stmt->bindValue(":e", $e);
$stmt->bindValue(":f", $f);
$stmt->bindValue(":g", $g);
$stmt->bindValue(":h", $h);
$stmt->bindValue(":i", $i);
$stmt->bindValue(":j", $j);
$stmt->bindValue(":k", $k);
$stmt->bindValue(":l", $l);
$stmt->bindValue(":m", $m);
$stmt->bindValue(":n", $n);
$stmt->bindValue(":o", $o);
$stmt->bindValue(":p", $p);
$stmt->bindValue(":a0", $a0);
$stmt->bindValue(":b0", $b0);
$stmt->bindValue(":c0", $c0);
$stmt->bindValue(":d0", $d0);
$stmt->bindValue(":e0", $e0);
$stmt->bindValue(":f0", $f0);
$stmt->bindValue(":g0", $g0);
$stmt->bindValue(":h0", $h0);
$stmt->bindValue(":i0", $i0);
$stmt->bindValue(":j0", $j0);
$stmt->bindValue(":k0", $k0);
$stmt->bindValue(":l0", $l0);
$stmt->bindValue(":m0", $m0);
$stmt->bindValue(":n0", $n0);
$stmt->bindValue(":o0", $o0);
$stmt->bindValue(":p0", $p0);
$stmt->bindValue(":a1", $a1);
$stmt->bindValue(":b1", $b1);
$stmt->bindValue(":c1", $c1);
$stmt->bindValue(":d1", $d1);
$stmt->bindValue(":e1", $e1);
$stmt->bindValue(":f1", $f1);
$stmt->bindValue(":g1", $g1);
$stmt->bindValue(":h1", $h1);
$stmt->bindValue(":i1", $i1);
$stmt->bindValue(":j1", $j1);
$stmt->bindValue(":k1", $k1);
$stmt->bindValue(":l1", $l1);
$stmt->bindValue(":m1", $m1);
$stmt->bindValue(":n1", $n1);
$stmt->bindValue(":o1", $o1);
$stmt->bindValue(":p1", $p1);
$stmt->bindValue(":x", $filename);
$stmt->bindValue(":x0", $filename2);
$stmt->bindValue(":x1", $filename3);
// execute Query
$stmt->execute();
$result = $stmt->rowCount();
if ($result > 0) {
$_SESSION["errorType"] = "success";
$_SESSION["errorMsg"] = "Der Prüfbericht wurde erfolgreich gespeichert. <a href='pruefberichte'>Hier</a> kommen Sie zur Übersicht der Prüfberichte";
} else {
$_SESSION["errorType"] = "danger";
$_SESSION["errorMsg"] = "Es ist ein Fehler beim speichern des Prüfberichts aufgetreten.";
}
} catch (Exception $ex) {
$_SESSION["errorType"] = "danger";
$_SESSION["errorMsg"] = $ex->getMessage();
}
} else {
$_SESSION["errorType"] = "danger";
$_SESSION["errorMsg"] = "Es ist ein Fehler beim hochladen des Fotos aufgetreten.";
}
header("location:neue-inspektion");
} elseif ( $mode == "update_old" ) {
$firmenname = trim($_POST['firmenname']);
$str_nr = trim($_POST['str_nr']);
$plz = trim($_POST['plz']);
$ort = trim($_POST['ort']);
$datum = trim($_POST['datum']);
$telefon = trim($_POST['telefon']);
$ansprechpartner = trim($_POST['ansprechpartner']);
$id = trim($_POST['id']);
$filename = "";
$error = FALSE;
if (is_uploaded_file($_FILES["b"]["tmp_name"])) {
$filename = time() . '_' . $_FILES["b"]["name"];
$filepath = 'bilder/' . $filename;
if (!move_uploaded_file($_FILES["b"]["tmp_name"], $filepath)) {
$error = TRUE;
}
} else {
$filename = $_POST['old_pic'];
}
if (!$error) {
$sql = "UPDATE `pruefbericht` SET `firmenname` = :firmenname, `str_nr` = :str_nr, `plz` = :plz, `ort` = :ort, `datum` = :datum, `telefon` = :telefon, `ansprechpartner` = :ansprechpartner, `profile_pic` = :pic "
. "WHERE id = :id ";
try {
$stmt = $DB->prepare($sql);
// bind the values
$stmt->bindValue(":firmenname", $firmenname);
$stmt->bindValue(":str_nr", $str_nr);
$stmt->bindValue(":plz", $plz);
$stmt->bindValue(":ort", $ort);
$stmt->bindValue(":datum", $datum);
$stmt->bindValue(":telefon", $telefon);
$stmt->bindValue(":ansprechpartner", $ansprechpartner);
$stmt->bindValue(":pic", $filename);
$stmt->bindValue(":id", $id);
// execute Query
$stmt->execute();
$result = $stmt->rowCount();
if ($result > 0) {
$_SESSION["errorType"] = "success";
$_SESSION["errorMsg"] = "Kundendaten wurden erfolgreich aktualisiert.";
} else {
$_SESSION["errorType"] = "info";
$_SESSION["errorMsg"] = "Es wurden keine Änderungen an den Kundendaten vorgenommen.";
}
} catch (Exception $ex) {
$_SESSION["errorType"] = "danger";
$_SESSION["errorMsg"] = $ex->getMessage();
}
} else {
$_SESSION["errorType"] = "danger";
$_SESSION["errorMsg"] = "Failed to upload image.";
}
header("location:neue-inspektion?pagenum=".$_POST['pagenum']);
} elseif ( $mode == "delete" ) {
$id = intval($_GET['id']);
$sql = "DELETE FROM `pruefbericht` WHERE id = :id";
try {
$stmt = $DB->prepare($sql);
$stmt->bindValue(":id", $id);
$stmt->execute();
$res = $stmt->rowCount();
if ($res > 0) {
$_SESSION["errorType"] = "success";
$_SESSION["errorMsg"] = "Der Prüfbericht wurde erfolgreich gelöscht.";
} else {
$_SESSION["errorType"] = "info";
$_SESSION["errorMsg"] = "Es ist ein Fehler beim löschen der Kundendaten aufgetreten.";
}
} catch (Exception $ex) {
$_SESSION["errorType"] = "danger";
$_SESSION["errorMsg"] = $ex->getMessage();
}
header("location:pruefberichte?pagenum=".$_GET['pagenum']);
}
?>