if (!empty($orderBy)) {
// this is special case while searching for
// change log CRM-1718
- if (preg_match('/sort_name/i', $orderBy)) {
- $orderBy = str_replace('sort_name', 'contact_a.sort_name', $orderBy);
+ if (preg_match('/`sort_name`/i', $orderBy)) {
+ $orderBy = str_replace('`sort_name`', '`contact_a`.`sort_name`', $orderBy);
}
$orderBy = CRM_Utils_Type::escape($orderBy, 'String');
$this->_vars[$this->_currentSortID]['direction'] == self::DONTCARE
) {
$this->_vars[$this->_currentSortID]['name'] = str_replace(' ', '_', $this->_vars[$this->_currentSortID]['name']);
- return $this->_vars[$this->_currentSortID]['name'] . ' asc';
+ return CRM_Utils_Type::escape($this->_vars[$this->_currentSortID]['name'], 'MysqlColumnNameOrAlias') . ' asc';
}
else {
$this->_vars[$this->_currentSortID]['name'] = str_replace(' ', '_', $this->_vars[$this->_currentSortID]['name']);
- return $this->_vars[$this->_currentSortID]['name'] . ' desc';
+ return CRM_Utils_Type::escape($this->_vars[$this->_currentSortID]['name'], 'MysqlColumnNameOrAlias') . ' desc';
}
}