dolibarr  13.0.2
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 <https://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 $fromid;
42  public $fromname;
43  public $fromsms;
44  public $fromtype;
45  public $replytoname;
46  public $replytomail;
47  public $toname;
48  public $tomail;
49 
50  public $withsubstit; // Show substitution array
51  public $withfrom;
52  public $withto;
53  public $withtopic;
54  public $withbody;
55 
59  public $withtosocid;
60 
61  public $withfromreadonly;
62  public $withreplytoreadonly;
63  public $withtoreadonly;
64  public $withtopicreadonly;
65  public $withcancel;
66 
67  public $substit = array();
68  public $param = array();
69 
73  public $error = '';
74 
78  public $errors = array();
79 
80 
86  public function __construct($db)
87  {
88  $this->db = $db;
89 
90  $this->withfrom = 1;
91  $this->withto = 1;
92  $this->withtopic = 1;
93  $this->withbody = 1;
94 
95  $this->withfromreadonly = 1;
96  $this->withreplytoreadonly = 1;
97  $this->withtoreadonly = 0;
98  $this->withtopicreadonly = 0;
99  $this->withbodyreadonly = 0;
100  }
101 
102  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
110  public function show_form($morecss = 'titlefield', $showform = 1)
111  {
112  // phpcs:enable
113  global $conf, $langs, $user, $form;
114 
115  if (!is_object($form)) $form = new Form($this->db);
116 
117  // Load translation files required by the page
118  $langs->loadLangs(array('other', 'mails', 'sms'));
119 
120  $soc = new Societe($this->db);
121  if (!empty($this->withtosocid) && $this->withtosocid > 0)
122  {
123  $soc->fetch($this->withtosocid);
124  }
125 
126  print "\n<!-- Begin form SMS -->\n";
127 
128  print '
129 <script language="javascript">
130 function limitChars(textarea, limit, infodiv)
131 {
132  var text = textarea.value;
133  var textlength = text.length;
134  var info = document.getElementById(infodiv);
135 
136  info.innerHTML = (limit - textlength);
137  return true;
138 }
139 </script>';
140 
141  if ($showform) print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
142 
143  print '<input type="hidden" name="token" value="'.newToken().'">';
144  foreach ($this->param as $key=>$value)
145  {
146  print "<input type=\"hidden\" name=\"$key\" value=\"$value\">\n";
147  }
148  print "<table class=\"border centpercent\">\n";
149 
150  // Substitution array
151  if (!empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this.
152  {
153  print "<tr><td colspan=\"2\">";
154  $help = "";
155  foreach ($this->substit as $key => $val)
156  {
157  $help .= $key.' -> '.$langs->trans($val).'<br>';
158  }
159  print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"), $help);
160  print "</td></tr>\n";
161  }
162 
163  // From
164  if ($this->withfrom)
165  {
166  if ($this->withfromreadonly)
167  {
168  print '<tr><td class="titlefield '.$morecss.'">'.$langs->trans("SmsFrom");
169  print '<input type="hidden" name="fromsms" value="'.$this->fromsms.'">';
170  print "</td><td>";
171  if ($this->fromtype == 'user')
172  {
173  $langs->load("users");
174  $fuser = new User($this->db);
175  $fuser->fetch($this->fromid);
176  print $fuser->getNomUrl(1);
177  print ' &nbsp; ';
178  }
179  if ($this->fromsms)
180  {
181  print $this->fromsms;
182  } else {
183  if ($this->fromtype)
184  {
185  $langs->load("errors");
186  print '<font class="warning"> &lt;'.$langs->trans("ErrorNoPhoneDefinedForThisUser").'&gt; </font>';
187  }
188  }
189  print "</td></tr>\n";
190  print "</td></tr>\n";
191  } else {
192  print '<tr><td class="'.$morecss.'">'.$langs->trans("SmsFrom")."</td><td>";
193  //print '<input type="text" name="fromname" size="30" value="'.$this->fromsms.'">';
194  if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') // For backward compatibility @deprecated
195  {
196  dol_include_once('/ovh/class/ovhsms.class.php');
197  try {
198  $sms = new OvhSms($this->db);
199  if (empty($conf->global->OVHSMS_ACCOUNT))
200  {
201  $resultsender = 'ErrorOVHSMS_ACCOUNT not defined';
202  } else {
203  $resultsender = $sms->SmsSenderList();
204  }
205  } catch (Exception $e)
206  {
207  dol_print_error('', 'Error to get list of senders: '.$e->getMessage());
208  }
209  } elseif (!empty($conf->global->MAIN_SMS_SENDMODE)) // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
210  {
211  $tmp = explode('@', $conf->global->MAIN_SMS_SENDMODE);
212  $classfile = $tmp[0]; $module = (empty($tmp[1]) ? $tmp[0] : $tmp[1]);
213  dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
214  try {
215  $classname = ucfirst($classfile);
216  if (class_exists($classname))
217  {
218  $sms = new $classname($this->db);
219  $resultsender = $sms->SmsSenderList();
220  } else {
221  $sms = new stdClass();
222  $sms->error = 'The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found';
223  }
224  } catch (Exception $e)
225  {
226  dol_print_error('', 'Error to get list of senders: '.$e->getMessage());
227  exit;
228  }
229  } else {
230  dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING);
231  $resultsender = array();
232  $resultsender[0]->number = $this->fromsms;
233  }
234 
235  if (is_array($resultsender) && count($resultsender) > 0)
236  {
237  print '<select name="fromsms" id="fromsms" class="flat">';
238  foreach ($resultsender as $obj)
239  {
240  print '<option value="'.$obj->number.'">'.$obj->number.'</option>';
241  }
242  print '</select>';
243  } else {
244  print '<span class="error">'.$langs->trans("SmsNoPossibleSenderFound");
245  if (is_object($sms) && !empty($sms->error)) print ' '.$sms->error;
246  print '</span>';
247  }
248  print '</td>';
249  print "</tr>\n";
250  }
251  }
252 
253  // To (target)
254  if ($this->withto || is_array($this->withto))
255  {
256  print '<tr><td>';
257  //$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients");
258  $moretext = '';
259  print $form->textwithpicto($langs->trans("SmsTo"), $moretext);
260  print '</td><td>';
261  if ($this->withtoreadonly)
262  {
263  print (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto : "";
264  } else {
265  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) : "+")."\">";
266  if (!empty($this->withtosocid) && $this->withtosocid > 0)
267  {
268  $liste = array();
269  foreach ($soc->thirdparty_and_contact_phone_array() as $key => $value)
270  {
271  $liste[$key] = $value;
272  }
273  print " ".$langs->trans("or")." ";
274  //var_dump($_REQUEST);exit;
275  print $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
276  }
277  print ' <span class="opacitymedium">'.$langs->trans("SmsInfoNumero").'</span>';
278  }
279  print "</td></tr>\n";
280  }
281 
282  // Message
283  if ($this->withbody)
284  {
285  $defaultmessage = '';
286  if ($this->param["models"] == 'body')
287  {
288  $defaultmessage = $this->withbody;
289  }
290  $defaultmessage = make_substitutions($defaultmessage, $this->substit);
291  if (GETPOSTISSET("message")) $defaultmessage = GETPOST("message", 'restricthtml');
292  $defaultmessage = str_replace('\n', "\n", $defaultmessage);
293 
294  print "<tr>";
295  print '<td class="tdtop">'.$langs->trans("SmsText")."</td>";
296  print "<td>";
297  if ($this->withbodyreadonly)
298  {
299  print nl2br($defaultmessage);
300  print '<input type="hidden" name="message" value="'.dol_escape_htmltag($defaultmessage).'">';
301  } else {
302  print '<textarea class="quatrevingtpercent" name="message" id="message" rows="'.ROWS_4.'" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>';
303  print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160 - dol_strlen($defaultmessage)).'</span></div></td>';
304  }
305  print "</td></tr>\n";
306  }
307 
308  print '
309  <tr>
310  <td>'.$langs->trans("DelayBeforeSending").':</td>
311  <td> <input name="deferred" id="deferred" size="4" value="0"></td></tr>
312 
313  <tr><td>'.$langs->trans("Priority").' :</td><td>
314  <select name="priority" id="priority" class="flat">
315  <option value="0">high</option>
316  <option value="1">medium</option>
317  <option value="2" selected>low</option>
318  <option value="3">veryLow</option>
319  </select></td></tr>
320 
321  <tr><td>'.$langs->trans("Type").' :</td><td>
322  <select name="class" id="class" class="flat">
323  <option value="0">Flash</option>
324  <option value="1" selected>Standard</option>
325  <option value="2">SIM</option>
326  <option value="3">ToolKit</option>
327  </select></td></tr>
328 
329  <tr><td>'.$langs->trans("DisableStopIfSupported").' :</td><td>
330  <select name="disablestop" id="disablestop" class="flat">
331  <option value="0" selected>No</option>
332  <option value="1" selected>Yes</option>
333  </select></td></tr>';
334 
335  print "</table>\n";
336 
337 
338  if ($showform)
339  {
340  print '<div class="center">';
341  print '<input class="button" type="submit" name="sendmail" value="'.dol_escape_htmltag($langs->trans("SendSms")).'">';
342  if ($this->withcancel)
343  {
344  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
345  print '<input class="button button-cancel" type="submit" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
346  }
347  print '</div>';
348 
349  print "</form>\n";
350  }
351 
352  print "<!-- End form SMS -->\n";
353  }
354 }
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage Dolibarr users.
Definition: user.class.php:44
$conf db
API class for accounts.
Definition: inc.php:54
show_form($morecss= 'titlefield', $showform=1)
Show the form to input an sms.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Classe permettant la generation du formulaire d&#39;envoi de Sms Usage: $formsms = new FormSms($db) $form...
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=&gt;newva...
__construct($db)
Constructor.