fhiiqm/vertrag_ins.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>Eingabe Vertragsdaten</title>
       
     9 </head>
       
    10 
       
    11 <body>
       
    12     <div class="float-r"><img src="img/document_mark_as_final.png" border="0" alt="Vertragsdaten eingeben" title="Vertragsdaten eingeben"/></div>
       
    13 
       
    14 <?php
       
    15 
       
    16 /**
       
    17  * @author Bettina Schwarzer, Fritz-Haber-Institut
       
    18  * @copyright 05/2011
       
    19  *
       
    20  * INSERT 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     
       
    29 	$ok		= $_POST["ok"];
       
    30 	$submit	= $_POST["ins"];
       
    31     $vtr    = $_POST["vertrag"];
       
    32     if (!$vtr['okn']) $ok=false;
       
    33     
       
    34 //    print_r($vtr);
       
    35 //    echo "<br><br>\n";
       
    36 //    echo "Vertragsbezeichnung: " . $vtr['cname'] ."<br><br>\n";
       
    37     
       
    38     if (!$ok || !$submit)
       
    39     {
       
    40         include_once("form/vertrag_form.inc.php");
       
    41         
       
    42         if ($submit)
       
    43 		{
       
    44             echo            
       
    45             "<tr>
       
    46         		<td>Upload Vertragsdokument </td>
       
    47         		<td><input type=\"file\" name=\"vfile\" size=\"50\" maxlength=\"50\" value=\"" .
       
    48             $_FILES["vfile"]["name"] . "\"/></td>
       
    49             </tr>";
       
    50     
       
    51 		  	$frage = "Alle Angaben ok?<br>
       
    52               erst wenn Haken gesetzt, Upload-File w&auml;hlen!";
       
    53 			echo "<tr>
       
    54 			  <td class=\"red\" valign=\"top\" align=\"left\">$frage</td>
       
    55 			        <td><input type=\"checkbox\" name=\"ok\" value=\"1\"";
       
    56 			        if ($ok)  echo "checked"; 
       
    57 			echo "></td>\n</tr>\n"; 
       
    58 		}
       
    59 		
       
    60 		echo "<tr>\n";
       
    61 		echo "
       
    62 		  <td>&nbsp;</td>
       
    63 		  <td><input class=\"button\" type=\"submit\" value=\"eingeben\" name=\"ins\" title=\"insert\" /></td>\n";
       
    64 		echo "</tr>\n";
       
    65         echo "</table>\n";
       
    66         echo "</div>\n";
       
    67         echo "</form>\n";	
       
    68 
       
    69     }
       
    70     else
       
    71     {
       
    72         echo "<div align='center'>\n";
       
    73         //daten speichern
       
    74 //            echo "1realer filename: " . $_FILES["vfile"]["name"] . "<br><br>\n";
       
    75         //INSERT Vertrag
       
    76 /*
       
    77         if ($vtr['vtyp']== -1 || !(is_numeric($vtr['vtyp']))) $vtr['vtyp'] = "NULL";
       
    78         if ($vtr['bjahr'] && $vtr['bmon'] && $vtr['btag'])
       
    79         {
       
    80             $vbegin = $vtr['bjahr'] . "-" . $vtr['bmon'] . "-" . $vtr['btag'];
       
    81             $vbegin = "'$vbegin'";
       
    82             $vbd = $vtr['btag'] . "." . $vtr['bmon'] . "." . $vtr['bjahr']; 
       
    83         }    
       
    84         else
       
    85             $vbegin = "NULL";
       
    86         if ($vtr['ejahr'] && $vtr['emon'] && $vtr['etag'])
       
    87         {
       
    88             $vend = $vtr['ejahr'] . "-" . $vtr['emon'] . "-" . $vtr['etag'];
       
    89             $vend = "'$vend'";
       
    90             $ved = $vtr['etag'] . "." . $vtr['emon'] . "." . $vtr['ejahr']; 
       
    91         }   
       
    92         else
       
    93             $vend = "NULL";
       
    94         if (!is_numeric($vtr['cnot'])) $vtr['cnot'] = "NULL";
       
    95         if ($vtr['cbem']) $vtr['cbem'] = "'" . str_replace("'","\"",substr($vtr['cbem'],0,500)) . "'"; else $vtr['cbem']="NULL";
       
    96 */
       
    97         $vtr['cname'] = substr($vtr['cname'],0,50);
       
    98 //        $vtr['cshort'] = substr($vtr['cshort'],0,50);
       
    99         $vtr['clong'] = substr($vtr['clong'],0,100);
       
   100         if ($vtr['vtyp']== -1 || !(is_numeric($vtr['vtyp']))) $vtr['vtyp'] = null;
       
   101         $vbegin = date_obj($vtr['bjahr'], $vtr['bmon'], $vtr['btag']);
       
   102         $vend = date_obj($vtr['ejahr'], $vtr['emon'], $vtr['etag']);
       
   103         if (!is_numeric($vtr['cnot'])) $vtr['cnot'] = null;
       
   104         if ($vtr['cbem']) $vtr['cbem'] = substr($vtr['cbem'],0,500); else $vtr['cbem']=null;
       
   105         // Filename Vertrag
       
   106         $vtr['cfname'] = substr($vtr['cfname'],0,50);
       
   107 
       
   108         if (!isset($dbc) || !$dbc) 
       
   109             $dbc = new dbconnection();
       
   110       
       
   111 /*        $sql = "INSERT INTO Vertrag (contract_name, contract_l,vtyp_ID,contract_begin, contract_end,contract_mon_notice,
       
   112                     contract_file,bemerkung) 
       
   113                     VALUES('" . $vtr['cname'] .
       
   114                     "', '" . $vtr['clong'] .
       
   115                     "', " . $vtr['vtyp'] .
       
   116                     ", " . $vbegin .
       
   117                     ", " . $vend .
       
   118                     ", " . $vtr['cnot'] .
       
   119                     ", '" . $vtr['cfname'] .
       
   120                     "', " . $vtr['cbem'] .
       
   121                     ")";
       
   122                     
       
   123 //        echo "INSERT = $sql<br />\n";
       
   124 
       
   125         $result=$dbc->execute($sql);
       
   126 */
       
   127         $stmt = $dbc -> stmtinit();
       
   128         if (is_object($stmt))
       
   129         {
       
   130             $stmt -> prepare("INSERT INTO Vertrag (contract_name, contract_l,vtyp_ID,contract_begin, contract_end,contract_mon_notice,
       
   131                     contract_file,bemerkung) 
       
   132                     VALUES(?,?,?,?,?,?,?,?)");
       
   133             $stmt -> bind_param('ssississ',$vtr["cname"],$vtr["clong"],$vtr['vtyp'],$vbegin,$vend,$vtr['cnot'],$cfile,$vtr['cbem']);
       
   134             $result = $stmt -> execute();
       
   135         }       
       
   136         if ($dbc->error) echo "error: " . $dbc->error . "<br><br>\n";
       
   137         if ($result)
       
   138         { // INSERT o.k.
       
   139           // contract_ID ermitteln
       
   140             $cid = $dbc -> insertId();
       
   141 
       
   142             // DELETE, INSERT n:m Tabellen
       
   143             include ("inc/vertragtab_ins.inc.php");
       
   144             
       
   145             // upload File
       
   146             if (is_uploaded_file($_FILES["vfile"]["tmp_name"]) && isset($_FILES["vfile"]["name"]) && $_FILES["vfile"]["name"] )
       
   147             {
       
   148                 include ("inc/file_upload.inc.php");
       
   149                 $fname = gen_filename($vtr['cfname'],"vfile",$cid);
       
   150                 $ret = upload("vfile", $fname, $cid);
       
   151                 
       
   152                 if ($ret)
       
   153                 {   // upload o.k.
       
   154                     //UPDATE des Filenamens
       
   155                     $sql = "UPDATE Vertrag SET contract_file = '" . $cid . "_" . $fname ."' WHERE contract_ID=$cid";
       
   156                     $retv=$dbc->execute($sql);
       
   157                     if (!$retv) 
       
   158                         echo $dbc -> error . "<br>\n";
       
   159                 }
       
   160                
       
   161             }
       
   162             else
       
   163             {   // upload failed
       
   164                 //UPDATE des Filenamens
       
   165                 $sql = "UPDATE Vertrag SET contract_file = NULL WHERE contract_ID=$cid";
       
   166                 $retv=$dbc->execute($sql);
       
   167                 if (!$retv) 
       
   168                     echo $dbc -> error . "<br>\n";
       
   169             }
       
   170             
       
   171             if ($retb && $retp && $retd && $retk) // INSERT n:m Tabellen zu Vertrag
       
   172             {
       
   173                     //Eingabe Daten, Upload File erfolgreich 
       
   174                         echo "<p class='green'><b>Vertragsdaten zu ID '$cid' wurden erfolgreich gespeichert.</b></p>\n";
       
   175                         echo "<br /><br />\n";
       
   176     
       
   177                         // Anzeigen gespeicherte Vertragsdaten
       
   178                         if ($fname)
       
   179                             $cfile = $cid . "_" . $fname;
       
   180                         else
       
   181                             $cfile = "";
       
   182                         include ("inc/vertrag_dat_show.inc.php");
       
   183             }            
       
   184         }
       
   185         $dbc -> close();
       
   186         echo "</div>\n";
       
   187         echo "<p>&nbsp;&nbsp;&nbsp;<a href=\"vertrag_flist1.php\" target=\"_self\" title=\"Vertragsliste\">Zur Vertragsliste</a></p>\n";    
       
   188         echo "<p>&nbsp;&nbsp;&nbsp;<a href=\"vertrag_ins.php\" target=\"_self\" title=\"Vertrag erfassen\">Weiteren Vertrag erfassen</a></p>\n";    
       
   189 
       
   190     }
       
   191 
       
   192 ?>
       
   193 
       
   194 </body>
       
   195 </html>