<TITLE>Add user to AR database</TITLE>
<BODY BGcolor=BLACK BACKGROUND="back3.gif" TEXT=WHITE ALINK=WHITE VLINK=WHITE LINK=WHITE>

<!
$field1="BGCOLOR=\"NAVY\"";
$field2="BGCOLOR=\"BLUE\"";

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

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

if (msqlQuery($sock, "SELECT * FROM title ORDER BY nmbr")<0) {
   echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=RED>\n");
   echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
   exit(0);
   }
$fd=msqlStoreResult();
$data=msqlFetchRow($fd);
$i=0;
$title_n[0]=0;
$title_s[0]="Other";
$title_l[0]="Other";
while(#$data>0) {
   $i= $i + 1;
   $title_n[$i]=(int)$data[0];
   $title_s[$i]=$data[1];
   $title_l[$i]=$data[2];
   $data=msqlFetchRow($fd);
   }
msqlFreeResult($fd);
$title_num=$i;

if (msqlQuery($sock, "SELECT * FROM job_title ORDER BY nmbr")<0) {
   echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=RED>\n");
   echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
   exit(0);
   }
$fd=msqlStoreResult();
$data=msqlFetchRow($fd);
$i=0;
$jobtitle_n[0]=0;
$jobtitle_s[0]="None";
$jobtitle_l[0]="None";
while(#$data>0) {
   $i= $i + 1;
   $jobtitle_n[$i]=(int)$data[0];
   $jobtitle_s[$i]=$data[1];
   $jobtitle_l[$i]=$data[2];
   $data=msqlFetchRow($fd);
   }
msqlFreeResult($fd);
$jobtitle_num=$i;

$err="";

if ($chng!="OK") {
   $user=""; $password=""; $ppassword=""; $name=""; $surname="";
   $usr_other_title=""; $h_street=""; $h_city=""; $h_country="";
   $h_zip=""; $h_phone=""; $company="";  $dept=""; $w_street="";
   $w_city=""; $w_zip=""; $w_country="";  $w_phone1=""; $fax="";
   $w_phone2=""; $w_account=""; $account=""; $home_page="";
   $email1=""; $email2="";
   }
