This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
||
3 | /********************************************************************************* |
||
4 | * SugarCRM Community Edition is a customer relationship management program developed by |
||
5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
||
6 | |||
7 | * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd. |
||
8 | * Copyright (C) 2011 - 2014 Salesagility Ltd. |
||
9 | * |
||
10 | * This program is free software; you can redistribute it and/or modify it under |
||
11 | * the terms of the GNU Affero General Public License version 3 as published by the |
||
12 | * Free Software Foundation with the addition of the following permission added |
||
13 | * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK |
||
14 | * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY |
||
15 | * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. |
||
16 | * |
||
17 | * This program is distributed in the hope that it will be useful, but WITHOUT |
||
18 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
||
19 | * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
||
20 | * details. |
||
21 | * |
||
22 | * You should have received a copy of the GNU Affero General Public License along with |
||
23 | * this program; if not, see http://www.gnu.org/licenses or write to the Free |
||
24 | * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
||
25 | * 02110-1301 USA. |
||
26 | * |
||
27 | * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, |
||
28 | * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected]. |
||
29 | * |
||
30 | * The interactive user interfaces in modified source and object code versions |
||
31 | * of this program must display Appropriate Legal Notices, as required under |
||
32 | * Section 5 of the GNU Affero General Public License version 3. |
||
33 | * |
||
34 | * In accordance with Section 7(b) of the GNU Affero General Public License version 3, |
||
35 | * these Appropriate Legal Notices must retain the display of the "Powered by |
||
36 | * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not |
||
37 | * reasonably feasible for technical reasons, the Appropriate Legal Notices must |
||
38 | * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM". |
||
39 | ********************************************************************************/ |
||
40 | |||
41 | /********************************************************************************* |
||
42 | |||
43 | ********************************************************************************/ |
||
44 | |||
45 | |||
46 | |||
47 | |||
48 | /** |
||
49 | * Currency.php |
||
50 | * This class encapsulates the handling of currency conversions and |
||
51 | * formatting in the SugarCRM application. |
||
52 | * |
||
53 | */ |
||
54 | class Currency extends SugarBean |
||
55 | { |
||
56 | // Stored fields |
||
57 | var $id; |
||
58 | var $iso4217; |
||
59 | var $name; |
||
60 | var $status; |
||
61 | var $conversion_rate; |
||
62 | var $deleted; |
||
63 | var $date_entered; |
||
64 | var $date_modified; |
||
65 | var $symbol; |
||
66 | var $hide = ''; |
||
67 | var $unhide = ''; |
||
68 | var $field_name_map; |
||
69 | |||
70 | var $table_name = "currencies"; |
||
71 | var $object_name = "Currency"; |
||
72 | var $module_dir = "Currencies"; |
||
73 | var $new_schema = true; |
||
74 | |||
75 | var $disable_num_format = true; |
||
76 | |||
77 | |||
78 | 34 | public function __construct() |
|
79 | { |
||
80 | 34 | parent::__construct(); |
|
81 | 34 | global $app_strings, $current_user, $sugar_config, $locale; |
|
82 | 34 | $this->field_defs['hide'] = array('name'=>'hide', 'source'=>'non-db', 'type'=>'varchar','len'=>25); |
|
83 | 34 | $this->field_defs['unhide'] = array('name'=>'unhide', 'source'=>'non-db', 'type'=>'varchar','len'=>25); |
|
84 | 34 | $this->disable_row_level_security =true; |
|
85 | 34 | } |
|
86 | |||
87 | /** |
||
88 | * convertToDollar |
||
89 | * This method accepts a currency amount and converts it to the US Dollar amount |
||
90 | * |
||
91 | * @param $amount The currency amount to convert to US Dollars |
||
92 | * @param $precision The rounding precision scale |
||
93 | * @return currency value in US Dollars from conversion |
||
94 | */ |
||
95 | 10 | function convertToDollar($amount, $precision = 6) { |
|
96 | 10 | return $this->conversion_rate ? round(($amount / $this->conversion_rate), $precision) : 0; |
|
97 | } |
||
98 | |||
99 | /** |
||
100 | * convertFromCollar |
||
101 | * This method accepts a US Dollar amount and returns a currency amount |
||
102 | * with the conversion rate applied to it. |
||
103 | * |
||
104 | * @param $amount The currency amount in US Dollars |
||
105 | * @param $precision The rounding precision scale |
||
106 | * @return currency value from US Dollar conversion |
||
107 | */ |
||
108 | 2 | function convertFromDollar($amount, $precision = 6){ |
|
109 | 2 | return round(($amount * $this->conversion_rate), $precision); |
|
110 | } |
||
111 | |||
112 | /** |
||
113 | * getDefaultCurrencyName |
||
114 | * |
||
115 | * Returns the default currency name as defined in application |
||
116 | * @return String value of default currency name |
||
117 | */ |
||
118 | 19 | function getDefaultCurrencyName(){ |
|
119 | 19 | global $sugar_config; |
|
120 | 19 | return $sugar_config['default_currency_name']; |
|
121 | } |
||
122 | |||
123 | /** |
||
124 | * getDefaultCurrencySymbol |
||
125 | * |
||
126 | * Returns the default currency symobol in application |
||
127 | * @return String value of default currency symbol(e.g. $) |
||
128 | */ |
||
129 | 19 | function getDefaultCurrencySymbol(){ |
|
130 | 19 | global $sugar_config; |
|
131 | 19 | return $sugar_config['default_currency_symbol']; |
|
132 | } |
||
133 | |||
134 | /** |
||
135 | * getDefaultISO4217 |
||
136 | * |
||
137 | * Returns the default ISO 4217 standard currency code value |
||
138 | * @return String value for the ISO 4217 standard code(e.g. EUR) |
||
139 | */ |
||
140 | 19 | function getDefaultISO4217(){ |
|
141 | 19 | global $sugar_config; |
|
142 | 19 | return $sugar_config['default_currency_iso4217']; |
|
143 | } |
||
144 | |||
145 | /** |
||
146 | * retrieveIDBySmbol |
||
147 | * |
||
148 | * Returns the id value for given currency symbol in Currencies table |
||
149 | * and currency entry for symbol is not set to deleted. |
||
150 | * |
||
151 | * @param $symbol Symbol value |
||
152 | * @return String id value for symbol defined in Currencies table, blank String value |
||
153 | * if none found |
||
154 | */ |
||
155 | 1 | function retrieveIDBySymbol($symbol) { |
|
156 | 1 | $query = "SELECT id FROM currencies WHERE symbol='$symbol' AND deleted=0;"; |
|
157 | 1 | $result = $this->db->query($query); |
|
158 | 1 | if($result){ |
|
159 | 1 | $row = $this->db->fetchByAssoc($result); |
|
160 | 1 | if($row){ |
|
161 | return $row['id']; |
||
162 | } |
||
163 | } |
||
164 | |||
165 | 1 | return ''; |
|
166 | } |
||
167 | |||
168 | 1 | function list_view_parse_additional_sections(&$list_form) { |
|
169 | 1 | global $isMerge; |
|
170 | |||
171 | 1 | if(isset($isMerge) && $isMerge && $this->id != '-99'){ |
|
172 | 1 | $list_form->assign('PREROW', '<input name="mergecur[]" type="checkbox" value="'.$this->id.'">'); |
|
173 | } |
||
174 | 1 | return $list_form; |
|
175 | } |
||
176 | |||
177 | 1 | function retrieve_id_by_name($name) { |
|
178 | 1 | $query = "select id from currencies where name='$name' and deleted=0;"; |
|
179 | 1 | $result = $this->db->query($query); |
|
180 | 1 | if($result){ |
|
181 | 1 | $row = $this->db->fetchByAssoc($result); |
|
182 | 1 | if($row){ |
|
183 | return $row['id']; |
||
184 | } |
||
185 | } |
||
186 | 1 | return ''; |
|
187 | } |
||
188 | |||
189 | 18 | function retrieve($id = -99, $encode = true, $deleted = true){ |
|
190 | 18 | if($id == '-99'){ |
|
191 | 7 | $this->name = $this->getDefaultCurrencyName(); |
|
192 | 7 | $this->symbol = $this->getDefaultCurrencySymbol(); |
|
193 | 7 | $this->id = '-99'; |
|
194 | 7 | $this->conversion_rate = 1; |
|
195 | 7 | $this->iso4217 = $this->getDefaultISO4217(); |
|
196 | 7 | $this->deleted = 0; |
|
197 | 7 | $this->status = 'Active'; |
|
198 | 7 | $this->hide = '<!--'; |
|
199 | 7 | $this->unhide = '-->'; |
|
200 | }else{ |
||
201 | 12 | parent::retrieve($id, $encode, $deleted); |
|
202 | } |
||
203 | 18 | if(!isset($this->name) || $this->deleted == 1){ |
|
204 | 12 | $this->name = $this->getDefaultCurrencyName(); |
|
205 | 12 | $this->symbol = $this->getDefaultCurrencySymbol(); |
|
206 | 12 | $this->conversion_rate = 1; |
|
207 | 12 | $this->iso4217 = $this->getDefaultISO4217(); |
|
208 | 12 | $this->id = '-99'; |
|
209 | 12 | $this->deleted = 0; |
|
210 | 12 | $this->status = 'Active'; |
|
211 | 12 | $this->hide = '<!--'; |
|
212 | 12 | $this->unhide = '-->'; |
|
213 | } |
||
214 | 18 | return $this; |
|
215 | } |
||
216 | |||
217 | /** |
||
218 | * Method for returning the currency symbol, must return chr(2) for the € symbol |
||
219 | * to display correctly in pdfs |
||
220 | * Parameters: |
||
221 | * none |
||
222 | * Returns: |
||
223 | * $symbol otherwise chr(2) for euro symbol |
||
224 | */ |
||
225 | 1 | function getPdfCurrencySymbol() { |
|
226 | 1 | if($this->symbol == '€' || $this->symbol == '€') |
|
227 | return chr(2); |
||
228 | 1 | return $this->symbol; |
|
229 | } |
||
230 | 1 | function get_list_view_data() { |
|
231 | 1 | $this->conversion_rate = format_number($this->conversion_rate, 10, 10); |
|
232 | 1 | $data = parent::get_list_view_data(); |
|
233 | 1 | return $data; |
|
234 | } |
||
235 | 1 | function save($check_notify = FALSE) { |
|
236 | 1 | sugar_cache_clear('currency_list'); |
|
237 | 1 | return parent::save($check_notify); |
|
238 | } |
||
239 | } // end currency class |
||
240 | |||
241 | /** |
||
242 | * currency_format_number |
||
243 | * |
||
244 | * This method is a wrapper designed exclusively for formatting currency values |
||
245 | * with the assumption that the method caller wants a currency formatted value |
||
246 | * matching his/her user preferences(if set) or the system configuration defaults |
||
247 | *(if user preferences are not defined). |
||
248 | * |
||
249 | * @param $amount The amount to be formatted |
||
250 | * @param $params Optional parameters(see @format_number) |
||
251 | * @return String representation of amount with formatting applied |
||
252 | */ |
||
253 | function currency_format_number($amount, $params = array()) { |
||
254 | 2 | global $locale; |
|
255 | 2 | if(isset($params['round']) && is_int($params['round'])){ |
|
256 | 1 | $real_round = $params['round']; |
|
257 | }else{ |
||
258 | 2 | $real_round = $locale->getPrecedentPreference('default_currency_significant_digits'); |
|
259 | } |
||
260 | 2 | if(isset($params['decimals']) && is_int($params['decimals'])){ |
|
261 | 1 | $real_decimals = $params['decimals']; |
|
262 | }else{ |
||
263 | 2 | $real_decimals = $locale->getPrecedentPreference('default_currency_significant_digits'); |
|
264 | } |
||
265 | 2 | $real_round = $real_round == '' ? 0 : $real_round; |
|
266 | 2 | $real_decimals = $real_decimals == '' ? 0 : $real_decimals; |
|
267 | |||
268 | 2 | $showCurrencySymbol = $locale->getPrecedentPreference('default_currency_symbol') != '' ? true : false; |
|
269 | 2 | if($showCurrencySymbol && !isset($params['currency_symbol'])) { |
|
270 | 2 | $params["currency_symbol"] = true; |
|
271 | } |
||
272 | 2 | return format_number($amount, $real_round, $real_decimals, $params); |
|
273 | |||
274 | } |
||
275 | |||
276 | /** |
||
277 | * format_number(deprecated) |
||
278 | * |
||
279 | * This method accepts an amount and formats it given the user's preferences. |
||
280 | * Should the values set in the user preferences be invalid then it will |
||
281 | * apply the system wide Sugar configuration values. Calls to |
||
282 | * getPrecendentPreference() method in Localization.php are made that |
||
283 | * handle this logic. |
||
284 | * |
||
285 | * Going forward with Sugar 4.5.0e+ implementations, users of this class should |
||
286 | * simple call this function with $amount parameter and leave it to the |
||
287 | * class to locate and apply the appropriate formatting. |
||
288 | * |
||
289 | * One of the problems is that there is considerable legacy code that is using |
||
290 | * this method for non currency formatting. In other words, the format_number |
||
291 | * method may be called to just display a number like 1,000 formatted appropriately. |
||
292 | * |
||
293 | * Also, issues about responsibilities arise. Currently the callers of this function |
||
294 | * are responsible for passing in the appropriate decimal and number rounding digits |
||
295 | * as well as parameters to control displaying the currency symbol or not. |
||
296 | * |
||
297 | * @param $amount The currency amount to apply formatting to |
||
298 | * @param $round Integer value for number of places to round to |
||
299 | * @param $decimals Integer value for number of decimals to round to |
||
300 | * @param $params Array of additional parameter values |
||
301 | * |
||
302 | * |
||
303 | * The following are passed in as an array of params: |
||
304 | * boolean $params['currency_symbol'] - true to display currency symbol |
||
305 | * boolean $params['convert'] - true to convert from USD dollar |
||
306 | * boolean $params['percentage'] - true to display % sign |
||
307 | * boolean $params['symbol_space'] - true to have space between currency symbol and amount |
||
308 | * String $params['symbol_override'] - string to over default currency symbol |
||
309 | * String $params['type'] - pass in 'pdf' for pdf currency symbol conversion |
||
310 | * String $params['currency_id'] - currency_id to retreive, defaults to current user |
||
311 | * String $params['human'] - formatting that truncates the first thousands and appends "k" |
||
312 | * @return String formatted currency value |
||
313 | * @see include/Localization/Localization.php |
||
314 | */ |
||
315 | function format_number($amount, $round = null, $decimals = null, $params = array()) { |
||
316 | 5 | global $app_strings, $current_user, $sugar_config, $locale; |
|
317 | 5 | static $current_users_currency = null; |
|
318 | 5 | static $last_override_currency = null; |
|
319 | 5 | static $override_currency_id = null; |
|
320 | 5 | static $currency; |
|
321 | |||
322 | 5 | $seps = get_number_seperators(); |
|
323 | 5 | $num_grp_sep = $seps[0]; |
|
324 | 5 | $dec_sep = $seps[1]; |
|
325 | |||
326 | // cn: bug 8522 - sig digits not honored in pdfs |
||
327 | 5 | if(is_null($decimals)) { |
|
328 | 2 | $decimals = $locale->getPrecision(); |
|
329 | } |
||
330 | 5 | if(is_null($round)) { |
|
331 | 2 | $round = $locale->getPrecision(); |
|
332 | } |
||
333 | |||
334 | // only create a currency object if we need it |
||
335 | 5 | if((!empty($params['currency_symbol']) && $params['currency_symbol']) || |
|
336 | 3 | (!empty($params['convert']) && $params['convert']) || |
|
337 | 5 | (!empty($params['currency_id']))) { |
|
338 | // if we have an override currency_id |
||
339 | 3 | if(!empty($params['currency_id'])) { |
|
340 | if($override_currency_id != $params['currency_id']) { |
||
341 | $override_currency_id = $params['currency_id']; |
||
342 | $currency = new Currency(); |
||
343 | $currency->retrieve($override_currency_id); |
||
344 | $last_override_currency = $currency; |
||
345 | } else { |
||
346 | $currency = $last_override_currency; |
||
347 | } |
||
348 | |||
349 | 3 | } elseif(!isset($current_users_currency)) { // else use current user's |
|
350 | 1 | $current_users_currency = new Currency(); |
|
351 | 1 | if($current_user->getPreference('currency')) $current_users_currency->retrieve($current_user->getPreference('currency')); |
|
352 | 1 | else $current_users_currency->retrieve('-99'); // use default if none set |
|
353 | 1 | $currency = $current_users_currency; |
|
354 | } |
||
355 | } |
||
356 | 5 | if(!empty($params['convert']) && $params['convert']) { |
|
357 | 1 | $amount = $currency->convertFromDollar($amount, 6); |
|
358 | } |
||
359 | |||
360 | 5 | if(!empty($params['currency_symbol']) && $params['currency_symbol']) { |
|
361 | 3 | if(!empty($params['symbol_override'])) { |
|
362 | $symbol = $params['symbol_override']; |
||
363 | } |
||
364 | 3 | elseif(!empty($params['type']) && $params['type'] == 'pdf') { |
|
365 | $symbol = $currency->getPdfCurrencySymbol(); |
||
366 | $symbol_space = false; |
||
367 | } else { |
||
368 | 3 | if(empty($currency->symbol)) |
|
369 | $symbol = $currency->getDefaultCurrencySymbol(); |
||
370 | else |
||
371 | 3 | $symbol = $currency->symbol; |
|
372 | 3 | $symbol_space = true; |
|
373 | } |
||
374 | } else { |
||
375 | 3 | $symbol = ''; |
|
376 | } |
||
377 | |||
378 | 5 | if(isset($params['charset_convert'])) { |
|
379 | $symbol = $locale->translateCharset($symbol, 'UTF-8', $locale->getExportCharset()); |
||
380 | } |
||
381 | |||
382 | 5 | if(empty($params['human'])) { |
|
383 | 5 | $amount = number_format(round($amount, $round), $decimals, $dec_sep, $num_grp_sep); |
|
384 | 5 | $amount = format_place_symbol($amount, $symbol,(empty($params['symbol_space']) ? false : true)); |
|
385 | } else { |
||
386 | // If amount is more greater than a thousand(positive or negative) |
||
387 | if(strpos($amount, '.') > 0) { |
||
388 | $checkAmount = strlen(substr($amount, 0, strpos($amount, '.'))); |
||
389 | } |
||
390 | |||
391 | if($checkAmount >= 1000 || $checkAmount <= -1000) { |
||
392 | $amount = round(($amount / 1000), 0); |
||
393 | $amount = number_format($amount, 0, $dec_sep, $num_grp_sep); // add for SI bug 52498 |
||
394 | $amount = $amount . 'k'; |
||
395 | $amount = format_place_symbol($amount, $symbol,(empty($params['symbol_space']) ? false : true)); |
||
396 | } else { |
||
397 | $amount = format_place_symbol($amount, $symbol,(empty($params['symbol_space']) ? false : true)); |
||
398 | } |
||
399 | } |
||
400 | |||
401 | 5 | if(!empty($params['percentage']) && $params['percentage']) $amount .= $app_strings['LBL_PERCENTAGE_SYMBOL']; |
|
402 | 5 | return $amount; |
|
403 | |||
404 | } //end function format_number |
||
405 | |||
406 | |||
407 | |||
408 | function format_place_symbol($amount, $symbol, $symbol_space) { |
||
409 | 6 | if($symbol != '') { |
|
410 | 4 | if($symbol_space == true) { |
|
411 | 1 | $amount = $symbol . ' ' . $amount; |
|
412 | } else { |
||
413 | 4 | $amount = $symbol . $amount; |
|
414 | } |
||
415 | } |
||
416 | 6 | return $amount; |
|
417 | } |
||
418 | |||
419 | function unformat_number($string) { |
||
420 | // Just in case someone passes an already unformatted number through. |
||
421 | 22 | if ( !is_string($string) ) { |
|
422 | 1 | return $string; |
|
423 | } |
||
424 | |||
425 | 22 | static $currency = null; |
|
426 | 22 | if(!isset($currency)) { |
|
427 | 1 | global $current_user; |
|
428 | 1 | $currency = new Currency(); |
|
429 | 1 | if(!empty($current_user->id)){ |
|
430 | if($current_user->getPreference('currency')){ |
||
431 | $currency->retrieve($current_user->getPreference('currency')); |
||
432 | } |
||
433 | else{ |
||
434 | $currency->retrieve('-99'); // use default if none set |
||
435 | } |
||
436 | }else{ |
||
437 | 1 | $currency->retrieve('-99'); // use default if none set |
|
438 | } |
||
439 | } |
||
440 | |||
441 | 22 | $seps = get_number_seperators(); |
|
442 | // remove num_grp_sep and replace decimal separator with decimal |
||
443 | 22 | $string = trim(str_replace(array($seps[0], $seps[1], $currency->symbol), array('', '.', ''), $string)); |
|
444 | 22 | if(preg_match('/^[+-]?\d(\.\d+)?[Ee]([+-]?\d+)?$/', $string)) $string = sprintf("%.0f", $string);//for scientific number format. After round(), we may get this number type. |
|
445 | 22 | preg_match('/[\-\+]?[0-9\.]*/', $string, $string); |
|
446 | |||
447 | 22 | $out_number = trim($string[0]); |
|
448 | 22 | if ( $out_number == '' ) { |
|
449 | 8 | return ''; |
|
450 | } else { |
||
451 | 17 | return (float)$out_number; |
|
452 | } |
||
453 | } |
||
454 | |||
455 | // deprecated use format_number() above |
||
456 | function format_money($amount, $for_display = TRUE) { |
||
457 | // This function formats an amount for display. |
||
458 | // Later on, this should be converted to use proper thousand and decimal seperators |
||
459 | // Currently, it stays closer to the existing format, and just rounds to two decimal points |
||
460 | 1 | if(isset($amount)) { |
|
461 | 1 | if($for_display) { |
|
462 | 1 | return sprintf("%0.02f",$amount); |
|
463 | } else { |
||
464 | // If it's an editable field, don't use a thousand seperator. |
||
465 | // Or perhaps we will want to, but it doesn't matter right now. |
||
466 | 1 | return sprintf("%0.02f",$amount); |
|
467 | } |
||
468 | } else { |
||
469 | return; |
||
470 | } |
||
471 | } |
||
472 | |||
473 | /** |
||
474 | * Returns user/system preference for number grouping separator character(default ",") and the decimal separator |
||
475 | *(default "."). Special case: when num_grp_sep is ".", it will return NULL as the num_grp_sep. |
||
476 | * @return array Two element array, first item is num_grp_sep, 2nd item is dec_sep |
||
477 | */ |
||
478 | function get_number_seperators($reset_sep = false) |
||
479 | { |
||
480 | 37 | global $current_user, $sugar_config; |
|
481 | |||
482 | 37 | static $dec_sep = null; |
|
483 | 37 | static $num_grp_sep = null; |
|
484 | |||
485 | // This is typically only used during unit-tests |
||
486 | // TODO: refactor this. unit tests should not have static dependencies |
||
487 | 37 | if ($reset_sep) |
|
488 | { |
||
489 | $dec_sep = $num_grp_sep = null; |
||
490 | } |
||
491 | |||
492 | 37 | if ($dec_sep == null) |
|
493 | { |
||
494 | 1 | $dec_sep = $sugar_config['default_decimal_seperator']; |
|
495 | 1 | if (!empty($current_user->id)) |
|
496 | { |
||
497 | $user_dec_sep = $current_user->getPreference('dec_sep'); |
||
498 | $dec_sep = (empty($user_dec_sep) ? $sugar_config['default_decimal_seperator'] : $user_dec_sep); |
||
499 | } |
||
500 | } |
||
501 | |||
502 | 37 | if ($num_grp_sep == null) |
|
503 | { |
||
504 | 1 | $num_grp_sep = $sugar_config['default_number_grouping_seperator']; |
|
505 | 1 | if (!empty($current_user->id)) |
|
506 | { |
||
507 | $user_num_grp_sep = $current_user->getPreference('num_grp_sep'); |
||
508 | $num_grp_sep = (empty($user_num_grp_sep) ? $sugar_config['default_number_grouping_seperator'] : $user_num_grp_sep); |
||
509 | } |
||
510 | } |
||
511 | |||
512 | 37 | return array($num_grp_sep, $dec_sep); |
|
513 | } |
||
514 | |||
515 | /** |
||
516 | * toString |
||
517 | * |
||
518 | * Utility function to print out some information about Currency instance. |
||
519 | */ |
||
520 | function toString($echo = true) { |
||
521 | 1 | $s = "\$m_currency_round=$m_currency_round \n" . |
|
522 | 1 | "\$m_currency_decimal=$m_currency_decimal \n" . |
|
523 | 1 | "\$m_currency_symbol=$m_currency_symbol \n" . |
|
524 | 1 | "\$m_currency_iso=$m_currency_iso \n" . |
|
525 | 1 | "\$m_currency_name=$m_currency_name \n"; |
|
526 | |||
527 | 1 | if($echo) { |
|
528 | echo $s; |
||
529 | } |
||
530 | |||
531 | 1 | return $s; |
|
532 | } |
||
533 | |||
534 | function getCurrencyDropDown($focus, $field='currency_id', $value='', $view='DetailView'){ |
||
535 | 1 | $view = ucfirst($view); |
|
536 | 1 | if($view == 'EditView' || $view == 'MassUpdate' || $view == 'QuickCreate' || $view == 'ConvertLead'){ |
|
537 | 1 | if ( isset($_REQUEST[$field]) && !empty($_REQUEST[$field]) ) { |
|
538 | $value = $_REQUEST[$field]; |
||
539 | } elseif ( empty($focus->id) ) { |
||
540 | 1 | $value = $GLOBALS['current_user']->getPreference('currency'); |
|
541 | 1 | if ( empty($value) ) { |
|
542 | // -99 is the system default currency |
||
543 | 1 | $value = -99; |
|
544 | } |
||
545 | } |
||
546 | 1 | require_once('modules/Currencies/ListCurrency.php'); |
|
547 | 1 | $currency_fields = array(); |
|
548 | //Bug 18276 - Fix for php 5.1.6 |
||
549 | 1 | $defs=$focus->field_defs; |
|
550 | // |
||
551 | 1 | foreach($defs as $name=>$key){ |
|
552 | if($key['type'] == 'currency'){ |
||
553 | $currency_fields[]= $name; |
||
554 | } |
||
555 | } |
||
556 | 1 | $currency = new ListCurrency(); |
|
557 | 1 | $selectCurrency = $currency->getSelectOptions($value); |
|
558 | |||
559 | 1 | $currency->setCurrencyFields($currency_fields); |
|
560 | 1 | $html = '<select name="'; |
|
561 | // If it's a lead conversion (ConvertLead view), add the module_name before the $field |
||
562 | 1 | if ($view == "ConvertLead") { |
|
563 | $html .= $focus->module_name; |
||
564 | } |
||
565 | 1 | $html .= $field. '" id="' . $field . '_select" '; |
|
566 | 1 | if($view != 'MassUpdate') |
|
567 | 1 | $html .= 'onchange="CurrencyConvertAll(this.form);"'; |
|
568 | 1 | $html .= '>'. $selectCurrency . '</select>'; |
|
569 | 1 | if($view != 'MassUpdate') |
|
570 | 1 | $html .= $currency->getJavascript(); |
|
571 | 1 | return $html; |
|
572 | }else{ |
||
573 | |||
574 | 1 | $currency = new Currency(); |
|
575 | 1 | $currency->retrieve($value); |
|
576 | 1 | return $currency->name; |
|
577 | } |
||
578 | |||
579 | } |
||
580 | |||
581 | function getCurrencyNameDropDown($focus, $field='currency_name', $value='', $view='DetailView') |
||
582 | { |
||
583 | 1 | if($view == 'EditView' || $view == 'MassUpdate' || $view == 'QuickCreate'){ |
|
584 | 1 | require_once('modules/Currencies/ListCurrency.php'); |
|
585 | 1 | $currency_fields = array(); |
|
586 | //Bug 18276 - Fix for php 5.1.6 |
||
587 | 1 | $defs=$focus->field_defs; |
|
588 | // |
||
589 | 1 | foreach($defs as $name=>$key){ |
|
590 | if($key['type'] == 'currency'){ |
||
591 | $currency_fields[]= $name; |
||
592 | } |
||
593 | } |
||
594 | 1 | $currency = new ListCurrency(); |
|
595 | 1 | $currency->lookupCurrencies(); |
|
596 | 1 | $listitems = array(); |
|
597 | 1 | foreach ( $currency->list as $item ) |
|
0 ignored issues
–
show
|
|||
598 | 1 | $listitems[$item->name] = $item->name; |
|
599 | 1 | return '<select name="'.$field.'" id="'.$field.'" />'. |
|
600 | 1 | get_select_options_with_id($listitems,$value).'</select>'; |
|
601 | }else{ |
||
602 | |||
603 | 1 | $currency = new Currency(); |
|
604 | 1 | if ( isset($focus->currency_id) ) { |
|
605 | $currency_id = $focus->currency_id; |
||
606 | } else { |
||
607 | 1 | $currency_id = -99; |
|
608 | } |
||
609 | 1 | $currency->retrieve($currency_id); |
|
610 | 1 | return $currency->name; |
|
611 | } |
||
612 | } |
||
613 | |||
614 | function getCurrencySymbolDropDown($focus, $field='currency_name', $value='', $view='DetailView') |
||
615 | { |
||
616 | 1 | if($view == 'EditView' || $view == 'MassUpdate' || $view == 'QuickCreate'){ |
|
617 | 1 | require_once('modules/Currencies/ListCurrency.php'); |
|
618 | 1 | $currency_fields = array(); |
|
619 | //Bug 18276 - Fix for php 5.1.6 |
||
620 | 1 | $defs=$focus->field_defs; |
|
621 | // |
||
622 | 1 | foreach($defs as $name=>$key){ |
|
623 | if($key['type'] == 'currency'){ |
||
624 | $currency_fields[]= $name; |
||
625 | } |
||
626 | } |
||
627 | 1 | $currency = new ListCurrency(); |
|
628 | 1 | $currency->lookupCurrencies(); |
|
629 | 1 | $listitems = array(); |
|
630 | 1 | foreach ( $currency->list as $item ) |
|
0 ignored issues
–
show
The expression
$currency->list of type array|null is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
631 | 1 | $listitems[$item->symbol] = $item->symbol; |
|
632 | 1 | return '<select name="'.$field.'" id="'.$field.'" />'. |
|
633 | 1 | get_select_options_with_id($listitems,$value).'</select>'; |
|
634 | }else{ |
||
635 | |||
636 | 1 | $currency = new Currency(); |
|
637 | 1 | if ( isset($focus->currency_id) ) { |
|
638 | $currency_id = $focus->currency_id; |
||
639 | } else { |
||
640 | 1 | $currency_id = -99; |
|
641 | } |
||
642 | 1 | $currency->retrieve($currency_id); |
|
643 | 1 | return $currency->name; |
|
644 | } |
||
645 | } |
||
646 | |||
647 | ?> |
||
648 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.