Exemplo n.º 1
0
function getTopPotentials($maxval, $calCnt)
{
    $log = LoggerManager::getLogger('top opportunity_list');
    $log->debug("Entering getTopPotentials() method ...");
    require_once "data/Tracker.php";
    require_once 'modules/Potentials/Potentials.php';
    require_once 'include/logging.php';
    require_once 'include/ListView/ListView.php';
    global $app_strings;
    global $adb;
    global $current_language;
    global $current_user;
    $current_module_strings = return_module_language($current_language, "Potentials");
    $title = array();
    $title[] = 'myTopOpenPotentials.gif';
    $title[] = $current_module_strings['LBL_TOP_OPPORTUNITIES'];
    $title[] = 'home_mypot';
    $where = "AND vtiger_potential.potentialid > 0 AND vtiger_potential.sales_stage not in ('Closed Won','Closed Lost','" . $current_module_strings['Closed Won'] . "','" . $current_module_strings['Closed Lost'] . "') AND vtiger_crmentity.smownerid='" . $current_user->id . "' AND vtiger_potential.amount > 0";
    $header = array();
    $header[] = $current_module_strings['LBL_LIST_OPPORTUNITY_NAME'];
    //$header[]=$current_module_strings['LBL_LIST_ACCOUNT_NAME'];
    $currencyid = fetchCurrency($current_user->id);
    $rate_symbol = getCurrencySymbolandCRate($currencyid);
    $rate = $rate_symbol['rate'];
    $curr_symbol = $rate_symbol['symbol'];
    $header[] = $current_module_strings['LBL_LIST_AMOUNT'] . '(' . $curr_symbol . ')';
    $list_query = "SELECT vtiger_crmentity.crmid, vtiger_potential.potentialname,\n\t\t\tvtiger_potential.amount, potentialid\n\t\t\tFROM vtiger_potential\n\t\t\tIGNORE INDEX(PRIMARY) INNER JOIN vtiger_crmentity\n\t\t\t\tON vtiger_crmentity.crmid = vtiger_potential.potentialid";
    $list_query .= getNonAdminAccessControlQuery('Potentials', $current_user);
    $list_query .= "WHERE vtiger_crmentity.deleted = 0 " . $where;
    $list_query .= " ORDER BY amount DESC";
    $list_query .= " LIMIT " . $adb->sql_escape_string($maxval);
    if ($calCnt == 'calculateCnt') {
        $list_result_rows = $adb->query(mkCountQuery($list_query));
        return $adb->query_result($list_result_rows, 0, 'count');
    }
    $list_result = $adb->query($list_query);
    $open_potentials_list = array();
    $noofrows = $adb->num_rows($list_result);
    $entries = array();
    if ($noofrows) {
        for ($i = 0; $i < $noofrows; $i++) {
            $open_potentials_list[] = array('name' => $adb->query_result($list_result, $i, 'potentialname'), 'id' => $adb->query_result($list_result, $i, 'potentialid'), 'amount' => $adb->query_result($list_result, $i, 'amount'));
            $potentialid = $adb->query_result($list_result, $i, 'potentialid');
            $potentialname = $adb->query_result($list_result, $i, 'potentialname');
            $Top_Potential = strlen($potentialname) > 20 ? substr($potentialname, 0, 20) . '...' : $potentialname;
            $value = array();
            $value[] = '<a href="index.php?action=DetailView&module=Potentials&record=' . $potentialid . '">' . $Top_Potential . '</a>';
            $value[] = CurrencyField::convertToUserFormat($adb->query_result($list_result, $i, 'amount'));
            $entries[$potentialid] = $value;
        }
    }
    $advft_criteria_groups = array('1' => array('groupcondition' => null));
    $advft_criteria = array(array('groupid' => 1, 'columnname' => 'vtiger_potential:sales_stage:sales_stage:Potentials_Sales_Stage:V', 'comparator' => 'k', 'value' => 'closed', 'columncondition' => 'and'), array('groupid' => 1, 'columnname' => 'vtiger_potential:amount:amount:Potentials_Amount:N', 'comparator' => 'g', 'value' => '0', 'columncondition' => 'and'), array('groupid' => 1, 'columnname' => 'vtiger_crmentity:smownerid:assigned_user_id:Leads_Assigned_To:V', 'comparator' => 'e', 'value' => getFullNameFromArray('Users', $current_user->column_fields), 'columncondition' => null));
    $search_qry = '&advft_criteria=' . Zend_Json::encode($advft_criteria) . '&advft_criteria_groups=' . Zend_Json::encode($advft_criteria_groups) . '&searchtype=advance&query=true';
    $values = array('ModuleName' => 'Potentials', 'Title' => $title, 'Header' => $header, 'Entries' => $entries, 'search_qry' => $search_qry);
    if (count($open_potentials_list) == 0 || count($open_potentials_list) > 0) {
        $log->debug("Exiting getTopPotentials method ...");
        return $values;
    }
}
Exemplo n.º 2
0
 public function getCreateViewUrl()
 {
     $createViewUrl = parent::getCreateViewUrl();
     $currentUserModel = Users_Record_Model::getCurrentUserModel();
     $parentRecordModel = $this->getParentRecordModel();
     $currencyValue = $parentRecordModel->get('hdnGrandTotal');
     $parentRecordModelCurrencyId = $parentRecordModel->get('currency_id');
     if ($parentRecordModelCurrencyId == $currentUserModel->get('currency_id')) {
         $amount = CurrencyField::convertToUserFormat($currencyValue, null, true);
     } else {
         $baseCurrencyId = CurrencyField::getDBCurrencyId();
         $allCurrencies = getAllCurrencies();
         foreach ($allCurrencies as $currencyInfo) {
             if ($parentRecordModelCurrencyId == $currencyInfo['currency_id']) {
                 $currencyValue = CurrencyField::convertToDollar($currencyValue, $currencyInfo['conversionrate']);
             }
         }
         foreach ($allCurrencies as $currencyInfo) {
             if ($baseCurrencyId == $currencyInfo['currency_id']) {
                 $currencyValue = CurrencyField::convertFromMasterCurrency($currencyValue, $currencyInfo['conversionrate']);
             }
         }
         $amount = CurrencyField::convertToUserFormat($currencyValue);
     }
     return $createViewUrl . '&relatedcontact=' . $parentRecordModel->get('contact_id') . '&relatedorganization=' . $parentRecordModel->get('account_id') . '&amount=' . $amount;
 }
Exemplo n.º 3
0
function getTopAccounts($maxval, $calCnt)
{
    $log = LoggerManager::getLogger('top accounts_list');
    $log->debug("Entering getTopAccounts() method ...");
    require_once "data/Tracker.php";
    require_once 'modules/Potentials/Potentials.php';
    require_once 'include/logging.php';
    require_once 'include/ListView/ListView.php';
    global $app_strings;
    global $adb;
    global $current_language;
    global $current_user;
    $current_module_strings = return_module_language($current_language, "Accounts");
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    require 'user_privileges/sharing_privileges_' . $current_user->id . '.php';
    $list_query = "select vtiger_potential.potentialname,vtiger_account.accountid, vtiger_account.accountname, " . "vtiger_account.tickersymbol, sum(vtiger_potential.amount) as amount from vtiger_potential " . "inner join vtiger_crmentity on (vtiger_potential.potentialid=vtiger_crmentity.crmid) " . "inner join vtiger_account on (vtiger_potential.related_to=vtiger_account.accountid) ";
    $list_query .= " WHERE vtiger_crmentity.deleted = 0 " . $where . " AND vtiger_potential.potentialid>0";
    $list_query .= " AND vtiger_crmentity.smownerid='" . $current_user->id . "' " . "and vtiger_potential.sales_stage not in ('Closed Won', 'Closed Lost','" . $app_strings['LBL_CLOSE_WON'] . "','" . $app_strings['LBL_CLOSE_LOST'] . "')";
    $list_query .= " group by vtiger_account.accountid, vtiger_account.tickersymbol order by amount desc";
    $list_query .= " LIMIT 0," . $adb->sql_escape_string($maxval);
    if ($calCnt == 'calculateCnt') {
        $list_result_rows = $adb->query(mkCountQuery($list_query));
        return $adb->query_result($list_result_rows, 0, 'count');
    }
    $list_result = $adb->query($list_query);
    $open_accounts_list = array();
    $noofrows = $adb->num_rows($list_result);
    if ($noofrows) {
        for ($i = 0; $i < $noofrows; $i++) {
            $open_accounts_list[] = array('accountid' => $adb->query_result($list_result, $i, 'accountid'), 'accountname' => $adb->query_result($list_result, $i, 'accountname'), 'amount' => $adb->query_result($list_result, $i, 'amount'), 'tickersymbol' => $adb->query_result($list_result, $i, 'tickersymbol'));
        }
    }
    $title = array();
    $title[] = 'myTopAccounts.gif';
    $title[] = $current_module_strings['LBL_TOP_ACCOUNTS'];
    $title[] = 'home_myaccount';
    $header = array();
    $header[] = $current_module_strings['LBL_LIST_ACCOUNT_NAME'];
    $currencyid = fetchCurrency($current_user->id);
    $rate_symbol = getCurrencySymbolandCRate($currencyid);
    $rate = $rate_symbol['rate'];
    $curr_symbol = $rate_symbol['symbol'];
    $header[] = $current_module_strings['LBL_LIST_AMOUNT'] . '(' . $curr_symbol . ')';
    $header[] = $current_module_strings['LBL_POTENTIAL_TITLE'];
    $entries = array();
    foreach ($open_accounts_list as $account) {
        $value = array();
        $account_fields = array('ACCOUNT_ID' => $account['accountid'], 'ACCOUNT_NAME' => $account['accountname'], 'AMOUNT' => $account['amount']);
        $Top_Accounts = strlen($account['accountname']) > 20 ? substr($account['accountname'], 0, 20) . '...' : $account['accountname'];
        $value[] = '<a href="index.php?action=DetailView&module=Accounts&record=' . $account['accountid'] . '">' . $Top_Accounts . '</a>';
        $value[] = CurrencyField::convertToUserFormat($account['amount']);
        $entries[$account['accountid']] = $value;
    }
    $values = array('ModuleName' => 'Accounts', 'Title' => $title, 'Header' => $header, 'Entries' => $entries);
    $log->debug("Exiting getTopAccounts method ...");
    if ($display_empty_home_blocks && count($entries) == 0 || count($entries) > 0) {
        return $values;
    }
}
    public function process($module, $id, Vtiger_PDF_Model $pdf)
    {
        $html = '';
        $recordId = $id;
        $record = Vtiger_Record_Model::getInstanceById($recordId);
        $moduleModel = $record->getModule();
        if (!$moduleModel->isInventory()) {
            return $html;
        }
        $inventoryField = Vtiger_InventoryField_Model::getInstance($module);
        $fields = $inventoryField->getFields(true);
        if ($fields[0] != 0) {
            $columns = $inventoryField->getColumns();
            $inventoryRows = $record->getInventoryData();
            $mainParams = $inventoryField->getMainParams($fields[1]);
            $countFields0 = count($fields[0]);
            $countFields1 = count($fields[1]);
            $countFields2 = count($fields[2]);
            $baseCurrency = Vtiger_Util_Helper::getBaseCurrency();
        }
        if (in_array("currency", $columns)) {
            if (count($inventoryRows) > 0 && $inventoryRows[0]['currency'] != NULL) {
                $currency = $inventoryRows[0]['currency'];
            } else {
                $currency = $baseCurrency['id'];
            }
            $currencySymbolRate = Vtiger_Functions::getCurrencySymbolandRate($currency);
        }
        $html .= '<style>' . '.productTable{color:#000; font-size:10px}' . '.productTable th {text-transform: uppercase;font-weight:normal}' . '.productTable tbody tr:nth-child(odd){background:#eee}' . '.productTable tbody tr td{border-bottom: 1px solid #ddd; padding:5px}' . '.colapseBorder {border-collapse: collapse;}' . '.productTable td, th {padding-left: 5px; padding-right: 5px;}' . '.productTable .summaryContainer{background:#ccc;}' . '</style>';
        if (count($fields[0]) != 0) {
            $discount = 0;
            foreach ($inventoryRows as $key => &$inventoryRow) {
                $taxes = $inventoryField->getTaxParam($inventoryRow['taxparam'], $inventoryRow['net'], $taxes);
            }
            if (in_array('discount', $columns) && in_array('discountmode', $columns)) {
                $html .= '<table class="productTable colapseBorder">
							<thead>
								<tr>
									<th class="tBorder noBottomBorder tHeader">
										<strong>' . vtranslate('LBL_DISCOUNTS_SUMMARY', $module) . '</strong>
									</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td class="textAlignRight tBorder">' . CurrencyField::convertToUserFormat($discount, null, true) . ' ' . $currencySymbolRate['symbol'] . '</td>
								</tr>
							</tbody>
						</table>';
            }
        }
        return $html;
    }
Exemplo n.º 5
0
 public function getEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $parentModule = $this->getParentRecordModel()->getModule();
     $relationModel = $this->getRelationModel();
     $relationModule = $relationModel->getRelationModuleModel();
     $relatedColumnFieldMapping = $relationModel->getRelationFields(true, true);
     if (count($relatedColumnFieldMapping) <= 0) {
         $relatedColumnFieldMapping = $relationModule->getConfigureRelatedListFields();
     }
     if (count($relatedColumnFieldMapping) <= 0) {
         $relatedColumnFieldMapping = $relationModule->getRelatedListFields();
     }
     $query = $this->getRelationQuery();
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $orderBy = $this->getForSql('orderby');
     $sortOrder = $this->getForSql('sortorder');
     if ($orderBy) {
         $query = "{$query} ORDER BY {$orderBy} {$sortOrder}";
     }
     $limitQuery = $query . ' LIMIT ' . $startIndex . ',' . $pageLimit;
     $result = $db->pquery($limitQuery, array());
     $relatedRecordList = array();
     for ($i = 0; $i < $db->num_rows($result); $i++) {
         $row = $db->fetch_row($result, $i);
         $newRow = array();
         foreach ($row as $col => $val) {
             if (array_key_exists($col, $relatedColumnFieldMapping)) {
                 $newRow[$relatedColumnFieldMapping[$col]] = $val;
             }
         }
         $recordId = $row['crmid'];
         $newRow['id'] = $recordId;
         //Added to support List Price
         $newRow['listprice'] = CurrencyField::convertToUserFormat($row['listprice'], null, true);
         $record = Vtiger_Record_Model::getCleanInstance($relationModule->get('name'));
         $relatedRecordList[$recordId] = $record->setData($newRow)->setModuleFromInstance($relationModule);
     }
     $pagingModel->calculatePageRange($relatedRecordList);
     $nextLimitQuery = $query . ' LIMIT ' . ($startIndex + $pageLimit) . ' , 1';
     $nextPageLimitResult = $db->pquery($nextLimitQuery, array());
     if ($db->num_rows($nextPageLimitResult) > 0) {
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     return $relatedRecordList;
 }
Exemplo n.º 6
0
 /**
  * this function takes in an array of values for an user and sanitizes it for export
  * @param array $arr - the array of values
  */
 function sanitizeValues($arr)
 {
     global $current_user, $adb;
     $roleid = fetchUserRole($current_user->id);
     $decimal = $current_user->currency_decimal_separator;
     $numsep = $current_user->currency_grouping_separator;
     foreach ($arr as $fieldlabel => &$value) {
         $fieldInfo = $this->fieldsArr[$fieldlabel];
         $uitype = $fieldInfo['uitype'];
         $fieldname = $fieldInfo['fieldname'];
         if ($uitype == 15 || $uitype == 16 || $uitype == 33) {
             //picklists
             if (empty($this->picklistValues[$fieldname])) {
                 $this->picklistValues[$fieldname] = getAssignedPicklistValues($fieldname, $roleid, $adb);
             }
             $value = trim($value);
         } elseif ($uitype == 10) {
             //have to handle uitype 10
             $value = trim($value);
             if (!empty($value)) {
                 $parent_module = getSalesEntityType($value);
                 $displayValueArray = getEntityName($parent_module, $value);
                 if (!empty($displayValueArray)) {
                     foreach ($displayValueArray as $k => $v) {
                         $displayValue = $v;
                     }
                 }
                 if (!empty($parent_module) && !empty($displayValue)) {
                     $value = $parent_module . "::::" . $displayValue;
                 } else {
                     $value = "";
                 }
             } else {
                 $value = '';
             }
         } elseif ($uitype == 71 || $uitype == 72) {
             $value = CurrencyField::convertToUserFormat($value, null, true);
         } elseif ($uitype == 7 || $fieldInfo['typeofdata'] == 'N~O' || $uitype == 9) {
             $value = number_format($value, 2, $decimal, $numsep);
         }
     }
     return $arr;
 }
Exemplo n.º 7
0
/**	Function used to get all the price details for different currencies which are associated to the given product
 *	@param int $productid - product id to which we want to get all the associated prices
 *  @param decimal $unit_price - Unit price of the product
 *  @param string $available - available or available_associated where as default is available, if available then the prices in the currencies which are available now will be returned, otherwise if the value is available_associated then prices of all the associated currencies will be retruned
 *	@return array $price_details - price details as a array with productid, curid, curname
 */
function getPriceDetailsForProduct($productid, $unit_price, $available = 'available', $itemtype = 'Products')
{
    global $log, $adb;
    $log->debug("Entering into function getPriceDetailsForProduct({$productid})");
    if ($productid != '') {
        $product_currency_id = getProductBaseCurrency($productid, $itemtype);
        $product_base_conv_rate = getBaseConversionRateForProduct($productid, 'edit', $itemtype);
        // Detail View
        if ($available == 'available_associated') {
            $query = "select vtiger_currency_info.*, vtiger_productcurrencyrel.converted_price, vtiger_productcurrencyrel.actual_price\n\t\t\t\t\tfrom vtiger_currency_info\n\t\t\t\t\tinner join vtiger_productcurrencyrel on vtiger_currency_info.id = vtiger_productcurrencyrel.currencyid\n\t\t\t\t\twhere vtiger_currency_info.currency_status = 'Active' and vtiger_currency_info.deleted=0\n\t\t\t\t\tand vtiger_productcurrencyrel.productid = ? and vtiger_currency_info.id != ?";
            $params = array($productid, $product_currency_id);
        } else {
            // Edit View
            $query = "select vtiger_currency_info.*, vtiger_productcurrencyrel.converted_price, vtiger_productcurrencyrel.actual_price\n\t\t\t\t\tfrom vtiger_currency_info\n\t\t\t\t\tleft join vtiger_productcurrencyrel\n\t\t\t\t\ton vtiger_currency_info.id = vtiger_productcurrencyrel.currencyid and vtiger_productcurrencyrel.productid = ?\n\t\t\t\t\twhere vtiger_currency_info.currency_status = 'Active' and vtiger_currency_info.deleted=0";
            $params = array($productid);
        }
        //Postgres 8 fixes
        if ($adb->dbType == "pgsql") {
            $query = fixPostgresQuery($query, $log, 0);
        }
        $res = $adb->pquery($query, $params);
        for ($i = 0; $i < $adb->num_rows($res); $i++) {
            $price_details[$i]['productid'] = $productid;
            $price_details[$i]['currencylabel'] = $adb->query_result($res, $i, 'currency_name');
            $price_details[$i]['currencycode'] = $adb->query_result($res, $i, 'currency_code');
            $price_details[$i]['currencysymbol'] = $adb->query_result($res, $i, 'currency_symbol');
            $currency_id = $adb->query_result($res, $i, 'id');
            $price_details[$i]['curid'] = $currency_id;
            $price_details[$i]['curname'] = 'curname' . $adb->query_result($res, $i, 'id');
            $cur_value = $adb->query_result($res, $i, 'actual_price');
            // Get the conversion rate for the given currency, get the conversion rate of the product currency to base currency.
            // Both together will be the actual conversion rate for the given currency.
            $conversion_rate = $adb->query_result($res, $i, 'conversion_rate');
            $actual_conversion_rate = $product_base_conv_rate * $conversion_rate;
            if ($cur_value == null || $cur_value == '') {
                $price_details[$i]['check_value'] = false;
                if ($unit_price != null) {
                    $cur_value = convertFromMasterCurrency($unit_price, $actual_conversion_rate);
                } else {
                    $cur_value = '0';
                }
            } else {
                $price_details[$i]['check_value'] = true;
            }
            $price_details[$i]['curvalue'] = CurrencyField::convertToUserFormat($cur_value, null, true);
            $price_details[$i]['conversionrate'] = $actual_conversion_rate;
            $is_basecurrency = false;
            if ($currency_id == $product_currency_id) {
                $is_basecurrency = true;
            }
            $price_details[$i]['is_basecurrency'] = $is_basecurrency;
        }
    } else {
        if ($available == 'available') {
            // Create View
            global $current_user;
            $user_currency_id = fetchCurrency($current_user->id);
            $query = "select vtiger_currency_info.* from vtiger_currency_info\n\t\t\t\t\twhere vtiger_currency_info.currency_status = 'Active' and vtiger_currency_info.deleted=0";
            $params = array();
            $res = $adb->pquery($query, $params);
            for ($i = 0; $i < $adb->num_rows($res); $i++) {
                $price_details[$i]['currencylabel'] = $adb->query_result($res, $i, 'currency_name');
                $price_details[$i]['currencycode'] = $adb->query_result($res, $i, 'currency_code');
                $price_details[$i]['currencysymbol'] = $adb->query_result($res, $i, 'currency_symbol');
                $currency_id = $adb->query_result($res, $i, 'id');
                $price_details[$i]['curid'] = $currency_id;
                $price_details[$i]['curname'] = 'curname' . $adb->query_result($res, $i, 'id');
                // Get the conversion rate for the given currency, get the conversion rate of the product currency(logged in user's currency) to base currency.
                // Both together will be the actual conversion rate for the given currency.
                $conversion_rate = $adb->query_result($res, $i, 'conversion_rate');
                $user_cursym_convrate = getCurrencySymbolandCRate($user_currency_id);
                $product_base_conv_rate = 1 / $user_cursym_convrate['rate'];
                $actual_conversion_rate = $product_base_conv_rate * $conversion_rate;
                $price_details[$i]['check_value'] = false;
                $price_details[$i]['curvalue'] = '0';
                $price_details[$i]['conversionrate'] = $actual_conversion_rate;
                $is_basecurrency = false;
                if ($currency_id == $user_currency_id) {
                    $is_basecurrency = true;
                }
                $price_details[$i]['is_basecurrency'] = $is_basecurrency;
            }
        } else {
            $log->debug("Product id is empty. we cannot retrieve the associated prices.");
        }
    }
    $log->debug("Exit from function getPriceDetailsForProduct({$productid})");
    return $price_details;
}
Exemplo n.º 8
0
    function getAdvancedFilterList($reportid)
    {
        global $adb;
        global $modules;
        global $log;
        global $current_user;
        $advft_criteria = array();
        $sql = 'SELECT * FROM vtiger_relcriteria_grouping WHERE queryid = ? ORDER BY groupid';
        $groupsresult = $adb->pquery($sql, array($reportid));
        $i = 1;
        $j = 0;
        while ($relcriteriagroup = $adb->fetch_array($groupsresult)) {
            $groupId = $relcriteriagroup["groupid"];
            $groupCondition = $relcriteriagroup["group_condition"];
            $ssql = 'select vtiger_relcriteria.* from vtiger_report
						inner join vtiger_relcriteria on vtiger_relcriteria.queryid = vtiger_report.queryid
						left join vtiger_relcriteria_grouping on vtiger_relcriteria.queryid = vtiger_relcriteria_grouping.queryid
								and vtiger_relcriteria.groupid = vtiger_relcriteria_grouping.groupid';
            $ssql .= " where vtiger_report.reportid = ? AND vtiger_relcriteria.groupid = ? order by vtiger_relcriteria.columnindex";
            $result = $adb->pquery($ssql, array($reportid, $groupId));
            $noOfColumns = $adb->num_rows($result);
            if ($noOfColumns <= 0) {
                continue;
            }
            while ($relcriteriarow = $adb->fetch_array($result)) {
                $columnIndex = $relcriteriarow["columnindex"];
                $criteria = array();
                $criteria['columnname'] = $relcriteriarow["columnname"];
                $criteria['comparator'] = $relcriteriarow["comparator"];
                $advfilterval = $relcriteriarow["value"];
                $col = explode(":", $relcriteriarow["columnname"]);
                $moduleFieldLabel = $col[2];
                $fieldName = $col[3];
                list($module, $fieldLabel) = explode('__', $moduleFieldLabel, 2);
                $fieldInfo = getFieldByReportLabel($module, $fieldLabel);
                $fieldType = null;
                if (!empty($fieldInfo)) {
                    $field = WebserviceField::fromArray($adb, $fieldInfo);
                    $fieldType = $field->getFieldDataType();
                }
                if ($fieldType == 'currency') {
                    if ($field->getUIType() == '71') {
                        $advfilterval = CurrencyField::convertToUserFormat($advfilterval, $current_user);
                    } else {
                        if ($field->getUIType() == '72') {
                            $advfilterval = CurrencyField::convertToUserFormat($advfilterval, $current_user, true);
                        }
                    }
                }
                $temp_val = explode(",", $relcriteriarow["value"]);
                if ($col[4] == 'D' || $col[4] == 'T' && $col[1] != 'time_start' && $col[1] != 'time_end' || $col[4] == 'DT') {
                    $val = array();
                    for ($x = 0; $x < count($temp_val); $x++) {
                        if ($col[4] == 'D') {
                            $date = new DateTimeField(trim($temp_val[$x]));
                            $val[$x] = $date->getDisplayDate();
                        } elseif ($col[4] == 'DT') {
                            $date = new DateTimeField(trim($temp_val[$x]));
                            $val[$x] = $date->getDisplayDateTimeValue();
                        } else {
                            $date = new DateTimeField(trim($temp_val[$x]));
                            $val[$x] = $date->getDisplayTime();
                        }
                    }
                    $advfilterval = implode(",", $val);
                }
                //In vtiger6 report filter conditions, if the value has "(double quotes) then it is failed.
                $criteria['value'] = Vtiger_Util_Helper::toSafeHTML(decode_html($advfilterval));
                $criteria['column_condition'] = $relcriteriarow["column_condition"];
                $advft_criteria[$relcriteriarow['groupid']]['columns'][$j] = $criteria;
                $advft_criteria[$relcriteriarow['groupid']]['condition'] = $groupCondition;
                $j++;
            }
            $i++;
        }
        // Clear the condition (and/or) for last group, if any.
        if (!empty($advft_criteria[$i - 1]['condition'])) {
            $advft_criteria[$i - 1]['condition'] = '';
        }
        $this->advft_criteria = $advft_criteria;
        $log->info("Reports :: Successfully returned getAdvancedFilterList");
        return true;
    }
