fix handling of multivalue attributes

This commit is contained in:
Uwe Steinmann 2014-02-20 21:05:22 +01:00
parent 5c07f7545b
commit 90bea9a2fb
5 changed files with 57 additions and 8 deletions

View File

@ -58,6 +58,13 @@ if ($action == "addattrdef") {
if (is_object($dms->getAttributeDefinitionByName($name))) {
UI::exitError(getMLText("admin_tools"),getMLText("attrdef_exists"));
}
if($minvalues > 1 && $multiple == 0) {
UI::exitError(getMLText("admin_tools"),getMLText("attrdef_must_be_multiple"));
}
if($minvalues > $maxvalues) {
UI::exitError(getMLText("admin_tools"),getMLText("attrdef_min_greater_max"));
}
$newAttrdef = $dms->addAttributeDefinition($name, $objtype, $type, $multiple, $minvalues, $maxvalues, $valueset, $regex);
if (!$newAttrdef) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
@ -124,6 +131,14 @@ else if ($action == "editattrdef") {
$maxvalues = intval($_POST["maxvalues"]);
$valueset = trim($_POST["valueset"]);
$regex = trim($_POST["regex"]);
if($minvalues > 1 && $multiple == 0) {
UI::exitError(getMLText("admin_tools"),getMLText("attrdef_must_be_multiple"));
}
if($minvalues > $maxvalues) {
UI::exitError(getMLText("admin_tools"),getMLText("attrdef_min_greater_max"));
}
if (!$attrdef->setName($name)) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}

View File

@ -231,8 +231,8 @@ if($categories) {
}
}
$oldattributes = $document->getAttributes();
if($attributes) {
$oldattributes = $document->getAttributes();
foreach($attributes as $attrdefid=>$attribute) {
$attrdef = $dms->getAttributeDefinition($attrdefid);
if($attribute) {
@ -251,6 +251,13 @@ if($attributes) {
}
}
}
foreach($oldattributes as $attrdefid=>$oldattribute) {
if(!isset($attributes[$attrdefid])) {
if(!$document->removeAttribute($dms->getAttributeDefinition($attrdefid)))
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
}
}
if($sequence != "keep") {
if($document->setSequence($sequence)) {

View File

@ -153,8 +153,8 @@ if(($oldcomment = $folder->getComment()) != $comment) {
}
}
$oldattributes = $folder->getAttributes();
if($attributes) {
$oldattributes = $folder->getAttributes();
foreach($attributes as $attrdefid=>$attribute) {
$attrdef = $dms->getAttributeDefinition($attrdefid);
if($attribute) {
@ -173,6 +173,13 @@ if($attributes) {
}
}
}
foreach($oldattributes as $attrdefid=>$oldattribute) {
if(!isset($attributes[$attrdefid])) {
if(!$folder->removeAttribute($dms->getAttributeDefinition($attrdefid)))
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("error_occured"));
}
}
if(strcasecmp($sequence, "keep")) {
if($folder->setSequence($sequence)) {

View File

@ -186,7 +186,11 @@ function showAttributeDefinitions(selectObj) {
print "<td><a href=\"../out/out.ViewDocument.php?documentid=".$doc->getID()."\">" . htmlspecialchars($doc->getName()) . "</a></td>\n";
print "<td>".htmlspecialchars($owner->getFullName())."</td>";
print "<td>".getOverallStatusText($status["status"])."</td>";
print "<td>".$doc->getAttributeValue($attrdef)."</td>";
$value = $doc->getAttributeValue($attrdef);
if(is_array($value))
print "<td>".implode('; ', $value)."</td>";
else
print "<td>".$value."</td>";
print "<td>";
print "<a href='../out/out.EditDocument.php?documentid=".$doc->getID()."' class=\"btn btn-mini\"><i class=\"icon-edit\"></i> ".getMLText("edit")."</a>";
print "</td></tr>\n";
@ -209,7 +213,11 @@ function showAttributeDefinitions(selectObj) {
print "<td><i class=\"icon-folder-close-alt\"></i></td>";
print "<td><a href=\"../out/out.ViewFolder.php?folderid=".$folder->getID()."\">" . htmlspecialchars($folder->getName()) . "</a></td>\n";
print "<td>".htmlspecialchars($owner->getFullName())."</td>";
print "<td>".$folder->getAttributeValue($attrdef)."</td>";
$value = $folder->getAttributeValue($attrdef);
if(is_array($value))
print "<td>".implode('; ', $value)."</td>";
else
print "<td>".$value."</td>";
print "<td>";
print "<a href='../out/out.EditFolder.php?folderid=".$folder->getID()."' class=\"btn btn-mini\"><i class=\"icon-edit\"></i> ".getMLText("edit")."</a>";
print "</td></tr>";
@ -237,7 +245,11 @@ function showAttributeDefinitions(selectObj) {
print "<td>".htmlspecialchars($owner->getFullName())."</td>";
print "<td>".$content->getMimeType()."</td>";
print "<td>".$content->getVersion()."</td>";
print "<td>".$content->getAttributeValue($attrdef)."</td>";
$value = $content->getAttributeValue($attrdef);
if(is_array($value))
print "<td>".implode('; ', $value)."</td>";
else
print "<td>".$value."</td>";
print "<td>";
print "<a href='../out/out.EditDocument.php?documentid=".$doc->getID()."' class=\"btn btn-mini\"><i class=\"icon-edit\"></i> ".getMLText("edit")."</a>";
print "</td></tr>\n";

View File

@ -875,13 +875,21 @@ function folderSelected<?php echo $formName ?>(id, name) {
function printAttributeEditField($attrdef, $objvalue, $fieldname='attributes') { /* {{{ */
if($valueset = $attrdef->getValueSetAsArray()) {
echo "<select name=\"".$fieldname."[".$attrdef->getId()."]\">";
if($attrdef->getMinValues() < 1) {
echo "<select name=\"".$fieldname."[".$attrdef->getId()."]";
if($attrdef->getMultipleValues()) {
echo "[]\" multiple";
} else {
echo "\"";
}
echo ">";
if(!$attrdef->getMultipleValues()) {
echo "<option value=\"\"></option>";
}
foreach($valueset as $value) {
echo "<option value=\"".htmlspecialchars($value)."\"";
if($value == $objvalue)
if(is_array($objvalue) && in_array($value, $objvalue))
echo " selected";
elseif($value == $objvalue)
echo " selected";
echo ">".htmlspecialchars($value)."</option>";
}