{source}

<?php
    $SelectedStandard = $_POST['SelectedStandard'];
    $SelectedType = $_POST['SelectedType'];
    $SelectedRating = $_POST['SelectedRating'];
    $tablename = "stdflange";
    $StandardNameSelected = $SelectedStandard;
    $FlangeTypeSelected = $SelectedType; 
    $PressureRatingSelected = $SelectedRating;
?>
    <h3>Flange Dimension</h3>
    <p>Flanges are used on equipment for the nozzles and in piping systems. The flanges are bolted together with a gasket in between to prevent leackage. The dimensions of flanges in piping systems and also the smaller flanges on equipment are standardized. Equipment such as pressure vessels can also have so-called body flanges. These flanges are specially made for the diameter of the equipment and are designed and calculated individually.</p>
    <p>Below figure gives the dimension legenda as used in the table for flange dimensions.</p>
    <div style="text-align: center">
        <img width="200" height="300" border="0" title="Flange Dimension" alt="Flange Dimension" src="/images/tools/nozzle.gif">
    </div>
    <div>
      <form method="post" action="<?php print("$PHP_SELF"); ?>">
        <table border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="150px" valign="top">Standards available:</td>
            <td valign="top"> ANSI B16.5 - American standard flanges<br>
              B16.47 a - serie is former MSS SP-44<br>
              B16.47 b - serie is former API 605<br>
              ISO DIN 2631 - 2638 </td>
          </tr>
          <tr>
            <td>Flange Standard</td>
            <td>
              <select class="calc_select" name="SelectedStandard">
                <option value="ASME B16.5" <?PHP if($SelectedStandard == "ASME B16.5") print("selected"); ?> >ASME B16.5</option>
                <option value="ASME B16.47B" <?PHP if($SelectedStandard == "ASME B16.47B") print("selected"); ?> >ASME B16.47B</option>
                <option value="ISO-DIN" <?PHP if($SelectedStandard == "ISO-DIN") print("selected"); ?> >ISO
                DIN 2631 - 2638</option>
              </select>
            </td>
          </tr>
          <tr>
            <td>Flange Type</td>
            <td>
              <select class="calc_select" name="SelectedType" size="1">
                <option value="WN" <?PHP if($SelectedType == WN) print("selected"); ?> >WN</option>
                <option value="LWN" <?PHP if($SelectedType == LWN) print("selected"); ?> >LWN</option>
                <option value="HLWN" <?PHP if($SelectedType == HLWN) print("selected"); ?> >HLWN</option>
              </select>
            </td>
          </tr>
          <tr>
            <td>Pressure Rating</td>
            <td>
              <select class="calc_select" name="SelectedRating" size="1">
                <option value="150" <?PHP if($SelectedRating == 150) print("selected"); ?> >150
                lbs</option>
                <option value="300" <?PHP if($SelectedRating == 300) print("selected"); ?> >300
                lbs</option>
                <option value="600" <?PHP if($SelectedRating == 600) print("selected"); ?> >600
                lbs</option>
                <option value="900" <?PHP if($SelectedRating == 900) print("selected"); ?> >900
                lbs</option>
                <option value="6" <?PHP if($SelectedRating == 6) print("selected"); ?> >PN
                6</option>
                <option value="10" <?PHP if($SelectedRating == 10) print("selected"); ?> >PN
                10</option>
                <option value="16" <?PHP if($SelectedRating == 16) print("selected"); ?> >PN
                16</option>
                <option value="25" <?PHP if($SelectedRating == 25) print("selected"); ?> >PN
                25</option>
                <option value="40" <?PHP if($SelectedRating == 40) print("selected"); ?> >PN
                40</option>
                <option value="64" <?PHP if($SelectedRating == 64) print("selected"); ?> >PN
                64</option>
                <option value="100" <?PHP if($SelectedRating == 100) print("selected"); ?> >PN
                100</option>
                <option value="160" <?PHP if($SelectedRating == 160) print("selected"); ?> >PN
                160</option>
              </select>
            </td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>
              <input type="hidden" name="stage" value=1>
              <!-- check if this window has not been opened before -->
            </td>
            <td>
              <input type="submit" name="show" value="Show dimensions">
            </td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table>
        <table width="605px" border="0" cellspacing="1" cellpadding="0" align="left" name="TempStress">
          <tr>
            <td width="40px" height="1px"></td>
            <td width="40px" height="1px"></td>
            <td width="40px" height="1px"></td>
            <td width="40px" height="1px"></td>
            <td width="40px" height="1px"></td>
            <td width="40px" height="1px"></td>
            <td width="40px" height="1px"></td>
            <td width="40px" height="1px"></td>
            <td width="40px" height="1px"></td>
            <td width="40px" height="1px"></td>
            <td width="40px" height="1px"></td>
            <td width="40px" height="1px"></td>
            <td width="40px" height="1px"></td>
            <td width="75px" height="1px"></td>
          </tr>
          <tr>
            <td colspan="14" bgcolor="#CCCCCC">
              <div align="center"> <?PHP
                if($SelectedStandard == 'ASME B16.5') print("ASME B16.5");
                if($SelectedStandard == 'ASME B16.47B') print("ANSI B 16.47B");
                if($SelectedStandard == 'ISO-DIN') print("ISO DIN 2631 - 2638");
                if($SelectedType == 'WN') print(" WN ");
                if($SelectedType == 'LWN') print(" LWN ");
                if($SelectedType == 'HLWN') print(" HLWN "); ?> Flanges<br>
                <?PHP
                if($SelectedRating == 150) print("150 LBS ");
                if($SelectedRating == 300) print("300 LBS ");
                if($SelectedRating == 600) print("600 LBS ");
                if($SelectedRating == 900) print("900 LBS ");
                if($SelectedRating == 6) print("PN 6 ");
                if($SelectedRating == 10) print("PN 10 ");
                if($SelectedRating == 16) print("PN 16 ");
                if($SelectedRating == 25) print("PN 25 ");
                if($SelectedRating == 40) print("PN 40 ");
                if($SelectedRating == 64) print("PN 64 ");
                if($SelectedRating == 100) print("PN 100 ");
                if($SelectedRating == 160) print("PN 160 "); ?> </div>
            </td>
          </tr>
          <tr>
            <td bgcolor="#CCCCCC">
              <div align="center"><font size="1">Nom.OD</font></div>
            </td>
            <td bgcolor="#CCCCCC">
              <div align="center"><font size="1">D0<br>
                [mm]</font></div>
            </td>
            <td bgcolor="#CCCCCC">
              <div align="center"><font size="1">D1<br>
                [mm]</font></div>
            </td>
            <td bgcolor="#CCCCCC">
              <div align="center"><font size="1">D2<br>
                [mm]</font></div>
            </td>
            <td bgcolor="#CCCCCC">
              <div align="center"><font size="1">D3<br>
                [mm]</font></div>
            </td>
            <td bgcolor="#CCCCCC">
              <div align="center"><font size="1">D4<br>
                [mm]</font></div>
            </td>
            <td bgcolor="#CCCCCC">
              <div align="center"><font size="1">D5<br>
                [mm]</font></div>
            </td>
            <td bgcolor="#CCCCCC">
              <div align="center"><font size="1">D6<br>
                [mm]</font></div>
            </td>
            <td bgcolor="#CCCCCC">
              <div align="center"><font size="1">H0<br>
                [mm]</font></div>
            </td>
            <td bgcolor="#CCCCCC">
              <div align="center"><font size="1">H1<br>
                [mm]</font></div>
            </td>
            <td bgcolor="#CCCCCC">
              <div align="center"><font size="1">H2<br>
                [mm]</font></div>
            </td>
            <td bgcolor="#CCCCCC">
              <div align="center"><font size="1">No.bolts </font></div>
            </td>
            <td bgcolor="#CCCCCC">
              <div align="center"><font size="1">Weight<br>
                [kg]</font></div>
            </td>
            <td bgcolor="#CCCCCC">
              <div align="center"><font size="1">Notes</font></div>
            </td>
          </tr>
         
