Переглянути джерело

Add default prefix for sending sms to fix international number problem with ovh

Mathieu Moulin 2 роки тому
батько
коміт
e29f12a939

+ 15 - 0
htdocs/admin/sms.php

@@ -56,6 +56,8 @@ if ($action == 'update' && !$cancel) {
 
 	dolibarr_set_const($db, "MAIN_MAIL_SMS_FROM", GETPOST("MAIN_MAIL_SMS_FROM", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
 
+	dolibarr_set_const($db, "MAIN_MAIL_SMS_INTL_PREFIX_DEFAULT", GETPOST("MAIN_MAIL_SMS_INTL_PREFIX_DEFAULT", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
+
 	header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
 	exit;
 }
@@ -192,6 +194,11 @@ if ($action == 'edit') {
 	print '<td><input class="flat" name="MAIN_MAIL_SMS_FROM" size="32" value="'.getDolGlobalString('MAIN_MAIL_SMS_FROM');
 	print '"></td></tr>';
 
+	// Default prefix
+	print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMS_INTL_PREFIX_DEFAULT", $langs->transnoentities("Undefined")).'</td>';
+	print '<td><input class="flat" name="MAIN_MAIL_SMS_INTL_PREFIX_DEFAULT" size="5" value="'.getDolGlobalString('MAIN_MAIL_SMS_INTL_PREFIX_DEFAULT');
+	print '"></td></tr>';
+
 	// Autocopy to
 	/*
 	print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
@@ -235,6 +242,14 @@ if ($action == 'edit') {
 	}
 	print '</td></tr>';
 
+	// Default prefix
+	print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMS_INTL_PREFIX_DEFAULT", $langs->transnoentities("Undefined")).'</td>';
+	print '<td>'.getDolGlobalString('MAIN_MAIL_SMS_INTL_PREFIX_DEFAULT');
+	if (!empty($conf->global->MAIN_MAIL_SMS_INTL_PREFIX_DEFAULT) && !isValidPhone($conf->global->MAIN_MAIL_SMS_INTL_PREFIX_DEFAULT)) {
+		print ' '.img_warning($langs->trans("ErrorBadPhone"));
+	}
+	print '</td></tr>';
+
 	// Autocopy to
 	/*
 	print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';

+ 17 - 0
htdocs/core/class/CSMSFile.class.php

@@ -83,6 +83,9 @@ class CSMSFile
 			return -1;
 		}
 
+		if (!empty($conf->global->MAIN_MAIL_SMS_INTL_PREFIX_DEFAULT))
+			$to = $this->tel_international($to, $conf->global->MAIN_MAIL_SMS_INTL_PREFIX_DEFAULT);
+
 		dol_syslog("CSMSFile::CSMSFile: MAIN_SMS_SENDMODE=".$conf->global->MAIN_SMS_SENDMODE." charset=".$conf->file->character_set_client." from=".$from.", to=".$to.", msg length=".strlen($msg), LOG_DEBUG);
 		dol_syslog("CSMSFile::CSMSFile: deferred=".$deferred." priority=".$priority." class=".$class, LOG_DEBUG);
 
@@ -258,4 +261,18 @@ class CSMSFile
 			}
 		}
 	}
+
+	// Added by MMI Mathieu Moulin iProspective
+	function tel_international($value, $prefix='') {
+		if (empty($prefix)) {
+			global $conf;
+			$prefix = $conf->global->MAIN_MAIL_SMS_INTL_PREFIX_DEFAULT;
+		}
+		$value = str_replace([' ', '.', '-'], ['', '', ''], $value);
+		if (substr($value, 0, 2)=='00')
+			$value = '+'.substr($value, 2);
+		if (substr($value, 0, 1)=='0')
+			$value = $prefix.substr($value, 1);
+		return $value;
+	}
 }

+ 0 - 10
htdocs/core/lib/company.lib.php

@@ -2121,13 +2121,3 @@ function addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
 		return $sql2;
 	}
 }
-
-// Added by MMI Mathieu Moulin iProspective
-function tel_international($value) {
-	$value = str_replace([' ', '.', '-'], ['', '', ''], $value);
-	if (substr($value, 0, 2)=='00')
-		$value = '+'.substr($value, 2);
-	if (substr($value, 0, 1)=='0')
-		$value = '+33'.substr($value, 1);
-	return $value;
-}

+ 1 - 0
htdocs/langs/fr_FR/admin.lang

@@ -310,6 +310,7 @@ MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY=Clé privée pour générer la signature DKIM
 MAIN_DISABLE_ALL_SMS=Désactiver globalement tout envoi de Sms (pour mode test ou démos)
 MAIN_SMS_SENDMODE=Méthode d'envoi des SMS
 MAIN_MAIL_SMS_FROM=Numéro de téléphone par défaut pour envoi Sms
+MAIN_MAIL_SMS_INTL_PREFIX_DEFAULT=Préfix par défaut pour envoi Sms
 MAIN_MAIL_DEFAULT_FROMTYPE=Expéditeur par défaut des e-mails pour les envois manuels (e-mail utilisateur ou de la société)
 UserEmail=Email utilisateur
 CompanyEmail=Email organization