2016-03-09 06:51:35 +00:00
|
|
|
<?php
|
|
|
|
// MyDMS. Document Management System
|
|
|
|
// Copyright (C) 2002-2005 Markus Westphal
|
|
|
|
// Copyright (C) 2006-2008 Malcolm Cowe
|
2016-08-09 05:34:30 +00:00
|
|
|
// Copyright (C) 2010-2016 Uwe Steinmann
|
2016-03-09 06:51:35 +00:00
|
|
|
//
|
|
|
|
// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
include("../inc/inc.Settings.php");
|
2022-11-09 05:40:50 +00:00
|
|
|
include("../inc/inc.Utils.php");
|
2016-03-09 06:51:35 +00:00
|
|
|
include("../inc/inc.LogInit.php");
|
2016-11-02 12:40:31 +00:00
|
|
|
include("../inc/inc.Language.php");
|
|
|
|
include("../inc/inc.Init.php");
|
|
|
|
include("../inc/inc.Extension.php");
|
2016-03-09 06:51:35 +00:00
|
|
|
include("../inc/inc.DBInit.php");
|
|
|
|
include("../inc/inc.ClassUI.php");
|
|
|
|
include("../inc/inc.Authentication.php");
|
|
|
|
|
2019-11-25 08:32:32 +00:00
|
|
|
$accessop = new SeedDMS_AccessOperation($dms, $user, $settings);
|
|
|
|
if (!$accessop->check_controller_access('EditOnline', $_POST)) {
|
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('access_denied')));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2016-03-09 06:51:35 +00:00
|
|
|
if (!isset($_POST["documentid"]) || !is_numeric($_POST["documentid"]) || intval($_POST["documentid"])<1) {
|
2019-11-25 08:32:32 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_doc_id')));
|
|
|
|
exit;
|
2016-03-09 06:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$documentid = $_POST["documentid"];
|
|
|
|
$document = $dms->getDocument($documentid);
|
|
|
|
|
|
|
|
if (!is_object($document)) {
|
2019-11-25 08:32:32 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('invalid_doc_id')));
|
|
|
|
exit;
|
2016-03-09 06:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$folder = $document->getFolder();
|
|
|
|
$docPathHTML = getFolderPathHTML($folder, true). " / <a href=\"../out/out.ViewDocument.php?documentid=".$documentid."\">".$document->getName()."</a>";
|
|
|
|
|
2018-07-12 20:36:44 +00:00
|
|
|
if ($document->getAccessMode($user, 'editOnline') < M_READWRITE) {
|
2019-11-25 08:32:32 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('access_denied')));
|
|
|
|
exit;
|
2016-03-09 06:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if($document->isLocked()) {
|
|
|
|
$lockingUser = $document->getLockingUser();
|
2018-07-12 20:36:44 +00:00
|
|
|
if (($lockingUser->getID() != $user->getID()) && ($document->getAccessMode($user, 'editOnline') != M_ALL)) {
|
2019-11-25 08:32:32 +00:00
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText("lock_message", array("email" => $lockingUser->getEmail(), "username" => htmlspecialchars($lockingUser->getFullName())))));
|
|
|
|
exit;
|
2016-03-09 06:51:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$tmpfname = tempnam(sys_get_temp_dir(), 'FOO');
|
|
|
|
file_put_contents($tmpfname, $_POST['data']);
|
|
|
|
|
|
|
|
/* Check if the uploaded file is identical to last version */
|
|
|
|
$lc = $document->getLatestContent();
|
|
|
|
if($lc->getChecksum() == SeedDMS_Core_File::checksum($tmpfname)) {
|
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('identical_version')));
|
|
|
|
} else {
|
|
|
|
if($document->replaceContent(0, $user, $tmpfname, $lc->getOriginalFileName(), $lc->getFileType(), $lc->getMimeType())) {
|
2016-03-09 16:57:14 +00:00
|
|
|
if($notifier) {
|
2021-05-21 07:14:55 +00:00
|
|
|
$notifier->sendReplaceContentMail($lc, $user);
|
2016-03-09 16:57:14 +00:00
|
|
|
}
|
2016-03-09 06:51:35 +00:00
|
|
|
echo json_encode(array('success'=>true, 'message'=>getMLText('splash_saved_file')));
|
|
|
|
} else {
|
|
|
|
echo json_encode(array('success'=>false, 'message'=>getMLText('splash_error_saving_file')));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unlink($tmpfname);
|