$smarty_obj->assign("APP", $app_strings);
$cnt = count($qc_modules);
$smarty_obj->assign("CNT", $cnt);
$smarty_obj->assign("PRINT_URL", "phprint.php?jt=" . session_id() . $GLOBALS['request_string']);
$smarty_obj->assign("MODULE_NAME", $currentModule);
$date = new DateTimeField(null);
$smarty_obj->assign("DATE", $date->getDisplayDateTimeValue());
$smarty_obj->assign("CURRENT_USER_MAIL", $current_user->email1);
$smarty_obj->assign("CURRENT_USER", $current_user->user_name);
$smarty_obj->assign("CURRENT_USER_ID", $current_user->id);
$smarty_obj->assign("MODULELISTS", $app_list_strings['moduleList']);
$smarty_obj->assign("CATEGORY", getParentTab());
$smarty_obj->assign("CALC", get_calc($image_path));
$smarty_obj->assign("MENUSTRUCTURE", getMenuStructure($currentModule));
$smarty_obj->assign("ANNOUNCEMENT", get_announcements());
$smarty_obj->assign("USE_ASTERISK", get_use_asterisk($current_user->id));
if (is_admin($current_user)) {
    $smarty_obj->assign("ADMIN_LINK", "<a href='index.php?module=Settings&action=index'>" . $app_strings['LBL_SETTINGS'] . "</a>");
}
$module_path = "modules/" . $currentModule . "/";
require_once 'include/Menu.php';
//Assign the entered global search string to a variable and display it again
if ($_REQUEST['query_string'] != '') {
    $smarty_obj->assign("QUERY_STRING", htmlspecialchars($_REQUEST['query_string'], ENT_QUOTES, $default_charset));
} else {
    $smarty_obj->assign("QUERY_STRING", "{$app_strings['LBL_SEARCH_STRING']}");
}
global $module_menu;
require_once 'data/Tracker.php';
$tracFocus = new Tracker();
$list = $tracFocus->get_recently_viewed($current_user->id);
 function getListViewRecords($focus, $module, $result)
 {
     global $listview_max_textlength, $theme, $default_charset;
     require 'user_privileges/user_privileges_' . $this->user->id . '.php';
     $fields = $this->queryGenerator->getFields();
     $meta = $this->queryGenerator->getMeta($this->queryGenerator->getModule());
     $moduleFields = $this->queryGenerator->getModuleFields();
     $accessibleFieldList = array_keys($moduleFields);
     $listViewFields = array_intersect($fields, $accessibleFieldList);
     $referenceFieldList = $this->queryGenerator->getReferenceFieldList();
     foreach ($referenceFieldList as $fieldName) {
         if (in_array($fieldName, $listViewFields)) {
             $field = $moduleFields[$fieldName];
             $this->fetchNameList($field, $result);
         }
     }
     $db = PearDatabase::getInstance();
     $rowCount = $db->num_rows($result);
     $ownerFieldList = $this->queryGenerator->getOwnerFieldList();
     foreach ($ownerFieldList as $fieldName) {
         if (in_array($fieldName, $listViewFields)) {
             $field = $moduleFields[$fieldName];
             $idList = array();
             for ($i = 0; $i < $rowCount; $i++) {
                 $id = $this->db->query_result($result, $i, $field->getColumnName());
                 if (!isset($this->ownerNameList[$fieldName][$id])) {
                     $idList[] = $id;
                 }
             }
             if (count($idList) > 0) {
                 if (!is_array($this->ownerNameList[$fieldName])) {
                     $this->ownerNameList[$fieldName] = getOwnerNameList($idList);
                 } else {
                     //array_merge API loses key information so need to merge the arrays
                     // manually.
                     $newOwnerList = getOwnerNameList($idList);
                     foreach ($newOwnerList as $id => $name) {
                         $this->ownerNameList[$fieldName][$id] = $name;
                     }
                 }
             }
         }
     }
     foreach ($listViewFields as $fieldName) {
         $field = $moduleFields[$fieldName];
         if (!$is_admin && ($field->getFieldDataType() == 'picklist' || $field->getFieldDataType() == 'multipicklist')) {
             $this->setupAccessiblePicklistValueList($fieldName);
         }
     }
     $useAsterisk = get_use_asterisk($this->user->id);
     $data = array();
     for ($i = 0; $i < $rowCount; ++$i) {
         //Getting the recordId
         if ($module != 'Users') {
             $baseTable = $meta->getEntityBaseTable();
             $moduleTableIndexList = $meta->getEntityTableIndexList();
             $baseTableIndex = $moduleTableIndexList[$baseTable];
             $recordId = $db->query_result($result, $i, $baseTableIndex);
         } else {
             $recordId = $db->query_result($result, $i, "id");
         }
         $row = array();
         foreach ($listViewFields as $fieldName) {
             $field = $moduleFields[$fieldName];
             $uitype = $field->getUIType();
             $rawValue = $this->db->query_result($result, $i, $field->getColumnName());
             if (in_array($uitype, array(15, 33, 16))) {
                 $value = html_entity_decode($rawValue, ENT_QUOTES, $default_charset);
             } else {
                 $value = $rawValue;
             }
             if ($module == 'Documents' && $fieldName == 'filename') {
                 $downloadtype = $db->query_result($result, $i, 'filelocationtype');
                 $fileName = $db->query_result($result, $i, 'filename');
                 $downloadType = $db->query_result($result, $i, 'filelocationtype');
                 $status = $db->query_result($result, $i, 'filestatus');
                 $fileIdQuery = "select attachmentsid from vtiger_seattachmentsrel where crmid=?";
                 $fileIdRes = $db->pquery($fileIdQuery, array($recordId));
                 $fileId = $db->query_result($fileIdRes, 0, 'attachmentsid');
                 if ($fileName != '' && $status == 1) {
                     if ($downloadType == 'I') {
                         $value = '<a onclick="Javascript:Documents_Index_Js.updateDownloadCount(\'index.php?module=Documents&action=UpdateDownloadCount&record=' . $recordId . '\');"' . ' href="index.php?module=Documents&action=DownloadFile&record=' . $recordId . '&fileid=' . $fileId . '"' . ' title="' . getTranslatedString('LBL_DOWNLOAD_FILE', $module) . '" >' . textlength_check($value) . '</a>';
                     } elseif ($downloadType == 'E') {
                         $value = '<a onclick="Javascript:Documents_Index_Js.updateDownloadCount(\'index.php?module=Documents&action=UpdateDownloadCount&record=' . $recordId . '\');"' . ' href="' . $fileName . '" target="_blank"' . ' title="' . getTranslatedString('LBL_DOWNLOAD_FILE', $module) . '" >' . textlength_check($value) . '</a>';
                     } else {
                         $value = ' --';
                     }
                 }
                 $value = $fileicon . $value;
             } elseif ($module == 'Documents' && $fieldName == 'filesize') {
                 $downloadType = $db->query_result($result, $i, 'filelocationtype');
                 if ($downloadType == 'I') {
                     $filesize = $value;
                     if ($filesize < 1024) {
                         $value = $filesize . ' B';
                     } elseif ($filesize > 1024 && $filesize < 1048576) {
                         $value = round($filesize / 1024, 2) . ' KB';
                     } else {
                         if ($filesize > 1048576) {
                             $value = round($filesize / (1024 * 1024), 2) . ' MB';
                         }
                     }
                 } else {
                     $value = ' --';
                 }
             } elseif ($module == 'Documents' && $fieldName == 'filestatus') {
                 if ($value == 1) {
                     $value = getTranslatedString('yes', $module);
                 } elseif ($value == 0) {
                     $value = getTranslatedString('no', $module);
                 } else {
                     $value = '--';
                 }
             } elseif ($module == 'Documents' && $fieldName == 'filetype') {
                 $downloadType = $db->query_result($result, $i, 'filelocationtype');
                 if ($downloadType == 'E' || $downloadType != 'I') {
                     $value = '--';
                 }
             } elseif ($module == 'OSSTimeControl' && $fieldName == 'sum_time') {
                 $value = Vtiger_Functions::decimalTimeFormat($value);
                 $value = $value['short'];
             } elseif ($field->getUIType() == '27') {
                 if ($value == 'I') {
                     $value = getTranslatedString('LBL_INTERNAL', $module);
                 } elseif ($value == 'E') {
                     $value = getTranslatedString('LBL_EXTERNAL', $module);
                 } else {
                     $value = ' --';
                 }
                 $value = Vtiger_Functions::textLength($value);
             } elseif ($field->getFieldDataType() == 'picklist') {
                 $value = Vtiger_Language_Handler::getTranslatedString($value, $module);
                 $value = textlength_check($value);
             } elseif ($field->getFieldDataType() == 'date' || $field->getFieldDataType() == 'datetime') {
                 if ($value != '' && $value != '0000-00-00') {
                     $fieldDataType = $field->getFieldDataType();
                     if ($module == 'Calendar' && ($fieldName == 'date_start' || $fieldName == 'due_date')) {
                         if ($fieldName == 'date_start') {
                             $timeField = 'time_start';
                         } else {
                             if ($fieldName == 'due_date') {
                                 $timeField = 'time_end';
                             }
                         }
                         $timeFieldValue = $this->db->query_result($result, $i, $timeField);
                         if (!empty($timeFieldValue)) {
                             $value .= ' ' . $timeFieldValue;
                             //TO make sure it takes time value as well
                             $fieldDataType = 'datetime';
                         }
                     }
                     if ($fieldDataType == 'datetime') {
                         $value = Vtiger_Datetime_UIType::getDateTimeValue($value);
                     } else {
                         if ($fieldDataType == 'date') {
                             $date = new DateTimeField($value);
                             $value = $date->getDisplayDate();
                         }
                     }
                 } elseif ($value == '0000-00-00') {
                     $value = '';
                 }
             } elseif ($field->getFieldDataType() == 'time') {
                 if (!empty($value)) {
                     $userModel = Users_Privileges_Model::getCurrentUserModel();
                     if ($userModel->get('hour_format') == '12') {
                         $value = Vtiger_Time_UIType::getTimeValueInAMorPM($value);
                     }
                 }
             } elseif ($field->getFieldDataType() == 'currency') {
                 if ($value != '') {
                     if ($field->getUIType() == 72) {
                         if ($fieldName == 'unit_price') {
                             $currencyId = getProductBaseCurrency($recordId, $module);
                             $cursym_convrate = getCurrencySymbolandCRate($currencyId);
                             $currencySymbol = $cursym_convrate['symbol'];
                         } else {
                             $currencyInfo = getInventoryCurrencyInfo($module, $recordId);
                             $currencySymbol = $currencyInfo['currency_symbol'];
                         }
                         $value = CurrencyField::convertToUserFormat($value, null, true);
                         $row['currencySymbol'] = $currencySymbol;
                         $value = CurrencyField::appendCurrencySymbol($value, $currencySymbol);
                     } else {
                         if (!empty($value)) {
                             $value = CurrencyField::convertToUserFormat($value);
                             $currencyModal = new CurrencyField($value);
                             $currencyModal->initialize();
                             $value = $currencyModal->appendCurrencySymbol($value, $currencyModal->currencySymbol);
                         }
                     }
                 }
             } elseif ($field->getFieldDataType() == 'url') {
                 $matchPattern = "^[\\w]+:\\/\\/^";
                 preg_match($matchPattern, $rawValue, $matches);
                 if (!empty($matches[0])) {
                     $value = '<a class="urlField cursorPointer" title="' . $rawValue . '" href="' . $rawValue . '" target="_blank">' . textlength_check($value) . '</a>';
                 } else {
                     $value = '<a class="urlField cursorPointer" title="' . $rawValue . '" href="http://' . $rawValue . '" target="_blank">' . textlength_check($value) . '</a>';
                 }
             } elseif ($field->getFieldDataType() == 'email') {
                 $current_user = vglobal('current_user');
                 if ($current_user->internal_mailer == 1) {
                     //check added for email link in user detailview
                     $value = "<a class='emailField' onclick=\"Vtiger_Helper_Js.getInternalMailer({$recordId}," . "'{$fieldName}','{$module}');\">" . textlength_check($value) . "</a>";
                 } else {
                     $value = '<a class="emailField" href="mailto:' . $rawValue . '">' . textlength_check($value) . '</a>';
                 }
             } elseif ($field->getFieldDataType() == 'boolean') {
                 if ($value === 'on') {
                     $value = 1;
                 } else {
                     if ($value == 'off') {
                         $value = 0;
                     }
                 }
                 if ($value == 1) {
                     $value = getTranslatedString('yes', $module);
                 } elseif ($value == 0) {
                     $value = getTranslatedString('no', $module);
                 } else {
                     $value = '--';
                 }
             } elseif ($field->getUIType() == 98) {
                 $value = '<a href="index.php?module=Roles&parent=Settings&view=Edit&record=' . $value . '">' . textlength_check(getRoleName($value)) . '</a>';
             } elseif ($field->getFieldDataType() == 'multipicklist') {
                 $value = $value != "" ? str_replace(' |##| ', ', ', $value) : "";
                 if (!$is_admin && $value != '') {
                     $valueArray = $rawValue != "" ? explode(' |##| ', $rawValue) : array();
                     $tmp = '';
                     $tmpArray = array();
                     foreach ($valueArray as $index => $val) {
                         if (!$listview_max_textlength || !(strlen(preg_replace("/(<\\/?)(\\w+)([^>]*>)/i", "", $tmp)) > $listview_max_textlength)) {
                             $tmpArray[] = $val;
                             $tmp .= ', ' . $val;
                         } else {
                             $tmpArray[] = '...';
                             $tmp .= '...';
                         }
                     }
                     $value = implode(', ', $tmpArray);
                     $value = textlength_check($value);
                 }
             } elseif ($field->getFieldDataType() == 'skype') {
                 $value = $value != "" ? "<a href='skype:{$value}?call'>" . textlength_check($value) . "</a>" : "";
             } elseif ($field->getUIType() == 11) {
                 $outgoingCallPermission = Vtiger_Mobile_Model::checkPermissionForOutgoingCall();
                 if ($outgoingCallPermission && !empty($value)) {
                     $phoneNumber = preg_replace('/[-()\\s]/', '', $value);
                     $value = '<a class="phoneField" data-phoneNumber="' . $phoneNumber . '" record="' . $recordId . '" onclick="Vtiger_Mobile_Js.registerOutboundCall(\'' . $phoneNumber . '\', ' . $recordId . ')">' . textlength_check($value) . '</a>';
                     $callUsers = Vtiger_Mobile_Model::getPrivilegesUsers();
                     if ($callUsers) {
                         $value .= '  <a class="btn btn-xs noLinkBtn" onclick="Vtiger_Mobile_Js.registerOutboundCallToUser(this,\'' . $phoneNumber . '\',' . $recordId . ')" data-placement="right" data-original-title="' . vtranslate('LBL_SELECT_USER_TO_CALL', $module) . '" data-content=\'<select class="select sesectedUser" name="sesectedUser">';
                         foreach ($callUsers as $key => $item) {
                             $value .= '<option value="' . $key . '">' . $item . '</option>';
                         }
                         $value .= '</select><br /><a class="btn btn-success popoverCallOK">' . vtranslate('LBL_BTN_CALL', $module) . '</a>   <a class="btn btn-inverse popoverCallCancel">' . vtranslate('LBL_CANCEL', $module) . '</a>\' data-trigger="manual"><i class="icon-user"></i></a>';
                     }
                 } else {
                     $value = textlength_check($value);
                 }
             } elseif ($field->getFieldDataType() == 'reference') {
                 $referenceFieldInfoList = $this->queryGenerator->getReferenceFieldInfoList();
                 $moduleList = $referenceFieldInfoList[$fieldName];
                 if (count($moduleList) == 1) {
                     $parentModule = reset($moduleList);
                 } else {
                     $parentModule = $this->typeList[$value];
                 }
                 if (!empty($value) && !empty($this->nameList[$fieldName]) && !empty($parentModule)) {
                     $parentMeta = $this->queryGenerator->getMeta($parentModule);
                     $value = textlength_check($this->nameList[$fieldName][$value]);
                     if ($parentMeta->isModuleEntity() && $parentModule != "Users") {
                         $value = "<a class='moduleColor_{$parentModule}' href='?module={$parentModule}&view=Detail&" . "record={$rawValue}' title='" . getTranslatedString($parentModule, $parentModule) . "'>{$value}</a>";
                     }
                 } else {
                     $value = '--';
                 }
             } elseif ($field->getFieldDataType() == 'owner') {
                 $value = textlength_check($this->ownerNameList[$fieldName][$value]);
             } elseif ($field->getUIType() == 25) {
                 //TODO clean request object reference.
                 $contactId = $_REQUEST['record'];
                 $emailId = $this->db->query_result($result, $i, "activityid");
                 $result1 = $this->db->pquery("SELECT access_count FROM vtiger_email_track WHERE " . "crmid=? AND mailid=?", array($contactId, $emailId));
                 $value = $this->db->query_result($result1, 0, "access_count");
                 if (!$value) {
                     $value = 0;
                 }
             } elseif ($field->getUIType() == 8) {
                 if (!empty($value)) {
                     $temp_val = html_entity_decode($value, ENT_QUOTES, $default_charset);
                     $json = new Zend_Json();
                     $value = vt_suppressHTMLTags(implode(',', $json->decode($temp_val)));
                 }
             } elseif ($field->getFieldDataType() == 'taxes') {
                 if (!empty($value)) {
                     $valueArray = $value != "" ? explode(',', $value) : [];
                     $tmp = '';
                     $tmpArray = [];
                     $taxs = Vtiger_Taxes_UIType::getTaxes();
                     foreach ($valueArray as $index => $tax) {
                         if (isset($taxs[$tax])) {
                             $tmpArray[] = $taxs[$tax]['value'] . '% - ' . $taxs[$tax]['name'];
                         }
                     }
                     $value = implode(', ', $tmpArray);
                     $value = Vtiger_Functions::textLength($value);
                 }
             } elseif ($field->getFieldDataType() == 'inventoryLimit') {
                 if (!empty($value)) {
                     $valueArray = $value != "" ? explode(',', $value) : [];
                     $tmp = '';
                     $tmpArray = [];
                     $limits = Vtiger_InventoryLimit_UIType::getLimits();
                     foreach ($valueArray as $index => $limit) {
                         if (isset($limits[$limit])) {
                             $tmpArray[] = $limits[$limit]['value'] . ' - ' . $limits[$limit]['name'];
                         }
                     }
                     $value = implode(', ', $tmpArray);
                     $value = Vtiger_Functions::textLength($value);
                 }
             } elseif ($field->getFieldDataType() == 'multiReferenceValue') {
                 $params = $field->getFieldParams();
                 $fieldModel = Vtiger_Field_Model::getInstanceFromFieldId($params['field']);
                 $valueTmp = trim($value, '|#|');
                 $valueTmp = $valueTmp != "" ? explode('|#|', $valueTmp) : [];
                 foreach ($valueTmp as $index => $tmp) {
                     $valueTmp[$index] = $fieldModel->getUITypeModel()->getDisplayValue($tmp);
                 }
                 $value = implode(', ', $valueTmp);
                 $value = Vtiger_Functions::textLength($value);
             } elseif (in_array($uitype, array(7, 9, 90))) {
                 $value = "<span align='right'>" . textlength_check($value) . "</div>";
             } else {
                 $value = Vtiger_Functions::textLength($value);
             }
             //				// vtlib customization: For listview javascript triggers
             //				$value = "$value <span type='vtlib_metainfo' vtrecordid='{$recordId}' vtfieldname=".
             //					"'{$fieldName}' vtmodule='$module' style='display:none;'></span>";
             //				// END
             $row[$fieldName] = $value;
         }
         $data[$recordId] = $row;
     }
     return $data;
 }
