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

This commit is contained in:
Uwe Steinmann 2022-05-10 18:33:41 +02:00
commit dfedd201dd
4 changed files with 86 additions and 49 deletions

View File

@ -226,6 +226,8 @@
Changes in version 5.1.26 Changes in version 5.1.26
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
- add hook additionalDocumentContentInfo - add hook additionalDocumentContentInfo
- add restapi function 'statstotal'
- custom attributes of type 'date' regard the date format
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
Changes in version 5.1.25 Changes in version 5.1.25

View File

@ -4153,6 +4153,24 @@ class SeedDMS_Core_DMS {
$res['total'] = $sum; $res['total'] = $sum;
} }
return $resArr; return $resArr;
case 'docstotal':
$queryStr = "SELECT count(*) AS total FROM `tblDocuments`";
$resArr = $this->db->getResultArray($queryStr);
if(is_bool($resArr) && $resArr == false)
return false;
return (int) $resArr[0]['total'];
case 'folderstotal':
$queryStr = "SELECT count(*) AS total FROM `tblFolders`";
$resArr = $this->db->getResultArray($queryStr);
if(is_bool($resArr) && $resArr == false)
return false;
return (int) $resArr[0]['total'];
case 'userstotal':
$queryStr = "SELECT count(*) AS total FROM `tblUsers`";
$resArr = $this->db->getResultArray($queryStr);
if(is_bool($resArr) && $resArr == false)
return false;
return (int) $resArr[0]['total'];
case 'sizeperuser': case 'sizeperuser':
$queryStr = "SELECT ".$this->db->concat(array('c.`fullName`', "' ('", 'c.`login`', "')'"))." AS `key`, sum(`fileSize`) AS total FROM `tblDocuments` a LEFT JOIN `tblDocumentContent` b ON a.id=b.`document` LEFT JOIN `tblUsers` c ON a.`owner`=c.`id` GROUP BY a.`owner`, c.`fullName`"; $queryStr = "SELECT ".$this->db->concat(array('c.`fullName`', "' ('", 'c.`login`', "')'"))." AS `key`, sum(`fileSize`) AS total FROM `tblDocuments` a LEFT JOIN `tblDocumentContent` b ON a.id=b.`document` LEFT JOIN `tblUsers` c ON a.`owner`=c.`id` GROUP BY a.`owner`, c.`fullName`";
$resArr = $this->db->getResultArray($queryStr); $resArr = $this->db->getResultArray($queryStr);

View File

