2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
39 function wrapTD($html, $options){
40 return wrapTag("td",$html, $options);
43 function wrapTR($html, $options){
44 return wrapTag("tr",$html, $options);
47 function wrapTable($html, $options){
48 return wrapTag("table",$html, $options);
51 function wrapB($html){
52 return "<b>".$html."</b>";
55 function wrapI($html){
56 return "<i>".$html."</i>";
58 function wrapTag($tag, $html, $options){
59 // Wrap the tags defined in the options array (like b, i, font... tags)
61 foreach($options as $k=>$v){
63 $html = wrapTag($k, "$html", $v);
67 // wrap the HTML content with the passed tag
70 foreach($options as $k=>$v){
72 $return .= " $k=".'"'.$v.'"';
76 return $return.">".$html."</$tag>";
80 * This function prepare a string to be ready for the PDF printing.
84 function prepare_string($string){
86 $string = html_entity_decode($string, ENT_QUOTES);
87 // return $locale->translateCharset($string, 'UTF-8', $locale->getExportCharset());
91 * Copy of format_number() from currency with fix for sugarpdf.
92 * @return String formatted currency value
93 * @see modules/Currencies/Currency.php
95 function format_number_sugarpdf($amount, $round = null, $decimals = null, $params = array()) {
96 global $app_strings, $current_user, $sugar_config, $locale;
97 static $current_users_currency = null;
98 static $last_override_currency = null;
99 static $override_currency_id = null;
102 $seps = get_number_seperators();
103 $num_grp_sep = $seps[0];
106 // cn: bug 8522 - sig digits not honored in pdfs
107 if(is_null($decimals)) {
108 $decimals = $locale->getPrecision();
110 if(is_null($round)) {
111 $round = $locale->getPrecision();
114 // only create a currency object if we need it
115 if((!empty($params['currency_symbol']) && $params['currency_symbol']) ||
116 (!empty($params['convert']) && $params['convert']) ||
117 (!empty($params['currency_id']))) {
118 // if we have an override currency_id
119 if(!empty($params['currency_id'])) {
120 if($override_currency_id != $params['currency_id']) {
121 $override_currency_id = $params['currency_id'];
122 $currency = new Currency();
123 $currency->retrieve($override_currency_id);
124 $last_override_currency = $currency;
126 $currency = $last_override_currency;
129 } elseif(!isset($current_users_currency)) { // else use current user's
130 $current_users_currency = new Currency();
131 if($current_user->getPreference('currency')) $current_users_currency->retrieve($current_user->getPreference('currency'));
132 else $current_users_currency->retrieve('-99'); // use default if none set
133 $currency = $current_users_currency;
136 if(!empty($params['convert']) && $params['convert']) {
137 $amount = $currency->convertFromDollar($amount, 6);
140 if(!empty($params['currency_symbol']) && $params['currency_symbol']) {
141 if(!empty($params['symbol_override'])) {
142 $symbol = $params['symbol_override'];
146 /*elseif(!empty($params['type']) && $params['type'] == 'pdf') {
147 $symbol = $currency->getPdfCurrencySymbol();
148 $symbol_space = false;
150 elseif(!empty($params['type']) && $params['type'] == 'sugarpdf') {
151 $symbol = $currency->symbol;
152 $symbol_space = false;
157 if(empty($currency->symbol))
158 $symbol = $currency->getDefaultCurrencySymbol();
160 $symbol = $currency->symbol;
161 $symbol_space = true;
167 if(isset($params['charset_convert'])) {
168 $symbol = $locale->translateCharset($symbol, 'UTF-8', $locale->getExportCharset());
171 if(empty($params['human'])) {
172 $amount = number_format(round($amount, $round), $decimals, $dec_sep, $num_grp_sep);
173 $amount = format_place_symbol($amount, $symbol,(empty($params['symbol_space']) ? false : true));
175 // If amount is more greater than a thousand(postiive or negative)
176 if(strpos($amount, '.') > 0) {
177 $checkAmount = strlen(substr($amount, 0, strpos($amount, '.')));
180 if($checkAmount >= 1000 || $checkAmount <= -1000) {
181 $amount = round(($amount / 1000), 0);
182 $amount = $amount . 'k';
183 $amount = format_place_symbol($amount, $symbol,(empty($params['symbol_space']) ? false : true));
185 $amount = format_place_symbol($amount, $symbol,(empty($params['symbol_space']) ? false : true));
189 if(!empty($params['percentage']) && $params['percentage']) $amount .= $app_strings['LBL_PERCENTAGE_SYMBOL'];
192 } //end function format_number