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

This commit is contained in:
Uwe Steinmann 2018-02-23 09:06:03 +01:00
commit a575714218
10 changed files with 290 additions and 85 deletions

View File

@ -90,6 +90,7 @@
- fix 2-factor authentification
- configuration variables in extension of type 'select' may have an empty option
- default position of documents/folders can be set in configuration (Closes #381)
- attribute values can be deleted from all folders, documents
--------------------------------------------------------------------------------
Changes in version 5.1.5

View File

@ -71,13 +71,13 @@ class SeedDMS_Core_Attribute { /* {{{ */
*/
protected $_dms;
/**
* SeedDMS_Core_Attribute constructor.
* @param $id
* @param $obj
* @param $attrdef
* @param $value
*/
/**
* SeedDMS_Core_Attribute constructor.
* @param $id
* @param $obj
* @param $attrdef
* @param $value
*/
function __construct($id, $obj, $attrdef, $value) { /* {{{ */
$this->_id = $id;
$this->_obj = $obj;
@ -379,10 +379,10 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
*/
protected $_dms;
/**
* @var string
*/
protected $_separator;
/**
* @var string
*/
protected $_separator;
/*
* Possible skalar data types of an attribute
@ -403,21 +403,21 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
const objtype_document = '2';
const objtype_documentcontent = '3';
/**
* Constructor
*
* @param integer $id internal id of attribute definition
* @param string $name name of attribute
* @param integer $objtype type of object for which this attribute definition
* may be used.
* @param integer $type skalar type of attribute
* @param boolean $multiple set to true if multiple values are allowed
* @param integer $minvalues minimum number of values
* @param integer $maxvalues maximum number of values
* @param string $valueset separated list of allowed values, the first char
* is taken as the separator
* @param $regex
*/
/**
* Constructor
*
* @param integer $id internal id of attribute definition
* @param string $name name of attribute
* @param integer $objtype type of object for which this attribute definition
* may be used.
* @param integer $type skalar type of attribute
* @param boolean $multiple set to true if multiple values are allowed
* @param integer $minvalues minimum number of values
* @param integer $maxvalues maximum number of values
* @param string $valueset separated list of allowed values, the first char
* is taken as the separator
* @param $regex
*/
function __construct($id, $name, $objtype, $type, $multiple, $minvalues, $maxvalues, $valueset, $regex) { /* {{{ */
$this->_id = $id;
$this->_name = $name;
@ -478,15 +478,15 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
*/
function getObjType() { return $this->_objtype; }
/**
* Set object type of attribute definition
*
* This can be one of objtype_all,
* objtype_folder, objtype_document, or objtype_documentcontent.
*
* @param integer $objtype type
* @return bool
*/
/**
* Set object type of attribute definition
*
* This can be one of objtype_all,
* objtype_folder, objtype_document, or objtype_documentcontent.
*
* @param integer $objtype type
* @return bool
*/
function setObjType($objtype) { /* {{{ */
$db = $this->_dms->getDB();
@ -509,15 +509,15 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
*/
function getType() { return $this->_type; }
/**
* Set type of attribute definition
*
* This can be one of type_int, type_float, type_string, type_boolean,
* type_url, type_email.
*
* @param integer $type type
* @return bool
*/
/**
* Set type of attribute definition
*
* This can be one of type_int, type_float, type_string, type_boolean,
* type_url, type_email.
*
* @param integer $type type
* @return bool
*/
function setType($type) { /* {{{ */
$db = $this->_dms->getDB();
@ -537,13 +537,13 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
*/
function getMultipleValues() { return $this->_multiple; }
/**
* Set if attribute definition allows multi values for attribute
*
* @param boolean $mv true if attribute may have multiple values, otherwise
* false
* @return bool
*/
/**
* Set if attribute definition allows multi values for attribute
*
* @param boolean $mv true if attribute may have multiple values, otherwise
* false
* @return bool
*/
function setMultipleValues($mv) { /* {{{ */
$db = $this->_dms->getDB();
@ -642,14 +642,14 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
return array();
} /* }}} */
/**
* Get the n'th value of a value set
*
* @param $ind
* @return string n'th value of value set or false if the index is
* out of range or the value set has less than 2 chars
* @internal param int $index
*/
/**
* Get the n'th value of a value set
*
* @param $ind
* @return string n'th value of value set or false if the index is
* out of range or the value set has less than 2 chars
* @internal param int $index
*/
function getValueSetValue($ind) { /* {{{ */
if(strlen($this->_valueset) > 1) {
$tmp = explode($this->_valueset[0], substr($this->_valueset, 1));
@ -755,15 +755,15 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
return true;
} /* }}} */
/**
* Parse a given value according to attribute definition
*
* The return value is always an array, even if the attribute is single
* value attribute.
*
* @param $value
* @return array|bool
*/
/**
* Parse a given value according to attribute definition
*
* The return value is always an array, even if the attribute is single
* value attribute.
*
* @param $value
* @return array|bool
*/
function parseValue($value) { /* {{{ */
if($this->getMultipleValues()) {
/* If the value doesn't start with the separator used in the value set,
@ -788,7 +788,7 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
*
* @param integer $limit return not more the n objects of each type
* @return array|bool
*/
*/
function getStatistics($limit=0) { /* {{{ */
$db = $this->_dms->getDB();
@ -921,7 +921,7 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
} /* }}} */
/**
* Get all documents and folder by a given attribute value
* Get all documents and folders by a given attribute value
*
* @param string $attrvalue value of attribute
* @param integer $limit limit number of documents/folders
@ -932,11 +932,14 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
$result = array('docs'=>array(), 'folders'=>array(), 'contents'=>array());
if($this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_all ||
$this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_document) {
if($this->_multiple)
$queryStr = "SELECT * FROM `tblDocumentAttributes` WHERE `attrdef`=".$this->_id." AND (`value` like ".$db->qstr("%".$this->getValueSetSeparator().$attrvalue.$this->getValueSetSeparator()."%")." OR `value` like ".$db->qstr("%".$this->getValueSetSeparator().$attrvalue).")";
else
$queryStr = "SELECT * FROM `tblDocumentAttributes` WHERE `attrdef`=".$this->_id." AND `value`=".$db->qstr($attrvalue);
$this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_document) {
$queryStr = "SELECT * FROM `tblDocumentAttributes` WHERE `attrdef`=".$this->_id." AND ";
if($this->getMultipleValues()) {
$sep = $this->getValueSetSeparator();
$queryStr .= "(`value` like ".$db->qstr($sep.$attrvalue.'%')." OR `value` like ".$db->qstr('%'.$sep.$attrvalue.$sep.'%')." OR `value` like ".$db->qstr('%'.$sep.$attrvalue).")";
} else {
$queryStr .= "`value`=".$db->qstr($attrvalue);
}
if($limit)
$queryStr .= " limit ".(int) $limit;
$resArr = $db->getResultArray($queryStr);
@ -951,10 +954,13 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
if($this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_all ||
$this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_folder) {
if($this->_multiple)
$queryStr = "SELECT * FROM `tblFolderAttributes` WHERE `attrdef`=".$this->_id." AND (`value` like ".$db->qstr("%".$this->getValueSetSeparator().$attrvalue.$this->getValueSetSeparator()."%")." OR `value` like ".$db->qstr("%".$this->getValueSetSeparator().$attrvalue).")";
else
$queryStr = "SELECT * FROM `tblFolderAttributes` WHERE `attrdef`=".$this->_id." AND `value`=".$db->qstr($attrvalue);
$queryStr = "SELECT * FROM `tblFolderAttributes` WHERE `attrdef`=".$this->_id." AND ";
if($this->getMultipleValues()) {
$sep = $this->getValueSetSeparator();
$queryStr .= "(`value` like ".$db->qstr($sep.$attrvalue.'%')." OR `value` like ".$db->qstr('%'.$sep.$attrvalue.$sep.'%')." OR `value` like ".$db->qstr('%'.$sep.$attrvalue).")";
} else {
$queryStr .= "`value`=".$db->qstr($attrvalue);
}
if($limit)
$queryStr .= " limit ".(int) $limit;
$resArr = $db->getResultArray($queryStr);
@ -970,6 +976,72 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
return $result;
} /* }}} */
/**
* Remove a given attribute value from all documents, versions and folders
*
* @param string $attrvalue value of attribute
* @return array array containing list of documents and folders
*/
public function removeValue($attrvalue) { /* {{{ */
$db = $this->_dms->getDB();
foreach(array('document', 'documentcontent', 'folder') as $type) {
if($type == 'document') {
$tablename = "tblDocumentAttributes";
$objtype = SeedDMS_Core_AttributeDefinition::objtype_document;
} elseif($type == 'documentcontent') {
$tablename = "tblDocumentContentAttributes";
$objtype = SeedDMS_Core_AttributeDefinition::objtype_documentcontent;
} elseif($type == 'folder') {
$tablename = "tblFolderAttributes";
$objtype = SeedDMS_Core_AttributeDefinition::objtype_folder;
}
if($this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_all || $objtype) {
$queryStr = "SELECT * FROM `".$tablename."` WHERE `attrdef`=".$this->_id." AND ";
if($this->getMultipleValues()) {
$sep = $this->getValueSetSeparator();
$queryStr .= "(`value` like ".$db->qstr($sep.$attrvalue.'%')." OR `value` like ".$db->qstr('%'.$sep.$attrvalue.$sep.'%')." OR `value` like ".$db->qstr('%'.$sep.$attrvalue).")";
} else {
$queryStr .= "`value`=".$db->qstr($attrvalue);
}
$resArr = $db->getResultArray($queryStr);
if($resArr) {
$db->startTransaction();
foreach($resArr as $rec) {
if($rec['value'] == $attrvalue) {
$queryStr = "DELETE FROM `".$tablename."` WHERE `id`=".$rec['id'];
} else {
if($this->getMultipleValues()) {
$sep = substr($rec['value'], 0, 1);
$vsep = $this->getValueSetSeparator();
if($sep == $vsep)
$values = explode($sep, substr($rec['value'], 1));
else
$values = array($rec['value']);
if (($key = array_search($attrvalue, $values)) !== false) {
unset($values[$key]);
}
if($values) {
$queryStr = "UPDATE `".$tablename."` SET `value`=".$db->qstr($sep.implode($sep, $values))." WHERE `id`=".$rec['id'];
} else {
$queryStr = "DELETE FROM `".$tablename."` WHERE `id`=".$rec['id'];
}
} else {
}
}
if (!$db->getResult($queryStr)) {
$db->rollbackTransaction();
return false;
}
}
$db->commitTransaction();
}
}
}
return true;
} /* }}} */
/**
* Validate value against attribute definition
*
@ -1057,7 +1129,7 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */
$this->_validation_error = 3;
break;
case self::type_boolean: /** @todo: Same case in LINE 966 */
foreach($values as $value) {
foreach($values as $value) {
$success &= preg_match('/^[01]$/', $value);
}
break;

View File

@ -1812,6 +1812,8 @@ class SeedDMS_Core_DMS {
if($attrdef->getObjType() == SeedDMS_Core_AttributeDefinition::objtype_folder || $attrdef->getObjType() == SeedDMS_Core_AttributeDefinition::objtype_all) {
if($valueset = $attrdef->getValueSet()) {
if($attrdef->getMultipleValues()) {
if(is_string($attribute))
$attribute = array($attribute);
$searchAttributes[] = "EXISTS (SELECT NULL FROM `tblFolderAttributes` WHERE `tblFolderAttributes`.`attrdef`=".$attrdefid." AND (`tblFolderAttributes`.`value` like '%".$valueset[0].implode("%' OR `tblFolderAttributes`.`value` like '%".$valueset[0], $attribute)."%') AND `tblFolderAttributes`.`folder`=`tblFolders`.`id`)";
} else
$searchAttributes[] = "EXISTS (SELECT NULL FROM `tblFolderAttributes` WHERE `tblFolderAttributes`.`attrdef`=".$attrdefid." AND `tblFolderAttributes`.`value`='".$attribute."' AND `tblFolderAttributes`.`folder`=`tblFolders`.`id`)";
@ -1965,6 +1967,8 @@ class SeedDMS_Core_DMS {
if($attrdef->getObjType() == SeedDMS_Core_AttributeDefinition::objtype_document || $attrdef->getObjType() == SeedDMS_Core_AttributeDefinition::objtype_all) {
if($valueset = $attrdef->getValueSet()) {
if($attrdef->getMultipleValues()) {
if(is_string($attribute))
$attribute = array($attribute);
$searchAttributes[] = "EXISTS (SELECT NULL FROM `tblDocumentAttributes` WHERE `tblDocumentAttributes`.`attrdef`=".$attrdefid." AND (`tblDocumentAttributes`.`value` like '%".$valueset[0].implode("%' OR `tblDocumentAttributes`.`value` like '%".$valueset[0], $attribute)."%') AND `tblDocumentAttributes`.`document` = `tblDocuments`.`id`)";
} else
$searchAttributes[] = "EXISTS (SELECT NULL FROM `tblDocumentAttributes` WHERE `tblDocumentAttributes`.`attrdef`=".$attrdefid." AND `tblDocumentAttributes`.`value`='".$attribute."' AND `tblDocumentAttributes`.`document` = `tblDocuments`.`id`)";
@ -1974,6 +1978,8 @@ class SeedDMS_Core_DMS {
if($attrdef->getValueSet()) {
if($attrdef->getMultipleValues()) {
/** @noinspection PhpUndefinedVariableInspection */
if(is_string($attribute))
$attribute = array($attribute);
$searchAttributes[] = "EXISTS (SELECT NULL FROM `tblDocumentContentAttributes` WHERE `tblDocumentContentAttributes`.`attrdef`=".$attrdefid." AND (`tblDocumentContentAttributes`.`value` like '%".$valueset[0].implode("%' OR `tblDocumentContentAttributes`.`value` like '%".$valueset[0], $attribute)."%') AND `tblDocumentContentAttributes`.`document` = `tblDocumentContent`.`id`)";
} else {
$searchAttributes[] = "EXISTS (SELECT NULL FROM `tblDocumentContentAttributes` WHERE `tblDocumentContentAttributes`.`attrdef`=".$attrdefid." AND `tblDocumentContentAttributes`.`value`='".$attribute."' AND `tblDocumentContentAttributes`.content = `tblDocumentContent`.id)";

View File

@ -1582,6 +1582,7 @@ returns just users which are not disabled
<notes>
add SeedDMS_Core_Folder::getDocumentsMinMax()
add lots of DocBlocks from merge request #8
add SeedDMS_Core_AttributeDefinition::removeValue()
</notes>
</release>
<release>

View File

@ -83,5 +83,12 @@ class SeedDMS_Controller_AttributeMgr extends SeedDMS_Controller_Common {
return true;
} /* }}} */
public function removeattrvalue() { /* {{{ */
$attrdef = $this->params['attrdef'];
$attrval = $this->params['attrval'];
//$attrdef->getObjects($attrval);
return $attrdef->removeValue($attrval);
} /* }}} */
}

View File

@ -36,7 +36,7 @@ if (!$user->isAdmin()) {
if (isset($_POST["action"])) $action=$_POST["action"];
else $action=NULL;
if(!in_array($action, array('addattrdef', 'removeattrdef', 'editattrdef')))
if(!in_array($action, array('addattrdef', 'removeattrdef', 'editattrdef', 'removeattrvalue')))
UI::exitError(getMLText("admin_tools"),getMLText("unknown_command"));
/* Check if the form data comes from a trusted request */
@ -168,6 +168,35 @@ else if ($action == "editattrdef") {
$session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_edit_attribute')));
add_log_line("&action=editattrdef&attrdefid=".$attrdefid);
}
// remove attribute value -----------------------------------------------
else if ($action == "removeattrvalue") {
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"));
}
$attrval = $_POST["attrvalue"];
$controller->setParam('attrval', $attrval);
$controller->setParam('attrdef', $attrdef);
if (!$controller($_POST)) {
header('Content-Type: application/json');
echo json_encode(array('success'=>false, 'message'=>getMLText('error_occured')));
} else {
header('Content-Type: application/json');
echo json_encode(array('success'=>true, 'message'=>getMLText('splash_rm_attr_value')));
}
add_log_line("&action=removeattrvalue&attrdefid=".$attrdefid);
exit;
} else {
UI::exitError(getMLText("admin_tools"),getMLText("unknown_command"));
}

View File

@ -52,7 +52,6 @@ if($view) {
$view->setParam('folder', $folder);
$view->setParam('allusers', $allUsers);
$view->setParam('allgroups', $allGroups);
$view->setParam('strictformcheck', $settings->_strictFormCheck);
$view->setParam('accessobject', $accessop);
$view($_GET);
exit;

View File

@ -53,6 +53,7 @@ $(document).ready( function() {
<?php
$this->printDeleteFolderButtonJs();
$this->printDeleteDocumentButtonJs();
$this->printDeleteAttributeValueButtonJs();
} /* }}} */
function info() { /* {{{ */
@ -79,11 +80,12 @@ $(document).ready( function() {
$content .= "<th>".getMLText("attribute_count")."</th>\n";
$content .= "<th></th>\n";
$content .= "</tr></thead>\n<tbody>\n";
$separator = $selattrdef->getValueSetSeparator();
foreach($res['frequencies'][$type] as $entry) {
$value = $selattrdef->parseValue($entry['value']);
$content .= "<tr>";
$content .= "<td>".implode(';', $value)."</td>";
$content .= "<td><a href=\"../out/out.Search.php?resultmode=".($type == 'folder' ? 2 : ($type == 'document' ? 1 : 3))."&attributes[".$selattrdef->getID()."]=".$entry['value']."\">".urlencode($entry['c'])."</a></td>";
$content .= "<td>".htmlspecialchars(implode('<span style="color: #aaa;">'.($separator ? ' '.$separator.' ' : ' ; ').'</span>', $value))."</td>";
$content .= "<td><a href=\"../out/out.Search.php?resultmode=".($type == 'folder' ? 2 : ($type == 'document' ? 1 : 3))."&attributes[".$selattrdef->getID()."]=".urlencode($entry['value'])."\">".urlencode($entry['c'])."</a></td>";
$content .= "<td>";
/* various checks, if the value is valid */
if(!$selattrdef->validate($entry['value'])) {
@ -99,6 +101,15 @@ $(document).ready( function() {
}
*/
$content .= "</td>";
$content .= "<td>";
$content .= "<div class=\"list-action\">";
if($user->isAdmin()) {
$content .= $this->printDeleteAttributeValueButton($selattrdef, implode(';', $value), 'splash_rm_attr_value', true);
} else {
$content .= '<span style="padding: 2px; color: #CCC;"><i class="icon-remove"></i></span>';
}
$content .= "</div>";
$content .= "</td>";
$content .= "</tr>";
}
$content .= "</tbody></table>";

View File

@ -2023,6 +2023,86 @@ $(document).ready( function() {
<?php
} /* }}} */
/**
* Print button with link for deleting an attribute value
*
* This button is used in document listings (e.g. on the ViewFolder page)
* for deleting a document. In seeddms version < 4.3.9 this was just a
* link to the out/out.RemoveDocument.php page which asks for confirmation
* an than calls op/op.RemoveDocument.php. Starting with version 4.3.9
* the button just opens a small popup asking for confirmation and than
* calls the ajax command 'deletedocument'. The ajax call is called
* in the click function of 'button.removedocument'. That button needs
* to have two attributes: 'rel' for the id of the document, and 'msg'
* for the message shown by notify if the document could be deleted.
*
* @param object $document document to be deleted
* @param string $msg message shown in case of successful deletion
* @param boolean $return return html instead of printing it
* @return string html content if $return is true, otherwise an empty string
*/
function printDeleteAttributeValueButton($attrdef, $value, $msg, $return=false){ /* {{{ */
$content = '';
$content .= '<a class="delete-attribute-value-btn" rel="'.$attrdef->getID().'" msg="'.getMLText($msg).'" attrvalue="'.htmlspecialchars($value, ENT_QUOTES).'" confirmmsg="'.htmlspecialchars(getMLText("confirm_rm_attr_value", array ("attrdefname" => $attrdef->getName())), ENT_QUOTES).'"><i class="icon-remove"></i></a>';
if($return)
return $content;
else
echo $content;
return '';
} /* }}} */
function printDeleteAttributeValueButtonJs(){ /* {{{ */
echo "
$(document).ready(function () {
// $('.delete-attribute-value-btn').click(function(ev) {
$('body').on('click', 'a.delete-attribute-value-btn', function(ev){
id = $(ev.currentTarget).attr('rel');
confirmmsg = $(ev.currentTarget).attr('confirmmsg');
attrvalue = $(ev.currentTarget).attr('attrvalue');
msg = $(ev.currentTarget).attr('msg');
formtoken = '".createFormKey('removeattrvalue')."';
bootbox.dialog(confirmmsg, [{
\"label\" : \"<i class='icon-remove'></i> ".getMLText("rm_attr_value")."\",
\"class\" : \"btn-danger\",
\"callback\": function() {
$.post('../op/op.AttributeMgr.php',
{ action: 'removeattrvalue', attrdefid: id, attrvalue: attrvalue, formtoken: formtoken },
function(data) {
if(data.success) {
$('#table-row-attrvalue-'+id).hide('slow');
noty({
text: msg,
type: 'success',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 1500,
});
} else {
noty({
text: data.message,
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 3500,
});
}
},
'json'
);
}
}, {
\"label\" : \"".getMLText("cancel")."\",
\"class\" : \"btn-cancel\",
\"callback\": function() {
}
}]);
});
});
";
} /* }}} */
/**
* Return HTML of a single row in the document list table
*

View File

@ -69,7 +69,6 @@ $(document).ready(function() {
$folder = $this->params['folder'];
$allUsers = $this->params['allusers'];
$allGroups = $this->params['allgroups'];
$strictformcheck = $this->params['strictformcheck'];
$notifyList = $folder->getNotifyList();