bulk email management

This commit is contained in:
Florian HENRY 2021-01-07 17:23:02 +01:00
parent 27b0b0e8d5
commit 5c53a963e2
7 changed files with 314 additions and 135 deletions

View File

@ -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 '<input size="32" type="text" name="MAILING_EMAIL_UNSUBSCRIBE_KEY" id="MAI
if (!empty($conf->use_javascript_ajax)) print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
print '</td></tr>';
// default blacklist from mailing
print '<tr class="oddeven">';
print '<td>' . $langs->trans("DefaultBlacklistMailingStatus") . '</td>';
print '<td>';
$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 '</td>';
print '</tr>';
if (!empty($conf->use_javascript_ajax) && $conf->global->MAIN_FEATURES_LEVEL >= 1) {
print '<tr class="oddeven"><td>';
print $langs->trans("MailAdvTargetRecipients").'</td><td>';

View File

@ -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 '<input type="text" name="email" id="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
print '</tr>';
//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".'<script type="text/javascript" language="javascript">'."\n";
print '$(document).ready(function () {
$("#email").keyup(function() {
if ($(this).val()!="") {
$(".noemail").addClass("fieldrequired");
} else {
$(".noemail").removeClass("fieldrequired");
}
});
})'."\n";
print '</script>'."\n";
}
if (!GETPOSTISSET("no_email") && !empty($object->email))
{
$result=$object->getNoEmail();
if ($result<0) {
setEventMessages($object->error, $object->errors, 'errors');
}
}
print '<tr>';
print '<td><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
print '<td>'.$form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'alpha') : $noemail), 1).'</td>';
print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
print '<td>'.$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)).'</td>';
print '</tr>';
}
print '</tr>';
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 '<tr><td><label for="skype">'.$form->editfieldkey('Jabber', 'jabberid', '', $object, 0).'</label></td>';
// print '<td colspan="3"><input type="text" name="jabberid" id="jabberid" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET("jabberid")?GETPOST("jabberid", 'alpha'):$object->jabberid).'"></td></tr>';
// }
// // Skype
// if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
// {
// print '<tr><td><label for="skype">'.$form->editfieldkey('Skype', 'skype', '', $object, 0).'</label></td>';
// print '<td colspan="3"><input type="text" name="skype" id="skype" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET("skype")?GETPOST("skype", 'alpha'):$object->skype).'"></td></tr>';
// }
// // Twitter
// if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
// {
// print '<tr><td><label for="twitter">'.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).'</label></td>';
// print '<td colspan="3"><input type="text" name="twitter" id="twitter" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET("twitter")?GETPOST("twitter", 'alpha'):$object->twitter).'"></td></tr>';
// }
// // Facebook
// if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
// {
// print '<tr><td><label for="facebook">'.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).'</label></td>';
// print '<td colspan="3"><input type="text" name="facebook" id="facebook" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET("facebook")?GETPOST("facebook", 'alpha'):$object->facebook).'"></td></tr>';
// }
// // LinkedIn
// if (! empty($conf->global->SOCIALNETWORKS_LINKEDIN))
// {
// print '<tr><td><label for="linkedin">'.$form->editfieldkey('LinkedIn', 'linkedin', '', $object, 0).'</label></td>';
// print '<td colspan="3"><input type="text" name="linkedin" id="linkedin" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET("linkedin")?GETPOST("linkedin", 'alpha'):$object->linkedin).'"></td></tr>';
// }
// }
// Visibility
print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
@ -1050,28 +1039,34 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print '</tr>';
// Unsubscribe
print '<tr>';
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".'<script type="text/javascript" language="javascript">'."\n";
print 'jQuery(document).ready(function () {
jQuery("#email").keyup(function() {
if ($(this).val()!="") {
$(".noemail").addClass("fieldrequired");
} else {
$(".noemail").removeClass("fieldrequired");
}
})
})'."\n";
print '</script>'."\n";
}
if (!GETPOSTISSET("no_email") && !empty($object->email))
{
$result=$object->getNoEmail();
if ($result<0) {
setEventMessages($object->error, $object->errors, 'errors');
}
}
print '<td><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
print '<td>'.$form->selectyesno('no_email', (GETPOSTISSET("no_email") ?GETPOST("no_email", 'alpha') : $noemail), 1).'</td>';
} else {
print '<td colspan="2"></td>';
print '<tr>';
print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
print '<td>'.$form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'int') : $object->no_email), 1, false, ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS==-1)).'</td>';
print '</tr>';
}
print '</tr>';
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 '<tr><td>'.$langs->trans("No_Email").'</td><td>'.yn($noemail).'</td></tr>';
print '<tr><td>'.$langs->trans("No_Email").'</td><td>'.yn($object->no_email).'</td></tr>';
}
print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td>';

View File

@ -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;
}
}

View File

@ -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();

View File

@ -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
RecordCreatedByEmailCollector=Record created by the Email Collector %s from email %s
DefaultBlacklistMailingStatus=Default contact status for refuse bulk emailing
DefaultStatusEmptyMandatory=Empty but mandatory

View File

@ -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 '</script>'."\n";
print '<div id="selectthirdpartytype">';
@ -1357,7 +1379,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
// Email / Web
print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', empty($conf->global->SOCIETE_EMAIL_MANDATORY) ? '' : $conf->global->SOCIETE_EMAIL_MANDATORY).'</td>';
print '<td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>'.img_picto('', 'object_email').' <input type="text" class="maxwidth200 widthcentpercentminusx" name="email" id="email" value="'.$object->email.'"></td></tr>';
print '<td'.(($conf->browser->layout == 'phone') || empty($conf->mailing->enabled) ? ' colspan="3"' : '').'>'.img_picto('', 'object_email').' <input type="text" class="maxwidth200 widthcentpercentminusx" name="email" id="email" value="'.$object->email.'"></td>';
if (!empty($conf->mailing->enabled) && !empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) {
if ($conf->browser->layout == 'phone') print '</tr><tr>';
print '<td class="individualline noemail">'.$form->editfieldkey($langs->trans('No_Email') .' ('.$langs->trans('Contact').')', 'contact_no_email', '', $object, 0).'</td>';
print '<td class="individualline" '.(($conf->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).'</td>';
}
print '</tr>';
print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
print '<td colspan="3">'.img_picto('', 'globe').' <input type="text" class="maxwidth500 widthcentpercentminusx" name="url" id="url" value="'.$object->url.'"></td></tr>';

View File

@ -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;
}