fhiiqm/alpruef_ed.php
changeset 19 33ee23fafd4d
child 20 5877137431e4
equal deleted inserted replaced
18:d0aa14180761 19:33ee23fafd4d
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * @author Bettina Schwarzer, Fritz-Haber-Institut
       
     5  * @copyright 12/2011
       
     6  */
       
     7 
       
     8     error_reporting(E_ALL ^ E_NOTICE);
       
     9     
       
    10     session_start();
       
    11     if (! isset($_SESSION["userid"]))
       
    12     { 
       
    13         include_once ("inc/func_lib.inc.php");	
       
    14         login($_SERVER["PHP_SELF"]);
       
    15         exit;
       
    16     }
       
    17     
       
    18     if (is_null($_SESSION["recht"]) || (!is_null($_SESSION["recht"]) && !in_array("ar",$_SESSION["recht"]) && !in_array("ae",$_SESSION["recht"])))
       
    19     {
       
    20         header("Location: start.php");
       
    21         exit;
       
    22     }    
       
    23     
       
    24     include_once($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/inc/dbconnect.inc.php");
       
    25     if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
       
    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 type="text/css" href="/fhiiqm/css/db.css" rel="Stylesheet" />	
       
    34     <link type="text/css" href="/fhiiqm/css/jquery/ui-lightness/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />	
       
    35     <script type="text/javascript" src="/fhiiqm/js/jquery/jquery-1.6.2.min.js"></script>
       
    36     <script type="text/javascript" src="/fhiiqm/js/jquery/jquery-ui-1.8.16.custom.min.js"></script>
       
    37     <title>Anlage Pruefung</title>
       
    38  </head>
       
    39  
       
    40  <body>
       
    41 
       
    42 <?php
       
    43     echo "&nbsp;";  
       
    44     echo "<div class=\"float-br smaller\" valign='top'>";
       
    45     echo "&nbsp;&nbsp;&nbsp;user: " . $_SESSION["userid"];
       
    46     echo "&nbsp;&nbsp;&nbsp;<a class='sc' href='/fhiiqm/logout.php' title='Session beenden'>logout</a></div>\n";
       
    47     echo "<div class=\"float-r\"><img src=\"img/rotate_01.png\" border=\"0\" alt=\"Anlage\" title=\"Anlage\"/></div>\n";
       
    48 ?>
       
    49 
       
    50     <div align='center'>
       
    51 
       
    52     <script>
       
    53       $(document).ready(function() {
       
    54         $("#albez").focus();
       
    55         $("#albez").autocomplete({
       
    56                 source: "/fhiiqm/inc/al_list_ac.inc.php",
       
    57     			minLength: 2,
       
    58                 select: function(event,ui){$("#alid").val(ui.item.id);}
       
    59     		});
       
    60         $("#alpdat").datepicker({
       
    61             dateFormat: 'yy-mm-dd 00:00:00', //damit kann auch Uhrzeit angegeben werden
       
    62             yearRange: '2000:2020',
       
    63             changeMonth: true,
       
    64 			changeYear: true,
       
    65             firstDay: 1,
       
    66             dayNamesMin: ['So','Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa' ],
       
    67             monthNamesShort: ['Jan','Feb','Mar','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'] 
       
    68         });
       
    69         $("input").albez("long20").addClass("long20");
       
    70         $("input").alpdat("long10").addClass("long10");
       
    71         });
       
    72     </script>
       
    73 <?php
       
    74         $al     = $_POST["al"];
       
    75         $alpid   = $_GET["i"];
       
    76         $sub    = $_POST["eintragen"];
       
    77     	$ok		= $_POST["ok"];
       
    78         if (!$al['okn']) $ok=false;
       
    79 //        print_r($al);
       
    80         
       
    81         if ($alpid) $text = "editieren"; else $text = "erfassen";
       
    82         echo "<h3>Pr&uuml;fung Anlage $text<h3>";
       
    83         
       
    84         echo "</div>\n";
       
    85         
       
    86         if (!$ok || !$sub)
       
    87         {
       
    88             // form anzeigen
       
    89             if ($alpid && !$sub)
       
    90             {
       
    91                 // Inhalte zu Pruefung holen
       
    92                 $sql = "SELECT p.al_ID,al_bez,pruef_date,pruef_file,pruef_bem 
       
    93                         FROM fhiiqm.A_Pruefung p INNER JOIN fhiiqm.Anlage a ON p.al_ID=a.al_ID
       
    94                         WHERE alp_ID = $alpid";
       
    95                 if ($result = $dbc -> queryObjectArray($sql))
       
    96                 {
       
    97                     foreach ($result as $row)
       
    98                     {
       
    99                         $al["id"]   = $row->al_ID;
       
   100                         $al["bez"]  = $row->al_bez;
       
   101                         $al["pdat"] = $row->pruef_date;
       
   102                         $al["bem"]  = $row->pruef_bem;
       
   103                         $al["pfname"]  = $row->pruef_file;
       
   104                     }
       
   105                 }
       
   106             }
       
   107             include ($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/form/alpruef_form.inc.php");     
       
   108             if ($sub)
       
   109     		{
       
   110             echo            
       
   111             "<tr>
       
   112         		<td>Upload  Protokoll </td>
       
   113         		<td><input type=\"file\" name=\"pfile\" size=\"50\" maxlength=\"50\" value=\"" .
       
   114             $_FILES["pfile"]["name"] . "\"/></td>
       
   115             </tr>";
       
   116     		  	$frage = "Alle Angaben ok?<br>
       
   117                         erst wenn Haken gesetzt, Upload-File w&auml;hlen!";
       
   118     			echo "<tr>
       
   119     			  <td class=\"red\" valign=\"top\" align=\"left\">$frage</td>
       
   120     			        <td><input type=\"checkbox\" name=\"ok\" value=\"1\"";
       
   121     			        if ($ok)  echo "checked"; 
       
   122     			echo "></td>\n</tr>\n"; 
       
   123     		}
       
   124             if (!is_null($_SESSION["recht"]) && in_array("ae",$_SESSION["recht"]))
       
   125             {
       
   126                 echo "
       
   127                	<tr><td>&nbsp;</td>\n
       
   128                 	<td><input  class=\"button\" type=\"submit\" name=\"eintragen\" value=\"  eintragen  \" /></td>\n
       
   129                	</tr>\n";
       
   130             }
       
   131             echo "</table>\n";
       
   132             echo "</div>\n";
       
   133             if (!is_null($_SESSION["recht"]) && !in_array("ae", $_SESSION["recht"]))
       
   134                 echo "<p>&nbsp;&nbsp;&nbsp;<a href=\"alpruef_flist.php\" target=\"_self\" title=\"Anlagen pruefen\">&laquo; zur Liste der Anlagenpr&uuml;fungen</a></p>\n"; 
       
   135             echo "</form>\n";   
       
   136         }
       
   137         else
       
   138         {
       
   139             // Daten speichern
       
   140             echo "<div align='center'>\n";
       
   141             // alte Bezeichnung Protokoll holen
       
   142             $sql = "SELECT pruef_file
       
   143                     FROM fhiiqm.A_Pruefung
       
   144                     WHERE alp_ID = $alpid";
       
   145             if ($result = $dbc -> queryObjectArray($sql))
       
   146                 foreach ($result as $row) $al["pfname_old"]  = $row->pruef_file;
       
   147                 
       
   148             if ($alpid)
       
   149             {
       
   150                 //update
       
   151                 // upload File
       
   152                 if (is_uploaded_file($_FILES["pfile"]["tmp_name"]) && isset($_FILES["pfile"]["name"]) && $_FILES["pfile"]["name"] )
       
   153                 {
       
   154                     include ("inc/file_upload.inc.php");
       
   155                     if ($al['pfname']<"!") $al['pfname']="al_pruefung";
       
   156                     $fname  = gen_filename($al['pfname'],"pfile",$alpid);
       
   157                     $retdf  = mod_file("/var/www/fhiiqm/alprot",$alpid,"","del");  // Loeschen alte Datei
       
   158                     $retf   = upload("pfile", $fname, $alpid, "alprot");           // Datei prüfen und in Dokumentenverzeichnis verschieben
       
   159                     if ($retf) 
       
   160                     {
       
   161                         $sql = "UPDATE A_Pruefung SET pruef_file = '" . $alpid . "_" . $fname ."' WHERE alp_ID=$alpid";
       
   162                         $retp=$dbc->execute($sql);
       
   163                         if (!$retp) 
       
   164                             echo $dbc -> error . "<br>\n";
       
   165                     }
       
   166                 }
       
   167                 else
       
   168                 {   // nur Aenderung Dateiname
       
   169                     include ("inc/file_upload.inc.php");
       
   170                     $fname = gen_filename($al["pfname"],$al["pfname_old"],$alpid,0);
       
   171                     $len = strlen($alpid)+1; 
       
   172                     if (substr($fname,0,$len) != "$alpid" . "_") $fname = $alpid . "_" . $fname;
       
   173                     if ($al["pfname"] != $al["pfname_old"])
       
   174                     {
       
   175                         $retf  = mod_file("/var/www/fhiiqm/alprot",$alpid,$fname,"upd");  // Umbenennen alte Datei
       
   176                         if ($retf) 
       
   177                         {
       
   178                             $sql = "UPDATE A_Pruefung SET pruef_file = '" . $fname ."' WHERE alp_ID=$alpid";
       
   179                             $retp=$dbc->execute($sql);
       
   180                             if (!$retp) 
       
   181                                 echo $dbc -> error . "<br>\n";
       
   182                             if (substr($fname,0,$len) == "$alpid" . "_") $fname = substr($fname,$len,50);
       
   183                         }
       
   184                         
       
   185                     }    
       
   186                 }    
       
   187                 $stmt = $dbc -> stmtinit();
       
   188                 if (is_object($stmt))
       
   189                 {
       
   190                     $stmt -> prepare ("UPDATE A_Pruefung SET 
       
   191                                 al_ID = ?,
       
   192                                 pruef_date = ?,
       
   193                                 pruef_bem = ?
       
   194                                 WHERE alp_ID = $alpid");
       
   195                     $stmt -> bind_param('iss', $al["id"], $al["pdat"],$al["bem"]);
       
   196                     $result = $stmt -> execute();      
       
   197                     if ($stmt->error) echo "UPDATE error: " . $stmt->errno . " - ". $stmt->error . "<br><br>\n";
       
   198                 }
       
   199             }
       
   200             else
       
   201             {
       
   202                 //insert
       
   203                 $stmt = $dbc -> stmtinit();
       
   204                 if (is_object($stmt))
       
   205                 {
       
   206                     $stmt -> prepare ("INSERT INTO A_Pruefung (al_ID,pruef_date,pruef_bem) VALUES (?,?,?)");
       
   207                     $stmt -> bind_param('iss', $al["id"], $al["pdat"],$al["bem"]);
       
   208                     $result = $stmt -> execute();      
       
   209                     if ($stmt->error) echo "INSERT error: " . $stmt->errno . " - ". $stmt->error . "<br><br>\n";
       
   210                 }
       
   211 //$result=1;
       
   212                 if ($result)
       
   213                 { // INSERT o.k.
       
   214                   // info_ID ermitteln
       
   215                     $alpid = $dbc -> insertId();
       
   216                     
       
   217                     // upload File
       
   218                     if (is_uploaded_file($_FILES["pfile"]["tmp_name"]) && isset($_FILES["pfile"]["name"]) && $_FILES["pfile"]["name"] )
       
   219                     {
       
   220                         include ("inc/file_upload.inc.php");
       
   221                         if ($al['pfname']<"!") $al['pfname']="al_pruefung";
       
   222                         $fname = gen_filename($al['pfname'],"pfile",$alpid);
       
   223 //echo $fname;
       
   224 
       
   225                         $retf   = upload("pfile", $fname, $alpid, "alprot");              // Datei prüfen und in Dokumentenverzeichnis verschieben
       
   226 
       
   227                         
       
   228                         if ($retf)
       
   229                         {   // upload o.k.
       
   230                             //UPDATE des Filenamens
       
   231                             $sql = "UPDATE A_Pruefung SET pruef_file = '" . $alpid . "_" . $fname ."' WHERE alp_ID=$alpid";
       
   232                             $retp=$dbc->execute($sql);
       
   233                             if (!$retp) 
       
   234                                 echo $dbc -> error . "<br>\n";
       
   235                         }
       
   236                        
       
   237                     }
       
   238                     else 
       
   239                     {
       
   240                         $retf=1; //kein Protokoll hochgeladen
       
   241                         $retp=1;
       
   242                     }
       
   243                 }
       
   244             }
       
   245             if ($result && $retf && $retp) // INSERT/UPDATE Pruefung
       
   246             {
       
   247                 //Eingabe Daten, Upload File erfolgreich 
       
   248                     echo "<p class='green'><b>Pr&uuml;fdaten zu Anlage '".$al["bez"]."' wurden erfolgreich gespeichert.</b></p>\n";
       
   249                     echo "<br /><br />\n";
       
   250 
       
   251                 // Anzeigen gespeicherte Pruefdaten
       
   252                 if ($fname)
       
   253                     $pfile = $alpid . "_" . $fname;
       
   254                 else
       
   255                     $pfile = $al['pfname'];
       
   256                 echo "<table>\n";
       
   257                 echo "<tr><td>Anlagen-ID: </td><td>" . $al["id"] . "<td></td></tr>\n";
       
   258                 echo "<tr><td>Anlagenbezeichnung: </td><td>" . $al['bez'] . "<td></td></tr>\n";
       
   259                 $pdat = new DateTime($al["pdat"]);
       
   260                 if (is_object($pdat)) $pdat = $pdat->format('d.m.Y H:i:s'); else $pdat = "&nbsp;";
       
   261                 echo "<tr><td>Prüfdatum: </td><td>" . $pdat. "</td></tr>\n";
       
   262                 if ($fname>"!") echo "<tr><td>Dateiname Prüfprotokoll: </td><td>" . $pfile. "</td></tr>\n";
       
   263                 echo "<tr><td>Bemerkung: </td><td>" . $al['bem'] . "<td></td></tr>\n";
       
   264                 echo "</table>\n";   
       
   265             }            
       
   266             $dbc -> close();
       
   267             echo "</div>\n";
       
   268             echo "<p>&nbsp;&nbsp;&nbsp;<a href=\"alpruef_ed.php\" target=\"_self\" title=\"Pr&uuml;fung erfassen\">Weitere Anlagen-Pr&uuml;fung erfassen</a></p>\n";    
       
   269             echo "<p>&nbsp;&nbsp;&nbsp;<a href=\"alpruef_flist.php\" target=\"_self\" title=\"Anlagen pruefen\">Liste der Anlagenpr&uuml;fungen</a></p>\n"; 
       
   270         }
       
   271  ?>
       
   272  </body>
       
   273  </html>