#!/usr/local/bin/perl5.00452
use CGI qw(:standard);
#binmode(STDIN);
$real_path="";
print header();

$id = param('ID');


if ($id eq "") {
  exit(-1);
}

$ename = param('E_NAME');
$bbc  = param('BBCALL');
$cell = param('HANDPHONE');
$o_tel = param('O_TEL');
$o_address = param('O_ADDRESS');
$c_tel = param('C_TEL');
$c_address = param('C_ADDRESS');
$h_tel = param('H_TEL');
$h_address = param('H_ADDRESS');
$email = param('EMAIL');
$homepage = param('HOMEPAGE');

#save the file list to a array.

sub DirFiles 
{
  my $Dir = $_[0];
  my @files;
  
  opendir(DIR, $Dir) || return ();
  @files = readdir(DIR);
  closedir(DIR);
  @files;
}

# Process the form if there is a file name entered.

print "<HTML>";
print "<BODY BGCOLOR=#FFFFFF BACKGROUND=\"/~cadmate/BrickWall.gif\">";
print "<TABLE BORDER=1>";
print "<TR><TD>中文姓名";
if ($ename eq "ON") {
  print "<TD>英文姓名";
}
if ($bbc eq "ON") {
  print "<TD>BBCALL";
}
if ($cell eq "ON") {
  print "<TD>大哥大";
}
if ($o_address eq "ON") {
  print "<TD>住址(公/學)";
}
if ($o_tel eq "ON") {
  print "<TD>電話(公/學)";
}
if ($c_address eq "ON") {
  print "<TD>住址(通訊)";
}
if ($c_tel eq "ON") {
  print "<TD>電話(通訊)";
}
if ($h_address eq "ON") {
  print "<TD>住址(家)";
}
if ($h_tel eq "ON") {
  print "<TD>電話(家)";
}
if ($email eq "ON") {
  print "<TD>E-Mail";
}
if ($homepage eq "ON") {
  print "<TD>Homepage";
}
print "<TD>詳細資料\n";

 foreach $DirFile 
  (&DirFiles("/users/others/cadmate/cadmate")) 
 { 
   if (!($DirFile eq ".") && !($DirFile eq "..")) {
     $filename = "/users/others/cadmate/cadmate/" . $DirFile;
     open (FH, "$filename");
     $_=<FH>;
     ($d1, $C_NAME) = split(/:/, $_, 2);
     $_=<FH>;
     ($d1, $E_NAME) = split(/:/, $_, 2);
     $_=<FH>;
     ($d1, $BBCALL) = split(/:/, $_, 2);
     $_=<FH>; 
     ($d1, $HANDPHONE) = split(/:/, $_, 2);
     $_=<FH>;
     ($d1, $O_TEL) = split(/:/, $_, 2);
     $_=<FH>;
     ($d1, $O_ADDRESS) = split(/:/, $_, 2);
     $_=<FH>;
     ($d1, $C_TEL) = split(/:/, $_, 2);
     $_=<FH>;
     ($d1, $C_ADDRESS) = split(/:/, $_, 2);
     $_=<FH>;
     ($d1, $H_TEL) = split(/:/, $_, 2);
     $_=<FH>;
     ($d1, $H_ADDRESS) = split(/:/, $_, 2);
     $_=<FH>;
     ($d1, $EMAIL) = split(/:/, $_, 2);
     $_=<FH>;
     ($d1, $HOMEPAGE) = split(/:/, $_, 2); 

     print "<TR><TD>$C_NAME&nbsp</TD>";
     
if ($ename eq "ON") {
  print "<TD>$E_NAME&nbsp";
}
if ($bbc eq "ON") {
  print "<TD>$BBCALL&nbsp";
}
if ($cell eq "ON") {
  print "<TD>$HANDPHONE&nbsp";
}
if ($o_address eq "ON") {
  print "<TD>$O_ADDRESS&nbsp";
}
if ($o_tel eq "ON") {
  print "<TD>$O_TEL&nbsp";
}
if ($c_address eq "ON") {
  print "<TD>$C_ADDRESS&nbsp";
}
if ($c_tel eq "ON") {
  print "<TD>$C_TEL&nbsp";
}
if ($h_address eq "ON") {
  print "<TD>$H_ADDRESS&nbsp";
}
if ($h_tel eq "ON") {
  print "<TD>$H_TEL&nbsp";
}
if ($email eq "ON") {
  @mails = split(/,/, $EMAIL);
  print "<TD>&nbsp";
    for ($i=0; $i< @mails; $i++) {
      $amail = @mails[$i];
      if (!($amail eq "\n")) {
        while (substr($amail,0,1) eq " ")  {
          $amail = substr($amail, 1, length($amail));   
        }
        print "<a href=mailto:$amail>$amail</a><br>";
      }
    }
}

if ($homepage eq "ON") {
   @pages = split(/,/, $HOMEPAGE);
  print "<TD>&nbsp";
    for ($i=0; $i< @pages; $i++) {
      $apage = @pages[$i];
      if (!($apage eq "\n")) {
        while (substr($apage,0,1) eq " ")  {
          $apage = substr($apage, 1, length($apage));
        }
        $http_header = substr($apage, 0, 7);
        if ($http_header eq "http://") {    
          print "<a href=$apage>$apage</a><br>";
        }
        else {
          print "<a href=http://$apage>$apage</a><br>";
        }  
      }
    }
}
     print 
     "<TD>
  <FORM METHOD=POST ACTION=\"/cgi-bin/cgiwrap?user=cadmate&script=detail4cad.cgi\">\n";
     print "<INPUT TYPE=HIDDEN NAME=ID VALUE=\"$DirFile\">\n";
     print "<INPUT TYPE=SUBMIT VALUE=\"查看\">\n";
     print "</FORM>\n";
     print "</TD>\n";
   close (FH);
  } 
 }
print "</TABLE>";
print "</BODY>";
print "</HTML>";
