Example #1
0
 public static function get_val($tab, $field, $record, $links_not_recommended = false, $args = null)
 {
     static $recurrence_call_stack = array();
     self::init($tab);
     $commondata_sep = '/';
     if (!isset(self::$table_rows[$field])) {
         if (!isset(self::$hash[$field])) {
             trigger_error('Unknown field "' . $field . '" for recordset "' . $tab . '"', E_USER_ERROR);
         }
         $field = self::$hash[$field];
     }
     if ($args === null) {
         $args = self::$table_rows[$field];
     }
     if (!array_key_exists('id', $record)) {
         $record['id'] = null;
     }
     if (!array_key_exists($args['id'], $record)) {
         trigger_error($args['id'] . ' - unknown field for record ' . serialize($record), E_USER_ERROR);
     }
     $val = $record[$args['id']];
     $function_call_id = implode('|', array($tab, $field, serialize($val)));
     if (isset($recurrence_call_stack[$function_call_id])) {
         return '!! ' . __('recurrence issue') . ' !!';
     } else {
         $recurrence_call_stack[$function_call_id] = true;
     }
     self::display_callback_cache($tab);
     if (isset(self::$display_callback_table[$tab][$field])) {
         $ret = self::call_display_callback(self::$display_callback_table[$tab][$field], $record, $links_not_recommended, self::$table_rows[$field], $tab);
     } else {
         $ret = $val;
         if ($args['type'] == 'select' || $args['type'] == 'multiselect') {
             if (is_array($val) && empty($val) || !is_array($val) && $val == '') {
                 $ret = '---';
                 unset($recurrence_call_stack[$function_call_id]);
                 return $ret;
             }
             $param = explode(';', $args['param']);
             $pp = explode('::', $param[0]);
             $tab = $pp[0];
             if (isset($pp[1])) {
                 $col = $pp[1];
             } else {
                 $col = null;
             }
             //return;//trigger_error("\"param\" attribute of field \"$field\" is not valid. Please set <recordset>::<field>");
             if (!$col && $tab == '__COMMON__') {
                 unset($recurrence_call_stack[$function_call_id]);
                 return;
             }
             if (!is_array($val)) {
                 $val = array($val);
             }
             //              if ($tab=='__COMMON__') $data = Utils_CommonDataCommon::get_translated_array($col, true);
             if ($tab == '__RECORDSETS__') {
                 $single_tab = false;
             } else {
                 $tabs = explode(',', $tab);
                 $single_tab = count($tabs) == 1;
             }
             $ret = '';
             $first = true;
             foreach ($val as $k => $v) {
                 //                  if ($tab=='__COMMON__' && !isset($data[$v])) continue;
                 if ($tab == '__COMMON__') {
                     $path = explode('/', $v);
                     $tooltip = '';
                     $res = '';
                     if (count($path) > 1) {
                         $res .= Utils_CommonDataCommon::get_value($col . '/' . $path[0], true);
                         if (count($path) > 2) {
                             $res .= $commondata_sep . '...';
                             $tooltip = '';
                             $full_path = $col;
                             foreach ($path as $w) {
                                 $full_path .= '/' . $w;
                                 $tooltip .= ($tooltip ? $commondata_sep : '') . Utils_CommonDataCommon::get_value($full_path, true);
                             }
                         }
                         $res .= $commondata_sep;
                     }
                     $val = Utils_CommonDataCommon::get_value($col . '/' . $v, true);
                     if (!$val) {
                         continue;
                     }
                     $res .= $val;
                     if ($first) {
                         $first = false;
                     } else {
                         $ret .= '<br>';
                     }
                     $res = self::no_wrap($res);
                     if ($tooltip) {
                         $res = '<span ' . Utils_TooltipCommon::open_tag_attrs($tooltip, false) . '>' . $res . '</span>';
                     }
                     $ret .= $res;
                 } else {
                     if (!$single_tab) {
                         list($tab, $v) = explode('/', $v, 2);
                     }
                     if ($first) {
                         $first = false;
                     } else {
                         $ret .= '<br>';
                     }
                     if ($col) {
                         $columns = explode('|', $col);
                         $ret .= Utils_RecordBrowserCommon::create_linked_label($tab, $columns, $v, $links_not_recommended);
                     } else {
                         $ret .= Utils_RecordBrowserCommon::create_default_linked_label($tab, $v, $links_not_recommended);
                     }
                 }
             }
             if ($ret == '') {
                 $ret = '---';
             }
         } elseif ($args['type'] == 'commondata') {
             if (!isset($val) || $val === '') {
                 $ret = '';
             } else {
                 $arr = explode('::', $args['param']['array_id']);
                 $path = array_shift($arr);
                 foreach ($arr as $v) {
                     $path .= '/' . $record[self::get_field_id($v)];
                 }
                 $path .= '/' . $record[$args['id']];
                 $ret = Utils_CommonDataCommon::get_value($path, true);
             }
             /*            } elseif ($args['type']=='record') {
                           if (!isset($val) || $val==='') {
                               $ret = '';
                           } else {
                               @list($rs,$rid) = explode('#',$record[$args['id']],2);
                               if(!$rid) $ret = '';
                               else {
                                   $ret = self::create_default_linked_label($rs,$rid,$links_not_recommended);
                               }
                           }*/
         } elseif ($args['type'] == 'autonumber') {
             if (!$links_not_recommended && isset($record['id']) && $record['id']) {
                 $ret = self::record_link_open_tag_r($tab, $record) . $val . self::record_link_close_tag();
             }
         } elseif ($args['type'] == 'currency') {
             $val = Utils_CurrencyFieldCommon::get_values($val);
             $ret = Utils_CurrencyFieldCommon::format($val[0], $val[1]);
         } elseif ($args['type'] == 'checkbox') {
             $ret = $ret ? __('Yes') : __('No');
         } elseif ($args['type'] == 'date') {
             if ($val != '') {
                 $ret = Base_RegionalSettingsCommon::time2reg($val, false, true, false);
             }
         } elseif ($args['type'] == 'timestamp') {
             if ($val != '') {
                 $ret = Base_RegionalSettingsCommon::time2reg($val, 'without_seconds');
             }
         } elseif ($args['type'] == 'time') {
             if ($val != '') {
                 $ret = Base_RegionalSettingsCommon::time2reg($val, 'without_seconds', false);
             }
         } elseif ($args['type'] == 'long text') {
             $ret = htmlspecialchars($val);
             $ret = str_replace("\n", '<br>', $ret);
             $ret = Utils_BBCodeCommon::parse($ret);
         }
     }
     unset($recurrence_call_stack[$function_call_id]);
     return $ret;
 }
