Location: PHPKode > projects > Modular Railroad Asset/Meeting Mgmt > fredl-2-1-9-Release/module/modulsvgbearbeiten.php
<?php
    require_once('../php/fredlSession.php');
    /****************************************************************
     * FREMO Asset Management
     * Module: modulesvgbearbeiten.php
     * Description: Edit the graphic information about a module
     *
     * Created: 12/2003
     * $Log: modulsvgbearbeiten.php,v $
     * Revision 1.4  2005/01/20 21:54:25  dirkj
     * Added button for module calculator.
     *
     * Revision 1.3  2004/11/01 12:35:47  dirkj
     * Modified session handling.
     *
     * Revision 1.2  2004/08/29 08:19:33  dirkj
     * Change in comment only.
     *
     ****************************************************************/
    require_once '../php/sessionhelpers.inc.php';
    $usrObj=getUserObject();
    $nl="\r\n";

    print "<html>";
    print "<head>";
    print '<link rel="stylesheet" type="text/css" href="../'.$myStyleSheet.'">';
?>
<script type="text/javascript">
<!--
   function createStdGerade()
   {
      var length = Number(document.getElementsByName("stdlength")[0].value);
      var width = Number(document.getElementsByName("stdwidth")[0].value);
      document.getElementsByName("newNumconnections")[0].value = 2;
      document.getElementsByName("newC1x")[0].value = 0;
      document.getElementsByName("newC1y")[0].value = 0;
      document.getElementsByName("newC1angle")[0].value = 0;
      document.getElementsByName("newC2x")[0].value = length; 
      document.getElementsByName("newC2y")[0].value = 0;
      document.getElementsByName("newC2angle")[0].value = 180;
      if (document.getElementsByName("g_createsvg")[0].checked)
      {
         /* create svg sequence */
         document.getElementsByName("svgcopy")[0].value = 
	      '<rext x="0" y="-' 
	      + width/2 
	      + '" height=' 
	      + width 
	      + '" width="' 
	      + length 
	      + '" stroke="black" fill="red" />\n'
	      + '<line x1="0" y1="0" x2="'
	      + length
	      + '" y2="0" stroke="black" stroke-width="3" />';
      }
   }

   function createStdBogen()
   {
      var radius = Number(document.getElementsByName("stdradius")[0].value);
      var angle = Number(document.getElementsByName("stdangle")[0].value);
      var width=Number(document.getElementsByName("stdwidth")[1].value);
      var width2=width/2.0;
      var anglerad=angle*Math.PI/180.0;
      var anglerad2=anglerad/2.0;
      var shortside=2.0*(radius-width2)*Math.sin(anglerad2);
      var longside=2.0*(radius+width2)*Math.sin(anglerad2);
      var midside=2.0*radius*Math.sin(anglerad2);
      // var trackendx=radius*Math.tan(anglerad);
      // var trackendy=2.0*radius*Math.sin(anglerad2)*Math.tan(anglerad);
      var trackendx = midside * Math.cos(anglerad2);
      var trackendy = midside * Math.sin(anglerad2);

      document.getElementsByName("newNumconnections")[0].value = 2;
      document.getElementsByName("newC1x")[0].value = 0;
      document.getElementsByName("newC1y")[0].value = 0;
      document.getElementsByName("newC1angle")[0].value = 0;
      document.getElementsByName("newC2x")[0].value = trackendx;
      document.getElementsByName("newC2y")[0].value = trackendy;
      document.getElementsByName("newC2angle")[0].value = angle+180;


      if (document.getElementsByName("b_createsvg")[0].checked)
      {
         /* create svg sequence */
	 var p1x=0, p1y=width2;
	 var p2x=shortside*Math.cos(anglerad2), p2y=p1y+shortside*Math.sin(anglerad2);
	 var p4x=0, p4y=-width2;
	 var p3x=longside*Math.cos(anglerad2), p3y=p4y+longside*Math.sin(anglerad2);

         document.getElementsByName("svgcopy")[0].value = 
	      '<path d="M'+p1x+','+p1y+' L'+p2x+','+p2y+' L'+p3x+','+p3y+' L'+p4x+','+p4y+' Z"\n'
	      + 'fill="grey" stroke="black" stroke-width="1" />\n'
	      + '<path d="M0,0 Q'+radius*Math.tan(anglerad2)+',0 '
	      +  trackendx+','+trackendy+'"\n '
	      + ' stroke="black" fill="none" stroke-width="9" />\n'

	      ;
      }
   }

