<TITLE>Member administration</TITLE>
<BODY BGcolor=BLACK TEXT=WHITE ALINK=WHITE VLINK=WHITE LINK=WHITE>

<CENTER>
<FONT SIZE=5>Member Administration:</FONT><BR>
(authorize memeber)<BR>
<P></P>

<TABLE WIDTH=500>
<TR><TD><CENTER>
Please, insert requested data, and than press AUTHORIZE button
</CENTER></TD></TR>
</TABLE>

<!
$color1="NAVY";
$color2="BLUE";
$color3="#99CCCC";
$color5="#2020FF";
$color4="RED";

$font1="WHITE";

$ffont1="<FONT FACE=\"Arial, Helvetica\" COLOR=\"GOLD\"><B>";
$ffont2="<FONT FACE=\"Arial, Helvetica\">&nbsp";
$fend="</FONT>";


$admin=$REMOTE_USER;
echo("$admin");

$sock=msqlConnect();
if ($sock<0) {
   echo("<CENTER><TABLE WIDTH=500 BORDER=2 BGCOLOR=\"$color4\">\n");
   echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
   exit(0);
   }

if (msqlSelectDB($sock, "MEMBERS")<0) {
   echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=\"$color4\">\n");
   echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
   exit(0);
   }

$id_us=(int)$id_us;

