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-11-07 09:10:41 +00:00
|
|
|
include("../inc/inc.Utils.php");
|
2022-11-09 05:40:50 +00:00
|
|
|
include("../inc/inc.LogInit.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
|
|
|
}
|
|
|
|
|
2020-02-18 08:45:59 +00:00
|
|
|
function getBaseData($colname, $coldata, $objdata) { /* {{{ */
|
|
|
|
$objdata[$colname] = $coldata;
|
|
|
|
return $objdata;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
function getAttributeData($attrdef, $coldata, $objdata) { /* {{{ */
|
|
|
|
$objdata['attributes'][$attrdef->getID()] = $coldata;
|
|
|
|
return $objdata;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
function getCategoryData($colname, $coldata, $objdata) { /* {{{ */
|
|
|
|
global $catids;
|
|
|
|
$kk = explode(',', $coldata);
|
2024-08-21 14:43:09 +00:00
|
|
|
$objdata['category'] = array();
|
2020-02-18 08:45:59 +00:00
|
|
|
foreach($kk as $k) {
|
|
|
|
if(isset($catids[$k]))
|
|
|
|
$objdata['category'][] = $catids[$k];
|
|
|
|
}
|
|
|
|
return $objdata;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
function getUserData($colname, $coldata, $objdata) { /* {{{ */
|
|
|
|
global $userids;
|
|
|
|
if(isset($userids[$coldata]))
|
|
|
|
$objdata['owner'] = $userids[$coldata];
|
|
|
|
return $objdata;
|
|
|
|
} /* }}} */
|
|
|
|
|
2019-07-30 04:34:16 +00:00
|
|
|
$metadata = array();
|
|
|
|
if(!empty($_GET["dropfolderfileform2"])) {
|
|
|
|
$metadatafile = realpath($settings->_dropFolderDir.'/'.$user->getLogin()."/".$_GET["dropfolderfileform2"]);
|
|
|
|
$csvdelim = ';';
|
|
|
|
$csvencl = '"';
|
|
|
|
if($fp = fopen($metadatafile, 'r')) {
|
|
|
|
$colmap = array();
|
|
|
|
if($header = fgetcsv($fp, 0, $csvdelim, $csvencl)) {
|
|
|
|
foreach($header as $i=>$colname) {
|
2020-02-18 08:45:59 +00:00
|
|
|
$colname = trim($colname);
|
|
|
|
if(in_array($colname, array('category'))) {
|
|
|
|
$colmap[$i] = array("getCategoryData", $colname);
|
|
|
|
} elseif(in_array($colname, array('owner'))) {
|
|
|
|
$colmap[$i] = array("getUserData", $colname);
|
2024-08-16 09:29:30 +00:00
|
|
|
} elseif(in_array($colname, array('filename', 'keywords', 'name', 'comment'))) {
|
2020-02-18 08:45:59 +00:00
|
|
|
$colmap[$i] = array("getBaseData", $colname);
|
|
|
|
} elseif(substr($colname, 0, 5) == 'attr:') {
|
|
|
|
$kk = explode(':', $colname, 2);
|
|
|
|
if(($attrdef = $dms->getAttributeDefinitionByName($kk[1])) || ($attrdef = $dms->getAttributeDefinition((int) $kk[1]))) {
|
|
|
|
$colmap[$i] = array("getAttributeData", $attrdef);
|
|
|
|
}
|
2019-07-30 04:34:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-21 14:43:54 +00:00
|
|
|
// echo "<pre>";var_dump($colmap);echo "</pre>";exit;
|
2019-07-30 04:34:16 +00:00
|
|
|
if(count($colmap) > 1) {
|
|
|
|
$nameprefix = dirname($dirname).'/';
|
|
|
|
$allcats = $dms->getDocumentCategories();
|
|
|
|
$catids = array();
|
|
|
|
foreach($allcats as $cat)
|
|
|
|
$catids[$cat->getName()] = $cat;
|
2020-02-18 08:45:59 +00:00
|
|
|
$allusers = $dms->getAllUsers();
|
|
|
|
$userids = array();
|
|
|
|
foreach($allusers as $muser)
|
|
|
|
$userids[$muser->getLogin()] = $muser;
|
2019-07-30 04:34:16 +00:00
|
|
|
while(!feof($fp)) {
|
|
|
|
if($data = fgetcsv($fp, 0, $csvdelim, $csvencl)) {
|
2020-02-18 08:45:59 +00:00
|
|
|
$md = array();
|
2020-02-21 08:59:58 +00:00
|
|
|
$md['attributes'] = array();
|
2020-02-18 08:45:59 +00:00
|
|
|
foreach($data as $i=>$coldata) {
|
|
|
|
if(isset($colmap[$i])) {
|
|
|
|
$md = call_user_func($colmap[$i][0], $colmap[$i][1], $coldata, $md);
|
|
|
|
}
|
|
|
|
}
|
2020-02-21 08:59:58 +00:00
|
|
|
if(!empty($md['filename']))
|
|
|
|
$metadata[$nameprefix.$md['filename']] = $md;
|
2019-07-30 04:34:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-21 08:59:58 +00:00
|
|
|
//echo "<pre>";print_r($metadata);echo "</pre>";
|
2019-07-30 04:34:16 +00:00
|
|
|
|
2018-09-18 16:31:15 +00:00
|
|
|
$setfiledate = false;
|
|
|
|
if(isset($_GET['setfiledate']) && $_GET["setfiledate"]) {
|
|
|
|
$setfiledate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$setfolderdate = false;
|
|
|
|
if(isset($_GET['setfolderdate']) && $_GET["setfolderdate"]) {
|
|
|
|
$setfolderdate = true;
|
|
|
|
}
|
|
|
|
|
2019-07-30 04:34:16 +00:00
|
|
|
function import_folder($dirname, $folder, $setfiledate, $setfolderdate, $metadata) { /* {{{ */
|
2024-08-21 14:44:19 +00:00
|
|
|
global $user, $doccount, $foldercount, $logger;
|
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();
|
|
|
|
$version_comment = '';
|
|
|
|
$reqversion = 1;
|
|
|
|
$expires = false;
|
|
|
|
$keywords = '';
|
|
|
|
$categories = array();
|
|
|
|
|
|
|
|
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
|
|
|
$mimetype = finfo_file($finfo, $path);
|
2019-08-27 19:47:05 +00:00
|
|
|
$lastDotIndex = strrpos($name, ".");
|
2016-03-08 17:35:39 +00:00
|
|
|
if (is_bool($lastDotIndex) && !$lastDotIndex) $filetype = ".";
|
2019-08-27 19:47:05 +00:00
|
|
|
else $filetype = substr($name, $lastDotIndex);
|
2016-03-08 17:35:39 +00:00
|
|
|
|
2020-02-21 08:59:58 +00:00
|
|
|
$docname = !empty($metadata[$path]['name']) ? $metadata[$path]['name'] : $name;
|
|
|
|
$comment = !empty($metadata[$path]['comment']) ? $metadata[$path]['comment'] : '';
|
|
|
|
$owner = !empty($metadata[$path]['owner']) ? $metadata[$path]['owner'] : $user;
|
|
|
|
|
2024-08-21 14:44:19 +00:00
|
|
|
// echo $mimetype." - ".$filetype." - ".$path."<br />\n";
|
|
|
|
if($logger)
|
|
|
|
$logger->log('ImportFS: importing \''.$path.'\' '.(!empty($metadata[$path]['attributes']) ? 'with' : 'without').' metadata', PEAR_LOG_INFO);
|
2020-02-21 08:59:58 +00:00
|
|
|
if($res = $folder->addDocument($docname, $comment, $expires, $owner, $keywords,
|
2020-10-15 11:30:34 +00:00
|
|
|
!empty($metadata[$path]['category']) ? $metadata[$path]['category'] : array(), $filetmp, $name,
|
2016-03-08 17:35:39 +00:00
|
|
|
$filetype, $mimetype, $sequence, $reviewers,
|
2020-02-21 08:59:58 +00:00
|
|
|
$approvers, $reqversion, $version_comment,
|
2020-10-15 11:30:34 +00:00
|
|
|
!empty($metadata[$path]['attributes']) ? $metadata[$path]['attributes'] : array())) {
|
2016-05-04 11:09:13 +00:00
|
|
|
$doccount++;
|
2018-09-18 16:31:15 +00:00
|
|
|
if($setfiledate) {
|
|
|
|
$newdoc = $res[0];
|
|
|
|
$newdoc->setDate(filemtime($path));
|
2018-09-25 06:54:25 +00:00
|
|
|
$lc = $newdoc->getLatestContent();
|
|
|
|
$lc->setDate(filemtime($path));
|
2018-09-18 16:31:15 +00:00
|
|
|
}
|
2024-08-21 14:44:19 +00:00
|
|
|
if($logger)
|
|
|
|
$logger->log('ImportFS: imported \''.$path.'\' as document '.$res[0]->getId(), PEAR_LOG_INFO);
|
2016-05-04 11:09:13 +00:00
|
|
|
} else {
|
2024-08-21 14:44:19 +00:00
|
|
|
if($logger)
|
|
|
|
$logger->log('ImportFS: importing \''.$path.'\' failed.', PEAR_LOG_ERR);
|
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++;
|
2018-09-18 16:31:15 +00:00
|
|
|
if($setfolderdate) {
|
|
|
|
$newfolder->setDate(filemtime($path));
|
|
|
|
}
|
2024-08-21 14:44:19 +00:00
|
|
|
if($logger)
|
|
|
|
$logger->log('ImportFS: creating folder \''.$path.'\' as folder '.$newfolder->getId(), PEAR_LOG_INFO);
|
2019-07-30 04:34:16 +00:00
|
|
|
if(!import_folder($path, $newfolder, $setfiledate, $setfolderdate, $metadata))
|
2016-05-04 11:09:13 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
2024-08-21 14:44:19 +00:00
|
|
|
if($logger)
|
|
|
|
$logger->log('ImportFS: creating folder \''.$path.'\' failed.', PEAR_LOG_ERR);
|
2016-05-04 11:09:13 +00:00
|
|
|
}
|
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;
|
2024-08-21 14:44:19 +00:00
|
|
|
if(!empty($_GET['createfolder'])) {
|
2024-08-16 09:29:30 +00:00
|
|
|
if($newfolder = $folder->addSubFolder($_GET["dropfolderfileform1"], '', $user, 1)) {
|
|
|
|
if($setfolderdate) {
|
|
|
|
$newfolder->setDate(filemtime($dirname));
|
|
|
|
}
|
2024-08-21 14:44:19 +00:00
|
|
|
if($logger)
|
|
|
|
$logger->log('ImportFS: creating folder \''.$_GET["dropfolderfileform1"].'\' as folder '.$newfolder->getId(), PEAR_LOG_INFO);
|
2024-08-16 09:29:30 +00:00
|
|
|
} else {
|
2024-08-21 14:44:19 +00:00
|
|
|
if($logger)
|
|
|
|
$logger->log('ImportFS: creating folder \''.$_GET["dropfolderfileform1"].'\' failed.', PEAR_LOG_ERR);
|
2018-09-18 16:31:15 +00:00
|
|
|
}
|
2024-08-16 09:29:30 +00:00
|
|
|
} else {
|
|
|
|
$newfolder = $folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($newfolder) {
|
2024-08-21 14:44:19 +00:00
|
|
|
if($logger) {
|
|
|
|
$logger->log('ImportFS: importing into folder '.$newfolder->getId(), PEAR_LOG_INFO);
|
|
|
|
if($metadata)
|
|
|
|
$logger->log('ImportFS: using metadata for '.count($metadata).' files from file \''.$metadatafile.'\'', PEAR_LOG_INFO);
|
|
|
|
}
|
2019-07-30 04:34:16 +00:00
|
|
|
if(!import_folder($dirname, $newfolder, $setfiledate, $setfolderdate, $metadata))
|
2016-05-04 11:09:13 +00:00
|
|
|
$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
|
|
|
}
|
2024-08-21 14:44:19 +00:00
|
|
|
} else {
|
|
|
|
$session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('error_importfs')));
|
2016-05-04 11:09:13 +00:00
|
|
|
}
|
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());
|