Exemplo n.º 9
0
 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;
 }
Exemplo n.º 10
0
 /**
  * this function takes in an array of values for an user and sanitizes it for export
  * @param array $arr - the array of values
  */
 function sanitizeValues($arr)
 {
     $db = PearDatabase::getInstance();
     $currentUser = Users_Record_Model::getCurrentUserModel();
     $roleid = $currentUser->get('roleid');
     if (empty($this->fieldArray)) {
         $this->fieldArray = $this->moduleFieldInstances;
         foreach ($this->fieldArray as $fieldName => $fieldObj) {
             //In database we have same column name in two tables. - inventory modules only
             if ($fieldObj->get('table') == 'vtiger_inventoryproductrel' && ($fieldName == 'discount_amount' || $fieldName == 'discount_percent')) {
                 $fieldName = 'item_' . $fieldName;
                 $this->fieldArray[$fieldName] = $fieldObj;
             } else {
                 $columnName = $fieldObj->get('column');
                 $this->fieldArray[$columnName] = $fieldObj;
             }
         }
     }
     $moduleName = $this->moduleInstance->getName();
     foreach ($arr as $fieldName => &$value) {
         if (isset($this->fieldArray[$fieldName])) {
             $fieldInfo = $this->fieldArray[$fieldName];
         } else {
             unset($arr[$fieldName]);
             continue;
         }
         $value = trim(decode_html($value), "\"");
         $uitype = $fieldInfo->get('uitype');
         $fieldname = $fieldInfo->get('name');
         if (!$this->fieldDataTypeCache[$fieldName]) {
             $this->fieldDataTypeCache[$fieldName] = $fieldInfo->getFieldDataType();
         }
         $type = $this->fieldDataTypeCache[$fieldName];
         if ($fieldname != 'hdnTaxType' && ($uitype == 15 || $uitype == 16 || $uitype == 33)) {
             if (empty($this->picklistValues[$fieldname])) {
                 $this->picklistValues[$fieldname] = $this->fieldArray[$fieldname]->getPicklistValues();
             }
             // If the value being exported is accessible to current user
             // or the picklist is multiselect type.
             if ($uitype == 33 || $uitype == 16 || array_key_exists($value, $this->picklistValues[$fieldname])) {
                 // NOTE: multipicklist (uitype=33) values will be concatenated with |# delim
                 $value = trim($value);
             } else {
                 $value = '';
             }
         } elseif ($uitype == 52 || $type == 'owner') {
             $value = Vtiger_Util_Helper::getOwnerName($value);
         } elseif ($type == 'reference') {
             $value = trim($value);
             if (!empty($value)) {
                 $parent_module = getSalesEntityType($value);
                 $displayValueArray = getEntityName($parent_module, $value);
                 if (!empty($displayValueArray)) {
                     foreach ($displayValueArray as $k => $v) {
                         $displayValue = $v;
                     }
                 }
                 if (!empty($parent_module) && !empty($displayValue)) {
                     $value = $parent_module . "::::" . $displayValue;
                 } else {
                     $value = "";
                 }
             } else {
                 $value = '';
             }
         } elseif ($uitype == 72 || $uitype == 71) {
             $value = CurrencyField::convertToUserFormat($value, null, true, true);
         } elseif ($uitype == 7 && $fieldInfo->get('typeofdata') == 'N~O' || $uitype == 9) {
             $value = decimalFormat($value);
         } else {
             if ($type == 'date' || $type == 'datetime') {
                 $value = DateTimeField::convertToUserFormat($value);
             }
         }
         if ($moduleName == 'Documents' && $fieldname == 'description') {
             $value = strip_tags($value);
             $value = str_replace('&nbsp;', '', $value);
             array_push($new_arr, $value);
         }
     }
     return $arr;
 }
Exemplo n.º 11
0
/** Function to return the duplicate records data as a formatted array */
function getDuplicateRecordsArr($module)
{
    global $adb, $app_strings, $list_max_entries_per_page, $theme;
    $field_values_array = getFieldValues($module);
    $field_values = $field_values_array['fieldnames_list'];
    $fld_arr = $field_values_array['fieldnames_array'];
    $col_arr = $field_values_array['columnnames_array'];
    $fld_labl_arr = $field_values_array['fieldlabels_array'];
    $ui_type = $field_values_array['fieldname_uitype'];
    $dup_query = getDuplicateQuery($module, $field_values, $ui_type);
    // added for page navigation
    $dup_count_query = substr($dup_query, stripos($dup_query, 'FROM'), strlen($dup_query));
    $dup_count_query = "SELECT count(*) as count " . $dup_count_query;
    $count_res = $adb->query($dup_count_query);
    $no_of_rows = $adb->query_result($count_res, 0, "count");
    if ($no_of_rows <= $list_max_entries_per_page) {
        $_SESSION['dup_nav_start' . $module] = 1;
    } else {
        if (isset($_REQUEST["start"]) && $_REQUEST["start"] != "" && $_SESSION['dup_nav_start' . $module] != $_REQUEST["start"]) {
            $_SESSION['dup_nav_start' . $module] = ListViewSession::getRequestStartPage();
        }
    }
    $start = $_SESSION['dup_nav_start' . $module] != "" ? $_SESSION['dup_nav_start' . $module] : 1;
    $navigation_array = getNavigationValues($start, $no_of_rows, $list_max_entries_per_page);
    $start_rec = $navigation_array['start'];
    $end_rec = $navigation_array['end_val'];
    $navigationOutput = getTableHeaderNavigation($navigation_array, "", $module, "FindDuplicate", "");
    if ($start_rec == 0) {
        $limit_start_rec = 0;
    } else {
        $limit_start_rec = $start_rec - 1;
    }
    $dup_query .= " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}";
    //ends
    $nresult = $adb->query($dup_query);
    $no_rows = $adb->num_rows($nresult);
    require_once 'modules/Vtiger/layout_utils.php';
    if ($no_rows == 0) {
        if ($_REQUEST['action'] == 'FindDuplicateRecords') {
            //echo "<br><br><center>".$app_strings['LBL_NO_DUPLICATE']." <a href='javascript:window.history.back()'>".$app_strings['LBL_GO_BACK'].".</a></center>";
            //die;
            echo "<link rel='stylesheet' type='text/css' href='themes/{$theme}/style.css'>";
            echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
            echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>\n\n\t\t\t\t<table border='0' cellpadding='5' cellspacing='0' width='98%'>\n\t\t\t\t<tbody><tr>\n\t\t\t\t<td rowspan='2' width='11%'><img src='" . vtiger_imageurl('empty.jpg', $theme) . "' ></td>\n\t\t\t\t<td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span class='genHeaderSmall'>{$app_strings['LBL_NO_DUPLICATE']}</span></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td class='small' align='right' nowrap='nowrap'>\n\t\t\t\t<a href='javascript:window.history.back();'>{$app_strings['LBL_GO_BACK']}</a><br>     </td>\n\t\t\t\t</tr>\n\t\t\t\t</tbody></table>\n\t\t\t\t</div>";
            echo "</td></tr></table>";
            exit;
        } else {
            echo "<br><br><table align='center' class='reportCreateBottom big' width='95%'><tr><td align='center'>" . $app_strings['LBL_NO_DUPLICATE'] . "</td></tr></table>";
            die;
        }
    }
    $rec_cnt = 0;
    $temp = array();
    $sl_arr = array();
    $grp = "group0";
    $gcnt = 0;
    $ii = 0;
    //ii'th record in group
    while ($rec_cnt < $no_rows) {
        $result = $adb->fetchByAssoc($nresult);
        //echo '<pre>';print_r($result);echo '</pre>';
        if ($rec_cnt != 0) {
            $sl_arr = array_slice($result, 2);
            array_walk($temp, 'lower_array');
            array_walk($sl_arr, 'lower_array');
            $arr_diff = array_diff($temp, $sl_arr);
            if (count($arr_diff) > 0) {
                $gcnt++;
                $temp = $sl_arr;
                $ii = 0;
            }
            $grp = "group" . $gcnt;
        }
        $fld_values[$grp][$ii]['recordid'] = $result['recordid'];
        for ($k = 0; $k < count($col_arr); $k++) {
            if ($rec_cnt == 0) {
                $temp[$fld_labl_arr[$k]] = $result[$col_arr[$k]];
            }
            if ($ui_type[$fld_arr[$k]] == 56) {
                if ($result[$col_arr[$k]] == 0) {
                    $result[$col_arr[$k]] = $app_strings['no'];
                } else {
                    $result[$col_arr[$k]] = $app_strings['yes'];
                }
            }
            if ($ui_type[$fld_arr[$k]] == 75 || $ui_type[$fld_arr[$k]] == 81) {
                $vendor_id = $result[$col_arr[$k]];
                if ($vendor_id != '') {
                    $vendor_name = getVendorName($vendor_id);
                }
                $result[$col_arr[$k]] = $vendor_name;
            }
            if ($ui_type[$fld_arr[$k]] == 57) {
                $contact_id = $result[$col_arr[$k]];
                if ($contact_id != '') {
                    $parent_module = 'Contacts';
                    $displayValueArray = getEntityName($parent_module, $contact_id);
                    if (!empty($displayValueArray)) {
                        foreach ($displayValueArray as $key => $field_value) {
                            $contactname = $field_value;
                        }
                    }
                }
                $result[$col_arr[$k]] = $contactname;
            }
            if ($ui_type[$fld_arr[$k]] == 15 || $ui_type[$fld_arr[$k]] == 16) {
                $result[$col_arr[$k]] = getTranslatedString($result[$col_arr[$k]], $module);
            }
            if ($ui_type[$fld_arr[$k]] == 33) {
                $fieldvalue = explode(' |##| ', $result[$col_arr[$k]]);
                $result[$col_arr[$k]] = array();
                foreach ($fieldvalue as $picklistValue) {
                    $result[$col_arr[$k]][] = getTranslatedString($picklistValue, $module);
                }
                $result[$col_arr[$k]] = implode(', ', $result[$col_arr[$k]]);
            }
            if ($ui_type[$fld_arr[$k]] == 68) {
                $parent_id = $result[$col_arr[$k]];
                if ($parent_id != '') {
                    $parentname = getParentName($parent_id);
                }
                $result[$col_arr[$k]] = $parentname;
            }
            if ($ui_type[$fld_arr[$k]] == 53 || $ui_type[$fld_arr[$k]] == 52) {
                if ($result[$col_arr[$k]] != '') {
                    $owner = getOwnerName($result[$col_arr[$k]]);
                }
                $result[$col_arr[$k]] = $owner;
            }
            if ($ui_type[$fld_arr[$k]] == 50 or $ui_type[$fld_arr[$k]] == 51) {
                if ($module != 'Products') {
                    $entity_name = getAccountName($result[$col_arr[$k]]);
                } else {
                    $entity_name = getProductName($result[$col_arr[$k]]);
                }
                if ($entity_name != '') {
                    $result[$col_arr[$k]] = $entity_name;
                } else {
                    $result[$col_arr[$k]] = '';
                }
            }
            if ($ui_type[$fld_arr[$k]] == 58) {
                $campaign_name = getCampaignName($result[$col_arr[$k]]);
                if ($campaign_name != '') {
                    $result[$col_arr[$k]] = $campaign_name;
                } else {
                    $result[$col_arr[$k]] = '';
                }
            }
            if ($ui_type[$fld_arr[$k]] == 59) {
                $product_name = getProductName($result[$col_arr[$k]]);
                if ($product_name != '') {
                    $result[$col_arr[$k]] = $product_name;
                } else {
                    $result[$col_arr[$k]] = '';
                }
            }
            /*uitype 10 handling*/
            if ($ui_type[$fld_arr[$k]] == 10) {
                $result[$col_arr[$k]] = getRecordInfoFromID($result[$col_arr[$k]]);
            }
            if ($ui_type[$fld_arr[$k]] == 5 || $ui_type[$fld_arr[$k]] == 6 || $ui_type[$fld_arr[$k]] == 23) {
                if (${$result}[$col_arr[$k]] != '' && ${$result}[$col_arr[$k]] != '0000-00-00') {
                    $date = new DateTimeField(${$result}[$col_arr[$k]]);
                    $value = $date->getDisplayDate();
                    if (strpos(${$result}[$col_arr[$k]], ' ') > -1) {
                        $value .= ' ' . $date->getDisplayTime();
                    }
                } elseif (${$result}[$col_arr[$k]] == '0000-00-00') {
                    $value = '';
                } else {
                    $value = ${$result}[$col_arr[$k]];
                }
                $result[$col_arr[$k]] = $value;
            }
            if ($ui_type[$fld_arr[$k]] == 71) {
                $result[$col_arr[$k]] = CurrencyField::convertToUserFormat($result[$col_arr[$k]]);
            }
            if ($ui_type[$fld_arr[$k]] == 72) {
                $result[$col_arr[$k]] = CurrencyField::convertToUserFormat($result[$col_arr[$k]], null, true);
            }
            $fld_values[$grp][$ii][$fld_labl_arr[$k]] = $result[$col_arr[$k]];
        }
        $fld_values[$grp][$ii]['Entity Type'] = $result['deleted'];
        $ii++;
        $rec_cnt++;
    }
    $gro = "group";
    for ($i = 0; $i < $no_rows; $i++) {
        $ii = 0;
        $dis_group[] = $fld_values[$gro . $i][$ii];
        $count_group[$i] = count($fld_values[$gro . $i]);
        $ii++;
        $new_group[] = $dis_group[$i];
    }
    $fld_nam = $new_group[0];
    $ret_arr[0] = $fld_values;
    $ret_arr[1] = $fld_nam;
    $ret_arr[2] = $ui_type;
    $ret_arr["navigation"] = $navigationOutput;
    return $ret_arr;
}
Exemplo n.º 12
0
 /**
  * Function to transform display value for currency field
  * @param $value
  * @param Current User
  * @param <Boolean> Skip Conversion
  * @return converted user format value
  */
 public static function transformDisplayValue($value, $user = null, $skipConversion = false)
 {
     return CurrencyField::convertToUserFormat($value, $user, $skipConversion);
 }
Exemplo n.º 13
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;
     $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;
 }
Exemplo n.º 14
0
 /**
  * Save the inventory data
  */
 public function initInventoryData()
 {
     $log = vglobal('log');
     $log->debug('Entering ' . __CLASS__ . '::' . __METHOD__);
     $moduleName = $this->getModuleName();
     $inventory = Vtiger_InventoryField_Model::getInstance($moduleName);
     $fields = $inventory->getColumns();
     $table = $inventory->getTableName('data');
     $summaryFields = $inventory->getSummaryFields();
     $inventoryData = $summary = [];
     if ($this->has('inventoryData')) {
         $request = $this->get('inventoryData');
     } else {
         $request = new Vtiger_Request($_REQUEST, $_REQUEST);
     }
     if ($request->has('inventoryItemsNo')) {
         $numRow = $request->get('inventoryItemsNo');
         for ($i = 1; $i <= $numRow; $i++) {
             if (!$request->has(reset($fields)) && !$request->has(reset($fields) . $i)) {
                 continue;
             }
             $insertData = ['seq' => $request->get('seq' . $i)];
             foreach ($fields as $field) {
                 $value = $insertData[$field] = $inventory->getValueForSave($request, $field, $i);
                 if (in_array($field, $summaryFields)) {
                     $summary[$field] += $value;
                 }
             }
             $inventoryData[] = $insertData;
         }
         foreach ($summary as $fieldName => $fieldValue) {
             if ($this->has($fieldName)) {
                 $this->set($fieldName, CurrencyField::convertToUserFormat($fieldValue, null, true));
             }
         }
     }
     $this->inventoryData = $inventoryData;
     $log->debug('Exiting ' . __CLASS__ . '::' . __METHOD__);
 }
Exemplo n.º 15
0
 /**
  * Function to transform display value for currency field
  * @param $value
  * @param Current User
  * @param <Boolean> Skip Conversion
  * @return converted user format value
  */
 public static function transformDisplayValue($value, $user = null, $skipConversion = false)
 {
     global $log;
     $log->debug("Entering ./uitypes/Currency.php::statictransformDisplayValue");
     return CurrencyField::convertToUserFormat($value, $user, $skipConversion);
 }
Exemplo n.º 16
0
 public function getPDFMakerFieldValue($report, $picklistArray, $dbField, $valueArray, $fieldName)
 {
     global $current_user, $default_charset;
     $db = PearDatabase::getInstance();
     $value = $valueArray[$fieldName];
     $fld_type = $dbField->type;
     list($module, $fieldLabel) = explode('_', $dbField->name, 2);
     $fieldInfo = $this->getFieldByPDFMakerLabel($module, $fieldLabel);
     $fieldType = null;
     $fieldvalue = $value;
     if (!empty($fieldInfo)) {
         $field = WebserviceField::fromArray($db, $fieldInfo);
         $fieldType = $field->getFieldDataType();
     }
     if ($fieldType == 'currency' && $value != '') {
         // Some of the currency fields like Unit Price, Total, Sub-total etc of Inventory modules, do not need currency conversion
         if ($field->getUIType() == '72') {
             $curid_value = explode("::", $value);
             $currency_id = $curid_value[0];
             $currency_value = $curid_value[1];
             $cur_sym_rate = getCurrencySymbolandCRate($currency_id);
             if ($value != '') {
                 if ($dbField->name == 'Products_Unit_Price') {
                     // need to do this only for Products Unit Price
                     if ($currency_id != 1) {
                         $currency_value = (double) $cur_sym_rate['rate'] * (double) $currency_value;
                     }
                 }
                 $formattedCurrencyValue = CurrencyField::convertToUserFormat($currency_value, null, true);
                 $fieldvalue = CurrencyField::appendCurrencySymbol($formattedCurrencyValue, $cur_sym_rate['symbol']);
             }
         } else {
             $currencyField = new CurrencyField($value);
             $fieldvalue = $currencyField->getDisplayValue();
         }
     } elseif ($dbField->name == "PurchaseOrder_Currency" || $dbField->name == "SalesOrder_Currency" || $dbField->name == "Invoice_Currency" || $dbField->name == "Quotes_Currency" || $dbField->name == "PriceBooks_Currency") {
         if ($value != '') {
             $fieldvalue = getTranslatedCurrencyString($value);
         }
     } elseif (in_array($dbField->name, $this->ui101_fields) && !empty($value)) {
         $entityNames = getEntityName('Users', $value);
         $fieldvalue = $entityNames[$value];
     } elseif ($fieldType == 'date' && !empty($value)) {
         if ($module == 'Calendar' && $field->getFieldName() == 'due_date') {
             $endTime = $valueArray['calendar_end_time'];
             if (empty($endTime)) {
                 $recordId = $valueArray['calendar_id'];
                 $endTime = getSingleFieldValue('vtiger_activity', 'time_end', 'activityid', $recordId);
             }
             $date = new DateTimeField($value . ' ' . $endTime);
             $fieldvalue = $date->getDisplayDate();
         } else {
             $fieldvalue = DateTimeField::convertToUserFormat($value);
         }
     } elseif ($fieldType == "datetime" && !empty($value)) {
         $date = new DateTimeField($value);
         $fieldvalue = $date->getDisplayDateTimeValue();
     } elseif ($fieldType == 'time' && !empty($value) && $field->getFieldName() != 'duration_hours') {
         if ($field->getFieldName() == "time_start" || $field->getFieldName() == "time_end") {
             $date = new DateTimeField($value);
             $fieldvalue = $date->getDisplayTime();
         } else {
             $fieldvalue = $value;
         }
     } elseif ($fieldType == "picklist" && !empty($value)) {
         if (is_array($picklistArray)) {
             if (is_array($picklistArray[$dbField->name]) && $field->getFieldName() != 'activitytype' && !in_array($value, $picklistArray[$dbField->name])) {
                 $fieldvalue = $app_strings['LBL_NOT_ACCESSIBLE'];
             } else {
                 $fieldvalue = $this->getTranslatedString($value, $module);
             }
         } else {
             $fieldvalue = $this->getTranslatedString($value, $module);
         }
     } elseif ($fieldType == "multipicklist" && !empty($value)) {
         if (is_array($picklistArray[1])) {
             $valueList = explode(' |##| ', $value);
             $translatedValueList = array();
             foreach ($valueList as $value) {
                 if (is_array($picklistArray[1][$dbField->name]) && !in_array($value, $picklistArray[1][$dbField->name])) {
                     $translatedValueList[] = $app_strings['LBL_NOT_ACCESSIBLE'];
                 } else {
                     $translatedValueList[] = $this->getTranslatedString($value, $module);
                 }
             }
         }
         if (!is_array($picklistArray[1]) || !is_array($picklistArray[1][$dbField->name])) {
             $fieldvalue = str_replace(' |##| ', ', ', $value);
         } else {
             implode(', ', $translatedValueList);
         }
     } elseif ($fieldType == 'double') {
         if ($current_user->truncate_trailing_zeros == true) {
             $fieldvalue = decimalFormat($fieldvalue);
         }
     }
     if ($fieldvalue == "") {
         return "-";
     }
     $fieldvalue = str_replace("<", "&lt;", $fieldvalue);
     $fieldvalue = str_replace(">", "&gt;", $fieldvalue);
     $fieldvalue = decode_html($fieldvalue);
     if (stristr($fieldvalue, "|##|") && empty($fieldType)) {
         $fieldvalue = str_ireplace(' |##| ', ', ', $fieldvalue);
     } elseif ($fld_type == "date" && empty($fieldType)) {
         $fieldvalue = DateTimeField::convertToUserFormat($fieldvalue);
     } elseif ($fld_type == "datetime" && empty($fieldType)) {
         $date = new DateTimeField($fieldvalue);
         $fieldvalue = $date->getDisplayDateTimeValue();
     }
     // Added to render html tag for description fields
     if ($fieldInfo['uitype'] == '19' && ($module == 'Documents' || $module == 'Emails')) {
         return $fieldvalue;
     }
     return htmlentities($fieldvalue, ENT_QUOTES, $default_charset);
 }
