PageRenderTime 46ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/admin/sms.php

https://bitbucket.org/speedealing/speedealing
PHP | 351 lines | 194 code | 65 blank | 92 comment | 32 complexity | a057a915121a0ad438dcff9968540acd MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009 Regis Houssin <regis.houssin@capnetworks.com>
  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 3 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. $wikihelp='EN:Setup Sms|FR:Paramétrage Sms|ES:Configuración Sms';
  121. llxHeader('',$langs->trans("Setup"),$wikihelp);
  122. print_fiche_titre($langs->trans("SmsSetup"),'','setup');
  123. print $langs->trans("SmsDesc")."<br>\n";
  124. print "<br>\n";
  125. dol_htmloutput_mesg($message);
  126. // List of sending methods
  127. $listofmethods=(is_array($conf->sms_engine_modules)?$conf->sms_engine_modules:array());
  128. asort($listofmethods);
  129. if ($action == 'edit')
  130. {
  131. $form=new Form($db);
  132. if (! count($listofmethods)) print '<div class="warning">'.$langs->trans("NoSmsEngine",'<a href="http://www.dolistore.com/search.php?orderby=position&orderway=desc&search_query=sms_manager">DoliStore</a>').'</div>';
  133. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  134. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  135. print '<input type="hidden" name="action" value="update">';
  136. clearstatcache();
  137. $var=true;
  138. print '<table class="noborder" width="100%">';
  139. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  140. // Disable
  141. $var=!$var;
  142. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>';
  143. print $form->selectyesno('MAIN_DISABLE_ALL_SMS',$conf->global->MAIN_DISABLE_ALL_SMS,1);
  144. print '</td></tr>';
  145. // Separator
  146. $var=!$var;
  147. print '<tr '.$bc[$var].'><td colspan="2">&nbsp;</td></tr>';
  148. // Method
  149. $var=!$var;
  150. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
  151. if (count($listofmethods)) print $form->selectarray('MAIN_SMS_SENDMODE',$listofmethods,$conf->global->MAIN_SMS_SENDMODE,1);
  152. else print '<font class="error">'.$langs->trans("None").'</font>';
  153. print '</td></tr>';
  154. // From
  155. $var=!$var;
  156. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMS_FROM",$langs->transnoentities("Undefined")).'</td>';
  157. print '<td><input class="flat" name="MAIN_MAIL_SMS_FROM" size="32" value="' . $conf->global->MAIN_MAIL_SMS_FROM;
  158. print '"></td></tr>';
  159. // Autocopy to
  160. /*$var=!$var;
  161. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  162. print '<td><input class="flat" name="MAIN_MAIL_AUTOCOPY_TO" size="32" value="' . $conf->global->MAIN_MAIL_AUTOCOPY_TO;
  163. print '"></td></tr>';
  164. */
  165. print '</table>';
  166. print '<br><center>';
  167. print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'"'.(!count($listofmethods)?' disabled="disbaled"':'').'>';
  168. print ' &nbsp; &nbsp; ';
  169. print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  170. print '</center>';
  171. print '</form>';
  172. print '<br>';
  173. }
  174. else
  175. {
  176. $var=true;
  177. if (! count($listofmethods)) print '<div class="warning">'.$langs->trans("NoSmsEngine",'<a href="http://www.dolistore.com/search.php?orderby=position&orderway=desc&search_query=sms_manager">DoliStore</a>').'</div>';
  178. print '<table class="noborder" width="100%">';
  179. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  180. // Disable
  181. $var=!$var;
  182. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_DISABLE_ALL_SMS").'</td><td>'.yn($conf->global->MAIN_DISABLE_ALL_SMS).'</td></tr>';
  183. // Separator
  184. $var=!$var;
  185. print '<tr '.$bc[$var].'><td colspan="2">&nbsp;</td></tr>';
  186. // Method
  187. $var=!$var;
  188. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_SMS_SENDMODE").'</td><td>';
  189. $text=$listofmethods[$conf->global->MAIN_SMS_SENDMODE];
  190. if (empty($text)) $text=$langs->trans("Undefined").' '.img_warning();
  191. print $text;
  192. print '</td></tr>';
  193. // From
  194. $var=!$var;
  195. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMS_FROM",$langs->transnoentities("Undefined")).'</td>';
  196. print '<td>'.$conf->global->MAIN_MAIL_SMS_FROM;
  197. if (!empty($conf->global->MAIN_MAIL_SMS_FROM) && ! isValidPhone($conf->global->MAIN_MAIL_SMS_FROM)) print ' '.img_warning($langs->trans("ErrorBadPhone"));
  198. print '</td></tr>';
  199. // Autocopy to
  200. /*$var=!$var;
  201. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  202. print '<td>'.$conf->global->MAIN_MAIL_AUTOCOPY_TO;
  203. if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO) && ! isValidEmail($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print img_warning($langs->trans("ErrorBadEMail"));
  204. print '</td></tr>';
  205. */
  206. print '</table>';
  207. // Boutons actions
  208. print '<div class="tabsAction">';
  209. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
  210. /*if ($conf->global->MAIN_SMS_SENDMODE != 'mail' || ! $linuxlike)
  211. {
  212. if (function_exists('fsockopen') && $port && $server)
  213. {
  214. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
  215. }
  216. }
  217. else
  218. {
  219. print '<a class="butActionRefused" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
  220. }*/
  221. if (count($listofmethods) && ! empty($conf->global->MAIN_SMS_SENDMODE))
  222. {
  223. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
  224. }
  225. else
  226. {
  227. print '<a class="butActionRefused" href="#">'.$langs->trans("DoTestSend").'</a>';
  228. }
  229. print '</div>';
  230. // Run the test to connect
  231. /*
  232. if ($_GET["action"] == 'testconnect')
  233. {
  234. print '<br>';
  235. print_titre($langs->trans("DoTestServerAvailability"));
  236. // If we use SSL/TLS
  237. if (! empty($conf->global->MAIN_MAIL_EMAIL_TLS) && function_exists('openssl_open')) $server='ssl://'.$server;
  238. include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  239. $mail = new CSMSFile('','','','');
  240. $result=$mail->check_server_port($server,$port);
  241. if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort",$server,$port).'</div>';
  242. else
  243. {
  244. print '<div class="error">'.$langs->trans("ServerNotAvailableOnIPOrPort",$server,$port);
  245. if ($mail->error) print ' - '.$mail->error;
  246. print '</div>';
  247. }
  248. print '<br>';
  249. }*/
  250. // Affichage formulaire de TEST simple
  251. if ($action == 'test')
  252. {
  253. print '<br>';
  254. print_titre($langs->trans("DoTestSend"));
  255. // Cree l'objet formulaire mail
  256. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formsms.class.php';
  257. $formsms = new FormSms($db);
  258. $formsms->fromtype='user';
  259. $formsms->fromid=$user->id;
  260. $formsms->fromsms = (isset($_POST['fromsms'])?$_POST['fromsms']:($conf->global->MAIN_MAIL_SMS_FROM?$conf->global->MAIN_MAIL_SMS_FROM:$user->user_mobile));
  261. $formsms->withfromreadonly=0;
  262. $formsms->withsubstit=0;
  263. $formsms->withfrom=1;
  264. $formsms->witherrorsto=1;
  265. $formsms->withto=(isset($_POST['sendto'])?$_POST['sendto']:$user->user_mobile?$user->user_mobile:1);
  266. $formsms->withfile=2;
  267. $formsms->withbody=(isset($_POST['message'])?(empty($_POST['message'])?1:$_POST['message']):$langs->trans("ThisIsATestMessage"));
  268. $formsms->withbodyreadonly=0;
  269. $formsms->withcancel=1;
  270. $formsms->withfckeditor=0;
  271. // Tableau des substitutions
  272. $formsms->substit=$substitutionarrayfortest;
  273. // Tableau des parametres complementaires du post
  274. $formsms->param["action"]="send";
  275. $formsms->param["models"]="body";
  276. $formsms->param["smsid"]=0;
  277. $formsms->param["returnurl"]=$_SERVER["PHP_SELF"];
  278. $formsms->show_form();
  279. print '<br>';
  280. }
  281. }
  282. llxFooter();
  283. $db->close();
  284. ?>