rewrote internationalization and help system

This commit is contained in:
JT Smith 2004-06-25 19:21:35 +00:00
parent e0d4792587
commit 7bb6ac31c1
57 changed files with 11072 additions and 731 deletions

View file

@ -13,257 +13,101 @@ package WebGUI::Operation::Help;
use Exporter;
use strict;
use Tie::IxHash;
use Tie::CPHash;
use WebGUI::DateTime;
use WebGUI::Grouping;
use WebGUI::HTMLForm;
use WebGUI::Icon;
use WebGUI::International;
use WebGUI::Macro;
use WebGUI::Operation::Shared;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::URL;
use WebGUI::Utility;
our @ISA = qw(Exporter);
our @EXPORT = qw(&www_viewHelp &www_viewHelpIndex &www_manageHelp &www_editHelp &www_editHelpSave
&www_exportHelp &www_deleteHelp &www_deleteHelpConfirm);
our @EXPORT = qw(&www_viewHelp &www_viewHelpIndex);
#-------------------------------------------------------------------
sub _helpLink {
return '<a href="'.WebGUI::URL::page('op=viewHelp&hid='.$_[0].'&namespace='.$_[1]).'">'.$_[2].'</a>';
sub _get {
my $id = shift;
my $namespace = shift;
my $cmd = "WebGUI::Help::".$namespace;
my $load = "use ".$cmd;
eval($load);
$cmd = "\$".$cmd."::HELP->{'".$id."'}";
return eval($cmd);
}
#-------------------------------------------------------------------
sub _link {
return '<a href="'.WebGUI::URL::page('op=viewHelp&hid='.WebGUI::URL::escape($_[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));
my $related = shift;
my $namespace = shift;
my $output;
foreach my $row (@{$related}) {
my $help = _get($row->{tag},$row->{namespace});
$output .= '<li>'._link($row->{tag},$row->{namespace},WebGUI::International::get($help->{title},$row->{namespace}));
}
return $output;
}
#-------------------------------------------------------------------
sub _submenu {
my (%menu);
tie %menu, 'Tie::IxHash';
%menu = %{$_[1]};
if ($session{form}{op} ne "viewHelp" && $session{form}{op} ne "viewHelpIndex") {
$menu{WebGUI::URL::page('op=editHelp&hid=new')} = "Add new help.";
$menu{WebGUI::URL::page('op=exportHelp')} = "Export help.";
}
if (($session{form}{op} eq "editHelp" && $session{form}{hid} ne "new") || $session{form}{op} eq "deleteHelp") {
$menu{WebGUI::URL::page('op=editHelpIndex&hid='.$session{form}{hid})} = "Edit this help.";
$menu{WebGUI::URL::page('op=deleteHelp&hid='.$session{form}{hid}.'&namespace='.$session{form}{namespace})} = "Delete this help.";
}
$menu{WebGUI::URL::page('op=viewHelpIndex')} = WebGUI::International::get(13);
return menuWrapper($_[0],\%menu);
}
#-------------------------------------------------------------------
sub www_deleteHelp {
return "" unless (WebGUI::Grouping::isInGroup(3));
my $output = '<h1>Confirm</h1>Are you sure? Deleting help is never a good idea. <a href="'
.WebGUI::URL::page("op=deleteHelpConfirm&hid=".$session{form}{hid}."&namespace=".$session{form}{namespace})
.'">Yes</a> / <a href="'.WebGUI::URL::page("op=manageHelp").'">No</a><p>';
return _submenu($output,{});
}
#-------------------------------------------------------------------
sub www_deleteHelpConfirm {
return "" unless (WebGUI::Grouping::isInGroup(3));
my ($titleId, $bodyId) = WebGUI::SQL->quickArray("select titleId,bodyId from help where helpId=".$session{form}{hid}."
and namespace=".quote($session{form}{namespace}));
WebGUI::SQL->write("delete from international where internationalId=$titleId
and namespace=".quote($session{form}{namespace}));
WebGUI::SQL->write("delete from international where internationalId=$bodyId
and namespace=".quote($session{form}{namespace}));
WebGUI::SQL->write("delete from help where helpId=".$session{form}{hid}."
and namespace=".quote($session{form}{namespace}));
return www_manageHelp();
}
#-------------------------------------------------------------------
sub www_editHelp {
return "" unless (WebGUI::Grouping::isInGroup(3));
my ($output, $f, %data, %help, @seeAlso);
tie %data, 'Tie::IxHash';
tie %help, 'Tie::CPHash';
if ($session{form}{hid} ne "new") {
%help = WebGUI::SQL->quickHash("select * from help where
helpId=$session{form}{hid} and namespace=".quote($session{form}{namespace}));
($help{title}) = WebGUI::SQL->quickArray("select message from international where internationalId=$help{titleId} and namespace=".quote($help{namespace})." and languageId=$session{user}{language}");
($help{body}) = WebGUI::SQL->quickArray("select message from international where internationalId=$help{bodyId} and namespace=".quote($help{namespace})." and languageId=$session{user}{language}");
$help{seeAlso} =~ s/\n//g;
$help{seeAlso} =~ s/\r//g;
$help{seeAlso} =~ s/ //g;
@seeAlso = split(/;/,$help{seeAlso});
} else {
$help{titleId} = "new";
$help{bodyId} = "new";
$help{namespace} = "WebGUI";
}
$output = '<h1>Edit Help</h1>';
$f = WebGUI::HTMLForm->new();
$f->hidden("op","editHelpSave");
$f->hidden("hid",$session{form}{hid});
$f->readOnly($session{form}{hid},"Help ID");
if ($session{form}{hid} eq "new") {
%data = WebGUI::SQL->buildHash("select namespace,namespace from help order by namespace");
$f->combo("namespace",\%data,"Namespace",[$help{namespace}]);
} else {
$f->hidden("namespace",$session{form}{namespace});
$f->readOnly($session{form}{namespace},"Namespace");
}
$f->hidden("titleId",$help{titleId});
$f->readOnly($help{titleId},"Title ID");
$f->text("title","Title",$help{title});
$f->hidden("bodyId",$help{bodyId});
$f->readOnly($help{bodyId},"Body ID");
$f->HTMLArea("body","Body",$help{body},'','','',20,60);
%data = WebGUI::SQL->buildHash("select concat(help.helpId,',',help.namespace),
concat(international.message,' (',help.helpId,'/',help.namespace,')')
from help,international where help.titleId=international.internationalId
and help.namespace=international.namespace and international.languageId=1 order by international.message");
$f->select("seeAlso",\%data,"See Also",\@seeAlso,8,1);
$f->submit;
$output .= $f->print;
return _submenu($output,{});
}
#-------------------------------------------------------------------
sub www_editHelpSave {
return "" unless (WebGUI::Grouping::isInGroup(3));
my (@seeAlso);
if ($session{form}{hid} eq "new") {
if ($session{form}{namespace_new} ne "") {
$session{form}{namespace} = $session{form}{namespace_new};
}
($session{form}{titleId}) = WebGUI::SQL->quickArray("select max(internationalId) from international
where namespace=".quote($session{form}{namespace})." and languageId=1");
$session{form}{titleId}++;
$session{form}{bodyId} = $session{form}{titleId}+1;
($session{form}{hid}) = WebGUI::SQL->quickArray("select max(helpId) from help
where namespace=".quote($session{form}{namespace}));
$session{form}{hid}++;
WebGUI::SQL->write("insert into international (internationalId,languageId,namespace) values
($session{form}{titleId},1,".quote($session{form}{namespace}).")");
WebGUI::SQL->write("insert into international (internationalId,languageId,namespace) values
($session{form}{bodyId},1,".quote($session{form}{namespace}).")");
WebGUI::SQL->write("insert into help (helpId,namespace,titleId,bodyId) values
($session{form}{hid},".quote($session{form}{namespace}).",$session{form}{titleId},
$session{form}{bodyId})");
}
@seeAlso = $session{cgi}->param('seeAlso');
if ($seeAlso[0] ne "") {
$session{form}{seeAlso} = join(";",@seeAlso);
$session{form}{seeAlso} .= ';';
}
WebGUI::SQL->write("update international set message=".quote($session{form}{title}).", lastUpdated=".time()."
where internationalId=$session{form}{titleId} and languageId=1 and namespace=".quote($session{form}{namespace}));
WebGUI::SQL->write("update international set message=".quote($session{form}{body}).", lastUpdated=".time()."
where internationalId=$session{form}{bodyId} and languageId=1 and namespace=".quote($session{form}{namespace}));
WebGUI::SQL->write("update help set seeAlso=".quote($session{form}{seeAlso})."
where helpId=$session{form}{hid} and namespace=".quote($session{form}{namespace}));
return www_manageHelp();
}
#-------------------------------------------------------------------
sub www_exportHelp {
return "" unless (WebGUI::Grouping::isInGroup(3));
my ($export, $output, %help, $sth);
$export = "#export of WebGUI ".$WebGUI::VERSION." help system.\n\n";
$sth = WebGUI::SQL->read("select * from help");
while (%help = $sth->hash) {
$export .= "delete from help where helpId=$help{helpId} and namespace=".quote($help{namespace}).";\n";
$export .= "insert into help (helpId,namespace,titleId,bodyId,seeAlso) values ($help{helpId}, "
.quote($help{namespace}).", $help{titleId}, $help{bodyId}, ".quote($help{seeAlso}).");\n";
}
$sth->finish;
$session{header}{mimetype} = 'text/plain';
return $export;
}
#-------------------------------------------------------------------
sub www_manageHelp {
my ($sth, @help, $output);
return "" unless (WebGUI::Grouping::isInGroup(3));
$output = '<h1>Manage Help</h1>';
$output .= 'This interface is for WebGUI developers only. If you\'re not a developer, leave this alone. Also,
this interface works <b>ONLY</b> under MySQL and is not supported by Plain Black under any
circumstances.<p>';
$output .= '<table class="tableData">';
$sth = WebGUI::SQL->read("select help.helpId,help.namespace,international.message from help,international
where help.titleId=international.internationalId and help.namespace=international.namespace
and international.languageId=1 order by international.message");
while (@help = $sth->array) {
$output .= '<tr><td>'
.deleteIcon("op=deleteHelp&hid=".$help[0]."&namespace=".$help[1])
.editIcon("op=editHelp&hid=".$help[0]."&namespace=".$help[1])
.'</td>'
.'<td>'._helpLink($help[0],$help[1],$help[2]).'</td>'
.'<td>'.$help[0].'/'.$help[1].'</td>'
.'</tr>';
}
$sth->finish;
$output .= '</table>';
return _submenu($output,{});
}
#-------------------------------------------------------------------
sub www_viewHelp {
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'");
$output = '<h1>'.WebGUI::International::get(93).': '.WebGUI::International::get($help{titleId},$help{namespace}).'</h1>';
$output .= WebGUI::International::get($help{bodyId},$help{namespace});
my $namespace = $session{form}{namespace} || "WebGUI";
my $help = _get($session{form}{hid},$namespace);
my $output = '<h1>'.WebGUI::International::get(93).': '.WebGUI::International::get($help->{title},$namespace).'</h1>';
$output .= WebGUI::International::get($help->{body},$namespace);
$output .= '<p><b>'.WebGUI::International::get(94).':<ul>';
$output .= _seeAlso($help{seeAlso});
$output .= _seeAlso($help->{related},$namespace);
$output .= '<li><a href="'.WebGUI::URL::page('op=viewHelpIndex').'">'.WebGUI::International::get(95).'</a></ul>';
return WebGUI::Macro::negate($output);
}
#-------------------------------------------------------------------
sub www_viewHelpIndex {
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>';
$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;
foreach $key (sort {$a cmp $b} keys %index) {
$sortedIndex{$key}=$index{$key};
my %helpIndex;
tie %helpIndex, "Tie::IxHash";
my $i;
my $dir = $session{config}{webguiRoot}.$session{os}{slash}."lib".$session{os}{slash}."WebGUI".$session{os}{slash}."Help";
opendir (DIR,$dir) or WebGUI::ErrorHandler::fatalError("Can't open Help directory!");
my @files = readdir(DIR);
closedir(DIR);
foreach my $file (@files) {
if ($file =~ /(.*?)\.pm$/) {
my $namespace = $1;
my $cmd = "WebGUI::Help::".$namespace;
my $load = "use ".$cmd;
eval($load);
unless ($@) {
$cmd = "\$".$cmd."::HELP";
my $help = eval($cmd);
foreach my $key (keys %{$help}) {
$helpIndex{$key."_".$namespace} = WebGUI::International::get($help->{$key}{title},$namespace);
$i++;
}
} else {
WebGUI::ErrorHandler::warn("Help failed to compile: $namespace. ".$@);
}
}
}
my $output = '<h1>Help Index</h1><table width="100%" class="content"><tr><td valign="top">';
my $halfway = round($i/2);
$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>';
%helpIndex = sortHash(%helpIndex);
foreach my $key (keys %helpIndex) {
my ($id,$namespace) = split("_",$key);
my $help = _get($id,$namespace);
$output .= _link($id,$namespace,$helpIndex{$key});
$output .= '<ul style="padding-left: 20px; margin: 2px; font-size: smaller;">';
$output .= _seeAlso($help->{related},$namespace);
$output .= '</ul>';
$output .= "<br>";
$i++;
if ($i == $halfway) {
$output .= '</td><td valign="top">';
}
}
$output .= '</table>';
$output .= '</td></tr></table>';
return $output;
}

View file

@ -1,409 +0,0 @@
package WebGUI::Operation::International;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2004 Plain Black LLC.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use Exporter;
use strict;
use Tie::CPHash;
use WebGUI::DateTime;
use WebGUI::Grouping;
use WebGUI::HTMLForm;
use WebGUI::Icon;
use WebGUI::International;
use WebGUI::Macro;
use WebGUI::Mail;
use WebGUI::Operation::Shared;
use WebGUI::Paginator;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::URL;
our @ISA = qw(Exporter);
our @EXPORT = qw(&www_listLanguages &www_editLanguage &www_submitTranslation &www_submitTranslationConfirm
&www_deleteLanguage &www_deleteLanguageConfirm &www_addInternationalMessage &www_addInternationalMessageSave
&www_listInternationalMessages &www_editLanguageSave &www_editInternationalMessage
&www_exportTranslation &www_editInternationalMessageSave );
#-------------------------------------------------------------------
sub _export {
my ($sth, %data, $export);
tie %data, 'Tie::CPHash';
%data = WebGUI::SQL->quickHash("select * from language where languageId=".$_[0]);
$export = "#Exported from ".$session{setting}{companyName}." (http://".$session{env}{SERVER_NAME}.") by "
.$session{user}{username}." (".$session{user}{email}.")\n";
$export .= "#".$data{language}." translation export for WebGUI ".$WebGUI::VERSION.".\n\n";
$export .= "#language\n\n";
$export .= "delete from language where languageId=".$_[0].";\n";
$export .= "insert into language (languageId,language,characterSet,toolbar) values ("
.$data{languageId}.", ".quote($data{language}).", ".quote($data{characterSet}).", "
.quote($data{toolbar}).");\n";
$export .= "\n#international messages\n\n";
$sth = WebGUI::SQL->read("select * from international where languageId=".$_[0]." order by lastUpdated desc");
while (%data = $sth->hash) {
$export .= "delete from international where languageId=".$_[0]." and namespace="
.quote($data{namespace})." and internationalId=".$data{internationalId}.";\n";
$export .= "insert into international (internationalId,languageId,namespace,message,lastUpdated";
$export .= ",context" if ($_[0] == 1);
$export .= ") values ("
.$data{internationalId}.",".$data{languageId}.",".quote($data{namespace})
.",".quote($data{message}).", ".$data{lastUpdated};
$export .= ",".quote($data{context}) if ($_[0] == 1);
$export .= ");\n";
}
$sth->finish;
return $export;
}
#-------------------------------------------------------------------
sub _submenu {
my (%menu);
tie %menu, 'Tie::IxHash';
$menu{WebGUI::URL::page('op=editLanguage&lid=new')} = WebGUI::International::get(584);
if ($session{form}{lid} == 1) {
$menu{WebGUI::URL::page('op=addInternationalMessage&lid=1')} = "Add a new message.";
}
if ($session{form}{lid} ne "new" && $session{form}{lid} ne "") {
$menu{WebGUI::URL::page('op=listInternationalMessages&lid='.$session{form}{lid})} =
WebGUI::International::get(594);
$menu{WebGUI::URL::page('op=exportTranslation&lid='.$session{form}{lid})} = WebGUI::International::get(718);
$menu{WebGUI::URL::page('op=submitTranslation&lid='.$session{form}{lid})} = WebGUI::International::get(593);
$menu{WebGUI::URL::page('op=editLanguage&lid='.$session{form}{lid})} = WebGUI::International::get(598);
$menu{WebGUI::URL::page("op=deleteLanguage&lid=".$session{form}{lid})} = WebGUI::International::get(791);
}
$menu{WebGUI::URL::page('op=listLanguages')} = WebGUI::International::get(585);
return menuWrapper($_[0],\%menu);
}
#-------------------------------------------------------------------
sub www_addInternationalMessage {
my ($output,$f);
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(10));
$output = '<h1>Add English Message</h1>';
$f = WebGUI::HTMLForm->new();
$f->hidden("lid",1);
$f->hidden("op","addInternationalMessageSave");
$f->combo("namespace",
WebGUI::SQL->buildHashRef("select namespace,namespace from international where languageId=1 order by namespace")
,"Namespace",['WebGUI']);
$f->textarea("message","Message");
$f->textarea("context","Context");
$f->submit;
$output .= $f->print;
return _submenu($output);
}
#-------------------------------------------------------------------
sub www_addInternationalMessageSave {
my ($nextId);
($nextId) = WebGUI::SQL->quickArray("select max(internationalId) from international where languageId=1
and namespace=".quote($session{form}{namespace}));
$nextId++;
my $namespace = $session{form}{namespace_new} || $session{form}{namespace};
WebGUI::SQL->write("insert into international (languageId, internationalId, namespace, message, lastUpdated,
context) values
(1,$nextId,".quote($namespace).",".quote($session{form}{message}).",".time().",
".quote($session{form}{context}).")");
return "<b>Message was added with id $nextId.</b>".www_listInternationalMessages();
}
#-------------------------------------------------------------------
sub www_deleteLanguage {
my ($output);
return WebGUI::Privilege::vitalComponent() if ($session{form}{lid} < 1000 && $session{form}{lid} > 0);
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(10));
$output .= '<h1>'.WebGUI::International::get(42).'</h1>';
$output .= WebGUI::International::get(587).'<p>';
$output .= '<div align="center"><a href="'.
WebGUI::URL::page('op=deleteLanguageConfirm&lid='.$session{form}{lid})
.'">'.WebGUI::International::get(44).'</a>';
$output .= '&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.WebGUI::URL::page('op=listLanguages').
'">'.WebGUI::International::get(45).'</a></div>';
return _submenu($output);
}
#-------------------------------------------------------------------
sub www_deleteLanguageConfirm {
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(10));
return WebGUI::Privilege::vitalComponent() if ($session{form}{lid} < 1000 && $session{form}{lid} > 0);
WebGUI::SQL->write("delete from language where languageId=".$session{form}{lid});
WebGUI::SQL->write("delete from international where languageId=".$session{form}{lid});
WebGUI::SQL->write("delete from userProfileData where fieldName='language' and fieldData=".$session{form}{lid});
$session{form}{lid} = "";
return www_listLanguages();
}
#-------------------------------------------------------------------
sub www_editInternationalMessage {
my ($output, $message, $context, $f, $language);
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(10));
($language) = WebGUI::SQL->quickArray("select language from language where languageId=".$session{form}{lid});
$output = '<h1>'.WebGUI::International::get(597).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->readOnly($session{form}{iid},WebGUI::International::get(601));
$f->hidden("lid",$session{form}{lid});
$f->hidden("status",$session{form}{status});
$f->hidden("iid",$session{form}{iid});
$f->hidden("pn",$session{form}{pn});
$f->hidden("namespace",$session{form}{namespace});
$f->hidden("op","editInternationalMessageSave");
($message) = WebGUI::SQL->quickArray("select message from international where internationalId=".$session{form}{iid}."
and namespace='".$session{form}{namespace}."' and languageId=".$session{form}{lid});
$f->textarea("message",$language,$message);
$f->submit;
($message, $context) = WebGUI::SQL->quickArray("select message,context from international where internationalId=".$session{form}{iid}."
and namespace='".$session{form}{namespace}."' and languageId=1");
$f->readOnly(WebGUI::Macro::negate($message),"English");
$f->readOnly(
-label=>"Message Context",
-value=>$context
);
$output .= $f->print;
return _submenu($output);
}
#-------------------------------------------------------------------
sub www_editInternationalMessageSave {
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(10));
if ($session{form}{status} eq "missing") {
WebGUI::SQL->write("insert into international (message,namespace,languageId,internationalId,lastUpdated)
values (".quote($session{form}{message}).",".quote($session{form}{namespace})
.",".$session{form}{lid}.",".$session{form}{iid}.", ".time().")");
} else {
WebGUI::SQL->write("update international set message=".quote($session{form}{message}).", lastUpdated="
.time()." where namespace=".quote($session{form}{namespace})."
and languageId=".$session{form}{lid}." and internationalId=".$session{form}{iid});
}
return www_listInternationalMessages();
}
#-------------------------------------------------------------------
sub www_editLanguage {
my ($output, $dir, @files, $file, %data, $f, %options);
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(10));
tie %data, 'Tie::CPHash';
$dir = $session{config}{extrasPath}.$session{os}{slash}."toolbar";
opendir (DIR,$dir) or WebGUI::ErrorHandler::warn("Can't open toolbar directory!");
@files = readdir(DIR);
foreach $file (@files) {
if ($file ne ".." && $file ne ".") {
$options{$file} = $file;
}
}
closedir(DIR);
if ($session{form}{lid} eq "new") {
$data{characterSet} = "ISO-8859-1";
$data{toolbar} = "default";
} else {
%data = WebGUI::SQL->quickHash("select * from language where languageId=".$session{form}{lid});
}
$output = '<h1>'.WebGUI::International::get(589).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->readOnly($session{form}{lid},WebGUI::International::get(590));
$f->hidden("lid",$session{form}{lid});
$f->hidden("op","editLanguageSave");
$f->text("language",WebGUI::International::get(591),$data{language});
$f->text("characterSet",WebGUI::International::get(592),$data{characterSet});
$f->select("toolbar",\%options,WebGUI::International::get(746),[$data{toolbar}]);
$f->submit;
$output .= $f->print;
return _submenu($output);
}
#-------------------------------------------------------------------
sub www_editLanguageSave {
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(10));
if ($session{form}{lid} eq "new") {
$session{form}{lid} = getNextId("languageId");
WebGUI::SQL->write("insert into language (languageId) values ($session{form}{lid})");
}
WebGUI::SQL->write("update language set language=".quote($session{form}{language}).",
characterSet=".quote($session{form}{characterSet}).", toolbar=".quote($session{form}{toolbar})."
where languageId=".$session{form}{lid});
return www_editLanguage();
}
#-------------------------------------------------------------------
sub www_exportTranslation {
$session{header}{mimetype} = 'text/plain';
return _export($session{form}{lid});
}
#-------------------------------------------------------------------
sub www_listInternationalMessages {
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(10));
my ($output, $sth, $key, $p, $status,%data, %list, $deprecated, $i, $missing, @row, $f, $outOfDate, $ok);
tie %data, 'Tie::CPHash';
%data = WebGUI::SQL->quickHash("select language from language where languageId=".$session{form}{lid});
$missing = '<b>'.WebGUI::International::get(596).'</b>';
$outOfDate = '<b>'.WebGUI::International::get(719).'</b>';
$ok = WebGUI::International::get(720);
$deprecated = WebGUI::International::get(723);
$output = '<h1>'.WebGUI::International::get(595).' ('.$data{language}.')</h1>';
WebGUI::Session::setScratch("internationalSearchId",$session{form}{internationalSearchId});
WebGUI::Session::setScratch("internationalSearchKeyword",$session{form}{internationalSearchKeyword});
WebGUI::Session::setScratch("internationalSearchNamespace",$session{form}{internationalSearchNamespace});
$f = WebGUI::HTMLForm->new(1);
$f->hidden("op","listInternationalMessages");
$f->hidden("lid",$session{form}{lid});
my $selectedNamespace = $session{scratch}{internationalSearchNamespace} || "Any";
my %namespaces;
tie %namespaces, 'Tie::IxHash';
%namespaces = (
""=>"Any",
WebGUI::SQL->buildHash("select distinct namespace,namespace from international order by namespace")
);
$f->selectList(
-name=>"internationalSearchNamespace",
-value=>[$selectedNamespace],
-options=>\%namespaces
);
$f->integer(
-name=>"internationalSearchId",
-value=>$session{scratch}{internationalSearchId},
-size=>4,
-maxLength=>4
);
$f->text(
-name=>"internationalSearchKeyword",
-value=>$session{scratch}{internationalSearchKeyword},
-size=>20
);
$f->submit("search");
$output .= $f->print;
my $search;
my $searchFlag = 0;
if ($session{scratch}{internationalSearchKeyword} ne "") {
$search = " and message like ".quote("%".$session{scratch}{internationalSearchKeyword}."%");
$searchFlag = 1;
}
if ($session{scratch}{internationalSearchNamespace} ne "") {
$search .= " and namespace=".quote($session{scratch}{internationalSearchNamespace});
$searchFlag = 1;
}
if ($session{scratch}{internationalSearchId}) {
$search .= " and internationalId=".$session{scratch}{internationalSearchId};
$searchFlag = 1;
}
$sth = WebGUI::SQL->read("select * from international where languageId=".$session{form}{lid}.$search);
while (%data = $sth->hash) {
$list{"z-".$data{namespace}."-".$data{internationalId}}{id} = $data{internationalId};
$list{"z-".$data{namespace}."-".$data{internationalId}}{namespace} = $data{namespace};
$list{"z-".$data{namespace}."-".$data{internationalId}}{message} = $data{message};
$list{"z-".$data{namespace}."-".$data{internationalId}}{lastUpdated} = $data{lastUpdated};
$list{"z-".$data{namespace}."-".$data{internationalId}}{status} = "deleted";
}
$sth->finish;
$sth = WebGUI::SQL->read("select * from international where languageId=1");
while (%data = $sth->hash) {
$key = $data{namespace}."-".$data{internationalId};
if ($searchFlag) {
if ($list{"z-".$key}) {
if ($list{"z-".$key}{lastUpdated} < $data{lastUpdated}) {
$list{"o-".$key} = $list{"z-".$key};
delete($list{"z-".$key});
$list{"o-".$key}{status} = "updated";
} else {
$list{"q-".$key} = $list{"z-".$key};
delete($list{"z-".$key});
$list{"q-".$key}{status} = "ok";
}
}
} else {
unless ($list{"z-".$key}) {
$list{"a-".$key}{namespace} = $data{namespace};
$list{"a-".$key}{id} = $data{internationalId};
$list{"a-".$key}{status} = "missing";
} else {
if ($list{"z-".$key}{lastUpdated} < $data{lastUpdated}) {
$list{"o-".$key} = $list{"z-".$key};
delete($list{"z-".$key});
$list{"o-".$key}{status} = "updated";
} else {
$list{"q-".$key} = $list{"z-".$key};
delete($list{"z-".$key});
$list{"q-".$key}{status} = "ok";
}
}
}
}
$sth->finish;
foreach $key (sort {$a cmp $b} keys %list) {
if ($list{$key}{status} eq "updated") {
$status = $outOfDate;
} elsif ($list{$key}{status} eq "missing") {
$status = $missing;
} elsif ($list{$key}{status} eq "deleted") {
$status = $deprecated;
} else {
$status = $ok;
}
$row[$i] = '<tr valign="top"><td nowrap="1">'.$status."</td><td>"
.editIcon('op=editInternationalMessage&lid='.$session{form}{lid}
.'&iid='.$list{$key}{id}.'&namespace='.$list{$key}{namespace}.'&pn='.$session{form}{pn}
."&status=".$list{$key}{status})."</td><td>".$list{$key}{namespace}."</td><td>"
.$list{$key}{id}."</td><td>".$list{$key}{message}."</td></tr>\n";
$i++;
}
$p = WebGUI::Paginator->new(WebGUI::URL::page('op=listInternationalMessages&lid='.$session{form}{lid}),100);
$p->setDataByArrayRef(\@row);
$output .= $p->getBarTraditional($session{form}{pn});
$output .= '<table style="font-size: 11px;" width="100%">';
$output .= '<tr><td class="tableHeader">'.WebGUI::International::get(434).'</td><td class="tableHeader">'.
WebGUI::International::get(575).'</td><td class="tableHeader">'.WebGUI::International::get(721)
.'</td><td class="tableHeader">'.WebGUI::International::get(722)
.'</td><td class="tableHeader" width="100%">'.WebGUI::International::get(230).'</td></tr>';
$output .= $p->getPage($session{form}{pn});
$output .= '</table>';
$output .= $p->getBarTraditional($session{form}{pn});
return _submenu(WebGUI::Macro::negate($output));
}
#-------------------------------------------------------------------
sub www_listLanguages {
my ($output, $sth, %data);
tie %data, 'Tie::CPHash';
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(10));
$output = '<h1>'.WebGUI::International::get(586).'</h1>';
$sth = WebGUI::SQL->read("select languageId,language from language where languageId<>1 order by language");
while (%data = $sth->hash) {
$output .= '<a href="'.WebGUI::URL::page("op=editLanguage&lid=".$data{languageId}).'">'.$data{language}.'<br>';
}
$sth->finish;
return _submenu($output);
}
#-------------------------------------------------------------------
sub www_submitTranslation {
my ($output);
$output .= '<h1>'.WebGUI::International::get(42).'</h1>';
$output .= WebGUI::International::get(588).'<p>';
$output .= '<div align="center"><a href="'.
WebGUI::URL::page('op=submitTranslationConfirm&lid='.$session{form}{lid})
.'">'.WebGUI::International::get(44).'</a>';
$output .= '&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.WebGUI::URL::page('op=listLanguages').
'">'.WebGUI::International::get(45).'</a></div>';
return _submenu($output);
}
#-------------------------------------------------------------------
sub www_submitTranslationConfirm {
WebGUI::Mail::send("info\@plainblack.com","International Message Submission",_export($session{form}{lid}));
return www_editLanguage();
}
1;

View file

@ -52,15 +52,15 @@ sub _reorderFields {
sub _submenu {
my (%menu);
tie %menu, 'Tie::IxHash';
$menu{WebGUI::URL::page("op=editProfileCategory")} = WebGUI::International::get(490,"WebGUI/Profile");
$menu{WebGUI::URL::page("op=editProfileField")} = WebGUI::International::get(491,"WebGUI/Profile");
$menu{WebGUI::URL::page("op=editProfileCategory")} = WebGUI::International::get(490,"WebGUI-Profile");
$menu{WebGUI::URL::page("op=editProfileField")} = WebGUI::International::get(491,"WebGUI-Profile");
if (($session{form}{op} eq "editProfileField" && $session{form}{fid} ne "new") || $session{form}{op} eq "deleteProfileField") {
$menu{WebGUI::URL::page('op=editProfileField&fid='.$session{form}{fid})} = WebGUI::International::get(787,"WebGUI/Profile");
$menu{WebGUI::URL::page('op=deleteProfileField&fid='.$session{form}{fid})} = WebGUI::International::get(788,"WebGUI/Profile");
$menu{WebGUI::URL::page('op=editProfileField&fid='.$session{form}{fid})} = WebGUI::International::get(787,"WebGUI-Profile");
$menu{WebGUI::URL::page('op=deleteProfileField&fid='.$session{form}{fid})} = WebGUI::International::get(788,"WebGUI-Profile");
}
if (($session{form}{op} eq "editProfileCategory" && $session{form}{cid} ne "new") || $session{form}{op} eq "deleteProfileCategory") {
$menu{WebGUI::URL::page('op=editProfileCategory&cid='.$session{form}{cid})} = WebGUI::International::get(789,"WebGUI/Profile");
$menu{WebGUI::URL::page('op=deleteProfileCategory&cid='.$session{form}{cid})} = WebGUI::International::get(790,"WebGUI/Profile");
$menu{WebGUI::URL::page('op=editProfileCategory&cid='.$session{form}{cid})} = WebGUI::International::get(789,"WebGUI-Profile");
$menu{WebGUI::URL::page('op=deleteProfileCategory&cid='.$session{form}{cid})} = WebGUI::International::get(790,"WebGUI-Profile");
}
$menu{WebGUI::URL::page("op=editProfileSettings")} = WebGUI::International::get(492);
$menu{WebGUI::URL::page('op=manageSettings')} = WebGUI::International::get(4);
@ -73,7 +73,7 @@ sub www_deleteProfileCategory {
my ($output);
return WebGUI::Privilege::vitalComponent() if ($session{form}{cid} < 1000);
$output = '<h1>'.WebGUI::International::get(42).'</h1>';
$output .= WebGUI::International::get(466,"WebGUI/Profile").'<p>';
$output .= WebGUI::International::get(466,"WebGUI-Profile").'<p>';
$output .= '<div align="center"><a href="'.WebGUI::URL::page('op=deleteProfileCategoryConfirm&cid='.$session{form}{cid}).
'">'.WebGUI::International::get(44).'</a>';
$output .= '&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.WebGUI::URL::page('op=editProfileSettings').'">'.
@ -97,7 +97,7 @@ sub www_deleteProfileField {
($protected) = WebGUI::SQL->quickArray("select protected from userProfileField where fieldname=".quote($session{form}{fid}));
return WebGUI::Privilege::vitalComponent() if ($protected);
$output = '<h1>'.WebGUI::International::get(42).'</h1>';
$output .= WebGUI::International::get(467,"WebGUI/Profile").'<p>';
$output .= WebGUI::International::get(467,"WebGUI-Profile").'<p>';
$output .= '<div align="center"><a href="'.WebGUI::URL::page('op=deleteProfileFieldConfirm&fid='.$session{form}{fid}).
'">'.WebGUI::International::get(44).'</a>';
$output .= '&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.WebGUI::URL::page('op=editProfileSettings').'">'.
@ -121,7 +121,7 @@ sub www_editProfileCategory {
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(3));
my ($output, $f, %data);
tie %data, 'Tie::CPHash';
$output = '<h1>'.WebGUI::International::get(468,"WebGUI/Profile").'</h1>';
$output = '<h1>'.WebGUI::International::get(468,"WebGUI-Profile").'</h1>';
$f = WebGUI::HTMLForm->new;
$f->hidden("op","editProfileCategorySave");
if ($session{form}{cid}) {
@ -134,13 +134,13 @@ sub www_editProfileCategory {
$f->text("categoryName",WebGUI::International::get(470),$data{categoryName});
$f->yesNo(
-name=>"visible",
-label=>WebGUI::International::get(473,"WebGUI/Profile"),
-label=>WebGUI::International::get(473,"WebGUI-Profile"),
-value=>$data{visible}
);
$f->yesNo(
-name=>"editable",
-value=>$data{editable},
-label=>WebGUI::International::get(897,"WebGUI/Profile")
-label=>WebGUI::International::get(897,"WebGUI-Profile")
);
$f->submit;
$output .= $f->print;
@ -171,7 +171,7 @@ sub www_editProfileField {
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(3));
my ($output, $f, %data, %hash, $key);
tie %data, 'Tie::CPHash';
$output = '<h1>'.WebGUI::International::get(471,"WebGUI/Profile").'</h1>';
$output = '<h1>'.WebGUI::International::get(471,"WebGUI-Profile").'</h1>';
$f = WebGUI::HTMLForm->new;
$f->hidden("op","editProfileFieldSave");
if ($session{form}{fid}) {
@ -185,17 +185,17 @@ sub www_editProfileField {
$f->text("fieldLabel",WebGUI::International::get(472),$data{fieldLabel});
$f->yesNo(
-name=>"visible",
-label=>WebGUI::International::get(473,"WebGUI/Profile"),
-label=>WebGUI::International::get(473,"WebGUI-Profile"),
-value=>$data{visible}
);
$f->yesNo(
-name=>"editable",
-value=>$data{editable},
-label=>WebGUI::International::get(897,"WebGUI/Profile")
-label=>WebGUI::International::get(897,"WebGUI-Profile")
);
$f->yesNo(
-name=>"required",
-label=>WebGUI::International::get(474,"WebGUI/Profile"),
-label=>WebGUI::International::get(474,"WebGUI-Profile"),
-value=>$data{required}
);
$f->fieldType(
@ -213,7 +213,7 @@ sub www_editProfileField {
$f->select(
-name=>"profileCategoryId",
-options=>\%hash,
-label=>WebGUI::International::get(489,"WebGUI/Profile"),
-label=>WebGUI::International::get(489,"WebGUI-Profile"),
-value=>[$data{profileCategoryId}]
);
$f->submit;