dolibarr  7.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@capnetworks.com>
4  * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
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 <http://www.gnu.org/licenses/>.
18  */
19 
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27 
28 $langs->load("companies");
29 $langs->load("products");
30 $langs->load("admin");
31 $langs->load("sms");
32 $langs->load("other");
33 $langs->load("errors");
34 
35 if (!$user->admin)
37 
38 $substitutionarrayfortest=array(
39 '__ID__' => 'TESTIdRecord',
40 '__PHONEFROM__' => 'TESTPhoneFrom',
41 '__PHONETO__' => 'TESTPhoneTo',
42 '__LASTNAME__' => 'TESTLastname',
43 '__FIRSTNAME__' => 'TESTFirstname'
44 );
45 
46 $action=GETPOST('action','aZ09');
47 
48 
49 /*
50  * Actions
51  */
52 
53 if ($action == 'update' && empty($_POST["cancel"]))
54 {
55  dolibarr_set_const($db, "MAIN_DISABLE_ALL_SMS", $_POST["MAIN_DISABLE_ALL_SMS"],'chaine',0,'',$conf->entity);
56 
57  dolibarr_set_const($db, "MAIN_SMS_SENDMODE", $_POST["MAIN_SMS_SENDMODE"],'chaine',0,'',$conf->entity);
58 
59  dolibarr_set_const($db, "MAIN_MAIL_SMS_FROM", $_POST["MAIN_MAIL_SMS_FROM"],'chaine',0,'',$conf->entity);
60  //dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", $_POST["MAIN_MAIL_AUTOCOPY_TO"],'chaine',0,'',$conf->entity);
61 
62  header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
63  exit;
64 }
65 
66 
67 /*
68  * Send sms
69  */
70 if ($action == 'send' && ! $_POST['cancel'])
71 {
72  $error=0;
73 
74  $smsfrom='';
75  if (! empty($_POST["fromsms"])) $smsfrom=GETPOST("fromsms");
76  if (empty($smsfrom)) $smsfrom=GETPOST("fromname");
77  $sendto = GETPOST("sendto");
78  $body = GETPOST('message');
79  $deliveryreceipt= GETPOST("deliveryreceipt");
80  $deferred = GETPOST('deferred');
81  $priority = GETPOST('priority');
82  $class = GETPOST('class');
83  $errors_to = GETPOST("errorstosms");
84 
85  // Create form object
86  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formsms.class.php';
87  $formsms = new FormSms($db);
88 
89  if (! empty($formsms->error))
90  {
91  setEventMessages($formsms->error, $formsms->errors, 'errors');
92  $action='test';
93  $error++;
94  }
95  if (empty($body))
96  {
97  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Message")), null, 'errors');
98  $action='test';
99  $error++;
100  }
101  if (empty($smsfrom) || ! str_replace('+','',$smsfrom))
102  {
103  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("SmsFrom")), null, 'errors');
104  $action='test';
105  $error++;
106  }
107  if (empty($sendto) || ! str_replace('+','',$sendto))
108  {
109  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("SmsTo")), null, 'errors');
110  $action='test';
111  $error++;
112  }
113  if (! $error)
114  {
115  // Make substitutions into message
116  complete_substitutions_array($substitutionarrayfortest, $langs);
117  $body=make_substitutions($body,$substitutionarrayfortest);
118 
119  require_once DOL_DOCUMENT_ROOT.'/core/class/CSMSFile.class.php';
120 
121  $smsfile = new CSMSFile($sendto, $smsfrom, $body, $deliveryreceipt, $deferred, $priority, $class); // This define OvhSms->login, pass, session and account
122  $result=$smsfile->sendfile(); // This send SMS
123 
124  if ($result)
125  {
126  setEventMessages($langs->trans("SmsSuccessfulySent",$smsfrom,$sendto), null, 'mesgs');
127  setEventMessages($smsfile->error, $smsfile->errors, 'mesgs');
128  }
129  else
130  {
131  setEventMessages($langs->trans("ResultKo"), null, 'errors');
132  setEventMessages($smsfile->error, $smsfile->errors, 'errors');
133  }
134 
135  $action='';
136  }
137 }
138 
139 
140 
141 /*
142  * View
143  */
144 
145 $linuxlike=1;
146 if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
147 if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
148 
149 $wikihelp='EN:Setup Sms|FR:Paramétrage Sms|ES:Configuración Sms';
150 llxHeader('',$langs->trans("Setup"),$wikihelp);
151 
152 print load_fiche_titre($langs->trans("SmsSetup"),'','title_setup');
153 
154 print $langs->trans("SmsDesc")."<br>\n";
155 print "<br>\n";
156 
157 // List of sending methods
158 $listofmethods=(is_array($conf->modules_parts['sms'])?$conf->modules_parts['sms']:array());
159 asort($listofmethods);
160 
161 if ($action == 'edit')
162 {
163  $form=new Form($db);
164 
165  if (! count($listofmethods)) print '<div class="warning">'.$langs->trans("NoSmsEngine",'<a href="http://www.dolistore.com/search.php?orderby=position&orderway=desc&search_query=smsmanager">DoliStore</a>').'</div>';
166 
167  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
168  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
169  print '<input type="hidden" name="action" value="update">';
170 
171  clearstatcache();
172  $var=true;
173 
174  print '<table class="noborder" width="100%">';
175  print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
176 
177  // Disable
178 
179  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>';
180  print $form->selectyesno('MAIN_DISABLE_ALL_SMS',$conf->global->MAIN_DISABLE_ALL_SMS,1);
181  print '</td></tr>';
182 
183  // Separator
184 
185  print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
186 
187  // Method
188 
189  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
190  if (count($listofmethods)) print $form->selectarray('MAIN_SMS_SENDMODE',$listofmethods,$conf->global->MAIN_SMS_SENDMODE,1);
191  else print '<font class="error">'.$langs->trans("None").'</font>';
192  print '</td></tr>';
193 
194  // From
195 
196  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMS_FROM",$langs->transnoentities("Undefined")).'</td>';
197  print '<td><input class="flat" name="MAIN_MAIL_SMS_FROM" size="32" value="' . $conf->global->MAIN_MAIL_SMS_FROM;
198  print '"></td></tr>';
199 
200  // Autocopy to
201  /*
202  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
203  print '<td><input class="flat" name="MAIN_MAIL_AUTOCOPY_TO" size="32" value="' . $conf->global->MAIN_MAIL_AUTOCOPY_TO;
204  print '"></td></tr>';
205  */
206  print '</table>';
207 
208  print '<br><div class="center">';
209  print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'"'.(!count($listofmethods)?' disabled':'').'>';
210  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
211  print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
212  print '</div>';
213 
214  print '</form>';
215  print '<br>';
216 }
217 else
218 {
219  $var=true;
220 
221  if (! count($listofmethods)) print '<div class="warning">'.$langs->trans("NoSmsEngine",'<a target="_blank" href="http://www.dolistore.com/search.php?orderby=position&orderway=desc&search_query=smsmanager">DoliStore</a>').'</div>';
222 
223  print '<table class="noborder" width="100%">';
224  print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
225 
226  // Disable
227 
228  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>'.yn($conf->global->MAIN_DISABLE_ALL_SMS).'</td></tr>';
229 
230  // Separator
231 
232  print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
233 
234  // Method
235 
236  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
237  $text=$listofmethods[$conf->global->MAIN_SMS_SENDMODE];
238  if (empty($text)) $text=$langs->trans("Undefined").' '.img_warning();
239  print $text;
240  print '</td></tr>';
241 
242  // From
243 
244  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMS_FROM",$langs->transnoentities("Undefined")).'</td>';
245  print '<td>'.$conf->global->MAIN_MAIL_SMS_FROM;
246  if (!empty($conf->global->MAIN_MAIL_SMS_FROM) && ! isValidPhone($conf->global->MAIN_MAIL_SMS_FROM)) print ' '.img_warning($langs->trans("ErrorBadPhone"));
247  print '</td></tr>';
248 
249  // Autocopy to
250  /*
251  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
252  print '<td>'.$conf->global->MAIN_MAIL_AUTOCOPY_TO;
253  if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO) && ! isValidEmail($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print img_warning($langs->trans("ErrorBadEMail"));
254  print '</td></tr>';
255  */
256 
257  print '</table>';
258 
259 
260  // Boutons actions
261 
262  print '<div class="tabsAction">';
263 
264  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
265 
266  /*if ($conf->global->MAIN_SMS_SENDMODE != 'mail' || ! $linuxlike)
267  {
268  if (function_exists('fsockopen') && $port && $server)
269  {
270  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
271  }
272  }
273  else
274  {
275  print '<a class="butActionRefused" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
276  }*/
277 
278  if (count($listofmethods) && ! empty($conf->global->MAIN_SMS_SENDMODE))
279  {
280  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
281  }
282  else
283  {
284  print '<a class="butActionRefused" href="#">'.$langs->trans("DoTestSend").'</a>';
285  }
286  print '</div>';
287 
288 
289  // Run the test to connect
290  /*
291  if ($_GET["action"] == 'testconnect')
292  {
293  print '<br>';
294  print load_fiche_titre($langs->trans("DoTestServerAvailability"));
295 
296  // If we use SSL/TLS
297  if (! empty($conf->global->MAIN_MAIL_EMAIL_TLS) && function_exists('openssl_open')) $server='ssl://'.$server;
298 
299  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
300  $mail = new CSMSFile('','','','');
301  $result=$mail->check_server_port($server,$port);
302  if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort",$server,$port).'</div>';
303  else
304  {
305  print '<div class="error">'.$langs->trans("ServerNotAvailableOnIPOrPort",$server,$port);
306  if ($mail->error) print ' - '.$mail->error;
307  print '</div>';
308  }
309  print '<br>';
310  }*/
311 
312  // Affichage formulaire de TEST simple
313  if ($action == 'test')
314  {
315  print '<br>';
316  print load_fiche_titre($langs->trans("DoTestSend"));
317 
318  // Cree l'objet formulaire mail
319  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formsms.class.php';
320  $formsms = new FormSms($db);
321  $formsms->fromtype='user';
322  $formsms->fromid=$user->id;
323  $formsms->fromsms = (isset($_POST['fromsms'])?$_POST['fromsms']:($conf->global->MAIN_MAIL_SMS_FROM?$conf->global->MAIN_MAIL_SMS_FROM:$user->user_mobile));
324  $formsms->withfromreadonly=0;
325  $formsms->withsubstit=0;
326  $formsms->withfrom=1;
327  $formsms->witherrorsto=1;
328  $formsms->withto=(isset($_POST['sendto'])?$_POST['sendto']:$user->user_mobile?$user->user_mobile:1);
329  $formsms->withfile=2;
330  $formsms->withbody=(isset($_POST['message'])?(empty($_POST['message'])?1:$_POST['message']):$langs->trans("ThisIsATestMessage"));
331  $formsms->withbodyreadonly=0;
332  $formsms->withcancel=1;
333  $formsms->withfckeditor=0;
334  // Tableau des substitutions
335  $formsms->substit=$substitutionarrayfortest;
336  // Tableau des parametres complementaires du post
337  $formsms->param["action"]="send";
338  $formsms->param["models"]="body";
339  $formsms->param["smsid"]=0;
340  $formsms->param["returnurl"]=$_SERVER["PHP_SELF"];
341 
342  $formsms->show_form();
343 
344  print '<br>';
345  }
346 }
347 
348 
349 llxFooter();
350 
351 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
Class to send SMS Usage: $smsfile = new CSMSFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to); $smsfile->sendfile();.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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:485
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
if(GETPOST('button_removefilter_x','alpha')||GETPOST('button_removefilter.x','alpha')||GETPOST('button_removefilter','alpha')) if($action=="save"&&empty($cancel)) if(preg_match('/set_(.*)/', $action, $reg)) if(preg_match('/del_(.*)/', $action, $reg) $wikihelp)
View.
Definition: agenda.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
Classe permettant la generation du formulaire d'envoi de Sms Usage: $formsms = new FormSms($db) $form...
print
Draft customers invoices.
Definition: index.php:91
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substition into a text string, replacing keys with vals from $substitutionarray (oldval=>newval)...
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...