package vosFacultyDisclosure;
use strict;
use Apache::DBI();
use CGI qw(:standard);
my ($path) = "../../../";
my ($title) = "Willingness to Participate and FDA Disclosure Form";
my ($dsn) = "DBI:mysql:vos:localhost";
my ($user) = "vosdb_user";
my ($password) = "";
my ($sth);
my (@ary);
my ($facultyname) = '';
my ($facultyid);
my ($num_lectures);
my ($counter) = 1;
my ($header) = '';
my %roles = ();
$main::cgi = new CGI; # to take advantage of the "param" decoding method
$vosFacultyDisclosure::meeting_no = $main::cgi->param('id');
if (!$vosFacultyDisclosure::meeting_no) {
print $main::cgi->redirect('../index.iphtml');
die "";
}
$main::dbh = DBI->connect ($dsn, $user, $password, { RaiseError => 0, PrintError => 0})
or die "Could not connect to server: $DBI::err ($DBI::errstr)\n";
my %States;
my $Current_Screen;
%States = (
'Default' => \&vosFacultyDisclosure::input_page,
'Submit' => \&vosFacultyDisclosure::submission_result_page
);
$Current_Screen = param(".State") || "Default";
die "No screen for $Current_Screen" unless $States{$Current_Screen};
!>
#include ../../../includes/wp-vos-header.iphtml
;
my $SQL = "SELECT name, meeting.city, meeting.state, meeting.location, MONTHNAME(meeting.start_date), DAYOFMONTH(meeting.start_date), YEAR(meeting.end_date), MONTHNAME(meeting.end_date), DAYOFMONTH(meeting.end_date) FROM meeting WHERE meeting_no = $vosFacultyDisclosure::meeting_no AND meeting.workshop_no = 0 AND meeting.breakout_no = 0";
$sth = $main::dbh->prepare ($SQL) ||
die "Prepare failed: $DBI::errstr\n";
$sth->execute() ||
die "Couldn't execute query $DBI::errstr\n";
undef(@ary);
@ary = $sth->fetchrow;
$sth->finish();
if (@ary) {
print '
\n";
print h3({-align=>'center'},'WILLINGNESS TO PARTICIPATE AND DISCLOSURE FORM');
} else {
print $main::cgi->redirect('../index.iphtml');
die "";
}
print start_form(-onsubmit =>"MM_validateForm('academic_title','Academic Title','R','institution','Academic Institution','R','email','Email Address','RisEmail','address','Preferred Mailing Address','R');return document.MM_returnValue");
while (my($screen_name, $function) = each %States) {
$function->($screen_name eq $Current_Screen);
}
print end_form();
!>
#include ../../../includes/wp-vos-footer.iphtml
;
sub input_page {
my $active = shift;
return unless $active;
my $access = 1;
my $username = $main::cgi->remote_user();
my $SQL = <prepare($SQL);
$sth->execute;
my @ary;
@ary = $sth->fetchrow;
$sth->finish;
$facultyid = $ary[0];
if (!$vosFacultyDisclosure::meeting_no) {
print $main::cgi->redirect('../index.iphtml');
die "";
}
if (!@ary) {
print $main::cgi->redirect('../index.iphtml');
die "";
}
!>
;
undef($SQL);
$SQL = "SELECT COUNT(*) FROM faculty_lecture WHERE facultyid = '$facultyid' AND meetingid= '$vosFacultyDisclosure::meeting_no'";
$sth = $main::dbh->prepare($SQL);
$sth->execute;
undef(@ary);
@ary = $sth->fetchrow;
$sth->finish;
if ($ary[0] eq "0") {
$access = 0;
print p('You are not listed as faculty for the above caption meeting. If this is an error, please contact VOS administrative assistant, Angela Puryear at angela@societyhq.com or phone (804) 565-6312.');
print p('Click',a({href=>"../"},'here'),'to select a different meeting.');
}
if ($access) {
$SQL = <prepare($SQL);
$sth->execute;
undef(@ary);
@ary = $sth->fetchrow;
$facultyname = $ary[0] . ' ' . $ary[1];
$facultyname .= ", $ary[2]" if $ary[2];
my $fac_addr;
$fac_addr .= "$ary[5]\n" if $ary[5];
$fac_addr .= "$ary[6]\n" if $ary[6];
$fac_addr .= "$ary[7]," if $ary[7];
$fac_addr .= " $ary[8]" if $ary[8];
$fac_addr .= " $ary[9]" if $ary[9];
$fac_addr .= "\n$ary[10]" if $ary[10];
print p(' ');
print '
DISCLOSURE FORM FOR: ' . $facultyname . '
';
print p(em('If you are not ' . $facultyname . ', you must close your web browser completely and re-login. | ',a({-href=>"./index.iphtml?id=$vosFacultyDisclosure::meeting_no"},'Return to Faculty Forms'),'.'));
# print "
DISCLOSURE FORM FOR: $facultyname If you are not $facultyname, you must close your web browser completely and re-login. | Return to Faculty Forms.
\n";
!>
print p(to_page("Submit")); !>
}
}
sub submission_result_page
{
my $active = shift;
return unless $active;
my $username = $main::cgi->remote_user();
$vosFacultyDisclosure::meeting_no = $main::cgi->param('id');
if (!$vosFacultyDisclosure::meeting_no) {
print $main::cgi->redirect('../index.iphtml');
die "";
}
my $SQL = <prepare($SQL);
$sth->execute;
my @ary;
@ary = $sth->fetchrow;
$sth->finish;
$facultyid = $ary[0];
my @db_fields = ();
my $updateSQL;
my $rows;
my $db_error = "";
my $missing_lecture = '';
my $missing_lecture_txt = "You must indicate if you will participate in the following lecture(s). Please use your browser's \"back\" button to return to the Willingness To Participate form.";
$sth = $main::dbh->prepare ("SELECT faculty_lecture.lectureid,lecture,DATE_FORMAT(lecture_date, '%a, %b %e, %Y') FROM faculty_lecture,new_lecture WHERE faculty_lecture.lectureid=new_lecture.lectureid AND meetingid=$vosFacultyDisclosure::meeting_no AND faculty_lecture.facultyid=$facultyid");
my $sender = 0;
my $subject = 0;
my $complete = 0;
my @missing = ();
my $missing_flds = "";
my $meeting_name = '';
if (!param('name')) { push @missing, "Name" };
if (!param('degree')) { push @missing, "Academic Title" };
if (!param('hospital')) { push @missing, "Academic Institution" };
if (!param('address')) { push @missing, "Address" };
if (!param('email')) { push @missing, "E-mail Address" };
if (!param('assignments'))
{
$sth->execute();
undef(@ary);
while (@ary = $sth->fetchrow_array())
{
$missing_lecture .= "
$ary[2] — $ary[1]
\n" if !$main::cgi->param("participation$ary[0]");
}
$sth->finish();
}
if (@missing)
{
$missing_flds = join " ", @missing;
print h3("Form Incomplete");
print p("Oops! The following fields are required:");
print p("
$missing_flds
");
print p("Please use your browser's \"back\" button and correct this information.");
} elsif ($missing_lecture) {
print "
$missing_lecture_txt
";
print "
$missing_lecture
\n";
} else {
$updateSQL = "UPDATE member SET ";
@db_fields = qw(degree hospital hospital_citystate phone fax financialRelations discussUnlabeled);
foreach (@db_fields)
{
$updateSQL .= $_ . "=";
if (!param($_))
{
if ($_ eq "financialRelations")
{
$updateSQL .= 0;
} else {
$updateSQL .= "NULL";
}
}
else
{
if ($_ eq "financialRelations" || $_ eq "discussUnlabeled")
{
$updateSQL .= "1" if param($_) eq "yes";
$updateSQL .= "0" if param($_) eq "no";
} else {
$updateSQL .= $main::dbh->quote(param($_));
}
}
$updateSQL .= ", ";
}
$updateSQL .= "disclosureUpdated=NOW(),updated_by='Member via Disclosure Form' WHERE member_id=$facultyid LIMIT 1";
$rows = $main::dbh->do(qq{$updateSQL});
$rows += 0;
if (!$rows)
{
$db_error .= "Failed to update academic info in database! Please make changes manually.\n";
}
# UPDATE FACULTY DATABASE
$sth = $main::dbh->prepare ("SELECT id FROM faculty_lecture WHERE meetingid=$vosFacultyDisclosure::meeting_no AND faculty_lecture.facultyid='$facultyid'");
$sth->execute();
@ary = ();
while (@ary = $sth->fetchrow_array()) {
$updateSQL = "UPDATE faculty_lecture SET wp=1 WHERE id = $ary[0]";
$rows = $main::dbh->do(qq{$updateSQL});
$rows += 0;
if (!$rows) { $db_error .= "Failed to Update LectureID $ary[0]\n"; }
}
$sth->finish;
$main::dbh->do(qq{UNLOCK TABLES});
my $SQL = "SELECT name, meeting.city, meeting.state, meeting.location, MONTHNAME(meeting.start_date), DAYOFMONTH(meeting.start_date), YEAR(meeting.end_date), MONTHNAME(meeting.end_date), DAYOFMONTH(meeting.end_date) FROM meeting WHERE meeting_no = '$vosFacultyDisclosure::meeting_no' AND meeting.workshop_no = 0 AND meeting.breakout_no = 0";
$sth = $main::dbh->prepare($SQL) ||
die "Prepare failed: $DBI::errstr\n";
$sth->execute() ||
die "Couldn't execute query $DBI::errstr\n";
undef(@ary);
@ary = $sth->fetchrow;
$sth->finish;
$meeting_name = $ary[0] . "\n" . $ary[4] . ' ' . $ary[5];
if ($ary[5] eq $ary[8]) {
$meeting_name .= ", $ary[6]";
} else {
if ($ary[4] eq $ary[7]) {
$meeting_name .= "-$ary[8], $ary[6]";
} else {
$meeting_name .= "-$ary[7] $ary[8], $ary[6]";
}
}
$meeting_name .= "\n$ary[3], $ary[1], $ary[2]";
$sender = "VOS Faculty Form ";
$subject = "VOS Willingness to Participate Form for " . param('name');
my $recipient = "angela\@societyhq.com, andrew\@societyhq.com";
# my $recipient = "wes\@societyhq.com";
my $buffer = 'VOS Willingness to Participate';
$buffer .= "\n\n" . $meeting_name;
$buffer .= "\n\nName: " . param('name');
$buffer .= "\nTitle: " . param('degree');
$buffer .= "\nInstitution: " . param('hospital');
$buffer .= "\n\Address: " . param('address') . "\n\nEmail: " . param('email') . "\nPhone Number: " . param('phone') . "\nFax Number: " . param('fax');
$buffer .= "\n\nAdmin Asst: " . param('secretary') . "\nAdmin Asst Phone:" . param('secretary_phone');
$buffer .= "\n\n\nWILLINGNESS TO PARTICIPATE\n";
if (param("assignments")) {
$buffer .= "\nI am pleased to participate in all lectures, workshops, case discussions, and/or as moderator as outlined in the " . $title . " Lecture Schedule.";
} else {
$sth = $main::dbh->prepare ("SELECT faculty_lecture.lectureid FROM faculty_lecture WHERE meetingid=$vosFacultyDisclosure::meeting_no AND faculty_lecture.facultyid='$facultyid'");
$sth->execute();
@ary = ();
while (@ary = $sth->fetchrow_array()) {
$buffer .= "\n\n" . $main::cgi->param("participation$ary[0]");
}
$sth->finish;
}
$buffer .= "\n\n" . $db_error;
open (MAIL, "|/usr/lib/sendmail -oi -t") or die "can't fork sendmail: $!";
print MAIL "From: $sender
To: $recipient
Subject: $subject
bcc: daniel\@societyhq.com
";
print MAIL $buffer;
close (MAIL);
print p('Thank you. Your Willingness to Participate Form has been submitted successfully.',a({href=>"../assignment.iphtml?id=$vosFacultyDisclosure::meeting_no"},'Click here'),'to check for other forms that you may need to complete for this meeting.');
}
}
sub to_page { submit(-NAME => ".State", -VALUE => shift) }
!>