Hi.
I'm working on a similar approach.
My installation is rev. 2.24.431, using groups module and Mysql module over a Linux server.
What I need is to get different "newticket" template depending on who's logged in.
At my application, tickets can only be submitted by an registered user (i.e. an operator belonging to certain group).
Therefore, when people enters URL
www.mysite.com/cgi-bin/ttx.cgi , application asks logon user/password, then sends user to a modified "newticket" that has a menu to manually select the corersponding newticket form temnplate I need to be filled for user.
But this is confusing to users as they can create mistaken tickets (using another newticket form).
My goal is to send user directly to the corresponding newticket template after he(she) logged in.
Sparky said that we can use "styles" function to get my needs. I understand.
I created 10 subfolders below templates folder (named "g1" to "g10") an its respective different newticket on each one, so now if type like this URL:
www.mysite.com/cgi-bin/ttx.cgi?style=g1 or ?style=g2 ... ?style=g10 I got displayed directly the correct newticket form.
BUT... I cannot get this automated yet. I was trying using some code like this above in
ttx.cgi to get automatic direction to proper "page" using styles function, but it donīt works (Internal server error):
Original code in black; my added code in BLUE:
#================================================================== loadtemplate
sub loadtemplate {
my ($t, $style);
if ($query->param('cmd') eq 'newticket' && $query->param('form') ne undef) {
my @parts = split(/\/|\\/, $query->param('form'));
$t = pop @parts;
$t .= '.html';
}
if ($t eq undef) {
$t = $cmddef->{$query->param('cmd')}->{template};
$t = $query->param('cmd').".html" if $t eq undef;
}
my $fn = $cfg->get('basedir')."/templates";
if ($query->param('style') ne undef) {
my @parts = split(/\/|\\/, $query->param('style'));
$style = pop @parts;
}
my $operador = $cfg->get('_USER')->get('login');
if ($operador eq 'arojas') {
$style = 'g8';
}
elsif ($operador eq 'avidal') {
$style = 'g12';
}
elsif ($operador eq 'avsapostventa') {
$style = 'g7';
}
elsif ($operador eq 'cvallejos') {
$style = 'g9';
}
elsif ($operador eq 'cvargas') {
$style = 'g7';
}
elsif ($operador eq 'hmeyer') {
$style = 'g3';
}
elsif ($operador eq 'jaroca') {
$style = 'g9';
}
elsif ($operador eq 'jrodriguez') {
$style = 'g11';
}
elsif ($operador eq 'kcarreņo') {
$style = 'g2';
}
elsif ($operador eq 'mdelgado') {
$style = 'g5';
}
elsif ($operador eq 'mzamora') {
$style = 'g6';
}
elsif ($operador eq 'soryan') {
$style = 'g12';
} else { } my $template;
if ($t ne '#') {
if ($style ne undef) {
if ((! -f "$fn/$style/$t" || !open(TMPL, "$fn/$style/$t")) &&
(! -f "$fn/$t" || !open(TMPL, "$fn/$t"))) {
fatalerror("Missing template $t");
}
} elsif (! -f "$fn/$t" || !open(TMPL, "$fn/$t")) {
fatalerror("Missing template $t");
}
my @buff = <TMPL>;
close TMPL;
$template = join('', @buff);
} else {
my @action_path = split(/::/, $cmddef->{$query->param('cmd')}->{action});
pop @action_path;
my $module = join("::", @action_path);
if ($module eq undef) {
fatalerror("No module defined for embedded template");
}
eval "use $module";
fatalerror("Unable to load module $module<br><br>$@<br><br>SD:".scriptdir()) if $@;
{
no strict 'refs';
my $tmplcmd = $module.'::xtemplate';
eval '$template = ($tmplcmd)->($cfg, $query, \%data)';
fatalerror("Failed to load embedded template, $@") if $@ ne undef;
}
}
if (!($cmddef->{$query->param('cmd')}->{noheader} || $query->param('noheader'))) {
if (($style ne undef && open(TMPL, "$fn/$style/header.shtml")) || open(TMPL, "$fn/header.shtml")) {
my @hdr = <TMPL>;
close TMPL;
$template = join('', @hdr) . $template;
}
if (($style ne undef && open(TMPL, "$fn/$style/footer.shtml")) || open(TMPL, "$fn/footer.shtml")) {
my @ftr = <TMPL>;
close TMPL;
$template .= join('', @ftr);
}
}
return $template;
}
#======================================================================= command
I will really aprecciate some help; my doubts are:
1) Is ttx.cgi and -loadtemplate- subroutine the right place to modify to get my goal?
2) Are Iīm using the correct code to get userid? my $operador = $cfg->get('_USER')->get('login');
3) Are there some code errors such colons, semi colons, parenthesis, apostrophes, etc that might cause server error?
Expecting your help, nice people...
PD: Sorry my bad english, I'm spanish mothertongue.