<?php
session_register("my_result");
session_register("user_err");
?>
<html>
<body>
<h2>Welcome to P2PP monitor.</h2>

<!--
<a href="user_name" >user_name_list</a><br><br> 

<h4>Lookup User</h4><br>
<form method="post" action="lookup.php">

  <table border="0" width="30%" cellpadding="2" cellspacing="1">
    <tr>
      <th> Lookup name: </th>
      <th> <input name="lookupname" type="text" /> </th>
    </tr>
    <tr>
      <th> IP: </th>
      <th> <input name="ip" type="text" /> </th>
    </tr>
    <tr>
      <th> Port: </th>
      <th> <input name="port" type="text" /> </th>
    </tr>
    <tr>
      <th> <input type="submit" value="Lookup user"/> </th>
    </tr>
  </table>
</form>

<br><br>
<h4>Insert key-value pair.</h4><br>
<form method="post" action="insert.php">
  <table border="0" width="30%" cellpadding="2" cellspacing="1">
    <tr>
      <th> Key: </th>
      <th> <input name="key" type="text" /> </th>
    </tr>
    <tr>
      <th> Value: </th>
      <th> <input name="value" type="text" > </th>
    </tr>
    <tr>
      <th> IP: </th>
      <th> <input name="ip" type="text" /> </th>
    </tr>
    <tr>
      <th> Port: </th>
      <th> <input name="port" type="text" /> </th>
    </tr>
    <tr>
      <th>
	<input type="submit" value="Publish object"/>
      </th>
    </tr>
  </table>
</form><?=$PHP_SELF?>">
-->
  <form method="post" action="lookup.php">
  <table> <tr> <td valign="top">
  <table border="0" widtd="50%" cellpadding="2" cellspacing="30">
    
<?php
  include 'create_select_list.php';
  create_select_list();
?>
  </table>
  </td>

    <td valign="top">
 <table >
      <tr> <br> </tr>
      <tr> <br> </tr>
      <tr> <br> </tr>
      <tr> <br> </tr>
   <tr >
      <td valign="top"> LookupObject </td>
      <td> <input type="checkbox" name="object"/> </td>
    </tr>
    <tr>
      <td> Object name </td>
      <td> <input type="text" name="objname"/> </td>
    </tr>
    <tr>
      <td> <input type="submit"  value="Lookup"/> </td>
    </tr>

    <tr> <td> <br> </td> </tr>
    <tr> <td> <br> </td> </tr>


    <tr>
      <td> Publish </td>
    </tr>
    <tr>
      <td> Key  </td>
      <td> <input type="text" name="key"/> </td>
    </tr>
    <tr>
      <td> Value </td>
      <td> <input type="text" name="value"/> </td>
    </tr>
    <tr>
      <td> <input type="submit"  name="insert"  value="Publish"/> </td>
    </tr>

    <tr> <td> <br> </td> </tr>
    <tr> <td> <br> </td> </tr>

    <tr>
      <td> Get routing table </td>
    </tr>
    <tr>
      <td> <input type="submit" name="getrt" value="Get routing table"> </td>
    </tr>

    <tr> <td> <br> </td> </tr>
    <tr> <td> <br> </td> </tr>

    <tr>
      <td> Get resource table </td>
    </tr>
    <tr>
      <td> <input type="submit" name="getro" value="Get resource table"> </td>
    </tr>

  </table>
  </td>
  <td> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp </td>
  <td valign="top" align="right">
    <table>
      <tr> <br> </tr>
      <tr> <br> </tr>
      <tr> <br> </tr>
      <tr> <br> </tr>
      <b>
	<?php
        $errstr=$_SESSION["user_err"];
        if($errstr){
	 echo("<tr> <td> <b> Error: </b></td> </tr>");
	 echo("<tr> <td>");
	 echo("<font color=\"red\"> $errstr </font> <br>");
	 echo("</tr> </td>");
        }
        $result=$_SESSION["my_result"];
	if($result){
	 echo("<tr> <td> <b> Result: </b></td> </tr>");
	 echo("<tr> <td>");
	   echo("<b>");
	   foreach ($result as $str) {
	   if(strstr($str,"200 Ok")!=FALSE){
	    $outstr= "<font color=\"green\"> $str </font> <br>";
	   }else if(strstr($str,"404 Not")!=FALSE) {
	    $outstr= "<font color=\"red\"> $str </font> <br>";
	   }else if(strstr($str,"413 Timeout")!=FALSE) {
	    $outstr= "<font color=\"orange\"> $str </font> <br>";
	   }else if(strstr($str,"302 response")!=FALSE) {
	    $outstr= "<font color=\"blue\"> $str </font> <br>";
	   }else {
	    $outstr = $str."<br>";
	   }
	   echo $outstr;
	   }
	   echo("</b>");
	   //echo ($result);
	   echo("</tr> </td>");
	}
	$_SESSION["my_result"]="";
	   $_SESSION["user_err"]="";    
	?>
    </table>
  </td>
  </tr>
  </table>
  </form>
</body>
</html>