dolibarr  9.0.0
html.formsms.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
4  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
25 require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php';
26 
27 
34 class FormSms
35 {
39  public $db;
40 
41  public $fromname;
42  public $fromsms;
43  public $replytoname;
44  public $replytomail;
45  public $toname;
46  public $tomail;
47 
48  public $withsubstit; // Show substitution array
49  public $withfrom;
50  public $withto;
51  public $withtopic;
52  public $withbody;
53 
54  public $withfromreadonly;
55  public $withreplytoreadonly;
56  public $withtoreadonly;
57  public $withtopicreadonly;
58  public $withcancel;
59 
60  public $substit=array();
61  public $param=array();
62 
66  public $error='';
67 
71  public $errors=array();
72 
73 
79  function __construct($db)
80  {
81  $this->db = $db;
82 
83  $this->withfrom=1;
84  $this->withto=1;
85  $this->withtopic=1;
86  $this->withbody=1;
87 
88  $this->withfromreadonly=1;
89  $this->withreplytoreadonly=1;
90  $this->withtoreadonly=0;
91  $this->withtopicreadonly=0;
92  $this->withbodyreadonly=0;
93  }
94 
95  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
103  function show_form($morecss='titlefield', $showform=1)
104  {
105  // phpcs:enable
106  global $conf, $langs, $user, $form;
107 
108  if (! is_object($form)) $form=new Form($this->db);
109 
110  // Load translation files required by the page
111  $langs->loadLangs(array('other', 'mails', 'sms'));
112 
113  $soc=new Societe($this->db);
114  if (!empty($this->withtosocid) && $this->withtosocid > 0)
115  {
116  $soc->fetch($this->withtosocid);
117  }
118 
119  print "\n<!-- Begin form SMS -->\n";
120 
121  print '
122 <script language="javascript">
123 function limitChars(textarea, limit, infodiv)
124 {
125  var text = textarea.value;
126  var textlength = text.length;
127  var info = document.getElementById(infodiv);
128 
129  info.innerHTML = (limit - textlength);
130  return true;
131 }
132 </script>';
133 
134  if ($showform) print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
135 
136  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
137  foreach ($this->param as $key=>$value)
138  {
139  print "<input type=\"hidden\" name=\"$key\" value=\"$value\">\n";
140  }
141  print "<table class=\"border centpercent\">\n";
142 
143  // Substitution array
144  if (! empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this.
145  {
146  print "<tr><td colspan=\"2\">";
147  $help="";
148  foreach($this->substit as $key => $val)
149  {
150  $help.=$key.' -> '.$langs->trans($val).'<br>';
151  }
152  print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"),$help);
153  print "</td></tr>\n";
154  }
155 
156  // From
157  if ($this->withfrom)
158  {
159  if ($this->withfromreadonly)
160  {
161  print '<tr><td class="titlefield '.$morecss.'">'.$langs->trans("SmsFrom");
162  print '<input type="hidden" name="fromsms" value="'.$this->fromsms.'">';
163  print "</td><td>";
164  if ($this->fromtype == 'user')
165  {
166  $langs->load("users");
167  $fuser=new User($this->db);
168  $fuser->fetch($this->fromid);
169  print $fuser->getNomUrl(1);
170  print ' &nbsp; ';
171  }
172  if ($this->fromsms)
173  {
174  print $this->fromsms;
175  }
176  else
177  {
178  if ($this->fromtype)
179  {
180  $langs->load("errors");
181  print '<font class="warning"> &lt;'.$langs->trans("ErrorNoPhoneDefinedForThisUser").'&gt; </font>';
182  }
183  }
184  print "</td></tr>\n";
185  print "</td></tr>\n";
186  }
187  else
188  {
189  print '<tr><td class="'.$morecss.'">'.$langs->trans("SmsFrom")."</td><td>";
190  //print '<input type="text" name="fromname" size="30" value="'.$this->fromsms.'">';
191  if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') // For backward compatibility @deprecated
192  {
193  dol_include_once('/ovh/class/ovhsms.class.php');
194  try
195  {
196  $sms = new OvhSms($this->db);
197  if (empty($conf->global->OVHSMS_ACCOUNT))
198  {
199  $resultsender = 'ErrorOVHSMS_ACCOUNT not defined';
200  }
201  else
202  {
203  $resultsender = $sms->SmsSenderList();
204  }
205  }
206  catch(Exception $e)
207  {
208  dol_print_error('','Error to get list of senders: '.$e->getMessage());
209  }
210  }
211  else if (!empty($conf->global->MAIN_SMS_SENDMODE)) // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
212  {
213  $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
214  $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
215  dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
216  try
217  {
218  $classname=ucfirst($classfile);
219  if (class_exists($classname))
220  {
221  $sms = new $classname($this->db);
222  $resultsender = $sms->SmsSenderList();
223  }
224  else
225  {
226  $sms = new stdClass();
227  $sms->error='The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found';
228  }
229  }
230  catch(Exception $e)
231  {
232  dol_print_error('','Error to get list of senders: '.$e->getMessage());
233  exit;
234  }
235  }
236  else
237  {
238  dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING);
239  $resultsender=array();
240  $resultsender[0]->number=$this->fromsms;
241  }
242 
243  if (is_array($resultsender) && count($resultsender) > 0)
244  {
245  print '<select name="fromsms" id="fromsms" class="flat">';
246  foreach($resultsender as $obj)
247  {
248  print '<option value="'.$obj->number.'">'.$obj->number.'</option>';
249  }
250  print '</select>';
251  }
252  else
253  {
254  print '<span class="error">'.$langs->trans("SmsNoPossibleSenderFound");
255  if (is_object($sms) && ! empty($sms->error)) print ' '.$sms->error;
256  print '</span>';
257  }
258  print '</td>';
259  print "</tr>\n";
260  }
261  }
262 
263  // To (target)
264  if ($this->withto || is_array($this->withto))
265  {
266  print '<tr><td>';
267  //$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients");
268  $moretext='';
269  print $form->textwithpicto($langs->trans("SmsTo"),$moretext);
270  print '</td><td>';
271  if ($this->withtoreadonly)
272  {
273  print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
274  }
275  else
276  {
277  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):"+")."\">";
278  if (! empty($this->withtosocid) && $this->withtosocid > 0)
279  {
280  $liste=array();
281  foreach ($soc->thirdparty_and_contact_phone_array() as $key => $value)
282  {
283  $liste[$key]=$value;
284  }
285  print " ".$langs->trans("or")." ";
286  //var_dump($_REQUEST);exit;
287  print $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
288  }
289  print ' '.$langs->trans("SmsInfoNumero");
290  }
291  print "</td></tr>\n";
292  }
293 
294  // Message
295  if ($this->withbody)
296  {
297  $defaultmessage='';
298  if ($this->param["models"]=='body')
299  {
300  $defaultmessage=$this->withbody;
301  }
302  $defaultmessage=make_substitutions($defaultmessage,$this->substit);
303  if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
304  $defaultmessage=str_replace('\n',"\n",$defaultmessage);
305 
306  print "<tr>";
307  print '<td class="tdtop">'.$langs->trans("SmsText")."</td>";
308  print "<td>";
309  if ($this->withbodyreadonly)
310  {
311  print nl2br($defaultmessage);
312  print '<input type="hidden" name="message" value="'.dol_escape_htmltag($defaultmessage).'">';
313  }
314  else
315  {
316  print '<textarea class="quatrevingtpercent" name="message" id="message" rows="'.ROWS_4.'" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>';
317  print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160-dol_strlen($defaultmessage)).'</span></div></td>';
318  }
319  print "</td></tr>\n";
320  }
321 
322  print '
323  <tr>
324  <td>'.$langs->trans("DelayBeforeSending").':</td>
325  <td> <input name="deferred" id="deferred" size="4" value="0"></td></tr>
326 
327  <tr><td>'.$langs->trans("Priority").' :</td><td>
328  <select name="priority" id="priority" class="flat">
329  <option value="0">high</option>
330  <option value="1">medium</option>
331  <option value="2" selected>low</option>
332  <option value="3">veryLow</option>
333  </select></td></tr>
334 
335  <tr><td>'.$langs->trans("Type").' :</td><td>
336  <select name="class" id="class" class="flat">
337  <option value="0">Flash</option>
338  <option value="1" selected>Standard</option>
339  <option value="2">SIM</option>
340  <option value="3">ToolKit</option>
341  </select></td></tr>
342 
343  <tr><td>'.$langs->trans("DisableStopIfSupported").' :</td><td>
344  <select name="disablestop" id="disablestop" class="flat">
345  <option value="0" selected>No</option>
346  <option value="1" selected>Yes</option>
347  </select></td></tr>';
348 
349  print "</table>\n";
350 
351 
352  if ($showform)
353  {
354  print '<div class="center">';
355  print '<input class="button" type="submit" name="sendmail" value="'.dol_escape_htmltag($langs->trans("SendSms")).'">';
356  if ($this->withcancel)
357  {
358  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
359  print '<input class="button" type="submit" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
360  }
361  print '</div>';
362 
363  print "</form>\n";
364  }
365 
366  print "<!-- End form SMS -->\n";
367  }
368 }
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
if(! function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Classe permettant la generation du formulaire d&#39;envoi de Sms Usage: $formsms = new FormSms($db) $form...
show_form($morecss='titlefield', $showform=1)
Show the form to input an sms.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
__construct($db)
Constructor.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.