$formparams{FIRSTNAME} = $query->param("firstname"); #### my $query = new CGI; my %db_hash; my $s_dept = $query->param("s_dept"); my $dept_name=&build_list("D", "",$s_dept); my @dept_loop = @tmp_hash; my @branch_loop; my $branch_name; if ($s_dept = $query->param("s_dept")) { my $s_branch = $query->param("s_branch"); $branch_name=&build_list("B", "AND PARENT_ID = $s_dept",$s_branch); @branch_loop = @tmp_hash; } my @div_loop; my $div_name; if ($s_branch = $query->param("s_branch")) { if ($s_branch != "Choose Branch") { my $s_div = $query->param("s_div"); $div_name=&build_list( "V", "AND PARENT_ID = $s_branch",$s_div); @div_loop = @tmp_hash; } } if ($final_sub = $query->param("final_sub")) { # submit and process the form (including send email) &processForm(); exit; } &formparams(); &createForm($formTemplate); exit; #=================================================== # build drop downs #=================================================== sub build_list () { my ($org_type,$sql_insert,$selected)=@_; #receive variable into subroutine my %isSelect; $isSelect{$selected}="SELECTED"; my $dbh=DBI->connect('DBI:Oracle:METAD1', 'ei_arf_webform_select', 'metad1') or die "Cannot connect to DB: " . DBI->errstr; my $sql = "SELECT org_id,org_name FROM mv_org_structure_list WHERE ORG_TYPE='$org_type' $sql_insert ORDER BY org_name ASC"; my $sth = $dbh->prepare($sql) || print "Cannot prepare"; $sth->execute || print "Cannot execute"; my @result; %db_hash = (); while (@result = $sth->fetchrow_array()) { $db_hash {$result[0]} = $result[1]; } @tmp_hash = (); foreach my $key (keys %db_hash) { push @tmp_hash, {ORG_ID => $key, ORG_NAME => $db_hash{$key}, ORG_SELECT => $isSelect{$key}}; } return $db_hash{$selected}; } #=================================================== # forparams #=================================================== sub formparams () { %formparams = (); $formparams{LOGO} = "/images/logobw.gif"; $formparams{TITLE} = "ARF Exempt Request (Network and/or E-Mail Account, Voicemail, Telephone Re-assignment)"; $formparams{PATH} = $ENV{SCRIPT_NAME}; $formparams{DEPARTMENT} = \@dept_loop; $formparams{BRANCH} = \@branch_loop; $formparams{DIVISION} = \@div_loop; } #===================================== # create new form from html template #===================================== sub createForm { $formTemplate = new HTML::Template( filename => $FORM_TMPL_FILE ); for my $key (keys %formparams) { $formTemplate->param($key => $formparams{"$key"}); } my ($formTemplate) = @_; print $formTemplate->output; return; } #===================================== # process submit request #===================================== sub processForm { my $body; $body = getbody(); my $email_subject = "EDS/Telecom Action"; &sendMail ($smtp, $to, $cc, $from, $email_subject, $body); print "
"; print "Thank you!
"; print "
"; print "Your request has been submitted.

"; print "Close Window\n"; return; } #================================================== # get email body set for specific body requirement #================================================== sub getbody() { my $resulttemplate = new HTML::Template( filename => $RESULTS_TMPL_FILE ); my $displaytemplate = new HTML::Template( filename => $DISPLAY_TMPL_FILE ); my $params = getdata(); $resulttemplate->param(FIRSTNAME => $params->{'firstname'}); $resulttemplate->param(LASTNAME => $params->{'lastname'}); #bunch of other parmas removed, you get the idea # To return a list of parameters in the template of $displaytemplate (keys) my @parameter_names = $displaytemplate->param(); foreach my $name (@parameter_names) { # Assign the value of $resulttemplate to the key of $displaytemplate # Since the keys have the same name in both templates. $displaytemplate->param($name => $resulttemplate->param($name)); } $body = $resulttemplate->output; if ($body) { print $displaytemplate->output; # Print out form data to screen return $body; # Returns form data to be sent by email } else { print "Error: Cannot send email body to send
"; exit; } } #======================================= # Get CGI data from the form submitting #======================================= sub getdata() { my %params; my $query = new CGI; foreach my $key ($query->param) { $params{$key} = $query->param($key); } return \%params; } #===================================== sub sendMail { # SEND EMAIL... BLAH BLAH return; }