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