Beispiel #1
0
 /**
  * Convertit des heures en centièmes d'heures.
  *
  * @static
  * @access public
  * @param float $hours les heures
  * @return string le time
  * @todo à enlever du framework et mettre dans onlogistics/lib-functions
  */
 static function hourTohundredthsOfHour($hours)
 {
     $hundredthsOfHour = (double) $hours * 100.0;
     return sprintf("%01.2f", I18N::formatNumber($hundredthsOfHour));
 }
Beispiel #2
0
 /**
  * Construit le formulaire quickform à partir du tableau des propriétés de
  * l'objet courant.
  *
  * @access protected
  * @return void
  */
 public function buildForm($forceNotRequired = false)
 {
     // champs cachés nécessaires
     unset($this->form->_attributes['name']);
     $this->form->addElement('hidden', 'submitFlag', '1', 'id="submitFlag"');
     $this->form->addElement('hidden', 'retURL', $this->guessReturnURL(), 'id="retURL"');
     $this->form->addElement('hidden', 'entity', $this->clsname, 'id="entity"');
     $this->form->addElement('hidden', 'altname', $this->altname, 'id="altname"');
     $this->form->addElement('hidden', 'action', $this->action, 'id="action"');
     $this->form->addElement('hidden', 'objID', $this->object->getId(), 'id="objID"');
     $this->form->addElement('hidden', 'redirectURL', '', 'id="redirectURL"');
     $this->form->addElement('hidden', 'fromAddButton', '0', 'id="fromAddButton"');
     if (isset($_REQUEST['fromEntity'])) {
         $this->form->addElement('hidden', 'fromEntity', $_REQUEST['fromEntity'], 'id="fromEntity"');
     }
     // actions valider et annuler
     $this->form->addElement('header', 'actions', '');
     if ($this->action == GenericController::FEATURE_VIEW) {
         $this->form->addElement('button', null, A_BACK, 'id="backButton" class="button" ' . 'onclick="window.location.href=\'' . $this->guessReturnURL() . '\'"');
     } else {
         $this->form->addElement('submit', 'submitButton', A_VALIDATE, 'id="submitButton" class="button"');
         $this->form->addElement('button', 'cancelButton', A_CANCEL, 'id="cancelButton" class="button" ' . 'onclick="window.location.href=\'' . $this->guessReturnURL() . '\'"');
     }
     $hasRequiredFields = false;
     $i = 0;
     $j = 0;
     // on récupère le mapping qui va nous permettre de construire le form
     $mapping = $this->getAddEditMapping();
     $hasPasswd = false;
     $addLater = array();
     foreach ($mapping as $section => $elements) {
         // header
         if ($i == 0) {
             // première section, on assign le formTitle
             $this->formTitle = $section;
         }
         $sectionID = sprintf('header%02d', $i);
         $this->form->addElement('header', $sectionID, $section);
         // elements du formulaire
         foreach ($elements as $name => $params) {
             if (isset($this->_blankElements["{$j}"]) && $this->_blankElements["{$j}"] === true) {
                 $this->form->addElement(new HTML_QuickForm_Static());
             }
             $j++;
             $ename = $this->clsname . '_' . $name;
             $type = $this->getElementType($name);
             if ($type == Object::TYPE_MANYTOMANY) {
                 // XXX FIXME hack pour advmultiselect
                 $ename = 'advmultiselect' . $this->clsname . '_' . $name . '_IDs';
             }
             // si une méthode custom existe on l'appelle, si la methode
             // retourne la chaine 'pass' on cree l'element
             $customMethod = 'render' . $name;
             if (method_exists($this, $customMethod) && $this->{$customMethod}($ename, $params) !== 'pass') {
                 continue;
             }
             // sinon on crée l'élément
             $label = $params['label'];
             $opt = isset($params['options']) ? $params['options'] : '';
             $required = isset($params['required']) && $params['required'] && !$forceNotRequired;
             $editInplace = isset($params['inplace_edit']) && $params['inplace_edit'];
             $aeButton = isset($params['add_button']) && $params['add_button'];
             // XXX TODO passer un tableau plutôt
             $elts = $this->_createElement($name, $ename, $type, $label, $opt, $required, $editInplace, $aeButton);
             if ($editInplace) {
                 $addLater = array_merge($addLater, $elts);
             } else {
                 if (count($elts) == 1) {
                     $this->form->addElement($elts[0]);
                 } else {
                     $this->form->addGroup($elts, $ename . '_Group', $label, null, false);
                 }
             }
             // gestion de la valeur par défaut
             $getter = 'get' . $name;
             $arg = false;
             if ($type == Object::TYPE_FKEY) {
                 $getter = 'get' . $name . 'Id';
                 $ename = $this->clsname . '_' . $name . '_ID';
             } else {
                 if ($type == Object::TYPE_MANYTOMANY) {
                     $getter = 'get' . $name . 'CollectionIds';
                 } else {
                     if ($type == Object::TYPE_TIME) {
                         $arg = 'H:i';
                     } else {
                         if ($type == Object::TYPE_DATE) {
                             $arg = I18N::DATE_LONG;
                             //getHTMLSelectDateFormat();
                         } else {
                             if ($type == Object::TYPE_DATETIME) {
                                 $arg = I18N::DATETIME_LONG;
                                 //I18N::getHTMLSelectDateFormat() . ' H:i';
                             }
                         }
                     }
                 }
             }
             if (method_exists($this->object, $getter)) {
                 if ($type == Object::TYPE_PASSWORD) {
                     $this->formDefaults[$ename] = self::PW_NOCHG;
                     $this->formDefaults[$ename . '_Again'] = self::PW_NOCHG;
                     $hasPasswd = true;
                 } else {
                     if ($type == Object::TYPE_DATE) {
                         $date = $this->object->{$getter}() . ' 00:00:00';
                         $this->formDefaults['displayed' . $ename] = I18N::formatDate($date, $arg);
                         $this->formDefaults[$ename] = $this->object->{$getter}();
                     } else {
                         if ($type == Object::TYPE_DATETIME) {
                             $this->formDefaults['displayed' . $ename] = I18N::formatDate($this->object->{$getter}(), $arg);
                             $this->formDefaults[$ename] = $this->object->{$getter}();
                         } else {
                             if (in_array($type, array(Object::TYPE_FLOAT, Object::TYPE_DECIMAL))) {
                                 $dec_num = isset($params['dec_num']) ? $params['dec_num'] : 2;
                                 $this->formDefaults[$ename] = I18N::formatNumber($this->object->{$getter}(), $dec_num);
                             } else {
                                 if ($arg) {
                                     $this->formDefaults[$ename] = $this->object->{$getter}($arg);
                                 } else {
                                     $this->formDefaults[$ename] = $this->object->{$getter}();
                                 }
                             }
                         }
                     }
                 }
             }
             // validations et filtres selon le type
             if ($type == Object::TYPE_INT) {
                 // ajoute une validation numérique
                 $msg = sprintf(E_VALIDATE_FIELD . ' "%s" ' . E_VALIDATE_IS_INT, $params['label']);
                 $this->form->addRule($ename, $msg, 'numeric', '', 'client');
             } else {
                 if ($type == Object::TYPE_FLOAT || $type == Object::TYPE_DECIMAL) {
                     // ajoute une validation nombre flottant
                     $msg = sprintf(E_VALIDATE_FIELD . ' "%s" ' . E_VALIDATE_IS_DECIMAL, substr($params['label'], 0, -2));
                     $this->form->addRule($ename, $msg, 'regex', '/\\d+[\\.,]?\\d*/', 'client');
                 } else {
                     if ($type == Object::TYPE_URL) {
                         // ajoute une validation sur le format de l''url
                         $msg = sprintf(E_VALIDATE_FIELD . ' "%s" ' . E_VALIDATE_IS_URL, $params['label']);
                         $rx = '/^(http|https|ftp|news):\\/\\/.*$/';
                         $this->form->addRule($ename, $msg, 'regex', $rx, 'client');
                     } else {
                         if ($type == Object::TYPE_EMAIL) {
                             // ajoute une validation sur le format de l''url
                             $msg = sprintf(E_VALIDATE_FIELD . ' "%s" ' . E_VALIDATE_IS_EMAIL, $params['label']);
                             $this->form->addRule($ename, $msg, 'email', '', 'client');
                         }
                     }
                 }
             }
             // gestion des règles de validation
             if ($required) {
                 $msg = sprintf(E_VALIDATE_FIELD . ' "%s" ' . E_VALIDATE_IS_REQUIRED, $label);
                 if ($type == Object::TYPE_FKEY) {
                     // cas special pour les fk required ne suffit pas la
                     // valeur ## est accepté par required
                     $this->form->addRule($ename, $msg, 'numeric', '', 'client');
                     $this->form->addRule($ename, $msg, 'numeric');
                 }
                 $this->form->addRule($ename, $msg, 'required', '', 'client');
                 $this->form->addRule($ename, $msg, 'required');
             }
             if (isset($params['validationrules'])) {
                 foreach ($params['validationrules'] as $rule => $msg) {
                     if (!$hasRequiredFields && $rule == 'required') {
                         $hasRequiredFields = true;
                     }
                     // validation côté et client
                     $this->form->addRule($ename, $msg, $rule, '', 'client');
                     // et côté serveur
                     $this->form->addRule($ename, $msg, $rule);
                 }
             }
             // gestion des filtres
             if (isset($params['filters'])) {
                 foreach ($params['filters'] as $filter) {
                     $this->form->applyFilter($ename, $filter);
                 }
             }
         }
         $i++;
     }
     foreach ($addLater as $elt) {
         $this->form->addElement($elt);
     }
     if ($this->innerForm) {
         // gestion validations
         foreach ($this->innerForm->form->_rules as $id => $rule) {
             foreach ($rule as $index => $ruleItem) {
                 $this->form->addRule($id, $ruleItem['message'], $ruleItem['type'], $ruleItem['format'], $ruleItem['validation']);
             }
         }
         $this->innerForm->form->_rules = array();
     }
     if ($hasPasswd) {
         //$this->form->_attributes['autocomplete'] = 'off';
     }
     // on assigne le tableau des valeurs
     $this->form->setDefaults($this->formDefaults);
     // traduction pour les messages de validation js
     $this->form->setJsWarnings(E_VALIDATE_FORM . ' : ', '');
     $asterisc = '<span style="color: #f00;">*</span>&nbsp;';
     $this->form->setRequiredNote($asterisc . E_VALIDATE_REQUIRED_FIELD);
 }
