2008-07-31 11:16:25 +02:00
< ? php
/*******************************************************************************
* Copyright ( C ) 2007 Easter - eggs
2021-04-13 18:04:19 +02:00
* https :// ldapsaisie . org
2008-07-31 11:16:25 +02:00
*
* 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 .
******************************************************************************/
2009-01-24 18:45:14 +01:00
LSsession :: loadLSclass ( 'LSformElement_text' );
2008-07-31 11:16:25 +02:00
/**
* Element mail d ' un formulaire pour LdapSaisie
*
* Cette classe définis les éléments textes des formulaires .
* Elle étant la classe basic LSformElement .
*
* @ author Benjamin Renard < brenard @ easter - eggs . com >
*/
2008-10-15 19:40:04 +02:00
class LSformElement_mail extends LSformElement_text {
2008-07-31 11:16:25 +02:00
2023-01-03 12:51:45 +01:00
var $JSscripts = array (
2008-10-15 19:40:04 +02:00
'LSformElement_mail.js'
);
2020-04-23 19:53:56 +02:00
2023-01-03 12:51:45 +01:00
var $fetchVariables = array (
2021-03-03 14:34:06 +01:00
'additionalCssClass' => array ( 'LSformElement_mail' ),
2008-10-15 20:29:14 +02:00
'uriPrefix' => 'mailto:'
);
2020-04-23 19:53:56 +02:00
2023-01-03 12:51:45 +01:00
var $fieldTemplate = 'LSformElement_uri_field.tpl' ;
2020-04-23 19:53:56 +02:00
2021-03-03 14:34:06 +01:00
// Flag to trigger warning about old Autocomplete config style
// (detect in constructor and show on getDisplay())
2023-01-03 12:51:45 +01:00
private $warnOldAutocompleteConfigStyle = false ;
2021-03-03 14:34:06 +01:00
/**
* Constructor
*
* @ author Benjamin Renard < brenard @ easter - eggs . com >
*
2022-12-31 05:52:31 +01:00
* @ param LSform & $form The LSform parent object
* @ param string $name The name of the element
* @ param string $label The label of the element
* @ param array $params The parameters of the element
* @ param LSattr_html & $attr_html The LSattr_html object of the corresponding attribute
2021-03-03 14:34:06 +01:00
*
2022-12-31 05:52:31 +01:00
* @ return void
2021-03-03 14:34:06 +01:00
*/
public function __construct ( & $form , $name , $label , $params , & $attr_html ){
parent :: __construct ( $form , $name , $label , $params , $attr_html );
// Handle autocomplete retro-compatibility & default value attributes
if ( $this -> getParam ( 'html_options.autocomplete' )) {
$mail_attributes = $this -> getParam ( 'html_options.autocomplete.mail_attributes' );
if ( $mail_attributes ) {
$this -> params [ 'html_options' ][ 'autocomplete' ][ 'value_attributes' ] = $mail_attributes ;
$this -> warnOldAutocompleteConfigStyle = true ;
}
elseif ( ! $this -> getParam ( 'html_options.autocomplete.value_attributes' )) {
if ( ! is_array ( $this -> params [ 'html_options' ][ 'autocomplete' ]))
$this -> params [ 'html_options' ][ 'autocomplete' ] = array ();
$this -> params [ 'html_options' ][ 'autocomplete' ][ 'value_attributes' ] = array ( 'mail' );
$this -> warnOldAutocompleteConfigStyle = true ;
}
}
}
2019-03-12 11:42:53 +01:00
public function getDisplay () {
2020-06-04 19:04:48 +02:00
LStemplate :: addHelpInfo (
2008-11-10 04:07:28 +01:00
'LSformElement_mail' ,
array (
2009-02-14 00:06:58 +01:00
'mail' => _ ( " Send a mail from here. " )
2008-11-10 04:07:28 +01:00
)
);
2009-02-20 15:05:22 +01:00
if ( LSsession :: loadLSclass ( 'LSmail' )) {
LSmail :: loadDependenciesDisplay ();
}
2021-03-03 14:34:06 +01:00
if ( $this -> warnOldAutocompleteConfigStyle )
LSerror :: addErrorCode ( 'LSformElement_mail_01' );
2010-11-16 19:50:40 +01:00
return parent :: getDisplay ();
2008-11-10 04:07:28 +01:00
}
2010-12-03 18:04:40 +01:00
2020-04-23 19:53:56 +02:00
/**
2021-03-03 14:34:06 +01:00
* Return HTML code of the LSformElement based on its ( smarty ) template file
2020-04-23 19:53:56 +02:00
*
2022-12-31 05:52:31 +01:00
* @ param string $template The template filename ( optional , default : $this -> template )
* @ param array $variables Array of template variables to assign before template compilation ( optional )
2020-04-23 19:53:56 +02:00
*
2022-12-31 05:52:31 +01:00
* @ return string HTML code of the LSformElement
2020-04-23 19:53:56 +02:00
*/
2021-03-03 14:34:06 +01:00
public function fetchTemplate ( $template = NULL , $variables = array ()) {
if ( $this -> getParam ( 'html_options.disableMailSending' , false , 'bool' )) {
$this -> fetchVariables [ 'additionalCssClass' ][] = " LSformElement_mail_disableMailSending " ;
2020-04-23 19:53:56 +02:00
}
2021-03-03 14:34:06 +01:00
return parent :: fetchTemplate ( $template , $variables );
2020-04-23 19:53:56 +02:00
}
}
2021-03-03 14:34:06 +01:00
/**
* Error Codes
**/
LSerror :: defineError ( 'LSformElement_mail_01' ,
___ ( " LSformElement_mail: the autocomplete feature was moved to parent LSformElement_text class and you still use old configuration style with parameter mail_attributes (and its default value). Please upgrade your configuration by renaming (or setting) this parameter to value_attributes. " )
);