#!/usr/bin/perl -w
###############################################################################
# submit.pl - this code inputs user submission into the system to be
# approved by authors
#
# Copyright (C) 1997 Rob "CmdrTaco" Malda
# malda@slashdot.org
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
# $Id: submit.pl,v 1.28 2000/09/22 15:25:19 pudge Exp $
###############################################################################
use strict;
use lib '../';
use vars '%I';
use Slash;
#################################################################
sub main {
*I = getSlashConf();
getSlash();
my $id = getFormkeyId($I{U}{uid});
my($section, $op, $seclev, $aid) = (
$I{F}{section}, $I{F}{op}, $I{U}{aseclev}, $I{U}{aid}
);
$I{F}{del} ||= "0";
$I{F}{op} ||= "";
$I{F}{from} = stripByMode($I{F}{from}) if $I{F}{from};
$I{F}{subj} = stripByMode($I{F}{subj}) if $I{F}{subj};
$I{F}{email} = stripByMode($I{F}{email}) if $I{F}{email};
# Show submission title on browser's titlebar.
my($tbtitle) = $I{F}{title};
if ($tbtitle) {
$tbtitle =~ s/^"?(.+?)"?$/"$1"/;
$tbtitle = "- $tbtitle";
}
$section = "admin" if $seclev > 100;
header("$I{sitename} Submissions$tbtitle", $section);
# print "from $I{F}{from} email $I{F}{email} subject $I{F}{subj} \n";
#adminMenu() if $seclev > 100;
if ($op eq "list" && ($seclev > 99 || $I{submiss_view})) {
titlebar("100%", 'Submissions ' . ($seclev > 99 ? 'Admin' : 'List'));
submissionEd();
} elsif ($op eq "Update" && $seclev > 99) {
titlebar("100%", "Deleting $I{F}{subid}");
rmSub();
submissionEd();
} elsif ($op eq "GenQuickies" && $seclev > 99) {
titlebar("100%", "Quickies Generated");
genQuickies();
submissionEd();
} elsif (! $op) {
yourPendingSubmissions();
titlebar("100%", "$I{sitename} Submissions", "c");
displayForm($I{U}{nickname}, $I{U}{fakeemail}, $I{F}{section}, $id);
} elsif ($op eq "PreviewStory") {
titlebar("100%", "$I{sitename} Submission Preview", "c");
# insert the fact that the form has been displayed,
# but not submitted at this point
insertFormkey("submissions",$id,"submission");
displayForm($I{F}{from}, $I{F}{email}, $I{F}{section}, $id);
} elsif ($op eq "viewsub" && ($seclev > 99 || $I{submiss_view})) {
previewForm($aid, $I{F}{subid});
} elsif ($op eq "SubmitStory") {
saveSub($id);
yourPendingSubmissions();
} else {
print "Huh?";
# foreach (keys %{$I{U}}) { print "$_ = $I{U}{$_} " }
}
footer();
}
#################################################################
sub yourPendingSubmissions {
return unless $I{U}{uid} > 0;
my $c = sqlSelectMany("*", "submissions", "uid=$I{U}{uid}");
if ($c->rows) {
my($count) = sqlSelect("count(*)", "submissions", "del=0");
titlebar("100%", "Your Recent Submissions (total:$count)");
print <Here are your recent submissions to $I{sitename},
and their status within the system:
EOT
while (my $S = $c->fetchrow_hashref) {
print "
\n\n";
}
#################################################################
sub saveSub {
my $id = shift;
# if formkey works
if (checkSubmission("submissions", $I{submission_speed_limit}, $I{max_submissions_allowed}, $id)) {
if (length $I{F}{subj} < 2) {
titlebar("100%", "Error:");
print "Please enter a reasonable subject.\n";
displayForm($I{F}{from}, $I{F}{email}, $I{F}{section});
return;
}
titlebar("100%", "Saving");
print "Perhaps you would like to enter an email address or a URL next time.
"
unless length $I{F}{email} > 2;
print "This story has been submitted anonymously
"
unless length $I{F}{from} > 2;
print "There are currently ",
sqlSelect("count(*)", "submissions", "del=0"),
" submissions pending.