#!/usr/bin/perl -w use CGI qw(:standard -debug); use CGI::Carp qw(fatalsToBrowser); ########### Credits ################# # Script written by R. Todd Vandenbark ##################################### # -------- initialize variables --------- $bsuIDnumber =""; # BSU ID # input $studentName=""; # student's last name input $organization=""; # Greek organization input @studentlist=(); # list of students $bsunum2=""; # search variable: ID $name2=""; # search variable: last name $org2=""; # search variable: Greek org @matches=(); # list of matches $found=0; # match indicator $title; # page title $subtitle; # page heading # --------- initialize error flagss ----- $badIDnum = 0; $badlast=0; $badOrg=0; $error=0; # ----- get form and data -------------- $form = "../manualStudentLogin.html"; $bsuIDnumber = param("bsuIDnumber"); chomp $bsuIDnumber; $bsuIDnumber = &cleaninput($bsuIDnumber); $studentName = param("studentName"); chomp $studentName; $organization = param("organization"); chomp $organization; # ---- form error checking -------------- if ((!$bsuIDnumber) && (!$studentName) && (!$organization)) { # if no input $title = 'oops...'; $subtitle = 'Invalid input'; $content = '

Please enter a valid BSU ID#, last name, or ' . 'organization name.

' . "\n" . '

Back to search form.

'; &errorpgprint(); exit; } if (($bsuIDnumber =~ /\D+/) || ($bsuIDnumber =~ /^\d{14,}$/)) { # invalid ID # $badIDnum=1; $error++; } elsif (($studentName ne "") && ($studentName !~ /^\w+[ -]?\w*$/)) { # invalid name input $badlast=1; $error++; } elsif (($organization ne "") && ($organization !~ /^\w+ \w+ ?\w*$/)) { # invalid org name $badOrg=1; $error++; } if ($error) { # if errors in form $title = 'Form error'; $subtitle = 'Invalid form input'; $content = '

Invalid '; if ($badIDnum) { #invalid ID number entered $content .= "BSU ID number ($bsuIDnumber) "; } if ($badlast) { # invalid last name entered $content .= "last name ($studentName) "; } if ($badOrg) { #invalid organization name entered $content .= "organization name ($organization) "; } $content .= 'entered. Please try again.

'; &errorpgprint(); exit; } # ------------ processing goes from here... -------- # ---- input student list file ---- $inStudents = '../../student.txt'; open (IN, "$inStudents") || die "Can't open $inStudents: $!\n"; @studentlist = ; close IN; # ---- search for matches --------- foreach $key (@studentlist) { # find ($bsunum2,$bsuname2,$fname2,$lname2,$org2) = split (/:/, $key); if ($bsuIDnumber eq $bsunum2) { # add to list push (@matches, $key); $found++; } elsif ($studentName eq $lname2) { # add to list push (@matches, $key); $found++; } elsif ($organization eq $org2) { # add to list push (@matches, $key); $found++; } } # ---- end foreach ---- # # ---- output search results ---- # if (!$found) { # if no results, print page $title ='Search results'; $subtitle = 'Unable to find:'; $content = "

$bsuIDnumber $studentName $organization<\/p> \n" . '

Search again -== OR ==- back to Main Menu

'; &errorpgprint(); } else { # one or more matches found, show list $title = 'Search successful'; $subtitle = 'Results'; $action = 'studentlogin.cgi'; $method = 'post'; $encoding = 'application/x-www-form-urlencoded'; my $css = ''; print header(-cookie => [$cookie_user, $cookie_pwd]); print start_html(-title => $title, -head => $css, -class => 'oneColFixCtrHdr'); print '
' . "\n"; print '
' . "\n"; print startform($method,$action,$encoding); print '
    '; foreach $key (@matches) { ($bsunum3,$username3,$first3,$last3,$org3) = split(/:/,$key); print '
  • '. "\n" . ' ' . "$last3, $first3 of $org3, ID\#$bsunum3 \n"; print "<\/li> \n"; }# -- end foreach -- print '
'; print '

'; # print reset; print '   '; print submit(-name=>'submit', -value=>'Login'); print '   '; print submit(-name=>'submit', -value=>'Logout'); print end_form(); &reportBugs(); &footerprint(); print end_html; # ---- end of script ------- } # ------------ subroutines used ----------- sub cleaninput { my $string = $_[0]; $string =~ s/<([^>]|\n)*>//g ; # strip HTML $string =~ s/^\s+// ; # strip leading spaces $string =~ s/\s+$// ; # strip trailing spaces return $string; } # ------ print page ------- sub errorpgprint { my $css = ''; print header(-cookie => [$cookie_user, $cookie_pwd]); print start_html (-title => $title, -head => $css, -class => 'oneColFixCtrHdr'); print '

' . "\n"; print '
' . "\n"; print "$content \n"; print '
'. "\n"; &footerprint(); print end_html(); } # ------ end sub -------- sub reportBugs { # ---- prints table for bug reporting ----------- print <
Report a problem.
Main menu. Help function EOF } # ----- end bug reporting subroutine ---------------- sub footerprint { # ---- prints footer with credits-------------- print ''. '
'; }