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