add management of link types

This commit is contained in:
Uwe Steinmann 2024-01-24 11:57:53 +01:00
parent 3be9cef85c
commit 9421d90077
3 changed files with 362 additions and 0 deletions

121
op/op.LinkTypes.php Normal file
View File

@ -0,0 +1,121 @@
<?php
// MyDMS. Document Management System
// Copyright (C) 2002-2005 Markus Westphal
// Copyright (C) 2006-2008 Malcolm Cowe
// Copyright (C) 2010-2016 Uwe Steinmann
//
// 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.
include("../inc/inc.Settings.php");
include("../inc/inc.Utils.php");
include("../inc/inc.LogInit.php");
include("../inc/inc.Language.php");
include("../inc/inc.Init.php");
include("../inc/inc.Extension.php");
include("../inc/inc.DBInit.php");
include("../inc/inc.ClassUI.php");
include("../inc/inc.Authentication.php");
if (!$user->isAdmin()) {
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
}
if (isset($_POST["action"])) $action=$_POST["action"];
else $action=NULL;
//Neue Kategorie anlegen -----------------------------------------------------------------------------
if ($action == "addlinktype") {
/* Check if the form data comes from a trusted request */
if(!checkFormKey('addlinktype')) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
}
$name = trim($_POST["name"]);
if($name == '') {
UI::exitError(getMLText("admin_tools"),getMLText("linktype_noname"));
}
if (is_object($dms->getDocumentCategoryByName($name))) {
UI::exitError(getMLText("admin_tools"),getMLText("linktype_exists"));
}
$newCategory = $dms->addLinkType($name);
if (!$newCategory) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
$linktypeid=$newCategory->getID();
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_add_linktype')));
add_log_line(".php&action=addlinktype&linktypeid=".$linktypeid);
}
//Kategorie löschen ----------------------------------------------------------------------------------
else if ($action == "removelinktype") {
/* Check if the form data comes from a trusted request */
if(!checkFormKey('removelinktype')) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
}
if (!isset($_POST["linktypeid"]) || !is_numeric($_POST["linktypeid"]) || intval($_POST["linktypeid"])<1) {
UI::exitError(getMLText("admin_tools"),getMLText("unknown_document_linktype"));
}
$linktypeid = $_POST["linktypeid"];
$linktype = $dms->getDocumentCategory($linktypeid);
if (!is_object($linktype)) {
UI::exitError(getMLText("admin_tools"),getMLText("unknown_document_linktype"));
}
if (!$linktype->remove()) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_rm_linktype')));
add_log_line(".php&action=removelinktype&linktypeid=".$linktypeid);
$linktypeid=-1;
}
//Kategorie bearbeiten: Neuer Name --------------------------------------------------------------------
else if ($action == "editlinktype") {
/* Check if the form data comes from a trusted request */
if(!checkFormKey('editlinktype')) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
}
if (!isset($_POST["linktypeid"]) || !is_numeric($_POST["linktypeid"]) || intval($_POST["linktypeid"])<1) {
UI::exitError(getMLText("admin_tools"),getMLText("unknown_document_linktype"));
}
$linktypeid = $_POST["linktypeid"];
$linktype = $dms->getLinkType($linktypeid);
if (!is_object($linktype)) {
UI::exitError(getMLText("admin_tools"),getMLText("unknown_document_linktype"));
}
$name = $_POST["name"];
if (!$linktype->setName($name)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_edit_linktype')));
add_log_line(".php&action=editlinktype&linktypeid=".$linktypeid);
}
else {
UI::exitError(getMLText("admin_tools"),getMLText("unknown_command"));
}
header("Location:../out/out.LinkTypes.php?linktypeid=".$linktypeid);
?>

60
out/out.LinkTypes.php Normal file
View File

