#!/usr/local/bin/perl # This file contains perl subroutines that handle non- # specific functions for the server-side functionalities # of the ProMEM/MealSaver website. # # All code written and created by Dan Strife. use DBI; require "mysql.pl"; # Check for existance of session ID in sessions table and # return corresponding netid. sub validateSession { my $dbh; my $sth; my $query; my $dis; ($dbh, $dis) = handleMySQLConnect($_[$#_]); my $sessionid = $_[0]; # query club tables for netid $query = "SELECT NETID FROM Sessions WHERE SESSIONID='$sessionid'"; $sth = $dbh->prepare($query); $sth->execute(); my ($netid) = $sth->fetchrow_array(); $sth->finish(); handleMySQLDisconnect($dbh, $dis); return $netid; } # Compares two exchange records for conflict. sub compareExchanges { my ($rec1, $rec2) = @_; return 1 if (($rec1->[0] eq $rec2->[0]) && ($rec1->[1] eq $rec2->[1]) && ($rec1->[2] eq $rec2->[2]) && ($rec1->[4] eq $rec2->[4])); return 1 if (($rec1->[0] eq $rec2->[1]) && ($rec1->[1] eq $rec2->[0]) && ($rec1->[2] eq $rec2->[2]) && ($rec1->[4] eq $rec2->[4])); return 0; } # Returns the current time in YYYY-MM-DD HH-MM-SS format. sub getTime { ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime(); $year = 1900 + $yearOffset; $month += 1; $time = "$year-$month-$dayOfMonth $hour:$minute:$second"; return $time; } 1;