Merge branch 'seeddms-5.1.x' into seeddms-6.0.x

This commit is contained in:
Uwe Steinmann 2017-12-21 15:27:33 +01:00
commit 3cd766468d
3 changed files with 1509 additions and 1178 deletions

View File

@ -2204,7 +2204,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
$link = new SeedDMS_Core_DocumentLink($resArr["id"], $document, $target, $resArr["userID"], $resArr["public"]);
$user = $this->_dms->getLoggedInUser();
if($link->getAccessMode($user, $document, $target) >= M_READ)
return $file;
return $link;
return null;
} /* }}} */

File diff suppressed because it is too large Load Diff

View File

@ -5,12 +5,6 @@ include("../inc/inc.Settings.php");
include("../inc/inc.Extension.php");
include("../inc/inc.Init.php");
include("../inc/inc.DBInit.php");
//require_once "SeedDMS/Core.php";
require_once "SeedDMS/Preview.php";
//$db = new SeedDMS_Core_DatabaseAccess($settings->_dbDriver, $settings->_dbHostname, $settings->_dbUser, $settings->_dbPass, $settings->_dbDatabase);
//$db->connect() or die ("Could not connect to db-server \"" . $settings->_dbHostname . "\"");
//$dms = new SeedDMS_Core_DMS($db, $settings->_contentDir.$settings->_contentOffsetDir);
if(USE_PHP_SESSION) {
session_start();
@ -55,10 +49,63 @@ if(USE_PHP_SESSION) {
}
}
#require 'Slim/Slim.php';
require "vendor/autoload.php";
#\Slim\Slim::registerAutoloader();
function __getLatestVersionData($lc) { /* {{{ */
$document = $lc->getDocument();
$data = array(
'type'=>'document',
'id'=>(int)$document->getId(),
'date'=>date('Y-m-d H:i:s', $document->getDate()),
'name'=>$document->getName(),
'comment'=>$document->getComment(),
'keywords'=>$document->getKeywords(),
'mimetype'=>$lc->getMimeType(),
'version'=>$lc->getVersion(),
'size'=>$lc->getFileSize(),
);
$cats = $document->getCategories();
if($cats) {
$c = array();
foreach($cats as $cat) {
$c[] = array('id'=>(int)$cat->getID(), 'name'=>$cat->getName());
}
$data['categories'] = $c;
}
$attributes = $document->getAttributes();
if($attributes) {
$attrvalues = array();
foreach($attributes as $attrdefid=>$attribute)
$attrvalues[] = array('id'=>(int)$attrdefid, 'value'=>$attribute->getValue());
$data['attributes'] = $attrvalues;
}
$attributes = $lc->getAttributes();
if($attributes) {
$attrvalues = array();
foreach($attributes as $attrdefid=>$attribute)
$attrvalues[] = array('id'=>(int)$attrdefid, 'value'=>$attribute->getValue());
$data['version-attributes'] = $attrvalues;
}
return $data;
} /* }}} */
function __getFolderData($folder) { /* {{{ */
$data = array(
'type'=>'folder',
'id'=>$folder->getID(),
'name'=>$folder->getName(),
'comment'=>$folder->getComment(),
'date'=>date('Y-m-d H:i:s', $folder->getDate()),
);
$attributes = $folder->getAttributes();
if($attributes) {
$attrvalues = array();
foreach($attributes as $attrdefid=>$attribute)
$attrvalues[] = array('id'=>(int)$attrdefid, 'value'=>$attribute->getValue());
$data['attributes'] = $attrvalues;
}
return $data;
} /* }}} */
function doLogin() { /* {{{ */
global $app, $dms, $userobj, $session, $settings;
@ -67,7 +114,23 @@ function doLogin() { /* {{{ */
$password = $app->request()->post('pass');
$userobj = $dms->getUserByLogin($username);
if(!$userobj || md5($password) != $userobj->getPwd()) {
$user = null;
/* Authenticate against LDAP server {{{ */
if (!$user && isset($settings->_ldapHost) && strlen($settings->_ldapHost)>0) {
require_once("../inc/inc.ClassLdapAuthentication.php");
$authobj = new SeedDMS_LdapAuthentication($dms, $settings);
$user = $authobj->authenticate($username, $password);
} /* }}} */
/* Authenticate against SeedDMS database {{{ */
if(!$user) {
require_once("../inc/inc.ClassDbAuthentication.php");
$authobj = new SeedDMS_DbAuthentication($dms, $settings);
$user = $authobj->authenticate($username, $password);
} /* }}} */
if(!$user) {
if(USE_PHP_SESSION) {
unset($_SESSION['userid']);
} else {
@ -115,8 +178,11 @@ function setFullName() { /* {{{ */
if(!$userobj) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Not logged in', 'data'=>''));
return;
}
$userobj->setFullName($app->request()->put('fullname'));
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$userobj->getFullName()));
} /* }}} */
@ -126,8 +192,11 @@ function setEmail($id) { /* {{{ */
if(!$userobj) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Not logged in', 'data'=>''));
return;
}
$userobj->setEmail($app->request()->put('fullname'));
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$userid));
} /* }}} */
@ -136,19 +205,12 @@ function getLockedDocuments() { /* {{{ */
if(false !== ($documents = $dms->getDocumentsLockedByUser($userobj))) {
$documents = SeedDMS_Core_DMS::filterAccess($documents, $userobj, M_READ);
$recs = array();
foreach($documents as $document) {
$lc = $document->getLatestContent();
$recs[] = array(
'type'=>'document',
'id'=>$document->getId(),
'date'=>$document->getDate(),
'name'=>$document->getName(),
'mimetype'=>$lc->getMimeType(),
'version'=>$lc->getVersion(),
'size'=>$lc->getFileSize(),
'comment'=>$document->getComment(),
'keywords'=>$document->getKeywords(),
);
if($lc) {
$recs[] = __getLatestVersionData($lc);
}
}
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$recs));
@ -158,10 +220,13 @@ function getLockedDocuments() { /* {{{ */
}
} /* }}} */
function getFolder($id) { /* {{{ */
global $app, $dms, $userobj;
function getFolder($id = null) { /* {{{ */
global $app, $dms, $userobj, $settings;
$forcebyname = $app->request()->get('forcebyname');
if(is_numeric($id) && empty($forcebyname))
if ($id === null)
$folder = $dms->getFolder($settings->_rootFolderID);
else if(is_numeric($id) && empty($forcebyname))
$folder = $dms->getFolder($id);
else {
$parentid = $app->request()->get('parentid');
@ -169,11 +234,8 @@ function getFolder($id) { /* {{{ */
}
if($folder) {
if($folder->getAccessMode($userobj) >= M_READ) {
$data = __getFolderData($folder);
$app->response()->header('Content-Type', 'application/json');
$data = array(
'id'=>$folder->getID(),
'name'=>$folder->getName()
);
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$data));
} else {
$app->response()->status(404);
@ -186,20 +248,24 @@ function getFolder($id) { /* {{{ */
function getFolderParent($id) { /* {{{ */
global $app, $dms, $userobj;
if($id == 0) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'id is 0', 'data'=>''));
return;
}
$root = $dms->getRootFolder();
if($root->getId() == $id) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'id is root folder', 'data'=>''));
return;
}
$folder = $dms->getFolder($id);
$parent = $folder->getParent();
if($parent) {
$rec = array('type'=>'folder', 'id'=>$parent->getId(), 'name'=>$parent->getName());
$rec = __getFolderData($parent);
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$rec));
} else {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'', 'data'=>''));
}
} /* }}} */
@ -207,6 +273,7 @@ function getFolderParent($id) { /* {{{ */
function getFolderPath($id) { /* {{{ */
global $app, $dms, $userobj;
if($id == 0) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'id is 0', 'data'=>''));
return;
}
@ -215,8 +282,9 @@ function getFolderPath($id) { /* {{{ */
$path = $folder->getPath();
$data = array();
foreach($path as $element) {
$data[] = array('id'=>$element->getId(), 'name'=>htmlspecialchars($element->getName()));
$data[] = array('id'=>$element->getId(), 'name'=>$element->getName());
}
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$data));
} /* }}} */
@ -247,7 +315,7 @@ function getFolderChildren($id) { /* {{{ */
global $app, $dms, $userobj;
if($id == 0) {
$folder = $dms->getRootFolder();
$recs = array(array('type'=>'folder', 'id'=>$folder->getId(), 'name'=>$folder->getName()));
$recs = array(__getFolderData($folder));
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$recs));
} else {
@ -258,30 +326,14 @@ function getFolderChildren($id) { /* {{{ */
$subfolders = $folder->getSubFolders();
$subfolders = SeedDMS_Core_DMS::filterAccess($subfolders, $userobj, M_READ);
foreach($subfolders as $subfolder) {
$recs[] = array(
'type'=>'folder',
'id'=>$subfolder->getId(),
'name'=>htmlspecialchars($subfolder->getName()),
'comment'=>$subfolder->getComment(),
'date'=>$subfolder->getDate(),
);
$recs[] = __getFolderData($subfolder);
}
$documents = $folder->getDocuments();
$documents = SeedDMS_Core_DMS::filterAccess($documents, $userobj, M_READ);
foreach($documents as $document) {
$lc = $document->getLatestContent();
if($lc) {
$recs[] = array(
'type'=>'document',
'id'=>$document->getId(),
'date'=>$document->getDate(),
'name'=>htmlspecialchars($document->getName()),
'mimetype'=>$lc->getMimeType(),
'version'=>$lc->getVersion(),
'size'=>$lc->getFileSize(),
'comment'=>$document->getComment(),
'keywords'=>$document->getKeywords(),
);
$recs[] = __getLatestVersionData($lc);
}
}
$app->response()->header('Content-Type', 'application/json');
@ -302,9 +354,11 @@ function createFolder($id) { /* {{{ */
if(!$userobj) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Not logged in', 'data'=>''));
return;
}
if($id == 0) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'id is 0', 'data'=>''));
return;
}
@ -314,39 +368,45 @@ function createFolder($id) { /* {{{ */
$comment = $app->request()->post('comment');
$attributes = $app->request()->post('attributes');
$newattrs = array();
if($attributes) {
foreach($attributes as $attrname=>$attrvalue) {
$attrdef = $dms->getAttributeDefinitionByName($attrname);
if($attrdef) {
$newattrs[$attrdef->getID()] = $attrvalue;
}
}
}
if($folder = $parent->addSubFolder($name, $comment, $userobj, 0, $newattrs)) {
$rec = array('id'=>$folder->getId(), 'name'=>$folder->getName(), 'comment'=>$folder->getComment());
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$rec));
} else {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'', 'data'=>''));
}
} else {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'', 'data'=>''));
}
} else {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'', 'data'=>''));
}
} /* }}} */
function moveFolder($id) { /* {{{ */
function moveFolder($id, $folderid) { /* {{{ */
global $app, $dms, $userobj;
if(!$userobj) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Not logged in', 'data'=>''));
return;
}
$mfolder = $dms->getFolder($id);
if($mfolder) {
if ($mfolder->getAccessMode($userobj) >= M_READ) {
$folderid = $app->request()->post('dest');
if($folder = $dms->getFolder($folderid)) {
if($folder->getAccessMode($userobj) >= M_READWRITE) {
if($mfolder->setParent($folder)) {
@ -380,9 +440,11 @@ function deleteFolder($id) { /* {{{ */
if(!$userobj) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Not logged in', 'data'=>''));
return;
}
if($id == 0) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'id is 0', 'data'=>''));
return;
}
@ -412,9 +474,76 @@ function uploadDocument($id) { /* {{{ */
if(!$userobj) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Not logged in', 'data'=>''));
return;
}
if($id == 0) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'id is 0', 'data'=>''));
return;
}
$mfolder = $dms->getFolder($id);
if($mfolder) {
if ($mfolder->getAccessMode($userobj) >= M_READWRITE) {
$docname = $app->request()->params('name');
$keywords = $app->request()->params('keywords');
// $categories = $app->request()->params('categories') ? $app->request()->params('categories') : [];
// $attributes = $app->request()->params('attributes') ? $app->request()->params('attributes') : [];
$origfilename = $app->request()->params('origfilename');
if (count($_FILES) == 0)
{
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'No file detected', 'data'=>''));
return;
}
$file_info = reset($_FILES);
if ($origfilename == null)
$origfilename = $file_info['name'];
if (trim($docname) == '')
$docname = $origfilename;
$temp = $file_info['tmp_name'];
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$userfiletype = finfo_file($finfo, $temp);
$fileType = ".".pathinfo($origfilename, PATHINFO_EXTENSION);
finfo_close($finfo);
$res = $mfolder->addDocument($docname, '', 0, $userobj, $keywords, array(), $temp, $origfilename ? $origfilename : basename($temp), $fileType, $userfiletype, 0);
// addDocumentCategories($res, $categories);
// setDocumentAttributes($res, $attributes);
unlink($temp);
if($res) {
$doc = $res[0];
$rec = array('id'=>$doc->getId(), 'name'=>$doc->getName());
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'Upload succeded', 'data'=>$rec));
} else {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Upload failed', 'data'=>''));
}
} else {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'No access', 'data'=>''));
}
} else {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'No folder', 'data'=>''));
}
} /* }}} */
/**
* Old upload method which uses put instead of post
*/
function uploadDocumentPut($id) { /* {{{ */
global $app, $dms, $userobj;
if(!$userobj) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Not logged in', 'data'=>''));
return;
}
if($id == 0) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'id is 0', 'data'=>''));
return;
}
@ -453,30 +582,84 @@ function uploadDocument($id) { /* {{{ */
}
} /* }}} */
function uploadDocumentFile($documentId) { /* {{{ */
global $app, $dms, $userobj;
if(!$userobj) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Not logged in', 'data'=>''));
return;
}
if($documentId == 0) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'id is 0', 'data'=>''));
return;
}
$document = $dms->getDocument($documentId);
if($document) {
if ($document->getAccessMode($userobj) >= M_READWRITE) {
$docname = $app->request()->params('name');
$keywords = $app->request()->params('keywords');
$origfilename = $app->request()->params('origfilename');
$comment = $app->request()->params('comment');
$version = $app->request()->params('version') == '' ? 0 : $app->request()->params('version');
$public = $app->request()->params('public') == '' ? 'false' : $app->request()->params('public');
if (count($_FILES) == 0)
{
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'No file detected', 'data'=>''));
return;
}
$file_info = reset($_FILES);
if ($origfilename == null)
$origfilename = $file_info['name'];
if (trim($docname) == '')
$docname = $origfilename;
$temp = $file_info['tmp_name'];
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$userfiletype = finfo_file($finfo, $temp);
$fileType = ".".pathinfo($origfilename, PATHINFO_EXTENSION);
finfo_close($finfo);
$res = $document->addDocumentFile($docname, $comment, $userobj, $temp,
$origfilename ? $origfilename : utf8_basename($temp),
$fileType, $userfiletype, $version, $public);
unlink($temp);
if($res) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'Upload succeded', 'data'=>$res));
} else {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Upload failed', 'data'=>''));
}
} else {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'No access', 'data'=>''));
}
} else {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'No such document', 'data'=>''));
}
} /* }}} */
function getDocument($id) { /* {{{ */
global $app, $dms, $userobj;
$document = $dms->getDocument($id);
if($document) {
if ($document->getAccessMode($userobj) >= M_READ) {
$lc = $document->getLatestContent();
$app->response()->header('Content-Type', 'application/json');
$data = array(
'id'=>$id,
'name'=>htmlspecialchars($document->getName()),
'comment'=>htmlspecialchars($document->getComment()),
'date'=>$document->getDate(),
'mimetype'=>$lc->getMimeType(),
'version'=>$lc->getVersion(),
'orig_filename'=>$lc->getOriginalFileName(),
'size'=>$lc->getFileSize(),
'keywords'=>htmlspecialchars($document->getKeywords()),
);
if($lc) {
$data = __getLatestVersionData($lc);
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$data));
} else {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'No access', 'data'=>''));
}
} else {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'No access', 'data'=>''));
}
} else {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'No document', 'data'=>''));
@ -505,12 +688,11 @@ function deleteDocument($id) { /* {{{ */
}
} /* }}} */
function moveDocument($id) { /* {{{ */
function moveDocument($id, $folderid) { /* {{{ */
global $app, $dms, $userobj;
$document = $dms->getDocument($id);
if($document) {
if ($document->getAccessMode($userobj) >= M_READ) {
$folderid = $app->request()->post('dest');
if($folder = $dms->getFolder($folderid)) {
if($folder->getAccessMode($userobj) >= M_READWRITE) {
if($document->setFolder($folder)) {
@ -545,8 +727,14 @@ function getDocumentContent($id) { /* {{{ */
if($document) {
if ($document->getAccessMode($userobj) >= M_READ) {
$lc = $document->getLatestContent();
if (pathinfo($document->getName(), PATHINFO_EXTENSION) == $lc->getFileType())
$filename = $document->getName();
else
$filename = $document->getName().$lc->getFileType();
$app->response()->header('Content-Type', $lc->getMimeType());
$app->response()->header("Content-Disposition: filename=\"" . $document->getName().$lc->getFileType() . "\"");
$app->response()->header("Content-Disposition", "filename=\"" . $filename . "\"");
$app->response()->header("Content-Length", filesize($dms->contentDir . $lc->getPath()));
$app->response()->header("Expires", "0");
$app->response()->header("Cache-Control", "no-cache, must-revalidate");
@ -574,7 +762,7 @@ function getDocumentVersions($id) { /* {{{ */
'date'=>$lc->getDate(),
'mimetype'=>$lc->getMimeType(),
'size'=>$lc->getFileSize(),
'comment'=>htmlspecialchars($lc->getComment()),
'comment'=>$lc->getComment(),
);
}
$app->response()->header('Content-Type', 'application/json');
@ -704,6 +892,7 @@ function getDocumentAttributes($id) { /* {{{ */
function getDocumentPreview($id, $version=0, $width=0) { /* {{{ */
global $app, $dms, $userobj, $settings;
require_once "SeedDMS/Preview.php";
$document = $dms->getDocument($id);
if($document) {
@ -836,26 +1025,12 @@ function doSearch() { /* {{{ */
if(get_class($entry) == 'SeedDMS_Core_Document') {
$document = $entry;
$lc = $document->getLatestContent();
$recs[] = array(
'type'=>'document',
'id'=>$document->getId(),
'date'=>$document->getDate(),
'name'=>$document->getName(),
'mimetype'=>$lc->getMimeType(),
'version'=>$lc->getVersion(),
'size'=>$lc->getFileSize(),
'comment'=>$document->getComment(),
'keywords'=>$document->getKeywords(),
);
if($lc) {
$recs[] = __getLatestVersionData($lc);
}
} elseif(get_class($entry) == 'SeedDMS_Core_Folder') {
$folder = $entry;
$recs[] = array(
'type'=>'folder',
'id'=>$folder->getId(),
'name'=>$folder->getName(),
'comment'=>$folder->getComment(),
'date'=>$folder->getDate(),
);
$recs[] = __getFolderData($folder);
}
}
$app->response()->header('Content-Type', 'application/json');
@ -899,26 +1074,12 @@ function doSearchByAttr() { /* {{{ */
if(get_class($entry) == 'SeedDMS_Core_Document') {
$document = $entry;
$lc = $document->getLatestContent();
$recs[] = array(
'type'=>'document',
'id'=>$document->getId(),
'date'=>$document->getDate(),
'name'=>$document->getName(),
'mimetype'=>$lc->getMimeType(),
'version'=>$lc->getVersion(),
'size'=>$lc->getFileSize(),
'comment'=>$document->getComment(),
'keywords'=>$document->getKeywords(),
);
if($lc) {
$recs[] = __getLatestVersionData($lc);
}
} elseif(get_class($entry) == 'SeedDMS_Core_Folder') {
$folder = $entry;
$recs[] = array(
'type'=>'folder',
'id'=>$folder->getId(),
'name'=>$folder->getName(),
'comment'=>$folder->getComment(),
'date'=>$folder->getDate(),
);
$recs[] = __getFolderData($folder);
}
}
$app->response()->header('Content-Type', 'application/json');
@ -927,6 +1088,7 @@ function doSearchByAttr() { /* {{{ */
function checkIfAdmin() { /* {{{ */
global $app, $dms, $userobj;
if(!$userobj) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Not logged in', 'data'=>''));
@ -1177,6 +1339,7 @@ function changeGroupMembership($id, $operationType) { /* {{{ */
{
$message = 'Could not remove user from group.';
}
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Something went wrong. ' . $message, 'data'=>''));
return;
}
@ -1354,6 +1517,7 @@ function changeFolderAccess($id, $operationType, $userOrGroup) { /* {{{ */
{
$message = 'Could not remove user/group access from this folder.';
}
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Something went wrong. ' . $message, 'data'=>''));
return;
}
@ -1363,6 +1527,151 @@ function changeFolderAccess($id, $operationType, $userOrGroup) { /* {{{ */
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$data));
} /* }}} */
function getCategories() { /* {{{ */
global $app, $dms, $userobj;
$categories = $dms->getDocumentCategories();
$data = [];
foreach($categories as $category)
$data[] = ['id' => $category->getId(), 'name' => $category->getName()];
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$data));
} /* }}} */
function addCategory() { /* {{{ */
global $app, $dms, $userobj;
checkIfAdmin();
$category = $app->request()->params("category");
if ($category == null) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Need a category.', 'data'=>''));
return;
}
$catobj = $dms->getDocumentCategoryByName($category);
if($catobj) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'Category already exists', 'data'=>''));
} else {
$data = $dms->addDocumentCategory($category);
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$data));
}
} /* }}} */
function deleteCategory($id) { /* {{{ */
global $app, $dms, $userobj;
checkIfAdmin();
$categories = new SeedDMS_Core_DocumentCategory($id, null);
$result = $categories->remove();
$data = null;
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>$result, 'message'=>'', 'data'=>$data));
} /* }}} */
/**
* Updates the name of an existing category
*
* @param <type> $id The user name or numerical identifier
*/
function changeCategoryName($id) { /* {{{ */
global $app, $dms, $userobj;
checkIfAdmin();
if ($app->request()->put('name') == null)
{
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'You must PUT a new name', 'data'=>''));
return;
}
$newname = $app->request()->put('name');
$category = null;
if(is_numeric($id))
$category = $dms->getDocumentCategory($id);
/**
* Category not found
*/
if (!$category) {
$app->response()->status(404);
return;
}
if (!$category->setName($newname)) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'', 'data'=>'Could not change name.'));
return;
}
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>''));
return;
} /* }}} */
function getAttributeDefinitions() { /* {{{ */
global $app, $dms, $userobj;
$attrdefs = $dms->getAllAttributeDefinitions();
$data = [];
foreach($attrdefs as $attrdef)
$data[] = ['id' => (int)$attrdef->getId(), 'name' => $attrdef->getName(), 'type'=>(int)$attrdef->getType(), 'objtype'=>(int)$attrdef->getObjType(), 'min'=>(int)$attrdef->getMinValues(), 'max'=>(int)$attrdef->getMaxValues(), 'multiple'=>$attrdef->getMultipleValues()?true:false, 'valueset'=>$attrdef->getValueSetAsArray()];
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$data));
} /* }}} */
/**
* Updates the name of an existing attribute definition
*
* @param <type> $id The user name or numerical identifier
*/
function changeAttributeDefinitionName($id) { /* {{{ */
global $app, $dms, $userobj;
checkIfAdmin();
if ($app->request()->put('name') == null)
{
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'You must PUT a new name', 'data'=>''));
return;
}
$newname = $app->request()->put('name');
$attrdef = null;
if(is_numeric($id))
$attrdef = $dms->getAttributeDefinition($id);
/**
* Category not found
*/
if (!$attrdef) {
$app->response()->status(404);
return;
}
if (!$attrdef->setName($newname)) {
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>false, 'message'=>'', 'data'=>'Could not change name.'));
return;
}
$app->response()->header('Content-Type', 'application/json');
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>''));
return;
} /* }}} */
function clearFolderAccessList($id) { /* {{{ */
global $app, $dms, $userobj;
checkIfAdmin();
@ -1372,35 +1681,30 @@ function clearFolderAccessList($id) { /* {{{ */
else {
$folder = $dms->getFolderByName($id);
}
if (!$folder)
{
if (!$folder) {
$app->response()->status(404);
return;
}
$operationResult = $folder->clearAccessList();
$data = array();
$app->response()->header('Content-Type', 'application/json');
if (!$operationResult)
{
echo json_encode(array('success'=>false, 'message'=>'Something went wrong. Could not clear access list for this folder.', 'data'=>$data));
if (!$folder->clearAccessList()) {
echo json_encode(array('success'=>false, 'message'=>'Something went wrong. Could not clear access list for this folder.', 'data'=>''));
}
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$data));
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>''));
} /* }}} */
//$app = new Slim(array('mode'=>'development', '_session.handler'=>null));
$app = new \Slim\Slim(array('mode'=>'development', '_session.handler'=>null));
$app = new \Slim\Slim(array('mode'=>'production', '_session.handler'=>null));
$app->configureMode('production', function () use ($app) {
$app->config(array(
'log.enable' => true,
'log.path' => '/tmp/',
'log.enable' => false,
'debug' => false
));
});
$app->configureMode('development', function () use ($app) {
$app->config(array(
'log.enable' => false,
'log.enable' => true,
'debug' => true
));
});
@ -1414,18 +1718,21 @@ $app->get('/logout', 'doLogout');
$app->get('/account', 'getAccount');
$app->get('/search', 'doSearch');
$app->get('/searchbyattr', 'doSearchByAttr');
$app->get('/folder/', 'getFolder');
$app->get('/folder/:id', 'getFolder');
$app->post('/folder/:id/move', 'moveFolder');
$app->post('/folder/:id/move/:folderid', 'moveFolder');
$app->delete('/folder/:id', 'deleteFolder');
$app->get('/folder/:id/children', 'getFolderChildren');
$app->get('/folder/:id/parent', 'getFolderParent');
$app->get('/folder/:id/path', 'getFolderPath');
$app->get('/folder/:id/attributes', 'getFolderAttributes');
$app->post('/folder/:id/createfolder', 'createFolder');
$app->put('/folder/:id/document', 'uploadDocument');
$app->put('/folder/:id/document', 'uploadDocumentPut');
$app->post('/folder/:id/document', 'uploadDocument');
$app->get('/document/:id', 'getDocument');
$app->post('/document/:id/attachment', 'uploadDocumentFile');
$app->delete('/document/:id', 'deleteDocument');
$app->post('/document/:id/move', 'moveDocument');
$app->post('/document/:id/move/:folderid', 'moveDocument');
$app->get('/document/:id/content', 'getDocumentContent');
$app->get('/document/:id/versions', 'getDocumentVersions');
$app->get('/document/:id/version/:version', 'getDocumentVersion');
@ -1451,6 +1758,12 @@ $app->put('/folder/:id/access/user/add', 'addUserAccessToFolder'); //
$app->put('/folder/:id/access/group/remove', 'removeGroupAccessFromFolder');
$app->put('/folder/:id/access/user/remove', 'removeUserAccessFromFolder');
$app->put('/folder/:id/access/clear', 'clearFolderAccessList');
$app->get('/categories', 'getCategories');
$app->delete('/categories/:id', 'deleteCategory');
$app->post('/categories', 'addCategory');
$app->put('/categories/:id/name', 'changeCategoryName');
$app->get('/attributedefinitions', 'getAttributeDefinitions');
$app->put('/attributedefinitions/:id/name', 'changeAttributeDefinitionName');
$app->run();
?>