Exemplo n.º 17
0
 protected function matchHandler($match)
 {
     ${"GLOBALS"}["xkaopqxzm"] = "match";
     if (count(${${"GLOBALS"}["fzudcyrhgcof"]}) == 2) {
         if (${${"GLOBALS"}["fzudcyrhgcof"]}[0] == "\$current_user_id") {
             ${"GLOBALS"}["pcmwmi"] = "sql";
             ${"GLOBALS"}["ikafodlyvv"] = "result";
             global $current_user, $adb;
             ${${"GLOBALS"}["pcmwmi"]} = "SELECT id FROM vtiger_ws_entity WHERE name = 'Users'";
             $qphgzkamlp = "wsTabId";
             ${${"GLOBALS"}["ikafodlyvv"]} = $adb->query(${${"GLOBALS"}["tmrwyiij"]});
             ${"GLOBALS"}["qtfuoyyj"] = "wsTabId";
             ${$qphgzkamlp} = $adb->query_result(${${"GLOBALS"}["lpwetnmjxv"]}, 0, "id");
             return ${${"GLOBALS"}["qtfuoyyj"]} . "x" . $current_user->id;
         }
         ${${"GLOBALS"}["tjyojamrs"]} = ${${"GLOBALS"}["fzudcyrhgcof"]}[1];
         ${${"GLOBALS"}["mduamvfjsqip"]} = $this->_context->get(${${"GLOBALS"}["tjyojamrs"]});
         if (${${"GLOBALS"}["mduamvfjsqip"]} === false) {
             $fhtdikgbwslw = "fieldname";
             return "\$" . ${$fhtdikgbwslw};
         }
         if (!empty(${${"GLOBALS"}["mduamvfjsqip"]})) {
             return ${${"GLOBALS"}["mduamvfjsqip"]};
         }
     } elseif (substr(${${"GLOBALS"}["xkaopqxzm"]}[0], 0, 2) == "\$[") {
         $dijnlqw = "date";
         $mqgzejwr = "parameter";
         ${"GLOBALS"}["nmvdtxgwlrfi"] = "parameter";
         ${"GLOBALS"}["ttjnpwjeoog"] = "function";
         ${${"GLOBALS"}["nnvfnxph"]} = strtolower(${${"GLOBALS"}["fzudcyrhgcof"]}[3]);
         ${"GLOBALS"}["pwzsndhjqsu"] = "format";
         ${"GLOBALS"}["smpvjojh"] = "time";
         if (count(${${"GLOBALS"}["fzudcyrhgcof"]}) > 4 && ${${"GLOBALS"}["fzudcyrhgcof"]}[4] != "") {
             ${"GLOBALS"}["dpyjijot"] = "i";
             $sotxthjssww = "parameter";
             $cwegxum = "i";
             ${"GLOBALS"}["abvuifgun"] = "i";
             ${$sotxthjssww} = explode(",", ${${"GLOBALS"}["fzudcyrhgcof"]}[6]);
             for (${${"GLOBALS"}["abvuifgun"]} = 0; ${$cwegxum} < count(${${"GLOBALS"}["hcmotgp"]}); ${${"GLOBALS"}["dpyjijot"]}++) {
                 ${"GLOBALS"}["grxhbqfel"] = "parameter";
                 $ligygcuopl = "i";
                 ${"GLOBALS"}["ndjfnng"] = "parameter";
                 ${${"GLOBALS"}["grxhbqfel"]}[${$ligygcuopl}] = trim(${${"GLOBALS"}["ndjfnng"]}[${${"GLOBALS"}["kmptlmxqx"]}], "'\" ");
             }
         } else {
             ${${"GLOBALS"}["hcmotgp"]} = false;
         }
         $jgqwmporwhlx = "parameter";
         ${"GLOBALS"}["vrsthbowou"] = "time";
         $rqvrwfirvnlx = "time";
         ${"GLOBALS"}["bpcyoqq"] = "time";
         ${"GLOBALS"}["ihnsia"] = "parameter";
         ${"GLOBALS"}["fnrwpimqo"] = "parameter";
         $jcrssxzdfxv = "parameter";
         switch (${${"GLOBALS"}["ttjnpwjeoog"]}) {
             case "url":
                 if (${$jcrssxzdfxv} != false && count(${${"GLOBALS"}["ihnsia"]}) > 0) {
                     $mrpmif = "parameter";
                     $dqjrkbsn = "parameter";
                     $jzqqvbm = "parameter";
                     ${$dqjrkbsn}[0] = intval(${${"GLOBALS"}["hcmotgp"]}[0]);
                     ${${"GLOBALS"}["xbpvinrmg"]} = VTEntity::getForId(${$mrpmif}[0]);
                     global $site_URL;
                     return ${${"GLOBALS"}["pvutchkhwqsg"]} . "/index.php?action=DetailView&module=" . $objTMP->getModuleName() . "&record=" . ${$jzqqvbm}[0];
                 }
                 break;
             case "round":
                 ${$jgqwmporwhlx}[0] = VTTemplate::parse(${${"GLOBALS"}["hcmotgp"]}[0], $this->_context);
                 if (count(${${"GLOBALS"}["hcmotgp"]}) == 3 && ${${"GLOBALS"}["hcmotgp"]}[2] == "1") {
                     ${"GLOBALS"}["alckvik"] = "return";
                     ${${"GLOBALS"}["alckvik"]} = \CurrencyField::convertToUserFormat(${${"GLOBALS"}["hcmotgp"]}[0]);
                 } else {
                     ${"GLOBALS"}["vlvxrxrbd"] = "return";
                     ${${"GLOBALS"}["vlvxrxrbd"]} = round(${${"GLOBALS"}["hcmotgp"]}[0], ${${"GLOBALS"}["hcmotgp"]}[1]);
                 }
                 return ${${"GLOBALS"}["eklrhak"]};
                 break;
             case "utctz":
                 ${${"GLOBALS"}["nmvdtxgwlrfi"]}[0] = VTTemplate::parse(${${"GLOBALS"}["hcmotgp"]}[0], $this->_context);
                 ${${"GLOBALS"}["eklrhak"]} = \DateTimeField::convertToDBTimeZone(${${"GLOBALS"}["hcmotgp"]}[0]);
                 return $return->format("H:i:s");
                 break;
             case "dateformat":
                 ${${"GLOBALS"}["hcmotgp"]}[0] = VTTemplate::parse(${${"GLOBALS"}["hcmotgp"]}[0], $this->_context);
                 ${$rqvrwfirvnlx} = strtotime(${${"GLOBALS"}["hcmotgp"]}[0]);
                 ${${"GLOBALS"}["gatkidfjf"]} = ${${"GLOBALS"}["hcmotgp"]}[1];
                 return date(${${"GLOBALS"}["gatkidfjf"]}, ${${"GLOBALS"}["bpcyoqq"]});
                 break;
             case "now":
                 ${${"GLOBALS"}["pwzsndhjqsu"]} = "Y-m-d";
                 ${$dijnlqw} = \DateTimeField::convertToUserTimeZone(date("Y-m-d H:i:s"));
                 ${${"GLOBALS"}["vrsthbowou"]} = strtotime($date->format("Y-m-d H:i:s"));
                 if (${${"GLOBALS"}["fnrwpimqo"]} != false) {
                     if (!empty(${${"GLOBALS"}["hcmotgp"]}[0])) {
                         ${${"GLOBALS"}["okbxsjn"]} += intval(${${"GLOBALS"}["hcmotgp"]}[0]) * 86400;
                     }
                     if (!empty(${${"GLOBALS"}["hcmotgp"]}[1])) {
                         ${"GLOBALS"}["ftrqsw"] = "parameter";
                         $mrgqelzfbcf = "format";
                         ${$mrgqelzfbcf} = ${${"GLOBALS"}["ftrqsw"]}[1];
                     }
                 }
                 return date(${${"GLOBALS"}["gatkidfjf"]}, ${${"GLOBALS"}["smpvjojh"]});
                 break;
             case "entityname":
                 if (${$mqgzejwr} != false) {
                     $cskxkqd = "parameter";
                     $hmnhgfaqeyo = "crmid";
                     $fcuyvjmvnnr = "parameter";
                     $gcsofxly = "parameter";
                     ${$fcuyvjmvnnr}[0] = VTTemplate::parse(${$gcsofxly}[0], $this->_context);
                     if (is_array(${$cskxkqd}[0]) || is_object(${${"GLOBALS"}["hcmotgp"]}[0])) {
                         ${"GLOBALS"}["fnlsgqesiuzo"] = "parameter";
                         throw new \Exception("Wrong input entityname: \$parameter=" . serialize(${${"GLOBALS"}["fnlsgqesiuzo"]}[0]));
                     }
                     ${"GLOBALS"}["bkvmzxylrca"] = "return";
                     ${"GLOBALS"}["vlrkemsbzk"] = "result";
                     if (strpos(${${"GLOBALS"}["hcmotgp"]}[0], "x") !== false) {
                         $tatcdibmrbv = "crmid";
                         $wvomkbuc = "parameter";
                         ${$tatcdibmrbv} = explode("x", ${$wvomkbuc}[0]);
                         $mpwtizdqou = "crmid";
                         ${${"GLOBALS"}["hchtdauhxls"]} = intval(${$mpwtizdqou}[1]);
                     } else {
                         ${"GLOBALS"}["shhwvpoq"] = "crmid";
                         ${${"GLOBALS"}["shhwvpoq"]} = intval(${${"GLOBALS"}["hcmotgp"]}[0]);
                     }
                     global $adb;
                     ${${"GLOBALS"}["tmrwyiij"]} = "SELECT setype FROM vtiger_crmentity WHERE crmid=?";
                     ${${"GLOBALS"}["vlrkemsbzk"]} = $adb->pquery(${${"GLOBALS"}["tmrwyiij"]}, array(${${"GLOBALS"}["hchtdauhxls"]}));
                     ${${"GLOBALS"}["ampkew"]} = $adb->fetchByAssoc(${${"GLOBALS"}["lpwetnmjxv"]});
                     ${${"GLOBALS"}["eklrhak"]} = getEntityName(${${"GLOBALS"}["ampkew"]}["setype"], array(${${"GLOBALS"}["hchtdauhxls"]}));
                     return ${${"GLOBALS"}["bkvmzxylrca"]}[${$hmnhgfaqeyo}];
                 } else {
                     return "";
                 }
                 break;
         }
     } else {
         $kwkieejbxn = "full";
         ${"GLOBALS"}["rvksgfjkohv"] = "matches";
         ${"GLOBALS"}["jjauqvcq"] = "referenceModule";
         $eyjfdznjzq = "referenceField";
         ${"GLOBALS"}["ckvljbgm"] = "fieldname";
         ${"GLOBALS"}["lzjihcwqljf"] = "referenceModule";
         ${"GLOBALS"}["nijbiieuq"] = "match";
         preg_match("/\\((\\w+) ?: \\(([_\\w]+)\\) (\\w+)\\)/", ${${"GLOBALS"}["nijbiieuq"]}[1], ${${"GLOBALS"}["vxkunswtk"]});
         list(${$kwkieejbxn}, ${$eyjfdznjzq}, ${${"GLOBALS"}["jjauqvcq"]}, ${${"GLOBALS"}["ckvljbgm"]}) = ${${"GLOBALS"}["rvksgfjkohv"]};
         if (${${"GLOBALS"}["ptyrsnuco"]} == "smownerid") {
             $oakmdiy = "referenceField";
             ${$oakmdiy} = "assigned_user_id";
         }
         if (${${"GLOBALS"}["lzjihcwqljf"]} === "__VtigerMeta__") {
             return $this->_getMetaValue(${${"GLOBALS"}["tjyojamrs"]});
         } else {
             ${"GLOBALS"}["ewdyzm"] = "referenceModule";
             $stlcjxh = "referenceField";
             if (${$stlcjxh} != "current_user") {
                 $conwshpzmoe = "referenceField";
                 ${"GLOBALS"}["utwbycs"] = "referenceField";
                 ${${"GLOBALS"}["itprpkcjk"]} = $this->_context->get(${$conwshpzmoe});
                 if (${${"GLOBALS"}["hncxzlio"]} == "Users" && ${${"GLOBALS"}["utwbycs"]} == "assigned_user_id") {
                     $gcpjmebsqn = "values";
                     $lxcfhlasynj = "values";
                     ${${"GLOBALS"}["hustoopi"]} = $this->_context->getOwners();
                     ${$lxcfhlasynj} = $owner->get(${${"GLOBALS"}["tjyojamrs"]});
                     return implode(",", ${$gcpjmebsqn});
                 }
                 if (empty(${${"GLOBALS"}["itprpkcjk"]})) {
                     return "";
                 }
             } else {
                 $mbxitu = "referenceId";
                 global $current_user;
                 ${$mbxitu} = $current_user->id;
             }
             ${"GLOBALS"}["guyjkru"] = "fieldname";
             ${"GLOBALS"}["xaflwfj"] = "referenceId";
             ${${"GLOBALS"}["qoieougsqps"]} = VTEntity::getForId(${${"GLOBALS"}["xaflwfj"]}, ${${"GLOBALS"}["ewdyzm"]} == "Users" ? "Users" : false);
             return $entity->get(${${"GLOBALS"}["guyjkru"]});
         }
     }
 }