//-->
</script>

</head>
<body class=right>
<h1>Modul-Grafikdaten bearbeiten</h1>
<?php
   if (!isset($_REQUEST['modifyModuleID'])) {
      echo '<br><br><font color="#FF0000"><b>FEHLER: Diese Funktion muß mit modifyModuleID=<i>value</i> aufgerufen werden!</b></font>';
      exit;
   } else $modifyModuleID=$_REQUEST['modifyModuleID'];
   if (isset($_POST['doModifyModule'])) {
      logAudit("modulsvgbearbeiten.php: Verändere ModulID=".$modifyModuleID);
      // Evtl. vorhandenen Wert in der DB löschen
      $sql="DELETE FROM modulesvg WHERE moduleid=".$_POST['newModuleID'];
      $result=mysql_query($sql) or die(mysql_error());

      /* Neue Wert ein die Datenbank eintragen */
      $sql="INSERT INTO modulesvg
            VALUES (".$_POST['newModuleID'].",
                    '".$_POST['newSvg']."',
                    ".$_POST['newNumconnections'].",
                    ".$_POST['newC1x'].",
                    ".$_POST['newC1y'].",
                    ".$_POST['newC1angle'].",
                    ".$_POST['newC2x'].",
                    ".$_POST['newC2y'].",
                    ".$_POST['newC2angle'].",
                    ".$_POST['newC3x'].",
                    ".$_POST['newC3y'].",
                    ".$_POST['newC3angle'].",
                    ".$_POST['newC4x'].",
                    ".$_POST['newC4y'].",
                    ".$_POST['newC4angle'].")";

      $result=mysql_query($sql) or die(mysql_error());
      echo '<p>Modul-Grafik für ' . $_POST['newModuleID'] . ' geändert.</p>';
      $modifyModuleID=$_POST['newModuleID'];
      $newModuleID=$modifyModuleID;
      if (isset($_POST['newSvg'])) { $newSvg=$_POST['newSvg']; } else { $newSvg='<g id="module'.$newModuleID.'"></g>'; }
      if (isset($_POST['newNumconnections'])) { $newNumconnections=$_POST['newNumconnections']; } else { $newNumconnections=2; }
      if (isset($_POST['newC1x'])) { $newC1x=$_POST['newC1x']; } else { $newC1x=0; }
      if (isset($_POST['newC1y'])) { $newC1y=$_POST['newC1y']; } else { $newC1y=0; }
      if (isset($_POST['newC1angle'])) { $newC1angle=$_POST['newC1angle']; } else { $newC1angle=0; }
      if (isset($_POST['newC2x'])) { $newC2x=$_POST['newC2x']; } else { $newC2x=0; }
      if (isset($_POST['newC2y'])) { $newC2y=$_POST['newC2y']; } else { $newC2y=0; }
      if (isset($_POST['newC2angle'])) { $newC2angle=$_POST['newC2angle']; } else { $newC2angle=0; }
      if (isset($_POST['newC3x'])) { $newC3x=$_POST['newC3x']; } else { $newC3x=0; }
      if (isset($_POST['newC3y'])) { $newC3y=$_POST['newC3y']; } else { $newC3y=0; }
      if (isset($_POST['newC3angle'])) { $newC3angle=$_POST['newC3angle']; } else { $newC3angle=0; }
      if (isset($_POST['newC4x'])) { $newC4x=$_POST['newC4x']; } else { $newC4x=0; }
      if (isset($_POST['newC4y'])) { $newC4y=$_POST['newC4y']; } else { $newC4y=0; }
      if (isset($_POST['newC4angle'])) { $newC4angle=$_POST['newC4angle']; } else { $newC4angle=0; }

   } else {

      /* Werte aus der Datenbank holen und im Formular eintragen */
      $sql="SELECT * FROM modulesvg WHERE moduleid=" . $modifyModuleID;
      $result=mysql_query($sql) or die(mysql_error());
      if (mysql_num_rows($result)<>1)
      {
         echo "<p>Keine Grafikinformationen gefunden. Korrekte Werte bitte eintragen.</p>";
         $newModuleID=$modifyModuleID;
         $newSvg='<g id="module'.$modifyModuleID.'"></g>';
         $newNumconnections=2;
         $newC1x=0;
         $newC1y=0;
         $newC1angle=0;
         $newC2x=100;
         $newC2y=0;
         $newC2angle=180;
         $newC3x=0;
         $newC3y=0;
         $newC3angle=0;
         $newC4x=0;
         $newC4y=0;
         $newC4angle=0;
      } else {
         $module=mysql_fetch_object($result);
         $newModuleID=$modifyModuleID;
         $newSvg=$module->svg;
         $newNumconnections=$module->numconnections;
         $newC1x=$module->c1x;
         $newC1y=$module->c1y;
         $newC1angle=$module->c1angle;
         $newC2x=$module->c2x;
         $newC2y=$module->c2y;
         $newC2angle=$module->c2angle;
         $newC3x=$module->c3x;
         $newC3y=$module->c3y;
         $newC3angle=$module->c3angle;
         $newC4x=$module->c4x;
         $newC4y=$module->c4y;
         $newC4angle=$module->c4angle;
      }
   }