Beispiel #3
0
function getValue($field_result, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, $mode, $popuptype, $returnset = '', $viewid = '')
{
    global $log, $listview_max_textlength, $app_strings, $current_language, $currentModule;
    $log->debug("Entering getValue(" . $field_result . "," . $list_result . "," . $fieldname . "," . get_class($focus) . "," . $module . "," . $entity_id . "," . $list_result_count . "," . $mode . "," . $popuptype . "," . $returnset . "," . $viewid . ") method ...");
    global $adb, $current_user, $default_charset;
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    $tabname = getParentTab();
    $tabid = getTabid($module);
    $current_module_strings = return_module_language($current_language, $module);
    $uicolarr = $field_result[$fieldname];
    foreach ($uicolarr as $key => $value) {
        $uitype = $key;
        $colname = $value;
    }
    //added for getting event status in Custom view - Jaguar
    if ($module == 'Calendar' && ($colname == "status" || $colname == "eventstatus")) {
        $colname = "activitystatus";
    }
    //Ends
    $field_val = $adb->query_result($list_result, $list_result_count, $colname);
    if ($uitype != 8) {
        $temp_val = html_entity_decode($field_val, ENT_QUOTES, $default_charset);
    } else {
        $temp_val = $field_val;
    }
    // vtlib customization: New uitype to handle relation between modules
    if ($uitype == '10') {
        $parent_id = $field_val;
        if (!empty($parent_id)) {
            $parent_module = getSalesEntityType($parent_id);
            $valueTitle = $parent_module;
            if ($app_strings[$valueTitle]) {
                $valueTitle = $app_strings[$valueTitle];
            }
            $displayValueArray = getEntityName($parent_module, $parent_id);
            if (!empty($displayValueArray)) {
                foreach ($displayValueArray as $key => $value) {
                    $value = $value;
                }
            }
            $value = "<a href='index.php?module={$parent_module}&action=DetailView&record={$parent_id}' title='{$valueTitle}'>" . textlength_check($value) . "</a>";
        } else {
            $value = '';
        }
    } else {
        if ($uitype == 53) {
            $value = $adb->query_result($list_result, $list_result_count, 'user_name');
            // When Assigned To field is used in Popup window
            if ($value == '') {
                $user_id = $adb->query_result($list_result, $list_result_count, 'smownerid');
                if ($user_id != null && $user_id != '') {
                    $value = getOwnerName($user_id);
                    $value = textlength_check($value);
                }
            }
        } elseif ($uitype == 52) {
            $value = getOwnerName($adb->query_result($list_result, $list_result_count, $colname));
            $value = textlength_check($value);
        } elseif ($uitype == 51) {
            //Accounts - Member Of
            $parentid = $adb->query_result($list_result, $list_result_count, "parentid");
            if ($module == 'Accounts') {
                $entity_name = textlength_check(getAccountName($parentid));
            } elseif ($module == 'Products') {
                $entity_name = textlength_check(getProductName($parentid));
            }
            $value = '<a href="index.php?module=' . $module . '&action=DetailView&record=' . $parentid . '&parenttab=' . $tabname . '" style="' . $P_FONT_COLOR . '">' . $entity_name . '</a>';
        } elseif ($uitype == 77) {
            $value = getOwnerName($adb->query_result($list_result, $list_result_count, 'inventorymanager'));
            $value = textlength_check($value);
        } elseif ($uitype == 5 || $uitype == 6 || $uitype == 23 || $uitype == 70) {
            $temp_val = trim($temp_val);
            $timeField = 'time_start';
            if ($fieldname == 'due_date') {
                $timeField = 'time_end';
            }
            if ($temp_val != '' && $module == 'Calendar' && ($uitype == 23 || $uitype == 6) && $timeField != '' && ($fieldname == 'date_start' || $fieldname == 'due_date')) {
                $time = $adb->query_result($list_result, $list_result_count, $timeField);
                if (empty($time)) {
                    $time = getSingleFieldValue('vtiger_activity', $timeField, 'activityid', $entity_id);
                }
            }
            if ($temp_val == '0000-00-00' || empty($temp_val)) {
                $value = '';
            } else {
                if (empty($time) && strpos($temp_val, ' ') == false) {
                    $value = DateTimeField::convertToUserFormat($temp_val);
                } else {
                    if (!empty($time)) {
                        $date = new DateTimeField($temp_val . ' ' . $time);
                        $value = $date->getDisplayDate();
                    } else {
                        $date = new DateTimeField($temp_val);
                        $value = $date->getDisplayDateTimeValue();
                    }
                }
            }
        } elseif ($uitype == 15 || $uitype == 55 && $fieldname == "salutationtype") {
            $temp_val = decode_html($adb->query_result($list_result, $list_result_count, $colname));
            if ($is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1 && $temp_val != '') {
                $temp_acttype = $adb->query_result($list_result, $list_result_count, 'activitytype');
                if ($temp_acttype != 'Task' && $fieldname == "taskstatus") {
                    $temptable = "eventstatus";
                } else {
                    $temptable = $fieldname;
                }
                $roleid = $current_user->roleid;
                $roleids = array();
                $subrole = getRoleSubordinates($roleid);
                if (count($subrole) > 0) {
                    $roleids = $subrole;
                }
                array_push($roleids, $roleid);
                //here we are checking wheather the table contains the sortorder column .If  sortorder is present in the main picklist table, then the role2picklist will be applicable for this table...
                $sql = "select * from vtiger_{$temptable} where {$temptable}=?";
                $res = $adb->pquery($sql, array(decode_html($temp_val)));
                $picklistvalueid = $adb->query_result($res, 0, 'picklist_valueid');
                if ($picklistvalueid != null) {
                    $pick_query = "select * from vtiger_role2picklist where picklistvalueid={$picklistvalueid} and roleid in (" . generateQuestionMarks($roleids) . ")";
                    $res_val = $adb->pquery($pick_query, array($roleids));
                    $num_val = $adb->num_rows($res_val);
                }
                if ($num_val > 0 || $temp_acttype == 'Task' && $fieldname == 'activitytype') {
                    $temp_val = $temp_val;
                } else {
                    $temp_val = "<font color='red'>" . $app_strings['LBL_NOT_ACCESSIBLE'] . "</font>";
                }
            }
            $value = $current_module_strings[$temp_val] != '' ? $current_module_strings[$temp_val] : ($app_strings[$temp_val] != '' ? $app_strings[$temp_val] : $temp_val);
            if ($value != "<font color='red'>" . $app_strings['LBL_NOT_ACCESSIBLE'] . "</font>") {
                $value = textlength_check($value);
            }
        } elseif ($uitype == 16) {
            $value = getTranslatedString($temp_val, $currentModule);
            $value = textlength_check($value);
        } elseif ($uitype == 71 || $uitype == 72) {
            if ($temp_val != '') {
                // Some of the currency fields like Unit Price, Total, Sub-total etc of Inventory modules, do not need currency conversion
                if ($uitype == 72) {
                    if ($fieldname == 'unit_price') {
                        $currency_id = getProductBaseCurrency($entity_id, $module);
                        $cursym_convrate = getCurrencySymbolandCRate($currency_id);
                        $currency_symbol = $cursym_convrate['symbol'];
                    } else {
                        $currency_info = getInventoryCurrencyInfo($module, $entity_id);
                        $currency_symbol = $currency_info['currency_symbol'];
                    }
                    $currencyValue = CurrencyField::convertToUserFormat($temp_val, null, true);
                    $value = CurrencyField::appendCurrencySymbol($currencyValue, $currency_symbol);
                } else {
                    //changes made to remove vtiger_currency symbol infront of each vtiger_potential amount
                    if ($temp_val != 0) {
                        $value = CurrencyField::convertToUserFormat($temp_val);
                    } else {
                        $value = $temp_val;
                    }
                }
            } else {
                $value = '';
            }
        } elseif ($uitype == 17) {
            $matchPattern = "^[\\w]+:\\/\\/^";
            preg_match($matchPattern, $field_val, $matches);
            if (!empty($matches[0])) {
                $value = '<a href="' . $field_val . '" target="_blank">' . textlength_check($temp_val) . '</a>';
            } else {
                $value = '<a href="http://' . $field_val . '" target="_blank">' . textlength_check($temp_val) . '</a>';
            }
        } elseif ($uitype == 13 || $uitype == 104 && ($_REQUEST['action'] != 'Popup' && $_REQUEST['file'] != 'Popup')) {
            if ($_SESSION['internal_mailer'] == 1) {
                //check added for email link in user detailview
                if ($module == 'Calendar') {
                    if (getActivityType($entity_id) == 'Task') {
                        $tabid = 9;
                    } else {
                        $tabid = 16;
                    }
                } else {
                    $tabid = getTabid($module);
                }
                $fieldid = getFieldid($tabid, $fieldname);
                if (empty($popuptype)) {
                    $value = '<a href="javascript:InternalMailer(' . $entity_id . ',' . $fieldid . ',\'' . $fieldname . '\',\'' . $module . '\',\'record_id\');">' . textlength_check($temp_val) . '</a>';
                } else {
                    $value = $temp_val;
                    $value = textlength_check($value);
                }
            } else {
                $value = '<a href="mailto:' . $field_val . '">' . textlength_check($temp_val) . '</a>';
            }
        } elseif ($uitype == 56) {
            if ($temp_val == 1) {
                $value = $app_strings['yes'];
            } elseif ($temp_val == 0) {
                $value = $app_strings['no'];
            } else {
                $value = '';
            }
        } elseif ($uitype == 57) {
            if ($temp_val != '') {
                $sql = "SELECT * FROM vtiger_contactdetails WHERE contactid=?";
                $result = $adb->pquery($sql, array($temp_val));
                $value = '';
                if ($adb->num_rows($result)) {
                    $name = getFullNameFromQResult($result, 0, "Contacts");
                    $value = '<a href=index.php?module=Contacts&action=DetailView&record=' . $temp_val . '>' . textlength_check($name) . '</a>';
                }
            } else {
                $value = '';
            }
        } elseif ($uitype == 58) {
            if ($temp_val != '') {
                $sql = "SELECT * FROM vtiger_campaign WHERE campaignid=?";
                $result = $adb->pquery($sql, array($temp_val));
                $campaignname = $adb->query_result($result, 0, "campaignname");
                $value = '<a href=index.php?module=Campaigns&action=DetailView&record=' . $temp_val . '>' . textlength_check($campaignname) . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 59) {
            if ($temp_val != '') {
                $value = getProductName($temp_val);
            } else {
                $value = '';
            }
        } elseif ($uitype == 61) {
            $attachmentid = $adb->query_result($adb->pquery("SELECT * FROM vtiger_seattachmentsrel WHERE crmid = ?", array($entity_id)), 0, 'attachmentsid');
            $value = '<a href = "index.php?module=uploads&action=downloadfile&return_module=' . $module . '&fileid=' . $attachmentid . '&filename=' . $temp_val . '">' . textlength_check($temp_val) . '</a>';
        } elseif ($uitype == 62) {
            $parentid = $adb->query_result($list_result, $list_result_count, "parent_id");
            $parenttype = $adb->query_result($list_result, $list_result_count, "parent_type");
            if ($parenttype == "Leads") {
                $tablename = "vtiger_leaddetails";
                $fieldname = "lastname";
                $idname = "leadid";
            }
            if ($parenttype == "Accounts") {
                $tablename = "vtiger_account";
                $fieldname = "accountname";
                $idname = "accountid";
            }
            if ($parenttype == "Products") {
                $tablename = "vtiger_products";
                $fieldname = "productname";
                $idname = "productid";
            }
            if ($parenttype == "HelpDesk") {
                $tablename = "vtiger_troubletickets";
                $fieldname = "title";
                $idname = "ticketid";
            }
            if ($parenttype == "Invoice") {
                $tablename = "vtiger_invoice";
                $fieldname = "subject";
                $idname = "invoiceid";
            }
            if ($parentid != '') {
                $sql = "SELECT * FROM {$tablename} WHERE {$idname} = ?";
                $fieldvalue = $adb->query_result($adb->pquery($sql, array($parentid)), 0, $fieldname);
                $value = '<a href=index.php?module=' . $parenttype . '&action=DetailView&record=' . $parentid . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($fieldvalue) . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 66) {
            $parentid = $adb->query_result($list_result, $list_result_count, "parent_id");
            $parenttype = $adb->query_result($list_result, $list_result_count, "parent_type");
            if ($parenttype == "Leads") {
                $tablename = "vtiger_leaddetails";
                $fieldname = "lastname";
                $idname = "leadid";
            }
            if ($parenttype == "Accounts") {
                $tablename = "vtiger_account";
                $fieldname = "accountname";
                $idname = "accountid";
            }
            if ($parenttype == "HelpDesk") {
                $tablename = "vtiger_troubletickets";
                $fieldname = "title";
                $idname = "ticketid";
            }
            if ($parentid != '') {
                $sql = "SELECT * FROM {$tablename} WHERE {$idname} = ?";
                $fieldvalue = $adb->query_result($adb->pquery($sql, array($parentid)), 0, $fieldname);
                $value = '<a href=index.php?module=' . $parenttype . '&action=DetailView&record=' . $parentid . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($fieldvalue) . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 67) {
            $parentid = $adb->query_result($list_result, $list_result_count, "parent_id");
            $parenttype = $adb->query_result($list_result, $list_result_count, "parent_type");
            if ($parenttype == "Leads") {
                $tablename = "vtiger_leaddetails";
                $fieldname = "lastname";
                $idname = "leadid";
            }
            if ($parenttype == "Contacts") {
                $tablename = "vtiger_contactdetails";
                $fieldname = "contactname";
                $idname = "contactid";
            }
            if ($parentid != '') {
                $sql = "SELECT * FROM {$tablename} WHERE {$idname} = ?";
                $fieldvalue = $adb->query_result($adb->pquery($sql, array($parentid)), 0, $fieldname);
                $value = '<a href=index.php?module=' . $parenttype . '&action=DetailView&record=' . $parentid . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($fieldvalue) . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 68) {
            $parentid = $adb->query_result($list_result, $list_result_count, "parent_id");
            $parenttype = $adb->query_result($list_result, $list_result_count, "parent_type");
            if ($parenttype == '' && $parentid != '') {
                $parenttype = getSalesEntityType($parentid);
            }
            if ($parenttype == "Contacts") {
                $tablename = "vtiger_contactdetails";
                $fieldname = "contactname";
                $idname = "contactid";
            }
            if ($parenttype == "Accounts") {
                $tablename = "vtiger_account";
                $fieldname = "accountname";
                $idname = "accountid";
            }
            if ($parentid != '') {
                $sql = "SELECT * FROM {$tablename} WHERE {$idname} = ?";
                $fieldvalue = $adb->query_result($adb->pquery($sql, array($parentid)), 0, $fieldname);
                $value = '<a href=index.php?module=' . $parenttype . '&action=DetailView&record=' . $parentid . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($fieldvalue) . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 78) {
            if ($temp_val != '') {
                $quote_name = getQuoteName($temp_val);
                $value = '<a href=index.php?module=Quotes&action=DetailView&record=' . $temp_val . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($quote_name) . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 79) {
            if ($temp_val != '') {
                $purchaseorder_name = getPoName($temp_val);
                $value = '<a href=index.php?module=PurchaseOrder&action=DetailView&record=' . $temp_val . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($purchaseorder_name) . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 80) {
            if ($temp_val != '') {
                $salesorder_name = getSoName($temp_val);
                $value = "<a href=index.php?module=SalesOrder&action=DetailView&record={$temp_val}&parenttab=" . urlencode($tabname) . ">" . textlength_check($salesorder_name) . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 75 || $uitype == 81) {
            if ($temp_val != '') {
                $vendor_name = getVendorName($temp_val);
                $value = '<a href=index.php?module=Vendors&action=DetailView&record=' . $temp_val . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($vendor_name) . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 98) {
            $value = '<a href="index.php?action=RoleDetailView&module=Settings&parenttab=Settings&roleid=' . $temp_val . '">' . textlength_check(getRoleName($temp_val)) . '</a>';
        } elseif ($uitype == 33) {
            $value = $temp_val != "" ? str_ireplace(' |##| ', ', ', $temp_val) : "";
            if (!$is_admin && $value != '') {
                $value = $field_val != "" ? str_ireplace(' |##| ', ', ', $field_val) : "";
                if ($value != '') {
                    $value_arr = explode(',', trim($value));
                    $roleid = $current_user->roleid;
                    $subrole = getRoleSubordinates($roleid);
                    if (count($subrole) > 0) {
                        $roleids = $subrole;
                        array_push($roleids, $roleid);
                    } else {
                        $roleids = $roleid;
                    }
                    if (count($roleids) > 0) {
                        $pick_query = "select distinct {$fieldname} from vtiger_{$fieldname} inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_{$fieldname}.picklist_valueid where roleid in (" . generateQuestionMarks($roleids) . ") and picklistid in (select picklistid from vtiger_{$fieldname}) order by {$fieldname} asc";
                        $params = array($roleids);
                    } else {
                        $pick_query = "select distinct {$fieldname} from vtiger_{$fieldname} inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_{$fieldname}.picklist_valueid where picklistid in (select picklistid from vtiger_{$fieldname}) order by {$fieldname} asc";
                        $params = array();
                    }
                    $pickListResult = $adb->pquery($pick_query, $params);
                    $picklistval = array();
                    for ($i = 0; $i < $adb->num_rows($pickListResult); $i++) {
                        $picklistarr[] = $adb->query_result($pickListResult, $i, $fieldname);
                    }
                    $value_temp = array();
                    $string_temp = '';
                    $str_c = 0;
                    foreach ($value_arr as $ind => $val) {
                        $notaccess = '<font color="red">' . $app_strings['LBL_NOT_ACCESSIBLE'] . "</font>";
                        if (!$listview_max_textlength || !(strlen(preg_replace("/(<\\/?)(\\w+)([^>]*>)/i", "", $string_temp)) > $listview_max_textlength)) {
                            $value_temp1 = in_array(trim($val), $picklistarr) ? $val : $notaccess;
                            if ($str_c != 0) {
                                $string_temp .= ' , ';
                            }
                            $string_temp .= $value_temp1;
                            $str_c++;
                        } else {
                            $string_temp .= '...';
                        }
                    }
                    $value = $string_temp;
                }
            }
        } elseif ($uitype == 85) {
            $value = $temp_val != "" ? "<a href='skype:{$temp_val}?call'>{$temp_val}</a>" : "";
        } elseif ($uitype == 116) {
            $value = $temp_val != "" ? getCurrencyName($temp_val) : "";
        } elseif ($uitype == 117) {
            // NOTE: Without symbol the value could be used for filtering/lookup hence avoiding the translation
            $value = $temp_val != "" ? getCurrencyName($temp_val, false) : "";
        } elseif ($uitype == 26) {
            $sql = "select foldername from vtiger_attachmentsfolder where folderid = ?";
            $res = $adb->pquery($sql, array($temp_val));
            $foldername = $adb->query_result($res, 0, 'foldername');
            $value = $foldername;
        } elseif ($uitype == 11) {
            // Fix added for Trac Id: 6139
            if (get_use_asterisk($current_user->id)) {
                $value = "<a href='javascript:;' onclick='startCall(&quot;{$temp_val}&quot;, &quot;{$entity_id}&quot;)'>" . textlength_check($temp_val) . "</a>";
            } else {
                $value = $temp_val;
            }
        } elseif ($uitype == 25) {
            $contactid = $_REQUEST['record'];
            $emailid = $adb->query_result($list_result, $list_result_count, "activityid");
            $result = $adb->pquery("SELECT access_count FROM vtiger_email_track WHERE crmid=? AND mailid=?", array($contactid, $emailid));
            $value = $adb->query_result($result, 0, "access_count");
            if (!$value) {
                $value = 0;
            }
        } elseif ($uitype == 8) {
            if (!empty($temp_val)) {
                $temp_val = html_entity_decode($temp_val, ENT_QUOTES, $default_charset);
                $json = new Zend_Json();
                $value = vt_suppressHTMLTags(implode(',', $json->decode($temp_val)));
            }
        } else {
            if ($fieldname == $focus->list_link_field) {
                if ($mode == "search") {
                    if ($popuptype == "specific" || $popuptype == "toDospecific") {
                        // Added for get the first name of contact in Popup window
                        if ($colname == "lastname" && $module == 'Contacts') {
                            $temp_val = getFullNameFromQResult($list_result, $list_result_count, "Contacts");
                        }
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        //Added to avoid the error when select SO from Invoice through AjaxEdit
                        if ($module == 'SalesOrder') {
                            $count = counterValue();
                            $value = '<a href="javascript:window.close();" onclick=\'set_return_specific("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '","' . $_REQUEST['form'] . '");\' id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                        } elseif ($module == 'Contacts') {
                            require_once 'modules/Contacts/Contacts.php';
                            $cntct_focus = new Contacts();
                            $cntct_focus->retrieve_entity_info($entity_id, "Contacts");
                            $slashes_temp_val = popup_from_html($temp_val);
                            $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                            //ADDED TO CHECK THE FIELD PERMISSIONS FOR
                            $xyz = array('mailingstreet', 'mailingcity', 'mailingzip', 'mailingpobox', 'mailingcountry', 'mailingstate', 'otherstreet', 'othercity', 'otherzip', 'otherpobox', 'othercountry', 'otherstate');
                            for ($i = 0; $i < 12; $i++) {
                                if (getFieldVisibilityPermission($module, $current_user->id, $xyz[$i]) == '0') {
                                    $cntct_focus->column_fields[$xyz[$i]] = $cntct_focus->column_fields[$xyz[$i]];
                                } else {
                                    $cntct_focus->column_fields[$xyz[$i]] = '';
                                }
                            }
                            // For ToDo creation the underlying form is not named as EditView
                            $form = !empty($_REQUEST['form']) ? $_REQUEST['form'] : '';
                            if (!empty($form)) {
                                $form = htmlspecialchars($form, ENT_QUOTES, $default_charset);
                            }
                            $count = counterValue();
                            $value = '<a href="javascript:void(0);" onclick=\'set_return_address("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingstreet']) . '", "' . popup_decode_html($cntct_focus->column_fields['otherstreet']) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingcity']) . '", "' . popup_decode_html($cntct_focus->column_fields['othercity']) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingstate']) . '", "' . popup_decode_html($cntct_focus->column_fields['otherstate']) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingzip']) . '", "' . popup_decode_html($cntct_focus->column_fields['otherzip']) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingcountry']) . '", "' . popup_decode_html($cntct_focus->column_fields['othercountry']) . '","' . popup_decode_html($cntct_focus->column_fields['mailingpobox']) . '", "' . popup_decode_html($cntct_focus->column_fields['otherpobox']) . '","' . $form . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                        } else {
                            if ($popuptype == 'toDospecific') {
                                $count = counterValue();
                                $value = '<a href="javascript:window.close();" onclick=\'set_return_toDospecific("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                            } else {
                                $count = counterValue();
                                $value = '<a href="javascript:window.close();" onclick=\'set_return_specific("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                            }
                        }
                    } elseif ($popuptype == "detailview") {
                        if ($colname == "lastname" && ($module == 'Contacts' || $module == 'Leads')) {
                            $temp_val = getFullNameFromQResult($list_result, $list_result_count, $module);
                        }
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $focus->record_id = $_REQUEST['recordid'];
                        $popupMode = $_REQUEST['popupmode'];
                        $callBack = $_REQUEST['callback'];
                        if ($_REQUEST['return_module'] == "Calendar") {
                            $count = counterValue();
                            $value = '<a href="javascript:window.close();" id="calendarCont' . $entity_id . '" LANGUAGE=javascript onclick=\'add_data_to_relatedlist_incal("' . $entity_id . '","' . decode_html($slashes_temp_val) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                        } else {
                            $count = counterValue();
                            if (empty($callBack)) {
                                $value = '<a style="cursor:pointer;" onclick=\'add_data_to_relatedlist("' . $entity_id . '","' . $focus->record_id . '","' . $module . '","' . $popupMode . '");\'>' . textlength_check($temp_val) . '</a>';
                            } else {
                                $value = '<a style="cursor:pointer;" onclick=\'add_data_to_relatedlist("' . $entity_id . '","' . $focus->record_id . '","' . $module . '","' . $popupMode . '",' . $callBack . ');\'>' . textlength_check($temp_val) . '</a>';
                            }
                            if ($module === 'Documents' && $_REQUEST['return_module'] === 'Emails') {
                                $attachment = $adb->query_result($list_result, $list_result_count, 'filename');
                                $value .= "<input type='hidden' id='document_attachment_{$entity_id}' value='{$attachment}'>";
                            }
                        }
                    } elseif ($popuptype == "formname_specific") {
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $count = counterValue();
                        $value = '<a href="javascript:window.close();" onclick=\'set_return_formname_specific("' . $_REQUEST['form'] . '", "' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                    } elseif ($popuptype == "inventory_prod") {
                        $row_id = $_REQUEST['curr_row'];
                        //To get all the tax types and values and pass it to product details
                        $tax_str = '';
                        $tax_details = getAllTaxes();
                        for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
                            $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
                        }
                        $tax_str = trim($tax_str, ',');
                        $rate = $user_info['conv_rate'];
                        if (getFieldVisibilityPermission('Products', $current_user->id, 'unit_price') == '0') {
                            $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
                            if ($_REQUEST['currencyid'] != null) {
                                $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id));
                                $unitprice = $prod_prices[$entity_id];
                            }
                        } else {
                            $unitprice = '';
                        }
                        $sub_products = '';
                        $sub_prod = '';
                        $sub_prod_query = $adb->pquery("SELECT vtiger_products.productid,vtiger_products.productname,vtiger_products.qtyinstock,vtiger_crmentity.description from vtiger_products INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_products.productid INNER JOIN vtiger_seproductsrel on vtiger_seproductsrel.crmid=vtiger_products.productid WHERE vtiger_seproductsrel.productid=? and vtiger_seproductsrel.setype='Products'", array($entity_id));
                        for ($i = 0; $i < $adb->num_rows($sub_prod_query); $i++) {
                            //$sub_prod=array();
                            $id = $adb->query_result($sub_prod_query, $i, "productid");
                            $str_sep = '';
                            if ($i > 0) {
                                $str_sep = ":";
                            }
                            $sub_products .= $str_sep . $id;
                            $sub_prod .= $str_sep . " - " . htmlspecialchars($adb->query_result($sub_prod_query, $i, "productname"), ENT_QUOTES, $default_charset);
                        }
                        $sub_det = $sub_products . "::" . str_replace(":", "<br>", $sub_prod);
                        $qty_stock = $adb->query_result($list_result, $list_result_count, 'qtyinstock');
                        //fix for T6943
                        $slashes_temp_val = popup_from_html($field_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $description = popup_from_html($adb->query_result($list_result, $list_result_count, 'description'));
                        $slashes_temp_desc = decode_html(htmlspecialchars($description, ENT_QUOTES, $default_charset));
                        $slashes_desc = str_replace(array("\r", "\n"), array('\\r', '\\n'), $slashes_temp_desc);
                        $tmp_arr = array("entityid" => $entity_id, "prodname" => "" . stripslashes(decode_html(nl2br($slashes_temp_val))) . "", "unitprice" => "{$unitprice}", "qtyinstk" => "{$qty_stock}", "taxstring" => "{$tax_str}", "rowid" => "{$row_id}", "desc" => "{$slashes_desc}", "subprod_ids" => "{$sub_det}");
                        require_once 'include/Zend/Json.php';
                        $prod_arr = Zend_Json::encode($tmp_arr);
                        $value = '<a href="javascript:window.close();" id=\'popup_product_' . $entity_id . '\' onclick=\'set_return_inventory("' . $entity_id . '", "' . decode_html(nl2br($slashes_temp_val)) . '", "' . $unitprice . '", "' . $qty_stock . '","' . $tax_str . '","' . $row_id . '","' . $slashes_desc . '","' . $sub_det . '");\' vt_prod_arr=\'' . $prod_arr . '\' >' . textlength_check($temp_val) . '</a>';
                    } elseif ($popuptype == "inventory_prod_po") {
                        $row_id = $_REQUEST['curr_row'];
                        //To get all the tax types and values and pass it to product details
                        $tax_str = '';
                        $tax_details = getAllTaxes();
                        for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
                            $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
                        }
                        $tax_str = trim($tax_str, ',');
                        $rate = $user_info['conv_rate'];
                        if (getFieldVisibilityPermission($module, $current_user->id, 'unit_price') == '0') {
                            $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
                            if ($_REQUEST['currencyid'] != null) {
                                $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id), $module);
                                $unitprice = $prod_prices[$entity_id];
                            }
                        } else {
                            $unitprice = '';
                        }
                        $sub_products = '';
                        $sub_prod = '';
                        $sub_prod_query = $adb->pquery("SELECT vtiger_products.productid,vtiger_products.productname,vtiger_products.qtyinstock,vtiger_crmentity.description from vtiger_products INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_products.productid INNER JOIN vtiger_seproductsrel on vtiger_seproductsrel.crmid=vtiger_products.productid WHERE vtiger_seproductsrel.productid=? and vtiger_seproductsrel.setype='Products'", array($entity_id));
                        for ($i = 0; $i < $adb->num_rows($sub_prod_query); $i++) {
                            //$sub_prod=array();
                            $id = $adb->query_result($sub_prod_query, $i, "productid");
                            $str_sep = '';
                            if ($i > 0) {
                                $str_sep = ":";
                            }
                            $sub_products .= $str_sep . $id;
                            $sub_prod .= $str_sep . " - {$id}." . $adb->query_result($sub_prod_query, $i, "productname");
                        }
                        $sub_det = $sub_products . "::" . str_replace(":", "<br>", $sub_prod);
                        $slashes_temp_val = popup_from_html($field_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $description = popup_from_html($adb->query_result($list_result, $list_result_count, 'description'));
                        $slashes_temp_desc = decode_html(htmlspecialchars($description, ENT_QUOTES, $default_charset));
                        $slashes_desc = str_replace(array("\r", "\n"), array('\\r', '\\n'), $slashes_temp_desc);
                        $tmp_arr = array("entityid" => $entity_id, "prodname" => "" . stripslashes(decode_html(nl2br($slashes_temp_val))) . "", "unitprice" => "{$unitprice}", "qtyinstk" => "{$qty_stock}", "taxstring" => "{$tax_str}", "rowid" => "{$row_id}", "desc" => "{$slashes_desc}", "subprod_ids" => "{$sub_det}");
                        require_once 'include/Zend/Json.php';
                        $prod_arr = Zend_Json::encode($tmp_arr);
                        $value = '<a href="javascript:window.close();" id=\'popup_product_' . $entity_id . '\' onclick=\'set_return_inventory_po("' . $entity_id . '", "' . decode_html(nl2br($slashes_temp_val)) . '", "' . $unitprice . '", "' . $tax_str . '","' . $row_id . '","' . $slashes_desc . '","' . $sub_det . '"); \'  vt_prod_arr=\'' . $prod_arr . '\' >' . textlength_check($temp_val) . '</a>';
                    } elseif ($popuptype == "inventory_service") {
                        $row_id = $_REQUEST['curr_row'];
                        //To get all the tax types and values and pass it to product details
                        $tax_str = '';
                        $tax_details = getAllTaxes();
                        for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
                            $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
                        }
                        $tax_str = trim($tax_str, ',');
                        $rate = $user_info['conv_rate'];
                        if (getFieldVisibilityPermission('Services', $current_user->id, 'unit_price') == '0') {
                            $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
                            if ($_REQUEST['currencyid'] != null) {
                                $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id), $module);
                                $unitprice = $prod_prices[$entity_id];
                            }
                        } else {
                            $unitprice = '';
                        }
                        $slashes_temp_val = popup_from_html($field_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $description = popup_from_html($adb->query_result($list_result, $list_result_count, 'description'));
                        $slashes_temp_desc = decode_html(htmlspecialchars($description, ENT_QUOTES, $default_charset));
                        $slashes_desc = str_replace(array("\r", "\n"), array('\\r', '\\n'), $slashes_temp_desc);
                        $tmp_arr = array("entityid" => $entity_id, "prodname" => "" . stripslashes(decode_html(nl2br($slashes_temp_val))) . "", "unitprice" => "{$unitprice}", "taxstring" => "{$tax_str}", "rowid" => "{$row_id}", "desc" => "{$slashes_desc}");
                        require_once 'include/Zend/Json.php';
                        $prod_arr = Zend_Json::encode($tmp_arr);
                        $value = '<a href="javascript:window.close();" id=\'popup_product_' . $entity_id . '\' onclick=\'set_return_inventory("' . $entity_id . '", "' . decode_html(nl2br($slashes_temp_val)) . '", "' . $unitprice . '", "' . $tax_str . '","' . $row_id . '","' . $slashes_desc . '");\'  vt_prod_arr=\'' . $prod_arr . '\' >' . textlength_check($temp_val) . '</a>';
                    } elseif ($popuptype == "inventory_pb") {
                        $prod_id = $_REQUEST['productid'];
                        $flname = $_REQUEST['fldname'];
                        $listprice = getListPrice($prod_id, $entity_id);
                        $temp_val = popup_from_html($temp_val);
                        $count = counterValue();
                        $value = '<a href="javascript:window.close();" onclick=\'set_return_inventory_pb("' . $listprice . '", "' . $flname . '"); \'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                    } elseif ($popuptype == "specific_account_address") {
                        require_once 'modules/Accounts/Accounts.php';
                        $acct_focus = new Accounts();
                        $acct_focus->retrieve_entity_info($entity_id, "Accounts");
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $xyz = array('bill_street', 'bill_city', 'bill_code', 'bill_pobox', 'bill_country', 'bill_state', 'ship_street', 'ship_city', 'ship_code', 'ship_pobox', 'ship_country', 'ship_state');
                        for ($i = 0; $i < 12; $i++) {
                            if (getFieldVisibilityPermission($module, $current_user->id, $xyz[$i]) == '0') {
                                $acct_focus->column_fields[$xyz[$i]] = $acct_focus->column_fields[$xyz[$i]];
                            } else {
                                $acct_focus->column_fields[$xyz[$i]] = '';
                            }
                        }
                        $bill_street = str_replace(array("\r", "\n"), array('\\r', '\\n'), popup_decode_html($acct_focus->column_fields['bill_street']));
                        $ship_street = str_replace(array("\r", "\n"), array('\\r', '\\n'), popup_decode_html($acct_focus->column_fields['ship_street']));
                        $count = counterValue();
                        $value = '<a href="javascript:void(0);" onclick=\'set_return_shipbilladdress("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $bill_street . '", "' . $ship_street . '", "' . popup_decode_html($acct_focus->column_fields['bill_city']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_city']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_state']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_state']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_code']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_code']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_country']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_country']) . '","' . popup_decode_html($acct_focus->column_fields['bill_pobox']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_pobox']) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                    } elseif ($popuptype == "specific_contact_account_address") {
                        require_once 'modules/Accounts/Accounts.php';
                        $acct_focus = new Accounts();
                        $acct_focus->retrieve_entity_info($entity_id, "Accounts");
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $bill_street = str_replace(array("\r", "\n"), array('\\r', '\\n'), popup_decode_html($acct_focus->column_fields['bill_street']));
                        $ship_street = str_replace(array("\r", "\n"), array('\\r', '\\n'), popup_decode_html($acct_focus->column_fields['ship_street']));
                        $count = counterValue();
                        $value = '<a href="javascript:window.close();" onclick=\'set_return_contact_address("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $bill_street . '", "' . $ship_street . '", "' . popup_decode_html($acct_focus->column_fields['bill_city']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_city']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_state']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_state']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_code']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_code']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_country']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_country']) . '","' . popup_decode_html($acct_focus->column_fields['bill_pobox']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_pobox']) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                    } elseif ($popuptype == "specific_potential_account_address") {
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        // For B2C support, Potential was enabled to be linked to Contacts also.
                        // Hence we need case handling for it.
                        $relatedid = $adb->query_result($list_result, $list_result_count, "related_to");
                        $relatedentity = getSalesEntityType($relatedid);
                        if ($relatedentity == 'Accounts') {
                            require_once 'modules/Accounts/Accounts.php';
                            $acct_focus = new Accounts();
                            $acct_focus->retrieve_entity_info($relatedid, "Accounts");
                            $account_name = getAccountName($relatedid);
                            $slashes_account_name = popup_from_html($account_name);
                            $slashes_account_name = htmlspecialchars($slashes_account_name, ENT_QUOTES, $default_charset);
                            $xyz = array('bill_street', 'bill_city', 'bill_code', 'bill_pobox', 'bill_country', 'bill_state', 'ship_street', 'ship_city', 'ship_code', 'ship_pobox', 'ship_country', 'ship_state');
                            for ($i = 0; $i < 12; $i++) {
                                if (getFieldVisibilityPermission('Accounts', $current_user->id, $xyz[$i]) == '0') {
                                    $acct_focus->column_fields[$xyz[$i]] = $acct_focus->column_fields[$xyz[$i]];
                                } else {
                                    $acct_focus->column_fields[$xyz[$i]] = '';
                                }
                            }
                            $bill_street = str_replace(array("\r", "\n"), array('\\r', '\\n'), popup_decode_html($acct_focus->column_fields['bill_street']));
                            $ship_street = str_replace(array("\r", "\n"), array('\\r', '\\n'), popup_decode_html($acct_focus->column_fields['ship_street']));
                            $count = counterValue();
                            $value = '<a href="javascript:window.close();" onclick=\'set_return_address("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $relatedid . '", "' . nl2br(decode_html($slashes_account_name)) . '", "' . $bill_street . '", "' . $ship_street . '", "' . popup_decode_html($acct_focus->column_fields['bill_city']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_city']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_state']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_state']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_code']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_code']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_country']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_country']) . '","' . popup_decode_html($acct_focus->column_fields['bill_pobox']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_pobox']) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                        } else {
                            if ($relatedentity == 'Contacts') {
                                require_once 'modules/Contacts/Contacts.php';
                                $displayValueArray = getEntityName('Contacts', $relatedid);
                                if (!empty($displayValueArray)) {
                                    foreach ($displayValueArray as $key => $field_value) {
                                        $contact_name = $field_value;
                                    }
                                } else {
                                    $contact_name = '';
                                }
                                $slashes_contact_name = popup_from_html($contact_name);
                                $slashes_contact_name = htmlspecialchars($slashes_contact_name, ENT_QUOTES, $default_charset);
                                $count = counterValue();
                                $value = '<a href="javascript:window.close();" onclick=\'set_return_contact("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $relatedid . '", "' . nl2br(decode_html($slashes_contact_name)) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                            } else {
                                $value = $temp_val;
                            }
                        }
                    } elseif ($popuptype == "set_return_emails") {
                        if (empty($_REQUEST['email_field'])) {
                            $sre_param = ', "default"';
                        } else {
                            $sre_param = ', "' . $_REQUEST['email_field'] . '"';
                        }
                        if ($module == 'Accounts') {
                            $name = $adb->query_result($list_result, $list_result_count, 'accountname');
                            $accid = $adb->query_result($list_result, $list_result_count, 'accountid');
                            if (CheckFieldPermission('email1', $module) == "true") {
                                $emailaddress = $adb->query_result($list_result, $list_result_count, "email1");
                                $email_check = 1;
                            } else {
                                $email_check = 0;
                            }
                            if ($emailaddress == '') {
                                if (CheckFieldPermission('email2', $module) == 'true') {
                                    $emailaddress2 = $adb->query_result($list_result, $list_result_count, "email2");
                                    $email_check = 2;
                                } else {
                                    if ($email_check == 1) {
                                        $email_check = 4;
                                    } else {
                                        $email_check = 3;
                                    }
                                }
                            }
                            $querystr = "SELECT fieldid,fieldlabel,columnname FROM vtiger_field WHERE tabid=? and uitype=13 and vtiger_field.presence in (0,2)";
                            $queryres = $adb->pquery($querystr, array(getTabid($module)));
                            //Change this index 0 - to get the vtiger_fieldid based on email1 or email2
                            $fieldid = $adb->query_result($queryres, 0, 'fieldid');
                            $slashes_name = popup_from_html($name);
                            $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
                            $count = counterValue();
                            $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',' . $fieldid . ',"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"' . $sre_param . '); \'id = ' . $count . '>' . textlength_check($name) . '</a>';
                        } elseif ($module == 'Vendors') {
                            $name = $adb->query_result($list_result, $list_result_count, 'vendorname');
                            $venid = $adb->query_result($list_result, $list_result_count, 'vendorid');
                            if (CheckFieldPermission('email', $module) == "true") {
                                $emailaddress = $adb->query_result($list_result, $list_result_count, "email");
                                $email_check = 1;
                            } else {
                                $email_check = 0;
                            }
                            $querystr = "SELECT fieldid,fieldlabel,columnname FROM vtiger_field WHERE tabid=? and uitype=13 and vtiger_field.presence in (0,2)";
                            $queryres = $adb->pquery($querystr, array(getTabid($module)));
                            //Change this index 0 - to get the vtiger_fieldid based on email1 or email2
                            $fieldid = $adb->query_result($queryres, 0, 'fieldid');
                            $slashes_name = popup_from_html($name);
                            $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
                            $count = counterValue();
                            $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',' . $fieldid . ',"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"' . $sre_param . '); \'id = ' . $count . '>' . textlength_check($name) . '</a>';
                        } elseif ($module == 'Contacts' || $module == 'Leads') {
                            $name = getFullNameFromQResult($list_result, $list_result_count, $module);
                            if (CheckFieldPermission('email', $module) == "true") {
                                $emailaddress = $adb->query_result($list_result, $list_result_count, "email");
                                $email_check = 1;
                            } else {
                                $email_check = 0;
                            }
                            if ($emailaddress == '') {
                                if (CheckFieldPermission('secondaryemail', $module) == 'true') {
                                    $emailaddress2 = $adb->query_result($list_result, $list_result_count, "secondaryemail");
                                    $email_check = 2;
                                } else {
                                    if ($email_check == 1) {
                                        $email_check = 4;
                                    } else {
                                        $email_check = 3;
                                    }
                                }
                            }
                            $querystr = "SELECT fieldid,fieldlabel,columnname FROM vtiger_field WHERE tabid=? and uitype=13 and vtiger_field.presence in (0,2)";
                            $queryres = $adb->pquery($querystr, array(getTabid($module)));
                            //Change this index 0 - to get the vtiger_fieldid based on email or secondaryemail
                            $fieldid = $adb->query_result($queryres, 0, 'fieldid');
                            $slashes_name = popup_from_html($name);
                            $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
                            $count = counterValue();
                            $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',' . $fieldid . ',"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"' . $sre_param . '); \'id = ' . $count . '>' . $name . '</a>';
                        } elseif ($module == 'Project') {
                            $name = $adb->query_result($list_result, $list_result_count, 'projectname');
                            $projid = $adb->query_result($list_result, $list_result_count, 'projectid');
                            if (CheckFieldPermission('email', $module) == "true") {
                                $emailaddress = $adb->query_result($list_result, $list_result_count, "email");
                                $email_check = 1;
                            } else {
                                $email_check = 0;
                            }
                            $querystr = "SELECT fieldid,fieldlabel,columnname FROM vtiger_field WHERE tabid=? and uitype=13 and vtiger_field.presence in (0,2)";
                            $queryres = $adb->pquery($querystr, array(getTabid($module)));
                            //Change this index 0 - to get the vtiger_fieldid based on email1 or email2
                            $fieldid = $adb->query_result($queryres, 0, 'fieldid');
                            $slashes_name = popup_from_html($name);
                            $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
                            $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',' . $fieldid . ',"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"' . $sre_param . '); \'>' . textlength_check($name) . '</a>';
                        } elseif ($module == 'ProjectTask') {
                            $name = $adb->query_result($list_result, $list_result_count, 'projecttaskname');
                            $projid = $adb->query_result($list_result, $list_result_count, 'projecttaskid');
                            if (CheckFieldPermission('email', $module) == "true") {
                                $emailaddress = $adb->query_result($list_result, $list_result_count, "email");
                                $email_check = 1;
                            } else {
                                $email_check = 0;
                            }
                            $querystr = "SELECT fieldid,fieldlabel,columnname FROM vtiger_field WHERE tabid=? and uitype=13 and vtiger_field.presence in (0,2)";
                            $queryres = $adb->pquery($querystr, array(getTabid($module)));
                            //Change this index 0 - to get the vtiger_fieldid based on email1 or email2
                            $fieldid = $adb->query_result($queryres, 0, 'fieldid');
                            $slashes_name = popup_from_html($name);
                            $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
                            $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',' . $fieldid . ',"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"' . $sre_param . '); \'>' . textlength_check($name) . '</a>';
                        } elseif ($module == 'Potentials') {
                            $name = $adb->query_result($list_result, $list_result_count, 'potentialname');
                            $potid = $adb->query_result($list_result, $list_result_count, 'potentialid');
                            if (CheckFieldPermission('email', $module) == "true") {
                                $emailaddress = $adb->query_result($list_result, $list_result_count, "email");
                                $email_check = 1;
                            } else {
                                $email_check = 0;
                            }
                            $querystr = "SELECT fieldid,fieldlabel,columnname FROM vtiger_field WHERE tabid=? and uitype=13 and vtiger_field.presence in (0,2)";
                            $queryres = $adb->pquery($querystr, array(getTabid($module)));
                            //Change this index 0 - to get the vtiger_fieldid based on email1 or email2
                            $fieldid = $adb->query_result($queryres, 0, 'fieldid');
                            $slashes_name = popup_from_html($name);
                            $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
                            $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',' . $fieldid . ',"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"' . $sre_param . '); \'>' . textlength_check($name) . '</a>';
                        } elseif ($module == 'HelpDesk') {
                            $name = $adb->query_result($list_result, $list_result_count, 'title');
                            $potid = $adb->query_result($list_result, $list_result_count, 'ticketid');
                            if (CheckFieldPermission('email', $module) == "true") {
                                $emailaddress = $adb->query_result($list_result, $list_result_count, "email");
                                $email_check = 1;
                            } else {
                                $email_check = 0;
                            }
                            $querystr = "SELECT fieldid,fieldlabel,columnname FROM vtiger_field WHERE tabid=? and uitype=13 and vtiger_field.presence in (0,2)";
                            $queryres = $adb->pquery($querystr, array(getTabid($module)));
                            //Change this index 0 - to get the vtiger_fieldid based on email1 or email2
                            $fieldid = $adb->query_result($queryres, 0, 'fieldid');
                            $slashes_name = popup_from_html($name);
                            $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
                            $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',' . $fieldid . ',"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"' . $sre_param . '); \'>' . textlength_check($name) . '</a>';
                        } else {
                            $name = getFullNameFromQResult($list_result, $list_result_count, $module);
                            $emailaddress = $adb->query_result($list_result, $list_result_count, "email1");
                            $slashes_name = popup_from_html($name);
                            $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
                            $email_check = 1;
                            $count = counterValue();
                            $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',-1,"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"' . $sre_param . '); \'id = ' . $count . '>' . textlength_check($name) . '</a>';
                        }
                    } elseif ($popuptype == "specific_vendor_address") {
                        require_once 'modules/Vendors/Vendors.php';
                        $acct_focus = new Vendors();
                        $acct_focus->retrieve_entity_info($entity_id, "Vendors");
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $xyz = array('street', 'city', 'postalcode', 'pobox', 'country', 'state');
                        for ($i = 0; $i < 6; $i++) {
                            if (getFieldVisibilityPermission($module, $current_user->id, $xyz[$i]) == '0') {
                                $acct_focus->column_fields[$xyz[$i]] = $acct_focus->column_fields[$xyz[$i]];
                            } else {
                                $acct_focus->column_fields[$xyz[$i]] = '';
                            }
                        }
                        $bill_street = str_replace(array("\r", "\n"), array('\\r', '\\n'), popup_decode_html($acct_focus->column_fields['street']));
                        $count = counterValue();
                        $value = '<a href="javascript:void(0);" onclick=\'set_return_address("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $bill_street . '", "' . popup_decode_html($acct_focus->column_fields['city']) . '", "' . popup_decode_html($acct_focus->column_fields['state']) . '", "' . popup_decode_html($acct_focus->column_fields['postalcode']) . '", "' . popup_decode_html($acct_focus->column_fields['country']) . '","' . popup_decode_html($acct_focus->column_fields['pobox']) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                    } elseif ($popuptype == "specific_campaign") {
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $count = counterValue();
                        $value = '<a href="javascript:window.close();" onclick=\'set_return_specific_campaign("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                    } else {
                        if ($colname == "lastname") {
                            $temp_val = getFullNameFromQResult($list_result, $list_result_count, $module);
                        } elseif ($module == 'Users' && $fieldname == 'last_name') {
                            $temp_val = getFullNameFromQResult($list_result, $list_result_count, $module);
                        }
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $log->debug("Exiting getValue method ...");
                        if ($_REQUEST['maintab'] == 'Calendar') {
                            $count = counterValue();
                            $value = '<a href="javascript:window.close();" onclick=\'set_return_todo("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                        } else {
                            $value = '<a href="javascript:window.close();" onclick=\'set_return("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'';
                            if (empty($_REQUEST['forfield']) && $focus->popup_type != 'detailview') {
                                $count = counterValue();
                                $value .= " id='{$count}' ";
                            }
                            $value .= '>' . textlength_check($temp_val) . '</a>';
                        }
                    }
                } else {
                    if ($module == "Leads" && $colname == "lastname" || $module == "Contacts" && $colname == "lastname") {
                        $count = counterValue();
                        $value = '<a href="index.php?action=DetailView&module=' . $module . '&record=' . $entity_id . '&parenttab=' . $tabname . '" id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                    } elseif ($module == "Calendar") {
                        $actvity_type = $adb->query_result($list_result, $list_result_count, 'activitytype');
                        $actvity_type = $actvity_type != '' ? $actvity_type : $adb->query_result($list_result, $list_result_count, 'type');
                        if ($actvity_type == "Task") {
                            $count = counterValue();
                            $value = '<a href="index.php?action=EventDetailView&module=Calendar4You&record=' . $entity_id . '&activity_mode=Task&parenttab=' . $tabname . '" id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                        } else {
                            $count = counterValue();
                            $value = '<a href="index.php?action=EventDetailView&module=Calendar4You&record=' . $entity_id . '&activity_mode=Events&parenttab=' . $tabname . '" id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                        }
                    } elseif ($module == "Vendors") {
                        $count = counterValue();
                        $value = '<a href="index.php?action=DetailView&module=Vendors&record=' . $entity_id . '&parenttab=' . $tabname . '" id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                    } elseif ($module == "PriceBooks") {
                        $count = counterValue();
                        $value = '<a href="index.php?action=DetailView&module=PriceBooks&record=' . $entity_id . '&parenttab=' . $tabname . '" id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                    } elseif ($module == "SalesOrder") {
                        $count = counterValue();
                        $value = '<a href="index.php?action=DetailView&module=SalesOrder&record=' . $entity_id . '&parenttab=' . $tabname . '" id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                    } elseif ($module == 'Emails') {
                        $value = $temp_val;
                    } elseif ($module == "Users" && $colname == "last_name") {
                        $temp_val = getFullNameFromQResult($list_result, $list_result_count, $module);
                        $value = '<a href="index.php?action=DetailView&module=' . $module . '&record=' . $entity_id . '&parenttab=' . $tabname . '">' . textlength_check($temp_val) . '</a>';
                    } else {
                        $count = counterValue();
                        $value = '<a href="index.php?action=DetailView&module=' . $module . '&record=' . $entity_id . '&parenttab=' . $tabname . '" id = ' . $count . '>' . textlength_check($temp_val) . '</a>';
                    }
                }
            } elseif ($module == 'Calendar' && ($fieldname == 'time_start' || $fieldname == 'time_end')) {
                $dateField = 'date_start';
                if ($fieldname == 'time_end') {
                    $dateField = 'due_date';
                }
                $type = $adb->query_result($list_result, $list_result_count, 'activitytype');
                if (empty($type)) {
                    $type = $adb->query_result($list_result, $list_result_count, 'type');
                }
                if ($type == 'Task' && $fieldname == 'time_end') {
                    $value = '--';
                } else {
                    $date_val = $adb->query_result($list_result, $list_result_count, $dateField);
                    $date = new DateTimeField($date_val . ' ' . $temp_val);
                    $value = $date->getDisplayTime();
                    $value = textlength_check($value);
                }
            } else {
                $value = $temp_val;
                $value = textlength_check($value);
            }
        }
    }
    // Mike Crowe Mod --------------------------------------------------------Make right justified and vtiger_currency value
    if (in_array($uitype, array(71, 72, 7, 9, 90))) {
        $value = '<span align="right">' . $value . '</div>';
    }
    $log->debug("Exiting getValue method ...");
    return $value;
}
 function getListViewEntries($focus, $module, $result, $navigationInfo, $skipActions = false)
 {
     require 'user_privileges/user_privileges_' . $this->user->id . '.php';
     global $listview_max_textlength, $theme, $default_charset;
     $fields = $this->queryGenerator->getFields();
     $whereFields = $this->queryGenerator->getWhereFields();
     $meta = $this->queryGenerator->getMeta($this->queryGenerator->getModule());
     $moduleFields = $meta->getModuleFields();
     $accessibleFieldList = array_keys($moduleFields);
     $listViewFields = array_intersect($fields, $accessibleFieldList);
     $referenceFieldList = $this->queryGenerator->getReferenceFieldList();
     foreach ($referenceFieldList as $fieldName) {
         if (in_array($fieldName, $listViewFields)) {
             $field = $moduleFields[$fieldName];
             $this->fetchNameList($field, $result);
         }
     }
     $db = PearDatabase::getInstance();
     $rowCount = $db->num_rows($result);
     $ownerFieldList = $this->queryGenerator->getOwnerFieldList();
     foreach ($ownerFieldList as $fieldName) {
         if (in_array($fieldName, $listViewFields)) {
             $field = $moduleFields[$fieldName];
             $idList = array();
             for ($i = 0; $i < $rowCount; $i++) {
                 $id = $this->db->query_result($result, $i, $field->getColumnName());
                 if (!isset($this->ownerNameList[$fieldName][$id])) {
                     $idList[] = $id;
                 }
             }
             if (count($idList) > 0) {
                 if (!is_array($this->ownerNameList[$fieldName])) {
                     $this->ownerNameList[$fieldName] = getOwnerNameList($idList);
                 } else {
                     //array_merge API loses key information so need to merge the arrays
                     // manually.
                     $newOwnerList = getOwnerNameList($idList);
                     foreach ($newOwnerList as $id => $name) {
                         $this->ownerNameList[$fieldName][$id] = $name;
                     }
                 }
             }
         }
     }
     foreach ($listViewFields as $fieldName) {
         $field = $moduleFields[$fieldName];
         if (!$is_admin && ($field->getFieldDataType() == 'picklist' || $field->getFieldDataType() == 'multipicklist')) {
             $this->setupAccessiblePicklistValueList($fieldName);
         }
     }
     $useAsterisk = get_use_asterisk($this->user->id);
     $data = array();
     for ($i = 0; $i < $rowCount; ++$i) {
         //Getting the recordId
         if ($module != 'Users') {
             $baseTable = $meta->getEntityBaseTable();
             $moduleTableIndexList = $meta->getEntityTableIndexList();
             $baseTableIndex = $moduleTableIndexList[$baseTable];
             $recordId = $db->query_result($result, $i, $baseTableIndex);
             $ownerId = $db->query_result($result, $i, "smownerid");
         } else {
             $recordId = $db->query_result($result, $i, "id");
         }
         $row = array();
         foreach ($listViewFields as $fieldName) {
             $field = $moduleFields[$fieldName];
             $uitype = $field->getUIType();
             $rawValue = $this->db->query_result($result, $i, $field->getColumnName());
             if ($module == 'Calendar') {
                 $activityType = $this->db->query_result($result, $i, 'activitytype');
             }
             if ($uitype != 8) {
                 $value = html_entity_decode($rawValue, ENT_QUOTES, $default_charset);
             } else {
                 $value = $rawValue;
             }
             if ($module == 'Documents' && $fieldName == 'filename') {
                 $downloadtype = $db->query_result($result, $i, 'filelocationtype');
                 if ($downloadtype == 'I') {
                     $ext = substr($value, strrpos($value, ".") + 1);
                     $ext = strtolower($ext);
                     if ($value != '') {
                         if ($ext == 'bin' || $ext == 'exe' || $ext == 'rpm') {
                             $fileicon = "<img src='" . vtiger_imageurl('fExeBin.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                         } elseif ($ext == 'jpg' || $ext == 'gif' || $ext == 'bmp') {
                             $fileicon = "<img src='" . vtiger_imageurl('fbImageFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                         } elseif ($ext == 'txt' || $ext == 'doc' || $ext == 'xls') {
                             $fileicon = "<img src='" . vtiger_imageurl('fbTextFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                         } elseif ($ext == 'zip' || $ext == 'gz' || $ext == 'rar') {
                             $fileicon = "<img src='" . vtiger_imageurl('fbZipFile.gif', $theme) . "' hspace='3' align='absmiddle'\tborder='0'>";
                         } else {
                             $fileicon = "<img src='" . vtiger_imageurl('fbUnknownFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                         }
                     }
                 } elseif ($downloadtype == 'E') {
                     if (trim($value) != '') {
                         $fileicon = "<img src='" . vtiger_imageurl('fbLink.gif', $theme) . "' alt='" . getTranslatedString('LBL_EXTERNAL_LNK', $module) . "' title='" . getTranslatedString('LBL_EXTERNAL_LNK', $module) . "' hspace='3' align='absmiddle' border='0'>";
                     } else {
                         $value = '--';
                         $fileicon = '';
                     }
                 } else {
                     $value = ' --';
                     $fileicon = '';
                 }
                 $fileName = $db->query_result($result, $i, 'filename');
                 $downloadType = $db->query_result($result, $i, 'filelocationtype');
                 $status = $db->query_result($result, $i, 'filestatus');
                 $fileIdQuery = "select attachmentsid from vtiger_seattachmentsrel where crmid=?";
                 $fileIdRes = $db->pquery($fileIdQuery, array($recordId));
                 $fileId = $db->query_result($fileIdRes, 0, 'attachmentsid');
                 if ($fileName != '' && $status == 1) {
                     if ($downloadType == 'I') {
                         $value = "<a href='index.php?module=uploads&action=downloadfile&" . "entityid={$recordId}&fileid={$fileId}' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "' onclick='javascript:dldCntIncrease({$recordId});'>" . textlength_check($value) . "</a>";
                     } elseif ($downloadType == 'E') {
                         $value = "<a target='_blank' href='{$fileName}' onclick='javascript:" . "dldCntIncrease({$recordId});' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "'>" . textlength_check($value) . "</a>";
                     } else {
                         $value = ' --';
                     }
                 }
                 $value = $fileicon . $value;
             } elseif ($module == 'Documents' && $fieldName == 'filesize') {
                 $downloadType = $db->query_result($result, $i, 'filelocationtype');
                 if ($downloadType == 'I') {
                     $filesize = $value;
                     if ($filesize < 1024) {
                         $value = $filesize . ' B';
                     } elseif ($filesize > 1024 && $filesize < 1048576) {
                         $value = round($filesize / 1024, 2) . ' KB';
                     } else {
                         if ($filesize > 1048576) {
                             $value = round($filesize / (1024 * 1024), 2) . ' MB';
                         }
                     }
                 } else {
                     $value = ' --';
                 }
             } elseif ($module == 'Documents' && $fieldName == 'filestatus') {
                 if ($value == 1) {
                     $value = getTranslatedString('yes', $module);
                 } elseif ($value == 0) {
                     $value = getTranslatedString('no', $module);
                 } else {
                     $value = '--';
                 }
             } elseif ($module == 'Documents' && $fieldName == 'filetype') {
                 $downloadType = $db->query_result($result, $i, 'filelocationtype');
                 if ($downloadType == 'E' || $downloadType != 'I') {
                     $value = '--';
                 }
             } elseif ($field->getUIType() == '27') {
                 if ($value == 'I') {
                     $value = getTranslatedString('LBL_INTERNAL', $module);
                 } elseif ($value == 'E') {
                     $value = getTranslatedString('LBL_EXTERNAL', $module);
                 } else {
                     $value = ' --';
                 }
             } elseif ($field->getFieldDataType() == 'picklist') {
                 if ($value != '' && !$is_admin && $this->picklistRoleMap[$fieldName] && !in_array($value, $this->picklistValueMap[$fieldName])) {
                     $value = "<font color='red'>" . getTranslatedString('LBL_NOT_ACCESSIBLE', $module) . "</font>";
                 } else {
                     $value = getTranslatedString($value, $module);
                     $value = textlength_check($value);
                 }
             } elseif ($field->getFieldDataType() == 'date' || $field->getFieldDataType() == 'datetime') {
                 if ($value != '' && $value != '0000-00-00') {
                     $date = new DateTimeField($value);
                     $value = $date->getDisplayDate();
                     if ($field->getFieldDataType() == 'datetime') {
                         $value .= ' ' . $date->getDisplayTime();
                     }
                 } elseif ($value == '0000-00-00') {
                     $value = '';
                 }
             } elseif ($field->getFieldDataType() == 'currency') {
                 if ($value != '') {
                     if ($field->getUIType() == 72) {
                         if ($fieldName == 'unit_price') {
                             $currencyId = getProductBaseCurrency($recordId, $module);
                             $cursym_convrate = getCurrencySymbolandCRate($currencyId);
                             $currencySymbol = $cursym_convrate['symbol'];
                         } else {
                             $currencyInfo = getInventoryCurrencyInfo($module, $recordId);
                             $currencySymbol = $currencyInfo['currency_symbol'];
                         }
                         $value = number_format($value, 2, '.', '');
                         $currencyValue = CurrencyField::convertToUserFormat($value, null, true);
                         $value = CurrencyField::appendCurrencySymbol($currencyValue, $currencySymbol);
                     } else {
                         //changes made to remove vtiger_currency symbol infront of each
                         //vtiger_potential amount
                         if ($value != 0) {
                             $value = CurrencyField::convertToUserFormat($value);
                         }
                     }
                 }
             } elseif ($field->getFieldDataType() == 'url') {
                 $matchPattern = "^[\\w]+:\\/\\/^";
                 preg_match($matchPattern, $rawValue, $matches);
                 if (!empty($matches[0])) {
                     $value = '<a href="' . $rawValue . '" target="_blank">' . textlength_check($value) . '</a>';
                 } else {
                     $value = '<a href="http://' . $rawValue . '" target="_blank">' . textlength_check($value) . '</a>';
                 }
             } elseif ($field->getFieldDataType() == 'email') {
                 if ($_SESSION['internal_mailer'] == 1) {
                     //check added for email link in user detailview
                     $fieldId = $field->getFieldId();
                     $value = "<a href=\"javascript:InternalMailer({$recordId},{$fieldId}," . "'{$fieldName}','{$module}','record_id');\">" . textlength_check($value) . "</a>";
                 } else {
                     $value = '<a href="mailto:' . $rawValue . '">' . textlength_check($value) . '</a>';
                 }
             } elseif ($field->getFieldDataType() == 'boolean') {
                 if ($value == 1) {
                     $value = getTranslatedString('yes', $module);
                 } elseif ($value == 0) {
                     $value = getTranslatedString('no', $module);
                 } else {
                     $value = '--';
                 }
             } elseif ($field->getUIType() == 98) {
                 $value = '<a href="index.php?action=RoleDetailView&module=Settings&parenttab=' . 'Settings&roleid=' . $value . '">' . textlength_check(getRoleName($value)) . '</a>';
             } elseif ($field->getFieldDataType() == 'multipicklist') {
                 $value = $value != "" ? str_replace(' |##| ', ', ', $value) : "";
                 if (!$is_admin && $value != '') {
                     $valueArray = $rawValue != "" ? explode(' |##| ', $rawValue) : array();
                     $notaccess = '<font color="red">' . getTranslatedString('LBL_NOT_ACCESSIBLE', $module) . "</font>";
                     $tmp = '';
                     $tmpArray = array();
                     foreach ($valueArray as $index => $val) {
                         if (!$listview_max_textlength || !(strlen(preg_replace("/(<\\/?)(\\w+)([^>]*>)/i", "", $tmp)) > $listview_max_textlength)) {
                             if (!$is_admin && $this->picklistRoleMap[$fieldName] && !in_array(trim($val), $this->picklistValueMap[$fieldName])) {
                                 $tmpArray[] = $notaccess;
                                 $tmp .= ', ' . $notaccess;
                             } else {
                                 $tmpArray[] = $val;
                                 $tmp .= ', ' . $val;
                             }
                         } else {
                             $tmpArray[] = '...';
                             $tmp .= '...';
                         }
                     }
                     $value = implode(', ', $tmpArray);
                     $value = textlength_check($value);
                 }
             } elseif ($field->getFieldDataType() == 'skype') {
                 $value = $value != "" ? "<a href='skype:{$value}?call'>" . textlength_check($value) . "</a>" : "";
             } elseif ($field->getFieldDataType() == 'phone') {
                 if ($useAsterisk == 'true') {
                     $value = "<a href='javascript:;' onclick='startCall(&quot;{$value}&quot;, " . "&quot;{$recordId}&quot;)'>" . textlength_check($value) . "</a>";
                 } else {
                     $value = textlength_check($value);
                 }
             } elseif ($field->getFieldDataType() == 'reference') {
                 $referenceFieldInfoList = $this->queryGenerator->getReferenceFieldInfoList();
                 $moduleList = $referenceFieldInfoList[$fieldName];
                 if (count($moduleList) == 1) {
                     $parentModule = $moduleList[0];
                 } else {
                     $parentModule = $this->typeList[$value];
                 }
                 if (!empty($value) && !empty($this->nameList[$fieldName]) && !empty($parentModule)) {
                     $parentMeta = $this->queryGenerator->getMeta($parentModule);
                     $value = textlength_check($this->nameList[$fieldName][$value]);
                     if ($parentMeta->isModuleEntity() && $parentModule != "Users") {
                         $value = "<a href='index.php?module={$parentModule}&action=DetailView&" . "record={$rawValue}' title='" . getTranslatedString($parentModule, $parentModule) . "'>{$value}</a>";
                     }
                 } else {
                     $value = '--';
                 }
             } elseif ($field->getFieldDataType() == 'owner') {
                 $value = textlength_check($this->ownerNameList[$fieldName][$value]);
             } elseif ($field->getUIType() == 25) {
                 //TODO clean request object reference.
                 $contactId = $_REQUEST['record'];
                 $emailId = $this->db->query_result($result, $i, "activityid");
                 $result1 = $this->db->pquery("SELECT access_count FROM vtiger_email_track WHERE " . "crmid=? AND mailid=?", array($contactId, $emailId));
                 $value = $this->db->query_result($result1, 0, "access_count");
                 if (!$value) {
                     $value = 0;
                 }
             } elseif ($field->getUIType() == 8) {
                 if (!empty($value)) {
                     $temp_val = html_entity_decode($value, ENT_QUOTES, $default_charset);
                     $json = new Zend_Json();
                     $value = vt_suppressHTMLTags(implode(',', $json->decode($temp_val)));
                 }
             } elseif (in_array($uitype, array(7, 9, 90))) {
                 $value = "<span align='right'>" . textlength_check($value) . "</div>";
             } elseif ($field->getUIType() == 55) {
                 $value = getTranslatedString($value, $currentModule);
             } else {
                 $value = textlength_check($value);
             }
             $parenttab = getParentTab();
             $nameFields = $this->queryGenerator->getModuleNameFields($module);
             $nameFieldList = explode(',', $nameFields);
             if (in_array($fieldName, $nameFieldList) && $module != 'Emails') {
                 $value = "<a href='index.php?module={$module}&parenttab={$parenttab}&action=DetailView&record=" . "{$recordId}' title='" . getTranslatedString($module, $module) . "'>{$value}</a>";
             } elseif ($fieldName == $focus->list_link_field && $module != 'Emails') {
                 $value = "<a href='index.php?module={$module}&parenttab={$parenttab}&action=DetailView&record=" . "{$recordId}' title='" . getTranslatedString($module, $module) . "'>{$value}</a>";
             }
             // vtlib customization: For listview javascript triggers
             $value = "{$value} <span type='vtlib_metainfo' vtrecordid='{$recordId}' vtfieldname=" . "'{$fieldName}' vtmodule='{$module}' style='display:none;'></span>";
             // END
             $row[] = $value;
         }
         //Added for Actions ie., edit and delete links in listview
         $actionLinkInfo = "";
         if (isPermitted($module, "EditView", "") == 'yes') {
             $edit_link = $this->getListViewEditLink($module, $recordId);
             if (isset($navigationInfo['start']) && $navigationInfo['start'] > 1 && $module != 'Emails') {
                 $actionLinkInfo .= "<a href=\"{$edit_link}&start=" . $navigationInfo['start'] . "\">" . getTranslatedString("LNK_EDIT", $module) . "</a> ";
             } else {
                 $actionLinkInfo .= "<a href=\"{$edit_link}\">" . getTranslatedString("LNK_EDIT", $module) . "</a> ";
             }
         }
         if (isPermitted($module, "Delete", "") == 'yes') {
             $del_link = $this->getListViewDeleteLink($module, $recordId);
             if ($actionLinkInfo != "" && $del_link != "") {
                 $actionLinkInfo .= " | ";
             }
             if ($del_link != "") {
                 $actionLinkInfo .= "<a href='javascript:confirmdelete(\"" . addslashes(urlencode($del_link)) . "\")'>" . getTranslatedString("LNK_DELETE", $module) . "</a>";
             }
         }
         // Record Change Notification
         if (method_exists($focus, 'isViewed') && PerformancePrefs::getBoolean('LISTVIEW_RECORD_CHANGE_INDICATOR', true)) {
             if (!$focus->isViewed($recordId)) {
                 $actionLinkInfo .= " | <img src='" . vtiger_imageurl('important1.gif', $theme) . "' border=0>";
             }
         }
         // END
         if ($actionLinkInfo != "" && !$skipActions) {
             $row[] = $actionLinkInfo;
         }
         $data[$recordId] = $row;
     }
     return $data;
 }
Beispiel #5
0
    for ($templateCount = 0; $templateCount < $tempCount; $templateCount++) {
        $optionString[$tempVal['templateid']] = $tempVal['filename'];
        $tempVal = $adb->fetch_array($wordTemplateResult);
    }
    if ($is_admin) {
        $smarty->assign('MERGEBUTTON', 'permitted');
    } elseif ($tempCount > 0) {
        $smarty->assign('MERGEBUTTON', 'permitted');
    }
    $smarty->assign('TEMPLATECOUNT', $tempCount);
    $smarty->assign('WORDTEMPLATEOPTIONS', $app_strings['LBL_SELECT_TEMPLATE_TO_MAIL_MERGE']);
    $smarty->assign('TOPTIONS', $optionString);
}
$smarty->assign('TODO_PERMISSION', CheckFieldPermission('parent_id', 'Calendar'));
$smarty->assign('EVENT_PERMISSION', CheckFieldPermission('parent_id', 'Events'));
$smarty->assign('USE_ASTERISK', get_use_asterisk($current_user->id));
if (useInternalMailer() == 1) {
    $smarty->assign('INT_MAILER', 'true');
}
if ($singlepane_view == 'true') {
    $related_array = getRelatedLists($currentModule, $focus);
    $smarty->assign("RELATEDLISTS", $related_array);
    require_once 'include/ListView/RelatedListViewSession.php';
    if (!empty($_REQUEST['selected_header']) && !empty($_REQUEST['relation_id'])) {
        RelatedListViewSession::addRelatedModuleToSession(vtlib_purify($_REQUEST['relation_id']), vtlib_purify($_REQUEST['selected_header']));
    }
    $open_related_modules = RelatedListViewSession::getRelatedModulesFromSession();
    $smarty->assign("SELECTEDHEADERS", $open_related_modules);
}
if (isPermitted($currentModule, 'EditView', $record) == 'yes') {
    $smarty->assign('EDIT_DUPLICATE', 'permitted');
 function getListViewRecords($focus, $module, $result)
 {
     global $listview_max_textlength, $theme, $default_charset;
     require 'user_privileges/user_privileges_' . $this->user->id . '.php';
     $fields = $this->queryGenerator->getFields();
     $meta = $this->queryGenerator->getMeta($this->queryGenerator->getModule());
     $moduleFields = $meta->getModuleFields();
     $accessibleFieldList = array_keys($moduleFields);
     $listViewFields = array_intersect($fields, $accessibleFieldList);
     $referenceFieldList = $this->queryGenerator->getReferenceFieldList();
     foreach ($referenceFieldList as $fieldName) {
         if (in_array($fieldName, $listViewFields)) {
             $field = $moduleFields[$fieldName];
             $this->fetchNameList($field, $result);
         }
     }
     $db = PearDatabase::getInstance();
     $rowCount = $db->num_rows($result);
     $ownerFieldList = $this->queryGenerator->getOwnerFieldList();
     foreach ($ownerFieldList as $fieldName) {
         if (in_array($fieldName, $listViewFields)) {
             $field = $moduleFields[$fieldName];
             $idList = array();
             for ($i = 0; $i < $rowCount; $i++) {
                 $id = $this->db->query_result($result, $i, $field->getColumnName());
                 if (!isset($this->ownerNameList[$fieldName][$id])) {
                     $idList[] = $id;
                 }
             }
             if (count($idList) > 0) {
                 if (!is_array($this->ownerNameList[$fieldName])) {
                     $this->ownerNameList[$fieldName] = getOwnerNameList($idList);
                 } else {
                     //array_merge API loses key information so need to merge the arrays
                     // manually.
                     $newOwnerList = getOwnerNameList($idList);
                     foreach ($newOwnerList as $id => $name) {
                         $this->ownerNameList[$fieldName][$id] = $name;
                     }
                 }
             }
         }
     }
     foreach ($listViewFields as $fieldName) {
         $field = $moduleFields[$fieldName];
         if (!$is_admin && ($field->getFieldDataType() == 'picklist' || $field->getFieldDataType() == 'multipicklist')) {
             $this->setupAccessiblePicklistValueList($fieldName);
         }
     }
     $useAsterisk = get_use_asterisk($this->user->id);
     $data = array();
     for ($i = 0; $i < $rowCount; ++$i) {
         //Getting the recordId
         if ($module != 'Users') {
             $baseTable = $meta->getEntityBaseTable();
             $moduleTableIndexList = $meta->getEntityTableIndexList();
             $baseTableIndex = $moduleTableIndexList[$baseTable];
             $recordId = $db->query_result($result, $i, $baseTableIndex);
         } else {
             $recordId = $db->query_result($result, $i, "id");
         }
         $row = array();
         foreach ($listViewFields as $fieldName) {
             $field = $moduleFields[$fieldName];
             $uitype = $field->getUIType();
             $rawValue = $this->db->query_result($result, $i, $field->getColumnName());
             if ($uitype != 8) {
                 $value = html_entity_decode($rawValue, ENT_QUOTES, $default_charset);
             } else {
                 $value = $rawValue;
             }
             if ($module == 'Documents' && $fieldName == 'filename') {
                 $downloadtype = $db->query_result($result, $i, 'filelocationtype');
                 $fileName = $db->query_result($result, $i, 'filename');
                 $downloadType = $db->query_result($result, $i, 'filelocationtype');
                 $status = $db->query_result($result, $i, 'filestatus');
                 $fileIdQuery = "select attachmentsid from vtiger_seattachmentsrel where crmid=?";
                 $fileIdRes = $db->pquery($fileIdQuery, array($recordId));
                 $fileId = $db->query_result($fileIdRes, 0, 'attachmentsid');
                 if ($fileName != '' && $status == 1) {
                     if ($downloadType == 'I') {
                         $value = '<a onclick="Javascript:Documents_Index_Js.updateDownloadCount(\'index.php?module=Documents&action=UpdateDownloadCount&record=' . $recordId . '\');"' . ' href="index.php?module=Documents&action=DownloadFile&record=' . $recordId . '&fileid=' . $fileId . '"' . ' title="' . getTranslatedString('LBL_DOWNLOAD_FILE', $module) . '" >' . textlength_check($value) . '</a>';
                     } elseif ($downloadType == 'E') {
                         $value = '<a onclick="Javascript:Documents_Index_Js.updateDownloadCount(\'index.php?module=Documents&action=UpdateDownloadCount&record=' . $recordId . '\');"' . ' href="' . $fileName . '" target="_blank"' . ' title="' . getTranslatedString('LBL_DOWNLOAD_FILE', $module) . '" >' . textlength_check($value) . '</a>';
                     } else {
                         $value = ' --';
                     }
                 }
                 $value = $fileicon . $value;
             } elseif ($module == 'Documents' && $fieldName == 'filesize') {
                 $downloadType = $db->query_result($result, $i, 'filelocationtype');
                 if ($downloadType == 'I') {
                     $filesize = $value;
                     if ($filesize < 1024) {
                         $value = $filesize . ' B';
                     } elseif ($filesize > 1024 && $filesize < 1048576) {
                         $value = round($filesize / 1024, 2) . ' KB';
                     } else {
                         if ($filesize > 1048576) {
                             $value = round($filesize / (1024 * 1024), 2) . ' MB';
                         }
                     }
                 } else {
                     $value = ' --';
                 }
             } elseif ($module == 'Documents' && $fieldName == 'filestatus') {
                 if ($value == 1) {
                     $value = getTranslatedString('yes', $module);
                 } elseif ($value == 0) {
                     $value = getTranslatedString('no', $module);
                 } else {
                     $value = '--';
                 }
             } elseif ($module == 'Documents' && $fieldName == 'filetype') {
                 $downloadType = $db->query_result($result, $i, 'filelocationtype');
                 if ($downloadType == 'E' || $downloadType != 'I') {
                     $value = '--';
                 }
             } elseif ($field->getUIType() == '27') {
                 if ($value == 'I') {
                     $value = getTranslatedString('LBL_INTERNAL', $module);
                 } elseif ($value == 'E') {
                     $value = getTranslatedString('LBL_EXTERNAL', $module);
                 } else {
                     $value = ' --';
                 }
             } elseif ($field->getFieldDataType() == 'picklist') {
                 //not check for permissions for non admin users for status and activity type field
                 if ($module == 'Calendar' && ($fieldName == 'taskstatus' || $fieldName == 'eventstatus' || $fieldName == 'activitytype')) {
                     $value = Vtiger_Language_Handler::getTranslatedString($value, $module);
                     $value = textlength_check($value);
                 } else {
                     if ($value != '' && !$is_admin && $this->picklistRoleMap[$fieldName] && !in_array($value, $this->picklistValueMap[$fieldName]) && strtolower($value) != '--none--' && strtolower($value) != 'none') {
                         $value = "<font color='red'>" . Vtiger_Language_Handler::getTranslatedString('LBL_NOT_ACCESSIBLE', $module) . "</font>";
                     } else {
                         $value = Vtiger_Language_Handler::getTranslatedString($value, $module);
                         $value = textlength_check($value);
                     }
                 }
             } elseif ($field->getFieldDataType() == 'date' || $field->getFieldDataType() == 'datetime') {
                 if ($value != '' && $value != '0000-00-00') {
                     $fieldDataType = $field->getFieldDataType();
                     if ($module == 'Calendar' && ($fieldName == 'date_start' || $fieldName == 'due_date')) {
                         if ($fieldName == 'date_start') {
                             $timeField = 'time_start';
                         } else {
                             if ($fieldName == 'due_date') {
                                 $timeField = 'time_end';
                             }
                         }
                         $timeFieldValue = $this->db->query_result($result, $i, $timeField);
                         if (!empty($timeFieldValue)) {
                             $value .= ' ' . $timeFieldValue;
                             //TO make sure it takes time value as well
                             $fieldDataType = 'datetime';
                         }
                     }
                     if ($fieldDataType == 'datetime') {
                         $value = Vtiger_Datetime_UIType::getDateTimeValue($value);
                     } else {
                         if ($fieldDataType == 'date') {
                             $date = new DateTimeField($value);
                             $value = $date->getDisplayDate();
                         }
                     }
                 } elseif ($value == '0000-00-00') {
                     $value = '';
                 }
             } elseif ($field->getFieldDataType() == 'time') {
                 if (!empty($value)) {
                     $value = Vtiger_Time_UIType::getTimeValueInAMorPM($value);
                 }
             } elseif ($field->getFieldDataType() == 'currency') {
                 if ($value != '') {
                     if ($field->getUIType() == 72) {
                         if ($fieldName == 'unit_price') {
                             $currencyId = getProductBaseCurrency($recordId, $module);
                             $cursym_convrate = getCurrencySymbolandCRate($currencyId);
                             $currencySymbol = $cursym_convrate['symbol'];
                         } else {
                             $currencyInfo = getInventoryCurrencyInfo($module, $recordId);
                             $currencySymbol = $currencyInfo['currency_symbol'];
                         }
                         $value = CurrencyField::convertToUserFormat($value, null, true);
                         $row['currencySymbol'] = $currencySymbol;
                         //							$value = CurrencyField::appendCurrencySymbol($currencyValue, $currencySymbol);
                     } else {
                         if (!empty($value)) {
                             $value = CurrencyField::convertToUserFormat($value);
                         }
                     }
                 }
             } elseif ($field->getFieldDataType() == 'url') {
                 $matchPattern = "^[\\w]+:\\/\\/^";
                 preg_match($matchPattern, $rawValue, $matches);
                 if (!empty($matches[0])) {
                     $value = '<a class="urlField cursorPointer" href="' . $rawValue . '" target="_blank">' . textlength_check($value) . '</a>';
                 } else {
                     $value = '<a class="urlField cursorPointer" href="http://' . $rawValue . '" target="_blank">' . textlength_check($value) . '</a>';
                 }
             } elseif ($field->getFieldDataType() == 'email') {
                 global $current_user;
                 if ($current_user->internal_mailer == 1) {
                     //check added for email link in user detailview
                     $value = "<a class='emailField' onclick=\"Vtiger_Helper_Js.getInternalMailer({$recordId}," . "'{$fieldName}');\">" . textlength_check($value) . "</a>";
                 } else {
                     $value = '<a class="emailField" href="mailto:' . $rawValue . '">' . textlength_check($value) . '</a>';
                 }
             } elseif ($field->getFieldDataType() == 'boolean') {
                 if ($value === 'on') {
                     $value = 1;
                 } else {
                     if ($value == 'off') {
                         $value = 0;
                     }
                 }
                 if ($value == 1) {
                     $value = getTranslatedString('yes', $module);
                 } elseif ($value == 0) {
                     $value = getTranslatedString('no', $module);
                 } else {
                     $value = '--';
                 }
             } elseif ($field->getUIType() == 98) {
                 $value = '<a href="index.php?module=Roles&parent=Settings&view=Edit&record=' . $value . '">' . textlength_check(getRoleName($value)) . '</a>';
             } elseif ($field->getFieldDataType() == 'multipicklist') {
                 $value = $value != "" ? str_replace(' |##| ', ', ', $value) : "";
                 if (!$is_admin && $value != '') {
                     $valueArray = $rawValue != "" ? explode(' |##| ', $rawValue) : array();
                     $notaccess = '<font color="red">' . getTranslatedString('LBL_NOT_ACCESSIBLE', $module) . "</font>";
                     $tmp = '';
                     $tmpArray = array();
                     foreach ($valueArray as $index => $val) {
                         if (!$listview_max_textlength || !(strlen(preg_replace("/(<\\/?)(\\w+)([^>]*>)/i", "", $tmp)) > $listview_max_textlength)) {
                             if (!$is_admin && $this->picklistRoleMap[$fieldName] && !in_array(trim($val), $this->picklistValueMap[$fieldName])) {
                                 $tmpArray[] = $notaccess;
                                 $tmp .= ', ' . $notaccess;
                             } else {
                                 $tmpArray[] = $val;
                                 $tmp .= ', ' . $val;
                             }
                         } else {
                             $tmpArray[] = '...';
                             $tmp .= '...';
                         }
                     }
                     $value = implode(', ', $tmpArray);
                     $value = textlength_check($value);
                 }
             } elseif ($field->getFieldDataType() == 'skype') {
                 $value = $value != "" ? "<a href='skype:{$value}?call'>" . textlength_check($value) . "</a>" : "";
             } elseif ($field->getFieldDataType() == 'phone') {
                 if ($useAsterisk == 'true') {
                     $value = "<a href='javascript:;' onclick='startCall(&quot;{$value}&quot;, " . "&quot;{$recordId}&quot;)'>" . textlength_check($value) . "</a>";
                 } else {
                     $value = textlength_check($value);
                 }
             } elseif ($field->getFieldDataType() == 'reference') {
                 $referenceFieldInfoList = $this->queryGenerator->getReferenceFieldInfoList();
                 $moduleList = $referenceFieldInfoList[$fieldName];
                 if (count($moduleList) == 1) {
                     $parentModule = $moduleList[0];
                 } else {
                     $parentModule = $this->typeList[$value];
                 }
                 if (!empty($value) && !empty($this->nameList[$fieldName]) && !empty($parentModule)) {
                     $parentMeta = $this->queryGenerator->getMeta($parentModule);
                     $value = textlength_check($this->nameList[$fieldName][$value]);
                     if ($parentMeta->isModuleEntity() && $parentModule != "Users") {
                         $value = "<a href='?module={$parentModule}&view=Detail&" . "record={$rawValue}' title='" . getTranslatedString($parentModule, $parentModule) . "'>{$value}</a>";
                     }
                 } else {
                     $value = '--';
                 }
             } elseif ($field->getFieldDataType() == 'owner') {
                 $value = textlength_check($this->ownerNameList[$fieldName][$value]);
             } elseif ($field->getUIType() == 25) {
                 //TODO clean request object reference.
                 $contactId = $_REQUEST['record'];
                 $emailId = $this->db->query_result($result, $i, "activityid");
                 $result1 = $this->db->pquery("SELECT access_count FROM vtiger_email_track WHERE " . "crmid=? AND mailid=?", array($contactId, $emailId));
                 $value = $this->db->query_result($result1, 0, "access_count");
                 if (!$value) {
                     $value = 0;
                 }
             } elseif ($field->getUIType() == 8) {
                 if (!empty($value)) {
                     $temp_val = html_entity_decode($value, ENT_QUOTES, $default_charset);
                     $json = new Zend_Json();
                     $value = vt_suppressHTMLTags(implode(',', $json->decode($temp_val)));
                 }
             } elseif (in_array($uitype, array(7, 9, 90))) {
                 $value = "<span align='right'>" . textlength_check($value) . "</div>";
             } else {
                 $value = textlength_check($value);
             }
             //				// vtlib customization: For listview javascript triggers
             //				$value = "$value <span type='vtlib_metainfo' vtrecordid='{$recordId}' vtfieldname=".
             //					"'{$fieldName}' vtmodule='$module' style='display:none;'></span>";
             //				// END
             $row[$fieldName] = $value;
         }
         $data[$recordId] = $row;
     }
     return $data;
 }
Beispiel #7
0
    function getListViewEntries($focus, $module, $result, $navigationInfo, $skipActions = false)
    {
        require 'user_privileges/user_privileges_' . $this->user->id . '.php';
        global $listview_max_textlength, $theme, $default_charset, $current_user, $currentModule, $adb;
        $fields = $this->queryGenerator->getFields();
        $whereFields = $this->queryGenerator->getWhereFields();
        $meta = $this->queryGenerator->getMeta($this->queryGenerator->getModule());
        $moduleFields = $meta->getModuleFields();
        $accessibleFieldList = array_keys($moduleFields);
        if ($this->queryGenerator->getReferenceFieldInfoList()) {
            $accessibleFieldList = array_merge($this->queryGenerator->getReferenceFieldNameList(), $accessibleFieldList);
        }
        $listViewFields = array_intersect($fields, $accessibleFieldList);
        $referenceFieldList = $this->queryGenerator->getReferenceFieldList();
        foreach ($referenceFieldList as $fieldName) {
            if (in_array($fieldName, $listViewFields)) {
                $field = $moduleFields[$fieldName];
                $this->fetchNameList($field, $result);
            }
        }
        $db = PearDatabase::getInstance();
        $rowCount = $db->num_rows($result);
        $listviewcolumns = $db->getFieldsArray($result);
        $ownerFieldList = $this->queryGenerator->getOwnerFieldList();
        foreach ($ownerFieldList as $fieldName) {
            if (in_array($fieldName, $listViewFields)) {
                if (!empty($moduleFields[$fieldName])) {
                    $field = $moduleFields[$fieldName];
                } else {
                    $field = $this->queryGenerator->getReferenceField($fieldName, false);
                    if (is_null($field)) {
                        continue;
                    }
                }
                $fldcolname = $field->getColumnName();
                $idList = array();
                for ($i = 0; $i < $rowCount; $i++) {
                    $id = $this->db->query_result($result, $i, $fldcolname);
                    if (!isset($this->ownerNameList[$fieldName][$id])) {
                        $idList[] = $id;
                    }
                }
                if (count($idList) > 0) {
                    if (!isset($this->ownerNameList[$fieldName]) or !is_array($this->ownerNameList[$fieldName])) {
                        $this->ownerNameList[$fieldName] = getOwnerNameList($idList);
                    } else {
                        $newOwnerList = getOwnerNameList($idList);
                        $this->ownerNameList[$fieldName] = $this->ownerNameList[$fieldName] + $newOwnerList;
                    }
                }
            }
        }
        foreach ($listViewFields as $fieldName) {
            if (!empty($moduleFields[$fieldName])) {
                $field = $moduleFields[$fieldName];
            } else {
                $field = $this->queryGenerator->getReferenceField($fieldName, false);
                if (is_null($field)) {
                    continue;
                }
            }
            if (!$is_admin && ($field->getFieldDataType() == 'picklist' || $field->getFieldDataType() == 'multipicklist')) {
                $this->setupAccessiblePicklistValueList($fieldName);
            }
            $idList = array();
            if ($fieldName != 'assigned_user_id' && strstr($fieldName, ".assigned_user_id")) {
                $modrel = getTabModuleName($field->getTabId());
                $fldcolname = 'smowner' . strtolower($modrel);
                $j = $rowCount * $k;
                $k++;
                for ($i = 0; $i < $rowCount; $i++) {
                    $id = $this->db->query_result($result, $i, $fldcolname);
                    if (!isset($this->ownerNameListrel[$fieldName][$id])) {
                        $idList[$j] = $id;
                        $j++;
                    }
                }
            } else {
                if (getTabid($currentModule) != $field->getTabId() && $field->getFieldDataType() == 'reference') {
                    $this->fetchNameList($field, $result, 1);
                }
            }
            if (count($idList) > 0) {
                if (!isset($this->ownerNameListrel[$fieldName]) or !is_array($this->ownerNameListrel[$fieldName])) {
                    $this->ownerNameListrel[$fieldName] = getOwnerNameList($idList);
                } else {
                    $newOwnerList = getOwnerNameList($idList);
                    $this->ownerNameListrel[$fieldName] = $this->ownerNameListrel[$fieldName] + $newOwnerList;
                }
            }
        }
        $useAsterisk = get_use_asterisk($this->user->id);
        $wfs = new VTWorkflowManager($adb);
        $data = array();
        for ($i = 0; $i < $rowCount; ++$i) {
            //Getting the recordId
            if ($module != 'Users') {
                $baseTable = $meta->getEntityBaseTable();
                $moduleTableIndexList = $meta->getEntityTableIndexList();
                $baseTableIndex = $moduleTableIndexList[$baseTable];
                $recordId = $db->query_result($result, $i, $baseTableIndex);
                $ownerId = $db->query_result($result, $i, "smownerid");
            } else {
                $recordId = $db->query_result($result, $i, "id");
            }
            $row = array();
            foreach ($listViewFields as $fieldName) {
                if (!empty($moduleFields[$fieldName])) {
                    $field = $moduleFields[$fieldName];
                } else {
                    $field = $this->queryGenerator->getReferenceField($fieldName, false);
                    if (is_null($field)) {
                        continue;
                    }
                }
                $uitype = $field->getUIType();
                if ($fieldName != 'assigned_user_id' && strstr($fieldName, ".assigned_user_id")) {
                    $modrel = getTabModuleName($field->getTabId());
                    $rawValue = $this->db->query_result($result, $i, "smowner" . strtolower($modrel));
                } else {
                    if (getTabid($currentModule) != $field->getTabId()) {
                        $modrel = getTabModuleName($field->getTabId());
                        $relfieldname = strtolower($modrel) . $field->getColumnName();
                        if (in_array($relfieldname, $listviewcolumns)) {
                            $rawValue = $this->db->query_result($result, $i, $relfieldname);
                        } else {
                            $rawValue = $this->db->query_result($result, $i, $field->getColumnName());
                        }
                    } else {
                        $rawValue = $this->db->query_result($result, $i, $field->getColumnName());
                    }
                }
                if ($module == 'Calendar') {
                    $activityType = $this->db->query_result($result, $i, 'activitytype');
                }
                if ($uitype != 8) {
                    $value = html_entity_decode($rawValue, ENT_QUOTES, $default_charset);
                } else {
                    $value = $rawValue;
                }
                if ($module == 'Documents' && $fieldName == 'filename' or $fieldName == 'Documents.filename') {
                    if ($fieldName == 'Documents.filename') {
                        $docrs = $db->pquery('select filename,filelocationtype,filestatus,notesid from vtiger_notes where note_no=?', array($db->query_result($result, $i, 'documentsnote_no')));
                        $downloadtype = $db->query_result($docrs, 0, 'filelocationtype');
                        $fileName = $db->query_result($docrs, 0, 'filename');
                        $status = $db->query_result($docrs, 0, 'filestatus');
                        $docid = $db->query_result($docrs, 0, 'notesid');
                    } else {
                        $docid = $recordId;
                        $downloadtype = $db->query_result($result, $i, 'filelocationtype');
                        $fileName = $db->query_result($result, $i, 'filename');
                        $status = $db->query_result($result, $i, 'filestatus');
                    }
                    $fileIdQuery = "select attachmentsid from vtiger_seattachmentsrel where crmid=?";
                    $fileIdRes = $db->pquery($fileIdQuery, array($docid));
                    $fileId = $db->query_result($fileIdRes, 0, 'attachmentsid');
                    if ($downloadtype == 'I') {
                        $ext = substr($value, strrpos($value, ".") + 1);
                        $ext = strtolower($ext);
                        if ($value != '') {
                            if ($ext == 'bin' || $ext == 'exe' || $ext == 'rpm') {
                                $fileicon = "<img src='" . vtiger_imageurl('fExeBin.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                            } elseif ($ext == 'jpg' || $ext == 'gif' || $ext == 'bmp') {
                                $fileicon = "<img src='" . vtiger_imageurl('fbImageFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                            } elseif ($ext == 'txt' || $ext == 'doc' || $ext == 'xls') {
                                $fileicon = "<img src='" . vtiger_imageurl('fbTextFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                            } elseif ($ext == 'zip' || $ext == 'gz' || $ext == 'rar') {
                                $fileicon = "<img src='" . vtiger_imageurl('fbZipFile.gif', $theme) . "' hspace='3' align='absmiddle'\tborder='0'>";
                            } else {
                                $fileicon = "<img src='" . vtiger_imageurl('fbUnknownFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                            }
                        }
                    } elseif ($downloadtype == 'E') {
                        if (trim($value) != '') {
                            $fileicon = "<img src='" . vtiger_imageurl('fbLink.gif', $theme) . "' alt='" . getTranslatedString('LBL_EXTERNAL_LNK', $module) . "' title='" . getTranslatedString('LBL_EXTERNAL_LNK', $module) . "' hspace='3' align='absmiddle' border='0'>";
                        } else {
                            $value = '--';
                            $fileicon = '';
                        }
                    } else {
                        $value = ' --';
                        $fileicon = '';
                    }
                    if ($fileName != '' && $status == 1) {
                        if ($downloadtype == 'I') {
                            $value = "<a href='index.php?module=uploads&action=downloadfile&" . "entityid={$docid}&fileid={$fileId}' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "' onclick='javascript:dldCntIncrease({$docid});'>" . textlength_check($value) . "</a>";
                        } elseif ($downloadtype == 'E') {
                            $value = "<a target='_blank' href='{$fileName}' onclick='javascript:" . "dldCntIncrease({$docid});' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "'>" . textlength_check($value) . "</a>";
                        } else {
                            $value = ' --';
                        }
                    }
                    $value = $fileicon . $value;
                } elseif ($module == 'Documents' && $fieldName == 'filesize') {
                    $downloadType = $db->query_result($result, $i, 'filelocationtype');
                    if ($downloadType == 'I') {
                        $filesize = $value;
                        if ($filesize < 1024) {
                            $value = $filesize . ' B';
                        } elseif ($filesize > 1024 && $filesize < 1048576) {
                            $value = round($filesize / 1024, 2) . ' KB';
                        } else {
                            if ($filesize > 1048576) {
                                $value = round($filesize / (1024 * 1024), 2) . ' MB';
                            }
                        }
                    } else {
                        $value = ' --';
                    }
                } elseif ($module == 'Documents' && $fieldName == 'filestatus') {
                    if ($value == 1) {
                        $value = getTranslatedString('yes', $module);
                    } elseif ($value == 0) {
                        $value = getTranslatedString('no', $module);
                    } else {
                        $value = '--';
                    }
                } elseif ($module == 'Documents' && $fieldName == 'filetype') {
                    $downloadType = $db->query_result($result, $i, 'filelocationtype');
                    if ($downloadType == 'E' || $downloadType != 'I') {
                        $value = '--';
                    }
                } elseif ($field->getUIType() == '27') {
                    if ($value == 'I') {
                        $value = getTranslatedString('LBL_INTERNAL', $module);
                    } elseif ($value == 'E') {
                        $value = getTranslatedString('LBL_EXTERNAL', $module);
                    } else {
                        $value = ' --';
                    }
                } elseif ($field->getFieldDataType() == 'picklist') {
                    if ($value != '' && !$is_admin && $this->picklistRoleMap[$fieldName] && !in_array($value, $this->picklistValueMap[$fieldName])) {
                        $value = "<font color='red'>" . getTranslatedString('LBL_NOT_ACCESSIBLE', $module) . "</font>";
                    } else {
                        $value = getTranslatedString($value, $module);
                        $value = textlength_check($value);
                    }
                } elseif ($field->getFieldDataType() == 'date' || $field->getFieldDataType() == 'datetime') {
                    if ($value != '' && $value != '0000-00-00') {
                        $date = new DateTimeField($value);
                        $value = $date->getDisplayDate();
                        if ($field->getFieldDataType() == 'datetime') {
                            $value .= ' ' . $date->getDisplayTime();
                        }
                    } elseif ($value == '0000-00-00') {
                        $value = '';
                    }
                } elseif ($field->getFieldDataType() == 'currency') {
                    if ($value != '') {
                        if ($field->getUIType() == 72) {
                            if ($fieldName == 'unit_price') {
                                $currencyId = getProductBaseCurrency($recordId, $module);
                                $cursym_convrate = getCurrencySymbolandCRate($currencyId);
                                $currencySymbol = $cursym_convrate['symbol'];
                            } else {
                                $currencyInfo = getInventoryCurrencyInfo($module, $recordId);
                                $currencySymbol = $currencyInfo['currency_symbol'];
                            }
                            $value = number_format($value, 2, '.', '');
                            $currencyValue = CurrencyField::convertToUserFormat($value, null, true);
                            $value = CurrencyField::appendCurrencySymbol($currencyValue, $currencySymbol);
                        } else {
                            //changes made to remove vtiger_currency symbol in front of each potential amount
                            if ($value != 0) {
                                $value = CurrencyField::convertToUserFormat($value);
                            }
                        }
                    }
                } elseif ($field->getFieldDataType() == 'url') {
                    $matchPattern = "^[\\w]+:\\/\\/^";
                    preg_match($matchPattern, $rawValue, $matches);
                    if (!empty($matches[0])) {
                        $value = '<a href="' . $rawValue . '" target="_blank">' . textlength_check($value) . '</a>';
                    } else {
                        $value = '<a href="http://' . $rawValue . '" target="_blank">' . textlength_check($value) . '</a>';
                    }
                } elseif ($field->getFieldDataType() == 'email') {
                    if ($_SESSION['internal_mailer'] == 1) {
                        //check added for email link in user detailview
                        $fieldId = $field->getFieldId();
                        $value = "<a href=\"javascript:InternalMailer({$recordId},{$fieldId}," . "'{$fieldName}','{$module}','record_id');\">" . textlength_check($value) . "</a>";
                    } else {
                        $value = '<a href="mailto:' . $rawValue . '">' . textlength_check($value) . '</a>';
                    }
                } elseif ($field->getFieldDataType() == 'boolean') {
                    if ($value == 1) {
                        $value = getTranslatedString('yes', $module);
                    } elseif ($value == 0) {
                        $value = getTranslatedString('no', $module);
                    } else {
                        $value = '--';
                    }
                } elseif ($field->getUIType() == 98) {
                    $value = '<a href="index.php?action=RoleDetailView&module=Settings&parenttab=' . 'Settings&roleid=' . $value . '">' . textlength_check(getRoleName($value)) . '</a>';
                } elseif ($field->getUIType() == 69) {
                    if ($module == 'Products') {
                        $queryPrdt = 'SELECT vtiger_attachments.path,vtiger_attachments.attachmentsid,vtiger_attachments.`name`
							FROM vtiger_attachments
							INNER JOIN vtiger_seattachmentsrel ON vtiger_attachments.attachmentsid = vtiger_seattachmentsrel.attachmentsid
							INNER JOIN vtiger_products ON vtiger_seattachmentsrel.crmid = vtiger_products.productid
							where vtiger_seattachmentsrel.crmid=?';
                        $resultprdt = $this->db->pquery($queryPrdt, array($recordId));
                        if ($resultprdt and $this->db->num_rows($resultprdt) > 0) {
                            $imgpath = $this->db->query_result($resultprdt, 0, 'path');
                            $attid = $this->db->query_result($resultprdt, 0, 'attachmentsid');
                            $imgfilename = $this->db->query_result($resultprdt, 0, 'name');
                            $value = "<div style='text-align:center;width:100%;'><img src='./" . $imgpath . $attid . '_' . $imgfilename . "' height='50'></div>";
                        } else {
                            $value = '';
                        }
                    } else {
                        if ($module == 'Contacts') {
                            $imageattachment = 'Image';
                        } else {
                            $imageattachment = 'Attachment';
                        }
                        //$imgpath = getModuleFileStoragePath('Contacts').$col_fields[$fieldname];
                        $sql = "select vtiger_attachments.*,vtiger_crmentity.setype\n\t\t\t\t\t\t from vtiger_attachments\n\t\t\t\t\t\t inner join vtiger_seattachmentsrel on vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid\n\t\t\t\t\t\t inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_attachments.attachmentsid\n\t\t\t\t\t\t where vtiger_crmentity.setype='{$module} {$imageattachment}'\n\t\t\t\t\t\t  and vtiger_attachments.name = ?\n\t\t\t\t\t\t  and vtiger_seattachmentsrel.crmid=?";
                        $image_res = $this->db->pquery($sql, array(str_replace(' ', '_', $value), $recordId));
                        $image_id = $this->db->query_result($image_res, 0, 'attachmentsid');
                        $image_path = $this->db->query_result($image_res, 0, 'path');
                        $image_name = urlencode(decode_html($this->db->query_result($image_res, 0, 'name')));
                        $imgpath = $image_path . $image_id . "_" . $image_name;
                        if ($image_name != '') {
                            $ftype = $this->db->query_result($image_res, 0, 'type');
                            $isimage = stripos($ftype, 'image') !== false;
                            if ($isimage) {
                                $imgtxt = getTranslatedString('SINGLE_' . $module, $module) . ' ' . getTranslatedString('Image');
                                $value = '<div style="width:100%;text-align:center;"><img src="' . $imgpath . '" alt="' . $imgtxt . '" title= "' . $imgtxt . '" style="max-width: 50px;"></div>';
                            } else {
                                $imgtxt = getTranslatedString('SINGLE_' . $module, $module) . ' ' . getTranslatedString('SINGLE_Documents');
                                $value = '<a href="' . $imgpath . '" alt="' . $imgtxt . '" title= "' . $imgtxt . '">' . $image_name . '</a>';
                            }
                        } else {
                            $value = '';
                        }
                    }
                } elseif ($field->getFieldDataType() == 'multipicklist') {
                    $value = $value != "" ? str_replace(' |##| ', ', ', $value) : "";
                    if (!$is_admin && $value != '') {
                        $valueArray = $rawValue != "" ? explode(' |##| ', $rawValue) : array();
                        $notaccess = '<font color="red">' . getTranslatedString('LBL_NOT_ACCESSIBLE', $module) . "</font>";
                        $tmp = '';
                        $tmpArray = array();
                        foreach ($valueArray as $index => $val) {
                            if (!$listview_max_textlength || !(strlen(preg_replace("/(<\\/?)(\\w+)([^>]*>)/i", "", $tmp)) > $listview_max_textlength)) {
                                if (!$is_admin && $this->picklistRoleMap[$fieldName] && !in_array(trim(decode_html($val)), $this->picklistValueMap[$fieldName])) {
                                    $tmpArray[] = $notaccess;
                                    $tmp .= ', ' . $notaccess;
                                } else {
                                    $tmpArray[] = $val;
                                    $tmp .= ', ' . $val;
                                }
                            } else {
                                $tmpArray[] = '...';
                                $tmp .= '...';
                            }
                        }
                        $value = implode(', ', $tmpArray);
                        $value = textlength_check($value);
                    }
                } elseif ($field->getUIType() == 1024) {
                    $content = array();
                    if ($value != '') {
                        $arr_evo_actions = explode(' |##| ', $value);
                        for ($fvalues = 0; $fvalues < sizeof($arr_evo_actions); $fvalues++) {
                            $roleid = $arr_evo_actions[$fvalues];
                            $rolename = getRoleName($roleid);
                            $content[$fvalues] = $rolename;
                        }
                    }
                    $value = textlength_check(implode(', ', $content));
                } elseif ($field->getFieldDataType() == 'skype') {
                    $value = $value != "" ? "<a href='skype:{$value}?call'>" . textlength_check($value) . "</a>" : "";
                } elseif ($field->getFieldDataType() == 'phone') {
                    if ($useAsterisk == 'true') {
                        $value = "<a href='javascript:;' onclick='startCall(&quot;{$value}&quot;, " . "&quot;{$recordId}&quot;)'>" . textlength_check($value) . "</a>";
                    } else {
                        $value = textlength_check($value);
                    }
                } elseif ($field->getFieldDataType() == 'reference') {
                    $referenceFieldInfoList = $this->queryGenerator->getReferenceFieldInfoList();
                    if (getTabid($currentModule) != $field->getTabId()) {
                        $modrel = getTabModuleName($field->getTabId());
                        $fieldName = str_replace($modrel . '.', "", $fieldName);
                    }
                    $moduleList = $referenceFieldInfoList[$fieldName];
                    if (count($moduleList) == 1) {
                        $parentModule = $moduleList[0];
                    } else {
                        $parentModule = $this->typeList[$value];
                    }
                    if (!empty($value) && !empty($this->nameList[$fieldName]) && !empty($parentModule)) {
                        $parentMeta = $this->queryGenerator->getMeta($parentModule);
                        $value = textlength_check($this->nameList[$fieldName][$value]);
                        if ($parentMeta->isModuleEntity() && $parentModule != "Users") {
                            $value = "<a href='index.php?module={$parentModule}&action=DetailView&" . "record={$rawValue}' title='" . getTranslatedString($parentModule, $parentModule) . "'>{$value}</a>";
                            $modMetaInfo = getEntityFieldNames($parentModule);
                            $fieldName = is_array($modMetaInfo['fieldname']) ? $modMetaInfo['fieldname'][0] : $modMetaInfo['fieldname'];
                            // vtlib customization: For listview javascript triggers
                            $value = "{$value} <span type='vtlib_metainfo' vtrecordid='{$rawValue}' vtfieldname=" . "'{$fieldName}' vtmodule='{$parentModule}' style='display:none;'></span>";
                        }
                    } else {
                        $value = '--';
                    }
                } elseif ($field->getFieldDataType() == 'owner') {
                    if ($fieldName != 'assigned_user_id' && strstr($fieldName, ".assigned_user_id")) {
                        $value = textlength_check($this->ownerNameListrel[$fieldName][$value]);
                    } else {
                        $value = textlength_check($this->ownerNameList[$fieldName][$value]);
                    }
                } elseif ($field->getUIType() == 25) {
                    //TODO clean request object reference.
                    $contactId = $_REQUEST['record'];
                    $emailId = $this->db->query_result($result, $i, "activityid");
                    $result1 = $this->db->pquery("SELECT access_count FROM vtiger_email_track WHERE " . "crmid=? AND mailid=?", array($contactId, $emailId));
                    $value = $this->db->query_result($result1, 0, "access_count");
                    if (!$value) {
                        $value = 0;
                    }
                } elseif ($field->getUIType() == 8) {
                    if (!empty($value)) {
                        $temp_val = html_entity_decode($value, ENT_QUOTES, $default_charset);
                        $json = new Zend_Json();
                        $value = vt_suppressHTMLTags(implode(',', $json->decode($temp_val)));
                    }
                } elseif (in_array($uitype, array(7, 9, 90))) {
                    $value = "<span align='right'>" . textlength_check($value) . "</div>";
                } elseif ($field->getUIType() == 55) {
                    $value = getTranslatedString($value, $currentModule);
                } elseif ($module == 'Emails' && $fieldName == 'subject') {
                    $value = '<a href="javascript:;" onClick="ShowEmail(\'' . $recordId . '\');">' . textlength_check($value) . '</a>';
                } else {
                    $value = textlength_check($value);
                }
                if ($field->getFieldDataType() != 'reference') {
                    $parenttab = getParentTab();
                    $nameFields = $this->queryGenerator->getModuleNameFields($module);
                    $nameFieldList = explode(',', $nameFields);
                    if (($fieldName == $focus->list_link_field or in_array($fieldName, $nameFieldList)) && $module != 'Emails') {
                        $opennewtab = GlobalVariable::getVariable('Application_OpenRecordInNewXOnListView', '', $module);
                        if ($opennewtab == '') {
                            $value = "<a href='index.php?module={$module}&parenttab={$parenttab}&action=DetailView&record=" . "{$recordId}' title='" . getTranslatedString($module, $module) . "'>{$value}</a>";
                        } elseif ($opennewtab == 'window') {
                            $value = "<a href='#' onclick='window.open(\"index.php?module={$module}&parenttab={$parenttab}&action=DetailView&record=" . "{$recordId}\", \"{$module}-{$entity_id}\", \"width=1300, height=900, scrollbars=yes\"); return false;' title='" . getTranslatedString($module, $module) . "'>{$value}</a>";
                        } else {
                            $value = "<a href='index.php?module={$module}&parenttab={$parenttab}&action=DetailView&record=" . "{$recordId}' title='" . getTranslatedString($module, $module) . "' target='_blank'>{$value}</a>";
                        }
                    }
                    // vtlib customization: For listview javascript triggers
                    $value = "{$value} <span type='vtlib_metainfo' vtrecordid='{$recordId}' vtfieldname=" . "'{$fieldName}' vtmodule='{$module}' style='display:none;'></span>";
                }
                $row[] = $value;
            }
            //Added for Actions ie., edit and delete links in listview
            $actionLinkInfo = "";
            if (isPermitted($module, "EditView", "") == 'yes') {
                $racbr = $wfs->getRACRuleForRecord($currentModule, $recordId);
                if (!$racbr or $racbr->hasListViewPermissionTo('edit')) {
                    $edit_link = $this->getListViewEditLink($module, $recordId);
                    if (isset($navigationInfo['start']) && $navigationInfo['start'] > 1 && $module != 'Emails') {
                        $actionLinkInfo .= "<a href=\"{$edit_link}&start=" . $navigationInfo['start'] . "\">" . getTranslatedString("LNK_EDIT", $module) . "</a> ";
                    } else {
                        $actionLinkInfo .= "<a href=\"{$edit_link}\">" . getTranslatedString("LNK_EDIT", $module) . "</a> ";
                    }
                }
            }
            if (isPermitted($module, "Delete", "") == 'yes') {
                $racbr = $wfs->getRACRuleForRecord($currentModule, $recordId);
                if (!$racbr or $racbr->hasListViewPermissionTo('delete')) {
                    $del_link = $this->getListViewDeleteLink($module, $recordId);
                    if ($actionLinkInfo != "" && $del_link != "") {
                        $actionLinkInfo .= ' | ';
                    }
                    if ($del_link != "") {
                        $actionLinkInfo .= "<a href='javascript:confirmdelete(\"" . addslashes(urlencode($del_link)) . "\")'>" . getTranslatedString('LNK_DELETE', $module) . '</a>';
                    }
                }
            }
            // Record Change Notification
            if (method_exists($focus, 'isViewed') && PerformancePrefs::getBoolean('LISTVIEW_RECORD_CHANGE_INDICATOR', true)) {
                if (!$focus->isViewed($recordId)) {
                    $actionLinkInfo .= " | <img src='" . vtiger_imageurl('important1.gif', $theme) . "' border=0>";
                }
            }
            // END
            if ($actionLinkInfo != "" && !$skipActions) {
                $row[] = $actionLinkInfo;
            }
            list($row, $unused, $unused2) = cbEventHandler::do_filter('corebos.filter.listview.render', array($row, $this->db->query_result_rowdata($result, $i), $recordId));
            $data[$recordId] = $row;
        }
        return $data;
    }