_validate_row_condition

This commit is contained in:
William Knauss
2014-06-05 20:49:49 -04:00
parent ce19deec4e
commit 494087ab1d

View File

@@ -985,19 +985,19 @@ class parseCSV {
$operators_regex = array(); $operators_regex = array();
foreach( $operators as $value ) { foreach ($operators as $value) {
$operators_regex[] = preg_quote($value, '/'); $operators_regex[] = preg_quote($value, '/');
} }
$operators_regex = implode('|', $operators_regex); $operators_regex = implode('|', $operators_regex);
if ( preg_match('/^(.+) ('.$operators_regex.') (.+)$/i', trim($condition), $capture) ) { if (preg_match('/^(.+) ('.$operators_regex.') (.+)$/i', trim($condition), $capture)) {
$field = $capture[1]; $field = $capture[1];
$op = $capture[2]; $op = $capture[2];
$value = $capture[3]; $value = $capture[3];
if ( preg_match('/^([\'\"]{1})(.*)([\'\"]{1})$/i', $value, $capture) ) { if (preg_match('/^([\'\"]{1})(.*)([\'\"]{1})$/i', $value, $capture)) {
if ( $capture[1] == $capture[3] ) { if ($capture[1] == $capture[3]) {
$value = $capture[2]; $value = $capture[2];
$value = str_replace("\\n", "\n", $value); $value = str_replace("\\n", "\n", $value);
$value = str_replace("\\r", "\r", $value); $value = str_replace("\\r", "\r", $value);
@@ -1006,29 +1006,29 @@ class parseCSV {
} }
} }
if ( array_key_exists($field, $row) ) { if (array_key_exists($field, $row)) {
if ( ($op == '=' || $op == 'equals' || $op == 'is') && $row[$field] == $value ) { if (($op == '=' || $op == 'equals' || $op == 'is') && $row[$field] == $value) {
return '1'; return '1';
} }
elseif ( ($op == '!=' || $op == 'is not') && $row[$field] != $value ) { elseif (($op == '!=' || $op == 'is not') && $row[$field] != $value) {
return '1'; return '1';
} }
elseif ( ($op == '<' || $op == 'is less than' ) && $row[$field] < $value ) { elseif (($op == '<' || $op == 'is less than' ) && $row[$field] < $value) {
return '1'; return '1';
} }
elseif ( ($op == '>' || $op == 'is greater than') && $row[$field] > $value ) { elseif (($op == '>' || $op == 'is greater than') && $row[$field] > $value) {
return '1'; return '1';
} }
elseif ( ($op == '<=' || $op == 'is less than or equals' ) && $row[$field] <= $value ) { elseif (($op == '<=' || $op == 'is less than or equals' ) && $row[$field] <= $value) {
return '1'; return '1';
} }
elseif ( ($op == '>=' || $op == 'is greater than or equals') && $row[$field] >= $value ) { elseif (($op == '>=' || $op == 'is greater than or equals') && $row[$field] >= $value) {
return '1'; return '1';
} }
elseif ( $op == 'contains' && preg_match('/'.preg_quote($value, '/').'/i', $row[$field]) ) { elseif ($op == 'contains' && preg_match('/'.preg_quote($value, '/').'/i', $row[$field])) {
return '1'; return '1';
} }
elseif ( $op == 'does not contain' && !preg_match('/'.preg_quote($value, '/').'/i', $row[$field]) ) { elseif ($op == 'does not contain' && !preg_match('/'.preg_quote($value, '/').'/i', $row[$field])) {
return '1'; return '1';
} }
else { else {