############################################################################## # The Faq-O-Matic is Copyright 1997 by Jon Howell, all rights reserved. # # # # 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.# # # # Jon Howell can be contacted at: # # 6211 Sudikoff Lab, Dartmouth College # # Hanover, NH 03755-3510 # # jonh@cs.dartmouth.edu # # # # An electronic copy of the GPL is available at: # # http://www.gnu.org/copyleft/gpl.html # # # ############################################################################## use strict; package FAQ::OMatic::submitPart; use CGI; use FAQ::OMatic::Item; use FAQ::OMatic::I18N; use FAQ::OMatic; use FAQ::OMatic::Auth; sub main { my $cgi = FAQ::OMatic::dispatch::cgi(); my $removed = 0; my $params = FAQ::OMatic::getParams($cgi); FAQ::OMatic::mirrorsCantEdit($cgi, $params); my $item = new FAQ::OMatic::Item($params->{'file'}); if ($item->isBroken()) { FAQ::OMatic::gripe('error', gettexta("The file (%0) doesn't exist.", $params->{'file'})); } my $insertpart = $params->{'_insertpart'} || $params->{'s_insertpart'}; # have to check the s_ case, because we don't extract the s_-encoded # parameters until later. (Any reason not to do them here?) if (not $insertpart) { # if inserting a part, we don't have to check -- inserts can # come out of order and it's not too bad. $item->checkSequence($params); } $item->incrementSequence(); my $partnum = $params->{'partnum'}; my $part; if ($partnum >= 0) { $part = $item->getPart($partnum); if (not $part) { FAQ::OMatic::gripe('error', "Part number \"$partnum\" in \"" .$params->{'file'}."\" doesn't exist."); } } else { $partnum = -1; } if (($partnum < 0) and (not $insertpart)) { FAQ::OMatic::gripe('error', "Part number \"$partnum\" in \"" .$params->{'file'}."\" doesn't exist."); } # if we're inserting a part, create a new one to hold the data # and stuff it into the item. (Don't worry about the permissions # check being later -- we're only modifying the in-memory copy; # we haven't written the item out yet.) if ($insertpart) { $part = new FAQ::OMatic::Part(); splice @{$item->{'Parts'}}, $partnum+1, 0, $part; $item->updateDirectoryHint(); } # verify that an evil cache hasn't truncated a POST if ((($params->{'_zzverify'}||'') ne 'zz') and (not $params->{'s_textInFile'})) { FAQ::OMatic::gripe('error', "Your browser or WWW cache has truncated your POST."); } # select source of data: file or textarea if (($params->{'_inputType'}||'') eq 'file') { # THANKS: John Nolan's fix applies here, too. my $formFileHandle = $cgi->param('_newTextFile'); $params->{'_newText'} = ''; # scrap