/** * 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_formatdate($date, $fmt = 'DATETIME_SHORT') { if (defined('I18N::' . $fmt)) { $fmt = constant('I18N::' . $fmt); } return I18N::formatDate($date, $fmt); }
/** * render * * @access public * @return void */ public function render() { $this->setSelection(); $header = array(array(), array('label' => I18N::formatDate(mktime(0, 0, 0, $this->month, $this->day, $this->year), I18N::DATE_LONG_TEXTUAL))); $rows = array(); while ($e = $this->fetch()) { $hour = $e->thisHour(); $minute = $e->thisMinute(); if ($hour >= $this->timetable->firstHour && $hour <= $this->timetable->lastHour) { $row = array('hour' => $hour . ':' . $minute); if ($e->isSelected()) { $cell = array('class' => 'timetable_calCell timetable_calCellBusy', 'busy' => 1); } elseif ($e->isEmpty()) { $cell = array('class' => 'timetable_calCell timetable_calCellEmpty', 'busy' => 0); } if (!$e->isEmpty()) { $cell['popup'] = ''; while ($entry = $e->getEntry()) { $cell['events'][] = $entry; } } $row['cells'][] = $cell; $rows[] = $row; } } $smarty = new Template(); $smarty->assign('header', $header); $smarty->assign('rows', $rows); }
/** * Transforme une date issue d'un Widget de date de QuickForm de la forme: * 'dMY H:i' en date au format french. * * @static * @param $fieldName string nom du champs * @access public * @return string */ static function quickFormDateToFrenchDate($fieldName, $hour = true) { $date = DateTimeTools::QuickFormDateToMySQL($fieldName); return I18N::formatDate($date, $hour ? I18N::DATETIME_LONG : I18N::DATE_LONG); }
/** * Retourne la date mysql au format $format. * * Valeurs possibles de $format et type de retour: * - 'timestamp': retourne un timestamp unix * - 'quickform': retourne une date au format PEAR::QuickForm * - 'localedate': retourne une date au format JJ/MM/AA HH:MM:SS (si fr) * - 'localedate_short': retourne une date au format JJ/MM/AA (si fr) * - une chaine acceptée par la fonction php "date" * (cf. http://php.net/date) * * @access public * @param string $value la valeur de la date au format MySQL * @param string $format le format désiré * @return mixed */ public function dateFormat($value, $format = false) { if (false == $format) { return $value; } switch ($format) { case 'timestamp': return DateTimeTools::MySQLDateToTimeStamp($value); case 'quickform': return DateTimeTools::MySQLToQuickFormDate($value); case 'localedate': return I18N::formatDate($value); case 'localedate_short': return I18N::formatDate($value, I18N::DATE_LONG); default: $value = DateTimeTools::MySQLDateToTimeStamp($value); return date($format, $value); } }
/** * 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> '; $this->form->setRequiredNote($asterisc . E_VALIDATE_REQUIRED_FIELD); }
/** * render * * @access public * @return void */ public function render() { $this->setSelection(); $header = array(0 => array()); $firstDayOfweek = $this->week->toArray($this->week->thisWeek); for ($i = 0; $i < 7; $i++) { $ts = mktime(0, 0, 0, $firstDayOfweek['month'], $firstDayOfweek['day'] + $i, $firstDayOfweek['year']); $header[$i + 1] = array('label' => I18N::formatDate(date('Y-m-d h:i:s', $ts), I18N::DATE_SHORT_TEXTUAL)); if (isset($this->clickOnDayUrl)) { $header[$i + 1]['onclick'] = sprintf('window.location=\'' . $this->clickOnDayUrl . '\';', date('Y', $ts), date('n', $ts), date('j', $ts)); } } $rows = array(); for ($j = $this->timetable->firstHour; $j <= $this->timetable->lastHour; $j++) { $row = array('hour' => $j . ':00'); $row['cells'] = array(); while ($e = $this->fetch($j)) { $cell = array(); if ($e->isSelected()) { $cell['divAttr'] = ''; $cell['busy'] = 1; $cell['events'] = array(); while ($entry = $e->getEntry()) { $cell['events'][] = $entry; unset($entry); } } $row['cells'][] = $cell; unset($cell, $e); } $rows[] = $row; unset($row); } $title = sprintf(_('Week %s of %s'), $this->thisWeek('n_in_year'), $this->thisYear()); $smarty = new Template(); $smarty->assign('title', $title); $smarty->assign('header', $header); $smarty->assign('rows', $rows); }