dolibarr  18.0.0-alpha
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
27 require '../main.inc.php';
28 require_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 
36 if (!$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 
53 if ($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
66 if ($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 
115  $smsfile = new CSMSFile($sendto, $smsfrom, $body, $deliveryreceipt, $deferred, $priority, $class); // This define OvhSms->login, pass, session and account
116  $result = $smsfile->sendfile(); // This send SMS
117 
118  if ($result) {
119  setEventMessages($langs->trans("SmsSuccessfulySent", $smsfrom, $sendto), null, 'mesgs');
120  setEventMessages($smsfile->error, $smsfile->errors, 'mesgs');
121  } else {
122  setEventMessages($langs->trans("ResultKo"), null, 'errors');
123  setEventMessages($smsfile->error, $smsfile->errors, 'errors');
124  }
125 
126  $action = '';
127  }
128 }
129 
130 
131 
132 /*
133  * View
134  */
135 
136 $form = new Form($db);
137 
138 $linuxlike = 1;
139 if (preg_match('/^win/i', PHP_OS)) {
140  $linuxlike = 0;
141 }
142 if (preg_match('/^mac/i', PHP_OS)) {
143  $linuxlike = 0;
144 }
145 
146 $wikihelp = 'EN:Setup Sms|FR:Paramétrage Sms|ES:Configuración Sms';
147 llxHeader('', $langs->trans("Setup"), $wikihelp);
148 
149 print load_fiche_titre($langs->trans("SmsSetup"), '', 'title_setup');
150 
151 print '<span class="opacitymedium">'.$langs->trans("SmsDesc")."</span><br>\n";
152 print "<br>\n";
153 
154 // List of sending methods
155 $listofmethods = (is_array($conf->modules_parts['sms']) ? $conf->modules_parts['sms'] : array());
156 asort($listofmethods);
157 
158 if (!count($listofmethods)) {
159  $descnosms = $langs->trans("NoSmsEngine", '{Dolistore}');
160  $descnosms = str_replace('{Dolistore}', '<a href="https://www.dolistore.com/search.php?orderby=position&orderway=desc&search_query=smsmanager">DoliStore</a>', $descnosms);
161  print '<div class="warning">'.$descnosms.'</div>';
162 }
163 
164 if ($action == 'edit') {
165  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
166  print '<input type="hidden" name="token" value="'.newToken().'">';
167  print '<input type="hidden" name="action" value="update">';
168 
169  clearstatcache();
170 
171  print '<table class="noborder centpercent">';
172  print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
173 
174  // Disable
175  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>';
176  print $form->selectyesno('MAIN_DISABLE_ALL_SMS', getDolGlobalString('MAIN_DISABLE_ALL_SMS'), 1);
177  print '</td></tr>';
178 
179  // Separator
180  print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
181 
182  // Method
183  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
184  if (count($listofmethods)) {
185  print $form->selectarray('MAIN_SMS_SENDMODE', $listofmethods, $conf->global->MAIN_SMS_SENDMODE, 1);
186  } else {
187  print '<span class="error">'.$langs->trans("None").'</span>';
188  }
189  print '</td></tr>';
190 
191  // From
192  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMS_FROM", $langs->transnoentities("Undefined")).'</td>';
193  print '<td><input class="flat" name="MAIN_MAIL_SMS_FROM" size="32" value="'.getDolGlobalString('MAIN_MAIL_SMS_FROM');
194  print '"></td></tr>';
195 
196  // Autocopy to
197  /*
198  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
199  print '<td><input class="flat" name="MAIN_MAIL_AUTOCOPY_TO" size="32" value="' . $conf->global->MAIN_MAIL_AUTOCOPY_TO;
200  print '"></td></tr>';
201  */
202  print '</table>';
203 
204  print '<br><div class="center">';
205  print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'"'.(!count($listofmethods) ? ' disabled' : '').'>';
206  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
207  print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
208  print '</div>';
209 
210  print '</form>';
211  print '<br>';
212 } else {
213  print '<table class="noborder centpercent">';
214  print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
215 
216  // Disable
217  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>'.yn(getDolGlobalString('MAIN_DISABLE_ALL_SMS')).'</td></tr>';
218 
219  // Separator
220  print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
221 
222  // Method
223  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
224  $text = empty(getDolGlobalString('MAIN_SMS_SENDMODE')) ? '' : $listofmethods[getDolGlobalString('MAIN_SMS_SENDMODE')];
225  if (empty($text)) {
226  $text = $langs->trans("Undefined").' '.img_warning();
227  }
228  print $text;
229  print '</td></tr>';
230 
231  // From
232  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMS_FROM", $langs->transnoentities("Undefined")).'</td>';
233  print '<td>'.getDolGlobalString('MAIN_MAIL_SMS_FROM');
234  if (!empty($conf->global->MAIN_MAIL_SMS_FROM) && !isValidPhone($conf->global->MAIN_MAIL_SMS_FROM)) {
235  print ' '.img_warning($langs->trans("ErrorBadPhone"));
236  }
237  print '</td></tr>';
238 
239  // Autocopy to
240  /*
241  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
242  print '<td>'.$conf->global->MAIN_MAIL_AUTOCOPY_TO;
243  if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO) && ! isValidEmail($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print img_warning($langs->trans("ErrorBadEMail"));
244  print '</td></tr>';
245  */
246 
247  print '</table>';
248 
249 
250  // Buttons for actions
251 
252  print '<div class="tabsAction">';
253 
254  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
255 
256  /*if ($conf->global->MAIN_SMS_SENDMODE != 'mail' || ! $linuxlike)
257  {
258  if (function_exists('fsockopen') && $port && $server)
259  {
260  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
261  }
262  }
263  else
264  {
265  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
266  }*/
267 
268  if (count($listofmethods) && !empty($conf->global->MAIN_SMS_SENDMODE)) {
269  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
270  } else {
271  print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("DoTestSend").'</a>';
272  }
273  print '</div>';
274 
275  // Affichage formulaire de TEST simple
276  if ($action == 'test') {
277  print '<br>';
278  print load_fiche_titre($langs->trans("DoTestSend"));
279 
280  // Cree l'objet formulaire mail
281  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formsms.class.php';
282  $formsms = new FormSms($db);
283  $formsms->fromtype = 'user';
284  $formsms->fromid = $user->id;
285  $formsms->fromsms = (GETPOSTISSET('fromsms') ? GETPOST('fromsms') : ($conf->global->MAIN_MAIL_SMS_FROM ? $conf->global->MAIN_MAIL_SMS_FROM : $user->user_mobile));
286  $formsms->withfromreadonly = 0;
287  $formsms->withsubstit = 0;
288  $formsms->withfrom = 1;
289  $formsms->withto = (GETPOSTISSET('sendto') ? GETPOST('sendto') : ($user->user_mobile ? $user->user_mobile : 1));
290  $formsms->withbody = (GETPOSTISSET('message') ? (!GETPOST('message') ? 1 : GETPOST('message')) : $langs->trans("ThisIsATestMessage"));
291  $formsms->withbodyreadonly = 0;
292  $formsms->withcancel = 1;
293  // Tableau des substitutions
294  $formsms->substit = $substitutionarrayfortest;
295  // Tableau des parametres complementaires du post
296  $formsms->param["action"] = "send";
297  $formsms->param["models"] = "body";
298  $formsms->param["smsid"] = 0;
299  $formsms->param["returnurl"] = $_SERVER["PHP_SELF"];
300 
301  $formsms->show_form();
302 
303  print '<br>';
304  }
305 }
306 
307 // End of page
308 llxFooter();
309 $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:8210
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6699
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
isValidPhone
isValidPhone($phone)
Return true if phone number syntax is ok TODO Decide what to do with this.
Definition: functions.lib.php:3854
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5363
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:530
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:4671
$wikihelp
if(GETPOSTISSET('MAIN_AGENDA_XCAL_EXPORTKEY')) if(GETPOSTISSET('MAIN_AGENDA_EXPORT_PAST_DELAY')) if(GETPOSTISSET('MAIN_AGENDA_EXPORT_CACHE')) if(GETPOSTISSET('AGENDA_EXPORT_FIX_TZ')) if($actionsave) if(!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $wikihelp
View.
Definition: agenda_xcal.php:90
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
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:82
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:633
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:431
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:8509
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1106
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:8333