@ -596,12 +596,12 @@ class RestapiController { /* {{{ */
return $response->withJson(array('success'=>false, 'message'=>'No parent folder id given', 'data'=>''), 400); return $response->withJson(array('success'=>false, 'message'=>'No parent folder id given', 'data'=>''), 400);
} }
if($settings->_quota > 0) { if($settings->_quota > 0) {
$remain = checkQuota($userobj); $remain = checkQuota($userobj);
if ($remain < 0) { if ($remain < 0) {
return $response->withJson(array('success'=>false, 'message'=>'Quota exceeded', 'data'=>''), 400); return $response->withJson(array('success'=>false, 'message'=>'Quota exceeded', 'data'=>''), 400);
} }
} }
$mfolder = $dms->getFolder($args['id']); $mfolder = $dms->getFolder($args['id']);
if($mfolder) { if($mfolder) {
@ -637,11 +637,11 @@ class RestapiController { /* {{{ */
foreach($categories as $catid) { foreach($categories as $catid) {
if($cat = $dms->getDocumentCategory($catid)) if($cat = $dms->getDocumentCategory($catid))
$cats[] = $cat; $cats[] = $cat;
} }
$owner = null; $owner = null;
if($userobj->isAdmin() && isset($params["owner"]) && ctype_digit($params['owner'])) { if($userobj->isAdmin() && isset($params["owner"]) && ctype_digit($params['owner'])) {
$owner = $dms->getUser($params["owner"]); $owner = $dms->getUser($params["owner"]);
} }
$attributes = isset($params["attributes"]) ? $params["attributes"] : array(); $attributes = isset($params["attributes"]) ? $params["attributes"] : array();
foreach($attributes as $attrdefid=>$attribute) { foreach($attributes as $attrdefid=>$attribute) {
if($attrdef = $dms->getAttributeDefinition($attrdefid)) { if($attrdef = $dms->getAttributeDefinition($attrdefid)) {
@ -710,12 +710,12 @@ class RestapiController { /* {{{ */
return $response->withJson(array('success'=>false, 'message'=>'No document id given', 'data'=>''), 400); return $response->withJson(array('success'=>false, 'message'=>'No document id given', 'data'=>''), 400);
} }
if($settings->_quota > 0) { if($settings->_quota > 0) {
$remain = checkQuota($userobj); $remain = checkQuota($userobj);
if ($remain < 0) { if ($remain < 0) {
return $response->withJson(array('success'=>false, 'message'=>'Quota exceeded', 'data'=>''), 400); return $response->withJson(array('success'=>false, 'message'=>'Quota exceeded', 'data'=>''), 400);
} }
} }
$document = $dms->getDocument($args['id']); $document = $dms->getDocument($args['id']);
if($document) { if($document) {
@ -742,13 +742,13 @@ class RestapiController { /* {{{ */
$file_info = array_pop($uploadedFiles); $file_info = array_pop($uploadedFiles);
if ($origfilename == null) if ($origfilename == null)
$origfilename = $file_info->getClientFilename(); $origfilename = $file_info->getClientFilename();
$temp = $file_info->file; $temp = $file_info->file;
/* Check if the uploaded file is identical to last version */ /* Check if the uploaded file is identical to last version */
$lc = $document->getLatestContent(); $lc = $document->getLatestContent();
if($lc->getChecksum() == SeedDMS_Core_File::checksum($temp)) { if($lc->getChecksum() == SeedDMS_Core_File::checksum($temp)) {
return $response->withJson(array('success'=>false, 'message'=>'Uploaded file identical to last version', 'data'=>''), 400); return $response->withJson(array('success'=>false, 'message'=>'Uploaded file identical to last version', 'data'=>''), 400);
} }
$finfo = finfo_open(FILEINFO_MIME_TYPE); $finfo = finfo_open(FILEINFO_MIME_TYPE);
$userfiletype = finfo_file($finfo, $temp); $userfiletype = finfo_file($finfo, $temp);
$fileType = ".".pathinfo($origfilename, PATHINFO_EXTENSION); $fileType = ".".pathinfo($origfilename, PATHINFO_EXTENSION);
@ -784,14 +784,14 @@ class RestapiController { /* {{{ */
if(!ctype_digit($args['id']) || $args['id'] == 0) { if(!ctype_digit($args['id']) || $args['id'] == 0) {
return $response->withJson(array('success'=>false, 'message'=>'No document id given', 'data'=>''), 400); return $response->withJson(array('success'=>false, 'message'=>'No document id given', 'data'=>''), 400);
} }
if($settings->_quota > 0) { if($settings->_quota > 0) {
$remain = checkQuota($userobj); $remain = checkQuota($userobj);
if ($remain < 0) { if ($remain < 0) {
return $response->withJson(array('success'=>false, 'message'=>'Quota exceeded', 'data'=>''), 400); return $response->withJson(array('success'=>false, 'message'=>'Quota exceeded', 'data'=>''), 400);
} }
} }
$mfolder = $dms->getFolder($args['id']); $mfolder = $dms->getFolder($args['id']);
if($mfolder) { if($mfolder) {
@ -1462,10 +1462,10 @@ class RestapiController { /* {{{ */
if(!$userobj) { if(!$userobj) {
return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403);
} }
if(!$userobj->isAdmin()) { if(!$userobj->isAdmin()) {
return $response->withJson(array('success'=>false, 'message'=>'No access on document', 'data'=>''), 403); return $response->withJson(array('success'=>false, 'message'=>'No access on document', 'data'=>''), 403);
} }
if(!ctype_digit($args['id']) || $args['id'] == 0) { if(!ctype_digit($args['id']) || $args['id'] == 0) {
return $response->withJson(array('success'=>false, 'message'=>'No document given', 'data'=>''), 400); return $response->withJson(array('success'=>false, 'message'=>'No document given', 'data'=>''), 400);
@ -1527,16 +1527,16 @@ class RestapiController { /* {{{ */
if(!isset($params['searchin']) || !$searchin = explode(",",$params['searchin'])) if(!isset($params['searchin']) || !$searchin = explode(",",$params['searchin']))
$searchin = array(); $searchin = array();
if(!isset($params['objects']) || !$objects = $params['objects']) if(!isset($params['objects']) || !$objects = $params['objects'])
$objects = 0x3; $objects = 0x3;
$sparams = array( $sparams = array(
'query'=>$querystr, 'query'=>$querystr,
'limit'=>$limit, 'limit'=>$limit,
'offset'=>$offset, 'offset'=>$offset,
'logicalmode'=>'AND', 'logicalmode'=>'AND',
'searchin'=>$searchin, 'searchin'=>$searchin,
'mode'=>$objects, 'mode'=>$objects,
// 'creationstartdate'=>array('hour'=>1, 'minute'=>0, 'second'=>0, 'year'=>date('Y')-1, 'month'=>date('m'), 'day'=>date('d')), // 'creationstartdate'=>array('hour'=>1, 'minute'=>0, 'second'=>0, 'year'=>date('Y')-1, 'month'=>date('m'), 'day'=>date('d')),
); );
$resArr = $dms->search($sparams); $resArr = $dms->search($sparams);
// $resArr = $dms->search($querystr, $limit, $offset, 'AND', $searchin, null, null, array(), array('hour'=>1, 'minute'=>0, 'second'=>0, 'year'=>date('Y')-1, 'month'=>date('m'), 'day'=>date('d')), array(), array(), array(), array(), array(), $objects); // $resArr = $dms->search($querystr, $limit, $offset, 'AND', $searchin, null, null, array(), array('hour'=>1, 'minute'=>0, 'second'=>0, 'year'=>date('Y')-1, 'month'=>date('m'), 'day'=>date('d')), array(), array(), array(), array(), array(), $objects);
if($resArr === false) { if($resArr === false) {
@ -2324,6 +2324,22 @@ class RestapiController { /* {{{ */
return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200); return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200);
} /* }}} */ } /* }}} */
function getStatsTotal($request, $response) { /* {{{ */
$dms = $this->container->dms;
$userobj = $this->container->userobj;
$check = $this->checkIfAdmin($request, $response);
if($check !== true)
return $check;
$data = [];
foreach(array('docstotal', 'folderstotal', 'userstotal') as $type) {
$total = $dms->getStatisticalData($type);
$data[$type] = $total;
}
return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>$data), 200);
} /* }}} */
} /* }}} */ } /* }}} */
class TestController { /* {{{ */ class TestController { /* {{{ */
@ -2373,9 +2389,9 @@ class Auth { /* {{{ */
} }
/* The preflight options request doesn't have authorization in the header. So /* The preflight options request doesn't have authorization in the header. So
* don't even try to authorize. * don't even try to authorize.
*/ */
if($request->getMethod() == 'OPTIONS') { if($request->getMethod() == 'OPTIONS') {
} elseif(!in_array($request->getUri()->getPath(), array('login')) && substr($request->getUri()->getPath(), 0, 5) != 'echo/') { } elseif(!in_array($request->getUri()->getPath(), array('login')) && substr($request->getUri()->getPath(), 0, 5) != 'echo/') {
$userobj = null; $userobj = null;
if(!empty($this->container->environment['HTTP_AUTHORIZATION']) && !empty($settings->_apiKey) && !empty($settings->_apiUserId)) { if(!empty($this->container->environment['HTTP_AUTHORIZATION']) && !empty($settings->_apiKey) && !empty($settings->_apiUserId)) {
if($settings->_apiKey == $this->container->environment['HTTP_AUTHORIZATION']) { if($settings->_apiKey == $this->container->environment['HTTP_AUTHORIZATION']) {
@ -2512,6 +2528,7 @@ $app->put('/categories/{id}/name', \RestapiController::class.':changeCategoryNam
$app->get('/attributedefinitions', \RestapiController::class.':getAttributeDefinitions'); $app->get('/attributedefinitions', \RestapiController::class.':getAttributeDefinitions');
$app->put('/attributedefinitions/{id}/name', \RestapiController::class.':changeAttributeDefinitionName'); $app->put('/attributedefinitions/{id}/name', \RestapiController::class.':changeAttributeDefinitionName');
$app->get('/echo/{data}', \TestController::class.':echoData'); $app->get('/echo/{data}', \TestController::class.':echoData');
$app->get('/statstotal', \RestapiController::class.':getStatsTotal');
$app->run(); $app->run();
?> ?>

View File

@ -1940,9 +1940,9 @@ $(document).ready(function() {
$content .= "<input type=\"checkbox\" id=\"".$fieldname."_".$attrdef->getId()."\" name=\"".$fieldname."[".$attrdef->getId()."]\" value=\"1\" ".($objvalue ? 'checked' : '')." />"; $content .= "<input type=\"checkbox\" id=\"".$fieldname."_".$attrdef->getId()."\" name=\"".$fieldname."[".$attrdef->getId()."]\" value=\"1\" ".($objvalue ? 'checked' : '')." />";
break; break;
case SeedDMS_Core_AttributeDefinition::type_date: case SeedDMS_Core_AttributeDefinition::type_date:
$objvalue = $attribute ? (is_object($attribute) ? $attribute->getValue() : $attribute) : ''; $objvalue = $attribute ? getReadableDate((is_object($attribute) ? $attribute->getValue() : $attribute)) : '';
$dateformat = getConvertDateFormat($this->params['settings']->_dateformat); $dateformat = getConvertDateFormat($this->params['settings']->_dateformat);
$content .= '<span class="input-append date span12 datepicker" data-date="'.getReadableDate().'" data-date-format="'.$dateformat.'" data-date-language="'.str_replace('_', '-', $this->params['session']->getLanguage()).'"> $content .= '<span class="input-append date span12 datepicker" data-date="'.getReadableDate().'" data-date-format="'.$dateformat.'" data-date-language="'.str_replace('_', '-', $this->params['session']->getLanguage()).'">
<input id="'.$fieldname.'_'.$attrdef->getId().($namepostfix ? '_'.$namepostfix : '').'" class="span6" size="16" name="'.$fieldname.'['.$attrdef->getId().']'.($namepostfix ? '['.$namepostfix.']' : '').'" type="text" value="'.($objvalue ? $objvalue : '').'"> <input id="'.$fieldname.'_'.$attrdef->getId().($namepostfix ? '_'.$namepostfix : '').'" class="span6" size="16" name="'.$fieldname.'['.$attrdef->getId().']'.($namepostfix ? '['.$namepostfix.']' : '').'" type="text" value="'.($objvalue ? $objvalue : '').'">
<span class="add-on"><i class="fa fa-calendar"></i></span> <span class="add-on"><i class="fa fa-calendar"></i></span>
</span>'; </span>';