WebGUI 1.0.0 release

This commit is contained in:
JT Smith 2001-09-07 02:35:00 +00:00
parent 597b9ff2b0
commit 655ba6d283
40 changed files with 606 additions and 267 deletions

View file

@ -1,650 +0,0 @@
package WebGUI::Config;
# This package was originally Data::Config
use strict;
use Carp;
use FileHandle;
use vars qw($CLASS $VERSION);
$CLASS = 'WebGUI::Config';
$VERSION = '0.8.3';
=head1 NAME
Data::Config - Module that can read easy-to-use configuration files
=head1 SYNOPSIS
Lets say you have a file F<mail.conf>
name = John Doe
email = doe@somewhere.net
server = mail.somewhere.net
signature = -
John Doe
--
Visit my homepage at http://www.somewhere.net/~doe/
.
You can read it using the following program:
use Data::Source;
my $mailconf = new Data::Source 'mail.conf';
and you can for example print the signature:
print $mailconf->param('signature');
=head1 DESCRIPTION
This module has been writen in order to provide an easy way to read
simple configuration files. The format of these configuration files is
itself extremely easy to understand, so that it can be used even by
non-tech people (I hope!).
One of the reason I wrote this module is that I wanted a very easy way
to feed data to HTML::Template-based scripts. Therefore, the API of
Data::Config is compatible with HTML::Template, and you can write
programs as simple as:
use strict;
use Data::Config;
use HTML::template;
my $source = new Data::Config 'file.src';
my $tmpl = new HTML::Template type => 'filename',
source => 'file.tmpl', associate => $source;
print $tmpl->output;
=head2 Syntax
The syntax of the configuration files is pretty simple. To affect a
value to a parameter, just write:
param = value of param
The parameter C<param> will have the value "value of param".
You can also give multi-lines values this way:
text = -
Perl is a language optimized for scanning arbitrary text files,
extracting information from those text files, and printing
reports based on that information. It's also a good language
for many system management tasks. The language is intended to
be practical (easy to use, efficient, complete) rather than
beautiful (tiny, elegant, minimal).
[from perl(1)]
.
Think of this as a "Unix-inspired" syntax. Instead of giving the value,
you write '-' to mean "the value will follow" (in Unix, this means the
data will come from standard input). To end the multi-lines value, you
simply put a single dot '.' on a line (as in Unix mail, but it needn't
be on the first column).
If you need to write several identical records, you can use lists.
The syntax is:
list_name {
# affectations
}
Example: a version history
## that's the version history of Data::Config :)
history {
date = 2000.10.10
vers = 0.7.0
text = First fully functional release.
}
history {
date = 2000.11.04
vers = 0.7.1
text = -
Minor change in the internal structure: options
are now grouped.
.
}
history {
date = 2000.11.05
vers = 0.8.0
text = -
Code cleanup (mainly auto-generation of the
options accessors).
Added list support.
.
}
Note that currently, there must be only one item on each line.
This means you can't write:
line { param = value }
but instead
line {
param = value
}
I think that's not a big deal.
Also note that you can't nest lists.
You can put some comments in your file. If a line begins with a
sharp sign '#', it will be ignored.
=head2 Objects Options
If the default symbols used in the configuration file syntax doesn't
fit your needs, you can change them using the following methods.
=over 4
=item affectation_symbol
Use this method to change the affectation symbol. Default is '='.
=item multiline_begin_symbol
Use this method to change the multiline begin symbol. Default is '-'.
=item multiline_end_symbol
Use this method to change the multiline end symbol. Default is '.'.
=item comment_line_symbol
Use this method to change the comment symbol. Default is '#'.
=item list_begin_symbol
Use this method to change the list begin symbol. Default is '{'.
=item list_end_symbol
Use this method to change the list end symbol. Default is '}'.
=item case_sensitive
Use this method to change the case behaviour. Defaults is 1 (case sensitive).
=back
=head2 Methods
=over 8
=item new
This method creates a new object. You can give an optional parameter, in
which case the C<read_source()> method is called with that parameter.
=item read_source ( FILENAME )
=item read_source ( FILEHANDLE )
This method reads the content of the given file and stores the parameters
values in the object. The argument can be either a filename or a filehandle.
This is useful if you want to store your parameters in your program:
use Data::Source;
my $conf = new Data::Source \*DATA;
$conf->param(-debug => 1); ## set debug on
if($conf->param('debug')) {
print "current options:\n";
print $conf->dump_param(-prefix => ' ');
}
# ...
__END__
## default values
verbose = 1
debug = 0
die_on_errors = 0
Note that you can call the C<read_source()> method several times if you want
to merge the settings from differents configuration files.
=item param
This is the general purpose manipulating method. It can used to get or set
the value of the parameters of an object.
1) Return a list of the parameters:
@params = $conf->param;
2) Return the value of a parameter:
print $conf->param('debug');
3) Return the values of a number of parameters:
@dbg = $conf->param(qw(debug verbose));
4) Set the value of a parameter:
## using CGI.pm-like syntax
$conf->param(-debug => 0);
## using a hashref
$conf->param({ debug => 0 });
5) Set the values of a number of parameters
## using CGI.pm-like syntax
$conf->param(
-warn_non_existant => 1,
-mangle => 0
);
## using a hashref
$conf->param(
{
warn_non_existant => 1,
mangle => 0
}
);
=item all_parameters
This method returns the list of the parameters of an object.
=item delete ( LIST )
This method deletes the given parameters.
=item delete_all
This method deletes all the parameters.
=item clear
This method sets the given parameters to undef.
=item clear_params
This method sets all the parameters to undef.
=item dump_param ( OPTIONS )
This method returns a dump of the parameters as a string. It can be used
to simply print them out, or to save them to a configuration file.
B<Options>
=over 4
=item *
prefix - If you set this option to a string, it will be printed before printing
each parameter.
=item *
suffix - If you set this option to a string, it will be printed after printing
each parameter.
=back
=back
=head1 VERSION HISTORY
=over 4
=item v0.8.3, Thursday, November 15, 2000
Added the method C<clear()>.
=item v0.8.2, Saturday, November 11, 2000
Added a destructor method. This was needed because of a strange behaviour
in MacPerl 5.2.0r4.
=item v0.8.1, Thursday, November 8, 2000
Minor bug corrected: empty or undefined parameters are not added.
Bug corrected: syntaxic symbol are now escaped through quotemeta().
=item v0.8.0, Sunday, November 5, 2000
Code cleanup (mainly auto-generation of the options accessors).
Added list support.
=item v0.7.1, Saturday, November 4, 2000
Minor change in the internal structure: options are now grouped.
=item v0.7.0, Tuesday, October 10, 2000
First fully functional release.
=back
=head1 AUTHOR
SE<eacute>bastien Aperghis-Tramoni <madingue@resus.univ-mrs.fr>
=head1 COPYRIGHT
Data::Config is Copyright (C)2000 SE<eacute>bastien Aperghis-Tramoni.
This program is free software. You can redistribute it and/or modify it
under the terms of either the Perl Artistic License or the GNU General
Public License, version 2 or later.
=cut
my @base = (
options => {
comment_line_symbol => '#',
affectation_symbol => '=',
multiline_begin_symbol => '-',
multiline_end_symbol => '.',
list_begin_symbol => '{',
list_end_symbol => '}',
case_sensitive => 1
},
state => { },
param => { }
);
## set the accessors for the object options
for my $option (keys %{$base[1]}) {
eval qq| sub $option { _get_set_option(shift, '$option', shift) } |;
warn "[$CLASS] Initialisation error: $@ " if $@;
}
#
# new()
# ---
sub new {
my $class = shift;
my $self = bless { @base }, $class;
$self->read_source(shift) if @_;
return $self;
}
#
# DESTROY()
# -------
sub DESTROY {
my $self = shift;
$self->clear_params;
$self->delete_all;
}
#
# _get_set_option()
# ---------------
sub _get_set_option {
my $self = shift;
my $option = shift;
my $value = shift;
carp "[$CLASS] Uknown option '$option' " unless exists $self->{options}{$option};
if(defined $value) {
($value, $self->{options}{$option}) = ($self->{options}{$option}, $value);
return $value
} else {
return $self->{options}{$option}
}
}
#
# read_source()
# -----------
sub read_source {
my $self = shift;
my $fh = _file_or_handle(shift);
my $aff_sym = $self->affectation_symbol;
my $multiline = $self->multiline_begin_symbol;
my $multi_end = $self->multiline_end_symbol;
my $list = $self->list_begin_symbol;
my $list_end = $self->list_end_symbol;
local $_;
while(defined($_ = <$fh>)) {
next if /^\s*$/; ## skip empty lines
next if /^\s*#/; ## skip comments
chomp;
if(/^\s*(\w+)\s*\Q${list}\E$/) {
$self->{state}{current_list} = $1;
$self->{state}{current_stack} = [];
next
}
if(/^\s*\Q${list_end}\E\s*$/) {
push @{$self->{'param'}{$self->{state}{current_list}}}, { @{$self->{state}{current_stack}} };
$self->{state}{current_list} = 0;
$self->{state}{current_stack} = [];
next
}
my($field,$value) = (/^\s*(\w+)\s*\Q${aff_sym}\E\s*(.*)$/);
if($value =~ /^\s*${multiline}\s*$/) {
$value = '';
$_ = <$fh>;
while(not /^\s*\Q${multi_end}\E\s*$/) {
$value .= $_;
$_ = <$fh>;
}
}
$self->param({ $field => $value });
}
}
#
# _file_or_handle()
# ---------------
sub _file_or_handle {
my $file = shift;
if(not ref $file) {
my $fh = new FileHandle $file;
croak "[$CLASS] Can't open file '$file': $! " unless defined $fh;
return $fh
}
return $file
}
#
# param()
# -----
sub param {
my $self = shift;
return $self->all_parameters unless @_;
my $args = _parse_args(@_);
my @retlist = (); ## return list
## get the value of the desired parameters
for my $arg (@{$args->{'get'}}) {
carp("[$CLASS] Parameter '$arg' does not exist ") and next
if not exists $self->{'param'}{_case_($self, $arg)};
push @retlist, $self->{'param'}{_case_($self, $arg)}
}
## set the names parameters to new values
my $current_list = $self->{'state'}{current_list};
my @arg_list = keys %{$args->{'set'}};
if($current_list) {
unless(exists $self->{'param'}{$current_list}) {
$self->{'param'}{$current_list} = []
}
for my $arg (@arg_list) {
push @{$self->{'state'}{'current_stack'}}, _case_($self, $arg) => $args->{'set'}{$arg}
}
} else {
for my $arg (@arg_list) {
$self->{'param'}{_case_($self, $arg)} = $args->{'set'}{$arg}
}
}
return wantarray ? @retlist : $retlist[0]
}
#
# _case_()
# ------
sub _case_ {
my $self = shift;
my $param = shift;
return ($self->case_sensitive ? $param : lc $param)
}
#
# _parse_args()
# -----------
sub _parse_args {
my %args = ( get => [], set => {} );
while(my $arg = shift) {
if(my $ref_type = ref $arg) {
## setting multiples parameters using a hashref
if($ref_type eq 'HASH') {
local $_;
for (keys %$arg) {
$args{'set'}{$_} = $arg->{$_} if $_
}
} else {
carp "[$CLASS] Bad ref $ref_type; ignoring it ";
next
}
} else {
## setting a parameter to a new value
if(substr($arg, 0, 1) eq '-') {
$arg = substr($arg, 1);
my $val = shift;
carp("[$CLASS] Undefined value for parameter '$arg' ") and next
if not defined $val;
$args{'set'}{$arg} = $val if $arg
## getting the value of a parameter
} else {
push @{$args{'get'}}, $arg
}
}
}
return \%args
}
#
# all_parameters()
# --------------
sub all_parameters {
my $self = shift;
return keys %{$self->{'param'}}
}
#
# delete()
# ------
sub delete {
my $self = shift;
for my $param (@_) {
carp("[$CLASS] Parameter '$param' does not exist ") and next
if not exists $self->{'param'}{_case_($self, $param)};
delete $self->{'param'}{_case_($self, $param)}
}
}
#
# delete_all()
# ----------
sub delete_all {
my $self = shift;
$self->delete($self->all_parameters)
}
#
# clear()
# -----
sub clear {
my $self = shift;
for my $param (@_) {
$self->param({$param => ''})
}
}
#
# clear_params()
# ------------
sub clear_params {
my $self = shift;
for my $param ($self->all_parameters) {
$self->param({$param => ''})
}
}
#
# dump_param()
# ----------
sub dump_param {
my $self = shift;
my $args = _parse_args(@_);
my $prefix = $args->{'set'}{'prefix'} || '';
my $suffix = $args->{'set'}{'suffix'} || '';
my $str = '';
for my $param (sort $self->all_parameters) {
next unless $param;
## multi-line value ?
my $multiline = 1 if $self->param($param) =~ /\n|\r/;
$str .= join '', $prefix, $param, ' ', $self->affectation_symbol, ' ',
($multiline ? $self->multiline_begin_symbol . $/ : ''),
$self->param($param),
($multiline ? $self->multiline_end_symbol . $/ : ''),
$suffix, $/;
}
return $str
}
1;

