dolibarr/htdocs/core/class/html.formsms.class.php

369 lines
13 KiB
PHP
Raw Normal View History

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@2byte.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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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
*/
require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php';
2011-03-05 17:27:26 +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
{
2018-08-22 11:06:34 +02:00
/**
* @var DoliDB Database handler.
*/
public $db;
2011-10-17 21:08:05 +02:00
2018-10-15 21:40:27 +02:00
public $fromname;
public $fromsms;
public $replytoname;
public $replytomail;
public $toname;
public $tomail;
2011-10-17 21:08:05 +02:00
2018-10-15 21:40:27 +02:00
public $withsubstit; // Show substitution array
public $withfrom;
public $withto;
public $withtopic;
public $withbody;
2011-10-17 21:08:05 +02:00
2018-10-15 21:40:27 +02:00
public $withfromreadonly;
public $withreplytoreadonly;
public $withtoreadonly;
public $withtopicreadonly;
public $withcancel;
2011-10-17 21:08:05 +02:00
2018-10-15 21:40:27 +02:00
public $substit=array();
public $param=array();
2011-10-17 21:08:05 +02:00
2018-08-22 10:37:16 +02:00
/**
2018-09-14 09:33:16 +02:00
* @var string Error code (or message)
*/
public $error='';
2011-10-17 21:08:05 +02:00
2018-10-15 21:40:27 +02:00
/**
* @var string[] Array of error strings
*/
public $errors=array();
2011-10-17 21:08:05 +02:00
/**
* Constructor
*
* @param DoliDB $db Database handler
2011-10-17 21:08:05 +02:00
*/
2019-02-26 23:15:28 +01:00
public function __construct($db)
2011-10-17 21:08:05 +02:00
{
$this->db = $db;
2011-10-17 21:08:05 +02:00
$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;
}
2019-02-26 23:15:28 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2011-10-17 21:08:05 +02:00
/**
* Show the form to input an sms.
2011-10-17 21:08:05 +02:00
*
2018-09-15 21:34:55 +02:00
* @param string $morecss Class on first column td
* @param int $showform Show form tags and submit button (recommanded is to use with value 0)
2011-10-17 21:08:05 +02:00
* @return void
*/
2019-02-26 23:15:28 +01:00
public function show_form($morecss = 'titlefield', $showform = 1)
2011-10-17 21:08:05 +02:00
{
2018-09-15 21:34:55 +02:00
// phpcs:enable
global $conf, $langs, $user, $form;
if (! is_object($form)) $form=new Form($this->db);
2011-10-17 21:08:05 +02:00
2018-09-13 15:06:06 +02:00
// Load translation files required by the page
$langs->loadLangs(array('other', 'mails', 'sms'));
2011-10-17 21:08:05 +02:00
2011-03-06 16:45:46 +01:00
$soc=new Societe($this->db);
2011-10-17 21:08:05 +02:00
if (!empty($this->withtosocid) && $this->withtosocid > 0)
2011-03-06 16:45:46 +01:00
{
$soc->fetch($this->withtosocid);
}
2011-10-17 21:08:05 +02:00
print "\n<!-- Begin form SMS -->\n";
2011-03-06 16:45:46 +01:00
2011-10-17 21:08:05 +02:00
print '
2011-03-06 16:45:46 +01:00
<script language="javascript">
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
2016-09-18 12:10:12 +02:00
if ($showform) print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
2017-09-01 16:38:56 +02:00
2011-10-17 21:08:05 +02:00
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
foreach ($this->param as $key=>$value)
{
print "<input type=\"hidden\" name=\"$key\" value=\"$value\">\n";
}
2016-09-18 12:10:12 +02:00
print "<table class=\"border centpercent\">\n";
2011-10-17 21:08:05 +02:00
// Substitution array
if (! empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this.
2011-10-17 21:08:05 +02:00
{
print "<tr><td colspan=\"2\">";
$help="";
foreach($this->substit as $key => $val)
{
$help.=$key.' -> '.$langs->trans($val).'<br>';
}
print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"), $help);
2011-10-17 21:08:05 +02:00
print "</td></tr>\n";
}
// From
if ($this->withfrom)
{
if ($this->withfromreadonly)
{
2017-09-01 17:07:26 +02:00
print '<tr><td class="titlefield '.$morecss.'">'.$langs->trans("SmsFrom");
2011-10-17 21:08:05 +02:00
print '<input type="hidden" name="fromsms" value="'.$this->fromsms.'">';
2016-09-18 12:10:12 +02:00
print "</td><td>";
2011-10-17 21:08:05 +02:00
if ($this->fromtype == 'user')
{
$langs->load("users");
$fuser=new User($this->db);
$fuser->fetch($this->fromid);
print $fuser->getNomUrl(1);
print ' &nbsp; ';
}
if ($this->fromsms)
{
print $this->fromsms;
}
else
{
if ($this->fromtype)
{
$langs->load("errors");
print '<font class="warning"> &lt;'.$langs->trans("ErrorNoPhoneDefinedForThisUser").'&gt; </font>';
}
}
print "</td></tr>\n";
print "</td></tr>\n";
}
else
{
2016-09-18 12:10:12 +02:00
print '<tr><td class="'.$morecss.'">'.$langs->trans("SmsFrom")."</td><td>";
2011-03-06 16:45:46 +01:00
//print '<input type="text" name="fromname" size="30" value="'.$this->fromsms.'">';
2011-10-17 21:08:05 +02:00
if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') // For backward compatibility @deprecated
2011-03-06 16:45:46 +01:00
{
dol_include_once('/ovh/class/ovhsms.class.php');
2011-04-13 20:43:31 +02:00
try
{
2011-06-09 01:10:42 +02:00
$sms = new OvhSms($this->db);
if (empty($conf->global->OVHSMS_ACCOUNT))
{
$resultsender = 'ErrorOVHSMS_ACCOUNT not defined';
}
else
{
2011-10-17 21:08:05 +02:00
$resultsender = $sms->SmsSenderList();
2011-06-09 01:10:42 +02:00
}
2011-04-13 20:43:31 +02:00
}
catch(Exception $e)
{
dol_print_error('', 'Error to get list of senders: '.$e->getMessage());
2011-04-13 20:43:31 +02:00
}
2011-03-06 16:45:46 +01:00
}
2019-01-27 10:49:34 +01:00
elseif (!empty($conf->global->MAIN_SMS_SENDMODE)) // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
2011-10-17 21:08:05 +02:00
{
$tmp=explode('@', $conf->global->MAIN_SMS_SENDMODE);
2011-10-17 21:08:05 +02:00
$classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
try
{
$classname=ucfirst($classfile);
2018-03-13 12:54:53 +01:00
if (class_exists($classname))
{
$sms = new $classname($this->db);
$resultsender = $sms->SmsSenderList();
}
else
{
$sms = new stdClass();
$sms->error='The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found';
2018-03-13 12:54:53 +01:00
}
2011-10-17 21:08:05 +02:00
}
catch(Exception $e)
{
dol_print_error('', 'Error to get list of senders: '.$e->getMessage());
2011-10-17 21:08:05 +02:00
exit;
}
}
2011-03-06 16:45:46 +01:00
else
{
2011-04-13 20:43:58 +02:00
dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING);
2014-04-23 14:51:08 +02:00
$resultsender=array();
2011-03-06 16:45:46 +01:00
$resultsender[0]->number=$this->fromsms;
}
2011-10-17 21:08:05 +02:00
if (is_array($resultsender) && count($resultsender) > 0)
2011-03-06 20:41:19 +01:00
{
2017-09-01 17:07:26 +02:00
print '<select name="fromsms" id="fromsms" class="flat">';
2011-06-09 01:40:20 +02:00
foreach($resultsender as $obj)
2011-03-06 20:41:19 +01:00
{
2011-06-09 01:40:20 +02:00
print '<option value="'.$obj->number.'">'.$obj->number.'</option>';
2011-03-06 20:41:19 +01:00
}
print '</select>';
2011-03-06 16:45:46 +01:00
}
2011-10-17 21:08:05 +02:00
else
{
2016-01-17 19:03:12 +01:00
print '<span class="error">'.$langs->trans("SmsNoPossibleSenderFound");
2011-10-17 21:08:05 +02:00
if (is_object($sms) && ! empty($sms->error)) print ' '.$sms->error;
print '</span>';
}
2011-03-06 16:45:46 +01:00
print '</td>';
2011-10-17 21:08:05 +02:00
print "</tr>\n";
}
}
2014-05-11 21:59:35 +02:00
// To (target)
2011-10-17 21:08:05 +02:00
if ($this->withto || is_array($this->withto))
{
2017-09-01 17:07:26 +02:00
print '<tr><td>';
2011-10-17 21:08:05 +02:00
//$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients");
$moretext='';
print $form->textwithpicto($langs->trans("SmsTo"), $moretext);
2011-10-17 21:08:05 +02:00
print '</td><td>';
if ($this->withtoreadonly)
{
print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
}
else
{
2016-12-18 01:44:26 +01:00
print "<input size=\"16\" id=\"sendto\" name=\"sendto\" value=\"".dol_escape_htmltag(! is_array($this->withto) && $this->withto != '1'? (isset($_REQUEST["sendto"])?GETPOST("sendto"):$this->withto):"+")."\">";
2011-10-17 21:08:05 +02:00
if (! empty($this->withtosocid) && $this->withtosocid > 0)
{
$liste=array();
2017-09-01 16:38:56 +02:00
foreach ($soc->thirdparty_and_contact_phone_array() as $key => $value)
2011-10-17 21:08:05 +02:00
{
$liste[$key]=$value;
}
print " ".$langs->trans("or")." ";
//var_dump($_REQUEST);exit;
print $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
2011-10-17 21:08:05 +02:00
}
print ' '.$langs->trans("SmsInfoNumero");
}
print "</td></tr>\n";
}
// Message
if ($this->withbody)
{
$defaultmessage='';
if ($this->param["models"]=='body')
{
$defaultmessage=$this->withbody;
}
$defaultmessage=make_substitutions($defaultmessage, $this->substit);
2011-10-17 21:08:05 +02:00
if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
$defaultmessage=str_replace('\n', "\n", $defaultmessage);
2011-10-17 21:08:05 +02:00
print "<tr>";
2017-09-01 17:07:26 +02:00
print '<td class="tdtop">'.$langs->trans("SmsText")."</td>";
2011-10-17 21:08:05 +02:00
print "<td>";
if ($this->withbodyreadonly)
{
print nl2br($defaultmessage);
2016-12-18 01:44:26 +01:00
print '<input type="hidden" name="message" value="'.dol_escape_htmltag($defaultmessage).'">';
2011-10-17 21:08:05 +02:00
}
else
{
2016-12-18 01:44:26 +01:00
print '<textarea class="quatrevingtpercent" name="message" id="message" rows="'.ROWS_4.'" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>';
2011-10-17 21:08:05 +02:00
print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160-dol_strlen($defaultmessage)).'</span></div></td>';
}
print "</td></tr>\n";
}
2011-03-05 17:27:26 +01:00
2011-10-17 21:08:05 +02:00
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>
<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>';
2011-10-17 21:08:05 +02:00
print "</table>\n";
2017-09-01 16:38:56 +02:00
if ($showform)
2011-10-17 21:08:05 +02:00
{
2016-09-18 12:10:12 +02:00
print '<div class="center">';
print '<input class="button" type="submit" name="sendmail" value="'.dol_escape_htmltag($langs->trans("SendSms")).'">';
if ($this->withcancel)
{
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input class="button" type="submit" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
}
print '</div>';
2017-09-01 16:38:56 +02:00
2016-09-18 12:10:12 +02:00
print "</form>\n";
2011-10-17 21:08:05 +02:00
}
2017-09-01 16:38:56 +02:00
2011-10-17 21:08:05 +02:00
print "<!-- End form SMS -->\n";
}
2011-03-05 17:27:26 +01:00
}