#!/usr/bin/perl -w ###################################################################### # $Id$ # # Package: identify.cgi # Author: Nicholas Studt # # Description: # # # ###################################################################### use strict; use CGI qw(:standard); ############################################################ # Variables # ############################################################ my $BASEDIR = "/home/learningstyle.com/html/secure"; #my $BASEDIR = "/home/sites/site29/web/secure"; # old #my $BASEDIR = '/home/httpd/html/learningstyle/secure'; # Testing my $RESPONSEDATA = 'data/orders.dat'; my $QUESTIONDATA = 'questions/LANG/identify.dat'; my $AREASDATA = 'questions/LANG/areas.dat'; my $LETTERDATA = 'questions/LANG/answers.dat'; my $LANGDATA = 'questions/LANG/static.dat'; my $LANG; my %Cmds = ( 'question' => \&do_question, 'billing' => \&do_billing, 'last' => \&do_last, 'main' => \&do_first, 'report' => \&do_report, 'resend' => \&do_resend ); ############################################################ # Functions # ############################################################ #------------------------------------------------- # get_answers #------------------------------------------------- # #------------------------------------------------- sub get_answers { if ( ! open ( ANSWERS, "$BASEDIR/$AREASDATA" ) ) { die "Can't open $BASEDIR/$AREASDATA"; } my $question = "0"; my %answers = (); while ( defined ( my $line = ) ) { if ( $line =~ /^---\s\d+:.\s---/ ) { $line =~ s/---//g; $line =~ s/\s//g; $question = $line; } else { if ( $line =~ /^\s?short:/i ) { ($answers{$question}{defn} .= $line ) =~ s/short:\s?//i } else { $answers{$question}{text} .= $line; } } } close ( ANSWERS ); return ( \%answers ); } # END get_answers #------------------------------------------------- # get_questions #------------------------------------------------- # #------------------------------------------------- sub get_questions { if ( ! open( QUESTIONS, "$BASEDIR/$QUESTIONDATA" ) ) { die "Can't open $BASEDIR/$QUESTIONDATA"; } my ( $question, $count, %info ) = ( 0, 0 ); while ( defined( my $line = ) ) { next if ( $line =~ /^\s+$/ ); $line =~ s/\r//g; chomp( $line ); if ( $line =~ /^---\s\d+:.\s---/ ) { $line =~ s/---//g; ( $question = $line ) =~ s/\s//g; $count++ if ( $line =~ /\d+:L/ ); } else { if ( $line =~ /^\s?picture:/i ) { ( $info{$question}{img} .= $line ) =~ s/picture:\s?//i; } else { $info{$question}{text} .= $line; } } } close( QUESTIONS ); return( $count, \%info ); } # END get_questions #------------------------------------------------- # get_form #------------------------------------------------- # #------------------------------------------------- sub get_form { if ( ! open ( FORM, "$BASEDIR/$LETTERDATA" ) ) { die "Can't open $BASEDIR/$LETTERDATA"; } my ( $top, @header, @footer ) = ( 1 ); while ( defined ( my $line =
) ) { chomp ( $line ); ( $top, $line ) = ( 0, "" ) if ( $line =~ /^--- SPLIT ---/ ); if ( $top ) { push( @header, $line ); } else { push( @footer, $line ); } } close ( FORM ); return( join( "\n", @header ), join( "\n", @footer ) ); } # END get_form #------------------------------------------------- # get_lang #------------------------------------------------- # #------------------------------------------------- sub get_lang { if ( ! open ( LANG, "$BASEDIR/$LANGDATA" ) ) { die "Can't open $BASEDIR/$LANGDATA"; } my $entry = '~'; my %lang = (); while ( defined ( my $line = ) ) { if ( $line =~ /^---\s\w+\s---/ ) { $line =~ s/---//g; $line =~ s/\s//g; $entry = $line; } else { $lang{$entry} .= $line; } } close ( LANG ); return( \%lang ); } # END get_lang #------------------------------------------------- # find_action #------------------------------------------------- # #------------------------------------------------- sub find_action { my $in = shift; return( 'report' ) if ( $$in{action} eq 'report' ); return( 'resend' ) if ( $$in{action} eq 'resend' ); if ( ( $$in{question} == 0 ) || ( ( ! defined ( $$in{name} ) ) && ( $$in{question} == 1 ) ) ) { return( 'main' ); } elsif ( ( $$in{question} eq ( $$in{size} + 1 ) ) && ( defined( $$in{creditcardnum} ) ) && ( $$in{creditcardnum} ne '' ) && ( $$in{creditcardnum} =~ /^[0-9\-\ ]{6,40}$/ ) && ( $$in{expdate} ne '' ) && ( $$in{nameoncard} ne '' ) && ( $$in{phone} ne '' ) && ( $$in{billingaddy} ne '' ) && ( $$in{signed} ne '' ) ) { return( 'last' ); } elsif ( $$in{question} == ( $$in{size} + 1 ) ) { return( 'billing' ); } else { return( 'question' ); } } # END find_action #------------------------------------------------- # do_question( $in ) #------------------------------------------------- # #------------------------------------------------- sub do_question { my $in = shift; my $quest = get_questions(); my $q = $$in{question}; my $blank = q!!; my@txt=(qq!!, qq!!, qq!!, q!!, q!!, qq!!, qq!!, q!!, qq!!, q!!, q! !, q! !, q!!, q!!, q!!, qq!!, q!
!, qq!$blank$blank
$blank
!, qq!
$blank
!, qq!
$blank
!, qq!
!, qq!
$blank
!, q! !, q!!, q!!, q!!, q!
!, q!

