Skip to content

Commit

Permalink
Merge pull request #5 from salesagility/hotfix
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
604media committed Jun 2, 2016
2 parents da6a69f + ce5a2b9 commit 596460b
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 95 deletions.
15 changes: 8 additions & 7 deletions include/SearchForm/SearchForm2.php
Original file line number Diff line number Diff line change
Expand Up @@ -814,26 +814,27 @@ public function generateSearchWhere($add_custom_fields = false, $module='') {
}

//This if-else block handles the shortcut checkbox selections for "My Items" and "Closed Only"
if(!empty($parms['my_items'])) {
if( $parms['value'] == false ) {
if (!empty($parms['my_items'])) {
if ($parms['value'] == false) {
continue;
} else {
//my items is checked.
global $current_user;
$field_value = $db->quote($current_user->id);
$operator = '=' ;
$operator = '=';
}
} else if(!empty($parms['closed_values']) && is_array($parms['closed_values'])) {
if( $parms['value'] == false ) {
} elseif (!empty($parms['closed_values']) && is_array($parms['closed_values'])) {
if ($parms['value'] == false) {
continue;
} else {
$field_value = '';
foreach($parms['closed_values'] as $closed_value)
{
foreach ($parms['closed_values'] as $closed_value) {
$field_value .= "," . $db->quoted($closed_value);
}
$field_value = substr($field_value, 1);
}
} elseif (!empty($parms['checked_only']) && $parms['value'] == false) {
continue;
}

$where = '';
Expand Down
32 changes: 21 additions & 11 deletions include/database/MssqlManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ public function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '',
//for paging, AFTER the distinct clause
$grpByStr = '';
$hasDistinct = strpos(strtolower($matches[0]), "distinct");
$hasGroupBy = strpos(strtolower($matches[0]), "group by");

require_once('include/php-sql-parser.php');
$parser = new PHPSQLParser();
Expand Down Expand Up @@ -542,6 +543,10 @@ public function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '',
$grpByStr[] = trim($record['base_expr']);
}
$grpByStr = implode(', ', $grpByStr);
} elseif ($hasGroupBy) {
$groupBy = explode("group by", strtolower($matches[0]));
$groupByVars = explode(',', $groupBy[1]);
$grpByStr = $groupByVars[0];
}

if (!empty($orderByMatch[3])) {
Expand All @@ -556,32 +561,37 @@ public function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '',
group by " . $grpByStr . "
) AS a
WHERE row_number > $start";
}
else {
$newSQL = "SELECT TOP $count * FROM
} else {
$newSQL = "SELECT TOP $count * FROM
(
" . $matches[1] . " ROW_NUMBER()
OVER (ORDER BY " . $this->returnOrderBy($sql, $orderByMatch[3]) . ") AS row_number,
" . $matches[2] . $orderByMatch[1]. "
" . $matches[2] . $orderByMatch[1] . "
) AS a
WHERE row_number > $start";
}
}else{
} else {
//if there is a distinct clause, form query with rownumber after distinct
if ($hasDistinct) {
$newSQL = "SELECT TOP $count * FROM
$newSQL = "SELECT TOP $count * FROM
(
SELECT ROW_NUMBER() OVER (ORDER BY ".$grpByStr.") AS row_number, count(*) counter, " . $distinctSQLARRAY[0] . "
SELECT ROW_NUMBER() OVER (ORDER BY " . $grpByStr . ") AS row_number, count(*) counter, " . $distinctSQLARRAY[0] . "
" . $distinctSQLARRAY[1] . "
group by " . $grpByStr . "
)
AS a
WHERE row_number > $start";
}
else {
$newSQL = "SELECT TOP $count * FROM
} elseif ($hasGroupBy) {
$newSQL = "SELECT TOP $count * FROM
(
" . $matches[1] . " ROW_NUMBER() OVER (ORDER BY " . $grpByStr . ") AS row_number, " . $matches[2] . $matches[3] . "
)
AS a
WHERE row_number > $start";
} else {
$newSQL = "SELECT TOP $count * FROM
(
" . $matches[1] . " ROW_NUMBER() OVER (ORDER BY " . $sqlArray['FROM'][0]['alias'] . ".id) AS row_number, " . $matches[2] . $matches[3]. "
" . $matches[1] . " ROW_NUMBER() OVER (ORDER BY " . $sqlArray['FROM'][0]['alias'] . ".id) AS row_number, " . $matches[2] . $matches[3] . "
)
AS a
WHERE row_number > $start";
Expand Down
17 changes: 10 additions & 7 deletions modules/AOR_Reports/AOR_Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -1097,14 +1097,17 @@ function build_report_query_select($query = array(), $group_value =''){
$select_field= $this->db->quoteIdentifier($table_alias).'.'.$field->field;
}

if($field->group_by == 1){
$query['group_by'][] = $field->format ? str_replace('(%1)', '(' . $select_field . ')', preg_replace(array('/\s+/', '/Y/', '/m/', '/d/'), array(', ', 'YEAR(%1)', 'MONTH(%1)', 'DAY(%1)'), trim(preg_replace('/[^Ymd]/', ' ', $field->format)))) : $select_field;
if ($field->group_by == 1) {
if ($field->format) {
$query['group_by'][] = str_replace('(%1)', '(' . $select_field . ')', preg_replace(array('/\s+/', '/Y/', '/m/', '/d/'), array(', ', 'YEAR(%1)', 'MONTH(%1)', 'DAY(%1)'), trim(preg_replace('/[^Ymd]/', ' ', $field->format))));
$query['second_group_by'][] = $select_field;
} else {
$query['group_by'][] = $select_field;
}
} elseif ($field->field_function != null) {
$select_field = $field->field_function . '(' . $select_field . ')';
} else {
$query['second_group_by'][] = $field->format ? str_replace('(%1)', '(' . $select_field . ')', preg_replace(array('/\s+/', '/Y/', '/m/', '/d/'), array(', ', 'YEAR(%1)', 'MONTH(%1)', 'DAY(%1)'), trim(preg_replace('/[^Ymd]/', ' ', $field->format)))) : $select_field;
}

if($field->field_function != null){
$select_field = $field->field_function.'('.$select_field.')';
$query['second_group_by'][] = $select_field;
}

if($field->sort_by != ''){
Expand Down
9 changes: 4 additions & 5 deletions modules/AOS_Contracts/metadata/SearchFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@
*
* @author Salesagility Ltd <support@salesagility.com>
*/
global $current_user;
$module_name = 'AOS_Contracts';
$searchFields[$module_name] =
$searchFields['AOS_Contracts'] =
array (
'name' => array( 'query_type'=>'default'),
'current_user_only'=> array('query_type'=>'default','db_field'=>array('assigned_user_id'),'my_items'=>true, 'vname' => 'LBL_CURRENT_USER_FILTER', 'type' => 'bool'),
'assigned_user_id'=> array('query_type'=>'default'),
'favorites_only' => array(
'query_type'=>'format',
'operator' => 'subquery',
'checked_only' => true,
'subquery' => "SELECT favorites.parent_id FROM favorites
WHERE favorites.deleted = 0
and favorites.parent_type = '".$module_name."'
and favorites.assigned_user_id = '" .$current_user->id . "') OR NOT ({0}",
and favorites.parent_type = 'AOS_Contracts'
and favorites.assigned_user_id = '{1}'",
'db_field'=>array('id')),
//Range Search Support
'range_end_date' => array ('query_type' => 'default', 'enable_range_search' => true, 'is_date_field' => true),
Expand Down
9 changes: 4 additions & 5 deletions modules/AOS_Invoices/metadata/SearchFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
*
* @author Salesagility Ltd <support@salesagility.com>
*/
global $current_user;
$module_name = 'AOS_Invoices';
$searchFields[$module_name] =
$searchFields['AOS_Invoices'] =
array (
'name' => array( 'query_type'=>'default'),
'account_type'=> array('query_type'=>'default', 'options' => 'account_type_dom', 'template_var' => 'ACCOUNT_TYPE_OPTIONS'),
Expand All @@ -56,10 +54,11 @@
'favorites_only' => array(
'query_type'=>'format',
'operator' => 'subquery',
'checked_only' => true,
'subquery' => "SELECT favorites.parent_id FROM favorites
WHERE favorites.deleted = 0
and favorites.parent_type = '".$module_name."'
and favorites.assigned_user_id = '" .$current_user->id . "') OR NOT ({0}",
and favorites.parent_type = 'AOS_Invoices'
and favorites.assigned_user_id = '{1}'",
'db_field'=>array('id')),
//Range Search Support
'range_total_amount' => array ('query_type' => 'default', 'enable_range_search' => true),
Expand Down
9 changes: 4 additions & 5 deletions modules/AOS_PDF_Templates/metadata/SearchFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,19 @@
* @author Salesagility Ltd <support@salesagility.com>
*/

global $current_user;
$module_name = 'AOS_PDF_Templates';
$searchFields[$module_name] =
$searchFields['AOS_PDF_Templates'] =
array (
'name' => array( 'query_type'=>'default'),
'current_user_only'=> array('query_type'=>'default','db_field'=>array('created_by'),'my_items'=>true, 'vname' => 'LBL_CURRENT_USER_FILTER', 'type' => 'bool'),
'assigned_user_id'=> array('query_type'=>'default'),
'favorites_only' => array(
'query_type'=>'format',
'operator' => 'subquery',
'checked_only' => true,
'subquery' => "SELECT favorites.parent_id FROM favorites
WHERE favorites.deleted = 0
and favorites.parent_type = '".$module_name."'
and favorites.assigned_user_id = '" .$current_user->id . "') OR NOT ({0}",
and favorites.parent_type = 'AOS_PDF_Templates'
and favorites.assigned_user_id = '{1}'",
'db_field'=>array('id')),

//Range Search Support
Expand Down
7 changes: 3 additions & 4 deletions modules/AOS_Products/metadata/SearchFields.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
// created: 2013-05-07 12:48:58
global $current_user;
$searchFields['AOS_Products'] = array (
'name' =>
array (
Expand Down Expand Up @@ -86,9 +84,10 @@
'favorites_only' => array(
'query_type'=>'format',
'operator' => 'subquery',
'checked_only' => true,
'subquery' => "SELECT favorites.parent_id FROM favorites
WHERE favorites.deleted = 0
and favorites.parent_type = '".$module_name."'
and favorites.assigned_user_id = '" .$current_user->id . "') OR NOT ({0}",
and favorites.parent_type = 'AOS_Products'
and favorites.assigned_user_id = '{1}'",
'db_field'=>array('id')),
);
9 changes: 4 additions & 5 deletions modules/AOS_Quotes/metadata/SearchFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
*
* @author SalesAgility <info@salesagility.com>
*/
global $current_user;
$module_name = 'AOS_Quotes';
$searchFields[$module_name] =
$searchFields['AOS_Quotes'] =
array (
'name' => array( 'query_type'=>'default'),
'account_type'=> array('query_type'=>'default', 'options' => 'account_type_dom', 'template_var' => 'ACCOUNT_TYPE_OPTIONS'),
Expand All @@ -47,10 +45,11 @@
'favorites_only' => array(
'query_type'=>'format',
'operator' => 'subquery',
'checked_only' => true,
'subquery' => "SELECT favorites.parent_id FROM favorites
WHERE favorites.deleted = 0
and favorites.parent_type = '".$module_name."'
and favorites.assigned_user_id = '" .$current_user->id . "') OR NOT ({0}",
and favorites.parent_type = 'AOS_Quotes'
and favorites.assigned_user_id = '{1}'",
'db_field'=>array('id')),

//Range Search Support
Expand Down
7 changes: 3 additions & 4 deletions modules/Accounts/metadata/SearchFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
* reasonably feasible for technical reasons, the Appropriate Legal Notices must
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
********************************************************************************/
global $current_user;
$module_name = "Accounts";

$searchFields['Accounts'] = array (
'name' =>
Expand Down Expand Up @@ -208,9 +206,10 @@
'favorites_only' => array(
'query_type'=>'format',
'operator' => 'subquery',
'checked_only' => true,
'subquery' => "SELECT favorites.parent_id FROM favorites
WHERE favorites.deleted = 0
and favorites.parent_type = '".$module_name."'
and favorites.assigned_user_id = '" .$current_user->id . "') OR NOT ({0}",
and favorites.parent_type = 'Accounts'
and favorites.assigned_user_id = '{1}'",
'db_field'=>array('id')),
);
7 changes: 3 additions & 4 deletions modules/Calls/metadata/SearchFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
* reasonably feasible for technical reasons, the Appropriate Legal Notices must
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
********************************************************************************/
global $current_user;
$module_name = "Calls";
$searchFields['Calls'] = array (
'name' =>
array (
Expand Down Expand Up @@ -172,9 +170,10 @@
'favorites_only' => array(
'query_type'=>'format',
'operator' => 'subquery',
'checked_only' => true,
'subquery' => "SELECT favorites.parent_id FROM favorites
WHERE favorites.deleted = 0
and favorites.parent_type = '".$module_name."'
and favorites.assigned_user_id = '" .$current_user->id . "') OR NOT ({0}",
and favorites.parent_type = 'Calls'
and favorites.assigned_user_id = '{1}'",
'db_field'=>array('id')),
);
7 changes: 3 additions & 4 deletions modules/Cases/metadata/SearchFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
* reasonably feasible for technical reasons, the Appropriate Legal Notices must
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
********************************************************************************/
global $current_user;
$module_name = "Cases";
$searchFields['Cases'] = array (
'name' =>
array (
Expand Down Expand Up @@ -147,9 +145,10 @@
'favorites_only' => array(
'query_type'=>'format',
'operator' => 'subquery',
'checked_only' => true,
'subquery' => "SELECT favorites.parent_id FROM favorites
WHERE favorites.deleted = 0
and favorites.parent_type = '".$module_name."'
and favorites.assigned_user_id = '" .$current_user->id . "') OR NOT ({0}",
and favorites.parent_type = 'Cases'
and favorites.assigned_user_id = '{1}'",
'db_field'=>array('id')),
);
7 changes: 3 additions & 4 deletions modules/Contacts/metadata/SearchFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
* reasonably feasible for technical reasons, the Appropriate Legal Notices must
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
********************************************************************************/
global $current_user;
$module_name = "Contacts";
$searchFields['Contacts'] =
array (
'first_name' => array( 'query_type'=>'default'),
Expand All @@ -59,10 +57,11 @@
'favorites_only' => array(
'query_type'=>'format',
'operator' => 'subquery',
'checked_only' => true,
'subquery' => "SELECT favorites.parent_id FROM favorites
WHERE favorites.deleted = 0
and favorites.parent_type = '".$module_name."'
and favorites.assigned_user_id = '" .$current_user->id . "') OR NOT ({0}",
and favorites.parent_type = 'Contacts'
and favorites.assigned_user_id = '{1}'",
'db_field'=>array('id')),
'assistant'=> array('query_type'=>'default'),
'address_street'=> array('query_type'=>'default','db_field'=>array('primary_address_street','alt_address_street')),
Expand Down
8 changes: 3 additions & 5 deletions modules/Documents/metadata/SearchFields.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<?php
// created: 2015-02-17 15:14:28
global $current_user;
$module_name = "Documents";
$searchFields['Documents'] = array (
'document_name' =>
array (
Expand Down Expand Up @@ -82,9 +79,10 @@
'favorites_only' => array(
'query_type'=>'format',
'operator' => 'subquery',
'checked_only' => true,
'subquery' => "SELECT favorites.parent_id FROM favorites
WHERE favorites.deleted = 0
and favorites.parent_type = '".$module_name."'
and favorites.assigned_user_id = '" .$current_user->id . "') OR NOT ({0}",
and favorites.parent_type = 'Documents'
and favorites.assigned_user_id = '{1}'",
'db_field'=>array('id')),
);
7 changes: 3 additions & 4 deletions modules/Leads/metadata/SearchFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
* reasonably feasible for technical reasons, the Appropriate Legal Notices must
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
********************************************************************************/
global $current_user;
$module_name = "Leads";
$searchFields['Leads'] =
array (
'first_name' => array( 'query_type'=>'default'),
Expand All @@ -60,10 +58,11 @@
'favorites_only' => array(
'query_type'=>'format',
'operator' => 'subquery',
'checked_only' => true,
'subquery' => "SELECT favorites.parent_id FROM favorites
WHERE favorites.deleted = 0
and favorites.parent_type = '".$module_name."'
and favorites.assigned_user_id = '" .$current_user->id . "') OR NOT ({0}",
and favorites.parent_type = 'Leads'
and favorites.assigned_user_id = '{1}'",
'db_field'=>array('id')),
'assistant'=> array('query_type'=>'default'),
'website'=> array('query_type'=>'default'),
Expand Down
Loading

0 comments on commit 596460b

Please sign in to comment.