<?php
/**
* @author Bettina Schwarzer, Fritz-Haber-Institut
* @copyright 12/2011, 01/2012
*
* Laser INSERT, UPDATE, DELETE, COPY
*/
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("lr",$_SESSION["recht"]) && !in_array("le",$_SESSION["recht"])))
{
header("Location: start.php");
exit;
}
include_once($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/inc/dbconnect.inc.php");
if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
$la = $_POST["la"];
$laid = $_GET["i"];
$copy = $_GET["c"];
$sub = $_POST["eintragen"];
$del = $_POST["del"];
$dup = $_POST["dup"];
if (!$dup) $dup = $_GET["d"];
$ok = $_POST["ok"];
if (!$la['okn']) $ok=false;
$duptext="";
if ($dup)
{ // Anlage duplizieren
include_once ($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/inc/func_lib.inc.php");
$tab = "Laser";
$key = "las_ID";
$val = $laid;
// $ret=1;
$ret = duplicate_record ($tab, $key, $val);
if ($ret)
{
$laid=$ret;
$addr = $_SERVER["PHP_SELF"] . "?i=$laid&c=1";
header("Location: $addr");
exit;
}
else $duptext = " - Fehler beim Duplizieren von ". $la["lbez"];
}
?>
<!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/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="/fhiiqm/js/jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="/fhiiqm/js/jquery/jquery-ui-1.8.16.custom.min.js"></script>
<title>Laser</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/laser.png\" border=\"0\" alt=\"Laser\" title=\"Laser\"/></div>\n";
?>
<div align='center'>
<script>
$(document).ready(function() {
$("#lbez").focus();
$("#persknr").autocomplete({
source: "/fhiiqm/inc/ma_list_ac.inc.php",
minLength: 2,
select: function(event,ui){$("#pid").val(ui.item.id);}
});
$("input").persknr("long20").addClass("long20");
});
</script>
<?php
// print_r($al);
if ($laid) $text = "editieren"; else $text = "erfassen";
if ($copy) $duptext = " (Kopie)";
echo "<h3>Laser $text$duptext<h3>";
echo "</div>\n";
if (!$ok || (!$sub && !$del && !$dup))
{
if ($laid && (!$sub || !$del) && !isset($la))
{ // update
$sql = "SELECT las_ID, las_bez, las_welle_von, las_welle_bis,
las_art_ID, las_klasse_ID, las_typ_ID, leistung, einheit_leistung,
apertur, einheit_apertur, energie, einheit_energie, frequenz, einheit_frequenz,
impulsbreite, einheit_impulsbreite, l.las_hersteller_ID, schutzst_ID,
l.aktiv, l.persknr, l.raum_ID, geb_ID, las_info,
CONCAT(nachname,', ',vorname) AS vname, las_hersteller_bez,
inventar_nr,maxleistung, einheit_maxleist,schutzst_od_ID,las_ref_ID,l.timestamp
FROM fhiiqm.Laser l LEFT OUTER JOIN fhiiqm.Mitarbeiter m
ON l.persknr=m.persknr LEFT OUTER JOIN fhiiqm.Laser_Hersteller h
ON l.las_hersteller_ID=h.las_hersteller_ID LEFT OUTER JOIN fhiiqm.Raum r
ON l.raum_ID=r.Raum_ID
WHERE las_ID = '$laid'";
if ($result = $dbc -> queryObjectArray($sql))
{
foreach ($result as $row)
{
$la["lid"] = $laid;
$la["lbez"] = $row->las_bez;
// $la['wvon'] = str_replace(".",",",$row->las_welle_von);
$la['wvon'] = str_replace(".",",",str_replace(".00","",$row->las_welle_von));
$la['wbis'] = str_replace(".",",",str_replace(".00","",$row->las_welle_bis));
$la["lart"] = ($row->las_art_ID) ? $row->las_art_ID : -1;
$la['lkla'] = ($row->las_klasse_ID) ? $row->las_klasse_ID : -1;
$la['ltyp'] = ($row->las_typ_ID) ? $row->las_typ_ID : -1;
$la['leist'] = str_replace(".",",",str_replace(".00","",$row->leistung));
$la['eleist'] = $row->einheit_leistung;
$la["apt"] = str_replace(".",",",str_replace(".00","",$row->apertur));
$la["eapt"] = $row->einheit_apertur;
$la["eng"] = str_replace(".",",",str_replace(".00","",$row->energie));
$la["eeng"] = $row->einheit_energie;
$la["frq"] = str_replace(".",",",str_replace(".00","",$row->frequenz));
$la["efrq"] = $row->einheit_frequenz;
$la["ipb"] = str_replace(".",",",str_replace(".00","",$row->impulsbreite));
$la["eipb"] = $row->einheit_impulsbreite;
$la["akt"] = $row->aktiv;
$la["hstid"] = $row->las_hersteller_ID;
if (!$la["hstid"]) $la["hstid"] = -1;
$la["suid"] = ($row->schutzst_ID)? $row->schutzst_ID : -1;
$la["akt"] = $row->aktiv;
$la["persknr"] = $row->vname;
$la["pid"] = ($row->persknr) ? $row->persknr : null;
$la["geb"] = $row->geb_ID;
$la["raum"] = ($row->raum_ID) ? $row->raum_ID : -1;
$la["linfo"] = $row->las_info;
$la["invnr"] = $row->inventar_nr;
$la["leistmax"] = str_replace(".",",",str_replace(".00","",$row->maxleistung));
$la["eleistmax"]= $row->einheit_maxleist;
$la["suodid"] = $row->schutzst_od_ID;
$la["lidref"] = $row->las_ref_ID;
$la["tstmp"] = $row->timestamp;
}
}
}
include ($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/form/laser_form.inc.php");
if ($sub || $del)
{
if ($sub)
$frage = "Alle Angaben ok?";
elseif ($del)
$frage = "Laser wirklich löschen?";
echo "<tr>
<td class=\"red\" valign=\"top\" align=\"left\">$frage</td>
<td><input type=\"checkbox\" name=\"ok\" value=\"1\"";
if ($ok) echo "checked=\"checked\"";
echo " /></td>\n</tr>\n";
}
if (!is_null($_SESSION["recht"]) && in_array("le",$_SESSION["recht"]))
{
echo "
<tr><td> </td>\n
<td><input class=\"button\" type=\"submit\" name=\"eintragen\" value=\" eintragen \" />";
if ($laid)
{
echo " <input class=\"buttonr\" type=\"submit\" value=\"löschen\" name=\"del\" title=\"delete\" />";
echo " <input class=\"button\" type=\"submit\" value=\"duplizieren\" name=\"dup\" title=\"delete\" />";
}
echo "</td></tr>\n";
}
echo "</table>\n";
echo "</div>\n";
// if (!is_null($_SESSION["recht"]) && !in_array("le", $_SESSION["recht"]))
echo "<p class='sc'> <a href=\"laser_flist.php\" target=\"_self\" title=\"Laser\">« zur Laserliste</a></p>\n";
echo "</form>\n";
}
else
{
echo "<div align='center'>\n";
if ($del)
{
$sql = "DELETE FROM Laser WHERE las_ID = '$laid'";
$retld = $dbc -> execute($sql);
if ($retld)
{
echo "<p class='green'><b>DELETE: Daten zu '".$la["lbez"]."' wurden erfolgreich gelöscht.</b></p>\n";
include ("inc/laser_dat_show.inc.php");
}
else
{
echo "<p class='red'><b>DELETE: Daten zu '".$la["lbez"]."' konnten nicht gelöscht werden!</b></p>\n";
echo "sql = $sql<br />";
echo "error DELETE: " . $dbc->error . "<br />";
}
}
else //INSERT oder UPDATE
{
if ($la["lbez"]) $la["lbez"] = substr($la["lbez"],0,250); else $la["lbez"] = null;
if ($la["linfo"]) $la["linfo"] = substr($la["linfo"],0,500); else $la["linfo"] = null;
if ($la["lart"] == -1) $la["lart"] = null;
if ($la["lkla"] == -1) $la["lkla"] = null;
if ($la["ltyp"] == -1) $la["ltyp"] = null;
if ($la["suid"] == -1) $la["suid"] = null;
if ($la["suodid"] == -1) $la["suodid"] = null;
if ($la["lidref"] == -1) $la["lidref"] = null;
// print_r($la); echo "<br /><br />";
if ($la["hstid"] == -1)
{
if ($la["herst"] > "!") // neuer Hersteller?
{
$sql = "SELECT las_hersteller_ID FROM Laser_Hersteller WHERE las_hersteller_bez = '" . ltrim($la["herst"]) . "'";
if ($res = $dbc -> queryObjectArray($sql))
{ // Hersteller vorhanden
foreach ($res as $row)
$la["hstid"] = $row->las_hersteller_ID;
}
else
{ // Hersteller neu
$sql = "INSERT INTO Laser_Hersteller (las_hersteller_bez) VALUES (LEFT(TRIM('" . $la["herst"] . "'),50))";
$reth = $dbc -> execute($sql);
if ($reth) $la["hstid"] = $dbc -> insertId(); else $la["hstid"] = null;
}
}
else
$la["hstid"] = null;
}
if ($la["lart"] == -1)
{
if ($la["lartnew"] > "!") // neue Laserart?
{
$sql = "SELECT las_art_ID FROM Laser_Art WHERE las_art_bez = '" . ltrim($la["lartnew"]) . "'";
if ($res = $dbc -> queryObjectArray($sql))
{ // Hersteller vorhanden
foreach ($res as $row)
$la["lart"] = $row->las_art_ID;
}
else
{ // Laserart neu
$sql = "INSERT INTO Laser_Art (las_art_bez) VALUES (LEFT(TRIM('" . $la["lartnew"] . "'),50))";
$reth = $dbc -> execute($sql);
if ($reth) $la["lart"] = $dbc -> insertId(); else $la["lart"] = null;
}
}
else
$la["lart"] = null;
}
foreach ($la as $key=>$value)
{
if (is_null($value) || $value < "!") $la["$key"] = null;
}
if (is_null($la["persknr"])) $la[pid] = null;
if (is_numeric(str_replace(",",".",$la["wvon"]))) $la["wvon"] = round(str_replace(",",".",$la["wvon"]),2);
if (is_numeric(str_replace(",",".",$la["wbis"]))) $la["wbis"] = round(str_replace(",",".",$la["wbis"]),2);
if (is_numeric(str_replace(",",".",$la["leist"]))) $la["leist"] = round(str_replace(",",".",$la["leist"]),2);
if (is_numeric(str_replace(",",".",$la["leistmax"]))) $la["leistmax"] = round(str_replace(",",".",$la["leistmax"]),2);
if (is_numeric(str_replace(",",".",$la["eng"]))) $la["eng"] = round(str_replace(",",".",$la["eng"]),2);
if (is_numeric(str_replace(",",".",$la["apt"]))) $la["apt"] = round(str_replace(",",".",$la["apt"]),2);
if (is_numeric(str_replace(",",".",$la["frq"]))) $la["frq"] = round(str_replace(",",".",$la["frq"]),2);
if (is_numeric(str_replace(",",".",$la["ipb"]))) $la["ipb"] = round(str_replace(",",".",$la["ipb"]),2);
$stmt = $dbc -> stmtinit();
if (is_object($stmt))
{
if ($laid)
{
//update
$stmt -> prepare("UPDATE fhiiqm.Laser SET
las_bez = ?,
las_welle_von = ?,
las_welle_bis = ?,
las_art_ID = ?,
las_klasse_ID = ?,
las_typ_ID = ?,
leistung = ?,
einheit_leistung = ?,
energie = ?,
einheit_energie = ?,
apertur = ?,
einheit_apertur = ?,
frequenz = ?,
einheit_frequenz = ?,
impulsbreite = ?,
einheit_impulsbreite = ?,
las_hersteller_ID = ?,
schutzst_ID = ?,
aktiv = ?,
persknr = ?,
raum_ID = ?,
las_info = ?,
inventar_nr = ?,
maxleistung = ?,
einheit_maxleist = ?,
schutzst_od_ID = ?,
las_ref_ID = ?
WHERE las_ID = '$laid'");
$stmt -> bind_param('sddisidididididiiiiiissdiii',$la["lbez"],$la['wvon'],$la['wbis'],$la["lart"],$la['lkla'],
$la['ltyp'],$la['leist'],$la["eleist"],$la["eng"],$la["eeng"],$la["apt"],$la["eapt"],$la["frq"],$la["efrq"],
$la["ipb"],$la["eipb"],$la["hstid"],$la["suid"],$la["akt"],$la["pid"],$la["raum"],$la["linfo"],
$la["invnr"],$la["leistmax"],$la["eleistmax"],$la["suodid"],$la["lidref"]);
$res = $stmt -> execute();
if ($stmt->error) echo "UPDATE Laser, error: " . $stmt->errno . " - ". $stmt->error . "<br><br>\n";
if ($res)
echo "<p class='green'><b>UPDATE: Daten zu '".$la["lbez"]."' wurden erfolgreich gespeichert.</b></p>\n";
else
echo "<p class='red'><b>UPDATE: Daten zu '".$la["lbez"]."' konnten nicht gespeichert werden!</b></p>\n";
}
else
{
//insert
$stmt -> prepare("INSERT INTO fhiiqm.Laser (las_bez, las_welle_von, las_welle_bis, las_art_ID,
las_klasse_ID, las_typ_ID, leistung, einheit_leistung, energie, einheit_energie,
apertur, einheit_apertur, frequenz, einheit_frequenz, impulsbreite, einheit_impulsbreite,
las_hersteller_ID, schutzst_ID, aktiv, persknr, raum_ID, las_info,
inventar_nr,maxleistung, einheit_maxleist,schutzst_od_ID,las_ref_ID)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt -> bind_param('sddisidididididiiiiiissdiii',$la["lbez"],$la['wvon'],$la['wbis'],$la["lart"],$la['lkla'],
$la['ltyp'],$la['leist'],$la["eleist"],$la["eng"],$la["eeng"],$la["apt"],$la["eapt"],$la["frq"],$la["efrq"],
$la["ipb"],$la["eipb"],$la["hstid"],$la["suid"],$la["akt"],$la["pid"],$la["raum"],$la["linfo"],
$la["invnr"],$la["leistmax"],$la["eleistmax"],$la["suodid"],$la["lidref"]);
$res = $stmt -> execute();
// print_r($stmt); echo "<br /><br />";
if ($stmt->error) echo "INSERT Laser, error: " . $stmt->errno . " - ". $stmt->error . "<br><br>\n";
if ($res)
{
$la["lid"] = $dbc -> insertId();
echo "<p class='green'><b>INSERT: Daten zu '".$la["lbez"]."' wurden erfolgreich gespeichert.</b></p>\n";
}
else
echo "<p class='red'><b>INSERT: Daten zu '".$la["lbez"]."' konnten nicht gespeichert werden!</b></p>\n";
}
if ($res) include ("inc/laser_dat_show.inc.php");
}
}
echo "</div>\n";
echo "<p class=\"sc\"> <a href=\"".$_SERVER["PHP_SELF"]."\" target=\"_self\" title=\"Laser erfassen\">Weiteren Laser erfassen</a></p>\n";
echo "<p class=\"sc\"> <a href=\"laser_flist.php\" target=\"_self\" title=\"Laser\">Laserliste</a></p>\n";
}
?>
</body>
</html>