fhiiqm/ap_vorsorge_ed.php
changeset 26 3c1e3ac7089f
child 27 d92bbe898f32
equal deleted inserted replaced
25:482252ff12fd 26:3c1e3ac7089f
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * @author Bettina Schwarzer, Fritz-Haber-Institut
       
     5  * @copyright 05/2012
       
     6  * 
       
     7  * INSERT/UPDATE Arbeitsplatztyp - Vorsorge
       
     8  * 
       
     9  */
       
    10 
       
    11     error_reporting(E_ALL ^ E_NOTICE);
       
    12     
       
    13     session_start();
       
    14     if (! isset($_SESSION["userid"]))
       
    15     { 
       
    16         include_once ("inc/func_lib.inc.php");	
       
    17         login($_SERVER["PHP_SELF"]);
       
    18         exit;
       
    19     }
       
    20     
       
    21     if (is_null($_SESSION["recht"]) || (!is_null($_SESSION["recht"]) && !in_array("asr",$_SESSION["recht"]) && !in_array("ase",$_SESSION["recht"])))
       
    22     {
       
    23         header("Location: start.php");
       
    24         exit;
       
    25     }    
       
    26 
       
    27 	include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
       
    28 	if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
       
    29 
       
    30     $sub = $_POST["eintragen"];
       
    31     $ap  = $_POST["ap"];
       
    32     $ok  = $_POST["ok"];
       
    33     $apid = $_GET["i"]; // arbeitsplatz_ID
       
    34     
       
    35 
       
    36 
       
    37 ?>
       
    38 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       
    39 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
       
    40 
       
    41 <head>
       
    42 	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
       
    43    	<link href="/fhiiqm/css/db.css" rel="STYLESHEET" type="TEXT/CSS" media="screen"/> 
       
    44    	<link href="/fhiiqm/css/db_print.css" rel="STYLESHEET" type="TEXT/CSS" media="print"/> 
       
    45 	<title>Arbeitsplatztyp - Vorsorge</title>
       
    46 
       
    47     <script type="text/javascript">
       
    48     <!--
       
    49     var counter = 0;
       
    50     var limit = 99;
       
    51     var arr = new Array();
       
    52     function addInput(divName){
       
    53          if (counter == limit)  {
       
    54               alert("Das Limit von " + counter + " zusätzlichen inputs ist erreicht");
       
    55          }
       
    56          else {
       
    57               var newdiv = document.createElement('div');
       
    58               var count;
       
    59               var opt="<option value='-1'></option>";
       
    60               for (var key in arr)  
       
    61               {
       
    62                 opt = opt.concat("<option value='",key,"'>",key, " - ",arr[key],"</option>\n" );
       
    63               }
       
    64               opt += "</select>\n";
       
    65               newdiv.innerHTML += "<select name='ap[vs][]'>"+opt;
       
    66               document.getElementById(divName).appendChild(newdiv);
       
    67               counter++;
       
    68          }
       
    69     }
       
    70     function delInput(divId){
       
    71             var kn = document.getElementById(divId); 
       
    72             while (kn.childNodes.length>0 && kn.lastChild.nodeName != "SELECT" && kn.lastChild.nodeName != "A")
       
    73             {
       
    74 //                alert ("vor "+kn.lastChild.nodeName+", nodetyp = "+ kn.lastChild.nodeType);
       
    75                 var knc = kn.lastChild;
       
    76                     document.getElementById(divId).removeChild(knc);
       
    77             }
       
    78             if (kn.lastChild.nodeName == "SELECT") document.getElementById(divId).removeChild(kn.lastChild);
       
    79     }
       
    80     //-->
       
    81     </script>
       
    82 
       
    83 </head>
       
    84 
       
    85 <body>
       
    86 
       
    87 <?php
       
    88     echo "&nbsp;";  
       
    89     echo "<div class=\"float-br smaller\" valign='top'>";
       
    90     echo "&nbsp;&nbsp;&nbsp;user: " . $_SESSION["userid"];
       
    91     echo "&nbsp;&nbsp;&nbsp;<a class='sc' href='/fhiiqm/logout.php' title='Session beenden'>logout</a></div>\n";
       
    92     echo "<div class=\"float-r\"><img src=\"img/role.png\" border=\"0\" alt=\"Arbeitsplatztyp - Vorsorge bearbeiten\" title=\"Arbeitsplatztyp - Vorsorge bearbeiten\"/></div>\n";
       
    93 
       
    94     if ($apid) $text = "editieren"; else $text = "erfassen";
       
    95     echo "<div align=\"center\">";
       
    96     echo "<h3>Arbeitsplatztyp - Grunds&auml;tze Vorsorge $text</h3>";
       
    97     echo "</div>\n";
       
    98     if (!$sub || !isset($ap) || !$ok) 
       
    99     {
       
   100         if ($apid && !$sub && !isset($ap))
       
   101         {
       
   102             $sql = "SELECT vs_ID, arbplatz_typ FROM Vorsorge_Arbplatz WHERE arbplatz_typ = '" . $apid . "'";
       
   103             if ($res = $dbc -> queryObjectArray($sql))
       
   104             {
       
   105                 foreach ($res as $row)
       
   106                 {
       
   107                     $ap["aptyp"] = $row->arbplatz_typ;
       
   108                     $ap["vs"][]  = $row->vs_ID;   
       
   109                 }
       
   110             }
       
   111             else $ap["aptyp"] = $apid;
       
   112         }
       
   113         include ($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/form/ap_vorsorge_form.inc.php");
       
   114         
       
   115 	  	if ($sub)
       
   116         {
       
   117             $frage = "Alle Angaben ok?";
       
   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=\"checked\""; 
       
   122 			echo " /></td>\n</tr>\n";
       
   123         }
       
   124         if (!is_null($_SESSION["recht"]) && in_array("ase",$_SESSION["recht"]))
       
   125         {
       
   126             echo "
       
   127            	<tr><td>&nbsp;</td>\n
       
   128             	<td><input  class=\"button\" type=\"submit\" name=\"eintragen\" value=\"  eintragen  \" />";
       
   129            	echo "</td></tr>\n";
       
   130         }
       
   131         echo "</table>\n";
       
   132         echo "</div>\n";
       
   133     echo "<p class='sc'>&nbsp;&nbsp;&nbsp;<a href=\"ap_vorsorge_flist.php\" target=\"_self\" title=\"Arbplatztyp-Liste\">&laquo; zur Arbeitsplatztyp-Liste</a></p>\n"; 
       
   134     echo "</form>\n";
       
   135     }
       
   136     else
       
   137     {
       
   138         echo "<div align='center'>\n";
       
   139 
       
   140         if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
       
   141         
       
   142         $stmt = $dbc -> stmtinit();
       
   143         if (is_object($stmt))
       
   144         {
       
   145             $retd = 1;
       
   146             if ($apid && is_array($ap['vs']))
       
   147             {   //UPDATE
       
   148                 // Loeschen alte Arbeitsplatztypen
       
   149                 $retd = $dbc -> execute("DELETE FROM Vorsorge_Arbplatz WHERE arbplatz_typ = '". $ap["aptyp"] ."'");
       
   150             }
       
   151             
       
   152             if ($retd && is_array($ap['vs']))
       
   153             {
       
   154                 $rett = 1;
       
   155                 $stmt -> prepare("INSERT INTO Vorsorge_Arbplatz (vs_ID,arbplatz_typ) VALUES(?,?)");
       
   156                 for ($k=0; $k<count($ap["vs"]); $k++)
       
   157                 {
       
   158                     if ($ap["vs"][$k] && $ap["vs"][$k] != -1) 
       
   159                     {
       
   160                         $stmt -> bind_param('ss',$ap["vs"][$k], $ap["aptyp"]);
       
   161                         $rett = $stmt -> execute();
       
   162                         if (!$rett) $rett = false;
       
   163                     }
       
   164                 }
       
   165                 if (!$rett) echo "error INSERT Vorsorge: $stmt->error<br />\n";
       
   166                 
       
   167             }
       
   168         }
       
   169             if ($rett)
       
   170             {
       
   171                 echo "<p class='green'><b>Vorsorgegrunds&auml;tze für Arbeitsplatztyp '$apid' wurden erfolgreich gespeichert.</b></p>\n";
       
   172                 echo "<table>\n";
       
   173                 if (is_array($ap["vs"]))
       
   174                 {
       
   175                     echo "<tr><td>Vorsorgegrunds&auml;tze: </td>";
       
   176                     foreach ($ap["vs"] as $vsg)
       
   177                     { 
       
   178                         if ($next) $next ="<tr><td>&nbsp;</td>"; else $next =" ";
       
   179                         if ($vsg && $vsg != -1) echo "$next<td>$vsg</td></tr>\n";
       
   180                     }
       
   181                 }
       
   182                 echo "</table>\n";
       
   183             }   
       
   184             else
       
   185                 echo "<p class='red'><b>Vorsorgegrunds&auml;tze für Arbeitsplatztyp '$apid'' wurden nicht oder nur teilweise gespeichert</b></p>\n";
       
   186         
       
   187         echo "</div>";
       
   188         echo "<p class='sc'>&nbsp;&nbsp;&nbsp;<a href=\"ap_vorsorge_flist.php\" target=\"_self\" title=\"Arbplatztyp-Liste\">&laquo; zur Arbeitsplatztyp-Liste</a></p>\n"; 
       
   189     }
       
   190 ?>
       
   191 </body>
       
   192 </html>