fhiiqm/test/plus_element.php
changeset 25 482252ff12fd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fhiiqm/test/plus_element.php	Thu Apr 05 15:35:43 2012 +0200
@@ -0,0 +1,184 @@
+<?php
+
+/**
+ * @author Bettina Schwarzer, Fritz-Haber-Institut
+ * @copyright 03/2012
+ * 
+ * TEST zusaetzliche Formularfelder anzeigen
+ */
+
+
+
+?>
+
+<!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="/fhiiqm/css/db.css" rel="STYLESHEET" type="TEXT/CSS" media="screen"/> 
+   	<link href="/fhiiqm/css/db_print.css" rel="STYLESHEET" type="TEXT/CSS" media="print"/> 
+	<title>Einblenden</title>
+
+    <script type="text/javascript">
+    <!--
+/*
+    function einblenden(elementname)
+    {
+    document.getElementById(elementname).style.display='block';
+    //document.getElementById(elementname).style.visibility='visible';
+    }
+    
+    function ausblenden(elementname)
+    {
+    document.getElementById(elementname).style.display='none';
+    //document.getElementById(elementname).style.visibility='hidden';
+    }
+    
+    function toggleMe(a){
+      var e=document.getElementById(a);
+      if(!e)return true;
+      if(e.style.display=="none"){
+        e.style.display="block"
+      } else {
+        e.style.display="none"
+      }
+      return true;
+    }
+*/    
+    var counter = 0;
+    var limit = 99;
+    var arr = new Array();
+    function addInput(divName){
+         if (counter == limit)  {
+              alert("Das Limit von " + counter + " zusätzlichen inputs ist erreicht");
+         }
+         else {
+              var newdiv = document.createElement('div');
+              var count;
+//              if (counter < 8) {count = "&nbsp;&nbsp;"+(counter + 2);} else {count = counter + 2;}  
+//              newdiv.innerHTML = "Entry " + (counter + 1) + " <br><input type='text' name='pz[akt][]' size='30' maxlength='50' />";
+              newdiv.innerHTML = "+&nbsp;Aktivitaet&nbsp;&nbsp;&nbsp;<input type='text' name='pz[akt][]' size='30' maxlength='50' />";
+              var opt="<option value='-1'></option>";
+              for (var key in arr)  
+              {
+                opt = opt.concat("<option value='",key,"'>",arr[key],"</option>\n" );
+              }
+              opt += "</select>";
+              newdiv.innerHTML += "&nbsp;&nbsp;&nbsp;&nbsp;verantwortlich&nbsp;&nbsp;&nbsp;<select name='pz[pers][]'>"+opt;
+              document.getElementById(divName).appendChild(newdiv);
+              counter++;
+         }
+    }
+    function delInput(divId){
+          var Node = document.getElementById(divId).lastChild;
+          document.getElementById(divId).removeChild(Node);
+    }
+    //-->
+    </script>
+
+</head>
+
+<body onload="javascript:ausblenden('akt0');ausblenden('akt1');">
+
+<?php
+	include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
+	if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
+
+    $sub = $_POST["eintragen"];
+    $pz  = $_POST["pz"];
+    $ok  = $_POST["ok"];
+    
+    echo "<div align=\"center\">";
+    echo "<h3>zus&auml;tzliche Formularfelder anzeigen</h3>";
+    if ($sub && isset($pz) && $ok) 
+        {print_r($pz); print("<br />");}
+    else
+    {     
+?>
+    
+
+    <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" name="form_info" target="_self"> 	
+    <table width="50%" border="0" cellspacing="3" cellpadding="3">
+    <tr>
+        <td>
+        <div id="akt">
+        <p>&nbsp;&nbsp;Aktivitaet&nbsp;&nbsp;&nbsp;<input name="pz[akt][]" type="text" size="30" maxlength="50" value="<?php echo $pz['akt'][0]; ?>" />&nbsp;&nbsp;&nbsp;
+            verantwortlich&nbsp;&nbsp;&nbsp;<select name="pz[pers][]" size="1">
+            <?php
+                $select = null;
+                $select = ( "-1"==$pz['cpers'][0] ) ? ' selected' : null;
+                echo "<option $select value=\"-1\"></option>\n";
+                $sql = "SELECT persknr, CONCAT (nachname, ', ',vorname) as pname FROM fhiiqm.Mitarbeiter WHERE abt_tel>5 AND abt_tel<8 ORDER BY 2";
+                if ($result = $dbc->queryObjectArray($sql))
+                {
+                    foreach ($result as $row)
+                    {
+                        $select = ( $row->persknr==$pz['pers'][0] ) ? ' selected' : null;
+    					echo "<option $select value=\"$row->persknr\">$row->pname</option>\n";
+                        $ma .= $row->persknr. ":'" . $row->pname . "',";
+                    }
+                }
+                $ma = substr($ma,0,strlen($ma)-1);
+            ?>
+            </select>
+            <script type="text/javascript">
+            <!--
+                arr = {<?php echo ($ma); ?>}; // Ergebnis: {key:'value',key:'value',...} 
+            //-->
+            </script>
+
+<!--        &nbsp;&nbsp;&nbsp;<a href="<?php //echo "javascript:addInput('akt'," . json_encode($ma) .");" ?>" title="weitere Aktivitaet"><img src="/fhiiqm/img/add.png" /></a></p> -->
+        &nbsp;&nbsp;&nbsp;<a href="<?php echo "javascript:addInput('akt');" ?>" title="weitere Aktivitaet"><img src="/fhiiqm/img/add.png" /></a>
+            &nbsp;&nbsp;&nbsp;<a href="<?php echo "javascript:delInput('akt');" ?>" title="l&ouml;schen letzten Schritt"><img src="/fhiiqm/img/delete.png" /></a></p>
+        <?php
+            if ($sub && isset($pz) && !$ok)
+            {
+                if (count($pz['pers'])>1)
+                {
+                    $i=0;
+                    foreach ($pz['pers'] as $pers)
+                    {
+                        if ($i>0)
+                        {
+                            echo "+&nbsp;Aktivitaet&nbsp;&nbsp;&nbsp;<input name=\"pz[akt][]\" type=\"text\" size=\"30\" maxlength=\"50\" value=\"" .$pz['akt'][$i] . "\" />
+                            &nbsp;&nbsp;&nbsp;verantwortlich&nbsp;&nbsp;&nbsp;<select name=\"pz[pers][]\" size=\"1\">";
+            
+                            $select = ( "-1" == $pers ) ? ' selected' : null;
+                            echo "<option $select value=\"-1\"></option>\n";
+                            foreach ($result as $row)
+                            {
+                                $select = ( $row->persknr == $pers ) ? ' selected' : null;
+            					echo "<option $select value=\"$row->persknr\">$row->pname</option>\n";
+                            }
+                            echo "</select><br/>";
+                        }
+                        $i++;
+                    }
+                }
+            }
+        ?>
+        </div>
+        </td>   
+    </tr>
+    <?php
+		  	if ($sub)
+            {
+                $frage = "Alle Angaben ok?";
+    			echo "<tr>
+    			  <td class=\"red\" valign=\"top\" align=\"left\">$frage
+    			        &nbsp;&nbsp;&nbsp;<input type=\"checkbox\" name=\"ok\" value=\"1\"";
+    			        if ($ok)  echo "checked=\"checked\""; 
+    			echo " /></td>\n</tr>\n";
+            }
+    ?> 
+    <tr>
+        <td><input  class="button" type="submit" name="eintragen" value="  eintragen  " /></td>
+    </tr>
+    </form>
+<?php
+    }
+?>
+    </div>
+</body>
+</html>
\ No newline at end of file