<HTML>
 <HEAD>
  <TITLE>
   Page admin
  </TITLE>
 </HEAD>
 <BODY BGCOLOR="#FF0000" TEXT="#000000">
 <H1>
  <CENTER>
   TallSkin's adminpage
  </CENTER>
 </H1>
 <? if (!$mode) {
    printLoginForm("Please log in");
    }
    else
    {
     if (checklogin($name,$password))
     {
      printAdminPage();
     }
     else
     {
      printLoginForm("Wrong username or password, please log in again");
     }
    }
    
    function printLoginForm($message)
    {
     echo "<CENTER><H3>$message</H3></CENTER>\n";
    ?>
    <CENTER>
    <FORM ACTION="admin.php" METHOD="POST">
    <TABLE COLS="2" BORDER="0">
    <TR>
     <TD>
      Username:
     </TD>
     <TD>
      <INPUT TYPE="TEXT" NAME="name">
    </TD>
   </TR>
   <TR>
    <TD>
     Password:
    </TD>
    <TD>
     <INPUT TYPE="PASSWORD" NAME="password">
    </TD>
   </TR>
   </TABLE>
   <INPUT TYPE="hidden" NAME="mode" VALUE="admin">
   <INPUT TYPE="submit" NAME="login">
   </FORM>
   <? } //end printLoginForm 
      function printAdminPage()
      {
       echo "<H1>Admin page</H1>";
       printLinkAdmin();
      }
      function checkLogin($n,$p)
      {
       $db="www_admin";
       $table="users";
       $checkquery="SELECT password FROM $table where user_id=\"$n\"";
       mysql_connect("localhost","root","redrum1");
       $r=mysql_db_query($db,$checkquery);
       if (!$r) {
         echo mysql_errno().": ";
         echo mysql_error()."<BR>";
       }
       $row=mysql_fetch_row($r);
       $found_p=$row[0];
       mysql_close();
       if ($row[0]==$p)
       {
        return 1;
       }
       else
       {
        return 0;
       }
      } //end checklogin
      function printLinkAdmin()
      {
       $db="www_admin";
       $table="links";
       $checkquery="SELECT * from $table ORDERED BY popularity";
       mysql_connect("localhost","root","redrum1");
       $result=mysql_db_query($db,$checkquery);
       if (!$r)
       {
        printLinkForm();
       }
       else
       {
       }
      } #end function

      function printLinkForm()
      {
      ?>
<FORM ACTION="admin.php" METHOD="post">
<INPUT TYPE="hidden" NAME="mode" VALUE="addlink">
<TABLE COLS="2" BORDER="1">
<TR>
 <TD>
  Name:
 </TD>
 <TD>
  <INPUT TYPE="TEXT" NAME="name">
 </TD>
</TR>
<TR>
 <TD>
  URL:
 </TD>

  ?>
  </BODY>
 </HTML>