Exemplo n.º 18
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 content_5696fc6c807b1($_smarty_tpl)
    {
        ?>
<div class="relatedContainer"><?php 
        $_smarty_tpl->tpl_vars['RELATED_MODULE_NAME'] = new Smarty_variable($_smarty_tpl->tpl_vars['RELATED_MODULE']->value->get('name'), null, 0);
        ?>
<input type="hidden" name="currentPageNum" value="<?php 
        echo $_smarty_tpl->tpl_vars['PAGING']->value->getCurrentPage();
        ?>
" /><input type="hidden" name="relatedModuleName" class="relatedModuleName" value="<?php 
        echo $_smarty_tpl->tpl_vars['RELATED_MODULE']->value->get('name');
        ?>
" /><input type="hidden" value="<?php 
        echo $_smarty_tpl->tpl_vars['ORDER_BY']->value;
        ?>
" id="orderBy"><input type="hidden" value="<?php 
        echo $_smarty_tpl->tpl_vars['SORT_ORDER']->value;
        ?>
" id="sortOrder"><input type="hidden" value="<?php 
        echo $_smarty_tpl->tpl_vars['RELATED_ENTIRES_COUNT']->value;
        ?>
" id="noOfEntries"><input type='hidden' value="<?php 
        echo $_smarty_tpl->tpl_vars['PAGING']->value->getPageLimit();
        ?>
" id='pageLimit'><input type='hidden' value="<?php 
        echo $_smarty_tpl->tpl_vars['TOTAL_ENTRIES']->value;
        ?>
" id='totalCount'><div class="relatedHeader "><div class="btn-toolbar row-fluid"><div class="span6"><?php 
        $_smarty_tpl->tpl_vars['RELATED_LINK'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['RELATED_LINK']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['RELATED_LIST_LINKS']->value['LISTVIEWBASIC'];
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        foreach ($_from as $_smarty_tpl->tpl_vars['RELATED_LINK']->key => $_smarty_tpl->tpl_vars['RELATED_LINK']->value) {
            $_smarty_tpl->tpl_vars['RELATED_LINK']->_loop = true;
            if ($_smarty_tpl->tpl_vars['RELATED_LINK']->value != null) {
                ?>
<div class="btn-group"><?php 
                ob_start();
                echo $_smarty_tpl->tpl_vars['RELATED_LINK']->value->get('_selectRelation');
                $_tmp1 = ob_get_clean();
                $_smarty_tpl->tpl_vars['IS_SELECT_BUTTON'] = new Smarty_variable($_tmp1, null, 0);
                ?>
<button type="button" class="btn addButton<?php 
                if ($_smarty_tpl->tpl_vars['IS_SELECT_BUTTON']->value == true) {
                    ?>
 selectRelation <?php 
                }
                ?>
 "<?php 
                if ($_smarty_tpl->tpl_vars['IS_SELECT_BUTTON']->value == true) {
                    ?>
 data-moduleName=<?php 
                    echo $_smarty_tpl->tpl_vars['RELATED_LINK']->value->get('_module')->get('name');
                    ?>
 <?php 
                }
                if ($_smarty_tpl->tpl_vars['RELATED_LINK']->value->isPageLoadLink()) {
                    if ($_smarty_tpl->tpl_vars['RELATION_FIELD']->value) {
                        ?>
 data-name="<?php 
                        echo $_smarty_tpl->tpl_vars['RELATION_FIELD']->value->getName();
                        ?>
" <?php 
                    }
                    ?>
data-url="<?php 
                    echo $_smarty_tpl->tpl_vars['RELATED_LINK']->value->getUrl();
                    ?>
"<?php 
                }
                if ($_smarty_tpl->tpl_vars['IS_SELECT_BUTTON']->value != true) {
                    ?>
name="addButton"<?php 
                }
                ?>
><?php 
                if ($_smarty_tpl->tpl_vars['IS_SELECT_BUTTON']->value == false) {
                    ?>
<i class="icon-plus icon-white"></i><?php 
                }
                ?>
&nbsp;<strong><?php 
                echo $_smarty_tpl->tpl_vars['RELATED_LINK']->value->getLabel();
                ?>
</strong></button></div><?php 
            }
        }
        ?>
&nbsp;</div><div class="span6"><div class="pull-right"><span class="pageNumbers"><span class="pageNumbersText"><?php 
        if (!empty($_smarty_tpl->tpl_vars['RELATED_RECORDS']->value)) {
            ?>
 <?php 
            echo $_smarty_tpl->tpl_vars['PAGING']->value->getRecordStartRange();
            ?>
 <?php 
            echo vtranslate('LBL_to', $_smarty_tpl->tpl_vars['RELATED_MODULE']->value->get('name'));
            ?>
 <?php 
            echo $_smarty_tpl->tpl_vars['PAGING']->value->getRecordEndRange();
        } else {
            ?>
<span>&nbsp;</span><?php 
        }
        ?>
</span><span class="icon-refresh totalNumberOfRecords cursorPointer<?php 
        if (empty($_smarty_tpl->tpl_vars['RELATED_RECORDS']->value)) {
            ?>
 hide<?php 
        }
        ?>
"></span></span><span class="btn-group"><button class="btn" id="relatedListPreviousPageButton" <?php 
        if (!$_smarty_tpl->tpl_vars['PAGING']->value->isPrevPageExists()) {
            ?>
 disabled <?php 
        }
        ?>
 type="button"><span class="icon-chevron-left"></span></button><button class="btn dropdown-toggle" type="button" id="relatedListPageJump" data-toggle="dropdown" <?php 
        if ($_smarty_tpl->tpl_vars['PAGE_COUNT']->value == 1) {
            ?>
 disabled <?php 
        }
        ?>
><i class="vtGlyph vticon-pageJump" title="<?php 
        echo vtranslate('LBL_LISTVIEW_PAGE_JUMP', $_smarty_tpl->tpl_vars['moduleName']->value);
        ?>
"></i></button><ul class="listViewBasicAction dropdown-menu" id="relatedListPageJumpDropDown"><li><span class="row-fluid"><span class="span3"><span class="pull-right"><?php 
        echo vtranslate('LBL_PAGE', $_smarty_tpl->tpl_vars['moduleName']->value);
        ?>
</span></span><span class="span4"><input type="text" id="pageToJump" class="listViewPagingInput" value="<?php 
        echo $_smarty_tpl->tpl_vars['PAGING']->value->getCurrentPage();
        ?>
"/></span><span class="span2 textAlignCenter"><?php 
        echo vtranslate('LBL_OF', $_smarty_tpl->tpl_vars['moduleName']->value);
        ?>
</span><span class="span3" id="totalPageCount"><?php 
        echo $_smarty_tpl->tpl_vars['PAGE_COUNT']->value;
        ?>
</span></span></li></ul><button class="btn" id="relatedListNextPageButton" <?php 
        if (!$_smarty_tpl->tpl_vars['PAGING']->value->isNextPageExists() || $_smarty_tpl->tpl_vars['PAGE_COUNT']->value == 1) {
            ?>
 disabled <?php 
        }
        ?>
 type="button"><span class="icon-chevron-right"></span></button></span></div></div></div></div><div class="contents-topscroll"><div class="topscroll-div">&nbsp;</div></div><div class="relatedContents contents-bottomscroll"><div class="bottomscroll-div"><?php 
        $_smarty_tpl->tpl_vars['WIDTHTYPE'] = new Smarty_variable($_smarty_tpl->tpl_vars['USER_MODEL']->value->get('rowheight'), null, 0);
        ?>
<table class="table table-bordered listViewEntriesTable"><thead><tr class="listViewHeaders"><?php 
        $_smarty_tpl->tpl_vars['HEADER_FIELD'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['HEADER_FIELD']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['RELATED_HEADERS']->value;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        $_smarty_tpl->tpl_vars['HEADER_FIELD']->total = $_smarty_tpl->_count($_from);
        $_smarty_tpl->tpl_vars['HEADER_FIELD']->iteration = 0;
        foreach ($_from as $_smarty_tpl->tpl_vars['HEADER_FIELD']->key => $_smarty_tpl->tpl_vars['HEADER_FIELD']->value) {
            $_smarty_tpl->tpl_vars['HEADER_FIELD']->_loop = true;
            $_smarty_tpl->tpl_vars['HEADER_FIELD']->iteration++;
            $_smarty_tpl->tpl_vars['HEADER_FIELD']->last = $_smarty_tpl->tpl_vars['HEADER_FIELD']->iteration === $_smarty_tpl->tpl_vars['HEADER_FIELD']->total;
            if ($_smarty_tpl->tpl_vars['HEADER_FIELD']->value != null) {
                ?>
<th <?php 
                if ($_smarty_tpl->tpl_vars['HEADER_FIELD']->last) {
                    ?>
 colspan="2" <?php 
                }
                ?>
 nowrap><?php 
                if ($_smarty_tpl->tpl_vars['HEADER_FIELD']->value->get('column') == 'access_count' || $_smarty_tpl->tpl_vars['HEADER_FIELD']->value->get('column') == 'idlists') {
                    ?>
<a href="javascript:void(0);" class="noSorting"><?php 
                    echo vtranslate($_smarty_tpl->tpl_vars['HEADER_FIELD']->value->get('label'), $_smarty_tpl->tpl_vars['RELATED_MODULE']->value->get('name'));
                    ?>
</a><?php 
                } elseif ($_smarty_tpl->tpl_vars['HEADER_FIELD']->value->get('column') == 'time_start') {
                } else {
                    ?>
<a href="javascript:void(0);" class="relatedListHeaderValues" data-nextsortorderval="<?php 
                    if ($_smarty_tpl->tpl_vars['COLUMN_NAME']->value == $_smarty_tpl->tpl_vars['HEADER_FIELD']->value->get('column')) {
                        echo $_smarty_tpl->tpl_vars['NEXT_SORT_ORDER']->value;
                    } else {
                        ?>
ASC<?php 
                    }
                    ?>
" data-fieldname="<?php 
                    echo $_smarty_tpl->tpl_vars['HEADER_FIELD']->value->get('column');
                    ?>
"><?php 
                    echo vtranslate($_smarty_tpl->tpl_vars['HEADER_FIELD']->value->get('label'), $_smarty_tpl->tpl_vars['RELATED_MODULE']->value->get('name'));
                    ?>
&nbsp;&nbsp;<?php 
                    if ($_smarty_tpl->tpl_vars['COLUMN_NAME']->value == $_smarty_tpl->tpl_vars['HEADER_FIELD']->value->get('column')) {
                        ?>
<img class="<?php 
                        echo $_smarty_tpl->tpl_vars['SORT_IMAGE']->value;
                        ?>
"><?php 
                    }
                    ?>
</a><?php 
                }
                ?>
</th><?php 
            }
        }
        ?>
</tr></thead><?php 
        $_smarty_tpl->tpl_vars['RELATED_RECORD'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['RELATED_RECORD']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['RELATED_RECORDS']->value;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        foreach ($_from as $_smarty_tpl->tpl_vars['RELATED_RECORD']->key => $_smarty_tpl->tpl_vars['RELATED_RECORD']->value) {
            $_smarty_tpl->tpl_vars['RELATED_RECORD']->_loop = true;
            if ($_smarty_tpl->tpl_vars['RELATED_RECORD']->value != null) {
                ?>
<tr class="listViewEntries" data-id='<?php 
                echo $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getId();
                ?>
'<?php 
                if ($_smarty_tpl->tpl_vars['RELATED_MODULE_NAME']->value == 'Calendar') {
                    $_smarty_tpl->tpl_vars['DETAILVIEWPERMITTED'] = new Smarty_variable(isPermitted($_smarty_tpl->tpl_vars['RELATED_MODULE']->value->get('name'), 'DetailView', $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getId()), null, 0);
                    if ($_smarty_tpl->tpl_vars['DETAILVIEWPERMITTED']->value == 'yes') {
                        ?>
data-recordUrl='<?php 
                        echo $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getDetailViewUrl();
                        ?>
'<?php 
                    }
                } else {
                    ?>
data-recordUrl='<?php 
                    echo $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getDetailViewUrl();
                    ?>
'<?php 
                }
                ?>
><?php 
                $_smarty_tpl->tpl_vars['HEADER_FIELD'] = new Smarty_Variable();
                $_smarty_tpl->tpl_vars['HEADER_FIELD']->_loop = false;
                $_from = $_smarty_tpl->tpl_vars['RELATED_HEADERS']->value;
                if (!is_array($_from) && !is_object($_from)) {
                    settype($_from, 'array');
                }
                $_smarty_tpl->tpl_vars['HEADER_FIELD']->total = $_smarty_tpl->_count($_from);
                $_smarty_tpl->tpl_vars['HEADER_FIELD']->iteration = 0;
                foreach ($_from as $_smarty_tpl->tpl_vars['HEADER_FIELD']->key => $_smarty_tpl->tpl_vars['HEADER_FIELD']->value) {
                    $_smarty_tpl->tpl_vars['HEADER_FIELD']->_loop = true;
                    $_smarty_tpl->tpl_vars['HEADER_FIELD']->iteration++;
                    $_smarty_tpl->tpl_vars['HEADER_FIELD']->last = $_smarty_tpl->tpl_vars['HEADER_FIELD']->iteration === $_smarty_tpl->tpl_vars['HEADER_FIELD']->total;
                    if ($_smarty_tpl->tpl_vars['HEADER_FIELD']->value != null) {
                        $_smarty_tpl->tpl_vars['RELATED_HEADERNAME'] = new Smarty_variable($_smarty_tpl->tpl_vars['HEADER_FIELD']->value->get('name'), null, 0);
                        ?>
<td class="<?php 
                        echo $_smarty_tpl->tpl_vars['WIDTHTYPE']->value;
                        ?>
" data-field-type="<?php 
                        echo $_smarty_tpl->tpl_vars['HEADER_FIELD']->value->getFieldDataType();
                        ?>
" nowrap><?php 
                        if ($_smarty_tpl->tpl_vars['HEADER_FIELD']->value->isNameField() == true || $_smarty_tpl->tpl_vars['HEADER_FIELD']->value->get('uitype') == '4') {
                            ?>
<a href="<?php 
                            echo $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getDetailViewUrl();
                            ?>
"><?php 
                            echo $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getDisplayValue($_smarty_tpl->tpl_vars['RELATED_HEADERNAME']->value);
                            ?>
</a><?php 
                        } elseif ($_smarty_tpl->tpl_vars['RELATED_HEADERNAME']->value == 'access_count') {
                            echo $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getAccessCountValue($_smarty_tpl->tpl_vars['PARENT_RECORD']->value->getId());
                        } elseif ($_smarty_tpl->tpl_vars['RELATED_HEADERNAME']->value == 'time_start') {
                        } elseif ($_smarty_tpl->tpl_vars['RELATED_HEADERNAME']->value == 'listprice' || $_smarty_tpl->tpl_vars['RELATED_HEADERNAME']->value == 'unit_price') {
                            echo CurrencyField::convertToUserFormat($_smarty_tpl->tpl_vars['RELATED_RECORD']->value->get($_smarty_tpl->tpl_vars['RELATED_HEADERNAME']->value), null, true);
                            if ($_smarty_tpl->tpl_vars['RELATED_HEADERNAME']->value == 'listprice') {
                                $_smarty_tpl->tpl_vars["LISTPRICE"] = new Smarty_variable(CurrencyField::convertToUserFormat($_smarty_tpl->tpl_vars['RELATED_RECORD']->value->get($_smarty_tpl->tpl_vars['RELATED_HEADERNAME']->value), null, true), null, 0);
                            }
                        } elseif ($_smarty_tpl->tpl_vars['RELATED_HEADERNAME']->value == 'filename') {
                            echo $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->get($_smarty_tpl->tpl_vars['RELATED_HEADERNAME']->value);
                        } else {
                            echo $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getDisplayValue($_smarty_tpl->tpl_vars['RELATED_HEADERNAME']->value);
                        }
                        if ($_smarty_tpl->tpl_vars['HEADER_FIELD']->last) {
                            ?>
</td><td nowrap class="<?php 
                            echo $_smarty_tpl->tpl_vars['WIDTHTYPE']->value;
                            ?>
"><div class="pull-right actions"><span class="actionImages"><?php 
                            if ($_smarty_tpl->tpl_vars['RELATED_MODULE_NAME']->value == 'Calendar') {
                                if ($_smarty_tpl->tpl_vars['IS_EDITABLE']->value && $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->get('taskstatus') != 'Held' && $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->get('taskstatus') != 'Completed') {
                                    ?>
<a class="markAsHeld"><i title="<?php 
                                    echo vtranslate('LBL_MARK_AS_HELD', $_smarty_tpl->tpl_vars['MODULE']->value);
                                    ?>
" class="icon-ok alignMiddle"></i></a>&nbsp;<?php 
                                }
                                if ($_smarty_tpl->tpl_vars['IS_EDITABLE']->value && $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->get('taskstatus') == 'Held') {
                                    ?>
<a class="holdFollowupOn"><i title="<?php 
                                    echo vtranslate('LBL_HOLD_FOLLOWUP_ON', "Events");
                                    ?>
" class="icon-flag alignMiddle"></i></a>&nbsp;<?php 
                                }
                                if ($_smarty_tpl->tpl_vars['DETAILVIEWPERMITTED']->value == 'yes') {
                                    ?>
<a href="<?php 
                                    echo $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getFullDetailViewUrl();
                                    ?>
"><i title="<?php 
                                    echo vtranslate('LBL_SHOW_COMPLETE_DETAILS', $_smarty_tpl->tpl_vars['MODULE']->value);
                                    ?>
" class="icon-th-list alignMiddle"></i></a>&nbsp;<?php 
                                }
                            } else {
                                ?>
<a href="<?php 
                                echo $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getFullDetailViewUrl();
                                ?>
"><i title="<?php 
                                echo vtranslate('LBL_SHOW_COMPLETE_DETAILS', $_smarty_tpl->tpl_vars['MODULE']->value);
                                ?>
" class="icon-th-list alignMiddle"></i></a>&nbsp;<?php 
                            }
                            if ($_smarty_tpl->tpl_vars['IS_EDITABLE']->value) {
                                if ($_smarty_tpl->tpl_vars['RELATED_MODULE_NAME']->value == 'PriceBooks') {
                                    ?>
<a data-url="index.php?module=PriceBooks&view=ListPriceUpdate&record=<?php 
                                    echo $_smarty_tpl->tpl_vars['PARENT_RECORD']->value->getId();
                                    ?>
&relid=<?php 
                                    echo $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getId();
                                    ?>
&currentPrice=<?php 
                                    echo $_smarty_tpl->tpl_vars['LISTPRICE']->value;
                                    ?>
"class="editListPrice cursorPointer" data-related-recordid='<?php 
                                    echo $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getId();
                                    ?>
' data-list-price=<?php 
                                    echo $_smarty_tpl->tpl_vars['LISTPRICE']->value;
                                    ?>
><i class="icon-pencil alignMiddle" title="<?php 
                                    echo vtranslate('LBL_EDIT', $_smarty_tpl->tpl_vars['MODULE']->value);
                                    ?>
"></i></a><?php 
                                } elseif ($_smarty_tpl->tpl_vars['RELATED_MODULE_NAME']->value == 'Calendar') {
                                    if (isPermitted($_smarty_tpl->tpl_vars['RELATED_MODULE']->value->get('name'), 'EditView', $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getId()) == 'yes') {
                                        ?>
<a href='<?php 
                                        echo $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getEditViewUrl();
                                        ?>
'><i title="<?php 
                                        echo vtranslate('LBL_EDIT', $_smarty_tpl->tpl_vars['MODULE']->value);
                                        ?>
" class="icon-pencil alignMiddle"></i></a><?php 
                                    }
                                } else {
                                    ?>
<a href='<?php 
                                    echo $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getEditViewUrl();
                                    ?>
'><i title="<?php 
                                    echo vtranslate('LBL_EDIT', $_smarty_tpl->tpl_vars['MODULE']->value);
                                    ?>
" class="icon-pencil alignMiddle"></i></a><?php 
                                }
                            }
                            if ($_smarty_tpl->tpl_vars['IS_DELETABLE']->value) {
                                if ($_smarty_tpl->tpl_vars['RELATED_MODULE_NAME']->value == 'Calendar') {
                                    if (isPermitted($_smarty_tpl->tpl_vars['RELATED_MODULE']->value->get('name'), 'Delete', $_smarty_tpl->tpl_vars['RELATED_RECORD']->value->getId()) == 'yes') {
                                        ?>
<a class="relationDelete"><i title="<?php 
                                        echo vtranslate('LBL_DELETE', $_smarty_tpl->tpl_vars['MODULE']->value);
                                        ?>
" class="icon-trash alignMiddle"></i></a><?php 
                                    }
                                } else {
                                    ?>
<a class="relationDelete"><i title="<?php 
                                    echo vtranslate('LBL_DELETE', $_smarty_tpl->tpl_vars['MODULE']->value);
                                    ?>
" class="icon-trash alignMiddle"></i></a><?php 
                                }
                            }
                            ?>
</span></div></td><?php 
                        }
                        ?>
</td><?php 
                    }
                }
                ?>
</tr><?php 
            }
        }
        ?>
</table></div></div></div>
<?php 
    }
Exemplo n.º 20
0
 function sanitizeCurrencyFieldsForInsert($row, $meta)
 {
     global $current_user;
     $moduleFields = $meta->getModuleFields();
     foreach ($moduleFields as $fieldName => $fieldObj) {
         if ($fieldObj->getFieldDataType() == "currency" && !empty($row[$fieldName])) {
             if ($fieldObj->getUIType() == '71') {
                 $row[$fieldName] = CurrencyField::convertToUserFormat($row[$fieldName], $current_user);
             } else {
                 if ($fieldObj->getUIType() == '72') {
                     $row[$fieldName] = CurrencyField::convertToUserFormat($row[$fieldName], $current_user, true);
                 }
             }
         }
     }
     return $row;
 }
Exemplo n.º 21
0
    function GenerateReport($outputformat, $filtersql, $directOutput = false, $startLimit = false, $endLimit = false)
    {
        global $adb, $current_user, $php_max_execution_time;
        global $modules, $app_strings;
        global $mod_strings;
        require 'user_privileges/user_privileges_' . $current_user->id . '.php';
        $modules_selected = array();
        $modules_selected[] = $this->primarymodule;
        if (!empty($this->secondarymodule)) {
            $sec_modules = split(":", $this->secondarymodule);
            for ($i = 0; $i < count($sec_modules); $i++) {
                $modules_selected[] = $sec_modules[$i];
            }
        }
        // Update Reference fields list list
        $referencefieldres = $adb->pquery("SELECT tabid, fieldlabel, uitype from vtiger_field WHERE uitype in (10,101)", array());
        if ($referencefieldres) {
            foreach ($referencefieldres as $referencefieldrow) {
                $uiType = $referencefieldrow['uitype'];
                $modprefixedlabel = getTabModuleName($referencefieldrow['tabid']) . ' ' . $referencefieldrow['fieldlabel'];
                $modprefixedlabel = str_replace(' ', '__', $modprefixedlabel);
                if ($uiType == 10 && !in_array($modprefixedlabel, $this->ui10_fields)) {
                    $this->ui10_fields[] = $modprefixedlabel;
                } elseif ($uiType == 101 && !in_array($modprefixedlabel, $this->ui101_fields)) {
                    $this->ui101_fields[] = $modprefixedlabel;
                }
            }
        }
        if ($outputformat == "HTML") {
            $sSQL = $this->sGetSQLforReport($this->reportid, $filtersql, $outputformat, false, $startLimit, $endLimit);
            $sSQL .= " LIMIT 0, " . (self::$HTMLVIEW_MAX_ROWS + 1);
            // Pull a record more than limit
            $result = $adb->query($sSQL);
            $error_msg = $adb->database->ErrorMsg();
            if (!$result && $error_msg != '') {
                // Performance Optimization: If direct output is requried
                if ($directOutput) {
                    echo getTranslatedString('LBL_REPORT_GENERATION_FAILED', $currentModule) . "<br>" . $error_msg;
                    $error_msg = false;
                }
                // END
                return $error_msg;
            }
            // Performance Optimization: If direct output is required
            if ($directOutput) {
                echo '<table cellpadding="5" cellspacing="0" align="center" class="rptTable"><tr>';
            }
            // END
            if ($is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1) {
                $picklistarray = $this->getAccessPickListValues();
            }
            if ($result) {
                $y = $adb->num_fields($result);
                $arrayHeaders = array();
                for ($x = 0; $x < $y; $x++) {
                    $fld = $adb->field_name($result, $x);
                    if (in_array($this->getLstringforReportHeaders($fld->name), $arrayHeaders)) {
                        $headerLabel = str_replace("__", " ", $fld->name);
                        $arrayHeaders[] = $headerLabel;
                    } else {
                        $headerLabel = str_replace($modules, " ", $this->getLstringforReportHeaders($fld->name));
                        $headerLabel = str_replace("__", " ", $this->getLstringforReportHeaders($fld->name));
                        $arrayHeaders[] = $headerLabel;
                    }
                    /*STRING TRANSLATION starts */
                    $mod_name = split(' ', $headerLabel, 2);
                    $moduleLabel = '';
                    if (in_array($mod_name[0], $modules_selected)) {
                        $moduleLabel = getTranslatedString($mod_name[0], $mod_name[0]);
                    }
                    if (!empty($this->secondarymodule)) {
                        if ($moduleLabel != '') {
                            $headerLabel_tmp = $moduleLabel . " " . getTranslatedString($mod_name[1], $mod_name[0]);
                        } else {
                            $headerLabel_tmp = getTranslatedString($mod_name[0] . " " . $mod_name[1]);
                        }
                    } else {
                        if ($moduleLabel != '') {
                            $headerLabel_tmp = getTranslatedString($mod_name[1], $mod_name[0]);
                        } else {
                            $headerLabel_tmp = getTranslatedString($mod_name[0] . " " . $mod_name[1]);
                        }
                    }
                    if ($headerLabel == $headerLabel_tmp) {
                        $headerLabel = getTranslatedString($headerLabel_tmp);
                    } else {
                        $headerLabel = $headerLabel_tmp;
                    }
                    /*STRING TRANSLATION ends */
                    $header .= "<td class='rptCellLabel'>" . $headerLabel . "</td>";
                    // Performance Optimization: If direct output is required
                    if ($directOutput) {
                        echo $header;
                        $header = '';
                    }
                    // END
                }
                // Performance Optimization: If direct output is required
                if ($directOutput) {
                    echo '</tr><tr>';
                }
                // END
                $noofrows = $adb->num_rows($result);
                $custom_field_values = $adb->fetch_array($result);
                $groupslist = $this->getGroupingList($this->reportid);
                $column_definitions = $adb->getFieldsDefinition($result);
                do {
                    $arraylists = array();
                    if (count($groupslist) == 1) {
                        $newvalue = $custom_field_values[0];
                    } elseif (count($groupslist) == 2) {
                        $newvalue = $custom_field_values[0];
                        $snewvalue = $custom_field_values[1];
                    } elseif (count($groupslist) == 3) {
                        $newvalue = $custom_field_values[0];
                        $snewvalue = $custom_field_values[1];
                        $tnewvalue = $custom_field_values[2];
                    }
                    if ($newvalue == "") {
                        $newvalue = "-";
                    }
                    if ($snewvalue == "") {
                        $snewvalue = "-";
                    }
                    if ($tnewvalue == "") {
                        $tnewvalue = "-";
                    }
                    $valtemplate .= "<tr>";
                    // Performance Optimization
                    if ($directOutput) {
                        echo $valtemplate;
                        $valtemplate = '';
                    }
                    // END
                    for ($i = 0; $i < $y; $i++) {
                        $fld = $adb->field_name($result, $i);
                        $fld_type = $column_definitions[$i]->type;
                        $fieldvalue = getReportFieldValue($this, $picklistarray, $fld, $custom_field_values, $i);
                        //check for Roll based pick list
                        $temp_val = $fld->name;
                        if ($fieldvalue == "") {
                            $fieldvalue = "-";
                        } else {
                            if ($fld->name == $this->primarymodule . '__LBL_ACTION' && $fieldvalue != '-') {
                                $fieldvalue = "<a href='index.php?module={$this->primarymodule}&action=DetailView&record={$fieldvalue}' target='_blank'>" . getTranslatedString('LBL_VIEW_DETAILS', 'Reports') . "</a>";
                            }
                        }
                        if ($lastvalue == $fieldvalue && $this->reporttype == "summary") {
                            if ($this->reporttype == "summary") {
                                $valtemplate .= "<td class='rptEmptyGrp'>&nbsp;</td>";
                            } else {
                                $valtemplate .= "<td class='rptData'>" . $fieldvalue . "</td>";
                            }
                        } else {
                            if ($secondvalue === $fieldvalue && $this->reporttype == "summary") {
                                if ($lastvalue === $newvalue) {
                                    $valtemplate .= "<td class='rptEmptyGrp'>&nbsp;</td>";
                                } else {
                                    $valtemplate .= "<td class='rptGrpHead'>" . $fieldvalue . "</td>";
                                }
                            } else {
                                if ($thirdvalue === $fieldvalue && $this->reporttype == "summary") {
                                    if ($secondvalue === $snewvalue) {
                                        $valtemplate .= "<td class='rptEmptyGrp'>&nbsp;</td>";
                                    } else {
                                        $valtemplate .= "<td class='rptGrpHead'>" . $fieldvalue . "</td>";
                                    }
                                } else {
                                    if ($this->reporttype == "tabular") {
                                        $valtemplate .= "<td class='rptData'>" . $fieldvalue . "</td>";
                                    } else {
                                        $valtemplate .= "<td class='rptGrpHead'>" . $fieldvalue . "</td>";
                                    }
                                }
                            }
                        }
                        // Performance Optimization: If direct output is required
                        if ($directOutput) {
                            echo $valtemplate;
                            $valtemplate = '';
                        }
                        // END
                    }
                    $valtemplate .= "</tr>";
                    // Performance Optimization: If direct output is required
                    if ($directOutput) {
                        echo $valtemplate;
                        $valtemplate = '';
                    }
                    // END
                    $lastvalue = $newvalue;
                    $secondvalue = $snewvalue;
                    $thirdvalue = $tnewvalue;
                    $arr_val[] = $arraylists;
                    set_time_limit($php_max_execution_time);
                } while ($custom_field_values = $adb->fetch_array($result));
                // Performance Optimization: Provide feedback on export option if required
                // NOTE: We should make sure to pull at-least 1 row more than max-limit for this to work.
                if ($noofrows > self::$HTMLVIEW_MAX_ROWS) {
                    // Performance Optimization: Output directly
                    if ($directOutput) {
                        echo '</tr></table><br><table width="100%" cellpading="0" cellspacing="0"><tr>';
                        echo sprintf('<td colspan="%s" align="right"><span class="genHeaderGray">%s</span></td>', $y, getTranslatedString('Only') . " " . self::$HTMLVIEW_MAX_ROWS . "+ " . getTranslatedString('records found') . ". " . getTranslatedString('Export to') . " <a href=\"javascript:;\" onclick=\"goToURL(CrearEnlace('ReportsAjax&file=CreateCSV',{$this->reportid}));\"><img style='vertical-align:text-top' src='themes/images/csv-file.png'></a> /" . " <a href=\"javascript:;\" onclick=\"goToURL(CrearEnlace('CreateXL',{$this->reportid}));\"><img style='vertical-align:text-top' src='themes/images/xls-file.jpg'></a>");
                    } else {
                        $valtemplate .= '</tr></table><br><table width="100%" cellpading="0" cellspacing="0"><tr>';
                        $valtemplate .= sprintf('<td colspan="%s" align="right"><span class="genHeaderGray">%s</span></td>', $y, getTranslatedString('Only') . " " . self::$HTMLVIEW_MAX_ROWS . " " . getTranslatedString('records found') . ". " . getTranslatedString('Export to') . " <a href=\"javascript:;\" onclick=\"goToURL(CrearEnlace('ReportsAjax&file=CreateCSV',{$this->reportid}));\"><img style='vertical-align:text-top' src='themes/images/csv-file.png'></a> /" . " <a href=\"javascript:;\" onclick=\"goToURL(CrearEnlace('CreateXL',{$this->reportid}));\"><img style='vertical-align:text-top' src='themes/images/xls-file.jpg'></a>");
                    }
                }
                // Performance Optimization
                if ($directOutput) {
                    $totalDisplayString = $noofrows;
                    if ($noofrows > self::$HTMLVIEW_MAX_ROWS) {
                        $totalDisplayString = self::$HTMLVIEW_MAX_ROWS . "+";
                    }
                    echo "</tr></table>";
                    echo "<script type='text/javascript' id='__reportrun_directoutput_recordcount_script'>\n\t\t\t\t\t\tif(\$('_reportrun_total')) \$('_reportrun_total').innerHTML='{$totalDisplayString}';</script>";
                } else {
                    $sHTML = '<table cellpadding="5" cellspacing="0" align="center" class="rptTable">
					<tr>' . $header . '<!-- BEGIN values -->
					<tr>' . $valtemplate . '</tr>
					</table>';
                }
                //<<<<<<<<construct HTML>>>>>>>>>>>>
                $return_data[] = $sHTML;
                $return_data[] = $noofrows;
                $return_data[] = $sSQL;
                return $return_data;
            }
        } elseif ($outputformat == "PDF") {
            $sSQL = $this->sGetSQLforReport($this->reportid, $filtersql, $outputformat, false, $startLimit, $endLimit);
            $result = $adb->pquery($sSQL, array());
            if ($is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1) {
                $picklistarray = $this->getAccessPickListValues();
            }
            if ($result) {
                $y = $adb->num_fields($result);
                $noofrows = $adb->num_rows($result);
                $custom_field_values = $adb->fetch_array($result);
                $column_definitions = $adb->getFieldsDefinition($result);
                do {
                    $arraylists = array();
                    for ($i = 0; $i < $y; $i++) {
                        $fld = $adb->field_name($result, $i);
                        $fld_type = $column_definitions[$i]->type;
                        list($module, $fieldLabel) = explode('__', $fld->name, 2);
                        $fieldInfo = getFieldByReportLabel($module, $fieldLabel);
                        $fieldType = null;
                        if (!empty($fieldInfo)) {
                            $field = WebserviceField::fromArray($adb, $fieldInfo);
                            $fieldType = $field->getFieldDataType();
                        }
                        if (!empty($fieldInfo)) {
                            $translatedLabel = getTranslatedString($field->getFieldLabelKey(), $module);
                        } else {
                            $fieldLabel = str_replace("__", " ", $fieldLabel);
                            $translatedLabel = getTranslatedString($fieldLabel, $module);
                        }
                        /*STRING TRANSLATION starts */
                        $moduleLabel = '';
                        if (in_array($module, $modules_selected)) {
                            $moduleLabel = getTranslatedString($module, $module);
                        }
                        if (empty($translatedLabel)) {
                            $translatedLabel = getTranslatedString(str_replace('__', " ", $fld->name), $module);
                        }
                        $headerLabel = $translatedLabel;
                        if (!empty($this->secondarymodule)) {
                            if ($moduleLabel != '') {
                                $headerLabel = $moduleLabel . " " . $translatedLabel;
                            }
                        }
                        // Check for role based pick list
                        $temp_val = $fld->name;
                        $fieldvalue = getReportFieldValue($this, $picklistarray, $fld, $custom_field_values, $i);
                        if ($fld->name == $this->primarymodule . '__LBL_ACTION' && $fieldvalue != '-') {
                            $fieldvalue = "<a href='index.php?module={$this->primarymodule}&view=Detail&record={$fieldvalue}' target='_blank'>" . getTranslatedString('LBL_VIEW_DETAILS', 'Reports') . "</a>";
                        }
                        $arraylists[$headerLabel] = $fieldvalue;
                    }
                    $arr_val[] = $arraylists;
                    set_time_limit($php_max_execution_time);
                } while ($custom_field_values = $adb->fetch_array($result));
                $data['data'] = $arr_val;
                $data['count'] = $noofrows;
                return $data;
            }
        } elseif ($outputformat == "TOTALXLS") {
            $escapedchars = array('__SUM', '__AVG', '__MIN', '__MAX');
            $totalpdf = array();
            $sSQL = $this->sGetSQLforReport($this->reportid, $filtersql, "COLUMNSTOTOTAL");
            if (isset($this->totallist)) {
                if ($sSQL != "") {
                    $result = $adb->query($sSQL);
                    $y = $adb->num_fields($result);
                    $custom_field_values = $adb->fetch_array($result);
                    foreach ($this->totallist as $key => $value) {
                        $fieldlist = explode(":", $key);
                        $mod_query = $adb->pquery("SELECT distinct(tabid) as tabid, uitype as uitype from vtiger_field where tablename = ? and columnname=?", array($fieldlist[1], $fieldlist[2]));
                        if ($adb->num_rows($mod_query) > 0) {
                            $module_name = getTabModuleName($adb->query_result($mod_query, 0, 'tabid'));
                            $fieldlabel = trim(str_replace($escapedchars, " ", $fieldlist[3]));
                            $fieldlabel = str_replace("__", " ", $fieldlabel);
                            if ($module_name) {
                                $field = getTranslatedString($module_name, $module_name) . " " . getTranslatedString($fieldlabel, $module_name);
                            } else {
                                $field = getTranslatedString($fieldlabel);
                            }
                        }
                        // Since there are duplicate entries for this table
                        if ($fieldlist[1] == 'vtiger_inventoryproductrel') {
                            $module_name = $this->primarymodule;
                        }
                        $uitype_arr[str_replace($escapedchars, " ", $module_name . "__" . $fieldlist[3])] = $adb->query_result($mod_query, 0, "uitype");
                        $totclmnflds[str_replace($escapedchars, " ", $module_name . "__" . $fieldlist[3])] = $field;
                    }
                    for ($i = 0; $i < $y; $i++) {
                        $fld = $adb->field_name($result, $i);
                        $keyhdr[$fld->name] = $custom_field_values[$i];
                    }
                    $rowcount = 0;
                    foreach ($totclmnflds as $key => $value) {
                        $col_header = trim(str_replace($modules, " ", $value));
                        $fld_name_1 = $this->primarymodule . "__" . trim($value);
                        $fld_name_2 = $this->secondarymodule . "__" . trim($value);
                        if ($uitype_arr[$key] == 71 || $uitype_arr[$key] == 72 || in_array($fld_name_1, $this->append_currency_symbol_to_value) || in_array($fld_name_2, $this->append_currency_symbol_to_value)) {
                            $col_header .= " (" . $app_strings['LBL_IN'] . " " . $current_user->currency_symbol . ")";
                            $convert_price = true;
                        } else {
                            $convert_price = false;
                        }
                        $value = trim($key);
                        $arraykey = $value . '__SUM';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $totalpdf[$rowcount][$arraykey] = $conv_value;
                        } else {
                            $totalpdf[$rowcount][$arraykey] = '';
                        }
                        $arraykey = $value . '__AVG';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $totalpdf[$rowcount][$arraykey] = $conv_value;
                        } else {
                            $totalpdf[$rowcount][$arraykey] = '';
                        }
                        $arraykey = $value . '__MIN';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $totalpdf[$rowcount][$arraykey] = $conv_value;
                        } else {
                            $totalpdf[$rowcount][$arraykey] = '';
                        }
                        $arraykey = $value . '__MAX';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $totalpdf[$rowcount][$arraykey] = $conv_value;
                        } else {
                            $totalpdf[$rowcount][$arraykey] = '';
                        }
                        $rowcount++;
                    }
                }
            }
            return $totalpdf;
        } elseif ($outputformat == "TOTALHTML") {
            $escapedchars = array('__SUM', '__AVG', '__MIN', '__MAX');
            $sSQL = $this->sGetSQLforReport($this->reportid, $filtersql, "COLUMNSTOTOTAL");
            static $modulename_cache = array();
            if (isset($this->totallist)) {
                if ($sSQL != "") {
                    $result = $adb->query($sSQL);
                    $y = $adb->num_fields($result);
                    $custom_field_values = $adb->fetch_array($result);
                    $coltotalhtml .= "<table align='center' width='60%' cellpadding='3' cellspacing='0' border='0' class='rptTable'><tr><td class='rptCellLabel'>" . $mod_strings[Totals] . "</td><td class='rptCellLabel'>" . $mod_strings[SUM] . "</td><td class='rptCellLabel'>" . $mod_strings[AVG] . "</td><td class='rptCellLabel'>" . $mod_strings[MIN] . "</td><td class='rptCellLabel'>" . $mod_strings[MAX] . "</td></tr>";
                    // Performation Optimization: If Direct output is desired
                    if ($directOutput) {
                        echo $coltotalhtml;
                        $coltotalhtml = '';
                    }
                    // END
                    foreach ($this->totallist as $key => $value) {
                        $fieldlist = explode(":", $key);
                        $module_name = NULL;
                        $cachekey = $fieldlist[1] . ":" . $fieldlist[2];
                        if (!isset($modulename_cache[$cachekey])) {
                            $mod_query = $adb->pquery("SELECT distinct(tabid) as tabid, uitype as uitype from vtiger_field where tablename = ? and columnname=?", array($fieldlist[1], $fieldlist[2]));
                            if ($adb->num_rows($mod_query) > 0) {
                                $module_name = getTabModuleName($adb->query_result($mod_query, 0, 'tabid'));
                                $modulename_cache[$cachekey] = $module_name;
                            }
                        } else {
                            $module_name = $modulename_cache[$cachekey];
                        }
                        if ($module_name) {
                            $fieldlabel = trim(str_replace($escapedchars, " ", $fieldlist[3]));
                            $fieldlabel = str_replace("__", " ", $fieldlabel);
                            $field = getTranslatedString($module_name, $module_name) . " " . getTranslatedString($fieldlabel, $module_name);
                        } else {
                            $field = getTranslatedString($fieldlabel);
                        }
                        $uitype_arr[str_replace($escapedchars, " ", $module_name . "__" . $fieldlist[3])] = $adb->query_result($mod_query, 0, "uitype");
                        $totclmnflds[str_replace($escapedchars, " ", $module_name . "__" . $fieldlist[3])] = $field;
                    }
                    for ($i = 0; $i < $y; $i++) {
                        $fld = $adb->field_name($result, $i);
                        $keyhdr[$fld->name] = $custom_field_values[$i];
                    }
                    foreach ($totclmnflds as $key => $value) {
                        $coltotalhtml .= '<tr class="rptGrpHead" valign=top>';
                        $col_header = trim(str_replace($modules, " ", $value));
                        $fld_name_1 = $this->primarymodule . "__" . trim($value);
                        $fld_name_2 = $this->secondarymodule . "__" . trim($value);
                        if ($uitype_arr[$key] == 71 || $uitype_arr[$key] == 72 || in_array($fld_name_1, $this->append_currency_symbol_to_value) || in_array($fld_name_2, $this->append_currency_symbol_to_value)) {
                            $col_header .= " (" . $app_strings['LBL_IN'] . " " . $current_user->currency_symbol . ")";
                            $convert_price = true;
                        } else {
                            $convert_price = false;
                        }
                        $coltotalhtml .= '<td class="rptData">' . $col_header . '</td>';
                        $value = trim($key);
                        $arraykey = $value . '__SUM';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $coltotalhtml .= '<td class="rptTotal">' . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= '<td class="rptTotal">&nbsp;</td>';
                        }
                        $arraykey = $value . '__AVG';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $coltotalhtml .= '<td class="rptTotal">' . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= '<td class="rptTotal">&nbsp;</td>';
                        }
                        $arraykey = $value . '__MIN';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $coltotalhtml .= '<td class="rptTotal">' . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= '<td class="rptTotal">&nbsp;</td>';
                        }
                        $arraykey = $value . '__MAX';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $coltotalhtml .= '<td class="rptTotal">' . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= '<td class="rptTotal">&nbsp;</td>';
                        }
                        $coltotalhtml .= '<tr>';
                        // Performation Optimization: If Direct output is desired
                        if ($directOutput) {
                            echo $coltotalhtml;
                            $coltotalhtml = '';
                        }
                        // END
                    }
                    $coltotalhtml .= "</table>";
                    // Performation Optimization: If Direct output is desired
                    if ($directOutput) {
                        echo $coltotalhtml;
                        $coltotalhtml = '';
                    }
                    // END
                }
            }
            return $coltotalhtml;
        } elseif ($outputformat == "PRINT") {
            $sSQL = $this->sGetSQLforReport($this->reportid, $filtersql, $outputformat);
            $result = $adb->query($sSQL);
            if ($is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1) {
                $picklistarray = $this->getAccessPickListValues();
            }
            if ($result) {
                $y = $adb->num_fields($result);
                $arrayHeaders = array();
                for ($x = 0; $x < $y - 1; $x++) {
                    $fld = $adb->field_name($result, $x);
                    if (in_array($this->getLstringforReportHeaders($fld->name), $arrayHeaders)) {
                        $headerLabel = str_replace("__", " ", $fld->name);
                        $arrayHeaders[] = $headerLabel;
                    } else {
                        $headerLabel = str_replace($modules, " ", $this->getLstringforReportHeaders($fld->name));
                        $headerLabel = str_replace("__", " ", $this->getLstringforReportHeaders($fld->name));
                        $arrayHeaders[] = $headerLabel;
                    }
                    /*STRING TRANSLATION starts */
                    $mod_name = split(' ', $headerLabel, 2);
                    $moduleLabel = '';
                    if (in_array($mod_name[0], $modules_selected)) {
                        $moduleLabel = getTranslatedString($mod_name[0], $mod_name[0]);
                    }
                    if (!empty($this->secondarymodule)) {
                        if ($moduleLabel != '') {
                            $headerLabel_tmp = $moduleLabel . " " . getTranslatedString($mod_name[1], $mod_name[0]);
                        } else {
                            $headerLabel_tmp = getTranslatedString($mod_name[0] . " " . $mod_name[1]);
                        }
                    } else {
                        if ($moduleLabel != '') {
                            $headerLabel_tmp = getTranslatedString($mod_name[1], $mod_name[0]);
                        } else {
                            $headerLabel_tmp = getTranslatedString($mod_name[0] . " " . $mod_name[1]);
                        }
                    }
                    if ($headerLabel == $headerLabel_tmp) {
                        $headerLabel = getTranslatedString($headerLabel_tmp);
                    } else {
                        $headerLabel = $headerLabel_tmp;
                    }
                    /*STRING TRANSLATION ends */
                    $header .= "<th>" . $headerLabel . "</th>";
                }
                $noofrows = $adb->num_rows($result);
                $custom_field_values = $adb->fetch_array($result);
                $groupslist = $this->getGroupingList($this->reportid);
                $column_definitions = $adb->getFieldsDefinition($result);
                do {
                    $arraylists = array();
                    if (count($groupslist) == 1) {
                        $newvalue = $custom_field_values[0];
                    } elseif (count($groupslist) == 2) {
                        $newvalue = $custom_field_values[0];
                        $snewvalue = $custom_field_values[1];
                    } elseif (count($groupslist) == 3) {
                        $newvalue = $custom_field_values[0];
                        $snewvalue = $custom_field_values[1];
                        $tnewvalue = $custom_field_values[2];
                    }
                    if ($newvalue == "") {
                        $newvalue = "-";
                    }
                    if ($snewvalue == "") {
                        $snewvalue = "-";
                    }
                    if ($tnewvalue == "") {
                        $tnewvalue = "-";
                    }
                    $valtemplate .= "<tr>";
                    for ($i = 0; $i < $y - 1; $i++) {
                        $fld = $adb->field_name($result, $i);
                        $fld_type = $column_definitions[$i]->type;
                        $fieldvalue = getReportFieldValue($this, $picklistarray, $fld, $custom_field_values, $i);
                        if ($lastvalue == $fieldvalue && $this->reporttype == "summary") {
                            if ($this->reporttype == "summary") {
                                $valtemplate .= "<td style='border-top:1px dotted #FFFFFF;'>&nbsp;</td>";
                            } else {
                                $valtemplate .= "<td>" . $fieldvalue . "</td>";
                            }
                        } else {
                            if ($secondvalue == $fieldvalue && $this->reporttype == "summary") {
                                if ($lastvalue == $newvalue) {
                                    $valtemplate .= "<td style='border-top:1px dotted #FFFFFF;'>&nbsp;</td>";
                                } else {
                                    $valtemplate .= "<td>" . $fieldvalue . "</td>";
                                }
                            } else {
                                if ($thirdvalue == $fieldvalue && $this->reporttype == "summary") {
                                    if ($secondvalue == $snewvalue) {
                                        $valtemplate .= "<td style='border-top:1px dotted #FFFFFF;'>&nbsp;</td>";
                                    } else {
                                        $valtemplate .= "<td>" . $fieldvalue . "</td>";
                                    }
                                } else {
                                    if ($this->reporttype == "tabular") {
                                        $valtemplate .= "<td>" . $fieldvalue . "</td>";
                                    } else {
                                        $valtemplate .= "<td>" . $fieldvalue . "</td>";
                                    }
                                }
                            }
                        }
                    }
                    $valtemplate .= "</tr>";
                    $lastvalue = $newvalue;
                    $secondvalue = $snewvalue;
                    $thirdvalue = $tnewvalue;
                    $arr_val[] = $arraylists;
                    set_time_limit($php_max_execution_time);
                } while ($custom_field_values = $adb->fetch_array($result));
                $sHTML = '<tr>' . $header . '</tr>' . $valtemplate;
                $return_data[] = $sHTML;
                $return_data[] = $noofrows;
                return $return_data;
            }
        } elseif ($outputformat == "PRINT_TOTAL") {
            $escapedchars = array('__SUM', '__AVG', '__MIN', '__MAX');
            $sSQL = $this->sGetSQLforReport($this->reportid, $filtersql, "COLUMNSTOTOTAL");
            if (isset($this->totallist)) {
                if ($sSQL != "") {
                    $result = $adb->query($sSQL);
                    $y = $adb->num_fields($result);
                    $custom_field_values = $adb->fetch_array($result);
                    $coltotalhtml .= "<br /><table align='center' width='60%' cellpadding='3' cellspacing='0' border='1' class='printReport'><tr><td class='rptCellLabel'>" . $mod_strings['Totals'] . "</td><td><b>" . $mod_strings['SUM'] . "</b></td><td><b>" . $mod_strings['AVG'] . "</b></td><td><b>" . $mod_strings['MIN'] . "</b></td><td><b>" . $mod_strings['MAX'] . "</b></td></tr>";
                    // Performation Optimization: If Direct output is desired
                    if ($directOutput) {
                        echo $coltotalhtml;
                        $coltotalhtml = '';
                    }
                    // END
                    foreach ($this->totallist as $key => $value) {
                        $fieldlist = explode(":", $key);
                        $mod_query = $adb->pquery("SELECT distinct(tabid) as tabid, uitype as uitype from vtiger_field where tablename = ? and columnname=?", array($fieldlist[1], $fieldlist[2]));
                        if ($adb->num_rows($mod_query) > 0) {
                            $module_name = getTabModuleName($adb->query_result($mod_query, 0, 'tabid'));
                            $fieldlabel = trim(str_replace($escapedchars, " ", $fieldlist[3]));
                            $fieldlabel = str_replace("__", " ", $fieldlabel);
                            if ($module_name) {
                                $field = getTranslatedString($module_name, $module_name) . " " . getTranslatedString($fieldlabel, $module_name);
                            } else {
                                $field = getTranslatedString($fieldlabel);
                            }
                        }
                        $uitype_arr[str_replace($escapedchars, " ", $module_name . "__" . $fieldlist[3])] = $adb->query_result($mod_query, 0, "uitype");
                        $totclmnflds[str_replace($escapedchars, " ", $module_name . "__" . $fieldlist[3])] = $field;
                    }
                    for ($i = 0; $i < $y; $i++) {
                        $fld = $adb->field_name($result, $i);
                        $keyhdr[$fld->name] = $custom_field_values[$i];
                    }
                    foreach ($totclmnflds as $key => $value) {
                        $coltotalhtml .= '<tr class="rptGrpHead">';
                        $col_header = getTranslatedString(trim(str_replace($modules, " ", $value)));
                        $fld_name_1 = $this->primarymodule . "__" . trim($value);
                        $fld_name_2 = $this->secondarymodule . "__" . trim($value);
                        if ($uitype_arr[$key] == 71 || $uitype_arr[$key] == 72 || in_array($fld_name_1, $this->append_currency_symbol_to_value) || in_array($fld_name_2, $this->append_currency_symbol_to_value)) {
                            $col_header .= " (" . $app_strings['LBL_IN'] . " " . $current_user->currency_symbol . ")";
                            $convert_price = true;
                        } else {
                            $convert_price = false;
                        }
                        $coltotalhtml .= '<td class="rptData">' . $col_header . '</td>';
                        $value = trim($key);
                        $arraykey = $value . '__SUM';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $coltotalhtml .= "<td class='rptTotal'>" . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= "<td class='rptTotal'>&nbsp;</td>";
                        }
                        $arraykey = $value . '__AVG';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $coltotalhtml .= "<td class='rptTotal'>" . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= "<td class='rptTotal'>&nbsp;</td>";
                        }
                        $arraykey = $value . '__MIN';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $coltotalhtml .= "<td class='rptTotal'>" . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= "<td class='rptTotal'>&nbsp;</td>";
                        }
                        $arraykey = $value . '__MAX';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $coltotalhtml .= "<td class='rptTotal'>" . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= "<td class='rptTotal'>&nbsp;</td>";
                        }
                        $coltotalhtml .= '</tr>';
                        // Performation Optimization: If Direct output is desired
                        if ($directOutput) {
                            echo $coltotalhtml;
                            $coltotalhtml = '';
                        }
                        // END
                    }
                    $coltotalhtml .= "</table>";
                    // Performation Optimization: If Direct output is desired
                    if ($directOutput) {
                        echo $coltotalhtml;
                        $coltotalhtml = '';
                    }
                    // END
                }
            }
            return $coltotalhtml;
        }
    }
