From 27b0b0e8d520a74a899ede4bd3654bb7f9c0fda1 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Wed, 6 Jan 2021 09:11:04 +0100 Subject: [PATCH 01/14] =?UTF-8?q?add=20contacg=20tag=20on=20thirdparty=20a?= =?UTF-8?q?nd=20contact=20cr=C3=A9ation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/societe/card.php | 13 +++++++++++-- htdocs/societe/class/societe.class.php | 18 ++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 7fccdf994b9..c24689675ea 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -562,7 +562,8 @@ 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'); + $result = $object->create_individual($user, $contcats); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -1356,7 +1357,7 @@ 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' ? ' colspan="3"' : '').'>'.img_picto('', 'object_email').' '; print ''.$form->editfieldkey('Web', 'url', '', $object, 0).''; print ''.img_picto('', 'globe').' '; @@ -1512,6 +1513,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 ($object->fournisseur) { print ''.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).''; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 4c25a002a8f..a809fe7d10d 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -900,9 +900,10 @@ class Societe extends CommonObject * Create a contact/address from thirdparty * * @param User $user Object user + * @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, $tags=array()) { // phpcs:enable require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; @@ -923,14 +924,23 @@ 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) { $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)) { + $result = $contact->setCategories($tags); + if ($result < 0) + { + $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; + } } - return $result; + return $contactId; } /** From 5c53a963e221443a3dff7f0cd6d3db3555ab4205 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 7 Jan 2021 17:23:02 +0100 Subject: [PATCH 02/14] bulk email management --- htdocs/admin/mailing.php | 28 ++- htdocs/contact/card.php | 232 +++++++++++------------ htdocs/contact/class/contact.class.php | 104 ++++++++++ htdocs/core/modules/modMailing.class.php | 8 + htdocs/langs/en_US/mails.lang | 4 +- htdocs/societe/card.php | 36 +++- htdocs/societe/class/societe.class.php | 37 +++- 7 files changed, 314 insertions(+), 135 deletions(-) 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; } From afc85c2f2d8be6c50c72aa218f6ccc517c73bc94 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Thu, 7 Jan 2021 18:24:44 +0100 Subject: [PATCH 03/14] Fix expedition class - update shipment, tms is auto update field - wrong vars - clean code --- htdocs/expedition/class/expedition.class.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index e4722cabb4d..752da8aca04 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -499,8 +499,8 @@ class Expedition extends CommonObject // create shipment lines foreach ($stockLocationQty as $stockLocation => $qty) { - if (($line_id = $this->create_line($stockLocation, $line_ext->origin_line_id, $qty, $line_ext->rang, $array_options)) < 0) - { + $line_id = $this->create_line($stockLocation, $line_ext->origin_line_id, $qty, $line_ext->rang, $array_options); + if ($line_id < 0) { $error++; } else { // create shipment batch lines for stockLocation @@ -629,7 +629,7 @@ class Expedition extends CommonObject if (!empty($conf->multicurrency->enabled)) { if (!empty($this->multicurrency_code)) $this->multicurrency_code = $this->thirdparty->multicurrency_code; - if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $this->multicurrency_tx = $this->thirdparty->multicurrency_tx; + if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($this->thirdparty->multicurrency_tx)) $this->multicurrency_tx = $this->thirdparty->multicurrency_tx; } /* @@ -1081,8 +1081,8 @@ class Expedition extends CommonObject if (isset($this->size_units)) $this->size_units = trim($this->size_units); if (isset($this->weight_units)) $this->weight_units = trim($this->weight_units); if (isset($this->trueWeight)) $this->weight = trim($this->trueWeight); - if (isset($this->note_private)) $this->note = trim($this->note_private); - if (isset($this->note_public)) $this->note = trim($this->note_public); + if (isset($this->note_private)) $this->note_private = trim($this->note_private); + if (isset($this->note_public)) $this->note_public = trim($this->note_public); if (isset($this->model_pdf)) $this->model_pdf = trim($this->model_pdf); @@ -1093,7 +1093,6 @@ class Expedition extends CommonObject // Update request $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET"; - $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; $sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").","; $sql .= " ref_ext=".(isset($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null").","; $sql .= " ref_customer=".(isset($this->ref_customer) ? "'".$this->db->escape($this->ref_customer)."'" : "null").","; @@ -2751,7 +2750,7 @@ class ExpeditionLigne extends CommonObjectLine $ranktouse = $this->rang; if ($ranktouse == -1) { - $rangmax = $this->line_max($fk_expedition); + $rangmax = $this->line_max($this->fk_expedition); $ranktouse = $rangmax + 1; } From 843f49643de526a1fbcfe9c3820c0a517b5277e7 Mon Sep 17 00:00:00 2001 From: Indelog Date: Fri, 8 Jan 2021 11:42:20 +0100 Subject: [PATCH 04/14] Fix Debugbarr : TraceableDB::idate not compatible with DolDB::idate The `TracableDB` class extend the `DolDB` but not implement the method `idate` correctly : it missing the `$gm` parameter. --- htdocs/debugbar/class/TraceableDB.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/debugbar/class/TraceableDB.php b/htdocs/debugbar/class/TraceableDB.php index 0cb380f39a1..af11f4c1d67 100644 --- a/htdocs/debugbar/class/TraceableDB.php +++ b/htdocs/debugbar/class/TraceableDB.php @@ -80,12 +80,13 @@ class TraceableDB extends DoliDB * Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field. * Function to use to build INSERT, UPDATE or WHERE predica * - * @param int $param Date TMS to convert - * @return string Date in a string YYYYMMDDHHMMSS + * @param int $param Date TMS to convert + * @param mixed $gm 'gmt'=Input informations are GMT values, 'tzserver'=Local to server TZ + * @return string Date in a string YYYY-MM-DD HH:MM:SS */ - public function idate($param) + public function idate($param, $gm = 'tzserver') { - return $this->db->idate($param); + return $this->db->idate($param, $gm); } /** From 004ee952d919d621f4043ad4248a6d7baf725925 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 10 Jan 2021 08:16:19 +0100 Subject: [PATCH 05/14] Various payment - Add Amount & Sens in clone mode --- htdocs/compta/bank/various_payment/card.php | 29 ++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/bank/various_payment/card.php b/htdocs/compta/bank/various_payment/card.php index 0efe367089c..597c2f4452c 100644 --- a/htdocs/compta/bank/various_payment/card.php +++ b/htdocs/compta/bank/various_payment/card.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2017-2021 Alexandre Spangaro * Copyright (C) 2018-2020 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -266,6 +266,18 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->banque->m $object->datev = $newdatepayment; } + if (GETPOSTINT("clone_sens")) { + $object->sens = GETPOSTINT("clone_sens"); + } else { + $object->sens = $object->sens; + } + + if (GETPOST("clone_amount", "alpha")) { + $object->amount = price2num(GETPOST("clone_amount", "alpha")); + } else { + $object->amount = price2num($object->amount); + } + if ($object->check()) { $id = $object->create($user); @@ -486,14 +498,19 @@ if ($id) // Clone confirmation if ($action === 'clone') { + $set_value_help = $form->textwithpicto('', $langs->trans($langs->trans("AccountingDirectionHelp"))); + $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit")); + $formquestion = array( array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label), - ); - $formquestion[] = array('type' => 'date', 'tdclass'=>'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1); - $formquestion[] = array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1); - $formquestion[] = array('type' => 'other', 'tdclass'=>'fieldrequired', 'name' => 'accountid', 'label' => $langs->trans("BankAccount"), 'value' => $form->select_comptes($accountid, "accountid", 0, '', 1, '', 0, 'minwidth200', 1)); + array('type' => 'date', 'tdclass'=>'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1), + array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1), + array('type' => 'other', 'tdclass'=>'fieldrequired', 'name' => 'clone_accountid', 'label' => $langs->trans("BankAccount"), 'value' => $form->select_comptes($object->fk_account, "accountid", 0, '', 1, '', 0, 'minwidth200', 1)), + array('type' => 'text', 'name' => 'clone_amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount)), + array('type' => 'select', 'name' => 'clone_sens', 'label' => $langs->trans("Sens") . ' ' . $set_value_help, 'values' => $sensarray, 'default' => $object->sens), + ); - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 300); + print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 350); } print dol_get_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, $object->picto); From c40976e4f9298ca4ff676c9088535c506ac6bbb1 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Mon, 11 Jan 2021 09:47:59 +0100 Subject: [PATCH 06/14] FIX: Hidden accountancy export button without any right --- htdocs/accountancy/bookkeeping/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index b3cec7710a4..39596d26ebe 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -638,7 +638,7 @@ if (empty($reshook)) { } $newcardbutton .= ''.$langs->trans("IncludeDocsAlreadyExported").''; - $newcardbutton .= dolGetButtonTitle($buttonLabel, $langs->trans("ExportFilteredList").' ('.$listofformat[$formatexportset].')', 'fa fa-file-export paddingleft', $_SERVER["PHP_SELF"].'?action=export_file'.($param ? '&'.$param : ''), $user->rights->accounting->mouvements->export); + if(!empty($user->rights->accounting->mouvements->export)) $newcardbutton .= dolGetButtonTitle($buttonLabel, $langs->trans("ExportFilteredList").' ('.$listofformat[$formatexportset].')', 'fa fa-file-export paddingleft', $_SERVER["PHP_SELF"].'?action=export_file'.($param ? '&'.$param : ''), $user->rights->accounting->mouvements->export); $newcardbutton .= dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?'.$param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected')); $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?'.$param, '', 1, array('morecss' => 'marginleftonly')); From 7339217cf1163e7497e29e59fef77a1ab2f6159f Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 11 Jan 2021 08:51:52 +0000 Subject: [PATCH 07/14] Fixing style errors. --- htdocs/accountancy/bookkeeping/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 39596d26ebe..33845492670 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -638,7 +638,7 @@ if (empty($reshook)) { } $newcardbutton .= ''.$langs->trans("IncludeDocsAlreadyExported").''; - if(!empty($user->rights->accounting->mouvements->export)) $newcardbutton .= dolGetButtonTitle($buttonLabel, $langs->trans("ExportFilteredList").' ('.$listofformat[$formatexportset].')', 'fa fa-file-export paddingleft', $_SERVER["PHP_SELF"].'?action=export_file'.($param ? '&'.$param : ''), $user->rights->accounting->mouvements->export); + if (!empty($user->rights->accounting->mouvements->export)) $newcardbutton .= dolGetButtonTitle($buttonLabel, $langs->trans("ExportFilteredList").' ('.$listofformat[$formatexportset].')', 'fa fa-file-export paddingleft', $_SERVER["PHP_SELF"].'?action=export_file'.($param ? '&'.$param : ''), $user->rights->accounting->mouvements->export); $newcardbutton .= dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?'.$param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected')); $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?'.$param, '', 1, array('morecss' => 'marginleftonly')); From d2c86578fa2d3ec5172c620d2d426896360ee9e7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 11 Jan 2021 15:58:20 +0100 Subject: [PATCH 08/14] Update card.php --- htdocs/compta/bank/various_payment/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/bank/various_payment/card.php b/htdocs/compta/bank/various_payment/card.php index 597c2f4452c..0c2db362e75 100644 --- a/htdocs/compta/bank/various_payment/card.php +++ b/htdocs/compta/bank/various_payment/card.php @@ -266,8 +266,8 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->banque->m $object->datev = $newdatepayment; } - if (GETPOSTINT("clone_sens")) { - $object->sens = GETPOSTINT("clone_sens"); + if (GETPOSTISSET("clone_sens")) { + $object->sens = GETPOST("clone_sens", 'int'); } else { $object->sens = $object->sens; } From f6de6078893bccc0b4c49aad39d2ba51e468e33e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 11 Jan 2021 16:07:02 +0100 Subject: [PATCH 09/14] Fix warning --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 90532e5ee1e..d6b67088e78 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1977,7 +1977,7 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = global $conf, $langs; if ($tzoutput == 'auto') { - $tzoutput = $conf->tzuserinputkey; + $tzoutput = (empty($conf) ? 'tzserver' : $conf->tzuserinputkey); } // Clean parameters From 6e860efa448157880a430e6bf7fe236f11985502 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 11 Jan 2021 20:53:18 +0100 Subject: [PATCH 10/14] CSS --- htdocs/projet/tasks/list.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/projet/tasks/list.php b/htdocs/projet/tasks/list.php index 1951df8c0e1..b318b44f053 100644 --- a/htdocs/projet/tasks/list.php +++ b/htdocs/projet/tasks/list.php @@ -511,7 +511,7 @@ if (!empty($arrayfields['t.label']['checked'])) print ''; print ''; } -//Task Description +// Task Description if (!empty($arrayfields['t.description']['checked'])) { print ''; @@ -728,7 +728,7 @@ while ($i < min($num, $limit)) // Project ref if (!empty($arrayfields['p.ref']['checked'])) { - print ''; + print ''; print $projectstatic->getNomUrl(1, 'task'); if ($projectstatic->hasDelay()) print img_warning("Late"); print ''; From 7f90c88d6a518709d7806b9193107ac0fbf4e5cc Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 12 Jan 2021 09:51:39 +0100 Subject: [PATCH 11/14] fix js syntax --- htdocs/societe/card.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 0e2b10bcb19..58f5645e25d 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -1167,8 +1167,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) $("#email").keyup(function() { init_check_no_email($(this)); }); - init_check_no_email($("#email")); - });'; + init_check_no_email($("#email"));'; } print '});'; print ''."\n"; From 3906acc951836b80306ac49f76e971a722de3ec1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Jan 2021 10:00:05 +0100 Subject: [PATCH 12/14] Must use the generic version --- htdocs/core/class/html.formmail.class.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index a4f936cfca0..1edcabf36a5 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1264,8 +1264,6 @@ class FormMail extends Form $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm"); } elseif ($type_template == 'thirdparty') { $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentThirdparty"); - } elseif ($type_template == 'user') { - $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentUser"); } elseif (!empty($type_template)) { $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric"); } From 2be924d5d8a96d3d3ac0f85172b71309cf856435 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 12 Jan 2021 10:01:32 +0100 Subject: [PATCH 13/14] fix js bulkemail --- htdocs/contact/card.php | 24 +++++++++++++++--------- htdocs/societe/card.php | 1 - 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 6ce4493c947..8c7e3b6c066 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -1044,15 +1044,21 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) if ($conf->use_javascript_ajax && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS==-1) { print "\n".''."\n"; } if (!GETPOSTISSET("no_email") && !empty($object->email)) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 58f5645e25d..3632137c637 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -1155,7 +1155,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) document.formsoc.submit(); });'; if ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS==-1) { - print ' function init_check_no_email(input) { if (input.val()!="") { From 3f13dacacd6da5373f42ae02af1aa5df97be1ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Luttringer?= Date: Sun, 10 Jan 2021 18:15:26 +0100 Subject: [PATCH 14/14] Use login from LDAP attribute The LDAP authentication function (check_user_password_ldap) returns the login sting when authentication is successful. The current implementation always return the provided login to the check function, instead of LDAP entry login field (as defined in the LDAP_FIELD_LOGIN). This is problematic when you expect user to log with several login, like mail, or the LDAP login doesn't match the dolibarr database. For example, the following filter allows users auth with mail and cn ldap fields: $dolibarr_main_auth_ldap_filter = '(&(objectClass=person)(|(cn=%1%)(mail=%1%)))'; but, dolibarr will not find the user when mail is provided. This patch returns the $ldap->login when LDAP_FIELD_LOGIN is configured. --- htdocs/core/login/functions_ldap.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/core/login/functions_ldap.php b/htdocs/core/login/functions_ldap.php index 41ce8a67316..c62c6add140 100644 --- a/htdocs/core/login/functions_ldap.php +++ b/htdocs/core/login/functions_ldap.php @@ -148,8 +148,11 @@ function check_user_password_ldap($usertotest, $passwordtotest, $entitytotest) { if ($result == 2) // Connection is ok for user/pass into LDAP { - dol_syslog("functions_ldap::check_user_password_ldap Authentification ok"); $login = $usertotest; + if (!empty($conf->global->LDAP_FIELD_LOGIN)) { + $login = $ldap->login; + } + dol_syslog("functions_ldap::check_user_password_ldap $login authentication ok"); require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';