debug("Entering return_name(".$row.",".$first_column.",".$last_column.") method ..."); $first_name = ""; $last_name = ""; $full_name = ""; if(isset($row[$first_column])) { $first_name = stripslashes($row[$first_column]); } if(isset($row[$last_column])) { $last_name = stripslashes($row[$last_column]); } $full_name = $first_name; // If we have a first name and we have a last name if($full_name != "" && $last_name != "") { // append a space, then the last name $full_name .= " ".$last_name; } // If we have no first name, but we have a last name else if($last_name != "") { // append the last name without the space. $full_name .= $last_name; } $log->debug("Exiting return_name method ..."); return $full_name; } /** Function to return language * @returns $languages -- languages:: Type string * */ function get_languages() { global $log; $log->debug("Entering get_languages() method ..."); global $languages; $log->debug("Exiting get_languages method ..."); return $languages; } /** Function to return language * @param $key -- key:: Type string * @returns $languages -- languages:: Type string * */ //seems not used function get_language_display($key) { global $log; $log->debug("Entering get_language_display(".$key.") method ..."); global $languages; $log->debug("Exiting get_language_display method ..."); return $languages[$key]; } /** Function returns the user array * @param $assigned_user_id -- assigned_user_id:: Type string * @returns $user_list -- user list:: Type array * */ function get_assigned_user_name(&$assigned_user_id) { global $log; $log->debug("Entering get_assigned_user_name(".$assigned_user_id.") method ..."); $user_list = &get_user_array(false,""); if(isset($user_list[$assigned_user_id])) { $log->debug("Exiting get_assigned_user_name method ..."); return $user_list[$assigned_user_id]; } $log->debug("Exiting get_assigned_user_name method ..."); return ""; } /** Function returns the user key in user array * @param $add_blank -- boolean:: Type boolean * @param $status -- user status:: Type string * @param $assigned_user -- user id:: Type string * @param $private -- sharing type:: Type string * @returns $user_array -- user array:: Type array * */ //used in module file function get_user_array($add_blank=true, $status="Active", $assigned_user="",$private="") { global $log; $log->debug("Entering get_user_array(".$add_blank.",". $status.",".$assigned_user.",".$private.") method ..."); global $current_user; if(isset($current_user) && $current_user->id != '') { require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); require('user_privileges/user_privileges_'.$current_user->id.'.php'); } static $user_array = null; $module=$_REQUEST['module']; if($user_array == null) { require_once('include/database/PearDatabase.php'); $db = new PearDatabase(); $temp_result = Array(); // Including deleted vtiger_users for now. if (empty($status)) { $query = "SELECT id, user_name from vtiger_users"; } else { if($private == 'private') { $log->debug("Sharing is Private. Only the current user should be listed"); $query = "select id as id,user_name as user_name from vtiger_users where id=".$current_user->id." and status='Active' union select vtiger_user2role.userid as id,vtiger_users.user_name as user_name from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like '".$current_user_parent_role_seq."::%' and status='Active' union select shareduserid as id,vtiger_users.user_name as user_name from vtiger_tmp_write_user_sharing_per inner join vtiger_users on vtiger_users.id=vtiger_tmp_write_user_sharing_per.shareduserid where status='Active' and vtiger_tmp_write_user_sharing_per.userid=".$current_user->id." and vtiger_tmp_write_user_sharing_per.tabid=".getTabid($module); } else { $log->debug("Sharing is Public. All vtiger_users should be listed"); $query = "SELECT id, user_name from vtiger_users WHERE status='$status'"; } } if (!empty($assigned_user)) { $query .= " OR id='$assigned_user'"; } $query .= " order by user_name ASC"; $result = $db->query($query, true, "Error filling in user array: "); if ($add_blank==true){ // Add in a blank row $temp_result[''] = ''; } // Get the id and the name. while($row = $db->fetchByAssoc($result)) { $temp_result[$row['id']] = $row['user_name']; } $user_array = &$temp_result; } $log->debug("Exiting get_user_array method ..."); return $user_array; } /** Function skips executing arbitary commands given in a string * @param $string -- string:: Type string * @param $maxlength -- maximun length:: Type integer * @returns $string -- escaped string:: Type string * */ function clean($string, $maxLength) { global $log; $log->debug("Entering clean(".$string.",". $maxLength.") method ..."); $string = substr($string, 0, $maxLength); $log->debug("Exiting clean method ..."); return escapeshellcmd($string); } /** * Copy the specified request variable to the member variable of the specified object. * Do no copy if the member variable is already set. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. */ function safe_map($request_var, & $focus, $always_copy = false) { global $log; $log->debug("Entering safe_map(".$request_var.",".$focus.",".$always_copy.") method ..."); safe_map_named($request_var, $focus, $request_var, $always_copy); $log->debug("Exiting safe_map method ..."); } /** * Copy the specified request variable to the member variable of the specified object. * Do no copy if the member variable is already set. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. */ function safe_map_named($request_var, & $focus, $member_var, $always_copy) { global $log; $log->debug("Entering safe_map_named(".$request_var.",".$focus.",".$member_var.",".$always_copy.") method ..."); if (isset($_REQUEST[$request_var]) && ($always_copy || is_null($focus->$member_var))) { $log->debug("safe map named called assigning '{$_REQUEST[$request_var]}' to $member_var"); $focus->$member_var = $_REQUEST[$request_var]; } $log->debug("Exiting safe_map_named method ..."); } /** This function retrieves an application language file and returns the array of strings included in the $app_list_strings var. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. * If you are using the current language, do not call this function unless you are loading it for the first time */ function return_app_list_strings_language($language) { global $log; $log->debug("Entering return_app_list_strings_language(".$language.") method ..."); global $app_list_strings, $default_language, $log, $translation_string_prefix; $temp_app_list_strings = $app_list_strings; $language_used = $language; @include("include/language/$language.lang.php"); if(!isset($app_list_strings)) { $log->warn("Unable to find the application language file for language: ".$language); require("include/language/$default_language.lang.php"); $language_used = $default_language; } if(!isset($app_list_strings)) { $log->fatal("Unable to load the application language file for the selected language($language) or the default language($default_language)"); $log->debug("Exiting return_app_list_strings_language method ..."); return null; } $return_value = $app_list_strings; $app_list_strings = $temp_app_list_strings; $log->debug("Exiting return_app_list_strings_language method ..."); return $return_value; } /** This function retrieves an application language file and returns the array of strings included. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. * If you are using the current language, do not call this function unless you are loading it for the first time */ function return_application_language($language) { global $log; $log->debug("Entering return_application_language(".$language.") method ..."); global $app_strings, $default_language, $log, $translation_string_prefix; $temp_app_strings = $app_strings; $language_used = $language; @include("include/language/$language.lang.php"); if(!isset($app_strings)) { $log->warn("Unable to find the application language file for language: ".$language); require("include/language/$default_language.lang.php"); $language_used = $default_language; } if(!isset($app_strings)) { $log->fatal("Unable to load the application language file for the selected language($language) or the default language($default_language)"); $log->debug("Exiting return_application_language method ..."); return null; } // If we are in debug mode for translating, turn on the prefix now! if($translation_string_prefix) { foreach($app_strings as $entry_key=>$entry_value) { $app_strings[$entry_key] = $language_used.' '.$entry_value; } } $return_value = $app_strings; $app_strings = $temp_app_strings; $log->debug("Exiting return_application_language method ..."); return $return_value; } /** This function retrieves a module's language file and returns the array of strings included. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. * If you are in the current module, do not call this function unless you are loading it for the first time */ function return_module_language($language, $module) { global $log; $log->debug("Entering return_module_language(".$language.",". $module.") method ..."); global $mod_strings, $default_language, $log, $currentModule, $translation_string_prefix; if($currentModule == $module && isset($mod_strings) && $mod_strings != null) { // We should have already loaded the array. return the current one. $log->debug("Exiting return_module_language method ..."); return $mod_strings; } $temp_mod_strings = $mod_strings; $language_used = $language; @include("modules/$module/language/$language.lang.php"); if(!isset($mod_strings)) { $log->warn("Unable to find the module language file for language: ".$language." and module: ".$module); require("modules/$module/language/$default_language.lang.php"); $language_used = $default_language; } if(!isset($mod_strings)) { $log->fatal("Unable to load the module($module) language file for the selected language($language) or the default language($default_language)"); $log->debug("Exiting return_module_language method ..."); return null; } // If we are in debug mode for translating, turn on the prefix now! if($translation_string_prefix) { foreach($mod_strings as $entry_key=>$entry_value) { $mod_strings[$entry_key] = $language_used.' '.$entry_value; } } $return_value = $mod_strings; $mod_strings = $temp_mod_strings; $log->debug("Exiting return_module_language method ..."); return $return_value; } /*This function returns the mod_strings for the current language and the specified module */ function return_specified_module_language($language, $module) { global $log; global $default_language, $translation_string_prefix; @include("modules/$module/language/$language.lang.php"); if(!isset($mod_strings)) { $log->warn("Unable to find the module language file for language: ".$language." and module: ".$module); require("modules/$module/language/$default_language.lang.php"); $language_used = $default_language; } if(!isset($mod_strings)) { $log->fatal("Unable to load the module($module) language file for the selected language($language) or the default language($default_language)"); $log->debug("Exiting return_module_language method ..."); return null; } $return_value = $mod_strings; $log->debug("Exiting return_module_language method ..."); return $return_value; } /** This function retrieves an application language file and returns the array of strings included in the $mod_list_strings var. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. * If you are using the current language, do not call this function unless you are loading it for the first time */ function return_mod_list_strings_language($language,$module) { global $log; $log->debug("Entering return_mod_list_strings_language(".$language.",".$module.") method ..."); global $mod_list_strings, $default_language, $log, $currentModule,$translation_string_prefix; $language_used = $language; $temp_mod_list_strings = $mod_list_strings; if($currentModule == $module && isset($mod_list_strings) && $mod_list_strings != null) { $log->debug("Exiting return_mod_list_strings_language method ..."); return $mod_list_strings; } @include("modules/$module/language/$language.lang.php"); if(!isset($mod_list_strings)) { $log->fatal("Unable to load the application list language file for the selected language($language) or the default language($default_language)"); $log->debug("Exiting return_mod_list_strings_language method ..."); return null; } $return_value = $mod_list_strings; $mod_list_strings = $temp_mod_list_strings; $log->debug("Exiting return_mod_list_strings_language method ..."); return $return_value; } /** This function retrieves a theme's language file and returns the array of strings included. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. */ function return_theme_language($language, $theme) { global $log; $log->debug("Entering return_theme_language(".$language.",". $theme.") method ..."); global $mod_strings, $default_language, $log, $currentModule, $translation_string_prefix; $language_used = $language; @include("themes/$theme/language/$current_language.lang.php"); if(!isset($theme_strings)) { $log->warn("Unable to find the theme file for language: ".$language." and theme: ".$theme); require("themes/$theme/language/$default_language.lang.php"); $language_used = $default_language; } if(!isset($theme_strings)) { $log->fatal("Unable to load the theme($theme) language file for the selected language($language) or the default language($default_language)"); $log->debug("Exiting return_theme_language method ..."); return null; } // If we are in debug mode for translating, turn on the prefix now! if($translation_string_prefix) { foreach($theme_strings as $entry_key=>$entry_value) { $theme_strings[$entry_key] = $language_used.' '.$entry_value; } } $log->debug("Exiting return_theme_language method ..."); return $theme_strings; } /** If the session variable is defined and is not equal to "" then return it. Otherwise, return the default value. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. */ function return_session_value_or_default($varname, $default) { global $log; $log->debug("Entering return_session_value_or_default(".$varname.",". $default.") method ..."); if(isset($_SESSION[$varname]) && $_SESSION[$varname] != "") { $log->debug("Exiting return_session_value_or_default method ..."); return $_SESSION[$varname]; } $log->debug("Exiting return_session_value_or_default method ..."); return $default; } /** * Creates an array of where restrictions. These are used to construct a where SQL statement on the query * It looks for the variable in the $_REQUEST array. If it is set and is not "" it will create a where clause out of it. * @param &$where_clauses - The array to append the clause to * @param $variable_name - The name of the variable to look for an add to the where clause if found * @param $SQL_name - [Optional] If specified, this is the SQL column name that is used. If not specified, the $variable_name is used as the SQL_name. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. */ function append_where_clause(&$where_clauses, $variable_name, $SQL_name = null) { global $log; $log->debug("Entering append_where_clause(".$where_clauses.",".$variable_name.",".$SQL_name.") method ..."); if($SQL_name == null) { $SQL_name = $variable_name; } if(isset($_REQUEST[$variable_name]) && $_REQUEST[$variable_name] != "") { array_push($where_clauses, "$SQL_name like '$_REQUEST[$variable_name]%'"); } $log->debug("Exiting append_where_clause method ..."); } /** * Generate the appropriate SQL based on the where clauses. * @param $where_clauses - An Array of individual where clauses stored as strings * @returns string where_clause - The final SQL where clause to be executed. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. */ function generate_where_statement($where_clauses) { global $log; $log->debug("Entering generate_where_statement(".$where_clauses.") method ..."); $where = ""; foreach($where_clauses as $clause) { if($where != "") $where .= " and "; $where .= $clause; } $log->info("Here is the where clause for the list view: $where"); $log->debug("Exiting generate_where_statement method ..."); return $where; } /** * A temporary method of generating GUIDs of the correct format for our DB. * @return String contianing a GUID in the format: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee * * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. */ function create_guid() { global $log; $log->debug("Entering create_guid() method ..."); $microTime = microtime(); list($a_dec, $a_sec) = explode(" ", $microTime); $dec_hex = sprintf("%x", $a_dec* 1000000); $sec_hex = sprintf("%x", $a_sec); ensure_length($dec_hex, 5); ensure_length($sec_hex, 6); $guid = ""; $guid .= $dec_hex; $guid .= create_guid_section(3); $guid .= '-'; $guid .= create_guid_section(4); $guid .= '-'; $guid .= create_guid_section(4); $guid .= '-'; $guid .= create_guid_section(4); $guid .= '-'; $guid .= $sec_hex; $guid .= create_guid_section(6); $log->debug("Exiting create_guid method ..."); return $guid; } /** Function to create guid section for a given character * @param $characters -- characters:: Type string * @returns $return -- integer:: Type integer`` */ function create_guid_section($characters) { global $log; $log->debug("Entering create_guid_section(".$characters.") method ..."); $return = ""; for($i=0; $i<$characters; $i++) { $return .= sprintf("%x", rand(0,15)); } $log->debug("Exiting create_guid_section method ..."); return $return; } /** Function to ensure length * @param $string -- string:: Type string * @param $length -- length:: Type string */ function ensure_length(&$string, $length) { global $log; $log->debug("Entering ensure_length(".$string.",". $length.") method ..."); $strlen = strlen($string); if($strlen < $length) { $string = str_pad($string,$length,"0"); } else if($strlen > $length) { $string = substr($string, 0, $length); } $log->debug("Exiting ensure_length method ..."); } /* function microtime_diff($a, $b) { global $log; $log->debug("Entering microtime_diff(".$a.",". $b.") method ..."); list($a_dec, $a_sec) = explode(" ", $a); list($b_dec, $b_sec) = explode(" ", $b); $log->debug("Exiting microtime_diff method ..."); return $b_sec - $a_sec + $b_dec - $a_dec; } */ /** * Return the display name for a theme if it exists. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. */ function get_theme_display($theme) { global $log; $log->debug("Entering get_theme_display(".$theme.") method ..."); global $theme_name, $theme_description; $temp_theme_name = $theme_name; $temp_theme_description = $theme_description; if (is_file("./themes/$theme/config.php")) { @include("./themes/$theme/config.php"); $return_theme_value = $theme_name; } else { $return_theme_value = $theme; } $theme_name = $temp_theme_name; $theme_description = $temp_theme_description; $log->debug("Exiting get_theme_display method ..."); return $return_theme_value; } /** * Return an array of directory names. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. */ function get_themes() { global $log; $log->debug("Entering get_themes() method ..."); if ($dir = @opendir("themes")) { while (($file = readdir($dir)) !== false) { if ($file != ".." && $file != "." && $file != "CVS" && $file != "Attic" && $file != "akodarkgem" && $file != "bushtree" && $file != "coolblue" && $file != "Amazon" && $file != "busthree" && $file != "Aqua" && $file != "nature" && $file != "orange" && $file != "blue") { if(is_dir("themes/".$file)) { if(!($file[0] == '.')) { // set the initial theme name to the filename $name = $file; // if there is a configuration class, load that. if(is_file("themes/$file/config.php")) { require_once("themes/$file/config.php"); $name = $theme_name; } if(is_file("themes/$file/header.php")) { $filelist[$file] = $name; } } } } } closedir($dir); } ksort($filelist); $log->debug("Exiting get_themes method ..."); dc_dump($filelist,'$filelist DIR'); return $filelist; } /** * Create javascript to clear values of all elements in a form. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. */ function get_clear_form_js () { global $log; $log->debug("Entering get_clear_form_js () method ..."); $the_script = << debug("Exiting get_clear_form_js method ..."); return $the_script; } /** * Create javascript to set the cursor focus to specific vtiger_field in a form * when the screen is rendered. The vtiger_field name is currently hardcoded into the * the function. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. */ function get_set_focus_js () { global $log; $log->debug("Entering set_focus() method ..."); //TODO Clint 5/20 - Make this function more generic so that it can take in the target form and vtiger_field names as variables $the_script = << debug("Exiting get_set_focus_js method ..."); return $the_script; } /** * Very cool algorithm for sorting multi-dimensional arrays. Found at http://us2.php.net/manual/en/function.array-multisort.php * Syntax: $new_array = array_csort($array [, 'col1' [, SORT_FLAG [, SORT_FLAG]]]...); * Explanation: $array is the array you want to sort, 'col1' is the name of the column * you want to sort, SORT_FLAGS are : SORT_ASC, SORT_DESC, SORT_REGULAR, SORT_NUMERIC, SORT_STRING * you can repeat the 'col',FLAG,FLAG, as often you want, the highest prioritiy is given to * the first - so the array is sorted by the last given column first, then the one before ... * Example: $array = array_csort($array,'town','age',SORT_DESC,'name'); * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. */ function array_csort() { global $log; $log->debug("Entering array_csort() method ..."); $args = func_get_args(); $marray = array_shift($args); $i = 0; $msortline = "return(array_multisort("; foreach ($args as $arg) { $i++; if (is_string($arg)) { foreach ($marray as $row) { $sortarr[$i][] = $row[$arg]; } } else { $sortarr[$i] = $arg; } $msortline .= "\$sortarr[".$i."],"; } $msortline .= "\$marray));"; eval($msortline); $log->debug("Exiting array_csort method ..."); return $marray; } /** Function to set default varibles on to the global variable * @param $defaults -- default values:: Type array */ function set_default_config(&$defaults) { global $log; $log->debug("Entering set_default_config(".$defaults.") method ..."); foreach ($defaults as $name=>$value) { if ( ! isset($GLOBALS[$name]) ) { $GLOBALS[$name] = $value; } } $log->debug("Exiting set_default_config method ..."); } $toHtml = array( '"' => '"', '<' => '<', '>' => '>', '& ' => '& ', "'" => ''', ); /** Function to convert the given string to html * @param $string -- string:: Type string * @param $ecnode -- boolean:: Type boolean * @returns $string -- string:: Type string * */ function to_html($string, $encode=true){ global $log; $log->debug("Entering to_html(".$string.",".$encode.") method ..."); global $toHtml; if($encode && is_string($string)){//$string = htmlentities($string, ENT_QUOTES); if (is_array($toHtml)) $string =strip_tags($string, '