Beispiel #3
0
/**
 * This file is part of the PWAK (PHP Web Application Kit) framework.
 *
 * PWAK is a php framework initially developed for the
 * {@link http://onlogistics.googlecode.com Onlogistics} ERP/Supply Chain
 * management web application.
 * It provides components and tools for developers to build complex web
 * applications faster and in a more reliable way.
 *
 * PHP version 5.1.0+
 * 
 * LICENSE: This source file is subject to the MIT license that is available
 * through the world-wide-web at the following URI:
 * http://opensource.org/licenses/mit-license.php
 *
 * @package   PWAK
 * @author    ATEOR dev team <*****@*****.**>
 * @copyright 2003-2008 ATEOR <*****@*****.**> 
 * @license   http://opensource.org/licenses/mit-license.php MIT License 
 * @version   SVN: $Id$
 * @link      http://pwak.googlecode.com
 * @since     File available since release 0.1.0
 * @filesource
 */
function grid_filter_formatnumber($number, $dec_num = 2, $skip_zeros = false)
{
    return $number === false || $number === "" || $number === null ? 'N/A' : I18N::formatNumber($number, $dec_num, $skip_zeros);
}
Beispiel #4
0
 /**
  * Formatte un pourcentage conformément aux usages dans la langue courante.
  *
  * Le premier paramètre doit être soit un entier, soit un nombre décimal,
  * soit une chaîne représentant le nombre.
  * Le deuxième paramètre permet de spécifier le nombre de décimales à
  * afficher, pour un entier ce sera 0 * $dec_num à moins que le paramètre 
  * skip_zeros vaille true, dans ce cas, si la partie décimale vaut zéro, 
  * seule la partie de gauche est retournée.
  *
  * Examples:
  * <code>
  * I18N::setLocale('fr_FR');
  * echo I18N::formatPercent("12.346");  // affiche: 12,35 %;
  *
  * I18N::setLocale('en_GB');
  * echo I18N::formatPercent('3412.300', 3, true); // affiche: % 3,412.3
  * </code>
  *
  * @static
  * @param  mixed int, double or string $number le nombre (montant)
  * @param  int $dec_num le nombre de décimales
  * @param  boolean $skip_zeros "effacer" les zeros en fin de chaine
  * @param  boolean $strict formate en tenant compte du separateur des milliers
  * @return string
  * @access public
  */
 public static function formatPercent($number, $dec_num = 2, $skip_zeros = false, $strict = false)
 {
     if (empty(self::$data)) {
         trigger_error(self::$messages['unset'], E_USER_ERROR);
     }
     $number = I18N::formatNumber($number, $dec_num, $skip_zeros, $strict);
     return sprintf(self::$data['percent_format'], $number);
 }