fhiiqm/deprecated/vertrag_ins.php
changeset 43 70cea8f0e807
equal deleted inserted replaced
42:cfc409017ba8 43:70cea8f0e807
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * @author Bettina Schwarzer, Fritz-Haber-Institut
       
     5  * @copyright 05/2011
       
     6  *
       
     7  * INSERT Vertragsdaten   
       
     8  */
       
     9 
       
    10     error_reporting(E_ALL ^ E_NOTICE);
       
    11     
       
    12     session_start();
       
    13     if (! isset($_SESSION["userid"]))
       
    14     { 
       
    15         include_once ("inc/func_lib.inc.php");	
       
    16         login("vertrag_ins.php");
       
    17         exit;
       
    18     }
       
    19     
       
    20     if (is_null($_SESSION["recht"]) || (!is_null($_SESSION["recht"]) && !in_array("ve",$_SESSION["recht"])))
       
    21     {
       
    22         header("Location: start.php");
       
    23         exit;
       
    24     }    
       
    25     
       
    26 ?>
       
    27     
       
    28 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       
    29 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
       
    30 
       
    31 <head>
       
    32 	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
       
    33    	<link href="css/db.css" rel="STYLESHEET" type="TEXT/CSS" media="screen"/> 
       
    34    	<link href="css/db_print.css" rel="STYLESHEET" type="TEXT/CSS" media="print"/> 
       
    35 
       
    36 	<title>Eingabe Vertragsdaten</title>
       
    37 </head>
       
    38 
       
    39 <body>
       
    40     
       
    41 <?php
       
    42     echo "&nbsp;";  
       
    43     echo "<div class=\"float-br smaller\" valign='top'>";
       
    44     echo "&nbsp;&nbsp;&nbsp;user: " . $_SESSION["userid"];
       
    45     echo "&nbsp;&nbsp;&nbsp;<a class='sc' href='/fhiiqm/logout.php' title='Session beenden'>logout</a></div>\n";
       
    46     echo "<div class=\"float-r\"><img src=\"img/document_mark_as_final.png\" border=\"0\" alt=\"Vertragsdaten eingeben\" title=\"Vertragsdaten eingeben\"/></div>\n";
       
    47 
       
    48 	include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
       
    49     include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/func_lib.inc.php");
       
    50 	//$dbc = new dbconnection();
       
    51     
       
    52 	$ok		= $_POST["ok"];
       
    53 	$submit	= $_POST["ins"];
       
    54     $vtr    = $_POST["vertrag"];
       
    55     if (!$vtr['okn']) $ok=false;
       
    56     
       
    57 //    print_r($vtr);
       
    58 //    echo "<br><br>\n";
       
    59 //    echo "Vertragsbezeichnung: " . $vtr['cname'] ."<br><br>\n";
       
    60 
       
    61     if ($_FILES["vfile"]["error"] == 1 || $_FILES["vfile"]["error"] == 2)
       
    62     {
       
    63         if ($_FILES["vfile"]["error"] == 2)
       
    64             echo "<p class='red'><b>Uploadfile > 10 MByte!</b></p>\n";
       
    65         $ok = 0;
       
    66     }
       
    67     
       
    68     if (!$ok || !$submit)
       
    69     {
       
    70         include_once("form/vertrag_form.inc.php");
       
    71         
       
    72         if ($submit)
       
    73 		{
       
    74             echo            
       
    75             "<tr>
       
    76         		<td>Upload Vertragsdokument </td>
       
    77         		<td><input type=\"file\" name=\"vfile\" size=\"50\" maxlength=\"50\" value=\"" .
       
    78             $_FILES["vfile"]["name"] . "\"/></td>
       
    79             </tr>";
       
    80     
       
    81 		  	$frage = "Alle Angaben ok?<br>
       
    82               erst wenn Haken gesetzt, Upload-File w&auml;hlen!";
       
    83 			echo "<tr>
       
    84 			  <td class=\"red\" valign=\"top\" align=\"left\">$frage</td>
       
    85 			        <td><input type=\"checkbox\" name=\"ok\" value=\"1\"";
       
    86 			        if ($ok)  echo "checked"; 
       
    87 			echo "></td>\n</tr>\n"; 
       
    88 		}
       
    89 		
       
    90         if (!is_null($_SESSION["recht"]) && in_array("ve",$_SESSION["recht"]))
       
    91         {
       
    92     		echo "<tr>\n";
       
    93     		echo "
       
    94     		  <td>&nbsp;</td>
       
    95     		  <td><input class=\"button\" type=\"submit\" value=\"eingeben\" name=\"ins\" title=\"insert\" /></td>\n";
       
    96     		echo "</tr>\n";
       
    97         }    
       
    98         echo "</table>\n";
       
    99         echo "</div>\n";
       
   100         echo "</form>\n";	
       
   101 
       
   102     }
       
   103     else
       
   104     {
       
   105         echo "<div align='center'>\n";
       
   106         //daten speichern
       
   107 //            echo "1realer filename: " . $_FILES["vfile"]["name"] . "<br><br>\n";
       
   108         //INSERT Vertrag
       
   109 /*
       
   110         if ($vtr['vtyp']== -1 || !(is_numeric($vtr['vtyp']))) $vtr['vtyp'] = "NULL";
       
   111         if ($vtr['bjahr'] && $vtr['bmon'] && $vtr['btag'])
       
   112         {
       
   113             $vbegin = $vtr['bjahr'] . "-" . $vtr['bmon'] . "-" . $vtr['btag'];
       
   114             $vbegin = "'$vbegin'";
       
   115             $vbd = $vtr['btag'] . "." . $vtr['bmon'] . "." . $vtr['bjahr']; 
       
   116         }    
       
   117         else
       
   118             $vbegin = "NULL";
       
   119         if ($vtr['ejahr'] && $vtr['emon'] && $vtr['etag'])
       
   120         {
       
   121             $vend = $vtr['ejahr'] . "-" . $vtr['emon'] . "-" . $vtr['etag'];
       
   122             $vend = "'$vend'";
       
   123             $ved = $vtr['etag'] . "." . $vtr['emon'] . "." . $vtr['ejahr']; 
       
   124         }   
       
   125         else
       
   126             $vend = "NULL";
       
   127         if (!is_numeric($vtr['cnot'])) $vtr['cnot'] = "NULL";
       
   128         if ($vtr['cbem']) $vtr['cbem'] = "'" . str_replace("'","\"",substr($vtr['cbem'],0,500)) . "'"; else $vtr['cbem']="NULL";
       
   129 */
       
   130         $vtr['cname'] = substr($vtr['cname'],0,50);
       
   131 //        $vtr['cshort'] = substr($vtr['cshort'],0,50);
       
   132         $vtr['clong'] = substr($vtr['clong'],0,100);
       
   133         if ($vtr['vtyp']== -1 || !(is_numeric($vtr['vtyp']))) $vtr['vtyp'] = null;
       
   134         $vbegin = date_obj($vtr['bjahr'], $vtr['bmon'], $vtr['btag']);
       
   135         $vend = date_obj($vtr['ejahr'], $vtr['emon'], $vtr['etag']);
       
   136         if (!is_numeric($vtr['cnot'])) $vtr['cnot'] = null;
       
   137         if ($vtr['cbem']) $vtr['cbem'] = substr($vtr['cbem'],0,500); else $vtr['cbem']=null;
       
   138         // Filename Vertrag
       
   139         $vtr['cfname'] = substr($vtr['cfname'],0,50);
       
   140 
       
   141         if (!isset($dbc) || !$dbc) 
       
   142             $dbc = new dbconnection();
       
   143       
       
   144 /*        $sql = "INSERT INTO Vertrag (contract_name, contract_l,vtyp_ID,contract_begin, contract_end,contract_mon_notice,
       
   145                     contract_file,bemerkung) 
       
   146                     VALUES('" . $vtr['cname'] .
       
   147                     "', '" . $vtr['clong'] .
       
   148                     "', " . $vtr['vtyp'] .
       
   149                     ", " . $vbegin .
       
   150                     ", " . $vend .
       
   151                     ", " . $vtr['cnot'] .
       
   152                     ", '" . $vtr['cfname'] .
       
   153                     "', " . $vtr['cbem'] .
       
   154                     ")";
       
   155                     
       
   156 //        echo "INSERT = $sql<br />\n";
       
   157 
       
   158         $result=$dbc->execute($sql);
       
   159 */
       
   160         $stmt = $dbc -> stmtinit();
       
   161         if (is_object($stmt))
       
   162         {
       
   163             $stmt -> prepare("INSERT INTO Vertrag (contract_name, contract_l,vtyp_ID,contract_begin, contract_end, contract_autoend, 
       
   164                     contract_mon_notice, bemerkung,email_send) 
       
   165                     VALUES(?,?,?,?,?,?,?,?,?)");
       
   166             $stmt -> bind_param('ssissiisi',$vtr["cname"],$vtr["clong"],$vtr['vtyp'],$vbegin,$vend,$vtr['cautoend'],$vtr['cnot'],$vtr['cbem'],$vtr["email"]);
       
   167             $result = $stmt -> execute();
       
   168         }       
       
   169         if ($stmt->error) echo "INSERT Vertrag, error: " . $stmt->errno . " - ". $stmt->error . "<br><br>\n";
       
   170         if ($result)
       
   171         { // INSERT o.k.
       
   172           // contract_ID ermitteln
       
   173             $cid = $dbc -> insertId();
       
   174 
       
   175             // DELETE, INSERT n:m Tabellen
       
   176             include ("inc/vertragtab_ins.inc.php");
       
   177             
       
   178             // upload File
       
   179             if (is_uploaded_file($_FILES["vfile"]["tmp_name"]) && isset($_FILES["vfile"]["name"]) && $_FILES["vfile"]["name"] )
       
   180             {
       
   181                 include ("inc/file_upload.inc.php");
       
   182                 $fname = gen_filename($vtr['cfname'],"vfile",$cid);
       
   183                 $ret = upload("vfile", $fname, $cid);
       
   184                 
       
   185                 if ($ret)
       
   186                 {   // upload o.k.
       
   187                     //UPDATE des Filenamens
       
   188                     $sql = "UPDATE Vertrag SET contract_file = '" . $cid . "_" . $fname ."' WHERE contract_ID=$cid";
       
   189                     $retv=$dbc->execute($sql);
       
   190                     if (!$retv) 
       
   191                         echo $dbc -> error . "<br>\n";
       
   192                 }
       
   193                
       
   194             }
       
   195             else
       
   196             {   // upload failed
       
   197                 //UPDATE des Filenamens
       
   198                 echo "<p class='red'>Upload von '" . $vtr['cfname'] . "' ist fehlgeschlagen. (max. 6 MB)</p>";
       
   199                 $sql = "UPDATE Vertrag SET contract_file = NULL WHERE contract_ID=$cid";
       
   200                 $retv=$dbc->execute($sql);
       
   201                 if (!$retv) 
       
   202                     echo $dbc -> error . "<br>\n";
       
   203             }
       
   204             
       
   205             if ($retb && $retp && $retd && $retk) // INSERT n:m Tabellen zu Vertrag
       
   206             {
       
   207                     //Eingabe Daten, Upload File erfolgreich 
       
   208                         echo "<p class='green'><b>Vertragsdaten zu ID '$cid' wurden erfolgreich gespeichert.</b></p>\n";
       
   209                         echo "<br /><br />\n";
       
   210     
       
   211                         // Anzeigen gespeicherte Vertragsdaten
       
   212                         if ($fname)
       
   213                             $cfile = $cid . "_" . $fname;
       
   214                         else
       
   215                             $cfile = "";
       
   216                         include ("inc/vertrag_dat_show.inc.php");
       
   217             }            
       
   218         }
       
   219         $dbc -> close();
       
   220         echo "</div>\n";
       
   221         echo "<p class='sc'>&nbsp;&nbsp;&nbsp;<a href=\"vertrag_flist1.php\" target=\"_self\" title=\"Vertragsliste\">Zur Vertragsliste</a></p>\n";    
       
   222         echo "<p class='sc'>&nbsp;&nbsp;&nbsp;<a href=\"vertrag_ins.php\" target=\"_self\" title=\"Vertrag erfassen\">Weiteren Vertrag erfassen</a></p>\n";    
       
   223 
       
   224     }
       
   225 
       
   226 ?>
       
   227 
       
   228 </body>
       
   229 </html>