View file

@ -1,4 +1,4 @@
package ErrorHandler;
package WebGUI::ErrorHandler;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001 Plain Black Software.
@ -15,25 +15,65 @@ use WebGUI::Session;
#-------------------------------------------------------------------
sub fatalError {
my ($key, $logfile);
print Session::httpHeader();
$logfile = FileHandle->new(">".$session{config}{logfile}) or die "Can't open log file.";
print $logfile localtime(time);
print "<h1>WebGUI Fatal Error</h1>Something unexpected happened that caused this system to fault. Please send this message to ";#.$session{setting}{adminEmail}."<p>";
my ($key, $log, $cgi, $logfile, $config);
if (exists $session{cgi}) {
$cgi = $session{cgi};
} else {
use CGI;
$cgi = CGI->new;
}
print $cgi->header;
if (exists $session{config}{logfile}) {
$logfile = $session{config}{logfile};
} else {
use Data::Config;
$config = new Data::Config '../etc/WebGUI.conf';
$logfile = $config->param('logfile');
}
$log = FileHandle->new(">>$logfile") or die "Can't open log file.";
print "<h1>WebGUI Fatal Error</h1>Something unexpected happened that caused this system to fault.<p>";
print $0." at ".localtime(time)." reported:<br>";
print $log localtime(time)." ".$0." ".$_[0]."\n";
print $_[0];
print "<p><h3>Caller</h3><table border=1><tr><td valign=top>";
print "<b>Level 1</b><br>".join("<br>",caller(1));
print $log "\t".join(",",caller(1))."\n";
print "</td><td valign=top>"."<b>Level 2</b><br>".join("<br>",caller(2));
print $log "\t".join(",",caller(2))."\n";
print "</td><td valign=top>"."<b>Level 3</b><br>".join("<br>",caller(3));
print "</td><td valign=top>"."<b>Level 4</b><br>".join("<br>",caller(4));
print "</td></tr></table><p><h3>Form Variables</h3>";
#foreach $key (keys %{$session(form}}) {
# print $key." = ".$session{form}{$key}."<br>";
#}
$logfile->close();
print $log "\t".join(",",caller(3))."\n";
print "</td></tr></table>";
print "<h3>Form Variables</h3>";
print $log "\t";
if (exists $session{form}) {
foreach $key (keys %{$session{form}}) {
print $key." = ".$session{form}{$key}."<br>";
print $log $key."=".$session{form}{$key}." ";
}
print $log "\n";
} else {
print "Cannot retrieve session information.";
print $log "Session not accessible for form variable dump.\n";
}
print $log "\n";
$log->close;
exit;
}
#-------------------------------------------------------------------
sub warn {
my ($log, $logfile, $config);
if (exists $session{config}{logfile}) {
$logfile = $session{config}{logfile};
} else {
use Data::Config;
$config = new Data::Config '../etc/WebGUI.conf';
$logfile = $config->param('logfile');
}
$log = FileHandle->new(">>".$logfile) or fatalError("Can't open log file for warning.");
print $log localtime(time)." ".$0." WARNING: ".$_[0]."\n";
$log->close;
}
1;

View file

@ -19,6 +19,7 @@ use WebGUI::Operation::Page;
use WebGUI::Operation::Settings;
use WebGUI::Operation::Style;
use WebGUI::Operation::Submission;
use WebGUI::Operation::Trash;
use WebGUI::Operation::User;

View file

