- new files to manage and use attributes

This commit is contained in:
steinm 2012-10-09 09:44:58 +00:00
parent c15d62fe73
commit cad78d5304
4 changed files with 576 additions and 0 deletions

147
op/op.AttributeMgr.php Normal file
View File

@ -0,0 +1,147 @@
<?php
// MyDMS. Document Management System
// Copyright (C) 2002-2005 Markus Westphal
// Copyright (C) 2006-2008 Malcolm Cowe
// Copyright (C) 2009-2012 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.DBInit.php");
include("../inc/inc.Language.php");
include("../inc/inc.ClassUI.php");
include("../inc/inc.ClassEmail.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;
// add new attribute definition ---------------------------------------------
if ($action == "addattrdef") {
/* Check if the form data comes for a trusted request */
if(!checkFormKey('addattrdef')) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
}
$name = trim($_POST["name"]);
$type = intval($_POST["type"]);
$objtype = intval($_POST["objtype"]);
if(isset($_POST["multiple"]))
$multiple = trim($_POST["multiple"]);
else
$multiple = 0;
$minvalues = intval($_POST["minvalues"]);
$maxvalues = intval($_POST["maxvalues"]);
$valueset = trim($_POST["valueset"]);
if($name == '') {
UI::exitError(getMLText("admin_tools"),getMLText("attrdef_noname"));
}
if (is_object($dms->getAttributeDefinitionByName($name))) {
UI::exitError(getMLText("admin_tools"),getMLText("attrdef_exists"));
}
$newAttrdef = $dms->addAttributeDefinition($name, $objtype, $type, $multiple, $minvalues, $maxvalues, $valueset);
if (!$newAttrdef) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
$attrdefid=$newAttrdef->getID();
}
// delet attribute definition -----------------------------------------------
else if ($action == "removeattrdef") {
/* Check if the form data comes for a trusted request */
if(!checkFormKey('removeattrdef')) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
}
if (!isset($_POST["attrdefid"]) || !is_numeric($_POST["attrdefid"]) || intval($_POST["attrdefid"])<1) {
UI::exitError(getMLText("admin_tools"),getMLText("unknown_attrdef"));
}
$attrdefid = $_POST["attrdefid"];
$attrdef = $dms->getAttributeDefinition($attrdefid);
if (!is_object($attrdef)) {
UI::exitError(getMLText("admin_tools"),getMLText("unknown_attrdef"));
}
if (!$attrdef->remove()) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
$attrdefid=-1;
}
// edit attribute definition -----------------------------------------------
else if ($action == "editattrdef") {
/* Check if the form data comes for a trusted request */
if(!checkFormKey('editattrdef')) {
UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token"));
}
if (!isset($_POST["attrdefid"]) || !is_numeric($_POST["attrdefid"]) || intval($_POST["attrdefid"])<1) {
UI::exitError(getMLText("admin_tools"),getMLText("unknown_attrdef"));
}
$attrdefid = $_POST["attrdefid"];
$attrdef = $dms->getAttributeDefinition($attrdefid);
if (!is_object($attrdef)) {
UI::exitError(getMLText("admin_tools"),getMLText("unknown_attrdef"));
}
$name = $_POST["name"];
$type = intval($_POST["type"]);
$objtype = intval($_POST["objtype"]);
if(isset($_POST["multiple"]))
$multiple = trim($_POST["multiple"]);
else
$multiple = 0;
$minvalues = intval($_POST["minvalues"]);
$maxvalues = intval($_POST["maxvalues"]);
$valueset = trim($_POST["valueset"]);
if (!$attrdef->setName($name)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
if (!$attrdef->setType($type)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
if (!$attrdef->setObjType($objtype)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
if (!$attrdef->setMultipleValues($multiple)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
if (!$attrdef->setMinValues($minvalues)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
if (!$attrdef->setMaxValues($maxvalues)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
if (!$attrdef->setValueSet($valueset)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}
}
else {
UI::exitError(getMLText("admin_tools"),getMLText("unknown_command"));
}
header("Location:../out/out.AttributeMgr.php?attrdefid=".$attrdefid);
?>

101
op/op.EditAttributes.php Normal file
View File

@ -0,0 +1,101 @@
<?php
// MyDMS. Document Management System
// Copyright (C) 2002-2005 Markus Westphal
// Copyright (C) 2006-2008 Malcolm Cowe
// Copyright (C) 2010 Matteo Lucarelli
//
// 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.LogInit.php");
include("../inc/inc.Utils.php");
include("../inc/inc.DBInit.php");
include("../inc/inc.Language.php");
include("../inc/inc.ClassUI.php");
include("../inc/inc.ClassEmail.php");
include("../inc/inc.Authentication.php");
/* Check if the form data comes for a trusted request */
if(!checkFormKey('editattributes')) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_request_token"))),getMLText("invalid_request_token"));
}
if (!isset($_POST["documentid"]) || !is_numeric($_POST["documentid"]) || intval($_POST["documentid"])<1) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
}
$documentid = $_POST["documentid"];
$document = $dms->getDocument($documentid);
if (!is_object($document)) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
}
$folder = $document->getFolder();
$docPathHTML = getFolderPathHTML($folder, true). " / <a href=\"../out/out.ViewDocument.php?documentid=".$documentid."\">".$document->getName()."</a>";
if ($document->getAccessMode($user) < M_READWRITE) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("access_denied"));
}
$versionid = $_POST["version"];
$version = $document->getContentByVersion($versionid);
if (!is_object($version)) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version"));
}
$attributes = $_POST["attributes"];
if($attributes) {
$oldattributes = $version->getAttributes();
foreach($attributes as $attrdefid=>$attribute) {
if(!isset($oldattributes[$attrdefid]) || $attribute != $oldattributes[$attrdefid]->getValue()) {
if(!$version->setAttributeValue($dms->getAttributeDefinition($attrdefid), $attribute)) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
} else {
$document->getNotifyList();
if($notifier) {
$subject = "###SITENAME###: ".$document->getName().", v.".$version->_version." - ".getMLText("attribute_changed_email");
$message = getMLText("attribute_changed_email")."\r\n";
$message .=
getMLText("document").": ".$document->getName()."\r\n".
getMLText("version").": ".$version->_version."\r\n".
getMLText("attribute").": ".$attribute."\r\n".
getMLText("user").": ".$user->getFullName()." <". $user->getEmail() .">\r\n".
"URL: ###URL_PREFIX###out/out.ViewDocument.php?documentid=".$document->getID()."&version=".$version->_version."\r\n";
// $subject=mydmsDecodeString($subject);
// $message=mydmsDecodeString($message);
if(isset($document->_notifyList["users"])) {
$notifier->toList($user, $document->_notifyList["users"], $subject, $message);
}
if(isset($document->_notifyList["groups"])) {
foreach ($document->_notifyList["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message);
}
}
}
}
}
}
}
add_log_line("?documentid=".$documentid);
header("Location:../out/out.DocumentVersionDetail.php?documentid=".$documentid."&version=".$versionid);
?>

