<?php
/**
* @author Bettina Schwarzer, Fritz-Haber-Institut
* @copyright 12/2011
*/
error_reporting(E_ALL ^ E_NOTICE);
session_start();
if (! isset($_SESSION["userid"]))
{
include_once ("inc/func_lib.inc.php");
login($_SERVER["PHP_SELF"]);
exit;
}
if (is_null($_SESSION["recht"]) || (!is_null($_SESSION["recht"]) && !in_array("ar",$_SESSION["recht"]) && !in_array("ae",$_SESSION["recht"])))
{
header("Location: start.php");
exit;
}
include_once($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/inc/dbconnect.inc.php");
if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link type="text/css" href="/fhiiqm/css/db.css" rel="Stylesheet" media="screen"/>
<link type="text/css" href="/fhiiqm/css/db_print.css" rel="Stylesheet" media="print"/>
<link type="text/css" href="/fhiiqm/css/jquery/ui-lightness-1.8.21/jquery-ui-1.8.21.custom.css" rel="Stylesheet" />
<link type="text/css" href="/fhiiqm/css/jquery/jquery-ui-timepicker-addon.css" rel="Stylesheet" />
<script type="text/javascript" src="/fhiiqm/js/jquery/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/fhiiqm/js/jquery/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="/fhiiqm/js/jquery/jquery-ui-timepicker-addon-1.0.1.js"></script>
<title>Anlage Pruefung</title>
</head>
<body>
<?php
echo " ";
echo "<div class=\"float-br smaller\" valign='top'>";
echo " user: " . $_SESSION["userid"];
echo " <a class='sc' href='/fhiiqm/logout.php' title='Session beenden'>logout</a></div>\n";
echo "<div class=\"float-r\"><img src=\"img/rotate_01.png\" border=\"0\" alt=\"Anlage\" title=\"Anlage\"/></div>\n";
?>
<div align='center'>
<script>
$(document).ready(function() {
$("#albez").focus();
$("#albez").autocomplete({
source: "/fhiiqm/inc/al_list_ac.inc.php",
minLength: 2,
select: function(event,ui){$("#alid").val(ui.item.id);}
});
$("#alpdat").datetimepicker({
dateFormat: 'yy-mm-dd',
timeFormat: 'hh:mm:ss', //damit kann auch Uhrzeit angegeben werden
yearRange: '2000:2020',
changeMonth: true,
changeYear: true,
firstDay: 1,
dayNamesMin: ['So','Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa' ],
monthNamesShort: ['Jan','Feb','Mar','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'],
timeText: 'Uhrzeit',
hourText: 'Stunde',
currentText: 'Jetzt',
closeText: 'OK'
});
$("input").albez("long20").addClass("long20");
$("input").alpdat("long10").addClass("long10");
});
</script>
<?php
$al = $_POST["al"];
$alpid = $_GET["i"];
$sub = $_POST["eintragen"];
$ok = $_POST["ok"];
if (!$al['okn']) $ok=false;
// print_r($al);
if ($alpid) $text = "editieren"; else $text = "erfassen";
echo "<h3>Prüfung Anlage $text<h3>";
echo "</div>\n";
if (!$ok || !$sub)
{
// form anzeigen
if ($alpid && !$sub)
{
// Inhalte zu Pruefung holen
$sql = "SELECT p.al_ID,al_bez,pruef_date,pruef_file,pruef_bem
FROM fhiiqm.A_Pruefung p INNER JOIN fhiiqm.Anlage a ON p.al_ID=a.al_ID
WHERE alp_ID = $alpid";
if ($result = $dbc -> queryObjectArray($sql))
{
foreach ($result as $row)
{
$al["id"] = $row->al_ID;
$al["bez"] = $row->al_bez;
$al["pdat"] = $row->pruef_date;
$al["bem"] = $row->pruef_bem;
$al["pfname"] = $row->pruef_file;
}
}
}
include ($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/form/alpruef_form.inc.php");
if ($sub)
{
echo
"<tr>
<td>Upload Protokoll </td>
<td><input type=\"file\" name=\"pfile\" size=\"50\" maxlength=\"50\" value=\"" .
$_FILES["pfile"]["name"] . "\"/></td>
</tr>";
$frage = "Alle Angaben ok?<br>
erst wenn Haken gesetzt, Upload-File wählen!";
echo "<tr>
<td class=\"red\" valign=\"top\" align=\"left\">$frage</td>
<td><input type=\"checkbox\" name=\"ok\" value=\"1\"";
if ($ok) echo "checked";
echo "></td>\n</tr>\n";
}
if (!is_null($_SESSION["recht"]) && in_array("ae",$_SESSION["recht"]))
{
echo "
<tr><td> </td>\n
<td><input class=\"button\" type=\"submit\" name=\"eintragen\" value=\" eintragen \" /></td>\n
</tr>\n";
}
echo "</table>\n";
echo "</div>\n";
if (!is_null($_SESSION["recht"]) && !in_array("ae", $_SESSION["recht"]))
echo "<p class='sc'> <a href=\"alpruef_flist.php\" target=\"_self\" title=\"Anlagen pruefen\">« zur Liste der Anlagenprüfungen</a></p>\n";
echo "</form>\n";
}
else
{
// Daten speichern
echo "<div align='center'>\n";
// alte Bezeichnung Protokoll holen
$sql = "SELECT pruef_file
FROM fhiiqm.A_Pruefung
WHERE alp_ID = $alpid";
if ($result = $dbc -> queryObjectArray($sql))
foreach ($result as $row) $al["pfname_old"] = $row->pruef_file;
if ($alpid)
{
//update
// upload File
if (is_uploaded_file($_FILES["pfile"]["tmp_name"]) && isset($_FILES["pfile"]["name"]) && $_FILES["pfile"]["name"] )
{
include ("inc/file_upload.inc.php");
if ($al['pfname']<"!") $al['pfname']="al_pruefung";
$fname = gen_filename($al['pfname'],"pfile",$alpid);
$retdf = mod_file("/var/www/fhiiqm/alprot",$alpid,"","del"); // Loeschen alte Datei
$retf = upload("pfile", $fname, $alpid, "alprot"); // Datei prüfen und in Dokumentenverzeichnis verschieben
if ($retf)
{
$sql = "UPDATE A_Pruefung SET pruef_file = '" . $alpid . "_" . $fname ."' WHERE alp_ID=$alpid";
$retp=$dbc->execute($sql);
if (!$retp)
echo $dbc -> error . "<br>\n";
}
}
else
{ // nur Aenderung Dateiname
include ("inc/file_upload.inc.php");
$fname = gen_filename($al["pfname"],$al["pfname_old"],$alpid,0);
$len = strlen($alpid)+1;
if (substr($fname,0,$len) != "$alpid" . "_") $fname = $alpid . "_" . $fname;
if ($al["pfname"] != $al["pfname_old"])
{
$retf = mod_file("/var/www/fhiiqm/alprot",$alpid,$fname,"upd"); // Umbenennen alte Datei
if ($retf)
{
$sql = "UPDATE A_Pruefung SET pruef_file = '" . $fname . "' WHERE alp_ID=$alpid";
$retp=$dbc->execute($sql);
if (!$retp)
echo $dbc -> error . "<br>\n";
if (substr($fname,0,$len) == "$alpid" . "_") $fname = substr($fname,$len,50);
}
}
else
{
//kein Upload, keine Dateinamenaenderung
if (substr($fname,0,$len) == "$alpid" . "_") $fname = substr($fname,$len,50);
$retf=1; $retp=1;
}
}
$stmt = $dbc -> stmtinit();
if (is_object($stmt))
{
$stmt -> prepare ("UPDATE A_Pruefung SET
al_ID = ?,
pruef_date = ?,
pruef_bem = ?
WHERE alp_ID = $alpid");
$stmt -> bind_param('iss', $al["id"], $al["pdat"],$al["bem"]);
$result = $stmt -> execute();
if ($stmt->error) echo "UPDATE error: " . $stmt->errno . " - ". $stmt->error . "<br><br>\n";
}
}
else
{
//insert
$stmt = $dbc -> stmtinit();
if (is_object($stmt))
{
$stmt -> prepare ("INSERT INTO A_Pruefung (al_ID,pruef_date,pruef_bem) VALUES (?,?,?)");
$stmt -> bind_param('iss', $al["id"], $al["pdat"],$al["bem"]);
$result = $stmt -> execute();
if ($stmt->error) echo "INSERT error: " . $stmt->errno . " - ". $stmt->error . "<br><br>\n";
}
//$result=1;
if ($result)
{ // INSERT o.k.
// info_ID ermitteln
$alpid = $dbc -> insertId();
// upload File
if (is_uploaded_file($_FILES["pfile"]["tmp_name"]) && isset($_FILES["pfile"]["name"]) && $_FILES["pfile"]["name"] )
{
include ("inc/file_upload.inc.php");
if ($al['pfname']<"!") $al['pfname']="al_pruefung";
$fname = gen_filename($al['pfname'],"pfile",$alpid);
//echo $fname;
$retf = upload("pfile", $fname, $alpid, "alprot"); // Datei prüfen und in Dokumentenverzeichnis verschieben
if ($retf)
{ // upload o.k.
//UPDATE des Filenamens
$sql = "UPDATE A_Pruefung SET pruef_file = '" . $alpid . "_" . $fname ."' WHERE alp_ID=$alpid";
$retp=$dbc->execute($sql);
if (!$retp)
echo $dbc -> error . "<br>\n";
}
}
else
{
$retf=1; //kein Protokoll hochgeladen
$retp=1;
}
}
}
if ($result && $retf && $retp) // INSERT/UPDATE Pruefung
{
//Eingabe Daten, Upload File erfolgreich
echo "<p class='green'><b>Prüfdaten zu Anlage '".$al["bez"]."' wurden erfolgreich gespeichert.</b></p>\n";
echo "<br /><br />\n";
// Anzeigen gespeicherte Pruefdaten
if ($fname)
$pfile = $alpid . "_" . $fname;
else
$pfile = $al['pfname'];
echo "<table>\n";
echo "<tr><td>Anlagen-ID: </td><td>" . $al["id"] . "<td></td></tr>\n";
echo "<tr><td>Anlagenbezeichnung: </td><td>" . $al['bez'] . "<td></td></tr>\n";
$pdat = new DateTime($al["pdat"]);
if (is_object($pdat)) $pdat = $pdat->format('d.m.Y H:i:s'); else $pdat = " ";
echo "<tr><td>Prüfdatum: </td><td>" . $pdat. "</td></tr>\n";
if ($fname>"!") echo "<tr><td>Dateiname Prüfprotokoll: </td><td>" . $pfile. "</td></tr>\n";
echo "<tr><td>Bemerkung: </td><td>" . nl2br($al['bem']) . "<td></td></tr>\n";
echo "</table>\n";
}
$dbc -> close();
echo "</div>\n";
echo "<p class=\"sc\"> <a href=\"alpruef_ed.php\" target=\"_self\" title=\"Prüfung erfassen\">Weitere Anlagen-Prüfung erfassen</a></p>\n";
echo "<p class=\"sc\"> <a href=\"alpruef_flist.php\" target=\"_self\" title=\"Anlagen pruefen\" class=\"sc\">Liste der Anlagenprüfungen</a>";
echo " | <a href=\"anlage_flist.php\" target=\"_self\" title=\"Anlagen\">Anlagenenliste</a></p>\n";
}
?>
</body>
</html>