| ');
$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 < count($parsedInfo); $i++) {
if (preg_match('/([^<]+)<\/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');
//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
// Bug 37579 - Comment out force enabling zlib.output_compression, since it can cause problems on certain hosts
/*
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
}
/**
* getTrackerSubstring
*
* Returns a [number]-char or less string for the Tracker to display in the header
* based on the tracker_max_display_length setting in config.php. If not set,
* or invalid length, then defaults to 15 for COM editions, 30 for others.
*
* @param string name field for a given Object
* @return string [number]-char formatted string if length of string exceeds the max allowed
*/
function getTrackerSubstring($name) {
static $max_tracker_item_length;
//Trim the name
$strlen = function_exists('mb_strlen') ? mb_strlen($name) : strlen($name);
global $sugar_config;
if (!isset($max_tracker_item_length)) {
if (isset($sugar_config['tracker_max_display_length'])) {
$max_tracker_item_length = (is_int($sugar_config['tracker_max_display_length']) && $sugar_config['tracker_max_display_length'] > 0 && $sugar_config['tracker_max_display_length'] < 50) ? $sugar_config['tracker_max_display_length'] : 15;
} else {
$max_tracker_item_length = 15;
}
}
if ($strlen > $max_tracker_item_length) {
$chopped = function_exists('mb_substr') ? mb_substr($name, 0, $max_tracker_item_length, "UTF-8") : substr($name, 0, $max_tracker_item_length, "UTF-8");
} 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);
}
}
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) {
$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) {
$iconPath = SugarThemeRegistry::current()->getImageURL("icon_{$iconFileName}.gif");
if (empty($iconPath))
$iconPath = SugarThemeRegistry::current()->getImageURL("{$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
//php will have issues with numbers with leading zeros, so do not include them in what we send to code2utf.
$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 function that returns the correct CSS file, dependent on the current theme.
*
* @todo this won't work completely right until we impliment css compression and combination
* for now, we'll just include the last css file found.
*
* @return chart.css file to use
*/
function chartStyle() {
return SugarThemeRegistry::current()->getCSSURL('chart.css');
}
/**
* Chart dashlet helper functions that returns the correct XML color file for charts,
* dependent on the current theme.
*
* @return sugarColors.xml to use
*/
function chartColors() {
if (SugarThemeRegistry::current()->getCSSURL('sugarColors.xml') == '')
return SugarThemeRegistry::current()->getImageURL('sugarColors.xml');
return SugarThemeRegistry::current()->getCSSURL('sugarColors.xml');
}
/* 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
*
* @deprecated use SugarModule::loadBean() instead
* @param string $module
* @return object
*/
function loadBean(
$module
) {
return SugarModule::get($module)->loadBean();
}
/**
* Returns true if the application is being accessed on a touch screen interface ( like an iPad )
*/
function isTouchScreen() {
$ua = empty($_SERVER['HTTP_USER_AGENT']) ? "undefined" : strtolower($_SERVER['HTTP_USER_AGENT']);
// first check if we have forced use of the touch enhanced interface
if (isset($_COOKIE['touchscreen']) && $_COOKIE['touchscreen'] == '1') {
return true;
}
// next check if we should use the touch interface with our device
if (strpos($ua, 'ipad') !== false) {
return true;
}
return false;
}
/**
* 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;
}
function load_link_class($properties) {
$class = 'Link';
if (!empty($properties['link_class']) && !empty($properties['link_file'])) {
require_once($properties['link_file']);
$class = $properties['link_class'];
}
return $class;
}
function inDeveloperMode() {
return isset($GLOBALS['sugar_config']['developerMode']) && $GLOBALS['sugar_config']['developerMode'];
}
/**
* Filter the protocol list for inbound email accounts.
*
* @param array $protocol
*/
function filterInboundEmailPopSelection($protocol) {
if (!isset($GLOBALS['sugar_config']['allow_pop_inbound']) || !$GLOBALS['sugar_config']['allow_pop_inbound']) {
if (isset($protocol['pop3']))
unset($protocol['pop3']);
} else
$protocol['pop3'] = 'POP3';
return $protocol;
}
/**
* The function is used because currently we are not supporting mbstring.func_overload
* For some user using mssql without FreeTDS, they may store multibyte charaters in varchar using latin_general collation. It cannot store so many mutilbyte characters, so we need to use strlen.
* The varchar in MySQL, Orcale, and nvarchar in FreeTDS, we can store $length mutilbyte charaters in it. we need mb_substr to keep more info.
* @returns the substred strings.
*/
function sugar_substr($string, $length, $charset = 'UTF-8') {
if ($GLOBALS['db']->dbType == 'mssql' && empty($GLOBALS['db']->isFreeTDS)) {
if (strlen($string) > $length) {
$string = trim(substr(trim($string), 0, $length));
}
} else {
if (mb_strlen($string, $charset) > $length) {
$string = trim(mb_substr(trim($string), 0, $length, $charset));
}
}
return $string;
}
/**
* The function is used because on FastCGI enviroment, the ucfirst(Chinese Characters) will produce bad charcters.
* This will work even without setting the mbstring.*encoding
*/
function sugar_ucfirst($string, $charset = 'UTF-8') {
return mb_strtoupper(mb_substr($string, 0, 1, $charset), $charset) . mb_substr($string, 1, mb_strlen($string), $charset);
}
/**
*
*/
function unencodeMultienum($string) {
if (is_array($string)) {
return $string;
}
if (substr($string, 0, 1) == "^" && substr($string, -1) == "^") {
$string = substr(substr($string, 1), 0, strlen($string) - 2);
}
return explode('^,^', $string);
}
function encodeMultienumValue($arr) {
if (!is_array($arr))
return $arr;
if (empty($arr))
return "";
$string = "^" . implode('^,^', $arr) . "^";
return $string;
}
/**
* create_export_query is used for export and massupdate
* We haven't handle the these fields: $field['type'] == 'relate' && isset($field['link']
* This function will correct the where clause and output necessary join condition for them
* @param $module: the module name
* @param $searchFields: searchFields which is got after $searchForm->populateFromArray()
* @param $where: where clauses
* @return $ret_array['where']: corrected where clause
* @return $ret_array['join']: extra join condition
*/
function create_export_query_relate_link_patch($module, $searchFields, $where) {
if (file_exists('modules/' . $module . '/SearchForm.html')) {
$ret_array['where'] = $where;
return $ret_array;
}
$seed = loadBean($module);
foreach ($seed->field_defs as $name => $field) {
if ($field['type'] == 'relate' && isset($field['link']) && !empty($searchFields[$name]['value'])) {
$seed->load_relationship($field['link']);
$params = array();
if (empty($join_type)) {
$params['join_type'] = ' LEFT JOIN ';
} else {
$params['join_type'] = $join_type;
}
if (isset($data['join_name'])) {
$params['join_table_alias'] = $field['join_name'];
} else {
$params['join_table_alias'] = 'join_' . $field['name'];
}
if (isset($data['join_link_name'])) {
$params['join_table_link_alias'] = $field['join_link_name'];
} else {
$params['join_table_link_alias'] = 'join_link_' . $field['name'];
}
$join = $seed->$field['link']->getJoin($params, true);
$join_table_alias = 'join_' . $field['name'];
if (isset($field['db_concat_fields'])) {
$db_field = db_concat($join_table_alias, $field['db_concat_fields']);
$where = preg_replace('/' . $field['name'] . '/', $db_field, $where);
} else {
$where = preg_replace('/(^|[\s(])' . $field['name'] . '/', '${1}' . $join_table_alias . '.' . $field['rname'], $where);
}
}
}
$ret_array = array('where' => $where, 'join' => $join['join']);
return $ret_array;
}
/**
* We need to clear all the js cache files, including the js language files in serval places in MB. So I extract them into a util function here.
* @Depends on QuickRepairAndRebuild.php
* @Relate bug 30642 ,23177
*/
function clearAllJsAndJsLangFilesWithoutOutput() {
global $current_language, $mod_strings;
$MBmodStrings = $mod_strings;
$mod_strings = return_module_language($current_language, 'Administration');
include_once ('modules/Administration/QuickRepairAndRebuild.php');
$repair = new RepairAndClear();
$repair->module_list = array();
$repair->show_output = false;
$repair->clearJsLangFiles();
$repair->clearJsFiles();
$mod_strings = $MBmodStrings;
}
/**
* should_hide_iframes
* This is a helper method to determine whether or not to show iframes (My Sites) related
* information in the application.
*
* @return boolean flag indicating whether or not iframes module should be hidden
*/
function should_hide_iframes() {
//Remove the MySites module
return !file_exists('modules/iFrames/iFrame.php');
}
/**
* Given a version such as 5.5.0RC1 return RC. If we have a version such as: 5.5 then return GA
*
* @param string $version
* @return string RC, BETA, GA
*/
function getVersionStatus($version) {
if (preg_match('/^[\d\.]+?([a-zA-Z]+?)[\d]*?$/si', $version, $matches)) {
return strtoupper($matches[1]);
} else {
return 'GA';
}
}
/**
* Return the numeric portion of a version. For example if passed 5.5.0RC1 then return 5.5. If given
* 5.5.1RC1 then return 5.5.1
*
* @param string $version
* @return version
*/
function getMajorMinorVersion($version) {
if (preg_match('/^([\d\.]+).*$/si', $version, $matches2)) {
$version = $matches2[1];
$arr = explode('.', $version);
if (count($arr) > 2) {
if ($arr[2] == '0') {
$version = substr($version, 0, 3);
}
}
}
return $version;
}
/**
* Sanitize image file from hostile content
* @param string $path Image file
* @param bool $jpeg Recode as JPEG (false - recode as PNG)
*/
function verify_image_file($path, $jpeg = false) {
if (function_exists('imagepng') && function_exists('imagejpeg') && function_exists('imagecreatefromstring')) {
$img = imagecreatefromstring(file_get_contents($path));
if (!$img) {
return false;
}
if ($jpeg) {
if (imagejpeg($img, $path)) {
return true;
}
} else {
imagealphablending($img, true);
imagesavealpha($img, true);
if (imagepng($img, $path)) {
return true;
}
}
} else {
// check image manually
$fp = fopen($path, "r");
if (!$fp)
return false;
$data = fread($fp, 4096);
fclose($fp);
if (preg_match("/<(html|!doctype|script|body|head|plaintext|table|img |pre(>| )|frameset|iframe|object|link|base|style|font|applet|meta|center|form|isindex)/i", $data, $m)) {
return false;
}
return true;
}
return false;
}
/**
* Verify uploaded image
* Verifies that image has proper extension, MIME type and doesn't contain hostile contant
* @param string $path Image path
* @param bool $jpeg_only Accept only JPEGs?
*/
function verify_uploaded_image($path, $jpeg_only = false) {
$supportedExtensions = array('jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg');
if (!$jpeg_only) {
$supportedExtensions['png'] = 'image/png';
}
if (!file_exists($path) || !is_file($path)) {
return false;
}
$img_size = getimagesize($path);
$filetype = $img_size['mime'];
$ext = end(explode(".", $path));
if (substr_count('..', $path) > 0 || $ext === $path || !in_array(strtolower($ext), array_keys($supportedExtensions)) ||
!in_array($filetype, array_values($supportedExtensions))) {
return false;
}
return verify_image_file($path, $jpeg_only);
}
/**
* Get header pdf for module
* Returns Html for header to pdf
* @param string $modulename english name for document
*/
function getHeaderForModule($modulename, $language='pl_pl'){
include('modules/EcmSysInfos/EcmSysInfo.php');
$ecmsysinfos = new EcmSysInfo();
return $ecmsysinfos->getHeaderForModule($modulename, $language);
}
function getFooterForModule($modulename, $language='pl_pl'){
include('modules/EcmSysInfos/EcmSysInfo.php');
$ecmsysinfos = new EcmSysInfo();
return $ecmsysinfos->getFooterForModule($modulename, $language);
}
function SlowniePL($liczba ,$part){
if($liczba==0) return '';
if($liczba==1) return 'jeden ' + $part;
if($liczba>999) return 'Błędna liczba (>999)';
$segment = '';
echo $set;
$set = intval(($liczba/100));
$dzi = intval(($liczba - 100*$set)/10);
$jed = intval(($liczba - 100*$set - 10*$dzi));
switch ($set) {
case 9: $segment.='dziewięćset '; break;
case 8 : $segment.='osiemset '; break;
case 7 : $segment.='siedemset '; break;
case 6 : $segment.='sześćset '; break;
case 5 : $segment.='pięćset '; break;
case 4 : $segment.='czterysta '; break;
case 3 : $segment.='trzysta '; break;
case 2 : $segment.='dwieście '; break;
case 1 : $segment.='sto '; break;
}
switch ($dzi) {
case 9 : $segment.='dziewięćdziesiąt '; break;
case 8 : $segment.='osiemdziesiąt '; break;
case 7 : $segment.='siedemdziesiąt '; break;
case 6 : $segment.='sześćdziesiąt '; break;
case 5 : $segment.='pięćdziesiąt '; break;
case 4 : $segment.='czterdzieści '; break;
case 3 : $segment.='trzydzieści '; break;
case 2 : $segment.='dwadzieścia '; break;
case 1 :
switch($jed)
{
case 9 : $segment.='dziewiętnaście '; break;
case 8 : $segment.='osiemnaście '; break;
case 7 : $segment.='siedemnaście '; break;
case 6 : $segment.='szesnaście '; break;
case 5 : $segment.='piętnaście '; break;
case 4 : $segment.='czternaście '; break;
case 3 : $segment.='trzynaście '; break;
case 2 : $segment.='dwanaście '; break;
case 1 : $segment.='jedenaście '; break;
case 0 : $segment.='dziesięć '; break;
}
}
if( $dzi != 1)
{
switch($jed)
{
case 9 : $segment.='dziewięć '; break;
case 8 : $segment.='osiem '; break;
case 7 : $segment.='siedem '; break;
case 6 : $segment.='sześć '; break;
case 5 : $segment.='pięć '; break;
case 4 : $segment.='cztery '; break;
case 3 : $segment.='trzy '; break;
case 2 : $segment.='dwa '; break;
case 1 : $segment.='jeden '; break;
}
}
return ($segment.$part);
}
function wypiszSlownie($liczba){
$mln = intval(($liczba/1000000));
$tys = intval((($liczba - 1000000*$mln)/1000));
$jed = intval(($liczba - 1000000*$mln - 1000*$tys));
$gr = (100*($liczba - 1000000*$mln - 1000*$tys - $jed));
return SlowniePL($mln, 'milionów ') . SlowniePL($tys, 'tysiące ') . SlowniePL($jed, 'złotych ') . SlowniePL(round($gr,2),'groszy');
} |