Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- ##############################################
- use strict;
- use Template;
- use DBI;
- use CGI;
- use warnings;
- ################################
- ## Declaration of Variables ##
- ################################
- my($template, $tt_object, $cgi_object, $sample, $vars, $title,$heading,
- %where);
- my($debug)=0;
- ##----------------------------------------------
- my $user='tom';
- my $password='P@ssw0rd';
- my $db='bible';
- my $dsn = "DBI:mysql:$db";
- my $dbh = DBI->connect($dsn, $user, $password) or die $DBI::errstr;
- #########################
- # Generate Magic Header #
- #########################
- $cgi_object=new CGI;
- print $cgi_object->header('text/html');
- ##-------------------------------------------
- my $N_query=qq~SELECT distinct(bname) FROM kjv WHERE bsect='N'~;
- my $O_query=qq~SELECT distinct(bname) FROM kjv WHERE bsect='O'~;
- my $sth=$dbh->prepare($N_query);
- $sth->execute;
- my $N_booknames=$sth->fetchall_arrayref({});
- $sth=$dbh->prepare($O_query);
- $sth->execute;
- my $O_booknames=$sth->fetchall_arrayref({});
- ######------SEARCH----------#########
- my $book=$cgi_object->param("book");
- my $search=$cgi_object->param("search");
- #my $vtext=param('vtext');
- my %bible=(
- ALL=>"SELECT * FROM kjv WHERE vtext LIKE ?",
- OT=>"SELECT * FROM kjv WHERE bsect='O' AND vtext LIKE ?",
- NT=>qq~SELECT * FROM kjv where bsect='N' AND vtext LIKE ?~
- );
- my $sth=$dbh->prepare("$bible{$book}");
- $sth->bind_param(1, "%$search%");
- $sth->bind_param(2, "%$search%");
- $sth->bind_param(3, "%$search%");
- $sth->execute;
- ##--------------------------------------------
- ################################
- ## New Template Object(step 2)##
- ################################
- $tt_object = Template->new(
- {
- INCLUDE_PATH =>
- [ '/var/www/tt2' ]
- }
- );
- $template = 'class.sample.tt2';
- ######################################
- ## Pretend do some work (step 3) ##
- ######################################
- $sample=("I R working!");
- $title=('This will be a milestone when it grows up');
- $heading="Thomas' Milestone 0 & 1";
- %where=(ALL=>'Entire Bible',
- OT=>'Old Testament',
- XT=>'New Testament',
- );
- ######################################
- ## Prep vars for template (step 4a) ##
- ######################################
- my $filename=File::Basename::basename($0);
- $vars = {
- bound_string => $sample,
- title => $title,
- books => \%where,
- script_pathname =>$filename,
- heading =>$heading,
- O_booknames =>$O_booknames,
- N_booknames =>$N_booknames,
- };
- ######################################
- ## Bind and pass flow (step 4b + 5) ##
- ######################################
- $tt_object->process ( $template, $vars )
- or die( $tt_object->error() );
- ######################################
- __END__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement