2016-03-08 17:35:39 +00:00
|
|
|
<?php
|
2016-08-09 05:08:27 +00:00
|
|
|
// SeedDMS. Document Management System
|
2016-08-09 05:34:30 +00:00
|
|
|
// Copyright (C) 2010-2016 Uwe Steinmann
|
2016-08-09 05:08:27 +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.
|
|
|
|
|
2016-03-08 17:35:39 +00:00
|
|
|
include("../inc/inc.Settings.php");
|
2016-07-06 11:04:19 +00:00
|
|
|
include("../inc/inc.LogInit.php");
|
2016-11-07 09:10:41 +00:00
|
|
|
include("../inc/inc.Utils.php");
|
2016-07-06 11:04:19 +00:00
|
|
|
include("../inc/inc.Language.php");
|
|
|
|
include("../inc/inc.Init.php");
|
2016-11-07 09:10:41 +00:00
|
|
|
include("../inc/inc.Extension.php");
|
2016-03-08 17:35:39 +00:00
|
|
|
include("../inc/inc.DBInit.php");
|
|
|
|
include("../inc/inc.ClassUI.php");
|
|
|
|
include("../inc/inc.Authentication.php");
|
|
|
|
|
|
|
|
if (!isset($_GET["targetid"]) || !is_numeric($_GET["targetid"]) || $_GET["targetid"]<1) {
|
|
|
|
UI::exitError(getMLText("admin_tools"),getMLText("invalid_target_folder"));
|
|
|
|
}
|
|
|
|
$targetid = $_GET["targetid"];
|
|
|
|
$folder = $dms->getFolder($targetid);
|
|
|
|
if (!is_object($folder)) {
|
2016-05-04 11:09:13 +00:00
|
|
|
UI::exitError(getMLText("admin_tools"),getMLText("invalid_target_folder"));
|
2016-03-08 17:35:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($folder->getAccessMode($user) < M_READWRITE) {
|
|
|
|
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($_GET["dropfolderfileform1"])) {
|
|
|
|
UI::exitError(getMLText("admin_tools"),getMLText("invalid_target_folder"));
|
|
|
|
}
|
2017-02-03 11:21:51 +00:00
|
|
|
|
|
|
|
$dirname = realpath($settings->_dropFolderDir.'/'.$user->getLogin()."/".$_GET["dropfolderfileform1"]);
|
|
|
|
if(strpos($dirname, realpath($settings->_dropFolderDir.'/'.$user->getLogin().'/')) !== 0 || !is_dir($dirname)) {
|
2016-07-06 07:06:09 +00:00
|
|
|
UI::exitError(getMLText("admin_tools"),getMLText("invalid_dropfolder_folder"));
|
2016-03-08 17:35:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function import_folder($dirname, $folder) { /* {{{ */
|
2016-05-04 11:09:13 +00:00
|
|
|
global $user, $doccount, $foldercount;
|
2016-03-08 17:35:39 +00:00
|
|
|
|
|
|
|
$d = dir($dirname);
|
|
|
|
$sequence = 1;
|
|
|
|
while(false !== ($entry = $d->read())) {
|
|
|
|
$path = $dirname.'/'.$entry;
|
|
|
|
if($entry != '.' && $entry != '..' && $entry != '.svn') {
|
|
|
|
if(is_file($path)) {
|
2018-03-31 12:38:27 +00:00
|
|
|
$name = utf8_basename($path);
|
2016-03-08 17:35:39 +00:00
|
|
|
$filetmp = $path;
|
|
|
|
|
|
|
|
$reviewers = array();
|
|
|
|
$approvers = array();
|
|
|
|
$comment = '';
|
|
|
|
$version_comment = '';
|
|
|
|
$reqversion = 1;
|
|
|
|
$expires = false;
|
|
|
|
$keywords = '';
|
|
|
|
$categories = array();
|
|
|
|
|
|
|
|
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
|
|
|
$mimetype = finfo_file($finfo, $path);
|
|
|
|
$lastDotIndex = strrpos($path, ".");
|
|
|
|
if (is_bool($lastDotIndex) && !$lastDotIndex) $filetype = ".";
|
|
|
|
else $filetype = substr($path, $lastDotIndex);
|
|
|
|
|
2016-05-04 11:09:13 +00:00
|
|
|
// echo $mimetype." - ".$filetype." - ".$path."\n";
|
|
|
|
if($res = $folder->addDocument($name, $comment, $expires, $user, $keywords,
|
2016-03-08 17:35:39 +00:00
|
|
|
$categories, $filetmp, $name,
|
|
|
|
$filetype, $mimetype, $sequence, $reviewers,
|
2016-05-04 11:09:13 +00:00
|
|
|
$approvers, $reqversion, $version_comment)) {
|
|
|
|
$doccount++;
|
|
|
|
} else {
|
|
|
|
return false;
|
2016-03-08 17:35:39 +00:00
|
|
|
}
|
2016-05-04 11:09:13 +00:00
|
|
|
set_time_limit(30);
|
2016-03-08 17:35:39 +00:00
|
|
|
} elseif(is_dir($path)) {
|
2018-03-31 12:38:27 +00:00
|
|
|
$name = utf8_basename($path);
|
2016-05-04 11:09:13 +00:00
|
|
|
if($newfolder = $folder->addSubFolder($name, '', $user, $sequence)) {
|
|
|
|
$foldercount++;
|
|
|
|
if(!import_folder($path, $newfolder))
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-08 17:35:39 +00:00
|
|
|
}
|
|
|
|
$sequence++;
|
|
|
|
}
|
|
|
|
}
|
2016-05-04 11:09:13 +00:00
|
|
|
return true;
|
2016-03-08 17:35:39 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
2016-05-04 11:09:13 +00:00
|
|
|
$foldercount = $doccount = 0;
|
|
|
|
if($newfolder = $folder->addSubFolder($_GET["dropfolderfileform1"], '', $user, 1)) {
|
|
|
|
if(!import_folder($dirname, $newfolder))
|
|
|
|
$session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('error_importfs')));
|
2017-02-03 11:21:51 +00:00
|
|
|
else {
|
|
|
|
if(isset($_GET['remove']) && $_GET["remove"]) {
|
|
|
|
$cmd = 'rm -rf '.$dirname;
|
|
|
|
$ret = null;
|
|
|
|
system($cmd, $ret);
|
|
|
|
}
|
2016-05-04 11:09:13 +00:00
|
|
|
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_importfs', array('docs'=>$doccount, 'folders'=>$foldercount))));
|
2017-02-03 11:21:51 +00:00
|
|
|
}
|
2016-05-04 11:09:13 +00:00
|
|
|
} else {
|
|
|
|
$session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('error_importfs')));
|
|
|
|
}
|
2016-03-08 17:35:39 +00:00
|
|
|
|
2016-05-04 11:09:13 +00:00
|
|
|
header("Location:../out/out.ViewFolder.php?folderid=".$newfolder->getID());
|