OMatic/selectBag.pm untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 74 CC 3 SCAR 16.7
CC
3
Cov
0%
main
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 5.3
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::selectBag;
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 FAQ::OMatic::Auth::ensurePerm('-item'=>'',
47 '-operation'=>'PermReplaceBag',
48 '-restart'=>FAQ::OMatic::commandName(),
49 '-cgi'=>$cgi,
50 '-xreason'=>'replace',
51 '-failexit'=>1);
52
53 $rt = FAQ::OMatic::pageHeader($params, ['help', 'faq']);
54
55 my @bagList = (); # list to choose from
56 my $file = $params->{'file'};
57 if (defined $file) {
58 my $item = new FAQ::OMatic::Item($file);
59 if ($item->isBroken()) {
60 FAQ::OMatic::gripe('error', gettexta("The file (%0) doesn't exist.", $file));
61 }
62 @bagList = $item->getBags();
63 } else {
64 # browse every bag in the system.
65 @bagList = grep { not m/\.desc$/ }
66 FAQ::OMatic::getAllItemNames($FAQ::OMatic::Config::bagsDir);
67 }
68  
69 $rt .= "<h3>".gettext("Replace which bag?")."</h3>\n";
70  
71 # display bags in a few columns.
72 my $numcols = 3;
73 my $bagsInCol = int((scalar(@bagList)+$numcols-1)/$numcols);
74  
75 $rt .= "<table><tr>\n";
76 my $col;
77 for ($col=0; $col<3; $col++) {
78 my $bagnum;
79 $rt .= " <td valign=top>\n";
80 for ($bagnum=$col*$bagsInCol;
81 $bagnum<($col+1)*$bagsInCol && $bagnum < scalar(@bagList);
82 $bagnum++) {
83 $rt .= " <br>"
84 .FAQ::OMatic::button(
85 FAQ::OMatic::makeAref('-command'=>'editBag',
86 '-params'=>$params,
87 '-changedParams'=>{'_target'=>$bagList[$bagnum]}),
88 "$bagList[$bagnum]")
89 ."\n";
90 }
91 $rt .= " </td>\n";
92 }
93 $rt .= "</tr></table>\n";
94  
95 $rt .= FAQ::OMatic::pageFooter($params, ['help', 'faq']);
96  
97 print $rt;
98 }
99  
100 1;