示例#1
0
 static function money_format($originalValue, $locale = DEFAULT_LOCALE)
 {
     if (!is_numeric($originalValue)) {
         return $originalValue;
     }
     if (!$locale) {
         $locale = DEFAULT_LOCALE;
     }
     $locales = uLocale::ListLocale(NULL, '%C', true);
     $c = null;
     if (isset($locales[$locale])) {
         $c = $locales[$locale];
     } else {
         foreach ($locales as $l) {
             foreach ($l as $v) {
                 if ($v === $locale) {
                     $c = $l;
                     break 2;
                 }
             }
         }
     }
     if (!$c) {
         return $originalValue;
     }
     $dp = $originalValue - floor($originalValue) > 0 || $originalValue < 100 ? 2 : 0;
     $value = number_format($originalValue, $dp, $c['mon_decimal_point'], $c['mon_thousands_sep']);
     if ($originalValue >= 0) {
         if ($c['p_cs_precedes']) {
             if ($c['p_sep_by_space']) {
                 $value = ' ' . $value;
             }
             $value = $c['currency_symbol'] . $value;
         } else {
             if ($c['p_sep_by_space']) {
                 $value .= ' ';
             }
             $value .= $c['currency_symbol'];
         }
     } else {
         if ($c['n_cs_precedes']) {
             if ($c['n_sep_by_space']) {
                 $value = ' ' . $value;
             }
             $value = $c['currency_symbol'] . $value;
         } else {
             if ($c['n_sep_by_space']) {
                 $value .= ' ';
             }
             $value .= $c['currency_symbol'];
         }
     }
     $value = mb_convert_encoding($value, 'HTML-ENTITIES', CHARSET_ENCODING);
     return $value;
 }
示例#2
0
 /**
  * Defines a virtual field in the module, allowing access to the data within the database.
  * @see CreateTable
  */
 public function &AddField($aliasName, $fieldName, $tableAlias = NULL, $visiblename = NULL, $inputtype = itNONE, $values = NULL)
 {
     //,$options=0,$values=NULL) {
     $this->_SetupFields();
     if ($tableAlias === NULL) {
         $tableAlias = $this->sqlTableSetup['alias'];
     }
     $this->fields[$aliasName] = array('alias' => $aliasName, 'tablename' => $tableAlias, 'visiblename' => $visiblename, 'inputtype' => $inputtype, 'options' => NULL, 'field' => $fieldName);
     $this->fields[$aliasName]['order'] = count($this->fields);
     $before = $this->insertBefore;
     if (is_string($before) && isset($this->fields[$before])) {
         $this->fields[$aliasName]['order'] = $this->fields[$before]['order'] - 0.5;
     }
     if (is_array($fieldName)) {
         $this->fields[$aliasName]['field'] = "";
         $this->AddPreProcessCallback($aliasName, $fieldName);
     }
     if ($tableAlias) {
         $this->fields[$aliasName]['vtable'] = $this->sqlTableSetupFlat[$tableAlias];
     }
     switch ($this->GetFieldType($aliasName)) {
         case ftFILE:
         case ftIMAGE:
         case ftUPLOAD:
             $this->AddField($aliasName . '_filename', $fieldName . '_filename', $tableAlias);
             $this->AddField($aliasName . '_filetype', $fieldName . '_filetype', $tableAlias);
             break;
         case ftCURRENCY:
             $list = uLocale::ListLocale();
             $this->AddField($aliasName . '_locale', $fieldName . '_locale', $tableAlias, count($list) > 1 ? 'Currency' : NULL, itCOMBO, $list);
             $this->AddPreProcessCallback($aliasName, array('utopia', 'convCurrency'));
             break;
         case ftDATE:
             $this->AddPreProcessCallback($aliasName, array('utopia', 'convDate'));
             break;
         case ftTIME:
             $this->AddPreProcessCallback($aliasName, array('utopia', 'convTime'));
             break;
         case ftDATETIME:
         case ftTIMESTAMP:
             $this->AddPreProcessCallback($aliasName, array('utopia', 'convDateTime'));
             break;
     }
     // values here
     if ($values === NULL) {
         switch ($inputtype) {
             //case itNONE: // commented to prevent huge memory usage on BLOB fields.  Set Values to true if you need it!
             case itCOMBO:
             case itOPTION:
                 $values = true;
             default:
                 break;
         }
     }
     $this->fields[$aliasName]['values'] = $values;
     if ($visiblename !== NULL) {
         if (!$this->layoutSections) {
             $this->NewSection('');
         }
         $this->fields[$aliasName]['layoutsection'] = $this->cLayoutSection;
     }
     return $this->fields[$aliasName];
 }
 public static function InitLocale()
 {
     uLocale::ResetLocale();
     if (self::$locale_limit === NULL) {
         uLocale::LimitLocale(array(DEFAULT_LOCALE));
     }
 }