dolibarr 24.0.0-beta
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-2025 Frédéric France <frederic.france@free.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
38// Load translation files required by the page
39$langs->loadLangs(array("companies", "admin", "products", "sms", "other", "errors"));
40
41$action = GETPOST('action', 'aZ09');
42$cancel = GETPOST('cancel', 'alpha');
43
44if (!$user->admin) {
46}
47
48$substitutionarrayfortest = array(
49 '__ID__' => 'TESTIdRecord',
50 '__PHONEFROM__' => 'TESTPhoneFrom',
51 '__PHONETO__' => 'TESTPhoneTo',
52 '__LASTNAME__' => 'TESTLastname',
53 '__FIRSTNAME__' => 'TESTFirstname'
54);
55
56
57/*
58 * Actions
59 */
60
61if ($action == 'update' && !$cancel) {
62 dolibarr_set_const($db, "MAIN_DISABLE_ALL_SMS", GETPOST("MAIN_DISABLE_ALL_SMS", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
63
64 dolibarr_set_const($db, "MAIN_SMS_SENDMODE", GETPOST("MAIN_SMS_SENDMODE", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
65
66 dolibarr_set_const($db, "MAIN_SMS_FROM", GETPOST("MAIN_SMS_FROM", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
67
68 header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
69 exit;
70}
71
72
73// Send sms
74if ($action == 'send' && !$cancel) {
75 $error = 0;
76
77 $smsfrom = '';
78 if (GETPOST("fromsms", 'alphanohtml')) {
79 $smsfrom = GETPOST("fromsms", 'alphanohtml');
80 }
81 if (empty($smsfrom)) {
82 $smsfrom = GETPOST("fromname", 'alphanohtml');
83 }
84 $sendto = GETPOST("sendto", 'alphanohtml');
85 $body = GETPOST('message', 'alphanohtml');
86 $deliveryreceipt = GETPOSTINT("deliveryreceipt");
87 $deferred = GETPOSTINT('deferred');
88 $priority = GETPOSTINT('priority');
89 $class = GETPOSTINT('class');
90 $errors_to = GETPOST("errorstosms", 'alphanohtml');
91
92 // Create form object
93 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formsms.class.php';
94 $formsms = new FormSms($db);
95
96 if (!empty($formsms->error)) {
97 setEventMessages($formsms->error, $formsms->errors, 'errors');
98 $action = 'test';
99 $error++;
100 }
101 if (empty($body)) {
102 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Message")), null, 'errors');
103 $action = 'test';
104 $error++;
105 }
106 if (empty($smsfrom) || !str_replace('+', '', $smsfrom)) {
107 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("SmsFrom")), null, 'errors');
108 $action = 'test';
109 $error++;
110 }
111 if (empty($sendto) || !str_replace('+', '', $sendto)) {
112 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("SmsTo")), null, 'errors');
113 $action = 'test';
114 $error++;
115 }
116 if (!$error) {
117 // Make substitutions into message
118 complete_substitutions_array($substitutionarrayfortest, $langs);
119 $body = make_substitutions($body, $substitutionarrayfortest);
120
121 require_once DOL_DOCUMENT_ROOT.'/core/class/CSMSFile.class.php';
122 try {
123 $smsfile = new CSMSFile($sendto, $smsfrom, $body, $deliveryreceipt, $deferred, $priority, $class); // This define OvhSms->login, pass, session and account
124 } catch (Exception $e) {
125 $error++;
126 setEventMessages($e->getMessage(), null, 'error');
127 }
128 if (!$error) {
129 $result = $smsfile->sendfile(); // This send SMS
130 if (!$result) {
131 $error++;
132 setEventMessages($smsfile->error, $smsfile->errors, 'mesgs');
133 }
134 }
135
136 if (!$error) {
137 setEventMessages($langs->trans("SmsSuccessfulySent", $smsfrom, $sendto), null, 'mesgs');
138 } else {
139 setEventMessages($langs->trans("ResultKo"), null, 'errors');
140 }
141
142 $action = '';
143 }
144}
145
146
147
148/*
149 * View
150 */
151
152$form = new Form($db);
153
154$linuxlike = 1;
155if (preg_match('/^win/i', PHP_OS)) {
156 $linuxlike = 0;
157}
158if (preg_match('/^mac/i', PHP_OS)) {
159 $linuxlike = 0;
160}
161
162$wikihelp = 'EN:Setup Sms|FR:Paramétrage Sms|ES:Configuración Sms';
163llxHeader('', $langs->trans("Setup"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-sms');
164
165print load_fiche_titre($langs->trans("SmsSetup"), '', 'title_setup');
166
167print '<span class="opacitymedium">'.$langs->trans("SmsDesc")."</span><br>\n";
168print "<br>\n";
169print "<br>\n";
170
171// List of sending methods
172$listofmethods = (is_array($conf->modules_parts['sms']) ? $conf->modules_parts['sms'] : array());
173asort($listofmethods);
174
175if (!count($listofmethods)) {
176 $descnosms = $langs->trans("NoSmsEngine", '{Dolistore}');
177 $descnosms = str_replace('{Dolistore}', '<a href="https://www.dolistore.com/index.php?controller=search&orderby=position&orderway=desc&website=marketplace&search_query=smsmanager">DoliStore</a>', $descnosms);
178 print '<div class="warning">'.$descnosms.'</div>';
179}
180
181if ($action == 'edit') {
182 print '<form method="post" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
183 print '<input type="hidden" name="token" value="'.newToken().'">';
184 print '<input type="hidden" name="action" value="update">';
185
186 clearstatcache();
187
188 print '<table class="noborder centpercent">';
189 print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td></td></tr>';
190
191 // Disable
192 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>';
193 print $form->selectyesno('MAIN_DISABLE_ALL_SMS', getDolGlobalString('MAIN_DISABLE_ALL_SMS'), 1);
194 print '</td></tr>';
195
196 // Separator
197 print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
198
199 // Method
200 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
201 if (count($listofmethods)) {
202 print $form->selectarray('MAIN_SMS_SENDMODE', $listofmethods, getDolGlobalString('MAIN_SMS_SENDMODE'), 1);
203 } else {
204 print '<span class="error">'.$langs->trans("None").'</span>';
205 }
206 print '</td></tr>';
207
208 // From
209 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_SMS_FROM", $langs->transnoentities("Undefined")).'</td>';
210 print '<td><input class="flat" name="MAIN_SMS_FROM" size="32" value="'.getDolGlobalString('MAIN_SMS_FROM');
211 print '"></td></tr>';
212
213 print '</table>';
214
215 print '<div class="center">';
216 print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'"'.(!count($listofmethods) ? ' disabled' : '').'>';
217 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
218 print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
219 print '</div>';
220
221 print '</form>';
222 print '<br>';
223} else {
224 print '<table class="noborder centpercent">';
225 print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td></td></tr>';
226
227 // Disable
228 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>'.yn(getDolGlobalString('MAIN_DISABLE_ALL_SMS')).'</td></tr>';
229
230 // Separator
231 print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
232
233 // Method
234 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
235 $text = getDolGlobalString('MAIN_SMS_SENDMODE') ? $listofmethods[getDolGlobalString('MAIN_SMS_SENDMODE')] : '';
236 if (empty($text)) {
237 $text = $langs->trans("Undefined").' '.img_warning();
238 }
239 print $text;
240 print '</td></tr>';
241
242 // From
243 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_SMS_FROM", $langs->transnoentities("Undefined")).'</td>';
244 print '<td>'.getDolGlobalString('MAIN_SMS_FROM');
245 if (getDolGlobalString('MAIN_SMS_FROM') && !isValidPhone(getDolGlobalString('MAIN_SMS_FROM'))) {
246 print ' '.img_warning($langs->trans("ErrorBadPhone"));
247 }
248 print '</td></tr>';
249
250 print '</table>';
251
252
253 // Buttons for actions
254
255 print '<div class="tabsAction">';
256
257 if ($action != 'test') {
258 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
259
260 if (count($listofmethods) && getDolGlobalString('MAIN_SMS_SENDMODE')) {
261 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&mode=init&token='.newToken().'">'.$langs->trans("DoTestSend").'</a>';
262 } else {
263 print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("DoTestSend").'</a>';
264 }
265 }
266
267 print '</div>';
268
269
270 // Affichage formulaire de TEST simple
271 if ($action == 'test') {
272 print '<br>';
273 print load_fiche_titre($langs->trans("DoTestSend"));
274
275 // Cree l'objet formulaire mail
276 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formsms.class.php';
277 $formsms = new FormSms($db);
278 $formsms->fromtype = 'user';
279 $formsms->fromid = $user->id;
280 $formsms->fromsms = (GETPOSTISSET('fromsms') ? GETPOST('fromsms') : getDolGlobalString('MAIN_SMS_FROM', $user->user_mobile));
281 $formsms->withfromreadonly = 0;
282 $formsms->withsubstit = 0;
283 $formsms->withfrom = 1;
284 $formsms->withto = (GETPOSTISSET('sendto') ? GETPOST('sendto') : ($user->user_mobile ? $user->user_mobile : 1));
285 $formsms->withbody = (GETPOSTISSET('message') ? (!GETPOST('message') ? 1 : GETPOST('message')) : $langs->trans("ThisIsATestMessage"));
286 $formsms->withbodyreadonly = 0;
287 $formsms->withcancel = 1;
288 // Tableau des substitutions
289 $formsms->substit = $substitutionarrayfortest;
290 // Tableau des parameters complementaires du post
291 $formsms->param["action"] = "send";
292 $formsms->param["models"] = "body";
293 $formsms->param["smsid"] = 0;
294 $formsms->param["returnurl"] = $_SERVER["PHP_SELF"];
295
296 $formsms->show_form();
297
298 print '<br>';
299 }
300}
301
302// End of page
303llxFooter();
304$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).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
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.
Class permettant la generation du formulaire d'envoi de Sms Usage: $formsms = new FormSms($db) $forms...
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
isValidPhone($phone)
Return true if phone number syntax is ok TODO Decide what to do with this.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a 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.