unserialize_task_params();
if (($parameters['empr_caddie'] || $parameters['empr_search_perso']) && $parameters['mailtpl_id']) {
if($this->statut == WAITING) {
$this->send_command(RUNNING);
}
if($this->statut == RUNNING) {
$result = array();
$email_cc = '';
if (isset($parameters['email_cc'])) {
$email_cc = trim($parameters['email_cc']);
}
$empr_choice = mailing_empr::TYPE_CADDIE;
if (isset($parameters['empr_choice'])) {
$empr_choice = $parameters['empr_choice'];
}
$associated_campaign = 0;
if (isset($parameters['associated_campaign'])) {
$associated_campaign = $parameters['associated_campaign'];
}
if (mailing_empr::TYPE_CADDIE == $empr_choice) {
if (method_exists($this->proxy, 'pmbesMailing_sendMailingCaddie')) {
if(!empty($parameters['pieces_jointes_mailing'])) {
$this->get_attachments($parameters['pieces_jointes_mailing']);
}
$result = $this->proxy->pmbesMailing_sendMailingCaddie($parameters['empr_caddie'], $parameters['mailtpl_id'], $email_cc, $this->attachments, $associated_campaign);
} else {
$this->add_function_rights_report("sendMailingCaddie","pmbesMailing");
}
} else {
if (method_exists($this->proxy, 'pmbesMailing_sendMailingSearchPerso')) {
if(!empty($parameters['pieces_jointes_mailing'])) {
$this->get_attachments($parameters['pieces_jointes_mailing']);
}
$result = $this->proxy->pmbesMailing_sendMailingSearchPerso($parameters['empr_search_perso'], $parameters['mailtpl_id'], $email_cc, $this->attachments, $associated_campaign);
} else {
$this->add_function_rights_report("sendMailingSearchPerso","pmbesMailing");
}
}
if (is_array($result) && count($result)) {
$this->report[] = "
$msg[empr_mailing_titre_resultat]
$msg[admin_mailtpl_sel]
".htmlentities($result["name"],ENT_QUOTES,$charset)."
$msg[empr_mailing_form_obj_mail]
".htmlentities($result["object_mail"],ENT_QUOTES,$charset)."
".(count($this->attachments) ? "".$this->msg['planificateur_attachments']." ".$this->get_display_attachments() : '')."
".(count($this->attachments_errors) ? "".$this->msg['planificateur_attachments_errors']." ".implode(', ',$this->attachments_errors) : '')."
|
";
$tpl_report = "
$msg[empr_mailing_resultat_envoi]";
$msg['empr_mailing_recap_comptes'] = str_replace("!!total_envoyes!!", $result["nb_mail_sended"], $msg['empr_mailing_recap_comptes']) ;
$msg['empr_mailing_recap_comptes'] = str_replace("!!total!!", $result["nb_mail"], $msg['empr_mailing_recap_comptes']) ;
$tpl_report .= $msg['empr_mailing_recap_comptes'] ;
$sql = "select id_empr, empr_mail, empr_nom, empr_prenom from empr, empr_caddie_content where flag='2' and empr_caddie_id=".$parameters['empr_caddie']." and object_id=id_empr ";
$sql_result = pmb_mysql_query($sql) ;
if (pmb_mysql_num_rows($sql_result)) {
$tpl_report .= "
$msg[empr_mailing_liste_erreurs]
";
while ($obj_erreur=pmb_mysql_fetch_object($sql_result)) {
$tpl_report .= "
".$obj_erreur->empr_nom." ".$obj_erreur->empr_prenom." (".$obj_erreur->empr_mail.")
";
}
}
//Reset du pointage les mails non envoyés
//DG - #76725 Je le laisse commenté pour la raison suivante :
// Si l'on dépointe les mails non envoyés (erreur sur l'adresse mail) sur une tâche auto fréquente, il y a des risques de devenir SPAMMEUR
// $mailing->reset_flag_not_sended();
$tpl_report .= " |
";
$this->report[] = $tpl_report;
$this->update_progression(100);
}
}
} else {
$this->add_content_report($this->msg["mailing_unknown"]);
}
} else {
$this->add_rights_bad_user_report();
}
}
protected function get_attachments($pieces_jointes_mailing = array()) {
global $pmb_attachments_folder;
$this->attachments = array();
$this->attachments_errors = array();
if(is_dir($pmb_attachments_folder)){
if (isset($pieces_jointes_mailing)) {
foreach ($pieces_jointes_mailing as $name) {
if($name) {
if(file_exists($pmb_attachments_folder.$name)) {
$this->attachments[] = array(
'nomfichier' => $name,
'contenu' => file_get_contents($pmb_attachments_folder.$name)
);
} else {
$this->attachments_errors[] = $name;
}
}
}
}
}
return $this->attachments;
}
protected function get_display_attachments() {
$files = array();
foreach ($this->attachments as $attachment) {
$files[] = $attachment['nomfichier'];
}
return implode(", ", $files);
}
}