echo  '<form action="modulsvgbearbeiten.php?modifyModuleID=' . $modifyModuleID . '" method="post">';
echo  '<table bgcolor="#dddddd">';
echo  '<tr><td><label>Modul-ID: </label></td><td><input type="Text" name="newModuleID" size="20" maxlength="20" value="'.$newModuleID.'" readonly></td></tr>';
echo  '<tr><td><label>SVG: </label></td><td><textarea cols="80" rows="10" name="newSvg"  maxlength="2000" >'.$newSvg.'</textarea></td></tr>
       </table>';
echo ' <p></p>';
echo ' <table bgcolor="#eeeeee">
       <tr><td><table bgcolor="#dddddd">
               <tr><td><label>Anzahl Anschlüsse: </label></td>';
        echo ' <td><input type="Text" name="newNumconnections" size="20" maxlength="20" value="'.$newNumconnections.'"></td></tr>';
        echo ' <tr><td><b>Anschluß 1:</b></td>
                   <td></td></tr>
               <tr><td><label>X: </label></td>
                   <td><input type="Text" name="newC1x" size="5" maxlength="5" value="'.$newC1x.'"></td></tr>
               <tr><td><label>Y: </label></td>
                   <td><input type="Text" name="newC1y" size="5" maxlength="5" value="'.$newC1y.'"></td></tr>
               <tr><td><label>Winkel: </label></td>
                   <td><input type="Text" name="newC1angle" size="5" maxlength="5" value="'.$newC1angle.'"></td></tr>';
        echo ' <tr><td><b>Anschluß 2:</b></td>
                   <td></td></tr>
               <tr><td><label>X: </label></td>
                   <td><input type="Text" name="newC2x" size="5" maxlength="5" value="'.$newC2x.'"></td></tr>
               <tr><td><label>Y: </label></td>
                   <td><input type="Text" name="newC2y" size="5" maxlength="5" value="'.$newC2y.'"></td></tr>
               <tr><td><label>Winkel: </label></td>
                   <td><input type="Text" name="newC2angle" size="5" maxlength="5" value="'.$newC2angle.'"></td></tr>';
        echo ' <tr><td><b>Anschluß 3:</b></td>
                   <td></td></tr>
               <tr><td><label>X: </label></td>
                   <td><input type="Text" name="newC3x" size="5" maxlength="5" value="'.$newC3x.'"></td></tr>
               <tr><td><label>Y: </label></td>
                   <td><input type="Text" name="newC3y" size="5" maxlength="5" value="'.$newC3y.'"></td></tr>
               <tr><td><label>Winkel: </label></td>
                   <td><input type="Text" name="newC3angle" size="5" maxlength="5" value="'.$newC3angle.'"></td></tr>';
        echo ' <tr><td><b>Anschluß 4:</b></td>
                   <td></td></tr>
               <tr><td><label>X: </label></td>
                   <td><input type="Text" name="newC4x" size="5" maxlength="5" value="'.$newC4x.'"></td></tr>
               <tr><td><label>Y: </label></td>
                   <td><input type="Text" name="newC4y" size="5" maxlength="5" value="'.$newC4y.'"></td></tr>
               <tr><td><label>Winkel: </label></td>
                   <td><input type="Text" name="newC4angle" size="5" maxlength="5" value="'.$newC4angle.'"></td></tr>';
        echo '     </table></td>';
