dolibarr 19.0.3
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
25require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
26
27
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 $withbodyreadonly;
66 public $withcancel;
67
68 public $substit = array();
69 public $param = array();
70
74 public $error = '';
75
79 public $errors = array();
80
81
87 public function __construct($db)
88 {
89 $this->db = $db;
90
91 $this->withfrom = 1;
92 $this->withto = 1;
93 $this->withtopic = 1;
94 $this->withbody = 1;
95
96 $this->withfromreadonly = 1;
97 $this->withreplytoreadonly = 1;
98 $this->withtoreadonly = 0;
99 $this->withtopicreadonly = 0;
100 $this->withbodyreadonly = 0;
101 }
102
103 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
111 public function show_form($morecss = 'titlefield', $showform = 1)
112 {
113 // phpcs:enable
114 global $conf, $langs, $form;
115
116 if (!is_object($form)) {
117 $form = new Form($this->db);
118 }
119
120 // Load translation files required by the page
121 $langs->loadLangs(array('other', 'mails', 'sms'));
122
123 $soc = new Societe($this->db);
124 if (!empty($this->withtosocid) && $this->withtosocid > 0) {
125 $soc->fetch($this->withtosocid);
126 }
127
128 print "\n<!-- Begin form SMS -->\n";
129
130 print '
131<script nonce="'.getNonce().'" type="text/javascript">
132function limitChars(textarea, limit, infodiv)
133{
134 var text = textarea.value;
135 var textlength = text.length;
136 var info = document.getElementById(infodiv);
137
138 info.innerHTML = (limit - textlength);
139 return true;
140}
141</script>';
142
143 if ($showform) {
144 print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
145 }
146
147 print '<input type="hidden" name="token" value="'.newToken().'">';
148 foreach ($this->param as $key => $value) {
149 print "<input type=\"hidden\" name=\"$key\" value=\"$value\">\n";
150 }
151 print "<table class=\"border centpercent\">\n";
152
153 // Substitution array
154 if (!empty($this->withsubstit)) { // Unset or set ->withsubstit=0 to disable this.
155 print "<tr><td colspan=\"2\">";
156 $help = "";
157 foreach ($this->substit as $key => $val) {
158 $help .= $key.' -> '.$langs->trans($val).'<br>';
159 }
160 print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"), $help);
161 print "</td></tr>\n";
162 }
163
164 // From
165 if ($this->withfrom) {
166 if ($this->withfromreadonly) {
167 print '<tr><td class="titlefield '.$morecss.'">'.$langs->trans("SmsFrom");
168 print '<input type="hidden" name="fromsms" value="'.$this->fromsms.'">';
169 print "</td><td>";
170 if ($this->fromtype == 'user') {
171 $langs->load("users");
172 $fuser = new User($this->db);
173 $fuser->fetch($this->fromid);
174 print $fuser->getNomUrl(1);
175 print ' &nbsp; ';
176 }
177 if ($this->fromsms) {
178 print $this->fromsms;
179 } else {
180 if ($this->fromtype) {
181 $langs->load("errors");
182 print '<span class="warning"> &lt;'.$langs->trans("ErrorNoPhoneDefinedForThisUser").'&gt; </span>';
183 }
184 }
185 print "</td></tr>\n";
186 print "</td></tr>\n";
187 } else {
188 print '<tr><td class="'.$morecss.'">'.$langs->trans("SmsFrom")."</td><td>";
189 if (getDolGlobalString('MAIN_SMS_SENDMODE')) {
190 $sendmode = getDolGlobalString('MAIN_SMS_SENDMODE'); // $conf->global->MAIN_SMS_SENDMODE looks like a value 'module'
191 $classmoduleofsender = getDolGlobalString('MAIN_MODULE_'.strtoupper($sendmode).'_SMS', $sendmode); // $conf->global->MAIN_MODULE_XXX_SMS looks like a value 'class@module'
192 if ($classmoduleofsender == 'ovh') {
193 $classmoduleofsender = 'ovhsms@ovh'; // For backward compatibility
194 }
195
196 $tmp = explode('@', $classmoduleofsender);
197 $classfile = $tmp[0];
198 $module = (empty($tmp[1]) ? $tmp[0] : $tmp[1]);
199 dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
200 try {
201 $classname = ucfirst($classfile);
202 if (class_exists($classname)) {
203 $sms = new $classname($this->db);
204 $resultsender = $sms->SmsSenderList();
205 } else {
206 $sms = new stdClass();
207 $sms->error = 'The SMS manager "'.$classfile.'" defined into SMS setup MAIN_MODULE_'.strtoupper($sendmode).'_SMS is not found';
208 }
209 } catch (Exception $e) {
210 dol_print_error('', 'Error to get list of senders: '.$e->getMessage());
211 exit;
212 }
213 } else {
214 dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING);
215 $resultsender = array();
216 $resultsender[0]->number = $this->fromsms;
217 }
218
219 if (is_array($resultsender) && count($resultsender) > 0) {
220 print '<select name="fromsms" id="fromsms" class="flat">';
221 foreach ($resultsender as $obj) {
222 print '<option value="'.$obj->number.'">'.$obj->number.'</option>';
223 }
224 print '</select>';
225 } else {
226 print '<span class="error wordbreak">'.$langs->trans("SmsNoPossibleSenderFound");
227 if (is_object($sms) && !empty($sms->error)) {
228 print ' '.$sms->error;
229 }
230 print '</span>';
231 }
232 print '</td>';
233 print "</tr>\n";
234 }
235 }
236
237 // To (target)
238 if ($this->withto || is_array($this->withto)) {
239 print '<tr><td>';
240 //$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients");
241 $moretext = '';
242 print $form->textwithpicto($langs->trans("SmsTo"), $moretext);
243 print '</td><td>';
244 if ($this->withtoreadonly) {
245 print (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto : "";
246 } else {
247 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) : "+").'">';
248 if (!empty($this->withtosocid) && $this->withtosocid > 0) {
249 $liste = array();
250 foreach ($soc->thirdparty_and_contact_phone_array() as $key => $value) {
251 $liste[$key] = $value;
252 }
253 print " ".$langs->trans("or")." ";
254 //var_dump($_REQUEST);exit;
255 print $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
256 }
257 print '<span class="opacitymedium hideonsmartphone"> '.$langs->trans("SmsInfoNumero").'</span>';
258 }
259 print "</td></tr>\n";
260 }
261
262 // Message
263 if ($this->withbody) {
264 $defaultmessage = '';
265 if ($this->param["models"] == 'body') {
266 $defaultmessage = $this->withbody;
267 }
268 $defaultmessage = make_substitutions($defaultmessage, $this->substit);
269 if (GETPOSTISSET("message")) {
270 $defaultmessage = GETPOST("message", 'restricthtml');
271 }
272 $defaultmessage = str_replace('\n', "\n", $defaultmessage);
273
274 print "<tr>";
275 print '<td class="tdtop">'.$langs->trans("SmsText")."</td>";
276 print "<td>";
277 if ($this->withbodyreadonly) {
278 print nl2br($defaultmessage);
279 print '<input type="hidden" name="message" value="'.dol_escape_htmltag($defaultmessage).'">';
280 } else {
281 print '<textarea class="quatrevingtpercent" name="message" id="message" rows="'.ROWS_4.'" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>';
282 print '<div id="charlimitinfo" class="opacitymedium">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160 - dol_strlen($defaultmessage)).'</span></div></td>';
283 }
284 print "</td></tr>\n";
285 }
286
287 print '
288 <tr>
289 <td>'.$langs->trans("DelayBeforeSending").':</td>
290 <td> <input name="deferred" id="deferred" size="4" value="0"></td></tr>
291
292 <tr><td>'.$langs->trans("Priority").' :</td><td>
293 <select name="priority" id="priority" class="flat">
294 <option value="0">high</option>
295 <option value="1">medium</option>
296 <option value="2" selected>low</option>
297 <option value="3">veryLow</option>
298 </select></td></tr>
299
300 <tr><td>'.$langs->trans("Type").' :</td><td>
301 <select name="class" id="class" class="flat">
302 <option value="0">Flash</option>
303 <option value="1" selected>Standard</option>
304 <option value="2">SIM</option>
305 <option value="3">ToolKit</option>
306 </select></td></tr>
307
308 <tr><td>'.$langs->trans("DisableStopIfSupported").' :</td><td>
309 <select name="disablestop" id="disablestop" class="flat">
310 <option value="0" selected>No</option>
311 <option value="1" selected>Yes</option>
312 </select></td></tr>';
313
314 print "</table>\n";
315
316
317 if ($showform) {
318 print '<div class="center">';
319 print '<input type="submit" class="button" name="sendmail" value="'.dol_escape_htmltag($langs->trans("SendSms")).'">';
320 if ($this->withcancel) {
321 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
322 print '<input class="button button-cancel" type="submit" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
323 }
324 print '</div>';
325
326 print "</form>\n";
327 }
328
329 print "<!-- End form SMS -->\n";
330 }
331}
Class to manage generation of HTML components Only common components must be here.
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.
__construct($db)
Constructor.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.