@ -0,0 +1,60 @@
<?php
// MyDMS. Document Management System
// Copyright (C) 2002-2005 Markus Westphal
// Copyright (C) 2006-2008 Malcolm Cowe
// Copyright (C) 2010 Matteo Lucarelli
// Copyright (C) 2010-2016 Uwe Steinmann
//
// 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.
if(!isset($settings))
require_once("../inc/inc.Settings.php");
require_once("inc/inc.Utils.php");
require_once("inc/inc.LogInit.php");
require_once("inc/inc.Language.php");
require_once("inc/inc.Init.php");
require_once("inc/inc.Extension.php");
require_once("inc/inc.DBInit.php");
require_once("inc/inc.ClassUI.php");
require_once("inc/inc.Authentication.php");
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
$view = UI::factory($theme, $tmp[1], array('dms'=>$dms, 'user'=>$user));
$accessop = new SeedDMS_AccessOperation($dms, $user, $settings);
if (!$accessop->check_view_access($view, $_GET)) {
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
}
$linktypes = $dms->getLinkTypes();
if(isset($_GET['linktypeid']) && $_GET['linktypeid']) {
$selcat = $dms->getLinkType($_GET['linktypeid']);
} else {
$selcat = null;
}
if($view) {
$view->setParam('conversionmgr', $conversionmgr);
$view->setParam('linktypes', $linktypes);
$view->setParam('sellinktype', $selcat);
$view->setParam('accessobject', $accessop);
$view->setParam('showtree', showtree());
$view->setParam('cachedir', $settings->_cacheDir);
$view->setParam('previewWidthList', $settings->_previewWidthList);
$view->setParam('timeout', $settings->_cmdTimeout);
$view->setParam('onepage', $settings->_onePageMode); // do most navigation by reloading areas of pages with ajax
$view->setParam('xsendfile', $settings->_enableXsendfile);
$view($_GET);
}

View File

