| ');
$phpinfo = preg_replace('/ | ]*>([^<]+)<\/th>/',"\\1",$phpinfo);
$phpinfo = preg_replace('/ | ]*>([^<]+)<\/td>/',"\\1",$phpinfo);
$parsedInfo = preg_split('/([^<]+<\/h.>)/', $phpinfo, -1, PREG_SPLIT_DELIM_CAPTURE);
$match = '';
$version = '';
$returnInfo = array();
if(preg_match('/PHP Version ([^<]+)<\/h1>/', $phpinfo, $version)) {
$returnInfo['PHP Version'] = $version[1];
}
for ($i=1; $i([^<]+)<\/h.>/', $parsedInfo[$i], $match)) {
$vName = trim($match[1]);
$parsedInfo2 = explode("\n",$parsedInfo[$i+1]);
foreach ($parsedInfo2 AS $vOne) {
$vPat = '([^<]+)<\/info>';
$vPat3 = "/$vPat\s*$vPat\s*$vPat/";
$vPat2 = "/$vPat\s*$vPat/";
if (preg_match($vPat3,$vOne,$match)) { // 3cols
$returnInfo[$vName][trim($match[1])] = array(trim($match[2]),trim($match[3]));
} elseif (preg_match($vPat2,$vOne,$match)) { // 2cols
$returnInfo[$vName][trim($match[1])] = trim($match[2]);
}
}
} elseif(true) {
}
}
return $returnInfo;
}
/**
* This function will take a string that has tokens like {0}, {1} and will replace
* those tokens with the args provided
* @param $format string to format
* @param $args args to replace
* @return $result a formatted string
*/
function string_format($format, $args){
$result = $format;
for($i = 0; $i < count($args); $i++){
$result = str_replace('{'.$i.'}', $args[$i], $result);
}
return $result;
}
/**
* Generate a string for displaying a unique identifier that is composed
* of a system_id and number. This is use to allow us to generate quote
* numbers using a DB auto-increment key from offline clients and still
* have the number be unique (since it is modified by the system_id.
*
* @param $num of bean
* @param $system_id from system
* @return $result a formatted string
*/
function format_number_display($num, $system_id){
global $sugar_config;
if(isset($num) && !empty($num)){
$num=unformat_number($num);
if(isset($system_id) && $system_id == 1){
return sprintf("%d", $num);
}
else{
return sprintf("%d-%d", $num, $system_id);
}
}
}
function checkLoginUserStatus(){
}
/**
* This function will take a number and system_id and format
* @param $url URL containing host to append port
* @param $port the port number - if '' is passed, no change to url
* @return $resulturl the new URL with the port appended to the host
*/
function appendPortToHost($url, $port)
{
$resulturl = $url;
// if no port, don't change the url
if($port != '')
{
$split = explode("/", $url);
//check if it starts with http, in case they didn't include that in url
if(str_begin($url, 'http'))
{
//third index ($split[2]) will be the host
$split[2] .= ":".$port;
}
else // otherwise assumed to start with host name
{
//first index ($split[0]) will be the host
$split[0] .= ":".$port;
}
$resulturl = implode("/", $split);
}
return $resulturl;
}
/**
* Singleton to return JSON object
* @return JSON object
*/
function getJSONobj() {
static $json = null;
if(!isset($json)) {
require_once('include/JSON.php');
$json = new JSON(JSON_LOOSE_TYPE);
}
return $json;
}
require_once('include/utils/db_utils.php');
require_once('include/utils/user_utils.php');
//check to see if custom utils exists
if(file_exists('custom/include/custom_utils.php')){
include_once('custom/include/custom_utils.php');
}
/**
* Set default php.ini settings for entry points
*/
function setPhpIniSettings() {
// zlib module
if(function_exists('gzclose') && headers_sent() == false) {
ini_set('zlib.output_compression', 1);
}
// mbstring module
//nsingh: breaks zip/unzip functionality. Commenting out 4/23/08
/*if(function_exists('mb_strlen')) {
ini_set('mbstring.func_overload', 7);
ini_set('mbstring.internal_encoding', 'UTF-8');
}*/
// http://us3.php.net/manual/en/ref.pcre.php#ini.pcre.backtrack-limit
// starting with 5.2.0, backtrack_limit breaks JSON decoding
$backtrack_limit = ini_get('pcre.backtrack_limit');
if(!empty($backtrack_limit)) {
ini_set('pcre.backtrack_limit', '-1');
}
// mssql only
if(ini_get("mssql.charset")) {
ini_set('mssql.charset', "UTF-8");
}
}
/**
* like array_merge() but will handle array elements that are themselves arrays;
* PHP's version just overwrites the element with the new one.
*
* @internal Note that this function deviates from the internal array_merge()
* functions in that it does does not treat numeric keys differently
* than string keys. Additionally, it deviates from
* array_merge_recursive() by not creating an array when like values
* found.
*
* @param array gimp the array whose values will be overloaded
* @param array dom the array whose values will pwn the gimp's
* @return array beaten gimp
*/
function sugarArrayMerge($gimp, $dom) {
if(is_array($gimp) && is_array($dom)) {
foreach($dom as $domKey => $domVal) {
if(array_key_exists($domKey, $gimp)) {
if(is_array($domVal)) {
$tempArr = array();
foreach ( $domVal as $domArrKey => $domArrVal )
$tempArr[$domArrKey] = $domArrVal;
foreach ( $gimp[$domKey] as $gimpArrKey => $gimpArrVal )
if ( !array_key_exists($gimpArrKey, $tempArr) )
$tempArr[$gimpArrKey] = $gimpArrVal;
$gimp[$domKey] = $tempArr;
} else {
$gimp[$domKey] = $domVal;
}
} else {
$gimp[$domKey] = $domVal;
}
}
}
// if the passed value for gimp isn't an array, then return the $dom
elseif(is_array($dom))
return $dom;
return $gimp;
}
/**
* Similiar to sugarArrayMerge except arrays of N depth are merged.
*
* @param array gimp the array whose values will be overloaded
* @param array dom the array whose values will pwn the gimp's
* @return array beaten gimp
*/
function sugarArrayMergeRecursive($gimp, $dom) {
if(is_array($gimp) && is_array($dom)) {
foreach($dom as $domKey => $domVal) {
if(array_key_exists($domKey, $gimp)) {
if(is_array($domVal) && is_array($gimp[$domKey])) {
$gimp[$domKey] = sugarArrayMergeRecursive($gimp[$domKey], $domVal);
} else {
$gimp[$domKey] = $domVal;
}
} else {
$gimp[$domKey] = $domVal;
}
}
}
// if the passed value for gimp isn't an array, then return the $dom
elseif(is_array($dom))
return $dom;
return $gimp;
}
/**
* finds the correctly working versions of PHP-JSON
* @return bool True if NOT found or WRONG version
*/
function returnPhpJsonStatus() {
$goodVersions = array('1.1.1',);
if(function_exists('json_encode')) {
$phpInfo = getPhpInfo(8);
if(!in_array($phpInfo['json']['json version'], $goodVersions)) {
return true; // bad version found
} else {
return false; // all requirements met
}
}
return true; // not found
}
/**
* returns a 20-char or less string for the Tracker to display in the header
* @param string name field for a given Object
* @return string 20-char or less name
*/
function getTrackerSubstring($name) {
$strlen = function_exists('mb_strlen') ? mb_strlen($name) : strlen($name);
if($strlen > 20) {
$chopped = function_exists('mb_substr') ? mb_substr($name, 0, 15) : substr($name, 0, 15);
} else {
$chopped = $name;
}
return $chopped;
}
function generate_search_where ($field_list=array(),$values=array(),&$bean,$add_custom_fields=false,$module='') {
$where_clauses= array();
$like_char='%';
$table_name=$bean->object_name;
foreach ($field_list[$module] as $field=>$parms) {
if(isset($values[$field]) && $values[$field] != "") {
$operator='like';
if (!empty($parms['operator'])) {
$operator=$parms['operator'];
}
if (is_array($values[$field])) {
$operator='in';
$field_value='';
foreach ($values[$field] as $key => $val) {
if ($val != ' ' and $val != '') {
if (!empty($field_value)) {
$field_value.=',';
}
$field_value .= "'".$GLOBALS['db']->quote($val)."'";
}
}
} else {
$field_value=$GLOBALS['db']->quote($values[$field]);
}
//set db_fields array.
if (!isset($parms['db_field']) ) {
$parms['db_field'] = array($field);
}
if (isset($parms['my_items']) and $parms['my_items'] == true) {
global $current_user;
$field_value = $GLOBALS['db']->quote($current_user->id);
$operator='=';
}
$where='';
$itr=0;
if ($field_value != '') {
foreach ($parms['db_field'] as $db_field) {
if (strstr($db_field,'.')===false) {
$db_field=$bean->table_name.".".$db_field;
}
if ($GLOBALS['db']->dbType=='oci8' && isset($parms['query_type']) && $parms['query_type']=='case_insensitive') {
$db_field='upper('.$db_field.")";
$field_value=strtoupper($field_value);
}
$itr++;
if (!empty($where)) {
$where .= " OR ";
}
switch (strtolower($operator)) {
case 'like' :
$where .= $db_field . " like '".$field_value.$like_char."'";
break;
case 'in':
$where .= $db_field . " in (".$field_value.')';
break;
case '=':
$where .= $db_field . " = '".$field_value ."'";
break;
}
}
}
if (!empty($where)) {
if ($itr>1) {
array_push($where_clauses, '( '.$where.' )');
} else {
array_push($where_clauses, $where);
}
}
}
}
if ($add_custom_fields) {
require_once('modules/DynamicFields/DynamicField.php');
$bean->setupCustomFields($module);
$bean->custom_fields->setWhereClauses($where_clauses);
}
return $where_clauses;
}
function add_quotes($str) {
return "'{$str}'";
}
/**
* This function will rebuild the config file
* @param $sugar_config
* @param $sugar_version
* @return bool true if successful
*/
function rebuildConfigFile($sugar_config, $sugar_version) {
// add defaults to missing values of in-memory sugar_config
$sugar_config = sugarArrayMerge(get_sugar_config_defaults(), $sugar_config );
// need to override version with default no matter what
$sugar_config['sugar_version'] = $sugar_version;
ksort( $sugar_config );
if( write_array_to_file( "sugar_config", $sugar_config, "config.php" ) ){
return true;
}
else {
return false;
}
}
/**
* getJavascriptSiteURL
* This function returns a URL for the client javascript calls to access
* the site. It uses $_SERVER['HTTP_REFERER'] in the event that Proxy servers
* are used to access the site. Thus, the hostname in the URL returned may
* not always match that of $sugar_config['site_url']. Basically, the
* assumption is that however the user accessed the website is how they
* will continue to with subsequent javascript requests. If the variable
* $_SERVER['HTTP_REFERER'] is not found then we default to old algorithm.
* @return $site_url The url used to refer to the website
*/
function getJavascriptSiteURL() {
global $sugar_config;
if(!empty($_SERVER['HTTP_REFERER'])) {
$url = parse_url($_SERVER['HTTP_REFERER']);
$replacement_url = $url['scheme']."://".$url['host'];
if(!empty($url['port']))
$replacement_url .= ':'.$url['port'];
$site_url = preg_replace('/^http[s]?\:\/\/[^\/]+/',$replacement_url,$sugar_config['site_url']);
} else {
$site_url = preg_replace('/^http(s)?\:\/\/[^\/]+/',"http$1://".$_SERVER['HTTP_HOST'],$sugar_config['site_url']);
if(!empty($_SERVER['SERVER_PORT']) &&$_SERVER['SERVER_PORT'] == '443') {
$site_url = preg_replace('/^http\:/','https:',$site_url);
}
}
$GLOBALS['log']->debug("getJavascriptSiteURL(), site_url=". $site_url);
return $site_url;
}
// works nicely with array_map() -- can be used to wrap single quotes around each element in an array
function add_squotes($str) {
return "'" . $str . "'";
}
// recursive function to count the number of levels within an array
function array_depth($array, $depth_count=-1, $depth_array=array()){
$depth_count++;
if (is_array($array)){
foreach ($array as $key => $value){
$depth_array[] = array_depth($value, $depth_count);
}
}
else{
return $depth_count;
}
foreach ($depth_array as $value){
$depth_count = $value > $depth_count ? $value : $depth_count;
}
return $depth_count;
}
/**
* Creates a new Group User
* @param string $name Name of Group User
* @return string GUID of new Group User
*/
function createGroupUser($name) {
require_once('modules/Users/User.php');
$group = new User();
$group->user_name = $name;
$group->last_name = $name;
$group->is_group = 1;
$group->deleted = 0;
$group->status = 'Active'; // cn: bug 6711
$timezone = lookupTimezone();
$group->setPreference('timezone', $timezone);
$group->save();
return $group->id;
}
/*
* Helper function to locate an icon file given only a name
* Searches through the various paths for the file
* @param string iconFileName The filename of the icon
* @return string Relative pathname of the located icon, or '' if not found
*/
function _getIcon($iconFileName)
{
global $theme;
//Try custom first
$base_paths = array("custom/themes/$theme/images/icon_", "themes/$theme/images/icon_",
"custom/themes/default/images/icon_", "themes/default/images/icon_");
$iconPath = '';
foreach ($base_paths as $base_path) {
if(sugar_is_file($base_path. $iconFileName. '.gif')){
$iconPath = $base_path. $iconFileName. '.gif';
}else if(sugar_is_file($base_path. ucfirst($iconFileName). '.gif')){
$iconPath = $base_path. ucfirst($iconFileName). '.gif';
}else if(sugar_is_file($base_path. strtolower($iconFileName). '.gif')){
$iconPath = $base_path. strtolower($iconFileName). '.gif';
}
if (!empty($iconPath))
{
return $iconPath;
}
}
if(empty($iconPath) && sugar_is_file("themes/".$theme."/images/".$iconFileName.".gif")){
$iconPath = "themes/".$theme."/images/".$iconFileName.".gif";
}
return $iconPath;
}
/**
* Function to grab the correct icon image for Studio
* @param string $iconFileName Name of the icon file
* @param string $altfilename Name of a fallback icon file (displayed if the imagefilename doesn't exist)
* @param string $width Width of image
* @param string $height Height of image
* @param string $align Alignment of image
* @return string $string tag with corresponding image
*/
function getStudioIcon($iconFileName='', $altFileName='', $width='48', $height='48', $align='baseline' )
{
global $app_strings, $theme;
$iconPath = _getIcon($iconFileName);
if(empty($iconPath)){
$iconPath = _getIcon($altFileName);
if (empty($iconPath))
{
return $app_strings['LBL_NO_IMAGE'];
}
}
return '';
}
/**
* Function to grab the correct icon image for Dashlets Dialog
* @param string $filename Location of the icon file
* @param string $module Name of the module to fall back onto if file does not exist
* @param string $width Width of image
* @param string $height Height of image
* @param string $align Alignment of image
* @return string $string tag with corresponding image
*/
function get_dashlets_dialog_icon($module='', $width='32', $height='32', $align='absmiddle'){
global $app_strings, $theme;
$icon_path = _getIcon($module . "_32");
if (empty($icon_path))
{
$icon_path = _getIcon($module);
}
if(empty($icon_path)){
$icon = $app_strings['LBL_NO_IMAGE'];
}
else{
$icon = '';
}
return $icon;
}
// works nicely to change UTF8 strings that are html entities - good for PDF conversions
function html_entity_decode_utf8($string)
{
static $trans_tbl;
// replace numeric entities
$string = preg_replace('~([0-9a-f]+);~ei', 'code2utf(hexdec("\\1"))', $string);
$string = preg_replace('~([0-9]+);~e', 'code2utf(\\1)', $string);
// replace literal entities
if (!isset($trans_tbl))
{
$trans_tbl = array();
foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key)
$trans_tbl[$key] = utf8_encode($val);
}
return strtr($string, $trans_tbl);
}
// Returns the utf string corresponding to the unicode value
function code2utf($num)
{
if ($num < 128) return chr($num);
if ($num < 2048) return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
if ($num < 65536) return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
if ($num < 2097152) return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
return '';
}
function str_split_php4($string, $length = 1) {
$string_length = strlen($string);
$return = array();
$cursor = 0;
if ($length > $string_length) {
// use the string_length as the string is shorter than the length
$length = $string_length;
}
for ($cursor = 0; $cursor < $string_length; $cursor = $cursor + $length) {
$return[] = substr($string, $cursor, $length);
}
return $return;
}
if (version_compare(phpversion(), '5.0.0', '<')) {
function str_split($string, $length = 1) {
return str_split_php4($string, $length);
}
}
/*
* Invoked when connected to mssql. checks if we have freetds version of mssql library.
* the response is put into a global variable.
*/
function is_freetds() {
$ret=false;
if (isset($GLOBALS['mssql_library_version'])) {
if ($GLOBALS['mssql_library_version']=='freetds') {
$ret=true;
} else {
$ret=false;
}
} else {
ob_start();
phpinfo();
$info=ob_get_contents();
ob_end_clean();
if (strpos($info,'FreeTDS') !== false) {
$GLOBALS['mssql_library_version']='freetds';
$ret=true;
} else {
$GLOBALS['mssql_library_version']='regular';
$ret=false;
}
}
return $ret;
}
/*
* stripos - Find position of first occurrence of a case-insensitive string
*
* The function is being defined for systems with PHP version < 5.
*
*/
if (!function_exists("stripos")){
function stripos($haystack,$needle,$offset=0){
return strpos(strtolower($haystack),strtolower($needle),$offset);
}
}
/*
* Chart dashlet helper functions that returns the correct CSS file
* and XML color file for charts, dependent on the current theme.
*/
function chartStyle(){
global $theme;
$chartStyleCSS = 'themes/'.$theme.'/chart.css';
if(defined('TEMPLATE_URL')){
$chartStyleCSS = TEMPLATE_URL . $chartStyleCSS;
}
if (!file_exists($chartStyleCSS)){
// fall back to default theme if no CSS for current theme
$chartStyleCSS = 'themes/default/chart.css';
if(defined('TEMPLATE_URL')){
$chartStyleCSS = TEMPLATE_URL . $chartStyleCSS;
}
}
return $chartStyleCSS;
}
function chartColors(){
global $theme;
$chartColorsXML = 'themes/'.$theme.'/sugarColors.xml';
if(defined('TEMPLATE_URL')){
$chartColorsXML = TEMPLATE_URL . $chartColorsXML ;
}
if (!file_exists($chartColorsXML)){
// fall back to default theme if no colors XML for current theme
$chartColorsXML = 'themes/default/sugarColors.xml';
if(defined('TEMPLATE_URL')){
$chartColorsXML = TEMPLATE_URL . $chartColorsXML ;
}
}
return $chartColorsXML;
}
/* End Chart Dashlet helper functions */
/**
* This function is designed to set up the php enviroment
* for AJAX requests.
*/
function ajaxInit() {
ini_set('display_errors', 'false');
}
/**
* Returns an absolute path from the given path, determining if it is relative or absolute
*
* @param string $path
* @return string
*/
function getAbsolutePath(
$path,
$currentServer = false
)
{
$path = trim($path);
// try to match absolute paths like \\server\share, /directory or c:\
if ( ( substr($path,0,2) == '\\\\' )
|| ( $path[0] == '/' )
|| preg_match('/^[A-z]:/i',$path)
|| $currentServer )
return $path;
return getcwd().'/'.$path;
}
/**
* Returns the bean object of the given module
*
* @param string $module
* @return object
*/
function loadBean(
$module
)
{
require('include/modules.php');
if ( isset($beanList[$module]) ) {
$bean = $beanList[$module];
if(isset($beanFiles[$bean])){
require_once($beanFiles[$bean]);
$focus = new $bean();
}else {
return false;
}
}
else {
return false;
}
return $focus;
}
/**
* Returns the shortcut keys to access the shortcut links. Shortcut
* keys vary depending on browser versions and operating systems.
* @return String value of the shortcut keys
*/
function get_alt_hot_key() {
$ua = '';
if ( isset($_SERVER['HTTP_USER_AGENT']) )
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$isMac = strpos($ua, 'mac') !== false;
$isLinux = strpos($ua, 'linux') !== false;
if(!$isMac && !$isLinux && strpos($ua, 'mozilla') !== false) {
if(preg_match('/firefox\/(\d)?\./', $ua, $matches)) {
return $matches[1] < 2 ? 'Alt+' : 'Alt+Shift+';
}
}
return $isMac ? 'Ctrl+' : 'Alt+';
}
function can_start_session(){
if(!empty($_GET['PHPSESSID'])) {
return true;
}
$session_id = session_id();
return empty($session_id) ? true : false;
}
?>
|