* SPDX-License-Identifier: AGPL-3.0-only ************************************/ /* crmv@101931 */ require_once("include/ListView/ListViewSession.php"); require_once("include/ListView/RelatedListViewSession.php"); //crmv@208173 /** * Get the content of a related list */ function GetRelatedList($module,$relatedmodule,$focus,$query,$button,$returnset,$id='',$edit_val='',$del_val='') { $RLU = RelatedListUtils::getInstance(); return $RLU->GetRelatedListBase($module, $relatedmodule, $focus, $query, $button, $returnset, $id, $edit_val, $del_val); // crmv@164120 } class RelatedListUtils extends SDKExtendableUniqueClass { // these module won't have the non-admin permission part of the query public $skipPermissionModules = array( 'Products', 'Faq', 'PriceBook', 'Vendors', 'Users' ); public function __construct() { // nothing at the moment } /** Function to get related list entries in detailed array format * @param $module -- modulename:: Type string * @param $relatedmodule -- relatedmodule:: Type string * @param $focus -- focus:: Type object * @param $query -- query:: Type string * @param $button -- buttons:: Type string * @param $returnset -- returnset:: Type string * @param $id -- id:: Type string * @param $edit_val -- edit value:: Type string * @param $del_val -- delete value:: Type string * @returns $related_entries -- related entires:: Type string array * */ public function GetRelatedListBase($module,$relatedmodule,$focus,$query,$button,$returnset,$id='',$edit_val='',$del_val='') { //crmv@47905 global $onlybutton; if ($onlybutton){ return; } //crmv@47905 e $log = LoggerManager::getLogger('account_list'); $log->debug("Entering GetRelatedList(".$module.",".$relatedmodule.",focus,".$query.",".$button.",".$returnset.",".$edit_val.",".$del_val.") method ..."); require_once("data/Tracker.php"); require_once('include/database/PearDatabase.php'); global $adb, $table_prefix; global $app_strings, $mod_strings; global $current_user; global $list_max_entries_per_page, $related_list_limit; // crmv@99953 if ($related_list_limit > 0) { $related_limit = $related_list_limit; } else { $related_limit = 10; } $list_max_entries_per_page = $related_limit; // crmv@99953e $LVU = ListViewUtils::getInstance(); global $theme, $theme_path; $smarty = new VteSmarty(); // Added to have Purchase Order as form Title $theme_path="themes/".$theme."/"; $image_path=$theme_path."images/"; $smarty->assign("MOD", $mod_strings); $smarty->assign("APP", $app_strings); $smarty->assign("THEME", $theme); $smarty->assign("IMAGE_PATH",$image_path); $smarty->assign("MODULE",$relatedmodule); // We do not have RelatedListView in Detail View mode of Calendar module. So need to skip it. if ($module!= 'Calendar') { $focus->initSortByField($relatedmodule); } //Retreive the list from Database //Appending the security parameter Security fix by Don if(!in_array($relatedmodule, $this->skipPermissionModules)) { $secQuery = getNonAdminAccessControlQuery($relatedmodule, $current_user); if(strlen($secQuery) > 1) { $query = appendFromClauseToQuery($query, $secQuery); } } //TODO: fix related list with advanced sharing rules,disabled for now $query = replaceSelectQueryFromList($relatedmodule,$focus,$query); //crmv@19370 if(!in_array($relatedmodule, $this->skipPermissionModules)) { $query = $focus->listQueryNonAdminChange($query, $relatedmodule); //crmv@24715 } if($relatedmodule == 'Leads') { $query .= " AND ".$table_prefix."_leaddetails.converted = 0"; } if(!VteSession::getArray(array('rlvs', $module, $relatedmodule))) { $modObj = new ListViewSession(); $modObj->sortby = $focus->default_order_by; $modObj->sorder = $focus->default_sort_order; VteSession::setArray(array('rlvs', $module, $relatedmodule), get_object_vars($modObj)); } if(!empty($_REQUEST['order_by'])) { if(method_exists($focus,'getSortOrder')) // crmv@187511 $sorder = $focus->getSortOrder(); if(method_exists($focus,'getOrderBy')) // crmv@187511 $order_by = $focus->getOrderBy(); if(isset($order_by) && $order_by != '') { VteSession::setArray(array('rlvs', $module, $relatedmodule, 'sorder'), $sorder); VteSession::setArray(array('rlvs', $module, $relatedmodule, 'sortby'), $order_by); } } elseif(VteSession::getArray(array('rlvs', $module, $relatedmodule))) { $sorder = VteSession::getArray(array('rlvs', $module, $relatedmodule, 'sorder')); $order_by = VteSession::getArray(array('rlvs', $module, $relatedmodule, 'sortby')); } else { $order_by = $focus->default_order_by; $sorder = $focus->default_sort_order; } if ($order_by == 'accountid') $order_by = 'accountname'; // crmv@118808 //Added by Don for AssignedTo ordering issue in Related Lists $query_order_by = $order_by; if($order_by == 'smownerid') { $query_order_by = "case when (".$table_prefix."_users.user_name is not null) then ".$table_prefix."_users.user_name else ".$table_prefix."_groups.groupname end "; } elseif($order_by != 'crmid' && !empty($order_by)) { $tabname = getTableNameForField($relatedmodule, $order_by); if($tabname !== '' and $tabname != NULL) $query_order_by = $tabname.".".$query_order_by; } if(!empty($query_order_by)){ $query .= ' ORDER BY '.$query_order_by.' '.$sorder; } if($relatedmodule == 'Calendar') $mod_listquery = "activity_listquery"; else $mod_listquery = strtolower($relatedmodule)."_listquery"; VteSession::set($mod_listquery, $query); //crmv@22700 global $onlyquery; if ($onlyquery) { return; } //crmv@22700e $url_qry .="&order_by=".$order_by."&sorder=".$sorder; //Retreiving the no of rows if($relatedmodule == "Calendar") { //for calendar related list, count will increase when we have multiple contacts //relationship for single activity $count_query = mkCountQuery($query); $count_result = $adb->query($count_query); $noofrows =$adb->query_result($count_result,0,"count"); } else { $count_query = mkCountQuery($query); $count_result = $adb->query($count_query); if($adb->num_rows($count_result) > 0) $noofrows =$adb->query_result($count_result,0,"count"); else $noofrows = $adb->num_rows($count_result); } //crmv@25809 if ($_REQUEST['onlycount'] == 'true'){ return Array('count'=>$noofrows); } //crmv@25809e //Setting Listview session object while sorting/pagination if(isset($_REQUEST['relmodule']) && $_REQUEST['relmodule']!='' && $_REQUEST['relmodule'] == $relatedmodule) { $relmodule = vtlib_purify($_REQUEST['relmodule']); if(VteSession::getArray(array('rlvs', $module, $relmodule))) { setSessionVar(VteSession::getArray(array('rlvs', $module, $relmodule)),$noofrows,$list_max_entries_per_page,$module,$relmodule); } } global $relationId; $start = RelatedListViewSession::getRequestCurrentPage($relationId, $query); $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows); $limit_start_rec = ($start-1) * $list_max_entries_per_page; $list_result = $adb->limitQuery($query,$limit_start_rec,$list_max_entries_per_page); // crmv@84630 if ($module == 'PriceBook' && $relatedmodule == 'Products') { $listview_entries = $LVU->getListViewEntries($focus,$relatedmodule,$list_result,$navigation_array,'relatedlist',$returnset,$edit_val,$del_val,'','','','',$skipActions); } elseif ($module == 'Products' && $relatedmodule == 'PriceBook') { $listview_entries = $LVU->getListViewEntries($focus,$relatedmodule,$list_result,$navigation_array,'relatedlist',$returnset,'EditListPrice','DeletePriceBookProductRel','','','','',$skipActions); } elseif($relatedmodule == 'SalesOrder') { $listview_entries = $LVU->getListViewEntries($focus,$relatedmodule,$list_result,$navigation_array,'relatedlist',$returnset,'SalesOrderEditView','DeleteSalesOrder','','','','',$skipActions); } else { $listview_entries = $LVU->getListViewEntries($focus,$relatedmodule,$list_result,$navigation_array,'relatedlist',$returnset,'','','','','','',$skipActions); } //Retreive the List View Table Header $id = vtlib_purify($_REQUEST['record']); $listview_header = $LVU->getListViewHeader($focus,$relatedmodule,'',$sorder,$order_by,$id,'',$module,$skipActions); if ($noofrows > 15) { $smarty->assign('SCROLLSTART','
';
$value .= '';
}
$entries[] = $value;
}
else
$entries[] = '';
//crmv@21092e crmv@23734e
// Private Permissions: crmv@17001 crmv@158871
if ($private_event && $readonly == 100) //crmv@sdk-26594
$entries[] = "".getTranslatedString('LBL_NOT_ACCESSIBLE')."";
else
$entries[] = $status;
//crmv@17001e crmv@158871e
if($row['user_name']==NULL && $row['groupname']!=NULL)
{
$entries[] = $row['groupname'];
}
else
{
$entries[] = $row['user_name'];
}
//crmv@7230 crmv@10445 crmv@105538
$clvColor = $ECU->getEntityColor('Calendar', $row["activityid"], $null, true);
if ($clvColor) {
$entries['clv_color'] = $clvColor;
// crmv@187406
$row['clv_foreground'] = '';
if ($TU->isDarkModePermitted($current_user)) {
$clvForeground = $ECU->getForegroundColor($clvColor);
$row['clv_foreground'] = $clvForeground;
}
// crmv@187406e
}
//crmv@7230e crmv@10445e crmv@105538
$i++;
$entries_list[] = $entries;
}
$return_data = array('header'=>$header,'entries'=>$entries_list,'count'=>$noofrows); //crmv@25809
$log->debug("Exiting getHistory method ...");
return $return_data;
}
}
/** Function to display the Products which are related to the PriceBook
* @param string $query - query to get the list of products which are related to the current PriceBook
* @param object $focus - PriceBook object which contains all the information of the current PriceBook
* @param string $returnset - return_module, return_action and return_id which are sequenced with & to pass to the URL which is optional
* return array $return_data which will be formed like array('header'=>$header,'entries'=>$entries_list) where as $header contains all the header columns and $entries_list will contain all the Product entries
*/
public function getPriceBookRelatedProducts($query,$focus,$returnset='') {
global $log;
$log->debug("Entering getPriceBookRelatedProducts(".$query.",focus,".$returnset.") method ...");
global $adb;
global $app_strings;
global $mod_strings;
global $current_language,$current_user;
$current_module_strings = return_module_language($current_language, 'PriceBook');
global $list_max_entries_per_page; $list_max_entries_per_page = 10;
global $urlPrefix;
global $theme;
$pricebook_id = vtlib_purify($_REQUEST['record']);
$theme_path="themes/".$theme."/";
$image_path=$theme_path."images/";
$LVU = ListViewUtils::getInstance();
$InventoryUtils = InventoryUtils::getInstance(); // crmv@42024
$noofrows = $adb->query_result($adb->query(mkCountQuery($query)),0,'count');
//crmv@25809
if ($_REQUEST['onlycount'] == 'true'){
return Array('count'=>$noofrows);
}
//crmv@25809e
$module = 'PriceBooks';
$relatedmodule = 'Products';
if(!VteSession::getArray(array('rlvs', $module, $relatedmodule)))
{
$modObj = new ListViewSession();
$modObj->sortby = $focus->default_order_by;
$modObj->sorder = $focus->default_sort_order;
VteSession::setArray(array('rlvs', $module, $relatedmodule), get_object_vars($modObj));
}
if(isset($_REQUEST['relmodule']) && $_REQUEST['relmodule']!='' && $_REQUEST['relmodule'] == $relatedmodule) {
$relmodule = vtlib_purify($_REQUEST['relmodule']);
if(VteSession::getArray(array('rlvs', $module, $relmodule))) {
setSessionVar(VteSession::getArray(array('rlvs', $module, $relmodule)),$noofrows,$list_max_entries_per_page,$module,$relmodule);
}
}
global $relationId;
$start = RelatedListViewSession::getRequestCurrentPage($relationId, $query);
$navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page,
$noofrows);
$limit_start_rec = ($start-1) * $list_max_entries_per_page;
$list_result = $adb->limitQuery($query,$limit_start_rec,$list_max_entries_per_page);
$header=array();
if(isPermitted("PriceBooks","EditView","") == 'yes' || isPermitted("PriceBooks","Delete","") == 'yes')
$header[]=$mod_strings['LBL_ACTION'];
$header[]=$mod_strings['LBL_LIST_PRODUCT_NAME'];
if(getFieldVisibilityPermission('Products', $current_user->id, 'productcode') == '0')
$header[]=$mod_strings['LBL_PRODUCT_CODE'];
if(getFieldVisibilityPermission('Products', $current_user->id, 'unit_price') == '0')
$header[]=$mod_strings['LBL_PRODUCT_UNIT_PRICE'];
$header[]=$mod_strings['LBL_PB_LIST_PRICE'];
$currency_id = $focus->column_fields['currency_id'];
$numRows = $adb->num_rows($list_result);
for($i=0; $i<$numRows; $i++) {
$entity_id = $adb->query_result($list_result,$i,"crmid");
$unit_price = $adb->query_result($list_result,$i,"unit_price");
if($currency_id != null) {
$prod_prices = $InventoryUtils->getPricesForProducts($currency_id, array($entity_id)); // crmv@42024
$unit_price = $prod_prices[$entity_id];
}
$listprice = $adb->query_result($list_result,$i,"listprice");
$field_name=$entity_id."_listprice";
$entries = Array();
$action = "";
if(isPermitted("PriceBooks","EditView","") == 'yes')
$action .= 'create'; //crmv@128983
if(isPermitted("PriceBooks","Delete","") == 'yes')
{
if($action != "")
$action .= ' ';
$action .= 'clear'; //crmv@128983
}
if($action != "")
$entries[] = $action;
$entries[] = ''.textlength_check($adb->query_result($list_result,$i,"productname")).''; //crmv@128983
if(getFieldVisibilityPermission('Products', $current_user->id, 'productcode') == '0')
$entries[] = $adb->query_result($list_result,$i,"productcode");
if(getFieldVisibilityPermission('Products', $current_user->id, 'unit_price') == '0')
$entries[] = formatUserNumber($unit_price); // crmv@173281
$entries[] = formatUserNumber($listprice); // crmv@173281
$entries_list[] = $entries;
}
$navigationOutput[] = getRecordRangeMessage($list_result, $limit_start_rec,$noofrows);
$navigationOutput[] = $LVU->getRelatedTableHeaderNavigation($navigation_array, '',$module,
$relatedmodule,$focus->id);
$return_data = array('header'=>$header,'entries'=>$entries_list,'navigation'=>$navigationOutput,'count'=>$noofrows); //crmv@25809
$log->debug("Exiting getPriceBookRelatedProducts method ...");
return $return_data;
}
}
// compatibility functions
function getAttachmentsAndNotes($parentmodule,$query,$id,$sid='') {
$RLU = RelatedListUtils::getInstance();
return $RLU->getAttachmentsAndNotes($parentmodule,$query,$id,$sid);
}
function getHistory($parentmodule,$query,$id) {
$RLU = RelatedListUtils::getInstance();
return $RLU->getHistory($parentmodule,$query,$id);
}
function getPriceBookRelatedProducts($query,$focus,$returnset='') {
$RLU = RelatedListUtils::getInstance();
return $RLU->getPriceBookRelatedProducts($query,$focus,$returnset);
}
// other functions, not sure if really necessary
function CheckFieldPermission($fieldname,$module) {
global $current_user, $adb, $table_prefix;
if($fieldname == '' || $module == '') return "false";
require('user_privileges/requireUserPrivileges.php'); // crmv@39110
if ($is_admin==false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1) {
$profileList = getCurrentUserProfileList();
$params = array(getTabid($module), $fieldname);
$sql1=
"SELECT ".$table_prefix."_field.fieldid
FROM ".$table_prefix."_field
INNER JOIN ".$table_prefix."_def_org_field ON ".$table_prefix."_def_org_field.fieldid=".$table_prefix."_field.fieldid
WHERE ".$table_prefix."_field.tabid=? AND fieldname=? AND ".$table_prefix."_field.displaytype IN (1,2,3,4)
AND ".$table_prefix."_def_org_field.visible=0
AND EXISTS(SELECT * FROM ".$table_prefix."_profile2field WHERE ".$table_prefix."_profile2field.fieldid = ".$table_prefix."_field.fieldid AND ".$table_prefix."_profile2field.visible = 0";
if (count($profileList) > 0) {
$sql1.=" AND ".$table_prefix."_profile2field.profileid IN (". generateQuestionMarks($profileList) .") "; //crmv@55241
array_push($params, $profileList);
}
$sql1 .= " ) ORDER BY block,sequence";
$result1= $adb->pquery($sql1,$params);
$permission = ($adb->num_rows($result1) > 0) ? "true" : "false";
} else {
$permission = "true";
}
return $permission;
}
function CheckColumnPermission($tablename, $columnname, $module) {
global $adb, $table_prefix;
$res = $adb->pquery("select fieldname from ".$table_prefix."_field where tablename=? and columnname=?", array($tablename, $columnname));
$fieldname = $adb->query_result_no_html($res, 0, 'fieldname');
return CheckFieldPermission($fieldname, $module);
}