dolibarr 19.0.3
sms.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2009 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2020 Frédéric France <frederic.france@netlogic.fr>
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
26// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29
30// Load translation files required by the page
31$langs->loadLangs(array("companies", "admin", "products", "sms", "other", "errors"));
32
33$action = GETPOST('action', 'aZ09');
34$cancel = GETPOST('cancel', 'aZ09');
35
36if (!$user->admin) {
38}
39
40$substitutionarrayfortest = array(
41 '__ID__' => 'TESTIdRecord',
42 '__PHONEFROM__' => 'TESTPhoneFrom',
43 '__PHONETO__' => 'TESTPhoneTo',
44 '__LASTNAME__' => 'TESTLastname',
45 '__FIRSTNAME__' => 'TESTFirstname'
46);
47
48
49/*
50 * Actions
51 */
52
53if ($action == 'update' && !$cancel) {
54 dolibarr_set_const($db, "MAIN_DISABLE_ALL_SMS", GETPOST("MAIN_DISABLE_ALL_SMS", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
55
56 dolibarr_set_const($db, "MAIN_SMS_SENDMODE", GETPOST("MAIN_SMS_SENDMODE", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
57
58 dolibarr_set_const($db, "MAIN_MAIL_SMS_FROM", GETPOST("MAIN_MAIL_SMS_FROM", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
59
60 header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
61 exit;
62}
63
64
65// Send sms
66if ($action == 'send' && !$cancel) {
67 $error = 0;
68
69 $smsfrom = '';
70 if (GETPOST("fromsms", 'alphanohtml')) {
71 $smsfrom = GETPOST("fromsms", 'alphanohtml');
72 }
73 if (empty($smsfrom)) {
74 $smsfrom = GETPOST("fromname", 'alphanohtml');
75 }
76 $sendto = GETPOST("sendto", 'alphanohtml');
77 $body = GETPOST('message', 'alphanohtml');
78 $deliveryreceipt = GETPOST("deliveryreceipt", 'alphanohtml');
79 $deferred = GETPOST('deferred', 'alphanohtml');
80 $priority = GETPOST('priority', 'alphanohtml');
81 $class = GETPOST('class', 'alphanohtml');
82 $errors_to = GETPOST("errorstosms", 'alphanohtml');
83
84 // Create form object
85 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formsms.class.php';
86 $formsms = new FormSms($db);
87
88 if (!empty($formsms->error)) {
89 setEventMessages($formsms->error, $formsms->errors, 'errors');
90 $action = 'test';
91 $error++;
92 }
93 if (empty($body)) {
94 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Message")), null, 'errors');
95 $action = 'test';
96 $error++;
97 }
98 if (empty($smsfrom) || !str_replace('+', '', $smsfrom)) {
99 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("SmsFrom")), null, 'errors');
100 $action = 'test';
101 $error++;
102 }
103 if (empty($sendto) || !str_replace('+', '', $sendto)) {
104 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("SmsTo")), null, 'errors');
105 $action = 'test';
106 $error++;
107 }
108 if (!$error) {
109 // Make substitutions into message
110 complete_substitutions_array($substitutionarrayfortest, $langs);
111 $body = make_substitutions($body, $substitutionarrayfortest);
112
113 require_once DOL_DOCUMENT_ROOT.'/core/class/CSMSFile.class.php';
114 try {
115 $smsfile = new CSMSFile($sendto, $smsfrom, $body, $deliveryreceipt, $deferred, $priority, $class); // This define OvhSms->login, pass, session and account
116 } catch (Exception $e) {
117 setEventMessages($e->getMessage(), null, 'error');
118 }
119 $result = $smsfile->sendfile(); // This send SMS
120
121 if ($result) {
122 setEventMessages($langs->trans("SmsSuccessfulySent", $smsfrom, $sendto), null, 'mesgs');
123 setEventMessages($smsfile->error, $smsfile->errors, 'mesgs');
124 } else {
125 setEventMessages($langs->trans("ResultKo"), null, 'errors');
126 setEventMessages($smsfile->error, $smsfile->errors, 'errors');
127 }
128
129 $action = '';
130 }
131}
132
133
134
135/*
136 * View
137 */
138
139$form = new Form($db);
140
141$linuxlike = 1;
142if (preg_match('/^win/i', PHP_OS)) {
143 $linuxlike = 0;
144}
145if (preg_match('/^mac/i', PHP_OS)) {
146 $linuxlike = 0;
147}
148
149$wikihelp = 'EN:Setup Sms|FR:Paramétrage Sms|ES:Configuración Sms';
150llxHeader('', $langs->trans("Setup"), $wikihelp);
151
152print load_fiche_titre($langs->trans("SmsSetup"), '', 'title_setup');
153
154print '<span class="opacitymedium">'.$langs->trans("SmsDesc")."</span><br>\n";
155print "<br>\n";
156
157// List of sending methods
158$listofmethods = (is_array($conf->modules_parts['sms']) ? $conf->modules_parts['sms'] : array());
159asort($listofmethods);
160
161if (!count($listofmethods)) {
162 $descnosms = $langs->trans("NoSmsEngine", '{Dolistore}');
163 $descnosms = str_replace('{Dolistore}', '<a href="https://www.dolistore.com/search.php?orderby=position&orderway=desc&search_query=smsmanager">DoliStore</a>', $descnosms);
164 print '<div class="warning">'.$descnosms.'</div>';
165}
166
167if ($action == 'edit') {
168 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
169 print '<input type="hidden" name="token" value="'.newToken().'">';
170 print '<input type="hidden" name="action" value="update">';
171
172 clearstatcache();
173
174 print '<table class="noborder centpercent">';
175 print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
176
177 // Disable
178 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>';
179 print $form->selectyesno('MAIN_DISABLE_ALL_SMS', getDolGlobalString('MAIN_DISABLE_ALL_SMS'), 1);
180 print '</td></tr>';
181
182 // Separator
183 print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
184
185 // Method
186 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
187 if (count($listofmethods)) {
188 print $form->selectarray('MAIN_SMS_SENDMODE', $listofmethods, getDolGlobalString('MAIN_SMS_SENDMODE'), 1);
189 } else {
190 print '<span class="error">'.$langs->trans("None").'</span>';
191 }
192 print '</td></tr>';
193
194 // From
195 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMS_FROM", $langs->transnoentities("Undefined")).'</td>';
196 print '<td><input class="flat" name="MAIN_MAIL_SMS_FROM" size="32" value="'.getDolGlobalString('MAIN_MAIL_SMS_FROM');
197 print '"></td></tr>';
198
199 // Autocopy to
200 /*
201 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
202 print '<td><input class="flat" name="MAIN_MAIL_AUTOCOPY_TO" size="32" value="' . $conf->global->MAIN_MAIL_AUTOCOPY_TO;
203 print '"></td></tr>';
204 */
205 print '</table>';
206
207 print '<br><div class="center">';
208 print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'"'.(!count($listofmethods) ? ' disabled' : '').'>';
209 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
210 print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
211 print '</div>';
212
213 print '</form>';
214 print '<br>';
215} else {
216 print '<table class="noborder centpercent">';
217 print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
218
219 // Disable
220 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>'.yn(getDolGlobalString('MAIN_DISABLE_ALL_SMS')).'</td></tr>';
221
222 // Separator
223 print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
224
225 // Method
226 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
227 $text = getDolGlobalString('MAIN_SMS_SENDMODE') ? $listofmethods[getDolGlobalString('MAIN_SMS_SENDMODE')] : '';
228 if (empty($text)) {
229 $text = $langs->trans("Undefined").' '.img_warning();
230 }
231 print $text;
232 print '</td></tr>';
233
234 // From
235 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMS_FROM", $langs->transnoentities("Undefined")).'</td>';
236 print '<td>'.getDolGlobalString('MAIN_MAIL_SMS_FROM');
237 if (getDolGlobalString('MAIN_MAIL_SMS_FROM') && !isValidPhone($conf->global->MAIN_MAIL_SMS_FROM)) {
238 print ' '.img_warning($langs->trans("ErrorBadPhone"));
239 }
240 print '</td></tr>';
241
242 // Autocopy to
243 /*
244 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
245 print '<td>'.$conf->global->MAIN_MAIL_AUTOCOPY_TO;
246 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO) && ! isValidEmail($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print img_warning($langs->trans("ErrorBadEMail"));
247 print '</td></tr>';
248 */
249
250 print '</table>';
251
252
253 // Buttons for actions
254
255 print '<div class="tabsAction">';
256
257 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
258
259 if (count($listofmethods) && getDolGlobalString('MAIN_SMS_SENDMODE')) {
260 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
261 } else {
262 print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("DoTestSend").'</a>';
263 }
264 print '</div>';
265
266 // Affichage formulaire de TEST simple
267 if ($action == 'test') {
268 print '<br>';
269 print load_fiche_titre($langs->trans("DoTestSend"));
270
271 // Cree l'objet formulaire mail
272 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formsms.class.php';
273 $formsms = new FormSms($db);
274 $formsms->fromtype = 'user';
275 $formsms->fromid = $user->id;
276 $formsms->fromsms = (GETPOSTISSET('fromsms') ? GETPOST('fromsms') : ($conf->global->MAIN_MAIL_SMS_FROM ? $conf->global->MAIN_MAIL_SMS_FROM : $user->user_mobile));
277 $formsms->withfromreadonly = 0;
278 $formsms->withsubstit = 0;
279 $formsms->withfrom = 1;
280 $formsms->withto = (GETPOSTISSET('sendto') ? GETPOST('sendto') : ($user->user_mobile ? $user->user_mobile : 1));
281 $formsms->withbody = (GETPOSTISSET('message') ? (!GETPOST('message') ? 1 : GETPOST('message')) : $langs->trans("ThisIsATestMessage"));
282 $formsms->withbodyreadonly = 0;
283 $formsms->withcancel = 1;
284 // Tableau des substitutions
285 $formsms->substit = $substitutionarrayfortest;
286 // Tableau des parametres complementaires du post
287 $formsms->param["action"] = "send";
288 $formsms->param["models"] = "body";
289 $formsms->param["smsid"] = 0;
290 $formsms->param["returnurl"] = $_SERVER["PHP_SELF"];
291
292 $formsms->show_form();
293
294 print '<br>';
295 }
296}
297
298// End of page
299llxFooter();
300$db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to send SMS Usage: $smsfile = new CSMSFile($subject,$sendto,$replyto,$message,...
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...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
isValidPhone($phone)
Return true if phone number syntax is ok TODO Decide what to do with this.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.