<?php
    if (false /* !IsSet($_POST['stage']) */ ) {
        // Initial settings for first opening of window
        $StandardName = 'ASME B16.5';
        $FlangeType = 'WN';
        $PressureRating = 150;
        $NomOD = 0;
        $Note = 0;
        $D0 = 0;
        $D1 = 0;
        $D2 = 0;
        $D3 = 0;
        $D4 = 0;
        $D5 = 0;
        $D6 = 0;
        $h0 = 0;
        $h1 = 0;
        $h2 = 0;
        $nb = 0;
        $Weight = 0;
       
        echo "<p>Click <i>Show dimensions</i> to view the flange dimensions</p>";
    } else {
        $db = JFactory::getDbo();
 
        // Create a new query object.
        $query = $db->getQuery(true);
        $query->select($db->quoteName(array('ID', 'StdName', 'TypeID', 'Rating', 'NomOD', 'Note', 'D0', 'D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'h0', 'h1', 'h2', 'nb', 'Weight')));
        $query->from($db->quoteName($tablename));
        $query->where($db->quoteName('StdName') . ' LIKE '. $db->quote($StandardNameSelected)
                        . ' AND ' . $db->quoteName('TypeID') . ' LIKE '. $db->quote($FlangeTypeSelected)
                        . ' AND ' . $db->quoteName('Rating') . ' LIKE '. $db->quote($PressureRatingSelected));
        $query->order('NomOD ASC');
       
        $db->setQuery($query);
        $result = $db->loadObjectList();

        if (!$result) {
            echo "<p>Result is invalid: ";
            echo $query;
            echo '<br/>Invalid query: '.mysql_error().'<br/>';
            echo $result."</p>";
        } else {
            $rowCount = count($result);
           
            for ($i = 0; $i < $rowCount; $i++) {
                //$ID = $row[0];
                $StandardName = $result[$i]->StdName;
                $FlangeType = $result[$i]->TypeID;
                $PressureRating = $result[$i]->Rating;
                $NomOD = $result[$i]->NomOD;
                $Note = $result[$i]->Note;
                $D0 = $result[$i]->D0;
                $D1 = $result[$i]->D1;
                $D2 = $result[$i]->D2;
                $D3 = $result[$i]->D3;
                $D4 = $result[$i]->D4;
                $D5 = $result[$i]->D5;
                $D6 = $result[$i]->D6;
                $h0 = $result[$i]->h0;
                $h1 = $result[$i]->h1;
                $h2 = $result[$i]->h2;
                $nb = $result[$i]->nb;
                $Weight = $result[$i]->Weight;
               
                print("
                    <tr>
                      <td bgcolor=#FFFFCC>
                       <div align=right><font color=000000 size='1'>$NomOD</font></div>
                      </td>
                      <td bgcolor=#FFFFCC>
                        <div align=right><font color=000000 size='1'>$D0</font></div>
                      </td>
                      <td bgcolor=#FFFFCC>
                        <div align=right><font color=000000 size='1'>$D1</font></div>
                      </td>
                      <td bgcolor=#FFFFCC>
                        <div align=right><font color=000000 size='1'>$D2</font></div>
                      </td>
                      <td bgcolor=#FFFFCC>
                        <div align=right><font color=000000 size='1'>$D3</font></div>
                      </td>
                      <td bgcolor=#FFFFCC>
                        <div align=right><font color=000000 size='1'>$D4</font></div>
                      </td>
                      <td bgcolor=#FFFFCC>
                        <div align=right><font color=000000 size='1'>$D5</font></div>
                      </td>
                      <td bgcolor=#FFFFCC>
                        <div align=right><font color=000000 size='1'>$D6</font></div>
                      </td>
                      <td bgcolor=#FFFFCC>
                        <div align=right><font color=000000 size='1'>$h0</font></div>
                      </td>
                      <td bgcolor=#FFFFCC>
                        <div align=right><font color=000000 size='1'>$h1</font></div>
                      </td>
                      <td bgcolor=#FFFFCC>
                        <div align=right><font color=000000 size='1'>$h2</font></div>
                      </td>
                      <td bgcolor=#FFFFCC>
                        <div align=right><font color=000000 size='1'>$nb</font></div>
                      </td>
                      <td bgcolor=#FFFFCC>
                        <div align=right><font color=000000 size='1'>$Weight</font></div>
                      </td>
                      <td bgcolor=#FFFFCC>
                        <div align=right><font color=000000 size='1'>$Note</font></div>
                      </td>
                    </tr>");
            } // for
        } // else result
    } // if IsSet stage
?>
        <tr>
        <td style="text-align:center;" colspan="14">
        <font size="1">Note: For study purposes only. Results should be optimized and approved by qualified engineer.</font>
        </td>
        </tr>
        </table>
      </form>
    </div>
    <p><br/></p>
    <p><br/></p>

{/source}