<html>
<head>
<title>Get URL</title>
<style type="text/css">
<!--
#Layer3 {
        position:relative;
        left:60px;
        top:10px;
        width:650px;
        height:110px;
}
.style4 {
        font-family: Arial, Helvetica, sans-serif;
        font-size: 16px;
        font-weight: bold;
}
-->
</style>
</head>

<body bgcolor="lightyellow">
<?php
    error_reporting(0);

//  include "get.php";                                      //include get functions
    include "/home/sultans/web/php/demo/7adv/get.php";      //to make it work with PHP*Tester

    if($_POST)
        validate();

    display();

//------------------------------------------------------------------------------------------------------
function validate()
{
        global $url, $display, $msg, $page;

        $url     = $_POST['url'];
        $display = $_POST['display'];

        if ($url == '') {
                $msg = '*** Please enter URL ***';
                return;
        }

        error_reporting(0);                     #turn off PHP error reporting

        $url2 = str_replace(' ','%20', $url);   #replace spaces with %20
        
        $page = getURL($url2);       
}

//------------------------------------------------------------------------------------------------------
function display()
{       
        global $url, $display, $msg, $page;
        
        $textChecked = ($display=='')     ? 'checked' : ''; 
        $textChecked = ($display=='text') ? 'checked' : ''; 
        $htmlChecked = ($display=='html') ? 'checked' : ''; 

        print "<div id='Layer3'> \n";
        print "<form METHOD=post ACTION=getURL.php> \n";        
        
        print "<fieldset style='width:750'> \n";
        print "<legend>Get a URL</legend> \n"; 

        print "<table border='0'> \n";

        print "<tr>";
        print "<td> Location </td> \n";
        print "<td><input type='text' name='url' value='$url' size='75'/> ";
        print "</tr>";
        print "<tr>";
        print "<td></td>";
        print "<td><input type='submit' value='  Retrieve  ' />";
        print "    <input type='radio'  name='display' value='text' $textChecked> as Text";
        print "    <input type='radio'  name='display' value='html' $htmlChecked> as HTML";
        print "<font color='red'> $msg </font></td> \n";
        print "</tr>";
        print "</table>";       
        print "</fieldset>";
        print "</form> \n";
        print "</div>  \n";
        print "<i>Example:</i> www.google.com \n"; 
        print "<br> \n";
        print "<i>Example:</i> workshop.sps.nyu.edu/~sultans/util/rest/REST.php?user=demo&pswd=demo&db=demo&sql=show tables \n"; 
        print "<hr />  \n";

        if ($display=='text')
            $page = str_replace('<', '<', $page);        //replace '<' with <
        
//      $page = nl2br($page);                               //replace '\n' with <br>

        print $page;
}
?>
</div>

<?php include "../include.php"; ?>              <!-- hyperlink to see the code -->
</body>
</html>