check for regular expression of attr values

This commit is contained in:
Uwe Steinmann 2013-05-28 17:32:52 +02:00
parent dc91417bcc
commit 7995fcac45
2 changed files with 47 additions and 45 deletions

View File

@ -62,31 +62,19 @@ $attributes = $_POST["attributes"];
if($attributes) {
$oldattributes = $version->getAttributes();
foreach($attributes as $attrdefid=>$attribute) {
$attrdef = $dms->getAttributeDefinition($attrdefid);
if($attribute) {
if($attrdef->getRegex()) {
if(!preg_match($attrdef->getRegex(), $attribute)) {
UI::exitError(getMLText("folder_title", array("foldername" => $document->getName())),getMLText("attr_no_regex_match"));
}
}
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 {
if($notifier) {
$notifyList = $document->getNotifyList();
/*
$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";
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);
}
}
*/
$subject = "attribute_changed_email_subject";
$message = "attribute_changed_email_body";
$params = array();
@ -110,6 +98,10 @@ if($attributes) {
}
}
}
} elseif(isset($oldattributes[$attrdefid])) {
if(!$folder->removeAttribute($dms->getAttributeDefinition($attrdefid)))
UI::exitError(getMLText("document_title", array("documentname" => $folder->getName())),getMLText("error_occured"));
}
}
}

View File

@ -169,6 +169,16 @@ if ($_FILES['userfile']['error'] == 0) {
}
$attributes = $_POST["attributes"];
foreach($attributes as $attrdefid=>$attribute) {
$attrdef = $dms->getAttributeDefinition($attrdefid);
if($attribute) {
if($attrdef->getRegex()) {
if(!preg_match($attrdef->getRegex(), $attribute)) {
UI::exitError(getMLText("document_title", array("documentname" => $folder->getName())),getMLText("attr_no_regex_match"));
}
}
}
}
$contentResult=$document->addContent($comment, $user, $userfiletmp, basename($userfilename), $fileType, $userfiletype, $reviewers, $approvers, $version=0, $attributes);
if (is_bool($contentResult) && !$contentResult) {