From 1f51f7601b218f91120cba079d9737ab4ce4d922 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Fri, 26 Sep 2008 13:57:11 +0000 Subject: [PATCH] =?UTF-8?q?-=20LSform=20:=20correction=20de=20la=20m=C3=A9?= =?UTF-8?q?thode=20checkRequired()=20qui=20prennait=20mal=20en=20compte=20?= =?UTF-8?q?=20=20les=20chaines=20"0"=20-=20Ajout=20du=20type=20de=20donn?= =?UTF-8?q?=C3=A9e=20boolean=20:=20=20=20-=20class.LSattr=5Fldap=5Fboolean?= =?UTF-8?q?.php=20=20=20-=20class.LSattr=5Fhtml=5Fboolean.php=20=20=20-=20?= =?UTF-8?q?class.LSformElement=5Fboolean.php=20-=20LSeepeople=20:=20Utilis?= =?UTF-8?q?ation=20du=20type=20boolean=20pour=20l'attribut=20loginshell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LSobjects/config.LSobjects.LSeepeople.php | 12 +-- .../class/class.LSattr_html_boolean.php | 53 +++++++++ .../class/class.LSattr_ldap_boolean.php | 76 +++++++++++++ trunk/includes/class/class.LSform.php | 2 +- .../class/class.LSformElement_boolean.php | 101 ++++++++++++++++++ 5 files changed, 236 insertions(+), 8 deletions(-) create mode 100644 trunk/includes/class/class.LSattr_html_boolean.php create mode 100644 trunk/includes/class/class.LSattr_ldap_boolean.php create mode 100644 trunk/includes/class/class.LSformElement_boolean.php diff --git a/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php b/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php index db6f6178..d3e05760 100644 --- a/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php +++ b/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php @@ -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'), diff --git a/trunk/includes/class/class.LSattr_html_boolean.php b/trunk/includes/class/class.LSattr_html_boolean.php new file mode 100644 index 00000000..953b8a9e --- /dev/null +++ b/trunk/includes/class/class.LSattr_html_boolean.php @@ -0,0 +1,53 @@ + + */ +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; + } + +} + +?> diff --git a/trunk/includes/class/class.LSattr_ldap_boolean.php b/trunk/includes/class/class.LSattr_ldap_boolean.php new file mode 100644 index 00000000..8eca3b35 --- /dev/null +++ b/trunk/includes/class/class.LSattr_ldap_boolean.php @@ -0,0 +1,76 @@ + 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; + } +} + +?> diff --git a/trunk/includes/class/class.LSform.php b/trunk/includes/class/class.LSform.php index c3670201..fcf78c4d 100644 --- a/trunk/includes/class/class.LSform.php +++ b/trunk/includes/class/class.LSform.php @@ -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; diff --git a/trunk/includes/class/class.LSformElement_boolean.php b/trunk/includes/class/class.LSformElement_boolean.php new file mode 100644 index 00000000..ec2771b0 --- /dev/null +++ b/trunk/includes/class/class.LSformElement_boolean.php @@ -0,0 +1,101 @@ + + */ + +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'] = "\n"; + } + else { + $return['html'] = "\n"; + } + return $return; + } + + /** + * Retourne le code HTML d'un champ vide + * + * @retval string Code HTML d'un champ vide. + */ + function getEmptyField() { + return " "._('Oui')." "._('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; + } + +} + +?>