dolibarr 21.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 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
26require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
27
28
36{
40 public $db;
41
45 public $fromid;
49 public $fromname;
53 public $fromsms;
54
58 public $fromtype;
62 public $replytoname;
66 public $replytomail;
70 public $toname;
74 public $tomail;
75
79 public $withsubstit; // Show substitution array
80
84 public $withfrom;
85
89 public $withto;
90
94 public $withtopic;
95
99 public $withbody;
100
104 public $withtosocid;
108 public $withfromreadonly;
112 public $withreplytoreadonly;
116 public $withtoreadonly;
120 public $withtopicreadonly;
124 public $withbodyreadonly;
128 public $withcancel;
129
133 public $substit = array();
137 public $param = array();
138
142 public $error = '';
143
147 public $errors = array();
148
149
155 public function __construct($db)
156 {
157 $this->db = $db;
158
159 $this->withfrom = 1;
160 $this->withto = 1;
161 $this->withtopic = 1;
162 $this->withbody = 1;
163
164 $this->withfromreadonly = 1;
165 $this->withreplytoreadonly = 1;
166 $this->withtoreadonly = 0;
167 $this->withtopicreadonly = 0;
168 $this->withbodyreadonly = 0;
169 }
170
171 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
179 public function show_form($morecss = 'titlefield', $showform = 1)
180 {
181 // phpcs:enable
182 global $conf, $langs, $form;
183
184 if (!is_object($form)) {
185 $form = new Form($this->db);
186 }
187
188 // Load translation files required by the page
189 $langs->loadLangs(array('other', 'mails', 'sms'));
190
191 $soc = new Societe($this->db);
192 if (!empty($this->withtosocid) && $this->withtosocid > 0) {
193 $soc->fetch($this->withtosocid);
194 }
195
196 print "\n<!-- Begin form SMS -->\n";
197
198 print '
199<script nonce="'.getNonce().'" type="text/javascript">
200function limitChars(textarea, limit, infodiv)
201{
202 var text = textarea.value;
203 var textlength = text.length;
204 var info = document.getElementById(infodiv);
205
206 info.innerHTML = (limit - textlength);
207 return true;
208}
209</script>';
210
211 if ($showform) {
212 print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
213 }
214
215 print '<input type="hidden" name="token" value="'.newToken().'">';
216 foreach ($this->param as $key => $value) {
217 print "<input type=\"hidden\" name=\"$key\" value=\"$value\">\n";
218 }
219 print "<table class=\"border centpercent\">\n";
220
221 // Substitution array
222 if (!empty($this->withsubstit)) { // Unset or set ->withsubstit=0 to disable this.
223 print "<tr><td colspan=\"2\">";
224 $help = "";
225 foreach ($this->substit as $key => $val) {
226 $help .= $key.' -> '.$langs->trans($val).'<br>';
227 }
228 print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"), $help);
229 print "</td></tr>\n";
230 }
231
232 // From
233 if ($this->withfrom) {
234 if ($this->withfromreadonly) {
235 print '<tr><td class="titlefield '.$morecss.'">'.$langs->trans("SmsFrom");
236 print '<input type="hidden" name="fromsms" value="'.$this->fromsms.'">';
237 print "</td><td>";
238 if ($this->fromtype == 'user') {
239 $langs->load("users");
240 $fuser = new User($this->db);
241 $fuser->fetch($this->fromid);
242 print $fuser->getNomUrl(1);
243 print ' &nbsp; ';
244 }
245 if ($this->fromsms) {
246 print $this->fromsms;
247 } else {
248 if ($this->fromtype) {
249 $langs->load("errors");
250 print '<span class="warning"> &lt;'.$langs->trans("ErrorNoPhoneDefinedForThisUser").'&gt; </span>';
251 }
252 }
253 print "</td></tr>\n";
254 print "</td></tr>\n";
255 } else {
256 print '<tr><td class="'.$morecss.'">'.$langs->trans("SmsFrom")."</td><td>";
257 $resultsender = array();
258 $sms = null;
259 if (getDolGlobalString('MAIN_SMS_SENDMODE')) {
260 $sendmode = getDolGlobalString('MAIN_SMS_SENDMODE'); // $conf->global->MAIN_SMS_SENDMODE looks like a value 'module'
261 $classmoduleofsender = getDolGlobalString('MAIN_MODULE_'.strtoupper($sendmode).'_SMS', $sendmode); // $conf->global->MAIN_MODULE_XXX_SMS looks like a value 'class@module'
262 if ($classmoduleofsender == 'ovh') {
263 $classmoduleofsender = 'ovhsms@ovh'; // For backward compatibility
264 }
265
266 $tmp = explode('@', $classmoduleofsender);
267 $classfile = $tmp[0];
268 $module = (empty($tmp[1]) ? $tmp[0] : $tmp[1]);
269 dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
270 try {
271 $classname = ucfirst($classfile);
272 if (class_exists($classname)) {
273 $sms = new $classname($this->db);
274 '@phan-var-force CommonObject $sms';
275 $resultsender = $sms->SmsSenderList(); // @phan-suppress-current-line PhanUndeclaredMethod
276 } else {
277 $sms = new stdClass();
278 $sms->error = 'The SMS manager "'.$classfile.'" defined into SMS setup MAIN_MODULE_'.strtoupper($sendmode).'_SMS is not found';
279 }
280 } catch (Exception $e) {
281 dol_print_error(null, 'Error to get list of senders: '.$e->getMessage());
282 exit;
283 }
284 } else {
285 dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING);
286 $resultsender = array(0 => new stdClass());
287 $resultsender[0]->number = $this->fromsms;
288 }
289
290 if (is_array($resultsender) && count($resultsender) > 0) {
291 print '<select name="fromsms" id="fromsms" class="flat">';
292 foreach ($resultsender as $obj) {
293 print '<option value="'.$obj->number.'">'.$obj->number.'</option>';
294 }
295 print '</select>';
296 } else {
297 print '<span class="error wordbreak">'.$langs->trans("SmsNoPossibleSenderFound");
298 if (is_object($sms) && !empty($sms->error)) {
299 print ' '.$sms->error;
300 }
301 print '</span>';
302 }
303 print '</td>';
304 print "</tr>\n";
305 }
306 }
307
308 // To (target)
309 if ($this->withto || is_array($this->withto)) {
310 print '<tr><td>';
311 //$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients");
312 $moretext = '';
313 print $form->textwithpicto($langs->trans("SmsTo"), $moretext);
314 print '</td><td>';
315 if ($this->withtoreadonly) {
316 print (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto : "";
317 } else {
318 print '<input class="width150" id="sendto" name="sendto" value="'.dol_escape_htmltag(!is_array($this->withto) && $this->withto != '1' ? (GETPOSTISSET("sendto") ? GETPOST("sendto") : $this->withto) : "+").'">';
319 if (!empty($this->withtosocid) && $this->withtosocid > 0) {
320 $liste = array();
321 foreach ($soc->thirdparty_and_contact_phone_array() as $key => $value) {
322 $liste[$key] = $value;
323 }
324 print " ".$langs->trans("or")." ";
325 //var_dump($_REQUEST);exit;
326 print $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
327 }
328 print '<span class="opacitymedium hideonsmartphone"> '.$langs->trans("SmsInfoNumero").'</span>';
329 }
330 print "</td></tr>\n";
331 }
332
333 // Message
334 if ($this->withbody) {
335 $defaultmessage = '';
336 if ($this->param["models"] == 'body') {
337 $defaultmessage = $this->withbody;
338 }
339 $defaultmessage = make_substitutions($defaultmessage, $this->substit);
340 if (GETPOSTISSET("message")) {
341 $defaultmessage = GETPOST("message", 'restricthtml');
342 }
343 $defaultmessage = str_replace('\n', "\n", $defaultmessage);
344
345 print "<tr>";
346 print '<td class="tdtop">'.$langs->trans("SmsText")."</td>";
347 print "<td>";
348 if ($this->withbodyreadonly) {
349 print nl2br($defaultmessage);
350 print '<input type="hidden" name="message" value="'.dol_escape_htmltag($defaultmessage).'">';
351 } else {
352 print '<textarea class="quatrevingtpercent" name="message" id="message" rows="'.ROWS_4.'" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>';
353 print '<div id="charlimitinfo" class="opacitymedium">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160 - dol_strlen($defaultmessage)).'</span></div></td>';
354 }
355 print "</td></tr>\n";
356 }
357
358 print '
359 <tr>
360 <td>'.$langs->trans("DelayBeforeSending").':</td>
361 <td> <input name="deferred" id="deferred" size="4" value="0"></td></tr>
362
363 <tr><td>'.$langs->trans("Priority").' :</td><td>
364 <select name="priority" id="priority" class="flat">
365 <option value="0">high</option>
366 <option value="1">medium</option>
367 <option value="2" selected>low</option>
368 <option value="3">veryLow</option>
369 </select></td></tr>
370
371 <tr><td>'.$langs->trans("Type").' :</td><td>
372 <select name="class" id="class" class="flat">
373 <option value="0">Flash</option>
374 <option value="1" selected>Standard</option>
375 <option value="2">SIM</option>
376 <option value="3">ToolKit</option>
377 </select></td></tr>
378
379 <tr><td>'.$langs->trans("DisableStopIfSupported").' :</td><td>
380 <select name="disablestop" id="disablestop" class="flat">
381 <option value="0" selected>No</option>
382 <option value="1" selected>Yes</option>
383 </select></td></tr>';
384
385 print "</table>\n";
386
387
388 if ($showform) {
389 print '<div class="center">';
390 print '<input type="submit" class="button" name="sendmail" value="'.dol_escape_htmltag($langs->trans("SendSms")).'">';
391 if ($this->withcancel) {
392 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
393 print '<input class="button button-cancel" type="submit" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
394 }
395 print '</div>';
396
397 print "</form>\n";
398 }
399
400 print "<!-- End form SMS -->\n";
401 }
402}
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation du formulaire d'envoi de Sms Usage: $formsms = new FormSms($db) $forms...
show_form($morecss='titlefield', $showform=1)
Show the form to input an sms.
__construct($db)
Constructor.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79