fhiiqm/vertrag_upd.php
changeset 1 6288d5685bff
child 8 908abe8cec4d
equal deleted inserted replaced
0:ef68113ff309 1:6288d5685bff
       
     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       
     2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
       
     3 
       
     4 <head>
       
     5 	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
       
     6    	<link href="css/db.css" rel="STYLESHEET" type="TEXT/CSS" /> 
       
     7 
       
     8 	<title>Aktualisieren Vertragsdaten</title>
       
     9 </head>
       
    10 
       
    11 <body>
       
    12     <div class="float-r"><img src="img/document_mark_as_final.png" border="0" alt="Vertragsdaten bearbeiten" title="Vertragsdaten bearbeiten"/></div>
       
    13 
       
    14 <?php
       
    15 
       
    16 /**
       
    17  * @author Bettina Schwarzer, Fritz-Haber-Institut
       
    18  * @copyright 05/2011
       
    19  *
       
    20  * UPDATE/DELETE Vertragsdaten   
       
    21  */
       
    22 
       
    23     error_reporting(E_ALL ^ E_NOTICE);
       
    24     
       
    25 	include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
       
    26     include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/func_lib.inc.php");
       
    27 	$dbc = new dbconnection();
       
    28     $cid    = $_GET["uid"];
       
    29     if (!$cid) $cid=3;
       
    30 	$ok		= $_POST["ok"];
       
    31 	$upd	= $_POST["upd"];
       
    32     $del    = $_POST["del"];
       
    33     $vtr    = $_POST["vertrag"];
       
    34     if (!$vtr['okn']) $ok=false;
       
    35     
       
    36 //    print_r($vtr);
       
    37 //    echo "<br><br>\n";
       
    38 //    echo "Vertragsbezeichnung: " . $vtr['cname'] ."<br><br>\n";
       
    39     
       
    40     if (!$ok && ((!$upd && !$del) || $upd || $del))
       
    41     {
       
    42         if (!$upd && !$del)
       
    43         {
       
    44             $sql = "SELECT contract_ID,contract_name,contract_s,contract_l,vtyp_ID,contract_begin,contract_end,
       
    45                     contract_mon_notice,contract_file,Bemerkung 
       
    46                     FROM fhiiqm.Vertrag WHERE contract_ID = $cid";
       
    47             if ($result = $dbc ->queryObjectArray($sql))
       
    48             {
       
    49                 foreach ($result as $row)
       
    50                 {
       
    51                     $vtr['cname']   = $row->contract_name;
       
    52 //                    $vtr['cshort'] = $row->contract_s;
       
    53                     $vtr['clong']   = $row->contract_l;
       
    54                     $vtr['vtyp']    = $row->vtyp_ID;
       
    55                     $vtr['bjahr']   = substr($row->contract_begin,0,4);
       
    56                     $vtr['bmon']    = substr($row->contract_begin,5,2);
       
    57                     $vtr['btag']    = substr($row->contract_begin,8,2);
       
    58                     $vtr['ejahr']   = substr($row->contract_end,0,4);
       
    59                     $vtr['emon']    = substr($row->contract_end,5,2);
       
    60                     $vtr['etag']    = substr($row->contract_end,8,2);
       
    61                     $vtr['cnot']    = $row->contract_mon_notice;
       
    62                     $vtr['cfname']  = $row->contract_file;
       
    63                     $vtr['cbem']    = $row->Bemerkung;
       
    64                 }  
       
    65             }
       
    66             // Bearbeiter
       
    67             $sql = "SELECT persknr FROM Vertrag_Bearbeiter WHERE contract_ID = $cid";
       
    68             if ($result = $dbc ->queryObjectArray($sql))
       
    69             {
       
    70                 foreach ($result as $row)
       
    71                 {
       
    72                    $vtr['cpers'][] = $row->persknr; 
       
    73                 }
       
    74             }
       
    75             // Partner
       
    76             $sql = "SELECT part_ID FROM Vertrag_Partner WHERE contract_ID = $cid";
       
    77             if ($result = $dbc -> queryObjectArray($sql))
       
    78             {
       
    79                 foreach ($result as $row)
       
    80                 {
       
    81                     $vtr['partid'] = $row->part_ID;
       
    82                 }
       
    83             }
       
    84             // Produkt
       
    85             $sql = "SELECT produkt_ID FROM Produkt_Vertrag WHERE contract_ID = $cid";
       
    86             if ($result = $dbc -> queryObjectArray($sql))
       
    87             {
       
    88                 foreach ($result as $row)
       
    89                 {
       
    90                     $vtr['prodid'] = $row->produkt_ID;
       
    91                 }
       
    92             }
       
    93             // Kosten
       
    94             $sql = "SELECT kosten FROM Vertrag_Kosten WHERE contract_ID = $cid ORDER BY k_year ";
       
    95             if ($result = $dbc -> queryObjectArray($sql))
       
    96             {
       
    97                 foreach ($result as $row)
       
    98                 {
       
    99                     $vtr['kost'][] = str_replace('.',',',$row->kosten);
       
   100                 }
       
   101             }
       
   102             
       
   103         }
       
   104 
       
   105         include_once("form/vertrag_form.inc.php");
       
   106         
       
   107         if ($upd)
       
   108 		{
       
   109             echo            
       
   110             "<tr>
       
   111         		<td>Upload Vertragsdokument </td>
       
   112         		<td><input type=\"file\" name=\"vfile\" size=\"50\" maxlength=\"50\" value=\"" .
       
   113             $_FILES["vfile"]["name"] . "\"/></td>
       
   114             </tr>";
       
   115     
       
   116 		}
       
   117 	  	if ($upd || $del)
       
   118         {
       
   119             if ($upd)
       
   120               $frage = "Alle Angaben ok?<br>
       
   121               erst wenn Haken gesetzt, Upload-File w&auml;hlen!";
       
   122             elseif ($del)
       
   123                 $frage = "Vertrag wirklich l&ouml;schen?";
       
   124     		echo "<tr>
       
   125     		  <td class=\"red\" valign=\"top\" align=\"left\">$frage</td>
       
   126     		        <td><input type=\"checkbox\" name=\"ok\" value=\"1\"";
       
   127     		        if ($ok)  echo "checked"; 
       
   128     		echo "></td>\n</tr>\n"; 
       
   129         }
       
   130 		
       
   131 		echo "<tr>\n";
       
   132 		echo "
       
   133 		  <td>&nbsp;</td>
       
   134 		  <td><input class=\"button\" type=\"submit\" value=\"&auml;ndern\" name=\"upd\" title=\"update\" />
       
   135 		  &nbsp;&nbsp;&nbsp;<input class=\"button\" type=\"submit\" value=\"l&ouml;schen\" name=\"del\" title=\"delete\" /></td>\n";
       
   136 		echo "</tr>\n";
       
   137         echo "</table>\n";
       
   138         echo "</div>\n";
       
   139         echo "</form>\n";	
       
   140 
       
   141     }
       
   142     elseif ($ok && $upd)
       
   143     {
       
   144         echo "<div align='center'>\n";
       
   145         //daten speichern
       
   146         
       
   147         //UPDATE Vertrag
       
   148 /*
       
   149         if ($vtr['vtyp']== -1 || !(is_numeric($vtr['vtyp']))) $vtr['vtyp'] = "NULL";
       
   150         if ($vtr['bjahr'] && $vtr['bmon'] && $vtr['btag'])
       
   151         {
       
   152             $vbegin = $vtr['bjahr'] . "-" . $vtr['bmon'] . "-" . $vtr['btag'];
       
   153             $vbegin = "'$vbegin'";
       
   154             $vbd = $vtr['btag'] . "." . $vtr['bmon'] . "." . $vtr['bjahr']; 
       
   155         }    
       
   156         else
       
   157             $vbegin = "NULL";
       
   158         if ($vtr['ejahr'] && $vtr['emon'] && $vtr['etag'])
       
   159         {
       
   160             $vend = $vtr['ejahr'] . "-" . $vtr['emon'] . "-" . $vtr['etag'];
       
   161             $vend = "'$vend'";
       
   162             $ved = $vtr['etag'] . "." . $vtr['emon'] . "." . $vtr['ejahr']; 
       
   163         }   
       
   164         else
       
   165             $vend = "NULL";
       
   166         if (!is_numeric($vtr['cnot'])) $vtr['cnot'] = "NULL";
       
   167         if ($vtr['cbem']) $vtr['cbem'] = "'" . str_replace("'","\"",substr($vtr['cbem'],0,500)) . "'"; else $vtr['cbem']="NULL";
       
   168 */        
       
   169         $vtr['cname'] = substr($vtr['cname'],0,50);
       
   170 //        $vtr['cshort'] = substr($vtr['cshort'],0,50);
       
   171         $vtr['clong'] = substr($vtr['clong'],0,100);
       
   172         if ($vtr['vtyp']== -1 || !(is_numeric($vtr['vtyp']))) $vtr['vtyp'] = null;
       
   173         $vbegin = date_obj($vtr['bjahr'], $vtr['bmon'], $vtr['btag']);
       
   174         $vend = date_obj($vtr['ejahr'], $vtr['emon'], $vtr['etag']);
       
   175         if (!is_numeric($vtr['cnot'])) $vtr['cnot'] = null;
       
   176         if ($vtr['cbem']) $vtr['cbem'] = substr($vtr['cbem'],0,500); else $vtr['cbem']=null;
       
   177         // Filename Vertrag
       
   178         $vtr['cfname'] = substr($vtr['cfname'],0,50);
       
   179 
       
   180         if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
       
   181         
       
   182         
       
   183         // upload File, wenn vorhanden
       
   184         if (is_uploaded_file($_FILES["vfile"]["tmp_name"]) && isset($_FILES["vfile"]["name"]) && $_FILES["vfile"]["name"] )
       
   185         {
       
   186             include ("inc/file_upload.inc.php");
       
   187             $fname  = gen_filename($vtr['cfname'],"vfile",$cid);            // Dateinamen generieren
       
   188             $retdf  = mod_file("/var/www/fhiiqm/documents",$cid,"","del");  // Loeschen alte Datei
       
   189             $retf   = upload("vfile", $fname, $cid);                        // Datei prüfen und in Dokumentenverzeichnis verschieben
       
   190         }
       
   191         
       
   192         if (isset($fname) && $retf) $cfile = $cid . "_" . $fname; else $cfile = $vtr['cfname'];
       
   193 /*        
       
   194         if (isset($fname) && $retf) $cfile = "contract_file = '" . $cid . "_" . $fname . "', ";
       
   195         $sql = "UPDATE fhiiqm.Vertrag SET
       
   196                 contract_name ='" . $vtr['cname'] ."', 
       
   197 --                contract_s ='" . $vtr['cshort'] ."', 
       
   198                 contract_l ='" . $vtr['clong'] ."', 
       
   199                 vtyp_ID = " . $vtr['vtyp'] . ", 
       
   200                 contract_begin = $vbegin, 
       
   201                 contract_end = $vend, 
       
   202                 contract_mon_notice = " . $vtr['cnot'] . ", " .
       
   203                 $cfile .  
       
   204                 "Bemerkung = " . $vtr['cbem'] ." 
       
   205                 WHERE contract_ID = $cid" ;
       
   206         $retv = $dbc -> execute($sql);
       
   207 */
       
   208         $stmt = $dbc -> stmtinit();
       
   209         if (is_object($stmt))
       
   210         {
       
   211             $stmt -> prepare("UPDATE fhiiqm.Vertrag SET
       
   212                     contract_name = ?, 
       
   213                     contract_l = ?, 
       
   214                     vtyp_ID = ?, 
       
   215                     contract_begin = ?, 
       
   216                     contract_end = ?, 
       
   217                     contract_mon_notice = ?,
       
   218                     contract_file = ?,  
       
   219                     Bemerkung = ? 
       
   220                     WHERE contract_ID = $cid") ;
       
   221             $stmt -> bind_param('ssississ',$vtr["cname"],$vtr["clong"],$vtr['vtyp'],$vbegin,$vend,$vtr['cnot'],$cfile,$vtr['cbem']);
       
   222             $retv = $stmt -> execute();
       
   223         }       
       
   224 //        echo "UPDATE-sql = $sql<br />\n";
       
   225         if (!$retv) echo "error update" . $dbc -> error ."<br />\n";
       
   226         if ($retv)
       
   227         {
       
   228             // DELETE, INSERT n:m Tabellen
       
   229             include ("inc/vertragtab_ins.inc.php");
       
   230         }
       
   231 //        echo "retv=$retv, retb=$retb, retp=$retp, retd=$retd, retk=$retk<br />\n";
       
   232         if ($retv && $retb && $retp && $retd && $retk)
       
   233         {//Eingabe Daten, Upload File erfolgreich 
       
   234             echo "<p class='green'><b>Vertragsdaten zu ID '$cid' wurden erfolgreich gespeichert.</b></p>\n";
       
   235             echo "<br /><br />\n";
       
   236 
       
   237             // Anzeigen gespeicherte Vertragsdaten
       
   238             if ($fname)
       
   239                 $cfile = $cid . "_" . $fname;
       
   240             else
       
   241                 $cfile = $vtr['cfname'];
       
   242             include ("inc/vertrag_dat_show.inc.php");
       
   243         }
       
   244     }
       
   245     elseif ($ok && $del)
       
   246     {
       
   247         // DELETE aus Tab Vertrag und abhaengigen Tabellen
       
   248         echo "<div align='center'>\n";
       
   249 
       
   250         $sql = "DELETE FROM Vertrag WHERE contract_ID = $cid";
       
   251         $retvd = $dbc -> execute($sql);
       
   252         if ($retvd)
       
   253         {
       
   254             include ("inc/file_upload.inc.php");
       
   255             $retdf  = mod_file("/var/www/fhiiqm/documents",$cid,"","del");  // Loeschen Dokument
       
   256             if ($retdf) echo "<p class='green'><b>Vertragsdokument zu ID '$cid' wurde gel&ouml;scht.</b></p>\n";
       
   257             echo "<p class='green'><b>Vertragsdaten zu ID '$cid' wurden gel&ouml;scht.</b></p>\n";
       
   258             echo "<br /><br />\n";
       
   259 
       
   260             // Anzeigen geloeschter Vertragsdaten
       
   261             if ($fname)
       
   262                 $cfile = $cid . "_" . $fname;
       
   263             else
       
   264                 $cfile = $vtr['cfname'];
       
   265             include ("inc/vertrag_dat_show.inc.php");
       
   266         }
       
   267     }
       
   268     if ($ok && ($upd || $del))
       
   269     {
       
   270         echo "</div><br /><br />\n";
       
   271         echo "<p>&nbsp;&nbsp;&nbsp;<a href=\"vertrag_flist1.php\" target=\"_self\" title=\"Vertragsliste\">Zur&uuml;ck zur Vertragsliste</a></p>\n";    
       
   272         echo "<p>&nbsp;&nbsp;&nbsp;<a href=\"vertrag_ins.php\" target=\"_self\" title=\"Vertrag erfassen\">Weiteren Vertrag erfassen</a></p>\n";    
       
   273     }
       
   274     
       
   275 ?>
       
   276 
       
   277 </body>
       
   278 </html>