!, $$quest{"$q:L"}{text}, q!


!, q!
!, q!

!, $$LANG{onenotimportant}, q!


!, q!
!, q!

!, $$quest{"$q:R"}{text}, q!


!, q!
$blank$blank
!, q!

!, $$quest{"$q:C"}{text}, q!

!, q! ! ); if ( $$in{question} == $$in{size} ) { my $new = $$in{question} + 1; push( @txt, q!!, qq!!, qq!! ); } else { my $new = $$in{question} + 1; push( @txt, qq!!, qq!!, qq!! ); } return( @txt, '
' ); } # END do_question #------------------------------------------------- # do_billing( $in ) #------------------------------------------------- # #------------------------------------------------- sub do_billing { my $in = shift; return( qq!
!, qq!!, qq!!, qq!!, qq!
!, $$LANG{creditcard}, qq!!, qq!!, qq!
!, $$LANG{cardtype}, q!!, q!!, q!
!, $$LANG{expdate}, q!!, q!!, q!
!, $$LANG{nameoncard}, q!!, q!!, q!
!, $$LANG{email}, q!!, q!!, q!
!, $$LANG{resultsby}, q!!, q!!, $$LANG{email}, q!
!, $$LANG{phonenumber}, q!!, q!!, q!
!, $$LANG{faxnumber}, q!!, q!!, q!
!, $$LANG{address}, q!!, q!!, q!
!, $$LANG{name}, q!!, q!!, q!
!, qq!!, qq!!, q!
! ); } # END do_billing #------------------------------------------------- # do_last( $in ) #------------------------------------------------- # #------------------------------------------------- sub do_last { my $in = shift; ( my $data = $$in{past} ) =~ s/\^/ /g; my @results = split( ':', $data ); my $orderid = $$in{order_id} = time(); $$in{past} =~ s/ /+/g; $$in{past} =~ s/:2$//; $$in{billingaddy} =~ s/\r//g; $$in{billingaddy} =~ s/\n/
/g; if ( open ( OUTFILE, ">>$BASEDIR/$RESPONSEDATA" ) ) { print OUTFILE "--- $orderid ---\n"; print OUTFILE "Type: TEST\n"; print OUTFILE "Date_Submited: " . localtime( $orderid ) . "\n"; print OUTFILE "Creditcard: $$in{creditcardnum}\n"; print OUTFILE "CardType: $$in{creditcardtype}\n"; print OUTFILE "ExpDate: $$in{expdate}\n"; print OUTFILE "Nameoncard: $$in{nameoncard}\n"; print OUTFILE "Email: $$in{email}\n"; print OUTFILE "ResultsBy: $$in{results_by}\n"; print OUTFILE "Phone: $$in{phone}\n"; print OUTFILE "Fax: $$in{fax}\n"; print OUTFILE "Address: $$in{billingaddy}\n"; print OUTFILE "Name: $$in{signed}\n"; print OUTFILE "Answers: $$in{past}\n"; close ( OUTFILE ); } else { return( "Can't open order file." ); } email_report( $$in{email}, $orderid, make_report( $in ) ); return( q!
!, q!!, qq!

$$LANG{pleaseprint}

!, qq!

$$LANG{date}: !. localtime( $orderid ). q!
!, qq!$$LANG{yourordernumber}: $orderid!, qq!
For: $results[0]

!, $$LANG{returnaddress}, qq!

$$LANG{thankyou}

!, qq!$$LANG{yourreportmail} "$$in{email}".!, q!
!, qq! $$LANG{returntosite} !, q!

! ); } # END do_last #------------------------------------------------- # do_report( $in ) #------------------------------------------------- # #------------------------------------------------- sub do_report { my $in = shift; return ( "Access Denied." ) if ( ! defined( $ENV{REMOTE_USER} ) ); my $data = $$in{past}; $data =~ s/\^/ /g; my @all = split( ':', $data ); $$in{order_id} = param( 'id' ); return( make_report ( $in ) ); } # END do_report #------------------------------------------------- # do_resend #------------------------------------------------- #------------------------------------------------- sub do_resend { my $in = shift; return ( "Access Denied." ) if ( ! defined( $ENV{REMOTE_USER} ) ); my $data = $$in{past}; $data =~ s/\^/ /g; my @all = split( ':', $data ); $$in{order_id} = param( 'id' ); email_report( $$in{email}, $$in{order_id}, make_report( $in ) ); return( "Report Sent to: $$in{email}" ); } #------------------------------------------------- # email_report( $email, $orderid, $report_text ) #------------------------------------------------- # #------------------------------------------------- sub email_report { my ( $email, $orderid, $report ) = @_; die "Can't send email, no address" if ( ! defined $email ); die "Can't send email to: $email" if ( $email !~ /.*\@.*/ ); if ( ! open(SENDMAIL, '|/usr/sbin/sendmail -oi -t' ) ) { die "Can't send email to: $email"; } print SENDMAIL "From: Price Systems \n"; print SENDMAIL "To: $email\n"; print SENDMAIL "Subject: Your learning style report ($orderid).\n"; print SENDMAIL "Mime-Version: 1.0\n"; print SENDMAIL qq!Content-Type: multipart/mixed; boundary="yrj/dFKFPuw6o+aM"\n!; print SENDMAIL "\n\n"; print SENDMAIL "--yrj/dFKFPuw6o+aM\n"; print SENDMAIL "Content-Type: text/plain; charset=us-ascii\n"; print SENDMAIL "Content-Disposition: inline\n\n"; print SENDMAIL "Your report is attached.\n\n"; print SENDMAIL "--yrj/dFKFPuw6o+aM\n"; print SENDMAIL "Content-Type: text/html; charset=us-ascii\n"; print SENDMAIL q!Content-Disposition: attachment; filename="report.html"!; print SENDMAIL "\n\n$report"; print SENDMAIL "\n--yrj/dFKFPuw6o+aM\n"; close(SENDMAIL); return(); } # END email_report #------------------------------------------------- # make_report( $in ) #------------------------------------------------- # #------------------------------------------------- sub make_report { my $in = shift; my $today = localtime(); my( $top, $bottom ) = get_form(); $$in{past} =~ s/\^/ /g; my @all = split( ':', $$in{past} ); my $answers = get_answers(); my( $name, $grade, $sex, $age ) = ( shift( @all ), shift( @all ), shift( @all ), shift( @all ) ); $name =~ s/\+/ /g; my @lines=( q!
LEARNING STYLE REPORT (LSR)
!, q!Copyright 1982,1987,1990,1993
!, q!- LEARNING STYLE REPORT - WEB -
INDIVIDUAL PROFILE
!, q!!, qq!!, qq!!, qq!!, qq!!, qq!
Name: $name 
ID. NO.: $$in{order_id}Date: $today
Sex: $sexGrade: $gradeAge: $age

