PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/admin/sms.php

https://github.com/asterix14/dolibarr
PHP | 355 lines | 193 code | 67 blank | 95 comment | 30 complexity | 87caee9e4dabe593a1109c886af3f661 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/admin/sms.php
  20. * \brief Page to setup emails sending
  21. */
  22. require("../main.inc.php");
  23. require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
  24. $langs->load("companies");
  25. $langs->load("products");
  26. $langs->load("admin");
  27. $langs->load("sms");
  28. $langs->load("other");
  29. $langs->load("errors");
  30. if (!$user->admin)
  31. accessforbidden();
  32. $substitutionarrayfortest=array(
  33. '__ID__' => 'TESTIdRecord',
  34. '__PHONEFROM__' => 'TESTPhoneFrom',
  35. '__PHONETO__' => 'TESTPhoneTo',
  36. '__LASTNAME__' => 'TESTLastname',
  37. '__FIRSTNAME__' => 'TESTFirstname'
  38. );
  39. $action=GETPOST('action');
  40. /*
  41. * Actions
  42. */
  43. if ($action == 'update' && empty($_POST["cancel"]))
  44. {
  45. dolibarr_set_const($db, "MAIN_DISABLE_ALL_SMS", $_POST["MAIN_DISABLE_ALL_SMS"],'chaine',0,'',$conf->entity);
  46. dolibarr_set_const($db, "MAIN_SMS_SENDMODE", $_POST["MAIN_SMS_SENDMODE"],'chaine',0,'',$conf->entity);
  47. dolibarr_set_const($db, "MAIN_MAIL_SMS_FROM", $_POST["MAIN_MAIL_SMS_FROM"],'chaine',0,'',$conf->entity);
  48. //dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", $_POST["MAIN_MAIL_AUTOCOPY_TO"],'chaine',0,'',$conf->entity);
  49. Header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
  50. exit;
  51. }
  52. /*
  53. * Send sms
  54. */
  55. if ($action == 'send' && ! $_POST['cancel'])
  56. {
  57. $error=0;
  58. $smsfrom='';
  59. if (! empty($_POST["fromsms"])) $smsfrom=GETPOST("fromsms");
  60. if (empty($smsfrom)) $smsfrom=GETPOST("fromname");
  61. $sendto = GETPOST("sendto");
  62. $body = GETPOST('message');
  63. $deliveryreceipt= GETPOST("deliveryreceipt");
  64. $deferred = GETPOST('deferred');
  65. $priority = GETPOST('priority');
  66. $class = GETPOST('class');
  67. $errors_to = GETPOST("errorstosms");
  68. // Create form object
  69. include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formsms.class.php');
  70. $formsms = new FormSms($db);
  71. if (! empty($formsms->error))
  72. {
  73. $message='<div class="error">'.$formsms->error.'</div>';
  74. $action='test';
  75. $error++;
  76. }
  77. if (empty($body))
  78. {
  79. $message='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Message")).'</div>';
  80. $action='test';
  81. $error++;
  82. }
  83. if (empty($smsfrom) || ! str_replace('+','',$smsfrom))
  84. {
  85. $message='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("SmsFrom")).'</div>';
  86. $action='test';
  87. $error++;
  88. }
  89. if (empty($sendto) || ! str_replace('+','',$sendto))
  90. {
  91. $message='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("SmsTo")).'</div>';
  92. $action='test';
  93. $error++;
  94. }
  95. if (! $error)
  96. {
  97. // Make substitutions into message
  98. complete_substitutions_array($substitutionarrayfortest, $langs);
  99. $body=make_substitutions($body,$substitutionarrayfortest);
  100. require_once(DOL_DOCUMENT_ROOT."/core/class/CSMSFile.class.php");
  101. $smsfile = new CSMSFile($sendto, $smsfrom, $body, $deliveryreceipt, $deferred, $priority, $class); // This define OvhSms->login, pass, session and account
  102. $result=$smsfile->sendfile(); // This send SMS
  103. if ($result)
  104. {
  105. $message='<div class="ok">'.$langs->trans("SmsSuccessfulySent",$smsfrom,$sendto).'</div>';
  106. }
  107. else
  108. {
  109. $message='<div class="error">'.$langs->trans("ResultKo").'<br>'.$smsfile->error.' '.$result.'</div>';
  110. }
  111. $action='';
  112. }
  113. }
  114. /*
  115. * View
  116. */
  117. $linuxlike=1;
  118. if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
  119. if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
  120. /*
  121. * View
  122. */
  123. $wikihelp='EN:Setup Sms|FR:Param茅trage Sms|ES:Configuraci贸n Sms';
  124. llxHeader('',$langs->trans("Setup"),$wikihelp);
  125. print_fiche_titre($langs->trans("SmsSetup"),'','setup');
  126. print $langs->trans("SmsDesc")."<br>\n";
  127. print "<br>\n";
  128. dol_htmloutput_mesg($message);
  129. // List of sending methods
  130. $listofmethods=(is_array($conf->sms_engine)?$conf->sms_engine:array());
  131. asort($listofmethods);
  132. if ($action == 'edit')
  133. {
  134. $form=new Form($db);
  135. if (! count($listofmethods)) print '<div class="error">'.$langs->trans("NoSmsEngine").'</div>';
  136. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  137. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  138. print '<input type="hidden" name="action" value="update">';
  139. clearstatcache();
  140. $var=true;
  141. print '<table class="noborder" width="100%">';
  142. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  143. // Disable
  144. $var=!$var;
  145. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>';
  146. print $form->selectyesno('MAIN_DISABLE_ALL_SMS',$conf->global->MAIN_DISABLE_ALL_SMS,1);
  147. print '</td></tr>';
  148. // Separator
  149. $var=!$var;
  150. print '<tr '.$bc[$var].'><td colspan="2">&nbsp;</td></tr>';
  151. // Method
  152. $var=!$var;
  153. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
  154. if (count($listofmethods)) print $form->selectarray('MAIN_SMS_SENDMODE',$listofmethods,$conf->global->MAIN_SMS_SENDMODE,1);
  155. else print '<font class="error">'.$langs->trans("None").'</font>';
  156. print '</td></tr>';
  157. // From
  158. $var=!$var;
  159. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMS_FROM",$langs->transnoentities("Undefined")).'</td>';
  160. print '<td><input class="flat" name="MAIN_MAIL_SMS_FROM" size="32" value="' . $conf->global->MAIN_MAIL_SMS_FROM;
  161. print '"></td></tr>';
  162. // Autocopy to
  163. /*$var=!$var;
  164. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  165. print '<td><input class="flat" name="MAIN_MAIL_AUTOCOPY_TO" size="32" value="' . $conf->global->MAIN_MAIL_AUTOCOPY_TO;
  166. print '"></td></tr>';
  167. */
  168. print '</table>';
  169. print '<br><center>';
  170. print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'"'.(!count($listofmethods)?' disabled="disbaled"':'').'>';
  171. print ' &nbsp; &nbsp; ';
  172. print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  173. print '</center>';
  174. print '</form>';
  175. print '<br>';
  176. }
  177. else
  178. {
  179. $var=true;
  180. print '<table class="noborder" width="100%">';
  181. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  182. // Disable
  183. $var=!$var;
  184. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>'.yn($conf->global->MAIN_DISABLE_ALL_SMS).'</td></tr>';
  185. // Separator
  186. $var=!$var;
  187. print '<tr '.$bc[$var].'><td colspan="2">&nbsp;</td></tr>';
  188. // Method
  189. $var=!$var;
  190. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
  191. $text=$listofmethods[$conf->global->MAIN_SMS_SENDMODE];
  192. if (empty($text)) $text=$langs->trans("Undefined").' '.img_warning();
  193. print $text;
  194. print '</td></tr>';
  195. // From
  196. $var=!$var;
  197. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMS_FROM",$langs->transnoentities("Undefined")).'</td>';
  198. print '<td>'.$conf->global->MAIN_MAIL_SMS_FROM;
  199. if (!empty($conf->global->MAIN_MAIL_SMS_FROM) && ! isValidPhone($conf->global->MAIN_MAIL_SMS_FROM)) print ' '.img_warning($langs->trans("ErrorBadPhone"));
  200. print '</td></tr>';
  201. // Autocopy to
  202. /*$var=!$var;
  203. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  204. print '<td>'.$conf->global->MAIN_MAIL_AUTOCOPY_TO;
  205. if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO) && ! isValidEmail($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print img_warning($langs->trans("ErrorBadEMail"));
  206. print '</td></tr>';
  207. */
  208. print '</table>';
  209. // Boutons actions
  210. print '<div class="tabsAction">';
  211. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
  212. /*if ($conf->global->MAIN_SMS_SENDMODE != 'mail' || ! $linuxlike)
  213. {
  214. if (function_exists('fsockopen') && $port && $server)
  215. {
  216. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
  217. }
  218. }
  219. else
  220. {
  221. print '<a class="butActionRefused" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
  222. }*/
  223. if (! empty($conf->global->MAIN_SMS_SENDMODE))
  224. {
  225. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
  226. }
  227. else
  228. {
  229. print '<a class="butActionRefused" href="#">'.$langs->trans("DoTestSend").'</a>';
  230. }
  231. print '</div>';
  232. // Run the test to connect
  233. /*
  234. if ($_GET["action"] == 'testconnect')
  235. {
  236. print '<br>';
  237. print_titre($langs->trans("DoTestServerAvailability"));
  238. // If we use SSL/TLS
  239. if (! empty($conf->global->MAIN_MAIL_EMAIL_TLS) && function_exists('openssl_open')) $server='ssl://'.$server;
  240. include_once(DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php");
  241. $mail = new CSMSFile('','','','');
  242. $result=$mail->check_server_port($server,$port);
  243. if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort",$server,$port).'</div>';
  244. else
  245. {
  246. print '<div class="error">'.$langs->trans("ServerNotAvailableOnIPOrPort",$server,$port);
  247. if ($mail->error) print ' - '.$langs->convToOutputCharset($mail->error,'ISO-8859-1');
  248. print '</div>';
  249. }
  250. print '<br>';
  251. }*/
  252. // Affichage formulaire de TEST simple
  253. if ($action == 'test')
  254. {
  255. print '<br>';
  256. print_titre($langs->trans("DoTestSend"));
  257. // Cree l'objet formulaire mail
  258. include_once(DOL_DOCUMENT_ROOT."/core/class/html.formsms.class.php");
  259. $formsms = new FormSms($db);
  260. $formsms->fromtype='user';
  261. $formsms->fromid=$user->id;
  262. $formsms->fromsms = (isset($_POST['fromsms'])?$_POST['fromsms']:($conf->global->MAIN_MAIL_SMS_FROM?$conf->global->MAIN_MAIL_SMS_FROM:$user->user_mobile));
  263. $formsms->withfromreadonly=0;
  264. $formsms->withsubstit=0;
  265. $formsms->withfrom=1;
  266. $formsms->witherrorsto=1;
  267. $formsms->withto=(isset($_POST['sendto'])?$_POST['sendto']:$user->user_mobile?$user->user_mobile:1);
  268. $formsms->withfile=2;
  269. $formsms->withbody=(isset($_POST['message'])?(empty($_POST['message'])?1:$_POST['message']):$langs->trans("ThisIsATestMessage"));
  270. $formsms->withbodyreadonly=0;
  271. $formsms->withcancel=1;
  272. $formsms->withfckeditor=0;
  273. // Tableau des substitutions
  274. $formsms->substit=$substitutionarrayfortest;
  275. // Tableau des parametres complementaires du post
  276. $formsms->param["action"]="send";
  277. $formsms->param["models"]="body";
  278. $formsms->param["smsid"]=0;
  279. $formsms->param["returnurl"]=$_SERVER["PHP_SELF"];
  280. $formsms->show_form();
  281. print '<br>';
  282. }
  283. }
  284. $db->close();
  285. llxFooter();
  286. ?>