Index: branches/5.1.x/core/units/helpers/user_helper.php =================================================================== diff -u -N -r13870 -r14106 --- branches/5.1.x/core/units/helpers/user_helper.php (.../user_helper.php) (revision 13870) +++ branches/5.1.x/core/units/helpers/user_helper.php (.../user_helper.php) (revision 14106) @@ -1,6 +1,6 @@ Application->getUnitOption('ban-rule', 'TableName'); + if (!$this->Conn->TableFound($table)) { // when ban table not found -> assume user is ok by default return true; } $sql = 'SELECT * - FROM '.$table.' + FROM ' . $table . ' WHERE ItemType = 6 AND Status = ' . STATUS_ACTIVE . ' ORDER BY Priority DESC'; $rules = $this->Conn->Query($sql); $found = false; + foreach ($rules as $rule) { $field = $rule['ItemField']; + $this_value = mb_strtolower( $object->GetDBField($field) ); + $test_value = mb_strtolower( $rule['ItemValue'] ); - $this_value = strtolower( $object->GetDBField($field) ); - $test_value = strtolower( $rule['ItemValue'] ); - - switch ($rule['ItemVerb']) { - /*case 0: // any - $found = true; - break;*/ - + switch ( $rule['ItemVerb'] ) { case 1: // is if ($this_value == $test_value) { $found = true; } break; - /*case 2: // is not + case 2: // is not if ($this_value != $test_value) { $found = true; } - break;*/ + break; case 3: // contains - if (strstr($this_value, $test_value)) { + if ( strstr($this_value, $test_value) ) { $found = true; } break; - - /*case 4: // not contains - if (!strstr($this_value, $test_value)) { + case 4: // not contains + if ( !strstr($this_value, $test_value) ) { $found = true; } break; - case 5: // Greater Than - if ($test_value > $this_value) { - $found = true; - } - break; - - case 6: // Less Than - if ($test_value < $this_value) { - $found = true; - } - break; - case 7: // exists - if (strlen($this_value) > 0) { + if ( strlen($this_value) > 0 ) { $found = true; } break; case 8: // unique - if ($this->ValueExists($field, $this_value)) { + if ( $this->_checkValueExist($field, $this_value) ) { $found = true; } - break;*/ + break; } - if ($found) { + if ( $found ) { + // check ban rules, until one of them matches + + if ( $rule['RuleType'] ) { + // invert rule type + $found = false; + } + break; } } return !$found; } + + /** + * Checks if value is unique in Users table against the specified field + * + * @param string $field + * @param string $value + * @return string + */ + function _checkValueExist($field, $value) + { + $sql = 'SELECT * + FROM ' . $this->Application->getUnitOption('u', 'TableName') . ' + WHERE '. $field .' = ' . $this->Conn->qstr($value); + + return $this->Conn->GetOne($sql); + } }