<TITLE>Update user data</TITLE>
<BODY BGcolor=BLACK 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, "AR")<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="";

   $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 ar_users WHERE user='$user' AND nmbr<>$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);
      if (#$data>0) {
         $out=0;
         $err="Sorry, user '$user' already exist.";
         }

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

$di_page=(int)$di_page;

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

$update="UPDATE ar_users SET " + $update + " WHERE nmbr=" + $nmbr;

if (msqlQuery($sock, $update)<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");

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");

echo("Brisem SHORT_USER<BR>\n");
if (msqlQuery($sock, "DELETE FROM short_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);
   }

echo("Citam podatke o clanovima ...");
if (msqlQuery($sock, "SELECT nmbr, user, name, surname, present FROM ar_users WHERE clan='1' ORDER BY surname, name")<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);

echo(" ucitao ...<BR>\n");

$nn=1;
while(#$data>0) {
   $input="($nn,$data[0],'$data[1]','$data[2]','$data[3]','$data[4]')";

   if (msqlQuery($sock, "INSERT INTO short_user VALUES $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);
      }

   $nn=$nn + 1;
   $data=msqlFetchRow($fd);
   }

echo("Broj podataka ... $nn<BR>\n");
msqlFreeResult($fd);

exit(0);
}


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

echo("<FORM ACTION=\"add-form.msql\">\n");
echo("<table width=720 cellpadding=0 cellspacing=0 border=0>\n");
echo("<td width=100><HR SIZE=5></TD><TD COLSPAN=2 WIDTH=620><hr size=5></td></tr>\n");
if ($err!="") {
   echo("<TR><TD COLSPAN=3><CENTER>\n<TABLE WIDTH=400 BORDER=2 BGCOLOR=RED>\n");
   echo("<TR><TD $field1>\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 WIDTH=100></td><td valign=top colspan=2>Now choose a <b>AR Username</b> - up to 20 characters (no spaces)<br>and case-sensitive.\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("<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 $field1>First Name:</TD><TD $field2><INPUT name=\"name\"  value=\"$name\" SIZE=30></TD></TR>\n");
echo("<TR><TD $field1>Last name:</TD><TD $field2><INPUT name=\"surname\" value=\"$surname\" SIZE=30></TD></TR>\n");
echo("<TR><TD $field1>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 $field1>Job title:</TD><TD $field2>\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 $field1>Address: </TD><TD $field2><INPUT name=\"h_street\" value=\"$h_street\" SIZE=30></TD></TR>\n");
echo("<TR><TD $field1>City:     </TD><TD $field2><INPUT name=\"h_city\" value=\"$h_city\" SIZE=20></TD></TR>\n");
echo("<TR><TD $field1>Zip:      </TD><TD $field2><INPUT name=\"h_zip\" value=\"$h_zip\" SIZE=10></TD></TR>\n");
echo("<TR><TD $field1>Country:  </TD><TD $field2><INPUT name=\"h_country\" value=\"$h_country\" SIZE=20></TD></TR>\n");
echo("<TR><TD $field1>Phone:    </TD><TD $field2><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 $field1>Company:  </TD><TD $field2><INPUT name=\"company\" value=\"$company\" SIZE=30></TD></TR>\n");
echo("<TR><TD $field1>Department:</TD><TD $field2><INPUT name=\"dept\" value=\"$dept\" SIZE=30></TD></TR>\n");
echo("<TR><TD $field1>Address:  </TD><TD $field2><INPUT name=\"w_street\" value=\"$w_street\" SIZE=30></TD></TR>\n");
echo("<TR><TD $field1>City:     </TD><TD $field2><INPUT name=\"w_city\" value=\"$w_city\" SIZE=20></TD></TR>\n");
echo("<TR><TD $field1>Zip:      </TD><TD $field2><INPUT name=\"w_zip\" value=\"$w_zip\" SIZE=10></TD></TR>\n");
echo("<TR><TD $field1>Country:  </TD><TD $field2><INPUT name=\"w_country\" value=\"$w_country\" SIZE=20></TD></TR>\n");
echo("<TR><TD $field1>Phone:    </TD><TD $field2><INPUT name=\"w_phone1\" value=\"$w_phone1\" SIZE=20></TD></TR>\n");
echo("<TR><TD $field1>Other phone:</TD><TD $field2><INPUT name=\"w_phone2\" value=\"$w_phone2\" SIZE=20></TD></TR>\n");
echo("<TR><TD $field1>Fax:      </TD><TD $field2><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 $field1>Business Acc:</TD><TD $field2><INPUT name=\"w_account\" value=\"$w_account\" SIZE=30></TD></TR>\n");
echo("<TR><TD $field1>Personal Acc:</TD><TD $field2><INPUT name=\"account\" value=\"$account\" SIZE=30></TD></TR>\n");
echo("<TR><TD COLSPAN=2><BR></TD></TR>\n");
echo("<TR><TD $field1>E-mail 1:   </TD><TD $field2><INPUT name=\"email1\" value=\"$email1\" SIZE=30></TD></TR>\n");
echo("<TR><TD $field1>E-mail 2:   </TD><TD $field2><INPUT name=\"email2\" value=\"$email2\" SIZE=30></TD></TR>\n");
echo("<TR><TD $field1>Home Page:</TD><TD $field2><INPUT name=\"home_page\" value=\"$home_page\" SIZE=30></TD></TR>\n");

$dip=""; if ($di_page==1) { $dip="CHECKED"; }
echo("<TR><TD $field1>DI Page:</TD><TD $field2><INPUT name=\"di_page\" value=\"1\" TYPE=\"CHECKBOX\" $dip></INPUT></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>
