sms.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. /**
  20. * \file htdocs/admin/sms.php
  21. * \brief Page to setup emails sending
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  25. $langs->load("companies");
  26. $langs->load("products");
  27. $langs->load("admin");
  28. $langs->load("sms");
  29. $langs->load("other");
  30. $langs->load("errors");
  31. if (!$user->admin)
  32. accessforbidden();
  33. $substitutionarrayfortest=array(
  34. '__ID__' => 'TESTIdRecord',
  35. '__PHONEFROM__' => 'TESTPhoneFrom',
  36. '__PHONETO__' => 'TESTPhoneTo',
  37. '__LASTNAME__' => 'TESTLastname',
  38. '__FIRSTNAME__' => 'TESTFirstname'
  39. );
  40. $action=GETPOST('action','aZ09');
  41. /*
  42. * Actions
  43. */
  44. if ($action == 'update' && empty($_POST["cancel"]))
  45. {
  46. dolibarr_set_const($db, "MAIN_DISABLE_ALL_SMS", $_POST["MAIN_DISABLE_ALL_SMS"],'chaine',0,'',$conf->entity);
  47. dolibarr_set_const($db, "MAIN_SMS_SENDMODE", $_POST["MAIN_SMS_SENDMODE"],'chaine',0,'',$conf->entity);
  48. dolibarr_set_const($db, "MAIN_MAIL_SMS_FROM", $_POST["MAIN_MAIL_SMS_FROM"],'chaine',0,'',$conf->entity);
  49. //dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", $_POST["MAIN_MAIL_AUTOCOPY_TO"],'chaine',0,'',$conf->entity);
  50. header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
  51. exit;
  52. }
  53. /*
  54. * Send sms
  55. */
  56. if ($action == 'send' && ! $_POST['cancel'])
  57. {
  58. $error=0;
  59. $smsfrom='';
  60. if (! empty($_POST["fromsms"])) $smsfrom=GETPOST("fromsms");
  61. if (empty($smsfrom)) $smsfrom=GETPOST("fromname");
  62. $sendto = GETPOST("sendto");
  63. $body = GETPOST('message');
  64. $deliveryreceipt= GETPOST("deliveryreceipt");
  65. $deferred = GETPOST('deferred');
  66. $priority = GETPOST('priority');
  67. $class = GETPOST('class');
  68. $errors_to = GETPOST("errorstosms");
  69. // Create form object
  70. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formsms.class.php';
  71. $formsms = new FormSms($db);
  72. if (! empty($formsms->error))
  73. {
  74. setEventMessages($formsms->error, $formsms->errors, 'errors');
  75. $action='test';
  76. $error++;
  77. }
  78. if (empty($body))
  79. {
  80. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Message")), null, 'errors');
  81. $action='test';
  82. $error++;
  83. }
  84. if (empty($smsfrom) || ! str_replace('+','',$smsfrom))
  85. {
  86. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("SmsFrom")), null, 'errors');
  87. $action='test';
  88. $error++;
  89. }
  90. if (empty($sendto) || ! str_replace('+','',$sendto))
  91. {
  92. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("SmsTo")), null, 'errors');
  93. $action='test';
  94. $error++;
  95. }
  96. if (! $error)
  97. {
  98. // Make substitutions into message
  99. complete_substitutions_array($substitutionarrayfortest, $langs);
  100. $body=make_substitutions($body,$substitutionarrayfortest);
  101. require_once DOL_DOCUMENT_ROOT.'/core/class/CSMSFile.class.php';
  102. $smsfile = new CSMSFile($sendto, $smsfrom, $body, $deliveryreceipt, $deferred, $priority, $class); // This define OvhSms->login, pass, session and account
  103. $result=$smsfile->sendfile(); // This send SMS
  104. if ($result)
  105. {
  106. setEventMessages($langs->trans("SmsSuccessfulySent",$smsfrom,$sendto), null, 'mesgs');
  107. setEventMessages($smsfile->error, $smsfile->errors, 'mesgs');
  108. }
  109. else
  110. {
  111. setEventMessages($langs->trans("ResultKo"), null, 'errors');
  112. setEventMessages($smsfile->error, $smsfile->errors, 'errors');
  113. }
  114. $action='';
  115. }
  116. }
  117. /*
  118. * View
  119. */
  120. $linuxlike=1;
  121. if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
  122. if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
  123. $wikihelp='EN:Setup Sms|FR:Paramétrage Sms|ES:Configuración Sms';
  124. llxHeader('',$langs->trans("Setup"),$wikihelp);
  125. print load_fiche_titre($langs->trans("SmsSetup"),'','title_setup');
  126. print $langs->trans("SmsDesc")."<br>\n";
  127. print "<br>\n";
  128. // List of sending methods
  129. $listofmethods=(is_array($conf->modules_parts['sms'])?$conf->modules_parts['sms']:array());
  130. asort($listofmethods);
  131. if ($action == 'edit')
  132. {
  133. $form=new Form($db);
  134. 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>';
  135. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  136. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  137. print '<input type="hidden" name="action" value="update">';
  138. clearstatcache();
  139. $var=true;
  140. print '<table class="noborder" width="100%">';
  141. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  142. // Disable
  143. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>';
  144. print $form->selectyesno('MAIN_DISABLE_ALL_SMS',$conf->global->MAIN_DISABLE_ALL_SMS,1);
  145. print '</td></tr>';
  146. // Separator
  147. print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
  148. // Method
  149. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
  150. if (count($listofmethods)) print $form->selectarray('MAIN_SMS_SENDMODE',$listofmethods,$conf->global->MAIN_SMS_SENDMODE,1);
  151. else print '<font class="error">'.$langs->trans("None").'</font>';
  152. print '</td></tr>';
  153. // From
  154. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMS_FROM",$langs->transnoentities("Undefined")).'</td>';
  155. print '<td><input class="flat" name="MAIN_MAIL_SMS_FROM" size="32" value="' . $conf->global->MAIN_MAIL_SMS_FROM;
  156. print '"></td></tr>';
  157. // Autocopy to
  158. /*
  159. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  160. print '<td><input class="flat" name="MAIN_MAIL_AUTOCOPY_TO" size="32" value="' . $conf->global->MAIN_MAIL_AUTOCOPY_TO;
  161. print '"></td></tr>';
  162. */
  163. print '</table>';
  164. print '<br><div class="center">';
  165. print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'"'.(!count($listofmethods)?' disabled':'').'>';
  166. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  167. print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  168. print '</div>';
  169. print '</form>';
  170. print '<br>';
  171. }
  172. else
  173. {
  174. $var=true;
  175. 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>';
  176. print '<table class="noborder" width="100%">';
  177. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  178. // Disable
  179. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>'.yn($conf->global->MAIN_DISABLE_ALL_SMS).'</td></tr>';
  180. // Separator
  181. print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
  182. // Method
  183. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
  184. $text=$listofmethods[$conf->global->MAIN_SMS_SENDMODE];
  185. if (empty($text)) $text=$langs->trans("Undefined").' '.img_warning();
  186. print $text;
  187. print '</td></tr>';
  188. // From
  189. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMS_FROM",$langs->transnoentities("Undefined")).'</td>';
  190. print '<td>'.$conf->global->MAIN_MAIL_SMS_FROM;
  191. if (!empty($conf->global->MAIN_MAIL_SMS_FROM) && ! isValidPhone($conf->global->MAIN_MAIL_SMS_FROM)) print ' '.img_warning($langs->trans("ErrorBadPhone"));
  192. print '</td></tr>';
  193. // Autocopy to
  194. /*
  195. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  196. print '<td>'.$conf->global->MAIN_MAIL_AUTOCOPY_TO;
  197. if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO) && ! isValidEmail($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print img_warning($langs->trans("ErrorBadEMail"));
  198. print '</td></tr>';
  199. */
  200. print '</table>';
  201. // Boutons actions
  202. print '<div class="tabsAction">';
  203. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
  204. /*if ($conf->global->MAIN_SMS_SENDMODE != 'mail' || ! $linuxlike)
  205. {
  206. if (function_exists('fsockopen') && $port && $server)
  207. {
  208. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
  209. }
  210. }
  211. else
  212. {
  213. print '<a class="butActionRefused" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
  214. }*/
  215. if (count($listofmethods) && ! empty($conf->global->MAIN_SMS_SENDMODE))
  216. {
  217. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
  218. }
  219. else
  220. {
  221. print '<a class="butActionRefused" href="#">'.$langs->trans("DoTestSend").'</a>';
  222. }
  223. print '</div>';
  224. // Run the test to connect
  225. /*
  226. if ($_GET["action"] == 'testconnect')
  227. {
  228. print '<br>';
  229. print load_fiche_titre($langs->trans("DoTestServerAvailability"));
  230. // If we use SSL/TLS
  231. if (! empty($conf->global->MAIN_MAIL_EMAIL_TLS) && function_exists('openssl_open')) $server='ssl://'.$server;
  232. include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  233. $mail = new CSMSFile('','','','');
  234. $result=$mail->check_server_port($server,$port);
  235. if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort",$server,$port).'</div>';
  236. else
  237. {
  238. print '<div class="error">'.$langs->trans("ServerNotAvailableOnIPOrPort",$server,$port);
  239. if ($mail->error) print ' - '.$mail->error;
  240. print '</div>';
  241. }
  242. print '<br>';
  243. }*/
  244. // Affichage formulaire de TEST simple
  245. if ($action == 'test')
  246. {
  247. print '<br>';
  248. print load_fiche_titre($langs->trans("DoTestSend"));
  249. // Cree l'objet formulaire mail
  250. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formsms.class.php';
  251. $formsms = new FormSms($db);
  252. $formsms->fromtype='user';
  253. $formsms->fromid=$user->id;
  254. $formsms->fromsms = (isset($_POST['fromsms'])?$_POST['fromsms']:($conf->global->MAIN_MAIL_SMS_FROM?$conf->global->MAIN_MAIL_SMS_FROM:$user->user_mobile));
  255. $formsms->withfromreadonly=0;
  256. $formsms->withsubstit=0;
  257. $formsms->withfrom=1;
  258. $formsms->witherrorsto=1;
  259. $formsms->withto=(isset($_POST['sendto'])?$_POST['sendto']:$user->user_mobile?$user->user_mobile:1);
  260. $formsms->withfile=2;
  261. $formsms->withbody=(isset($_POST['message'])?(empty($_POST['message'])?1:$_POST['message']):$langs->trans("ThisIsATestMessage"));
  262. $formsms->withbodyreadonly=0;
  263. $formsms->withcancel=1;
  264. $formsms->withfckeditor=0;
  265. // Tableau des substitutions
  266. $formsms->substit=$substitutionarrayfortest;
  267. // Tableau des parametres complementaires du post
  268. $formsms->param["action"]="send";
  269. $formsms->param["models"]="body";
  270. $formsms->param["smsid"]=0;
  271. $formsms->param["returnurl"]=$_SERVER["PHP_SELF"];
  272. $formsms->show_form();
  273. print '<br>';
  274. }
  275. }
  276. llxFooter();
  277. $db->close();