* SPDX-License-Identifier: AGPL-3.0-only
************************************/
require_once('include/utils/utils.php');
require_once('include/utils/RecurringType.php');
require_once('include/utils/crmv_utils.php');
require_once('include/QueryGenerator/QueryGenerator.php');
require_once('vtlib/Vtecrm/Module.php'); // crmv@104568
require_once('include/utils/VtlibUtils.php');
/**
* Check if user id belongs to a system admin.
*/
function is_admin($user) {
return ($user->is_admin == 'on');
}
/**
* Create HTML to display select options in a dropdown list. To be used inside
* of a select statement in a form. This method expects the option list to have keys and values. The keys are the ids. The values is an array of the datas
* param $option_list - the array of strings to that contains the option list
* param $selected - the string which contains the default value
*/
function get_select_options_with_id (&$option_list, $selected_key, $advsearch='false') {
global $log;
$log->debug("Entering get_select_options_with_id (".$option_list.",".$selected_key.",".$advsearch.") method ...");
$log->debug("Exiting get_select_options_with_id method ...");
return get_select_options_with_id_separate_key($option_list, $option_list, $selected_key, $advsearch);
}
/**
* Create HTML to display select options in a dropdown list. To be used inside
* of a select statement in a form. This method expects the option list to have keys and values. The keys are the ids.
* The values are the display strings.
*/
function get_select_options_array (&$option_list, $selected_key, $advsearch='false', &$selected_value=false) { //crmv@160843
global $log;
$log->debug("Entering get_select_options_array (".$option_list.",".$selected_key.",".$advsearch.") method ...");
$log->debug("Exiting get_select_options_array method ...");
return get_options_array_seperate_key($option_list, $option_list, $selected_key, $advsearch, $selected_value); //crmv@160843
}
/**
* Create HTML to display select options in a dropdown list. To be used inside
* of a select statement in a form. This method expects the option list to have keys and values. The keys are the ids. The value is an array of data
* param $label_list - the array of strings to that contains the option list
* param $key_list - the array of strings to that contains the values list
* param $selected - the string which contains the default value
*/
function get_options_array_seperate_key (&$label_list, &$key_list, $selected_key, $advsearch='false', &$selected_value=false) { //crmv@160843
global $log;
$log->debug("Entering get_options_array_seperate_key (".$label_list.",".$key_list.",".$selected_key.",".$advsearch.") method ...");
global $app_strings;
if($advsearch=='true')
$select_options = "\n";
else
$select_options = "";
//for setting null selection values to human readable --None--
$pattern = "/'0?'>";
$replacement = "''>".$app_strings['LBL_NONE']."<";
if (!is_array($selected_key)) $selected_key = array($selected_key);
//create the type dropdown domain and set the selected value if $opp value already exists
if (!empty($key_list)) {
foreach ($key_list as $option_key=>$option_value) {
$selected_string = '';
// the system is evaluating $selected_key == 0 || '' to true. Be very careful when changing this. Test all cases.
// The vte_reported bug was only happening with one of the vte_users in the drop down. It was being replaced by none.
if (($option_key != '' && $selected_key == $option_key) || ($selected_key == '' && $option_key == '') || (in_array($option_key, $selected_key)))
{
$selected_string = 'selected';
$selected_value = $option_key; //crmv@160843
}
$html_value = $option_key;
$select_options .= "\n";
$options[$html_value]=array($label_list[$option_key]=>$selected_string);
}
}
$select_options = preg_replace($pattern, $replacement, $select_options);
$log->debug("Exiting get_options_array_seperate_key method ...");
return $options;
}
/**
* Create HTML to display select options in a dropdown list. To be used inside
* of a select statement in a form. This method expects the option list to have keys and values. The keys are the ids.
* The values are the display strings.
*/
function get_select_options_with_id_separate_key(&$label_list, &$key_list, $selected_key, $advsearch='false')
{
global $log;
$log->debug("Entering get_select_options_with_id_separate_key(".$label_list.",".$key_list.",".$selected_key.",".$advsearch.") method ...");
global $app_strings;
if($advsearch=='true')
$select_options = "\n";
else
$select_options = "";
$pattern = "/'0?'>";
$replacement = "''>".$app_strings['LBL_NONE']."<";
if (!is_array($selected_key)) $selected_key = array($selected_key);
foreach ($key_list as $option_key=>$option_value) {
$selected_string = '';
if (($option_key != '' && $selected_key == $option_key) || ($selected_key == '' && $option_key == '') || (in_array($option_key, $selected_key)))
{
$selected_string = 'selected ';
}
$html_value = $option_key;
$select_options .= "\n";
}
$select_options = preg_replace($pattern, $replacement, $select_options);
$log->debug("Exiting get_select_options_with_id_separate_key method ...");
return $select_options;
}
/**
* Converts localized date format string to jscalendar format
* Example: $array = array_csort($array,'town','age',SORT_DESC,'name');
*/
function parse_calendardate($local_format) {
global $log;
$log->debug("Entering parse_calendardate(".$local_format.") method ...");
global $current_user;
if($current_user->date_format == 'dd-mm-yyyy')
{
$dt_popup_fmt = "%d-%m-%Y";
}
elseif($current_user->date_format == 'mm-dd-yyyy')
{
$dt_popup_fmt = "%m-%d-%Y";
}
elseif($current_user->date_format == 'yyyy-mm-dd')
{
$dt_popup_fmt = "%Y-%m-%d";
}
//ds@30
elseif($current_user->date_format == 'mm.dd.yyyy')
{
$dt_popup_fmt = "%m.%d.%Y";
}
elseif($current_user->date_format == 'dd.mm.yyyy')
{
$dt_popup_fmt = "%d.%m.%y";
}
elseif($current_user->date_format == 'yyyy.mm.dd')
{
$dt_popup_fmt = "%Y.%m.%d";
}
elseif($current_user->date_format == 'mm/dd/yyyy')
{
$dt_popup_fmt = "%m/%d/%Y";
}
elseif($current_user->date_format == 'dd/mm/yyyy')
{
$dt_popup_fmt = "%d/%m/%y";
}
elseif($current_user->date_format == 'yyyy/mm/dd')
{
$dt_popup_fmt = "%Y/%m/%d";
}
//ds@30e
$log->debug("Exiting parse_calendardate method ...");
return $dt_popup_fmt;
}
/**
* Decodes the given set of special character
* input values $string - string to be converted, $encode - flag to decode
* returns the decoded value in string fromat
*/
function from_html($string, $encode=true){
global $log;
if(is_string($string)){
if(preg_match("/(';
if($imagename != '')
{
$log->debug("Exiting getProductImages method ...");
return $script;
}
}
/**
* This function is used to save the Images .
* It acceps the File lists,modulename,id and the mode as arguments
* It returns the array details of the upload
*/
function SaveImage($file,$module,$id,$mode)
{
global $log, $root_directory;
$log->debug("Entering SaveImage(".$file.",".$module.",".$id.",".$mode.") method ...");
global $adb;
$uploaddir = $root_directory."test/".$module."/" ;//set this to which location you need to give the contact image
$log->info("The Location to Save the Contact Image is ".$uploaddir);
$file_path_name = $file['imagename']['name'];
if (isset($_REQUEST['imagename_hidden'])) {
$file_name = vtlib_purify($_REQUEST['imagename_hidden']);
} else {
//allowed filename like UTF-8 Character
$file_name = ltrim(basename(" ".$file_path_name)); // basename($file_path_name);
}
$image_error="false";
$saveimage="true";
if($file_name!="")
{
$log->debug("Contact Image is given for uploading");
$image_name_val=file_exist_fn($file_name,0);
$encode_field_values="";
$errormessage="";
$move_upload_status=move_uploaded_file($file["imagename"]["tmp_name"],$uploaddir.$image_name_val);
$image_error="false";
//if there is an error in the uploading of image
$filetype= $file['imagename']['type'];
$filesize = $file['imagename']['size'];
$filetype_array=explode("/",$filetype);
$file_type_val_image=strtolower($filetype_array[0]);
$file_type_val=strtolower($filetype_array[1]);
$log->info("The File type of the Contact Image is :: ".$file_type_val);
//checking the uploaded image is if an image type or not
if(!$move_upload_status) //if any error during file uploading
{
$log->debug("Error is present in uploading Contact Image.");
$errorCode = $file['imagename']['error'];
if($errorCode == 4)
{
$errorcode="no-image";
$saveimage="false";
$image_error="true";
}
else if($errorCode == 2)
{
$errormessage = 2;
$saveimage="false";
$image_error="true";
}
else if($errorCode == 3 )
{
$errormessage = 3;
$saveimage="false";
$image_error="true";
}
}
else
{
$log->debug("Successfully uploaded the Contact Image.");
if($filesize != 0)
{
if (($file_type_val == "jpeg" ) || ($file_type_val == "png") || ($file_type_val == "jpg" ) || ($file_type_val == "pjpeg" ) || ($file_type_val == "x-png") || ($file_type_val == "gif") ) //Checking whether the file is an image or not
{
$saveimage="true";
$image_error="false";
}
else
{
$savelogo="false";
$image_error="true";
$errormessage = "image";
}
}
else
{
$savelogo="false";
$image_error="true";
$errormessage = "invalid";
}
}
}
else //if image is not given
{
$log->debug("Contact Image is not given for uploading.");
if($mode=="edit" && $image_error=="false" )
{
if($module='contact')
$image_name_val=getContactImageName($id);
elseif($module='user')
$image_name_val=getUserImageName($id);
$saveimage="true";
}
else
{
$image_name_val="";
}
}
$return_value=array('imagename'=>$image_name_val,
'imageerror'=>$image_error,
'errormessage'=>$errormessage,
'saveimage'=>$saveimage,
'mode'=>$mode);
$log->debug("Exiting SaveImage method ...");
return $return_value;
}
/**
* This function is used to generate file name if more than one image with same name is added to a given Product.
* Param $filename - product file name
* Param $exist - number time the file name is repeated.
*/
function file_exist_fn($filename,$exist)
{
global $log;
$log->debug("Entering file_exist_fn(".$filename.",".$exist.") method ...");
global $uploaddir;
if(!isset($exist))
{
$exist=0;
}
$filename_path=$uploaddir.$filename;
if (file_exists($filename_path)) //Checking if the file name already exists in the directory
{
if($exist!=0)
{
$previous=$exist-1;
$next=$exist+1;
$explode_name=explode("_",$filename);
$implode_array=array();
for($j=0;$jdebug("Exiting file_exist_fn method ...");
return $testfilename;
}
}
else
{
$log->debug("Exiting file_exist_fn method ...");
return $filename;
}
}
/**
* This function is used get the User Count.
* It returns the array which has the total vte_users ,admin vte_users,and the non admin vte_users
*/
function UserCount()
{
global $log;
$log->debug("Entering UserCount() method ...");
global $adb, $table_prefix;
$result=$adb->pquery("select id from ".$table_prefix."_users where deleted =0", array()); // crmv@39110
$user_count=$adb->num_rows($result);
$result=$adb->pquery("select id from ".$table_prefix."_users where deleted =0 AND is_admin != 'on'", array()); // crmv@39110
$nonadmin_count = $adb->num_rows($result);
$admin_count = $user_count-$nonadmin_count;
$count=array('user'=>$user_count,'admin'=>$admin_count,'nonadmin'=>$nonadmin_count);
$log->debug("Exiting UserCount method ...");
return $count;
}
/**
* This function is used to create folders recursively.
* Param $dir - directory name
* Param $mode - directory access mode
* Param $recursive - create directory recursive, default true
*/
function mkdirs($dir, $mode = 0777, $recursive = true)
{
global $log;
$log->debug("Entering mkdirs(".$dir.",".$mode.",".$recursive.") method ...");
if( is_null($dir) || $dir === "" ){
$log->debug("Exiting mkdirs method ...");
return FALSE;
}
if( is_dir($dir) || $dir === "/" ){
$log->debug("Exiting mkdirs method ...");
return TRUE;
}
if( mkdirs(dirname($dir), $mode, $recursive) ){
$log->debug("Exiting mkdirs method ...");
return mkdir($dir, $mode);
}
$log->debug("Exiting mkdirs method ...");
return FALSE;
}
/**
* This function is used to set the Object values from the REQUEST values.
* @param object reference $focus - reference of the object
*/
function setObjectValuesFromRequest($focus)
{
global $log, $current_user, $iAmAProcess; //crmv@144872
$log->debug("Entering setObjectValuesFromRequest(focus) method ...");
$currencyid=fetchCurrency($current_user->id);
$rate_symbol = getCurrencySymbolandCRate($currencyid);
$rate = $rate_symbol['rate'];
if(isset($_REQUEST['record']))
{
$focus->id = $_REQUEST['record'];
}
if(isset($_REQUEST['mode']))
{
$focus->mode = $_REQUEST['mode'];
}
foreach($focus->column_fields as $fieldname => $val)
{
if(isset($_REQUEST[$fieldname]))
{
if(is_array($_REQUEST[$fieldname]))
$value = $_REQUEST[$fieldname];
else
$value = trim($_REQUEST[$fieldname]);
$focus->column_fields[$fieldname] = $value;
}
}
//crmv@144872
if(isInventoryModule($focus->modulename) && $_REQUEST['action'] != $focus->modulename.'Ajax' && $_REQUEST['ajxaction'] != 'DETAILVIEW' && $_REQUEST['action'] != 'MassEditSave' && !$iAmAProcess)
{
$InventoryUtils = InventoryUtils::getInstance();
$inventoryTotals = $InventoryUtils->saveInventoryProductDetails($focus,$focus->modulename,'false','',true);
if (!empty($inventoryTotals)) {
foreach($inventoryTotals as $fieldname => $value) {
$focus->column_fields[$fieldname] = $value;
}
}
}
//crmv@144872e
// crmv@198024 - copy prodattr_ fields to column_fields
if ($focus->modulename == 'Products') {
foreach ($_REQUEST as $k => $v) {
if (substr($k, 0, 9) === 'prodattr_') {
$focus->column_fields[$k] = $v;
}
}
}
// crmv@198024e
//crmv@171832
if ($focus->mode == 'edit' && isset($_REQUEST['editview_etag'])){
if (method_exists('EditViewChangeLog','set_currentid')){
EditViewChangeLog::set_currentid($_REQUEST['editview_etag']);
$focus->editview_etag = $_REQUEST['editview_etag'];
}
if (method_exists('EditViewChangeLog','get_data')){
$focus->editview_presavedata = EditViewChangeLog::get_data();
}
$focus->editview_aftersavedata = Array();
foreach($focus->column_fields as $fieldname => $val){
if(isset($_REQUEST[$fieldname])){
$focus->editview_aftersavedata[$fieldname] = $_REQUEST[$fieldname];
// crmv@177395
// I need to replicate column_fields, which always has the key, even if the field is not in REQUEST
} else {
$focus->editview_aftersavedata[$fieldname] = null;
}
// crmv@177395e
}
}
//crmv@171832e
$log->debug("Exiting setObjectValuesFromRequest method ...");
}
// crmv@64542 - added inventory and product modules
/**
* Function to write the tabid and name to a flat file vte_tabdata.txt so that the data
* is obtained from the file instead of repeated queries
* returns null
*/
function create_tab_data_file() {
global $log;
global $adb, $table_prefix;
$log->debug("Entering create_tab_data_file() method ...");
$log->info("creating vte_tabdata file");
// vtlib customization: Disabling the tab item based on presence
$sql = "select * from ".$table_prefix."_tab where presence in (0,2)";
$result = $adb->pquery($sql, array());
$num_rows=$adb->num_rows($result);
$result_array=Array();
$seq_array=Array();
$ownedby_array=Array();
$entitymods_array = array(); // crmv@164144
for ($i=0; $i<$num_rows; ++$i) {
$tabid = $adb->query_result_no_html($result,$i,'tabid');
$tabname = $adb->query_result($result,$i,'name');
$presence = $adb->query_result_no_html($result,$i,'presence');
$ownedby = $adb->query_result_no_html($result,$i,'ownedby');
$result_array[$tabname]=$tabid;
$seq_array[$tabid]=$presence;
$ownedby_array[$tabid]=$ownedby;
// crmv@164144
if ($adb->query_result_no_html($result,$i,'isentitytype') == '1') {
$entitymods_array[] = $tabname;
}
// crmv@164144e
}
//Constructing the actionname=>actionid array
$actionid_array=Array();
$sql1="select * from ".$table_prefix."_actionmapping";
$result1=$adb->pquery($sql1, array());
$num_seq1=$adb->num_rows($result1);
for ($i=0; $i<$num_seq1; ++$i) {
$actionname=$adb->query_result($result1,$i,'actionname');
$actionid=$adb->query_result_no_html($result1,$i,'actionid');
$actionid_array[$actionname]=$actionid;
}
//Constructing the actionid=>actionname array with securitycheck=0
$actionname_array=Array();
$sql2="select * from ".$table_prefix."_actionmapping where securitycheck=0";
$result2=$adb->pquery($sql2, array());
$num_seq2=$adb->num_rows($result2);
for ($i=0; $i<$num_seq2; ++$i) {
$actionname=$adb->query_result($result2,$i,'actionname');
$actionid=$adb->query_result_no_html($result2,$i,'actionid');
$actionname_array[$actionid]=$actionname;
}
// retrieve inventory modules
$inventory_modules = array();
$res = $adb->query(
"SELECT t.tabid, t.name
FROM {$table_prefix}_tab t
INNER JOIN {$table_prefix}_tab_info ti ON ti.tabid = t.tabid AND ti.prefname = 'is_inventory'
WHERE t.presence IN (0,2) AND ti.prefvalue = '1'"
);
if ($res && $adb->num_rows($res) > 0) {
while ($row = $adb->FetchByAssoc($res, -1, false)) {
$inventory_modules[] = $row['name'];
}
}
// retrieve product modules
$product_modules = array();
$res = $adb->query(
"SELECT t.tabid, t.name
FROM {$table_prefix}_tab t
INNER JOIN {$table_prefix}_tab_info ti ON ti.tabid = t.tabid AND ti.prefname = 'is_product'
WHERE t.presence IN (0,2) AND ti.prefvalue = '1'"
);
if ($res && $adb->num_rows($res) > 0) {
while ($row = $adb->FetchByAssoc($res, -1, false)) {
$product_modules[] = $row['name'];
}
}
//crmv@140903
TabdataCache::setMulti(array(
'tab_info_array' => $result_array,
'tab_seq_array' => $seq_array,
'tab_ownedby_array' => $ownedby_array,
'action_id_array' => $actionid_array,
'action_name_array' => $actionname_array,
'inventory_modules' => $inventory_modules,
'product_modules' => $product_modules,
'entitytype_modules' => $entitymods_array,
));
$log->debug("Exiting create_tab_data_file method ...");
//crmv@140903e
}
// crmv@64542e
/**
* Function to write the vte_parenttabid and name to a flat file parent_tabdata.txt so that the data
* is obtained from the file instead of repeated queries
* returns null
*/
function create_parenttab_data_file() {
global $log, $adb, $table_prefix;
$log->debug("Entering create_parenttab_data_file() method ...");
$log->info("creating parent_tabdata file");
$result_array=Array();
$result = $adb->query("select parenttabid,parenttab_label from ".$table_prefix."_parenttab where visible=0 order by sequence");
$num_rows=$adb->num_rows($result);
for ($i=0;$i<$num_rows;++$i) {
$parenttabid=$adb->query_result_no_html($result,$i,'parenttabid');
$parenttab_label=$adb->query_result_no_html($result,$i,'parenttab_label');
$result_array[$parenttabid]=$parenttab_label;
}
//crmv@140903
$parChildTabRelArray=Array();
foreach($result_array as $parid=>$parvalue) {
$childArray=Array();
//$sql = "select * from ".$table_prefix."_parenttabrel where parenttabid=? order by sequence";
// vtlib customization: Disabling the tab item based on presence
$sql = "select * from ".$table_prefix."_parenttabrel where parenttabid=?
and tabid in (select tabid from ".$table_prefix."_tab where presence in (0,2)) order by sequence";
// END
$result = $adb->pquery($sql, array($parid));
$num_rows=$adb->num_rows($result);
for ($i=0; $i<$num_rows; ++$i) {
$childArray[] = $adb->query_result_no_html($result,$i,'tabid');
}
$parChildTabRelArray[$parid]=$childArray;
}
TabdataCache::setMulti(array(
'parent_tab_info_array' => $result_array,
'parent_child_tab_rel_array' => $parChildTabRelArray,
));
$log->debug("Exiting create_parenttab_data_file method ...");
//crmv@140903e
}
/**
* This function is used to get the all the modules that have Quick Create Feature.
* Returns Tab Name and Tablabel.
*/
function getQuickCreateModules($qc_module='') /* crmv@20702 crmv@31197 crmv@47905bis */
{
global $log;
$log->debug("Entering getQuickCreateModules() method ...");
global $adb, $table_prefix;
$cache = Cache::getInstance('getQuickCreateModules');
$tmp = $cache->get();
if ($tmp === false) {
$tmp = array();
$qc_query = "select ".$table_prefix."_tab.tablabel,".$table_prefix."_tab.name,".$table_prefix."_quickcreate.img from ".$table_prefix."_tab inner join ".$table_prefix."_quickcreate ON ".$table_prefix."_quickcreate.tabid = ".$table_prefix."_tab.tabid where ".$table_prefix."_tab.presence != 1";
$qc_query .= " order by ".$table_prefix."_tab.tablabel";
$result = $adb->query($qc_query);
if ($result && $adb->num_rows($result) > 0) {
while($row=$adb->fetchByAssoc($result)) {
$tabname = $row['name'];
$tablabel = getTranslatedString("SINGLE_$tabname", $tabname);
$img = $row['img'];
if (empty($img)) {
$img = resourcever('qc_default.png');
}
$tmp[$tabname] = array($tablabel,$tabname,$img);
}
}
$cache->set($tmp,3600);
}
if (!empty($qc_module)) {
$tmp = array($tmp[$qc_module]);
}
$return_qcmodule = Array();
foreach($tmp as $module => $info) {
if(isPermitted($module,'EditView','') == 'yes') {
$return_qcmodule[] = $info;
}
}
$log->debug("Exiting getQuickCreateModules method ...");
return $return_qcmodule;
}
/**
* This function is used to get the Quick create form vte_field parameters for a given module.
* Param $module - module name
* returns the value in array format
*/
function QuickCreate($module, $col_fields=array()) //crmv@26631
{
global $log;
$log->debug("Entering QuickCreate(".$module.") method ...");
global $adb, $table_prefix;
global $current_user;
global $mod_strings;
$tabid = getTabid($module);
//Adding Security Check
require('user_privileges/requireUserPrivileges.php'); // crmv@39110
// crmv@49510 crmv@56945 crmv@101877 crmv@165801
/* crmv@54659 : delete "OR {$table_prefix}_profile2field.mandatory = 0" */
$profileList = getCurrentUserProfileList();
if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0)
{
$quickcreate_query = "SELECT {$table_prefix}_field.fieldid, MIN({$table_prefix}_profile2field.mandatory) as mandatory
FROM ".$table_prefix."_field
INNER JOIN {$table_prefix}_profile2field ON ({$table_prefix}_profile2field.fieldid = {$table_prefix}_field.fieldid AND {$table_prefix}_profile2field.profileid IN (".generateQuestionMarks($profileList)."))
WHERE {$table_prefix}_field.tabid = ? AND {$table_prefix}_field.presence in (0,2) AND {$table_prefix}_field.displaytype = 1 AND {$table_prefix}_field.uitype != 220
GROUP BY {$table_prefix}_field.fieldid"; // crmv@174218
$params = array($profileList, $tabid);
}
else
{
$quickcreate_query = "SELECT {$table_prefix}_field.fieldid, MIN({$table_prefix}_profile2field.mandatory) as mandatory
FROM {$table_prefix}_field
INNER JOIN {$table_prefix}_def_org_field ON {$table_prefix}_def_org_field.fieldid={$table_prefix}_field.fieldid
INNER JOIN {$table_prefix}_profile2field ON ({$table_prefix}_profile2field.fieldid = {$table_prefix}_field.fieldid AND {$table_prefix}_profile2field.profileid IN (".generateQuestionMarks($profileList)."))
WHERE {$table_prefix}_field.tabid=? AND {$table_prefix}_def_org_field.visible=0 AND {$table_prefix}_field.presence in (0,2) and displaytype = 1 AND {$table_prefix}_profile2field.visible = 0 AND {$table_prefix}_field.uitype != 220
GROUP BY {$table_prefix}_field.fieldid"; // crmv@174218
$params = array($profileList, $tabid);
}
$quickcreate_query = "SELECT {$table_prefix}_field.*, CASE WHEN (q.mandatory is not null) THEN q.mandatory ELSE 1 END AS mandatory
FROM ($quickcreate_query) q
INNER JOIN {$table_prefix}_field ON {$table_prefix}_field.fieldid = q.fieldid
INNER JOIN {$table_prefix}_blocks ON {$table_prefix}_blocks.blockid = {$table_prefix}_field.block
ORDER BY {$table_prefix}_blocks.sequence, {$table_prefix}_field.sequence";
//crmv@49510e crmv@56945e crmv@101877e crmv@165801
$category = getParentTab();
$result = $adb->pquery($quickcreate_query, $params);
$noofrows = $adb->num_rows($result);
$fieldName_array = $qcreate_arr = Array();
for($i=0; $i<$noofrows; $i++)
{
$fieldtablename = $adb->query_result($result,$i,'tablename');
$uitype = $adb->query_result($result,$i,"uitype");
$fieldname = $adb->query_result($result,$i,"fieldname");
$fieldlabel = $adb->query_result($result,$i,"fieldlabel");
$maxlength = $adb->query_result($result,$i,"maximumlength");
$generatedtype = $adb->query_result($result,$i,"generatedtype");
$readonly = $adb->query_result($result,$i,"readonly");
$typeofdata = getFinalTypeOfData($adb->query_result($result,$i,"typeofdata"), $adb->query_result($result,$i,"mandatory")); //crmv@49510
$fieldid = $adb->query_result($result,$i,"fieldid");
//crmv@101877
$quickcreate = $adb->query_result($result,$i,"quickcreate");
$tmp = explode('~',$typeofdata);
$is_mandatory = ($tmp[1] == 'M');
if (!(in_array($quickcreate,array(0,2)) || $is_mandatory)) continue; // use quickcreate and mandatory fields
//crmv@101877e
if ($module == 'Charts' && in_array($fieldname, array('assigned_user_id', 'reportid'))) continue; // crmv@104740
//to get validationdata
$fldLabel_array = Array();
$fldLabel_array[getTranslatedString($fieldlabel)] = $typeofdata;
$fieldName_array[$fieldname] = $fldLabel_array;
//crmv@sdk-18508
$sdk_files = SDK::getViews($module,'');
if (!empty($sdk_files)) {
foreach($sdk_files as $sdk_file) {
$success = false;
$readonly_old = $readonly;
include($sdk_file['src']);
SDK::checkReadonly($readonly_old,$readonly,$sdk_file['mode']);
if ($success && $sdk_file['on_success'] == 'stop') {
break;
}
}
}
//crmv@sdk-18508 e
$custfld = getOutputHtml($uitype, $fieldname, $fieldlabel, $maxlength, $col_fields,$generatedtype,$module,'',$readonly,$typeofdata);
$custfld[] = $fieldid;
$qcreate_arr[]=$custfld;
}
for ($i=0,$j=0;$i $key1,1 => $key2);
}
$form_data['form'] = $return_data;
$form_data['data'] = $fieldName_array;
$log->debug("Exiting QuickCreate method ...".print_r($form_data,true));
return $form_data;
}
function getUserslist($setdefval=true,$ret_array=false) //crmv@31171
{
global $log,$current_user,$module,$adb,$assigned_user_id;
$log->debug("Entering getUserslist() method ...");
require('user_privileges/requireUserPrivileges.php'); // crmv@39110
require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
if($is_admin==false && $profileGlobalPermission[2] == 1 && ($defaultOrgSharingPermission[getTabid($module)] == 3 or $defaultOrgSharingPermission[getTabid($module)] == 0))
{
$users_combo = get_select_options_array(get_user_array(FALSE, "Active", $current_user->id,'private'), $current_user->id);
}
else
{
$users_combo = get_select_options_array(get_user_array(FALSE, "Active", $current_user->id),$current_user->id);
}
//crmv@31171
if ($ret_array) {
return $users_combo;
}
//crmv@31171e
foreach($users_combo as $userid=>$value)
{
foreach($value as $username=>$selected)
{
if ($setdefval == false) {
$change_owner .= "";
} else {
$change_owner .= "";
}
}
}
$log->debug("Exiting getUserslist method ...");
return $change_owner;
}
function getGroupslist($ret_array=false) //crmv@31171
{
global $log,$adb,$module,$current_user;
$log->debug("Entering getGroupslist() method ...");
require('user_privileges/requireUserPrivileges.php'); // crmv@39110
require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
//Commented to avoid security check for groups
if($is_admin==false && $profileGlobalPermission[2] == 1 && ($defaultOrgSharingPermission[getTabid($module)] == 3 or $defaultOrgSharingPermission[getTabid($module)] == 0))
{
$result=get_current_user_access_groups($module);
}
else
{
$result = get_group_options();
}
if($result) $nameArray = $adb->fetch_array($result);
if(!empty($nameArray))
{
if($is_admin==false && $profileGlobalPermission[2] == 1 && ($defaultOrgSharingPermission[getTabid($module)] == 3 or $defaultOrgSharingPermission[getTabid($module)] == 0))
{
$groups_combo = get_select_options_array(get_group_array(FALSE, "Active", $current_user->id,'private'), $current_user->id);
}
else
{
$groups_combo = get_select_options_array(get_group_array(FALSE, "Active", $current_user->id), $current_user->id);
}
}
//crmv@31171
if ($ret_array) {
return $groups_combo;
}
//crmv@31171e
if(is_array($groups_combo) && count($groups_combo) > 0) { // crmv@191020
foreach($groups_combo as $groupid=>$value)
{
foreach($value as $groupname=>$selected)
{
$change_groups_owner .= "";
}
}
}
$log->debug("Exiting getGroupslist method ...");
return $change_groups_owner;
}
/**
* Function to Check for Security whether the Buttons are permitted in List/Edit/Detail View of all Modules
* @param string $module -- module name
* Returns an array with permission as Yes or No
**/
function Button_Check($module)
{
global $log;
$log->debug("Entering Button_Check(".$module.") method ...");
$permit_arr = array ('EditView' => '',
'index' => '',
'Import' => '',
'Export' => '',
//crmv@8719
'Merge' => '',
'DuplicatesHandling' => '' );
//crmv@8719e
foreach($permit_arr as $action => $perr){
$tempPer=isPermitted($module,$action,'');
$permit_arr[$action] = $tempPer;
}
$permit_arr["Calendar"] = isPermitted("Calendar","index",'');
// crmv@105193
// TODO: find a way to avoid using the request
if ($_REQUEST['action'] == 'index' || $_REQUEST['action'] == 'HomeView' || $_REQUEST['action'] == 'ListView' || ($_REQUEST['ajax'] == 'true' || $_REQUEST['file'] == 'ListView')) { // crmv@160778 // crmv@173746
$permit_arr["moduleSettings"] = 'yes';
} else {
$permit_arr["moduleSettings"] = isModuleSettingPermitted($module);
}
// cmrv@163797
if ($_REQUEST['action'] == 'index' && $module == 'Calendar') {
$permit_arr["moduleSettings"] = 'no';
}
// cmrv@163797e
// crmv@105193e
$log->debug("Exiting Button_Check method ...");
return $permit_arr;
}
// crmv@144125 - moved in the EntityNameUtils class
function getEntityName($module, $ids_list, $single_result = false, $useCache = true) {
$ENU = EntityNameUtils::getInstance();
return $ENU->getEntityName($module, $ids_list, $single_result, $useCache);
}
// crmv@144125e
/**Function to get all permitted modules for a user with their parent
*/
//crmv@9587
function getAllParenttabmoduleslist($layout)
{
global $adb, $table_prefix;
global $current_user;
$resultant_array = Array();
require('user_privileges/requireUserPrivileges.php'); // crmv@39110
if ($layout == 'tabs') {
//$query = 'select name,tablabel,parenttab_label,'.$table_prefix.'_tab.tabid from '.$table_prefix.'_parenttabrel inner join '.$table_prefix.'_tab on '.$table_prefix.'_parenttabrel.tabid = '.$table_prefix.'_tab.tabid inner join '.$table_prefix.'_parenttab on '.$table_prefix.'_parenttabrel.parenttabid = '.$table_prefix.'_parenttab.parenttabid and '.$table_prefix.'_tab.presence order by '.$table_prefix.'_parenttab.sequence, '.$table_prefix.'_parenttabrel.sequence';
// vtlib customization: Disabling the tab item based on presence
$query = 'select name,tablabel,parenttab_label,'.$table_prefix.'_tab.tabid from '.$table_prefix.'_parenttabrel inner join '.$table_prefix.'_tab on '.$table_prefix.'_parenttabrel.tabid = '.$table_prefix.'_tab.tabid inner join '.$table_prefix.'_parenttab on '.$table_prefix.'_parenttabrel.parenttabid = '.$table_prefix.'_parenttab.parenttabid and '.$table_prefix.'_tab.presence in (0,2) order by '.$table_prefix.'_parenttab.sequence, '.$table_prefix.'_parenttabrel.sequence';
// END
$result = $adb->pquery($query, array());
for($i=0;$i<$adb->num_rows($result);$i++)
{
$parenttabname = $adb->query_result($result,$i,'parenttab_label');
$modulename = $adb->query_result($result,$i,'name');
$tablabel = $adb->query_result($result,$i,'tablabel');
$tabid = $adb->query_result($result,$i,'tabid');
if($is_admin){
$resultant_array[$parenttabname][] = Array($modulename,$tablabel);
}
elseif($profileGlobalPermission[2]==0 || $profileGlobalPermission[1]==0 || $profileTabsPermission[$tabid]==0) {
$resultant_array[$parenttabname][] = Array($modulename,$tablabel);
}
}
}
return $resultant_array;
}
// crmv@95157
/**
* @deprecated
* Please use the method FileStorage::decideFilePath()
* This function is kept here for compatibility only
*/
function decideFilePath() {
$FS = FileStorage::getInstance();
return $FS->decideFilePath();
}
// crmv@95157e
/**
* This function is used to get the Path in where we store the vte_files based on the module.
* @param string $module - module name
* return string $storage_path - path inwhere the file will be uploaded (also where it was stored) will be return based on the module
*/
function getModuleFileStoragePath($module)
{
global $log;
$log->debug("Entering into getModuleFileStoragePath($module) method ...");
$storage_path = "test/";
if($module == 'Products')
{
$storage_path .= 'product/';
}
if($module == 'Contacts')
{
$storage_path .= 'contact/';
}
$log->debug("Exiting from getModuleFileStoragePath($module) method. return storage_path = \"$storage_path\"");
return $storage_path;
}
/**
* This function is used to check whether the attached file is a image file or not
* @param string $file_details - vte_files array which contains all the uploaded file details
* return string $save_image - true or false. if the image can be uploaded then true will return otherwise false.
*/
function validateImageFile($file_details)
{
global $adb, $log,$app_strings;
$log->debug("Entering into validateImageFile($file_details) method.");
$savefile = 'true';
$file_type_details = explode("/",$file_details['type']);
$filetype = $file_type_details['1'];
if(!empty($filetype)) $filetype = strtolower($filetype);
if (($filetype == "jpeg" ) || ($filetype == "png") || ($filetype == "jpg" ) || ($filetype == "pjpeg" ) || ($filetype == "x-png") || ($filetype == "gif") || ($filetype == 'bmp') )
{
$saveimage = 'true';
}
else
{
$saveimage = 'false';
VteSession::concat('image_type_error', " ".$file_details[name]."".$app_strings['MSG_IS_NOT_UPLOADED']);
$log->debug("Invalid Image type == $filetype");
}
$log->debug("Exiting from validateImageFile($file_details) method. return saveimage=$saveimage");
return $saveimage;
}
/**
* This function is used to get the Email Template Details like subject and content for particular template.
* @param integer $templateid - Template Id for an Email Template
* return array $returndata - Returns Subject, Body of Template of the the particular email template.
*/
function getTemplateDetails($templateid)
{
global $adb,$log, $table_prefix;
$log->debug("Entering into getTemplateDetails($templateid) method ...");
$returndata = Array();
//crmv@80155
$result = $adb->pquery("select * from ".$table_prefix."_emailtemplates where templateid=?", array($templateid)); // crmv@39110
if ($result) while($row=$adb->fetchByASsoc($result)) $returndata = $row;
//crmv@80155e
$log->debug("Exiting from getTemplateDetails($templateid) method ...");
return $returndata;
}
//crmv@15309
function construct_ws_id($id,$module){
global $adb, $table_prefix;
$sql = "select id from ".$table_prefix."_ws_entity where name = ?";
$res = $adb->pquery($sql,Array($module));
if ($res && $adb->num_rows($res) > 0){
$ret = $adb->query_result($res,0,'id')."x".$id;
}
return $ret;
}
/**
* This function is used to merge the Template Details with the email description
* @param string $description -body of the mail(ie template)
* @param integer $tid - Id of the entity
* @param string $parent_type - module of the entity
* return string $description - Returns description, merged with the input template.
*/
function getMergedDescription($description,$id,$parent_type,$newsletterid='',$templateid='', &$replacements = null) //crmv@22700 crmv@38592
{
global $adb,$log;
$log->debug("Entering getMergedDescription ...");
require_once("include/Webservices/Retrieve.php");
require_once('modules/com_workflow/VTEntityCache.inc');//crmv@207901
require_once('modules/com_workflow/VTWorkflowUtils.php');//crmv@207901
require_once('modules/com_workflow/VTEmailRecipientsTemplate.inc');//crmv@207901
$util = new VTWorkflowUtils();
$admin = $util->adminUser();
$wsid = construct_ws_id($id,$parent_type);
if ($wsid){
$entity = new VTWorkflowEntity($admin, $wsid);
$entityCache = new VTEntityCache($admin);
$ct = new VTSimpleTemplate2($description,$newsletterid,$templateid); //crmv@22700
$description = $ct->render($entityCache, $entity->getId());
if (!is_null($replacements)) $replacements = $ct->getReplacements(); //crmv@38592
}
$util->revertUser(); //crmv@28425
$log->debug("Exiting from getMergedDescription ...");
return $description;
}
//crmv@15309 end
/** Function used to retrieve a single field value from database
* @param string $tablename - tablename from which we will retrieve the field value
* @param string $fieldname - fieldname to which we want to get the value from database
* @param string $idname - idname which is the name of the entity id in the table like, inoviceid, quoteid, etc.,
* @param int $id - entity id
* return string $fieldval - field value of the needed fieldname from database will be returned
*/
function getSingleFieldValue($tablename, $fieldname, $idname, $id, $html=true)
{
global $log, $adb;
$log->debug("Entering into function getSingleFieldValue($tablename, $fieldname, $idname, $id)");
//crmv@30007
$res = $adb->pquery("select $fieldname from $tablename where $idname = ?", array($id));
if ($res){
if ($html) {
$fieldval = $adb->query_result($res,0,$fieldname);
} else {
$fieldval = $adb->query_result_no_html($res,0,$fieldname);
}
}
//crmv@30007 e
$log->debug("Exit from function getSingleFieldValue. return value ==> \"$fieldval\"");
return $fieldval;
}
/** Function used to retrieve the rate converted into dollar tobe saved into database
* The function accepts the price in the current currency
* return integer $conv_price -
*/
function getConvertedPrice($price)
{
global $current_user;
$currencyid=fetchCurrency($current_user->id);
$rate_symbol = getCurrencySymbolandCRate($currencyid);
$conv_price = convertToDollar($price,$rate_symbol['rate']);
return $conv_price;
}
/** Function used to get the converted amount from dollar which will be showed to the user
* @param float $price - amount in dollor which we want to convert to the user configured amount
* @return float $conv_price - amount in user configured currency
*/
function getConvertedPriceFromDollar($price)
{
global $current_user;
$currencyid=fetchCurrency($current_user->id);
$rate_symbol = getCurrencySymbolandCRate($currencyid);
$conv_price = convertFromDollar($price,$rate_symbol['rate']);
return $conv_price;
}
/**
* Function to get recurring info depending on the recurring type
* return $recurObj - Object of class RecurringType
*/
function getrecurringObjValue() {
$recurring_data = array();
if (isset($_REQUEST['recurringtype']) && $_REQUEST['recurringtype'] != null && $_REQUEST['recurringtype'] != '--None--') {
if (!empty($_REQUEST['date_start'])) {
$startDate = $_REQUEST['date_start'];
}
if (!empty($_REQUEST['calendar_repeat_limit_date'])) {
$endDate = $_REQUEST['calendar_repeat_limit_date'];
} elseif (isset($_REQUEST['due_date']) && $_REQUEST['due_date'] != null) {
$endDate = $_REQUEST['due_date'];
}
if (!empty($_REQUEST['time_start'])) {
$startTime = $_REQUEST['time_start'];
}
if (!empty($_REQUEST['time_end'])) {
$endTime = $_REQUEST['time_end'];
}
$recurring_data['startdate'] = $startDate;
$recurring_data['starttime'] = $startTime;
$recurring_data['enddate'] = $endDate;
$recurring_data['endtime'] = $endTime;
$recurring_data['type'] = $_REQUEST['recurringtype'];
if ($_REQUEST['recurringtype'] == 'Weekly') {
if (isset($_REQUEST['sun_flag']) && $_REQUEST['sun_flag'] != null)
$recurring_data['sun_flag'] = true;
if (isset($_REQUEST['mon_flag']) && $_REQUEST['mon_flag'] != null)
$recurring_data['mon_flag'] = true;
if (isset($_REQUEST['tue_flag']) && $_REQUEST['tue_flag'] != null)
$recurring_data['tue_flag'] = true;
if (isset($_REQUEST['wed_flag']) && $_REQUEST['wed_flag'] != null)
$recurring_data['wed_flag'] = true;
if (isset($_REQUEST['thu_flag']) && $_REQUEST['thu_flag'] != null)
$recurring_data['thu_flag'] = true;
if (isset($_REQUEST['fri_flag']) && $_REQUEST['fri_flag'] != null)
$recurring_data['fri_flag'] = true;
if (isset($_REQUEST['sat_flag']) && $_REQUEST['sat_flag'] != null)
$recurring_data['sat_flag'] = true;
}
elseif ($_REQUEST['recurringtype'] == 'Monthly') {
if (isset($_REQUEST['repeatMonth']) && $_REQUEST['repeatMonth'] != null)
$recurring_data['repeatmonth_type'] = $_REQUEST['repeatMonth'];
if ($recurring_data['repeatmonth_type'] == 'date') {
if (isset($_REQUEST['repeatMonth_date']) && $_REQUEST['repeatMonth_date'] != null)
$recurring_data['repeatmonth_date'] = $_REQUEST['repeatMonth_date'];
else
$recurring_data['repeatmonth_date'] = 1;
}
elseif ($recurring_data['repeatmonth_type'] == 'day') {
$recurring_data['repeatmonth_daytype'] = $_REQUEST['repeatMonth_daytype'];
switch ($_REQUEST['repeatMonth_day']) {
case 0 :
$recurring_data['sun_flag'] = true;
break;
case 1 :
$recurring_data['mon_flag'] = true;
break;
case 2 :
$recurring_data['tue_flag'] = true;
break;
case 3 :
$recurring_data['wed_flag'] = true;
break;
case 4 :
$recurring_data['thu_flag'] = true;
break;
case 5 :
$recurring_data['fri_flag'] = true;
break;
case 6 :
$recurring_data['sat_flag'] = true;
break;
}
}
}
if (isset($_REQUEST['repeat_frequency']) && $_REQUEST['repeat_frequency'] != null)
$recurring_data['repeat_frequency'] = $_REQUEST['repeat_frequency'];
$recurObj = RecurringType::fromUserRequest($recurring_data);
return $recurObj;
}
}
/** Function used to get the translated string to the input string
* @param string $str - input string which we want to translate
* @return string $str - translated string, if the translated string is available then the translated string other wise original string will be returned
*/
function getTranslatedString($str,$module='')
{
//crmv@sdk
global $adb;
if (empty($adb->database) || !isModuleInstalled('SDK') || !function_exists('return_module_language')) {
return $str;
}
//crmv@sdk e
global $app_strings, $mod_strings, $log, $current_language;
//crmv@28065
if (empty($app_strings)) {
$app_strings = return_application_language($current_language);
}
//crmv@28065e
$temp_mod_strings = ($module != '' )?return_module_language($current_language,$module):$mod_strings;
$trans_str = (isset($temp_mod_strings[$str]) && !empty($temp_mod_strings[$str])) ? $temp_mod_strings[$str] : ((isset($app_strings[$str]) && !empty($app_strings[$str])) ? $app_strings[$str] : $str);
$log->debug("function getTranslatedString($str) - translated to ($trans_str)");
return $trans_str;
}
/**
* Get translated currency name string.
* @param String $str - input currency name
* @return String $str - translated currency name
*/
function getTranslatedCurrencyString($str) {
global $app_currency_strings;
if(isset($app_currency_strings) && isset($app_currency_strings[$str])) {
return $app_currency_strings[$str];
}
return $str;
}
/** function used to get the list of importable fields
* @param string $module - module name
* @return array $fieldslist - array with list of fieldnames and the corresponding translated fieldlabels. The return array will be in the format of [fieldname]=>[fieldlabel] where as the fieldlabel will be translated
*/
function getImportFieldsList($module)
{
global $adb, $log, $table_prefix;
$log->debug("Entering into function getImportFieldsList($module)");
$tabid = getTabid($module);
//Here we can add special cases for module basis, ie., if we want the fields of display type 3, we can add
$displaytype = " displaytype=1 and ".$table_prefix."_field.presence in (0,2) ";
$fieldnames = "";
//For module basis we can add the list of fields for Import mapping
if($module == "Leads" || $module == "Contacts")
{
$fieldnames = " fieldname='salutationtype' ";
}
//Form the where condition based on tabid , displaytype and extra fields
$where = " WHERE tabid=? and ( $displaytype ";
$params = array($tabid);
if($fieldnames != "")
{
$where .= " or $fieldnames ";
}
$where .= ")";
//Get the list of fields and form as array with [fieldname] => [fieldlabel]
$query = "SELECT fieldname, fieldlabel FROM ".$table_prefix."_field $where";
$result = $adb->pquery($query, $params);
for($i=0;$i<$adb->num_rows($result);$i++)
{
$fieldname = $adb->query_result($result,$i,'fieldname');
$fieldlabel = $adb->query_result($result,$i,'fieldlabel');
$fieldslist[$fieldname] = getTranslatedString($fieldlabel, $module);
}
$log->debug("Exit from function getImportFieldsList($module)");
return $fieldslist;
}
/** Function to get all the comments for a troubleticket
* @param int $ticketid -- troubleticket id
* return all the comments as a sequencial string which are related to this ticket
**/
function getTicketComments($ticketid)
{
global $log;
$log->debug("Entering getTicketComments(".$ticketid.") method ...");
global $adb, $table_prefix;
$commentlist = '';
$sql = "select comments from ".$table_prefix."_ticketcomments where ticketid=?"; // crmv@39110
$result = $adb->pquery($sql, array($ticketid));
for($i=0;$i<$adb->num_rows($result);$i++)
{
$comment = $adb->query_result($result,$i,'comments');
if($comment != '')
{
$commentlist .= '