diff --git a/htdocs/admin/mailing.php b/htdocs/admin/mailing.php
index 1c96ce68780..32aa7accfcf 100644
--- a/htdocs/admin/mailing.php
+++ b/htdocs/admin/mailing.php
@@ -34,7 +34,7 @@ if (!$user->admin) accessforbidden();
$action = GETPOST('action', 'aZ09');
-
+$form = new Form($db);
/*
* Actions
@@ -49,6 +49,7 @@ if ($action == 'setvalue')
$checkread = GETPOST('value', 'alpha');
$checkread_key = GETPOST('MAILING_EMAIL_UNSUBSCRIBE_KEY', 'alpha');
$mailingdelay = GETPOST('MAILING_DELAY', 'int');
+ $contactbulkdefault = GETPOST('MAILING_CONTACT_DEFAULT_BULK_STATUS', 'int');
$res = dolibarr_set_const($db, "MAILING_EMAIL_FROM", $mailfrom, 'chaine', 0, '', $conf->entity);
if (!$res > 0) $error++;
@@ -56,11 +57,14 @@ if ($action == 'setvalue')
if (!$res > 0) $error++;
$res = dolibarr_set_const($db, "MAILING_DELAY", $mailingdelay, 'chaine', 0, '', $conf->entity);
if (!$res > 0) $error++;
+ $res = dolibarr_set_const($db, "MAILING_CONTACT_DEFAULT_BULK_STATUS", $contactbulkdefault, 'chaine', 0, '', $conf->entity);
+ if (!$res > 0) $error++;
// Create temporary encryption key if nedded
$res = dolibarr_set_const($db, "MAILING_EMAIL_UNSUBSCRIBE_KEY", $checkread_key, 'chaine', 0, '', $conf->entity);
if (!$res > 0) $error++;
+
if (!$error)
{
$db->commit();
@@ -70,7 +74,17 @@ if ($action == 'setvalue')
setEventMessages($langs->trans("Error"), null, 'errors');
}
}
-
+if ($action == 'setonsearchandlistgooncustomerorsuppliercard') {
+ $setonsearchandlistgooncustomerorsuppliercard = GETPOST('value', 'int');
+ $res = dolibarr_set_const($db, "SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD", $setonsearchandlistgooncustomerorsuppliercard, 'yesno', 0, '', $conf->entity);
+ if (!$res > 0) $error++;
+ if (!$error)
+ {
+ setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
+ } else {
+ setEventMessages($langs->trans("Error"), null, 'errors');
+ }
+}
/*
* View
@@ -136,6 +150,16 @@ print '';
+// default blacklist from mailing
+print '
';
+print '| ' . $langs->trans("DefaultBlacklistMailingStatus") . ' | ';
+print '';
+$blacklist_setting=array(0=>$langs->trans('No'),1=>$langs->trans('Yes'),-1=>$langs->trans('DefaultStatusEmptyMandatory'));
+print $form->selectarray("MAILING_CONTACT_DEFAULT_BULK_STATUS", $blacklist_setting, $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS);
+print ' | ';
+print '
';
+
+
if (!empty($conf->use_javascript_ajax) && $conf->global->MAIN_FEATURES_LEVEL >= 1) {
print '| ';
print $langs->trans("MailAdvTargetRecipients").' | ';
diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php
index 0726e2c33e2..6ce4493c947 100644
--- a/htdocs/contact/card.php
+++ b/htdocs/contact/card.php
@@ -200,7 +200,7 @@ if (empty($reshook))
}
}
}
- $object->email = (string) GETPOST("email", 'alpha');
+ $object->email = (string) GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
$object->no_email = GETPOST("no_email", "int");
$object->phone_pro = (string) GETPOST("phone_pro", 'alpha');
$object->phone_perso = (string) GETPOST("phone_perso", 'alpha');
@@ -225,44 +225,59 @@ if (empty($reshook))
$action = 'create';
}
- if (!GETPOST("lastname")) {
+ if (!empty($conf->mailing->enabled) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS==-1 && $object->no_email==-1 && !empty($object->email)) {
+ $error++;
+ $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email"));
+ $action = 'create';
+ }
+
+ if (!empty($object->email) && !isValidEMail($object->email))
+ {
+ $langs->load("errors");
+ $error++;
+ $errors[] = $langs->trans("ErrorBadEMail", GETPOST('email', 'alpha'));
+ $action = 'create';
+ }
+
+ if (empty($object->lastname)) {
$error++;
$errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"));
$action = 'create';
}
- if (!$error)
- {
+ if (empty($error)) {
$id = $object->create($user);
- if ($id <= 0)
- {
+ if ($id <= 0) {
$error++;
$errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
$action = 'create';
- } else {
- // Categories association
- $contcats = GETPOST('contcats', 'array');
- $object->setCategories($contcats);
+ }
+ }
- // Add mass emailing flag into table mailing_unsubscribe
- if (GETPOST('no_email', 'int') && $object->email)
- {
- $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing', 0).") AND email = '".$db->escape($object->email)."'";
- $resql = $db->query($sql);
- if ($resql)
- {
- $obj = $db->fetch_object($resql);
- if (empty($obj->nb))
- {
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe(email, entity, date_creat) VALUES ('".$db->escape($object->email)."', ".$db->escape(getEntity('mailing', 0)).", '".$db->idate(dol_now())."')";
- $resql = $db->query($sql);
- }
- }
+ if (empty($error)) {
+ // Categories association
+ $contcats = GETPOST('contcats', 'array');
+ if (count($contcats)>0) {
+ $result = $object->setCategories($contcats);
+ if ($result <= 0) {
+ $error++;
+ $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
+ $action = 'create';
}
}
}
- if (!$error && $id > 0)
+ if (empty($error) && !empty($conf->mailing->enabled) && !empty($object->email)) {
+ // Add mass emailing flag into table mailing_unsubscribe
+ $result=$object->setNoEmail($object->no_email);
+ if ($result<0) {
+ $error++;
+ $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
+ $action = 'create';
+ }
+ }
+
+ if (empty($error) && $id > 0)
{
$db->commit();
if (!empty($backtopage)) $url = $backtopage;
@@ -298,12 +313,26 @@ if (empty($reshook))
if ($action == 'update' && !$_POST["cancel"] && $user->rights->societe->contact->creer)
{
- if (empty($_POST["lastname"]))
+ if (empty(GETPOST("lastname", 'alpha')))
{
$error++; $errors = array($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
$action = 'edit';
}
+ if (!empty($conf->mailing->enabled) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS==-1 && GETPOST("no_email", "int")==-1 && !empty(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL))) {
+ $error++;
+ $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email"));
+ $action = 'edit';
+ }
+
+ if (!empty(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)) && !isValidEMail(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)))
+ {
+ $langs->load("errors");
+ $error++;
+ $errors[] = $langs->trans("ErrorBadEMail", GETPOST('email', 'alpha'));
+ $action = 'edit';
+ }
+
if (!$error)
{
$contactid = GETPOST("contactid", 'int');
@@ -374,7 +403,7 @@ if (empty($reshook))
$object->state_id = GETPOST("state_id", 'int');
$object->country_id = GETPOST("country_id", 'int');
- $object->email = (string) GETPOST("email", 'alpha');
+ $object->email = (string) GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
$object->no_email = GETPOST("no_email", "int");
//$object->jabberid = GETPOST("jabberid", 'alpha');
//$object->skype = GETPOST("skype", 'alpha');
@@ -411,31 +440,15 @@ if (empty($reshook))
$categories = GETPOST('contcats', 'array');
$object->setCategories($categories);
- $no_email = GETPOST('no_email', 'int');
-
// Update mass emailing flag into table mailing_unsubscribe
if (GETPOSTISSET('no_email') && $object->email)
{
- if ($no_email)
- {
- $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing', 0).") AND email = '".$db->escape($object->email)."'";
- $resql = $db->query($sql);
- if ($resql)
- {
- $obj = $db->fetch_object($resql);
- $noemail = $obj->nb;
- if (empty($noemail))
- {
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe(email, entity, date_creat) VALUES ('".$db->escape($object->email)."', ".$db->escape(getEntity('mailing', 0)).", '".$db->idate(dol_now())."')";
- $resql = $db->query($sql);
- }
- }
- } else {
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = '".$db->escape($object->email)."' AND entity = ".$db->escape(getEntity('mailing', 0));
- $resql = $db->query($sql);
+ $no_email = GETPOST('no_email', 'int');
+ $result=$object->setNoEmail($no_email);
+ if ($result<0) {
+ setEventMessages($object->error, $object->errors, 'errors');
+ $action = 'edit';
}
-
- $object->no_email = $no_email;
}
$object->old_lastname = '';
@@ -738,27 +751,36 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print ' | ';
print '
';
+ //Unsubscribe
if (!empty($conf->mailing->enabled))
{
- $noemail = '';
- if (empty($noemail) && !empty($object->email))
+ if ($conf->use_javascript_ajax && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS==-1)
{
- $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing').") AND email = '".$db->escape($object->email)."'";
- //print $sql;
- $resql = $db->query($sql);
- if ($resql)
- {
- $obj = $db->fetch_object($resql);
- $noemail = $obj->nb;
+ print "\n".''."\n";
+ }
+ if (!GETPOSTISSET("no_email") && !empty($object->email))
+ {
+ $result=$object->getNoEmail();
+ if ($result<0) {
+ setEventMessages($object->error, $object->errors, 'errors');
}
}
-
print '';
- print ' | ';
- print ''.$form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'alpha') : $noemail), 1).' | ';
+ print ' | ';
+ print ''.$form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'int') : $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS), 1, false, ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS==-1)).' | ';
print '
';
}
- print '';
+
if (!empty($conf->socialnetworks->enabled)) {
foreach ($socialnetworks as $key => $value) {
@@ -774,39 +796,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
}
}
}
- // if (! empty($conf->socialnetworks->enabled))
- // {
- // // Jabber
- // if (! empty($conf->global->SOCIALNETWORKS_JABBER))
- // {
- // print ' | ';
- // print 'jabberid).'"> |
';
- // }
- // // Skype
- // if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
- // {
- // print ' | ';
- // print 'skype).'"> |
';
- // }
- // // Twitter
- // if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
- // {
- // print ' | ';
- // print 'twitter).'"> |
';
- // }
- // // Facebook
- // if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
- // {
- // print ' | ';
- // print 'facebook).'"> |
';
- // }
- // // LinkedIn
- // if (! empty($conf->global->SOCIALNETWORKS_LINKEDIN))
- // {
- // print ' | ';
- // print 'linkedin).'"> |
';
- // }
- // }
// Visibility
print ' | ';
@@ -1050,28 +1039,34 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print ' |
';
// Unsubscribe
- print '';
if (!empty($conf->mailing->enabled))
{
- $noemail = '';
- if (empty($noemail) && !empty($object->email))
+ if ($conf->use_javascript_ajax && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS==-1)
{
- $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing').") AND email = '".$db->escape($object->email)."'";
- //print $sql;
- $resql = $db->query($sql);
- if ($resql)
- {
- $obj = $db->fetch_object($resql);
- $noemail = $obj->nb;
+ print "\n".''."\n";
+ }
+ if (!GETPOSTISSET("no_email") && !empty($object->email))
+ {
+ $result=$object->getNoEmail();
+ if ($result<0) {
+ setEventMessages($object->error, $object->errors, 'errors');
}
}
-
- print ' | ';
- print ''.$form->selectyesno('no_email', (GETPOSTISSET("no_email") ?GETPOST("no_email", 'alpha') : $noemail), 1).' | ';
- } else {
- print ' | ';
+ print '
';
+ print ' | ';
+ print ''.$form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'int') : $object->no_email), 1, false, ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS==-1)).' | ';
+ print '
';
}
- print '';
if (!empty($conf->socialnetworks->enabled)) {
foreach ($socialnetworks as $key => $value) {
@@ -1300,20 +1295,11 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
// Unsubscribe opt-out
if (!empty($conf->mailing->enabled))
{
- //print 'eee'.$object->email;
- $noemail = $object->no_email;
- if (empty($noemail) && !empty($object->email))
- {
- $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing').") AND email = '".$db->escape($object->email)."'";
- //print $sql;
- $resql = $db->query($sql);
- if ($resql)
- {
- $obj = $db->fetch_object($resql);
- $noemail = $obj->nb;
- }
+ $result=$object->getNoEmail();
+ if ($result<0) {
+ setEventMessages($object->error, $object->errors, 'errors');
}
- print '| '.$langs->trans("No_Email").' | '.yn($noemail).' |
';
+ print '| '.$langs->trans("No_Email").' | '.yn($object->no_email).' |
';
}
print '| '.$langs->trans("ContactVisibility").' | ';
diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php
index 367a2e7cd62..7427e16e5db 100644
--- a/htdocs/contact/class/contact.class.php
+++ b/htdocs/contact/class/contact.class.php
@@ -1180,6 +1180,20 @@ class Contact extends CommonObject
}
}
+ if (!$error)
+ {
+ // Remove Roles
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople = ".$this->id;
+ dol_syslog(__METHOD__, LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (!$resql)
+ {
+ $error++;
+ $this->error .= $this->db->lasterror();
+ $errorflag = -1;
+ }
+ }
+
if (!$error)
{
// Remove category
@@ -1910,4 +1924,94 @@ class Contact extends CommonObject
return "Error, mode/status not found";
}
+
+
+ /**
+ * Set "blacklist" mailing status
+ *
+ * @param int $no_email 1=Do not send mailing, 0=Ok to recieve mailling
+ * @return int <0 if KO, >0 if OK
+ */
+ public function setNoEmail($no_email)
+ {
+ $error = 0;
+
+ // Update mass emailing flag into table mailing_unsubscribe
+ if ($this->email)
+ {
+ $this->db->begin();
+
+ if ($no_email)
+ {
+ $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing', 0).") AND email = '".$this->db->escape($this->email)."'";
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $obj = $this->db->fetch_object($resql);
+ $noemail = $obj->nb;
+ if (empty($noemail))
+ {
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe(email, entity, date_creat) VALUES ('".$this->db->escape($this->email)."', ".$this->db->escape(getEntity('mailing', 0)).", '".$this->db->idate(dol_now())."')";
+ $resql = $this->db->query($sql);
+ if (!$resql)
+ {
+ $error++;
+ $this->error = $this->db->lasterror();
+ $this->errors[] = $this->error;
+ }
+ }
+ } else {
+ $error++;
+ $this->error = $this->db->lasterror();
+ $this->errors[] = $this->error;
+ }
+ } else {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = '".$this->db->escape($this->email)."' AND entity = ".$this->db->escape(getEntity('mailing', 0));
+ $resql = $this->db->query($sql);
+ if (!$resql)
+ {
+ $error++;
+ $this->error = $this->db->lasterror();
+ $this->errors[] = $this->error;
+ }
+ }
+
+ if (empty($error)) {
+ $this->no_email = $no_email;
+ $this->db->commit();
+ return 1;
+ } else {
+ $this->db->rollback();
+ return $error * -1;
+ }
+ }
+
+ return 0;
+ }
+
+ /**
+ * get "blacklist" mailing status
+ * set no_email attribut to 1 or 0
+ *
+ * @return int <0 if KO, >0 if OK
+ */
+ public function getNoEmail()
+ {
+ if ($this->email)
+ {
+ $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing').") AND email = '".$this->db->escape($this->email)."'";
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $obj = $this->db->fetch_object($resql);
+ $this->no_email = $obj->nb;
+ return 1;
+ } else {
+ $this->error = $this->db->lasterror();
+ $this->errors[] = $this->error;
+ return -1;
+ }
+ }
+ return 0;
+ }
}
diff --git a/htdocs/core/modules/modMailing.class.php b/htdocs/core/modules/modMailing.class.php
index 22cc75689a5..75d423e3ecd 100644
--- a/htdocs/core/modules/modMailing.class.php
+++ b/htdocs/core/modules/modMailing.class.php
@@ -74,6 +74,14 @@ class modMailing extends DolibarrModules
// Constants
$this->const = array();
+ $r = 0;
+
+ $this->const[$r][0] = "MAILING_CONTACT_DEFAULT_BULK_STATUS";
+ $this->const[$r][1] = "chaine";
+ $this->const[$r][2] = "0";
+ $this->const[$r][3] = 'Default black list mailing';
+ $this->const[$r][4] = 0;
+ $r++;
// Boxes
$this->boxes = array();
diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang
index a7cfde68ae7..4345dd15d86 100644
--- a/htdocs/langs/en_US/mails.lang
+++ b/htdocs/langs/en_US/mails.lang
@@ -174,4 +174,6 @@ Unanswered=Unanswered
Answered=Answered
IsNotAnAnswer=Is not answer (initial email)
IsAnAnswer=Is an answer of an initial email
-RecordCreatedByEmailCollector=Record created by the Email Collector %s from email %s
\ No newline at end of file
+RecordCreatedByEmailCollector=Record created by the Email Collector %s from email %s
+DefaultBlacklistMailingStatus=Default contact status for refuse bulk emailing
+DefaultStatusEmptyMandatory=Empty but mandatory
diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php
index c24689675ea..b1951affe7f 100644
--- a/htdocs/societe/card.php
+++ b/htdocs/societe/card.php
@@ -394,6 +394,11 @@ if (empty($reshook))
$error++;
}
+ if (!empty($conf->mailing->enabled) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS==-1 && GETPOST('contact_no_email', 'int')==-1 && !empty(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL))) {
+ $error++;
+ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email")), null, 'errors');
+ }
+
if (!$error)
{
if ($action == 'update')
@@ -563,7 +568,8 @@ if (empty($reshook))
{
dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
$contcats = GETPOST('contcats', 'array');
- $result = $object->create_individual($user, $contcats);
+ $no_email = GETPOST('contact_no_email', 'int');
+ $result = $object->create_individual($user, $no_email, $contcats);
if ($result < 0)
{
setEventMessages($object->error, $object->errors, 'errors');
@@ -1147,8 +1153,24 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$("#selectcountry_id").change(function() {
document.formsoc.action.value="create";
document.formsoc.submit();
- });
- });';
+ });';
+ if ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS==-1) {
+
+ print '
+ function init_check_no_email(input) {
+ if (input.val()!="") {
+ $(".noemail").addClass("fieldrequired");
+ } else {
+ $(".noemail").removeClass("fieldrequired");
+ }
+ }
+ $("#email").keyup(function() {
+ init_check_no_email($(this));
+ });
+ init_check_no_email($("#email"));
+ });';
+ }
+ print '});';
print ''."\n";
print ' ';
@@ -1357,7 +1379,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
// Email / Web
print ' |
| '.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', empty($conf->global->SOCIETE_EMAIL_MANDATORY) ? '' : $conf->global->SOCIETE_EMAIL_MANDATORY).' | ';
- print 'browser->layout == 'phone' ? ' colspan="3"' : '').'>'.img_picto('', 'object_email').' |
';
+ print 'browser->layout == 'phone') || empty($conf->mailing->enabled) ? ' colspan="3"' : '').'>'.img_picto('', 'object_email').' | ';
+ if (!empty($conf->mailing->enabled) && !empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) {
+ if ($conf->browser->layout == 'phone') print '';
+ print '| '.$form->editfieldkey($langs->trans('No_Email') .' ('.$langs->trans('Contact').')', 'contact_no_email', '', $object, 0).' | ';
+ print 'browser->layout == 'phone') || empty($conf->mailing->enabled) ? ' colspan="3"' : '').'>'.$form->selectyesno('contact_no_email', (GETPOSTISSET("contact_no_email") ?GETPOST("contact_no_email", 'alpha') : $object->no_email), 1, false, 1).' | ';
+ }
+ print '
';
print '| '.$form->editfieldkey('Web', 'url', '', $object, 0).' | ';
print ''.img_picto('', 'globe').' |
';
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index a809fe7d10d..91cc0cb1e13 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -900,11 +900,18 @@ class Societe extends CommonObject
* Create a contact/address from thirdparty
*
* @param User $user Object user
+ * @param int $no_email 1=Do not send mailing, 0=Ok to recieve mailling
* @param array $tags Array of tag to affect to contact
* @return int <0 if KO, >0 if OK
*/
- public function create_individual(User $user, $tags=array())
+ public function create_individual(User $user, $no_email, $tags = array())
{
+ global $conf;
+
+ $error = 0;
+
+ $this->db->begin();
+
// phpcs:enable
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
$contact = new Contact($this->db);
@@ -926,20 +933,40 @@ class Societe extends CommonObject
$contactId = $contact->create($user);
if ($contactId < 0) {
+ $error++;
$this->error = $contact->error;
$this->errors = $contact->errors;
dol_syslog(get_class($this)."::create_individual ERROR:".$this->error, LOG_ERR);
- } elseif (is_array($tags) && !empty($tags)) {
+ }
+
+ if (empty($error) && is_array($tags) && !empty($tags)) {
$result = $contact->setCategories($tags);
- if ($result < 0)
- {
+ if ($result < 0) {
+ $error++;
$this->error = $contact->error;
$this->errors = array_merge($this->errors, $contact->errors);
- dol_syslog(get_class($this)."::create_individual Affect Tag ERROR:".$this->error, LOG_ERR);
+ dol_syslog(get_class($this) . "::create_individual Affect Tag ERROR:" . $this->error, LOG_ERR);
$contactId = $result;
}
}
+ if (empty($error) && !empty($conf->mailing->enabled) && !empty($contact->email) && isset($no_email)) {
+ $result = $contact->setNoEmail($no_email);
+ if ($result < 0) {
+ $this->error = $contact->error;
+ $this->errors = array_merge($this->errors, $contact->errors);
+ dol_syslog(get_class($this) . "::create_individual set mailing status ERROR:" . $this->error, LOG_ERR);
+ $contactId = $result;
+ }
+ }
+
+ if (!empty($error)) {
+ dol_syslog(get_class($this)."::create_individual success");
+ $this->db->commit();
+ } else {
+ $this->db->rollback();
+ }
+
return $contactId;
}