package WebGUI::Utility; #------------------------------------------------------------------- # WebGUI is Copyright 2001-2002 Plain Black Software. #------------------------------------------------------------------- # 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::IxHash; use WebGUI::International; use WebGUI::Session; use WebGUI::SQL; use WebGUI::URL; our @ISA = qw(Exporter); our @EXPORT = qw(&sortByColumn &sortHashDescending &sortHash &paginate &randint &round); #------------------------------------------------------------------- sub paginate { my ($pn, $i, $dataRows, $prevNextBar, $itemsPerPage, @row, $url); $itemsPerPage = $_[0]; $url = $_[1]; @row = @{$_[2]}; if ($session{form}{pn} < 1) { $pn = 0; } else { $pn = $session{form}{pn}; } for ($i=($itemsPerPage*$pn); $i<($itemsPerPage*($pn+1));$i++) { $dataRows .= $row[$i]; } if ($#row+1 > $itemsPerPage) { $prevNextBar = '
';
} else {
$output .= '
';
}
}
return $output;
}
#-------------------------------------------------------------------
sub sortHash {
my (%hash, %reversedHash, %newHash, $key);
tie %hash, "Tie::IxHash";
tie %reversedHash, "Tie::IxHash";
tie %newHash, "Tie::IxHash";
%hash = @_;
%reversedHash = reverse %hash;
foreach $key (sort {$b cmp $a} keys %reversedHash) {
$newHash{$key}=$reversedHash{$key};
}
%reversedHash = reverse %newHash;
return %reversedHash;
}
#-------------------------------------------------------------------
sub sortHashDescending {
my (%hash, %reversedHash, %newHash, $key);
tie %hash, "Tie::IxHash";
tie %reversedHash, "Tie::IxHash";
tie %newHash, "Tie::IxHash";
%hash = @_;
%reversedHash = reverse %hash;
foreach $key (sort {$a cmp $b} keys %reversedHash) {
$newHash{$key}=$reversedHash{$key};
}
%reversedHash = reverse %newHash;
return %reversedHash;
}
1;