echo ' <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>';
?>
       <td valign=top>Standard-Elemente:<br>
       <table><tr bgcolor="#aa8866"><td><table>
          <tr><td>Standard-Gerade</td></tr>
	  <tr><td><label>Länge: </label><input type="Text" name="stdlength" size="10" value="0" ></input></td></tr>
	  <tr><td><label>Breite: </label><input type="Text" name="stdwidth" size="10" value="0" ></input></td></tr>
	  <tr><td><input type="checkbox" name="g_createsvg" >SVG erzeugen</input></td></tr>
	  <tr><td><input type="Button" value="Erzeugen" onClick="javascript:createStdGerade()"></td></tr>
	  </table></td></tr>
       <tr><td>&nbsp;<br><br><br><br></td></tr>
       <tr bgcolor="#aa8866"><td><table>
          <tr><td>Standard-Bogen</td></tr>
	  <tr><td><label>Radius: </label><input type="Text" name="stdradius" size=10 value="0" /></td></tr>
	  <tr><td><label>Winkel: </label><input type="Text" name="stdangle" size=10 value="0" /></td></tr>
	  <tr><td><label>Breite: </label><input type="Text" name="stdwidth" size="10" value="0" ></input></td></tr>
	  <tr><td><input type="checkbox" name="b_createsvg" >SVG erzeugen</input></td></tr>
	  <tr><td><input type="Button" value="Erzeugen" onClick="javascript:createStdBogen()"></td></tr>
          </table></td></tr>
       </table>
       </td>
       <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
       <td valign=top>
       SVG-Vorlage:<br>
       <textarea cols="33" rows="10" name="svgcopy" readonly></textarea>
       </td>
       </tr>
      </table>
      </td></tr>
     </table>
    <p>
    <input type="Submit" name="doModifyModule" value="Änderung speichern">
    </p>
<?php
print $nl.'<p>
    <input type=Button 
           class=cmd 
	   onClick=\'parent.frames["rechts"].location.href="modulbearbeiten.php?modifyModuleID='.$newModuleID.'"\' 
	   value="Moduldaten bearbeiten" >'.$nl;
print '<input type=Button 
           class=cmd 
	   onClick=\'parent.frames["rechts"].location.href="modulcopy.php?moduleID='.$newModuleID.'"\' 
	   value="Dieses Modul kopieren" >'.$nl;
print '</p>'.$nl;
print '<p>'.$nl;
print '<a href="modulecalc.php" target="_blank">Modulrechner anzeigen</a>';
print '</p>';
?>
    </form>
</body>
</html>
Return current item: Modular Railroad Asset/Meeting Mgmt