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