diff --git a/SeedDMS_Core/Core/inc.ClassAttribute.php b/SeedDMS_Core/Core/inc.ClassAttribute.php index 6f7db8f14..5bd694ad2 100644 --- a/SeedDMS_Core/Core/inc.ClassAttribute.php +++ b/SeedDMS_Core/Core/inc.ClassAttribute.php @@ -251,6 +251,12 @@ class SeedDMS_Core_Attribute { /* {{{ */ else $queryStr = "UPDATE `tblFolderAttributes` SET `value` = ".$db->qstr($value)." WHERE `folder` = " . $this->_obj->getID() . " AND `attrdef` = " . $this->_attrdef->getId(); break; + case $this->_dms->getClassname('user'): + if(trim($value) === '') + $queryStr = "DELETE FROM `tblUserAttributes WHERE` `userID` = " . $this->_obj->getID() . " AND `attrdef` = " . $this->_attrdef->getId(); + else + $queryStr = "UPDATE `tblUserAttributes` SET `value` = ".$db->qstr($value)." WHERE `userID` = " . $this->_obj->getID() . " AND `attrdef` = " . $this->_attrdef->getId(); + break; default: return false; } @@ -440,6 +446,7 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ const objtype_folder = '1'; const objtype_document = '2'; const objtype_documentcontent = '3'; + const objtype_user = '4'; /** * Constructor @@ -517,7 +524,7 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ * Get object type of attribute definition * * This can be one of objtype_all, - * objtype_folder, objtype_document, or objtype_documentcontent. + * objtype_folder, objtype_document, objtype_documentcontent, or objtype_user. * * @return integer type */ @@ -527,7 +534,7 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ * Set object type of attribute definition * * This can be one of objtype_all, - * objtype_folder, objtype_document, or objtype_documentcontent. + * objtype_folder, objtype_document, objtype_documentcontent, or objtype_user. * * @param integer $objtype type * @return bool @@ -1064,6 +1071,27 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ } } + if($this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_all || + $this->_objtype == SeedDMS_Core_AttributeDefinition::objtype_user) { + $queryStr = "SELECT * FROM `tblUserAttributes` 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); + if($resArr) { + foreach($resArr as $rec) { + if($user = $this->_dms->getUser($rec['userID'])) { + $result['users'][] = $user; + } + } + } + } + return $result; } /* }}} */ diff --git a/SeedDMS_Core/Core/inc.ClassObject.php b/SeedDMS_Core/Core/inc.ClassObject.php index bc02592fa..f4d60ef84 100644 --- a/SeedDMS_Core/Core/inc.ClassObject.php +++ b/SeedDMS_Core/Core/inc.ClassObject.php @@ -100,6 +100,9 @@ class SeedDMS_Core_Object { /* {{{ */ case $this->_dms->getClassname('folder'): $queryStr = "SELECT a.* FROM `tblFolderAttributes` a LEFT JOIN `tblAttributeDefinitions` b ON a.`attrdef`=b.`id` WHERE a.`folder` = " . $this->_id." ORDER BY b.`name`"; break; + case $this->_dms->getClassname('user'): + $queryStr = "SELECT a.* FROM `tblUserAttributes` a LEFT JOIN `tblAttributeDefinitions` b ON a.`attrdef`=b.`id` WHERE a.`userID` = " . $this->_id." ORDER BY b.`name`"; + break; default: return false; } @@ -259,6 +262,10 @@ class SeedDMS_Core_Object { /* {{{ */ $tablename = 'tblFolderAttributes'; $queryStr = "INSERT INTO `tblFolderAttributes` (`folder`, `attrdef`, `value`) VALUES (".$this->_id.", ".$attrdef->getId().", ".$db->qstr($value).")"; break; + case $this->_dms->getClassname('user'): + $tablename = 'tblUserAttributes'; + $queryStr = "INSERT INTO `tblUserAttributes` (`userID`, `attrdef`, `value`) VALUES (".$this->_id.", ".$attrdef->getId().", ".$db->qstr($value).")"; + break; default: return false; } @@ -299,6 +306,9 @@ class SeedDMS_Core_Object { /* {{{ */ case $this->_dms->getClassname('folder'): $queryStr = "DELETE FROM `tblFolderAttributes` WHERE `folder`=".$this->_id." AND `attrdef`=".$attrdef->getId(); break; + case $this->_dms->getClassname('user'): + $queryStr = "DELETE FROM `tblUserAttributes` WHERE `userID`=".$this->_id." AND `attrdef`=".$attrdef->getId(); + break; default: return false; } diff --git a/SeedDMS_Core/Core/inc.ClassUser.php b/SeedDMS_Core/Core/inc.ClassUser.php index 8e00e75ae..0fb6e4f55 100644 --- a/SeedDMS_Core/Core/inc.ClassUser.php +++ b/SeedDMS_Core/Core/inc.ClassUser.php @@ -430,14 +430,7 @@ class SeedDMS_Core_ApiKey { /* {{{ */ * 2010 Uwe Steinmann * @version Release: @package_version@ */ -class SeedDMS_Core_User { /* {{{ */ - /** - * @var integer id of user - * - * @access protected - */ - var $_id; - +class SeedDMS_Core_User extends SeedDMS_Core_Object { /* {{{ */ /** * @var string login name of user * @@ -559,13 +552,6 @@ class SeedDMS_Core_User { /* {{{ */ */ var $_rev_substitutes; - /** - * @var SeedDMS_Core_DMS reference to the dms instance this user belongs to - * - * @access protected - */ - var $_dms; - /** * @var int */ diff --git a/SeedDMS_Core/package.xml b/SeedDMS_Core/package.xml index 859ebc226..5d23cc8ca 100644 --- a/SeedDMS_Core/package.xml +++ b/SeedDMS_Core/package.xml @@ -26,6 +26,7 @@ add class SeedDMS_Core_ApiKey add property color to SeedDMS_Document_Category +support custom attributes for users diff --git a/install/update-6.1.0/update-postgres.sql b/install/update-6.1.0/update-postgres.sql index 26669ff8e..a130be888 100644 --- a/install/update-6.1.0/update-postgres.sql +++ b/install/update-6.1.0/update-postgres.sql @@ -44,6 +44,14 @@ CREATE TABLE "tblFolderAttributeDefinitionGroup" ( UNIQUE ("folder", "attrgrp") ); +CREATE TABLE "tblUserAttributes" ( + "id" SERIAL UNIQUE, + "userID" INTEGER default NULL REFERENCES "tblUsers" ("id") ON DELETE CASCADE, + "attrdef" INTEGER default NULL REFERENCES "tblAttributeDefinitions" ("id"), + "value" text default NULL, + UNIQUE (userID, attrdef) +) ; + UPDATE "tblVersion" set "major"=6, "minor"=1, "subminor"=0, "module"='core'; COMMIT; diff --git a/install/update-6.1.0/update-sqlite3.sql b/install/update-6.1.0/update-sqlite3.sql index 68027fc35..0755cce8e 100644 --- a/install/update-6.1.0/update-sqlite3.sql +++ b/install/update-6.1.0/update-sqlite3.sql @@ -90,6 +90,14 @@ CREATE TABLE `tblFolderAttributeDefinitionGroup` ( UNIQUE(`folder`, `attrgrp`) ); +CREATE TABLE `tblUserAttributes` ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `userID` INTEGER default NULL REFERENCES `tblUsers` (`id`) ON DELETE CASCADE, + `attrdef` INTEGER default NULL REFERENCES `tblAttributeDefinitions` (`id`), + `value` text default NULL, + UNIQUE (`userID`, `attrdef`) +); + UPDATE `tblVersion` set `major`=6, `minor`=1, `subminor`=0, `module`='core'; COMMIT; diff --git a/install/update-6.1.0/update.sql b/install/update-6.1.0/update.sql index 88c65155d..0780eb231 100644 --- a/install/update-6.1.0/update.sql +++ b/install/update-6.1.0/update.sql @@ -49,6 +49,18 @@ CREATE TABLE `tblFolderAttributeDefinitionGroup` ( CONSTRAINT `tblFolderAttributeDefinitionGroup_attrgrp` FOREIGN KEY (`attrgrp`) REFERENCES `tblAttributeDefinitionGroups` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `tblUserAttributes` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `userID` int(11) DEFAULT NULL, + `attrdef` int(11) DEFAULT NULL, + `value` text, + PRIMARY KEY (`id`), + UNIQUE KEY `userID` (`userID`,`attrdef`), + KEY `tblUserAttributes_attrdef` (`attrdef`), + CONSTRAINT `tblUserAttributes_attrdef` FOREIGN KEY (`attrdef`) REFERENCES `tblAttributeDefinitions` (`id`), + CONSTRAINT `tblUserAttributes_userid` FOREIGN KEY (`userID`) REFERENCES `tblUsers` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + UPDATE `tblVersion` set `major`=6, `minor`=1, `subminor`=0, `module`='core'; COMMIT; diff --git a/op/op.UsrMgr.php b/op/op.UsrMgr.php index 343737941..8cb63b874 100644 --- a/op/op.UsrMgr.php +++ b/op/op.UsrMgr.php @@ -379,6 +379,39 @@ else if ($action == "edituser") { $homefolder = (isset($_POST["homefolder"]) ? $_POST["homefolder"] : 0); $quota = (isset($_POST["quota"]) ? (int) $_POST["quota"] : 0); + if(isset($_POST["attributes"])) + $attributes = $_POST["attributes"]; + else + $attributes = array(); + + $oldattributes = $user->getAttributes(); + if($attributes) { + foreach($attributes as $attrdefid=>$attribute) { + $attrdef = $dms->getAttributeDefinition($attrdefid); + if($attribute) { + if(!$attrdef->validate($attribute, $editedUser, true)) { + UI::exitError(getMLText("error_occured"), getAttributeValidationText($attrdef->getValidationError(), $attrdef->getName(), $attribute)); + } + + if(!isset($oldattributes[$attrdefid]) || $attribute != $oldattributes[$attrdefid]->getValue()) { + if(!$editedUser->setAttributeValue($dms->getAttributeDefinition($attrdefid), $attribute)) + UI::exitError(getMLText("error_occured"), getMLText("error_occured")); + } + } elseif($attrdef->getMinValues() > 0) { + $this->errormsg = getMLText("attr_min_values", array("attrname"=>$attrdef->getName())); + } elseif(isset($oldattributes[$attrdefid])) { + if(!$editedUser->removeAttribute($dms->getAttributeDefinition($attrdefid))) + UI::exitError(getMLText("error_occured"), getMLText("error_occured")); + } + } + } + foreach($oldattributes as $attrdefid=>$oldattribute) { + if(!isset($attributes[$attrdefid])) { + if(!$editedUser->removeAttribute($dms->getAttributeDefinition($attrdefid))) + UI::exitError(getMLText("error_occured"), getMLText("error_occured")); + } + } + if (isset($pwd) && ($pwd != "")) { if($settings->_passwordStrength) { $ps = new Password_Strength(); diff --git a/views/bootstrap/class.AttributeMgr.php b/views/bootstrap/class.AttributeMgr.php index 25f660053..2e5325130 100644 --- a/views/bootstrap/class.AttributeMgr.php +++ b/views/bootstrap/class.AttributeMgr.php @@ -218,6 +218,7 @@ $(document).ready( function() { $options[] = array(SeedDMS_Core_AttributeDefinition::objtype_folder, getMLText('folder'), $attrdef && $attrdef->getObjType() == SeedDMS_Core_AttributeDefinition::objtype_folder); $options[] = array(SeedDMS_Core_AttributeDefinition::objtype_document, getMLText('document'), $attrdef && $attrdef->getObjType() == SeedDMS_Core_AttributeDefinition::objtype_document); $options[] = array(SeedDMS_Core_AttributeDefinition::objtype_documentcontent, getMLText('documentcontent'), $attrdef && $attrdef->getObjType() == SeedDMS_Core_AttributeDefinition::objtype_documentcontent); + $options[] = array(SeedDMS_Core_AttributeDefinition::objtype_user, getMLText('user'), $attrdef && $attrdef->getObjType() == SeedDMS_Core_AttributeDefinition::objtype_user); $this->formField( getMLText("attrdef_objtype"), array( diff --git a/views/bootstrap/class.UsrMgr.php b/views/bootstrap/class.UsrMgr.php index 598802bf5..97556c77c 100644 --- a/views/bootstrap/class.UsrMgr.php +++ b/views/bootstrap/class.UsrMgr.php @@ -399,6 +399,21 @@ $(document).ready( function() { 'value'=>($currUser ? htmlspecialchars($currUser->getComment()) : '') ) ); + $attrdefs = $dms->getAllAttributeDefinitions(array(SeedDMS_Core_AttributeDefinition::objtype_user)); + if($attrdefs) { + foreach($attrdefs as $attrdef) { + $arr = $this->callHook('editUserAttribute', $currUser, $attrdef); + if(is_array($arr)) { + if($arr) { + $this->formField($arr[0], $arr[1], isset($arr[2]) ? $arr[2] : null); + } + } elseif(is_string($arr)) { + echo $arr; + } else { + $this->formField(htmlspecialchars($attrdef->getName()), $this->getAttributeEditField($attrdef, $currUser->getAttribute($attrdef))); + } + } + } $options = array(); foreach($roles as $role) { $options[] = array($role->getID(), $role->getName(), ($currUser && $currUser->getRole()->getID() == $role->getID()));