#!/usr/bin/perl ##########$################## ## CGI / DB INITIALIZATION ## ############################# use DBI; use CGI; use Socket; use IIIkey; use dbihelper; use fuseIt; do "alumniMarket.cfg"; $form = new CGI; my @formKeys = $form->param; my $formVars = {}; foreach $key (@formKeys) { $formVars->{$key} = $form->param($key); } my $loadPage = $formVars->{d}; my $dbh = DBHOpen($databaseName, $dbiType, $dbUsername, $dbPassword); if (!$dbh) { printErrorPage("Could not connect to database."); exit; } my @infoFields = qw| firstName lastName jobTitle yearGraduated companyID companyName companyAddress companyCity companyState companyZipCode companyCountry companyPhone companyFax industryType description photoOfBusiness eMail webPage username password active timeStamp dateStamp image companyTag class |; ############################ my $adminEmail = getAdminEmail(); ############################################################ ## CONFIRMATION TO CHECK THAT THIS PAGE IS AN ACTUAL PAGE ## ############################################################ my %validPages = ( "", 1, "add", 1, "update", 1, "join", 1, "login", 1, "verify", 1, "search", 1, "view", 1, "help", 1 ); if ( !(defined $validPages{$loadPage})) { printErrorPage("Invalid page reference: $loadPage"); exit; } ############################################################ #################### ## PAGE SELECTION ## #################### #-------------------------------------------------------------------------------# if (!$loadPage) { printMainPage("", $formVars); exit; #-------------------------------------------------------------------------------# } elsif ($loadPage eq "join") { my $homelink = "Cancel and return to Alumni Marketplace"; printCompanyForm("", "Enter your information in the form below
$homelink"); exit; #-------------------------------------------------------------------------------# } elsif ($loadPage eq "add" || $loadPage eq "update") { # always check the password # if ($loadPage eq "update") { my $companyID = verifyLogin($formVars->{username}, $formVars->{password}); if (!$companyID) { printLoginPage("Invalid username or password."); } } if (!checkUsername($formVars->{username}) && $loadPage eq "add") { printCompanyForm($formVars->{companyID}, "That username has already been chosen. Please choose another."); exit; } my $fileSize = fileSize($formVars->{image}); if ($fileSize > $maxImageSize) { printCompanyForm($formVars->{companyID}, "Images must be less than $maxImageSize bytes. Please choose a smaller image."); } modifyDB($formVars); sendMail(makeEmail($formVars)); $loadPage .= ($loadPage eq "add") ? "ed" : "d"; my $homelink = "Back to Alumni Marketplace"; printCompanyForm($formVars->{companyID}, "Your information has been $loadPage.