else {
   $out=1;

   if ($surname=="") {
      $out=0;
      $err="Last name must be suplied.";
      }
   if ($name=="") {
      $out=0;
      $err="First name must be suplied.";
      }
   if (($password!=$ppassword) && $password!="") {
      $out=0;
      $err="Password and Verify password does not match.";
      }
   if ($password=="") {
      $out=0;
      $err="Password field can not be empty.";
      }
   if ($user=="") {
      $out=0;
      $err="Username field must be suplied.";
      }

   $user=tr($user, "A-Z", "a-z");

   if ($out>0) {
      if (msqlQuery($sock, "SELECT * FROM dis_users WHERE user='$user'")<0) {
         echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=RED>\n");
         echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
         exit(0);
         }
      $fd=msqlStoreResult();
      $data=msqlFetchRow($fd);
      if (#$data>0) {
         $out=0;
         $err="Sorry, user '$user' already exist.";
         }

$title=0;
$other_title="";

   if ($out>0) {
      $title=(int)$usr_title;
      if ($title==0) {
         $other_title=$usr_other_title;
         }

      $input=",'$user','$password','$name','$surname',$title,'$other_title',$job_title,";
      $input=$input + "'$h_street','$h_city','$h_zip','$h_country','$h_phone',";
      $input=$input + "'$company','$dept',";
      $input=$input + "'$w_street','$w_city','$w_zip','$w_country','$w_phone1',";
      $input=$input + "'$w_phone2','$fax','$w_account','$account',";
      $input=$input + "'$email1','$email2','$home_page','0','0'";

      if (msqlQuery($sock, "SELECT _seq FROM dis_users")<0) {
         echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=RED>\n");
         echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
         exit(0);
         }
      $fd=msqlStoreResult();
      $data=msqlFetchRow($fd);

      $input="INSERT INTO dis_users VALUES (" + $data[0] + $input + " )";

      if (msqlQuery($sock, $input)<0) {
         echo("<CENTER><TABLE WIDTH=400 BORDER=2 BGCOLOR=RED>\n");
         echo("<TR><TD>\n<BR><CENTER>$ERRMSG</CENTER><BR>\n</TD></TR>\n</TABLE>\n");
         exit(0);
         }
      echo("</CENTER>\n<FONT SIZE=4>");
      echo("Thank you $surname $name, for taking time to register.<BR>\n");
      echo("Your data has been added to mSQL database.<BR>\n");
      echo("Received data follows:<BR><FONT SIZE=2>\n");

echo("<TABLE WIDTH=500>\n");
echo("<TR><TD WIDTH=150 $field1>Name:</TD><TD WIDTH=350 $field2>$surname, $name</TD></TR>\n");

$tlt=$title_s[$title];
if ((int)$title==0) {
   $tlt=$other_title;
   }
if ($tlt=="") {
   $tlt="(none)";
   }
echo("<TR><TD $field1>Title:</td><td $field2>$tlt</TD></tr>\n");
$job_title=(int)$job_title;
echo("<TR><TD $field1>Job title:</TD><TD $field2>$jobtitle_s[$job_title]</TD></TR>\n");
echo("<tr>\n");
echo("<tr><td $field1></td><td colspan=4><hr size=5></td>\n");
echo("</tr>\n");

echo("<TR><TD COLSPAN=2><BR><FONT COLOR=\"BLACK\">Home Address:</FONT></TD></TR>\n");
echo("<TR><TD $field1>Address: </TD><TD $field2>$h_street</TD></TR>\n");
echo("<TR><TD $field1>City:     </TD><TD $field2>$h_zip, $h_city</TD></TR>\n");
echo("<TR><TD $field1>Country:  </TD><TD $field2>$h_country</TD></TR>\n");
echo("<TR><TD $field1>Phone:    </TD><TD $field2>$h_phone</TD></TR>\n");

echo("<TR><TD COLSPAN=2><BR><FONT COLOR=\"BLACK\">Business Address:</FONT></TD></TR>\n");
echo("<TR><TD $field1>Company:  </TD><TD $field2>$company</TD></TR>\n");
echo("<TR><TD $field1>Department:</TD><TD $field2>$dept</TD></TR>\n");
echo("<TR><TD $field1>Address:  </TD><TD $field2>$w_street</TD></TR>\n");
echo("<TR><TD $field1>City:     </TD><TD $field2>$w_city</TD></TR>\n");
echo("<TR><TD $field1>Zip:      </TD><TD $field2>$w_zip</TD></TR>\n");
echo("<TR><TD $field1>Country:  </TD><TD $field2>$w_country</TD></TR>\n");
echo("<TR><TD $field1>Phone:    </TD><TD $field2>$w_phone1</TD></TR>\n");
echo("<TR><TD $field1>Other phone:</TD><TD $field2>$w_phone2</TD></TR>\n");
echo("<TR><TD $field1>Fax:      </TD><TD $field2>$fax</TD></TR>\n");
echo("<TR><TD COLSPAN=2><BR><FONT SIZE=4 COLOR=\"BLACK\">Account Data:</FONT></TD></TR>\n");
echo("<TR><TD $field1>Business Acc:</TD><TD $field2>$w_account</TD></TR>\n");
echo("<TR><TD $field1>Personal Acc:</TD><TD $field2>$account</TD></TR>\n");
echo("<TR><TD COLSPAN=2><BR></TD></TR>\n");
echo("<TR><TD $field1>E-mail 1:   </TD><TD $field2>$email1</TD></TR>\n");
echo("<TR><TD $field1>E-mail 2:   </TD><TD $field2>$email2</TD></TR>\n");
echo("<TR><TD $field1>Home Page:</TD><TD $field2>$home_page</TD></TR>\n");
$dip="No"; if ((int)$di_page==1) { $dip="Yes"; }
echo("<TR><TD $field1>DI Page:</TD><TD $field2>$dip</TD></TR>\n");
echo("<TR><TD COLSPAN=2><BR></TD></TR>\n");

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



      exit(0);
      }
   }
}


