2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
41 * @deprecated use DBManager::convert() instead.
43 function db_convert($string, $type, $additional_parameters=array(),$additional_parameters_oracle_only=array())
45 return $GLOBALS['db']->convert($string, $type, $additional_parameters, $additional_parameters_oracle_only);
49 * @deprecated use DBManager::concat() instead.
51 function db_concat($table, $fields)
53 return $GLOBALS['db']->concat($table, $fields);
57 * @deprecated use DBManager::fromConvert() instead.
59 function from_db_convert($string, $type)
61 return $GLOBALS['db']->fromConvert($string, $type);
70 $GLOBALS['toHTML_keys'] = array_keys($toHTML);
71 $GLOBALS['toHTML_values'] = array_values($toHTML);
74 * Replaces specific characters with their HTML entity values
75 * @param string $string String to check/replace
76 * @param bool $encode Default true
79 * @todo Make this utilize the external caching mechanism after re-testing (see
82 * Bug 49489 - removed caching of to_html strings as it was consuming memory and
85 function to_html($string, $encode=true){
92 if($encode && is_string($string)){
94 * cn: bug 13376 - handle ampersands separately
95 * credit: ashimamura via bug portal
97 //$string = str_replace("&", "&", $string);
100 { // cn: causing errors in i18n test suite ($toHTML is non-array)
101 $string = str_ireplace($GLOBALS['toHTML_keys'],$GLOBALS['toHTML_values'],$string);
109 * Replaces specific HTML entity values with the true characters
110 * @param string $string String to check/replace
111 * @param bool $encode Default true
114 function from_html($string, $encode=true) {
115 if (!is_string($string) || !$encode) {
120 static $toHTML_values = null;
121 static $toHTML_keys = null;
122 static $cache = array();
123 if (!empty($toHTML) && is_array($toHTML) && (!isset($toHTML_values) || !empty($GLOBALS['from_html_cache_clear']))) {
124 $toHTML_values = array_values($toHTML);
125 $toHTML_keys = array_keys($toHTML);
128 // Bug 36261 - Decode & so we can handle double encoded entities
129 $string = str_ireplace("&", "&", $string);
131 if (!isset($cache[$string])) {
132 $cache[$string] = str_ireplace($toHTML_values, $toHTML_keys, $string);
134 return $cache[$string];
138 * Return a version of $proposed that can be used as a column name in any of our supported databases
139 * Practically this means no longer than 25 characters as the smallest identifier length for our supported DBs is 30 chars for Oracle plus we add on at least four characters in some places (for indicies for example)
140 * @param string $name Proposed name for the column
141 * @param string $ensureUnique
142 * @param int $maxlen Deprecated and ignored
143 * @return string Valid column name trimmed to right length and with invalid characters removed
145 function getValidDBName ($name, $ensureUnique = false, $maxLen = 30)
147 return DBManagerFactory::getInstance()->getValidDBName($name, $ensureUnique);
154 * Utility to perform the check during install to ensure a database name entered by the user
155 * is valid based on the type of database server
156 * @param string $name Proposed name for the DB
157 * @param string $dbType Type of database server
158 * @return bool true or false based on the validity of the DB name
160 function isValidDBName($name, $dbType)
162 $db = DBManagerFactory::getTypeInstance($dbType);
163 return $db->isDatabaseNameValid($name);