print "
| "; if ($user_type eq 'admin' || $user_type eq 'staff') { print ""; } print $item; if ($user_type eq 'admin' || $user_type eq 'staff') { print ""; } print " |
##
use DBI;
use Template;
# a little extra shown for cliarity - first get user type
$sql = "SELECT user_type FROM usersTable WHERE (username = $user_name);
$sth = $dbh->prepare($sql) or die("Could not prepare!" . $dbh->errstr);
$sth->execute() or die("Could not execute!" . $dbh->errstr);
$user_type = $sth->fetchrow_array();
$sth->finish;
# get the attributes of the item ids being requested, in this example, corresponding to all items with attribute x = y
$sql = "SELECT item_id, att_2, att_3....att_n FROM theTable WHERE (att_x = 'y');
$sth = $dbh->prepare($sql) or die("Could not prepare!" . $dbh->errstr);
$sth->execute() or die("Could not execute!" . $dbh->errstr);
# build a data structure to store them
while ($item_id, $att_2, $att_3....$att_n) = $sth->fetchrow_array()) {
$data{$item_id} = {
att_2 => $att_2,
att_3 => $att_3,
.....
att_n => $att_n
}
}
$sth->finish;
#user TT to output the results
$template_file = "my_template.htm";
# this passes the whole data hash to the template
$vars = {
user_type => $user_type,
data => \%data
}
$template->process($template_file, $vars) || die "Template process failed: ", $template->error(), "\n";
####
#insert appropriate toolbars depending on user type
[% IF user_type == 'admin' %]
[% INCLUDE admin_function_buttons %]
[% ELSIF user_type == 'staff' %]
[% INCLUDE staff_function_buttons %]
[% ELSE %]
[% INCLUDE client_function_buttons %]
[% END %]
#loop through data hash
[% FOREACH item_id IN data.keys.sort %]
#insert links to functions on items attributes depending on user type
[% IF user_type == 'admin' || user_type == 'staff' %]
[% END %]
data.$item_id.att_1
[% IF user_type == 'admin' || user_type == 'staff' %]
[% END %]
[% data.$item_id.att_2 %]
[% data.$item_id.att_3 %]
# display messages depending on condition and user type
[% IF data.$item_id.att_3 >= 100 && user_type == 'staff'%]High stock - move these suckers!![% END %]
.....
[% data.$item_id.att_N %]
[% END %]