Exemplo n.º 22
0
 /**
  * Getting value to display
  * @param type $value
  * @return type
  */
 public function getDisplayValue($value)
 {
     return CurrencyField::convertToUserFormat($value, null, true);
 }
Exemplo n.º 23
0
/** This function returns a HTML output of associated vtiger_products for a given entity (Quotes,Invoice,Sales order or Purchase order)
 * Param $module - module name
 * Param $focus - module object
 * Return type string
 */
function getDetailAssociatedProducts($module, $focus)
{
    global $log;
    $log->debug("Entering getDetailAssociatedProducts(" . $module . "," . get_class($focus) . ") method ...");
    global $adb;
    global $mod_strings;
    global $theme;
    global $log;
    global $app_strings, $current_user;
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    if (vtlib_isModuleActive("Products")) {
        $hide_stock = 'no';
    } else {
        $hide_stock = 'yes';
    }
    if ($module != 'PurchaseOrder') {
        if (GlobalVariable::getVariable('B2B', '1') == '1') {
            $acvid = $focus->column_fields['account_id'];
        } else {
            $acvid = $focus->column_fields['contact_id'];
        }
        if ($hide_stock == 'no') {
            $colspan = '2';
        } else {
            $colspan = '1';
        }
    } else {
        $acvid = $focus->column_fields['vendor_id'];
        $colspan = '1';
    }
    //Get the taxtype of this entity
    $taxtype = getInventoryTaxType($module, $focus->id);
    $currencytype = getInventoryCurrencyInfo($module, $focus->id);
    $output = '';
    //Header Rows
    $output .= '

	<table width="100%"  border="0" align="center" cellpadding="5" cellspacing="0" class="crmTable" id="proTab">
	   <tr valign="top">
	   	<td colspan="' . $colspan . '" class="dvInnerHeader"><b>' . $app_strings['LBL_ITEM_DETAILS'] . '</b></td>
		<td class="dvInnerHeader" align="center" colspan="2"><b>' . $app_strings['LBL_CURRENCY'] . ' : </b>' . getTranslatedCurrencyString($currencytype['currency_name']) . ' (' . $currencytype['currency_symbol'] . ')
		</td>
		<td class="dvInnerHeader" align="center" colspan="2"><b>' . $app_strings['LBL_TAX_MODE'] . ' : </b>' . $app_strings[$taxtype] . '
		</td>
	   </tr>
	   <tr valign="top">
		<td width=40% class="lvtCol"><font color="red">*</font>
			<b>' . $app_strings['LBL_ITEM_NAME'] . '</b>
		</td>';
    //Add Quantity in Stock column for SO, Quotes and Invoice
    if (($module == 'Quotes' || $module == 'SalesOrder' || $module == 'Invoice') && $hide_stock == 'no') {
        $output .= '<td width=10% class="lvtCol"><b>' . $app_strings['LBL_QTY_IN_STOCK'] . '</b></td>';
    }
    $output .= '

		<td width=10% class="lvtCol"><b>' . $app_strings['LBL_QTY'] . '</b></td>
		<td width=10% class="lvtCol" align="right"><b>' . $app_strings['LBL_LIST_PRICE'] . '</b></td>
		<td width=12% nowrap class="lvtCol" align="right"><b>' . $app_strings['LBL_TOTAL'] . '</b></td>
		<td width=13% valign="top" class="lvtCol" align="right"><b>' . $app_strings['LBL_NET_PRICE'] . '</b></td>
	   </tr>
	   	';
    // DG 15 Aug 2006
    // Add "ORDER BY sequence_no" to retain add order on all inventoryproductrel items
    if ($module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Invoice') {
        $query = "select case when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname," . " case when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype," . " case when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price," . " case when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock, vtiger_inventoryproductrel.* " . " from vtiger_inventoryproductrel" . " left join vtiger_products on vtiger_products.productid=vtiger_inventoryproductrel.productid " . " left join vtiger_service on vtiger_service.serviceid=vtiger_inventoryproductrel.productid " . " where id=? ORDER BY sequence_no";
    }
    $result = $adb->pquery($query, array($focus->id));
    $num_rows = $adb->num_rows($result);
    $netTotal = '0.00';
    for ($i = 1; $i <= $num_rows; $i++) {
        $sub_prod_query = $adb->pquery("SELECT productid from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($focus->id, $i));
        $subprodname_str = '';
        if ($adb->num_rows($sub_prod_query) > 0) {
            for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) {
                $sprod_id = $adb->query_result($sub_prod_query, $j, 'productid');
                $sprod_name = getProductName($sprod_id);
                $str_sep = "";
                if ($j > 0) {
                    $str_sep = ":";
                }
                $subprodname_str .= $str_sep . " - " . $sprod_name;
            }
        }
        $subprodname_str = str_replace(":", "<br>", $subprodname_str);
        $productid = $adb->query_result($result, $i - 1, 'productid');
        $entitytype = $adb->query_result($result, $i - 1, 'entitytype');
        $productname = $adb->query_result($result, $i - 1, 'productname');
        $productname = '<a href="index.php?action=DetailView&record=' . $productid . '&module=' . $entitytype . '">' . $productname . '</a>';
        if ($subprodname_str != '') {
            $productname .= "<br/><span style='color:#C0C0C0;font-style:italic;'>" . $subprodname_str . "</span>";
        }
        $comment = $adb->query_result($result, $i - 1, 'comment');
        $qtyinstock = $adb->query_result($result, $i - 1, 'qtyinstock');
        $qty = $adb->query_result($result, $i - 1, 'quantity');
        $qty = number_format($qty, 2, '.', '');
        //Convert to 2 decimals
        $unitprice = $adb->query_result($result, $i - 1, 'unit_price');
        $listprice = $adb->query_result($result, $i - 1, 'listprice');
        $total = $qty * $listprice;
        $listprice = number_format($listprice, 2, '.', '');
        //Convert to 2 decimals
        //Product wise Discount calculation - starts
        $discount_percent = $adb->query_result($result, $i - 1, 'discount_percent');
        $discount_amount = $adb->query_result($result, $i - 1, 'discount_amount');
        $totalAfterDiscount = $total;
        $productDiscount = '0.00';
        if ($discount_percent != 'NULL' && $discount_percent != '') {
            $productDiscount = $total * $discount_percent / 100;
            $productDiscount = number_format($productDiscount, 2, '.', '');
            $totalAfterDiscount = $total - $productDiscount;
            //if discount is percent then show the percentage
            $discount_info_message = "{$discount_percent} % of " . CurrencyField::convertToUserFormat($total, null, true) . " = " . CurrencyField::convertToUserFormat($productDiscount, null, true);
        } elseif ($discount_amount != 'NULL' && $discount_amount != '') {
            $productDiscount = $discount_amount;
            $productDiscount = number_format($productDiscount, 2, '.', '');
            $totalAfterDiscount = $total - $productDiscount;
            $discount_info_message = $app_strings['LBL_DIRECT_AMOUNT_DISCOUNT'] . " = " . CurrencyField::convertToUserFormat($productDiscount, null, true);
        } else {
            $discount_info_message = $app_strings['LBL_NO_DISCOUNT_FOR_THIS_LINE_ITEM'];
        }
        //Product wise Discount calculation - ends
        $totalAfterDiscount = number_format($totalAfterDiscount, 2, '.', '');
        //Convert to 2 decimals
        $netprice = $totalAfterDiscount;
        //Calculate the individual tax if taxtype is individual
        if ($taxtype == 'individual') {
            $taxtotal = '0.00';
            $tax_info_message = $app_strings['LBL_TOTAL_AFTER_DISCOUNT'] . " = " . CurrencyField::convertToUserFormat($totalAfterDiscount, null, true) . " \\n";
            $tax_details = getTaxDetailsForProduct($productid, 'all', $acvid);
            for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
                $tax_name = $tax_details[$tax_count]['taxname'];
                $tax_label = $tax_details[$tax_count]['taxlabel'];
                $tax_value = getInventoryProductTaxValue($focus->id, $productid, $tax_name);
                $individual_taxamount = $totalAfterDiscount * $tax_value / 100;
                $individual_taxamount = number_format($individual_taxamount, 2, '.', '');
                //Convert to 2 decimals
                $taxtotal = $taxtotal + $individual_taxamount;
                $taxtotal = number_format($taxtotal, 2, '.', '');
                //Convert to 2 decimals
                $tax_info_message .= "{$tax_label} : {$tax_value} % = " . CurrencyField::convertToUserFormat($individual_taxamount, null, true) . " \\n";
            }
            $tax_info_message .= "\\n " . $app_strings['LBL_TOTAL_TAX_AMOUNT'] . " = " . CurrencyField::convertToUserFormat($taxtotal, null, true);
            $netprice = $netprice + $taxtotal;
            $netprice = number_format($netprice, 2, '.', '');
            //Convert to 2 decimals
        }
        $sc_image_tag = '';
        if ($module == 'Invoice') {
            switch ($entitytype) {
                case 'Services':
                    if (vtlib_isModuleActive('ServiceContracts')) {
                        $sc_image_tag = '<a href="index.php?module=ServiceContracts&action=EditView&service_id=' . $productid . '&sc_related_to=' . $focus->column_fields['account_id'] . '&start_date=' . DateTimeField::convertToUserFormat($focus->column_fields['invoicedate']) . '&return_module=' . $module . '&return_id=' . $focus->id . '">' . '<img border="0" src="' . vtiger_imageurl('handshake.gif', $theme) . '" title="' . getTranslatedString('LBL_ADD_NEW', $module) . " " . getTranslatedString('ServiceContracts', 'ServiceContracts') . '" style="cursor: pointer;" align="absmiddle" />' . '</a>';
                    }
                    break;
                case 'Products':
                    if (vtlib_isModuleActive('Assets')) {
                        $sc_image_tag = '<a href="index.php?module=Assets&action=EditView&invoiceid=' . $focus->id . '&product=' . $productid . '&account=' . $focus->column_fields['account_id'] . '&datesold=' . DateTimeField::convertToUserFormat($focus->column_fields['invoicedate']) . '&return_module=' . $module . '&return_id=' . $focus->id . '" onmouseout="vtlib_listview.trigger(\'invoiceasset.onmouseout\', $(this))" onmouseover="vtlib_listview.trigger(\'cell.onmouseover\', $(this))">' . '<img border="0" src="' . vtiger_imageurl('barcode.png', $theme) . '" title="' . getTranslatedString('LBL_ADD_NEW', $module) . " " . getTranslatedString('Assets', 'Assets') . '" style="cursor: pointer;" align="absmiddle" />' . '<span style="display:none;" vtmodule="Assets" vtfieldname="invoice_product" vtrecordid="' . $focus->id . '::' . $productid . '::' . $i . '" type="vtlib_metainfo"></span>' . '</a>';
                    }
                    break;
                default:
                    $sc_image_tag = '';
            }
        }
        //For Product Name
        $output .= '
			   <tr valign="top">
				<td class="crmTableRow small lineOnTop">
					' . $productname . '&nbsp;' . $sc_image_tag . '
					<br>' . $comment . '
				</td>';
        //Upto this added to display the Product name and comment
        if ($module != 'PurchaseOrder' && $hide_stock == 'no') {
            $output .= '<td class="crmTableRow small lineOnTop">' . $qtyinstock . '</td>';
        }
        $output .= '<td class="crmTableRow small lineOnTop">' . $qty . '</td>';
        $output .= '
			<td class="crmTableRow small lineOnTop" align="right">
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
				   <tr>
				   	<td align="right">' . CurrencyField::convertToUserFormat($listprice, null, true) . '</td>
				   </tr>
				   <tr>
					   <td align="right">(-)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $discount_info_message . '\'); ">' . $app_strings['LBL_DISCOUNT'] . ' : </a></b></td>
				   </tr>
				   <tr>
				   	<td align="right" nowrap>' . $app_strings['LBL_TOTAL_AFTER_DISCOUNT'] . ' : </td>
				   </tr>';
        if ($taxtype == 'individual') {
            $output .= '
				   <tr>
					   <td align="right" nowrap>(+)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $tax_info_message . '\');">' . $app_strings['LBL_TAX'] . ' : </a></b></td>
				   </tr>';
        }
        $output .= '
				</table>
			</td>';
        $output .= '
			<td class="crmTableRow small lineOnTop" align="right">
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
				   <tr><td align="right">' . CurrencyField::convertToUserFormat($total, null, true) . '</td></tr>
				   <tr><td align="right">' . CurrencyField::convertToUserFormat($productDiscount, null, true) . '</td></tr>
				   <tr><td align="right" nowrap>' . CurrencyField::convertToUserFormat($totalAfterDiscount, null, true) . '</td></tr>';
        if ($taxtype == 'individual') {
            $output .= '<tr><td align="right" nowrap>' . CurrencyField::convertToUserFormat($taxtotal, null, true) . '</td></tr>';
        }
        $output .= '
				</table>
			</td>';
        $output .= '<td class="crmTableRow small lineOnTop" valign="bottom" align="right">' . CurrencyField::convertToUserFormat($netprice, null, true) . '</td>';
        $output .= '</tr>';
        $netTotal = $netTotal + $netprice;
    }
    $output .= '</table>';
    //$netTotal should be equal to $focus->column_fields['hdnSubTotal']
    $netTotal = $focus->column_fields['hdnSubTotal'];
    $netTotal = number_format($netTotal, 2, '.', '');
    //Convert to 2 decimals
    //Display the total, adjustment, S&H details
    $output .= '<table width="100%" border="0" cellspacing="0" cellpadding="5" class="crmTable">';
    $output .= '<tr>';
    $output .= '<td width="88%" class="crmTableRow small" align="right"><b>' . $app_strings['LBL_NET_TOTAL'] . '</td>';
    $output .= '<td width="12%" class="crmTableRow small" align="right"><b>' . CurrencyField::convertToUserFormat($netTotal, null, true) . '</b></td>';
    $output .= '</tr>';
    //Decide discount
    $finalDiscount = '0.00';
    $final_discount_info = '0';
    //if($focus->column_fields['hdnDiscountPercent'] != '') - previously (before changing to prepared statement) the selected option (either percent or amount) will have value and the other remains empty. So we can find the non selected item by empty check. But now with prepared statement, the non selected option stored as 0
    if ($focus->column_fields['hdnDiscountPercent'] != '0') {
        $finalDiscount = $netTotal * $focus->column_fields['hdnDiscountPercent'] / 100;
        $finalDiscount = number_format($finalDiscount, 2, '.', '');
        $final_discount_info = $focus->column_fields['hdnDiscountPercent'] . " % of " . CurrencyField::convertToUserFormat($netTotal, null, true) . " = " . CurrencyField::convertToUserFormat($finalDiscount, null, true);
    } elseif ($focus->column_fields['hdnDiscountAmount'] != '0') {
        $finalDiscount = $focus->column_fields['hdnDiscountAmount'];
        $finalDiscount = number_format($finalDiscount, 2, '.', '');
        $final_discount_info = CurrencyField::convertToUserFormat($finalDiscount, null, true);
    }
    //Alert the Final Discount amount even it is zero
    $final_discount_info = $app_strings['LBL_FINAL_DISCOUNT_AMOUNT'] . " = {$final_discount_info}";
    $final_discount_info = 'onclick="alert(\'' . $final_discount_info . '\');"';
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small lineOnTop">(-)&nbsp;<b><a href="javascript:;" ' . $final_discount_info . '>' . $app_strings['LBL_DISCOUNT'] . '</a></b></td>';
    $output .= '<td align="right" class="crmTableRow small lineOnTop">' . CurrencyField::convertToUserFormat($finalDiscount, null, true) . '</td>';
    $output .= '</tr>';
    if ($taxtype == 'group') {
        $taxtotal = '0.00';
        $final_totalAfterDiscount = $netTotal - $finalDiscount;
        $tax_info_message = $app_strings['LBL_TOTAL_AFTER_DISCOUNT'] . " = " . CurrencyField::convertToUserFormat($final_totalAfterDiscount, null, true) . " \\n";
        //First we should get all available taxes and then retrieve the corresponding tax values
        $tax_details = getAllTaxes('available', '', 'edit', $focus->id);
        $ipr_cols = $adb->getColumnNames('vtiger_inventoryproductrel');
        //if taxtype is group then the tax should be same for all products in vtiger_inventoryproductrel table
        for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
            $tax_name = $tax_details[$tax_count]['taxname'];
            $tax_label = $tax_details[$tax_count]['taxlabel'];
            if (in_array($tax_name, $ipr_cols)) {
                $tax_value = $adb->query_result($result, 0, $tax_name);
            } else {
                $tax_value = $tax_details[$tax_count]['percentage'];
            }
            if ($tax_value == '' || $tax_value == 'NULL') {
                $tax_value = '0.00';
            }
            $taxamount = ($netTotal - $finalDiscount) * $tax_value / 100;
            $taxtotal = $taxtotal + $taxamount;
            $tax_info_message .= "{$tax_label} : {$tax_value} % = " . CurrencyField::convertToUserFormat($taxtotal, null, true) . " \\n";
        }
        $tax_info_message .= "\\n " . $app_strings['LBL_TOTAL_TAX_AMOUNT'] . " = " . CurrencyField::convertToUserFormat($taxtotal, null, true);
        $output .= '<tr>';
        $output .= '<td align="right" class="crmTableRow small">(+)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $tax_info_message . '\');">' . $app_strings['LBL_TAX'] . '</a></b></td>';
        $output .= '<td align="right" class="crmTableRow small">' . CurrencyField::convertToUserFormat($taxtotal, null, true) . '</td>';
        $output .= '</tr>';
    }
    $shAmount = $focus->column_fields['hdnS_H_Amount'] != '' ? $focus->column_fields['hdnS_H_Amount'] : '0.00';
    $shAmount = number_format($shAmount, 2, '.', '');
    //Convert to 2 decimals
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small">(+)&nbsp;<b>' . $app_strings['LBL_SHIPPING_AND_HANDLING_CHARGES'] . '</b></td>';
    $output .= '<td align="right" class="crmTableRow small">' . CurrencyField::convertToUserFormat($shAmount, null, true) . '</td>';
    $output .= '</tr>';
    //calculate S&H tax
    $shtaxtotal = '0.00';
    //First we should get all available taxes and then retrieve the corresponding tax values
    $shtax_details = getAllTaxes('available', 'sh', 'edit', $focus->id);
    //if taxtype is group then the tax should be same for all products in vtiger_inventoryproductrel table
    $shtax_info_message = $app_strings['LBL_SHIPPING_AND_HANDLING_CHARGE'] . " = " . CurrencyField::convertToUserFormat($shAmount, null, true) . "\\n";
    for ($shtax_count = 0; $shtax_count < count($shtax_details); $shtax_count++) {
        $shtax_name = $shtax_details[$shtax_count]['taxname'];
        $shtax_label = $shtax_details[$shtax_count]['taxlabel'];
        $shtax_percent = getInventorySHTaxPercent($focus->id, $shtax_name);
        $shtaxamount = $shAmount * $shtax_percent / 100;
        $shtaxamount = number_format($shtaxamount, 2, '.', '');
        $shtaxtotal = $shtaxtotal + $shtaxamount;
        $shtax_info_message .= "{$shtax_label} : {$shtax_percent} % = " . CurrencyField::convertToUserFormat($shtaxamount, null, true) . " \\n";
    }
    $shtax_info_message .= "\\n " . $app_strings['LBL_TOTAL_TAX_AMOUNT'] . " = " . CurrencyField::convertToUserFormat($shtaxtotal, null, true);
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small">(+)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $shtax_info_message . '\')">' . $app_strings['LBL_TAX_FOR_SHIPPING_AND_HANDLING'] . '</a></b></td>';
    $output .= '<td align="right" class="crmTableRow small">' . CurrencyField::convertToUserFormat($shtaxtotal, null, true) . '</td>';
    $output .= '</tr>';
    $adjustment = $focus->column_fields['txtAdjustment'] != '' ? $focus->column_fields['txtAdjustment'] : '0.00';
    $adjustment = number_format($adjustment, 2, '.', '');
    //Convert to 2 decimals
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small">&nbsp;<b>' . $app_strings['LBL_ADJUSTMENT'] . '</b></td>';
    $output .= '<td align="right" class="crmTableRow small">' . CurrencyField::convertToUserFormat($adjustment, null, true) . '</td>';
    $output .= '</tr>';
    $grandTotal = $focus->column_fields['hdnGrandTotal'] != '' ? $focus->column_fields['hdnGrandTotal'] : '0.00';
    $grandTotal = number_format($grandTotal, 2, '.', '');
    //Convert to 2 decimals
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small lineOnTop"><b>' . $app_strings['LBL_GRAND_TOTAL'] . '</b></td>';
    $output .= '<td align="right" class="crmTableRow small lineOnTop">' . CurrencyField::convertToUserFormat($grandTotal, null, true) . '</td>';
    $output .= '</tr>';
    $output .= '</table>';
    $log->debug("Exiting getDetailAssociatedProducts method ...");
    return $output;
}
Exemplo n.º 24
0
/**
 *
 * @global Users $current_user
 * @param ReportRun $report
 * @param Array $picklistArray
 * @param ADOFieldObject $dbField
 * @param Array $valueArray
 * @param String $fieldName
 * @return String
 */
