diff --git a/ChangeLog b/ChangeLog index 2aa466a76dd..ad210c55c0f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -46,6 +46,7 @@ For users: - Fix: Project Task numbering customs rule works. - Fix: Add actions events not implemented. - New: Add filter date in bank writing list page +- New: Enable option "clone target emailing" TODO - New: Predefined product and free product use same form. diff --git a/htdocs/comm/mailing/class/mailing.class.php b/htdocs/comm/mailing/class/mailing.class.php index a0094c2f3f6..a6db4738bb5 100644 --- a/htdocs/comm/mailing/class/mailing.class.php +++ b/htdocs/comm/mailing/class/mailing.class.php @@ -305,8 +305,55 @@ class Mailing extends CommonObject if (! $error) { - - + //Clone target + if (!empty($option2)) { + + require_once DOL_DOCUMENT_ROOT .'/core/modules/mailings/modules_mailings.php'; + + $mailing_target = new MailingTargets($this->db); + + $target_array=array(); + + $sql = "SELECT fk_contact, "; + $sql.=" lastname, "; + $sql.=" firstname,"; + $sql.=" email,"; + $sql.=" other,"; + $sql.=" source_url,"; + $sql.=" source_id ,"; + $sql.=" source_type "; + $sql.= " FROM ".MAIN_DB_PREFIX."mailing_cibles "; + $sql.= " WHERE fk_mailing = ".$fromid; + + dol_syslog(get_class($this)."::createFromClone sql=".$sql); + $result=$this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + while ($obj = $this->db->fetch_object($result)) { + + $target_array[]=array('fk_contact'=>$obj->fk_contact, + 'lastname'=>$obj->lastname, + 'firstname'=>$obj->firstname, + 'email'=>$obj->email, + 'other'=>$obj->other, + 'source_url'=>$obj->source_url, + 'source_id'=>$obj->source_id, + 'source_type'=>$obj->source_type); + } + + } + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog("Mailing::createFromClone ".$this->error, LOG_ERR); + return -1; + } + + $mailing_target->add_to_target($object->id, $target_array); + } } diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php index 03caf79d9d5..9d6a31cdfac 100644 --- a/htdocs/comm/mailing/fiche.php +++ b/htdocs/comm/mailing/fiche.php @@ -822,7 +822,7 @@ else $formquestion=array( 'text' => $langs->trans("ConfirmClone"), array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneContent"), 'value' => 1), - array('type' => 'checkbox', 'name' => 'clone_receivers', 'label' => $langs->trans("CloneReceivers").' ('.$langs->trans("FeatureNotYetAvailable").')', 'value' => 0, 'disabled' => true) + array('type' => 'checkbox', 'name' => 'clone_receivers', 'label' => $langs->trans("CloneReceivers"), 'value' => 0) ); // Paiement incomplet. On demande si motif = escompte ou autre print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneEMailing'),$langs->trans('ConfirmCloneEMailing',$object->ref),'confirm_clone',$formquestion,'yes',2,240); diff --git a/htdocs/core/modules/mailings/modules_mailings.php b/htdocs/core/modules/mailings/modules_mailings.php index 4f0599bfb3b..6f4a573ccfc 100644 --- a/htdocs/core/modules/mailings/modules_mailings.php +++ b/htdocs/core/modules/mailings/modules_mailings.php @@ -168,7 +168,7 @@ class MailingTargets // This can't be abstract as it is used for some method $sql.= "'".$this->db->escape($targetarray['other'])."',"; $sql.= "'".$this->db->escape($targetarray['source_url'])."',"; $sql.= (empty($targetarray['source_id']) ? 'null' : "'".$this->db->escape($targetarray['source_id'])."'").","; - $sql .= "'".$this->db->escape(dol_hash($targetarray['email'].';'.$targetarray['name'].';'.$mailing_id.';'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY))."',"; + $sql .= "'".$this->db->escape(dol_hash($targetarray['email'].';'.$targetarray['lastname'].';'.$mailing_id.';'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY))."',"; $sql .= "'".$this->db->escape($targetarray['source_type'])."')"; $result=$this->db->query($sql); if ($result)