package TTXUpgrade; # # This module is a part of Trouble Ticket Express package # http://www.troubleticketexpress.com # # COPYRIGHT: 2005-2006, United Web Coders # http://www.unitedwebcoders.com # # $Revision: 181 $ # $Date: 2006-06-07 02:20:54 -0400 (Wed, 07 Jun 2006) $ # $TTXUpgrade::VERSION='2.22'; BEGIN { $TTXUpgrade::REVISION = '$Revision: 181 $'; if ($TTXUpgrade::REVISION =~ /(\d+)/) { $TTXUpgrade::REVISION = $1; } }; use strict; require TTXSetup; my %upgradepath = ( '2.182' => { ver => '2.19', code => \&upgrade219 }, '2.19' => { ver => '2.191', code => \&upgrade2191 }, '2.191' => { ver => '2.20', code => \&upgrade220 }, '2.20' => { ver => '2.21', code => \&upgrade221 }, '2.21' => { ver => '2.22', code => \&upgrade222 }, ); # ====================================================================== upgrade sub upgrade { my $cfg = $_[0]; my $v = $cfg->get('ttx.version'); if ($v eq undef) { if (-f $cfg->get('basedir'). "/templates/ticketed.html") { $v = '2.182'; } } for (my $ver = $upgradepath{$v}; $ver ne undef ; $ver = $upgradepath{$ver->{ver}}) { my $err = &{$ver->{code}}($cfg); if ($err ne undef) { return $err; } $cfg->set('ttx.version', $ver->{ver}); $cfg->save(); } return undef; } # =================================================================== upgrade219 sub upgrade219 { my $cfg = $_[0]; my $fn = $cfg->get('basedir'). "/templates/header.shtml"; return "File $fn does not exist" if ! -f $fn; return "File $fn is not writable" if ! -w $fn; return "Can't open file $fn" if !open(F, "+<$fn"); flock(F,2); my $buff = join('', ); if ($buff !~ /\btd\.txt\s+\{/) { my $addthis = </$addthis\n<\/style>/; seek(F,0,0); print F $buff; truncate(F, tell(F)); } close(F); $fn = $cfg->get('basedir'). "/templates/helpdesk.html"; return "File $fn does not exist" if ! -f $fn; return "File $fn is not writable" if ! -w $fn; return "Can't open file $fn" if !open(F, "+<$fn"); flock(F,2); $buff = join('', ); if ($buff =~ /<\s*input\s+type="?hidden"?\s+name="?qwindow"?\s+value="?\(%INPUT_qwindow%\)"?\s*>/) { $buff =~ s/<\s*input\s+type="?hidden"?\s+name="?qwindow"?\s+value="?\(%INPUT_qwindow%\)"?\s*>//; my $addthis = < Show tickets per page. Include abstracts   EOT my $findthis = '\s*]*>]*>[^<]*]*>[^<]*[^<]*'; $buff =~ s/$findthis/$addthis\n/i; seek(F,0,0); print F $buff; truncate(F, tell(F)); } close(F); $fn = $cfg->get('basedir'). "/templates/ticket.html"; return "File $fn does not exist" if ! -f $fn; return "File $fn is not writable" if ! -w $fn; return "Can't open file $fn" if !open(F, "+<$fn"); flock(F,2); $buff = join('', ); if ($buff =~ /width=700,\s*height=300,\s*resizable/) { $buff =~ s/width=700,\s*height=300,\s*resizable/width=700,height=360,resizable/; seek(F,0,0); print F $buff; truncate(F, tell(F)); } close(F); $fn = $cfg->get('basedir'). "/templates/answerlib.html"; return "File $fn does not exist" if ! -f $fn; return "File $fn is not writable" if ! -w $fn; return "Can't open file $fn" if !open(F, "+<$fn"); flock(F,2); $buff = join('', ); if ($buff !~ /showcat/) { $buff =~ s/-->\s*<\/style>/.lbl { font-size: 9pt; font-weight: 700;}-->\n<\/style>/; my $addthis = < EOT $buff =~ s/<\/head>/$addthis/i; $buff =~ s/\(%ANSWERLIBMSG%\)\s*
/(%ANSWERLIBMSG%)\n/; $addthis = < EOT $buff =~ s//$addthis/i; seek(F,0,0); print F $buff; truncate(F, tell(F)); } close(F); $fn = $cfg->get('basedir'). "/templates/newanswer.html"; return "File $fn does not exist" if ! -f $fn; return "File $fn is not writable" if ! -w $fn; return "Can't open file $fn" if !open(F, "+<$fn"); flock(F,2); $buff = join('', ); if ($buff !~ /CATSELECTOR/) { $buff =~ s/-->\s*<\/style>/.lbl { font-size: 9pt; font-weight: 700;}-->\n<\/style>/; my $addthis = < Select existing category or define new one: Answer EOT $buff =~ s/]*>\s*Answer\s*<\/td>/$addthis/i; seek(F,0,0); print F $buff; truncate(F, tell(F)); } close(F); $fn = $cfg->get('basedir'). "/templates/delanswer.html"; return "File $fn does not exist" if ! -f $fn; return "File $fn is not writable" if ! -w $fn; return "Can't open file $fn" if !open(F, "+<$fn"); flock(F,2); $buff = join('', ); if ($buff !~ /\.lbl/) { $buff =~ s/-->\s*<\/style>/.lbl { font-size: 9pt; font-weight: 700;}-->\n<\/style>/; seek(F,0,0); print F $buff; truncate(F, tell(F)); } close(F); eval "use TTXLayout"; if ($@ ne undef) { $cfg->set('fltrcols', 'text|subject|oper|status|id'); $cfg->save(); } else { $cfg->set('fltrcols', 'text|'.$cfg->get('fltrcols')); } return undef; } # =================================================================== upgrade219 sub upgrade2191 { my $cfg = $_[0]; my $fn = $cfg->get('basedir'). "/templates/helpdesk.html"; return "File $fn does not exist" if ! -f $fn; return "File $fn is not writable" if ! -w $fn; return "Can't open file $fn" if !open(F, "+<$fn"); flock(F,2); my $buff = join('', ); if ($buff =~ /<\s*input\s+type="?hidden"?\s+name="?qwindow"?\s+value="?\(%INPUT_qwindow%\)"?\s*>/) { $buff =~ s/<\s*input\s+type="?hidden"?\s+name="?qwindow"?\s+value="?\(%INPUT_qwindow%\)"?\s*>//; seek(F,0,0); print F $buff; truncate(F, tell(F)); } close(F); return undef; } # =================================================================== upgrade220 sub upgrade220 { my $cfg = $_[0]; # Disabled in 2.22. Default is do not use cache. Just to avoid problems while # editing templates. # $cfg->set('usecache', 1); eval "use TTXSetup"; if ($@ ne undef) { return "Error loading TTXSetup: $@"; } my $v; eval '$v = $TTXSetup::VERSION'; if ($@ ne undef) { return "Error reading TTXSetup version: $@"; } if ($v eq undef || $v < 2.20) { return "Error: Version mismatch: TTXSetup $v, TTXUpgrade ".$TTXUpgrade::VERSION; } return TTXSetup::tmplreset($cfg, 'reports.html'); } # =================================================================== upgrade221 sub upgrade221 { return undef; } # =================================================================== upgrade222 sub upgrade222 { my $cfg = $_[0]; for my $f ('header.shtml', 'ticketed.html', 'newanswer.html', 'answerlib.html', 'delanswer.html') { my $fn = $cfg->get('basedir'). "/templates/$f"; next if ! -f $fn; return "File $fn is not writable" if ! -w $fn; return "Can't open file $fn" if !open(F, "+<$fn"); flock(F,2); my $buff = join('', ); if ($buff !~ /\(%HTML_CHARSET%\)/) { $buff =~ s//\n(%HTML_CHARSET%)/i; seek(F,0,0); print F $buff; truncate(F, tell(F)); } close(F); } my $fn = $cfg->get('basedir'). "/templates/ticket.html"; if (-f $fn) { return "File $fn is not writable" if ! -w $fn; return "Can't open file $fn" if !open(F, "+<$fn"); flock(F,2); my $buff = join('', ); if ($buff !~ /function preview\(\)/) { my $addthis = < EOT $buff =~ s/ EOT } truncate(F, tell(F)); close(F); } my $ccode = TTXSetup::tmplreset($cfg, 'preview.html'); return $ccode if $ccode ne undef; return TTXSetup::tmplreset($cfg, 'roticket.html'); } 1; #