OMatic/moveItem.pm untested

filter: Statementstmt 0.0% 0 / 84 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 130 CC 15 SCAR 51.0
CC
15
Cov
0%
main
240.0
BEGIN
2.0
BEGIN
2.0
CRAP 164.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::moveItem;
31  
32 use CGI;
33 use FAQ::OMatic::Item;
34 use FAQ::OMatic;
35 use FAQ::OMatic::Auth;
36 use FAQ::OMatic::HelpMod;
37 use FAQ::OMatic::I18N;
38  
39 sub main {
40 my $cgi = FAQ::OMatic::dispatch::cgi();
41
42 my $params = FAQ::OMatic::getParams($cgi);
43  
44 FAQ::OMatic::mirrorsCantEdit($cgi, $params);
45
46 my $rt = FAQ::OMatic::pageHeader($params, ['help', 'faq']);
47
48 my $item = new FAQ::OMatic::Item($params->{'file'});
49 if ($item->isBroken()) {
50 FAQ::OMatic::gripe('error', gettexta("The file (%0) doesn't exist.", $params->{'file'}));
51 }
52  
53 FAQ::OMatic::Auth::ensurePerm('-item'=>$item,
54 '-operation'=>'PermEditDirectory',
55 '-restart'=>'moveItem',
56 '-cgi'=>$cgi,
57 '-failexit'=>1);
58  
59 my $anyPermProblems = 0; # so we can make a note later
60 my $authFailed;
61 my %itemSet = ();
62 my $clickable;
63  
64 my ($filei, $itemi);
65 foreach $filei (FAQ::OMatic::getAllItemNames()) {
66 next if ($item->isEmptyStub());
67  
68 # I can't be my own parent
69 next if ($filei eq $item->{'filename'});
70  
71 # No point in moving to our current parent
72 next if ($filei eq $item->{'Parent'});
73  
74 # take a peek at the potential target
75 $itemi = new FAQ::OMatic::Item($filei);
76  
77 # Can't move to a descendent, or we'd break the tree apart.
78 next if ($itemi->hasParent($params->{'file'}));
79  
80 # Don't show items with no other kids already unless asked
81 next if ((not $params->{'showBarrenItems'})
82 and (not defined $itemi->{'directoryHint'})
83 and (not $itemi->{'filename'} eq 'trash'));
84  
85 $authFailed = FAQ::OMatic::Auth::checkPerm($itemi,'PermAddItem');
86 # need only the weaker PermAddItem for destination category
87 if ($authFailed) {
88 $anyPermProblems = 1;
89 $clickable = 0;
90 next;
91 } else {
92 $clickable = 1;
93 }
94  
95 my ($titles, $filenames) = $itemi->getParentChain();
96 my $fullname = join(":", reverse @{$titles});
97 my $display = '';
98 if ($clickable) {
99 $display .=
100 FAQ::OMatic::makeAref('submitMove', {'_newParent'=>$filei});
101 }
102 $display .= $fullname;
103 $display .= "</a>" if ($clickable);
104 $display .= "<br>\n";
105 if ($fullname =~ m/^Trash/) {
106 # sort trash items at end.
107 $itemSet{'9'.$fullname} = $display;
108 } else {
109 $itemSet{'0'.$fullname} = $display;
110 }
111 }
112  
113 if (scalar %itemSet) {
114 $rt .= gettexta("Make <b>%0</b> belong to which other item?", $item->getTitle())
115 ."<p>\n";
116 $rt .= join("\n", map {$itemSet{$_}} (sort keys (%itemSet)));
117 } elsif (not $params->{'showBarrenItems'}) {
118 $rt .= gettext("No item that already has sub-items can become the parent of")." <b>".$item->getTitle()."</b>.\n";
119 } else {
120 $rt .= gettext("No item can become the parent of")." <b>"
121 .$item->getTitle()."</b>.\n";
122 }
123 if ($anyPermProblems) {
124 $rt.= "<p>".gettext("Some destinations are not available (not clickable) because you do not have permission to edit them as currently authorized.")."\n";
125 $rt.=FAQ::OMatic::makeAref('authenticate',
126 {'_restart'=>FAQ::OMatic::commandName(), '_reason'=>$authFailed});
127 $rt.=gettext("Click here</a> to provide better authentication.")."\n";
128 }
129  
130 $rt .= "<p>";
131 if ($params->{'showBarrenItems'}) {
132 $rt .= FAQ::OMatic::button(FAQ::OMatic::makeAref('moveItem',
133 {'showBarrenItems'=>''}), gettext("Hide answers, show only categories"))."\n";
134 } else {
135 $rt .= FAQ::OMatic::button(FAQ::OMatic::makeAref('moveItem',
136 {'showBarrenItems'=>'1'}), gettext("Show both categories and answers"))."\n";
137 }
138 $rt.="<br>\n";
139 # $rt .= FAQ::OMatic::button(FAQ::OMatic::makeAref('faq', {}),
140 # "Cancel and return to FAQ")."\n";
141  
142 $rt .= FAQ::OMatic::HelpMod::helpFor($params, 'moveItem');
143  
144 print $rt;
145  
146 print FAQ::OMatic::pageFooter($params, ['help', 'faq']);
147 }
148  
149 1;
150  
151