dolibarr  9.0.0
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  *
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 // Load translation files required by the page
29 $langs->loadLangs(array("companies","admin","products","sms","other","errors"));
30 
31 if (!$user->admin)
33 
34 $substitutionarrayfortest=array(
35 '__ID__' => 'TESTIdRecord',
36 '__PHONEFROM__' => 'TESTPhoneFrom',
37 '__PHONETO__' => 'TESTPhoneTo',
38 '__LASTNAME__' => 'TESTLastname',
39 '__FIRSTNAME__' => 'TESTFirstname'
40 );
41 
42 $action=GETPOST('action','aZ09');
43 
44 
45 /*
46  * Actions
47  */
48 
49 if ($action == 'update' && empty($_POST["cancel"]))
50 {
51  dolibarr_set_const($db, "MAIN_DISABLE_ALL_SMS", $_POST["MAIN_DISABLE_ALL_SMS"], 'chaine', 0, '', $conf->entity);
52 
53  dolibarr_set_const($db, "MAIN_SMS_SENDMODE", $_POST["MAIN_SMS_SENDMODE"], 'chaine', 0, '', $conf->entity);
54 
55  dolibarr_set_const($db, "MAIN_MAIL_SMS_FROM", $_POST["MAIN_MAIL_SMS_FROM"], 'chaine', 0, '', $conf->entity);
56  //dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", $_POST["MAIN_MAIL_AUTOCOPY_TO"], 'chaine', 0, '', $conf->entity);
57 
58  header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
59  exit;
60 }
61 
62 
63 /*
64  * Send sms
65  */
66 if ($action == 'send' && ! $_POST['cancel'])
67 {
68  $error=0;
69 
70  $smsfrom='';
71  if (! empty($_POST["fromsms"])) $smsfrom=GETPOST("fromsms");
72  if (empty($smsfrom)) $smsfrom=GETPOST("fromname");
73  $sendto = GETPOST("sendto");
74  $body = GETPOST('message');
75  $deliveryreceipt= GETPOST("deliveryreceipt");
76  $deferred = GETPOST('deferred');
77  $priority = GETPOST('priority');
78  $class = GETPOST('class');
79  $errors_to = GETPOST("errorstosms");
80 
81  // Create form object
82  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formsms.class.php';
83  $formsms = new FormSms($db);
84 
85  if (! empty($formsms->error))
86  {
87  setEventMessages($formsms->error, $formsms->errors, 'errors');
88  $action='test';
89  $error++;
90  }
91  if (empty($body))
92  {
93  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Message")), null, 'errors');
94  $action='test';
95  $error++;
96  }
97  if (empty($smsfrom) || ! str_replace('+','',$smsfrom))
98  {
99  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("SmsFrom")), null, 'errors');
100  $action='test';
101  $error++;
102  }
103  if (empty($sendto) || ! str_replace('+','',$sendto))
104  {
105  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("SmsTo")), null, 'errors');
106  $action='test';
107  $error++;
108  }
109  if (! $error)
110  {
111  // Make substitutions into message
112  complete_substitutions_array($substitutionarrayfortest, $langs);
113  $body=make_substitutions($body,$substitutionarrayfortest);
114 
115  require_once DOL_DOCUMENT_ROOT.'/core/class/CSMSFile.class.php';
116 
117  $smsfile = new CSMSFile($sendto, $smsfrom, $body, $deliveryreceipt, $deferred, $priority, $class); // This define OvhSms->login, pass, session and account
118  $result=$smsfile->sendfile(); // This send SMS
119 
120  if ($result)
121  {
122  setEventMessages($langs->trans("SmsSuccessfulySent",$smsfrom,$sendto), null, 'mesgs');
123  setEventMessages($smsfile->error, $smsfile->errors, 'mesgs');
124  }
125  else
126  {
127  setEventMessages($langs->trans("ResultKo"), null, 'errors');
128  setEventMessages($smsfile->error, $smsfile->errors, 'errors');
129  }
130 
131  $action='';
132  }
133 }
134 
135 
136 
137 /*
138  * View
139  */
140 
141 $linuxlike=1;
142 if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
143 if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
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 $langs->trans("SmsDesc")."<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 ($action == 'edit')
158 {
159  $form=new Form($db);
160 
161  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>';
162 
163  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
164  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
165  print '<input type="hidden" name="action" value="update">';
166 
167  clearstatcache();
168 
169  print '<table class="noborder" width="100%">';
170  print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
171 
172  // Disable
173  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>';
174  print $form->selectyesno('MAIN_DISABLE_ALL_SMS',$conf->global->MAIN_DISABLE_ALL_SMS,1);
175  print '</td></tr>';
176 
177  // Separator
178  print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
179 
180  // Method
181  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
182  if (count($listofmethods)) print $form->selectarray('MAIN_SMS_SENDMODE',$listofmethods,$conf->global->MAIN_SMS_SENDMODE,1);
183  else print '<font class="error">'.$langs->trans("None").'</font>';
184  print '</td></tr>';
185 
186  // From
187  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMS_FROM",$langs->transnoentities("Undefined")).'</td>';
188  print '<td><input class="flat" name="MAIN_MAIL_SMS_FROM" size="32" value="' . $conf->global->MAIN_MAIL_SMS_FROM;
189  print '"></td></tr>';
190 
191  // Autocopy to
192  /*
193  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
194  print '<td><input class="flat" name="MAIN_MAIL_AUTOCOPY_TO" size="32" value="' . $conf->global->MAIN_MAIL_AUTOCOPY_TO;
195  print '"></td></tr>';
196  */
197  print '</table>';
198 
199  print '<br><div class="center">';
200  print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'"'.(!count($listofmethods)?' disabled':'').'>';
201  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
202  print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
203  print '</div>';
204 
205  print '</form>';
206  print '<br>';
207 }
208 else
209 {
210 
211  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>';
212 
213  print '<table class="noborder" width="100%">';
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($conf->global->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=$listofmethods[$conf->global->MAIN_SMS_SENDMODE];
225  if (empty($text)) $text=$langs->trans("Undefined").' '.img_warning();
226  print $text;
227  print '</td></tr>';
228 
229  // From
230  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMS_FROM",$langs->transnoentities("Undefined")).'</td>';
231  print '<td>'.$conf->global->MAIN_MAIL_SMS_FROM;
232  if (!empty($conf->global->MAIN_MAIL_SMS_FROM) && ! isValidPhone($conf->global->MAIN_MAIL_SMS_FROM)) print ' '.img_warning($langs->trans("ErrorBadPhone"));
233  print '</td></tr>';
234 
235  // Autocopy to
236  /*
237  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
238  print '<td>'.$conf->global->MAIN_MAIL_AUTOCOPY_TO;
239  if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO) && ! isValidEmail($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print img_warning($langs->trans("ErrorBadEMail"));
240  print '</td></tr>';
241  */
242 
243  print '</table>';
244 
245 
246  // Boutons actions
247 
248  print '<div class="tabsAction">';
249 
250  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
251 
252  /*if ($conf->global->MAIN_SMS_SENDMODE != 'mail' || ! $linuxlike)
253  {
254  if (function_exists('fsockopen') && $port && $server)
255  {
256  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
257  }
258  }
259  else
260  {
261  print '<a class="butActionRefused" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
262  }*/
263 
264  if (count($listofmethods) && ! empty($conf->global->MAIN_SMS_SENDMODE))
265  {
266  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
267  }
268  else
269  {
270  print '<a class="butActionRefused" href="#">'.$langs->trans("DoTestSend").'</a>';
271  }
272  print '</div>';
273 
274 
275  // Run the test to connect
276  /*
277  if ($_GET["action"] == 'testconnect')
278  {
279  print '<br>';
280  print load_fiche_titre($langs->trans("DoTestServerAvailability"));
281 
282  // If we use SSL/TLS
283  if (! empty($conf->global->MAIN_MAIL_EMAIL_TLS) && function_exists('openssl_open')) $server='ssl://'.$server;
284 
285  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
286  $mail = new CSMSFile('','','','');
287  $result=$mail->check_server_port($server,$port);
288  if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort",$server,$port).'</div>';
289  else
290  {
291  print '<div class="error">'.$langs->trans("ServerNotAvailableOnIPOrPort",$server,$port);
292  if ($mail->error) print ' - '.$mail->error;
293  print '</div>';
294  }
295  print '<br>';
296  }*/
297 
298  // Affichage formulaire de TEST simple
299  if ($action == 'test')
300  {
301  print '<br>';
302  print load_fiche_titre($langs->trans("DoTestSend"));
303 
304  // Cree l'objet formulaire mail
305  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formsms.class.php';
306  $formsms = new FormSms($db);
307  $formsms->fromtype='user';
308  $formsms->fromid=$user->id;
309  $formsms->fromsms = (isset($_POST['fromsms'])?$_POST['fromsms']:($conf->global->MAIN_MAIL_SMS_FROM?$conf->global->MAIN_MAIL_SMS_FROM:$user->user_mobile));
310  $formsms->withfromreadonly=0;
311  $formsms->withsubstit=0;
312  $formsms->withfrom=1;
313  $formsms->witherrorsto=1;
314  $formsms->withto=(isset($_POST['sendto'])?$_POST['sendto']:$user->user_mobile?$user->user_mobile:1);
315  $formsms->withfile=2;
316  $formsms->withbody=(isset($_POST['message'])?(empty($_POST['message'])?1:$_POST['message']):$langs->trans("ThisIsATestMessage"));
317  $formsms->withbodyreadonly=0;
318  $formsms->withcancel=1;
319  $formsms->withfckeditor=0;
320  // Tableau des substitutions
321  $formsms->substit=$substitutionarrayfortest;
322  // Tableau des parametres complementaires du post
323  $formsms->param["action"]="send";
324  $formsms->param["models"]="body";
325  $formsms->param["smsid"]=0;
326  $formsms->param["returnurl"]=$_SERVER["PHP_SELF"];
327 
328  $formsms->show_form();
329 
330  print '<br>';
331  }
332 }
333 
334 // End of page
335 llxFooter();
336 $db->close();
img_warning($titlealt='default', $moreatt='')
Show warning logo.
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
print
Draft customers invoices.
Definition: index.php:91
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:510
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.
llxHeader()
Empty header.
Definition: wrapper.php:44
Classe permettant la generation du formulaire d&#39;envoi de Sms Usage: $formsms = new FormSms($db) $form...
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
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...
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $wikihelp
View.
Definition: agenda.php:120