function getReportFieldValue($report, $picklistArray, $dbField, $valueArray, $fieldName)
{
    global $current_user, $default_charset;
    $db = PearDatabase::getInstance();
    $value = $valueArray[$fieldName];
    $fld_type = $dbField->type;
    list($module, $fieldLabel) = explode('__', $dbField->name, 2);
    $fieldInfo = getFieldByReportLabel($module, $fieldLabel);
    $fieldType = null;
    $fieldvalue = $value;
    if (!empty($fieldInfo)) {
        $field = WebserviceField::fromArray($db, $fieldInfo);
        $fieldType = $field->getFieldDataType();
    }
    if ($fieldType == 'currency' && $value != '') {
        // Some of the currency fields like Unit Price, Total, Sub-total etc of Inventory modules, do not need currency conversion
        if ($field->getUIType() == '72') {
            $curid_value = explode("::", $value);
            $currency_id = $curid_value[0];
            $currency_value = $curid_value[1];
            $cur_sym_rate = getCurrencySymbolandCRate($currency_id);
            if ($value != '') {
                if ($dbField->name == 'Products_Unit_Price') {
                    // need to do this only for Products Unit Price
                    if ($currency_id != 1) {
                        $currency_value = (double) $cur_sym_rate['rate'] * (double) $currency_value;
                    }
                }
                $formattedCurrencyValue = CurrencyField::convertToUserFormat($currency_value, null, true);
                $fieldvalue = CurrencyField::appendCurrencySymbol($formattedCurrencyValue, $cur_sym_rate['symbol']);
            }
        } else {
            $currencyField = new CurrencyField($value);
            $fieldvalue = $currencyField->getDisplayValue();
        }
    } elseif ($dbField->name == "PriceBooks_Currency") {
        if ($value != '') {
            $fieldvalue = getTranslatedCurrencyString($value);
        }
    } elseif (in_array($dbField->name, $report->ui101_fields) && !empty($value)) {
        $entityNames = getEntityName('Users', $value);
        $fieldvalue = $entityNames[$value];
    } elseif ($fieldType == 'date' && !empty($value)) {
        if ($module == 'Calendar' && $field->getFieldName() == 'due_date') {
            $endTime = $valueArray['calendar_end_time'];
            if (empty($endTime)) {
                $recordId = $valueArray['calendar_id'];
                $endTime = getSingleFieldValue('vtiger_activity', 'time_end', 'activityid', $recordId);
            }
            $date = new DateTimeField($value . ' ' . $endTime);
            $fieldvalue = $date->getDisplayDate();
        } else {
            if (!($field->getUIType() == '5')) {
                $date = new DateTimeField($fieldvalue);
                $fieldvalue = $date->getDisplayDateTimeValue();
            }
        }
    } elseif ($fieldType == "datetime" && !empty($value)) {
        $date = new DateTimeField($value);
        $fieldvalue = $date->getDisplayDateTimeValue();
    } elseif ($fieldType == 'time' && !empty($value) && $field->getFieldName() != 'duration_hours') {
        if ($field->getFieldName() == "time_start" || $field->getFieldName() == "time_end") {
            $date = new DateTimeField($value);
            $fieldvalue = $date->getDisplayTime();
        } else {
            $userModel = Users_Privileges_Model::getCurrentUserModel();
            if ($userModel->get('hour_format') == '12') {
                $value = Vtiger_Time_UIType::getTimeValueInAMorPM($value);
            }
            $fieldvalue = $value;
        }
    } elseif ($fieldType == "picklist" && !empty($value)) {
        if (is_array($picklistArray)) {
            if (is_array($picklistArray[$dbField->name]) && $field->getFieldName() != 'activitytype' && !in_array($value, $picklistArray[$dbField->name])) {
                $fieldvalue = $app_strings['LBL_NOT_ACCESSIBLE'];
            } else {
                $fieldvalue = getTranslatedString($value, $module);
            }
        } else {
            $fieldvalue = getTranslatedString($value, $module);
        }
    } elseif ($fieldType == "multipicklist" && !empty($value)) {
        if (is_array($picklistArray[1])) {
            $valueList = explode(' |##| ', $value);
            $translatedValueList = array();
            foreach ($valueList as $value) {
                if (is_array($picklistArray[1][$dbField->name]) && !in_array($value, $picklistArray[1][$dbField->name])) {
                    $translatedValueList[] = $app_strings['LBL_NOT_ACCESSIBLE'];
                } else {
                    $translatedValueList[] = getTranslatedString($value, $module);
                }
            }
        }
        if (!is_array($picklistArray[1]) || !is_array($picklistArray[1][$dbField->name])) {
            $fieldvalue = str_replace(' |##| ', ', ', $value);
        } else {
            implode(', ', $translatedValueList);
        }
    } elseif ($fieldType == 'double') {
        if ($current_user->truncate_trailing_zeros == true) {
            $fieldvalue = decimalFormat($fieldvalue);
        }
    } elseif ($fieldType == 'boolean') {
        if (strtolower($value) === 'yes' || strtolower($value) === 'on' || $value == 1) {
            $fieldvalue = vtranslate('LBL_YES');
        } else {
            $fieldvalue = vtranslate('LBL_NO');
        }
    } elseif ($field && $field->getUIType() == 117 && $value != '') {
        if ($value != '0') {
            $currencyList = Settings_Currency_Record_Model::getAll();
            $fieldvalue = $currencyList[$value]->getName() . ' (' . $currencyList[$value]->get('currency_symbol') . ')';
        } else {
            $fieldvalue = '-';
        }
    }
    if ('vtiger_crmentity' == $dbField->table && false != strpos($dbField->name, 'Share__with__users')) {
        if ($value) {
            $listId = explode(',', $value);
            $usersSqlFullName = getSqlForNameInDisplayFormat(['first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'], 'Users');
            $getListUserSql = "select {$usersSqlFullName} as uname from vtiger_users WHERE id IN (" . generateQuestionMarks($listId) . ') ';
            $getListUserResult = $db->pquery($getListUserSql, array($listId), TRUE);
            $fieldvalue = '';
            $finalList = array();
            $listUsers = $getListUserResult->GetAll();
            for ($i = 0; $i < count($listUsers); $i++) {
                $finalList[] = $listUsers[$i][0];
            }
            $fieldvalue = implode(', ', $finalList);
        }
    }
    if ($fieldvalue == "") {
        return "-";
    }
    $fieldvalue = str_replace("<", "&lt;", $fieldvalue);
    $fieldvalue = str_replace(">", "&gt;", $fieldvalue);
    $fieldvalue = decode_html($fieldvalue);
    if (stristr($fieldvalue, "|##|") && empty($fieldType)) {
        $fieldvalue = str_ireplace(' |##| ', ', ', $fieldvalue);
    } elseif ($fld_type == "date" && empty($fieldType)) {
        $fieldvalue = DateTimeField::convertToUserFormat($fieldvalue);
    } elseif ($fld_type == "datetime" && empty($fieldType)) {
        $date = new DateTimeField($fieldvalue);
        $fieldvalue = $date->getDisplayDateTimeValue();
    }
    // Added to render html tag for description fields
    if ($fieldInfo['uitype'] == '19' && ($module == 'Documents' || $module == 'Emails')) {
        return $fieldvalue;
    }
    return htmlentities($fieldvalue, ENT_QUOTES, $default_charset);
}
Exemplo n.º 25
0
 /**	Function to display the Services which are related to the PriceBook
  *	@param string $query - query to get the list of products which are related to the current PriceBook
  *	@param object $focus - PriceBook object which contains all the information of the current PriceBook
  *	@param string $returnset - return_module, return_action and return_id which are sequenced with & to pass to the URL which is optional
  *	return array $return_data which will be formed like array('header'=>$header,'entries'=>$entries_list) where as $header contains all the header columns and $entries_list will contain all the Service entries
  */
 function getPriceBookRelatedServices($query, $focus, $returnset = '')
 {
     global $log;
     $log->debug("Entering getPriceBookRelatedServices(" . $query . "," . get_class($focus) . "," . $returnset . ") method ...");
     global $adb;
     global $app_strings;
     global $current_language, $current_user;
     $current_module_strings = return_module_language($current_language, 'Services');
     global $list_max_entries_per_page;
     global $urlPrefix;
     global $theme;
     $pricebook_id = $_REQUEST['record'];
     $theme_path = "themes/" . $theme . "/";
     $image_path = $theme_path . "images/";
     $computeCount = $_REQUEST['withCount'];
     if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true || (bool) $computeCount == true) {
         $noofrows = $adb->query_result($adb->query(mkCountQuery($query)), 0, 'count');
     } else {
         $noofrows = null;
     }
     $module = 'PriceBooks';
     $relatedmodule = 'Services';
     if (!$_SESSION['rlvs'][$module][$relatedmodule]) {
         $modObj = new ListViewSession();
         $modObj->sortby = $focus->default_order_by;
         $modObj->sorder = $focus->default_sort_order;
         $_SESSION['rlvs'][$module][$relatedmodule] = get_object_vars($modObj);
     }
     if (isset($_REQUEST['relmodule']) && $_REQUEST['relmodule'] != '' && $_REQUEST['relmodule'] == $relatedmodule) {
         $relmodule = vtlib_purify($_REQUEST['relmodule']);
         if ($_SESSION['rlvs'][$module][$relmodule]) {
             setSessionVar($_SESSION['rlvs'][$module][$relmodule], $noofrows, $list_max_entries_per_page, $module, $relmodule);
         }
     }
     global $relationId;
     $start = RelatedListViewSession::getRequestCurrentPage($relationId, $query);
     $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows);
     $limit_start_rec = ($start - 1) * $list_max_entries_per_page;
     if ($adb->dbType == "pgsql") {
         $list_result = $adb->pquery($query . " OFFSET {$limit_start_rec} LIMIT {$list_max_entries_per_page}", array());
     } else {
         $list_result = $adb->pquery($query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array());
     }
     $header = array();
     $header[] = $current_module_strings['LBL_LIST_SERVICE_NAME'];
     if (getFieldVisibilityPermission('Services', $current_user->id, 'unit_price') == '0') {
         $header[] = $current_module_strings['LBL_SERVICE_UNIT_PRICE'];
     }
     $header[] = $current_module_strings['LBL_PB_LIST_PRICE'];
     if (isPermitted("PriceBooks", "EditView", "") == 'yes' || isPermitted("PriceBooks", "Delete", "") == 'yes') {
         $header[] = $app_strings['LBL_ACTION'];
     }
     $currency_id = $focus->column_fields['currency_id'];
     $numRows = $adb->num_rows($list_result);
     for ($i = 0; $i < $numRows; $i++) {
         $entity_id = $adb->query_result($list_result, $i, "crmid");
         $unit_price = $adb->query_result($list_result, $i, "unit_price");
         if ($currency_id != null) {
             $prod_prices = getPricesForProducts($currency_id, array($entity_id), 'Services');
             $unit_price = $prod_prices[$entity_id];
         }
         $listprice = $adb->query_result($list_result, $i, "listprice");
         $field_name = $entity_id . "_listprice";
         $entries = array();
         $entries[] = textlength_check($adb->query_result($list_result, $i, "servicename"));
         if (getFieldVisibilityPermission('Services', $current_user->id, 'unit_price') == '0') {
             $entries[] = CurrencyField::convertToUserFormat($unit_price, null, true);
         }
         $entries[] = CurrencyField::convertToUserFormat($listprice, null, true);
         $action = "";
         if (isPermitted("PriceBooks", "EditView", "") == 'yes' && isPermitted('Services', 'EditView', $entity_id) == 'yes') {
             $action .= '<img style="cursor:pointer;" src="themes/images/editfield.gif" border="0" onClick="fnvshobj(this,\'editlistprice\'),editProductListPrice(\'' . $entity_id . '\',\'' . $pricebook_id . '\',\'' . $listprice . '\')" alt="' . $app_strings["LBL_EDIT_BUTTON"] . '" title="' . $app_strings["LBL_EDIT_BUTTON"] . '"/>';
         } else {
             $action .= '<img src="' . vtiger_imageurl('blank.gif', $theme) . '" border="0" />';
         }
         if (isPermitted("PriceBooks", "Delete", "") == 'yes' && isPermitted('Services', 'Delete', $entity_id) == 'yes') {
             if ($action != "") {
                 $action .= '&nbsp;|&nbsp;';
             }
             $action .= '<img src="themes/images/delete.gif" onclick="if(confirm(\'' . $app_strings['ARE_YOU_SURE'] . '\')) deletePriceBookProductRel(' . $entity_id . ',' . $pricebook_id . ');" alt="' . $app_strings["LBL_DELETE"] . '" title="' . $app_strings["LBL_DELETE"] . '" style="cursor:pointer;" border="0">';
         }
         if ($action != "") {
             $entries[] = $action;
         }
         $entries_list[] = $entries;
     }
     $navigationOutput[] = getRecordRangeMessage($list_result, $limit_start_rec, $noofrows);
     $navigationOutput[] = getRelatedTableHeaderNavigation($navigation_array, '', $module, $relatedmodule, $focus->id);
     $return_data = array('header' => $header, 'entries' => $entries_list, 'navigation' => $navigationOutput);
     $log->debug("Exiting getPriceBookRelatedServices method ...");
     return $return_data;
 }
