#!/usr/bin/perl -w #--------------------------------------------------------------- # Study Log: Check Student ID CGI # By Crystal White and Modified by Todd Vandenbark # April 4, 2009 (last modified April 26, 2009) # Task: # -check for an ID in the ldap.txt file (from BSU, means they are valid students with ID numbers) # -check to see if person has loged in before (student.txt), if so bypass the welcome page and print the main menu # -If not, print out a Welcome page where we will get there information for the student.txt file # -use cookies to maintain the state of pages # Input: ID number # Output: ID number, info to student.txt, welcome page or main menu page #--------------------------------------------------------------- use CGI qw(:standard -debug); use CGI::Carp qw(fatalsToBrowser); # ---- define variables ------------------ $found=0; # counter for number of matches $cookiedata=""; # for retrieving info from cookie $title=""; # page title $subtitle=""; # text in h1 heading $id=""; # input from form # Input from Form $id = param ("id"); # Set stylesheet $css = ''; # text file $stf = '../ldap.txt'; # user file $users = '../student.txt'; # HTML forms $form1 = "http://studylog.firesidelibrarian.com/studentid.cgi"; $form2 = "http://studylog.firesidelibrarian.com/faq.htm"; # ----------- read in user id file -------------- if (-r $stf) { # read in file open(IN,$stf) || die "can't read $stf"; @sts = ; close IN; chomp @sts; } $cookiedata=cookie('id'); #print "cd= $cookiedata\n"; if (!$cookiedata) { # ---- get ID # entered ---------------------- $cookiedata = param("id"); chomp $cookiedata; } #print "param(id) = $cookiedata\n"; # ---- search for match ------------------ foreach $key (@sts) { ($num,$username,$fname,$lname) = split (/:/, $key); if ( $cookiedata eq $num ) { $found++; } # end if } # ---- end foreach ------- #print "found = $found\n"; if (!$found) { # if no match, present error message $title = "Invalid entry"; $content = '

Please go back and try again

'; &pgprint; } # ------- end if ------ # ---- tv ----------------------------- # read in list of current system users # ------------------------------------- else { @usr = (); if (-r $users) { # read in file open(IN2,$users) || die "Can't read $users: !$\n"; @usr = ; close IN2; chomp @usr; %useh = (); # hash of current users of Study Log system foreach $key (@usr) { ($num,$username,$last,$first,$org,$session) = split(/:/, $key); $useh{$num} = $first . $last; } # Create cookie $cookie = cookie(-name=>'id',-value=>"$cookiedata",-expires=>'+5M'); } #print "cookie = $cookie \n"; #Print HTML and Errors if ( exists $useh{$id} ) { # if user already in Study Log system $title = "Study Log Main Menu"; $content ='

' . "\n" . '

' . "\n" . '' . "\n" . '
'. '' . "\n" . '
' . "\n". '' . "\n". '
' . "\n" .'

'. '' . "\n" . '

Help

'; &pgprint(); exit; } else { # create new student user # ---- read org file ------ $orgfile = "../org.txt"; open (IN2, "$orgfile") || die "Can't open $orgfile: $!\n"; @orglist = ; close IN2; print header(-cookie=>$cookie); print start_html(-title=>"Welcome New User!", -head =>$css); print ' ' . "\n"; print h2("Set up account"); print "\n"; print qq|
|; print "

Please select Your Greek House:
\n"; print "

' . "\n"; print '' . "\n"; print qq|

Back |; print qq|Help

|; print qq||; print "<\/form> \n"; print end_html(); } } # --------------------------------------------------------------- # subroutine to print error page content # --------------------------------------------------------------- sub pgprint { if ($cookie) { print header(-cookie=>$cookie); } else { print header(); } print start_html(-title=>$title, -head =>$css); print ' '; print '
'; print h2("$subtitle"); print "$content\n"; print '
' . "\n"; print ''. "\n" . ''. "\n" . '' . "\n"; print end_html(); }