$time=time();
$cur_year=unixtime2year($time);

echo("<FORM ACTION=\"add-form.msql\">\n");
echo("<table width=650 cellpadding=0 cellspacing=0 border=0>\n");
if ($err!="") {
   echo("<TR><TD COLSPAN=3><CENTER>\n<TABLE WIDTH=400 BORDER=2 BGCOLOR=RED>\n");
   echo("<TR><TD>\n<BR><CENTER>$err</CENTER><BR>\n</TD></TR>\n</TABLE>\n</TD></TR>\n");
   echo("<TR><TD COLSPAN=3><HR SIZE=5></TD></TR>\n");
   }
echo("<tr>\n");
echo("<tr><td valign=top colspan=3>Now choose a <b>AR Username</b> - up to 20 characters (no spaces, case-sensitive).<BR>\n");
echo("You will also need to choose a <b>Password</b> - at least 5 characters long and case-sensitive.</td>\n");
echo("</tr>\n");
echo("<tr>\n");
echo("<td align=right valign=top><font size=+1 color=red>&nbsp;&nbsp;&nbsp;Username</font></td><td valign=top colspan=2><input maxlength=\"20\" name=\"user\" type=\"text\" value=\"$user\" size=\"20\"></input></td>\n");
echo("</tr>\n");
echo("<input name=\"chng\" type=\"hidden\" value=\"OK\"></input>\n");
echo("<tr>\n");
echo("<td align=right valign=top><font size=+1 color=red>Password</font></td><td valign=\"top\" colspan=2><input name=\"password\" type=\"password\" value=\"$password\" size=\"20\"></input></td>\n");
echo("</tr>\n");
echo("<tr>\n");
echo("<td align=right valign=top><font size=+1 color=red>Verify <br>password</font></td><td valign=top colspan=2><input name=\"ppassword\" type=\"password\" value=\"$ppassword\" size=\"20\"></input></td>\n");
echo("</tr>\n");
echo("<tr>\n");
echo("<td></td><td colspan=2><hr size=5></td>\n");
echo("</tr>\n");
echo("<TR><TD>First Name:</TD><TD><INPUT name=\"name\"  value=\"$name\" SIZE=30></TD></TR>\n");
echo("<TR><TD>Last name:</TD><TD><INPUT name=\"surname\" value=\"$surname\" SIZE=30></TD></TR>\n");
echo("<TR><TD>Title</td><td>\n");
echo("<select name=\"usr_title\">\n");

$i=0;
while($i<=$title_num) {
   echo("   <OPTION VALUE=\"$title_n[$i]\">$title_s[$i]</OPTION>\n");
   $i=$i + 1;
   }

echo("</select>\n");
echo("<input name=\"usr_other_title\" type=\"text\" value=\"$usr_other_title\" size=\"10\"> (If \"Other\")</input></td>\n");
echo("</tr>\n");
echo("<TR><TD>Job title:</TD><TD>\n");
echo("<select name=\"job_title\">\n");

$i=0;
while($i<=$jobtitle_num) {
   echo("   <OPTION VALUE=\"$jobtitle_n[$i]\">$jobtitle_s[$i]</OPTION>\n");
   $i=$i + 1;
   }

