mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-11 09:35:00 +00:00
add checking of attribute values against regular expression
This commit is contained in:
parent
4918256544
commit
06e06a4ac0
|
@ -58,10 +58,32 @@ if(isset($_POST["attributes"]))
|
|||
$attributes = $_POST["attributes"];
|
||||
else
|
||||
$attributes = array();
|
||||
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" => $folder->getName())),getMLText("attr_no_regex_match"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_POST["attributes_version"]))
|
||||
$attributes_version = $_POST["attributes_version"];
|
||||
else
|
||||
$attributes_version = array();
|
||||
foreach($attributes_version 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" => $folder->getName())),getMLText("attr_no_regex_match"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(isset($_POST["workflow"]))
|
||||
$workflow = $dms->getWorkflow($_POST["workflow"]);
|
||||
|
|
|
@ -60,6 +60,17 @@ if(isset($_POST["attributes"]))
|
|||
$attributes = $_POST["attributes"];
|
||||
else
|
||||
$attributes = array();
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$subFolder = $folder->addSubFolder($name, $comment, $user, $sequence, $attributes);
|
||||
|
||||
if (is_object($subFolder)) {
|
||||
|
|
|
@ -50,6 +50,7 @@ if ($action == "addattrdef") {
|
|||
$minvalues = intval($_POST["minvalues"]);
|
||||
$maxvalues = intval($_POST["maxvalues"]);
|
||||
$valueset = trim($_POST["valueset"]);
|
||||
$regex = trim($_POST["regex"]);
|
||||
|
||||
if($name == '') {
|
||||
UI::exitError(getMLText("admin_tools"),getMLText("attrdef_noname"));
|
||||
|
@ -57,7 +58,7 @@ if ($action == "addattrdef") {
|
|||
if (is_object($dms->getAttributeDefinitionByName($name))) {
|
||||
UI::exitError(getMLText("admin_tools"),getMLText("attrdef_exists"));
|
||||
}
|
||||
$newAttrdef = $dms->addAttributeDefinition($name, $objtype, $type, $multiple, $minvalues, $maxvalues, $valueset);
|
||||
$newAttrdef = $dms->addAttributeDefinition($name, $objtype, $type, $multiple, $minvalues, $maxvalues, $valueset, $regex);
|
||||
if (!$newAttrdef) {
|
||||
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
|
||||
}
|
||||
|
@ -114,6 +115,7 @@ else if ($action == "editattrdef") {
|
|||
$minvalues = intval($_POST["minvalues"]);
|
||||
$maxvalues = intval($_POST["maxvalues"]);
|
||||
$valueset = trim($_POST["valueset"]);
|
||||
$regex = trim($_POST["regex"]);
|
||||
if (!$attrdef->setName($name)) {
|
||||
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
|
||||
}
|
||||
|
@ -135,6 +137,9 @@ else if ($action == "editattrdef") {
|
|||
if (!$attrdef->setValueSet($valueset)) {
|
||||
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
|
||||
}
|
||||
if (!$attrdef->setRegex($regex)) {
|
||||
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
|
|
|
@ -234,8 +234,19 @@ if($categories) {
|
|||
if($attributes) {
|
||||
$oldattributes = $document->getAttributes();
|
||||
foreach($attributes as $attrdefid=>$attribute) {
|
||||
if(!isset($oldattributes[$attrdefid]) || $attribute != $oldattributes[$attrdefid]->getValue()) {
|
||||
if(!$document->setAttributeValue($dms->getAttributeDefinition($attrdefid), $attribute))
|
||||
$attrdef = $dms->getAttributeDefinition($attrdefid);
|
||||
if($attribute) {
|
||||
if($attrdef->getRegex()) {
|
||||
if(!preg_match($attrdef->getRegex(), $attribute)) {
|
||||
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("attr_no_regex_match"));
|
||||
}
|
||||
}
|
||||
if(!isset($oldattributes[$attrdefid]) || $attribute != $oldattributes[$attrdefid]->getValue()) {
|
||||
if(!$document->setAttributeValue($dms->getAttributeDefinition($attrdefid), $attribute))
|
||||
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
|
||||
}
|
||||
} elseif(isset($oldattributes[$attrdefid])) {
|
||||
if(!$document->removeAttribute($dms->getAttributeDefinition($attrdefid)))
|
||||
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,8 +156,19 @@ if(($oldcomment = $folder->getComment()) != $comment) {
|
|||
if($attributes) {
|
||||
$oldattributes = $folder->getAttributes();
|
||||
foreach($attributes as $attrdefid=>$attribute) {
|
||||
if(!isset($oldattributes[$attrdefid]) || $attribute != $oldattributes[$attrdefid]->getValue()) {
|
||||
if(!$folder->setAttributeValue($dms->getAttributeDefinition($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(!$folder->setAttributeValue($dms->getAttributeDefinition($attrdefid), $attribute))
|
||||
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("error_occured"));
|
||||
}
|
||||
} elseif(isset($oldattributes[$attrdefid])) {
|
||||
if(!$folder->removeAttribute($dms->getAttributeDefinition($attrdefid)))
|
||||
UI::exitError(getMLText("folder_title", array("foldername" => $folder->getName())),getMLText("error_occured"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,6 +126,9 @@ function showAttributeDefinitions(selectObj) {
|
|||
<tr>
|
||||
<td><?php printMLText("attrdef_valueset");?>:</td><td><input type="text" value="" name="valueset" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php printMLText("attrdef_regex");?>:</td><td><input type="text" value="" name="regex" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td><input type="submit" class="btn" value="<?php printMLText("new_attrdef"); ?>"></td>
|
||||
|
@ -222,6 +225,14 @@ function showAttributeDefinitions(selectObj) {
|
|||
<input type="text" value="<?php echo $attrdef->getValueSet() ?>" name="valueset" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<?php printMLText("attrdef_regex");?>:
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" value="<?php echo $attrdef->getRegex() ?>" name="regex" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
|
|
Loading…
Reference in New Issue
Block a user