if ($id_us==0) {
   echo("<CENTER><TABLE WIDTH=500 BORDER=2 BGCOLOR=\"$color4\">\n"); 
   echo("<TR><TD>\n<BR><CENTER>Error occourred. Previous program did not supply ID_US variable.</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
   exit(0);
   }

if (msqlQuery($sock, "SELECT * FROM user_data WHERE id_us=$id_us")<0) {
   echo("<CENTER><TABLE WIDTH=500 BORDER=2 BGCOLOR=\"$color4\">\n");
   echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
   exit(0);
   }
$fd=msqlStoreResult();
$user_data=msqlFetchRow($fd);
msqlFreeResult($fd);

if (msqlQuery($sock, "SELECT * FROM billing WHERE id_us=$id_us ORDER BY id_bill DESC")<0) {
   echo("<CENTER><TABLE WIDTH=500 BORDER=2 BGCOLOR=\"$color4\">\n");
   echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
   exit(0);
   }
$fd=msqlStoreResult();
$billing=msqlFetchRow($fd);

if (#$user_data==0) {
   echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=\"$color3\">\n");
   echo("<TR><TD>\n<BR><CENTER>Error occoured.<BR>You are trying to authorize nonexistent user.</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
   exit(0);
   }


echo("<FORM ACTION=\"authorize.msql\" METHOD=\"POST\">\n");

echo("<INPUT TYPE=\"HIDDEN\" NAME=\"authorize\" VALUE=\"OK\">\n");
echo("<INPUT TYPE=\"HIDDEN\" NAME=\"id_us\" VALUE=\"$id_us\">\n");

echo("<CENTER>\n<BR>\n<P>\n<TABLE WIDTH=530>\n");

echo("<TR><TD WIDTH=100 BGCOLOR=\"$color1\">$ffont1 Username: $fend</TD><TD WIDTH=200 BGCOLOR=\"$color2\">$ffont2<A HREF=\"userinfo.msql?id_us=$id_us\">$user_data[1]</A>$fend</TD>\n");
echo("<TD WIDTH=200 BGCOLOR=\"$color1\">$ffont1 Password:</TD><TD WIDTH=200 BGCOLOR=\"$color2\" COLSPAN=2>$ffont2 $user_data[2] $fend</TD>\n");
echo("<TR><TD BGCOLOR=\"$color1\">$ffont1 Real Name: $fend</TD><TD COLSPAN=4 BGCOLOR=\"$color2\">$ffont2<FONT COLOR=\"$font1\">$user_data[4], $user_data[3] $fend</TD></TR>\n");
echo("<TR><TD BGCOLOR=\"$color1\">$ffont1 Street: $fend</TD><TD COLSPAN=4 BGCOLOR=\"$color2\">$ffont2 $billing[2] $fend</TD></TR>\n");
echo("<TR><TD BGCOLOR=\"$color1\">$ffont1 Zip, Country: $fend</TD><TD COLSPAN=4 BGCOLOR=\"$color2\">$ffont2 $billing[4], $billing[3] $fend</TD></TR>\n");
echo("<TR><TD BGCOLOR=\"$color1\">$ffont1 Country: $fend</TD><TD COLSPAN=4 BGCOLOR=\"$color2\">$ffont2 $billing[5] $fend</TD></TR>\n");

echo("<TR><TD BGCOLOR=\"$color1\">$ffont1 Card type: $fend</TD><TD COLSPAN=2 BGCOLOR=\"$color2\">$ffont2 $billing[6] $fend</TD><TD BGCOLOR=\"$color1\">$ffont1 Card expire:</TD><TD BGCOLOR=\"$color2\">$ffont2 $billing[8] $fend</TD></TR>\n");
echo("<TR><TD BGCOLOR=\"$color1\">$ffont1 Card No: $fend</TD><TD COLSPAN=2 BGCOLOR=\"$color2\">$ffont2 $billing[7] $fend</TD>\n");
echo("<TD BGCOLOR=\"$color1\">$ffont1 Amount: $fend</TD><TD BGCOLOR=\"$color2\">$ffont2 $billing[9]\$ $fend</TD></TR>\n");

if ($auth=="" && $authorize=="OK") {
   $authorize="";
   }

if ($authorize!="OK") {
   echo("<TR><TD BGCOLOR=\"$color1\">$ffont1 Auth Code: $fend</TD><TD BGCOLOR=\"$color2\">$ffont2 <INPUT NAME=\"auth\" SIZE=6 MAXLENGTH=6></INPUT>$fend</TD>\n");
   echo("<TD BGCOLOR=\"$color1\">Credits:</TD><TD BGCOLOR=\"$color2\">\n");
   echo("<center>\n<SELECT NAME=\"credit\">\n");
   echo("<OPTION VALUE=\"300000000\">300M</OPTION>\n");
   echo("<OPTION VALUE=\"100000000\" SELECTED >100M</OPTION>\n");
   echo("<OPTION VALUE=\"5000000\">5M</OPTION>\n");
   echo("<OPTION VALUE=\"2000000\">2M</OPTION>\n");
   echo("<OPTION VALUE=\"100000\">100K</OPTION>\n");
   echo("<OPTION VALUE=\"-1\">REVOKE</OPTION>\n");
   echo("</SELECT>\n</TD>");
   echo("<TD BGCOLOR=\"BLACK\"><CENTER><A HREF=\"adduser.msql?delete=OK&id_us=$id_us\">Delete</A></CENTER></TD></TR>\n");

   echo("<TR><TD COLSPAN=5><CENTER>$ffont2<INPUT TYPE=\"submit\" VALUE=\"AUTHORIZE\">$fend</CENTER></TD></TR>\n");

   echo("</TABLE>\n");
   echo("</FORM>\n");
} 
else {
   echo("<TR><TD BGCOLOR=\"$color1\">$ffont1 Auth Code: $fend</TD><TD BGCOLOR=\"$color2\">$ffont2 $auth</TD>\n");
   echo("<TD BGCOLOR=\"$color1\">Credits:</TD><TD COLSPAN=2 BGCOLOR=\"$color2\">\n");
   echo("$credit\n</TD>");

   echo("</TABLE>\n");
   echo("</FORM>\n");

   $tme=time();                       /* What's current time ? */
   $datum=strftime("%Y%m%d", $tme);   /* Generate time stamp.  */

   if (msqlQuery($sock, "SELECT _seq FROM transaction")<0) {
      echo("<CENTER><TABLE WIDTH=500 BORDER=2 BGCOLOR=\"$color4\">\n");
      echo("<TR><TD>\n<BR><CENTER>_SEQ: $ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
      exit(0);
      }
   $rt=msqlStoreResult();
   $tt=msqlFetchRow($rt);
   $next=$tt[0];
   msqlFreeResult($rt);

   if (msqlQuery($sock, "INSERT INTO transaction VALUES($next,$billing[0],$datum,'$auth',$billing[9],'1')")<0) {
      echo("<CENTER><TABLE WIDTH=500 BORDER=2 BGCOLOR=\"$color4\">\n");
      echo("<TR><TD>\n<BR><CENTER>TRANSACTION: $ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
      exit(0);
      }

   if (msqlQuery($sock, "SELECT user FROM credits WHERE id_us=$id_us")<0) {
      echo("<CENTER><TABLE WIDTH=500 BORDER=2 BGCOLOR=\"$color4\">\n");
      echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
      exit(0);
      }
   $rt=msqlStoreResult();
   if (msqlNumRows($rt)>0) {
      if (msqlQuery($sock, "UPDATE credits SET credit=$credit, datum=$datum")<0) {
         echo("<CENTER><TABLE WIDTH=500 BORDER=2 BGCOLOR=\"$color4\">\n");
         echo("<TR><TD>\n<BR><CENTER>QUERY: $ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
         exit(0);
         }
      }
   else { 
      if (msqlQuery($sock, "INSERT INTO credits VALUES ($id_us,'$user_data[1]',$credit,$datum)")<0) {
         echo("<CENTER><TABLE WIDTH=500 BORDER=2 BGCOLOR=\"$color4\">\n");
         echo("<TR><TD>\n<BR><CENTER>INSERT: $ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
         exit(0);
         }
      }
  msqlFreeResult($rt);
   if (msqlQuery($sock, "UPDATE user_data SET member='1' WHERE id_us=$id_us")<0) {
      echo("<CENTER><TABLE WIDTH=500 BORDER=2 BGCOLOR=\"$color4\">\n");
      echo("<TR><TD>\n<BR><CENTER>UPDATE: $ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
      exit(0);
      }

   echo("$ffont1 <BLINK>This user has just been AUTHORIZED!!!</BLINK> $fend\n");
   }


echo("<br><A HREF=index.html>BACK</A>");
msqlClose($sock);
>