echo("</select>\n");
echo("</TD>\n");
echo("</tr>\n");
echo("<tr>\n");
echo("<tr><td></td><td colspan=4><hr size=5></td>\n");
echo("</tr>\n");
echo("<TR><TD COLSPAN=2><BR>Home Address:</TD></TR>\n");
echo("<TR><TD>Address: </TD><TD><INPUT name=\"h_street\" value=\"$h_street\" SIZE=30></TD></TR>\n");
echo("<TR><TD>City:     </TD><TD><INPUT name=\"h_city\" value=\"$h_city\" SIZE=20></TD></TR>\n");
echo("<TR><TD>Zip:      </TD><TD><INPUT name=\"h_zip\" value=\"$h_zip\" SIZE=10></TD></TR>\n");
echo("<TR><TD>Country:  </TD><TD><INPUT name=\"h_country\" value=\"$h_country\" SIZE=20></TD></TR>\n");
echo("<TR><TD>Phone:    </TD><TD><INPUT name=\"h_phone\" value=\"$h_phone\" SIZE=20></TD></TR>\n");
echo("<TR><TD COLSPAN=2><BR>Business Address:</TD></TR>\n");
echo("<TR><TD>Company:  </TD><TD><INPUT name=\"company\" value=\"$company\" SIZE=30></TD></TR>\n");
echo("<TR><TD>Department:</TD><TD><INPUT name=\"dept\" value=\"$dept\" SIZE=30></TD></TR>\n");
echo("<TR><TD>Address:  </TD><TD><INPUT name=\"w_street\" value=\"$w_street\" SIZE=30></TD></TR>\n");
echo("<TR><TD>City:     </TD><TD><INPUT name=\"w_city\" value=\"$w_city\" SIZE=20></TD></TR>\n");
echo("<TR><TD>Zip:      </TD><TD><INPUT name=\"w_zip\" value=\"$w_zip\" SIZE=10></TD></TR>\n");
echo("<TR><TD>Country:  </TD><TD><INPUT name=\"w_country\" value=\"$w_country\" SIZE=20></TD></TR>\n");
echo("<TR><TD>Phone:    </TD><TD><INPUT name=\"w_phone1\" value=\"$w_phone1\" SIZE=20></TD></TR>\n");
echo("<TR><TD>Other phone:</TD><TD><INPUT name=\"w_phone2\" value=\"$w_phone2\" SIZE=20></TD></TR>\n");
echo("<TR><TD>Fax:      </TD><TD><INPUT name=\"fax\" value=\"$fax\" SIZE=20></TD></TR>\n");
echo("<TR><TD COLSPAN=2><BR><FONT SIZE=4>Account Data:</FONT></TD></TR>\n");
echo("<TR><TD>Business Acc:</TD><TD><INPUT name=\"w_account\" value=\"$w_account\" SIZE=30></TD></TR>\n");
echo("<TR><TD>Personal Acc:</TD><TD><INPUT name=\"account\" value=\"$account\" SIZE=30></TD></TR>\n");
echo("<TR><TD COLSPAN=2><BR></TD></TR>\n");
echo("<TR><TD>E-mail 1:   </TD><TD><INPUT name=\"email1\" value=\"$email1\" SIZE=30></TD></TR>\n");
echo("<TR><TD>E-mail 2:   </TD><TD><INPUT name=\"email2\" value=\"$email2\" SIZE=30></TD></TR>\n");
echo("<TR><TD>Home Page:</TD><TD><INPUT name=\"home_page\" value=\"$home_page\" SIZE=30></TD></TR>\n");
echo("<TR><TD COLSPAN=2><BR></TD></TR>\n");
echo("</tr>\n");
echo("<tr><TD><HR SIZE=5></td><td colspan=4><hr size=5></td>\n");
echo("</tr>\n");
echo("<TR><TD COLSPAN=3><INPUT TYPE=\"reset\" VALUE=\"Clear fileds\">\n");
echo("<INPUT TYPE=\"submit\" VALUE=\"Submit data\"></TD></TR>\n");
echo("</TD></TR>\n");
echo("</TABLE>\n</FORM>");

>

</BODY>
</HTML>
