diff --git a/class.paperless.php b/class.paperless.php index fde2fe1..5fb860a 100644 --- a/class.paperless.php +++ b/class.paperless.php @@ -23,6 +23,8 @@ class SeedDMS_ExtPaperless extends SeedDMS_ExtBase { /* {{{ */ function init() { /* {{{ */ $GLOBALS['SEEDDMS_HOOKS']['initRestAPI'][] = new SeedDMS_ExtPaperless_RestAPI; $GLOBALS['SEEDDMS_HOOKS']['view']['settings'][] = new SeedDMS_ExtPaperless_Settings; + $GLOBALS['SEEDDMS_HOOKS']['view']['bootstrap'][] = new SeedDMS_ExtPaperless_Bootstrap; + $GLOBALS['SEEDDMS_HOOKS']['view']['style'][] = new SeedDMS_ExtPaperless_Bootstrap; } /* }}} */ function main() { /* {{{ */ @@ -56,6 +58,29 @@ class SeedDMS_ExtPaperless_Settings { /* {{{ */ } } /* }}} */ +/** + * Class containing methods for hooks when a + * + * @author Uwe Steinmann + * @package SeedDMS + * @subpackage paperless + */ +class SeedDMS_ExtPaperless_Bootstrap { /* {{{ */ + + function userMenuItems($view, $menuitems) { /* {{{ */ + $user = $view->getParam('user'); + $settings = $view->getParam('settings'); + $accessobject = $view->getParam('accessobject'); + + if(!$user->isGuest()) { + if (((new SeedDMS_Version())->version() < '6.0.0') || !$settings->_advancedAcl || $accessobject->check_view_access('PaperlessViews')) + $menuitems['paperless_views'] = array('link'=>$settings->_httpRoot.'ext/paperless/out/out.PaperlessViews.php', 'label'=>getMLText('paperless_views')); + } + return $menuitems; + } /* }}} */ + +} /* }}} */ + use Psr\Container\ContainerInterface; class SeedDMS_ExtPaperless_Process_Folder { /* {{{ */ @@ -86,7 +111,14 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ return array_count_values(preg_split($regEx,$string, -1, PREG_SPLIT_NO_EMPTY)); } /* }}} */ - protected function __getDocumentData($document, $truncate_content=false) { /* {{{ */ + /** + * Get data of document + * + * @param $document object + * @param bool $truncate_content set to true if content shall be truncated + * @param bool $full set to true for content from the file instead of the index + */ + protected function __getDocumentData($document, $truncate_content=false, $full=false) { /* {{{ */ $fulltextservice = $this->container->fulltextservice; $settings = $this->container->config; $conversionmgr = $this->container->conversionmgr; @@ -100,7 +132,7 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ * does not have stop words anymore if a stop words file was * configured during indexing. */ - if(1) { + if($full) { $txtpreviewer = new SeedDMS_Preview_TxtPreviewer($settings->_cacheDir, $settings->_cmdTimeout, $settings->_enableXsendfile); $txtpreviewer->setConversionMgr($conversionmgr); if(!$txtpreviewer->hasPreview($lc)) @@ -633,23 +665,25 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ /* tags__id__in is used when searching for documents by id */ if(isset($params['tags__id__all'])) { $catids = explode(',', $params['tags__id__all']); - foreach($catids as $catid) + foreach($catids as $catid) { if($catid) { if($cat = $dms->getDocumentCategory($catid)) { $categories[] = $cat; $categorynames[] = $cat->getName(); } } + } } /* tags__id__in is used when getting the documents of the inbox */ if(isset($params['tags__id__in'])) { $catids = explode(',', $params['tags__id__in']); if($catids) { - foreach($catids as $catid) + foreach($catids as $catid) { if($cat = $dms->getDocumentCategory($catid)) { $categories[] = $cat; $categorynames[] = $cat->getName(); } + } } } elseif(isset($params['is_tagged']) && $params['is_tagged'] == '1') { $categorynames[] = '*'; @@ -867,7 +901,8 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ $document = $dms->getDocument($args['id']); if($document) { if($document->getAccessMode($userobj) >= M_READ) { - $rec = $this->__getDocumentData($document, true); + /* get untruncated content from file */ + $rec = $this->__getDocumentData($document, true, true); return $response->withJson($rec, 200); } else { return $response->withStatus(404); diff --git a/lang.php b/lang.php index 014fa56..dbdc4ea 100644 --- a/lang.php +++ b/lang.php @@ -9,6 +9,18 @@ $__lang['en_GB'] = array( 'paperless_token_has_expired'=>'Token has expired. Login again before you proceed.', 'paperless_jwtsecret_not_set'=>'The secret for the JSON Web Token is not set. This is required for successful login.', 'paperless_needs_fulltextsearch'=>'The extension needs fulltext search to be on.', + 'paperless_views'=>'Paperless', + 'paperless_view_name'=>'Name', + 'paperless_view_rules'=>'Rules', + 'paperless_view_sort_by'=>'Sort by', + 'paperless_view_dashboard'=>'Dashboard', + 'paperless_view_sidebar'=>'Sidebar', + 'paperless_view_rule_13'=>'Added until', + 'paperless_view_rule_14'=>'Added from', + 'paperless_view_rule_6'=>'Category', + 'paperless_view_rule_3'=>'Correspondent', + 'paperless_view_rule_19'=>'Title & Content', + 'paperless_view_rule_20'=>'Advanced Search', ); $__lang['de_DE'] = array( 'paperless'=>'Paperless', @@ -20,5 +32,17 @@ $__lang['de_DE'] = array( 'paperless_token_has_expired'=>'Token abgelaufen. Melden Sie sich bitte neu an.', 'paperless_jwtsecret_not_set'=>'Das Geheimnis des JSON Web Token ist nicht gesetzt. Dies ist für eine erfolgreiche Anmeldung erforderlich.', 'paperless_needs_fulltextsearch'=>'Die Erweiterung erfordert eine konfigurierte Volltextsuche .', + 'paperless_views'=>'Paperless', + 'paperless_view_name'=>'Name', + 'paperless_view_rules'=>'Regeln', + 'paperless_view_sort_by'=>'Sortiere nach', + 'paperless_view_dashboard'=>'Dashboard', + 'paperless_view_sidebar'=>'Sidebar', + 'paperless_view_rule_13'=>'Hinzugefügt bis', + 'paperless_view_rule_14'=>'Hinzugefügt von', + 'paperless_view_rule_6'=>'Kategorie', + 'paperless_view_rule_3'=>'Korrepondent', + 'paperless_view_rule_19'=>'Titel & Inhalt', + 'paperless_view_rule_20'=>'Erweiterte Suche', ); diff --git a/out/out.PaperlessViews.php b/out/out.PaperlessViews.php new file mode 100644 index 0000000..1f74432 --- /dev/null +++ b/out/out.PaperlessViews.php @@ -0,0 +1,69 @@ + $dms, 'user' => $user)); + +$v = new SeedDMS_Version(); +if($v->majorVersion() > 5) { + $accessop = new SeedDMS_AccessOperation($dms, $user, $settings); + if (!$accessop->check_view_access($view, $_GET)) { + UI::exitError(getMLText("admin_tools"), getMLText("access_denied")); + } +} else + $accessop = new SeedDMS_AccessOperation($dms, null, $user, $settings); + +$pview = null; +if (isset($_GET["view"])) { + $pview = SeedDMS_PaperlessView::getInstance($_GET['view'], $dms); +} + +if($view) { + $view->setParam('accessobject', $accessop); + $view->setParam('showtree', showtree()); + $view->setParam('pview', $pview); + $view->setParam('fulltextservice', $fulltextservice); + $view->setParam('logger', $logger); + $view->setParam('conversionmgr', $conversionmgr); + $view->setParam('previewWidthList', $settings->_previewWidthList); + $view->setParam('previewconverters', $settings->_converters['preview']); + $view->setParam('timeout', $settings->_cmdTimeout); + $view($_GET); + exit; +} + diff --git a/views/bootstrap/class.PaperlessViews.php b/views/bootstrap/class.PaperlessViews.php new file mode 100644 index 0000000..148aff3 --- /dev/null +++ b/views/bootstrap/class.PaperlessViews.php @@ -0,0 +1,357 @@ + + * @copyright Copyright (C) 2017 Uwe Steinmann + * @version Release: @package_version@ + */ + +/** + * Class which outputs the html page for PaperlessViews view + * + * @category DMS + * @package SeedDMS + * @author Uwe Steinmann + * @copyright Copyright (C) 2017 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_View_PaperlessViews extends SeedDMS_Bootstrap_Style { + + function js() { /* {{{ */ + $dms = $this->params['dms']; + $user = $this->params['user']; + $onepage = $this->params['onepage']; + header('Content-Type: application/javascript'); + parent::jsTranslations(array('cancel', 'splash_move_document', 'confirm_move_document', 'move_document', 'confirm_transfer_link_document', 'transfer_content', 'link_document', 'splash_move_folder', 'confirm_move_folder', 'move_folder')); +?> +$(document).ready(function() { + $('body').on('click', '.view', function(ev){ + ev.preventDefault(); + $('#paperless_view.ajax').trigger('update', {view: $(this).data('view')}); + }); +}); +printClickDocumentJs(); + } + $this->printDeleteDocumentButtonJs(); + } /* }}} */ + + protected function printListHeader($previewer, $order=false) { /* {{{ */ + print ""; + print "\n\n"; + print "\n"; + if($order) { + $orderby = ''; //$this->params['orderby']; + $orderdir = ''; //$this->params['orderdir']; + + print "\n"; + } else + print "\n"; + if($order) + print "\n"; + else + print "\n"; + print "\n"; + print "\n\n\n"; + } /* }}} */ + + protected function printListFooter() { /* {{{ */ + echo "\n
".getMLText("name")." ".($orderby == 'n' || $orderby == '' ? ($orderdir == 'desc' ? '' : '') : '')." · ".getMLText("last_update")." ".($orderby == 'u' ? ($orderdir == 'desc' ? '' : '') : '')." · ".getMLText("expires")." ".($orderby == 'e' ? ($orderdir == 'desc' ? '' : '') : '')."".getMLText("name")."".getMLText("status")."".($orderby == 's' ? " ".($orderdir == 'desc' ? '' : '') : '')."".getMLText("status")."".getMLText("action")."
"; + } /* }}} */ + + private function getSearchParameter($data) { /* {{{ */ + $dms = $this->params['dms']; + $user = $this->params['user']; + $settings = $this->params['settings']; + + $categories = array(); + $categorynames = array(); + $astart = null; + $aend = null; + $mstart = null; + $mend = null; + $startfolder = $dms->getRootFolder(); + $rootfolder = $dms->getRootFolder(); + $cattrs = []; + $query = ''; + foreach ($data['filter_rules'] as $rule) { + switch ($rule['rule_type']) { + case 3: + $correspondent = null; + if(!empty($settings->_extensions['paperless']['correspondentsattr']) && $attrdef = $dms->getAttributeDefinition($settings->_extensions['paperless']['correspondentsattr'])) { + $valueset = $attrdef->getValueSetAsArray(); + if(isset($valueset[$rule['value']-1])) { + $correspondent = $valueset[$rule['value']-1]; + $cattrs['attr_'.$attrdef->getId()] = $correspondent; + } + } + break; + case 6: + $catid = (int) $rule['value']; + if($catid) { + if($cat = $dms->getDocumentCategory($catid)) { + $categories[] = $cat; + $categorynames[] = $cat->getName(); + } + } + break; + case 13: + $aend = makeTsFromDate($rule['value']); + break; + case 14: + $astart = makeTsFromDate($rule['value']); + break; + case 19: + $query = $rule['value']; + break; + case 20: + $tmp = explode(',', $rule['value']); + foreach ($tmp as $t) { + if (substr($t, 0, 9) == 'created:[') { + $q = substr($t, 9, -1); + if($x = explode(' to ', $q, 2)) { + $astart = strtotime($x[0]); + $aend = strtotime($x[1])+86400; + } + } elseif (substr($t, 0, 7) == 'added:[') { + $q = substr($t, 7, -1); + if($x = explode(' to ', $q, 2)) { + $astart = strtotime($x[0]); + $aend = strtotime($x[1])+86400; + } + } else { + $query = $t; + } + } + break; + } + } + return [$query, array('record_type'=>['document'], 'status'=>[2], 'user'=>[$user->getLogin()], 'category'=>$categorynames, 'created_start'=>$astart, 'created_end'=>$aend, 'modified_start'=>$mstart, 'modified_end'=>$mend, 'startFolder'=>$startfolder, 'rootFolder'=>$rootfolder, 'attributes'=>$cattrs)]; + } /* }}} */ + + private function printList($data, $previewer) { /* {{{ */ + $dms = $this->params['dms']; + $user = $this->params['user']; + $settings = $this->params['settings']; + $fulltextservice = $this->params['fulltextservice']; + $logger = $this->params['logger']; + + $order = []; + $order['dir'] = $data['sort_reverse'] ? 'desc' : 'asc'; + $orderfield = $data["sort_field"]; + if(in_array($orderfield, ['modified', 'created', 'title'])) + $order['by'] = $orderfield; + elseif($orderfield == 'added') + $order['by'] = 'created'; + elseif($orderfield == 'archive_serial_number') + $order['by'] = 'id'; + elseif($orderfield == 'correspondent__name') { + if(!empty($settings->_extensions['paperless']['correspondentsattr']) && $attrdef = $dms->getAttributeDefinition($settings->_extensions['paperless']['correspondentsattr'])) { + $order['by'] = 'attr_'.$attrdef->getId(); + } + } + + list($query, $searchparams) = $this->getSearchParameter($data); + + if($fulltextservice && $index = $fulltextservice->Indexer()) { + $lucenesearch = $fulltextservice->Search(); + $limit = 10; + $offset = 0; + $logger->log('Query is '.$query, PEAR_LOG_DEBUG); + /* + $logger->log('User is '.$userobj->getLogin(), PEAR_LOG_DEBUG); + $logger->log('limit is '.$limit, PEAR_LOG_DEBUG); + $logger->log('offset is '.$offset, PEAR_LOG_DEBUG); + */ + $searchresult = $lucenesearch->search($query, $searchparams, array('limit'=>$limit, 'offset'=>$offset), $order, array('no_facets'=>true)); + if($searchresult) { + $recs = array(); + $facets = $searchresult['facets']; + $dcount = 0; + $fcount = 0; + if($searchresult['hits']) { + $allids = ''; + $this->printListHeader($previewer); + foreach($searchresult['hits'] as $hit) { + if($hit['document_id'][0] == 'D') { + if($document = $dms->getDocument((int) substr($hit['document_id'], 1))) { + $document->verifyLastestContentExpriry(); + $v = new SeedDMS_Version(); + if($v->majorVersion() > 5) { + $document->checkForDueRevisionWorkflow($user); + } + + $lc = $document->getLatestContent(); + if($document->getAccessMode($user) >= M_READ && $lc) { + $txt = $this->callHook('documentListItem', $document, $previewer, false, 'opentasks'); + if(is_string($txt)) + echo $txt; + else { + /* + $errormsg = ''; + $errorcls = ''; + if(!$doc['error']) { + } else { + $errorcls = $doc['error'] < 0 ? " error" : ($doc['error'] === 0 ? " success" : ""); + $errormsg = $doc['error']; + } + */ + $extracontent = array(); + $extracontent['below_title'] = $this->getListRowPath($document); + echo $this->documentListRowStart($document); + echo $this->documentListRow($document, $previewer, true, 0, $extracontent); + echo $this->documentListRowEnd($document); + } + } + } + } + } + $this->printListFooter(); + $logger->log('Result is '.$allids, PEAR_LOG_DEBUG); + } + } + } + } /* }}} */ + + private function count($data) { /* {{{ */ + $dms = $this->params['dms']; + $user = $this->params['user']; + $settings = $this->params['settings']; + $fulltextservice = $this->params['fulltextservice']; + $logger = $this->params['logger']; + + list($query, $searchparams) = $this->getSearchParameter($data); + + if($fulltextservice && $index = $fulltextservice->Indexer()) { + $lucenesearch = $fulltextservice->Search(); + $limit = 10; + $offset = 0; + $logger->log('Query is '.$query, PEAR_LOG_DEBUG); + /* + $logger->log('User is '.$userobj->getLogin(), PEAR_LOG_DEBUG); + $logger->log('limit is '.$limit, PEAR_LOG_DEBUG); + $logger->log('offset is '.$offset, PEAR_LOG_DEBUG); + */ + $searchresult = $lucenesearch->search($query, $searchparams, array('limit'=>0, 'offset'=>0), [], array('no_facets'=>true)); + if($searchresult) { + return $searchresult['count']; + } + } + return false; + } /* }}} */ + + public function list() { /* {{{ */ + $dms = $this->params['dms']; + $user = $this->params['user']; + $settings = $this->params['settings']; + $pview = $this->params['pview']; + $cachedir = $this->params['cachedir']; + $conversionmgr = $this->params['conversionmgr']; + $previewwidth = $this->params['previewWidthList']; + $previewconverters = $this->params['previewconverters']; + $timeout = $this->params['timeout']; + + $previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidth, $timeout); + if($conversionmgr) + $previewer->setConversionMgr($conversionmgr); + else + $previewer->setConverters($previewconverters); + + if ($pview) { + $data = $pview->getView(); + $this->printList($data, $previewer); + } + } /* }}} */ + + private function getFilterValue($rule) { /* {{{ */ + $dms = $this->params['dms']; + $settings = $this->params['settings']; + + switch($rule['rule_type']) { + case 13: // Added until + case 14: // Added from + return getReadableDate($rule['value']); + case 3: // Correspondent + if(!empty($settings->_extensions['paperless']['correspondentsattr']) && $attrdef = $dms->getAttributeDefinition($settings->_extensions['paperless']['correspondentsattr'])) { + $valueset = $attrdef->getValueSetAsArray(); + if(isset($valueset[$rule['value']-1])) { + return $valueset[$rule['value']-1]; + } + } + return '???'; + break; + case 6: // Category + return $dms->getDocumentCategory($rule['value'])->getName(); + break; + default: + return $rule['value']; + } + } /* }}} */ + + public function show() { /* {{{ */ + $dms = $this->params['dms']; + $user = $this->params['user']; + $settings = $this->params['settings']; + $session = $this->params['session']; + + $area = 'my_account'; + $this->htmlStartPage(getMLText("paperless_views"), '', '../../'); + $this->globalNavigation(); + $this->contentStart(); + $this->pageNavigation(getMLText($area), $area); + $this->contentHeading(getMLText("paperless_views")); + + $this->rowStart(); + $this->columnStart(4); + $views = SeedDMS_PaperlessView::getAllInstances($user, $dms); + + if($views) { + print ""; + print "\n\n"; + print "\n"; + print "\n"; + print "\n\n\n"; + foreach($views as $view) { + $data = $view->getView(); + $c = $this->count($data); + echo ""; + echo ""; + echo ""; + } + echo "\n
".getMLText("paperless_view_name")."".getMLText("paperless_view_rules")."
".$data['name']." (".$c.")"; + echo "
".getMLText('paperless_view_sort_by').": ".$data['sort_field']; + if ($data['show_on_dashboard']) { + echo "
".getMLText('paperless_view_dashboard').': '; + } + if ($data['show_in_sidebar']) { + echo "
".getMLText('paperless_view_sidebar').': '; + } + echo "
"; + foreach ($data['filter_rules'] as $rule) { + echo getMLText('paperless_view_rule_'.$rule['rule_type']).": ".$this->getFilterValue($rule)."
"; + } +// echo "
";
+//				print_r($data);
+//				echo "
"; + echo "
\n"; + } else { + $this->infoMsg(getMLText('upload_area_no_secret_info')); + } + $this->columnEnd(); + $this->columnStart(8); + echo '
'; + $this->columnEnd(); + $this->rowEnd(); + + $this->contentEnd(); + $this->htmlEndPage(); + } /* }}} */ +} + +