Exemplo n.º 26
0
    function GenerateReport($outputformat, $filtersql, $directOutput = false, &$returnfieldinfo = array())
    {
        global $adb, $current_user, $php_max_execution_time;
        global $modules, $app_strings, $mod_strings, $current_language;
        require 'user_privileges/user_privileges_' . $current_user->id . '.php';
        $picklistarray = array();
        $modules_selected = array();
        $modules_selected[] = $this->primarymodule;
        if (!empty($this->secondarymodule)) {
            $sec_modules = explode(":", $this->secondarymodule);
            for ($i = 0; $i < count($sec_modules); $i++) {
                $modules_selected[] = $sec_modules[$i];
            }
        }
        // Update Reference fields list list
        $referencefieldres = $adb->pquery("SELECT tabid, fieldlabel, uitype from vtiger_field WHERE uitype in (10,101)", array());
        if ($referencefieldres) {
            foreach ($referencefieldres as $referencefieldrow) {
                $uiType = $referencefieldrow['uitype'];
                $modprefixedlabel = getTabModuleName($referencefieldrow['tabid']) . ' ' . $referencefieldrow['fieldlabel'];
                $modprefixedlabel = str_replace(' ', '_', $modprefixedlabel);
                if ($uiType == 10 && !in_array($modprefixedlabel, $this->ui10_fields)) {
                    $this->ui10_fields[] = $modprefixedlabel;
                } elseif ($uiType == 101 && !in_array($modprefixedlabel, $this->ui101_fields)) {
                    $this->ui101_fields[] = $modprefixedlabel;
                }
            }
        }
        if ($outputformat == "HTML") {
            $sSQL = $this->sGetSQLforReport($this->reportid, $filtersql, $outputformat);
            $result = $adb->query($sSQL);
            $error_msg = $adb->database->ErrorMsg();
            if (!$result && $error_msg != '') {
                // Performance Optimization: If direct output is requried
                if ($directOutput) {
                    echo getTranslatedString('LBL_REPORT_GENERATION_FAILED', $currentModule) . "<br>" . $error_msg;
                    $error_msg = false;
                }
                // END
                return $error_msg;
            }
            // Performance Optimization: If direct output is required
            if ($directOutput) {
                echo '<table cellpadding="5" cellspacing="0" align="center" class="rptTable"><tr>';
            }
            // END
            if ($is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1) {
                $picklistarray = $this->getAccessPickListValues();
            }
            if ($result) {
                $y = $adb->num_fields($result);
                $noofrows = $adb->num_rows($result);
                $custom_field_values = $adb->fetch_array($result);
                $groupslist = $this->getGroupingList($this->reportid);
                $column_definitions = $adb->getFieldsDefinition($result);
                $arrayHeaders = array();
                $header = '';
                for ($x = 0; $x < $y; $x++) {
                    $fld = $adb->field_name($result, $x);
                    $fld_type = $column_definitions[$x]->type;
                    list($module, $fieldLabel) = explode('_', $fld->name, 2);
                    $fieldInfo = getFieldByReportLabel($module, $fieldLabel);
                    if (!empty($fieldInfo)) {
                        $field = WebserviceField::fromArray($adb, $fieldInfo);
                    }
                    if (!empty($fieldInfo)) {
                        $headerLabel = getTranslatedString($field->getFieldLabelKey(), $module);
                    } else {
                        $headerLabel = getTranslatedString(str_replace('_', " ", $fieldLabel), $module);
                    }
                    /*STRING TRANSLATION starts */
                    $moduleLabel = '';
                    if (in_array($module, $modules_selected)) {
                        $moduleLabel = getTranslatedString($module, $module);
                    }
                    if (empty($headerLabel)) {
                        $headerLabel = getTranslatedString(str_replace('_', " ", $fld->name));
                    }
                    if (!empty($this->secondarymodule)) {
                        if ($moduleLabel != '') {
                            $headerLabel = $moduleLabel . " " . $headerLabel;
                        }
                    }
                    $header .= "<td class='rptCellLabel'>" . $headerLabel . "</td>";
                    // Performance Optimization: If direct output is required
                    if ($directOutput) {
                        echo $header;
                        $header = '';
                    }
                    // END
                }
                // Performance Optimization: If direct output is required
                if ($directOutput) {
                    echo '</tr><tr>';
                }
                $valtemplate = '';
                $lastvalue = '';
                $secondvalue = '';
                $thirdvalue = '';
                $sHTML = '';
                do {
                    $arraylists = array();
                    $newvalue = '';
                    $snewvalue = '';
                    $tnewvalue = '';
                    if (count($groupslist) == 1) {
                        $newvalue = $custom_field_values[0];
                    } elseif (count($groupslist) == 2) {
                        $newvalue = $custom_field_values[0];
                        $snewvalue = $custom_field_values[1];
                    } elseif (count($groupslist) == 3) {
                        $newvalue = $custom_field_values[0];
                        $snewvalue = $custom_field_values[1];
                        $tnewvalue = $custom_field_values[2];
                    }
                    if ($newvalue == '') {
                        $newvalue = '-';
                    }
                    if ($snewvalue == '') {
                        $snewvalue = '-';
                    }
                    if ($tnewvalue == '') {
                        $tnewvalue = '-';
                    }
                    $valtemplate .= '<tr>';
                    // Performance Optimization
                    if ($directOutput) {
                        echo $valtemplate;
                        $valtemplate = '';
                    }
                    for ($i = 0; $i < $y; $i++) {
                        $fld = $adb->field_name($result, $i);
                        $fld_type = $column_definitions[$i]->type;
                        $fieldvalue = getReportFieldValue($this, $picklistarray, $fld, $custom_field_values, $i);
                        if ($fieldvalue == '') {
                            $fieldvalue = "-";
                        } else {
                            if ($fld->name == 'LBL_ACTION' && $fieldvalue != '-') {
                                $fieldvalue = "<a href='index.php?module={$this->primarymodule}&action=DetailView&record={$fieldvalue}' target='_blank'>" . getTranslatedString('LBL_VIEW_DETAILS') . "</a>";
                            }
                        }
                        if ($lastvalue == $fieldvalue && $this->reporttype == "summary") {
                            if ($this->reporttype == "summary") {
                                $valtemplate .= "<td class='rptEmptyGrp'>&nbsp;</td>";
                            } else {
                                $valtemplate .= "<td class='rptData'>" . $fieldvalue . "</td>";
                            }
                        } else {
                            if ($secondvalue === $fieldvalue && $this->reporttype == "summary") {
                                if ($lastvalue === $newvalue) {
                                    $valtemplate .= "<td class='rptEmptyGrp'>&nbsp;</td>";
                                } else {
                                    $valtemplate .= "<td class='rptGrpHead'>" . $fieldvalue . "</td>";
                                }
                            } else {
                                if ($thirdvalue === $fieldvalue && $this->reporttype == "summary") {
                                    if ($secondvalue === $snewvalue) {
                                        $valtemplate .= "<td class='rptEmptyGrp'>&nbsp;</td>";
                                    } else {
                                        $valtemplate .= "<td class='rptGrpHead'>" . $fieldvalue . "</td>";
                                    }
                                } else {
                                    if ($this->reporttype == "tabular") {
                                        $valtemplate .= "<td class='rptData'>" . $fieldvalue . "</td>";
                                    } else {
                                        $valtemplate .= "<td class='rptGrpHead'>" . $fieldvalue . "</td>";
                                    }
                                }
                            }
                        }
                        // Performance Optimization: If direct output is required
                        if ($directOutput) {
                            echo $valtemplate;
                            $valtemplate = '';
                        }
                    }
                    $valtemplate .= "</tr>";
                    // Performance Optimization: If direct output is required
                    if ($directOutput) {
                        echo $valtemplate;
                        $valtemplate = '';
                    }
                    $lastvalue = $newvalue;
                    $secondvalue = $snewvalue;
                    $thirdvalue = $tnewvalue;
                    $arr_val[] = $arraylists;
                    set_time_limit($php_max_execution_time);
                } while ($custom_field_values = $adb->fetch_array($result));
                // Performance Optimization
                if ($directOutput) {
                    echo "</tr></table>";
                    echo "<script type='text/javascript' id='__reportrun_directoutput_recordcount_script'>\n\t\t\t\t\t\tif(\$('_reportrun_total')) \$('_reportrun_total').innerHTML={$noofrows};</script>";
                } else {
                    $sHTML = '<table cellpadding="5" cellspacing="0" align="center" class="rptTable">
					<tr>' . $header . '<!-- BEGIN values -->
					<tr>' . $valtemplate . '</tr>
					</table>';
                }
                //<<<<<<<<construct HTML>>>>>>>>>>>>
                $return_data[] = $sHTML;
                $return_data[] = $noofrows;
                $return_data[] = $sSQL;
                return $return_data;
            }
        } elseif ($outputformat == "PDF") {
            $sSQL = $this->sGetSQLforReport($this->reportid, $filtersql);
            $result = $adb->pquery($sSQL, array());
            if ($is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1) {
                $picklistarray = $this->getAccessPickListValues();
            }
            if ($result) {
                $y = $adb->num_fields($result);
                $noofrows = $adb->num_rows($result);
                $custom_field_values = $adb->fetch_array($result);
                $column_definitions = $adb->getFieldsDefinition($result);
                do {
                    $arraylists = array();
                    for ($i = 0; $i < $y - 1; $i++) {
                        $fld = $adb->field_name($result, $i);
                        $fld_type = $column_definitions[$i]->type;
                        list($module, $fieldLabel) = explode('_', $fld->name, 2);
                        $fieldInfo = getFieldByReportLabel($module, $fieldLabel);
                        if (!empty($fieldInfo)) {
                            $field = WebserviceField::fromArray($adb, $fieldInfo);
                        }
                        if (!empty($fieldInfo)) {
                            $headerLabel = getTranslatedString($field->getFieldLabelKey(), $module);
                        } else {
                            $headerLabel = getTranslatedString(str_replace('_', " ", $fieldLabel), $module);
                        }
                        /*STRING TRANSLATION starts */
                        $moduleLabel = '';
                        if (in_array($module, $modules_selected)) {
                            $moduleLabel = getTranslatedString($module, $module);
                        }
                        if (empty($headerLabel)) {
                            $headerLabel = getTranslatedString(str_replace('_', " ", $fld->name));
                        }
                        if (!empty($this->secondarymodule)) {
                            if ($moduleLabel != '') {
                                $headerLabel = $moduleLabel . " " . $headerLabel;
                            }
                        }
                        $fieldvalue = getReportFieldValue($this, $picklistarray, $fld, $custom_field_values, $i);
                        if (empty($returnfieldinfo[$headerLabel])) {
                            $returnfieldinfo[$headerLabel] = $field;
                        }
                        $arraylists[$headerLabel] = $fieldvalue;
                    }
                    $arr_val[] = $arraylists;
                    set_time_limit($php_max_execution_time);
                } while ($custom_field_values = $adb->fetch_array($result));
                return $arr_val;
            }
        } elseif ($outputformat == "TOTALXLS") {
            $escapedchars = array('_SUM', '_AVG', '_MIN', '_MAX');
            $totalpdf = array();
            $sSQL = $this->sGetSQLforReport($this->reportid, $filtersql, "COLUMNSTOTOTAL");
            if (isset($this->totallist) and count($this->totallist) > 0) {
                if ($sSQL != '') {
                    $result = $adb->query($sSQL);
                    $y = $adb->num_fields($result);
                    $custom_field_values = $adb->fetch_array($result);
                    foreach ($this->totallist as $key => $value) {
                        $fieldlist = explode(":", $key);
                        $mod_query = $adb->pquery("SELECT distinct(tabid) as tabid, uitype as uitype from vtiger_field where tablename = ? and columnname=?", array($fieldlist[1], $fieldlist[2]));
                        if ($adb->num_rows($mod_query) > 0) {
                            $module_name = getTabModuleName($adb->query_result($mod_query, 0, 'tabid'));
                            $fieldlabel = trim(str_replace($escapedchars, " ", $fieldlist[3]));
                            $fieldlabel = str_replace("_", " ", $fieldlabel);
                            if ($module_name) {
                                $field = getTranslatedString($module_name, $module_name) . " " . getTranslatedString($fieldlabel, $module_name);
                            } else {
                                $field = getTranslatedString($fieldlabel);
                            }
                        }
                        $uitype_arr[str_replace($escapedchars, " ", $module_name . "_" . $fieldlist[3])] = $adb->query_result($mod_query, 0, "uitype");
                        $totclmnflds[str_replace($escapedchars, " ", $module_name . "_" . $fieldlist[3])] = $field;
                    }
                    for ($i = 0; $i < $y; $i++) {
                        $fld = $adb->field_name($result, $i);
                        $keyhdr[$fld->name] = $custom_field_values[$i];
                    }
                    $rowcount = 0;
                    foreach ($totclmnflds as $key => $value) {
                        $col_header = trim(str_replace($modules, " ", $value));
                        $fld_name_1 = $this->primarymodule . "_" . trim($value);
                        $fld_name_2 = $this->secondarymodule . "_" . trim($value);
                        if ($uitype_arr[$key] == 71 || $uitype_arr[$key] == 72 || in_array($fld_name_1, $this->append_currency_symbol_to_value) || in_array($fld_name_2, $this->append_currency_symbol_to_value)) {
                            $col_header .= " (" . $app_strings['LBL_IN'] . " " . $current_user->currency_symbol . ")";
                            $convert_price = true;
                        } else {
                            $convert_price = false;
                        }
                        $value = decode_html(trim($key));
                        $arraykey = $value . '_SUM';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $totalpdf[$rowcount][$arraykey] = $conv_value;
                        } else {
                            $totalpdf[$rowcount][$arraykey] = '';
                        }
                        $arraykey = $value . '_AVG';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $totalpdf[$rowcount][$arraykey] = $conv_value;
                        } else {
                            $totalpdf[$rowcount][$arraykey] = '';
                        }
                        $arraykey = $value . '_MIN';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $totalpdf[$rowcount][$arraykey] = $conv_value;
                        } else {
                            $totalpdf[$rowcount][$arraykey] = '';
                        }
                        $arraykey = $value . '_MAX';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $totalpdf[$rowcount][$arraykey] = $conv_value;
                        } else {
                            $totalpdf[$rowcount][$arraykey] = '';
                        }
                        $rowcount++;
                    }
                }
            }
            return $totalpdf;
        } elseif ($outputformat == "TOTALHTML") {
            $escapedchars = array('_SUM', '_AVG', '_MIN', '_MAX');
            $sSQL = $this->sGetSQLforReport($this->reportid, $filtersql, "COLUMNSTOTOTAL");
            $coltotalhtml = '';
            if (isset($this->totallist) and count($this->totallist) > 0) {
                if ($sSQL != "") {
                    $result = $adb->query($sSQL);
                    $y = $adb->num_fields($result);
                    $custom_field_values = $adb->fetch_array($result);
                    $coltotalhtml = "<table align='center' width='60%' cellpadding='3' cellspacing='0' border='0' class='rptTable'><tr><td class='rptCellLabel'>" . $mod_strings['Totals'] . "</td><td class='rptCellLabel'>" . $mod_strings['SUM'] . "</td><td class='rptCellLabel'>" . $mod_strings['AVG'] . "</td><td class='rptCellLabel'>" . $mod_strings['MIN'] . "</td><td class='rptCellLabel'>" . $mod_strings['MAX'] . "</td></tr>";
                    // Performation Optimization: If Direct output is desired
                    if ($directOutput) {
                        echo $coltotalhtml;
                        $coltotalhtml = '';
                    }
                    foreach ($this->totallist as $key => $value) {
                        $fieldlist = explode(":", $key);
                        $mod_query = $adb->pquery("SELECT distinct(tabid) as tabid, uitype as uitype from vtiger_field where tablename = ? and columnname=?", array($fieldlist[1], $fieldlist[2]));
                        if ($adb->num_rows($mod_query) > 0) {
                            $module_name = getTabModuleName($adb->query_result($mod_query, 0, 'tabid'));
                            $fieldlabel = trim(str_replace($escapedchars, " ", $fieldlist[3]));
                            $fieldlabel = str_replace("_", " ", $fieldlabel);
                            if ($module_name) {
                                $field = getTranslatedString($module_name, $module_name) . " " . getTranslatedString($fieldlabel, $module_name);
                            } else {
                                $field = getTranslatedString($fieldlabel);
                            }
                        }
                        $uitype_arr[str_replace($escapedchars, " ", $module_name . "_" . $fieldlist[3])] = $adb->query_result($mod_query, 0, "uitype");
                        $totclmnflds[str_replace($escapedchars, " ", $module_name . "_" . $fieldlist[3])] = $field;
                    }
                    for ($i = 0; $i < $y; $i++) {
                        $fld = $adb->field_name($result, $i);
                        $keyhdr[$fld->name] = $custom_field_values[$i];
                    }
                    foreach ($totclmnflds as $key => $value) {
                        $coltotalhtml .= '<tr class="rptGrpHead" valign=top>';
                        $col_header = trim(str_replace($modules, " ", $value));
                        $fld_name_1 = $this->primarymodule . "_" . trim($value);
                        $fld_name_2 = $this->secondarymodule . "_" . trim($value);
                        if ($uitype_arr[$key] == 71 || $uitype_arr[$key] == 72 || in_array($fld_name_1, $this->append_currency_symbol_to_value) || in_array($fld_name_2, $this->append_currency_symbol_to_value)) {
                            $col_header .= " (" . $app_strings['LBL_IN'] . " " . $current_user->currency_symbol . ")";
                            $convert_price = true;
                        } else {
                            $convert_price = false;
                        }
                        $coltotalhtml .= '<td class="rptData">' . $col_header . '</td>';
                        $value = decode_html(trim($key));
                        $arraykey = $value . '_SUM';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            if (substr($arraykey, 0, 21) == 'Timecontrol_TotalTime' or substr($arraykey, 0, 18) == 'TCTotals_TotalTime') {
                                $conv_value = $keyhdr[$arraykey];
                            }
                            $coltotalhtml .= '<td class="rptTotal">' . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= '<td class="rptTotal">&nbsp;</td>';
                        }
                        $arraykey = $value . '_AVG';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            if (substr($arraykey, 0, 21) == 'Timecontrol_TotalTime' or substr($arraykey, 0, 18) == 'TCTotals_TotalTime') {
                                $conv_value = $keyhdr[$arraykey];
                            }
                            $coltotalhtml .= '<td class="rptTotal">' . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= '<td class="rptTotal">&nbsp;</td>';
                        }
                        $arraykey = $value . '_MIN';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            if (substr($arraykey, 0, 21) == 'Timecontrol_TotalTime' or substr($arraykey, 0, 18) == 'TCTotals_TotalTime') {
                                $conv_value = $keyhdr[$arraykey];
                            }
                            $coltotalhtml .= '<td class="rptTotal">' . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= '<td class="rptTotal">&nbsp;</td>';
                        }
                        $arraykey = $value . '_MAX';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            if (substr($arraykey, 0, 21) == 'Timecontrol_TotalTime' or substr($arraykey, 0, 18) == 'TCTotals_TotalTime') {
                                $conv_value = $keyhdr[$arraykey];
                            }
                            $coltotalhtml .= '<td class="rptTotal">' . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= '<td class="rptTotal">&nbsp;</td>';
                        }
                        $coltotalhtml .= '<tr>';
                        // Performation Optimization: If Direct output is desired
                        if ($directOutput) {
                            echo $coltotalhtml;
                            $coltotalhtml = '';
                        }
                    }
                    $coltotalhtml .= "</table>";
                    // Performation Optimization: If Direct output is desired
                    if ($directOutput) {
                        echo $coltotalhtml;
                        $coltotalhtml = '';
                    }
                }
            }
            return $coltotalhtml;
        } elseif ($outputformat == "PRINT") {
            $sSQL = $this->sGetSQLforReport($this->reportid, $filtersql);
            $result = $adb->query($sSQL);
            if ($is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1) {
                $picklistarray = $this->getAccessPickListValues();
            }
            if ($result) {
                $noofrows = $adb->num_rows($result);
                $custom_field_values = $adb->fetch_array($result);
                $groupslist = $this->getGroupingList($this->reportid);
                $column_definitions = $adb->getFieldsDefinition($result);
                $y = $adb->num_fields($result);
                $arrayHeaders = array();
                $header = '';
                for ($x = 0; $x < $y - 1; $x++) {
                    $fld = $adb->field_name($result, $x);
                    $fld_type = $column_definitions[$x]->type;
                    list($module, $fieldLabel) = explode('_', $fld->name, 2);
                    $fieldInfo = getFieldByReportLabel($module, $fieldLabel);
                    if (!empty($fieldInfo)) {
                        $field = WebserviceField::fromArray($adb, $fieldInfo);
                    }
                    if (!empty($fieldInfo)) {
                        $headerLabel = getTranslatedString($field->getFieldLabelKey(), $module);
                    } else {
                        $headerLabel = getTranslatedString(str_replace('_', " ", $fieldLabel), $module);
                    }
                    /*STRING TRANSLATION starts */
                    $moduleLabel = '';
                    if (in_array($module, $modules_selected)) {
                        $moduleLabel = getTranslatedString($module, $module);
                    }
                    if (empty($headerLabel)) {
                        $headerLabel = getTranslatedString(str_replace('_', " ", $fld->name));
                    }
                    if (!empty($this->secondarymodule)) {
                        if ($moduleLabel != '') {
                            $headerLabel = $moduleLabel . " " . $headerLabel;
                        }
                    }
                    $header .= "<th>" . $headerLabel . "</th>";
                }
                $valtemplate = '';
                $lastvalue = '';
                $secondvalue = '';
                $thirdvalue = '';
                do {
                    $arraylists = array();
                    $newvalue = '';
                    $snewvalue = '';
                    $tnewvalue = '';
                    if (count($groupslist) == 1) {
                        $newvalue = $custom_field_values[0];
                    } elseif (count($groupslist) == 2) {
                        $newvalue = $custom_field_values[0];
                        $snewvalue = $custom_field_values[1];
                    } elseif (count($groupslist) == 3) {
                        $newvalue = $custom_field_values[0];
                        $snewvalue = $custom_field_values[1];
                        $tnewvalue = $custom_field_values[2];
                    }
                    if ($newvalue == '') {
                        $newvalue = '-';
                    }
                    if ($snewvalue == '') {
                        $snewvalue = '-';
                    }
                    if ($tnewvalue == '') {
                        $tnewvalue = '-';
                    }
                    $valtemplate .= '<tr>';
                    for ($i = 0; $i < $y - 1; $i++) {
                        $fld = $adb->field_name($result, $i);
                        $fld_type = $column_definitions[$i]->type;
                        $fieldvalue = getReportFieldValue($this, $picklistarray, $fld, $custom_field_values, $i);
                        if ($lastvalue == $fieldvalue && $this->reporttype == "summary") {
                            if ($this->reporttype == "summary") {
                                $valtemplate .= "<td style='border-top:1px dotted #FFFFFF;'>&nbsp;</td>";
                            } else {
                                $valtemplate .= "<td>" . $fieldvalue . "</td>";
                            }
                        } else {
                            if ($secondvalue == $fieldvalue && $this->reporttype == "summary") {
                                if ($lastvalue == $newvalue) {
                                    $valtemplate .= "<td style='border-top:1px dotted #FFFFFF;'>&nbsp;</td>";
                                } else {
                                    $valtemplate .= "<td>" . $fieldvalue . "</td>";
                                }
                            } else {
                                if ($thirdvalue == $fieldvalue && $this->reporttype == "summary") {
                                    if ($secondvalue == $snewvalue) {
                                        $valtemplate .= "<td style='border-top:1px dotted #FFFFFF;'>&nbsp;</td>";
                                    } else {
                                        $valtemplate .= "<td>" . $fieldvalue . "</td>";
                                    }
                                } else {
                                    if ($this->reporttype == "tabular") {
                                        $valtemplate .= "<td>" . $fieldvalue . "</td>";
                                    } else {
                                        $valtemplate .= "<td>" . $fieldvalue . "</td>";
                                    }
                                }
                            }
                        }
                    }
                    $valtemplate .= "</tr>";
                    $lastvalue = $newvalue;
                    $secondvalue = $snewvalue;
                    $thirdvalue = $tnewvalue;
                    $arr_val[] = $arraylists;
                    set_time_limit($php_max_execution_time);
                } while ($custom_field_values = $adb->fetch_array($result));
                $sHTML = '<tr>' . $header . '</tr>' . $valtemplate;
                $return_data[] = $sHTML;
                $return_data[] = $noofrows;
                return $return_data;
            }
        } elseif ($outputformat == "PRINT_TOTAL") {
            $escapedchars = array('_SUM', '_AVG', '_MIN', '_MAX');
            $sSQL = $this->sGetSQLforReport($this->reportid, $filtersql, "COLUMNSTOTOTAL");
            $coltotalhtml = '';
            if (isset($this->totallist) and count($this->totallist) > 0) {
                if ($sSQL != "") {
                    $result = $adb->query($sSQL);
                    $y = $adb->num_fields($result);
                    $custom_field_values = $adb->fetch_array($result);
                    $coltotalhtml = "<br /><table align='center' width='60%' cellpadding='3' cellspacing='0' border='1' class='printReport'><tr><td class='rptCellLabel'>" . $mod_strings['Totals'] . "</td><td><b>" . $mod_strings['SUM'] . "</b></td><td><b>" . $mod_strings['AVG'] . "</b></td><td><b>" . $mod_strings['MIN'] . "</b></td><td><b>" . $mod_strings['MAX'] . "</b></td></tr>";
                    // Performation Optimization: If Direct output is desired
                    if ($directOutput) {
                        echo $coltotalhtml;
                        $coltotalhtml = '';
                    }
                    foreach ($this->totallist as $key => $value) {
                        $fieldlist = explode(":", $key);
                        $mod_query = $adb->pquery("SELECT distinct(tabid) as tabid, uitype as uitype from vtiger_field where tablename = ? and columnname=?", array($fieldlist[1], $fieldlist[2]));
                        if ($adb->num_rows($mod_query) > 0) {
                            $module_name = getTabModuleName($adb->query_result($mod_query, 0, 'tabid'));
                            $fieldlabel = trim(str_replace($escapedchars, " ", $fieldlist[3]));
                            $fieldlabel = str_replace("_", " ", $fieldlabel);
                            if ($module_name) {
                                $field = getTranslatedString($module_name, $module_name) . " " . getTranslatedString($fieldlabel, $module_name);
                            } else {
                                $field = getTranslatedString($fieldlabel);
                            }
                        }
                        $uitype_arr[str_replace($escapedchars, " ", $module_name . "_" . $fieldlist[3])] = $adb->query_result($mod_query, 0, "uitype");
                        $totclmnflds[str_replace($escapedchars, " ", $module_name . "_" . $fieldlist[3])] = $field;
                    }
                    for ($i = 0; $i < $y; $i++) {
                        $fld = $adb->field_name($result, $i);
                        $keyhdr[$fld->name] = $custom_field_values[$i];
                    }
                    foreach ($totclmnflds as $key => $value) {
                        $coltotalhtml .= '<tr class="rptGrpHead">';
                        $col_header = getTranslatedString(trim(str_replace($modules, " ", $value)));
                        $fld_name_1 = $this->primarymodule . "_" . trim($value);
                        $fld_name_2 = $this->secondarymodule . "_" . trim($value);
                        if ($uitype_arr[$key] == 71 || $uitype_arr[$key] == 72 || in_array($fld_name_1, $this->append_currency_symbol_to_value) || in_array($fld_name_2, $this->append_currency_symbol_to_value)) {
                            $col_header .= " (" . $app_strings['LBL_IN'] . " " . $current_user->currency_symbol . ")";
                            $convert_price = true;
                        } else {
                            $convert_price = false;
                        }
                        $coltotalhtml .= '<td class="rptData">' . $col_header . '</td>';
                        $value = decode_html(trim($key));
                        $arraykey = $value . '_SUM';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $coltotalhtml .= "<td class='rptTotal'>" . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= "<td class='rptTotal'>&nbsp;</td>";
                        }
                        $arraykey = $value . '_AVG';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $coltotalhtml .= "<td class='rptTotal'>" . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= "<td class='rptTotal'>&nbsp;</td>";
                        }
                        $arraykey = $value . '_MIN';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $coltotalhtml .= "<td class='rptTotal'>" . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= "<td class='rptTotal'>&nbsp;</td>";
                        }
                        $arraykey = $value . '_MAX';
                        if (isset($keyhdr[$arraykey])) {
                            if ($convert_price) {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey]);
                            } else {
                                $conv_value = CurrencyField::convertToUserFormat($keyhdr[$arraykey], null, true);
                            }
                            $coltotalhtml .= "<td class='rptTotal'>" . $conv_value . '</td>';
                        } else {
                            $coltotalhtml .= "<td class='rptTotal'>&nbsp;</td>";
                        }
                        $coltotalhtml .= '</tr>';
                        // Performation Optimization: If Direct output is desired
                        if ($directOutput) {
                            echo $coltotalhtml;
                            $coltotalhtml = '';
                        }
                    }
                    $coltotalhtml .= "</table>";
                    // Performation Optimization: If Direct output is desired
                    if ($directOutput) {
                        echo $coltotalhtml;
                        $coltotalhtml = '';
                    }
                }
            }
            return $coltotalhtml;
        }
    }
