Changed the help system to use the internationalization system directly.

This commit is contained in:
JT Smith 2002-07-14 20:55:18 +00:00
parent 2836eb1ef1
commit d1f8f816f8
4 changed files with 94 additions and 131 deletions

View file

@ -12,92 +12,85 @@ package WebGUI::Operation::Help;
use Exporter;
use strict;
use Tie::IxHash;
use Tie::CPHash;
use WebGUI::International;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::URL;
use WebGUI::Utility;
our @ISA = qw(Exporter);
our @EXPORT = qw(&www_viewHelp &www_viewHelpIndex);
#-------------------------------------------------------------------
sub _helpLink {
return '<a href="'.WebGUI::URL::page('op=viewHelp&hid='.$_[0].'&namespace='.$_[1]).'">'.$_[2].'</a>';
}
#-------------------------------------------------------------------
sub _seeAlso {
my ($item, $seeAlso, @items, $namespace, $helpId, $titleId, $output);
$seeAlso = $_[0];
$seeAlso =~ s/\n//g; #removes line feeds
$seeAlso =~ s/\r//g; #removes carriage returns
$seeAlso =~ s/ //g; #removes spaces
@items = split(/;/,$seeAlso);
foreach $item (@items) {
($helpId,$namespace) = split(/,/,$item);
($titleId) = WebGUI::SQL->quickArray("select titleId from help where helpId=$helpId
and namespace='$namespace'");
$output .= '<li>'._helpLink($helpId,$namespace,WebGUI::International::get($titleId,$namespace));
}
return $output;
}
#-------------------------------------------------------------------
sub www_viewHelp {
my ($output, %help, @data, $sth, %seeAlso, $namespace);
my ($output, %help, $namespace);
$namespace = $session{form}{namespace} || "WebGUI";
tie %help, 'Tie::CPHash';
%help = WebGUI::SQL->quickHash("select * from help where helpId=$session{form}{hid} and namespace='$namespace' and
languageId='$session{user}{language}'");
if ($help{action} eq "") {
%help = WebGUI::SQL->quickHash("select * from help where helpId=$session{form}{hid} and namespace='$namespace' and languageId=1");
}
$output = '<h1>'.WebGUI::International::get(93).': '.$help{action}.' '.$help{object}.'</h1>';
$output .= $help{body};
$output .= '<p><b>'.WebGUI::International::get(94).':';
$sth = WebGUI::SQL->read("select helpId, action, object, namespace from help where object='$help{object}'
and action<>'$help{action}' and languageId='$session{user}{language}' order by action");
unless ($sth->rows) {
$sth->finish;
$sth = WebGUI::SQL->read("select helpId, action, object, namespace from help where object='$help{object}'
and action<>'$help{action}' and languageId=1 order by action");
}
while (@data = $sth->array) {
$output .= ' <a href="'.WebGUI::URL::page('op=viewHelp&hid='.$data[0].'&namespace='.$data[3])
.'">'.$data[1].' '.$data[2].'</a>,';
}
$sth->finish;
$sth = WebGUI::SQL->read("select helpId, namespace from helpSeeAlso where seeAlsoId in ($help{seeAlso})");
while (@data = $sth->array) {
%seeAlso = WebGUI::SQL->quickHash("select helpId,namespace,action,object from help where helpId='$data[0]'
and namespace='$data[1]' and languageId='$session{user}{language}'");
if ($seeAlso{helpId} eq "") {
%seeAlso = WebGUI::SQL->quickHash("select helpId,namespace,action,object from help where helpId='$data[0]'
and namespace='$data[1]' and languageId=1");
}
$output .= ' <a href="'.
WebGUI::URL::page('op=viewHelp&hid='.$seeAlso{helpId}.'&namespace='.$seeAlso{namespace})
.'">'.$seeAlso{action}.' '.$seeAlso{object}.'</a>,';
}
$sth->finish;
$output .= ' <a href="'.WebGUI::URL::page('op=viewHelpIndex').'">'.WebGUI::International::get(95).'</a>';
%help = WebGUI::SQL->quickHash("select * from help where helpId=$session{form}{hid} and namespace='$namespace'");
$output = '<h1>'.WebGUI::International::get(93).': '.
WebGUI::International::get($help{titleId},$help{namespace}).'</h1>';
$output .= WebGUI::International::get($help{bodyId},$help{namespace});
$output .= '<p><b>'.WebGUI::International::get(94).':<ul>';
$output .= _seeAlso($help{seeAlso});
$output .= '<li><a href="'.WebGUI::URL::page('op=viewHelpIndex').'">'.WebGUI::International::get(95).'</a></ul>';
return $output;
}
#-------------------------------------------------------------------
sub www_viewHelpIndex {
my ($sth, @data, $output, $previous);
my ($sth, %help, $output, $key, %index, $title, $seeAlso, %sortedIndex, $i, $midpoint);
tie %help, 'Tie::CPHash';
tie %sortedIndex, 'Tie::IxHash';
$output = '<h1>'.WebGUI::International::get(95).'</h1>';
$output .= '<table width="100%"><tr><td valign="top"><b>'.WebGUI::International::get(96).'</b><p>';
$sth = WebGUI::SQL->read("select helpId, action, object, namespace from help where languageId='$session{user}{language}' order by action,object");
unless ($sth->rows) {
$sth->finish;
$sth = WebGUI::SQL->read("select helpId, action, object, namespace from help where languageId=1 order by action,object");
}
while (@data = $sth->array) {
if ($data[1] ne $previous) {
$output .= '<p><b>'.$data[1].'</b><br>';
$previous = $data[1];
}
$output .= '<li><a href="'.WebGUI::URL::page('op=viewHelp&hid='.$data[0].'&namespace='.$data[3])
.'">'.$data[2].'</a><br>';
$sth = WebGUI::SQL->read("select helpId,namespace,titleId,seeAlso from help");
while (%help = $sth->hash) {
$title = WebGUI::International::get($help{titleId},$help{namespace});
$index{$title} = _helpLink($help{helpId},$help{namespace},$title);
$seeAlso = _seeAlso($help{seeAlso});
if ($seeAlso ne "") {
$index{$title} .= '<span style="font-size: 11px"><ul>'.$seeAlso.'</ul></span>';
}
$i++;
}
$midpoint = round($i/2);
$sth->finish;
$output .= '</td><td valign="top"><b>'.WebGUI::International::get(97).'</b><p>';
$sth = WebGUI::SQL->read("select helpId, object, action, namespace from help where languageId='$session{user}{language}' order by object,action");
unless ($sth->rows) {
$sth->finish;
$sth = WebGUI::SQL->read("select helpId, object, action, namespace from help where languageId=1 order by object,action");
foreach $key (sort {$a cmp $b} keys %index) {
$sortedIndex{$key}=$index{$key};
}
while (@data = $sth->array) {
if ($data[1] ne $previous) {
$output .= '<p><b>'.$data[1].'</b><br>';
$previous = $data[1];
}
$output .= '<li><a href="'.WebGUI::URL::page('op=viewHelp&hid='.$data[0].'&namespace='.$data[3])
.'">'.$data[2].'</a><br>';
}
$sth->finish;
$output .= '</td></tr></table>';
$i = 0;
$output .= '<table width="100%"><tr><td width="50%" valign="top" class="content">';
foreach $key (keys %sortedIndex) {
if ($i == $midpoint) {
$output .= '</td><td width="50%" valign="top" class="content">';
}
$output .= $sortedIndex{$key}.'<p>';
$i++;
}
$output .= '</table>';
return $output;
}