PHP Classes

File: testdist.php

Recommend this page to a friend!
  Classes of Thomas Jakober   distance class   testdist.php   Download  
File: testdist.php
Role: Example script
Content type: text/plain
Description: Example file
Class: distance class
Calculate the air distance between two cities
Author: By
Last change:
Date: 15 years ago
Size: 2,198 bytes
 

Contents

Class file image Download
<?php

/**
 * testdist.php
 *
 * @version $Id$
 * @copyright 2009
 */

include "distance.class.php";
$d1 = '';
$d2 = '';
$d3 = '';
$di = '';

if (isset(
$_POST['center'])) {
   
$di = 'Distance';
   
$oDist = new distance($_POST['center'], $_POST['unit']);
    if (!empty(
$_POST['c1'])) {
       
$d1 = round($oDist->calcDistance($_POST['c1']), 1) . $_POST['unit'];
    }
    if (!empty(
$_POST['c2'])) {
       
$d2 = round($oDist->calcDistance($_POST['c2']), 1) . $_POST['unit'];
    }
    if (!empty(
$_POST['c3'])) {
       
$d3 = round($oDist->calcDistance($_POST['c3']), 1) . $_POST['unit'];
    }
}
$ct0 = (isset($_POST['center']) ? $_POST['center'] : '');
$ct1 = (isset($_POST['c1']) ? $_POST['c1'] : '');
$ct2 = (isset($_POST['c2']) ? $_POST['c2'] : '');
$ct3 = (isset($_POST['c3']) ? $_POST['c3'] : '');

?>
<html>
    <head>
        <title>Distance Calculator</title>
    </head>
    <body>
        <h3>Calculate the Air Distance between Cities</h3>
        <p>Enter cities in the form: 'Z&uuml;rich Switzerland'</p>
        <div id="cdst">
            <form name="dcc" method="post" action="<?=$_SERVER['SCRIPT_NAME']?>">
                <input type="hidden" name="app" value="dic">
                <input type="hidden" name="cmd" value="dst">
                <table>
                    <tr>
                        <td>Units</td>
                        <td>
                            <select name="unit">
                                <option selected>km</option>
                                <option>mi</option>
                                <option>nmi</option>
                            </select>
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>Center City</td>
                        <td><input type="text" name="center" value="<?=$ct0?>"></td>
                        <td><?=$di?></td>
                    </tr>
                    <tr>
                        <td>City 1</td>
                        <td><input type="text" name="c1" value="<?=$ct1?>"></td>
                        <td class="dist"><?=$d1?></td>
                    </tr>
                    <tr>
                        <td>City 2</td>
                        <td><input type="text" name="c2" value="<?=$ct2?>"></td>
                        <td class="dist"><?=$d2?></td>
                    </td>
                    <tr>
                        <td>City 3</td>
                        <td><input type="text" name="c3" value="<?=$ct3?>"></td>
                        <td class="dist"><?=$d3?></td>
                    </tr>
                    <tr>
                        <td>Action:</td>
                        <td><button type="submit">Calculate</button></td>
                        <td></td>
                    </tr>
                </table>
            </form>
        </div>
    </body>
</html>