| 1 | ############################################################################## | ||
| 2 | # The Faq-O-Matic is Copyright 1997 by Jon Howell, all rights reserved. # | ||
| 3 | # # | ||
| 4 | # This program is free software; you can redistribute it and/or # | ||
| 5 | # modify it under the terms of the GNU General Public License # | ||
| 6 | # as published by the Free Software Foundation; either version 2 # | ||
| 7 | # of the License, or (at your option) any later version. # | ||
| 8 | # # | ||
| 9 | # This program is distributed in the hope that it will be useful, # | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
| 12 | # GNU General Public License for more details. # | ||
| 13 | # # | ||
| 14 | # You should have received a copy of the GNU General Public License # | ||
| 15 | # along with this program; if not, write to the Free Software # | ||
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.# | ||
| 17 | # # | ||
| 18 | # Jon Howell can be contacted at: # | ||
| 19 | # 6211 Sudikoff Lab, Dartmouth College # | ||
| 20 | # Hanover, NH 03755-3510 # | ||
| 21 | # jonh@cs.dartmouth.edu # | ||
| 22 | # # | ||
| 23 | # An electronic copy of the GPL is available at: # | ||
| 24 | # http://www.gnu.org/copyleft/gpl.html # | ||
| 25 | # # | ||
| 26 | ############################################################################## | ||
| 27 | |||
| 28 | use strict; | ||
| 29 | |||
| 30 | package FAQ::OMatic::editBag; | ||
| 31 | |||
| 32 | use CGI; | ||
| 33 | use FAQ::OMatic::Item; | ||
| 34 | use FAQ::OMatic; | ||
| 35 | use FAQ::OMatic::Auth; | ||
| 36 | use FAQ::OMatic::I18N; | ||
| 37 | |||
| 38 | sub main { | ||
| 39 | my $cgi = FAQ::OMatic::dispatch::cgi(); | ||
| 40 | my $rt = ''; | ||
| 41 | |||
| 42 | my $params = FAQ::OMatic::getParams($cgi); | ||
| 43 | |||
| 44 | FAQ::OMatic::mirrorsCantEdit($cgi, $params); | ||
| 45 | |||
| 46 | $rt = FAQ::OMatic::pageHeader($params, ['help', 'faq']); | ||
| 47 | |||
| 48 | my $bagName = $params->{'_target'} || ''; # no bag name => upload new. | ||
| 49 | |||
| 50 | if ($bagName) { | ||
| 51 | # bag exists | ||
| 52 | FAQ::OMatic::Auth::ensurePerm('-item'=>'', | ||
| 53 | '-operation'=>'PermReplaceBag', | ||
| 54 | '-restart'=>FAQ::OMatic::commandName(), | ||
| 55 | '-cgi'=>$cgi, | ||
| 56 | '-xreason'=>'replace', | ||
| 57 | '-failexit'=>1); | ||
| 58 | } else { | ||
| 59 | # new bag name | ||
| 60 | FAQ::OMatic::Auth::ensurePerm('-item'=>'', | ||
| 61 | '-operation'=>'PermNewBag', | ||
| 62 | '-restart'=>FAQ::OMatic::commandName(), | ||
| 63 | '-cgi'=>$cgi, | ||
| 64 | '-failexit'=>1); | ||
| 65 | } | ||
| 66 | |||
| 67 | my $bagDescName = $bagName.".desc"; | ||
| 68 | my $bagDesc = new FAQ::OMatic::Item($bagDescName, | ||
| 69 | $FAQ::OMatic::Config::bagsDir); | ||
| 70 | $bagDesc->setProperty('Title', 'Bag Description'); # if bagDesc not found | ||
| 71 | my $sizeWidth = $bagDesc->{'SizeWidth'} || ''; | ||
| 72 | my $sizeHeight = $bagDesc->{'SizeHeight'} || ''; | ||
| 73 | |||
| 74 | if ($bagName ne '') { | ||
| 75 | $rt .= "<h3>".gettext("Replace bag")." <i>$bagName</i>:</h3>\n"; | ||
| 76 | } else { | ||
| 77 | my $item = new FAQ::OMatic::Item($params->{'file'}); | ||
| 78 | my $itemTitle = $item->getTitle(); | ||
| 79 | my $partnum = $params->{'partnum'}; | ||
| 80 | $partnum = -1 if (not defined $partnum); | ||
| 81 | $rt .= gettexta("Upload new bag to show in the %0 part in <b>%1</b>.", | ||
| 82 | FAQ::OMatic::cardinal($partnum+1), | ||
| 83 | $itemTitle) | ||
| 84 | ."\n"; | ||
| 85 | } | ||
| 86 | |||
| 87 | $rt .= "<table>\n"; | ||
| 88 | $rt .= FAQ::OMatic::makeAref('-command'=>'submitBag', | ||
| 89 | '-params'=>$params, | ||
| 90 | '-refType'=>'POST', | ||
| 91 | '-multipart'=>1, | ||
| 92 | '-saveTransients'=>1); | ||
| 93 | if ($bagName ne '') { | ||
| 94 | $rt .= "<input type=hidden name=\"_bagName\" value=\"$bagName\" size=30>\n"; | ||
| 95 | } else { | ||
| 96 | $rt .= "<tr><td align=right valign=top>".gettext("Bag name:")."</td><td valign=top>" | ||
| 97 | ."<input type=text name=\"_bagName\" value=\"\" size=30>" | ||
| 98 | ."<br><i>".gettext("The bag name is used as a filename, so it is restricted to only contain letters, numbers, underscores (_), hyphens (-), and periods (.). It should also carry a meaningful extension (such as .gif) so that web browsers will know what to do with the data.") | ||
| 99 | ."</i><br>".gettext("Hint: Leave blank and Bag Data filename will be used.") | ||
| 100 | ."</td></tr>\n"; | ||
| 101 | } | ||
| 102 | $rt .= "<tr><td align=right>".gettext("Bag data:")."</td><td>" | ||
| 103 | ."<input type=file name=\"_bagData\"></td></tr>"; | ||
| 104 | |||
| 105 | if ($bagName eq ''){ | ||
| 106 | $rt .= "<tr><td align=right>".gettext("Inline (Images only):")."</td><td><input type=checkbox value=\"y\" name=\"_bagInline\"></td></tr>"; | ||
| 107 | } | ||
| 108 | |||
| 109 | if ($bagName ne '') { | ||
| 110 | $rt .= "<tr><td colspan=2 align=right>".gettext("(Leave blank to keep original bag data and change only the associated information below.)")."</td></tr>"; | ||
| 111 | } | ||
| 112 | |||
| 113 | $rt .= "<tr><td colspan=2>" | ||
| 114 | .gettext("If this bag is an image, fill in its dimensions.")."</td></tr>\n" | ||
| 115 | ."<td align=right>".gettext("Width:")."</td><td align=left>" | ||
| 116 | ."<input type=text name=\"_sizeWidth\" value=\"$sizeWidth\" size=6>\n" | ||
| 117 | .gettext("Height:")." " | ||
| 118 | ."<input type=text name=\"_sizeHeight\" value=\"$sizeHeight\" size=6>" | ||
| 119 | ."</td></tr>\n"; | ||
| 120 | |||
| 121 | $rt .= "<tr><td></td><td>" | ||
| 122 | ."<input type=submit name=\"_submit\" value=\"".gettext("Submit Changes")."\">\n"; | ||
| 123 | $rt .= "<input type=reset name=\"_reset\" value=\"".gettext("Revert")."\">\n" | ||
| 124 | ."</td></tr>\n"; | ||
| 125 | $rt .= "</form>\n"; | ||
| 126 | $rt .= "</table>\n"; | ||
| 127 | |||
| 128 | $rt .= FAQ::OMatic::pageFooter($params, ['help', 'faq']); | ||
| 129 | |||
| 130 | print $rt; | ||
| 131 | } | ||
| 132 | |||
| 133 | 1; | ||
| 134 | |||
| 135 | |||
| 136 | |||
| 137 | |||
| 138 | |||
| 139 | |||
| 140 |