コード例 #1
0
ファイル: yetiportal.php プロジェクト: JeRRimix/YetiForceCRM
function get_details($id, $module, $customerid, $sessionid)
{
    $adb = PearDatabase::getInstance();
    $log = vglobal('log');
    require_once 'include/utils/utils.php';
    require_once 'include/utils/UserInfoUtil.php';
    $log->debug("Entering customer portal function get_details ..");
    $user = new Users();
    $userid = getPortalUserid();
    $current_user = $user->retrieveCurrentUserInfoFromFile($userid);
    $isPermitted = check_permission($customerid, $module, $id);
    if ($isPermitted == false) {
        return array("#NOT AUTHORIZED#");
    }
    if (!validateSession($customerid, $sessionid)) {
        return null;
    }
    $params = array($id);
    if ($module == 'Quotes') {
        $query = "SELECT\n\t\t\tvtiger_quotes.*,vtiger_crmentity.*,vtiger_quotesaddress.*,\n\t\t\tvtiger_quotescf.* FROM vtiger_quotes\n\t\t\tINNER JOIN vtiger_crmentity " . "ON vtiger_crmentity.crmid = vtiger_quotes.quoteid\n\t\t\tINNER JOIN vtiger_quotesaddress\n\t\t\t\tON vtiger_quotes.quoteid = vtiger_quotesaddress.quoteaddressid\n\t\t\tLEFT JOIN vtiger_quotescf\n\t\t\t\tON vtiger_quotes.quoteid = vtiger_quotescf.quoteid\n\t\t\tWHERE vtiger_quotes.quoteid=(" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0";
    } else {
        if ($module == 'SalesOrder') {
            $query = "SELECT vtiger_salesorder.*,vtiger_crmentity.*,vtiger_salesorderaddress.*,\n\t\t\tvtiger_salesordercf.* \n\t\t\tFROM vtiger_salesorder\n\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_salesorder.salesorderid\n\t\t\tINNER JOIN vtiger_salesorderaddress ON vtiger_salesorder.salesorderid = vtiger_salesorderaddress.salesorderaddressid\n\t\t\tLEFT JOIN vtiger_salesordercf ON vtiger_salesorder.salesorderid = vtiger_salesordercf.salesorderid\n\t\t\tWHERE vtiger_salesorder.salesorderid=(" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0";
        } 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');
                $params[] = $tree;
                $query = "SELECT\n\t\t\tvtiger_notes.*,vtiger_crmentity.*, vtiger_trees_templates_data.label as foldername,vtiger_notescf.*\n\t\t\tFROM vtiger_notes\n\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_notes.notesid\n\t\t\tLEFT JOIN vtiger_trees_templates_data ON vtiger_trees_templates_data.tree = vtiger_notes.folderid\n\t\t\tLEFT JOIN vtiger_notescf ON vtiger_notescf.notesid = vtiger_notes.notesid\n\t\t\tWHERE vtiger_notes.notesid=(" . generateQuestionMarks($id) . ") AND vtiger_trees_templates_data.templateid = ? AND vtiger_crmentity.deleted=0";
            } else {
                if ($module == 'HelpDesk') {
                    $query = "SELECT\n\t\t\tvtiger_troubletickets.*,vtiger_crmentity.smownerid,vtiger_crmentity.createdtime,vtiger_crmentity.modifiedtime,vtiger_crmentity.attention,\n\t\t\tvtiger_ticketcf.*,vtiger_crmentity.description  FROM vtiger_troubletickets\n\t\t\tINNER JOIN vtiger_crmentity on vtiger_crmentity.crmid = vtiger_troubletickets.ticketid\n\t\t\tINNER JOIN vtiger_ticketcf\n\t\t\t\tON vtiger_ticketcf.ticketid = vtiger_troubletickets.ticketid\n\t\t\tWHERE (vtiger_troubletickets.ticketid=(" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0)";
                } else {
                    if ($module == 'Services') {
                        $result = $adb->pquery('SELECT fieldparams FROM vtiger_field WHERE columnname = ? AND tablename = ?', ['pscategory', 'vtiger_service']);
                        $tree = $adb->query_result($result, 0, 'fieldparams');
                        $query = "SELECT vtiger_service.*,vtiger_crmentity.*,vtiger_servicecf.*, vtiger_trees_templates_data.label as pscategory\n\t\t\tFROM vtiger_service\n\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\tON vtiger_crmentity.crmid = vtiger_service.serviceid AND vtiger_crmentity.deleted = 0\n\t\t\tLEFT JOIN vtiger_servicecf ON vtiger_service.serviceid = vtiger_servicecf.serviceid\n\t\t\tLEFT JOIN vtiger_trees_templates_data ON vtiger_trees_templates_data.tree = vtiger_service.pscategory\n\t\t\tWHERE vtiger_service.serviceid= (" . generateQuestionMarks($id) . ")";
                    } else {
                        if ($module == 'Contacts') {
                            $query = "SELECT vtiger_contactdetails.*,vtiger_contactaddress.*,vtiger_contactsubdetails.*,vtiger_contactscf.*" . " ,vtiger_crmentity.*,vtiger_customerdetails.*\n\t\t \tFROM vtiger_contactdetails\n\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\tON vtiger_crmentity.crmid = vtiger_contactdetails.contactid\n\t\t\tINNER JOIN vtiger_contactaddress\n\t\t\t\tON vtiger_contactaddress.contactaddressid = vtiger_contactdetails.contactid\n\t\t\tINNER JOIN vtiger_contactsubdetails\n\t\t\t\tON vtiger_contactsubdetails.contactsubscriptionid = vtiger_contactdetails.contactid\n\t\t\tINNER JOIN vtiger_contactscf\n\t\t\t\tON vtiger_contactscf.contactid = vtiger_contactdetails.contactid\n\t\t\tLEFT JOIN vtiger_customerdetails\n\t\t\t\tON vtiger_customerdetails.customerid = vtiger_contactdetails.contactid\n\t\t\tWHERE vtiger_contactdetails.contactid = (" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0";
                        } else {
                            if ($module == 'Accounts') {
                                $query = "SELECT vtiger_account.*,vtiger_accountaddress.*,vtiger_accountscf.*,\n\t\t\tvtiger_crmentity.* FROM vtiger_account\n\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\tON vtiger_crmentity.crmid = vtiger_account.accountid\n\t\t\tINNER JOIN vtiger_accountaddress\n\t\t\t\tON vtiger_account.accountid = vtiger_accountaddress.accountaddressid\n\t\t\tINNER JOIN vtiger_accountscf\n\t\t\t\tON vtiger_account.accountid = vtiger_accountscf.accountid" . " WHERE vtiger_account.accountid = (" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0";
                            } else {
                                if ($module == 'Products') {
                                    $query = "SELECT vtiger_products.*,vtiger_productcf.*,vtiger_crmentity.* " . "FROM vtiger_products " . "INNER JOIN vtiger_crmentity " . "ON vtiger_crmentity.crmid = vtiger_products.productid " . "LEFT JOIN vtiger_productcf " . "ON vtiger_productcf.productid = vtiger_products.productid " . "LEFT JOIN vtiger_vendor\n\t\t\tON vtiger_vendor.vendorid = vtiger_products.vendor_id " . "WHERE vtiger_products.productid = (" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0";
                                } else {
                                    if ($module == 'Assets') {
                                        $query = "SELECT vtiger_assets.*, vtiger_assetscf.*, vtiger_crmentity.*\n\t\tFROM vtiger_assets\n\t\tINNER JOIN vtiger_crmentity\n\t\tON vtiger_assets.assetsid = vtiger_crmentity.crmid\n\t\tINNER JOIN vtiger_assetscf\n\t\tON vtiger_assetscf.assetsid = vtiger_assets.assetsid\n\t\tWHERE vtiger_crmentity.deleted = 0 AND vtiger_assets.assetsid = (" . generateQuestionMarks($id) . ")";
                                    } else {
                                        if ($module == 'Project') {
                                            $query = "SELECT vtiger_project.*, vtiger_projectcf.*, vtiger_crmentity.*\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\tLEFT JOIN vtiger_projectcf ON vtiger_projectcf.projectid = vtiger_project.projectid\n\t\t\t\t\tWHERE vtiger_project.projectid = ? AND vtiger_crmentity.deleted = 0";
                                        } else {
                                            if ($module == 'ProjectMilestone') {
                                                $query = "SELECT vtiger_projectmilestone . * , vtiger_projectmilestonecf . * , vtiger_crmentity . * \n\t\t\t\t\tFROM vtiger_projectmilestone\n\t\t\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_projectmilestone.projectmilestoneid\n\t\t\t\t\tLEFT JOIN vtiger_projectmilestonecf ON vtiger_projectmilestonecf.projectmilestoneid = vtiger_projectmilestone.projectmilestoneid\n\t\t\t\t\tWHERE vtiger_projectmilestone.projectmilestoneid = ? AND vtiger_crmentity.deleted =0";
                                            } else {
                                                if ($module == 'ProjectTask') {
                                                    $query = "SELECT vtiger_projecttask.*, vtiger_projecttaskcf.*, vtiger_crmentity.*\n\t\t\t\t\tFROM vtiger_projecttask\n\t\t\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_projecttask.projecttaskid\n\t\t\t\t\tLEFT JOIN vtiger_projecttaskcf ON vtiger_projecttaskcf.projecttaskid = vtiger_projecttask.projecttaskid\n\t\t\t\t\tWHERE vtiger_projecttask.projecttaskid = ? AND vtiger_crmentity.deleted = 0";
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $res = $adb->pquery($query, $params);
    $fieldquery = "SELECT fieldname,columnname,fieldlabel,blocklabel,uitype FROM vtiger_field\n\t\tINNER JOIN  vtiger_blocks on vtiger_blocks.blockid=vtiger_field.block WHERE vtiger_field.tabid = ? AND displaytype in (1,2,4,10)\n\t\tORDER BY vtiger_field.block,vtiger_field.sequence";
    $fieldres = $adb->pquery($fieldquery, array(getTabid($module)));
    $nooffields = $adb->num_rows($fieldres);
    // Dummy instance to make sure column fields are initialized for futher processing
    $focus = CRMEntity::getInstance($module);
    for ($i = 0; $i < $nooffields; $i++) {
        $columnname = $adb->query_result($fieldres, $i, 'columnname');
        $fieldname = $adb->query_result($fieldres, $i, 'fieldname');
        $fieldid = $adb->query_result($fieldres, $i, 'fieldid');
        $blockid = $adb->query_result($fieldres, $i, 'block');
        $uitype = $adb->query_result($fieldres, $i, 'uitype');
        $blocklabel = $adb->query_result($fieldres, $i, 'blocklabel');
        $blockname = Vtiger_Language_Handler::getTranslatedString($blocklabel, $module, vglobal('default_language'));
        if ($blocklabel == 'LBL_COMMENTS' || $blocklabel == 'LBL_IMAGE_INFORMATION') {
            // the comments block of tickets is hardcoded in customer portal,get_ticket_comments is used for it
            continue;
        }
        if ($uitype == 83) {
            //for taxclass in products and services
            continue;
        }
        $fieldper = getFieldVisibilityPermission($module, $current_user->id, $fieldname);
        if ($fieldper == '1') {
            continue;
        }
        $fieldlabel = Vtiger_Language_Handler::getTranslatedString($adb->query_result($fieldres, $i, 'fieldlabel'), $module, vglobal('default_language'));
        $fieldvalue = $adb->query_result($res, 0, $columnname);
        $output[0][$module][$i]['fieldlabel'] = $fieldlabel;
        $output[0][$module][$i]['blockname'] = $blockname;
        if ($columnname == 'title' || $columnname == 'description' || $columnname == 'attention' || $columnname == 'solution') {
            $fieldvalue = decode_html($fieldvalue);
        }
        if ($uitype == 10 && $fieldvalue == 0) {
            $fieldvalue = '';
        }
        if ($uitype == 71 || $uitype == 72) {
            $fieldvalue = number_format($fieldvalue, 5, '.', '');
        }
        if ($uitype == 56) {
            if ($fieldvalue == 1) {
                $fieldvalue = Vtiger_Language_Handler::getTranslatedString('LBL_YES', $module, vglobal('default_language'));
            } else {
                $fieldvalue = Vtiger_Language_Handler::getTranslatedString('LBL_NO', $module, vglobal('default_language'));
            }
        }
        if ($columnname == 'parent_id' || $columnname == 'contactid' || $columnname == 'accountid' || $columnname == 'potentialid' || $fieldname == 'account_id' || $fieldname == 'contact_id' || $columnname == '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>';
                } else {
                    $fieldvalue = $fieldvalues[$crmid];
                }
            } else {
                $fieldvalue = '';
            }
        }
        if ($module == 'Quotes') {
            if ($fieldname == 'subject' && $fieldvalue != '') {
                $fieldid = $adb->query_result($res, 0, 'quoteid');
                $fieldvalue = '<a href="index.php?downloadfile=true&module=Quotes&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
            }
            if ($fieldname == 'total') {
                $sym = getCurrencySymbol($res, 0, 'currency_id');
                $fieldvalue = $sym . $fieldvalue;
            }
        }
        if ($module == 'Services') {
            if ($fieldname == 'pscategory' && $fieldvalue != '') {
                $fieldvalue = Vtiger_Language_Handler::getTranslatedString($fieldvalue, $module, vglobal('default_language'));
            }
        }
        if ($module == 'Documents') {
            $fieldid = $adb->query_result($res, 0, 'notesid');
            $filename = $fieldvalue;
            $folderid = $adb->query_result($res, 0, 'folderid');
            $filestatus = $adb->query_result($res, 0, 'filestatus');
            $filetype = $adb->query_result($res, 0, 'filelocationtype');
            if ($fieldname == 'filename') {
                if ($filestatus == 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>';
                    }
                }
            }
            if ($fieldname == 'folderid') {
                $fieldvalue = Vtiger_Language_Handler::getTranslatedString($adb->query_result($res, 0, 'foldername'), $module, vglobal('default_language'));
            }
            if ($fieldname == 'filesize') {
                if ($filetype == 'I') {
                    $fieldvalue = $fieldvalue . ' B';
                } elseif ($filetype == 'E') {
                    $fieldvalue = '--';
                }
            }
            if ($fieldname == 'filelocationtype') {
                if ($fieldvalue == 'I') {
                    $fieldvalue = Vtiger_Language_Handler::getTranslatedString('LBL_INTERNAL', $module, vglobal('default_language'));
                } elseif ($fieldvalue == 'E') {
                    $fieldvalue = Vtiger_Language_Handler::getTranslatedString('LBL_EXTERNAL', $module, vglobal('default_language'));
                } else {
                    $fieldvalue = '---';
                }
            }
        }
        if ($columnname == 'product_id') {
            $fieldvalues = getEntityName('Products', array($fieldvalue));
            $fieldvalue = '<a href="index.php?module=Products&action=index&productid=' . $fieldvalue . '">' . $fieldvalues[$fieldvalue] . '</a>';
        }
        if ($module == 'Products') {
            if ($fieldname == 'vendor_id') {
                $fieldvalue = get_vendor_name($fieldvalue);
            }
        }
        if ($module == 'Assets') {
            if ($fieldname == 'account') {
                $accountid = $adb->query_result($res, 0, 'account');
                $accountres = $adb->pquery("select vtiger_account.accountname from vtiger_account where accountid=?", array($accountid));
                $accountname = $adb->query_result($accountres, 0, 'accountname');
                $fieldvalue = $accountname;
            }
            if ($fieldname == 'product') {
                $productid = $adb->query_result($res, 0, 'product');
                $productres = $adb->pquery("select vtiger_products.productname from vtiger_products where productid=?", array($productid));
                $productname = $adb->query_result($productres, 0, 'productname');
                $fieldvalue = $productname;
            }
            if ($fieldname == 'invoiceid') {
                $invoiceid = $adb->query_result($res, 0, 'invoiceid');
                $invoiceres = $adb->pquery("select vtiger_invoice.subject from vtiger_invoice where invoiceid=?", array($invoiceid));
                $invoicename = $adb->query_result($invoiceres, 0, 'subject');
                $fieldvalue = $invoicename;
            }
        }
        if (in_array($uitype, array('15', '16', '120'))) {
            $output[0][$module][$i]['orgfieldvalue'] = $fieldvalue;
            $fieldvalue = Vtiger_Language_Handler::getTranslatedString($fieldvalue, $module, vglobal('default_language'));
        }
        if (in_array($uitype, array('10'))) {
            $fieldvalue = Vtiger_Functions::getCRMRecordLabel($fieldvalue);
        }
        if (in_array($uitype, array('53', '52', '77'))) {
            $fieldvalue = Vtiger_Functions::getOwnerRecordLabel($fieldvalue);
        }
        if ($fieldname == 'unit_price') {
            $sym = getCurrencySymbol($res, 0, 'currency_id');
            $fieldvalue = round($fieldvalue, 2);
            $fieldvalue = $sym . $fieldvalue;
        }
        $output[0][$module][$i]['fieldvalue'] = $fieldvalue;
    }
    if ($module == 'HelpDesk') {
        $ticketid = $adb->query_result($res, 0, 'ticketid');
        $sc_info = getRelatedServiceContracts($ticketid);
        if (!empty($sc_info)) {
            $modulename = 'ServiceContracts';
            $blocklable = Vtiger_Language_Handler::getTranslatedString('LBL_SERVICE_CONTRACT_INFORMATION', $modulename, vglobal('default_language'));
            $j = $i;
            for ($k = 0; $k < count($sc_info); $k++) {
                foreach ($sc_info[$k] as $label => $value) {
                    $output[0][$module][$j]['fieldlabel'] = Vtiger_Language_Handler::getTranslatedString($label, $modulename, vglobal('default_language'));
                    $output[0][$module][$j]['fieldvalue'] = $value;
                    $output[0][$module][$j]['blockname'] = $blocklable;
                    $j++;
                }
            }
        }
    }
    $log->debug("Existing customer portal function get_details ..");
    return $output;
}
コード例 #2
0
function get_details($id, $module, $customerid, $sessionid)
{
    global $adb, $log, $current_language, $default_language, $current_user;
    require_once 'include/utils/utils.php';
    require_once 'include/utils/UserInfoUtil.php';
    $log->debug("Entering customer portal function get_details ..");
    $user = new Users();
    $userid = getPortalUserid();
    $current_user = $user->retrieveCurrentUserInfoFromFile($userid);
    $current_language = $default_language;
    $isPermitted = check_permission($customerid, $module, $id);
    if ($isPermitted == false) {
        return array("#NOT AUTHORIZED#");
    }
    if (!validateSession($customerid, $sessionid)) {
        return null;
    }
    if ($module == 'Quotes') {
        $query = "SELECT\n\t\t\tvtiger_quotes.*,vtiger_crmentity.*,vtiger_quotesbillads.*,vtiger_quotesshipads.*,\n\t\t\tvtiger_quotescf.* FROM vtiger_quotes\n\t\t\tINNER JOIN vtiger_crmentity " . "ON vtiger_crmentity.crmid = vtiger_quotes.quoteid\n\t\t\tINNER JOIN vtiger_quotesbillads\n\t\t\t\tON vtiger_quotes.quoteid = vtiger_quotesbillads.quotebilladdressid\n\t\t\tINNER JOIN vtiger_quotesshipads\n\t\t\t\tON vtiger_quotes.quoteid = vtiger_quotesshipads.quoteshipaddressid\n\t\t\tLEFT JOIN vtiger_quotescf\n\t\t\t\tON vtiger_quotes.quoteid = vtiger_quotescf.quoteid\n\t\t\tWHERE vtiger_quotes.quoteid=(" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0";
    } else {
        if ($module == 'Documents') {
            $query = "SELECT\n\t\t\tvtiger_notes.*,vtiger_crmentity.*,vtiger_attachmentsfolder.foldername,vtiger_notescf.*\n\t\t\tFROM vtiger_notes\n\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_notes.notesid\n\t\t\tLEFT JOIN vtiger_attachmentsfolder\n\t\t\t\tON vtiger_notes.folderid = vtiger_attachmentsfolder.folderid\n\t\t\tLEFT JOIN vtiger_notescf ON vtiger_notescf.notesid = vtiger_notes.notesid\n\t\t\tWHERE vtiger_notes.notesid=(" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted=0";
        } else {
            if ($module == 'HelpDesk') {
                $query = "SELECT\n\t\t\tvtiger_troubletickets.*,vtiger_crmentity.smownerid,vtiger_crmentity.createdtime,vtiger_crmentity.modifiedtime,\n\t\t\tvtiger_ticketcf.*,vtiger_crmentity.description  FROM vtiger_troubletickets\n\t\t\tINNER JOIN vtiger_crmentity on vtiger_crmentity.crmid = vtiger_troubletickets.ticketid\n\t\t\tINNER JOIN vtiger_ticketcf\n\t\t\t\tON vtiger_ticketcf.ticketid = vtiger_troubletickets.ticketid\n\t\t\tWHERE (vtiger_troubletickets.ticketid=(" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0)";
            } else {
                if ($module == 'Services') {
                    $query = "SELECT vtiger_service.*,vtiger_crmentity.*,vtiger_servicecf.*  FROM vtiger_service\n\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\tON vtiger_crmentity.crmid = vtiger_service.serviceid AND vtiger_crmentity.deleted = 0\n\t\t\tLEFT JOIN vtiger_servicecf\n\t\t\t\tON vtiger_service.serviceid = vtiger_servicecf.serviceid\n\t\t\tWHERE vtiger_service.serviceid= (" . generateQuestionMarks($id) . ")";
                } else {
                    if ($module == 'Contacts') {
                        $query = "SELECT vtiger_contactdetails.*,vtiger_contactaddress.*,vtiger_contactsubdetails.*,vtiger_contactscf.*" . " ,vtiger_crmentity.*,vtiger_customerdetails.*\n\t\t \tFROM vtiger_contactdetails\n\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\tON vtiger_crmentity.crmid = vtiger_contactdetails.contactid\n\t\t\tINNER JOIN vtiger_contactaddress\n\t\t\t\tON vtiger_contactaddress.contactaddressid = vtiger_contactdetails.contactid\n\t\t\tINNER JOIN vtiger_contactsubdetails\n\t\t\t\tON vtiger_contactsubdetails.contactsubscriptionid = vtiger_contactdetails.contactid\n\t\t\tINNER JOIN vtiger_contactscf\n\t\t\t\tON vtiger_contactscf.contactid = vtiger_contactdetails.contactid\n\t\t\tLEFT JOIN vtiger_customerdetails\n\t\t\t\tON vtiger_customerdetails.customerid = vtiger_contactdetails.contactid\n\t\t\tWHERE vtiger_contactdetails.contactid = (" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0";
                    } else {
                        if ($module == 'Accounts') {
                            $query = "SELECT vtiger_account.*,vtiger_accountbillads.*,vtiger_accountshipads.*,vtiger_accountscf.*,\n\t\t\tvtiger_crmentity.* FROM vtiger_account\n\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\tON vtiger_crmentity.crmid = vtiger_account.accountid\n\t\t\tINNER JOIN vtiger_accountbillads\n\t\t\t\tON vtiger_account.accountid = vtiger_accountbillads.accountaddressid\n\t\t\tINNER JOIN vtiger_accountshipads\n\t\t\t\tON vtiger_account.accountid = vtiger_accountshipads.accountaddressid\n\t\t\tINNER JOIN vtiger_accountscf\n\t\t\t\tON vtiger_account.accountid = vtiger_accountscf.accountid" . " WHERE vtiger_account.accountid = (" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0";
                        } else {
                            if ($module == 'Products') {
                                $query = "SELECT vtiger_products.*,vtiger_productcf.*,vtiger_crmentity.* " . "FROM vtiger_products " . "INNER JOIN vtiger_crmentity " . "ON vtiger_crmentity.crmid = vtiger_products.productid " . "LEFT JOIN vtiger_productcf " . "ON vtiger_productcf.productid = vtiger_products.productid " . "LEFT JOIN vtiger_vendor\n\t\t\tON vtiger_vendor.vendorid = vtiger_products.vendor_id " . "WHERE vtiger_products.productid = (" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0";
                            } else {
                                if ($module == 'Assets') {
                                    $query = "SELECT vtiger_assets.*, vtiger_assetscf.*, vtiger_crmentity.*\n\t\tFROM vtiger_assets\n\t\tINNER JOIN vtiger_crmentity\n\t\tON vtiger_assets.assetsid = vtiger_crmentity.crmid\n\t\tINNER JOIN vtiger_assetscf\n\t\tON vtiger_assetscf.assetsid = vtiger_assets.assetsid\n\t\tWHERE vtiger_crmentity.deleted = 0 AND vtiger_assets.assetsid = (" . generateQuestionMarks($id) . ")";
                                } else {
                                    if ($module == 'Project') {
                                        $query = "SELECT vtiger_project.*, vtiger_projectcf.*, vtiger_crmentity.*\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\tLEFT JOIN vtiger_projectcf ON vtiger_projectcf.projectid = vtiger_project.projectid\n\t\t\t\t\tWHERE vtiger_project.projectid = ? AND vtiger_crmentity.deleted = 0";
                                        // SalesPlatform.ru begin
                                    } else {
                                        if ($module == 'PriceBooks') {
                                            $query = "SELECT vtiger_pricebook.*, vtiger_crmentity.* " . "FROM vtiger_pricebook " . "INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_pricebook.pricebookid " . "WHERE active = 1 AND vtiger_crmentity.deleted = 0 AND pricebookid = ? ";
                                        } else {
                                            if ($module == 'SalesOrder') {
                                                $query = "SELECT vtiger_salesorder.*, vtiger_crmentity.*, vtiger_sobillads.*, vtiger_soshipads.* " . "FROM vtiger_salesorder " . "INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_salesorder.salesorderid " . "INNER JOIN vtiger_sobillads ON vtiger_salesorder.salesorderid = vtiger_sobillads.sobilladdressid " . "INNER JOIN vtiger_soshipads ON vtiger_salesorder.salesorderid = vtiger_soshipads.soshipaddressid " . "WHERE vtiger_crmentity.deleted = 0 AND salesorderid = ? ";
                                                // SalesPlatform.ru end
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $params = array($id);
    $res = $adb->pquery($query, $params);
    $fieldquery = "SELECT fieldname,columnname,fieldlabel,blocklabel,uitype FROM vtiger_field\n\t\tINNER JOIN  vtiger_blocks on vtiger_blocks.blockid=vtiger_field.block WHERE vtiger_field.tabid = ? AND displaytype in (1,2,4)\n\t\tORDER BY vtiger_field.block,vtiger_field.sequence";
    $fieldres = $adb->pquery($fieldquery, array(getTabid($module)));
    $nooffields = $adb->num_rows($fieldres);
    // Dummy instance to make sure column fields are initialized for futher processing
    $focus = CRMEntity::getInstance($module);
    for ($i = 0; $i < $nooffields; $i++) {
        $columnname = $adb->query_result($fieldres, $i, 'columnname');
        $fieldname = $adb->query_result($fieldres, $i, 'fieldname');
        $fieldid = $adb->query_result($fieldres, $i, 'fieldid');
        $blockid = $adb->query_result($fieldres, $i, 'block');
        $uitype = $adb->query_result($fieldres, $i, 'uitype');
        $blocklabel = $adb->query_result($fieldres, $i, 'blocklabel');
        $blockname = getTranslatedString($blocklabel, $module);
        if ($blocklabel == 'LBL_COMMENTS' || $blocklabel == 'LBL_IMAGE_INFORMATION') {
            // the comments block of tickets is hardcoded in customer portal,get_ticket_comments is used for it
            continue;
        }
        if ($uitype == 83) {
            //for taxclass in products and services
            continue;
        }
        $fieldper = getFieldVisibilityPermission($module, $current_user->id, $fieldname);
        if ($fieldper == '1' && strcmp($fieldname, 'total') != 0) {
            continue;
        }
        // SalesPlatform.ru begin
        $fieldlabel = getTranslatedString($adb->query_result($fieldres, $i, 'fieldlabel'), $module);
        $fieldvalue = getTranslatedString($adb->query_result($res, 0, $columnname), $module);
        //$fieldlabel = getTranslatedString($adb->query_result($fieldres,$i,'fieldlabel'));
        //$fieldvalue = $adb->query_result($res,0,$columnname);
        // SalesPlatform.ru end
        // SalesPlatform.ru begin : don't send empty fields
        if (empty($fieldvalue)) {
            continue;
        }
        // SalesPlatform.ru end
        $output[0][$module][$i]['fieldlabel'] = $fieldlabel;
        $output[0][$module][$i]['blockname'] = $blockname;
        if ($columnname == 'title' || $columnname == 'description') {
            $fieldvalue = decode_html($fieldvalue);
        }
        if ($uitype == 71 || $uitype == 72) {
            $fieldvalue = number_format($fieldvalue, 5, '.', '');
        }
        if ($columnname == 'parent_id' || $columnname == 'contactid' || $columnname == 'accountid' || $columnname == 'potentialid' || $fieldname == 'account_id' || $fieldname == 'contact_id' || $columnname == '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>';
                } else {
                    $fieldvalue = $fieldvalues[$crmid];
                }
            } else {
                $fieldvalue = '';
            }
        }
        if ($module == 'Quotes') {
            if ($fieldname == 'subject' && $fieldvalue != '') {
                $fieldid = $adb->query_result($res, 0, 'quoteid');
                $fieldvalue = '<a href="index.php?downloadfile=true&module=Quotes&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>';
            }
            if ($fieldname == 'total') {
                $sym = getCurrencySymbol($res, 0, 'currency_id');
                // SalesPlatform.ru begin
                $fieldvalue = getCurrencyValue($sym, $fieldvalue);
                //$fieldvalue = $sym.$fieldvalue;
                // SalesPlatform.ru end
            }
        }
        if ($module == 'Documents') {
            $fieldid = $adb->query_result($res, 0, 'notesid');
            $filename = $fieldvalue;
            $folderid = $adb->query_result($res, 0, 'folderid');
            $filestatus = $adb->query_result($res, 0, 'filestatus');
            $filetype = $adb->query_result($res, 0, 'filelocationtype');
            if ($fieldname == 'filename') {
                if ($filestatus == 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>';
                    }
                }
            }
            if ($fieldname == 'folderid') {
                $fieldvalue = $adb->query_result($res, 0, 'foldername');
            }
            if ($fieldname == 'filesize') {
                if ($filetype == 'I') {
                    $fieldvalue = $fieldvalue . ' B';
                } elseif ($filetype == 'E') {
                    $fieldvalue = '--';
                }
            }
            if ($fieldname == 'filelocationtype') {
                if ($fieldvalue == 'I') {
                    $fieldvalue = getTranslatedString('LBL_INTERNAL', $module);
                } elseif ($fieldvalue == 'E') {
                    $fieldvalue = getTranslatedString('LBL_EXTERNAL', $module);
                } else {
                    $fieldvalue = '---';
                }
            }
        }
        if ($columnname == 'product_id') {
            $fieldvalues = getEntityName('Products', array($fieldvalue));
            $fieldvalue = '<a href="index.php?module=Products&action=index&productid=' . $fieldvalue . '">' . $fieldvalues[$fieldvalue] . '</a>';
        }
        if ($module == 'Products') {
            if ($fieldname == 'vendor_id') {
                $fieldvalue = get_vendor_name($fieldvalue);
            }
        }
        if ($module == 'Assets') {
            if ($fieldname == 'account') {
                $accountid = $adb->query_result($res, 0, 'account');
                $accountres = $adb->pquery("select vtiger_account.accountname from vtiger_account where accountid=?", array($accountid));
                $accountname = $adb->query_result($accountres, 0, 'accountname');
                $fieldvalue = $accountname;
            }
            if ($fieldname == 'product') {
                $productid = $adb->query_result($res, 0, 'product');
                $productres = $adb->pquery("select vtiger_products.productname from vtiger_products where productid=?", array($productid));
                $productname = $adb->query_result($productres, 0, 'productname');
                $fieldvalue = $productname;
            }
            if ($fieldname == 'invoiceid') {
                $invoiceid = $adb->query_result($res, 0, 'invoiceid');
                $invoiceres = $adb->pquery("select vtiger_invoice.subject from vtiger_invoice where invoiceid=?", array($invoiceid));
                $invoicename = $adb->query_result($invoiceres, 0, 'subject');
                $fieldvalue = $invoicename;
            }
        }
        if ($fieldname == 'assigned_user_id' || $fieldname == 'assigned_user_id1') {
            $fieldvalue = getOwnerName($fieldvalue);
        }
        if ($uitype == 56) {
            if ($fieldvalue == 1) {
                $fieldvalue = 'Yes';
            } else {
                $fieldvalue = 'No';
            }
        }
        if ($module == 'HelpDesk' && $fieldname == 'ticketstatus') {
            $parentid = $adb->query_result($res, 0, 'parent_id');
            $contactid = $adb->query_result($res, 0, 'contact_id');
            $status = $adb->query_result($res, 0, 'status');
            if ($parentid != 0) {
                //allow contacts related to organization to close the ticket
                $focus = CRMEntity::getInstance('Accounts');
                $focus->id = $parentid;
                $entityIds = $focus->getRelatedContactsIds();
                if ($contactid != 0) {
                    if (in_array($customerid, $entityIds) && in_array($contactid, $entityIds)) {
                        $fieldvalue = $status;
                    } else {
                        if ($customerid == $contactid) {
                            $fieldvalue = $status;
                        } else {
                            $fieldvalue = '';
                        }
                    }
                } else {
                    if (in_array($customerid, $entityIds)) {
                        $fieldvalue = $status;
                    } else {
                        $fieldvalue = '';
                    }
                }
            } else {
                if ($customerid != $contactid) {
                    //allow only the owner to close the ticket
                    $fieldvalue = '';
                } else {
                    $fieldvalue = $status;
                }
            }
        }
        if ($fieldname == 'unit_price') {
            $sym = getCurrencySymbol($res, 0, 'currency_id');
            // SalesPlatform.ru begin
            $fieldvalue = getCurrencyValue($sym, $fieldvalue);
            //$fieldvalue = $sym.$fieldvalue;
            // SalesPlatform.ru end
        }
        // SalesPlatform.ru begin
        if ($fieldname == 'currency_id') {
            $sym = getCurrencySymbol($res, 0, 'currency_id');
            $fieldvalue = $sym;
        }
        // SalesPlatform.ru end
        $output[0][$module][$i]['fieldvalue'] = $fieldvalue;
    }
    if ($module == 'HelpDesk') {
        $ticketid = $adb->query_result($res, 0, 'ticketid');
        $sc_info = getRelatedServiceContracts($ticketid);
        if (!empty($sc_info)) {
            $modulename = 'ServiceContracts';
            $blocklable = getTranslatedString('LBL_SERVICE_CONTRACT_INFORMATION', $modulename);
            // SalesPlatform.ru begin
            $j = $i + 1;
            //$j=$i;
            // SalesPlatform.ru end
            for ($k = 0; $k < count($sc_info); $k++) {
                foreach ($sc_info[$k] as $label => $value) {
                    $output[0][$module][$j]['fieldlabel'] = getTranslatedString($label, $modulename);
                    $output[0][$module][$j]['fieldvalue'] = $value;
                    $output[0][$module][$j]['blockname'] = $blocklable;
                    $j++;
                }
            }
        }
    } else {
        if ($module == 'PriceBooks') {
            $sc_info = getRelatedPriceBookProducts($id);
            if (!empty($sc_info)) {
                $modulename = 'Products';
                $blocklable = getTranslatedString('LBL_LIST_FORM_TITLE', $modulename);
                $j = $i + 1;
                for ($k = 0; $k < count($sc_info); $k++) {
                    foreach ($sc_info[$k] as $label => $value) {
                        $output[0][$module][$j]['fieldlabel'] = getTranslatedString($label, $modulename);
                        $output[0][$module][$j]['fieldvalue'] = $value;
                        $output[0][$module][$j]['blockname'] = $blocklable;
                        $j++;
                    }
                }
            }
        } else {
            if ($module == 'SalesOrder') {
                $sym = getCurrencySymbol($res, 0, 'currency_id');
                $blocklable = getTranslatedString('Total', $module);
                $i++;
                $output[0][$module][$i]['fieldlabel'] = getTranslatedString('Sub Total', $module);
                $output[0][$module][$i]['fieldvalue'] = getCurrencyValue($sym, $adb->query_result($res, 0, 'subtotal'));
                $output[0][$module][$i]['blockname'] = $blocklable;
                $i++;
                $output[0][$module][$i]['fieldlabel'] = getTranslatedString('Shipping & Handling Charges', $module);
                $output[0][$module][$i]['fieldvalue'] = getCurrencyValue($sym, $adb->query_result($res, 0, 's_h_amount'));
                $output[0][$module][$i]['blockname'] = $blocklable;
                $i++;
                $output[0][$module][$i]['fieldlabel'] = getTranslatedString('Total', $module);
                $output[0][$module][$i]['fieldvalue'] = getCurrencyValue($sym, $adb->query_result($res, 0, 'total'));
                $output[0][$module][$i]['blockname'] = $blocklable;
                $i++;
                $sc_info = getRelatedSalesOrderItems($id);
                if (!empty($sc_info)) {
                    $modulename = 'Products';
                    $blocklable = getTranslatedString('LBL_LIST_FORM_TITLE', $modulename);
                    $j = $i + 1;
                    for ($k = 0; $k < count($sc_info); $k++) {
                        foreach ($sc_info[$k] as $label => $value) {
                            $output[0][$module][$j]['fieldlabel'] = getTranslatedString($label, $modulename);
                            $output[0][$module][$j]['fieldvalue'] = $value;
                            $output[0][$module][$j]['blockname'] = $blocklable;
                            $j++;
                        }
                    }
                }
            }
        }
    }
    // SalesPlatform.ru end
    $log->debug("Existing customer portal function get_details ..");
    return $output;
}