247
out/out.AttributeMgr.php Normal file
View File

@ -0,0 +1,247 @@
<?php
// MyDMS. Document Management System
// Copyright (C) 2002-2005 Markus Westphal
// Copyright (C) 2006-2008 Malcolm Cowe
// Copyright (C) 2010 Matteo Lucarelli
// Copyright (C) 2009-2012 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.DBInit.php");
include("../inc/inc.Language.php");
include("../inc/inc.ClassUI.php");
include("../inc/inc.Authentication.php");
if (!$user->isAdmin()) {
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
}
$attrdefs = $dms->getAllAttributeDefinitions();
?>
<script language="JavaScript">
obj = -1;
function showAttributeDefinitions(selectObj) {
if (obj != -1)
obj.style.display = "none";
id = selectObj.options[selectObj.selectedIndex].value;
if (id == -1)
return;
obj = document.getElementById("attrdefs" + id);
obj.style.display = "";
}
</script>
<?php
UI::htmlStartPage(getMLText("admin_tools"));
UI::globalNavigation();
UI::pageNavigation(getMLText("admin_tools"), "admin_tools");
UI::contentHeading(getMLText("attrdef_management"));
UI::contentContainerStart();
?>
<table>
<tr>
<td><?php echo getMLText("selection")?>:</td>
<td>
<select onchange="showAttributeDefinitions(this)" id="selector">
<option value="-1"><?php echo getMLText("choose_attrdef")?>
<option value="0"><?php echo getMLText("new_attrdef")?>
<?php
$selected=0;
$count=2;
if($attrdefs) {
foreach ($attrdefs as $attrdef) {
if (isset($_GET["attrdefid"]) && $attrdef->getID()==$_GET["attrdefid"]) $selected=$count;
switch($attrdef->getObjType()) {
case LetoDMS_Core_AttributeDefinition::objtype_all:
$ot = "all";
break;
case LetoDMS_Core_AttributeDefinition::objtype_folder:
$ot = getMLText("folder");
break;
case LetoDMS_Core_AttributeDefinition::objtype_document:
$ot = getMLText("document");
break;
case LetoDMS_Core_AttributeDefinition::objtype_documentcontent:
$ot = getMLText("version");
break;
}
print "<option value=\"".$attrdef->getID()."\">" . htmlspecialchars($attrdef->getName() ." (".$ot.")");
$count++;
}
}
?>
</select>
&nbsp;&nbsp;
</td>
<td id="attrdefs0" style="display : none;">
<form action="../op/op.AttributeMgr.php" method="post">
<?php echo createHiddenFieldWithKey('addattrdef'); ?>
<input type="Hidden" name="action" value="addattrdef">
<table>
<tr>
<td><?php printMLText("attrdef_name");?>:</td><td><input type="text" name="name"></td>
</tr>
<tr>
<td><?php printMLText("attrdef_objtype");?>:</td><td><select name="objtype"><option value="<?php echo LetoDMS_Core_AttributeDefinition::objtype_all ?>">All</option><option value="<?php echo LetoDMS_Core_AttributeDefinition::objtype_folder ?>">Folder</option><option value="<?php echo LetoDMS_Core_AttributeDefinition::objtype_document ?>"><?php printMLText("document"); ?></option><option value="<?php echo LetoDMS_Core_AttributeDefinition::objtype_documentcontent ?>"><?php printMLText("version"); ?></option></select>
</tr>
<tr>
<td><?php printMLText("attrdef_type");?>:</td><td><select name="type"><option value="<?php echo LetoDMS_Core_AttributeDefinition::type_int ?>">Integer</option><option value="<?php echo LetoDMS_Core_AttributeDefinition::type_float ?>">Float</option><option value="<?php echo LetoDMS_Core_AttributeDefinition::type_string ?>">String</option><option value="<?php echo LetoDMS_Core_AttributeDefinition::type_boolean ?>">Boolean</option></select></td>
</tr>
<tr>
<td><?php printMLText("attrdef_multiple");?>:</td><td><input type="checkbox" value="1" name="multiple" /></td>
</tr>
<tr>
<td><?php printMLText("attrdef_minvalues");?>:</td><td><input type="text" value="" name="minvalues" /></td>
</tr>
<tr>
<td><?php printMLText("attrdef_maxvalues");?>:</td><td><input type="text" value="" name="maxvalues" /></td>
</tr>
<tr>
<td><?php printMLText("attrdef_valueset");?>:</td><td><input type="text" value="" name="valueset" /></td>
</tr>
</table>
<input type="Submit" value="<?php printMLText("new_attrdef"); ?>">
</form>
</td>
<?php
if($attrdefs) {
foreach ($attrdefs as $attrdef) {
print "<td id=\"attrdefs".$attrdef->getID()."\" style=\"display : none;\">";
?>
<table>
<tr>
<td colspan="2">
<?php
if(!$attrdef->isUsed()) {
?>
<form style="display: inline-block;" method="post" action="../op/op.AttributeMgr.php" >
<?php echo createHiddenFieldWithKey('removeattrdef'); ?>
<input type="Hidden" name="attrdefid" value="<?php echo $attrdef->getID()?>">
<input type="Hidden" name="action" value="removeattrdef">
<input value="<?php echo getMLText("rm_attrdef")?>" type="submit">
</form>
<?php
} else {
?>
<p><?php echo getMLText('attrdef_in_use') ?></p>
<?php
}
?>
</td>
</tr>
<tr>
<td colspan="2">
<?php UI::contentSubHeading("");?>
</td>
</tr>
<form action="../op/op.AttributeMgr.php" method="post">
<tr>
<td>
<?php echo createHiddenFieldWithKey('editattrdef'); ?>
<input type="Hidden" name="action" value="editattrdef">
<input type="Hidden" name="attrdefid" value="<?php echo $attrdef->getID()?>" />
<?php printMLText("attrdef_name");?>:
</td>
<td>
<input name="name" value="<?php echo htmlspecialchars($attrdef->getName()) ?>">
</td>
</tr>
<tr>
<td>
<?php printMLText("attrdef_type");?>:
</td>
<td>
<select name="type"><option value="<?php echo LetoDMS_Core_AttributeDefinition::type_int ?>" <?php if($attrdef->getType() == LetoDMS_Core_AttributeDefinition::type_int) echo "selected"; ?>>Integer</option><option value="<?php echo LetoDMS_Core_AttributeDefinition::type_float ?>" <?php if($attrdef->getType() == LetoDMS_Core_AttributeDefinition::type_float) echo "selected"; ?>>Float</option><option value="<?php echo LetoDMS_Core_AttributeDefinition::type_string ?>" <?php if($attrdef->getType() == LetoDMS_Core_AttributeDefinition::type_string) echo "selected"; ?>>String</option><option value="<?php echo LetoDMS_Core_AttributeDefinition::type_boolean ?>" <?php if($attrdef->getType() == LetoDMS_Core_AttributeDefinition::type_boolean) echo "selected"; ?>>Boolean</option></select><br />
</td>
</tr>
<tr>
<td>
<?php printMLText("attrdef_objtype");?>:
</td>
<td>
<select name="objtype"><option value="<?php echo LetoDMS_Core_AttributeDefinition::objtype_all ?>">All</option><option value="<?php echo LetoDMS_Core_AttributeDefinition::objtype_folder ?>" <?php if($attrdef->getObjType() == LetoDMS_Core_AttributeDefinition::objtype_folder) echo "selected"; ?>>Folder</option><option value="<?php echo LetoDMS_Core_AttributeDefinition::objtype_document ?>" <?php if($attrdef->getObjType() == LetoDMS_Core_AttributeDefinition::objtype_document) echo "selected"; ?>>Document</option><option value="<?php echo LetoDMS_Core_AttributeDefinition::objtype_documentcontent ?>" <?php if($attrdef->getObjType() == LetoDMS_Core_AttributeDefinition::objtype_documentcontent) echo "selected"; ?>>Document content</option></select><br />
</td>
</tr>
<tr>
<td>
<?php printMLText("attrdef_multiple");?>:
</td>
<td>
<input type="checkbox" value="1" name="multiple" /><br />
</td>
</tr>
<tr>
<td>
<?php printMLText("attrdef_minvalues");?>:
</td>
<td>
<input type="text" value="<?php echo $attrdef->getMinValues() ?>" name="minvalues" /><br />
</td>
</tr>
<tr>
<td>
<?php printMLText("attrdef_maxvalues");?>:
</td>
<td>
<input type="text" value="<?php echo $attrdef->getMaxValues() ?>" name="maxvalues" /><br />
</td>
</tr>
<tr>
<td>
<?php printMLText("attrdef_valueset");?>:
</td>
<td>
<input type="text" value="<?php echo $attrdef->getValueSet() ?>" name="valueset" /><br />
</td>
</tr>
<tr>
<td>
<input type="Submit" value="<?php printMLText("save");?>">
</td>
</tr>
</form>
</table>
</td>
<?php
}
}
?>
</tr></table>
<script language="JavaScript">
sel = document.getElementById("selector");
sel.selectedIndex=<?php print $selected ?>;
showAttributeDefinitions(sel);
</script>
<?php
UI::contentContainerEnd();
UI::htmlEndPage();
?>

