- LSform : correction de la méthode checkRequired() qui prennait mal en compte

les chaines "0"
- Ajout du type de donnée boolean :
  - class.LSattr_ldap_boolean.php
  - class.LSattr_html_boolean.php
  - class.LSformElement_boolean.php
- LSeepeople : Utilisation du type boolean pour l'attribut loginshell
This commit is contained in:
Benjamin Renard 2008-09-26 13:57:11 +00:00
parent d75a8823c2
commit 1f51f7601b
5 changed files with 236 additions and 8 deletions

View file

@ -163,7 +163,7 @@ $GLOBALS['LSobjects']['LSeepeople'] = array (
'html_type' => 'text',
'html_options' => array(
'generate_value_format' => '%{givenName} %{sn}',
'autoGenerateOnModify' => false // default : false
'autoGenerateOnModify' => true // default : false
),
'required' => 1,
'validation' => 'valid',
@ -222,8 +222,8 @@ $GLOBALS['LSobjects']['LSeepeople'] = array (
),
'loginShell' => array (
'label' => _('Interpreteur de commande'),
'ldap_type' => 'ascii',
'html_type' => 'select_list',
'ldap_type' => 'boolean',
'html_type' => 'boolean',
'required' => 1,
'default_value' => '/bin/false',
'rights' => array(
@ -235,10 +235,8 @@ $GLOBALS['LSobjects']['LSeepeople'] = array (
'modify' => 1,
'create' => 1
),
'possible_values' => array(
'/bin/false' => _('Aucun'),
'/bin/bash' => 'Bash',
)
'true_value' => '/bin/bash',
'false_value' => '/bin/false'
),
'sambaSID' => array (
'label' => _('Identifiant Samba'),

View file

@ -0,0 +1,53 @@
<?php
/*******************************************************************************
* Copyright (C) 2007 Easter-eggs
* http://ldapsaisie.labs.libre-entreprise.org
*
* Author: See AUTHORS file in top-level directory.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/
/**
* Type d'attribut HTML boolean
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSattr_html_boolean extends LSattr_html {
/**
* Ajoute l'attribut au formualaire passer en paramètre
*
* @param[in] &$form LSform Le formulaire
* @param[in] $idForm L'identifiant du formulaire
* @param[in] $data Valeur du champs du formulaire
*
* @retval LSformElement L'element du formulaire ajouté
*/
function addToForm (&$form,$idForm,$data=NULL) {
$element=$form -> addElement('boolean', $this -> name, $this -> config['label'],$this -> config, $this);
if(!$element) {
$GLOBALS['LSerror'] -> addErrorCode(206,$this -> name);
return;
}
if ($data) {
$element -> setValue($data);
}
return $element;
}
}
?>

View file

@ -0,0 +1,76 @@
<?php
/*******************************************************************************
* Copyright (C) 2007 Easter-eggs
* http://ldapsaisie.labs.libre-entreprise.org
*
* Author: See AUTHORS file in top-level directory.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/
/**
* Type d'attribut Ldap boolean
*
*/
class LSattr_ldap_boolean extends LSattr_ldap {
/**
* Retourne la valeur d'affichage de l'attribut après traitement lié à son type ldap
*
* @param[in] $data mixed La valeur de l'attribut
*
* @retval mixed La valeur d'affichage de l'attribut
*/
function getDisplayValue($data) {
if ($data==NULL)
return;
return ($this -> isTrue($data))?1:0;
}
/**
* Retourne la valeur de l'attribut après traitement lié à son type ldap
*
* @param[in] $data mixed La valeur de l'attribut
*
* @retval mixed La valeur traitée de l'attribut
*/
function getUpdateData($data) {
if ($data[0]==1) {
return array($this -> config['true_value']);
}
else {
return array($this -> config['false_value']);
}
}
/**
* Determine si la valeur passé en paramètre correspond a True ou non
*
* @param[in] $data La valeur de l'attribut
*
* @retval boolean True ou False
*/
function isTrue($data) {
if (!is_array($data)) {
$data=array($data);
}
if ($data[0] == $this -> config['true_value']) {
return true;
}
return;
}
}
?>

View file

@ -247,7 +247,7 @@ class LSform {
*/
function checkRequired($data) {
foreach($data as $val) {
if (!empty($val))
if (!empty($val)||(is_string($val)&&($val=="0")))
return true;
}
return;

View file

@ -0,0 +1,101 @@
<?php
/*******************************************************************************
* Copyright (C) 2007 Easter-eggs
* http://ldapsaisie.labs.libre-entreprise.org
*
* Author: See AUTHORS file in top-level directory.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/
/**
* Element texte d'un formulaire pour LdapSaisie
*
* Cette classe définis les éléments boolean des formulaires.
* Elle étant la classe basic LSformElement.
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSformElement_boolean extends LSformElement {
/**
* Retourne les infos d'affichage de l'élément
*
* Cette méthode retourne les informations d'affichage de l'élement
*
* @retval array
*/
function getDisplay(){
$return = $this -> getLabelInfos();
// value
if (!$this -> isFreeze()) {
$return['html'] = "<ul class='LSform'>\n";
if (empty($this -> values)) {
$return['html'] .= "<li>".$this -> getEmptyField()."</li>\n";
}
else {
foreach ($this -> values as $value) {
$return['html'] .= "<li><input type='radio' value='1' name='".$this -> name."[0]' ".(($this -> isTrue($this -> values))?'checked':'')." /> "._('Oui')."<input type='radio' value='0' name='".$this -> name."[0]' ".(($this -> isTrue($this -> values))?'':'checked')." /> "._('Non')."</li>\n";
}
}
$return['html'] .= "</ul>\n";
}
else {
$return['html'] = "<ul class='LSform LSformElement_text'>\n";
if (empty($this -> values)) {
$return['html'] .= "<li>"._('Aucune valeur definie')."</li>\n";
}
else {
$return['html'] .= "<li>".(($this -> isTrue($this -> values))?_('Oui'):_('Non'))."</li>\n";
}
$return['html'] .= "</ul>\n";
}
return $return;
}
/**
* Retourne le code HTML d'un champ vide
*
* @retval string Code HTML d'un champ vide.
*/
function getEmptyField() {
return "<input type='radio' value='1' name='".$this -> name."[0]' /> "._('Oui')."<input type='radio' value='0' name='".$this -> name."[0]' /> "._('Non');
}
/**
* Determine si la valeur passé en paramètre correspond a True ou non
*
* - true = si $data[] contient un champ à 1
* - false = sinon
*
* @param[in] $data La valeur de l'attribut
*
* @retval boolean True ou False
*/
function isTrue($data) {
if(!is_array($data)) {
$data=array($data);
}
if($data[0]==1) {
return true;
}
return;
}
}
?>