fhiiqm/vertrag_ins.php
author Bettina Schwarzer
Fri, 05 Feb 2016 14:03:40 +0100
changeset 44 d652bbba2d43
parent 31 0a1eb975fbd9
permissions -rw-r--r--
fhiiqm: achilleus -> db2, Korrekturen

<?php

/**
 * @author Bettina Schwarzer, Fritz-Haber-Institut
 * @copyright 05/2011
 *
 * INSERT Vertragsdaten   
 */

    error_reporting(E_ALL ^ E_NOTICE);
    
    session_start();
    if (! isset($_SESSION["userid"]))
    { 
        include_once ("inc/func_lib.inc.php");	
        login("vertrag_ins.php");
        exit;
    }
    
    if (is_null($_SESSION["recht"]) || (!is_null($_SESSION["recht"]) && !in_array("ve",$_SESSION["recht"])))
    {
        header("Location: start.php");
        exit;
    }    
    
?>
    
<!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" media="screen"/> 
   	<link href="css/db_print.css" rel="STYLESHEET" type="TEXT/CSS" media="print"/> 

	<title>Eingabe Vertragsdaten</title>
</head>

<body>
    
<?php
    echo "&nbsp;";  
    echo "<div class=\"float-br smaller\" valign='top'>";
    echo "&nbsp;&nbsp;&nbsp;user: " . $_SESSION["userid"];
    echo "&nbsp;&nbsp;&nbsp;<a class='sc' href='/fhiiqm/logout.php' title='Session beenden'>logout</a></div>\n";
    echo "<div class=\"float-r\"><img src=\"img/document_mark_as_final.png\" border=\"0\" alt=\"Vertragsdaten eingeben\" title=\"Vertragsdaten eingeben\"/></div>\n";

	include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
    include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/func_lib.inc.php");
	//$dbc = new dbconnection();
    
	$ok		= $_POST["ok"];
	$submit	= $_POST["ins"];
    $vtr    = $_POST["vertrag"];
    if (!$vtr['okn']) $ok=false;
    
//    print_r($vtr);
//    echo "<br><br>\n";
//    echo "Vertragsbezeichnung: " . $vtr['cname'] ."<br><br>\n";

    if ($_FILES["vfile"]["error"] == 1 || $_FILES["vfile"]["error"] == 2)
    {
        if ($_FILES["vfile"]["error"] == 2)
            echo "<p class='red'><b>Uploadfile > 10 MByte!</b></p>\n";
        $ok = 0;
    }
    
    if (!$ok || !$submit)
    {
        include_once("form/vertrag_form.inc.php");
        
        if ($submit)
		{
            echo            
            "<tr>
        		<td>Upload Vertragsdokument </td>
        		<td><input type=\"file\" name=\"vfile\" size=\"50\" maxlength=\"50\" value=\"" .
            $_FILES["vfile"]["name"] . "\"/></td>
            </tr>";
    
		  	$frage = "Alle Angaben ok?<br>
              erst wenn Haken gesetzt, Upload-File w&auml;hlen!";
			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"; 
		}
		
        if (!is_null($_SESSION["recht"]) && in_array("ve",$_SESSION["recht"]))
        {
    		echo "<tr>\n";
    		echo "
    		  <td>&nbsp;</td>
    		  <td><input class=\"button\" type=\"submit\" value=\"eingeben\" name=\"ins\" title=\"insert\" /></td>\n";
    		echo "</tr>\n";
        }    
        echo "</table>\n";
        echo "</div>\n";
        echo "</form>\n";	

    }
    else
    {
        echo "<div align='center'>\n";
        //daten speichern
//            echo "1realer filename: " . $_FILES["vfile"]["name"] . "<br><br>\n";
        //INSERT 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();
      
/*        $sql = "INSERT INTO Vertrag (contract_name, contract_l,vtyp_ID,contract_begin, contract_end,contract_mon_notice,
                    contract_file,bemerkung) 
                    VALUES('" . $vtr['cname'] .
                    "', '" . $vtr['clong'] .
                    "', " . $vtr['vtyp'] .
                    ", " . $vbegin .
                    ", " . $vend .
                    ", " . $vtr['cnot'] .
                    ", '" . $vtr['cfname'] .
                    "', " . $vtr['cbem'] .
                    ")";
                    
//        echo "INSERT = $sql<br />\n";

        $result=$dbc->execute($sql);
*/
        $stmt = $dbc -> stmtinit();
        if (is_object($stmt))
        {
            $stmt -> prepare("INSERT INTO Vertrag (contract_name, contract_l,vtyp_ID,contract_begin, contract_end, contract_autoend, 
                    contract_mon_notice, bemerkung,email_send) 
                    VALUES(?,?,?,?,?,?,?,?,?)");
            $stmt -> bind_param('ssissiisi',$vtr["cname"],$vtr["clong"],$vtr['vtyp'],$vbegin,$vend,$vtr['cautoend'],$vtr['cnot'],$vtr['cbem'],$vtr["email"]);
            $result = $stmt -> execute();
        }       
        if ($stmt->error) echo "INSERT Vertrag, error: " . $stmt->errno . " - ". $stmt->error . "<br><br>\n";
        if ($result)
        { // INSERT o.k.
          // contract_ID ermitteln
            $cid = $dbc -> insertId();

            // DELETE, INSERT n:m Tabellen
            include ("inc/vertragtab_ins.inc.php");
            
            // upload File
            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);
                $ret = upload("vfile", $fname, $cid);
                
                if ($ret)
                {   // upload o.k.
                    //UPDATE des Filenamens
                    $sql = "UPDATE Vertrag SET contract_file = '" . $cid . "_" . $fname ."' WHERE contract_ID=$cid";
                    $retv=$dbc->execute($sql);
                    if (!$retv) 
                        echo $dbc -> error . "<br>\n";
                }
               
            }
            else
            {   // upload failed
                //UPDATE des Filenamens
                echo "<p class='red'>Upload von '" . $vtr['cfname'] . "' ist fehlgeschlagen. (max. 6 MB)</p>";
                $sql = "UPDATE Vertrag SET contract_file = NULL WHERE contract_ID=$cid";
                $retv=$dbc->execute($sql);
                if (!$retv) 
                    echo $dbc -> error . "<br>\n";
            }
            
            if ($retb && $retp && $retd && $retk) // INSERT n:m Tabellen zu Vertrag
            {
                    //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 = "";
                        include ("inc/vertrag_dat_show.inc.php");
            }            
        }
        $dbc -> close();
        echo "</div>\n";
        echo "<p class='sc'>&nbsp;&nbsp;&nbsp;<a href=\"vertrag_flist1.php\" target=\"_self\" title=\"Vertragsliste\">Zur Vertragsliste</a></p>\n";    
        echo "<p class='sc'>&nbsp;&nbsp;&nbsp;<a href=\"vertrag_ins.php\" target=\"_self\" title=\"Vertrag erfassen\">Weiteren Vertrag erfassen</a></p>\n";    

    }

?>

</body>
</html>