$homelink"); exit; #-------------------------------------------------------------------------------# } elsif ($loadPage eq "login") { printLoginPage("Enter your username and password."); exit; #-------------------------------------------------------------------------------# } elsif ($loadPage eq "verify") { my $companyID = verifyLogin($formVars->{username}, $formVars->{password}); if ($companyID) { my $homelink = "Cancel and return to Alumni Marketplace"; printCompanyForm($companyID, "Modify your information below.
$homelink"); } else { printLoginPage("Invalid username or password."); } exit; #-------------------------------------------------------------------------------# } elsif ($loadPage eq "search") { my $first = $formVars->{first} || 0; my @results = doSearch($formVars); if (scalar(@results) == 0) { printMainPage("No Matches Found!", $formVars); } else { printSearchResults($first, @results); } exit; #-------------------------------------------------------------------------------# } elsif ($loadPage eq "view") { my $companyInfo = getCompanyData($formVars->{c}); printCompanyDetails($companyInfo); exit; #-------------------------------------------------------------------------------# } elsif ($loadPage eq "help") { printHelpPage(); exit; } #-------------------------------------------------------------------------------# ##################### ############### ## SHUT DOWN ## ############### DBHClose($dbh); exit; ############### ############################# ## PAGE PRINTING FUNCTIONS ## ############################# sub printHelpPage { Fusion($templateDir, $template{helpPage}, @rIdx); } sub printCompanyDetails { my $companyData = shift; my $search; if (!defined $formVars->{a_name} && !defined $formVars->{c_name} && !defined $formVars->{city} && !defined $formVars->{state} && !defined $formVars->{type}) { $search = ""; } else { $search = "d=search&a_name=$formVars->{a_name}&c_name=$formVars->{c_name}&first=$formVars->{first}". "&city=$formVars->{city}&state=$formVars->{state}&type=$formVars->{type}"; } $companyData->{dateStamp} = humanDate($companyData->{dateStamp}); $companyData->{timeStamp} = humanTime($companyData->{timeStamp}); my $imageHTML; if ($companyData->{image} ne "") { $imageHTML =< Business Photo EOF } my $tagHTML; if ($companyData->{companyTag} ne "") { $tagHTML =< $companyData->{companyTag} EOF } ############################################ # Add company data to form if there is any # ############################################ foreach $field (@infoFields) { unless ($field eq "image" || $field eq "companyTag") { $companyData->{$field} ||= "N/A" } push (@rIdx, { replace => $field, replaceWith => $companyData->{$field} } ); } push (@rIdx, { replace => "userScript", replaceWith => "$userScript?" . $search }, { replace => "tagHTML", replaceWith => $tagHTML }, { replace => "imageHTML", replaceWith => $imageHTML } ); Fusion($templateDir, $template{companyDetails}, @rIdx); } sub printSearchResults { my $first = shift; my @results = @_; my $totalEntries = @results; my $resultTable = resultTable(@_[$first .. $first + $resultsPerPage - 1]); my $searchNav = searchNav($first, $resultsPerPage, $#results + 1); my $searchTotals = searchTotals($totalEntries, $first); my $search = "a_name=$formVars->{a_name}&c_name=$formVars->{c_name}&first=$formVars->{first}". "&city=$formVars->{city}&state=$formVars->{state}&type=$formVars->{type}"; my @rIdx = ( { replace => "searchResults", replaceWith => $resultTable }, { replace => "searchNav", replaceWith => $searchNav }, { replace => "searchTotals", replaceWith => $searchTotals }, { replace => "userScript", replaceWith => $userScript . "?" . $search } ); Fusion($templateDir, $template{searchResults}, @rIdx); } sub printLoginPage { my $message = shift; my $JS = loginJS(); $JS = ""; my @rIdx = ( { replace => "javascript", replaceWith => $JS }, { replace => "userScript", replaceWith => $userScript }, { replace => "message", replaceWith => $message } ); Fusion($templateDir, $template{loginPage}, @rIdx); return; } ####################################################################### # print the company input form # # # # no arguments = (new user) # # $companyID = use this companies info in the form # ######################################################### sub printCompanyForm { my $companyID = shift; my $message = shift; my $JS = companyFormJS(); $JS = ""; my ($process); my @rIdx; ########################################################## # use the company id to determine if we create or modify # ########################################################## if ($companyID eq "") { $companyID = newCompanyID(); $process = "add"; } else { $process = "update"; } my $companyData = getCompanyData($companyID); if (!$companyData) { $companyData = $formVars; } ########################### # Tidy up things a little # ########################### my $cryptIt = new IIIkey; $companyData->{password} = $cryptIt->decrypt($companyData->{password}, $cryptKey); if ($companyData->{timeStamp} eq "" ) { $companyData->{timeStamp} = "Never"; } else { $companyData->{timeStamp} = humanTime($companyData->{timeStamp}); } if ($companyData->{dateStamp} eq "") { $companyData->{dateStamp} = "Never"; } else { $companyData->{dateStamp} = humanDate($companyData->{dateStamp}); } if ($companyData->{image} eq "") { $companyData->{image} = "[ No image uploaded] "; } else { $companyData->{image} = "{image}\" width=150 height=150>"; } ############################################ # Add company data to form if there is any # ############################################ foreach $field (@infoFields) { next if ($field eq "companyID"); push (@rIdx, { replace => $field, replaceWith => $companyData->{$field} } ); } my $industryOptions = industryList($companyData->{industryType}); my $stateOptions = stateList($companyData->{companyState}); my ($dateStamp, $timeStamp) = getDateTime(); my $formTag = "action=\"$userScript\" method=\"post\" onSubmit=\"return verify()\" encType=\"multipart/form-data\""; my $activeText =< If, at any time, you wish to have your information removed from the Alumni Marketplace, please email $adminEmail with your request. EOF @rIdx = (@rIdx, { replace => "javascript", replaceWith => $JS }, { replace => "message", replaceWith => $message }, { replace => "process", replaceWith => $process, }, { replace => "formTag", replaceWith => $formTag, }, { replace => "maxImageSize", replaceWith => $maxImageSize }, ############## # company ID # ############## { replace => "companyID", replaceWith => $companyID, }, ################### # selection lists # ################### { replace => "industryOptions", replaceWith => $industryOptions }, { replace => "stateOptions", replaceWith => $stateOptions }, #################### # date/time stamps # #################### { replace => "nDateStamp", replaceWith => $dateStamp }, { replace => "nTimeStamp", replaceWith => $timeStamp }, { replace => "activeText", replaceWith => $activeText } ); Fusion($templateDir, $template{joinPage}, @rIdx); return; } ####################################################################### ####################################################################### # print the main (index) page for the # # alumni market place (user side) # ######################################### sub printMainPage { my $message = shift; my $searchData = shift; my $industryList = industryList($searchData->{type}); my $stateList = stateList($searchData->{state}); my $JS = indexJS(); my $actionLinks=<Join the Marketplace Modify your Account EOF $JS = ""; $randomImage = getRandomImage(); if ($randomImage->{image} eq "") { $randomImage->{image} = "[ No image uploaded ]"; } else { $randomImage->{image} = "{image}\" width=150 height=150>"; } my @rIdx = ( { replace => "javaScript", replaceWith => $JS }, # form action="" # { replace => "userScript", replaceWith => $userScript }, { replace => "cID", replaceWith => $randomImage->{companyID} }, { replace => "message", replaceWith => $message }, { replace => "industryOptions", replaceWith => $industryList }, { replace => "help", replaceWith => "javascript:openHelp()" }, { replace => "image", replaceWith => $randomImage->{image} }, { replace => "tagline", replaceWith => $randomImage->{companyTag} }, { replace => "companyName", replaceWith => $randomImage->{companyName} }, { replace => "firstName", replaceWith => $randomImage->{firstName} }, { replace => "lastName", replaceWith => $randomImage->{lastName} }, { replace => "yearGraduated", replaceWith => $randomImage->{yearGraduated} }, { replace => "stateOptions", replaceWith => $stateList }, ## Search Variables ## { replace => "c_name", replaceWith => $searchData->{c_name} }, { replace => "a_name", replaceWith => $searchData->{a_name} }, { replace => "city", replaceWith => $searchData->{city} }, { replace => "actionLinks", replaceWith => $actionLinks } ); Fusion($templateDir, $template{mainPage}, @rIdx); return; } ####################################################################### ####################################################################### # print a general error page # # # $errorMsg = The error message to display ####################################################################### sub printErrorPage { my $errorMsg = shift; my @rIdx = ( { replace => "errorMessage", replaceWith => $errorMsg } ); Fusion($templateDir, $template{errorPage}, @rIdx); return; } ####################################################################### ############################# ##################### ## JAVASCRIPT CODE ## ##################### sub companyFormJS { my $JS=<!*\\()~$%^=+,?:[]{}'`"; for (var i = 0; i < InvalidEmailChars.length; i++) { if (eMail.indexOf(InvalidEmailChars.charAt(i)) != -1) { alert('Invalid character in email address: ' + InvalidEmailChars.charAt(i)); return false; } } if (formref.image.value != '') { var filename = new String(formref.image.value); var ext = filename.split('.'); var extension = ext[ext.length-1]; extension = extension.toLowerCase(); if ( ( (extension != 'gif' && extension != 'jpg' && extension != 'jpeg') && filename != '') ) { alert('Images must have an extension of .gif, .jpg, or .jpeg'); return false; } } return true; } EOF return ($JS); } sub loginJS { my $JS=<{companyID} || 0; $companyID++; return ($companyID); } ####################################################################### ###################### ####################################################################### sub industryList { my $selected = shift; my ($optionList, $industry); ############################# ## industry list goes here ## ############################# my @industries = ( "Accounting", "Activism", "Administrative Supp", "Advertising", "Aerospace", "Air Conditioning", "Airlines", "Apartment Management", "Architecture", "Art", "Automotive", "Aviation", "Banking", "Beauty", "Bilingual", "Bookkeeping", "Broadcasting", "Care Giving", "Civil Service", "Clerical", "College", "Computer", "Construction", "Counseling", "Customer Service", "Decorating", "Dental", "Driving", "Education", "Electronic", "Emergency", "Employment", "Engineering", "Entertainment", "Environmental", "Executive", "Fashion/Apparel", "Financial", "Food Services", "Forestry", "Fundraising", "Gardening", "General Office", "Graphics", "Grocery", "Health/Medical", "Home Services", "Hospital", "Hotel/Motel", "Housekeeping", "Human Resources", "HVAC", "Import/Export", "Installer", "Insurance", "Janitorial", "Law Enforcement", "Legal", "Maintenance", "Management", "Manufacturing", "Marketing", "Mechanical", "Media", "Merchandising", "Modeling", "Nursing", "Nutrition", "Personnel", "Pest Control", "Pet Care", "Photography", "Plumbing", "Printing", "Property Management", "Public Relations", "Publishing", "Purchasing", "Quality Control", "Real Estate", "Recreation", "Research", "Restaurant", "Sales", "Science", "Security", "Service Occupations", "Shipping/Receiving", "Social Services", "Teaching", "Technical", "Telecommunications", "Telemarketing", "Television", "Textile", "Training", "Transportation", "Travel", "Warehouse", "Waste Management", "Word Processing", "Other" ); ############################# $optionList = "\n"; foreach $industry (@industries) { $optionList .= "\n"; foreach $state (@states) { $optionList .= "