2012-08-22 23:27:53 +02:00
< ? php
2018-10-15 21:40:27 +02:00
/* Copyright ( C ) 2005 - 2011 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2010 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2018-10-15 21:40:27 +02:00
*/
2011-03-05 17:27:26 +01:00
/**
2015-12-12 16:10:36 +01:00
* \file htdocs / core / class / html . formsms . class . php
2011-03-05 17:27:26 +01:00
* \ingroup core
* \brief Fichier de la classe permettant la generation du formulaire html d ' envoi de mail unitaire
*/
2020-04-10 10:59:32 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ;
2011-03-05 17:27:26 +01:00
2014-05-01 16:26:57 +02:00
/**
2012-01-27 16:10:44 +01:00
* Classe permettant la generation du formulaire d ' envoi de Sms
* Usage : $formsms = new FormSms ( $db )
* $formsms -> proprietes = 1 ou chaine ou tableau de valeurs
* $formsms -> show_form () affiche le formulaire
2011-03-05 17:27:26 +01:00
*/
class FormSms
{
2020-10-31 14:32:18 +01:00
/**
* @ var DoliDB Database handler .
*/
public $db ;
public $fromid ;
public $fromname ;
public $fromsms ;
public $fromtype ;
public $replytoname ;
public $replytomail ;
public $toname ;
public $tomail ;
public $withsubstit ; // Show substitution array
public $withfrom ;
public $withto ;
public $withtopic ;
public $withbody ;
/**
* @ var int Id of company
*/
public $withtosocid ;
public $withfromreadonly ;
public $withreplytoreadonly ;
public $withtoreadonly ;
public $withtopicreadonly ;
2023-09-02 10:14:25 +02:00
public $withbodyreadonly ;
2020-10-31 14:32:18 +01:00
public $withcancel ;
public $substit = array ();
public $param = array ();
/**
* @ var string Error code ( or message )
*/
public $error = '' ;
/**
* @ var string [] Array of error strings
*/
public $errors = array ();
/**
* Constructor
*
* @ param DoliDB $db Database handler
*/
public function __construct ( $db )
{
$this -> db = $db ;
$this -> withfrom = 1 ;
$this -> withto = 1 ;
$this -> withtopic = 1 ;
$this -> withbody = 1 ;
$this -> withfromreadonly = 1 ;
$this -> withreplytoreadonly = 1 ;
$this -> withtoreadonly = 0 ;
$this -> withtopicreadonly = 0 ;
$this -> withbodyreadonly = 0 ;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Show the form to input an sms .
*
* @ param string $morecss Class on first column td
* @ param int $showform Show form tags and submit button ( recommanded is to use with value 0 )
* @ return void
*/
public function show_form ( $morecss = 'titlefield' , $showform = 1 )
{
// phpcs:enable
2023-08-26 12:02:19 +02:00
global $conf , $langs , $form ;
2020-10-31 14:32:18 +01:00
2021-02-23 22:03:23 +01:00
if ( ! is_object ( $form )) {
$form = new Form ( $this -> db );
}
2020-10-31 14:32:18 +01:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'other' , 'mails' , 'sms' ));
$soc = new Societe ( $this -> db );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $this -> withtosocid ) && $this -> withtosocid > 0 ) {
2020-10-31 14:32:18 +01:00
$soc -> fetch ( $this -> withtosocid );
}
print " \n <!-- Begin form SMS --> \n " ;
print '
2023-02-18 15:10:05 +01:00
< script nonce = " '.getNonce().' " type = " text/javascript " >
2011-03-06 16:45:46 +01:00
function limitChars ( textarea , limit , infodiv )
{
var text = textarea . value ;
var textlength = text . length ;
var info = document . getElementById ( infodiv );
2011-10-17 21:36:10 +02:00
info . innerHTML = ( limit - textlength );
2011-03-06 16:45:46 +01:00
return true ;
}
</ script > ' ;
2011-03-05 17:27:26 +01:00
2021-02-23 22:03:23 +01:00
if ( $showform ) {
print " <form method= \" POST \" name= \" smsform \" enctype= \" multipart/form-data \" action= \" " . $this -> param [ " returnurl " ] . " \" > \n " ;
}
2020-10-31 14:32:18 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2021-02-23 22:03:23 +01:00
foreach ( $this -> param as $key => $value ) {
2020-10-31 14:32:18 +01:00
print " <input type= \" hidden \" name= \" $key\ " value = \ " $value\ " > \n " ;
}
print " <table class= \" border centpercent \" > \n " ;
// Substitution array
2021-02-23 22:03:23 +01:00
if ( ! empty ( $this -> withsubstit )) { // Unset or set ->withsubstit=0 to disable this.
2020-10-31 14:32:18 +01:00
print " <tr><td colspan= \" 2 \" > " ;
$help = " " ;
2021-02-23 22:03:23 +01:00
foreach ( $this -> substit as $key => $val ) {
2020-10-31 14:32:18 +01:00
$help .= $key . ' -> ' . $langs -> trans ( $val ) . '<br>' ;
}
print $form -> textwithpicto ( $langs -> trans ( " SmsTestSubstitutionReplacedByGenericValues " ), $help );
print " </td></tr> \n " ;
}
// From
2021-02-23 22:03:23 +01:00
if ( $this -> withfrom ) {
if ( $this -> withfromreadonly ) {
2020-10-31 14:32:18 +01:00
print '<tr><td class="titlefield ' . $morecss . '">' . $langs -> trans ( " SmsFrom " );
print '<input type="hidden" name="fromsms" value="' . $this -> fromsms . '">' ;
print " </td><td> " ;
2021-02-23 22:03:23 +01:00
if ( $this -> fromtype == 'user' ) {
2020-10-31 14:32:18 +01:00
$langs -> load ( " users " );
$fuser = new User ( $this -> db );
$fuser -> fetch ( $this -> fromid );
print $fuser -> getNomUrl ( 1 );
print ' ' ;
}
2021-02-23 22:03:23 +01:00
if ( $this -> fromsms ) {
2020-10-31 14:32:18 +01:00
print $this -> fromsms ;
} else {
2021-02-23 22:03:23 +01:00
if ( $this -> fromtype ) {
2020-10-31 14:32:18 +01:00
$langs -> load ( " errors " );
2021-10-05 09:41:03 +02:00
print '<span class="warning"> <' . $langs -> trans ( " ErrorNoPhoneDefinedForThisUser " ) . '> </span>' ;
2020-10-31 14:32:18 +01:00
}
}
print " </td></tr> \n " ;
print " </td></tr> \n " ;
} else {
print '<tr><td class="' . $morecss . '">' . $langs -> trans ( " SmsFrom " ) . " </td><td> " ;
2023-08-26 12:02:19 +02:00
if ( getDolGlobalString ( 'MAIN_SMS_SENDMODE' )) {
$sendmode = getDolGlobalString ( 'MAIN_SMS_SENDMODE' ); // $conf->global->MAIN_SMS_SENDMODE looks like a value 'module'
$classmoduleofsender = getDolGlobalString ( 'MAIN_MODULE_' . strtoupper ( $sendmode ) . '_SMS' , $sendmode ); // $conf->global->MAIN_MODULE_XXX_SMS looks like a value 'class@module'
if ( $classmoduleofsender == 'ovh' ) {
$classmoduleofsender = 'ovhsms@ovh' ; // For backward compatibility
2020-10-31 14:32:18 +01:00
}
2023-08-26 12:02:19 +02:00
$tmp = explode ( '@' , $classmoduleofsender );
2021-03-01 20:37:16 +01:00
$classfile = $tmp [ 0 ];
$module = ( empty ( $tmp [ 1 ]) ? $tmp [ 0 ] : $tmp [ 1 ]);
2020-10-31 14:32:18 +01:00
dol_include_once ( '/' . $module . '/class/' . $classfile . '.class.php' );
try {
$classname = ucfirst ( $classfile );
2021-02-23 22:03:23 +01:00
if ( class_exists ( $classname )) {
2020-10-31 14:32:18 +01:00
$sms = new $classname ( $this -> db );
$resultsender = $sms -> SmsSenderList ();
} else {
$sms = new stdClass ();
2023-08-26 12:02:19 +02:00
$sms -> error = 'The SMS manager "' . $classfile . '" defined into SMS setup MAIN_MODULE_' . strtoupper ( $sendmode ) . '_SMS is not found' ;
2020-10-31 14:32:18 +01:00
}
2021-02-23 22:03:23 +01:00
} catch ( Exception $e ) {
2020-10-31 14:32:18 +01:00
dol_print_error ( '' , 'Error to get list of senders: ' . $e -> getMessage ());
exit ;
}
} else {
dol_syslog ( " Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE " , LOG_WARNING );
$resultsender = array ();
$resultsender [ 0 ] -> number = $this -> fromsms ;
}
2021-02-23 22:03:23 +01:00
if ( is_array ( $resultsender ) && count ( $resultsender ) > 0 ) {
2020-10-31 14:32:18 +01:00
print '<select name="fromsms" id="fromsms" class="flat">' ;
2021-02-23 22:03:23 +01:00
foreach ( $resultsender as $obj ) {
2020-10-31 14:32:18 +01:00
print '<option value="' . $obj -> number . '">' . $obj -> number . '</option>' ;
}
print '</select>' ;
} else {
print '<span class="error">' . $langs -> trans ( " SmsNoPossibleSenderFound " );
2021-02-23 22:03:23 +01:00
if ( is_object ( $sms ) && ! empty ( $sms -> error )) {
print ' ' . $sms -> error ;
}
2020-10-31 14:32:18 +01:00
print '</span>' ;
}
print '</td>' ;
print " </tr> \n " ;
}
}
// To (target)
2021-02-23 22:03:23 +01:00
if ( $this -> withto || is_array ( $this -> withto )) {
2020-10-31 14:32:18 +01:00
print '<tr><td>' ;
//$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients");
$moretext = '' ;
print $form -> textwithpicto ( $langs -> trans ( " SmsTo " ), $moretext );
print '</td><td>' ;
2021-02-23 22:03:23 +01:00
if ( $this -> withtoreadonly ) {
2020-10-31 14:32:18 +01:00
print ( ! is_array ( $this -> withto ) && ! is_numeric ( $this -> withto )) ? $this -> withto : " " ;
} else {
2022-12-28 12:42:44 +01:00
print '<input size="16" id="sendto" name="sendto" value="' . dol_escape_htmltag ( ! is_array ( $this -> withto ) && $this -> withto != '1' ? ( GETPOSTISSET ( " sendto " ) ? GETPOST ( " sendto " ) : $this -> withto ) : " + " ) . '">' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $this -> withtosocid ) && $this -> withtosocid > 0 ) {
2020-10-31 14:32:18 +01:00
$liste = array ();
2021-02-23 22:03:23 +01:00
foreach ( $soc -> thirdparty_and_contact_phone_array () as $key => $value ) {
2020-10-31 14:32:18 +01:00
$liste [ $key ] = $value ;
}
print " " . $langs -> trans ( " or " ) . " " ;
//var_dump($_REQUEST);exit;
print $form -> selectarray ( " receiver " , $liste , GETPOST ( " receiver " ), 1 );
}
print ' <span class="opacitymedium">' . $langs -> trans ( " SmsInfoNumero " ) . '</span>' ;
}
print " </td></tr> \n " ;
}
// Message
2021-02-23 22:03:23 +01:00
if ( $this -> withbody ) {
2020-10-31 14:32:18 +01:00
$defaultmessage = '' ;
2021-02-23 22:03:23 +01:00
if ( $this -> param [ " models " ] == 'body' ) {
2020-10-31 14:32:18 +01:00
$defaultmessage = $this -> withbody ;
}
$defaultmessage = make_substitutions ( $defaultmessage , $this -> substit );
2021-02-23 22:03:23 +01:00
if ( GETPOSTISSET ( " message " )) {
$defaultmessage = GETPOST ( " message " , 'restricthtml' );
}
2020-10-31 14:32:18 +01:00
$defaultmessage = str_replace ( '\n' , " \n " , $defaultmessage );
print " <tr> " ;
print '<td class="tdtop">' . $langs -> trans ( " SmsText " ) . " </td> " ;
print " <td> " ;
2021-02-23 22:03:23 +01:00
if ( $this -> withbodyreadonly ) {
2020-10-31 14:32:18 +01:00
print nl2br ( $defaultmessage );
print '<input type="hidden" name="message" value="' . dol_escape_htmltag ( $defaultmessage ) . '">' ;
} else {
print '<textarea class="quatrevingtpercent" name="message" id="message" rows="' . ROWS_4 . '" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">' . $defaultmessage . '</textarea>' ;
2022-11-18 00:58:23 +01:00
print '<div id="charlimitinfo" class="opacitymedium">' . $langs -> trans ( " SmsInfoCharRemain " ) . ': <span id="charlimitinfospan">' . ( 160 - dol_strlen ( $defaultmessage )) . '</span></div></td>' ;
2020-10-31 14:32:18 +01:00
}
print " </td></tr> \n " ;
}
print '
2011-03-06 16:45:46 +01:00
< tr >
< td > '.$langs->trans("DelayBeforeSending").' :</ td >
< td > < input name = " deferred " id = " deferred " size = " 4 " value = " 0 " ></ td ></ tr >
< tr >< td > '.$langs->trans("Priority").' :</ td >< td >
2017-09-01 17:07:26 +02:00
< select name = " priority " id = " priority " class = " flat " >
2016-01-17 19:03:12 +01:00
< option value = " 0 " > high </ option >
< option value = " 1 " > medium </ option >
< option value = " 2 " selected > low </ option >
< option value = " 3 " > veryLow </ option >
2011-03-06 20:41:19 +01:00
</ select ></ td ></ tr >
< tr >< td > '.$langs->trans("Type").' :</ td >< td >
2017-09-01 17:07:26 +02:00
< select name = " class " id = " class " class = " flat " >
2011-03-06 20:41:19 +01:00
< option value = " 0 " > Flash </ option >
2015-05-07 12:20:20 +02:00
< option value = " 1 " selected > Standard </ option >
2011-03-06 20:41:19 +01:00
< option value = " 2 " > SIM </ option >
< option value = " 3 " > ToolKit </ option >
2017-09-01 17:07:26 +02:00
</ select ></ td ></ tr >
< tr >< td > '.$langs->trans("DisableStopIfSupported").' :</ td >< td >
< select name = " disablestop " id = " disablestop " class = " flat " >
< option value = " 0 " selected > No </ option >
< option value = " 1 " selected > Yes </ option >
2011-03-06 16:45:46 +01:00
</ select ></ td ></ tr > ' ;
2020-10-31 14:32:18 +01:00
print " </table> \n " ;
2011-10-17 21:08:05 +02:00
2017-09-01 16:38:56 +02:00
2021-02-23 22:03:23 +01:00
if ( $showform ) {
2020-10-31 14:32:18 +01:00
print '<div class="center">' ;
2021-08-24 17:04:17 +02:00
print '<input type="submit" class="button" name="sendmail" value="' . dol_escape_htmltag ( $langs -> trans ( " SendSms " )) . '">' ;
2021-02-23 22:03:23 +01:00
if ( $this -> withcancel ) {
2020-10-31 14:32:18 +01:00
print ' ' ;
2020-11-23 15:12:52 +01:00
print '<input class="button button-cancel" type="submit" name="cancel" value="' . dol_escape_htmltag ( $langs -> trans ( " Cancel " )) . '">' ;
2020-10-31 14:32:18 +01:00
}
print '</div>' ;
2017-09-01 16:38:56 +02:00
2020-10-31 14:32:18 +01:00
print " </form> \n " ;
}
2017-09-01 16:38:56 +02:00
2020-10-31 14:32:18 +01:00
print " <!-- End form SMS --> \n " ;
}
2011-03-05 17:27:26 +01:00
}