View File

@ -0,0 +1,81 @@
<?php
// MyDMS. Document Management System
// Copyright (C) 2002-2005 Markus Westphal
// Copyright (C) 2006-2008 Malcolm Cowe
// Copyright (C) 2010 Matteo Lucarelli
//
// 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.DBInit.php");
include("../inc/inc.Language.php");
include("../inc/inc.ClassUI.php");
include("../inc/inc.Authentication.php");
if (!isset($_GET["documentid"]) || !is_numeric($_GET["documentid"]) || intval($_GET["documentid"])<1) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
}
$documentid = $_GET["documentid"];
$document = $dms->getDocument($documentid);
if (!is_object($document)) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
}
$folder = $document->getFolder();
$docPathHTML = getFolderPathHTML($folder, true). " / <a href=\"../out/out.ViewDocument.php?documentid=".$documentid."\">".htmlspecialchars($document->getName())."</a>";
$versionid = $_GET["version"];
$version = $document->getContentByVersion($versionid);
if (!is_object($version)) {
UI::exitError(getMLText("document_title", array("documentname" => htmlspecialchars($document->getName()))),getMLText("invalid_version"));
}
UI::htmlStartPage(getMLText("document_title", array("documentname" => htmlspecialchars($document->getName()))));
UI::globalNavigation($folder);
UI::pageNavigation($docPathHTML, "view_document");
UI::contentHeading(getMLText("edit_attributes"));
UI::contentContainerStart();
?>
<form action="../op/op.EditAttributes.php" name="form1" method="POST">
<?php echo createHiddenFieldWithKey('editattributes'); ?>
<input type="Hidden" name="documentid" value="<?php print $documentid;?>">
<input type="Hidden" name="version" value="<?php print $versionid;?>">
<table cellpadding="3">
<?php
$attrdefs = $dms->getAllAttributeDefinitions(array(LetoDMS_Core_AttributeDefinition::objtype_documentcontent, LetoDMS_Core_AttributeDefinition::objtype_all));
if($attrdefs) {
foreach($attrdefs as $attrdef) {
?>
<tr>
<td><?php echo htmlspecialchars($attrdef->getName()); ?></td>
<td><?php UI::printAttributeEditField($attrdef, $version->getAttributeValue($attrdef)) ?></td>
</tr>
<?php
}
}
?>
<tr>
<td colspan="2"><br><input type="Submit" value="<?php printMLText("save") ?>"></td>
</tr>
</table>
</form>
<?php
UI::contentContainerEnd();
UI::htmlEndPage();
?>