2007-11-15 19:07:24 +01:00
< ? 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 password d ' un formulaire pour LdapSaisie
*
2008-04-25 16:09:27 +02:00
* Cette classe définis les éléments password des formulaires .
* Elle étant la classe basic LSformElement .
2007-11-15 19:07:24 +01:00
*
* @ author Benjamin Renard < brenard @ easter - eggs . com >
*/
class LSformElement_password extends LSformElement {
2008-02-12 18:59:44 +01:00
/**
2008-04-25 16:09:27 +02:00
* Recupère la valeur de l ' élement passée en POST
2007-11-15 19:07:24 +01:00
*
2008-04-25 16:09:27 +02:00
* Cette méthode vérifie la présence en POST de la valeur de l ' élément et la récupère
* pour la mettre dans le tableau passer en paramètre avec en clef le nom de l ' élément
2007-11-15 19:07:24 +01:00
*
2008-04-25 16:09:27 +02:00
* @ param [] array Pointeur sur le tableau qui recupèrera la valeur .
2007-11-15 19:07:24 +01:00
*
2008-04-25 16:09:27 +02:00
* @ retval boolean true si la valeur est présente en POST , false sinon
2007-11-15 19:07:24 +01:00
*/
function getPostData ( & $return ) {
2008-04-25 16:09:27 +02:00
// Récupère la valeur dans _POST, et les vérifie avec la fonction générale
2008-02-12 18:59:44 +01:00
$retval = parent :: getPostData ( $return );
2008-04-25 16:09:27 +02:00
// Si une valeur est recupérée
2007-11-15 19:07:24 +01:00
if ( $retval ) {
2008-02-12 18:59:44 +01:00
$val = $this -> form -> ldapObject -> attrs [ $this -> name ] -> getValue ();
if ( ( empty ( $return [ $this -> name ][ 0 ]) ) && ( ! empty ( $val ) ) ) {
unset ( $return [ $this -> name ]);
$this -> form -> _notUpdate [ $this -> name ] == true ;
return true ;
}
}
2007-11-15 19:07:24 +01:00
return $retval ;
}
2008-05-15 12:56:55 +02:00
/**
2008-04-25 16:09:27 +02:00
* Retourne les infos d 'affichage de l' élément
2007-11-15 19:07:24 +01:00
*
2008-04-25 16:09:27 +02:00
* Cette méthode retourne les informations d 'affichage de l' élement
2007-11-15 19:07:24 +01:00
*
2008-02-05 17:11:21 +01:00
* @ retval array
2007-11-15 19:07:24 +01:00
*/
2008-02-12 18:59:44 +01:00
function getDisplay (){
$return = $this -> getLabelInfos ();
if ( ! $this -> isFreeze ()) {
2008-05-07 16:09:47 +02:00
$numberId = rand ();
$value_txt = '' ;
$input_type = 'password' ;
$autogenerate_html = '' ;
$class_txt = '' ;
// AutoGenerate
if (( $this -> params [ 'html_options' ][ 'generationTool' ]) || ( ! isset ( $this -> params [ 'html_options' ][ 'generationTool' ]))) {
if (( $this -> params [ 'html_options' ][ 'autoGenerate' ]) && ( empty ( $this -> values ))) {
$value_txt = " value=' " . $this -> generatePassword () . " ' " ;
$input_type = 'text' ;
}
$class_txt = " class='LSformElement_password_generate' " ;
$id = " LSformElement_password_generate_btn_ " . $this -> name . " _ " . $numberId ;
$autogenerate_html = " <img src='templates/images/generate.png' id=' $id ' class='LSformElement_password_generate_btn'/> \n " ;
}
$id = " LSformElement_password_ " . $this -> name . " _ " . $numberId ;
$return [ 'html' ] = " <input type=' $input_type ' name=' " . $this -> name . " []' $value_txt id=' $id ' $class_txt /> \n " ;
$return [ 'html' ] .= $autogenerate_html ;
$id = " LSformElement_password_view_btn_ " . $this -> name . " _ " . $numberId ;
$return [ 'html' ] .= " <img src='templates/images/view.png' id=' $id ' class='LSformElement_password_view_btn'/> \n " ;
2008-06-19 16:07:57 +02:00
if ( ! $this -> attr_html -> attribute -> ldapObject -> isNew ()) {
$id = " LSformElement_password_verify_btn_ " . $this -> name . " _ " . $numberId ;
$return [ 'html' ] .= " <img src='templates/images/verify.png' id=' $id ' class='LSformElement_password_verify_btn' alt= \" " . ( 'Vérifier le mot de passe' ) . " \" title= \" " . ( 'Vérifier le mot de passe' ) . " \" /> \n " ;
}
2008-05-07 16:09:47 +02:00
2008-02-12 18:59:44 +01:00
if ( ! empty ( $this -> values )) {
$return [ 'html' ] .= " * " . _ ( 'Modification uniquement' ) . " . " ;
}
2008-07-05 22:28:49 +02:00
$GLOBALS [ 'LSsession' ] -> addJSscript ( 'LSformElement_password.js' );
2008-02-12 18:59:44 +01:00
}
else {
if ( empty ( $this -> values )) {
2008-06-05 15:21:18 +02:00
$return [ 'html' ] = _ ( 'Aucune valeur definie' );
2008-02-12 18:59:44 +01:00
}
else {
$return [ 'html' ] = " ******** " ;
}
2007-11-15 19:07:24 +01:00
2008-02-12 18:59:44 +01:00
}
return $return ;
}
2008-05-07 16:09:47 +02:00
function generatePassword () {
2008-06-05 15:21:18 +02:00
return generatePassword ( $this -> params [ 'html_options' ][ 'chars' ], $this -> params [ 'html_options' ][ 'lenght' ]);
2008-05-07 16:09:47 +02:00
}
2008-06-19 16:07:57 +02:00
function verifyPassword ( $pwd ) {
if ( $this -> attr_html -> attribute -> ldapObject -> isNew ()) {
return false ;
}
return $GLOBALS [ 'LSsession' ] -> checkUserPwd ( $this -> attr_html -> attribute -> ldapObject , $pwd );
}
2007-11-15 19:07:24 +01:00
}
2008-02-12 18:59:44 +01:00
2007-11-15 19:07:24 +01:00
?>