po/src/admin.volume.edit.2.php

73 lines
2.5 KiB
PHP

<?php
// Copyright (C) 2002-2006 Balint Kis (balint@k-i-s.net)
// Copyright (C) 2005-2013 Solomon Peachy (pizza@shaftnet.org)
// 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 3 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
include_once "include/config.php";
include_once "include/admin.php";
include_once "include/site.php";
$database = site_prolog(PO_USER_TYPE_ADMIN);
$volume = pg_escape_string($database, $_REQUEST['volume']);
$new_volume = pg_escape_string($database, $_REQUEST['new_volume']);
$current = pg_escape_string($database, $_REQUEST['current']);
$result = TRUE;
if (($handle = opendir($image_repository_path . "/" . $volume)) == FALSE) {
site_push_error($strings['errors_cant_open_volume']);
header("Location: admin.php?selector=".$admin_data['repository']['idx']);
site_epilog($database);
exit();
}
closedir($handle);
/* update current volume */
if ($result && ($current == 't')) {
unlink($image_repository_path."/current");
$result = po_symlink($new_volume, "$image_repository_path/current");
if (!$result) {
site_push_error($strings['errors_cant_link_volume']);
}
}
if ($result && ($new_volume != $volume)) {
pg_query($database, "begin");
$result = pg_query($database, "
update files
set path = ('$new_volume' || (substr(path, char_length('$volume') + 1)))
where '$volume' = substr(path, 0, char_length('$volume') +1 )");
if ($result) {
if (!rename($image_repository_path . "/" . $volume, $image_repository_path . "/" . $new_volume)) {
site_push_error($strings['errors_cant_rename_volume']);
pg_query($database, "rollback");
} else {
pg_query($database, "commit");
}
} else {
site_push_error($strings['errors_db_insert_failed']);
pg_query($database, "rollback");
}
}
site_epilog($database);
header("Location: admin.php?selector=".$admin_data['repository']['idx']);
?>