!, q!!, q!!, q!! ); for ( my $i = 1; $i < $$in{size} + 1; $i++ ) { push( @lines, qq!! ); } push( @lines, q!! ); for ( my $i = 0; $i < $$in{size} ; $i++ ) { push( @lines, qq!! ); } push( @lines, q!
Scale
Score:$i
Raw:$all[$i]

!, q!!, q!!, q!!, q!! ); for ( my( $i, $j) = ( 0, 1 ); $i < $$in{size} ; $i++, $j++ ) { my $low = ( $all[$i] eq '1' ); my $mid = ( $all[$i] eq '2' ); my $high = ( $all[$i] eq '3' ); push( @lines, qq! !); } push( @lines, q!!, q!!, q!
Prefrence Summary!, q!
2030507080
$j!, ( $low ? '' : '' ), $$answers{"$j:L"}{defn}, ( $low ? "" : "" ), qq!!, ( $mid ? '' : '' ), $$answers{"$j:M"}{defn}, ( $mid ? '' : '' ), qq!!, ( $high ? '' : '' ), $$answers{"$j:H"}{defn}, ( $high ? '' : '' ), qq!$j
2030507080
!, q!

Price Systems,Inc., 763 N 1750 Rd., Lawrence, Ks.!, q!66049 - Phone 785-843-7892

!, $top ); for ( my $i = 1; $i < ( $$in{size} + 1 ) ; $i++ ) { if ( $all[$i - 1] < 2 ) { push( @lines, qq!

$$answers{"$i:L"}{text}

! ); } elsif ( $all[$i - 1] > 2 ) { push( @lines, qq!

$$answers{"$i:H"}{text}

! ); } } return( join( "\n", @lines, $bottom ) ); } # END make_report #------------------------------------------------- # do_first( $in ) #------------------------------------------------- # #------------------------------------------------- sub do_first { my $in = shift; return( q!
!, qq!
!, qq!!, q!!, q!
!, q!Name:!, q!!, q!!, q!!, q!
!, q!Your gender:!, q!!, q!!, q!Male!, q!   !, q!Female!, q!
!, q!Grade:!, q!!, q!!, q!!, q!
!, q!!, q!Your age:!, q!!, q!!, q!!, q!
!, q!!, q!!, q!
! ); } # END do_first #------------------------------------------------- # do_prep( ) #------------------------------------------------- # #------------------------------------------------- sub do_prep { my %in = (); # GET the right language. $in{LANG} = param('LANG') || 'en'; $QUESTIONDATA =~ s/LANG/$in{LANG}/; $AREASDATA =~ s/LANG/$in{LANG}/; $LETTERDATA =~ s/LANG/$in{LANG}/; $LANGDATA =~ s/LANG/$in{LANG}/; $LANG = get_lang(); ( $in{size}, $in{info_ref} ) = get_questions(); $in{question} = param('question') || 0; $in{action} = param('action') || param('back') || param('forward') || 'main'; $in{past} = param('past') || ''; $in{answer} = param('answer') || 2; $in{name} = param('name'); $in{grade} = param('grade'); $in{age} = param("age"); $in{gen} = param("gen"); # stuff from the final order form. $in{creditcardnum} = param('creditCardNum'); $in{creditcardtype} = param('creditCardType'); $in{expdate} = param('expDate'); $in{nameoncard} = param('nameOnCard'); $in{email} = param('email'); $in{phone} = param('phoneNo'); $in{fax} = param('faxNo'); $in{billingaddy} = param('billingAddress'); $in{shippingaddy} = param('shippingAddress'); $in{signed} = param('signed'); $in{results_by} = param('results_by'); # THIS IS PREP FOR ALL. return ( \%in ) if ( $in{action} eq 'first' || $in{action} eq 'report' ); if ( $in{action} eq 'Back' ) { $in{question} -= 2; my @all = split( ':', $in{past} ); pop( @all ); $in{past} = join( ':', @all ); } elsif ( $in{question} eq '1' ) { $in{name} .= ( length( $in{name} ) < 20) ? '^' x ( 20 - length( $in{name} ) ) : ''; $in{age} .= ( length( $in{age} ) < 2) ? '^' x ( 2 - length( $in{age} ) ) : ''; $in{grade} .= ( length( $in{grade} ) < 2) ? '^' x ( 2 - length( $in{grade} ) ) : ''; $in{gen} = '' if ( ! defined $in{gen} ); $in{past} = "$in{name}:$in{grade}:$in{gen}:$in{age}"; } else { $in{past} = "$in{past}:$in{answer}"; } return( \%in ); } # do_prep ###################################################################### # Main Execution Begins Here # ###################################################################### { my @txt; eval { my $in = do_prep(); my $action = find_action( $in ); if ( my $function = $Cmds{$action} ) { push( @txt, &$function( $in ) ); } else { push( @txt, 'Page does not exist' ); } }; push( @txt, "Error:
$@" ) if ( $@ ); eval { print header(), q!Learning Survey!, q!!, join( "\n", @txt ), q!!; }; print ( "Printing Error: $@" ) if ( $@ ); } # END main # EOF 1;