--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/fhiiqm/vertrag_upd.php Wed Aug 31 14:22:19 2011 +0200
@@ -0,0 +1,278 @@
+<!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 href="css/db.css" rel="STYLESHEET" type="TEXT/CSS" />
+
+ <title>Aktualisieren Vertragsdaten</title>
+</head>
+
+<body>
+ <div class="float-r"><img src="img/document_mark_as_final.png" border="0" alt="Vertragsdaten bearbeiten" title="Vertragsdaten bearbeiten"/></div>
+
+<?php
+
+/**
+ * @author Bettina Schwarzer, Fritz-Haber-Institut
+ * @copyright 05/2011
+ *
+ * UPDATE/DELETE Vertragsdaten
+ */
+
+ error_reporting(E_ALL ^ E_NOTICE);
+
+ include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
+ include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/func_lib.inc.php");
+ $dbc = new dbconnection();
+ $cid = $_GET["uid"];
+ if (!$cid) $cid=3;
+ $ok = $_POST["ok"];
+ $upd = $_POST["upd"];
+ $del = $_POST["del"];
+ $vtr = $_POST["vertrag"];
+ if (!$vtr['okn']) $ok=false;
+
+// print_r($vtr);
+// echo "<br><br>\n";
+// echo "Vertragsbezeichnung: " . $vtr['cname'] ."<br><br>\n";
+
+ if (!$ok && ((!$upd && !$del) || $upd || $del))
+ {
+ if (!$upd && !$del)
+ {
+ $sql = "SELECT contract_ID,contract_name,contract_s,contract_l,vtyp_ID,contract_begin,contract_end,
+ contract_mon_notice,contract_file,Bemerkung
+ FROM fhiiqm.Vertrag WHERE contract_ID = $cid";
+ if ($result = $dbc ->queryObjectArray($sql))
+ {
+ foreach ($result as $row)
+ {
+ $vtr['cname'] = $row->contract_name;
+// $vtr['cshort'] = $row->contract_s;
+ $vtr['clong'] = $row->contract_l;
+ $vtr['vtyp'] = $row->vtyp_ID;
+ $vtr['bjahr'] = substr($row->contract_begin,0,4);
+ $vtr['bmon'] = substr($row->contract_begin,5,2);
+ $vtr['btag'] = substr($row->contract_begin,8,2);
+ $vtr['ejahr'] = substr($row->contract_end,0,4);
+ $vtr['emon'] = substr($row->contract_end,5,2);
+ $vtr['etag'] = substr($row->contract_end,8,2);
+ $vtr['cnot'] = $row->contract_mon_notice;
+ $vtr['cfname'] = $row->contract_file;
+ $vtr['cbem'] = $row->Bemerkung;
+ }
+ }
+ // Bearbeiter
+ $sql = "SELECT persknr FROM Vertrag_Bearbeiter WHERE contract_ID = $cid";
+ if ($result = $dbc ->queryObjectArray($sql))
+ {
+ foreach ($result as $row)
+ {
+ $vtr['cpers'][] = $row->persknr;
+ }
+ }
+ // Partner
+ $sql = "SELECT part_ID FROM Vertrag_Partner WHERE contract_ID = $cid";
+ if ($result = $dbc -> queryObjectArray($sql))
+ {
+ foreach ($result as $row)
+ {
+ $vtr['partid'] = $row->part_ID;
+ }
+ }
+ // Produkt
+ $sql = "SELECT produkt_ID FROM Produkt_Vertrag WHERE contract_ID = $cid";
+ if ($result = $dbc -> queryObjectArray($sql))
+ {
+ foreach ($result as $row)
+ {
+ $vtr['prodid'] = $row->produkt_ID;
+ }
+ }
+ // Kosten
+ $sql = "SELECT kosten FROM Vertrag_Kosten WHERE contract_ID = $cid ORDER BY k_year ";
+ if ($result = $dbc -> queryObjectArray($sql))
+ {
+ foreach ($result as $row)
+ {
+ $vtr['kost'][] = str_replace('.',',',$row->kosten);
+ }
+ }
+
+ }
+
+ include_once("form/vertrag_form.inc.php");
+
+ if ($upd)
+ {
+ echo
+ "<tr>
+ <td>Upload Vertragsdokument </td>
+ <td><input type=\"file\" name=\"vfile\" size=\"50\" maxlength=\"50\" value=\"" .
+ $_FILES["vfile"]["name"] . "\"/></td>
+ </tr>";
+
+ }
+ if ($upd || $del)
+ {
+ if ($upd)
+ $frage = "Alle Angaben ok?<br>
+ erst wenn Haken gesetzt, Upload-File wählen!";
+ elseif ($del)
+ $frage = "Vertrag 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";
+ echo "></td>\n</tr>\n";
+ }
+
+ echo "<tr>\n";
+ echo "
+ <td> </td>
+ <td><input class=\"button\" type=\"submit\" value=\"ändern\" name=\"upd\" title=\"update\" />
+ <input class=\"button\" type=\"submit\" value=\"löschen\" name=\"del\" title=\"delete\" /></td>\n";
+ echo "</tr>\n";
+ echo "</table>\n";
+ echo "</div>\n";
+ echo "</form>\n";
+
+ }
+ elseif ($ok && $upd)
+ {
+ echo "<div align='center'>\n";
+ //daten speichern
+
+ //UPDATE Vertrag
+/*
+ if ($vtr['vtyp']== -1 || !(is_numeric($vtr['vtyp']))) $vtr['vtyp'] = "NULL";
+ if ($vtr['bjahr'] && $vtr['bmon'] && $vtr['btag'])
+ {
+ $vbegin = $vtr['bjahr'] . "-" . $vtr['bmon'] . "-" . $vtr['btag'];
+ $vbegin = "'$vbegin'";
+ $vbd = $vtr['btag'] . "." . $vtr['bmon'] . "." . $vtr['bjahr'];
+ }
+ else
+ $vbegin = "NULL";
+ if ($vtr['ejahr'] && $vtr['emon'] && $vtr['etag'])
+ {
+ $vend = $vtr['ejahr'] . "-" . $vtr['emon'] . "-" . $vtr['etag'];
+ $vend = "'$vend'";
+ $ved = $vtr['etag'] . "." . $vtr['emon'] . "." . $vtr['ejahr'];
+ }
+ else
+ $vend = "NULL";
+ if (!is_numeric($vtr['cnot'])) $vtr['cnot'] = "NULL";
+ if ($vtr['cbem']) $vtr['cbem'] = "'" . str_replace("'","\"",substr($vtr['cbem'],0,500)) . "'"; else $vtr['cbem']="NULL";
+*/
+ $vtr['cname'] = substr($vtr['cname'],0,50);
+// $vtr['cshort'] = substr($vtr['cshort'],0,50);
+ $vtr['clong'] = substr($vtr['clong'],0,100);
+ if ($vtr['vtyp']== -1 || !(is_numeric($vtr['vtyp']))) $vtr['vtyp'] = null;
+ $vbegin = date_obj($vtr['bjahr'], $vtr['bmon'], $vtr['btag']);
+ $vend = date_obj($vtr['ejahr'], $vtr['emon'], $vtr['etag']);
+ if (!is_numeric($vtr['cnot'])) $vtr['cnot'] = null;
+ if ($vtr['cbem']) $vtr['cbem'] = substr($vtr['cbem'],0,500); else $vtr['cbem']=null;
+ // Filename Vertrag
+ $vtr['cfname'] = substr($vtr['cfname'],0,50);
+
+ if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
+
+
+ // upload File, wenn vorhanden
+ if (is_uploaded_file($_FILES["vfile"]["tmp_name"]) && isset($_FILES["vfile"]["name"]) && $_FILES["vfile"]["name"] )
+ {
+ include ("inc/file_upload.inc.php");
+ $fname = gen_filename($vtr['cfname'],"vfile",$cid); // Dateinamen generieren
+ $retdf = mod_file("/var/www/fhiiqm/documents",$cid,"","del"); // Loeschen alte Datei
+ $retf = upload("vfile", $fname, $cid); // Datei prüfen und in Dokumentenverzeichnis verschieben
+ }
+
+ if (isset($fname) && $retf) $cfile = $cid . "_" . $fname; else $cfile = $vtr['cfname'];
+/*
+ if (isset($fname) && $retf) $cfile = "contract_file = '" . $cid . "_" . $fname . "', ";
+ $sql = "UPDATE fhiiqm.Vertrag SET
+ contract_name ='" . $vtr['cname'] ."',
+-- contract_s ='" . $vtr['cshort'] ."',
+ contract_l ='" . $vtr['clong'] ."',
+ vtyp_ID = " . $vtr['vtyp'] . ",
+ contract_begin = $vbegin,
+ contract_end = $vend,
+ contract_mon_notice = " . $vtr['cnot'] . ", " .
+ $cfile .
+ "Bemerkung = " . $vtr['cbem'] ."
+ WHERE contract_ID = $cid" ;
+ $retv = $dbc -> execute($sql);
+*/
+ $stmt = $dbc -> stmtinit();
+ if (is_object($stmt))
+ {
+ $stmt -> prepare("UPDATE fhiiqm.Vertrag SET
+ contract_name = ?,
+ contract_l = ?,
+ vtyp_ID = ?,
+ contract_begin = ?,
+ contract_end = ?,
+ contract_mon_notice = ?,
+ contract_file = ?,
+ Bemerkung = ?
+ WHERE contract_ID = $cid") ;
+ $stmt -> bind_param('ssississ',$vtr["cname"],$vtr["clong"],$vtr['vtyp'],$vbegin,$vend,$vtr['cnot'],$cfile,$vtr['cbem']);
+ $retv = $stmt -> execute();
+ }
+// echo "UPDATE-sql = $sql<br />\n";
+ if (!$retv) echo "error update" . $dbc -> error ."<br />\n";
+ if ($retv)
+ {
+ // DELETE, INSERT n:m Tabellen
+ include ("inc/vertragtab_ins.inc.php");
+ }
+// echo "retv=$retv, retb=$retb, retp=$retp, retd=$retd, retk=$retk<br />\n";
+ if ($retv && $retb && $retp && $retd && $retk)
+ {//Eingabe Daten, Upload File erfolgreich
+ echo "<p class='green'><b>Vertragsdaten zu ID '$cid' wurden erfolgreich gespeichert.</b></p>\n";
+ echo "<br /><br />\n";
+
+ // Anzeigen gespeicherte Vertragsdaten
+ if ($fname)
+ $cfile = $cid . "_" . $fname;
+ else
+ $cfile = $vtr['cfname'];
+ include ("inc/vertrag_dat_show.inc.php");
+ }
+ }
+ elseif ($ok && $del)
+ {
+ // DELETE aus Tab Vertrag und abhaengigen Tabellen
+ echo "<div align='center'>\n";
+
+ $sql = "DELETE FROM Vertrag WHERE contract_ID = $cid";
+ $retvd = $dbc -> execute($sql);
+ if ($retvd)
+ {
+ include ("inc/file_upload.inc.php");
+ $retdf = mod_file("/var/www/fhiiqm/documents",$cid,"","del"); // Loeschen Dokument
+ if ($retdf) echo "<p class='green'><b>Vertragsdokument zu ID '$cid' wurde gelöscht.</b></p>\n";
+ echo "<p class='green'><b>Vertragsdaten zu ID '$cid' wurden gelöscht.</b></p>\n";
+ echo "<br /><br />\n";
+
+ // Anzeigen geloeschter Vertragsdaten
+ if ($fname)
+ $cfile = $cid . "_" . $fname;
+ else
+ $cfile = $vtr['cfname'];
+ include ("inc/vertrag_dat_show.inc.php");
+ }
+ }
+ if ($ok && ($upd || $del))
+ {
+ echo "</div><br /><br />\n";
+ echo "<p> <a href=\"vertrag_flist1.php\" target=\"_self\" title=\"Vertragsliste\">Zurück zur Vertragsliste</a></p>\n";
+ echo "<p> <a href=\"vertrag_ins.php\" target=\"_self\" title=\"Vertrag erfassen\">Weiteren Vertrag erfassen</a></p>\n";
+ }
+
+?>
+
+</body>
+</html>
\ No newline at end of file