#!/usr/bin/env perl
use strict;
use CGI qw(:all);
use TTPP;
use Template;
use DBI;
use Text::CSV;
### configure variables below ###
my $dbfile='eftattr.sqlite';
### codes after here
my $basename = "eftattrshow";
my $csvObject = Text::CSV->new();
my $datasourcename = "dbi:SQLite:dbname=$dbfile";
my $databasehandle = DBI->connect($datasourcename,"","");
my $selectst;
my $id;
my $cgi = new CGI;
if(defined $cgi->param('uid')) {
$id = $cgi->param('uid');
} else {
TTPP::error("Information ID was not specified. Contact the site administrator.");
exit 0;
}
$databasehandle->{RaiseError} = 1;
eval {
$selectst = $databasehandle->prepare("SELECT attr FROM eftattr WHERE id=?;");
$selectst->execute($id);
};
if($@) {
TTPP::error("Error occurred while database access. Contact the site administrator.
$DBI::errstr"); } my $vars = {}; # print STDERR "ID: $id\n"; while(my ($attr) = $selectst->fetchrow_array()) { my $parseSucceeded = $csvObject->parse($attr); if($parseSucceeded) { # print STDERR "FF: $attr\n"; my @arr = (); for($csvObject->fields()) { if(m|^(.*?)=(.*)$|) { my ($k, $v) = ($1, $2); # print STDERR "KV: $k = $v\n"; push(@arr, {key => $k, value => $v}); } else { push(@arr, {key => "Error", value => $_}); } } @{$vars->{attributes}} = @arr; } else { @{$vars->{attributes}} = (); } } ########################################### ### DO NOT EDIT AFTER HERE ### ### TemplateToolkit Preprocessing ### my $TTFile = $basename . '.tt'; my $TemplateFile = $basename . '.t'; TTPP::preprocess($TemplateFile, $TTFile) or TTPP::error("Error while template preprocessing"); ### invoke TemplateToolkit ### my $template = Template->new(); $template->process($TTFile, $vars);