/include/utils/utils.php
PHP | 5134 lines | 3858 code | 546 blank | 730 comment | 627 complexity | 197315424f47b9465bebeda30209d9cb MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /*********************************************************************************
- * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
- * ("License"); You may not use this file except in compliance with the
- * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
- * the specific language governing rights and limitations under the License.
- * The Original Code is: SugarCRM Open Source
- * The Initial Developer of the Original Code is SugarCRM, Inc.
- * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
- * All Rights Reserved.
- * Contributor(s): ______________________________________.
- ********************************************************************************/
- /*********************************************************************************
- * $Header$
- * Description: Includes generic helper functions used throughout the application.
- * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
- * All Rights Reserved.
- * Contributor(s): ______________________________________..
- ********************************************************************************/
-
-
-
- /** This function returns the name of the person.
- * It currently returns "first last". It should not put the space if either name is not available.
- * It should not return errors if either name is not available.
- * If no names are present, it will return ""
- * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
- * All Rights Reserved.
- * Contributor(s): ______________________________________..
- */
-
- require_once('include/database/PearDatabase.php');
- require_once('include/ComboUtil.php'); //new
- require_once('include/utils/ListViewUtils.php');
- require_once('include/utils/EditViewUtils.php');
- require_once('include/utils/DetailViewUtils.php');
- require_once('include/utils/CommonUtils.php');
- require_once('include/utils/InventoryUtils.php');
- require_once('include/utils/SearchUtils.php');
- require_once('include/FormValidationUtil.php');
- require_once('include/DatabaseUtil.php');
- require_once('include/events/SqlResultIterator.inc');
- require_once('include/fields/DateTimeField.php');
- require_once('include/fields/CurrencyField.php');
- require_once('data/CRMEntity.php');
- require_once 'vtlib/Vtiger/Language.php';
-
- // Constants to be defined here
-
- // For Migration status.
- define("MIG_CHARSET_PHP_UTF8_DB_UTF8", 1);
- define("MIG_CHARSET_PHP_NONUTF8_DB_NONUTF8", 2);
- define("MIG_CHARSET_PHP_NONUTF8_DB_UTF8", 3);
- define("MIG_CHARSET_PHP_UTF8_DB_NONUTF8", 4);
-
- // For Customview status.
- define("CV_STATUS_DEFAULT", 0);
- define("CV_STATUS_PRIVATE", 1);
- define("CV_STATUS_PENDING", 2);
- define("CV_STATUS_PUBLIC", 3);
-
- // For Restoration.
- define("RB_RECORD_DELETED", 'delete');
- define("RB_RECORD_INSERTED", 'insert');
- define("RB_RECORD_UPDATED", 'update');
-
- /** Function to return a full name
- * @param $row -- row:: Type integer
- * @param $first_column -- first column:: Type string
- * @param $last_column -- last column:: Type string
- * @returns $fullname -- fullname:: Type string
- *
- */
- function return_name(&$row, $first_column, $last_column)
- {
- global $log;
- $log->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 = PearDatabase::getInstance();
- $temp_result = Array();
- // Including deleted vtiger_users for now.
- if (empty($status)) {
- $query = "SELECT id, user_name from vtiger_users";
- $params = array();
- }
- 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,first_name,last_name from vtiger_users where id=? and status='Active' union select vtiger_user2role.userid as id,vtiger_users.user_name as user_name ,
- vtiger_users.first_name as first_name ,vtiger_users.last_name as last_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 ? and status='Active' union
- select shareduserid as id,vtiger_users.user_name as user_name ,
- vtiger_users.first_name as first_name ,vtiger_users.last_name as last_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=? and vtiger_tmp_write_user_sharing_per.tabid=?";
- $params = array($current_user->id, $current_user_parent_role_seq."::%", $current_user->id, getTabid($module));
- }
- else
- {
- $log->debug("Sharing is Public. All vtiger_users should be listed");
- $query = "SELECT id, user_name,first_name,last_name from vtiger_users WHERE status=?";
- $params = array($status);
- }
- }
- if (!empty($assigned_user)) {
- $query .= " OR id=?";
- array_push($params, $assigned_user);
- }
-
- $query .= " order by user_name ASC";
-
- $result = $db->pquery($query, $params, 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']] = getFullNameFromArray('Users', $row);
- }
-
- $user_array = &$temp_result;
- }
-
- $log->debug("Exiting get_user_array method ...");
-
- return $user_array;
- }
-
- function get_group_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 $group_array = null;
- $module=$_REQUEST['module'];
-
- if($group_array == null)
- {
- require_once('include/database/PearDatabase.php');
- $db = PearDatabase::getInstance();
- $temp_result = Array();
- // Including deleted vtiger_users for now.
- $log->debug("Sharing is Public. All vtiger_users should be listed");
- $query = "SELECT groupid, groupname from vtiger_groups";
- $params = array();
-
- if($private == 'private'){
-
- $query .= " WHERE groupid=?";
- $params = array( $current_user->id);
-
- if(count($current_user_groups) != 0) {
- $query .= " OR vtiger_groups.groupid in (".generateQuestionMarks($current_user_groups).")";
- array_push($params, $current_user_groups);
- }
- $log->debug("Sharing is Private. Only the current user should be listed");
- $query .= " union select vtiger_group2role.groupid as groupid,vtiger_groups.groupname as groupname from vtiger_group2role inner join vtiger_groups on vtiger_groups.groupid=vtiger_group2role.groupid inner join vtiger_role on vtiger_role.roleid=vtiger_group2role.roleid where vtiger_role.parentrole like ?";
- array_push($params, $current_user_parent_role_seq."::%");
-
- if(count($current_user_groups) != 0) {
- $query .= " union select vtiger_groups.groupid as groupid,vtiger_groups.groupname as groupname from vtiger_groups inner join vtiger_group2rs on vtiger_groups.groupid=vtiger_group2rs.groupid where vtiger_group2rs.roleandsubid in (".generateQuestionMarks($parent_roles).")";
- array_push($params, $parent_roles);
- }
-
- $query .= " union select sharedgroupid as groupid,vtiger_groups.groupname as groupname from vtiger_tmp_write_group_sharing_per inner join vtiger_groups on vtiger_groups.groupid=vtiger_tmp_write_group_sharing_per.sharedgroupid where vtiger_tmp_write_group_sharing_per.userid=?";
- array_push($params, $current_user->id);
-
- $query .= " and vtiger_tmp_write_group_sharing_per.tabid=?";
- array_push($params, getTabid($module));
- }
- $query .= " order by groupname ASC";
-
- $result = $db->pquery($query, $params, 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['groupid']] = $row['groupname'];
- }
-
- $group_array = &$temp_result;
- }
-
- $log->debug("Exiting get_user_array method ...");
- return $group_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.",".get_class($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.",".get_class($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;
- }
-
- /**
- * Retrieve the app_currency_strings for the required language.
- */
- function return_app_currency_strings_language($language) {
- global $log;
- $log->debug("Entering return_app_currency_strings_language(".$language.") method ...");
- global $app_currency_strings, $default_language, $log, $translation_string_prefix;
- // Backup the value first
- $temp_app_currency_strings = $app_currency_strings;
- @include("include/language/$language.lang.php");
- if(!isset($app_currency_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_currency_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_currency_strings_language method ...");
- return null;
- }
- $return_value = $app_currency_strings;
-
- // Restore the value back
- $app_currency_strings = $temp_app_currency_strings;
-
- $log->debug("Exiting return_app_currency_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;
-
- checkFileAccessForInclusion("include/language/$language.lang.php");
- @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;
- static $cachedModuleStrings = array();
-
- if(!empty($cachedModuleStrings[$module])) {
- $log->debug("Exiting return_module_language method ...");
- return $cachedModuleStrings[$module];
- }
-
- $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);
- if($default_language == 'en_us') {
- require("modules/$module/language/$default_language.lang.php");
- $language_used = $default_language;
- } else {
- @include("modules/$module/language/$default_language.lang.php");
- if(!isset($mod_strings)) {
- require("modules/$module/language/en_us.lang.php");
- $language_used = 'en_us';
- } else {
- $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 ...");
- $cachedModuleStrings[$module] = $return_value;
- 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");
- }
-
- if(is_file("./themes/$file/style.css"))
- {
- $filelist[$file] = $name;
- }
- }
- }
- }
- }
- closedir($dir);
- }
-
- ksort($filelist);
- $log->debug("Exiting get_themes method ...");
- 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 = <<<EOQ
- <script type="text/javascript" language="JavaScript">
- <!-- Begin
- function clear_form(form) {
- for (j = 0; j < form.elements.length; j++) {
- if (form.elements[j].type == 'text' || form.elements[j].type == 'select-one') {
- form.elements[j].value = '';
- }
- }
- }
- // End -->
- </script>
- EOQ;
-
- $log->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 = <<<EOQ
- <script type="text/javascript" language="JavaScript">
- <!-- Begin
- function set_focus() {
- if (document.forms.length > 0) {
- for (i = 0; i < document.forms.length; i++) {
- for (j = 0; j < document.forms[i].elements.length; j++) {
- var vtiger_field = document.forms[i].elements[j];
- if ((vtiger_field.type == "text" || vtiger_field.type == "textarea" || vtiger_field.type == "password") &&
- !field.disabled && (vtiger_field.name == "first_name" || vtiger_field.name == "name")) {
- vtiger_field.focus();
- if (vtiger_field.type == "text") {
- vtiger_field.select();
- }
- break;
- }
- }
- }
- }
- }
- // End -->
- </script>
- EOQ;
-
- $log->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(
- '"' => '"',
- '<' => '<',
- '>' => '>',
- '& ' => '& ',
- "'" => ''',
- '' => '\r',
- '\r\n'=>'\n',
-
- );
-
- /** 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,$default_charset;
- //$log->debug("Entering to_html(".$string.",".$encode.") method ...");
- global $toHtml;
- $action = $_REQUEST['action'];
- $search = $_REQUEST['search'];
-
- $doconvert = false;
-
- if($_REQUEST['module'] != 'Settings' && $_REQUEST['file'] != 'ListView' && $_REQUEST['module'] != 'Portal' && $_REQUEST['module'] != "Reports")// && $_REQUEST['module'] != 'Emails')
- $ajax_action = $_REQUEST['module'].'Ajax';
-
- if(is_string($string))
- {
- if($action != 'CustomView' && $action != 'Export' && $action != $ajax_action && $action != 'LeadConvertToEntities' && $action != 'CreatePDF' && $action != 'ConvertAsFAQ' && $_REQUEST['module'] != 'Dashboard' && $action != 'CreateSOPDF' && $action != 'SendPDFMail' && (!isset($_REQUEST['submode'])) )
- {
- $doconvert = true;
- }
- else if($search == true)
- {
- // Fix for tickets #4647, #4648. Conversion required in case of search results also.
- $doconvert = true;
- }
- if ($doconvert == true)
- {
- if(strtolower($default_charset) == 'utf-8')
- $string = htmlentities($string, ENT_QUOTES, $default_charset);
- else
- $string = preg_replace(array('/</', '/>/', '/"/'), array('<', '>', '"'), $string);
- }
- }
-
- //$log->debug("Exiting to_html method ...");
- return $string;
- }
-
- /** Function to get the tablabel for a given id
- * @param $tabid -- tab id:: Type integer
- * @returns $string -- string:: Type string
- */
-
- function getTabname($tabid)
- {
- global $log;
- $log->debug("Entering getTabname(".$tabid.") method ...");
- $log->info("tab id is ".$tabid);
- global $adb;
- $sql = "select tablabel from vtiger_tab where tabid=?";
- $result = $adb->pquery($sql, array($tabid));
- $tabname= $adb->query_result($result,0,"tablabel");
- $log->debug("Exiting getTabname method ...");
- return $tabname;
-
- }
-
- /** Function to get the tab module name for a given id
- * @param $tabid -- tab id:: Type integer
- * @returns $string -- string:: Type string
- *
- */
-
- function getTabModuleName($tabid)
- {
- global $log;
- $log->debug("Entering getTabModuleName(".$tabid.") method ...");
-
- // Lookup information in cache first
- $tabname = VTCacheUtils::lookupModulename($tabid);
- if($tabname === false) {
- if (file_exists('tabdata.php') && (filesize('tabdata.php') != 0)) {
- include('tabdata.php');
- $tabname = array_search($tabid,$tab_info_array);
-
- if($tabname == false) {
- global $adb;
- $sql = "select name from vtiger_tab where tabid=?";
- $result = $adb->pquery($sql, array($tabid));
- $tabname= $adb->query_result($result,0,"name");
- }
-
- // Update information to cache for re-use
- VTCacheUtils::updateTabidInfo($tabid, $tabname);
-
- } else {
- $log->info("tab id is ".$tabid);
- global $adb;
- $sql = "select name from vtiger_tab where tabid=?";
- $result = $adb->pquery($sql, array($tabid));
- $tabname= $adb->query_result($result,0,"name");
-
- // Update information to cache for re-use
- VTCacheUtils::updateTabidInfo($tabid, $tabname);
- }
- }
- $log->debug("Exiting getTabModuleName method ...");
- return $tabname;
- }
-
- /** Function to get column fields for a given module
- * @param $module -- module:: Type string
- * @returns $column_fld -- column field :: Type array
- *
- */
-
- function getColumnFields($module)
- {
- global $log;
- $log->debug("Entering getColumnFields(".$module.") method ...");
- $log->debug("in getColumnFields ".$module);
-
- // Lookup in cache for information
- $cachedModuleFields = VTCacheUtils::lookupFieldInfo_Module($module);
-
- if($cachedModuleFields === false) {
- global $adb;
- $tabid = getTabid($module);
- if ($module == 'Calendar') {
- $tabid = array('9','16');
- }
-
- // Let us pick up all the fields first so that we can cache information
- $sql = "SELECT tabid, fieldname, fieldid, fieldlabel, columnname, tablename, uitype, typeofdata, presence
- FROM vtiger_field WHERE tabid in (" . generateQuestionMarks($tabid) . ")";
-
- $result = $adb->pquery($sql, array($tabid));
- $noofrows = $adb->num_rows($result);
-
- if($noofrows) {
- while($resultrow = $adb->fetch_array($result)) {
- // Update information to cache for re-use
- VTCacheUtils::updateFieldInfo(
- $resultrow['tabid'], $resultrow['fieldname'], $resultrow['fieldid'],
- $resultrow['fieldlabel'], $resultrow['columnname'], $resultrow['tablename'],
- $resultrow['uitype'], $resultrow['typeofdata'], $resultrow['presence']
- );
- }
- }
-
- // For consistency get information from cache
- $cachedModuleFields = VTCacheUtils::lookupFieldInfo_Module($module);
- }
-
- if($module == 'Calendar') {
- $cachedEventsFields = VTCacheUtils::lookupFieldInfo_Module('Events');
- if($cachedModuleFields == false) $cachedModuleFields = $cachedEventsFields;
- else $cachedModuleFields = array_merge($cachedModuleFields, $cachedEventsFields);
- }
-
- $column_fld = array();
- if($cachedModuleFields) {
- foreach($cachedModuleFields as $fieldinfo) {
- $column_fld[$fieldinfo['fieldname']] = '';
- }
- }
-
- $log->debug("Exiting getColumnFields method ...");
- return $column_fld;
- }
-
- /** Function to get a users's mail id
- * @param $userid -- userid :: Type integer
- * @returns $email -- email :: Type string
- *
- */
-
- function getUserEmail($userid)
- {
- global $log;
- $log->debug("Entering getUserEmail(".$userid.") method ...");
- $log->info("in getUserEmail ".$userid);
-
- global $adb;
- if($userid != '')
- {
- $sql = "select email1 from vtiger_users where id=?";
- $result = $adb->pquery($sql, array($userid));
- $email = $adb->query_result($result,0,"email1");
- }
- $log->debug("Exiting getUserEmail method ...");
- return $email;
- }
-
- /** Function to get a userid for outlook
- * @param $username -- username :: Type string
- * @returns $user_id -- user id :: Type integer
- */
-
- //outlook security
- function getUserId_Ol($username)
- {
- global $log;
- $log->debug("Entering getUserId_Ol(".$username.") method ...");
- $log->info("in getUserId_Ol ".$username);
-
- global $adb;
- $sql = "select id from vtiger_users where user_name=?";
- $result = $adb->pquery($sql, array($username));
- $num_rows = $adb->num_rows($result);
- if($num_rows > 0)
- {
- $user_id = $adb->query_result($result,0,"id");
- }
- else
- {
- $user_id = 0;
- }
- $log->debug("Exiting getUserId_Ol method ...");
- return $user_id;
- }
-
-
- /** Function to get a action id for a given action name
- * @param $action -- action name :: Type string
- * @returns $actionid -- action id :: Type integer
- */
-
- //outlook security
-
- function getActionid($action)
- {
- global $log;
- $log->debug("Entering getActionid(".$action.") method ...");
- global $adb;
- $log->info("get Actionid ".$action);
- $actionid = '';
- if(file_exists('tabdata.php') && (filesize('tabdata.php') != 0))
- {
- include('tabdata.php');
- $actionid= $action_id_array[$action];
- }
- else
- {
- $query="select * from vtiger_actionmapping where actionname=?";
- $result =$adb->pquery($query, array($action));
- $actionid=$adb->query_result($result,0,'actionid');
-
- }
- $log->info("action id selected is ".$actionid );
- $log->debug("Exiting getActionid method ...");
- return $actionid;
- }
-
- /** Function to get a action for a given action id
- * @param $action id -- action id :: Type integer
- * @returns $actionname-- action name :: Type string
- */
-
-
- function getActionname($actionid)
- {
- global $log;
- $log->debug("Entering getActionname(".$actionid.") method ...");
- global $adb;
-
- $actionname='';
-
- if (file_exists('tabdata.php') && (filesize('tabdata.php') != 0))
- {
- include('tabdata.php');
- $actionname= $action_name_array[$actionid];
- }
- else
- {
-
- $query="select * from vtiger_actionmapping where actionid=? and securitycheck=0";
- $result =$adb->pquery($query, array($actionid));
- $actionname=$adb->query_result($result,0,"actionname");
- }
- $log->debug("Exiting getActionname method ...");
- return $actionname;
- }
-
- /** Function to get a assigned user id for a given entity
- * @param $record -- entity id :: Type integer
- * @returns $user_id -- user id :: Type integer
- */
-
- function getUserId($record)
- {
- global $log;
- $log->debug("Entering getUserId(".$record.") method ...");
- $log->info("in getUserId ".$record);
-
- global $adb;
- $user_id=$adb->query_result($adb->pquery("select * from vtiger_crmentity where crmid = ?", array($record)),0,'smownerid');
- $log->debug("Exiting getUserId method ...");
- return $user_id;
- }
-
- /** Function to get a user id or group id for a given entity
- * @param $record -- entity id :: Type integer
- * @returns $ownerArr -- owner id :: Type array
- */
-
- function getRecordOwnerId($record)
- {
- global $log;
- $log->debug("Entering getRecordOwnerId(".$record.") method ...");
- global $adb;
- $ownerArr=Array();
- $query="select smownerid from vtiger_crmentity where crmid = ?";
- $result=$adb->pquery($query, array($record));
- if($adb->num_rows($result) > 0)
- {
- $ownerId=$adb->query_result($result,0,'smownerid');
- $sql_result = $adb->pquery("select count(*) as count from vtiger_users where id = ?",array($ownerId));
- if($adb->query_result($sql_result,0,'count') > 0)
- $ownerArr['Users'] = $ownerId;
- else
- $ownerArr['Groups'] = $ownerId;
- }
- $log->debug("Exiting getRecordOwnerId method ...");
- return $ownerArr;
-
- }
-
- /** Function to insert value to profile2field table
- * @param $profileid -- profileid :: Type integer
- */
-
-
- function insertProfile2field($profileid)
- {
- global $log;
- $log->debug("Entering insertProfile2field(".$profileid.") method ...");
- $log->info("in insertProfile2field ".$profileid);
-
- global $adb;
- $adb->database->SetFetchMode(ADODB_FETCH_ASSOC);
- $fld_result = $adb->pquery("select * from vtiger_field where generatedtype=1 and displaytype in (1,2,3) and vtiger_field.presence in (0,2) and tabid != 29", array());
- $num_rows = $adb->num_rows($fld_result);
- for($i=0; $i<$num_rows; $i++) {
- $tab_id = $adb->query_result($fld_result,$i,'tabid');
- $field_id = $adb->query_result($fld_result,$i,'fieldid');
- $params = array($profileid, $tab_id, $field_id, 0, 0);
- $adb->pquery("insert into vtiger_profile2field values (?,?,?,?,?)", $params);
- }
- $log->debug("Exiting insertProfile2field method ...");
- }
-
- /** Function to insert into default org field
- */
-
- function insert_def_org_field()
- {
- global $log;
- $log->debug("Entering insert_def_org_field() method ...");
- global $adb;
- $adb->database->SetFetchMode(ADODB_FETCH_ASSOC);
- $fld_result = $adb->pquery("select * from vtiger_field where generatedtype=1 and displaytype in (1,2,3) and vtiger_field.presence in (0,2) and tabid != 29", array());
- $num_rows = $adb->num_rows($fld_result);
- for($i=0; $i<$num_rows; $i++)
- {
- $tab_id = $adb->query_result($fld_result,$i,'tabid');
- $field_id = $adb->query_result($fld_result,$i,'fieldid');
- $params = array($tab_id, $field_id, 0, 0);
- $adb->pquery("insert into vtiger_def_org_field values (?,?,?,?)", $params);
- }
- $log->debug("Exiting insert_def_org_field() method ...");
- }
-
- /** Function to insert value to profile2field table
- * @param $fld_module -- field module :: Type string
- * @param $profileid -- profileid :: Type integer
- * @returns $result -- result :: Type string
- */
-
- function getProfile2FieldList($fld_module, $profileid)
- {
- global $log;
- $log->debug("Entering getProfile2FieldList(".$fld_module.",". $profileid.") method ...");
- $log->info("in getProfile2FieldList ".$fld_module. ' vtiger_profile id is '.$profileid);
-
- global $adb;
- $tabid = getTabid($fld_module);
-
- $query = "select vtiger_profile2field.visible,vtiger_field.* from vtiger_profile2field inner join vtiger_field on vtiger_field.fieldid=vtiger_profile2field.fieldid where vtiger_profile2field.profileid=? and vtiger_profile2field.tabid=? and vtiger_field.presence in (0,1,2)";
- $result = $adb->pquery($query, array($profileid, $tabid));
- $log->debug("Exiting getProfile2FieldList method ...");
- return $result;
- }
-
- /** Function to insert value to profile2fieldPermissions table
- * @param $fld_module -- field module :: Type string
- * @param $profileid -- profileid :: Type integer
- * @returns $return_data -- return_data :: Type string
- */
-
- //added by jeri
-
- function getProfile2FieldPermissionList($fld_module, $profileid)
- {
- global $log;
- $log->debug("Entering getProfile2FieldPermissionList(".$fld_module.",". $profileid.") method ...");
- $log->info("in getProfile2FieldList ".$fld_module. ' vtiger_profile id is '.$profileid);
-
- // Cache information to re-use
- static $_module_fieldpermission_cache = array();
-
- if(!isset($_module_fieldpermission_cache[$fld_module])) {
- $_module_fieldpermission_cache[$fld_module] = array();
- }
-
- // Lookup cache first
- $return_data = VTCacheUtils::lookupProfile2FieldPermissionList($fld_module, $profileid);
-
- if($return_data === false) {
-
- $return_data = array();
-
- global $adb;
- $tabid = getTabid($fld_module);
-
- $query = "SELECT vtiger_profile2field.visible, vtiger_profile2field.readonly, vtiger_field.fieldlabel, vtiger_field.uitype,
- vtiger_field.fieldid, vtiger_field.displaytype, vtiger_field.typeofdata
- FROM vtiger_profile2field INNER JOIN vtiger_field ON vtiger_field.fieldid=vtiger_profile2field.fieldid
- WHERE vtiger_profile2field.profileid=? and vtiger_profile2field.tabid=? and vtiger_field.presence in (0,2)";
-
- $qparams = array($profileid, $tabid);
- $result = $adb->pquery($query, $qparams);
-
- for($i=0; $i<$adb->num_rows($result); $i++) {
- $return_data[]=array(
- $adb->query_result($result,$i,"fieldlabel"),
- $adb->query_result($result,$i,"visible"), // From vtiger_profile2field.visible
- $adb->query_result($result,$i,"uitype"),
- $adb->query_result($result,$i,"readonly"),
- $adb->query_result($result,$i,"fieldid"),
- $adb->query_result($result,$i,"displaytype"),
- $adb->query_result($result,$i,"typeofdata")
- );
- }
-
- // Update information to cache for re-use
- VTCacheUtils::updateProfile2FieldPermissionList($fld_module, $profileid, $return…
Large files files are truncated, but you can click here to view the full file