@ -119,7 +119,11 @@ sub www_displayAccount {
$output .= '</form> ';
$output .= '<div class="accountOptions"><ul>';
if (WebGUI::Privilege::isInGroup(3) || WebGUI::Privilege::isInGroup(4)) {
$output .= '<li><a href="'.$session{page}{url}.'?op=switchOnAdmin">Turn admin on.</a>';
if ($session{var}{adminOn}) {
$output .= '<li><a href="'.$session{page}{url}.'?op=switchOffAdmin">Turn admin off.</a>';
} else {
$output .= '<li><a href="'.$session{page}{url}.'?op=switchOnAdmin">Turn admin on.</a>';
}
}
$output .= '<li><a href="'.$session{page}{url}.'?op=logout">Logout.</a><li><a href="'.$session{page}{url}.'?op=deactivateAccount">Please deactivate my account permanently.</a></ul></div>';
} else {

View file

@ -115,33 +115,37 @@ sub www_editGroupSave {
#-------------------------------------------------------------------
sub www_listGroups {
my ($output, $sth, @data, $totalItems, $currentPage, $itemsPerPage);
my ($output, $pn, $sth, @data, @row, $i, $itemsPerPage);
if (WebGUI::Privilege::isInGroup(3)) {
$itemsPerPage = 50;
if ($session{form}{pageNumber} < 1) {
$currentPage = 1;
} else {
$currentPage = $session{form}{pageNumber};
}
($totalItems) = WebGUI::SQL->quickArray("select count(*) from groups where groupName<>'Reserved'",$session{dbh});
$output = '<a href="'.$session{page}{url}.'?op=viewHelp&hid=10"><img src="'.$session{setting}{lib}.'/help.gif" border="0" align="right"></a><h1>Groups</h1>';
$output .= '<div align="center"><a href="'.$session{page}{url}.'?op=addGroup">Add a new group.</a></div>';
$output .= '<table border=1 cellpadding=5 cellspacing=0 align="center">';
$sth = WebGUI::SQL->read("select groupId,groupName,description from groups where groupName<>'Reserved' order by groupName limit ".(($currentPage*$itemsPerPage)-$itemsPerPage).",".$itemsPerPage,$session{dbh});
$sth = WebGUI::SQL->read("select groupId,groupName,description from groups where groupName<>'Reserved' order by groupName",$session{dbh});
while (@data = $sth->array) {
$output .= '<tr><td valign="top"><a href="'.$session{page}{url}.'?op=deleteGroup&gid='.$data[0].'"><img src="'.$session{setting}{lib}.'/delete.gif" border=0></a><a href="'.$session{page}{url}.'?op=editGroup&gid='.$data[0].'"><img src="'.$session{setting}{lib}.'/edit.gif" border=0></a></td>';
$output .= '<td valign="top">'.$data[1].'</td>';
$output .= '<td valign="top">'.$data[2].'</td></tr>';
$row[$i] = '<tr><td valign="top"><a href="'.$session{page}{url}.'?op=deleteGroup&gid='.$data[0].'"><img src="'.$session{setting}{lib}.'/delete.gif" border=0></a><a href="'.$session{page}{url}.'?op=editGroup&gid='.$data[0].'"><img src="'.$session{setting}{lib}.'/edit.gif" border=0></a></td>';
$row[$i] .= '<td valign="top">'.$data[1].'</td>';
$row[$i] .= '<td valign="top">'.$data[2].'</td></tr>';
$i++;
}
$output .= '</table><div class="pagination">';
if ($currentPage > 1) {
$output .= '<a href="'.$session{page}{url}.'?op=listGroups&pageNumber='.($currentPage-1).'">&laquo;Previous Page</a>';
if ($session{form}{pn} < 1) {
$pn = 0;
} else {
$pn = $session{form}{pn};
}
for ($i=($itemsPerPage*$pn); $i<($itemsPerPage*($pn+1));$i++) {
$output .= $row[$i];
}
$output .= '</table>';
$output .= '<div class="pagination">';
if ($pn > 0) {
$output .= '<a href="'.$session{page}{url}.'?pn='.($pn-1).'&op=listGroups">&laquo;Previous Page</a>';
} else {
$output .= '&laquo;Previous Page';
}
$output .= ' &middot; ';
if ($currentPage < round($totalItems/$itemsPerPage)) {
$output .= '<a href="'.$session{page}{url}.'?op=listGroups&pageNumber='.($currentPage+1).'">Next Page&raquo;</a>';
if ($pn < round($#row/$itemsPerPage)) {
$output .= '<a href="'.$session{page}{url}.'?pn='.($pn+1).'&op=listGroups">Next Page&raquo;</a>';
} else {
$output .= 'Next Page&raquo;';
}

View file

@ -40,7 +40,7 @@ sub www_editSettings {
$output .= '<tr><td></td><td>'.WebGUI::Form::submit("save").'</td></tr>';
$output .= '</table>';
$output .= '</form> ';
$output .= '<hr size=1>Build Version: '.$session{wg}{version}.'<br>Release Date: '.$session{wg}{date};
$output .= '<hr size=1>Build Version: '.$WebGUI::VERSION;
} else {
$output = WebGUI::Privilege::insufficient();
}

View file

@ -112,32 +112,36 @@ sub www_editStyleSave {
#-------------------------------------------------------------------
sub www_listStyles {
my ($output, $sth, @data, $totalItems, $currentPage, $itemsPerPage);
my ($output, $pn, $sth, @data, @row, $i, $itemsPerPage);
if (WebGUI::Privilege::isInGroup(3)) {
$itemsPerPage = 50;
if ($session{form}{pageNumber} < 1) {
$currentPage = 1;
} else {
$currentPage = $session{form}{pageNumber};
}
($totalItems) = WebGUI::SQL->quickArray("select count(*) from style where name<>'Reserved'",$session{dbh});
$output = '<a href="'.$session{page}{url}.'?op=viewHelp&hid=9"><img src="'.$session{setting}{lib}.'/help.gif" border="0" align="right"></a><h1>Styles</h1>';
$output .= '<div align="center"><a href="'.$session{page}{url}.'?op=addStyle">Add a new style.</a></div>';
$output .= '<table border=1 cellpadding=5 cellspacing=0 align="center">';
$sth = WebGUI::SQL->read("select styleId,name from style where name<>'Reserved' order by name limit ".(($currentPage*$itemsPerPage)-$itemsPerPage).",".$itemsPerPage,$session{dbh});
$sth = WebGUI::SQL->read("select styleId,name from style where name<>'Reserved' order by name",$session{dbh});
while (@data = $sth->array) {
$output .= '<tr><td valign="top"><a href="'.$session{page}{url}.'?op=deleteStyle&sid='.$data[0].'"><img src="'.$session{setting}{lib}.'/delete.gif" border=0></a><a href="'.$session{page}{url}.'?op=editStyle&sid='.$data[0].'"><img src="'.$session{setting}{lib}.'/edit.gif" border=0></a></td>';
$output .= '<td valign="top">'.$data[1].'</td>';
$row[$i] = '<tr><td valign="top"><a href="'.$session{page}{url}.'?op=deleteStyle&sid='.$data[0].'"><img src="'.$session{setting}{lib}.'/delete.gif" border=0></a><a href="'.$session{page}{url}.'?op=editStyle&sid='.$data[0].'"><img src="'.$session{setting}{lib}.'/edit.gif" border=0></a></td>';
$row[$i] .= '<td valign="top">'.$data[1].'</td></tr>';
$i++;
}
$output .= '</table><div class="pagination">';
if ($currentPage > 1) {
$output .= '<a href="'.$session{page}{url}.'?op=listGroups&pageNumber='.($currentPage-1).'">&laquo;Previous Page</a>';
if ($session{form}{pn} < 1) {
$pn = 0;
} else {
$pn = $session{form}{pn};
}
for ($i=($itemsPerPage*$pn); $i<($itemsPerPage*($pn+1));$i++) {
$output .= $row[$i];
}
$output .= '</table>';
$output .= '<div class="pagination">';
if ($pn > 0) {
$output .= '<a href="'.$session{page}{url}.'?pn='.($pn-1).'&op=listStyles">&laquo;Previous Page</a>';
} else {
$output .= '&laquo;Previous Page';
}
$output .= ' &middot; ';
if ($currentPage < round($totalItems/$itemsPerPage)) {
$output .= '<a href="'.$session{page}{url}.'?op=listGroups&pageNumber='.($currentPage+1).'">Next Page&raquo;</a>';
if ($pn < round($#row/$itemsPerPage)) {
$output .= '<a href="'.$session{page}{url}.'?pn='.($pn+1).'&op=listStyles">Next Page&raquo;</a>';
} else {
$output .= 'Next Page&raquo;';
}

View file

@ -0,0 +1,71 @@
package WebGUI::Operation::Trash;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001 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 qw(vars subs);
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Utility;
our @ISA = qw(Exporter);
our @EXPORT = qw(&www_purgeTrash &www_purgeTrashConfirm);
#-------------------------------------------------------------------
sub _purgeWidgets {
my ($b, $widgetId, $widgetType, $func);
$b = WebGUI::SQL->read("select widgetId, widgetType from widget where pageId=$_[0]",$session{dbh});
while (($widgetId,$widgetType) = $b->array) {
$func = "WebGUI::Widget::".$widgetType."::purge";
&$func($widgetId,$session{dbh});
}
$b->finish;
}
#-------------------------------------------------------------------
sub _recursePageTree {
my ($a, $pageId);
$a = WebGUI::SQL->read("select pageId from page where parentId=$_[0]",$session{dbh});
while (($pageId) = $a->array) {
_recursePageTree($pageId);
_purgeWidgets($pageId);
WebGUI::SQL->write("delete from page where pageId=$pageId",$session{dbh});
}
$a->finish;
}
#-------------------------------------------------------------------
sub www_purgeTrash {
my ($output);
if (WebGUI::Privilege::isInGroup(3)) {
$output = '<h1>Please Confirm</h1>';
$output .= 'Are you certain that you wish to purge all the pages and widgets in the trash?<p>';
$output .= '<div align="center"><a href="'.$session{page}{url}.'?op=purgeTrashConfirm">Yes, I\'m sure.</a>';
$output .= '&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.$session{page}{url}.'">No, I made a mistake.</a></div>';
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_purgeTrashConfirm {
if (WebGUI::Privilege::isInGroup(3)) {
_recursePageTree(3);
_purgeWidgets(3);
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
1;

View file

@ -138,38 +138,42 @@ sub www_editUserSave {
#-------------------------------------------------------------------
sub www_listUsers {
my ($output, $sth, @data, $totalItems, $currentPage, $itemsPerPage);
my ($output, $sth, @data, @row, $pn, $i, $itemsPerPage);
if (WebGUI::Privilege::isInGroup(3)) {
$itemsPerPage = 50;
if ($session{form}{pageNumber} < 1) {
$currentPage = 1;
} else {
$currentPage = $session{form}{pageNumber};
}
($totalItems) = WebGUI::SQL->quickArray("select count(*) from user where username<>'Reserved'",$session{dbh});
$output = '<a href="'.$session{page}{url}.'?op=viewHelp&hid=8"><img src="'.$session{setting}{lib}.'/help.gif" border="0" align="right"></a><h1>Users</h1>';
$output .= '<div align="center"><a href="'.$session{page}{url}.'?op=addUser">Add a new user.</a></div>';
$output .= '<table border=1 cellpadding=5 cellspacing=0 align="center">';
$sth = WebGUI::SQL->read("select userId,username,email from user where username<>'Reserved' order by username limit ".(($currentPage*$itemsPerPage)-$itemsPerPage).",".$itemsPerPage,$session{dbh});
$sth = WebGUI::SQL->read("select userId,username,email from user where username<>'Reserved' order by username",$session{dbh});
while (@data = $sth->array) {
$output .= '<tr><td><a href="'.$session{page}{url}.'?op=deleteUser&uid='.$data[0].'"><img src="'.$session{setting}{lib}.'/delete.gif" border=0></a><a href="'.$session{page}{url}.'?op=editUser&uid='.$data[0].'"><img src="'.$session{setting}{lib}.'/edit.gif" border=0></a></td>';
#$output .= '<td><a href="'.$session{page}{url}.'?op=viewUserProfile&uid='.$data[0].'">'.$data[1].'</a></td>';
$output .= '<td>'.$data[1].'</td>';
$output .= '<td><a href="mailto:'.$data[2].'">'.$data[2].'</a></td></tr>';
$row[$i] = '<tr><td><a href="'.$session{page}{url}.'?op=deleteUser&uid='.$data[0].'"><img src="'.$session{setting}{lib}.'/delete.gif" border=0></a><a href="'.$session{page}{url}.'?op=editUser&uid='.$data[0].'"><img src="'.$session{setting}{lib}.'/edit.gif" border=0></a></td>';
#$row[$i] .= '<td><a href="'.$session{page}{url}.'?op=viewUserProfile&uid='.$data[0].'">'.$data[1].'</a></td>';
$row[$i] .= '<td>'.$data[1].'</td>';
$row[$i] .= '<td><a href="mailto:'.$data[2].'">'.$data[2].'</a></td></tr>';
$i++;
}
$output .= '</table><div class="pagination">';
if ($currentPage > 1) {
$output .= '<a href="'.$session{page}{url}.'?op=listUsers&pageNumber='.($currentPage-1).'">&laquo;Previous Page</a>';
} else {
$output .= '&laquo;Previous Page';
}
$output .= ' &middot; ';
if ($currentPage < round($totalItems/$itemsPerPage)) {
$output .= '<a href="'.$session{page}{url}.'?op=listUsers&pageNumber='.($currentPage+1).'">Next Page&raquo;</a>';
} else {
$output .= 'Next Page&raquo;';
}
$output .= '</div>';
if ($session{form}{pn} < 1) {
$pn = 0;
} else {
$pn = $session{form}{pn};
}
for ($i=($itemsPerPage*$pn); $i<($itemsPerPage*($pn+1));$i++) {
$output .= $row[$i];
}
$output .= '</table>';
$output .= '<div class="pagination">';
if ($pn > 0) {
$output .= '<a href="'.$session{page}{url}.'?pn='.($pn-1).'&op=listUsers">&laquo;Previous Page</a>';
} else {
$output .= '&laquo;Previous Page';
}
$output .= ' &middot; ';
if ($pn < round($#row/$itemsPerPage)) {
$output .= '<a href="'.$session{page}{url}.'?pn='.($pn+1).'&op=listUsers">Next Page&raquo;</a>';
} else {
$output .= 'Next Page&raquo;';
}
$output .= '</div>';
return $output;
} else {
return WebGUI::Privilege::insufficient();

View file

@ -65,7 +65,7 @@ sub isInGroup {
}
($result) = WebGUI::SQL->quickArray("select count(*) from groupings where groupId='$gid' && userId='$uid'",$session{dbh});
if ($result < 1 && $gid == 1) { # registered users can
isInGroup(2, $uid); # do anything visitors
$result = isInGroup(2, $uid); # do anything visitors
} # can do
return $result;
}

View file

@ -14,6 +14,7 @@ use CGI::Carp qw(fatalsToBrowser);
use DBI;
use strict;
use Tie::IxHash;
use WebGUI::ErrorHandler;
# Note: This class is really not necessary, I just decided to wrapper DBI in case
# I wanted to change to some other DB connector in the future. Also, it shorthands
@ -21,7 +22,7 @@ use Tie::IxHash;
#-------------------------------------------------------------------
sub array {
return $_[0]->{_sth}->fetchrow_array() or croak DBI->errstr;
return $_[0]->{_sth}->fetchrow_array() or WebGUI::ErrorHandler::fatalError(DBI->errstr);
}
#-------------------------------------------------------------------
@ -56,7 +57,7 @@ sub finish {
#-------------------------------------------------------------------
sub hash {
return $_[0]->{_sth}->fetchrow_hashref() or croak DBI->errstr;
return $_[0]->{_sth}->fetchrow_hashref() or WebGUI::ErrorHandler::fatalError(DBI->errstr);
}
#-------------------------------------------------------------------
@ -65,8 +66,8 @@ sub new {
$class = shift;
$sql = shift;
$dbh = shift;
$sth = $dbh->prepare($sql) or croak "Couldn't prepare statement: ".$sql." : ". DBI->errstr;
$sth->execute or croak "Couldn't execute statement: ".$sql." : ". DBI->errstr;
$sth = $dbh->prepare($sql) or WebGUI::ErrorHandler::fatalError("Couldn't prepare statement: ".$sql." : ". DBI->errstr);
$sth->execute or WebGUI::ErrorHandler::fatalError("Couldn't execute statement: ".$sql." : ". DBI->errstr);
bless ({_sth => $sth}, $class);
}
@ -97,9 +98,9 @@ sub read {
#-------------------------------------------------------------------
sub write {
$_[2]->do($_[1]) or croak "Couldn't prepare statement: ".$_[1]." : ". DBI->errstr;
$_[2]->do($_[1]) or WebGUI::ErrorHandler::fatalError("Couldn't prepare statement: ".$_[1]." : ". DBI->errstr);
}
1;

View file

@ -14,7 +14,7 @@ use CGI;
use DBI;
use Exporter;
use strict;
use WebGUI::Config;
use Data::Config;
use WebGUI::SQL;
our @ISA = qw(Exporter);
@ -93,9 +93,8 @@ sub httpRedirect {
#-------------------------------------------------------------------
sub open {
my ($key, %WebGUI, %CONFIG, %VARS, %PAGE, %FORM, $query, %COOKIES, $config, %USER, %SETTINGS, $dbh);
%WebGUI = (version=>"0.12.0", date=>"2001-08-26");
$config = new WebGUI::Config '../etc/WebGUI.conf';
my ($key, %CONFIG, %VARS, %PAGE, %FORM, $query, %COOKIES, $config, %USER, %SETTINGS, $dbh);
$config = new Data::Config '../etc/WebGUI.conf';
foreach ($config->param) {
$CONFIG{$_} = $config->param($_);
}
@ -124,7 +123,6 @@ sub open {
page => \%PAGE, # variables related to the current page
header => {}, # settings to be passed back through the http header
dbh => $dbh, # interface to the default WebGUI database
wg => \%WebGUI # WebGUI internal settings
);
}

View file

@ -19,7 +19,7 @@ use WebGUI::SQL;
use WebGUI::Utility;
our @ISA = qw(Exporter);
our @EXPORT = qw(&www_jumpDown &www_jumpUp &update &www_moveUp &www_moveDown &www_delete &www_deleteConfirm &www_cut &create &www_paste);
our @EXPORT = qw(&purgeWidget &www_jumpDown &www_jumpUp &update &www_moveUp &www_moveDown &www_delete &www_deleteConfirm &www_cut &create &www_paste);
#-------------------------------------------------------------------
sub _reorderWidgets {
@ -46,6 +46,11 @@ sub update {
WebGUI::SQL->write("update widget set title=".quote($session{form}{title}).", displayTitle='$session{form}{displayTitle}', description=".quote($session{form}{description}).", processMacros='$session{form}{processMacros}', lastEdited=now(), editedBy='$session{user}{userId}' where widgetId=$session{form}{wid}",$session{dbh});
}
#-------------------------------------------------------------------
sub purgeWidget {
WebGUI::SQL->write("delete from widget where widgetId=$_[0]",$_[1]);
}
#-------------------------------------------------------------------
sub www_cut {
if (WebGUI::Privilege::canEditPage()) {

View file

@ -18,6 +18,12 @@ use WebGUI::SQL;
use WebGUI::Utility;
use WebGUI::Widget;
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from Article where widgetId=$_[0]",$_[1]);
purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return "Article";
@ -41,6 +47,7 @@ sub www_add {
$output .= '<tr><td class="formDescription">Link Title</td><td>'.WebGUI::Form::text("linkTitle",20,30).'</td></tr>';
$output .= '<tr><td class="formDescription">Link URL</td><td>'.WebGUI::Form::text("linkURL",20,2048).'</td></tr>';
$output .= '<tr><td class="formDescription">Attachment</td><td>'.WebGUI::Form::file("attachment").'</td></tr>';
$output .= '<tr><td class="formDescription">Convert Carriage Returns</td><td>'.WebGUI::Form::checkbox("convertCarriageReturns",1).' <span style="font-size: 8pt;">(check if you\'re not adding &lt;br&gt; manually)</span></td></tr>';
$output .= '<tr><td></td><td>'.WebGUI::Form::submit("save").'</td></tr>';
$output .= '</table></form>';
return $output;
@ -57,7 +64,7 @@ sub www_addSave {
$widgetId = create();
$image = saveAttachment("image",$widgetId);
$attachment = saveAttachment("attachment",$widgetId);
WebGUI::SQL->write("insert into Article set widgetId=$widgetId, startDate='".humanToMysqlDate($session{form}{startDate})."', endDate='".humanToMysqlDate($session{form}{endDate})."', body=".quote($session{form}{body}).", image=".quote($image).", linkTitle=".quote($session{form}{linkTitle}).", linkURL=".quote($session{form}{linkURL}).", attachment=".quote($attachment),$session{dbh});
WebGUI::SQL->write("insert into Article set widgetId=$widgetId, startDate='".humanToMysqlDate($session{form}{startDate})."', endDate='".humanToMysqlDate($session{form}{endDate})."', convertCarriageReturns='$session{form}{convertCarriageReturns}', body=".quote($session{form}{body}).", image=".quote($image).", linkTitle=".quote($session{form}{linkTitle}).", linkURL=".quote($session{form}{linkURL}).", attachment=".quote($attachment),$session{dbh});
return "";
} else {
return WebGUI::Privilege::insufficient();
@ -88,7 +95,7 @@ sub www_deleteImage {
sub www_edit {
my ($output, %article);
if (WebGUI::Privilege::canEditPage()) {
%article = WebGUI::SQL->quickHash("select widget.title, widget.displayTitle, date_format(Article.startDate,'%m/%d/%Y') as start, date_format(Article.endDate,'%m/%d/%Y') as end, Article.body, Article.image, Article.linkTitle, Article.linkURL, Article.attachment, widget.processMacros from widget left join Article on (widget.widgetId=Article.widgetId) where widget.widgetId=$session{form}{wid}",$session{dbh});
%article = WebGUI::SQL->quickHash("select widget.title, widget.displayTitle, date_format(Article.startDate,'%m/%d/%Y') as start, date_format(Article.endDate,'%m/%d/%Y') as end, Article.body, Article.image, Article.linkTitle, Article.linkURL, Article.attachment, widget.processMacros, Article.convertCarriageReturns from widget left join Article on (widget.widgetId=Article.widgetId) where widget.widgetId=$session{form}{wid}",$session{dbh});
$output = '<a href="'.$session{page}{url}.'?op=viewHelp&hid=24"><img src="'.$session{setting}{lib}.'/help.gif" border="0" align="right"></a><h1>Edit Article</h1><form method="post" enctype="multipart/form-data" action="'.$session{page}{url}.'">';
$output .= WebGUI::Form::hidden("wid",$session{form}{wid});
$output .= WebGUI::Form::hidden("func","editSave");
@ -111,6 +118,7 @@ sub www_edit {
} else {
$output .= '<tr><td class="formDescription">Attachment</td><td>'.WebGUI::Form::file("attachment").'</td></tr>';
}
$output .= '<tr><td class="formDescription">Convert Carriage Returns</td><td>'.WebGUI::Form::checkbox("convertCarriageReturns",1,$article{convertCarriageReturns}).' <span style="font-size: 8pt;">(check if you\'re not adding &lt;br&gt; manually)</span></td></tr>';
$output .= '<tr><td></td><td>'.WebGUI::Form::submit("save").'</td></tr>';
$output .= '</table></form>';
return $output;
@ -132,7 +140,7 @@ sub www_editSave {
if ($attachment ne "") {
$attachment = ', attachment='.quote($attachment);
}
WebGUI::SQL->write("update Article set startDate='".humanToMysqlDate($session{form}{startDate})."', endDate='".humanToMysqlDate($session{form}{endDate})."', body=".quote($session{form}{body}).", linkTitle=".quote($session{form}{linkTitle}).", linkURL=".quote($session{form}{linkURL}).$attachment.$image." where widgetId=$session{form}{wid}",$session{dbh});
WebGUI::SQL->write("update Article set startDate='".humanToMysqlDate($session{form}{startDate})."', endDate='".humanToMysqlDate($session{form}{endDate})."', convertCarriageReturns='$session{form}{convertCarriageReturns}', body=".quote($session{form}{body}).", linkTitle=".quote($session{form}{linkTitle}).", linkURL=".quote($session{form}{linkURL}).$attachment.$image." where widgetId=$session{form}{wid}",$session{dbh});
return "";
} else {
return WebGUI::Privilege::insufficient();
@ -143,14 +151,17 @@ sub www_editSave {
sub www_view {
my (%data, @test, $output, $widgetId);
$widgetId = shift;
%data = WebGUI::SQL->quickHash("select widget.title, widget.displayTitle, widget.processMacros, Article.body, Article.image, Article.linkTitle, Article.linkURL, Article.attachment from widget,Article where widget.widgetId='$widgetId' and widget.WidgetId=Article.widgetId and Article.startDate<now() and Article.endDate>now()",$session{dbh});
%data = WebGUI::SQL->quickHash("select widget.title, widget.displayTitle, widget.processMacros, Article.body, Article.image, Article.linkTitle, Article.linkURL, Article.attachment, Article.convertCarriageReturns from widget,Article where widget.widgetId='$widgetId' and widget.WidgetId=Article.widgetId and Article.startDate<now() and Article.endDate>now()",$session{dbh});
if (defined %data) {
if ($data{displayTitle} == 1) {
$output = "<h2>".$data{title}."</h2>";
$output = "<h1>".$data{title}."</h1>";
}
if ($data{image} ne "") {
$output .= '<img src="'.$session{setting}{attachmentDirectoryWeb}.'/'.$widgetId.'/'.$data{image}.'" border="0" align="right">';
}
if ($data{convertCarriageReturns}) {
$data{body} =~ s/\n/\<br\>/g;
}
$output .= $data{body};
if ($data{linkURL} ne "" && $data{linkTitle} ne "") {
$output .= '<p><a href="'.$data{linkURL}.'">'.$data{linkTitle}.'</a>';

View file

@ -18,6 +18,12 @@ use WebGUI::SQL;
use WebGUI::Utility;
use WebGUI::Widget;
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from event where widgetId=$_[0]",$_[1]);
purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return "Events Calendar";
@ -193,12 +199,12 @@ sub www_view {
%data = WebGUI::SQL->quickHash("select * from widget where widget.widgetId='$widgetId'",$session{dbh});
if (defined %data) {
if ($data{displayTitle}) {
$output = "<h2>".$data{title}."</h2>";
$output = "<h1>".$data{title}."</h1>";
}
if ($data{description} ne "") {
$output .= $data{description}.'<p>';
}
$sth = WebGUI::SQL->read("select name, description, date_format(startDate,'%M'), date_format(startDate,'%e'), date_format(startDate,'%Y'), date_format(endDate,'%e') from event where widgetId='$widgetId' and startDate>now() order by startDate",$session{dbh});
$sth = WebGUI::SQL->read("select name, description, date_format(startDate,'%M'), date_format(startDate,'%e'), date_format(startDate,'%Y'), date_format(endDate,'%e') from event where widgetId='$widgetId' and to_days(startDate)>(to_days(now())-1) order by startDate",$session{dbh});
while (@event = $sth->array) {
$output .= "<b>$event[2] $event[3]";
if ($event[3] ne $event[5]) {

View file

@ -17,6 +17,12 @@ use WebGUI::SQL;
use WebGUI::Utility;
use WebGUI::Widget;
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from ExtraColumn where widgetId=$_[0]",$_[1]);
purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return "Extra Column";

View file

@ -29,6 +29,12 @@ sub _reorderQuestions {
$sth->finish;
}
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from faqQuestion where widgetId=$_[0]",$_[1]);
purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return "F.A.Q.";
@ -103,7 +109,7 @@ sub www_deleteQuestion {
my ($output);
if (WebGUI::Privilege::canEditPage()) {
$output = '<h1>Please Confirm</h1>';
$output = 'Are you certain that you want to delete this question?<p><div align="center"><a href="'.$session{page}{url}.'?func=deleteQuestionConfirm&wid='.$session{form}{wid}.'&lid='.$session{form}{lid}.'">Yes, I\'m sure.</a> &nbsp; <a href="'.$session{page}{url}.'?func=edit&wid='.$session{form}{wid}.'">No, I made a mistake.</a></div>';
$output = 'Are you certain that you want to delete this question?<p><div align="center"><a href="'.$session{page}{url}.'?func=deleteQuestionConfirm&wid='.$session{form}{wid}.'&qid='.$session{form}{qid}.'">Yes, I\'m sure.</a> &nbsp; <a href="'.$session{page}{url}.'?func=edit&wid='.$session{form}{wid}.'">No, I made a mistake.</a></div>';
return $output;
} else {
return WebGUI::Privilege::insufficient();
@ -186,7 +192,7 @@ sub www_editQuestion {
sub www_editQuestionSave {
if (WebGUI::Privilege::canEditPage()) {
WebGUI::SQL->write("update faqQuestion set question=".quote($session{form}{question}).", answer=".quote($session{form}{answer})." where questionId=$session{form}{qid}",$session{dbh});
return "";
return www_edit();
} else {
return WebGUI::Privilege::insufficient();
}
@ -231,7 +237,7 @@ sub www_view {
%data = WebGUI::SQL->quickHash("select * from widget where widget.widgetId='$widgetId'",$session{dbh});
if (defined %data) {
if ($data{displayTitle} == 1) {
$output = "<h2>".$data{title}."</h2>";
$output = "<h1>".$data{title}."</h1>";
}
if ($data{description} ne "") {
$output .= $data{description};

View file

@ -29,6 +29,12 @@ sub _reorderLinks {
$sth->finish;
}
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from link where widgetId=$_[0]",$_[1]);
purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return "Link List";
@ -234,7 +240,7 @@ sub www_view {
%data = WebGUI::SQL->quickHash("select * from widget where widget.widgetId='$widgetId'",$session{dbh});
if (defined %data) {
if ($data{displayTitle}) {
$output = "<h2>".$data{title}."</h2>";
$output = "<h1>".$data{title}."</h1>";
}
if ($data{description} ne "") {
$output .= $data{description}.'<p>';

View file

@ -43,6 +43,13 @@ sub _traverseReplyTree {
return $html;
}
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from message where widgetId=$_[0]",$_[1]);
WebGUI::SQL->write("delete from MessageBoard where widgetId=$_[0]",$_[1]);
purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return "Message Board";
@ -310,18 +317,12 @@ sub www_showMessage {
#-------------------------------------------------------------------
sub www_view {
my ($sth, @data, $html, %board, $itemsPerPage, $currentPage, $totalItems);
my ($sth, @data, $html, %board, $itemsPerPage, $i, @row, $pn);
%board = _getBoardProperties($_[0]);
$itemsPerPage = $board{messagesPerPage};
if ($session{form}{pageNumber} < 1) {
$currentPage = 1;
} else {
$currentPage = $session{form}{pageNumber};
}
if ($board{description} ne "") {
$html .= $board{description}.'<p>';
}
($totalItems) = WebGUI::SQL->quickArray("select count(*) from message where widgetId=$_[0]",$session{dbh});
$html .= '<table width="100%"><tr><td class="boardTitle">';
if ($board{displayTitle}) {
$html .= $board{title};
@ -329,32 +330,34 @@ sub www_view {
$html .= '</td><td align="right" valign="bottom" class="boardMenu"><a href="'.$session{page}{url}.'?func=postNewMessage&wid='.$_[0].'">Post New Message</a></td></tr></table>';
$html .= '<table border=0 cellpadding=2 cellspacing=1 width="100%">';
$html .= '<tr><td class="tableHeader">Subject</td><td class="tableHeader">Author</td><td class="tableHeader">Thread Started</td><td class="tableHeader">Replies</td><td class="tableHeader">Last Reply</td></tr>';
$sth = WebGUI::SQL->read("select messageId,substring(subject,1,30),count(messageId)-1,username,date_format(dateOfPost,'%c/%e %l:%i%p'),date_format(max(dateOfPost),'%c/%e %l:%i%p'),max(messageId) from message where widgetId=$_[0] group by rid order by messageId desc limit ".(($currentPage*$itemsPerPage)-$itemsPerPage).",".$itemsPerPage, $session{dbh});
$sth = WebGUI::SQL->read("select messageId,substring(subject,1,30),count(messageId)-1,username,date_format(dateOfPost,'%c/%e %l:%i%p'),date_format(max(dateOfPost),'%c/%e %l:%i%p'),max(messageId) from message where widgetId=$_[0] group by rid order by messageId desc", $session{dbh});
while (@data = $sth->array) {
$html .= '<tr><td class="tableData"><a href="'.$session{page}{url}.'?func=showMessage&mid='.$data[0].'&wid='.$_[0].'">'.$data[1].'</a></td><td class="tableData">'.$data[3].'</td><td class="tableData">'.$data[4].'</td><td class="tableData">'.$data[2].'</td><td class="tableData"><a href="'.$session{page}{url}.'?func=showMessage&mid='.$data[6].'&wid='.$_[0].'">'.$data[5].'</a></td></tr>';
}
$html .= "</table>";
$sth->finish;
$html .= '<div class="pagination">';
if ($currentPage > 1) {
$html .= '<a href="'.$session{page}{url}.'?pageNumber='.($currentPage-1).'">&laquo;Previous Page</a>';
} else {
$html .= '&laquo;Previous Page';
}
$html .= ' &middot; ';
if ($currentPage < round($totalItems/$itemsPerPage)) {
$html .= '<a href="'.$session{page}{url}.'?pageNumber='.($currentPage+1).'">Next Page&raquo;</a>';
} else {
$html .= 'Next Page&raquo;';
}
$html .= '</div>';
$row[$i] = '<tr><td class="tableData"><a href="'.$session{page}{url}.'?func=showMessage&mid='.$data[0].'&wid='.$_[0].'">'.$data[1].'</a></td><td class="tableData">'.$data[3].'</td><td class="tableData">'.$data[4].'</td><td class="tableData">'.$data[2].'</td><td class="tableData"><a href="'.$session{page}{url}.'?func=showMessage&mid='.$data[6].'&wid='.$_[0].'">'.$data[5].'</a></td></tr>';
$i++;
}
if ($session{form}{pn} < 1) {
$pn = 0;
} else {
$pn = $session{form}{pn};
}
for ($i=($itemsPerPage*$pn); $i<($itemsPerPage*($pn+1));$i++) {
$html .= $row[$i];
}
$html .= '</table>';
$html .= '<div class="pagination">';
if ($pn > 0) {
$html .= '<a href="'.$session{page}{url}.'?pn='.($pn-1).'">&laquo;Previous Page</a>';
} else {
$html .= '&laquo;Previous Page';
}
$html .= ' &middot; ';
if ($pn < round($#row/$itemsPerPage)) {
$html .= '<a href="'.$session{page}{url}.'?pn='.($pn+1).'">Next Page&raquo;</a>';
} else {
$html .= 'Next Page&raquo;';
}
$html .= '</div>';
return $html;
}
1;

View file

@ -24,7 +24,7 @@ sub _viewPoll {
%poll = WebGUI::SQL->quickHash("select * from widget,Poll where widget.widgetId=Poll.widgetId and widget.widgetId='$widgetId'",$session{dbh});
if (defined %poll) {
if ($poll{displayTitle} == 1) {
$output = "<h2>".$poll{title}."</h2>";
$output = "<h1>".$poll{title}."</h1>";
}
if ($poll{description} ne "") {
$output .= $poll{description}.'<p>';
@ -52,7 +52,7 @@ sub _viewResults {
%poll = WebGUI::SQL->quickHash("select * from widget,Poll where widget.widgetId=Poll.widgetId and widget.widgetId='$widgetId'",$session{dbh});
if (defined %poll) {
if ($poll{displayTitle} == 1) {
$output = "<h2>".$poll{title}."</h2>";
$output = "<h1>".$poll{title}."</h1>";
}
if ($poll{description} ne "") {
$output .= $poll{description}.'<p>';
@ -73,6 +73,13 @@ sub _viewResults {
return $output;
}
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from pollAnswer where widgetId=$_[0]",$_[1]);
WebGUI::SQL->write("delete from Poll where widgetId=$_[0]",$_[1]);
purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return "Poll";

View file

@ -11,6 +11,7 @@ package WebGUI::Widget::SQLReport;
#-------------------------------------------------------------------
use strict;
use WebGUI::ErrorHandler;
use WebGUI::Macro;
use WebGUI::Privilege;
use WebGUI::Session;
@ -18,6 +19,12 @@ use WebGUI::SQL;
use WebGUI::Utility;
use WebGUI::Widget;
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from SQLReport where widgetId=$_[0]",$_[1]);
purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return "SQL Report";
@ -108,7 +115,7 @@ sub www_view {
%data = WebGUI::SQL->quickHash("select * from widget,SQLReport where widget.widgetId=$widgetId and widget.widgetId=SQLReport.widgetId",$session{dbh});
if (defined %data) {
if ($data{displayTitle} == 1) {
$output = "<h2>".$data{title}."</h2>";
$output = "<h1>".$data{title}."</h1>";
}
if ($data{description} ne "") {
$output .= $data{description}.'<p>';
@ -119,9 +126,15 @@ sub www_view {
$dbh = DBI->connect($data{DSN},$data{username},$data{identifier});
} else {
$output .= '<b>Error</b>: The DSN specified is of an improper format.<p>';
WebGUI::ErrorHandler::warn("SQLReport [$widgetId] The DSN specified is of an improper format.");
}
if (defined $dbh) {
$sth = WebGUI::SQL->read($data{dbQuery},$dbh);
if ($data{dbQuery} =~ /select/i) {
$sth = WebGUI::SQL->read($data{dbQuery},$dbh);
} else {
$output .= '<b>Error</b>: The SQL query is improperly formatted.<p>';
WebGUI::ErrorHandler::warn("SQLReport [$widgetId] The SQL query is improperly formatted.");
}
if (defined $sth) {
while (@result = $sth->array) {
$temp = $template[1];
@ -133,11 +146,13 @@ sub www_view {
}
$sth->finish;
} else {
$output .= '<b>Error</b>: There was a problem with the query.';
$output .= '<b>Error</b>: There was a problem with the query.<p>';
WebGUI::ErrorHandler::warn("SQLReport [$widgetId] There was a problem with the query.");
}
$dbh->disconnect();
} else {
$output .= '<b>Error</b>: Could not connect to remote database.';
$output .= '<b>Error</b>: Could not connect to remote database.<p>';
WebGUI::ErrorHandler::warn("SQLReport [$widgetId] Could not connect to remote database.");
}
$output .= $template[2];
}

View file

@ -27,6 +27,7 @@ sub _mnogoSearch {
$dbh = DBI->connect($data{DSN},$data{username},$data{identifier});
} else {
$output .= '<b>Error</b>: The DSN specified is of an improper format.<p>';
WebGUI::ErrorHandler::warn("Search (MnoGo) The DSN specified is of an improper format.");
}
if (defined $dbh) {
foreach $word (@keyword) {
@ -38,6 +39,7 @@ sub _mnogoSearch {
$sth->finish;
} else {
$output .= '<b>Error</b>: There was a problem with the query.<p>';
WebGUI::ErrorHandler::warn("Search (MnoGo) There was a problem with the query.");
}
}
foreach $key (sort {$result{$b} <=> $result{$a}} keys %result) {
@ -50,10 +52,17 @@ sub _mnogoSearch {
$dbh->disconnect();
} else {
$output .= '<b>Error</b>: Could not connect to remote database.<p>';
WebGUI::ErrorHandler::warn("Search (MnoGo) Could not connect to remote database.");
}
return $output;
}
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from SearchMnoGo where widgetId=$_[0]",$_[1]);
purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return "Search (MnoGo)";
@ -63,7 +72,7 @@ sub widgetName {
sub www_add {
my ($output);
if (WebGUI::Privilege::canEditPage()) {
$output = '<h1>Add Search (MnoGo)</h1><form method="post" enctype="multipart/form-data" action="'.$session{page}{url}.'">';
$output = '<a href="'.$session{page}{url}.'?op=viewHelp&hid=42"><img src="'.$session{setting}{lib}.'/help.gif" border="0" align="right"></a><h1>Add Search (MnoGo)</h1><form method="post" enctype="multipart/form-data" action="'.$session{page}{url}.'">';
$output .= WebGUI::Form::hidden("widget","SearchMnoGo");
$output .= WebGUI::Form::hidden("func","addSave");
$output .= '<table>';
@ -99,7 +108,7 @@ sub www_edit {
my ($output, %data);
if (WebGUI::Privilege::canEditPage()) {
%data = WebGUI::SQL->quickHash("select * from widget,SearchMnoGo where widget.widgetId=SearchMnoGo.widgetId and widget.widgetId=$session{form}{wid}",$session{dbh});
$output = '<h1>Edit Search (MnoGo)</h1><form method="post" enctype="multipart/form-data" action="'.$session{page}{url}.'">';
$output = '<a href="'.$session{page}{url}.'?op=viewHelp&hid=43"><img src="'.$session{setting}{lib}.'/help.gif" border="0" align="right"></a><h1>Edit Search (MnoGo)</h1><form method="post" enctype="multipart/form-data" action="'.$session{page}{url}.'">';
$output .= WebGUI::Form::hidden("wid",$session{form}{wid});
$output .= WebGUI::Form::hidden("func","editSave");
$output .= '<table>';
@ -135,7 +144,7 @@ sub www_view {
%data = WebGUI::SQL->quickHash("select * from widget,SearchMnoGo where widget.widgetId='$widgetId' and widget.WidgetId=SearchMnoGo.widgetId",$session{dbh});
if (%data) {
if ($data{displayTitle} == 1) {
$output = "<h2>".$data{title}."</h2>";
$output = "<h1>".$data{title}."</h1>";
}
if ($data{description} ne "") {
$output .= $data{description}.'<p>';

View file

@ -34,6 +34,12 @@ sub _traversePageTree {
return $output;
}
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from SiteMap where widgetId=$_[0]",$_[1]);
purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return "Site Map";
@ -86,7 +92,7 @@ sub www_edit {
$output .= '<tr><td class="formDescription">Display title?</td><td>'.WebGUI::Form::checkbox("displayTitle",1,$data{displayTitle}).'</td></tr>';
$output .= '<tr><td class="formDescription">Description</td><td>'.WebGUI::Form::textArea("description",$data{description}).'</td></tr>';
$output .= '<tr><td class="formDescription">Starting from this level?</td><td>'.WebGUI::Form::checkbox("startAtThisLevel",1,$data{startAtThisLevel}).'</td></tr>';
$output .= '<tr><td class="formDescription">Show only one level?uuuu</td><td>'.WebGUI::Form::checkbox("showOnlyThisLevel",1,$data{showOnlyThisLevel}).'</td></tr>';
$output .= '<tr><td class="formDescription">Show only one level?</td><td>'.WebGUI::Form::checkbox("showOnlyThisLevel",1,$data{showOnlyThisLevel}).'</td></tr>';
$output .= '<tr><td></td><td>'.WebGUI::Form::submit("save").'</td></tr>';
$output .= '</table></form>';
return $output;

View file

@ -18,6 +18,12 @@ use WebGUI::SQL;
use WebGUI::Utility;
use WebGUI::Widget;
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from SyndicatedContent where widgetId=$_[0]",$_[1]);
purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return "Syndicated Content";
@ -98,7 +104,7 @@ sub www_view {
%data = WebGUI::SQL->quickHash("select * from widget,SyndicatedContent where widget.widgetId=$widgetId",$session{dbh});
if (defined %data) {
if ($data{displayTitle} == 1) {
$output = "<h2>".$data{title}."</h2>";
$output = "<h1>".$data{title}."</h1>";
}
if ($data{description} ne "") {
$output .= $data{description}.'<p>';

View file

@ -17,6 +17,13 @@ use WebGUI::SQL;
use WebGUI::Utility;
use WebGUI::Widget;
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from submission where widgetId=$_[0]",$_[1]);
WebGUI::SQL->write("delete from UserSubmission where widgetId=$_[0]",$_[1]);
purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return "User Submission System";
@ -27,7 +34,7 @@ sub www_add {
my ($output, %hash);
tie %hash, "Tie::IxHash";
if (WebGUI::Privilege::canEditPage()) {
$output = '<h1>Add User Submission System</h1><form method="post" enctype="multipart/form-data" action="'.$session{page}{url}.'">';
$output = '<a href="'.$session{page}{url}.'?op=viewHelp&hid=44"><img src="'.$session{setting}{lib}.'/help.gif" border="0" align="right"></a><h1>Add User Submission System</h1><form method="post" enctype="multipart/form-data" action="'.$session{page}{url}.'">';
$output .= WebGUI::Form::hidden("widget","UserSubmission");
$output .= WebGUI::Form::hidden("func","addSave");
$output .= '<table>';
@ -73,11 +80,12 @@ sub www_addSubmission {
$output .= '<tr><td class="formDescription">Content</td><td>'.WebGUI::Form::textArea("content",'',50,10,1).'</td></tr>';
$output .= '<tr><td class="formDescription">Image</td><td>'.WebGUI::Form::file("image").'</td></tr>';
$output .= '<tr><td class="formDescription">Attachment</td><td>'.WebGUI::Form::file("attachment").'</td></tr>';
$output .= '<tr><td class="formDescription">Convert Carriage Returns</td><td>'.WebGUI::Form::checkbox("convertCarriageReturns",1,1).' <span style="font-size: 8pt;">(uncheck if you\'re writing an HTML submission)</span></td></tr>';
$output .= '<tr><td></td><td>'.WebGUI::Form::submit("save").'</td></tr>';
$output .= '</table></form>';
$output .= '<table width="100%" cellspacing=1 cellpadding=2 border=0>';
$output .= '<tr><td class="tableHeader">Edit/Delete</td><td class="tableHeader">Title</td><td class="tableHeader">Date Submitted</td><td class="tableHeader">Status</td></tr>';
$sth = WebGUI::SQL->read("select title,submissionId,date_format(dateSubmitted,'%c/%e %l:%i%p'),status from submission where widgetId='$session{form}{wid}' and userId=$session{user}{userId} order by dateSubmitted desc",$session{dbh});
$sth = WebGUI::SQL->read("select title,submissionId,date_format(dateSubmitted,'%c/%e/%Y'),status from submission where widgetId='$session{form}{wid}' and userId=$session{user}{userId} order by dateSubmitted desc",$session{dbh});
while (@submission = $sth->array) {
$output .= '<tr><td class="tableData"><a href="'.$session{page}{url}.'?func=editSubmission&wid='.$session{form}{wid}.'&sid='.$submission[1].'"><img src="'.$session{setting}{lib}.'/edit.gif" border=0></a><a href="'.$session{page}{url}.'?wid='.$session{form}{wid}.'&sid='.$submission[1].'&func=deleteSubmission"><img src="'.$session{setting}{lib}.'/delete.gif" border=0></a></td><td class="tableData"><a href="'.$session{page}{url}.'?wid='.$session{form}{wid}.'&func=viewSubmission&sid='.$submission[1].'">'.$submission[0].'</a></td><td class="tableData">'.$submission[2].'</td><td class="tableData">'.$submission[3].'</td></tr>';
}
@ -91,13 +99,18 @@ sub www_addSubmission {
#-------------------------------------------------------------------
sub www_addSubmissionSave {
my ($submissionId, $image, $attachment, $status, $groupToContribute);
my ($title, $submissionId, $image, $attachment, $status, $groupToContribute);
($status, $groupToContribute) = WebGUI::SQL->quickArray("select defaultStatus,groupToContribute from UserSubmission where widgetId=$session{form}{wid}",$session{dbh});
if (WebGUI::Privilege::isInGroup($groupToContribute,$session{user}{userId})) {
$submissionId = getNextId("submissionId");
$image = saveAttachment("image",$session{form}{wid},$submissionId);
$attachment = saveAttachment("attachment",$session{form}{wid},$submissionId);
WebGUI::SQL->write("insert into submission set widgetId=$session{form}{wid}, submissionId=$submissionId, title=".quote($session{form}{title}).", username=".quote($session{user}{username}).", status='$status', dateSubmitted=now(), userId='$session{user}{userId}', content=".quote($session{form}{content}).", image=".quote($image).", attachment=".quote($attachment),$session{dbh});
if ($session{form}{title} ne "") {
$title = $session{form}{title};
} else {
$title = "Untitled";
}
WebGUI::SQL->write("insert into submission set widgetId=$session{form}{wid}, submissionId=$submissionId, convertCarriageReturns='$session{form}{convertCarriageReturns}', title=".quote($title).", username=".quote($session{user}{username}).", status='$status', dateSubmitted=now(), userId='$session{user}{userId}', content=".quote($session{form}{content}).", image=".quote($image).", attachment=".quote($attachment),$session{dbh});
return "";
} else {
return WebGUI::Privilege::insufficient();
@ -158,7 +171,7 @@ sub www_edit {
my ($output, %data, @array, $sth, %hash);
if (WebGUI::Privilege::canEditPage()) {
%data = WebGUI::SQL->quickHash("select * from widget,UserSubmission where widget.widgetId=$session{form}{wid} and widget.widgetId=UserSubmission.widgetId",$session{dbh});
$output = '<h1>Edit User Submission System</h1><form method="post" enctype="multipart/form-data" action="'.$session{page}{url}.'">';
$output = '<a href="'.$session{page}{url}.'?op=viewHelp&hid=45"><img src="'.$session{setting}{lib}.'/help.gif" border="0" align="right"></a><h1>Edit User Submission System</h1><form method="post" enctype="multipart/form-data" action="'.$session{page}{url}.'">';
$output .= WebGUI::Form::hidden("wid",$session{form}{wid});
$output .= WebGUI::Form::hidden("func","editSave");
$output .= '<table>';
@ -214,6 +227,7 @@ sub www_editSubmission {
} else {
$output .= '<tr><td class="formDescription">Attachment</td><td>'.WebGUI::Form::file("attachment").'</td></tr>';
}
$output .= '<tr><td class="formDescription">Convert Carriage Returns</td><td>'.WebGUI::Form::checkbox("convertCarriageReturns",1,$submission{convertCarriageReturns}).' <span style="font-size: 8pt;">(uncheck if you\'re writing an HTML submission)</span></td></tr>';
$output .= '<tr><td></td><td>'.WebGUI::Form::submit("save").'</td></tr>';
$output .= '</table></form>';
return $output;
@ -225,7 +239,7 @@ sub www_editSubmission {
#-------------------------------------------------------------------
sub www_editSubmissionSave {
my ($owner,$status,$image,$attachment);
my ($owner,$status,$image,$attachment,$title);
($owner) = WebGUI::SQL->quickArray("select userId from submission where submissionId=$session{form}{sid}",$session{dbh});
if ($owner == $session{user}{userId}) {
($status) = WebGUI::SQL->quickArray("select defaultStatus from UserSubmission where widgetId=$session{form}{wid}",$session{dbh});
@ -237,7 +251,12 @@ sub www_editSubmissionSave {
if ($attachment ne "") {
$attachment = 'attachment='.quote($attachment).', ';
}
WebGUI::SQL->write("update submission set title=".quote($session{form}{title}).", content=".quote($session{form}{content}).", ".$image.$attachment." status='$status' where submissionId=$session{form}{sid}",$session{dbh});
if ($session{form}{title} ne "") {
$title = $session{form}{title};
} else {
$title = "Untitled";
}
WebGUI::SQL->write("update submission set convertCarriageReturns='$session{form}{convertCarriageReturns}', title=".quote($title).", content=".quote($session{form}{content}).", ".$image.$attachment." status='$status' where submissionId=$session{form}{sid}",$session{dbh});
return www_viewSubmission();
} else {
return WebGUI::Privilege::insufficient();
@ -251,12 +270,12 @@ sub www_view {
%data = WebGUI::SQL->quickHash("select * from widget,UserSubmission where widget.widgetId=$widgetId and widget.widgetId=UserSubmission.widgetId",$session{dbh});
if (%data) {
if ($data{displayTitle} == 1) {
$output = "<h2>".$data{title}."</h2>";
$output = "<h1>".$data{title}."</h1>";
}
if ($data{description} ne "") {
$output .= $data{description}.'<p>';
}
$sth = WebGUI::SQL->read("select title,submissionId,date_format(dateSubmitted,'%c/%e %l:%i%p'),username,userId from submission where widgetId='$widgetId' and status='Approved' order by dateSubmitted desc",$session{dbh});
$sth = WebGUI::SQL->read("select title,submissionId,date_format(dateSubmitted,'%c/%e/%Y'),username,userId from submission where widgetId='$widgetId' and status='Approved' order by dateSubmitted desc",$session{dbh});
while (@submission = $sth->array) {
$row[$i] = '<tr><td class="tableData"><a href="'.$session{page}{url}.'?wid='.$widgetId.'&func=viewSubmission&sid='.$submission[1].'">'.$submission[0].'</a></td><td class="tableData">'.$submission[2].'</td><td class="tableData">'.$submission[3].'</td></tr>';
$i++;
@ -295,7 +314,7 @@ sub www_view {
sub www_viewSubmission {
my ($output, %submission);
%submission = WebGUI::SQL->quickHash("select * from submission where submissionId=$session{form}{sid}",$session{dbh});
$output = "<h2>".$submission{title}."</h2>";
$output = "<h1>".$submission{title}."</h1>";
$output .= '<b>Submitted By:</b> '.$submission{username}.'<br>';
$output .= '<b>Date Submitted:</b> '.$submission{dateSubmitted}.'<p>';
if ($submission{image} ne "") {
@ -307,7 +326,10 @@ sub www_viewSubmission {
$output .= '<a href="'.$session{page}{url}.'?op=viewPendingSubmissions">Leave Pending</a> &middot; ';
$output .= '<a href="'.$session{page}{url}.'?op=denySubmission&sid='.$session{form}{sid}.'">Deny</a> ';
$output .= '</div>';
}
}
if ($submission{convertCarriageReturns}) {
$submission{content} =~ s/\n/\<br\>/g;
}
$output .= $submission{content}.'<p>';
if ($submission{attachment} ne "") {
$output .= '<p><a href="'.$session{setting}{attachmentDirectoryWeb}.'/'.$session{form}{wid}.'/'.$session{form}{sid}.'/'.$submission{attachment}.'"><img src="'.$session{setting}{lib}.'/attachment.gif" border=0 alt="Download Attachment"></a><p>';