$list_body = '';
for ($i = 0; $i < count($new_prod_array); $i++) {
    $log->info("Products :: Showing the List of products to be added in price book");
    $entity_id = $new_prod_array[$i];
    $list_body .= '<tr class="lvtColData" onmouseover="this.className=\'lvtColDataHover\'" onmouseout="this.className=\'lvtColData\'" bgcolor="white">';
    $unit_price = $prod_price_list[$entity_id];
    $field_name = $entity_id . "_listprice";
    $unit_price_array[] = '"' . CurrencyField::convertToUserFormat($unit_price, null, true) . '"';
    $field_name_array[] = "'" . $field_name . "'";
    $list_body .= '<td><INPUT type=checkbox NAME="selected_id" id="check_' . $entity_id . '" value= ' . $entity_id . ' onClick=\'toggleSelectAll(this.name,"selectall");updateListPriceForField("' . $field_name . '",this)\'></td>';
    $list_body .= '<td>' . $adb->query_result($list_result, $entity_id_array[$entity_id], "productname") . '</td>';
    if (getFieldVisibilityPermission('Products', $current_user->id, 'productcode') == '0') {
        $list_body .= '<td>' . $adb->query_result($list_result, $entity_id_array[$entity_id], "productcode") . '</td>';
    }
    if (getFieldVisibilityPermission('Products', $current_user->id, 'unit_price') == '0') {
        $list_body .= '<td>' . CurrencyField::convertToUserFormat($unit_price, null, true) . '</td>';
    }
    $list_body .= '<td>';
    if (isPermitted("PriceBooks", "EditView", "") == 'yes') {
        $list_body .= '<input type="text" name="' . $field_name . '" style="visibility:hidden;" id="' . $field_name . '">';
    } else {
        $list_body .= '<input type="text" name="' . $field_name . '" style="visibility:hidden;" readonly id="' . $field_name . '">';
    }
    $list_body .= '</td></tr>';
}
$smarty->assign("UNIT_PRICE_ARRAY", implode(",", $unit_price_array));
$smarty->assign("FIELD_NAME_ARRAY", implode(",", $field_name_array));
if ($order_by != '') {
    $url_string .= "&order_by=" . $order_by;
}
if ($sorder != '') {
    function content_5674f1d67ee41($_smarty_tpl)
    {
        ?>
<input type='hidden' id='pageNumber' value="<?php 
        echo $_smarty_tpl->tpl_vars['PAGE_NUMBER']->value;
        ?>
"><input type='hidden' id='pageLimit' value="<?php 
        echo $_smarty_tpl->tpl_vars['PAGING_MODEL']->value->getPageLimit();
        ?>
"><input type="hidden" id="noOfEntries" value="<?php 
        echo $_smarty_tpl->tpl_vars['LISTVIEW_ENTRIES_COUNT']->value;
        ?>
"><input type="hidden" id="pageStartRange" value="<?php 
        echo $_smarty_tpl->tpl_vars['PAGING_MODEL']->value->getRecordStartRange();
        ?>
" /><input type="hidden" id="pageEndRange" value="<?php 
        echo $_smarty_tpl->tpl_vars['PAGING_MODEL']->value->getRecordEndRange();
        ?>
" /><input type="hidden" id="previousPageExist" value="<?php 
        echo $_smarty_tpl->tpl_vars['PAGING_MODEL']->value->isPrevPageExists();
        ?>
" /><input type="hidden" id="nextPageExist" value="<?php 
        echo $_smarty_tpl->tpl_vars['PAGING_MODEL']->value->isNextPageExists();
        ?>
" /><input type="hidden" id="totalCount" value="<?php 
        echo $_smarty_tpl->tpl_vars['LISTVIEW_COUNT']->value;
        ?>
" /><div class="contents-topscroll"><div class="topscroll-div">&nbsp;</div></div><div class="popupEntriesDiv relatedContents contents-bottomscroll"><input type="hidden" value="<?php 
        echo $_smarty_tpl->tpl_vars['ORDER_BY']->value;
        ?>
" id="orderBy"><input type="hidden" value="<?php 
        echo $_smarty_tpl->tpl_vars['SORT_ORDER']->value;
        ?>
" id="sortOrder"><?php 
        if ($_smarty_tpl->tpl_vars['SOURCE_MODULE']->value == "Emails") {
            ?>
<input type="hidden" value="Vtiger_EmailsRelatedModule_Popup_Js" id="popUpClassName"/><?php 
        }
        $_smarty_tpl->tpl_vars['WIDTHTYPE'] = new Smarty_variable($_smarty_tpl->tpl_vars['CURRENT_USER_MODEL']->value->get('rowheight'), null, 0);
        ?>
<div class="bottomscroll-div"><table class="table table-bordered listViewEntriesTable"><thead><tr class="listViewHeaders"><?php 
        if ($_smarty_tpl->tpl_vars['MULTI_SELECT']->value) {
            ?>
<th class="<?php 
            echo $_smarty_tpl->tpl_vars['WIDTHTYPE']->value;
            ?>
"><input type="checkbox"  class="selectAllInCurrentPage" /></th><?php 
        }
        $_smarty_tpl->tpl_vars['LISTVIEW_HEADER'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['LISTVIEW_HEADERS']->value;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        foreach ($_from as $_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->key => $_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->value) {
            $_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->_loop = true;
            ?>
<th class="<?php 
            echo $_smarty_tpl->tpl_vars['WIDTHTYPE']->value;
            ?>
"><a href="javascript:void(0);" class="listViewHeaderValues <?php 
            if ($_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->value->get('name') == 'listprice') {
                ?>
 noSorting <?php 
            }
            ?>
" data-nextsortorderval="<?php 
            if ($_smarty_tpl->tpl_vars['ORDER_BY']->value == $_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->value->get('column')) {
                echo $_smarty_tpl->tpl_vars['NEXT_SORT_ORDER']->value;
            } else {
                ?>
ASC<?php 
            }
            ?>
" data-columnname="<?php 
            echo $_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->value->get('column');
            ?>
"><?php 
            echo vtranslate($_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->value->get('label'), $_smarty_tpl->tpl_vars['MODULE']->value);
            if ($_smarty_tpl->tpl_vars['ORDER_BY']->value == $_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->value->get('column')) {
                ?>
<img class="sortImage" src="<?php 
                echo vimage_path($_smarty_tpl->tpl_vars['SORT_IMAGE']->value, $_smarty_tpl->tpl_vars['MODULE']->value);
                ?>
"><?php 
            } else {
                ?>
<img class="hide sortingImage" src="<?php 
                echo vimage_path('downArrowSmall.png', $_smarty_tpl->tpl_vars['MODULE']->value);
                ?>
"><?php 
            }
            ?>
</a></th><?php 
        }
        ?>
</tr></thead><?php 
        $_smarty_tpl->tpl_vars['LISTVIEW_ENTRY'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['LISTVIEW_ENTRIES']->value;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        $_smarty_tpl->tpl_vars['smarty']->value['foreach']['popupListView']['index'] = -1;
        foreach ($_from as $_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->key => $_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->value) {
            $_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->_loop = true;
            $_smarty_tpl->tpl_vars['smarty']->value['foreach']['popupListView']['index']++;
            ?>
<tr class="listViewEntries" data-id="<?php 
            echo $_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->value->getId();
            ?>
" data-name='<?php 
            echo $_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->value->getName();
            ?>
' data-info='<?php 
            echo ZEND_JSON::encode($_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->value->getRawData());
            ?>
'<?php 
            if ($_smarty_tpl->tpl_vars['GETURL']->value != '') {
                ?>
 data-url='<?php 
                $_tmp1 = $_smarty_tpl->tpl_vars['GETURL']->value;
                echo $_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->value->{$_tmp1}();
                ?>
' <?php 
            }
            ?>
  id="<?php 
            echo $_smarty_tpl->tpl_vars['MODULE']->value;
            ?>
_popUpListView_row_<?php 
            echo $_smarty_tpl->getVariable('smarty')->value['foreach']['popupListView']['index'] + 1;
            ?>
"><?php 
            if ($_smarty_tpl->tpl_vars['MULTI_SELECT']->value) {
                ?>
<td class="<?php 
                echo $_smarty_tpl->tpl_vars['WIDTHTYPE']->value;
                ?>
"><input class="entryCheckBox" type="checkbox" /></td><?php 
            }
            $_smarty_tpl->tpl_vars['LISTVIEW_HEADER'] = new Smarty_Variable();
            $_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->_loop = false;
            $_from = $_smarty_tpl->tpl_vars['LISTVIEW_HEADERS']->value;
            if (!is_array($_from) && !is_object($_from)) {
                settype($_from, 'array');
            }
            foreach ($_from as $_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->key => $_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->value) {
                $_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->_loop = true;
                $_smarty_tpl->tpl_vars['LISTVIEW_HEADERNAME'] = new Smarty_variable($_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->value->get('name'), null, 0);
                ?>
<td class="listViewEntryValue <?php 
                echo $_smarty_tpl->tpl_vars['WIDTHTYPE']->value;
                ?>
"><?php 
                if ($_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->value->isNameField() == true || $_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->value->get('uitype') == '4') {
                    ?>
<a><?php 
                    echo $_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->value->get($_smarty_tpl->tpl_vars['LISTVIEW_HEADERNAME']->value);
                    ?>
</a><?php 
                } elseif ($_smarty_tpl->tpl_vars['LISTVIEW_HEADER']->value->get('uitype') == '72') {
                    ob_start();
                    echo $_smarty_tpl->tpl_vars['CURRENT_USER_MODEL']->value->get('currency_symbol_placement');
                    $_tmp2 = ob_get_clean();
                    $_smarty_tpl->tpl_vars['CURRENCY_SYMBOL_PLACEMENT'] = new Smarty_variable($_tmp2, null, 0);
                    if ($_smarty_tpl->tpl_vars['CURRENCY_SYMBOL_PLACEMENT']->value == '1.0$') {
                        echo $_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->value->get($_smarty_tpl->tpl_vars['LISTVIEW_HEADERNAME']->value);
                        echo $_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->value->get('currencySymbol');
                    } else {
                        echo $_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->value->get('currencySymbol');
                        echo $_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->value->get($_smarty_tpl->tpl_vars['LISTVIEW_HEADERNAME']->value);
                    }
                } elseif ($_smarty_tpl->tpl_vars['LISTVIEW_HEADERNAME']->value == 'listprice') {
                    echo CurrencyField::convertToUserFormat($_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->value->get($_smarty_tpl->tpl_vars['LISTVIEW_HEADERNAME']->value), null, true, true);
                } else {
                    echo $_smarty_tpl->tpl_vars['LISTVIEW_ENTRY']->value->get($_smarty_tpl->tpl_vars['LISTVIEW_HEADERNAME']->value);
                }
                ?>
</td><?php 
            }
            ?>
</tr><?php 
        }
        ?>
</table></div><!--added this div for Temporarily --><?php 
        if ($_smarty_tpl->tpl_vars['LISTVIEW_ENTRIES_COUNT']->value == '0') {
            ?>
<div class="row-fluid"><div class="emptyRecordsDiv"><?php 
            echo vtranslate('LBL_EQ_ZERO', $_smarty_tpl->tpl_vars['MODULE']->value);
            ?>
 <?php 
            echo vtranslate($_smarty_tpl->tpl_vars['RELATED_MODULE']->value, $_smarty_tpl->tpl_vars['RELATED_MODULE']->value);
            ?>
 <?php 
            echo vtranslate('LBL_FOUND', $_smarty_tpl->tpl_vars['MODULE']->value);
            ?>
.</div></div><?php 
        }
        ?>
</div>
<?php 
    }
Exemplo n.º 29
0
 /**
  * Function to get the record model based on the request parameters
  * @param Vtiger_Request $request
  * @return Vtiger_Record_Model or Module specific Record Model instance
  */
 public function getRecordModelFromRequest(Vtiger_Request $request)
 {
     $moduleName = $request->getModule();
     $recordId = $request->get('record');
     if (!empty($recordId)) {
         $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName);
         $recordModel->set('id', $recordId);
         $recordModel->set('mode', 'edit');
         $fieldModelList = $recordModel->getModule()->getFields();
         foreach ($fieldModelList as $fieldName => $fieldModel) {
             //For not converting craetedtime and modified time to user format
             $uiType = $fieldModel->get('uitype');
             if ($uiType == 70) {
                 $fieldValue = $recordModel->get($fieldName);
             } elseif (in_array($uiType, [71, 72])) {
                 // currency ui types
                 $fieldValue = $recordModel->get($fieldName);
                 $fieldValue = CurrencyField::convertToUserFormat($fieldValue, null, true);
             } else {
                 $fieldValue = $fieldModel->getUITypeModel()->getUserRequestValue($recordModel->get($fieldName), $recordId);
             }
             if ($fieldName === $request->get('field')) {
                 $fieldValue = $request->get('value');
             }
             $fieldDataType = $fieldModel->getFieldDataType();
             if ($fieldDataType == 'time') {
                 $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue);
             }
             if ($fieldValue !== null) {
                 if (!is_array($fieldValue)) {
                     $fieldValue = trim($fieldValue);
                 }
                 $recordModel->set($fieldName, $fieldValue);
             }
             $recordModel->set($fieldName, $fieldValue);
         }
     } else {
         $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
         $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName);
         $recordModel->set('mode', '');
         $fieldModelList = $moduleModel->getFields();
         foreach ($fieldModelList as $fieldName => $fieldModel) {
             if ($request->has($fieldName)) {
                 $fieldValue = $request->get($fieldName, null);
             } else {
                 $fieldValue = $fieldModel->getDefaultFieldValue();
             }
             $fieldDataType = $fieldModel->getFieldDataType();
             if ($fieldDataType == 'time') {
                 $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue);
             }
             if ($fieldValue !== null) {
                 if (!is_array($fieldValue)) {
                     $fieldValue = trim($fieldValue);
                 }
                 $recordModel->set($fieldName, $fieldValue);
             }
         }
     }
     return $recordModel;
 }
Exemplo n.º 30
0
    public function process($module, $id, Vtiger_PDF_Model $pdf)
    {
        $html = '';
        $recordId = $id;
        $record = Vtiger_Record_Model::getInstanceById($recordId);
        $moduleModel = $record->getModule();
        if (!$moduleModel->isInventory()) {
            return $html;
        }
        $inventoryField = Vtiger_InventoryField_Model::getInstance($module);
        $fields = $inventoryField->getFields(true);
        if ($fields[0] != 0) {
            $columns = $inventoryField->getColumns();
            $inventoryRows = $record->getInventoryData();
            $mainParams = $inventoryField->getMainParams($fields[1]);
            $countFields0 = count($fields[0]);
            $countFields1 = count($fields[1]);
            $countFields2 = count($fields[2]);
            $baseCurrency = Vtiger_Util_Helper::getBaseCurrency();
        }
        if (in_array("currency", $columns)) {
            if (count($inventoryRows) > 0 && $inventoryRows[0]['currency'] != NULL) {
                $currency = $inventoryRows[0]['currency'];
            } else {
                $currency = $baseCurrency['id'];
            }
            $currencySymbolRate = Vtiger_Functions::getCurrencySymbolandRate($currency);
        }
        $html .= '<style>' . '.colapseBorder {border-collapse: collapse;}' . '.tBorder {border: 1px solid grey;}' . '.tHeader {background-color: lightgrey;}' . '.summaryBorder {border-left: 1px solid grey; border-bottom: 1px solid grey; border-right: 1px solid grey;}' . '.pTable td, th {padding-left: 5px; padding-right: 5px;}' . '.noBottomBorder {border-bottom: none;}' . '.noBorder {border: none !important;}' . '</style>';
        if (count($fields[0]) != 0) {
            $html .= '<table class="pTable colapseBorder">
				<thead>
					<tr>
						<th style="width: 65%;"></th>';
            foreach ($fields[0] as $field) {
                $html .= '<th colspan="' . $field->get('colspan') . '" class="tBorder noBottomBorder tHeader">
								<span>' . vtranslate($field->get('label'), $module) . ':</span>&nbsp;';
                switch ($field->getTemplateName('DetailView', $module)) {
                    case 'DetailViewBase.tpl':
                        $html .= $field->getDisplayValue($inventoryRows[0][$field->get('columnname')]);
                        break;
                    case 'DetailViewTaxMode.tpl':
                    case 'DetailViewDiscountMode.tpl':
                        $html .= vtranslate($field->getDisplayValue($inventoryRows[0][$field->get('columnname')]), $MODULE);
                        break;
                }
                $html .= '</th>';
            }
            $html .= '</tr>
				</thead>
			</table>';
            $fieldsTextAlignRight = ['TotalPrice', 'Tax', 'MarginP', 'Margin', 'Purchase', 'Discount', 'NetPrice', 'GrossPrice', 'UnitPrice', 'Quantity'];
            $html .= '<table class="pTable colapseBorder">
				<thead>
					<tr>';
            foreach ($fields[1] as $field) {
                if ($field->isVisible($inventoryRows)) {
                    $html .= '<th colspan="' . $field->get('colspan') . '" class="textAlignCenter tBorder tHeader">' . vtranslate($field->get('label'), $module) . '</th>';
                }
            }
            $html .= '</tr>
				</thead>
				<tbody>';
            //			for($i=0; $i<100; $i++) {
            foreach ($inventoryRows as $key => &$inventoryRow) {
                $rowNo = $key + 1;
                $html .= '<tr>';
                foreach ($fields[1] as $field) {
                    if ($field->isVisible($inventoryRows)) {
                        $itemValue = $inventoryRow[$field->get('columnname')];
                        $html .= '<td ' . ($field->getName() == 'Name' ? 'width="40%;" ' : '') . ' class="' . (in_array($field->getName(), $fieldsTextAlignRight) ? 'textAlignRight ' : '') . 'tBorder">';
                        switch ($field->getTemplateName('DetailView', $module)) {
                            case 'DetailViewName.tpl':
                                $html .= '<strong>' . $field->getDisplayValue($itemValue) . '</strong>';
                                if (isset($fields[2]['comment' . $rowNo])) {
                                    $COMMENT_FIELD = $fields[2]['comment' . $rowNo];
                                    $html .= '<br/>' . $COMMENT_FIELD->getDisplayValue($inventoryRow[$COMMENT_FIELD->get('columnname')]);
                                }
                                break;
                            case 'DetailViewBase.tpl':
                                $html .= $field->getDisplayValue($itemValue);
                                break;
                        }
                        $html .= '</td>';
                    }
                }
                $html .= '</tr>';
            }
            //			}
            $html .= '</tbody>
					<tfoot>
						<tr>';
            foreach ($fields[1] as $field) {
                if ($field->isVisible($inventoryRows)) {
                    $html .= '<td colspan="' . $field->get('colspan') . '" class="textAlignRight ';
                    if ($field->isSummary()) {
                        $html .= 'summaryBorder';
                    }
                    $html .= '">';
                    if ($field->isSummary()) {
                        $sum = 0;
                        foreach ($inventoryRows as $key => &$inventoryRow) {
                            $sum += $inventoryRow[$field->get('columnname')];
                        }
                        $html .= CurrencyField::convertToUserFormat($sum, null, true);
                    }
                    $html .= '</td>';
                }
            }
            $html .= '</tr>
					</tfoot>
				</table>';
            $discount = 0;
            $taxes = 0;
            foreach ($inventoryRows as $key => &$inventoryRow) {
                $discount += $inventoryRow['discount'];
                $taxes = $inventoryField->getTaxParam($inventoryRow['taxparam'], $inventoryRow['net'], $taxes);
            }
            $html .= '<br /><table width="100%" style="vertical-align: top; text-align: center;">
							<tr>
								<td>';
            if (in_array('discount', $columns) && in_array('discountmode', $columns)) {
                $html .= '<table class="pTable colapseBorder">
							<thead>
								<tr>
									<th class="tBorder noBottomBorder tHeader">
										<strong>' . vtranslate('LBL_DISCOUNTS_SUMMARY', $module) . '</strong>
									</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td class="textAlignRight tBorder">' . CurrencyField::convertToUserFormat($discount, null, true) . ' ' . $currencySymbolRate['symbol'] . '</td>
								</tr>
							</tbody>
						</table>';
            }
            $html .= '</td><td>';
            if (in_array('tax', $columns) && in_array('taxmode', $columns)) {
                $html .= '
						<table class="pTable colapseBorder">
							<thead>
								<tr>
									<th colspan="2" class="tBorder noBottomBorder tHeader">
										<strong>' . vtranslate('LBL_TAX_SUMMARY', $module) . '</strong>
									</th>
								</tr>
							</thead>
							<tbody>';
                foreach ($taxes as $key => &$tax) {
                    $tax_AMOUNT += $tax;
                    $html .= '<tr>
										<td class="textAlignRight tBorder" width="70px">' . $key . '%</td>
										<td class="textAlignRight tBorder">' . CurrencyField::convertToUserFormat($tax, null, true) . ' ' . $currencySymbolRate['symbol'] . '</td>
									</tr>';
                }
                $html .= '<tr>
									<td class="textAlignRight tBorder" width="70px">' . vtranslate('LBL_AMOUNT', $module) . '</td>
									<td class="textAlignRight tBorder">' . CurrencyField::convertToUserFormat($tax_AMOUNT, null, true) . ' ' . $currencySymbolRate['symbol'] . '</td>
								</tr>
							</tbody>
						</table>
					</div>';
                if (in_array('currency', $columns) && $baseCurrency['id'] != $currency) {
                    $RATE = $baseCurrency['conversion_rate'] / $currencySymbolRate['rate'];
                    $html .= '<br /><table class="pTable colapseBorder">
								<thead>
									<tr>
										<th colspan="2" class="tBorder noBottomBorder tHeader">
											<strong>' . vtranslate('LBL_CURRENCIES_SUMMARY', $module) . '</strong>
										</th>
									</tr>
								</thead>
								<tbody>';
                    foreach ($taxes as $key => &$tax) {
                        $currencyAmount += $tax;
                        $html .= '<tr>
									<td class="textAlignRight tBorder" width="70px">' . $key . '%</td>
									<td class="textAlignRight tBorder">' . CurrencyField::convertToUserFormat($tax * $RATE, null, true) . ' ' . $baseCurrency['currency_symbol'] . '</td>
								</tr>';
                    }
                    $html .= '<tr>
								<td class="textAlignRight tBorder" width="70px">' . vtranslate('LBL_AMOUNT', $module) . '</td>
								<td class="textAlignRight tBorder">' . CurrencyField::convertToUserFormat($currencyAmount * $RATE, null, true) . ' ' . $baseCurrency['currency_symbol'] . '</td>
							</tr>
						</tbody>
					</table>';
                }
            }
            $html .= '</td></tr></table>';
        }
        return $html;
    }