Example #2
0
	function getFrozenHtml() {
		$val = Utils_CurrencyFieldCommon::get_values(str_replace(Utils_CurrencyFieldCommon::get_decimal_point(), '.', $this->getValue()));
		return Utils_CurrencyFieldCommon::format($val[0], isset($this->currency)?$this->currency:1);
	}
Example #3
0
 public function format_cell($format, $val, $type = 'none')
 {
     if (!is_array($format)) {
         $format = array($format => '');
     } else {
         $format = array_flip($format);
     }
     $ret = array();
     if (!is_array($val)) {
         $val = array($val);
     }
     if (isset($format['currency']) || isset($format['numeric']) || isset($format['percent'])) {
         $format['fade_out_zero'] = 1;
     }
     if (isset($format['currency']) && empty($val)) {
         $val = array(Base_User_SettingsCommon::get('Utils_CurrencyField', 'default_currency') => 0);
     }
     $css_class = '';
     $style = '';
     $attrs = '';
     foreach ($val as $k => $v) {
         $next = $v;
         if ((double) $v == 0 && strlen($v) > 0 && $v != (string) (double) $v) {
             unset($format['fade_out_zero']);
         } else {
             if (isset($format['currency'])) {
                 $v = strip_tags($v);
                 $next = Utils_CurrencyFieldCommon::format($v, $k);
             }
             if (isset($format['currency']) || isset($format['numeric'])) {
                 if ((double) $v != 0) {
                     unset($format['fade_out_zero']);
                 }
             }
         }
         if (isset($format['percent'])) {
             if ($type == 'row_total' || $type == 'total_all') {
                 $cols = count($this->gb_captions) - 2;
                 if (!empty($this->categories)) {
                     $cols--;
                 }
                 if (!$v) {
                     $v = '--';
                 }
             }
             if ($type == 'col_total' || $type == 'total_all') {
                 $rows = count($this->ref_records);
                 if (!$v) {
                     $v = '--';
                 }
             }
             if (is_numeric($v)) {
                 $v = number_format($v, 2);
             }
             $next = $v . ' %';
             if ($v != 0) {
                 unset($format['fade_out_zero']);
             }
         }
         $ret[] = $next;
     }
     if (isset($format['currency'])) {
         foreach ($ret as $k => $v) {
             if (count($ret) == 1) {
                 break;
             }
             $value = Utils_CurrencyFieldCommon::parse_currency($v);
             if ($value[0] == 0) {
                 unset($ret[$k]);
             }
         }
     }
     if (isset($format['currency']) || isset($format['numeric']) || isset($format['percent'])) {
         $css_class .= ' number';
         if (isset($format['fade_out_zero'])) {
             $css_class .= ' fade-out-zero';
         }
     }
     if ($this->first) {
         $css_class .= ' top-row';
     }
     if (isset($format['total-row_desc'])) {
         $css_class .= ' total-row_desc';
     }
     if (isset($format['row_desc'])) {
         $css_class .= ' row-desc';
     }
     if (isset($format['total_all'])) {
         $css_class .= ' total-all';
     } elseif (isset($format['total'])) {
         $css_class .= ' total';
     }
     $ret = implode('<br>', $ret);
     if ($this->pdf) {
         $ret = array('value' => $ret, 'style' => $format, 'attrs' => '', 'class' => '');
     } else {
         $ret = array('value' => $ret, 'style' => $style, 'attrs' => $attrs, 'class' => $css_class);
     }
     return $ret;
 }
Example #4
0
 public function format()
 {
     return Utils_CurrencyFieldCommon::format($this->get_amount(), $this->get_currency_id());
 }