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 35c4bdc43e5..887e97e76e9 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 8fe4943d267..0283a01074d 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
@@ -1880,4 +1894,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 7fd93be7b71..2d02c5ddcf9 100644
--- a/htdocs/langs/en_US/mails.lang
+++ b/htdocs/langs/en_US/mails.lang
@@ -175,3 +175,5 @@ 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
+DefaultBlacklistMailingStatus=Default contact status for refuse bulk emailing
+DefaultStatusEmptyMandatory=Empty but mandatory
diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang
index 01b1a23609b..cf7a828164b 100644
--- a/htdocs/langs/en_US/main.lang
+++ b/htdocs/langs/en_US/main.lang
@@ -1113,6 +1113,7 @@ OutOfDate=Out-of-date
EventReminder=Event Reminder
UpdateForAllLines=Update for all lines
OnHold=On hold
+Civility=Civility
AffectTag=Affect Tag
ConfirmAffectTag=Bulk Tag Affect
ConfirmAffectTagQuestion=Are you sure you want to affect tags to the %s selected record(s)?
diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php
index 99b8fe1bf8f..77f0e25c945 100644
--- a/htdocs/societe/card.php
+++ b/htdocs/societe/card.php
@@ -397,6 +397,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')
@@ -568,7 +573,9 @@ if (empty($reshook))
if ($object->particulier)
{
dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
- $result = $object->create_individual($user);
+ $contcats = GETPOST('contcats', 'array');
+ $no_email = GETPOST('contact_no_email', 'int');
+ $result = $object->create_individual($user, $no_email, $contcats);
if ($result < 0)
{
setEventMessages($object->error, $object->errors, 'errors');
@@ -1156,8 +1163,23 @@ 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 ' ';
@@ -1366,7 +1388,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 ''.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').' |
';
@@ -1522,6 +1550,14 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print "";
//}
+ if (!empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION))
+ {
+ print '| '.$form->editfieldkey('ContactCategoriesShort', 'contcats', '', $object, 0).' | ';
+ $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, null, 'parent', null, null, 1);
+ print img_picto('', 'category').$form->multiselectarray('contcats', $cate_arbo, GETPOST('contcats', 'array'), null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
+ print " |
";
+ }
+
// Supplier
if (!empty($conf->fournisseur->enabled)) {
print '| '.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).' | ';
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index ca6aa9faebd..14e2cbe3277 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -931,10 +931,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)
+ 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);
@@ -954,14 +962,43 @@ class Societe extends CommonObject
$contact->town = $this->town;
$contact->phone_pro = $this->phone;
- $result = $contact->create($user);
- if ($result < 0) {
+ $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);
}
- return $result;
+ if (empty($error) && is_array($tags) && !empty($tags)) {
+ $result = $contact->setCategories($tags);
+ 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);
+ $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;
}
/**
|