diff --git a/lib/dao/dao.class.php b/lib/dao/dao.class.php index 1622f91df6..5038f819fe 100755 --- a/lib/dao/dao.class.php +++ b/lib/dao/dao.class.php @@ -1527,7 +1527,22 @@ class sql { if($this->inCondition and !$this->conditionIsTrue) return $this; - $order = str_replace(array('|', '', '_'), ' ', $order); + $order = str_replace(array('|', '', '_'), ' ', $order); + + /* Add "`" in order. */ + $orders = explode(',', $order); + foreach($orders as $i => $order) + { + $orderParse = explode(' ', trim($order)); + foreach($orderParse as $key => $value) + { + $value = trim($value); + if(empty($value) or $value == 'desc' or $value == 'asc') continue; + $orderParse[$key] = "`" . trim($value, '`') . "`"; + } + $orders[$i] = join(' ', $orderParse); + } + $order = join(',', $orders); $this->sql .= ' ' . DAO::ORDERBY . " $order"; return $this; diff --git a/module/common/control.php b/module/common/control.php index 80913df9ee..fd35fbf04b 100644 --- a/module/common/control.php +++ b/module/common/control.php @@ -170,19 +170,19 @@ class common extends control { if(isset($order[1]) and $order[1] == 'asc') { - $orderBy = "`{$order[0]}`_desc"; + $orderBy = "{$order[0]}_desc"; $className = 'headerSortDown'; } else { - $orderBy = "`{$order[0]}`_asc"; + $orderBy = "{$order[0]}_asc"; $className = 'headerSortUp'; } } else { - $orderBy = "`" . trim($fieldName, '`') . "`" . '_' . 'asc'; + $orderBy = "" . trim($fieldName, '`') . "" . '_' . 'asc'; $className = 'header'; } $link = helper::createLink($module, $method, sprintf($vars, $orderBy));