Merge pull request #15925 from FHenry/dev_add_tag_contact_thirdpartycontactcreateion
NEW : Add contact tag and bulk email status on thirparty+contact create form
This commit is contained in:
commit
cae9dc3acf
@ -34,7 +34,7 @@ if (!$user->admin) accessforbidden();
|
|||||||
|
|
||||||
$action = GETPOST('action', 'aZ09');
|
$action = GETPOST('action', 'aZ09');
|
||||||
|
|
||||||
|
$form = new Form($db);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Actions
|
* Actions
|
||||||
@ -49,6 +49,7 @@ if ($action == 'setvalue')
|
|||||||
$checkread = GETPOST('value', 'alpha');
|
$checkread = GETPOST('value', 'alpha');
|
||||||
$checkread_key = GETPOST('MAILING_EMAIL_UNSUBSCRIBE_KEY', 'alpha');
|
$checkread_key = GETPOST('MAILING_EMAIL_UNSUBSCRIBE_KEY', 'alpha');
|
||||||
$mailingdelay = GETPOST('MAILING_DELAY', 'int');
|
$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);
|
$res = dolibarr_set_const($db, "MAILING_EMAIL_FROM", $mailfrom, 'chaine', 0, '', $conf->entity);
|
||||||
if (!$res > 0) $error++;
|
if (!$res > 0) $error++;
|
||||||
@ -56,11 +57,14 @@ if ($action == 'setvalue')
|
|||||||
if (!$res > 0) $error++;
|
if (!$res > 0) $error++;
|
||||||
$res = dolibarr_set_const($db, "MAILING_DELAY", $mailingdelay, 'chaine', 0, '', $conf->entity);
|
$res = dolibarr_set_const($db, "MAILING_DELAY", $mailingdelay, 'chaine', 0, '', $conf->entity);
|
||||||
if (!$res > 0) $error++;
|
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
|
// Create temporary encryption key if nedded
|
||||||
$res = dolibarr_set_const($db, "MAILING_EMAIL_UNSUBSCRIBE_KEY", $checkread_key, 'chaine', 0, '', $conf->entity);
|
$res = dolibarr_set_const($db, "MAILING_EMAIL_UNSUBSCRIBE_KEY", $checkread_key, 'chaine', 0, '', $conf->entity);
|
||||||
if (!$res > 0) $error++;
|
if (!$res > 0) $error++;
|
||||||
|
|
||||||
|
|
||||||
if (!$error)
|
if (!$error)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$db->commit();
|
||||||
@ -70,7 +74,17 @@ if ($action == 'setvalue')
|
|||||||
setEventMessages($langs->trans("Error"), null, 'errors');
|
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
|
* 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 ' '.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
|
if (!empty($conf->use_javascript_ajax)) print ' '.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
|
||||||
print '</td></tr>';
|
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) {
|
if (!empty($conf->use_javascript_ajax) && $conf->global->MAIN_FEATURES_LEVEL >= 1) {
|
||||||
print '<tr class="oddeven"><td>';
|
print '<tr class="oddeven"><td>';
|
||||||
print $langs->trans("MailAdvTargetRecipients").'</td><td>';
|
print $langs->trans("MailAdvTargetRecipients").'</td><td>';
|
||||||
|
|||||||
@ -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->no_email = GETPOST("no_email", "int");
|
||||||
$object->phone_pro = (string) GETPOST("phone_pro", 'alpha');
|
$object->phone_pro = (string) GETPOST("phone_pro", 'alpha');
|
||||||
$object->phone_perso = (string) GETPOST("phone_perso", 'alpha');
|
$object->phone_perso = (string) GETPOST("phone_perso", 'alpha');
|
||||||
@ -225,44 +225,59 @@ if (empty($reshook))
|
|||||||
$action = 'create';
|
$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++;
|
$error++;
|
||||||
$errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"));
|
$errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"));
|
||||||
$action = 'create';
|
$action = 'create';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error)
|
if (empty($error)) {
|
||||||
{
|
|
||||||
$id = $object->create($user);
|
$id = $object->create($user);
|
||||||
if ($id <= 0)
|
if ($id <= 0) {
|
||||||
{
|
|
||||||
$error++;
|
$error++;
|
||||||
$errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
|
$errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
|
||||||
$action = 'create';
|
$action = 'create';
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($error)) {
|
||||||
// Categories association
|
// Categories association
|
||||||
$contcats = GETPOST('contcats', 'array');
|
$contcats = GETPOST('contcats', 'array');
|
||||||
$object->setCategories($contcats);
|
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 (empty($error) && !empty($conf->mailing->enabled) && !empty($object->email)) {
|
||||||
// Add mass emailing flag into table mailing_unsubscribe
|
// Add mass emailing flag into table mailing_unsubscribe
|
||||||
if (GETPOST('no_email', 'int') && $object->email)
|
$result=$object->setNoEmail($object->no_email);
|
||||||
{
|
if ($result<0) {
|
||||||
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing', 0).") AND email = '".$db->escape($object->email)."'";
|
$error++;
|
||||||
$resql = $db->query($sql);
|
$errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
|
||||||
if ($resql)
|
$action = 'create';
|
||||||
{
|
|
||||||
$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 (!$error && $id > 0)
|
if (empty($error) && $id > 0)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$db->commit();
|
||||||
if (!empty($backtopage)) $url = $backtopage;
|
if (!empty($backtopage)) $url = $backtopage;
|
||||||
@ -298,12 +313,26 @@ if (empty($reshook))
|
|||||||
|
|
||||||
if ($action == 'update' && !$_POST["cancel"] && $user->rights->societe->contact->creer)
|
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")));
|
$error++; $errors = array($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
|
||||||
$action = 'edit';
|
$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)
|
if (!$error)
|
||||||
{
|
{
|
||||||
$contactid = GETPOST("contactid", 'int');
|
$contactid = GETPOST("contactid", 'int');
|
||||||
@ -374,7 +403,7 @@ if (empty($reshook))
|
|||||||
$object->state_id = GETPOST("state_id", 'int');
|
$object->state_id = GETPOST("state_id", 'int');
|
||||||
$object->country_id = GETPOST("country_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->no_email = GETPOST("no_email", "int");
|
||||||
//$object->jabberid = GETPOST("jabberid", 'alpha');
|
//$object->jabberid = GETPOST("jabberid", 'alpha');
|
||||||
//$object->skype = GETPOST("skype", 'alpha');
|
//$object->skype = GETPOST("skype", 'alpha');
|
||||||
@ -411,32 +440,16 @@ if (empty($reshook))
|
|||||||
$categories = GETPOST('contcats', 'array');
|
$categories = GETPOST('contcats', 'array');
|
||||||
$object->setCategories($categories);
|
$object->setCategories($categories);
|
||||||
|
|
||||||
$no_email = GETPOST('no_email', 'int');
|
|
||||||
|
|
||||||
// Update mass emailing flag into table mailing_unsubscribe
|
// Update mass emailing flag into table mailing_unsubscribe
|
||||||
if (GETPOSTISSET('no_email') && $object->email)
|
if (GETPOSTISSET('no_email') && $object->email)
|
||||||
{
|
{
|
||||||
if ($no_email)
|
$no_email = GETPOST('no_email', 'int');
|
||||||
{
|
$result=$object->setNoEmail($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)."'";
|
if ($result<0) {
|
||||||
$resql = $db->query($sql);
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
if ($resql)
|
$action = 'edit';
|
||||||
{
|
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
$object->no_email = $no_email;
|
|
||||||
}
|
|
||||||
|
|
||||||
$object->old_lastname = '';
|
$object->old_lastname = '';
|
||||||
$object->old_firstname = '';
|
$object->old_firstname = '';
|
||||||
@ -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 '<input type="text" name="email" id="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
|
//Unsubscribe
|
||||||
if (!empty($conf->mailing->enabled))
|
if (!empty($conf->mailing->enabled))
|
||||||
{
|
{
|
||||||
$noemail = '';
|
if ($conf->use_javascript_ajax && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS==-1)
|
||||||
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 "\n".'<script type="text/javascript" language="javascript">'."\n";
|
||||||
//print $sql;
|
print '$(document).ready(function () {
|
||||||
$resql = $db->query($sql);
|
$("#email").keyup(function() {
|
||||||
if ($resql)
|
if ($(this).val()!="") {
|
||||||
{
|
$(".noemail").addClass("fieldrequired");
|
||||||
$obj = $db->fetch_object($resql);
|
} else {
|
||||||
$noemail = $obj->nb;
|
$(".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 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>';
|
|
||||||
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 '</tr>';
|
|
||||||
}
|
|
||||||
print '</tr>';
|
|
||||||
|
|
||||||
if (!empty($conf->socialnetworks->enabled)) {
|
if (!empty($conf->socialnetworks->enabled)) {
|
||||||
foreach ($socialnetworks as $key => $value) {
|
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
|
// Visibility
|
||||||
print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
|
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>';
|
print '</tr>';
|
||||||
|
|
||||||
// Unsubscribe
|
// Unsubscribe
|
||||||
print '<tr>';
|
|
||||||
if (!empty($conf->mailing->enabled))
|
if (!empty($conf->mailing->enabled))
|
||||||
{
|
{
|
||||||
$noemail = '';
|
if ($conf->use_javascript_ajax && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS==-1)
|
||||||
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 "\n".'<script type="text/javascript" language="javascript">'."\n";
|
||||||
//print $sql;
|
print 'jQuery(document).ready(function () {
|
||||||
$resql = $db->query($sql);
|
jQuery("#email").keyup(function() {
|
||||||
if ($resql)
|
if ($(this).val()!="") {
|
||||||
{
|
$(".noemail").addClass("fieldrequired");
|
||||||
$obj = $db->fetch_object($resql);
|
|
||||||
$noemail = $obj->nb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
} else {
|
||||||
print '<td colspan="2"></td>';
|
$(".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 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)) {
|
if (!empty($conf->socialnetworks->enabled)) {
|
||||||
foreach ($socialnetworks as $key => $value) {
|
foreach ($socialnetworks as $key => $value) {
|
||||||
@ -1300,20 +1295,11 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
|
|||||||
// Unsubscribe opt-out
|
// Unsubscribe opt-out
|
||||||
if (!empty($conf->mailing->enabled))
|
if (!empty($conf->mailing->enabled))
|
||||||
{
|
{
|
||||||
//print 'eee'.$object->email;
|
$result=$object->getNoEmail();
|
||||||
$noemail = $object->no_email;
|
if ($result<0) {
|
||||||
if (empty($noemail) && !empty($object->email))
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
{
|
|
||||||
$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 '<tr><td>'.$langs->trans("No_Email").'</td><td>'.yn($object->no_email).'</td></tr>';
|
||||||
print '<tr><td>'.$langs->trans("No_Email").'</td><td>'.yn($noemail).'</td></tr>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td>';
|
print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td>';
|
||||||
|
|||||||
@ -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)
|
if (!$error)
|
||||||
{
|
{
|
||||||
// Remove category
|
// Remove category
|
||||||
@ -1880,4 +1894,94 @@ class Contact extends CommonObject
|
|||||||
|
|
||||||
return "Error, mode/status not found";
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,6 +74,14 @@ class modMailing extends DolibarrModules
|
|||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
$this->const = array();
|
$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
|
// Boxes
|
||||||
$this->boxes = array();
|
$this->boxes = array();
|
||||||
|
|||||||
@ -175,3 +175,5 @@ Answered=Answered
|
|||||||
IsNotAnAnswer=Is not answer (initial email)
|
IsNotAnAnswer=Is not answer (initial email)
|
||||||
IsAnAnswer=Is an answer of an 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
|
||||||
|
|||||||
@ -1113,6 +1113,7 @@ OutOfDate=Out-of-date
|
|||||||
EventReminder=Event Reminder
|
EventReminder=Event Reminder
|
||||||
UpdateForAllLines=Update for all lines
|
UpdateForAllLines=Update for all lines
|
||||||
OnHold=On hold
|
OnHold=On hold
|
||||||
|
Civility=Civility
|
||||||
AffectTag=Affect Tag
|
AffectTag=Affect Tag
|
||||||
ConfirmAffectTag=Bulk Tag Affect
|
ConfirmAffectTag=Bulk Tag Affect
|
||||||
ConfirmAffectTagQuestion=Are you sure you want to affect tags to the %s selected record(s)?
|
ConfirmAffectTagQuestion=Are you sure you want to affect tags to the %s selected record(s)?
|
||||||
|
|||||||
@ -397,6 +397,11 @@ if (empty($reshook))
|
|||||||
$error++;
|
$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 (!$error)
|
||||||
{
|
{
|
||||||
if ($action == 'update')
|
if ($action == 'update')
|
||||||
@ -568,7 +573,9 @@ if (empty($reshook))
|
|||||||
if ($object->particulier)
|
if ($object->particulier)
|
||||||
{
|
{
|
||||||
dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
|
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)
|
if ($result < 0)
|
||||||
{
|
{
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
@ -1156,8 +1163,23 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
|
|||||||
$("#selectcountry_id").change(function() {
|
$("#selectcountry_id").change(function() {
|
||||||
document.formsoc.action.value="create";
|
document.formsoc.action.value="create";
|
||||||
document.formsoc.submit();
|
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 '</script>'."\n";
|
||||||
|
|
||||||
print '<div id="selectthirdpartytype">';
|
print '<div id="selectthirdpartytype">';
|
||||||
@ -1366,7 +1388,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
|
|||||||
|
|
||||||
// Email / Web
|
// 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 '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', empty($conf->global->SOCIETE_EMAIL_MANDATORY) ? '' : $conf->global->SOCIETE_EMAIL_MANDATORY).'</td>';
|
||||||
print '<td colspan="3">'.img_picto('', 'object_email').' <input type="text" class="maxwidth500 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 '<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>';
|
print '<td colspan="3">'.img_picto('', 'globe').' <input type="text" class="maxwidth500 widthcentpercentminusx" name="url" id="url" value="'.$object->url.'"></td></tr>';
|
||||||
|
|
||||||
@ -1522,6 +1550,14 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
|
|||||||
print "</td></tr>";
|
print "</td></tr>";
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
if (!empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION))
|
||||||
|
{
|
||||||
|
print '<tr class="individualline"><td class="toptd">'.$form->editfieldkey('ContactCategoriesShort', 'contcats', '', $object, 0).'</td><td colspan="3">';
|
||||||
|
$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 "</td></tr>";
|
||||||
|
}
|
||||||
|
|
||||||
// Supplier
|
// Supplier
|
||||||
if (!empty($conf->fournisseur->enabled)) {
|
if (!empty($conf->fournisseur->enabled)) {
|
||||||
print '<tr class="visibleifsupplier"><td class="toptd">'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td><td colspan="3">';
|
print '<tr class="visibleifsupplier"><td class="toptd">'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td><td colspan="3">';
|
||||||
|
|||||||
@ -931,10 +931,18 @@ class Societe extends CommonObject
|
|||||||
* Create a contact/address from thirdparty
|
* Create a contact/address from thirdparty
|
||||||
*
|
*
|
||||||
* @param User $user Object user
|
* @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
|
* @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
|
// phpcs:enable
|
||||||
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
|
||||||
$contact = new Contact($this->db);
|
$contact = new Contact($this->db);
|
||||||
@ -954,14 +962,43 @@ class Societe extends CommonObject
|
|||||||
$contact->town = $this->town;
|
$contact->town = $this->town;
|
||||||
$contact->phone_pro = $this->phone;
|
$contact->phone_pro = $this->phone;
|
||||||
|
|
||||||
$result = $contact->create($user);
|
$contactId = $contact->create($user);
|
||||||
if ($result < 0) {
|
if ($contactId < 0) {
|
||||||
|
$error++;
|
||||||
$this->error = $contact->error;
|
$this->error = $contact->error;
|
||||||
$this->errors = $contact->errors;
|
$this->errors = $contact->errors;
|
||||||
dol_syslog(get_class($this)."::create_individual ERROR:".$this->error, LOG_ERR);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user