2 /*******************************************************************************
3 * Copyright (C) 2007 Easter-eggs
4 * http://ldapsaisie.labs.libre-entreprise.org
6 * Author: See AUTHORS file in top-level directory.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ******************************************************************************/
25 * Element mailQuota d'un formulaire pour LdapSaisie
27 * Cette classe définis les éléments mailQuota des formulaires.
28 * Elle étant la classe basic LSformElement.
30 * @author Benjamin Renard <brenard@easter-eggs.com>
33 class LSformElement_mailQuota extends LSformElement {
35 var $fieldTemplate = 'LSformElement_mailQuota_field.tpl';
37 var $sizeFacts = array(
45 * Retourne les infos d'affichage de l'élément
47 * Cette méthode retourne les informations d'affichage de l'élement
51 function getDisplay(){
52 $return = $this -> getLabelInfos();
56 foreach ($this -> values as $value) {
57 if (ereg('([0-9]*)S',$value,$regs)) {
61 if ($infos['size'] >= 1000000000) {
62 $infos['valueSizeFact']=1000000000;
64 else if ($infos['size'] >= 1000000) {
65 $infos['valueSizeFact']=1000000;
67 else if ($infos['size'] >= 1000) {
68 $infos['valueSizeFact']=1000;
71 $infos['valueSizeFact']=1;
73 $infos['valueSize'] = $infos['size'] / $infos['valueSizeFact'];
74 $infos['valueTxt'] = $infos['valueSize'].$this ->sizeFacts[$infos['valueSizeFact']];
76 $quotas[$value] = $infos;
79 $quotas[$value] = array(
80 'unknown' => _('Incorrect value')
85 LSsession :: addCssFile('LSformElement_mailQuota.css');
87 $return['html'] = $this -> fetchTemplate(
91 'sizeFacts' => $this -> sizeFacts
98 * Retourne le code HTML d'un champ vide
100 * @retval string Code HTML d'un champ vide.
102 function getEmptyField() {
103 return $this -> fetchTemplate(
104 $this -> fieldTemplate,
106 'sizeFacts' => $this -> sizeFacts
112 * Recupère la valeur de l'élement passée en POST
114 * Cette méthode vérifie la présence en POST de la valeur de l'élément et la récupère
115 * pour la mettre dans le tableau passer en paramètre avec en clef le nom de l'élément
117 * @param[] array Pointeur sur le tableau qui recupèrera la valeur.
119 * @retval boolean true si la valeur est présente en POST, false sinon
121 function getPostData(&$return) {
122 if($this -> isFreeze()) {
125 if (isset($_POST[$this -> name.'_size'])) {
126 $return[$this -> name]=array();
127 if(!is_array($_POST[$this -> name.'_size'])) {
128 $_POST[$this -> name.'_size'] = array($_POST[$this -> name.'_size']);
130 if(isset($_POST[$this -> name.'_sizeFact']) && !is_array($_POST[$this -> name.'_sizeFact'])) {
131 $_POST[$this -> name.'_sizeFact'] = array($_POST[$this -> name.'_sizeFact']);
133 foreach($_POST[$this -> name.'_size'] as $key => $val) {
136 if (isset($_POST[$this -> name.'_sizeFact'][$key]) && ($_POST[$this -> name.'_sizeFact'][$key]!=1)) {
137 $f = $_POST[$this -> name.'_sizeFact'][$key];
139 $return[$this -> name][$key] = ($val*$f).'S';
145 $return[$this -> name] = array();