@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3 | 3 | /********************************************************************************* |
4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -63,26 +63,26 @@ discard block |
||
63 | 63 | |
64 | 64 | $action = 'DeleteRelationship'; |
65 | 65 | $record = $layout_def['fields']['ID']; |
66 | - $current_module=$layout_def['module']; |
|
66 | + $current_module = $layout_def['module']; |
|
67 | 67 | //in document revisions subpanel ,users are now allowed to |
68 | 68 | //delete the latest revsion of a document. this will be tested here |
69 | 69 | //and if the condition is met delete button will be removed. |
70 | - $hideremove=false; |
|
71 | - if ($current_module=='DocumentRevisions') { |
|
72 | - if ($layout_def['fields']['ID']==$layout_def['fields']['LATEST_REVISION_ID']) { |
|
73 | - $hideremove=true; |
|
70 | + $hideremove = false; |
|
71 | + if ($current_module == 'DocumentRevisions') { |
|
72 | + if ($layout_def['fields']['ID'] == $layout_def['fields']['LATEST_REVISION_ID']) { |
|
73 | + $hideremove = true; |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | // Implicit Team-memberships are not "removeable" |
77 | 77 | elseif ($_REQUEST['module'] == 'Teams' && $current_module == 'Users') { |
78 | - if($layout_def['fields']['UPLINE'] != translate('LBL_TEAM_UPLINE_EXPLICIT', 'Users')) { |
|
78 | + if ($layout_def['fields']['UPLINE'] != translate('LBL_TEAM_UPLINE_EXPLICIT', 'Users')) { |
|
79 | 79 | $hideremove = true; |
80 | 80 | } |
81 | 81 | |
82 | 82 | //We also cannot remove the user whose private team is set to the parent_record_id value |
83 | 83 | $user = new User(); |
84 | 84 | $user->retrieve($layout_def['fields']['ID']); |
85 | - if($parent_record_id == $user->getPrivateTeamID()) |
|
85 | + if ($parent_record_id == $user->getPrivateTeamID()) |
|
86 | 86 | { |
87 | 87 | $hideremove = true; |
88 | 88 | } |
@@ -94,22 +94,22 @@ discard block |
||
94 | 94 | $subpanel = $layout_def['subpanel_id']; |
95 | 95 | $return_id = $_REQUEST['record']; |
96 | 96 | if (isset($layout_def['linked_field_set']) && !empty($layout_def['linked_field_set'])) { |
97 | - $linked_field= $layout_def['linked_field_set'] ; |
|
97 | + $linked_field = $layout_def['linked_field_set']; |
|
98 | 98 | } else { |
99 | 99 | $linked_field = $layout_def['linked_field']; |
100 | 100 | } |
101 | 101 | $refresh_page = 0; |
102 | - if(!empty($layout_def['refresh_page'])){ |
|
102 | + if (!empty($layout_def['refresh_page'])) { |
|
103 | 103 | $refresh_page = 1; |
104 | 104 | } |
105 | 105 | $return_url = "index.php?module=$return_module&action=$return_action&subpanel=$subpanel&record=$return_id&sugar_body_only=1&inline=1"; |
106 | 106 | |
107 | 107 | $icon_remove_text = mb_strtolower($app_strings['LBL_ID_FF_REMOVE'], 'UTF-8'); |
108 | 108 | |
109 | - if($linked_field == 'get_emails_by_assign_or_link') |
|
109 | + if ($linked_field == 'get_emails_by_assign_or_link') |
|
110 | 110 | $linked_field = 'emails'; |
111 | 111 | //based on listview since that lets you select records |
112 | - if($layout_def['ListView'] && !$hideremove) { |
|
112 | + if ($layout_def['ListView'] && !$hideremove) { |
|
113 | 113 | $retStr = "<a href=\"javascript:sub_p_rem('$subpanel', '$linked_field'" |
114 | 114 | .", '$record', $refresh_page);\"" |
115 | 115 | . ' class="listViewTdToolsS1"' |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | . ">$icon_remove_text</a>"; |
119 | 119 | return $retStr; |
120 | 120 | |
121 | - }else{ |
|
121 | + } else { |
|
122 | 122 | return ''; |
123 | 123 | } |
124 | 124 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3 | 3 | /********************************************************************************* |
4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | |
49 | 49 | function get_currency() |
50 | 50 | { |
51 | - global $current_user,$global_currency_obj; |
|
51 | + global $current_user, $global_currency_obj; |
|
52 | 52 | if (empty($global_currency_obj)) |
53 | 53 | { |
54 | 54 | $global_currency_obj = new Currency(); |
55 | 55 | // $global_currency_symbol = '$'; |
56 | 56 | |
57 | - if($current_user->getPreference('currency') ) |
|
57 | + if ($current_user->getPreference('currency')) |
|
58 | 58 | { |
59 | 59 | $global_currency_obj->retrieve($current_user->getPreference('currency')); |
60 | 60 | } |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | $currency_id = $locale->getPrecedentPreference('currency'); |
83 | 83 | |
84 | 84 | // If it's not grouped, or if it's grouped around a system currency column, look up the currency symbol so we can display it next to the amount |
85 | - if ( empty($layout_def['group_function']) || $this->isSystemCurrency($layout_def) ) { |
|
85 | + if (empty($layout_def['group_function']) || $this->isSystemCurrency($layout_def)) { |
|
86 | 86 | $c = $this->getCurrency($layout_def); |
87 | - if(!empty($c['currency_id']) && !empty($c['currency_symbol'])) |
|
87 | + if (!empty($c['currency_id']) && !empty($c['currency_symbol'])) |
|
88 | 88 | { |
89 | 89 | $symbol = $c['currency_symbol']; |
90 | 90 | $currency_id = $c['currency_id']; |
@@ -94,15 +94,15 @@ discard block |
||
94 | 94 | $layout_def['currency_id'] = $currency_id; |
95 | 95 | $display = $this->displayListPlain($layout_def); |
96 | 96 | |
97 | - if(!empty($layout_def['column_key'])){ |
|
97 | + if (!empty($layout_def['column_key'])) { |
|
98 | 98 | $field_def = $this->reporter->all_fields[$layout_def['column_key']]; |
99 | - }else if(!empty($layout_def['fields'])){ |
|
99 | + } else if (!empty($layout_def['fields'])) { |
|
100 | 100 | $field_def = $layout_def['fields']; |
101 | 101 | } |
102 | 102 | $record = ''; |
103 | 103 | if ($layout_def['table_key'] == 'self' && isset($layout_def['fields']['PRIMARYID'])) |
104 | 104 | $record = $layout_def['fields']['PRIMARYID']; |
105 | - else if (isset($layout_def['fields'][strtoupper($layout_def['table_alias']."_id")])){ |
|
105 | + else if (isset($layout_def['fields'][strtoupper($layout_def['table_alias']."_id")])) { |
|
106 | 106 | $record = $layout_def['fields'][strtoupper($layout_def['table_alias']."_id")]; |
107 | 107 | } |
108 | 108 | if (!empty($record)) { |
@@ -110,11 +110,11 @@ discard block |
||
110 | 110 | $field_type = $field_def['type']; |
111 | 111 | $module = $field_def['module']; |
112 | 112 | |
113 | - $div_id = $module ."&$record&$field_name"; |
|
113 | + $div_id = $module."&$record&$field_name"; |
|
114 | 114 | $str = "<div id='$div_id'>".$display; |
115 | 115 | global $sugar_config; |
116 | 116 | if (isset ($sugar_config['enable_inline_reports_edit']) && $sugar_config['enable_inline_reports_edit']) { |
117 | - $str .= " " .SugarThemeRegistry::current()->getImage("edit_inline","border='0' alt='Edit Layout' align='bottom' onClick='SUGAR.reportsInlineEdit.inlineEdit(\"$div_id\",\"$value\",\"$module\",\"$record\",\"$field_name\",\"$field_type\",\"$currency_id\",\"$symbol\");'"); |
|
117 | + $str .= " ".SugarThemeRegistry::current()->getImage("edit_inline", "border='0' alt='Edit Layout' align='bottom' onClick='SUGAR.reportsInlineEdit.inlineEdit(\"$div_id\",\"$value\",\"$module\",\"$record\",\"$field_name\",\"$field_type\",\"$currency_id\",\"$symbol\");'"); |
|
118 | 118 | } |
119 | 119 | $str .= "</div>"; |
120 | 120 | return $str; |
@@ -155,13 +155,13 @@ discard block |
||
155 | 155 | return $this->_get_column_select($layout_def)." < ".$GLOBALS['db']->quote(unformat_number($layout_def['input_name0']))."\n"; |
156 | 156 | } |
157 | 157 | |
158 | - function queryFilterBetween(&$layout_def){ |
|
159 | - return $this->_get_column_select($layout_def)." > ".$GLOBALS['db']->quote(unformat_number($layout_def['input_name0'])). " AND ". $this->_get_column_select($layout_def)." < ".$GLOBALS['db']->quote(unformat_number($layout_def['input_name1']))."\n"; |
|
158 | + function queryFilterBetween(&$layout_def) { |
|
159 | + return $this->_get_column_select($layout_def)." > ".$GLOBALS['db']->quote(unformat_number($layout_def['input_name0']))." AND ".$this->_get_column_select($layout_def)." < ".$GLOBALS['db']->quote(unformat_number($layout_def['input_name1']))."\n"; |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | function isSystemCurrency(&$layout_def) |
163 | 163 | { |
164 | - if (strpos($layout_def['name'],'_usdoll') === false) { |
|
164 | + if (strpos($layout_def['name'], '_usdoll') === false) { |
|
165 | 165 | return false; |
166 | 166 | } else { |
167 | 167 | return true; |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | { |
173 | 173 | // add currency column to select |
174 | 174 | $table = $this->getCurrencyIdTable($layout_def); |
175 | - if($table) { |
|
176 | - return $this->_get_column_select($layout_def)." ".$this->_get_column_alias($layout_def)." , ".$table.".currency_id ". $this->getTruncatedColumnAlias($this->_get_column_alias($layout_def)."_currency") . "\n"; |
|
175 | + if ($table) { |
|
176 | + return $this->_get_column_select($layout_def)." ".$this->_get_column_alias($layout_def)." , ".$table.".currency_id ".$this->getTruncatedColumnAlias($this->_get_column_alias($layout_def)."_currency")."\n"; |
|
177 | 177 | } |
178 | 178 | return $this->_get_column_select($layout_def)." ".$this->_get_column_alias($layout_def)."\n"; |
179 | 179 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | { |
183 | 183 | // add currency column to group by |
184 | 184 | $table = $this->getCurrencyIdTable($layout_def); |
185 | - if($table) { |
|
185 | + if ($table) { |
|
186 | 186 | return $this->_get_column_select($layout_def)." , ".$table.".currency_id \n"; |
187 | 187 | } |
188 | 188 | return $this->_get_column_select($layout_def)." \n"; |
@@ -191,9 +191,9 @@ discard block |
||
191 | 191 | function getCurrencyIdTable($layout_def) |
192 | 192 | { |
193 | 193 | // We need to fetch the currency id as well |
194 | - if ( !$this->isSystemCurrency($layout_def) && empty($layout_def['group_function'])) { |
|
194 | + if (!$this->isSystemCurrency($layout_def) && empty($layout_def['group_function'])) { |
|
195 | 195 | |
196 | - if ( !empty($layout_def['table_alias']) ) { |
|
196 | + if (!empty($layout_def['table_alias'])) { |
|
197 | 197 | $table = $layout_def['table_alias']; |
198 | 198 | } else { |
199 | 199 | $table = ''; |
@@ -204,16 +204,16 @@ discard block |
||
204 | 204 | $real_table = $this->reporter->all_fields[$layout_def['column_key']]['real_table']; |
205 | 205 | |
206 | 206 | $add_currency_id = false; |
207 | - if(!empty($table)) { |
|
207 | + if (!empty($table)) { |
|
208 | 208 | $cols = $GLOBALS['db']->getHelper()->get_columns($real_table); |
209 | 209 | $add_currency_id = isset($cols['currency_id']) ? true : false; |
210 | 210 | |
211 | - if(!$add_currency_id && preg_match('/.*?_cstm$/i', $real_table)) { |
|
211 | + if (!$add_currency_id && preg_match('/.*?_cstm$/i', $real_table)) { |
|
212 | 212 | $table = str_replace('_cstm', '', $table); |
213 | 213 | $cols = $GLOBALS['db']->getHelper()->get_columns($table); |
214 | 214 | $add_currency_id = isset($cols['currency_id']) ? true : false; |
215 | 215 | } |
216 | - if($add_currency_id) { |
|
216 | + if ($add_currency_id) { |
|
217 | 217 | return $table; |
218 | 218 | } |
219 | 219 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | { |
231 | 231 | $currency_id = false; |
232 | 232 | $currency_symbol = false; |
233 | - if(isset($layout_def['currency_symbol']) && isset($layout_def['currency_id'])) |
|
233 | + if (isset($layout_def['currency_symbol']) && isset($layout_def['currency_id'])) |
|
234 | 234 | { |
235 | 235 | $currency_symbol = $layout_def['currency_symbol']; |
236 | 236 | $currency_id = $layout_def['currency_id']; |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | else |
239 | 239 | { |
240 | 240 | $key = strtoupper(isset($layout_def['varname']) ? $layout_def['varname'] : $this->_get_column_alias($layout_def)); |
241 | - if ( $this->isSystemCurrency($layout_def) ) |
|
241 | + if ($this->isSystemCurrency($layout_def)) |
|
242 | 242 | { |
243 | 243 | $currency_id = '-99'; |
244 | 244 | } |
@@ -246,14 +246,14 @@ discard block |
||
246 | 246 | { |
247 | 247 | $currency_id = $layout_def['fields'][$key.'_CURRENCY']; |
248 | 248 | } |
249 | - elseif(isset($layout_def['fields'][$this->getTruncatedColumnAlias($this->_get_column_alias($layout_def)."_currency")])) |
|
249 | + elseif (isset($layout_def['fields'][$this->getTruncatedColumnAlias($this->_get_column_alias($layout_def)."_currency")])) |
|
250 | 250 | { |
251 | 251 | $currency_id = $layout_def['fields'][$this->getTruncatedColumnAlias($this->_get_column_alias($layout_def)."_currency")]; |
252 | 252 | } |
253 | - if($currency_id) |
|
253 | + if ($currency_id) |
|
254 | 254 | { |
255 | 255 | $currency = BeanFactory::getBean('Currencies', $currency_id); |
256 | - if(!empty($currency ->symbol)) |
|
256 | + if (!empty($currency ->symbol)) |
|
257 | 257 | { |
258 | 258 | $currency_symbol = $currency ->symbol; |
259 | 259 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3 | 3 | /********************************************************************************* |
4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -66,18 +66,18 @@ discard block |
||
66 | 66 | |
67 | 67 | require_once('include/formbase.php'); |
68 | 68 | |
69 | - global $beanFiles,$beanList; |
|
69 | + global $beanFiles, $beanList; |
|
70 | 70 | $bean_name = $beanList[$_REQUEST['module']]; |
71 | 71 | require_once($beanFiles[$bean_name]); |
72 | 72 | $focus = new $bean_name(); |
73 | - if ( empty($_REQUEST['linked_id']) || empty($_REQUEST['linked_field']) || empty($_REQUEST['record'])) |
|
73 | + if (empty($_REQUEST['linked_id']) || empty($_REQUEST['linked_field']) || empty($_REQUEST['record'])) |
|
74 | 74 | { |
75 | 75 | die("need linked_field, linked_id and record fields"); |
76 | 76 | } |
77 | 77 | $linked_field = $_REQUEST['linked_field']; |
78 | 78 | $record = $_REQUEST['record']; |
79 | 79 | $linked_id = $_REQUEST['linked_id']; |
80 | - if($bean_name == 'Team') |
|
80 | + if ($bean_name == 'Team') |
|
81 | 81 | { |
82 | 82 | $focus->retrieve($record); |
83 | 83 | $focus->remove_user_from_team($linked_id); |
@@ -86,21 +86,21 @@ discard block |
||
86 | 86 | { |
87 | 87 | // cut it off: |
88 | 88 | $focus->load_relationship($linked_field); |
89 | - if($focus->$linked_field->_relationship->relationship_name == 'quotes_contacts_shipto') |
|
89 | + if ($focus->$linked_field->_relationship->relationship_name == 'quotes_contacts_shipto') |
|
90 | 90 | unset($focus->$linked_field->_relationship->relationship_role_column); |
91 | - $focus->$linked_field->delete($record,$linked_id); |
|
91 | + $focus->$linked_field->delete($record, $linked_id); |
|
92 | 92 | } |
93 | - if ($bean_name == 'Campaign' and $linked_field=='prospectlists' ) { |
|
93 | + if ($bean_name == 'Campaign' and $linked_field == 'prospectlists') { |
|
94 | 94 | |
95 | - $query="SELECT email_marketing_prospect_lists.id from email_marketing_prospect_lists "; |
|
96 | - $query.=" left join email_marketing on email_marketing.id=email_marketing_prospect_lists.email_marketing_id"; |
|
97 | - $query.=" where email_marketing.campaign_id='$record'"; |
|
98 | - $query.=" and email_marketing_prospect_lists.prospect_list_id='$linked_id'"; |
|
95 | + $query = "SELECT email_marketing_prospect_lists.id from email_marketing_prospect_lists "; |
|
96 | + $query .= " left join email_marketing on email_marketing.id=email_marketing_prospect_lists.email_marketing_id"; |
|
97 | + $query .= " where email_marketing.campaign_id='$record'"; |
|
98 | + $query .= " and email_marketing_prospect_lists.prospect_list_id='$linked_id'"; |
|
99 | 99 | |
100 | - $result=$focus->db->query($query); |
|
101 | - while (($row=$focus->db->fetchByAssoc($result)) != null) { |
|
102 | - $del_query =" update email_marketing_prospect_lists set email_marketing_prospect_lists.deleted=1, email_marketing_prospect_lists.date_modified=".$focus->db->convert("'".TimeDate::getInstance()->nowDb()."'",'datetime'); |
|
103 | - $del_query.=" WHERE email_marketing_prospect_lists.id='{$row['id']}'"; |
|
100 | + $result = $focus->db->query($query); |
|
101 | + while (($row = $focus->db->fetchByAssoc($result)) != null) { |
|
102 | + $del_query = " update email_marketing_prospect_lists set email_marketing_prospect_lists.deleted=1, email_marketing_prospect_lists.date_modified=".$focus->db->convert("'".TimeDate::getInstance()->nowDb()."'", 'datetime'); |
|
103 | + $del_query .= " WHERE email_marketing_prospect_lists.id='{$row['id']}'"; |
|
104 | 104 | $focus->db->query($del_query); |
105 | 105 | } |
106 | 106 | $focus->db->query($query); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $user->retrieve($linked_id); |
112 | 112 | if (!empty($user->id)) { //make sure that record exists. we may have a contact on our hands. |
113 | 113 | |
114 | - if($focus->update_vcal) |
|
114 | + if ($focus->update_vcal) |
|
115 | 115 | { |
116 | 116 | vCal::cache_sugar_vcal($user); |
117 | 117 | } |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | $eapm->mark_deleted($linked_id); |
123 | 123 | } |
124 | 124 | |
125 | -if(!empty($_REQUEST['return_url'])){ |
|
126 | - $_REQUEST['return_url'] =urldecode($_REQUEST['return_url']); |
|
125 | +if (!empty($_REQUEST['return_url'])) { |
|
126 | + $_REQUEST['return_url'] = urldecode($_REQUEST['return_url']); |
|
127 | 127 | } |
128 | -$GLOBALS['log']->debug("deleted relationship: bean: $bean_name, linked_field: $linked_field, linked_id:$linked_id" ); |
|
129 | -if(empty($_REQUEST['refresh_page'])){ |
|
128 | +$GLOBALS['log']->debug("deleted relationship: bean: $bean_name, linked_field: $linked_field, linked_id:$linked_id"); |
|
129 | +if (empty($_REQUEST['refresh_page'])) { |
|
130 | 130 | handleRedirect(); |
131 | 131 | } |
132 | 132 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3 | 3 | /********************************************************************************* |
4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * theme basis. |
47 | 47 | ********************************************************************************/ |
48 | 48 | |
49 | -if(!defined('JSMIN_AS_LIB')) |
|
49 | +if (!defined('JSMIN_AS_LIB')) |
|
50 | 50 | define('JSMIN_AS_LIB', true); |
51 | 51 | |
52 | 52 | require_once("include/SugarTheme/cssmin.php"); |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @deprecated only here for BC during upgrades |
115 | 115 | * @var array |
116 | 116 | */ |
117 | - protected $fonts = array(); |
|
117 | + protected $fonts = array(); |
|
118 | 118 | |
119 | 119 | /** |
120 | 120 | * Maximum sugar version this theme is for; defaults to 5.5.1 as all the themes without this |
@@ -292,44 +292,44 @@ discard block |
||
292 | 292 | ) |
293 | 293 | { |
294 | 294 | // apply parent theme's properties first |
295 | - if ( isset($defaults['parentTheme']) ) { |
|
295 | + if (isset($defaults['parentTheme'])) { |
|
296 | 296 | $themedef = array(); |
297 | 297 | include("themes/{$defaults['parentTheme']}/themedef.php"); |
298 | - foreach ( $themedef as $key => $value ) { |
|
299 | - if ( property_exists(__CLASS__,$key) ) { |
|
298 | + foreach ($themedef as $key => $value) { |
|
299 | + if (property_exists(__CLASS__, $key)) { |
|
300 | 300 | // For all arrays ( except colors and fonts ) you can just specify the items |
301 | 301 | // to change instead of all of the values |
302 | - if ( is_array($this->$key) && !in_array($key,array('colors','fonts')) ) |
|
303 | - $this->$key = array_merge($this->$key,$value); |
|
302 | + if (is_array($this->$key) && !in_array($key, array('colors', 'fonts'))) |
|
303 | + $this->$key = array_merge($this->$key, $value); |
|
304 | 304 | else |
305 | 305 | $this->$key = $value; |
306 | 306 | } |
307 | 307 | } |
308 | 308 | } |
309 | - foreach ( $defaults as $key => $value ) { |
|
310 | - if ( property_exists(__CLASS__,$key) ) { |
|
309 | + foreach ($defaults as $key => $value) { |
|
310 | + if (property_exists(__CLASS__, $key)) { |
|
311 | 311 | // For all arrays ( except colors and fonts ) you can just specify the items |
312 | 312 | // to change instead of all of the values |
313 | - if ( is_array($this->$key) && !in_array($key,array('colors','fonts')) ) |
|
314 | - $this->$key = array_merge($this->$key,$value); |
|
313 | + if (is_array($this->$key) && !in_array($key, array('colors', 'fonts'))) |
|
314 | + $this->$key = array_merge($this->$key, $value); |
|
315 | 315 | else |
316 | 316 | $this->$key = $value; |
317 | 317 | } |
318 | 318 | } |
319 | - if ( !inDeveloperMode() ) { |
|
320 | - if ( sugar_is_file($cachedfile = sugar_cached($this->getFilePath().'/pathCache.php'))) { |
|
319 | + if (!inDeveloperMode()) { |
|
320 | + if (sugar_is_file($cachedfile = sugar_cached($this->getFilePath().'/pathCache.php'))) { |
|
321 | 321 | $caches = unserialize(file_get_contents($cachedfile)); |
322 | - if ( isset($caches['jsCache']) ) |
|
322 | + if (isset($caches['jsCache'])) |
|
323 | 323 | $this->_jsCache = $caches['jsCache']; |
324 | - if ( isset($caches['cssCache']) ) |
|
324 | + if (isset($caches['cssCache'])) |
|
325 | 325 | $this->_cssCache = $caches['cssCache']; |
326 | - if ( isset($caches['imageCache']) ) |
|
326 | + if (isset($caches['imageCache'])) |
|
327 | 327 | $this->_imageCache = $caches['imageCache']; |
328 | - if ( isset($caches['templateCache']) ) |
|
328 | + if (isset($caches['templateCache'])) |
|
329 | 329 | $this->_templateCache = $caches['templateCache']; |
330 | 330 | } |
331 | 331 | $cachedfile = sugar_cached($this->getFilePath().'/spriteCache.php'); |
332 | - if(!empty($GLOBALS['sugar_config']['use_sprites']) && sugar_is_file($cachedfile)) { |
|
332 | + if (!empty($GLOBALS['sugar_config']['use_sprites']) && sugar_is_file($cachedfile)) { |
|
333 | 333 | $this->_spriteCache = unserialize(sugar_file_get_contents($cachedfile)); |
334 | 334 | } |
335 | 335 | } |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | public function __wakeup() |
349 | 349 | { |
350 | 350 | // clean all properties |
351 | - foreach(get_object_vars($this) as $k => $v) { |
|
351 | + foreach (get_object_vars($this) as $k => $v) { |
|
352 | 352 | $this->$k = null; |
353 | 353 | } |
354 | 354 | throw new Exception("Not a serializable object"); |
@@ -361,14 +361,14 @@ discard block |
||
361 | 361 | public function __destruct() |
362 | 362 | { |
363 | 363 | // Set the current directory to one which we expect it to be (i.e. the root directory of the install |
364 | - $dir = realpath(dirname(__FILE__) . '/../..'); |
|
364 | + $dir = realpath(dirname(__FILE__).'/../..'); |
|
365 | 365 | static $includePathIsPatched = false; |
366 | 366 | if ($includePathIsPatched == false) |
367 | 367 | { |
368 | 368 | $path = explode(PATH_SEPARATOR, get_include_path()); |
369 | 369 | if (in_array($dir, $path) == false) |
370 | 370 | { |
371 | - set_include_path($dir . PATH_SEPARATOR . get_include_path()); |
|
371 | + set_include_path($dir.PATH_SEPARATOR.get_include_path()); |
|
372 | 372 | } |
373 | 373 | $includePathIsPatched = true; |
374 | 374 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | $cachedir = sugar_cached($this->getFilePath()); |
377 | 377 | sugar_mkdir($cachedir, 0775, true); |
378 | 378 | // clear out the cache on destroy if we are asked to |
379 | - if ( $this->_clearCacheOnDestroy ) { |
|
379 | + if ($this->_clearCacheOnDestroy) { |
|
380 | 380 | |
381 | 381 | if (is_file("$cachedir/pathCache.php")) |
382 | 382 | unlink("$cachedir/pathCache.php"); |
@@ -384,9 +384,9 @@ discard block |
||
384 | 384 | unlink("$cachedir/spriteCache.php"); |
385 | 385 | |
386 | 386 | } |
387 | - elseif ( !inDeveloperMode() ) { |
|
387 | + elseif (!inDeveloperMode()) { |
|
388 | 388 | // only update the caches if they have been changed in this request |
389 | - if ( count($this->_jsCache) != $this->_initialCacheSize['jsCache'] |
|
389 | + if (count($this->_jsCache) != $this->_initialCacheSize['jsCache'] |
|
390 | 390 | || count($this->_cssCache) != $this->_initialCacheSize['cssCache'] |
391 | 391 | || count($this->_imageCache) != $this->_initialCacheSize['imageCache'] |
392 | 392 | || count($this->_templateCache) != $this->_initialCacheSize['templateCache'] |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | ); |
405 | 405 | |
406 | 406 | } |
407 | - if ( count($this->_spriteCache) != $this->_initialCacheSize['spriteCache']) { |
|
407 | + if (count($this->_spriteCache) != $this->_initialCacheSize['spriteCache']) { |
|
408 | 408 | sugar_file_put_contents( |
409 | 409 | "$cachedir/spriteCache.php", |
410 | 410 | serialize($this->_spriteCache) |
@@ -433,11 +433,11 @@ discard block |
||
433 | 433 | $key |
434 | 434 | ) |
435 | 435 | { |
436 | - if ( isset($this->$key) ) |
|
436 | + if (isset($this->$key)) |
|
437 | 437 | return $this->$key; |
438 | 438 | } |
439 | 439 | |
440 | - public function __isset($key){ |
|
440 | + public function __isset($key) { |
|
441 | 441 | return isset($this->$key); |
442 | 442 | |
443 | 443 | } |
@@ -604,38 +604,38 @@ discard block |
||
604 | 604 | |
605 | 605 | |
606 | 606 | // sprites |
607 | - if(!empty($GLOBALS['sugar_config']['use_sprites']) && $GLOBALS['sugar_config']['use_sprites']) { |
|
607 | + if (!empty($GLOBALS['sugar_config']['use_sprites']) && $GLOBALS['sugar_config']['use_sprites']) { |
|
608 | 608 | |
609 | 609 | // system wide sprites |
610 | - if(file_exists("cache/sprites/default/sprites.css")) |
|
610 | + if (file_exists("cache/sprites/default/sprites.css")) |
|
611 | 611 | $html .= '<link rel="stylesheet" type="text/css" href="'.getJSPath('cache/sprites/default/sprites.css').'" />'; |
612 | 612 | |
613 | 613 | // theme specific sprites |
614 | - if(file_exists("cache/sprites/{$this->dirName}/sprites.css")) |
|
614 | + if (file_exists("cache/sprites/{$this->dirName}/sprites.css")) |
|
615 | 615 | $html .= '<link rel="stylesheet" type="text/css" href="'.getJSPath('cache/sprites/'.$this->dirName.'/sprites.css').'" />'; |
616 | 616 | |
617 | 617 | // parent sprites |
618 | - if($this->parentTheme && $parent = SugarThemeRegistry::get($this->parentTheme)) { |
|
619 | - if(file_exists("cache/sprites/{$parent->dirName}/sprites.css")) |
|
618 | + if ($this->parentTheme && $parent = SugarThemeRegistry::get($this->parentTheme)) { |
|
619 | + if (file_exists("cache/sprites/{$parent->dirName}/sprites.css")) |
|
620 | 620 | $html .= '<link rel="stylesheet" type="text/css" href="'.getJSPath('cache/sprites/'.$parent->dirName.'/sprites.css').'" />'; |
621 | 621 | } |
622 | 622 | |
623 | 623 | // repeatable sprites |
624 | - if(file_exists("cache/sprites/Repeatable/sprites.css")) |
|
624 | + if (file_exists("cache/sprites/Repeatable/sprites.css")) |
|
625 | 625 | $html .= '<link rel="stylesheet" type="text/css" href="'.getJSPath('cache/sprites/Repeatable/sprites.css').'" />'; |
626 | 626 | } |
627 | 627 | |
628 | 628 | // for BC during upgrade |
629 | - if ( !empty($this->colors) ) { |
|
630 | - if ( isset($_SESSION['authenticated_user_theme_color']) && in_array($_SESSION['authenticated_user_theme_color'], $this->colors)) |
|
629 | + if (!empty($this->colors)) { |
|
630 | + if (isset($_SESSION['authenticated_user_theme_color']) && in_array($_SESSION['authenticated_user_theme_color'], $this->colors)) |
|
631 | 631 | $color = $_SESSION['authenticated_user_theme_color']; |
632 | 632 | else |
633 | 633 | $color = $this->colors[0]; |
634 | 634 | $html .= '<link rel="stylesheet" type="text/css" href="'.$this->getCSSURL('colors.'.$color.'.css').'" id="current_color_style" />'; |
635 | 635 | } |
636 | 636 | |
637 | - if ( !empty($this->fonts) ) { |
|
638 | - if ( isset($_SESSION['authenticated_user_theme_font']) && in_array($_SESSION['authenticated_user_theme_font'], $this->fonts)) |
|
637 | + if (!empty($this->fonts)) { |
|
638 | + if (isset($_SESSION['authenticated_user_theme_font']) && in_array($_SESSION['authenticated_user_theme_font'], $this->fonts)) |
|
639 | 639 | $font = $_SESSION['authenticated_user_theme_font']; |
640 | 640 | else |
641 | 641 | $font = $this->fonts[0]; |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | $templateName |
670 | 670 | ) |
671 | 671 | { |
672 | - if ( isset($this->_templateCache[$templateName]) ) |
|
672 | + if (isset($this->_templateCache[$templateName])) |
|
673 | 673 | return $this->_templateCache[$templateName]; |
674 | 674 | |
675 | 675 | $templatePath = ''; |
@@ -719,28 +719,28 @@ discard block |
||
719 | 719 | static $cached_results = array(); |
720 | 720 | |
721 | 721 | // trap deprecated use of image extension |
722 | - if(is_null($ext)) { |
|
723 | - $imageNameExp = explode('.',$imageName); |
|
724 | - if(count($imageNameExp) == 1) |
|
722 | + if (is_null($ext)) { |
|
723 | + $imageNameExp = explode('.', $imageName); |
|
724 | + if (count($imageNameExp) == 1) |
|
725 | 725 | $imageName .= '.gif'; |
726 | 726 | } else { |
727 | 727 | $imageName .= $ext; |
728 | 728 | } |
729 | 729 | |
730 | 730 | // trap alt attributes in other_attributes |
731 | - if(preg_match('/alt=["\']([^\'"]+)["\']/i', $other_attributes)) |
|
731 | + if (preg_match('/alt=["\']([^\'"]+)["\']/i', $other_attributes)) |
|
732 | 732 | $GLOBALS['log']->debug("Sprites: alt attribute detected for $imageName"); |
733 | 733 | // sprite handler, makes use of own caching mechanism |
734 | - if(!empty($GLOBALS['sugar_config']['use_sprites']) && $GLOBALS['sugar_config']['use_sprites']) { |
|
734 | + if (!empty($GLOBALS['sugar_config']['use_sprites']) && $GLOBALS['sugar_config']['use_sprites']) { |
|
735 | 735 | // get sprite metadata |
736 | - if($sp = $this->getSpriteMeta($imageName)) { |
|
736 | + if ($sp = $this->getSpriteMeta($imageName)) { |
|
737 | 737 | // requested size should match |
738 | - if( (!is_null($width) && $sp['width'] == $width) || (is_null($width)) && |
|
739 | - (!is_null($height) && $sp['height'] == $height) || (is_null($height)) ) |
|
738 | + if ((!is_null($width) && $sp['width'] == $width) || (is_null($width)) && |
|
739 | + (!is_null($height) && $sp['height'] == $height) || (is_null($height))) |
|
740 | 740 | { |
741 | 741 | $other_attributes .= ' data-orig="'.$imageName.'"'; |
742 | 742 | |
743 | - if($sprite = $this->getSprite($sp['class'], $other_attributes, $alt)) |
|
743 | + if ($sprite = $this->getSprite($sp['class'], $other_attributes, $alt)) |
|
744 | 744 | { |
745 | 745 | return $sprite; |
746 | 746 | } |
@@ -749,11 +749,11 @@ discard block |
||
749 | 749 | } |
750 | 750 | |
751 | 751 | // img caching |
752 | - if(empty($cached_results[$imageName])) { |
|
753 | - $imageURL = $this->getImageURL($imageName,false); |
|
754 | - if ( empty($imageURL) ) |
|
752 | + if (empty($cached_results[$imageName])) { |
|
753 | + $imageURL = $this->getImageURL($imageName, false); |
|
754 | + if (empty($imageURL)) |
|
755 | 755 | return false; |
756 | - if(strpos($imageURL, '.svg', strlen($imageURL)-4)){ |
|
756 | + if (strpos($imageURL, '.svg', strlen($imageURL) - 4)) { |
|
757 | 757 | $cached_results[$imageName] = file_get_contents($imageURL); |
758 | 758 | } else { |
759 | 759 | $cached_results[$imageName] = '<img src="'.getJSPath($imageURL).'" '; |
@@ -764,10 +764,10 @@ discard block |
||
764 | 764 | $attr_width = (is_null($width)) ? "" : "width=\"$width\""; |
765 | 765 | $attr_height = (is_null($height)) ? "" : "height=\"$height\""; |
766 | 766 | |
767 | - if(strpos($cached_results[$imageName], 'svg') !== false){ |
|
767 | + if (strpos($cached_results[$imageName], 'svg') !== false) { |
|
768 | 768 | return $cached_results[$imageName]; |
769 | 769 | } |
770 | - return $cached_results[$imageName] . " $attr_width $attr_height $other_attributes alt=\"$alt\" />"; |
|
770 | + return $cached_results[$imageName]." $attr_width $attr_height $other_attributes alt=\"$alt\" />"; |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | /** |
@@ -779,12 +779,12 @@ discard block |
||
779 | 779 | public function getSpriteMeta($imageName) { |
780 | 780 | |
781 | 781 | // return from cache |
782 | - if(isset($this->_spriteCache[$imageName])) |
|
782 | + if (isset($this->_spriteCache[$imageName])) |
|
783 | 783 | return $this->_spriteCache[$imageName]; |
784 | 784 | |
785 | 785 | // sprite keys are base on imageURL |
786 | - $imageURL = $this->getImageURL($imageName,false); |
|
787 | - if(empty($imageURL)) { |
|
786 | + $imageURL = $this->getImageURL($imageName, false); |
|
787 | + if (empty($imageURL)) { |
|
788 | 788 | $this->_spriteCache[$imageName] = false; |
789 | 789 | return false; |
790 | 790 | } |
@@ -795,12 +795,12 @@ discard block |
||
795 | 795 | // add current theme dir |
796 | 796 | $meta->loadSpriteMeta($this->dirName); |
797 | 797 | // add parent theme dir |
798 | - if($this->parentTheme && $parent = SugarThemeRegistry::get($this->parentTheme)) { |
|
798 | + if ($this->parentTheme && $parent = SugarThemeRegistry::get($this->parentTheme)) { |
|
799 | 799 | $meta->loadSpriteMeta($parent->dirName); |
800 | 800 | } |
801 | 801 | |
802 | 802 | // add to cache |
803 | - if(isset($meta->sprites[$imageURL])) { |
|
803 | + if (isset($meta->sprites[$imageURL])) { |
|
804 | 804 | $this->_spriteCache[$imageName] = $meta->sprites[$imageURL]; |
805 | 805 | // add imageURL to cache |
806 | 806 | //$this->_spriteCache[$imageName]['imageURL'] = $imageURL; |
@@ -824,7 +824,7 @@ discard block |
||
824 | 824 | // handle multiple class tags |
825 | 825 | $class_regex = '/class=["\']([^\'"]+)["\']/i'; |
826 | 826 | preg_match($class_regex, $attr, $match); |
827 | - if(isset($match[1])) { |
|
827 | + if (isset($match[1])) { |
|
828 | 828 | $attr = preg_replace($class_regex, 'class="spr_'.$class.' ${1}"', $attr); |
829 | 829 | |
830 | 830 | // single class |
@@ -832,7 +832,7 @@ discard block |
||
832 | 832 | $attr .= ' class="spr_'.$class.'"'; |
833 | 833 | } |
834 | 834 | |
835 | - if($title) |
|
835 | + if ($title) |
|
836 | 836 | $attr .= ' title="'.$title.'"'; |
837 | 837 | |
838 | 838 | // use </span> instead of /> to prevent weird UI results |
@@ -856,13 +856,13 @@ discard block |
||
856 | 856 | ) |
857 | 857 | { |
858 | 858 | |
859 | - if($img_name) { |
|
859 | + if ($img_name) { |
|
860 | 860 | $img = $this->getImage($img_name, $img_other_attributes, $img_width, $img_height, null, $img_alt); |
861 | - if($img == false) { |
|
861 | + if ($img == false) { |
|
862 | 862 | $GLOBALS['log']->debug('Sprites: unknown image getLink'); |
863 | 863 | $img = 'unknown'; |
864 | 864 | } |
865 | - switch($img_placement) { |
|
865 | + switch ($img_placement) { |
|
866 | 866 | case 'left': $inner_html = $img."<span class='title'>".$title."</span>"; break; |
867 | 867 | case 'right': $inner_html = "<span class='title'>".$title."</span>".$img; break; |
868 | 868 | default: $inner_html = $img; break; |
@@ -885,9 +885,9 @@ discard block |
||
885 | 885 | public function getImageURL( |
886 | 886 | $imageName, |
887 | 887 | $addJSPath = true |
888 | - ){ |
|
889 | - if ( isset($this->_imageCache[$imageName]) ) { |
|
890 | - if ( $addJSPath ) |
|
888 | + ) { |
|
889 | + if (isset($this->_imageCache[$imageName])) { |
|
890 | + if ($addJSPath) |
|
891 | 891 | return getJSPath($this->_imageCache[$imageName]); |
892 | 892 | else |
893 | 893 | return $this->_imageCache[$imageName]; |
@@ -899,7 +899,7 @@ discard block |
||
899 | 899 | $imagePath = $filename; |
900 | 900 | elseif (isset($this->parentTheme) |
901 | 901 | && SugarThemeRegistry::get($this->parentTheme) instanceOf SugarTheme |
902 | - && ($filename = SugarThemeRegistry::get($this->parentTheme)->getImageURL($imageName,false)) != '') |
|
902 | + && ($filename = SugarThemeRegistry::get($this->parentTheme)->getImageURL($imageName, false)) != '') |
|
903 | 903 | $imagePath = $filename; |
904 | 904 | elseif (($filename = $this->_getImageFileName('custom/'.$this->getDefaultImagePath().'/'.$imageName)) != '') |
905 | 905 | $imagePath = $filename; |
@@ -914,7 +914,7 @@ discard block |
||
914 | 914 | |
915 | 915 | $this->_imageCache[$imageName] = $imagePath; |
916 | 916 | |
917 | - if ( $addJSPath ) |
|
917 | + if ($addJSPath) |
|
918 | 918 | return getJSPath($imagePath); |
919 | 919 | |
920 | 920 | return $imagePath; |
@@ -931,13 +931,13 @@ discard block |
||
931 | 931 | ) |
932 | 932 | { |
933 | 933 | // return now if the extension matches that of which we are looking for |
934 | - if ( sugar_is_file($imageName) ) |
|
934 | + if (sugar_is_file($imageName)) |
|
935 | 935 | return $imageName; |
936 | 936 | $pathParts = pathinfo($imageName); |
937 | - foreach ( $this->imageExtensions as $extension ) |
|
938 | - if ( isset($pathParts['extension']) ) |
|
939 | - if ( ( $extension != $pathParts['extension'] ) |
|
940 | - && sugar_is_file($pathParts['dirname'].'/'.$pathParts['filename'].'.'.$extension) ) |
|
937 | + foreach ($this->imageExtensions as $extension) |
|
938 | + if (isset($pathParts['extension'])) |
|
939 | + if (($extension != $pathParts['extension']) |
|
940 | + && sugar_is_file($pathParts['dirname'].'/'.$pathParts['filename'].'.'.$extension)) |
|
941 | 941 | return $pathParts['dirname'].'/'.$pathParts['filename'].'.'.$extension; |
942 | 942 | |
943 | 943 | return ''; |
@@ -953,8 +953,8 @@ discard block |
||
953 | 953 | */ |
954 | 954 | public function getCSSURL($cssFileName, $returnURL = true) |
955 | 955 | { |
956 | - if ( isset($this->_cssCache[$cssFileName]) && sugar_is_file(sugar_cached($this->_cssCache[$cssFileName])) ) { |
|
957 | - if ( $returnURL ) |
|
956 | + if (isset($this->_cssCache[$cssFileName]) && sugar_is_file(sugar_cached($this->_cssCache[$cssFileName]))) { |
|
957 | + if ($returnURL) |
|
958 | 958 | return getJSPath("cache/".$this->_cssCache[$cssFileName]); |
959 | 959 | else |
960 | 960 | return sugar_cached($this->_cssCache[$cssFileName]); |
@@ -965,7 +965,7 @@ discard block |
||
965 | 965 | $fullFileName = $this->getCSSPath().'/'.$cssFileName; |
966 | 966 | if (isset($this->parentTheme) |
967 | 967 | && SugarThemeRegistry::get($this->parentTheme) instanceOf SugarTheme |
968 | - && ($filename = SugarThemeRegistry::get($this->parentTheme)->getCSSURL($cssFileName,false)) != '') |
|
968 | + && ($filename = SugarThemeRegistry::get($this->parentTheme)->getCSSURL($cssFileName, false)) != '') |
|
969 | 969 | $cssFileContents .= file_get_contents($filename); |
970 | 970 | else { |
971 | 971 | if (sugar_is_file($defaultFileName)) |
@@ -994,24 +994,24 @@ discard block |
||
994 | 994 | |
995 | 995 | // if this is the style.css file, prepend the base.css and calendar-win2k-cold-1.css |
996 | 996 | // files before the theme styles |
997 | - if ( $cssFileName == 'style.css' && !isset($this->parentTheme) ) { |
|
998 | - if ( inDeveloperMode() ) |
|
999 | - $cssFileContents = file_get_contents('include/javascript/yui/build/base/base.css') . $cssFileContents; |
|
997 | + if ($cssFileName == 'style.css' && !isset($this->parentTheme)) { |
|
998 | + if (inDeveloperMode()) |
|
999 | + $cssFileContents = file_get_contents('include/javascript/yui/build/base/base.css').$cssFileContents; |
|
1000 | 1000 | else |
1001 | - $cssFileContents = file_get_contents('include/javascript/yui/build/base/base-min.css') . $cssFileContents; |
|
1001 | + $cssFileContents = file_get_contents('include/javascript/yui/build/base/base-min.css').$cssFileContents; |
|
1002 | 1002 | } |
1003 | 1003 | |
1004 | 1004 | // minify the css |
1005 | - if ( !inDeveloperMode() && !sugar_is_file($cssFilePath) ) { |
|
1005 | + if (!inDeveloperMode() && !sugar_is_file($cssFilePath)) { |
|
1006 | 1006 | $cssFileContents = cssmin::minify($cssFileContents); |
1007 | 1007 | } |
1008 | 1008 | |
1009 | 1009 | // now write the css to cache |
1010 | - sugar_file_put_contents($cssFilePath,$cssFileContents); |
|
1010 | + sugar_file_put_contents($cssFilePath, $cssFileContents); |
|
1011 | 1011 | |
1012 | 1012 | $this->_cssCache[$cssFileName] = $fullFileName; |
1013 | 1013 | |
1014 | - if ( $returnURL ) |
|
1014 | + if ($returnURL) |
|
1015 | 1015 | return getJSPath("cache/".$fullFileName); |
1016 | 1016 | |
1017 | 1017 | return sugar_cached($fullFileName); |
@@ -1027,8 +1027,8 @@ discard block |
||
1027 | 1027 | */ |
1028 | 1028 | public function getJSURL($jsFileName, $returnURL = true) |
1029 | 1029 | { |
1030 | - if ( isset($this->_jsCache[$jsFileName]) && sugar_is_file(sugar_cached($this->_jsCache[$jsFileName])) ) { |
|
1031 | - if ( $returnURL ) |
|
1030 | + if (isset($this->_jsCache[$jsFileName]) && sugar_is_file(sugar_cached($this->_jsCache[$jsFileName]))) { |
|
1031 | + if ($returnURL) |
|
1032 | 1032 | return getJSPath("cache/".$this->_jsCache[$jsFileName]); |
1033 | 1033 | else |
1034 | 1034 | return sugar_cached($this->_jsCache[$jsFileName]); |
@@ -1039,7 +1039,7 @@ discard block |
||
1039 | 1039 | $defaultFileName = $this->getDefaultJSPath().'/'.$jsFileName; |
1040 | 1040 | if (isset($this->parentTheme) |
1041 | 1041 | && SugarThemeRegistry::get($this->parentTheme) instanceOf SugarTheme |
1042 | - && ($filename = SugarThemeRegistry::get($this->parentTheme)->getJSURL($jsFileName,false)) != '' && !in_array($jsFileName,$this->ignoreParentFiles)) { |
|
1042 | + && ($filename = SugarThemeRegistry::get($this->parentTheme)->getJSURL($jsFileName, false)) != '' && !in_array($jsFileName, $this->ignoreParentFiles)) { |
|
1043 | 1043 | $jsFileContents .= file_get_contents($filename); |
1044 | 1044 | } else { |
1045 | 1045 | if (sugar_is_file($defaultFileName)) |
@@ -1060,18 +1060,18 @@ discard block |
||
1060 | 1060 | $jsFilePath = create_cache_directory($fullFileName); |
1061 | 1061 | |
1062 | 1062 | // minify the js |
1063 | - if ( !inDeveloperMode()&& !sugar_is_file(str_replace('.js','-min.js',$jsFilePath)) ) { |
|
1063 | + if (!inDeveloperMode() && !sugar_is_file(str_replace('.js', '-min.js', $jsFilePath))) { |
|
1064 | 1064 | $jsFileContents = SugarMin::minify($jsFileContents); |
1065 | - $jsFilePath = str_replace('.js','-min.js',$jsFilePath); |
|
1066 | - $fullFileName = str_replace('.js','-min.js',$fullFileName); |
|
1065 | + $jsFilePath = str_replace('.js', '-min.js', $jsFilePath); |
|
1066 | + $fullFileName = str_replace('.js', '-min.js', $fullFileName); |
|
1067 | 1067 | } |
1068 | 1068 | |
1069 | 1069 | // now write the js to cache |
1070 | - sugar_file_put_contents($jsFilePath,$jsFileContents); |
|
1070 | + sugar_file_put_contents($jsFilePath, $jsFileContents); |
|
1071 | 1071 | |
1072 | 1072 | $this->_jsCache[$jsFileName] = $fullFileName; |
1073 | 1073 | |
1074 | - if ( $returnURL ) |
|
1074 | + if ($returnURL) |
|
1075 | 1075 | return getJSPath("cache/".$fullFileName); |
1076 | 1076 | |
1077 | 1077 | return sugar_cached($fullFileName); |
@@ -1087,7 +1087,7 @@ discard block |
||
1087 | 1087 | // first, lets get all the paths of where to look |
1088 | 1088 | $pathsToSearch = array($this->getImagePath()); |
1089 | 1089 | $theme = $this; |
1090 | - while (isset($theme->parentTheme) && SugarThemeRegistry::get($theme->parentTheme) instanceOf SugarTheme ) { |
|
1090 | + while (isset($theme->parentTheme) && SugarThemeRegistry::get($theme->parentTheme) instanceOf SugarTheme) { |
|
1091 | 1091 | $theme = SugarThemeRegistry::get($theme->parentTheme); |
1092 | 1092 | $pathsToSearch[] = $theme->getImagePath(); |
1093 | 1093 | } |
@@ -1095,7 +1095,7 @@ discard block |
||
1095 | 1095 | |
1096 | 1096 | // now build the array |
1097 | 1097 | $imageArray = array(); |
1098 | - foreach ( $pathsToSearch as $path ) |
|
1098 | + foreach ($pathsToSearch as $path) |
|
1099 | 1099 | { |
1100 | 1100 | if (!sugar_is_dir($path)) $path = "custom/$path"; |
1101 | 1101 | if (sugar_is_dir($path) && is_readable($path) && $dir = opendir($path)) { |
@@ -1107,8 +1107,8 @@ discard block |
||
1107 | 1107 | || $file == "Attic" |
1108 | 1108 | ) |
1109 | 1109 | continue; |
1110 | - if ( !isset($imageArray[$file]) ) |
|
1111 | - $imageArray[$file] = $this->getImageURL($file,false); |
|
1110 | + if (!isset($imageArray[$file])) |
|
1111 | + $imageArray[$file] = $this->getImageURL($file, false); |
|
1112 | 1112 | } |
1113 | 1113 | closedir($dir); |
1114 | 1114 | } |
@@ -1130,13 +1130,13 @@ discard block |
||
1130 | 1130 | |
1131 | 1131 | $config = array(); |
1132 | 1132 | |
1133 | - foreach($this->config_options as $name => $def){ |
|
1133 | + foreach ($this->config_options as $name => $def) { |
|
1134 | 1134 | $config[$name] = $def; |
1135 | 1135 | |
1136 | 1136 | $value = ''; |
1137 | - if(isset($sugar_config['theme_settings'][$this->dirName][$name])){ |
|
1137 | + if (isset($sugar_config['theme_settings'][$this->dirName][$name])) { |
|
1138 | 1138 | $value = $sugar_config['theme_settings'][$this->dirName][$name]; |
1139 | - } else if(isset($def['default'])){ |
|
1139 | + } else if (isset($def['default'])) { |
|
1140 | 1140 | $value = $def['default']; |
1141 | 1141 | } |
1142 | 1142 | $config[$name] = $value; |
@@ -1189,28 +1189,28 @@ discard block |
||
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | // Assume theme is designed for 5.5.x if not specified otherwise |
1192 | - if ( !isset($themedef['version']) ) |
|
1192 | + if (!isset($themedef['version'])) |
|
1193 | 1193 | $themedef['version']['regex_matches'] = array('5\.5\.*'); |
1194 | 1194 | |
1195 | 1195 | // Check to see if theme is valid for this version of Sugar; return false if not |
1196 | 1196 | $version_ok = false; |
1197 | - if( isset($themedef['version']['exact_matches']) ){ |
|
1197 | + if (isset($themedef['version']['exact_matches'])) { |
|
1198 | 1198 | $matches_empty = false; |
1199 | - foreach( $themedef['version']['exact_matches'] as $match ){ |
|
1200 | - if( $match == $GLOBALS['sugar_version'] ){ |
|
1199 | + foreach ($themedef['version']['exact_matches'] as $match) { |
|
1200 | + if ($match == $GLOBALS['sugar_version']) { |
|
1201 | 1201 | $version_ok = true; |
1202 | 1202 | } |
1203 | 1203 | } |
1204 | 1204 | } |
1205 | - if( !$version_ok && isset($themedef['version']['regex_matches']) ){ |
|
1205 | + if (!$version_ok && isset($themedef['version']['regex_matches'])) { |
|
1206 | 1206 | $matches_empty = false; |
1207 | - foreach( $themedef['version']['regex_matches'] as $match ){ |
|
1208 | - if( preg_match( "/$match/", $GLOBALS['sugar_version'] ) ){ |
|
1207 | + foreach ($themedef['version']['regex_matches'] as $match) { |
|
1208 | + if (preg_match("/$match/", $GLOBALS['sugar_version'])) { |
|
1209 | 1209 | $version_ok = true; |
1210 | 1210 | } |
1211 | 1211 | } |
1212 | 1212 | } |
1213 | - if ( !$version_ok ) |
|
1213 | + if (!$version_ok) |
|
1214 | 1214 | return false; |
1215 | 1215 | |
1216 | 1216 | $theme = new SugarTheme($themedef); |
@@ -1226,7 +1226,7 @@ discard block |
||
1226 | 1226 | $themeName |
1227 | 1227 | ) |
1228 | 1228 | { |
1229 | - if ( self::exists($themeName) ) |
|
1229 | + if (self::exists($themeName)) |
|
1230 | 1230 | unset(self::$_themes[$themeName]); |
1231 | 1231 | } |
1232 | 1232 | |
@@ -1239,7 +1239,7 @@ discard block |
||
1239 | 1239 | $themeName |
1240 | 1240 | ) |
1241 | 1241 | { |
1242 | - if ( isset(self::$_themes[$themeName]) ) |
|
1242 | + if (isset(self::$_themes[$themeName])) |
|
1243 | 1243 | return self::$_themes[$themeName]; |
1244 | 1244 | } |
1245 | 1245 | |
@@ -1250,7 +1250,7 @@ discard block |
||
1250 | 1250 | */ |
1251 | 1251 | public static function current() |
1252 | 1252 | { |
1253 | - if ( !isset(self::$_currentTheme) ) |
|
1253 | + if (!isset(self::$_currentTheme)) |
|
1254 | 1254 | self::buildRegistry(); |
1255 | 1255 | |
1256 | 1256 | return self::$_themes[self::$_currentTheme]; |
@@ -1263,10 +1263,10 @@ discard block |
||
1263 | 1263 | */ |
1264 | 1264 | public static function getDefault() |
1265 | 1265 | { |
1266 | - if ( !isset(self::$_currentTheme) ) |
|
1266 | + if (!isset(self::$_currentTheme)) |
|
1267 | 1267 | self::buildRegistry(); |
1268 | 1268 | |
1269 | - if ( isset($GLOBALS['sugar_config']['default_theme']) && self::exists($GLOBALS['sugar_config']['default_theme']) ) { |
|
1269 | + if (isset($GLOBALS['sugar_config']['default_theme']) && self::exists($GLOBALS['sugar_config']['default_theme'])) { |
|
1270 | 1270 | return self::get($GLOBALS['sugar_config']['default_theme']); |
1271 | 1271 | } |
1272 | 1272 | $array_keys = array_keys(self::availableThemes()); |
@@ -1295,7 +1295,7 @@ discard block |
||
1295 | 1295 | $themeName |
1296 | 1296 | ) |
1297 | 1297 | { |
1298 | - if ( !self::exists($themeName) ) |
|
1298 | + if (!self::exists($themeName)) |
|
1299 | 1299 | return false; |
1300 | 1300 | |
1301 | 1301 | self::$_currentTheme = $themeName; |
@@ -1312,17 +1312,17 @@ discard block |
||
1312 | 1312 | public static function buildRegistry() |
1313 | 1313 | { |
1314 | 1314 | self::$_themes = array(); |
1315 | - $dirs = array("themes/","custom/themes/"); |
|
1315 | + $dirs = array("themes/", "custom/themes/"); |
|
1316 | 1316 | |
1317 | 1317 | // check for a default themedef file |
1318 | 1318 | $themedefDefault = array(); |
1319 | - if ( sugar_is_file("custom/themes/default/themedef.php") ) { |
|
1319 | + if (sugar_is_file("custom/themes/default/themedef.php")) { |
|
1320 | 1320 | $themedef = array(); |
1321 | 1321 | require("custom/themes/default/themedef.php"); |
1322 | 1322 | $themedefDefault = $themedef; |
1323 | 1323 | } |
1324 | 1324 | |
1325 | - foreach ($dirs as $dirPath ) { |
|
1325 | + foreach ($dirs as $dirPath) { |
|
1326 | 1326 | if (sugar_is_dir('./'.$dirPath) && is_readable('./'.$dirPath) && $dir = opendir('./'.$dirPath)) { |
1327 | 1327 | while (($file = readdir($dir)) !== false) { |
1328 | 1328 | if ($file == ".." |
@@ -1337,18 +1337,18 @@ discard block |
||
1337 | 1337 | continue; |
1338 | 1338 | $themedef = array(); |
1339 | 1339 | require("./{$dirPath}{$file}/themedef.php"); |
1340 | - $themedef = array_merge($themedef,$themedefDefault); |
|
1340 | + $themedef = array_merge($themedef, $themedefDefault); |
|
1341 | 1341 | $themedef['dirName'] = $file; |
1342 | 1342 | // check for theme already existing in the registry |
1343 | 1343 | // if so, then it will override the current one |
1344 | - if ( self::exists($themedef['dirName']) ) { |
|
1344 | + if (self::exists($themedef['dirName'])) { |
|
1345 | 1345 | $existingTheme = self::get($themedef['dirName']); |
1346 | - foreach ( SugarTheme::getThemeDefFields() as $field ) |
|
1347 | - if ( !isset($themedef[$field]) ) |
|
1346 | + foreach (SugarTheme::getThemeDefFields() as $field) |
|
1347 | + if (!isset($themedef[$field])) |
|
1348 | 1348 | $themedef[$field] = $existingTheme->$field; |
1349 | 1349 | self::remove($themedef['dirName']); |
1350 | 1350 | } |
1351 | - if ( isset($themedef['name']) ) { |
|
1351 | + if (isset($themedef['name'])) { |
|
1352 | 1352 | self::add($themedef); |
1353 | 1353 | } |
1354 | 1354 | } |
@@ -1356,8 +1356,8 @@ discard block |
||
1356 | 1356 | } |
1357 | 1357 | } |
1358 | 1358 | // default to setting the default theme as the current theme |
1359 | - if ( !isset($GLOBALS['sugar_config']['default_theme']) || !self::set($GLOBALS['sugar_config']['default_theme']) ) { |
|
1360 | - if ( count(self::availableThemes()) == 0 ) |
|
1359 | + if (!isset($GLOBALS['sugar_config']['default_theme']) || !self::set($GLOBALS['sugar_config']['default_theme'])) { |
|
1360 | + if (count(self::availableThemes()) == 0) |
|
1361 | 1361 | { |
1362 | 1362 | sugar_die('No valid themes are found on this instance'); |
1363 | 1363 | } else { |
@@ -1379,9 +1379,9 @@ discard block |
||
1379 | 1379 | private static function getDefaultThemeKey() |
1380 | 1380 | { |
1381 | 1381 | $availableThemes = self::availableThemes(); |
1382 | - foreach($availableThemes as $key=>$theme) |
|
1382 | + foreach ($availableThemes as $key=>$theme) |
|
1383 | 1383 | { |
1384 | - if(strtolower($key) == 'sugar') |
|
1384 | + if (strtolower($key) == 'sugar') |
|
1385 | 1385 | { |
1386 | 1386 | return $key; |
1387 | 1387 | } |
@@ -1400,11 +1400,11 @@ discard block |
||
1400 | 1400 | { |
1401 | 1401 | $themelist = array(); |
1402 | 1402 | $disabledThemes = array(); |
1403 | - if ( isset($GLOBALS['sugar_config']['disabled_themes']) ) |
|
1404 | - $disabledThemes = explode(',',$GLOBALS['sugar_config']['disabled_themes']); |
|
1403 | + if (isset($GLOBALS['sugar_config']['disabled_themes'])) |
|
1404 | + $disabledThemes = explode(',', $GLOBALS['sugar_config']['disabled_themes']); |
|
1405 | 1405 | |
1406 | - foreach ( self::$_themes as $themename => $themeobject ) { |
|
1407 | - if ( in_array($themename,$disabledThemes) ) |
|
1406 | + foreach (self::$_themes as $themename => $themeobject) { |
|
1407 | + if (in_array($themename, $disabledThemes)) |
|
1408 | 1408 | continue; |
1409 | 1409 | $themelist[$themeobject->dirName] = $themeobject->name; |
1410 | 1410 | } |
@@ -1421,11 +1421,11 @@ discard block |
||
1421 | 1421 | { |
1422 | 1422 | $themelist = array(); |
1423 | 1423 | $disabledThemes = array(); |
1424 | - if ( isset($GLOBALS['sugar_config']['disabled_themes']) ) |
|
1425 | - $disabledThemes = explode(',',$GLOBALS['sugar_config']['disabled_themes']); |
|
1424 | + if (isset($GLOBALS['sugar_config']['disabled_themes'])) |
|
1425 | + $disabledThemes = explode(',', $GLOBALS['sugar_config']['disabled_themes']); |
|
1426 | 1426 | |
1427 | - foreach ( self::$_themes as $themename => $themeobject ) { |
|
1428 | - if ( in_array($themename,$disabledThemes) ) |
|
1427 | + foreach (self::$_themes as $themename => $themeobject) { |
|
1428 | + if (in_array($themename, $disabledThemes)) |
|
1429 | 1429 | $themelist[$themeobject->dirName] = $themeobject->name; |
1430 | 1430 | } |
1431 | 1431 | |
@@ -1441,7 +1441,7 @@ discard block |
||
1441 | 1441 | { |
1442 | 1442 | $themelist = array(); |
1443 | 1443 | |
1444 | - foreach ( self::$_themes as $themename => $themeobject ) |
|
1444 | + foreach (self::$_themes as $themename => $themeobject) |
|
1445 | 1445 | $themelist[$themeobject->dirName] = $themeobject->name; |
1446 | 1446 | |
1447 | 1447 | return $themelist; |
@@ -1478,18 +1478,18 @@ discard block |
||
1478 | 1478 | { |
1479 | 1479 | global $sugar_config; |
1480 | 1480 | |
1481 | - if ( !self::exists($themeName) ) |
|
1481 | + if (!self::exists($themeName)) |
|
1482 | 1482 | return false; |
1483 | 1483 | |
1484 | 1484 | $config = array(); |
1485 | 1485 | |
1486 | - foreach(self::$_themes[$themeName]->config_options as $name => $def){ |
|
1486 | + foreach (self::$_themes[$themeName]->config_options as $name => $def) { |
|
1487 | 1487 | $config[$name] = $def; |
1488 | 1488 | |
1489 | 1489 | $value = ''; |
1490 | - if(isset($sugar_config['theme_settings'][$themeName][$name])){ |
|
1490 | + if (isset($sugar_config['theme_settings'][$themeName][$name])) { |
|
1491 | 1491 | $value = $sugar_config['theme_settings'][$themeName][$name]; |
1492 | - } else if(isset($def['default'])){ |
|
1492 | + } else if (isset($def['default'])) { |
|
1493 | 1493 | $value = $def['default']; |
1494 | 1494 | } |
1495 | 1495 | $config[$name]['value'] = $value; |
@@ -1505,7 +1505,7 @@ discard block |
||
1505 | 1505 | */ |
1506 | 1506 | public static function clearAllCaches() |
1507 | 1507 | { |
1508 | - foreach ( self::$_themes as $themeobject ) { |
|
1508 | + foreach (self::$_themes as $themeobject) { |
|
1509 | 1509 | $themeobject->clearCache(); |
1510 | 1510 | } |
1511 | 1511 | } |
@@ -49,21 +49,21 @@ discard block |
||
49 | 49 | * @param module - the name of the module we are working with |
50 | 50 | * @param templates - an array of templates this module uses |
51 | 51 | */ |
52 | - static function createLanguageFile($module , $templates=array('default'), $refresh = false){ |
|
52 | + static function createLanguageFile($module, $templates = array('default'), $refresh = false) { |
|
53 | 53 | global $mod_strings, $current_language; |
54 | - if(inDeveloperMode() || !empty($_SESSION['developerMode'])){ |
|
54 | + if (inDeveloperMode() || !empty($_SESSION['developerMode'])) { |
|
55 | 55 | $refresh = true; |
56 | 56 | } |
57 | 57 | $temp_mod_strings = $mod_strings; |
58 | 58 | $lang = $current_language; |
59 | - if(empty($lang)) |
|
59 | + if (empty($lang)) |
|
60 | 60 | $lang = $GLOBALS['sugar_config']['default_language']; |
61 | 61 | static $createdModules = array(); |
62 | - if(empty($createdModules[$module]) && ($refresh || !file_exists(sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'))){ |
|
62 | + if (empty($createdModules[$module]) && ($refresh || !file_exists(sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'))) { |
|
63 | 63 | $loaded_mod_strings = array(); |
64 | - $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module , $templates, $lang , $loaded_mod_strings); |
|
64 | + $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module, $templates, $lang, $loaded_mod_strings); |
|
65 | 65 | $createdModules[$module] = true; |
66 | - LanguageManager::refreshLanguage($module,$lang, $loaded_mod_strings); |
|
66 | + LanguageManager::refreshLanguage($module, $lang, $loaded_mod_strings); |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
@@ -74,48 +74,48 @@ discard block |
||
74 | 74 | * @param lang - current language this module use |
75 | 75 | * @param loaded_mod_strings - the string that we will add the module template language into |
76 | 76 | */ |
77 | - static function loadTemplateLanguage($module , $templates , $lang, $loaded_mod_strings){ |
|
77 | + static function loadTemplateLanguage($module, $templates, $lang, $loaded_mod_strings) { |
|
78 | 78 | $templates = array_reverse($templates); |
79 | - foreach($templates as $template){ |
|
80 | - $temp = LanguageManager::addTemplate($module,$lang, $template); |
|
79 | + foreach ($templates as $template) { |
|
80 | + $temp = LanguageManager::addTemplate($module, $lang, $template); |
|
81 | 81 | $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $temp); |
82 | 82 | } |
83 | 83 | return $loaded_mod_strings; |
84 | 84 | } |
85 | 85 | |
86 | - static function addTemplate($module, $lang, $template){ |
|
87 | - if($template == 'default')$template = 'basic'; |
|
86 | + static function addTemplate($module, $lang, $template) { |
|
87 | + if ($template == 'default')$template = 'basic'; |
|
88 | 88 | $templates = array(); |
89 | 89 | $fields = array(); |
90 | - if(empty($templates[$template])){ |
|
91 | - $path = 'include/SugarObjects/templates/' . $template . '/language/'.$lang.'.lang.php'; |
|
92 | - if(file_exists($path)){ |
|
90 | + if (empty($templates[$template])) { |
|
91 | + $path = 'include/SugarObjects/templates/'.$template.'/language/'.$lang.'.lang.php'; |
|
92 | + if (file_exists($path)) { |
|
93 | 93 | require($path); |
94 | 94 | $templates[$template] = $mod_strings; |
95 | - }else{ |
|
96 | - $path = 'include/SugarObjects/implements/' . $template . '/language/'.$lang.'.lang.php'; |
|
97 | - if(file_exists($path)){ |
|
95 | + } else { |
|
96 | + $path = 'include/SugarObjects/implements/'.$template.'/language/'.$lang.'.lang.php'; |
|
97 | + if (file_exists($path)) { |
|
98 | 98 | require($path); |
99 | 99 | $templates[$template] = $mod_strings; |
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
103 | - if(!empty($templates[$template])){ |
|
103 | + if (!empty($templates[$template])) { |
|
104 | 104 | return $templates[$template]; |
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
108 | - static function saveCache($module,$lang, $loaded_mod_strings, $additonal_objects= array()){ |
|
109 | - if(empty($lang)) |
|
108 | + static function saveCache($module, $lang, $loaded_mod_strings, $additonal_objects = array()) { |
|
109 | + if (empty($lang)) |
|
110 | 110 | $lang = $GLOBALS['sugar_config']['default_language']; |
111 | 111 | |
112 | - $file = create_cache_directory('modules/' . $module . '/language/'.$lang.'.lang.php'); |
|
113 | - write_array_to_file('mod_strings',$loaded_mod_strings, $file); |
|
112 | + $file = create_cache_directory('modules/'.$module.'/language/'.$lang.'.lang.php'); |
|
113 | + write_array_to_file('mod_strings', $loaded_mod_strings, $file); |
|
114 | 114 | include($file); |
115 | 115 | |
116 | 116 | // put the item in the sugar cache. |
117 | - $key = self::getLanguageCacheKey($module,$lang); |
|
118 | - sugar_cache_put($key,$loaded_mod_strings); |
|
117 | + $key = self::getLanguageCacheKey($module, $lang); |
|
118 | + sugar_cache_put($key, $loaded_mod_strings); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -124,24 +124,24 @@ discard block |
||
124 | 124 | * clear language cache for all modules. |
125 | 125 | * @param string lang the name of the object we are clearing this is for sugar_cache |
126 | 126 | */ |
127 | - static function clearLanguageCache($module_dir = '', $lang = ''){ |
|
128 | - if(empty($lang)) { |
|
127 | + static function clearLanguageCache($module_dir = '', $lang = '') { |
|
128 | + if (empty($lang)) { |
|
129 | 129 | $languages = array_keys($GLOBALS['sugar_config']['languages']); |
130 | 130 | } else { |
131 | 131 | $languages = array($lang); |
132 | 132 | } |
133 | 133 | //if we have a module name specified then just remove that language file |
134 | 134 | //otherwise go through each module and clean up the language |
135 | - if(!empty($module_dir)) { |
|
136 | - foreach($languages as $clean_lang) { |
|
135 | + if (!empty($module_dir)) { |
|
136 | + foreach ($languages as $clean_lang) { |
|
137 | 137 | LanguageManager::_clearCache($module_dir, $clean_lang); |
138 | 138 | } |
139 | 139 | } else { |
140 | 140 | $cache_dir = sugar_cached('modules/'); |
141 | - if(file_exists($cache_dir) && $dir = @opendir($cache_dir)) { |
|
142 | - while(($entry = readdir($dir)) !== false) { |
|
141 | + if (file_exists($cache_dir) && $dir = @opendir($cache_dir)) { |
|
142 | + while (($entry = readdir($dir)) !== false) { |
|
143 | 143 | if ($entry == "." || $entry == "..") continue; |
144 | - foreach($languages as $clean_lang) { |
|
144 | + foreach ($languages as $clean_lang) { |
|
145 | 145 | LanguageManager::_clearCache($entry, $clean_lang); |
146 | 146 | } |
147 | 147 | } |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | * @param string module_dir the module_dir to clear |
156 | 156 | * @param string lang the name of the language file we are clearing this is for sugar_cache |
157 | 157 | */ |
158 | - static function _clearCache($module_dir = '', $lang){ |
|
159 | - if(!empty($module_dir) && !empty($lang)){ |
|
158 | + static function _clearCache($module_dir = '', $lang) { |
|
159 | + if (!empty($module_dir) && !empty($lang)) { |
|
160 | 160 | $file = sugar_cached('modules/').$module_dir.'/language/'.$lang.'.lang.php'; |
161 | - if(file_exists($file)){ |
|
161 | + if (file_exists($file)) { |
|
162 | 162 | unlink($file); |
163 | - $key = self::getLanguageCacheKey($module_dir,$lang); |
|
163 | + $key = self::getLanguageCacheKey($module_dir, $lang); |
|
164 | 164 | sugar_cache_clear($key); |
165 | 165 | } |
166 | 166 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @param string $lang the given language we wish to load |
175 | 175 | * @param array $additional_search_paths an array which allows a consumer to pass in additional vardef locations to search |
176 | 176 | */ |
177 | - static function refreshLanguage($module, $lang, $loaded_mod_strings = array(), $additional_search_paths = null){ |
|
177 | + static function refreshLanguage($module, $lang, $loaded_mod_strings = array(), $additional_search_paths = null) { |
|
178 | 178 | // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
179 | 179 | $lang_paths = array( |
180 | 180 | 'modules/'.$module.'/language/'.$lang.'.lang.php', |
@@ -185,35 +185,35 @@ discard block |
||
185 | 185 | |
186 | 186 | #27023, if this module template language file was not attached , get the template from this module vardef cache file if exsits and load the template language files. |
187 | 187 | static $createdModules; |
188 | - if(empty($createdModules[$module]) && isset($GLOBALS['beanList'][$module])){ |
|
188 | + if (empty($createdModules[$module]) && isset($GLOBALS['beanList'][$module])) { |
|
189 | 189 | $object = $GLOBALS['beanList'][$module]; |
190 | 190 | |
191 | 191 | if ($object == 'aCase') |
192 | 192 | $object = 'Case'; |
193 | 193 | |
194 | - if(!empty($GLOBALS["dictionary"]["$object"]["templates"])){ |
|
194 | + if (!empty($GLOBALS["dictionary"]["$object"]["templates"])) { |
|
195 | 195 | $templates = $GLOBALS["dictionary"]["$object"]["templates"]; |
196 | - $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module , $templates, $lang , $loaded_mod_strings); |
|
196 | + $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module, $templates, $lang, $loaded_mod_strings); |
|
197 | 197 | $createdModules[$module] = true; |
198 | 198 | } |
199 | 199 | } |
200 | 200 | //end of fix #27023 |
201 | 201 | |
202 | 202 | // Add in additional search paths if they were provided. |
203 | - if(!empty($additional_search_paths) && is_array($additional_search_paths)) |
|
203 | + if (!empty($additional_search_paths) && is_array($additional_search_paths)) |
|
204 | 204 | { |
205 | 205 | $lang_paths = array_merge($lang_paths, $additional_search_paths); |
206 | 206 | } |
207 | 207 | |
208 | 208 | //search a predefined set of locations for the vardef files |
209 | - foreach($lang_paths as $path){ |
|
210 | - if(file_exists($path)){ |
|
209 | + foreach ($lang_paths as $path) { |
|
210 | + if (file_exists($path)) { |
|
211 | 211 | require($path); |
212 | - if(!empty($mod_strings)){ |
|
213 | - if (function_exists('sugarArrayMergeRecursive')){ |
|
212 | + if (!empty($mod_strings)) { |
|
213 | + if (function_exists('sugarArrayMergeRecursive')) { |
|
214 | 214 | $loaded_mod_strings = sugarArrayMergeRecursive($loaded_mod_strings, $mod_strings); |
215 | 215 | } |
216 | - else{ |
|
216 | + else { |
|
217 | 217 | $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $mod_strings); |
218 | 218 | } |
219 | 219 | } |
@@ -222,43 +222,43 @@ discard block |
||
222 | 222 | |
223 | 223 | //great! now that we have loaded all of our vardefs. |
224 | 224 | //let's go save them to the cache file. |
225 | - if(!empty($loaded_mod_strings)) |
|
225 | + if (!empty($loaded_mod_strings)) |
|
226 | 226 | LanguageManager::saveCache($module, $lang, $loaded_mod_strings); |
227 | 227 | } |
228 | 228 | |
229 | - static function loadModuleLanguage($module, $lang, $refresh=false){ |
|
229 | + static function loadModuleLanguage($module, $lang, $refresh = false) { |
|
230 | 230 | //here check if the cache file exists, if it does then load it, if it doesn't |
231 | 231 | //then call refreshVardef |
232 | 232 | //if either our session or the system is set to developerMode then refresh is set to true |
233 | 233 | |
234 | 234 | // Retrieve the vardefs from cache. |
235 | - $key = self::getLanguageCacheKey($module,$lang); |
|
235 | + $key = self::getLanguageCacheKey($module, $lang); |
|
236 | 236 | |
237 | - if(!$refresh) |
|
237 | + if (!$refresh) |
|
238 | 238 | { |
239 | 239 | $return_result = sugar_cache_retrieve($key); |
240 | - if(!empty($return_result) && is_array($return_result)){ |
|
240 | + if (!empty($return_result) && is_array($return_result)) { |
|
241 | 241 | return $return_result; |
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
245 | 245 | // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
246 | 246 | $cachedfile = sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'; |
247 | - if($refresh || !file_exists($cachedfile)){ |
|
247 | + if ($refresh || !file_exists($cachedfile)) { |
|
248 | 248 | LanguageManager::refreshLanguage($module, $lang); |
249 | 249 | } |
250 | 250 | |
251 | 251 | //at this point we should have the cache/modules/... file |
252 | 252 | //which was created from the refreshVardefs so let's try to load it. |
253 | - if(file_exists($cachedfile)){ |
|
253 | + if (file_exists($cachedfile)) { |
|
254 | 254 | global $mod_strings; |
255 | 255 | |
256 | 256 | require $cachedfile; |
257 | 257 | |
258 | 258 | // now that we hae loaded the data from disk, put it in the cache. |
259 | - if(!empty($mod_strings)) |
|
260 | - sugar_cache_put($key,$mod_strings); |
|
261 | - if(!empty($_SESSION['translation_mode'])){ |
|
259 | + if (!empty($mod_strings)) |
|
260 | + sugar_cache_put($key, $mod_strings); |
|
261 | + if (!empty($_SESSION['translation_mode'])) { |
|
262 | 262 | $mod_strings = array_map('translated_prefix', $mod_strings); |
263 | 263 | } |
264 | 264 | return $mod_strings; |
@@ -288,19 +288,19 @@ discard block |
||
288 | 288 | { |
289 | 289 | $jsFiles = array(); |
290 | 290 | getFiles($jsFiles, sugar_cached('jsLanguage')); |
291 | - foreach($jsFiles as $file) { |
|
291 | + foreach ($jsFiles as $file) { |
|
292 | 292 | unlink($file); |
293 | 293 | } |
294 | 294 | |
295 | - if( empty($GLOBALS['sugar_config']['js_lang_version']) ) |
|
295 | + if (empty($GLOBALS['sugar_config']['js_lang_version'])) |
|
296 | 296 | $GLOBALS['sugar_config']['js_lang_version'] = 1; |
297 | 297 | else |
298 | 298 | $GLOBALS['sugar_config']['js_lang_version'] += 1; |
299 | 299 | |
300 | - write_array_to_file( "sugar_config", $GLOBALS['sugar_config'], "config.php"); |
|
300 | + write_array_to_file("sugar_config", $GLOBALS['sugar_config'], "config.php"); |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
304 | -function translated_prefix($key){ |
|
305 | - return '[translated]' . $key; |
|
304 | +function translated_prefix($key) { |
|
305 | + return '[translated]'.$key; |
|
306 | 306 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * Vardefs management |
43 | 43 | * @api |
44 | 44 | */ |
45 | -class VardefManager{ |
|
45 | +class VardefManager { |
|
46 | 46 | static $custom_disabled_modules = array(); |
47 | 47 | static $linkFields; |
48 | 48 | |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | if (isset(VardefManager::$custom_disabled_modules[$module])) |
68 | 68 | { |
69 | 69 | $vardef_paths = array( |
70 | - 'custom/modules/' . $module . '/Ext/Vardefs/vardefs.ext.php', |
|
71 | - 'custom/Extension/modules/' . $module . '/Ext/Vardefs/vardefs.php' |
|
70 | + 'custom/modules/'.$module.'/Ext/Vardefs/vardefs.ext.php', |
|
71 | + 'custom/Extension/modules/'.$module.'/Ext/Vardefs/vardefs.php' |
|
72 | 72 | ); |
73 | 73 | |
74 | 74 | //search a predefined set of locations for the vardef files |
@@ -95,41 +95,41 @@ discard block |
||
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
98 | - static function addTemplate($module, $object, $template, $object_name=false){ |
|
99 | - if($template == 'default')$template = 'basic'; |
|
98 | + static function addTemplate($module, $object, $template, $object_name = false) { |
|
99 | + if ($template == 'default')$template = 'basic'; |
|
100 | 100 | $templates = array(); |
101 | 101 | $fields = array(); |
102 | - if(empty($object_name))$object_name = $object; |
|
102 | + if (empty($object_name))$object_name = $object; |
|
103 | 103 | $_object_name = strtolower($object_name); |
104 | - if(!empty($GLOBALS['dictionary'][$object]['table'])){ |
|
104 | + if (!empty($GLOBALS['dictionary'][$object]['table'])) { |
|
105 | 105 | $table_name = $GLOBALS['dictionary'][$object]['table']; |
106 | - }else{ |
|
106 | + } else { |
|
107 | 107 | $table_name = strtolower($module); |
108 | 108 | } |
109 | 109 | |
110 | - if(empty($templates[$template])){ |
|
111 | - $path = 'include/SugarObjects/templates/' . $template . '/vardefs.php'; |
|
112 | - if(file_exists($path)){ |
|
110 | + if (empty($templates[$template])) { |
|
111 | + $path = 'include/SugarObjects/templates/'.$template.'/vardefs.php'; |
|
112 | + if (file_exists($path)) { |
|
113 | 113 | require($path); |
114 | 114 | $templates[$template] = $vardefs; |
115 | - }else{ |
|
116 | - $path = 'include/SugarObjects/implements/' . $template . '/vardefs.php'; |
|
117 | - if(file_exists($path)){ |
|
115 | + } else { |
|
116 | + $path = 'include/SugarObjects/implements/'.$template.'/vardefs.php'; |
|
117 | + if (file_exists($path)) { |
|
118 | 118 | require($path); |
119 | 119 | $templates[$template] = $vardefs; |
120 | 120 | } |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - if(!empty($templates[$template])){ |
|
125 | - if(empty($GLOBALS['dictionary'][$object]['fields']))$GLOBALS['dictionary'][$object]['fields'] = array(); |
|
126 | - if(empty($GLOBALS['dictionary'][$object]['relationships']))$GLOBALS['dictionary'][$object]['relationships'] = array(); |
|
127 | - if(empty($GLOBALS['dictionary'][$object]['indices']))$GLOBALS['dictionary'][$object]['indices'] = array(); |
|
124 | + if (!empty($templates[$template])) { |
|
125 | + if (empty($GLOBALS['dictionary'][$object]['fields']))$GLOBALS['dictionary'][$object]['fields'] = array(); |
|
126 | + if (empty($GLOBALS['dictionary'][$object]['relationships']))$GLOBALS['dictionary'][$object]['relationships'] = array(); |
|
127 | + if (empty($GLOBALS['dictionary'][$object]['indices']))$GLOBALS['dictionary'][$object]['indices'] = array(); |
|
128 | 128 | $GLOBALS['dictionary'][$object]['fields'] = array_merge($templates[$template]['fields'], $GLOBALS['dictionary'][$object]['fields']); |
129 | - if(!empty($templates[$template]['relationships']))$GLOBALS['dictionary'][$object]['relationships'] = array_merge($templates[$template]['relationships'], $GLOBALS['dictionary'][$object]['relationships']); |
|
130 | - if(!empty($templates[$template]['indices']))$GLOBALS['dictionary'][$object]['indices'] = array_merge($templates[$template]['indices'], $GLOBALS['dictionary'][$object]['indices']); |
|
129 | + if (!empty($templates[$template]['relationships']))$GLOBALS['dictionary'][$object]['relationships'] = array_merge($templates[$template]['relationships'], $GLOBALS['dictionary'][$object]['relationships']); |
|
130 | + if (!empty($templates[$template]['indices']))$GLOBALS['dictionary'][$object]['indices'] = array_merge($templates[$template]['indices'], $GLOBALS['dictionary'][$object]['indices']); |
|
131 | 131 | // maintain a record of this objects inheritance from the SugarObject templates... |
132 | - $GLOBALS['dictionary'][$object]['templates'][ $template ] = $template ; |
|
132 | + $GLOBALS['dictionary'][$object]['templates'][$template] = $template; |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | static function cleanVardefs($fieldDefs) |
144 | 144 | { |
145 | - foreach($fieldDefs as $field => $defs) |
|
145 | + foreach ($fieldDefs as $field => $defs) |
|
146 | 146 | { |
147 | 147 | if (empty($def['name']) || empty($def['type'])) |
148 | 148 | { |
@@ -158,15 +158,15 @@ discard block |
||
158 | 158 | * @param string $module the name of the module |
159 | 159 | * @param string $object the name of the object |
160 | 160 | */ |
161 | - static function saveCache($module,$object, $additonal_objects= array()){ |
|
161 | + static function saveCache($module, $object, $additonal_objects = array()) { |
|
162 | 162 | |
163 | 163 | if (empty($GLOBALS['dictionary'][$object])) |
164 | 164 | $object = BeanFactory::getObjectName($module); |
165 | - $file = create_cache_directory('modules/' . $module . '/' . $object . 'vardefs.php'); |
|
165 | + $file = create_cache_directory('modules/'.$module.'/'.$object.'vardefs.php'); |
|
166 | 166 | |
167 | - $out="<?php \n \$GLOBALS[\"dictionary\"][\"". $object . "\"]=" . var_export($GLOBALS['dictionary'][$object], true) .";"; |
|
167 | + $out = "<?php \n \$GLOBALS[\"dictionary\"][\"".$object."\"]=".var_export($GLOBALS['dictionary'][$object], true).";"; |
|
168 | 168 | sugar_file_put_contents_atomic($file, $out); |
169 | - if ( sugar_is_file($file) && is_readable($file)) { |
|
169 | + if (sugar_is_file($file) && is_readable($file)) { |
|
170 | 170 | include($file); |
171 | 171 | } |
172 | 172 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | $key = "VardefManager.$module.$object"; |
175 | 175 | //Sometimes bad definitions can get in from left over extensions or file system lag(caching). We need to clean those. |
176 | 176 | $data = self::cleanVardefs($GLOBALS['dictionary'][$object]); |
177 | - sugar_cache_put($key,$data); |
|
177 | + sugar_cache_put($key, $data); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -184,14 +184,14 @@ discard block |
||
184 | 184 | * clear vardef cache for all modules. |
185 | 185 | * @param string object_name the name of the object we are clearing this is for sugar_cache |
186 | 186 | */ |
187 | - static function clearVardef($module_dir = '', $object_name = ''){ |
|
187 | + static function clearVardef($module_dir = '', $object_name = '') { |
|
188 | 188 | //if we have a module name specified then just remove that vardef file |
189 | 189 | //otherwise go through each module and remove the vardefs.php |
190 | - if(!empty($module_dir) && !empty($object_name)){ |
|
190 | + if (!empty($module_dir) && !empty($object_name)) { |
|
191 | 191 | VardefManager::_clearCache($module_dir, $object_name); |
192 | - }else{ |
|
192 | + } else { |
|
193 | 193 | global $beanList; |
194 | - foreach($beanList as $module_dir => $object_name){ |
|
194 | + foreach ($beanList as $module_dir => $object_name) { |
|
195 | 195 | VardefManager::_clearCache($module_dir, $object_name); |
196 | 196 | } |
197 | 197 | } |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | * @param string module_dir the module_dir to clear |
203 | 203 | * @param string object_name the name of the object we are clearing this is for sugar_cache |
204 | 204 | */ |
205 | - static function _clearCache($module_dir = '', $object_name = ''){ |
|
206 | - if(!empty($module_dir) && !empty($object_name)){ |
|
205 | + static function _clearCache($module_dir = '', $object_name = '') { |
|
206 | + if (!empty($module_dir) && !empty($object_name)) { |
|
207 | 207 | |
208 | 208 | //Some modules like cases have a bean name that doesn't match the object name |
209 | 209 | if (empty($GLOBALS['dictionary'][$object_name])) { |
@@ -211,9 +211,9 @@ discard block |
||
211 | 211 | $object_name = $newName != false ? $newName : $object_name; |
212 | 212 | } |
213 | 213 | |
214 | - $file = sugar_cached('modules/').$module_dir.'/' . $object_name . 'vardefs.php'; |
|
214 | + $file = sugar_cached('modules/').$module_dir.'/'.$object_name.'vardefs.php'; |
|
215 | 215 | |
216 | - if(file_exists($file)){ |
|
216 | + if (file_exists($file)) { |
|
217 | 217 | unlink($file); |
218 | 218 | $key = "VardefManager.$module_dir.$object_name"; |
219 | 219 | sugar_cache_clear($key); |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @param string $object the given object we wish to load the vardefs for |
230 | 230 | * @param array $additional_search_paths an array which allows a consumer to pass in additional vardef locations to search |
231 | 231 | */ |
232 | - static function refreshVardefs($module, $object, $additional_search_paths = null, $cacheCustom = true, $params = array()){ |
|
232 | + static function refreshVardefs($module, $object, $additional_search_paths = null, $cacheCustom = true, $params = array()) { |
|
233 | 233 | // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
234 | 234 | global $dictionary, $beanList; |
235 | 235 | $vardef_paths = array( |
@@ -239,20 +239,20 @@ discard block |
||
239 | 239 | ); |
240 | 240 | |
241 | 241 | // Add in additional search paths if they were provided. |
242 | - if(!empty($additional_search_paths) && is_array($additional_search_paths)) |
|
242 | + if (!empty($additional_search_paths) && is_array($additional_search_paths)) |
|
243 | 243 | { |
244 | 244 | $vardef_paths = array_merge($vardef_paths, $additional_search_paths); |
245 | 245 | } |
246 | 246 | $found = false; |
247 | 247 | //search a predefined set of locations for the vardef files |
248 | - foreach($vardef_paths as $path){ |
|
249 | - if(file_exists($path)){ |
|
248 | + foreach ($vardef_paths as $path) { |
|
249 | + if (file_exists($path)) { |
|
250 | 250 | require($path); |
251 | 251 | $found = true; |
252 | 252 | } |
253 | 253 | } |
254 | 254 | //Some modules have multiple beans, we need to see if this object has a module_dir that is different from its module_name |
255 | - if(!$found){ |
|
255 | + if (!$found) { |
|
256 | 256 | $temp = BeanFactory::newBean($module); |
257 | 257 | if ($temp) |
258 | 258 | { |
@@ -271,15 +271,15 @@ discard block |
||
271 | 271 | } |
272 | 272 | |
273 | 273 | //load custom fields into the vardef cache |
274 | - if($cacheCustom){ |
|
274 | + if ($cacheCustom) { |
|
275 | 275 | require_once("modules/DynamicFields/DynamicField.php"); |
276 | - $df = new DynamicField ($module) ; |
|
276 | + $df = new DynamicField($module); |
|
277 | 277 | $df->buildCache($module, false); |
278 | 278 | } |
279 | 279 | |
280 | 280 | //great! now that we have loaded all of our vardefs. |
281 | 281 | //let's go save them to the cache file. |
282 | - if(!empty($dictionary[$object])) { |
|
282 | + if (!empty($dictionary[$object])) { |
|
283 | 283 | VardefManager::saveCache($module, $object); |
284 | 284 | } |
285 | 285 | } |
@@ -316,10 +316,10 @@ discard block |
||
316 | 316 | |
317 | 317 | $vardef = $dictionary[$object]; |
318 | 318 | $links = array(); |
319 | - foreach($vardef['fields'] as $name => $def) |
|
319 | + foreach ($vardef['fields'] as $name => $def) |
|
320 | 320 | { |
321 | 321 | //Look through all link fields for related modules that have calculated fields that use that relationship |
322 | - if(!empty($def['type']) && $def['type'] == 'link' && !empty($def['relationship'])) |
|
322 | + if (!empty($def['type']) && $def['type'] == 'link' && !empty($def['relationship'])) |
|
323 | 323 | { |
324 | 324 | $links[$name] = $def; |
325 | 325 | } |
@@ -335,14 +335,14 @@ discard block |
||
335 | 335 | { |
336 | 336 | $cacheKey = "LFR{$module}{$object}{$relName}"; |
337 | 337 | $cacheValue = sugar_cache_retrieve($cacheKey); |
338 | - if(!empty($cacheValue)) |
|
338 | + if (!empty($cacheValue)) |
|
339 | 339 | return $cacheValue; |
340 | 340 | |
341 | 341 | $relLinkFields = self::getLinkFieldsForModule($module, $object); |
342 | 342 | $matches = array(); |
343 | 343 | if (!empty($relLinkFields)) |
344 | 344 | { |
345 | - foreach($relLinkFields as $rfName => $rfDef) |
|
345 | + foreach ($relLinkFields as $rfName => $rfDef) |
|
346 | 346 | { |
347 | 347 | if ($rfDef['relationship'] == $relName) |
348 | 348 | { |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | $results = $matches; |
360 | 360 | |
361 | 361 | sugar_cache_put($cacheKey, $results); |
362 | - return $results ; |
|
362 | + return $results; |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | |
@@ -398,22 +398,22 @@ discard block |
||
398 | 398 | * @param string $object the given object we wish to load the vardefs for |
399 | 399 | * @param bool $refresh whether or not we wish to refresh the cache file. |
400 | 400 | */ |
401 | - static function loadVardef($module, $object, $refresh=false, $params = array()){ |
|
401 | + static function loadVardef($module, $object, $refresh = false, $params = array()) { |
|
402 | 402 | //here check if the cache file exists, if it does then load it, if it doesn't |
403 | 403 | //then call refreshVardef |
404 | 404 | //if either our session or the system is set to developerMode then refresh is set to true |
405 | - if(inDeveloperMode() || !empty($_SESSION['developerMode'])){ |
|
405 | + if (inDeveloperMode() || !empty($_SESSION['developerMode'])) { |
|
406 | 406 | $refresh = true; |
407 | 407 | } |
408 | 408 | // Retrieve the vardefs from cache. |
409 | 409 | $key = "VardefManager.$module.$object"; |
410 | 410 | |
411 | - if(!$refresh) |
|
411 | + if (!$refresh) |
|
412 | 412 | { |
413 | 413 | $return_result = sugar_cache_retrieve($key); |
414 | 414 | $return_result = self::applyGlobalAccountRequirements($return_result); |
415 | 415 | |
416 | - if(!empty($return_result)) |
|
416 | + if (!empty($return_result)) |
|
417 | 417 | { |
418 | 418 | $GLOBALS['dictionary'][$object] = $return_result; |
419 | 419 | return; |
@@ -422,28 +422,28 @@ discard block |
||
422 | 422 | |
423 | 423 | // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
424 | 424 | global $dictionary; |
425 | - if(empty($GLOBALS['dictionary'][$object]) || $refresh){ |
|
425 | + if (empty($GLOBALS['dictionary'][$object]) || $refresh) { |
|
426 | 426 | //if the consumer has demanded a refresh or the cache/modules... file |
427 | 427 | //does not exist, then we should do out and try to reload things |
428 | 428 | |
429 | - $cachedfile = sugar_cached('modules/'). $module . '/' . $object . 'vardefs.php'; |
|
430 | - if($refresh || !file_exists($cachedfile)){ |
|
429 | + $cachedfile = sugar_cached('modules/').$module.'/'.$object.'vardefs.php'; |
|
430 | + if ($refresh || !file_exists($cachedfile)) { |
|
431 | 431 | VardefManager::refreshVardefs($module, $object, null, true, $params); |
432 | 432 | } |
433 | 433 | |
434 | 434 | //at this point we should have the cache/modules/... file |
435 | 435 | //which was created from the refreshVardefs so let's try to load it. |
436 | - if(file_exists($cachedfile)) |
|
436 | + if (file_exists($cachedfile)) |
|
437 | 437 | { |
438 | 438 | if (is_readable($cachedfile)) |
439 | 439 | { |
440 | 440 | include($cachedfile); |
441 | 441 | } |
442 | 442 | // now that we hae loaded the data from disk, put it in the cache. |
443 | - if(!empty($GLOBALS['dictionary'][$object])) |
|
443 | + if (!empty($GLOBALS['dictionary'][$object])) |
|
444 | 444 | { |
445 | 445 | $GLOBALS['dictionary'][$object] = self::applyGlobalAccountRequirements($GLOBALS['dictionary'][$object]); |
446 | - sugar_cache_put($key,$GLOBALS['dictionary'][$object]); |
|
446 | + sugar_cache_put($key, $GLOBALS['dictionary'][$object]); |
|
447 | 447 | } |
448 | 448 | } |
449 | 449 | } |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | ********************************************************************************/ |
39 | 39 | |
40 | 40 | $vardefs = array( |
41 | -'fields' => array ( |
|
41 | +'fields' => array( |
|
42 | 42 | 'id' => |
43 | - array ( |
|
43 | + array( |
|
44 | 44 | 'name' => 'id', |
45 | 45 | 'vname' => 'LBL_ID', |
46 | 46 | 'type' => 'id', |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | 'merge_filter' => 'selected', |
67 | 67 | ), |
68 | 68 | 'date_entered' => |
69 | - array ( |
|
69 | + array( |
|
70 | 70 | 'name' => 'date_entered', |
71 | 71 | 'vname' => 'LBL_DATE_ENTERED', |
72 | 72 | 'type' => 'datetime', |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | 'inline_edit' => false, |
78 | 78 | ), |
79 | 79 | 'date_modified' => |
80 | - array ( |
|
80 | + array( |
|
81 | 81 | 'name' => 'date_modified', |
82 | 82 | 'vname' => 'LBL_DATE_MODIFIED', |
83 | 83 | 'type' => 'datetime', |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | 'inline_edit' => false, |
89 | 89 | ), |
90 | 90 | 'modified_user_id' => |
91 | - array ( |
|
91 | + array( |
|
92 | 92 | 'name' => 'modified_user_id', |
93 | 93 | 'rname' => 'user_name', |
94 | 94 | 'id_name' => 'modified_user_id', |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | 'inline_edit' => false, |
105 | 105 | ), |
106 | 106 | 'modified_by_name' => |
107 | - array ( |
|
107 | + array( |
|
108 | 108 | 'name' => 'modified_by_name', |
109 | 109 | 'vname' => 'LBL_MODIFIED_NAME', |
110 | 110 | 'type' => 'relate', |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | 'inline_edit' => false, |
121 | 121 | ), |
122 | 122 | 'created_by' => |
123 | - array ( |
|
123 | + array( |
|
124 | 124 | 'name' => 'created_by', |
125 | 125 | 'rname' => 'user_name', |
126 | 126 | 'id_name' => 'modified_user_id', |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | 'inline_edit' => false, |
136 | 136 | ), |
137 | 137 | 'created_by_name' => |
138 | - array ( |
|
138 | + array( |
|
139 | 139 | 'name' => 'created_by_name', |
140 | 140 | 'vname' => 'LBL_CREATED', |
141 | 141 | 'type' => 'relate', |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | 'inline_edit' => false, |
153 | 153 | ), |
154 | 154 | 'description' => |
155 | - array ( |
|
155 | + array( |
|
156 | 156 | 'name' => 'description', |
157 | 157 | 'vname' => 'LBL_DESCRIPTION', |
158 | 158 | 'type' => 'text', |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | 'cols' => 80, |
162 | 162 | ), |
163 | 163 | 'deleted' => |
164 | - array ( |
|
164 | + array( |
|
165 | 165 | 'name' => 'deleted', |
166 | 166 | 'vname' => 'LBL_DELETED', |
167 | 167 | 'type' => 'bool', |
@@ -172,10 +172,10 @@ discard block |
||
172 | 172 | |
173 | 173 | /////////////////RELATIONSHIP LINKS//////////////////////////// |
174 | 174 | 'created_by_link' => |
175 | - array ( |
|
175 | + array( |
|
176 | 176 | 'name' => 'created_by_link', |
177 | 177 | 'type' => 'link', |
178 | - 'relationship' => strtolower($module) . '_created_by', |
|
178 | + 'relationship' => strtolower($module).'_created_by', |
|
179 | 179 | 'vname' => 'LBL_CREATED_USER', |
180 | 180 | 'link_type' => 'one', |
181 | 181 | 'module'=>'Users', |
@@ -183,10 +183,10 @@ discard block |
||
183 | 183 | 'source'=>'non-db', |
184 | 184 | ), |
185 | 185 | 'modified_user_link' => |
186 | - array ( |
|
186 | + array( |
|
187 | 187 | 'name' => 'modified_user_link', |
188 | 188 | 'type' => 'link', |
189 | - 'relationship' => strtolower($module). '_modified_user', |
|
189 | + 'relationship' => strtolower($module).'_modified_user', |
|
190 | 190 | 'vname' => 'LBL_MODIFIED_USER', |
191 | 191 | 'link_type' => 'one', |
192 | 192 | 'module'=>'Users', |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | ), |
196 | 196 | |
197 | 197 | ), |
198 | -'indices' => array ( |
|
198 | +'indices' => array( |
|
199 | 199 | 'id'=>array('name' =>strtolower($module).'pk', 'type' =>'primary', 'fields'=>array('id')), |
200 | 200 | ), |
201 | 201 | 'relationships'=>array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3 | 3 | /********************************************************************************* |
4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | "ReturnDatesAsStrings" => true, |
176 | 176 | "MultipleActiveResultSets" => true, |
177 | 177 | ); |
178 | - if(!empty($configOptions['db_name'])) { |
|
178 | + if (!empty($configOptions['db_name'])) { |
|
179 | 179 | $options["Database"] = $configOptions['db_name']; |
180 | 180 | } |
181 | 181 | $this->database = sqlsrv_connect($connect_param, $options); |
182 | - if(empty($this->database)) { |
|
182 | + if (empty($this->database)) { |
|
183 | 183 | $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']." as ".$configOptions['db_user_name']."."); |
184 | - if($dieOnError) { |
|
185 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
184 | + if ($dieOnError) { |
|
185 | + if (isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
186 | 186 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
187 | 187 | } else { |
188 | 188 | sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | - if($this->checkError('Could Not Connect:', $dieOnError)) |
|
195 | + if ($this->checkError('Could Not Connect:', $dieOnError)) |
|
196 | 196 | $GLOBALS['log']->info("connected to db"); |
197 | 197 | |
198 | 198 | sqlsrv_query($this->database, 'SET DATEFORMAT mdy'); |
@@ -208,26 +208,26 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
210 | 210 | { |
211 | - if(is_array($sql)) { |
|
211 | + if (is_array($sql)) { |
|
212 | 212 | return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
213 | 213 | } |
214 | 214 | $sql = $this->_appendN($sql); |
215 | 215 | |
216 | 216 | $this->countQuery($sql); |
217 | - $GLOBALS['log']->info('Query:' . $sql); |
|
217 | + $GLOBALS['log']->info('Query:'.$sql); |
|
218 | 218 | $this->checkConnection(); |
219 | 219 | $this->query_time = microtime(true); |
220 | 220 | |
221 | - $result = $suppress?@sqlsrv_query($this->database, $sql):sqlsrv_query($this->database, $sql); |
|
221 | + $result = $suppress ? @sqlsrv_query($this->database, $sql) : sqlsrv_query($this->database, $sql); |
|
222 | 222 | |
223 | 223 | $this->query_time = microtime(true) - $this->query_time; |
224 | 224 | $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
225 | 225 | |
226 | 226 | |
227 | - $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
|
227 | + $this->checkError($msg.' Query Failed:'.$sql.'::', $dieOnError); |
|
228 | 228 | |
229 | 229 | //suppress non error messages |
230 | - sqlsrv_configure('WarningsReturnAsErrors',false); |
|
230 | + sqlsrv_configure('WarningsReturnAsErrors', false); |
|
231 | 231 | |
232 | 232 | return $result; |
233 | 233 | } |
@@ -239,13 +239,13 @@ discard block |
||
239 | 239 | { |
240 | 240 | $field_array = array(); |
241 | 241 | |
242 | - if ( !$result ) { |
|
242 | + if (!$result) { |
|
243 | 243 | return false; |
244 | 244 | } |
245 | 245 | |
246 | - foreach ( sqlsrv_field_metadata($result) as $fieldMetadata ) { |
|
246 | + foreach (sqlsrv_field_metadata($result) as $fieldMetadata) { |
|
247 | 247 | $key = $fieldMetadata['Name']; |
248 | - if($make_lower_case==true) |
|
248 | + if ($make_lower_case == true) |
|
249 | 249 | $key = strtolower($key); |
250 | 250 | |
251 | 251 | $field_array[] = $key; |
@@ -261,12 +261,12 @@ discard block |
||
261 | 261 | { |
262 | 262 | if (empty($result)) return false; |
263 | 263 | |
264 | - $row = sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC); |
|
264 | + $row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC); |
|
265 | 265 | if (empty($row)) { |
266 | 266 | return false; |
267 | 267 | } |
268 | 268 | |
269 | - foreach($row as $key => $column) { |
|
269 | + foreach ($row as $key => $column) { |
|
270 | 270 | // MSSQL returns a space " " when a varchar column is empty ("") and not null. |
271 | 271 | // We need to strip empty spaces |
272 | 272 | // notice we only strip if one space is returned. we do not want to strip |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | */ |
285 | 285 | public function convert($string, $type, array $additional_parameters = array()) |
286 | 286 | { |
287 | - if ( $type == 'datetime') |
|
287 | + if ($type == 'datetime') |
|
288 | 288 | // see http://msdn.microsoft.com/en-us/library/ms187928.aspx for details |
289 | 289 | return "CONVERT(datetime,$string,120)"; |
290 | 290 | else |
@@ -300,10 +300,10 @@ discard block |
||
300 | 300 | * @param array $fielddef2 |
301 | 301 | * @return bool true if they match, false if they don't |
302 | 302 | */ |
303 | - public function compareVarDefs($fielddef1,$fielddef2, $ignoreName = false) |
|
303 | + public function compareVarDefs($fielddef1, $fielddef2, $ignoreName = false) |
|
304 | 304 | { |
305 | - if((isset($fielddef2['dbType']) && $fielddef2['dbType'] == 'id') || preg_match('/(_id$|^id$)/', $fielddef2['name'])){ |
|
306 | - if(isset($fielddef1['type']) && isset($fielddef2['type'])){ |
|
305 | + if ((isset($fielddef2['dbType']) && $fielddef2['dbType'] == 'id') || preg_match('/(_id$|^id$)/', $fielddef2['name'])) { |
|
306 | + if (isset($fielddef1['type']) && isset($fielddef2['type'])) { |
|
307 | 307 | $fielddef2['type'] = $fielddef1['type']; |
308 | 308 | } |
309 | 309 | } |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | public function disconnect() |
319 | 319 | { |
320 | 320 | $GLOBALS['log']->debug('Calling Mssql::disconnect()'); |
321 | - if(!empty($this->database)){ |
|
321 | + if (!empty($this->database)) { |
|
322 | 322 | $this->freeResult(); |
323 | 323 | sqlsrv_close($this->database); |
324 | 324 | $this->database = null; |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | */ |
331 | 331 | protected function freeDbResult($dbResult) |
332 | 332 | { |
333 | - if(!empty($dbResult)) |
|
333 | + if (!empty($dbResult)) |
|
334 | 334 | sqlsrv_free_stmt($dbResult); |
335 | 335 | } |
336 | 336 | |
@@ -342,19 +342,19 @@ discard block |
||
342 | 342 | */ |
343 | 343 | public function getConstraintSql($indices, $table) |
344 | 344 | { |
345 | - if ( $this->doesTableHaveAClusteredIndexDefined($table) ) { |
|
345 | + if ($this->doesTableHaveAClusteredIndexDefined($table)) { |
|
346 | 346 | return parent::getConstraintSql($indices, $table); |
347 | 347 | } |
348 | 348 | |
349 | 349 | // check to see if one of the passed in indices is a primary one; if so we can bail as well |
350 | - foreach ( $indices as $index ) { |
|
351 | - if ( $index['type'] == 'primary' ) { |
|
350 | + foreach ($indices as $index) { |
|
351 | + if ($index['type'] == 'primary') { |
|
352 | 352 | return parent::getConstraintSql($indices, $table); |
353 | 353 | } |
354 | 354 | } |
355 | 355 | |
356 | 356 | // Change the first index listed to be a clustered one instead ( so we have at least one for the table ) |
357 | - if ( isset($indices[0]) ) { |
|
357 | + if (isset($indices[0])) { |
|
358 | 358 | $indices[0]['type'] = 'clustered'; |
359 | 359 | } |
360 | 360 | |
@@ -370,41 +370,41 @@ discard block |
||
370 | 370 | $result = $this->query("sp_columns_90 $tablename"); |
371 | 371 | |
372 | 372 | $columns = array(); |
373 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
373 | + while (($row = $this->fetchByAssoc($result)) != null) { |
|
374 | 374 | $column_name = strtolower($row['COLUMN_NAME']); |
375 | - $columns[$column_name]['name']=$column_name; |
|
376 | - $columns[$column_name]['type']=strtolower($row['TYPE_NAME']); |
|
377 | - if ( $row['TYPE_NAME'] == 'decimal' ) { |
|
378 | - $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
379 | - $columns[$column_name]['len'].=','.strtolower($row['SCALE']); |
|
375 | + $columns[$column_name]['name'] = $column_name; |
|
376 | + $columns[$column_name]['type'] = strtolower($row['TYPE_NAME']); |
|
377 | + if ($row['TYPE_NAME'] == 'decimal') { |
|
378 | + $columns[$column_name]['len'] = strtolower($row['PRECISION']); |
|
379 | + $columns[$column_name]['len'] .= ','.strtolower($row['SCALE']); |
|
380 | 380 | } |
381 | - elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) { |
|
382 | - $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
383 | - if ( $row['TYPE_NAME'] == 'nvarchar' && $row['PRECISION'] == '0' ) { |
|
384 | - $columns[$column_name]['len']='max'; |
|
381 | + elseif (in_array($row['TYPE_NAME'], array('nchar', 'nvarchar'))) { |
|
382 | + $columns[$column_name]['len'] = strtolower($row['PRECISION']); |
|
383 | + if ($row['TYPE_NAME'] == 'nvarchar' && $row['PRECISION'] == '0') { |
|
384 | + $columns[$column_name]['len'] = 'max'; |
|
385 | 385 | } |
386 | 386 | } |
387 | - elseif ( !in_array($row['TYPE_NAME'],array('datetime','text')) ) { |
|
388 | - $columns[$column_name]['len']=strtolower($row['LENGTH']); |
|
387 | + elseif (!in_array($row['TYPE_NAME'], array('datetime', 'text'))) { |
|
388 | + $columns[$column_name]['len'] = strtolower($row['LENGTH']); |
|
389 | 389 | } |
390 | - if ( stristr($row['TYPE_NAME'],'identity') ) { |
|
390 | + if (stristr($row['TYPE_NAME'], 'identity')) { |
|
391 | 391 | $columns[$column_name]['auto_increment'] = '1'; |
392 | - $columns[$column_name]['type']=str_replace(' identity','',strtolower($row['TYPE_NAME'])); |
|
392 | + $columns[$column_name]['type'] = str_replace(' identity', '', strtolower($row['TYPE_NAME'])); |
|
393 | 393 | } |
394 | 394 | |
395 | - if (!empty($row['IS_NULLABLE']) && $row['IS_NULLABLE'] == 'NO' && (empty($row['KEY']) || !stristr($row['KEY'],'PRI'))) |
|
395 | + if (!empty($row['IS_NULLABLE']) && $row['IS_NULLABLE'] == 'NO' && (empty($row['KEY']) || !stristr($row['KEY'], 'PRI'))) |
|
396 | 396 | $columns[strtolower($row['COLUMN_NAME'])]['required'] = 'true'; |
397 | 397 | |
398 | 398 | $column_def = 1; |
399 | - if ( strtolower($tablename) == 'relationships' ) { |
|
399 | + if (strtolower($tablename) == 'relationships') { |
|
400 | 400 | $column_def = $this->getOne("select cdefault from syscolumns where id = object_id('relationships') and name = '$column_name'"); |
401 | 401 | } |
402 | - if ( $column_def != 0 && ($row['COLUMN_DEF'] != null)) { // NOTE Not using !empty as an empty string may be a viable default value. |
|
402 | + if ($column_def != 0 && ($row['COLUMN_DEF'] != null)) { // NOTE Not using !empty as an empty string may be a viable default value. |
|
403 | 403 | $matches = array(); |
404 | - $row['COLUMN_DEF'] = html_entity_decode($row['COLUMN_DEF'],ENT_QUOTES); |
|
405 | - if ( preg_match('/\([\(|\'](.*)[\)|\']\)/i',$row['COLUMN_DEF'],$matches) ) |
|
404 | + $row['COLUMN_DEF'] = html_entity_decode($row['COLUMN_DEF'], ENT_QUOTES); |
|
405 | + if (preg_match('/\([\(|\'](.*)[\)|\']\)/i', $row['COLUMN_DEF'], $matches)) |
|
406 | 406 | $columns[$column_name]['default'] = $matches[1]; |
407 | - elseif ( preg_match('/\(N\'(.*)\'\)/i',$row['COLUMN_DEF'],$matches) ) |
|
407 | + elseif (preg_match('/\(N\'(.*)\'\)/i', $row['COLUMN_DEF'], $matches)) |
|
408 | 408 | $columns[$column_name]['default'] = $matches[1]; |
409 | 409 | else |
410 | 410 | $columns[$column_name]['default'] = $row['COLUMN_DEF']; |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | EOSQL; |
431 | 431 | |
432 | 432 | $result = $this->getOne($query); |
433 | - if ( !$result ) { |
|
433 | + if (!$result) { |
|
434 | 434 | return false; |
435 | 435 | } |
436 | 436 | |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | EOSQL; |
454 | 454 | |
455 | 455 | $result = $this->getOne($query); |
456 | - if ( !$result ) { |
|
456 | + if (!$result) { |
|
457 | 457 | return false; |
458 | 458 | } |
459 | 459 | |
@@ -466,10 +466,10 @@ discard block |
||
466 | 466 | * @see DBManager::changeColumnSQL() |
467 | 467 | * @see MssqlHelper::changeColumnSQL() |
468 | 468 | */ |
469 | - protected function changeColumnSQL($tablename,$fieldDefs, $action, $ignoreRequired = false) |
|
469 | + protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
|
470 | 470 | { |
471 | 471 | $sql = ''; |
472 | - if ( $action == 'drop' && $this->doesTableHaveAFulltextIndexDefined($tablename) ) { |
|
472 | + if ($action == 'drop' && $this->doesTableHaveAFulltextIndexDefined($tablename)) { |
|
473 | 473 | $sql .= "DROP FULLTEXT INDEX ON {$tablename}"; |
474 | 474 | } |
475 | 475 | |
@@ -495,33 +495,33 @@ discard block |
||
495 | 495 | public function lastDbError() |
496 | 496 | { |
497 | 497 | $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); |
498 | - if(empty($errors)) return false; |
|
498 | + if (empty($errors)) return false; |
|
499 | 499 | global $app_strings; |
500 | 500 | if (empty($app_strings) |
501 | 501 | or !isset($app_strings['ERR_MSSQL_DB_CONTEXT']) |
502 | - or !isset($app_strings['ERR_MSSQL_WARNING']) ) { |
|
502 | + or !isset($app_strings['ERR_MSSQL_WARNING'])) { |
|
503 | 503 | //ignore the message from sql-server if $app_strings array is empty. This will happen |
504 | 504 | //only if connection if made before languge is set. |
505 | 505 | return false; |
506 | 506 | } |
507 | 507 | $messages = array(); |
508 | - foreach($errors as $error) { |
|
508 | + foreach ($errors as $error) { |
|
509 | 509 | $sqlmsg = $error['message']; |
510 | 510 | $sqlpos = strpos($sqlmsg, 'Changed database context to'); |
511 | 511 | $sqlpos2 = strpos($sqlmsg, 'Warning:'); |
512 | 512 | $sqlpos3 = strpos($sqlmsg, 'Checking identity information:'); |
513 | - if ( $sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false ) { |
|
513 | + if ($sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false) { |
|
514 | 514 | continue; |
515 | 515 | } |
516 | 516 | $sqlpos = strpos($sqlmsg, $app_strings['ERR_MSSQL_DB_CONTEXT']); |
517 | 517 | $sqlpos2 = strpos($sqlmsg, $app_strings['ERR_MSSQL_WARNING']); |
518 | - if ( $sqlpos !== false || $sqlpos2 !== false) { |
|
518 | + if ($sqlpos !== false || $sqlpos2 !== false) { |
|
519 | 519 | continue; |
520 | 520 | } |
521 | 521 | $messages[] = $sqlmsg; |
522 | 522 | } |
523 | 523 | |
524 | - if(!empty($messages)) { |
|
524 | + if (!empty($messages)) { |
|
525 | 525 | return join("\n", $messages); |
526 | 526 | } |
527 | 527 | return false; |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | protected function verifyGenericQueryRollback($type, $table, $query) |
549 | 549 | { |
550 | 550 | $this->log->debug("verifying $type statement"); |
551 | - if(!sqlsrv_begin_transaction($this->database)) { |
|
551 | + if (!sqlsrv_begin_transaction($this->database)) { |
|
552 | 552 | return "Failed to create transaction"; |
553 | 553 | } |
554 | 554 | $this->query($query, false); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3 | 3 | /********************************************************************************* |
4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -175,11 +175,11 @@ discard block |
||
175 | 175 | ini_set('mssql.datetimeconvert', '0'); |
176 | 176 | |
177 | 177 | //set the text size and textlimit to max number so that blob columns are not truncated |
178 | - ini_set('mssql.textlimit','2147483647'); |
|
179 | - ini_set('mssql.textsize','2147483647'); |
|
180 | - ini_set('mssql.charset','UTF-8'); |
|
178 | + ini_set('mssql.textlimit', '2147483647'); |
|
179 | + ini_set('mssql.textsize', '2147483647'); |
|
180 | + ini_set('mssql.charset', 'UTF-8'); |
|
181 | 181 | |
182 | - if(!empty($configOptions['db_host_instance'])) { |
|
182 | + if (!empty($configOptions['db_host_instance'])) { |
|
183 | 183 | $configOptions['db_host_instance'] = trim($configOptions['db_host_instance']); |
184 | 184 | } |
185 | 185 | //set the connections parameters |
@@ -191,37 +191,37 @@ discard block |
||
191 | 191 | |
192 | 192 | //create persistent connection |
193 | 193 | if ($this->getOption('persistent')) { |
194 | - $this->database =@mssql_pconnect( |
|
195 | - $connect_param , |
|
194 | + $this->database = @mssql_pconnect( |
|
195 | + $connect_param, |
|
196 | 196 | $configOptions['db_user_name'], |
197 | 197 | $configOptions['db_password'] |
198 | 198 | ); |
199 | 199 | } |
200 | 200 | //if no persistent connection created, then create regular connection |
201 | - if(!$this->database){ |
|
201 | + if (!$this->database) { |
|
202 | 202 | $this->database = mssql_connect( |
203 | - $connect_param , |
|
203 | + $connect_param, |
|
204 | 204 | $configOptions['db_user_name'], |
205 | 205 | $configOptions['db_password'] |
206 | 206 | ); |
207 | - if(!$this->database){ |
|
207 | + if (!$this->database) { |
|
208 | 208 | $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']. |
209 | 209 | " as ".$configOptions['db_user_name']."."); |
210 | - if($dieOnError) { |
|
210 | + if ($dieOnError) { |
|
211 | 211 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
212 | 212 | } else { |
213 | 213 | return false; |
214 | 214 | } |
215 | 215 | } |
216 | - if($this->database && $this->getOption('persistent')){ |
|
216 | + if ($this->database && $this->getOption('persistent')) { |
|
217 | 217 | $_SESSION['administrator_error'] = "<B>Severe Performance Degradation: Persistent Database Connections " |
218 | 218 | . "not working. Please set \$sugar_config['dbconfigoption']['persistent'] to false in your " |
219 | 219 | . "config.php file</B>"; |
220 | 220 | } |
221 | 221 | } |
222 | 222 | //make sure connection exists |
223 | - if(!$this->database) { |
|
224 | - if($dieOnError) { |
|
223 | + if (!$this->database) { |
|
224 | + if ($dieOnError) { |
|
225 | 225 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
226 | 226 | } else { |
227 | 227 | return false; |
@@ -235,19 +235,19 @@ discard block |
||
235 | 235 | //mssql db maximum number of 5 times at the interval of .2 second. If can not connect |
236 | 236 | //it will throw an Unable to select database message. |
237 | 237 | |
238 | - if(!empty($configOptions['db_name']) && !@mssql_select_db($configOptions['db_name'], $this->database)){ |
|
238 | + if (!empty($configOptions['db_name']) && !@mssql_select_db($configOptions['db_name'], $this->database)) { |
|
239 | 239 | $connected = false; |
240 | - for($i=0;$i<5;$i++){ |
|
240 | + for ($i = 0; $i < 5; $i++) { |
|
241 | 241 | usleep(200000); |
242 | - if(@mssql_select_db($configOptions['db_name'], $this->database)){ |
|
242 | + if (@mssql_select_db($configOptions['db_name'], $this->database)) { |
|
243 | 243 | $connected = true; |
244 | 244 | break; |
245 | 245 | } |
246 | 246 | } |
247 | - if(!$connected){ |
|
248 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}"); |
|
249 | - if($dieOnError) { |
|
250 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
247 | + if (!$connected) { |
|
248 | + $GLOBALS['log']->fatal("Unable to select database {$configOptions['db_name']}"); |
|
249 | + if ($dieOnError) { |
|
250 | + if (isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
251 | 251 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
252 | 252 | } else { |
253 | 253 | sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | } |
259 | 259 | } |
260 | 260 | |
261 | - if(!$this->checkError('Could Not Connect', $dieOnError)) |
|
261 | + if (!$this->checkError('Could Not Connect', $dieOnError)) |
|
262 | 262 | $GLOBALS['log']->info("connected to db"); |
263 | 263 | |
264 | 264 | $this->connectOptions = $configOptions; |
@@ -280,16 +280,16 @@ discard block |
||
280 | 280 | */ |
281 | 281 | public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
282 | 282 | { |
283 | - if(is_array($sql)) { |
|
283 | + if (is_array($sql)) { |
|
284 | 284 | return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
285 | 285 | } |
286 | 286 | // Flag if there are odd number of single quotes |
287 | 287 | if ((substr_count($sql, "'") & 1)) |
288 | - $GLOBALS['log']->error("SQL statement[" . $sql . "] has odd number of single quotes."); |
|
288 | + $GLOBALS['log']->error("SQL statement[".$sql."] has odd number of single quotes."); |
|
289 | 289 | |
290 | 290 | $sql = $this->_appendN($sql); |
291 | 291 | |
292 | - $GLOBALS['log']->info('Query:' . $sql); |
|
292 | + $GLOBALS['log']->info('Query:'.$sql); |
|
293 | 293 | $this->checkConnection(); |
294 | 294 | $this->countQuery($sql); |
295 | 295 | $this->query_time = microtime(true); |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | // Bug 34892 - Clear out previous error message by checking the @@ERROR global variable |
298 | 298 | @mssql_query("SELECT @@ERROR", $this->database); |
299 | 299 | |
300 | - $result = $suppress?@mssql_query($sql, $this->database):mssql_query($sql, $this->database); |
|
300 | + $result = $suppress ? @mssql_query($sql, $this->database) : mssql_query($sql, $this->database); |
|
301 | 301 | |
302 | 302 | if (!$result) { |
303 | 303 | // awu Bug 10657: ignoring mssql error message 'Changed database context to' - an intermittent |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | $sqlpos3 = strpos($sqlmsg, 'Checking identity information:'); |
310 | 310 | |
311 | 311 | if ($sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false) // if sqlmsg has 'Changed database context to', just log it |
312 | - $GLOBALS['log']->debug($sqlmsg . ": " . $sql ); |
|
312 | + $GLOBALS['log']->debug($sqlmsg.": ".$sql); |
|
313 | 313 | else { |
314 | - $GLOBALS['log']->fatal($sqlmsg . ": " . $sql ); |
|
315 | - if($dieOnError) |
|
316 | - sugar_die('SQL Error : ' . $sqlmsg); |
|
314 | + $GLOBALS['log']->fatal($sqlmsg.": ".$sql); |
|
315 | + if ($dieOnError) |
|
316 | + sugar_die('SQL Error : '.$sqlmsg); |
|
317 | 317 | else |
318 | - echo 'SQL Error : ' . $sqlmsg; |
|
318 | + echo 'SQL Error : '.$sqlmsg; |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
324 | 324 | |
325 | 325 | |
326 | - $this->checkError($msg.' Query Failed: ' . $sql, $dieOnError); |
|
326 | + $this->checkError($msg.' Query Failed: '.$sql, $dieOnError); |
|
327 | 327 | |
328 | 328 | return $result; |
329 | 329 | } |
@@ -341,14 +341,14 @@ discard block |
||
341 | 341 | { |
342 | 342 | //set the start to 0, no negs |
343 | 343 | if ($start < 0) |
344 | - $start=0; |
|
344 | + $start = 0; |
|
345 | 345 | |
346 | - $GLOBALS['log']->debug(print_r(func_get_args(),true)); |
|
346 | + $GLOBALS['log']->debug(print_r(func_get_args(), true)); |
|
347 | 347 | |
348 | 348 | $this->lastsql = $sql; |
349 | 349 | |
350 | 350 | //change the casing to lower for easier string comparison, and trim whitespaces |
351 | - $sql = strtolower(trim($sql)) ; |
|
351 | + $sql = strtolower(trim($sql)); |
|
352 | 352 | |
353 | 353 | //set default sql |
354 | 354 | $limitUnionSQL = $sql; |
@@ -364,16 +364,16 @@ discard block |
||
364 | 364 | $arr_count = 0; |
365 | 365 | |
366 | 366 | //process if there are elements |
367 | - if ($unionOrderByCount){ |
|
367 | + if ($unionOrderByCount) { |
|
368 | 368 | //we really want the last order by, so reconstruct string |
369 | 369 | //adding a 1 to count, as we dont wish to process the last element |
370 | 370 | $unionsql = ''; |
371 | - while ($unionOrderByCount>$arr_count+1) { |
|
371 | + while ($unionOrderByCount > $arr_count + 1) { |
|
372 | 372 | $unionsql .= $orderByArray[$arr_count]; |
373 | - $arr_count = $arr_count+1; |
|
373 | + $arr_count = $arr_count + 1; |
|
374 | 374 | //add an "order by" string back if we are coming into loop again |
375 | 375 | //remember they were taken out when array was created |
376 | - if ($unionOrderByCount>$arr_count+1) { |
|
376 | + if ($unionOrderByCount > $arr_count + 1) { |
|
377 | 377 | $unionsql .= "order by"; |
378 | 378 | } |
379 | 379 | } |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | //so we do not want to strip the alias like in other queries. Just add the "order by" string and |
404 | 404 | //pass column name as is |
405 | 405 | if ($unionOrderBy != '') { |
406 | - $unionOrderBy = ' order by ' . $unionOrderBy; |
|
406 | + $unionOrderBy = ' order by '.$unionOrderBy; |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | //Bug 56560, use top query in conjunction with rownumber() function |
@@ -412,13 +412,13 @@ discard block |
||
412 | 412 | //If not for paging, no need to use rownumber() function |
413 | 413 | if ($count == 1 && $start == 0) |
414 | 414 | { |
415 | - $limitUnionSQL = "SELECT TOP $count * FROM (" .$unionsql .") as top_count ".$unionOrderBy; |
|
415 | + $limitUnionSQL = "SELECT TOP $count * FROM (".$unionsql.") as top_count ".$unionOrderBy; |
|
416 | 416 | } |
417 | 417 | else |
418 | 418 | { |
419 | 419 | $limitUnionSQL = "SELECT TOP $count * FROM( select ROW_NUMBER() OVER ( order by " |
420 | 420 | .$rowNumOrderBy.") AS row_number, * FROM (" |
421 | - .$unionsql .") As numbered) " |
|
421 | + .$unionsql.") As numbered) " |
|
422 | 422 | . "As top_count_limit WHERE row_number > $start " |
423 | 423 | .$unionOrderBy; |
424 | 424 | } |
@@ -437,64 +437,64 @@ discard block |
||
437 | 437 | $newSQL = $sql; |
438 | 438 | $distinctSQLARRAY = array(); |
439 | 439 | if (strpos($sql, "UNION") && !preg_match("/(')(UNION).?(')/i", $sql)) |
440 | - $newSQL = $this->handleUnionLimitQuery($sql,$start,$count); |
|
440 | + $newSQL = $this->handleUnionLimitQuery($sql, $start, $count); |
|
441 | 441 | else { |
442 | 442 | if ($start < 0) |
443 | 443 | $start = 0; |
444 | - $GLOBALS['log']->debug(print_r(func_get_args(),true)); |
|
444 | + $GLOBALS['log']->debug(print_r(func_get_args(), true)); |
|
445 | 445 | $this->lastsql = $sql; |
446 | 446 | $matches = array(); |
447 | - preg_match('/^(.*SELECT\b)(.*?\bFROM\b.*\bWHERE\b)(.*)$/isU',$sql, $matches); |
|
447 | + preg_match('/^(.*SELECT\b)(.*?\bFROM\b.*\bWHERE\b)(.*)$/isU', $sql, $matches); |
|
448 | 448 | if (!empty($matches[3])) { |
449 | 449 | if ($start == 0) { |
450 | 450 | $match_two = strtolower($matches[2]); |
451 | - if (!strpos($match_two, "distinct")> 0 && strpos($match_two, "distinct") !==0) { |
|
451 | + if (!strpos($match_two, "distinct") > 0 && strpos($match_two, "distinct") !== 0) { |
|
452 | 452 | $orderByMatch = array(); |
453 | - preg_match('/^(.*)(\bORDER BY\b)(.*)$/is',$matches[3], $orderByMatch); |
|
453 | + preg_match('/^(.*)(\bORDER BY\b)(.*)$/is', $matches[3], $orderByMatch); |
|
454 | 454 | if (!empty($orderByMatch[3])) { |
455 | 455 | $selectPart = array(); |
456 | 456 | preg_match('/^(.*)(\bFROM\b.*)$/isU', $matches[2], $selectPart); |
457 | 457 | $newSQL = "SELECT TOP $count * FROM |
458 | 458 | ( |
459 | - " . $matches[1] . $selectPart[1] . ", ROW_NUMBER() |
|
460 | - OVER (ORDER BY " . $this->returnOrderBy($sql, $orderByMatch[3]) . ") AS row_number |
|
461 | - " . $selectPart[2] . $orderByMatch[1]. " |
|
459 | + ".$matches[1].$selectPart[1].", ROW_NUMBER() |
|
460 | + OVER (ORDER BY " . $this->returnOrderBy($sql, $orderByMatch[3]).") AS row_number |
|
461 | + " . $selectPart[2].$orderByMatch[1]." |
|
462 | 462 | ) AS a |
463 | 463 | WHERE row_number > $start"; |
464 | 464 | } |
465 | 465 | else { |
466 | - $newSQL = $matches[1] . " TOP $count " . $matches[2] . $matches[3]; |
|
466 | + $newSQL = $matches[1]." TOP $count ".$matches[2].$matches[3]; |
|
467 | 467 | } |
468 | 468 | } |
469 | 469 | else { |
470 | 470 | $distinct_o = strpos($match_two, "distinct"); |
471 | 471 | $up_to_distinct_str = substr($match_two, 0, $distinct_o); |
472 | 472 | //check to see if the distinct is within a function, if so, then proceed as normal |
473 | - if (strpos($up_to_distinct_str,"(")) { |
|
473 | + if (strpos($up_to_distinct_str, "(")) { |
|
474 | 474 | //proceed as normal |
475 | - $newSQL = $matches[1] . " TOP $count " . $matches[2] . $matches[3]; |
|
475 | + $newSQL = $matches[1]." TOP $count ".$matches[2].$matches[3]; |
|
476 | 476 | } |
477 | 477 | else { |
478 | 478 | //if distinct is not within a function, then parse |
479 | 479 | //string contains distinct clause, "TOP needs to come after Distinct" |
480 | 480 | //get position of distinct |
481 | 481 | $match_zero = strtolower($matches[0]); |
482 | - $distinct_pos = strpos($match_zero , "distinct"); |
|
482 | + $distinct_pos = strpos($match_zero, "distinct"); |
|
483 | 483 | //get position of where |
484 | 484 | $where_pos = strpos($match_zero, "where"); |
485 | 485 | //parse through string |
486 | - $beg = substr($matches[0], 0, $distinct_pos+9 ); |
|
487 | - $mid = substr($matches[0], strlen($beg), ($where_pos+5) - (strlen($beg))); |
|
488 | - $end = substr($matches[0], strlen($beg) + strlen($mid) ); |
|
486 | + $beg = substr($matches[0], 0, $distinct_pos + 9); |
|
487 | + $mid = substr($matches[0], strlen($beg), ($where_pos + 5) - (strlen($beg))); |
|
488 | + $end = substr($matches[0], strlen($beg) + strlen($mid)); |
|
489 | 489 | //repopulate matches array |
490 | 490 | $matches[1] = $beg; $matches[2] = $mid; $matches[3] = $end; |
491 | 491 | |
492 | - $newSQL = $matches[1] . " TOP $count " . $matches[2] . $matches[3]; |
|
492 | + $newSQL = $matches[1]." TOP $count ".$matches[2].$matches[3]; |
|
493 | 493 | } |
494 | 494 | } |
495 | 495 | } else { |
496 | 496 | $orderByMatch = array(); |
497 | - preg_match('/^(.*)(\bORDER BY\b)(.*)$/is',$matches[3], $orderByMatch); |
|
497 | + preg_match('/^(.*)(\bORDER BY\b)(.*)$/is', $matches[3], $orderByMatch); |
|
498 | 498 | |
499 | 499 | //if there is a distinct clause, parse sql string as we will have to insert the rownumber |
500 | 500 | //for paging, AFTER the distinct clause |
@@ -512,8 +512,8 @@ discard block |
||
512 | 512 | |
513 | 513 | //take out the select and distinct from string so we can reuse in group by |
514 | 514 | $dist_str = 'distinct'; |
515 | - preg_match('/\b' . $dist_str . '\b/simU', $matches_sql, $matchesPartSQL, PREG_OFFSET_CAPTURE); |
|
516 | - $matches_sql = trim(substr($matches_sql,$matchesPartSQL[0][1] + strlen($dist_str))); |
|
515 | + preg_match('/\b'.$dist_str.'\b/simU', $matches_sql, $matchesPartSQL, PREG_OFFSET_CAPTURE); |
|
516 | + $matches_sql = trim(substr($matches_sql, $matchesPartSQL[0][1] + strlen($dist_str))); |
|
517 | 517 | //get the position of where and from for further processing |
518 | 518 | preg_match('/\bfrom\b/simU', $matches_sql, $matchesPartSQL, PREG_OFFSET_CAPTURE); |
519 | 519 | $from_pos = $matchesPartSQL[0][1]; |
@@ -521,17 +521,17 @@ discard block |
||
521 | 521 | $where_pos = $matchesPartSQL[0][1]; |
522 | 522 | //split the sql into a string before and after the from clause |
523 | 523 | //we will use the columns being selected to construct the group by clause |
524 | - if ($from_pos>0 ) { |
|
524 | + if ($from_pos > 0) { |
|
525 | 525 | $distinctSQLARRAY[0] = substr($matches_sql, 0, $from_pos); |
526 | 526 | $distinctSQLARRAY[1] = substr($matches_sql, $from_pos); |
527 | 527 | //get position of order by (if it exists) so we can strip it from the string |
528 | 528 | $ob_pos = strpos($distinctSQLARRAY[1], "order by"); |
529 | 529 | if ($ob_pos) { |
530 | - $distinctSQLARRAY[1] = substr($distinctSQLARRAY[1],0,$ob_pos); |
|
530 | + $distinctSQLARRAY[1] = substr($distinctSQLARRAY[1], 0, $ob_pos); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | // strip off last closing parentheses from the where clause |
534 | - $distinctSQLARRAY[1] = preg_replace('/\)\s$/',' ',$distinctSQLARRAY[1]); |
|
534 | + $distinctSQLARRAY[1] = preg_replace('/\)\s$/', ' ', $distinctSQLARRAY[1]); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | $grpByStr = array(); |
@@ -550,30 +550,30 @@ discard block |
||
550 | 550 | $newSQL = "SELECT TOP $count * FROM |
551 | 551 | ( |
552 | 552 | SELECT ROW_NUMBER() |
553 | - OVER (ORDER BY " . preg_replace('/^' . $dist_str . '\s+/', '', $this->returnOrderBy($sql, $orderByMatch[3])) . ") AS row_number, |
|
554 | - count(*) counter, " . $distinctSQLARRAY[0] . " |
|
555 | - " . $distinctSQLARRAY[1] . " |
|
556 | - group by " . $grpByStr . " |
|
553 | + OVER (ORDER BY ".preg_replace('/^'.$dist_str.'\s+/', '', $this->returnOrderBy($sql, $orderByMatch[3])).") AS row_number, |
|
554 | + count(*) counter, " . $distinctSQLARRAY[0]." |
|
555 | + " . $distinctSQLARRAY[1]." |
|
556 | + group by " . $grpByStr." |
|
557 | 557 | ) AS a |
558 | 558 | WHERE row_number > $start"; |
559 | 559 | } |
560 | 560 | else { |
561 | 561 | $newSQL = "SELECT TOP $count * FROM |
562 | 562 | ( |
563 | - " . $matches[1] . " ROW_NUMBER() |
|
564 | - OVER (ORDER BY " . $this->returnOrderBy($sql, $orderByMatch[3]) . ") AS row_number, |
|
565 | - " . $matches[2] . $orderByMatch[1]. " |
|
563 | + ".$matches[1]." ROW_NUMBER() |
|
564 | + OVER (ORDER BY " . $this->returnOrderBy($sql, $orderByMatch[3]).") AS row_number, |
|
565 | + " . $matches[2].$orderByMatch[1]." |
|
566 | 566 | ) AS a |
567 | 567 | WHERE row_number > $start"; |
568 | 568 | } |
569 | - }else{ |
|
569 | + } else { |
|
570 | 570 | //if there is a distinct clause, form query with rownumber after distinct |
571 | 571 | if ($hasDistinct) { |
572 | 572 | $newSQL = "SELECT TOP $count * FROM |
573 | 573 | ( |
574 | - SELECT ROW_NUMBER() OVER (ORDER BY ".$grpByStr.") AS row_number, count(*) counter, " . $distinctSQLARRAY[0] . " |
|
575 | - " . $distinctSQLARRAY[1] . " |
|
576 | - group by " . $grpByStr . " |
|
574 | + SELECT ROW_NUMBER() OVER (ORDER BY ".$grpByStr.") AS row_number, count(*) counter, ".$distinctSQLARRAY[0]." |
|
575 | + " . $distinctSQLARRAY[1]." |
|
576 | + group by " . $grpByStr." |
|
577 | 577 | ) |
578 | 578 | AS a |
579 | 579 | WHERE row_number > $start"; |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | else { |
582 | 582 | $newSQL = "SELECT TOP $count * FROM |
583 | 583 | ( |
584 | - " . $matches[1] . " ROW_NUMBER() OVER (ORDER BY " . $sqlArray['FROM'][0]['alias'] . ".id) AS row_number, " . $matches[2] . $matches[3]. " |
|
584 | + ".$matches[1]." ROW_NUMBER() OVER (ORDER BY ".$sqlArray['FROM'][0]['alias'].".id) AS row_number, ".$matches[2].$matches[3]." |
|
585 | 585 | ) |
586 | 586 | AS a |
587 | 587 | WHERE row_number > $start"; |
@@ -591,9 +591,9 @@ discard block |
||
591 | 591 | } |
592 | 592 | } |
593 | 593 | |
594 | - $GLOBALS['log']->debug('Limit Query: ' . $newSQL); |
|
595 | - if($execute) { |
|
596 | - $result = $this->query($newSQL, $dieOnError, $msg); |
|
594 | + $GLOBALS['log']->debug('Limit Query: '.$newSQL); |
|
595 | + if ($execute) { |
|
596 | + $result = $this->query($newSQL, $dieOnError, $msg); |
|
597 | 597 | $this->dump_slow_queries($newSQL); |
598 | 598 | return $result; |
599 | 599 | } else { |
@@ -615,15 +615,15 @@ discard block |
||
615 | 615 | private function removePatternFromSQL($p_sql, $strip_beg, $strip_end, $patt = 'patt') |
616 | 616 | { |
617 | 617 | //strip all single quotes out |
618 | - $count = substr_count ( $p_sql, $strip_beg); |
|
618 | + $count = substr_count($p_sql, $strip_beg); |
|
619 | 619 | $increment = 1; |
620 | 620 | if ($strip_beg != $strip_end) |
621 | 621 | $increment = 2; |
622 | 622 | |
623 | - $i=0; |
|
623 | + $i = 0; |
|
624 | 624 | $offset = 0; |
625 | 625 | $strip_array = array(); |
626 | - while ($i<$count && $offset<strlen($p_sql)) { |
|
626 | + while ($i < $count && $offset < strlen($p_sql)) { |
|
627 | 627 | if ($offset > strlen($p_sql)) |
628 | 628 | { |
629 | 629 | break; |
@@ -634,22 +634,22 @@ discard block |
||
634 | 634 | { |
635 | 635 | break; |
636 | 636 | } |
637 | - $sec_sin = strpos($p_sql, $strip_end, $beg_sin+1); |
|
638 | - $strip_array[$patt.$i] = substr($p_sql, $beg_sin, $sec_sin - $beg_sin +1); |
|
637 | + $sec_sin = strpos($p_sql, $strip_end, $beg_sin + 1); |
|
638 | + $strip_array[$patt.$i] = substr($p_sql, $beg_sin, $sec_sin - $beg_sin + 1); |
|
639 | 639 | if ($increment > 1) { |
640 | 640 | //we are in here because beginning and end patterns are not identical, so search for nesting |
641 | - $exists = strpos($strip_array[$patt.$i], $strip_beg ); |
|
642 | - if ($exists>=0) { |
|
643 | - $nested_pos = (strrpos($strip_array[$patt.$i], $strip_beg )); |
|
644 | - $strip_array[$patt.$i] = substr($p_sql,$nested_pos+$beg_sin,$sec_sin - ($nested_pos+$beg_sin)+1); |
|
645 | - $p_sql = substr($p_sql, 0, $nested_pos+$beg_sin) . " ##". $patt.$i."## " . substr($p_sql, $sec_sin+1); |
|
641 | + $exists = strpos($strip_array[$patt.$i], $strip_beg); |
|
642 | + if ($exists >= 0) { |
|
643 | + $nested_pos = (strrpos($strip_array[$patt.$i], $strip_beg)); |
|
644 | + $strip_array[$patt.$i] = substr($p_sql, $nested_pos + $beg_sin, $sec_sin - ($nested_pos + $beg_sin) + 1); |
|
645 | + $p_sql = substr($p_sql, 0, $nested_pos + $beg_sin)." ##".$patt.$i."## ".substr($p_sql, $sec_sin + 1); |
|
646 | 646 | $i = $i + 1; |
647 | 647 | continue; |
648 | 648 | } |
649 | 649 | } |
650 | - $p_sql = substr($p_sql, 0, $beg_sin) . " ##". $patt.$i."## " . substr($p_sql, $sec_sin+1); |
|
650 | + $p_sql = substr($p_sql, 0, $beg_sin)." ##".$patt.$i."## ".substr($p_sql, $sec_sin + 1); |
|
651 | 651 | //move the marker up |
652 | - $offset = $sec_sin+1; |
|
652 | + $offset = $sec_sin + 1; |
|
653 | 653 | |
654 | 654 | $i = $i + 1; |
655 | 655 | } |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | $pattern_array = array_reverse($pattern_array); |
672 | 672 | |
673 | 673 | foreach ($pattern_array as $key => $replace) { |
674 | - $token = str_replace( " ##".$key."## ", $replace,$token); |
|
674 | + $token = str_replace(" ##".$key."## ", $replace, $token); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | return $token; |
@@ -687,11 +687,11 @@ discard block |
||
687 | 687 | private function getAliasFromSQL($sql, $alias) |
688 | 688 | { |
689 | 689 | $matches = array(); |
690 | - preg_match('/^(.*SELECT)(.*?FROM.*WHERE)(.*)$/isU',$sql, $matches); |
|
690 | + preg_match('/^(.*SELECT)(.*?FROM.*WHERE)(.*)$/isU', $sql, $matches); |
|
691 | 691 | //parse all single and double quotes out of array |
692 | - $sin_array = $this->removePatternFromSQL($matches[2], "'", "'","sin_"); |
|
692 | + $sin_array = $this->removePatternFromSQL($matches[2], "'", "'", "sin_"); |
|
693 | 693 | $new_sql = array_pop($sin_array); |
694 | - $dub_array = $this->removePatternFromSQL($new_sql, "\"", "\"","dub_"); |
|
694 | + $dub_array = $this->removePatternFromSQL($new_sql, "\"", "\"", "dub_"); |
|
695 | 695 | $new_sql = array_pop($dub_array); |
696 | 696 | |
697 | 697 | //search for parenthesis |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | |
701 | 701 | //all functions should be removed now, so split the array on commas |
702 | 702 | $mstr_sql_array = explode(",", $new_sql); |
703 | - foreach($mstr_sql_array as $token ) { |
|
703 | + foreach ($mstr_sql_array as $token) { |
|
704 | 704 | if (strpos($token, $alias)) { |
705 | 705 | //found token, add back comments |
706 | 706 | $token = $this->addPatternToSQL($token, $paren_array); |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | $found = $found_in_sql; |
739 | 739 | |
740 | 740 | //if still no match found, then we need to parse through the string |
741 | - if (!$found_in_sql){ |
|
741 | + if (!$found_in_sql) { |
|
742 | 742 | //get count of how many times the match exists in string |
743 | 743 | $found_count = substr_count($sql, $orderMatch); |
744 | 744 | $i = 0; |
@@ -747,21 +747,21 @@ discard block |
||
747 | 747 | //loop through string as many times as there is a match |
748 | 748 | while ($found_count > $i) { |
749 | 749 | //get the first match |
750 | - $found_in_sql = strpos($sql, $orderMatch,$first_); |
|
750 | + $found_in_sql = strpos($sql, $orderMatch, $first_); |
|
751 | 751 | //make sure there was a match |
752 | - if($found_in_sql){ |
|
752 | + if ($found_in_sql) { |
|
753 | 753 | //grab the next 2 individual characters |
754 | - $str_plusone = substr($sql,$found_in_sql + $len,1); |
|
755 | - $str_plustwo = substr($sql,$found_in_sql + $len+1,1); |
|
754 | + $str_plusone = substr($sql, $found_in_sql + $len, 1); |
|
755 | + $str_plustwo = substr($sql, $found_in_sql + $len + 1, 1); |
|
756 | 756 | //if one of those characters is a comma, then we have our alias |
757 | - if ($str_plusone === "," || $str_plustwo === ","){ |
|
757 | + if ($str_plusone === "," || $str_plustwo === ",") { |
|
758 | 758 | //keep track of this position |
759 | 759 | $found = $found_in_sql; |
760 | 760 | } |
761 | 761 | } |
762 | 762 | //set the offset and increase the iteration counter |
763 | - $first_ = $found_in_sql+$len; |
|
764 | - $i = $i+1; |
|
763 | + $first_ = $found_in_sql + $len; |
|
764 | + $i = $i + 1; |
|
765 | 765 | } |
766 | 766 | } |
767 | 767 | //return $found, defaults have been set, so if no match was found it will be a negative number |
@@ -793,8 +793,8 @@ discard block |
||
793 | 793 | $firstSpace = strpos($orig_order_match, " "); |
794 | 794 | |
795 | 795 | //split order by into column name and ascending/descending |
796 | - $orderMatch = " " . strtolower(substr($orig_order_match, 0, $firstSpace)); |
|
797 | - $asc_desc = trim(substr($orig_order_match,$firstSpace)); |
|
796 | + $orderMatch = " ".strtolower(substr($orig_order_match, 0, $firstSpace)); |
|
797 | + $asc_desc = trim(substr($orig_order_match, $firstSpace)); |
|
798 | 798 | |
799 | 799 | //look for column name as an alias in sql string |
800 | 800 | $found_in_sql = $this->findColumnByAlias($sql, $orderMatch); |
@@ -805,18 +805,18 @@ discard block |
||
805 | 805 | $colMatchPos = strpos($sql, $orderMatch); |
806 | 806 | if ($colMatchPos !== false) { |
807 | 807 | //grab sub string up to column name |
808 | - $containsColStr = substr($sql,0, $colMatchPos); |
|
808 | + $containsColStr = substr($sql, 0, $colMatchPos); |
|
809 | 809 | //get position of first space, so we can grab table name |
810 | 810 | $lastSpacePos = strrpos($containsColStr, " "); |
811 | 811 | //use positions of column name, space before name, and length of column to find the correct column name |
812 | - $col_name = substr($sql, $lastSpacePos, $colMatchPos-$lastSpacePos+strlen($orderMatch)); |
|
812 | + $col_name = substr($sql, $lastSpacePos, $colMatchPos - $lastSpacePos + strlen($orderMatch)); |
|
813 | 813 | //bug 25485. When sorting by a custom field in Account List and then pressing NEXT >, system gives an error |
814 | 814 | $containsCommaPos = strpos($col_name, ","); |
815 | - if($containsCommaPos !== false) { |
|
816 | - $col_name = substr($col_name, $containsCommaPos+1); |
|
815 | + if ($containsCommaPos !== false) { |
|
816 | + $col_name = substr($col_name, $containsCommaPos + 1); |
|
817 | 817 | } |
818 | 818 | //add the "asc/desc" order back |
819 | - $col_name = $col_name. " ". $asc_desc; |
|
819 | + $col_name = $col_name." ".$asc_desc; |
|
820 | 820 | |
821 | 821 | //return column name |
822 | 822 | return $col_name; |
@@ -830,22 +830,22 @@ discard block |
||
830 | 830 | //grab string up to the aliased column |
831 | 831 | $GLOBALS['log']->debug("order by found, process sql string"); |
832 | 832 | |
833 | - $psql = (trim($this->getAliasFromSQL($sql, $orderMatch ))); |
|
833 | + $psql = (trim($this->getAliasFromSQL($sql, $orderMatch))); |
|
834 | 834 | if (empty($psql)) |
835 | 835 | $psql = trim(substr($sql, 0, $found_in_sql)); |
836 | 836 | |
837 | 837 | //grab the last comma before the alias |
838 | - preg_match('/\s+' . trim($orderMatch). '/', $psql, $match, PREG_OFFSET_CAPTURE); |
|
838 | + preg_match('/\s+'.trim($orderMatch).'/', $psql, $match, PREG_OFFSET_CAPTURE); |
|
839 | 839 | $comma_pos = $match[0][1]; |
840 | 840 | //substring between the comma and the alias to find the joined_table alias and column name |
841 | - $col_name = substr($psql,0, $comma_pos); |
|
841 | + $col_name = substr($psql, 0, $comma_pos); |
|
842 | 842 | |
843 | 843 | //make sure the string does not have an end parenthesis |
844 | 844 | //and is not part of a function (i.e. "ISNULL(leads.last_name,'') as name" ) |
845 | 845 | //this is especially true for unified search from home screen |
846 | 846 | |
847 | 847 | $alias_beg_pos = 0; |
848 | - if(strpos($psql, " as ")) |
|
848 | + if (strpos($psql, " as ")) |
|
849 | 849 | $alias_beg_pos = strpos($psql, " as "); |
850 | 850 | |
851 | 851 | // Bug # 44923 - This breaks the query and does not properly filter isnull |
@@ -854,13 +854,13 @@ discard block |
||
854 | 854 | $alias_beg_pos = strpos($psql, " "); */ |
855 | 855 | |
856 | 856 | if ($alias_beg_pos > 0) { |
857 | - $col_name = substr($psql,0, $alias_beg_pos ); |
|
857 | + $col_name = substr($psql, 0, $alias_beg_pos); |
|
858 | 858 | } |
859 | 859 | //add the "asc/desc" order back |
860 | - $col_name = $col_name. " ". $asc_desc; |
|
860 | + $col_name = $col_name." ".$asc_desc; |
|
861 | 861 | |
862 | 862 | //pass in new order by |
863 | - $GLOBALS['log']->debug("order by being returned is " . $col_name); |
|
863 | + $GLOBALS['log']->debug("order by being returned is ".$col_name); |
|
864 | 864 | return $col_name; |
865 | 865 | } |
866 | 866 | } |
@@ -876,12 +876,12 @@ discard block |
||
876 | 876 | { |
877 | 877 | |
878 | 878 | global $beanList, $beanFiles; |
879 | - $GLOBALS['log']->debug("Module being processed is " . $module_str); |
|
879 | + $GLOBALS['log']->debug("Module being processed is ".$module_str); |
|
880 | 880 | //get the right module files |
881 | 881 | //the module string exists in bean list, then process bean for correct table name |
882 | 882 | //note that we exempt the reports module from this, as queries from reporting module should be parsed for |
883 | 883 | //correct table name. |
884 | - if (($module_str != 'Reports' && $module_str != 'SavedReport') && isset($beanList[$module_str]) && isset($beanFiles[$beanList[$module_str]])){ |
|
884 | + if (($module_str != 'Reports' && $module_str != 'SavedReport') && isset($beanList[$module_str]) && isset($beanFiles[$beanList[$module_str]])) { |
|
885 | 885 | //if the class is not already loaded, then load files |
886 | 886 | if (!class_exists($beanList[$module_str])) |
887 | 887 | require_once($beanFiles[$beanList[$module_str]]); |
@@ -893,7 +893,7 @@ discard block |
||
893 | 893 | //make sure table name is not just a blank space, or empty |
894 | 894 | $tbl_name = trim($tbl_name); |
895 | 895 | |
896 | - if(empty($tbl_name)){ |
|
896 | + if (empty($tbl_name)) { |
|
897 | 897 | $GLOBALS['log']->debug("Could not find table name for module $module_str. "); |
898 | 898 | $tbl_name = $module_str; |
899 | 899 | } |
@@ -910,20 +910,20 @@ discard block |
||
910 | 910 | $sql = str_replace(array("\n", "\r"), " ", $sql); |
911 | 911 | |
912 | 912 | //look for the location of the "from" in sql string |
913 | - $fromLoc = strpos($sql," from " ); |
|
914 | - if ($fromLoc>0){ |
|
913 | + $fromLoc = strpos($sql, " from "); |
|
914 | + if ($fromLoc > 0) { |
|
915 | 915 | //found from, substring from the " FROM " string in sql to end |
916 | - $tableEnd = substr($sql, $fromLoc+6); |
|
916 | + $tableEnd = substr($sql, $fromLoc + 6); |
|
917 | 917 | //We know that tablename will be next parameter after from, so |
918 | 918 | //grab the next space after table name. |
919 | 919 | // MFH BUG #14009: Also check to see if there are any carriage returns before the next space so that we don't grab any arbitrary joins or other tables. |
920 | - $carriage_ret = strpos($tableEnd,"\n"); |
|
921 | - $next_space = strpos($tableEnd," " ); |
|
920 | + $carriage_ret = strpos($tableEnd, "\n"); |
|
921 | + $next_space = strpos($tableEnd, " "); |
|
922 | 922 | if ($carriage_ret < $next_space) |
923 | 923 | $next_space = $carriage_ret; |
924 | 924 | if ($next_space > 0) { |
925 | - $tbl_name= substr($tableEnd,0, $next_space); |
|
926 | - if(empty($tbl_name)){ |
|
925 | + $tbl_name = substr($tableEnd, 0, $next_space); |
|
926 | + if (empty($tbl_name)) { |
|
927 | 927 | $GLOBALS['log']->debug("Could not find table name sql either, return $module_str. "); |
928 | 928 | $tbl_name = $module_str; |
929 | 929 | } |
@@ -931,11 +931,11 @@ discard block |
||
931 | 931 | |
932 | 932 | //grab the table, to see if it is aliased |
933 | 933 | $aliasTableEnd = trim(substr($tableEnd, $next_space)); |
934 | - $alias_space = strpos ($aliasTableEnd, " " ); |
|
935 | - if ($alias_space > 0){ |
|
936 | - $alias_tbl_name= substr($aliasTableEnd,0, $alias_space); |
|
934 | + $alias_space = strpos($aliasTableEnd, " "); |
|
935 | + if ($alias_space > 0) { |
|
936 | + $alias_tbl_name = substr($aliasTableEnd, 0, $alias_space); |
|
937 | 937 | strtolower($alias_tbl_name); |
938 | - if(empty($alias_tbl_name) |
|
938 | + if (empty($alias_tbl_name) |
|
939 | 939 | || $alias_tbl_name == "where" |
940 | 940 | || $alias_tbl_name == "inner" |
941 | 941 | || $alias_tbl_name == "left" |
@@ -947,9 +947,9 @@ discard block |
||
947 | 947 | elseif ($alias_tbl_name == "as") { |
948 | 948 | //the next word is the table name |
949 | 949 | $aliasTableEnd = trim(substr($aliasTableEnd, $alias_space)); |
950 | - $alias_space = strpos ($aliasTableEnd, " " ); |
|
950 | + $alias_space = strpos($aliasTableEnd, " "); |
|
951 | 951 | if ($alias_space > 0) { |
952 | - $alias_tbl_name= trim(substr($aliasTableEnd,0, $alias_space)); |
|
952 | + $alias_tbl_name = trim(substr($aliasTableEnd, 0, $alias_space)); |
|
953 | 953 | if (!empty($alias_tbl_name)) |
954 | 954 | $tbl_name = $alias_tbl_name; |
955 | 955 | } |
@@ -974,7 +974,7 @@ discard block |
||
974 | 974 | { |
975 | 975 | $field_array = array(); |
976 | 976 | |
977 | - if(! isset($result) || empty($result)) |
|
977 | + if (!isset($result) || empty($result)) |
|
978 | 978 | return 0; |
979 | 979 | |
980 | 980 | $i = 0; |
@@ -982,7 +982,7 @@ discard block |
||
982 | 982 | $meta = mssql_fetch_field($result, $i); |
983 | 983 | if (!$meta) |
984 | 984 | return 0; |
985 | - if($make_lower_case==true) |
|
985 | + if ($make_lower_case == true) |
|
986 | 986 | $meta->name = strtolower($meta->name); |
987 | 987 | |
988 | 988 | $field_array[] = $meta->name; |
@@ -1011,11 +1011,11 @@ discard block |
||
1011 | 1011 | $row = mssql_fetch_assoc($result); |
1012 | 1012 | //MSSQL returns a space " " when a varchar column is empty ("") and not null. |
1013 | 1013 | //We need to iterate through the returned row array and strip empty spaces |
1014 | - if(!empty($row)){ |
|
1015 | - foreach($row as $key => $column) { |
|
1014 | + if (!empty($row)) { |
|
1015 | + foreach ($row as $key => $column) { |
|
1016 | 1016 | //notice we only strip if one space is returned. we do not want to strip |
1017 | 1017 | //strings with intentional spaces (" foo ") |
1018 | - if (!empty($column) && $column ==" ") { |
|
1018 | + if (!empty($column) && $column == " ") { |
|
1019 | 1019 | $row[$key] = ''; |
1020 | 1020 | } |
1021 | 1021 | } |
@@ -1028,10 +1028,10 @@ discard block |
||
1028 | 1028 | */ |
1029 | 1029 | public function quote($string) |
1030 | 1030 | { |
1031 | - if(is_array($string)) { |
|
1031 | + if (is_array($string)) { |
|
1032 | 1032 | return $this->arrayQuote($string); |
1033 | 1033 | } |
1034 | - return str_replace("'","''", $this->quoteInternal($string)); |
|
1034 | + return str_replace("'", "''", $this->quoteInternal($string)); |
|
1035 | 1035 | } |
1036 | 1036 | |
1037 | 1037 | /** |
@@ -1069,7 +1069,7 @@ discard block |
||
1069 | 1069 | if (!empty($r)) { |
1070 | 1070 | while ($a = $this->fetchByAssoc($r)) { |
1071 | 1071 | $row = array_values($a); |
1072 | - $tables[]=$row[0]; |
|
1072 | + $tables[] = $row[0]; |
|
1073 | 1073 | } |
1074 | 1074 | return $tables; |
1075 | 1075 | } |
@@ -1084,7 +1084,7 @@ discard block |
||
1084 | 1084 | { |
1085 | 1085 | $GLOBALS['log']->debug('MSSQL fetching table list'); |
1086 | 1086 | |
1087 | - if($this->getDatabase()) { |
|
1087 | + if ($this->getDatabase()) { |
|
1088 | 1088 | $tables = array(); |
1089 | 1089 | $r = $this->query('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES'); |
1090 | 1090 | if (is_resource($r)) { |
@@ -1108,7 +1108,7 @@ discard block |
||
1108 | 1108 | { |
1109 | 1109 | $GLOBALS['log']->debug('MSSQL about to wakeup FTS'); |
1110 | 1110 | |
1111 | - if($this->getDatabase()) { |
|
1111 | + if ($this->getDatabase()) { |
|
1112 | 1112 | //create wakeup catalog |
1113 | 1113 | $FTSqry[] = "if not exists( select * from sys.fulltext_catalogs where name ='wakeup_catalog' ) |
1114 | 1114 | CREATE FULLTEXT CATALOG wakeup_catalog |
@@ -1148,7 +1148,7 @@ discard block |
||
1148 | 1148 | $FTSqry[] = 'ALTER FULLTEXT INDEX ON fts_wakeup START FULL POPULATION'; |
1149 | 1149 | $FTSqry[] = 'ALTER FULLTEXT INDEX ON fts_wakeup SET CHANGE_TRACKING AUTO'; |
1150 | 1150 | |
1151 | - foreach($FTSqry as $q){ |
|
1151 | + foreach ($FTSqry as $q) { |
|
1152 | 1152 | sleep(3); |
1153 | 1153 | $this->query($q); |
1154 | 1154 | } |
@@ -1171,12 +1171,12 @@ discard block |
||
1171 | 1171 | { |
1172 | 1172 | // convert the parameters array into a comma delimited string |
1173 | 1173 | if (!empty($additional_parameters)) { |
1174 | - $additional_parameters_string = ','.implode(',',$additional_parameters); |
|
1174 | + $additional_parameters_string = ','.implode(',', $additional_parameters); |
|
1175 | 1175 | } else { |
1176 | 1176 | $additional_parameters_string = ''; |
1177 | 1177 | } |
1178 | 1178 | $all_parameters = $additional_parameters; |
1179 | - if(is_array($string)) { |
|
1179 | + if (is_array($string)) { |
|
1180 | 1180 | $all_parameters = array_merge($string, $all_parameters); |
1181 | 1181 | } elseif (!is_null($string)) { |
1182 | 1182 | array_unshift($all_parameters, $string); |
@@ -1188,22 +1188,22 @@ discard block |
||
1188 | 1188 | case 'left': |
1189 | 1189 | return "LEFT($string$additional_parameters_string)"; |
1190 | 1190 | case 'date_format': |
1191 | - if(!empty($additional_parameters[0]) && $additional_parameters[0][0] == "'") { |
|
1191 | + if (!empty($additional_parameters[0]) && $additional_parameters[0][0] == "'") { |
|
1192 | 1192 | $additional_parameters[0] = trim($additional_parameters[0], "'"); |
1193 | 1193 | } |
1194 | - if(!empty($additional_parameters) && isset($this->date_formats[$additional_parameters[0]])) { |
|
1194 | + if (!empty($additional_parameters) && isset($this->date_formats[$additional_parameters[0]])) { |
|
1195 | 1195 | $len = $this->date_formats[$additional_parameters[0]]; |
1196 | - return "LEFT(CONVERT(varchar($len),". $string . ",120),$len)"; |
|
1196 | + return "LEFT(CONVERT(varchar($len),".$string.",120),$len)"; |
|
1197 | 1197 | } else { |
1198 | - return "LEFT(CONVERT(varchar(10),". $string . ",120),10)"; |
|
1198 | + return "LEFT(CONVERT(varchar(10),".$string.",120),10)"; |
|
1199 | 1199 | } |
1200 | 1200 | case 'ifnull': |
1201 | - if(empty($additional_parameters_string)) { |
|
1201 | + if (empty($additional_parameters_string)) { |
|
1202 | 1202 | $additional_parameters_string = ",''"; |
1203 | 1203 | } |
1204 | 1204 | return "ISNULL($string$additional_parameters_string)"; |
1205 | 1205 | case 'concat': |
1206 | - return implode("+",$all_parameters); |
|
1206 | + return implode("+", $all_parameters); |
|
1207 | 1207 | case 'text2char': |
1208 | 1208 | return "CAST($string AS varchar(8000))"; |
1209 | 1209 | case 'quarter': |
@@ -1219,7 +1219,7 @@ discard block |
||
1219 | 1219 | case 'add_tz_offset' : |
1220 | 1220 | $getUserUTCOffset = $GLOBALS['timedate']->getUserUTCOffset(); |
1221 | 1221 | $operation = $getUserUTCOffset < 0 ? '-' : '+'; |
1222 | - return 'DATEADD(minute, ' . $operation . abs($getUserUTCOffset) . ', ' . $string. ')'; |
|
1222 | + return 'DATEADD(minute, '.$operation.abs($getUserUTCOffset).', '.$string.')'; |
|
1223 | 1223 | case 'avg': |
1224 | 1224 | return "avg($string)"; |
1225 | 1225 | } |
@@ -1232,9 +1232,9 @@ discard block |
||
1232 | 1232 | */ |
1233 | 1233 | public function fromConvert($string, $type) |
1234 | 1234 | { |
1235 | - switch($type) { |
|
1235 | + switch ($type) { |
|
1236 | 1236 | case 'datetimecombo': |
1237 | - case 'datetime': return substr($string, 0,19); |
|
1237 | + case 'datetime': return substr($string, 0, 19); |
|
1238 | 1238 | case 'date': return substr($string, 0, 10); |
1239 | 1239 | case 'time': return substr($string, 11); |
1240 | 1240 | } |
@@ -1263,8 +1263,8 @@ discard block |
||
1263 | 1263 | public function isTextType($type) |
1264 | 1264 | { |
1265 | 1265 | $type = strtolower($type); |
1266 | - if(!isset($this->type_map[$type])) return false; |
|
1267 | - return in_array($this->type_map[$type], array('ntext','text','image', 'nvarchar(max)')); |
|
1266 | + if (!isset($this->type_map[$type])) return false; |
|
1267 | + return in_array($this->type_map[$type], array('ntext', 'text', 'image', 'nvarchar(max)')); |
|
1268 | 1268 | } |
1269 | 1269 | |
1270 | 1270 | /** |
@@ -1274,13 +1274,13 @@ discard block |
||
1274 | 1274 | public function emptyValue($type) |
1275 | 1275 | { |
1276 | 1276 | $ctype = $this->getColumnType($type); |
1277 | - if($ctype == "datetime") { |
|
1277 | + if ($ctype == "datetime") { |
|
1278 | 1278 | return $this->convert($this->quoted("1970-01-01 00:00:00"), "datetime"); |
1279 | 1279 | } |
1280 | - if($ctype == "date") { |
|
1280 | + if ($ctype == "date") { |
|
1281 | 1281 | return $this->convert($this->quoted("1970-01-01"), "datetime"); |
1282 | 1282 | } |
1283 | - if($ctype == "time") { |
|
1283 | + if ($ctype == "time") { |
|
1284 | 1284 | return $this->convert($this->quoted("00:00:00"), "time"); |
1285 | 1285 | } |
1286 | 1286 | return parent::emptyValue($type); |
@@ -1303,21 +1303,21 @@ discard block |
||
1303 | 1303 | */ |
1304 | 1304 | protected function alterSQLRep($action, array $def, $ignoreRequired, $tablename) |
1305 | 1305 | { |
1306 | - switch($action){ |
|
1306 | + switch ($action) { |
|
1307 | 1307 | case 'add': |
1308 | - $f_def=$this->oneColumnSQLRep($def, $ignoreRequired,$tablename,false); |
|
1309 | - return "ADD " . $f_def; |
|
1308 | + $f_def = $this->oneColumnSQLRep($def, $ignoreRequired, $tablename, false); |
|
1309 | + return "ADD ".$f_def; |
|
1310 | 1310 | break; |
1311 | 1311 | case 'drop': |
1312 | - return "DROP COLUMN " . $def['name']; |
|
1312 | + return "DROP COLUMN ".$def['name']; |
|
1313 | 1313 | break; |
1314 | 1314 | case 'modify': |
1315 | 1315 | //You cannot specify a default value for a column for MSSQL |
1316 | - $f_def = $this->oneColumnSQLRep($def, $ignoreRequired,$tablename, true); |
|
1316 | + $f_def = $this->oneColumnSQLRep($def, $ignoreRequired, $tablename, true); |
|
1317 | 1317 | $f_stmt = "ALTER COLUMN ".$f_def['name'].' '.$f_def['colType'].' '. |
1318 | 1318 | $f_def['required'].' '.$f_def['auto_increment']."\n"; |
1319 | - if (!empty( $f_def['default'])) |
|
1320 | - $f_stmt .= " ALTER TABLE " . $tablename . " ADD ". $f_def['default'] . " FOR " . $def['name']; |
|
1319 | + if (!empty($f_def['default'])) |
|
1320 | + $f_stmt .= " ALTER TABLE ".$tablename." ADD ".$f_def['default']." FOR ".$def['name']; |
|
1321 | 1321 | return $f_stmt; |
1322 | 1322 | break; |
1323 | 1323 | default: |
@@ -1333,7 +1333,7 @@ discard block |
||
1333 | 1333 | */ |
1334 | 1334 | protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
1335 | 1335 | { |
1336 | - $sql=$sql2=''; |
|
1336 | + $sql = $sql2 = ''; |
|
1337 | 1337 | $constraints = $this->get_field_default_constraint_name($tablename); |
1338 | 1338 | $columns = array(); |
1339 | 1339 | if ($this->isFieldArray($fieldDefs)) { |
@@ -1342,41 +1342,41 @@ discard block |
||
1342 | 1342 | //if the column is being modified drop the default value |
1343 | 1343 | //constraint if it exists. alterSQLRep will add the constraint back |
1344 | 1344 | if (!empty($constraints[$def['name']])) { |
1345 | - $sql.=" ALTER TABLE " . $tablename . " DROP CONSTRAINT " . $constraints[$def['name']]; |
|
1345 | + $sql .= " ALTER TABLE ".$tablename." DROP CONSTRAINT ".$constraints[$def['name']]; |
|
1346 | 1346 | } |
1347 | 1347 | //check to see if we need to drop related indexes before the alter |
1348 | 1348 | $indices = $this->get_indices($tablename); |
1349 | - foreach ( $indices as $index ) { |
|
1350 | - if ( in_array($def['name'],$index['fields']) ) { |
|
1351 | - $sql .= ' ' . $this->add_drop_constraint($tablename,$index,true).' '; |
|
1352 | - $sql2 .= ' ' . $this->add_drop_constraint($tablename,$index,false).' '; |
|
1349 | + foreach ($indices as $index) { |
|
1350 | + if (in_array($def['name'], $index['fields'])) { |
|
1351 | + $sql .= ' '.$this->add_drop_constraint($tablename, $index, true).' '; |
|
1352 | + $sql2 .= ' '.$this->add_drop_constraint($tablename, $index, false).' '; |
|
1353 | 1353 | } |
1354 | 1354 | } |
1355 | 1355 | |
1356 | - $columns[] = $this->alterSQLRep($action, $def, $ignoreRequired,$tablename); |
|
1356 | + $columns[] = $this->alterSQLRep($action, $def, $ignoreRequired, $tablename); |
|
1357 | 1357 | } |
1358 | 1358 | } |
1359 | 1359 | else { |
1360 | 1360 | //if the column is being modified drop the default value |
1361 | 1361 | //constraint if it exists. alterSQLRep will add the constraint back |
1362 | 1362 | if (!empty($constraints[$fieldDefs['name']])) { |
1363 | - $sql.=" ALTER TABLE " . $tablename . " DROP CONSTRAINT " . $constraints[$fieldDefs['name']]; |
|
1363 | + $sql .= " ALTER TABLE ".$tablename." DROP CONSTRAINT ".$constraints[$fieldDefs['name']]; |
|
1364 | 1364 | } |
1365 | 1365 | //check to see if we need to drop related indexes before the alter |
1366 | 1366 | $indices = $this->get_indices($tablename); |
1367 | - foreach ( $indices as $index ) { |
|
1368 | - if ( in_array($fieldDefs['name'],$index['fields']) ) { |
|
1369 | - $sql .= ' ' . $this->add_drop_constraint($tablename,$index,true).' '; |
|
1370 | - $sql2 .= ' ' . $this->add_drop_constraint($tablename,$index,false).' '; |
|
1367 | + foreach ($indices as $index) { |
|
1368 | + if (in_array($fieldDefs['name'], $index['fields'])) { |
|
1369 | + $sql .= ' '.$this->add_drop_constraint($tablename, $index, true).' '; |
|
1370 | + $sql2 .= ' '.$this->add_drop_constraint($tablename, $index, false).' '; |
|
1371 | 1371 | } |
1372 | 1372 | } |
1373 | 1373 | |
1374 | 1374 | |
1375 | - $columns[] = $this->alterSQLRep($action, $fieldDefs, $ignoreRequired,$tablename); |
|
1375 | + $columns[] = $this->alterSQLRep($action, $fieldDefs, $ignoreRequired, $tablename); |
|
1376 | 1376 | } |
1377 | 1377 | |
1378 | 1378 | $columns = implode(", ", $columns); |
1379 | - $sql .= " ALTER TABLE $tablename $columns " . $sql2; |
|
1379 | + $sql .= " ALTER TABLE $tablename $columns ".$sql2; |
|
1380 | 1380 | |
1381 | 1381 | return $sql; |
1382 | 1382 | } |
@@ -1391,7 +1391,7 @@ discard block |
||
1391 | 1391 | */ |
1392 | 1392 | public function setAutoIncrementStart($table, $field_name, $start_value) |
1393 | 1393 | { |
1394 | - if($start_value > 1) |
|
1394 | + if ($start_value > 1) |
|
1395 | 1395 | $start_value -= 1; |
1396 | 1396 | $this->query("DBCC CHECKIDENT ('$table', RESEED, $start_value) WITH NO_INFOMSGS"); |
1397 | 1397 | return true; |
@@ -1426,11 +1426,11 @@ discard block |
||
1426 | 1426 | $result = $this->query($query); |
1427 | 1427 | |
1428 | 1428 | $indices = array(); |
1429 | - while (($row=$this->fetchByAssoc($result)) != null) { |
|
1429 | + while (($row = $this->fetchByAssoc($result)) != null) { |
|
1430 | 1430 | $index_type = 'index'; |
1431 | 1431 | if ($row['is_primary_key'] == '1') |
1432 | 1432 | $index_type = 'primary'; |
1433 | - elseif ($row['is_unique'] == 1 ) |
|
1433 | + elseif ($row['is_unique'] == 1) |
|
1434 | 1434 | $index_type = 'unique'; |
1435 | 1435 | $name = strtolower($row['index_name']); |
1436 | 1436 | $indices[$name]['name'] = $name; |
@@ -1449,36 +1449,36 @@ discard block |
||
1449 | 1449 | $result = $this->query("sp_columns $tablename"); |
1450 | 1450 | |
1451 | 1451 | $columns = array(); |
1452 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
1452 | + while (($row = $this->fetchByAssoc($result)) != null) { |
|
1453 | 1453 | $column_name = strtolower($row['COLUMN_NAME']); |
1454 | - $columns[$column_name]['name']=$column_name; |
|
1455 | - $columns[$column_name]['type']=strtolower($row['TYPE_NAME']); |
|
1456 | - if ( $row['TYPE_NAME'] == 'decimal' ) { |
|
1457 | - $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
1458 | - $columns[$column_name]['len'].=','.strtolower($row['SCALE']); |
|
1454 | + $columns[$column_name]['name'] = $column_name; |
|
1455 | + $columns[$column_name]['type'] = strtolower($row['TYPE_NAME']); |
|
1456 | + if ($row['TYPE_NAME'] == 'decimal') { |
|
1457 | + $columns[$column_name]['len'] = strtolower($row['PRECISION']); |
|
1458 | + $columns[$column_name]['len'] .= ','.strtolower($row['SCALE']); |
|
1459 | 1459 | } |
1460 | - elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) |
|
1461 | - $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
1462 | - elseif ( !in_array($row['TYPE_NAME'],array('datetime','text')) ) |
|
1463 | - $columns[$column_name]['len']=strtolower($row['LENGTH']); |
|
1464 | - if ( stristr($row['TYPE_NAME'],'identity') ) { |
|
1460 | + elseif (in_array($row['TYPE_NAME'], array('nchar', 'nvarchar'))) |
|
1461 | + $columns[$column_name]['len'] = strtolower($row['PRECISION']); |
|
1462 | + elseif (!in_array($row['TYPE_NAME'], array('datetime', 'text'))) |
|
1463 | + $columns[$column_name]['len'] = strtolower($row['LENGTH']); |
|
1464 | + if (stristr($row['TYPE_NAME'], 'identity')) { |
|
1465 | 1465 | $columns[$column_name]['auto_increment'] = '1'; |
1466 | - $columns[$column_name]['type']=str_replace(' identity','',strtolower($row['TYPE_NAME'])); |
|
1466 | + $columns[$column_name]['type'] = str_replace(' identity', '', strtolower($row['TYPE_NAME'])); |
|
1467 | 1467 | } |
1468 | 1468 | |
1469 | - if (!empty($row['IS_NULLABLE']) && $row['IS_NULLABLE'] == 'NO' && (empty($row['KEY']) || !stristr($row['KEY'],'PRI'))) |
|
1469 | + if (!empty($row['IS_NULLABLE']) && $row['IS_NULLABLE'] == 'NO' && (empty($row['KEY']) || !stristr($row['KEY'], 'PRI'))) |
|
1470 | 1470 | $columns[strtolower($row['COLUMN_NAME'])]['required'] = 'true'; |
1471 | 1471 | |
1472 | 1472 | $column_def = 1; |
1473 | - if ( strtolower($tablename) == 'relationships' ) { |
|
1473 | + if (strtolower($tablename) == 'relationships') { |
|
1474 | 1474 | $column_def = $this->getOne("select cdefault from syscolumns where id = object_id('relationships') and name = '$column_name'"); |
1475 | 1475 | } |
1476 | - if ( $column_def != 0 && ($row['COLUMN_DEF'] != null)) { // NOTE Not using !empty as an empty string may be a viable default value. |
|
1476 | + if ($column_def != 0 && ($row['COLUMN_DEF'] != null)) { // NOTE Not using !empty as an empty string may be a viable default value. |
|
1477 | 1477 | $matches = array(); |
1478 | - $row['COLUMN_DEF'] = html_entity_decode($row['COLUMN_DEF'],ENT_QUOTES); |
|
1479 | - if ( preg_match('/\([\(|\'](.*)[\)|\']\)/i',$row['COLUMN_DEF'],$matches) ) |
|
1478 | + $row['COLUMN_DEF'] = html_entity_decode($row['COLUMN_DEF'], ENT_QUOTES); |
|
1479 | + if (preg_match('/\([\(|\'](.*)[\)|\']\)/i', $row['COLUMN_DEF'], $matches)) |
|
1480 | 1480 | $columns[$column_name]['default'] = $matches[1]; |
1481 | - elseif ( preg_match('/\(N\'(.*)\'\)/i',$row['COLUMN_DEF'],$matches) ) |
|
1481 | + elseif (preg_match('/\(N\'(.*)\'\)/i', $row['COLUMN_DEF'], $matches)) |
|
1482 | 1482 | $columns[$column_name]['default'] = $matches[1]; |
1483 | 1483 | else |
1484 | 1484 | $columns[$column_name]['default'] = $row['COLUMN_DEF']; |
@@ -1493,7 +1493,7 @@ discard block |
||
1493 | 1493 | */ |
1494 | 1494 | protected function ftsCatalogName() |
1495 | 1495 | { |
1496 | - if(isset($this->connectOptions['db_name'])) { |
|
1496 | + if (isset($this->connectOptions['db_name'])) { |
|
1497 | 1497 | return $this->connectOptions['db_name']."_fts_catalog"; |
1498 | 1498 | } |
1499 | 1499 | return 'sugar_fts_catalog'; |
@@ -1505,11 +1505,11 @@ discard block |
||
1505 | 1505 | public function add_drop_constraint($table, $definition, $drop = false) |
1506 | 1506 | { |
1507 | 1507 | $type = $definition['type']; |
1508 | - $fields = is_array($definition['fields'])?implode(',',$definition['fields']):$definition['fields']; |
|
1508 | + $fields = is_array($definition['fields']) ? implode(',', $definition['fields']) : $definition['fields']; |
|
1509 | 1509 | $name = $definition['name']; |
1510 | 1510 | $sql = ''; |
1511 | 1511 | |
1512 | - switch ($type){ |
|
1512 | + switch ($type) { |
|
1513 | 1513 | // generic indices |
1514 | 1514 | case 'index': |
1515 | 1515 | case 'alternate_key': |
@@ -1547,13 +1547,13 @@ discard block |
||
1547 | 1547 | if ($this->full_text_indexing_enabled() && $drop) { |
1548 | 1548 | $sql = "DROP FULLTEXT INDEX ON {$table}"; |
1549 | 1549 | } elseif ($this->full_text_indexing_enabled()) { |
1550 | - $catalog_name=$this->ftsCatalogName(); |
|
1551 | - if ( isset($definition['catalog_name']) && $definition['catalog_name'] != 'default') |
|
1550 | + $catalog_name = $this->ftsCatalogName(); |
|
1551 | + if (isset($definition['catalog_name']) && $definition['catalog_name'] != 'default') |
|
1552 | 1552 | $catalog_name = $definition['catalog_name']; |
1553 | 1553 | |
1554 | 1554 | $language = "Language 1033"; |
1555 | 1555 | if (isset($definition['language']) && !empty($definition['language'])) |
1556 | - $language = "Language " . $definition['language']; |
|
1556 | + $language = "Language ".$definition['language']; |
|
1557 | 1557 | |
1558 | 1558 | $key_index = $definition['key_index']; |
1559 | 1559 | |
@@ -1561,7 +1561,7 @@ discard block |
||
1561 | 1561 | if (isset($definition['change_tracking']) && !empty($definition['change_tracking'])) |
1562 | 1562 | $change_tracking = $definition['change_tracking']; |
1563 | 1563 | |
1564 | - $sql = " CREATE FULLTEXT INDEX ON $table ($fields $language) KEY INDEX $key_index ON $catalog_name WITH CHANGE_TRACKING $change_tracking" ; |
|
1564 | + $sql = " CREATE FULLTEXT INDEX ON $table ($fields $language) KEY INDEX $key_index ON $catalog_name WITH CHANGE_TRACKING $change_tracking"; |
|
1565 | 1565 | } |
1566 | 1566 | break; |
1567 | 1567 | } |
@@ -1585,11 +1585,11 @@ discard block |
||
1585 | 1585 | protected function full_text_indexing_enabled($dbname = null) |
1586 | 1586 | { |
1587 | 1587 | // check to see if we already have install setting in session |
1588 | - if(!isset($_SESSION['IsFulltextInstalled'])) |
|
1588 | + if (!isset($_SESSION['IsFulltextInstalled'])) |
|
1589 | 1589 | $_SESSION['IsFulltextInstalled'] = $this->full_text_indexing_installed(); |
1590 | 1590 | |
1591 | 1591 | // check to see if FTS Indexing service is installed |
1592 | - if(empty($_SESSION['IsFulltextInstalled'])) |
|
1592 | + if (empty($_SESSION['IsFulltextInstalled'])) |
|
1593 | 1593 | return false; |
1594 | 1594 | |
1595 | 1595 | // grab the dbname if it was not passed through |
@@ -1639,7 +1639,7 @@ discard block |
||
1639 | 1639 | { |
1640 | 1640 | static $results = array(); |
1641 | 1641 | |
1642 | - if ( empty($column) && isset($results[$table]) ) |
|
1642 | + if (empty($column) && isset($results[$table])) |
|
1643 | 1643 | return $results[$table]; |
1644 | 1644 | |
1645 | 1645 | $query = <<<EOQ |
@@ -1653,17 +1653,17 @@ discard block |
||
1653 | 1653 | on s.schema_id = o.schema_id |
1654 | 1654 | where o.name = '$table' |
1655 | 1655 | EOQ; |
1656 | - if ( !empty($column) ) |
|
1656 | + if (!empty($column)) |
|
1657 | 1657 | $query .= " and c.name = '$column'"; |
1658 | 1658 | $res = $this->query($query); |
1659 | - if ( !empty($column) ) { |
|
1659 | + if (!empty($column)) { |
|
1660 | 1660 | $row = $this->fetchByAssoc($res); |
1661 | 1661 | if (!empty($row)) |
1662 | 1662 | return $row['ctrt']; |
1663 | 1663 | } |
1664 | 1664 | else { |
1665 | 1665 | $returnResult = array(); |
1666 | - while ( $row = $this->fetchByAssoc($res) ) |
|
1666 | + while ($row = $this->fetchByAssoc($res)) |
|
1667 | 1667 | $returnResult[$row['dtrt']] = $row['ctrt']; |
1668 | 1668 | $results[$table] = $returnResult; |
1669 | 1669 | return $returnResult; |
@@ -1677,14 +1677,14 @@ discard block |
||
1677 | 1677 | */ |
1678 | 1678 | public function massageFieldDef(&$fieldDef, $tablename) |
1679 | 1679 | { |
1680 | - parent::massageFieldDef($fieldDef,$tablename); |
|
1680 | + parent::massageFieldDef($fieldDef, $tablename); |
|
1681 | 1681 | |
1682 | 1682 | if ($fieldDef['type'] == 'int') |
1683 | 1683 | $fieldDef['len'] = '4'; |
1684 | 1684 | |
1685 | - if(empty($fieldDef['len'])) |
|
1685 | + if (empty($fieldDef['len'])) |
|
1686 | 1686 | { |
1687 | - switch($fieldDef['type']) { |
|
1687 | + switch ($fieldDef['type']) { |
|
1688 | 1688 | case 'bit' : |
1689 | 1689 | case 'bool' : $fieldDef['len'] = '1'; break; |
1690 | 1690 | case 'smallint' : $fieldDef['len'] = '2'; break; |
@@ -1694,22 +1694,22 @@ discard block |
||
1694 | 1694 | $fieldDef['len'] = $this->isTextType($fieldDef['dbType']) ? 'max' : '255'; |
1695 | 1695 | break; |
1696 | 1696 | case 'image' : $fieldDef['len'] = '2147483647'; break; |
1697 | - case 'ntext' : $fieldDef['len'] = '2147483646'; break; // Note: this is from legacy code, don't know if this is correct |
|
1697 | + case 'ntext' : $fieldDef['len'] = '2147483646'; break; // Note: this is from legacy code, don't know if this is correct |
|
1698 | 1698 | } |
1699 | 1699 | } |
1700 | - if($fieldDef['type'] == 'decimal' |
|
1700 | + if ($fieldDef['type'] == 'decimal' |
|
1701 | 1701 | && empty($fieldDef['precision']) |
1702 | 1702 | && !strpos($fieldDef['len'], ',')) |
1703 | 1703 | { |
1704 | 1704 | $fieldDef['len'] .= ',0'; // Adding 0 precision if it is not specified |
1705 | 1705 | } |
1706 | 1706 | |
1707 | - if(empty($fieldDef['default']) |
|
1708 | - && in_array($fieldDef['type'],array('bit','bool'))) |
|
1707 | + if (empty($fieldDef['default']) |
|
1708 | + && in_array($fieldDef['type'], array('bit', 'bool'))) |
|
1709 | 1709 | { |
1710 | 1710 | $fieldDef['default'] = '0'; |
1711 | 1711 | } |
1712 | - if (isset($fieldDef['required']) && $fieldDef['required'] && !isset($fieldDef['default']) ) |
|
1712 | + if (isset($fieldDef['required']) && $fieldDef['required'] && !isset($fieldDef['default'])) |
|
1713 | 1713 | $fieldDef['default'] = ''; |
1714 | 1714 | // if ($fieldDef['type'] == 'bit' && empty($fieldDef['len']) ) |
1715 | 1715 | // $fieldDef['len'] = '1'; |
@@ -1740,13 +1740,13 @@ discard block |
||
1740 | 1740 | protected function oneColumnSQLRep($fieldDef, $ignoreRequired = false, $table = '', $return_as_array = false) |
1741 | 1741 | { |
1742 | 1742 | //Bug 25814 |
1743 | - if(isset($fieldDef['name'])){ |
|
1743 | + if (isset($fieldDef['name'])) { |
|
1744 | 1744 | $colType = $this->getFieldType($fieldDef); |
1745 | - if(stristr($this->getFieldType($fieldDef), 'decimal') && isset($fieldDef['len'])){ |
|
1746 | - $fieldDef['len'] = min($fieldDef['len'],38); |
|
1745 | + if (stristr($this->getFieldType($fieldDef), 'decimal') && isset($fieldDef['len'])) { |
|
1746 | + $fieldDef['len'] = min($fieldDef['len'], 38); |
|
1747 | 1747 | } |
1748 | 1748 | //bug: 39690 float(8) is interpreted as real and this generates a diff when doing repair |
1749 | - if(stristr($colType, 'float') && isset($fieldDef['len']) && $fieldDef['len'] == 8){ |
|
1749 | + if (stristr($colType, 'float') && isset($fieldDef['len']) && $fieldDef['len'] == 8) { |
|
1750 | 1750 | unset($fieldDef['len']); |
1751 | 1751 | } |
1752 | 1752 | } |
@@ -1755,10 +1755,10 @@ discard block |
||
1755 | 1755 | $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
1756 | 1756 | |
1757 | 1757 | // Bug 24307 - Don't add precision for float fields. |
1758 | - if ( stristr($ref['colType'],'float') ) |
|
1759 | - $ref['colType'] = preg_replace('/(,\d+)/','',$ref['colType']); |
|
1758 | + if (stristr($ref['colType'], 'float')) |
|
1759 | + $ref['colType'] = preg_replace('/(,\d+)/', '', $ref['colType']); |
|
1760 | 1760 | |
1761 | - if ( $return_as_array ) |
|
1761 | + if ($return_as_array) |
|
1762 | 1762 | return $ref; |
1763 | 1763 | else |
1764 | 1764 | return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
@@ -1773,10 +1773,10 @@ discard block |
||
1773 | 1773 | public function save_audit_records(SugarBean $bean, $changes) |
1774 | 1774 | { |
1775 | 1775 | //Bug 25078 fixed by Martin Hu: sqlserver haven't 'date' type, trim extra "00:00:00" |
1776 | - if($changes['data_type'] == 'date'){ |
|
1777 | - $changes['before'] = str_replace(' 00:00:00','',$changes['before']); |
|
1776 | + if ($changes['data_type'] == 'date') { |
|
1777 | + $changes['before'] = str_replace(' 00:00:00', '', $changes['before']); |
|
1778 | 1778 | } |
1779 | - parent::save_audit_records($bean,$changes); |
|
1779 | + parent::save_audit_records($bean, $changes); |
|
1780 | 1780 | } |
1781 | 1781 | |
1782 | 1782 | /** |
@@ -1787,7 +1787,7 @@ discard block |
||
1787 | 1787 | public function disconnect() |
1788 | 1788 | { |
1789 | 1789 | $GLOBALS['log']->debug('Calling Mssql::disconnect()'); |
1790 | - if(!empty($this->database)){ |
|
1790 | + if (!empty($this->database)) { |
|
1791 | 1791 | $this->freeResult(); |
1792 | 1792 | mssql_close($this->database); |
1793 | 1793 | $this->database = null; |
@@ -1799,7 +1799,7 @@ discard block |
||
1799 | 1799 | */ |
1800 | 1800 | protected function freeDbResult($dbResult) |
1801 | 1801 | { |
1802 | - if(!empty($dbResult)) |
|
1802 | + if (!empty($dbResult)) |
|
1803 | 1803 | mssql_free_result($dbResult); |
1804 | 1804 | } |
1805 | 1805 | |
@@ -1810,11 +1810,11 @@ discard block |
||
1810 | 1810 | public function lastDbError() |
1811 | 1811 | { |
1812 | 1812 | $sqlmsg = mssql_get_last_message(); |
1813 | - if(empty($sqlmsg)) return false; |
|
1813 | + if (empty($sqlmsg)) return false; |
|
1814 | 1814 | global $app_strings; |
1815 | 1815 | if (empty($app_strings) |
1816 | 1816 | or !isset($app_strings['ERR_MSSQL_DB_CONTEXT']) |
1817 | - or !isset($app_strings['ERR_MSSQL_WARNING']) ) { |
|
1817 | + or !isset($app_strings['ERR_MSSQL_WARNING'])) { |
|
1818 | 1818 | //ignore the message from sql-server if $app_strings array is empty. This will happen |
1819 | 1819 | //only if connection if made before language is set. |
1820 | 1820 | return false; |
@@ -1823,7 +1823,7 @@ discard block |
||
1823 | 1823 | $sqlpos = strpos($sqlmsg, 'Changed database context to'); |
1824 | 1824 | $sqlpos2 = strpos($sqlmsg, 'Warning:'); |
1825 | 1825 | $sqlpos3 = strpos($sqlmsg, 'Checking identity information:'); |
1826 | - if ( $sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false ) { |
|
1826 | + if ($sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false) { |
|
1827 | 1827 | return false; |
1828 | 1828 | } else { |
1829 | 1829 | global $app_strings; |
@@ -1831,18 +1831,18 @@ discard block |
||
1831 | 1831 | if (empty($app_strings) or !isset($app_strings['ERR_MSSQL_DB_CONTEXT'])) { |
1832 | 1832 | //ignore the message from sql-server if $app_strings array is empty. This will happen |
1833 | 1833 | //only if connection if made before languge is set. |
1834 | - $GLOBALS['log']->debug("Ignoring this database message: " . $sqlmsg); |
|
1834 | + $GLOBALS['log']->debug("Ignoring this database message: ".$sqlmsg); |
|
1835 | 1835 | return false; |
1836 | 1836 | } |
1837 | 1837 | else { |
1838 | 1838 | $sqlpos = strpos($sqlmsg, $app_strings['ERR_MSSQL_DB_CONTEXT']); |
1839 | - if ( $sqlpos !== false ) |
|
1839 | + if ($sqlpos !== false) |
|
1840 | 1840 | return false; |
1841 | 1841 | } |
1842 | 1842 | } |
1843 | 1843 | |
1844 | - if ( strlen($sqlmsg) > 2 ) { |
|
1845 | - return "SQL Server error: " . $sqlmsg; |
|
1844 | + if (strlen($sqlmsg) > 2) { |
|
1845 | + return "SQL Server error: ".$sqlmsg; |
|
1846 | 1846 | } |
1847 | 1847 | |
1848 | 1848 | return false; |
@@ -1863,7 +1863,7 @@ discard block |
||
1863 | 1863 | */ |
1864 | 1864 | public function validateQuery($query) |
1865 | 1865 | { |
1866 | - if(!$this->isSelect($query)) { |
|
1866 | + if (!$this->isSelect($query)) { |
|
1867 | 1867 | return false; |
1868 | 1868 | } |
1869 | 1869 | $this->query("SET SHOWPLAN_TEXT ON"); |
@@ -1887,7 +1887,7 @@ discard block |
||
1887 | 1887 | |
1888 | 1888 | // Flag if there are odd number of single quotes, just continue without trying to append N |
1889 | 1889 | if ((substr_count($sql, "'") & 1)) { |
1890 | - $GLOBALS['log']->error("SQL statement[" . $sql . "] has odd number of single quotes."); |
|
1890 | + $GLOBALS['log']->error("SQL statement[".$sql."] has odd number of single quotes."); |
|
1891 | 1891 | return $sql; |
1892 | 1892 | } |
1893 | 1893 | |
@@ -1917,7 +1917,7 @@ discard block |
||
1917 | 1917 | // We are assuming that all nvarchar columns are no more than 200 characters in length |
1918 | 1918 | // One problem we face is the image column type in reports which cannot accept nvarchar data |
1919 | 1919 | if (!empty($value) && !is_numeric(trim(str_replace(array("'", ","), "", $value))) && !preg_match('/^\'[\,]\'$/', $value)) { |
1920 | - $replace[$value] = 'N' . trim($value, "N"); |
|
1920 | + $replace[$value] = 'N'.trim($value, "N"); |
|
1921 | 1921 | } |
1922 | 1922 | } |
1923 | 1923 | } |
@@ -1928,7 +1928,7 @@ discard block |
||
1928 | 1928 | if (!empty($pairs)) |
1929 | 1929 | $sql = str_replace(array_keys($pairs), $pairs, $sql); |
1930 | 1930 | |
1931 | - if(strpos($sql, "<@#@#@PAIR@#@#@>")) |
|
1931 | + if (strpos($sql, "<@#@#@PAIR@#@#@>")) |
|
1932 | 1932 | $sql = str_replace(array('<@#@#@PAIR@#@#@>'), array("''"), $sql); |
1933 | 1933 | |
1934 | 1934 | return $sql; |
@@ -1955,22 +1955,22 @@ discard block |
||
1955 | 1955 | public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()) |
1956 | 1956 | { |
1957 | 1957 | $condition = $or_condition = array(); |
1958 | - foreach($must_terms as $term) { |
|
1958 | + foreach ($must_terms as $term) { |
|
1959 | 1959 | $condition[] = $this->quoteTerm($term); |
1960 | 1960 | } |
1961 | 1961 | |
1962 | - foreach($terms as $term) { |
|
1962 | + foreach ($terms as $term) { |
|
1963 | 1963 | $or_condition[] = $this->quoteTerm($term); |
1964 | 1964 | } |
1965 | 1965 | |
1966 | - if(!empty($or_condition)) { |
|
1966 | + if (!empty($or_condition)) { |
|
1967 | 1967 | $condition[] = "(".join(" | ", $or_condition).")"; |
1968 | 1968 | } |
1969 | 1969 | |
1970 | - foreach($exclude_terms as $term) { |
|
1970 | + foreach ($exclude_terms as $term) { |
|
1971 | 1971 | $condition[] = " NOT ".$this->quoteTerm($term); |
1972 | 1972 | } |
1973 | - $condition = $this->quoted(join(" AND ",$condition)); |
|
1973 | + $condition = $this->quoted(join(" AND ", $condition)); |
|
1974 | 1974 | return "CONTAINS($field, $condition)"; |
1975 | 1975 | } |
1976 | 1976 | |
@@ -2059,7 +2059,7 @@ discard block |
||
2059 | 2059 | public function isDatabaseNameValid($name) |
2060 | 2060 | { |
2061 | 2061 | // No funny chars, does not begin with number |
2062 | - return preg_match('/^[0-9#@]+|[\"\'\*\/\\?\:\\<\>\-\ \&\!\(\)\[\]\{\}\;\,\.\`\~\|\\\\]+/', $name)==0; |
|
2062 | + return preg_match('/^[0-9#@]+|[\"\'\*\/\\?\:\\<\>\-\ \&\!\(\)\[\]\{\}\;\,\.\`\~\|\\\\]+/', $name) == 0; |
|
2063 | 2063 | } |
2064 | 2064 | |
2065 | 2065 | public function installConfig() |