@ -0,0 +1,181 @@
<?php
/**
* Implementation of LinkTypes view
*
* @category DMS
* @package SeedDMS
* @license GPL 2
* @version @version@
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2002-2005 Markus Westphal,
* 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli,
* 2010-2024 Uwe Steinmann
* @version Release: @package_version@
*/
/**
* Class which outputs the html page for LinkTypes view
*
* @category DMS
* @package SeedDMS
* @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2002-2005 Markus Westphal,
* 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli,
* 2010-2024 Uwe Steinmann
* @version Release: @package_version@
*/
class SeedDMS_View_LinkTypes extends SeedDMS_Theme_Style {
function js() { /* {{{ */
$sellinktype = $this->params['sellinktype'];
header('Content-Type: application/javascript; charset=UTF-8');
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() {
$( "#selector" ).change(function() {
$('div.ajax').trigger('update', {linktypeid: $(this).val()});
window.history.pushState({"html":"","pageTitle":""},"", '../out/out.LinkTypes.php?linktypeid=' + $(this).val());
});
});
<?php
$this->printDeleteFolderButtonJs();
$this->printDeleteDocumentButtonJs();
$this->printClickDocumentJs();
} /* }}} */
function info() { /* {{{ */
$dms = $this->params['dms'];
$sellinktype = $this->params['sellinktype'];
$conversionmgr = $this->params['conversionmgr'];
$cachedir = $this->params['cachedir'];
$previewwidth = $this->params['previewWidthList'];
$timeout = $this->params['timeout'];
$xsendfile = $this->params['xsendfile'];
if($sellinktype) {
$this->contentHeading(getMLText("link_type_info"));
/*
$c = $sellinktype->countDocumentLinksByType();
echo "<table class=\"table table-condensed table-sm\">\n";
echo "<tr><td>".getMLText('document_count')."</td><td>".($c)."</td></tr>\n";
echo "</table>";
$documents = $sellinktype->getDocumentsByCategory(10);
if($documents) {
print $this->folderListHeader();
print "<tbody>\n";
$previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidth, $timeout, $xsendfile);
if($conversionmgr)
$previewer->setConversionMgr($conversionmgr);
foreach($documents as $doc) {
echo $this->documentListRow($doc, $previewer);
}
print "</tbody></table>";
}
*/
}
} /* }}} */
function actionmenu() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$sellinktype = $this->params['sellinktype'];
if($sellinktype && !$sellinktype->isUsed()) {
?>
<form style="display: inline-block;" method="post" action="../op/op.LinkTypes.php" >
<?php echo createHiddenFieldWithKey('removelinktype'); ?>
<input type="hidden" name="linktypeid" value="<?php echo $sellinktype->getID()?>">
<input type="hidden" name="action" value="removelinktype">
<?php $this->formSubmit('<i class="fa fa-remove"></i> '.getMLText('rm_link_type'),'','','danger');?>
</form>
<?php
}
} /* }}} */
function showCategoryForm($linktype) { /* {{{ */
?>
<form class="form-horizontal" style="margin-bottom: 0px;" action="../op/op.LinkTypes.php" method="post">
<?php if(!$linktype) { ?>
<?php echo createHiddenFieldWithKey('addlinktype'); ?>
<input type="hidden" name="action" value="addlinktype">
<?php } else { ?>
<?php echo createHiddenFieldWithKey('editlinktype'); ?>
<input type="hidden" name="action" value="editlinktype">
<input type="hidden" name="linktypeid" value="<?php echo $linktype->getID()?>">
<?php } ?>
<?php
$this->contentContainerStart();
$this->formField(
getMLText("name"),
array(
'element'=>'input',
'type'=>'text',
'name'=>'name',
'value'=>($linktype ? htmlspecialchars($linktype->getName()) : '')
)
);
$this->contentContainerEnd();
$this->formSubmit("<i class=\"fa fa-save\"></i> ".getMLText('save'));
?>
</form>
<?php
} /* }}} */
function form() { /* {{{ */
$sellinktype = $this->params['sellinktype'];
$this->showCategoryForm($sellinktype);
} /* }}} */
function show() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$linktypes = $this->params['linktypes'];
$sellinktype = $this->params['sellinktype'];
$this->htmlStartPage(getMLText("admin_tools"));
$this->globalNavigation();
$this->contentStart();
$this->pageNavigation(getMLText("admin_tools"), "admin_tools");
$this->contentHeading(getMLText("global_link_types"));
$this->rowStart();
$this->columnStart(6);
?>
<form class="form-horizontal">
<?php
$options = array();
$options[] = array("-1", getMLText("choose_link_type"));
$options[] = array("0", getMLText("new_link_type"));
foreach ($linktypes as $linktype) {
$options[] = array($linktype->getID(), htmlspecialchars($linktype->getName()), $sellinktype && $linktype->getID()==$sellinktype->getID(), array(/*array('data-subtitle', $linktype->countDocumentLinksByType().' '.getMLText('documents'))*/));
}
$this->formField(
null, //getMLText("selection"),
array(
'element'=>'select',
'id'=>'selector',
'class'=>'chzn-select',
'options'=>$options,
'placeholder'=>getMLText('choose_link_type'),
)
);
?>
</form>
<div class="ajax" style="margin-bottom: 15px;" data-view="LinkTypes" data-action="actionmenu" <?php echo ($sellinktype ? "data-query=\"linktypeid=".$sellinktype->getID()."\"" : "") ?>></div>
<!-- <div class="ajax" data-view="LinkTypes" data-action="info" <?php echo ($sellinktype ? "data-query=\"linktypeid=".$sellinktype->getID()."\"" : "") ?>></div> -->
<?php
$this->columnEnd();
$this->columnStart(6);
?>
<div class="ajax" data-view="LinkTypes" data-action="form" <?php echo ($sellinktype ? "data-query=\"linktypeid=".$sellinktype->getID()."\"" : "") ?>></div>
<?php
$this->columnEnd();
$this->rowEnd();
$this->contentEnd();
$this->htmlEndPage();
} /* }}} */
}