public function getListData($request) { $db = ezcDbInstance::get(); $sql = $this->getListSQL(); // Crea la tabella per poter chiamare createListTableHeader $this->createListTable(); $this->createListTableHeader($this->order); $init = array_key_exists('init', $this->request) || array_key_exists('reset', $this->request); if (!isset($this->limit)) { $this->limit = $this->auth === null ? 10 : max(10, $this->auth->getConfigValue('SETTINGS', 'ROW_COUNT', 10)); } if (!isset($this->pg)) { $this->pg = PageVar('pg', 1, $init); } // Apply the SQL order if ($this->order != '') { $orderFields = $this->simpleTable->getSQLOrder($this->order); if ($orderFields != '') { $sql .= " ORDER BY " . $this->simpleTable->getSQLOrder($this->order); } } if ($this->limit > 0) { $sql .= " LIMIT " . (int) max(0, $this->limit); $sql .= " OFFSET " . (int) max(0, ($this->pg - 1) * $this->limit); } $rows = array(); $stmt = $db->query($sql); $rowNo = 0; while ($row = $stmt->fetch()) { $rowNo++; $data = array(); foreach ($this->simpleTable->getFields() as $field) { $links = $this->getListTableRowOperations($row); if ($field['type'] == 'LINK') { $data[] = $this->simpleTable->CreateLinksCell($links); } else { if ($field['type'] == 'CALCULATED') { $data[] = $this->simpleTable->getCalcValue($field['field']); } else { $value = $row[$field['field']]; $format = $field['format']; $number_format = $field['number_format']; // Corregge il campo data if ($field['type'] == 'DATE') { if ($value == '0000-00-00') { $value = ''; } else { $value = SQLDateToStr($value, $format === false ? 'd/m/Y' : $format); } } else { if ($field['type'] == 'TIME') { if ($value == '00:00:00') { $value = ''; } else { $value = SQLDateToStr($value, $format === false ? 'h:i:s' : $format); } } else { if ($field['type'] == 'DATETIME') { if ($value == '0000-00-00 00:00:00') { $value = ''; } else { $value = SQLDateToStr($value, $format === false ? 'd/m/Y H:i:s' : $format); } } else { if (strpos($field['type'], 'URL') !== false) { if (strpos($field['type'], 'MAILTO') !== false) { $value = sprintf("<a href=\"mailto:%s\">%s</a>", $value, $value); } else { $value = sprintf("<a href=\"%s\" target=\"_BLANK\">%s</a>", $value, $value); } } else { // Format or number_format if ($value != '') { if ($format !== false) { $value = sprintf($format, $value); } else { if ($number_format !== false) { if (!defined("__R3_LOCALE__")) { require_once 'r3locale.php'; } $localeInfo = getLocaleInfo(); if (!is_array($number_format)) { $number_format = array('decimals' => $number_format, 'dec_point' => $localeInfo['decimal_point'], 'thousands_sep' => $localeInfo['thousands_sep']); } else { $number_format = array_merge(array('decimals' => 0, 'dec_point' => $localeInfo['decimal_point'], 'thousands_sep' => $localeInfo['thousands_sep']), $number_format); } if ($number_format['decimals'] === null && is_numeric($value)) { $diff = round($value - (int) $value, 10); if ($diff == 0) { $number_format['decimals'] = 0; } else { $number_format['decimals'] = strlen($diff) - 2; // -2 is 0. of the number } } $value = number_format($value, $number_format['decimals'], $number_format['dec_point'], $number_format['thousands_sep']); } } } } } } } $data[] = $value; } } } $rows[] = array('id' => $rowNo, 'cell' => $data); } $result = array(); $tot = $db->query($this->getListTotSQL())->fetchColumn(); $result['total'] = ceil($tot / $this->limit); $result['page'] = $this->pg; $result['records'] = $tot; $result['rows'] = $rows; return $result; }
public function CreateTableRow($row, $links = null, $styles = null, $events = null, $id = null) { // Replace Standart Styles $class_normal = $this->baseclass . '_normal'; $class_over = $this->baseclass . '_over'; $class_td = $this->baseclass . '_td'; if (count($styles) > 0) { if (array_key_exists('normal', $styles)) { if (is_array($styles['normal'])) { $class_normal = implode(' ', $styles['normal']); } else { $class_normal = $styles['normal']; } } if (array_key_exists('over', $styles)) { $class_over = $styles['over']; } if (array_key_exists('td', $styles)) { $class_td = $styles['td']; } } // Get Additional Events $AddEvents = ''; if ($events !== null && count($events) > 0) { while (list($event, $action) = each($events)) { if (strtolower($event) != 'onmouseover' && strtolower($event) != 'onmouseout') { $AddEvents = " {$event}=\"{$action};\" "; } } } if ($id !== null) { $id = "id=\"{$id}\" "; } $res = "<tr {$id}class=\"{$class_normal}\" onmouseover=\"this.className='{$class_over}';\" onmouseout=\"this.className='{$class_normal}';\" {$AddEvents}>\n"; $cont = 0; foreach ($this->fields as $field) { $hint = ''; if ($field['visible']) { $type = strtoupper($field['type']); if ($type == 'LINK') { $value = $this->CreateLinksCell($links); $res .= " <td class=\"{$class_td}\" align=\"center\">{$value}</td>\n"; } else { if ($field['align'] == '') { $align = $this->GetDefaultAlign($field['type']); } else { $align = strtolower($field['align']); } if ($field['type'] != 'CALCULATED') { // if (is_array($row)) $value = $row[$field['field']]; // else if (is_object($row)) $value = $row->getField($field['field']); if (is_array($row)) { $value = $row[$field['field']]; } else { $value = $row->getField($field['field']); } // PH: do not escape anything different from a string // TODO: check if a not empty string is returned as empty string. Give a warning mentioning the charset in that case if ($this->SetHtmlEntities && is_string($value)) { $value = HtmlEntities($value, ENT_QUOTES, $this->charset); } $format = $field['format']; $number_format = $field['number_format']; // Corregge il campo data if ($field['type'] == 'DATE') { if ($value == '0000-00-00') { $value = ''; } else { $value = SQLDateToStr($value, $format === false ? 'd/m/Y' : $format); } } else { if ($field['type'] == 'TIME') { if ($value == '00:00:00') { $value = ''; } else { $value = SQLDateToStr($value, $format === false ? 'H:i:s' : $format); } } else { if ($field['type'] == 'DATETIME') { if ($value == '0000-00-00 00:00:00') { $value = ''; } else { $value = SQLDateToStr($value, $format === false ? 'd/m/Y H:i:s' : $format); } } else { if (strpos($field['type'], 'URL') !== false) { if (strpos($field['type'], 'MAILTO') !== false) { $value = sprintf("<a href=\"mailto:%s\">%s</a>", $value, $value); } else { $value = sprintf("<a href=\"%s\" target=\"_BLANK\">%s</a>", $value, $value); } } else { if ($field['type'] == 'EURO') { // DEPRECATED! $value = valueToEuro($value); } else { if ($field['type'] == 'CHECKBOX') { if (!isset($_SESSION[$this->name][$field['field']])) { $_SESSION[$this->name][$field['field']] = array(); } if (!isset($_SESSION[$this->name][$field['field'] . '_off'])) { $_SESSION[$this->name][$field['field'] . '_off'] = array(); } if (in_array($value, $_SESSION[$this->name][$field['field']]) || $_SESSION[$this->name][$field['field'] . '_header'] == 'T' && !in_array($value, $_SESSION[$this->name][$field['field'] . '_off'])) { $checked = 'checked'; } else { $checked = ''; } // if (1==1) $checked = 'checked'; // else $checked = ''; // $value = "<input type=\"checkbox\" name=\"" . $field['field'] . "[]\" id=\"" . $field['field'] . "_$value\" value=\"$value\" $checked onclick=\"simpletable_onCheckboxClick(this, '" . $field['field'] . "', '" . $value . "')\">"; $tmp_value = ''; // - checkbox $tmp_value .= "<input type=\"checkbox\" name=\"" . $field['field'] . "[]\" id=\"" . $field['field'] . "_{$value}\" value=\"{$value}\" onClick=\"simpletable_setHeaderCheckboxStatus(this);\" {$checked}>"; // - hidden var (to store/remove old status) $tmp_value .= "<input type=\"hidden\" name=\"" . $field['field'] . "_hd[]\" id=\"" . $field['field'] . "_hd_{$value}\" value=\"{$value}\">"; $value = $tmp_value; //if (isset($field['header_checkbox']) && $field['header_checkbox'] == true) { //$label = "<input type=\"checkbox\" name=\"" . $field['field'] . "_header\" value=\"T\" onclick='simpletable_onHeaderCheckboxClick()'>" . $label; //unset($field['sortable']); //} } else { // Format or number_format if ($value != '') { if ($format !== false) { $value = sprintf($format, $value); } else { if ($number_format !== false) { if (!defined("__R3_LOCALE__")) { require_once 'r3locale.php'; } $localeInfo = getLocaleInfo(); if (!is_array($number_format)) { $number_format = array('decimals' => $number_format, 'dec_point' => $localeInfo['decimal_point'], 'thousands_sep' => $localeInfo['thousands_sep']); } else { $number_format = array_merge(array('decimals' => 0, 'dec_point' => $localeInfo['decimal_point'], 'thousands_sep' => $localeInfo['thousands_sep']), $number_format); } if ($number_format['decimals'] === null && is_numeric($value)) { $diff = round($value - (int) $value, 10); if ($diff == 0) { $number_format['decimals'] = 0; } else { $number_format['decimals'] = strlen($diff) - 2; // -2 is 0. of the number } } $value = number_format($value, $number_format['decimals'], $number_format['dec_point'], $number_format['thousands_sep']); } } } } } } } } } } else { // Calculated fields if (isset($this->calcvalues[$cont]['value'])) { $value = $this->calcvalues[$cont]['value']; } else { $value = ''; } if (isset($this->calcvalues[$cont]['hint'])) { $hint = 'title="' . htmlspecialchars($this->calcvalues[$cont]['hint']) . '"'; } } // Replace spaces from value with if ($field['type'] != 'CALCULATED' && $field['type'] != 'CHECKBOX' && strpos($field['type'], 'URL') === false && $field['wrap'] != true) { $value = str_replace(" ", " ", $value); } // add new line if ($field['wrap']) { $value = nl2br($value); } $res .= " <td class=\"{$class_td}\" align=\"{$align}\" {$hint}>{$value}</td>\n"; } } $cont++; } $res .= "</tr>\n"; // Clear calculated array unset($this->calcvalues); return $res; }
public function convert2Locale(array $vlu) { // Change to locale $oldMessageLocale = setlocale(LC_MESSAGES, 0); $oldNumericLocale = setlocale(LC_NUMERIC, 0); setlocale(LC_NUMERIC, getLocaleInfo(R3Locale::getLanguageCode())); setLangInfo(array('thousands_sep' => ".")); foreach ($this->fields as $key => $field) { if (isset($field['name'])) { $key = $field['name']; if (isset($field['dec']) && !isset($field['precision'])) { $field['precision'] = $field['dec']; } if (isset($field['is_primary_key']) && $field['is_primary_key'] === true) { continue; } if (array_key_exists($key, $vlu)) { if ($vlu[$key] === null) { $vlu[$key] = ''; // IE Fix in json response } else { $type = strToLower($field['type']); switch ($field['type']) { case 'real': case 'double': case 'number': case 'float': $vlu[$key] = R3NumberFormat($vlu[$key], isset($field['precision']) ? $field['precision'] : null, true); break; case 'integer': $vlu[$key] = R3NumberFormat($vlu[$key], isset($field['precision']) ? $field['precision'] : 0, true); break; case 'date': $vlu[$key] = SQLDateToStr($vlu[$key], R3Locale::getPhpDateFormat()); break; case 'datetime': case 'now': $vlu[$key] = SQLDateToStr($vlu[$key], R3Locale::getPhpDateTimeFormat()); break; case 'boolean': if ($vlu[$key] === true) { $vlu[$key] = 'T'; } else { if ($vlu[$key] === false) { $vlu[$key] = 'F'; } } } } } } } setlocale(LC_MESSAGES, $oldMessageLocale); setlocale(LC_NUMERIC, $oldNumericLocale); return $vlu; }
/** * Format a number with grouped thousands * * @param float the number * @param mixed the number of decimal points or null * @param mixed The locale code or null. If null the current locale is used * @return boolean return true on success * @see localeconv */ function locale_number_format($number, $decimals = null, $locale = null) { $info = getLocaleInfo($locale); if ($info === null) { return number_format($number, $decimals); } return number_format($number, $decimals, $info['decimal_point'], $info['thousands_sep']); }
function R3NumberFormat($value, $decimals = null, $useThousandsSep = false, $maxDec = 10) { if (is_array($value)) { foreach ($value as $key => $val) { $value[$key] = R3NumberFormat($val, $decimals, $useThousandsSep, $maxDec); } return $value; } else { if (strlen($value) == '') { return ''; } if (!defined("__R3_LOCALE__")) { require_once 'r3locale.php'; } $oldLocale = setlocale(LC_NUMERIC, 0); setlocale(LC_NUMERIC, getLocaleInfo(R3Locale::getLanguageCode())); setLangInfo(array('thousands_sep' => ".")); $localeInfo = getLocaleInfo(getLangLocaleByCode(R3Locale::getLanguageCode())); if ($decimals === null) { $diff = round($value - (int) $value, $maxDec); if ($diff == 0) { $decimals = 0; } else { $decimals = strlen($diff) - 2; // -2 is 0. of the number } } $thousands_sep = $useThousandsSep === true ? $localeInfo['thousands_sep'] : ''; $result = number_format($value, $decimals, $localeInfo['decimal_point'], $thousands_sep); setlocale(LC_ALL, $oldLocale); return $result; } }