Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.74 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. ##############################################
  4. use strict;
  5. use Template;
  6. use DBI;
  7. use CGI;
  8. use warnings;
  9.  
  10. ################################
  11. ## Declaration of Variables   ##
  12. ################################
  13. my($template, $tt_object, $cgi_object, $sample, $vars, $title,$heading,
  14.     %where);
  15. my($debug)=0;
  16. ##----------------------------------------------
  17.  
  18. my $user='tom';
  19. my $password='P@ssw0rd';
  20. my $db='bible';
  21. my $dsn = "DBI:mysql:$db";
  22. my $dbh = DBI->connect($dsn, $user, $password) or die $DBI::errstr;
  23.  
  24. #########################
  25. # Generate Magic Header #
  26. #########################
  27. $cgi_object=new CGI;
  28. print $cgi_object->header('text/html');
  29.  
  30. ##-------------------------------------------
  31. my $N_query=qq~SELECT distinct(bname) FROM kjv WHERE bsect='N'~;
  32. my $O_query=qq~SELECT distinct(bname) FROM kjv WHERE bsect='O'~;
  33. my $sth=$dbh->prepare($N_query);
  34. $sth->execute;
  35. my $N_booknames=$sth->fetchall_arrayref({});
  36.  
  37. $sth=$dbh->prepare($O_query);
  38. $sth->execute;
  39. my $O_booknames=$sth->fetchall_arrayref({});
  40.  
  41. ######------SEARCH----------#########
  42. my $book=$cgi_object->param("book");
  43. my $search=$cgi_object->param("search");
  44. #my $vtext=param('vtext');
  45. my %bible=(
  46.         ALL=>"SELECT * FROM kjv WHERE vtext LIKE ?",
  47.         OT=>"SELECT * FROM kjv WHERE bsect='O' AND vtext LIKE ?",
  48.         NT=>qq~SELECT * FROM kjv where bsect='N' AND vtext LIKE ?~
  49.         );
  50. my $sth=$dbh->prepare("$bible{$book}");
  51. $sth->bind_param(1, "%$search%");
  52. $sth->bind_param(2, "%$search%");
  53. $sth->bind_param(3, "%$search%");
  54. $sth->execute;
  55.  
  56. ##--------------------------------------------
  57. ################################
  58. ## New Template Object(step 2)##
  59. ################################
  60. $tt_object = Template->new(
  61.     {
  62.     INCLUDE_PATH =>
  63.         [ '/var/www/tt2' ]
  64.     }
  65.     );
  66. $template = 'class.sample.tt2';
  67.  
  68. ######################################
  69. ## Pretend do some work (step 3)    ##
  70. ######################################
  71.  
  72. $sample=("I R working!");
  73. $title=('This will be a milestone when it grows up');
  74. $heading="Thomas' Milestone 0 & 1";
  75. %where=(ALL=>'Entire Bible',
  76.         OT=>'Old Testament',
  77.         XT=>'New Testament',
  78.         );
  79. ######################################
  80. ## Prep vars for template (step 4a) ##
  81. ######################################
  82. my $filename=File::Basename::basename($0);
  83.  
  84. $vars = {
  85.         bound_string => $sample,
  86.         title => $title,
  87.         books => \%where,
  88.         script_pathname =>$filename,
  89.         heading =>$heading,
  90.         O_booknames =>$O_booknames,
  91.         N_booknames =>$N_booknames,
  92.         };
  93. ######################################
  94. ## Bind and pass flow (step 4b + 5) ##
  95. ######################################
  96. $tt_object->process ( $template, $vars )
  97.     or die( $tt_object->error() );
  98.  
  99.    
  100. ######################################
  101.  
  102. __END__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement