1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
##############################################################################
# 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::submitMove;
use CGI;
use FAQ::OMatic::Item;
use FAQ::OMatic;
use FAQ::OMatic::Auth;
use FAQ::OMatic::I18N;
sub main {
my $cgi = FAQ::OMatic::dispatch::cgi();
my $params = FAQ::OMatic::getParams($cgi);
FAQ::OMatic::mirrorsCantEdit($cgi, $params);
my $movingFilename = $params->{'file'};
my $newParentFilename = $params->{'_newParent'};
# load up the moving file and the new parent
my $movingItem = new FAQ::OMatic::Item($movingFilename);
if ($movingItem->isBroken()) {
FAQ::OMatic::gripe('error',
gettexta("The moving file (%0) is broken or missing.",
$movingFilename));
}
my $newParentItem = new FAQ::OMatic::Item($newParentFilename);
if ($newParentItem->isBroken()) {
FAQ::OMatic::gripe('error',
gettexta("The newParent file (%0) is broken or missing.",
$newParentFilename));
}
# load up the old parent
my $oldParentFilename = $movingItem->{'Parent'};
my $oldParentItem = new FAQ::OMatic::Item($oldParentFilename);
if ($oldParentItem->isBroken()) {
FAQ::OMatic::gripe('error',
gettexta("The oldParent file (%0) is broken or missing.",
$oldParentFilename));
}
# make sure the new parent isn't the old parent or
# the moving item itself
if ($newParentFilename eq $oldParentFilename) {
FAQ::OMatic::gripe('error',
gettexta("The new parent (%0) is the same as the old parent.",
$newParentItem->getTitle()));
}
if ($newParentFilename eq $movingFilename) {
FAQ::OMatic::gripe('error',
gettexta("The new parent (%0) is the same as the item you want to move.",
$newParentItem->getTitle()));
}
# make sure the new parent isn't a child of movingItem
if ($newParentItem->hasParent($movingFilename)) {
FAQ::OMatic::gripe('error',
gettexta("The new parent (%0) is a child of the item being moved (%1).",
$newParentItem->getTitle(), $movingItem->getTitle()));
}
if ($movingItem->{'filename'} eq '1') {
FAQ::OMatic::gripe('error',
gettext("You can't move the top item."));
}
# check permissions on the parents to see that the move is legal
# we need to check more than a single permission, and want
# to return the error corresponding to the greater of the two.
my ($url1,$aq1) =
FAQ::OMatic::Auth::ensurePerm($oldParentItem, 'PermEditDirectory',
'submitMove', $cgi, 1);
my ($url2,$aq2) =
FAQ::OMatic::Auth::ensurePerm($newParentItem, 'PermAddItem',
'submitMove', $cgi, 1);
# If both ends of the move are not authorized, demand authentication
# at the higher of the two levels
if ($url1 and $url2) {
FAQ::OMatic::redirect($cgi, ($aq1 > $aq2) ? $url1 : $url2 );
} elsif ($url1) {
FAQ::OMatic::redirect($cgi, $url1);
} elsif ($url2) {
FAQ::OMatic::redirect($cgi, $url2);
}
# don't remove an item from itself if it's a root (own parent)
if ($oldParentItem ne $movingItem) {
$oldParentItem->removeSubItem($movingFilename);
}
$newParentItem->addSubItem($movingFilename);
$movingItem->setProperty('Parent', $newParentFilename);
$oldParentItem->saveToFile();
$newParentItem->saveToFile();
$movingItem->saveToFile();
my $oldModerator =
FAQ::OMatic::Auth::getInheritedProperty($oldParentItem, 'Moderator');
my $newModerator =
FAQ::OMatic::Auth::getInheritedProperty($newParentItem, 'Moderator');
$oldParentItem->notifyModerator($cgi, gettexta("moved a sub-item to %0",
$newParentItem->getTitle()));
if ($newModerator ne $oldModerator) {
$newParentItem->notifyModerator($cgi, gettexta("moved a sub-item from %0",
$oldParentItem->getTitle()));
}
# If user clicked "trash this item," they probably don't want
# to go see it in the trash.
my $target = ($newParentFilename ne 'trash')
? $newParentFilename
: $oldParentFilename;
my $url = FAQ::OMatic::makeAref('faq', {'file'=>$target}, 'url');
FAQ::OMatic::redirect($cgi, $url);
}
1;
|