Exemple #1
0
/**	function used to get the Quotes/Invoice List
 *	@param int $id - id -Contactid
 *	return string $output - Quotes/Invoice list Array
 */
function get_list_values($id, $module, $sessionid, $only_mine = 'true')
{
    checkFileAccessForInclusion('modules/' . $module . '/' . $module . '.php');
    require_once 'modules/' . $module . '/' . $module . '.php';
    require_once 'include/utils/UserInfoUtil.php';
    $adb = PearDatabase::getInstance();
    $log = vglobal('log');
    $log->debug("Entering customer portal function get_list_values");
    $check = checkModuleActive($module);
    if ($check == false) {
        return array("#MODULE INACTIVE#");
    }
    //To avoid SQL injection we are type casting as well as bound the id variable.
    $id = (int) vtlib_purify($id);
    $user = new Users();
    $userid = getPortalUserid();
    $current_user = $user->retrieveCurrentUserInfoFromFile($userid);
    $focus = new $module();
    $focus->filterInactiveFields($module);
    foreach ($focus->list_fields as $fieldlabel => $values) {
        foreach ($values as $table => $fieldname) {
            $fields_list[$fieldlabel] = $fieldname;
        }
    }
    if (!validateSession($id, $sessionid)) {
        return null;
    }
    $entity_ids_list = array();
    $show_all = show_all($module);
    if ($only_mine == 'true' || $show_all == 'false') {
        array_push($entity_ids_list, $id);
    } else {
        $contactquery = "SELECT contactid, parentid FROM vtiger_contactdetails " . " INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid" . " AND vtiger_crmentity.deleted = 0 " . " WHERE (parentid = (SELECT parentid FROM vtiger_contactdetails WHERE contactid = ?)  AND parentid != 0) OR contactid = ?";
        $contactres = $adb->pquery($contactquery, array($id, $id));
        $no_of_cont = $adb->num_rows($contactres);
        for ($i = 0; $i < $no_of_cont; $i++) {
            $cont_id = $adb->query_result($contactres, $i, 'contactid');
            $acc_id = $adb->query_result($contactres, $i, 'parentid');
            if (!in_array($cont_id, $entity_ids_list)) {
                $entity_ids_list[] = $cont_id;
            }
            if (!in_array($acc_id, $entity_ids_list) && $acc_id != '0') {
                $entity_ids_list[] = $acc_id;
            }
        }
    }
    if ($module == 'Quotes') {
        $query = "select distinct vtiger_quotes.*,vtiger_crmentity.smownerid,\n\t\tvtiger_quotes.accountid as entityid,\n\t\t'Accounts' as setype,\n\t\tvtiger_potential.potentialname,vtiger_account.accountid\n\t\tfrom vtiger_quotes left join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_quotes.quoteid\n\t\tLEFT OUTER JOIN vtiger_account\n\t\tON vtiger_account.accountid = vtiger_quotes.accountid\n\t\tLEFT OUTER JOIN vtiger_potential\n\t\tON vtiger_potential.potentialid = vtiger_quotes.potentialid\n\t\twhere vtiger_crmentity.deleted=0 and (vtiger_quotes.accountid in  (" . generateQuestionMarks($entity_ids_list) . ") )";
        $params = array($entity_ids_list);
        $fields_list['Related To'] = 'entityid';
    } else {
        if ($module == 'Invoice') {
            $query = "select distinct vtiger_invoice.*,vtiger_crmentity.smownerid, vtiger_invoice.accountid as entityid,\n\t\t'Accounts' as setype\n\t\tfrom vtiger_invoice\n\t\tleft join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_invoice.invoiceid\n\t\twhere vtiger_crmentity.deleted=0 and accountid in (" . generateQuestionMarks($entity_ids_list) . ")";
            $params = array($entity_ids_list);
            $fields_list['Related To'] = 'entityid';
        } else {
            if ($module == 'SalesOrder') {
                $query = "select distinct vtiger_salesorder.*,vtiger_crmentity.smownerid, vtiger_salesorder.accountid as entityid,\n\t\t'Accounts' as setype\n\t\tfrom vtiger_salesorder\n\t\tleft join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_salesorder.salesorderid\n\t\twhere vtiger_crmentity.deleted=0 and accountid in (" . generateQuestionMarks($entity_ids_list) . ")";
                $params = array($entity_ids_list);
                $fields_list['Related To'] = 'entityid';
            } else {
                if ($module == 'Documents') {
                    $result = $adb->pquery('SELECT fieldparams FROM vtiger_field WHERE columnname = ? AND tablename = ?', ['folderid', 'vtiger_notes']);
                    $tree = $adb->query_result($result, 0, 'fieldparams');
                    $query = "select vtiger_notes.*, vtiger_crmentity.*, vtiger_senotesrel.crmid as entityid, '' as setype, vtiger_trees_templates_data.label as foldername from vtiger_notes " . "inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_notes.notesid " . "left join vtiger_senotesrel on vtiger_senotesrel.notesid=vtiger_notes.notesid " . "LEFT JOIN vtiger_trees_templates_data ON vtiger_trees_templates_data.tree = vtiger_notes.folderid " . "where vtiger_crmentity.deleted = 0 and vtiger_trees_templates_data.templateid = ? and vtiger_senotesrel.crmid in (" . generateQuestionMarks($entity_ids_list) . ")";
                    $params = array($tree, $entity_ids_list);
                    $fields_list['Related To'] = 'entityid';
                } else {
                    if ($module == 'Contacts') {
                        $query = "select vtiger_contactdetails.*,vtiger_crmentity.smownerid from vtiger_contactdetails\n\t\t inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid\n\t\t where vtiger_crmentity.deleted = 0 and contactid IN (" . generateQuestionMarks($entity_ids_list) . ")";
                        $params = array($entity_ids_list);
                    } else {
                        if ($module == 'Assets') {
                            $accountRes = $adb->pquery("SELECT parentid FROM vtiger_contactdetails\n\t\t\t\t\t\tINNER JOIN vtiger_crmentity ON vtiger_contactdetails.contactid = vtiger_crmentity.crmid\n\t\t\t\t\t\tWHERE contactid = ? AND deleted = 0", array($id));
                            $accountRow = $adb->num_rows($accountRes);
                            if ($accountRow) {
                                $accountid = $adb->query_result($accountRes, 0, 'parentid');
                                $query = "select vtiger_assets.*, vtiger_assets.parent_id as entityid , vtiger_crmentity.smownerid from vtiger_assets\n\t\t\t\t\t\t\tinner join vtiger_crmentity on vtiger_assets.assetsid = vtiger_crmentity.crmid\n\t\t\t\t\t\t\tleft join vtiger_account on vtiger_account.accountid = vtiger_assets.parent_id\n\t\t\t\t\t\t\tleft join vtiger_products on vtiger_products.productid = vtiger_assets.product\n\t\t\t\t\t\t\twhere vtiger_crmentity.deleted = 0 and parent_id = ?";
                                $params = array($accountid);
                                $fields_list['Related To'] = 'entityid';
                            }
                        } else {
                            if ($module == 'Project') {
                                $query = "SELECT vtiger_project.*, vtiger_crmentity.smownerid\n\t\t\t\t\tFROM vtiger_project\n\t\t\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_project.projectid\n\t\t\t\t\tWHERE vtiger_crmentity.deleted = 0 AND vtiger_project.linktoaccountscontacts IN (" . generateQuestionMarks($entity_ids_list) . ")";
                                $params = array($entity_ids_list);
                                $fields_list['Related To'] = 'linktoaccountscontacts';
                            }
                        }
                    }
                }
            }
        }
    }
    $res = $adb->pquery($query, $params);
    $noofdata = $adb->num_rows($res);
    $columnVisibilityByFieldnameInfo = array();
    if ($noofdata) {
        foreach ($fields_list as $fieldlabel => $fieldname) {
            $columnVisibilityByFieldnameInfo[$fieldname] = getColumnVisibilityPermission($current_user->id, $fieldname, $module);
        }
    }
    for ($j = 0; $j < $noofdata; $j++) {
        $i = 0;
        foreach ($fields_list as $fieldlabel => $fieldname) {
            $fieldper = $columnVisibilityByFieldnameInfo[$fieldname];
            if ($fieldper == '1' && $fieldname != 'entityid') {
                continue;
            }
            $fieldlabelOrg = $fieldlabel;
            $fieldlabel = Vtiger_Language_Handler::getTranslatedString($fieldlabel, $module, vglobal('default_language'));
            $output[0][$module]['head'][0][$i]['fielddata'] = $fieldlabel;
            $fieldvalue = $adb->query_result($res, $j, $fieldname);
            $fieldValuesToRound = array('total', 'subtotal', 'discount_amount', 'pre_tax_total', 'received', 'balance', 'unit_price');
            if ($module == 'Quotes') {
                if ($fieldname == 'subject') {
                    $fieldid = $adb->query_result($res, $j, 'quoteid');
                    $filename = $fieldid . '_Quotes.pdf';
                    $fieldvalue = '<a href="index.php?&module=Quotes&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                }
                if (in_array($fieldname, $fieldValuesToRound)) {
                    $fieldvalue = round($fieldvalue, 2);
                }
                if ($fieldname == 'total') {
                    $sym = getCurrencySymbol($res, $j, 'currency_id');
                    $fieldvalue = $sym . $fieldvalue;
                }
            }
            if ($module == 'Invoice') {
                if ($fieldname == 'subject') {
                    $fieldid = $adb->query_result($res, $j, 'invoiceid');
                    $filename = $fieldid . '_Invoice.pdf';
                    $fieldvalue = '<a href="index.php?&module=Invoice&action=index&status=true&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                }
                if (in_array($fieldname, $fieldValuesToRound)) {
                    $fieldvalue = round($fieldvalue, 2);
                }
                if ($fieldname == 'total') {
                    $sym = getCurrencySymbol($res, $j, 'currency_id');
                    $fieldvalue = $sym . $fieldvalue;
                }
            }
            if ($module == 'SalesOrder') {
                if ($fieldname == 'subject') {
                    $fieldid = $adb->query_result($res, $j, 'salesorderid');
                    $filename = $fieldid . '_SalesOrder.pdf';
                    $fieldvalue = '<a href="index.php?&module=SalesOrder&action=index&status=true&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                }
                if (in_array($fieldname, $fieldValuesToRound)) {
                    $fieldvalue = round($fieldvalue, 2);
                }
                if ($fieldname == 'total') {
                    $sym = getCurrencySymbol($res, $j, 'currency_id');
                    $fieldvalue = $sym . $fieldvalue;
                }
            }
            if ($module == 'Documents') {
                if ($fieldname == 'title') {
                    $fieldid = $adb->query_result($res, $j, 'notesid');
                    $fieldvalue = '<a href="index.php?&module=Documents&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                }
                if ($fieldname == 'filename') {
                    $fieldid = $adb->query_result($res, $j, 'notesid');
                    $filename = $fieldvalue;
                    $folderid = $adb->query_result($res, $j, 'folderid');
                    $filename = $adb->query_result($res, $j, 'filename');
                    $fileactive = $adb->query_result($res, $j, 'filestatus');
                    $filetype = $adb->query_result($res, $j, 'filelocationtype');
                    if ($fileactive == 1) {
                        if ($filetype == 'I') {
                            $fieldvalue = '<a href="index.php?&downloadfile=true&folderid=' . $folderid . '&filename=' . $filename . '&module=Documents&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                        } elseif ($filetype == 'E') {
                            $fieldvalue = '<a target="_blank" href="' . $filename . '" onclick = "updateCount(' . $fieldid . ');">' . $filename . '</a>';
                        }
                    } else {
                        $fieldvalue = $filename;
                    }
                }
                if ($fieldname == 'folderid') {
                    $fieldvalue = Vtiger_Language_Handler::getTranslatedString($adb->query_result($res, $j, 'foldername'), $module, vglobal('default_language'));
                }
            }
            if ($module == 'Invoice' && $fieldname == 'salesorderid') {
                if ($fieldvalue != '') {
                    $fieldvalue = get_salesorder_name($fieldvalue);
                }
            }
            if ($module == 'Services') {
                if ($fieldname == 'servicename') {
                    $fieldid = $adb->query_result($res, $j, 'serviceid');
                    $fieldvalue = '<a href="index.php?module=Services&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                }
                if ($fieldname == 'discontinued') {
                    if ($fieldvalue == 1) {
                        $fieldvalue = 'Yes';
                    } else {
                        $fieldvalue = 'No';
                    }
                }
                if (in_array($fieldname, $fieldValuesToRound)) {
                    $fieldvalue = round($fieldvalue, 2);
                }
                if ($fieldname == 'unit_price') {
                    $sym = getCurrencySymbol($res, $j, 'currency_id');
                    $fieldvalue = $sym . $fieldvalue;
                }
            }
            if ($module == 'Contacts') {
                if ($fieldname == 'lastname' || $fieldname == 'firstname') {
                    $fieldid = $adb->query_result($res, $j, 'contactid');
                    $fieldvalue = '<a href="index.php?module=Contacts&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                } elseif ($fieldname == 'parentid') {
                    $fieldvalue = Vtiger_Functions::getCRMRecordLabel($fieldvalue);
                }
            }
            if ($module == 'Project') {
                if ($fieldname == 'projectname') {
                    $fieldid = $adb->query_result($res, $j, 'projectid');
                    $fieldvalue = '<a href="index.php?module=Project&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                }
            }
            if ($module == 'ProjectTask') {
                if ($fieldname == 'projecttaskname') {
                    $fieldid = $adb->query_result($res, $j, 'projecttaskid');
                    $fieldvalue = '<a href="index.php?module=ProjectTask&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                }
            }
            if ($module == 'ProjectMilestone') {
                if ($fieldname == 'projectmilestonename') {
                    $fieldid = $adb->query_result($res, $j, 'projectmilestoneid');
                    $fieldvalue = '<a href="index.php?module=ProjectMilestone&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                }
            }
            if ($fieldname == 'entityid' || $fieldname == 'contactid' || $fieldname == 'accountid' || $fieldname == 'potentialid' || $fieldname == 'account' || $fieldname == 'linktoaccountscontacts') {
                $crmid = $fieldvalue;
                $modulename = getSalesEntityType($crmid);
                if ($crmid != '' && $modulename != '') {
                    $fieldvalues = getEntityName($modulename, array($crmid));
                    if ($modulename == 'Contacts') {
                        $fieldvalue = '<a href="index.php?module=Contacts&action=index&id=' . $crmid . '">' . $fieldvalues[$crmid] . '</a>';
                    } elseif ($modulename == 'Accounts') {
                        $fieldvalue = '<a href="index.php?module=Accounts&action=index&id=' . $crmid . '">' . $fieldvalues[$crmid] . '</a>';
                    } elseif ($modulename == 'Potentials') {
                        $fieldvalue = $adb->query_result($res, $j, 'potentialname');
                    }
                } else {
                    $fieldvalue = '';
                }
            }
            if ($module == 'Assets' && $fieldname == 'assetname') {
                $assetname = $fieldvalue;
                $assetid = $adb->query_result($res, $j, 'assetsid');
                $fieldvalue = '<a href="index.php?module=Assets&action=index&id=' . $assetid . '">' . $assetname . '</a>';
            }
            if ($fieldname == 'product' && $module == 'Assets') {
                $crmid = $adb->query_result($res, $j, 'product');
                $fres = $adb->pquery('select vtiger_products.productname from vtiger_products where productid=?', array($crmid));
                $productname = $adb->query_result($fres, 0, 'productname');
                $fieldvalue = '<a href="index.php?module=Products&action=index&id=' . $crmid . '">' . $productname . '</a>';
            }
            if ($fieldname == 'smownerid') {
                $fieldvalue = getOwnerName($fieldvalue);
            }
            if (in_array($fieldlabelOrg, array('Status'))) {
                $fieldvalue = Vtiger_Language_Handler::getTranslatedString($fieldvalue, $module, vglobal('default_language'));
            }
            $output[1][$module]['data'][$j][$i]['fielddata'] = $fieldvalue;
            $i++;
        }
    }
    $log->debug("Exiting customer portal function get_list_values");
    return $output;
}
/**	function used to get the Quotes/Invoice List
 *	@param int $id - id -Contactid
 *	return string $output - Quotes/Invoice list Array
 */
function get_list_values($id, $module, $sessionid, $only_mine = 'true')
{
    require_once 'modules/' . $module . '/' . $module . '.php';
    require_once 'include/utils/UserInfoUtil.php';
    global $adb, $log, $current_user;
    $log->debug("Entering customer portal function get_list_values");
    $check = checkModuleActive($module);
    if ($check == false) {
        return array("#MODULE INACTIVE#");
    }
    $user = new Users();
    $userid = getPortalUserid();
    $current_user = $user->retrieveCurrentUserInfoFromFile($userid);
    $focus = new $module();
    $focus->filterInactiveFields($module);
    foreach ($focus->list_fields as $fieldlabel => $values) {
        foreach ($values as $table => $fieldname) {
            $fields_list[$fieldlabel] = $fieldname;
        }
    }
    if (!validateSession($id, $sessionid)) {
        return null;
    }
    $entity_ids_list = array();
    $show_all = show_all($module);
    if ($only_mine == 'true' || $show_all == 'false') {
        array_push($entity_ids_list, $id);
    } else {
        $contactquery = "SELECT contactid, accountid FROM vtiger_contactdetails " . " INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid" . " AND vtiger_crmentity.deleted = 0 " . " WHERE (accountid = (SELECT accountid FROM vtiger_contactdetails WHERE contactid = ?)  AND accountid != 0) OR contactid = ?";
        $contactres = $adb->pquery($contactquery, array($id, $id));
        $no_of_cont = $adb->num_rows($contactres);
        for ($i = 0; $i < $no_of_cont; $i++) {
            $cont_id = $adb->query_result($contactres, $i, 'contactid');
            $acc_id = $adb->query_result($contactres, $i, 'accountid');
            if (!in_array($cont_id, $entity_ids_list)) {
                $entity_ids_list[] = $cont_id;
            }
            if (!in_array($acc_id, $entity_ids_list) && $acc_id != '0') {
                $entity_ids_list[] = $acc_id;
            }
        }
    }
    if ($module == 'Quotes') {
        $query = "select distinct vtiger_quotes.*,vtiger_crmentity.smownerid,\n\t\tcase when vtiger_quotes.contactid is not null then vtiger_quotes.contactid else vtiger_quotes.accountid end as entityid,\n\t\tcase when vtiger_quotes.contactid is not null then 'Contacts' else 'Accounts' end as setype,\n\t\tvtiger_potential.potentialname,vtiger_account.accountid\n\t\tfrom vtiger_quotes left join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_quotes.quoteid\n\t\tLEFT OUTER JOIN vtiger_account\n\t\tON vtiger_account.accountid = vtiger_quotes.accountid\n\t\tLEFT OUTER JOIN vtiger_potential\n\t\tON vtiger_potential.potentialid = vtiger_quotes.potentialid\n\t\twhere vtiger_crmentity.deleted=0 and (vtiger_quotes.accountid in  (" . generateQuestionMarks($entity_ids_list) . ") or contactid in (" . generateQuestionMarks($entity_ids_list) . "))";
        $params = array($entity_ids_list, $entity_ids_list);
        $fields_list['Related To'] = 'entityid';
    } else {
        if ($module == 'Invoice') {
            $query = "select distinct vtiger_invoice.*,vtiger_crmentity.smownerid,\n\t\tcase when vtiger_invoice.contactid !=0 then vtiger_invoice.contactid else vtiger_invoice.accountid end as entityid,\n\t\tcase when vtiger_invoice.contactid !=0 then 'Contacts' else 'Accounts' end as setype\n\t\tfrom vtiger_invoice\n\t\tleft join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_invoice.invoiceid\n\t\twhere vtiger_crmentity.deleted=0 and (accountid in (" . generateQuestionMarks($entity_ids_list) . ") or contactid in  (" . generateQuestionMarks($entity_ids_list) . "))";
            $params = array($entity_ids_list, $entity_ids_list);
            $fields_list['Related To'] = 'entityid';
        } else {
            if ($module == 'Documents') {
                $query = "select vtiger_notes.*, vtiger_crmentity.*, vtiger_senotesrel.crmid as entityid, '' as setype,vtiger_attachmentsfolder.foldername from vtiger_notes " . "inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_notes.notesid " . "left join vtiger_senotesrel on vtiger_senotesrel.notesid=vtiger_notes.notesid " . "LEFT JOIN vtiger_attachmentsfolder ON vtiger_attachmentsfolder.folderid = vtiger_notes.folderid " . "where vtiger_crmentity.deleted = 0 and  vtiger_senotesrel.crmid in (" . generateQuestionMarks($entity_ids_list) . ")";
                $params = array($entity_ids_list);
                $fields_list['Related To'] = 'entityid';
            } else {
                if ($module == 'Contacts') {
                    $query = "select vtiger_contactdetails.*,vtiger_crmentity.smownerid from vtiger_contactdetails\n\t\t inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid\n\t\t where vtiger_crmentity.deleted = 0 and contactid IN (" . generateQuestionMarks($entity_ids_list) . ")";
                    $params = array($entity_ids_list);
                } else {
                    if ($module == 'Assets') {
                        $accountRes = $adb->pquery("SELECT accountid FROM vtiger_contactdetails\n\t\t\t\t\t\tINNER JOIN vtiger_crmentity ON vtiger_contactdetails.contactid = vtiger_crmentity.crmid\n\t\t\t\t\t\tWHERE contactid = ? AND deleted = 0", array($id));
                        $accountRow = $adb->num_rows($accountRes);
                        if ($accountRow) {
                            $accountid = $adb->query_result($accountRes, 0, 'accountid');
                            $query = "select vtiger_assets.*, vtiger_assets.account as entityid , vtiger_crmentity.smownerid from vtiger_assets\n\t\t\t\t\t\tinner join vtiger_crmentity on vtiger_assets.assetsid = vtiger_crmentity.crmid\n\t\t\t\t\t\tleft join vtiger_account on vtiger_account.accountid = vtiger_assets.account\n\t\t\t\t\t\tleft join vtiger_products on vtiger_products.productid = vtiger_assets.product\n\t\t\t\t\t\twhere vtiger_crmentity.deleted = 0 and account = ?";
                            $params = array($accountid);
                            $fields_list['Related To'] = 'entityid';
                        }
                    } else {
                        if ($module == 'Project') {
                            $query = "SELECT vtiger_project.*, vtiger_crmentity.smownerid\n\t\t\t\t\tFROM vtiger_project\n\t\t\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_project.projectid\n\t\t\t\t\tWHERE vtiger_crmentity.deleted = 0 AND vtiger_project.linktoaccountscontacts IN (" . generateQuestionMarks($entity_ids_list) . ")";
                            $params = array($entity_ids_list);
                            $fields_list['Related To'] = 'linktoaccountscontacts';
                        }
                    }
                }
            }
        }
    }
    $res = $adb->pquery($query, $params);
    $noofdata = $adb->num_rows($res);
    $columnVisibilityByFieldnameInfo = array();
    if ($noofdata) {
        foreach ($fields_list as $fieldlabel => $fieldname) {
            $columnVisibilityByFieldnameInfo[$fieldname] = getColumnVisibilityPermission($current_user->id, $fieldname, $module);
        }
    }
    for ($j = 0; $j < $noofdata; $j++) {
        $i = 0;
        foreach ($fields_list as $fieldlabel => $fieldname) {
            $fieldper = $columnVisibilityByFieldnameInfo[$fieldname];
            if ($fieldper == '1' && $fieldname != 'entityid') {
                continue;
            }
            $fieldlabel = getTranslatedString($fieldlabel, $module);
            $output[0][$module]['head'][0][$i]['fielddata'] = $fieldlabel;
            $fieldvalue = $adb->query_result($res, $j, $fieldname);
            if ($module == 'Quotes') {
                if ($fieldname == 'subject') {
                    $fieldid = $adb->query_result($res, $j, 'quoteid');
                    $filename = $fieldid . '_Quotes.pdf';
                    $fieldvalue = '<a href="index.php?&module=Quotes&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                }
                if ($fieldname == 'total') {
                    $sym = getCurrencySymbol($res, $j, 'currency_id');
                    $fieldvalue = $sym . $fieldvalue;
                }
            }
            if ($module == 'Invoice') {
                if ($fieldname == 'subject') {
                    $fieldid = $adb->query_result($res, $j, 'invoiceid');
                    $filename = $fieldid . '_Invoice.pdf';
                    $fieldvalue = '<a href="index.php?&module=Invoice&action=index&status=true&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                }
                if ($fieldname == 'total') {
                    $sym = getCurrencySymbol($res, $j, 'currency_id');
                    $fieldvalue = $sym . $fieldvalue;
                }
            }
            if ($module == 'Documents') {
                if ($fieldname == 'title') {
                    $fieldid = $adb->query_result($res, $j, 'notesid');
                    $fieldvalue = '<a href="index.php?&module=Documents&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                }
                if ($fieldname == 'filename') {
                    $fieldid = $adb->query_result($res, $j, 'notesid');
                    $filename = $fieldvalue;
                    $folderid = $adb->query_result($res, $j, 'folderid');
                    $filename = $adb->query_result($res, $j, 'filename');
                    $fileactive = $adb->query_result($res, $j, 'filestatus');
                    $filetype = $adb->query_result($res, $j, 'filelocationtype');
                    if ($fileactive == 1) {
                        if ($filetype == 'I') {
                            $fieldvalue = '<a href="index.php?&downloadfile=true&folderid=' . $folderid . '&filename=' . $filename . '&module=Documents&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                        } elseif ($filetype == 'E') {
                            $fieldvalue = '<a target="_blank" href="' . $filename . '" onclick = "updateCount(' . $fieldid . ');">' . $filename . '</a>';
                        }
                    } else {
                        $fieldvalue = $filename;
                    }
                }
                if ($fieldname == 'folderid') {
                    $fieldvalue = $adb->query_result($res, $j, 'foldername');
                }
            }
            if ($module == 'Invoice' && $fieldname == 'salesorderid') {
                if ($fieldvalue != '') {
                    $fieldvalue = get_salesorder_name($fieldvalue);
                }
            }
            if ($module == 'Services') {
                if ($fieldname == 'servicename') {
                    $fieldid = $adb->query_result($res, $j, 'serviceid');
                    $fieldvalue = '<a href="index.php?module=Services&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                }
                if ($fieldname == 'discontinued') {
                    if ($fieldvalue == 1) {
                        $fieldvalue = 'Yes';
                    } else {
                        $fieldvalue = 'No';
                    }
                }
                if ($fieldname == 'unit_price') {
                    $sym = getCurrencySymbol($res, $j, 'currency_id');
                    $fieldvalue = $sym . $fieldvalue;
                }
            }
            if ($module == 'Contacts') {
                if ($fieldname == 'lastname' || $fieldname == 'firstname') {
                    $fieldid = $adb->query_result($res, $j, 'contactid');
                    $fieldvalue = '<a href="index.php?module=Contacts&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                }
            }
            if ($module == 'Project') {
                if ($fieldname == 'projectname') {
                    $fieldid = $adb->query_result($res, $j, 'projectid');
                    $fieldvalue = '<a href="index.php?module=Project&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
                }
            }
            if ($fieldname == 'entityid' || $fieldname == 'contactid' || $fieldname == 'accountid' || $fieldname == 'potentialid' || $fieldname == 'account' || $fieldname == 'linktoaccountscontacts') {
                $crmid = $fieldvalue;
                $modulename = getSalesEntityType($crmid);
                if ($crmid != '' && $modulename != '') {
                    $fieldvalues = getEntityName($modulename, array($crmid));
                    if ($modulename == 'Contacts') {
                        $fieldvalue = '<a href="index.php?module=Contacts&action=index&id=' . $crmid . '">' . $fieldvalues[$crmid] . '</a>';
                    } elseif ($modulename == 'Accounts') {
                        $fieldvalue = '<a href="index.php?module=Accounts&action=index&id=' . $crmid . '">' . $fieldvalues[$crmid] . '</a>';
                    } elseif ($modulename == 'Potentials') {
                        $fieldvalue = $adb->query_result($res, $j, 'potentialname');
                    }
                } else {
                    $fieldvalue = '';
                }
            }
            if ($module == 'Assets' && $fieldname == 'assetname') {
                $assetname = $fieldvalue;
                $assetid = $adb->query_result($res, $j, 'assetsid');
                $fieldvalue = '<a href="index.php?module=Assets&action=index&id=' . $assetid . '">' . $assetname . '</a>';
            }
            if ($fieldname == 'product' && $module == 'Assets') {
                $crmid = $adb->query_result($res, $j, 'product');
                $fres = $adb->pquery('select vtiger_products.productname from vtiger_products where productid=?', array($crmid));
                $productname = $adb->query_result($fres, 0, 'productname');
                $fieldvalue = '<a href="index.php?module=Products&action=index&id=' . $crmid . '">' . $productname . '</a>';
            }
            if ($fieldname == 'smownerid') {
                $fieldvalue = getOwnerName($fieldvalue);
            }
            $output[1][$module]['data'][$j][$i]['fielddata'] = $fieldvalue;
            $i++;
        }
    }
    $log->debug("Exiting customer portal function get_list_values");
    return $output;
}