-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
html.formsms.class.php
365 lines (328 loc) · 13 KB
/
html.formsms.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<?php
/* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
*
* 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/>.
*/
/**
* \file htdocs/core/class/html.formsms.class.php
* \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';
/**
* 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
*/
class FormSms
{
/**
* @var DoliDB Database handler.
*/
public $db;
var $fromname;
var $fromsms;
var $replytoname;
var $replytomail;
var $toname;
var $tomail;
var $withsubstit; // Show substitution array
var $withfrom;
var $withto;
var $withtopic;
var $withbody;
var $withfromreadonly;
var $withreplytoreadonly;
var $withtoreadonly;
var $withtopicreadonly;
var $withcancel;
var $substit=array();
var $param=array();
/**
* @var string Error code (or message)
*/
public $error='';
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
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;
return 1;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
/**
* 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
*/
function show_form($morecss='titlefield', $showform=1)
{
// phpcs:enable
global $conf, $langs, $user, $form;
if (! is_object($form)) $form=new Form($this->db);
$langs->load("other");
$langs->load("mails");
$langs->load("sms");
$soc=new Societe($this->db);
if (!empty($this->withtosocid) && $this->withtosocid > 0)
{
$soc->fetch($this->withtosocid);
}
print "\n<!-- Begin form SMS -->\n";
print '
<script language="javascript">
function limitChars(textarea, limit, infodiv)
{
var text = textarea.value;
var textlength = text.length;
var info = document.getElementById(infodiv);
info.innerHTML = (limit - textlength);
return true;
}
</script>';
if ($showform) print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
foreach ($this->param as $key=>$value)
{
print "<input type=\"hidden\" name=\"$key\" value=\"$value\">\n";
}
print "<table class=\"border centpercent\">\n";
// Substitution array
if (! empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this.
{
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);
print "</td></tr>\n";
}
// From
if ($this->withfrom)
{
if ($this->withfromreadonly)
{
print '<tr><td class="titlefield '.$morecss.'">'.$langs->trans("SmsFrom");
print '<input type="hidden" name="fromsms" value="'.$this->fromsms.'">';
print "</td><td>";
if ($this->fromtype == 'user')
{
$langs->load("users");
$fuser=new User($this->db);
$fuser->fetch($this->fromid);
print $fuser->getNomUrl(1);
print ' ';
}
if ($this->fromsms)
{
print $this->fromsms;
}
else
{
if ($this->fromtype)
{
$langs->load("errors");
print '<font class="warning"> <'.$langs->trans("ErrorNoPhoneDefinedForThisUser").'> </font>';
}
}
print "</td></tr>\n";
print "</td></tr>\n";
}
else
{
print '<tr><td class="'.$morecss.'">'.$langs->trans("SmsFrom")."</td><td>";
//print '<input type="text" name="fromname" size="30" value="'.$this->fromsms.'">';
if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') // For backward compatibility @deprecated
{
dol_include_once('/ovh/class/ovhsms.class.php');
try
{
$sms = new OvhSms($this->db);
if (empty($conf->global->OVHSMS_ACCOUNT))
{
$resultsender = 'ErrorOVHSMS_ACCOUNT not defined';
}
else
{
$resultsender = $sms->SmsSenderList();
}
}
catch(Exception $e)
{
dol_print_error('','Error to get list of senders: '.$e->getMessage());
}
}
else if (!empty($conf->global->MAIN_SMS_SENDMODE)) // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
{
$tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
$classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
try
{
$classname=ucfirst($classfile);
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';
}
}
catch(Exception $e)
{
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;
}
if (is_array($resultsender) && count($resultsender) > 0)
{
print '<select name="fromsms" id="fromsms" class="flat">';
foreach($resultsender as $obj)
{
print '<option value="'.$obj->number.'">'.$obj->number.'</option>';
}
print '</select>';
}
else
{
print '<span class="error">'.$langs->trans("SmsNoPossibleSenderFound");
if (is_object($sms) && ! empty($sms->error)) print ' '.$sms->error;
print '</span>';
}
print '</td>';
print "</tr>\n";
}
}
// To (target)
if ($this->withto || is_array($this->withto))
{
print '<tr><td>';
//$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients");
$moretext='';
print $form->textwithpicto($langs->trans("SmsTo"),$moretext);
print '</td><td>';
if ($this->withtoreadonly)
{
print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
}
else
{
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):"+")."\">";
if (! empty($this->withtosocid) && $this->withtosocid > 0)
{
$liste=array();
foreach ($soc->thirdparty_and_contact_phone_array() as $key => $value)
{
$liste[$key]=$value;
}
print " ".$langs->trans("or")." ";
//var_dump($_REQUEST);exit;
print $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
}
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);
if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
$defaultmessage=str_replace('\n',"\n",$defaultmessage);
print "<tr>";
print '<td class="tdtop">'.$langs->trans("SmsText")."</td>";
print "<td>";
if ($this->withbodyreadonly)
{
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>';
print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160-dol_strlen($defaultmessage)).'</span></div></td>';
}
print "</td></tr>\n";
}
print '
<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>
<select name="priority" id="priority" class="flat">
<option value="0">high</option>
<option value="1">medium</option>
<option value="2" selected>low</option>
<option value="3">veryLow</option>
</select></td></tr>
<tr><td>'.$langs->trans("Type").' :</td><td>
<select name="class" id="class" class="flat">
<option value="0">Flash</option>
<option value="1" selected>Standard</option>
<option value="2">SIM</option>
<option value="3">ToolKit</option>
</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>
</select></td></tr>';
print "</table>\n";
if ($showform)
{
print '<div class="center">';
print '<input class="button" type="submit" name="sendmail" value="'.dol_escape_htmltag($langs->trans("SendSms")).'">';
if ($this->withcancel)
{
print ' ';
print '<input class="button" type="submit" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
}
print '</div>';
print "</form>\n";
}
print "<!-- End form SMS -->\n";
}
}