fhiiqm/laser_ed.php
changeset 22 aae5b0ecc47b
parent 21 97dba0fe820c
child 23 a382de56a8e4
equal deleted inserted replaced
21:97dba0fe820c 22:aae5b0ecc47b
     1 <?php
     1 <?php
     2 
     2 
     3 /**
     3 /**
     4  * @author Bettina Schwarzer, Fritz-Haber-Institut
     4  * @author Bettina Schwarzer, Fritz-Haber-Institut
     5  * @copyright 12/2011
     5  * @copyright 12/2011, 01/2012
       
     6  * 
       
     7  * Laser INSERT, UPDATE, DELETE, COPY
     6  */
     8  */
     7 
     9 
     8     error_reporting(E_ALL ^ E_NOTICE);
    10     error_reporting(E_ALL ^ E_NOTICE);
     9     
    11     
    10     session_start();
    12     session_start();
    33     $dup    = $_POST["dup"];
    35     $dup    = $_POST["dup"];
    34     if (!$dup) $dup = $_GET["d"];
    36     if (!$dup) $dup = $_GET["d"];
    35 	$ok		= $_POST["ok"];
    37 	$ok		= $_POST["ok"];
    36     if (!$la['okn']) $ok=false;
    38     if (!$la['okn']) $ok=false;
    37     $duptext="";
    39     $duptext="";
    38 
    40     
    39     if ($dup)
    41     if ($dup)
    40     {   // Anlage duplizieren
    42     {   // Anlage duplizieren
    41         include_once ($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/inc/func_lib.inc.php");
    43         include_once ($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/inc/func_lib.inc.php");
    42         $tab = "Laser";
    44         $tab = "Laser";
    43         $key = "las_ID";
    45         $key = "las_ID";
    49             $laid=$ret;
    51             $laid=$ret;
    50             $addr = $_SERVER["PHP_SELF"] . "?i=$laid&c=1";
    52             $addr = $_SERVER["PHP_SELF"] . "?i=$laid&c=1";
    51             header("Location: $addr");
    53             header("Location: $addr");
    52             exit;
    54             exit;
    53         }
    55         }
    54         else $duptext = " - Fehler beim Duplizieren von ". $al["bez"];    
    56         else $duptext = " - Fehler beim Duplizieren von ". $la["lbez"];    
    55     }
    57     }
    56 
    58 
    57 ?>
    59 ?>
    58 
    60 
    59 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    61 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   102         
   104         
   103         echo "</div>\n";
   105         echo "</div>\n";
   104         
   106         
   105         if (!$ok || (!$sub && !$del && !$dup))
   107         if (!$ok || (!$sub && !$del && !$dup))
   106         {
   108         {
   107             if ($laid && (!$sub || !$del) && !isset($al))
   109             if ($laid && (!$sub || !$del) && !isset($la))
   108             { // update
   110             { // update
   109                 $sql = "SELECT las_ID, las_bez, las_welle_von, las_welle_bis, 
   111                 $sql = "SELECT las_ID, las_bez, las_welle_von, las_welle_bis, 
   110                             las_art_ID, las_klasse_ID, las_typ_ID, leistung, einheit_leistung, 
   112                             las_art_ID, las_klasse_ID, las_typ_ID, leistung, einheit_leistung, 
   111                             apertur, einheit_apertur, energie, einheit_energie, frequenz, einheit_frequenz, 
   113                             apertur, einheit_apertur, energie, einheit_energie, frequenz, einheit_frequenz, 
   112                             impulsbreite, einheit_impulsbreite, l.las_hersteller_ID, schutzst_ID, 
   114                             impulsbreite, einheit_impulsbreite, l.las_hersteller_ID, schutzst_ID, 
   113                             l.aktiv, l.persknr, l.raum_ID, geb_ID, las_info,
   115                             l.aktiv, l.persknr, l.raum_ID, geb_ID, las_info,
   114                             CONCAT(nachname,', ',vorname) AS vname, las_hersteller_bez
   116                             CONCAT(nachname,', ',vorname) AS vname, las_hersteller_bez,
       
   117                             inventar_nr,maxleistung, einheit_maxleist,schutzst_od_ID,las_ref_ID,l.timestamp
   115                         FROM fhiiqm.Laser l LEFT OUTER JOIN fhiiqm.Mitarbeiter m 
   118                         FROM fhiiqm.Laser l LEFT OUTER JOIN fhiiqm.Mitarbeiter m 
   116                             ON l.persknr=m.persknr LEFT OUTER JOIN fhiiqm.Laser_Hersteller h
   119                             ON l.persknr=m.persknr LEFT OUTER JOIN fhiiqm.Laser_Hersteller h
   117                             ON l.las_hersteller_ID=h.las_hersteller_ID LEFT OUTER JOIN fhiiqm.Raum r
   120                             ON l.las_hersteller_ID=h.las_hersteller_ID LEFT OUTER JOIN fhiiqm.Raum r
   118                             ON l.raum_ID=r.Raum_ID
   121                             ON l.raum_ID=r.Raum_ID
   119                         WHERE las_ID = $laid";
   122                         WHERE las_ID = '$laid'";
   120                 if ($result = $dbc -> queryObjectArray($sql))
   123                 if ($result = $dbc -> queryObjectArray($sql))
   121                 {
   124                 {
   122                     foreach ($result as $row)
   125                     foreach ($result as $row)
   123                     {
   126                     {
   124                         $la["lbez"] = $row->las_bez;   
   127                         $la["lid"]      = $laid;  
   125                         $la['wvon'] = $row->las_welle_von;
   128                         $la["lbez"]     = $row->las_bez;   
   126                         $la['wbis'] = $row->las_welle_bis;
   129 //                        $la['wvon']     = str_replace(".",",",$row->las_welle_von);
   127                         $la["lart"] = $row->las_art_ID;   
   130                         $la['wvon']     = str_replace(".",",",str_replace(".00","",$row->las_welle_von));
   128                         $la['lkla'] = $row->las_klasse_ID;
   131                         $la['wbis']     = str_replace(".",",",str_replace(".00","",$row->las_welle_bis));
   129                         $la['ltyp'] = $row->las_typ_ID;
   132                         $la["lart"]     = ($row->las_art_ID) ? $row->las_art_ID : -1;   
   130                         $la['leist'] = $row->leistung;
   133                         $la['lkla']     = ($row->las_klasse_ID) ? $row->las_klasse_ID : -1;
   131                         $la["apt"] = $row->apertur;
   134                         $la['ltyp']     = ($row->las_typ_ID) ? $row->las_typ_ID : -1;
   132                         $la["eapt"] = $row->einheit_apertur;
   135                         $la['leist']    = str_replace(".",",",str_replace(".00","",$row->leistung));
   133                         $la["eng"]  = $row->energie;
   136                         $la['eleist']   = $row->einheit_leistung;
   134                         $la["eeng"] = $row->einheit_energie;
   137                         $la["apt"]      = str_replace(".",",",str_replace(".00","",$row->apertur));
   135                         $la["efrq"]  = $row->frequenz;
   138                         $la["eapt"]     = $row->einheit_apertur;
   136                         $la["efrq"] = $row->einheit_frequenz;
   139                         $la["eng"]      = str_replace(".",",",str_replace(".00","",$row->energie));
   137                         $la["ipb"]  = $row->impulsbreite;
   140                         $la["eeng"]     = $row->einheit_energie;
   138                         $la["eipb"] = $row->einheit_impulsbreite;
   141                         $la["frq"]      = str_replace(".",",",str_replace(".00","",$row->frequenz));
   139                         $la["akt"] = $row->aktiv;
   142                         $la["efrq"]     = $row->einheit_frequenz;
   140                         $la["hstid"] = $row->las_hersteller_ID;
   143                         $la["ipb"]      = str_replace(".",",",str_replace(".00","",$row->impulsbreite));
   141                         $la["suid"] = $row->schutzst_ID;
   144                         $la["eipb"]     = $row->einheit_impulsbreite;
   142                         $la["persknr"] = $row->vname;
   145                         $la["akt"]      = $row->aktiv;
   143                         $la["pid"] = $row->persknr;
   146                         $la["hstid"]    = $row->las_hersteller_ID;
   144                         $la["geb"] = $row->geb->ID;    
   147                         if (!$la["hstid"]) $la["hstid"] = -1;
   145                         $la["raum"] = $row->raum_ID;
   148                         $la["suid"]     = ($row->schutzst_ID)? $row->schutzst_ID : -1;
   146                         $la["linfo"] = $row->las_info;
   149                         $la["akt"]      = $row->aktiv;  
   147                         
   150                         $la["persknr"]  = $row->vname;
       
   151                         $la["pid"]      = ($row->persknr) ? $row->persknr : null;
       
   152                         $la["geb"]      = $row->geb_ID;    
       
   153                         $la["raum"]     = ($row->raum_ID) ? $row->raum_ID : -1;
       
   154                         $la["linfo"]    = $row->las_info;
       
   155                         $la["invnr"]    = $row->inventar_nr;
       
   156                         $la["leistmax"] = str_replace(".",",",str_replace(".00","",$row->maxleistung));
       
   157                         $la["eleistmax"]= $row->einheit_maxleist;
       
   158                         $la["suodid"]   = $row->schutzst_od_ID;
       
   159                         $la["lidref"]   = $row->las_ref_ID;
       
   160                         $la["tstmp"]    = $row->timestamp; 
   148                     }
   161                     }
   149                 }
   162                 }
   150             }
   163             }
   151             include ($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/form/laser_form.inc.php");     
   164             include ($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/form/laser_form.inc.php");     
   152             if ($sub || $del)
   165             if ($sub || $del)
   156                 elseif ($del)
   169                 elseif ($del)
   157                     $frage = "Laser wirklich l&ouml;schen?";
   170                     $frage = "Laser wirklich l&ouml;schen?";
   158     			echo "<tr>
   171     			echo "<tr>
   159     			  <td class=\"red\" valign=\"top\" align=\"left\">$frage</td>
   172     			  <td class=\"red\" valign=\"top\" align=\"left\">$frage</td>
   160     			        <td><input type=\"checkbox\" name=\"ok\" value=\"1\"";
   173     			        <td><input type=\"checkbox\" name=\"ok\" value=\"1\"";
   161     			        if ($ok)  echo "checked"; 
   174     			        if ($ok)  echo "checked=\"checked\""; 
   162     			echo "></td>\n</tr>\n"; 
   175     			echo " /></td>\n</tr>\n"; 
   163     		}
   176     		}
   164             if (!is_null($_SESSION["recht"]) && in_array("le",$_SESSION["recht"]))
   177             if (!is_null($_SESSION["recht"]) && in_array("le",$_SESSION["recht"]))
   165             {
   178             {
   166                 echo "
   179                 echo "
   167                	<tr><td>&nbsp;</td>\n
   180                	<tr><td>&nbsp;</td>\n
   173                 }    
   186                 }    
   174                	echo "</td></tr>\n";
   187                	echo "</td></tr>\n";
   175             }
   188             }
   176             echo "</table>\n";
   189             echo "</table>\n";
   177             echo "</div>\n";
   190             echo "</div>\n";
   178             if (!is_null($_SESSION["recht"]) && !in_array("le", $_SESSION["recht"]))
   191 //            if (!is_null($_SESSION["recht"]) && !in_array("le", $_SESSION["recht"]))
   179                 echo "<p class='sc'>&nbsp;&nbsp;&nbsp;<a href=\"laser_flist.php\" target=\"_self\" title=\"Laser\">&laquo; zur Laserliste</a></p>\n"; 
   192                 echo "<p class='sc'>&nbsp;&nbsp;&nbsp;<a href=\"laser_flist.php\" target=\"_self\" title=\"Laser\">&laquo; zur Laserliste</a></p>\n"; 
   180             echo "</form>\n";   
   193             echo "</form>\n";   
   181 
   194 
   182             
   195             
   183         }
   196         }
   184         else
   197         else
   185         {
   198         {
   186             echo "speichern";
   199             echo "<div align='center'>\n";
       
   200             
       
   201             if ($del)
       
   202             {
       
   203                 $sql = "DELETE FROM Laser WHERE las_ID = '$laid'";
       
   204                 $retld = $dbc -> execute($sql);
       
   205                 if ($retld)
       
   206                 {
       
   207                     echo "<p class='green'><b>DELETE: Daten  zu '".$la["lbez"]."' wurden erfolgreich gel&ouml;scht.</b></p>\n";
       
   208                     include ("inc/laser_dat_show.inc.php");
       
   209                 }                
       
   210                 else
       
   211                 {
       
   212                     echo "<p class='red'><b>DELETE: Daten  zu '".$la["lbez"]."' konnten nicht gel&ouml;scht werden!</b></p>\n";
       
   213                     echo "sql = $sql<br />";
       
   214                     echo "error DELETE: " . $dbc->error . "<br />";
       
   215                 }
       
   216             }
       
   217             else //INSERT oder UPDATE
       
   218             {
       
   219                 if ($la["lbez"]) $la["lbez"] = substr($la["lbez"],0,250); else $la["lbez"] = null;
       
   220                 if ($la["linfo"]) $la["linfo"] = substr($la["linfo"],0,500); else $la["linfo"] = null;
       
   221                 if ($la["lart"] == -1) $la["lart"] = null;
       
   222                 if ($la["lkla"] == -1) $la["lkla"] = null;
       
   223                 if ($la["ltyp"] == -1) $la["ltyp"] = null;
       
   224                 if ($la["suid"] == -1) $la["suid"] = null;
       
   225                 if ($la["suodid"] == -1) $la["suodid"] = null;
       
   226                 if ($la["lidref"] == -1) $la["lidref"] = null;
       
   227 //                print_r($la); echo "<br /><br />";
       
   228 
       
   229                 if ($la["hstid"] == -1)
       
   230                 {
       
   231                     if ($la["herst"] > "!") // neuer Hersteller?
       
   232                     {
       
   233                         $sql = "SELECT las_hersteller_ID FROM Laser_Hersteller WHERE las_hersteller_bez = '" . ltrim($la["herst"]) . "'";
       
   234                         if ($res = $dbc -> queryObjectArray($sql))
       
   235                         {   // Hersteller vorhanden
       
   236                             foreach ($res as $row)
       
   237                                 $la["hstid"] = $row->las_hersteller_ID;
       
   238                         }        
       
   239                         else
       
   240                         {   // Hersteller neu
       
   241                             $sql = "INSERT INTO Laser_Hersteller (las_hersteller_bez) VALUES (LEFT(TRIM('" . $la["herst"] . "'),50))";
       
   242                             $reth = $dbc -> execute($sql); 
       
   243                             if ($reth) $la["hstid"] = $dbc -> insertId(); else $la["hstid"] = null;
       
   244                         }
       
   245                     }
       
   246                     else
       
   247                         $la["hstid"] = null;
       
   248                 } 
       
   249                 
       
   250                 if ($la["lart"] == -1)
       
   251                 {
       
   252                     if ($la["lartnew"] > "!") // neue Laserart?
       
   253                     {
       
   254                         $sql = "SELECT las_art_ID FROM Laser_Art WHERE las_art_bez = '" . ltrim($la["lartnew"]) . "'";
       
   255                         if ($res = $dbc -> queryObjectArray($sql))
       
   256                         {   // Hersteller vorhanden
       
   257                             foreach ($res as $row)
       
   258                                 $la["lart"] = $row->las_art_ID;
       
   259                         }        
       
   260                         else
       
   261                         {   // Laserart neu
       
   262                             $sql = "INSERT INTO Laser_Art (las_art_bez) VALUES (LEFT(TRIM('" . $la["lartnew"] . "'),50))";
       
   263                             $reth = $dbc -> execute($sql); 
       
   264                             if ($reth) $la["lart"] = $dbc -> insertId(); else $la["lart"] = null;
       
   265                         }
       
   266                     }
       
   267                     else
       
   268                         $la["lart"] = null;
       
   269                 } 
       
   270                 
       
   271                 foreach ($la as $key=>$value)
       
   272                 {
       
   273         			if (is_null($value) || $value < "!") $la["$key"] = null;
       
   274                 }
       
   275                 if (is_null($la["persknr"])) $la[pid] = null;
       
   276                 if (is_numeric(str_replace(",",".",$la["wvon"]))) $la["wvon"] = round(str_replace(",",".",$la["wvon"]),2);    
       
   277                 if (is_numeric(str_replace(",",".",$la["wbis"]))) $la["wbis"] = round(str_replace(",",".",$la["wbis"]),2);    
       
   278                 if (is_numeric(str_replace(",",".",$la["leist"]))) $la["leist"] = round(str_replace(",",".",$la["leist"]),2);    
       
   279                 if (is_numeric(str_replace(",",".",$la["leistmax"]))) $la["leistmax"] = round(str_replace(",",".",$la["leistmax"]),2);    
       
   280                 if (is_numeric(str_replace(",",".",$la["eng"]))) $la["eng"] = round(str_replace(",",".",$la["eng"]),2);    
       
   281                 if (is_numeric(str_replace(",",".",$la["apt"]))) $la["apt"] = round(str_replace(",",".",$la["apt"]),2);    
       
   282                 if (is_numeric(str_replace(",",".",$la["frq"]))) $la["frq"] = round(str_replace(",",".",$la["frq"]),2);    
       
   283                 if (is_numeric(str_replace(",",".",$la["ipb"]))) $la["ipb"] = round(str_replace(",",".",$la["ipb"]),2);
       
   284                     
       
   285                 $stmt = $dbc -> stmtinit();
       
   286                 if (is_object($stmt))
       
   287                 {
       
   288                     if ($laid)
       
   289                     {
       
   290                         //update
       
   291                         $stmt -> prepare("UPDATE fhiiqm.Laser SET 
       
   292                                     las_bez = ?, 
       
   293                                     las_welle_von = ?, 
       
   294                                     las_welle_bis = ?, 
       
   295                                     las_art_ID = ?, 
       
   296                                     las_klasse_ID = ?, 
       
   297                                     las_typ_ID = ?, 
       
   298                                     leistung = ?, 
       
   299                                     einheit_leistung = ?, 
       
   300                                     energie = ?, 
       
   301                                     einheit_energie = ?, 
       
   302                                     apertur = ?, 
       
   303                                     einheit_apertur = ?, 
       
   304                                     frequenz = ?, 
       
   305                                     einheit_frequenz = ?, 
       
   306                                     impulsbreite = ?, 
       
   307                                     einheit_impulsbreite = ?, 
       
   308                                     las_hersteller_ID = ?, 
       
   309                                     schutzst_ID = ?, 
       
   310                                     aktiv = ?, 
       
   311                                     persknr = ?, 
       
   312                                     raum_ID = ?, 
       
   313                                     las_info = ?,
       
   314                                     inventar_nr = ?,
       
   315                                     maxleistung = ?,
       
   316                                     einheit_maxleist = ?,
       
   317                                     schutzst_od_ID = ?,
       
   318                                     las_ref_ID = ? 
       
   319                                     WHERE las_ID = '$laid'");
       
   320                         $stmt -> bind_param('sddisidididididiiiiiissdiii',$la["lbez"],$la['wvon'],$la['wbis'],$la["lart"],$la['lkla'],
       
   321                                             $la['ltyp'],$la['leist'],$la["eleist"],$la["eng"],$la["eeng"],$la["apt"],$la["eapt"],$la["frq"],$la["efrq"],
       
   322                                             $la["ipb"],$la["eipb"],$la["hstid"],$la["suid"],$la["akt"],$la["pid"],$la["raum"],$la["linfo"],
       
   323                                             $la["invnr"],$la["leistmax"],$la["eleistmax"],$la["suodid"],$la["lidref"]);
       
   324                             
       
   325                         $res = $stmt -> execute();
       
   326                         if ($stmt->error) echo "UPDATE Laser, error: " . $stmt->errno . " - ". $stmt->error . "<br><br>\n";
       
   327                         if ($res)
       
   328                             echo "<p class='green'><b>UPDATE: Daten  zu '".$la["lbez"]."' wurden erfolgreich gespeichert.</b></p>\n";
       
   329                         else
       
   330                             echo "<p class='red'><b>UPDATE: Daten  zu '".$la["lbez"]."' konnten nicht gespeichert werden!</b></p>\n";
       
   331 
       
   332                     }
       
   333                     else
       
   334                     {
       
   335                         //insert
       
   336                         $stmt -> prepare("INSERT INTO fhiiqm.Laser (las_bez, las_welle_von, las_welle_bis, las_art_ID, 
       
   337                                             las_klasse_ID, las_typ_ID, leistung, einheit_leistung, energie, einheit_energie, 
       
   338                                             apertur, einheit_apertur, frequenz, einheit_frequenz, impulsbreite, einheit_impulsbreite, 
       
   339                                             las_hersteller_ID, schutzst_ID, aktiv, persknr, raum_ID, las_info,
       
   340                                             inventar_nr,maxleistung, einheit_maxleist,schutzst_od_ID,las_ref_ID)
       
   341                                           VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
       
   342                         $stmt -> bind_param('sddisidididididiiiiiissdiii',$la["lbez"],$la['wvon'],$la['wbis'],$la["lart"],$la['lkla'],
       
   343                                             $la['ltyp'],$la['leist'],$la["eleist"],$la["eng"],$la["eeng"],$la["apt"],$la["eapt"],$la["frq"],$la["efrq"],
       
   344                                             $la["ipb"],$la["eipb"],$la["hstid"],$la["suid"],$la["akt"],$la["pid"],$la["raum"],$la["linfo"],
       
   345                                             $la["invnr"],$la["leistmax"],$la["eleistmax"],$la["suodid"],$la["lidref"]);
       
   346                         $res = $stmt -> execute();
       
   347 //                        print_r($stmt); echo "<br /><br />";
       
   348                         if ($stmt->error) echo "INSERT Laser, error: " . $stmt->errno . " - ". $stmt->error . "<br><br>\n";
       
   349                         if ($res)
       
   350                         {
       
   351                             $la["lid"] = $dbc -> insertId();
       
   352                             echo "<p class='green'><b>INSERT: Daten  zu '".$la["lbez"]."' wurden erfolgreich gespeichert.</b></p>\n";
       
   353                         }   
       
   354                         else
       
   355                             echo "<p class='red'><b>INSERT: Daten  zu '".$la["lbez"]."' konnten nicht gespeichert werden!</b></p>\n";
       
   356                     }
       
   357                     if ($res) include ("inc/laser_dat_show.inc.php");
       
   358                 }
       
   359 
       
   360             }
       
   361             echo "</div>\n";       
       
   362             echo "<p class=\"sc\">&nbsp;&nbsp;&nbsp;<a href=\"".$_SERVER["PHP_SELF"]."\" target=\"_self\" title=\"Laser erfassen\">Weiteren Laser erfassen</a></p>\n";    
       
   363             echo "<p class=\"sc\">&nbsp;&nbsp;&nbsp;<a href=\"laser_flist.php\" target=\"_self\" title=\"Laser\">Laserliste</a></p>\n";    
   187         }
   364         }
   188     ?>
   365     ?>
   189  </body>
   366  </body>
   190  </html>
   367  </html>