#!/usr/bin/perl # check-reg.cgi - check registration use CGI qw/:standard :html3 :netscape/; use CGI::Carp qw(fatalsToBrowser carpout); use HTML::Entities (); # $encoded = HTML::Entities::encode($a); # $decoded = HTML::Entities::decode($a); use vars qw { $DEBUG }; $DEBUG = 0; use vars qw{ @REQUIRED @OPTIONAL @HIDDEN @VIEWABLE}; @REQUIRED = qw/ Last_name TTitle First_name Email /; @OPTIONAL = qw/ Enum EmpType NoNumber Phone Fax URL Address CCompany CTitle /; @HIDDEN = qw / EmpNum /; use vars qw { $Enum, $enum, $EmpType, $Last_name }; use vars qw {$ContactDir $ContactFile $SequenceNumbers}; $webdir = '/WWW/technofile/Talumni'; $ContactDir = "$webdir/Contacts"; $ContactFile = "$webdir/contactData.htm"; $SequenceNumbers = "$webdir/NextInSequence"; #main { chdir($webdir); print header, start_html(-title=>'Taligent Alumni Address Book Registration', -background=>"", -bgcolor=>"white", ), h1("Taligent Alumni Address Book Registration"); $_ = param('action'); CASE: { /^search|modify/i and do { my $found = do_checks('search'); generate_regform('create') if ($found == 0); last CASE; }; /^retrieve/i and do { do_checks('retrieve'); generate_regform(); last CASE; }; /^create/i and do { my $found = do_checks('create'); generate_regform('create') if ($found == 0); last CASE; }; /^update/i and do { generate_regform(); last CASE; }; /^register/i and do { create_record(); last CASE; }; # default generate_checkform(); } print end_html; } sub do_checks { my $options = shift; my @contact_list; my $found; my $record; my $empnumfile; my $Enum = param('Enum'); my $EmpType = param('EmpType'); my $Last_name = param('Last_name'); my $First_name = param('First_name'); my $NoNumber = param('NoNumber'); my $TTitle = param('TTitle'); my $Phone = param('Phone'); my $Fax = param('Fax'); my $Email = param('Email'); my $URL = param('URL'); my $Address = param('Address'); my $CCompany = param('CCompany'); my $CTitle = param('CTitle'); if ($options =~ /update/) { $found = 1; } else { unless ($Last_name && $First_name) { print_warning("Please enter First and Last name " . "for search"); generate_checkform(); return (-1); } else { $grep_cmd = "grep -il '^
}x )
{
$Last_name = $1;
$First_name = $2;
$TTitle = $3;
}
if ($record =~ m{Current\sEmployment:
(.*?)\s-\s(.*?)
}x )
{
$CTitle = $1;
$CCompany = $2;
}
if ($record =~ m|Phone:\s(.*?)
|) {
$Phone = $1;
}
if ($record =~ m|Fax:\s(.*?)
|) {
$Fax = $1;
}
if ($record =~ m|Email:(.*?)
|) {
$Email = $1;
if ($Email =~ m{
[A-z0-9\@\.]+
}x )
{
$Email = $1;
}
}
if ($record =~ m|URL:(.*?)
|) {
$URL = $1;
if ($URL =~ m{.*}) {
$URL = $1;
}
}
if ($record =~ m|Address:(.*?)
|) {
$Address = $1;
}
if ($DEBUG) {
print << "EOT";
Last_name = $Last_name
First_name = $First_name
TTitle = $TTitle
CTitle = $CTitle
CCompany = $CCompany
Phone = $Phone
Fax = $Fax
Email = $Email
URL = $URL
Address = $Address
EOT
}
print "\n";
if ($options =~ /search/) {
print start_form(-method=>'POST');
}
param(-name=>'Enum', -value=>"$Enum");
param(-name=>'EmpNum', -value=>"$EmpNum");
param(-name=>'EmpType', -value=>"$EmpType");
param(-name=>'Last_name', -value=>"$Last_name");
param(-name=>'First_name', -value=>"$First_name");
param(-name=>'TTitle', -value=>"$TTitle");
param(-name=>'CCompany', -value=>"$CCompany");
param(-name=>'CTitle', -value=>"$CTitle");
param(-name=>'Phone', -value=>"$Phone");
param(-name=>'Fax', -value=>"$Fax");
param(-name=>'Email', -value=>"$Email");
param(-name=>'URL', -value=>"$URL");
param(-name=>'Address', -value=>"$Address");
print hr({-width=>'150', -align=>'left'});
if ($options =~ /search/) {
print
p,
submit(-name=>'action', -value=>'Update record'),
p,
submit(-name=>'action', -value=>'Modify Search'),
;
}
} else {
if ($empnumfile) {
print_warning("Found Record for employee number: $EmpNum " .
"but name does not match $Last_name, $First_name.");
print_warning("You can try again to find your record, or " .
"create a new record.", p);
param(-name=>'Enum', -value=>'');
if (($options =~ /create/) || ($options =~ /search/)) {
generate_checkform();
} else {
generate_checkform('tryagain');
}
return(-1);
}
}
foreach (@REQUIRED, @OPTIONAL, @HIDDEN) {
print hidden(-name=>$_);
}
print end_form;
return($found);
}
sub normalize_empnum {
my $EmpNum = shift;
my $EmpType = shift;
my $options = shift;
my $type = '';
$EmpNum =~ s/^([TCX])//;
$t = $1;
$EmpNum = sprintf("%04d", $EmpNum);
if ($options =~ /X/) {
# new number
$EmpNum = "X$EmpNum";
} elsif ($EmpType eq 'Permanent' || $t eq 'T') {
$EmpNum = "T$EmpNum";
} elsif ($EmpType eq 'Contractor' || $t eq 'C') {
$EmpNum = "C$EmpNum";
}
return $EmpNum;
}
sub generate_checkform {
my $options = shift;
if ($options =~ /retrieve/) {
print "Note: This is the Taligent Address Book registration page.",
br,
"This is not the way to sign up ",
"for the mailing list or to change your address for the ",
"mailing list!", br,
"To subscribe or unsubscribe from the mailing list, go to the ",
"",
"mailing list page! ", p, hr, p;
print "Enter your employee number and name", br,
"Then click \"Retrieve My Record\"";
print_warning("* Fields in red are required");
} elsif ($options =~ /tryagain/) {
print "Check spelling. " .
"Could you have registered under " .
"a different variation on your name?)
\n"; if (defined param('EmpNum')) { print "Could you be mistaken about the employee number? " . "Try the search without entering an employee number."; } } else { print "Note: This is the Taligent Address Book registration page.", br, "This is not the way to sign up ", "for the mailing list or to change your address for the ", "mailing list!", br, "To subscribe or unsubscribe from the mailing list, go to the ", "", "mailing list page!", p, hr, p; print "Enter your employee number and name (First and Last).", br, " If you can't remember your number, leave it blank and check " . "the box that says \"I've forgotten...\".", p, "If you already have a ", a({-href=>'./list_contacts.cgi'}, 'data record'), " click \"Search for Record\" " . "and we'll look it up.", br, "Otherwise, you can create a new record.", p; print_warning("* Fields in red are required"); } print "\n", start_form(-method=>'POST'), table( TR({-align=>LEFT}, td(checkbox(-name=>'NoNumber', -checked=>0, -value=>'checked', -label=>'I\'ve forgotten my employee #.')), ), TR({-align=>LEFT}, th({-align=>'right'}, font({-color=>'red'},'* First Name') ), td({-colspan=>'2'}, textfield(-name=>'First_name', -size=>25)) ), TR({-align=>LEFT}, th({-align=>'right'}, font({-color=>'red'},'* Last Name') ), td({-colspan=>'2'}, textfield(-name=>'Last_name', -size=>25)) ), TR({-align=>LEFT}, th({-align=>'right'},'Tal Employee#:'), td(textfield(-name=>'Enum', -size=>5)), td(popup_menu(-name=>'EmpType', -value=>['Permanent', 'Contractor'], -default=>'Permanent')), ), ), br; foreach (@REQUIRED, @OPTIONAL, @HIDDEN) { print hidden(-name=>$_) if defined($_); } if ($options =~ /retrieve/ ) { print submit(-name=>'action',-value=>'Retrieve My Record'), p, submit(-name=>'action',-value=>'Create New Record'); print hr({-width=>"150", -align=>'Left'}), p; } elsif ($options =~ /tryagain/ ) { print submit(-name=>'action',-value=>'Search for Record'), p, submit(-name=>'action',-value=>'Create New Record'); } elsif ($options =~ /trycreate/ ) { print submit(-name=>'action',-value=>'Search for Record'), p; print hr({-width=>"150", -align=>'Left'}), p; print p, "Or create a new record below " . "(A new psudo-employee number will be assigned)", p; } else { print submit(-name=>'action',-value=>'Search for Record'), p, submit(-name=>'action',-value=>'Create New Record'); } print end_form; } sub generate_regform { my $Enum = param('Enum'); my $EmpNum = param('EmpNum'); my $EmpType = param('EmpType'); my $Last_name = param('Last_name'); my $First_name = param('First_name'); my $TTitle = param('TTitle'); my $Phone = param('Phone'); my $Fax = param('Fax'); my $Email = param('Email'); my $URL = param('URL'); my $Address = param('Address'); my $CCompany = param('CCompany'); my $CTitle = param('CTitle'); # param(-name=>'PrevLast_name', -value=>"$Last_name"); # param(-name=>'PrevFirst_name', -value=>"$First_name"); unless ($EmpNum) { my $x = ($EmpType eq 'Permanent') ? 'T' : 'C'; $Enum = get_next_number() unless $Enum; $EmpNum = normalize_empnum($Enum, $EmpType, '$x'); param(-name=>'Enum', -value=>"$Enum"); param(-name=>'EmpNum', -value=>"$EmpNum"); } print h3("Employee Number: $EmpNum ($EmpType)"), p, h3("Name: $Last_name, $First_name"), p; print_warning("* Fields in red are required"); print start_form(-method=>'POST'); print table( TR({-align=>RIGHT}, th({-align=>'right'}, font({-color=>'red'},'* Taligent Title/ Job description *') ), td(textfield(-name=>'TTitle', -size=>30)), ), TR({-align=>RIGHT}, th({-align=>'right'}, font({-color=>'red'},'* Current Email Address *') ), td(textfield(-name=>'Email', -size=>30)), th({-align=>'right'},'URL'), td(textfield(-name=>'URL', -size=>30)), ), TR({-align=>RIGHT}, th({-align=>'right'},'Current Title'), td(textfield(-name=>'CTitle', -size=>30)), th({-align=>'right'},'Current Company'), td(textfield(-name=>'CCompany', -size=>30)), ), TR({-align=>RIGHT}, th({-align=>'right'},'Phone Number'), td(textfield(-name=>'Phone', -size=>30)), th({-align=>'right'},'Fax Number'), td(textfield(-name=>'Fax', -size=>30)), ), ), table( TR({-align=>RIGHT, -colspan=>4}, th({-align=>'right'},'Address'), td(textfield(-name=>'Address', -size=>60)) ), ), br; foreach (@REQUIRED, @OPTIONAL, @HIDDEN) { print hidden(-name=>$_); } print submit(-name=>'action',-value=>'Register'), reset(-name=>'Reset'), end_form; } sub LOCK_SH { 1 } sub LOCK_EX { 2 } sub LOCK_UN { 8 } sub read_record { my $file = shift; my $options = shift; my $fh = Lock($file,0); unless ($fh) { warn; return undef; } $record = <$fh>; UnLock($fh); if ($options =~ /nohr/) { $record =~ s/
Taligent Title, current Email " . "Address"; print "
Or return to the home page, " . "if you want.<\P>"; generate_regform(); return undef; } my $pwd = `pwd`; chdir($ContactDir); if (! -e $ContactFile) { $newfile = 1; } unless ($newfile) { unless ( -e "RCS/${ContactFile},v" ) { # Contact file never inited in RCS system("/usr/bin/ci -u -q -t-'New Contact' $ContactFile"); } system("/usr/bin/co -l -q $ContactFile"); } if (-w $ContactFile || $newfile) { open(FILE, ">$ContactFile") or die "Error: Cannot Open $ContactFile: $!"; printf FILE ( "
" . "
" . "
\n"; if (-e $filename) { @mtime = localtime((stat($filename))[9]); $mod_date = sprintf("%02d-%02d-%04d\n", $mtime[4]+1, $mtime[3], $mtime[5]+1900); } return($mod_date); } # sub mod_date