You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
823 lines
39 KiB
823 lines
39 KiB
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
/**
|
|
* This Class handles the sending of emails of Backoffice and FrontofficeV2
|
|
* Api : Mailjet
|
|
*/
|
|
|
|
// require 'mailjet/vendor/autoload.php';
|
|
use \Mailjet\Resources;
|
|
|
|
class Mailjet_libr {
|
|
|
|
protected $search = [];
|
|
protected $replacements = [];
|
|
|
|
public function __construct () {
|
|
|
|
$_config = array(
|
|
"sender" => MAILJET_API['SENDER_EMAIL'],
|
|
"fromName" => MAILJET_API['SENDER_NAME'],
|
|
"apikey" => MAILJET_API['KEY'],
|
|
"apisecret" => MAILJET_API['SECRET']
|
|
);
|
|
$this->cfg = $_config;
|
|
|
|
$this->mj = new \Mailjet\Client($this->cfg["apikey"], $this->cfg["apisecret"], true);
|
|
|
|
$CI =& get_instance();
|
|
$CI->lang->load('frontoffice/subscribe', 'fr');
|
|
}
|
|
|
|
public function _ci_instance_email(){
|
|
return array(
|
|
'sender' => $this->cfg["sender"],
|
|
'protocol' => 'smtp',
|
|
'smtp_host' => 'ssl://in.mailjet.com',
|
|
'smtp_port' => 465,
|
|
'smtp_user' => $this->cfg["apikey"],
|
|
'smtp_pass' => $this->cfg["apisecret"],
|
|
'mailtype' => 'html',
|
|
'charset' => 'UTF-8',
|
|
'newline' => "\r\n"
|
|
);
|
|
}
|
|
|
|
public function fo_send_template_email($maildata) {
|
|
//initialize vars
|
|
$maildata["vars"] = $this->initialize_event_vars($maildata["vars"]);
|
|
$body = [
|
|
'FromEmail' => $this->cfg["sender"],
|
|
'FromName' => (isset($this->cfg["fromName"]) && !empty($this->cfg["fromName"]))?$this->cfg["fromName"]:'',
|
|
'Subject' => str_ireplace($this->search, $this->replacements, $maildata["message"]->email_tpl_subject),
|
|
'Html-part' => customEmailFormat($maildata["message"]->email_tpl_detail, $maildata["vars"]),
|
|
'Recipients' => [
|
|
[
|
|
'Email' => $maildata["vars"]->email_address,
|
|
'Name' => $maildata["vars"]->subscriber,
|
|
'Vars' => (array) $maildata["vars"]
|
|
]
|
|
]
|
|
];
|
|
|
|
$response = $this->mj->post(Resources::$Email, ['body' => $body]);
|
|
if($response->success()) {
|
|
$msgSent = (object) $response->getData();
|
|
if(isset($msgSent->Sent) && !empty($msgSent->Sent)){
|
|
if($msgSent->Sent) {
|
|
$processed_email = array_column($msgSent->Sent, 'MessageID', 'Email');
|
|
|
|
if(isset($processed_email[$maildata["vars"]->email_address]) && !empty($processed_email[$maildata["vars"]->email_address])){
|
|
|
|
return array(
|
|
"email_reference_id" => $processed_email[$maildata["vars"]->email_address],
|
|
"email_number_of_send_attempt" => 1,
|
|
"email_status" => 1,
|
|
"email_description" => "Sent!"
|
|
);
|
|
} else {
|
|
return false;
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
} else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function fo_send_default_email($maildata) {
|
|
|
|
$body = [
|
|
'FromEmail' => $this->cfg["sender"],
|
|
'FromName' => (isset($maildata['fromName']) && !empty($maildata['fromName']))?$maildata['fromName']:$this->cfg["fromName"],
|
|
'Subject' => $maildata["subject"],
|
|
'Html-part' => urldecode($maildata["message"]),
|
|
'Recipients' => [
|
|
[
|
|
'Email' => $maildata["recipient"],
|
|
]
|
|
]
|
|
];
|
|
$response = $this->mj->post(Resources::$Email, ['body' => $body]);
|
|
if($response->success()) {
|
|
return $response->getData();
|
|
}
|
|
else
|
|
return false;
|
|
}
|
|
|
|
function send($data, int $type){
|
|
switch($type){
|
|
case 1:
|
|
return $this->send_reminder_email($data);
|
|
break;
|
|
case 2:
|
|
return $this->send_waiting_list_reinvitation_email($data);
|
|
break;
|
|
case 3:
|
|
return $this->send_push_event_emails($data);
|
|
break;
|
|
case 4:
|
|
return $this->send_frontoffice_emails($data);
|
|
break;
|
|
case 5:
|
|
return $this->send_workshop_informer_emails($data);
|
|
break;
|
|
case 6:
|
|
return $this->send_cancel_email($data);
|
|
break;
|
|
case 7:
|
|
return $this->send_distance_reminder_email($data);
|
|
default :
|
|
echo "No action has been specified.";
|
|
exit(0);
|
|
break;
|
|
};
|
|
}
|
|
|
|
private function send_workshop_informer_emails($maildata){
|
|
$emails = array();
|
|
$sent_emails = array();
|
|
$failed_emails = array();
|
|
$mjLog = "";
|
|
|
|
foreach ($maildata["maildata"] as $key => $value) {
|
|
|
|
//initialize variables
|
|
$value["event"] = $this->initialize_event_vars($value["event"]);
|
|
|
|
$mjBODY = array(
|
|
'FromEmail' => $this->cfg["sender"],
|
|
'FromName' => $this->cfg["fromName"],
|
|
'Subject' => str_replace($this->search, $this->replacements, $value["event_email_tpl"]->email_tpl_subject),
|
|
'Html-part' => customEmailFormat($value["event_email_tpl"]->email_tpl_detail, $value["event"]),
|
|
'Vars' => (array) $value["event"]
|
|
);
|
|
|
|
$mjBODY['Vars'] = array_merge($mjBODY['Vars'], $maildata["addVars"]);
|
|
$mjBODY['Vars']['event_url'] = $mjBODY['Vars']['event_url'].$value["event"]->event_id;
|
|
$mjBODY['Vars']['event_picture'] = $maildata["addVars"]['event_picture'].$value["event"]->event_picture;
|
|
$mjBODY['Recipients'] = array();
|
|
|
|
foreach ($value["subscribers"] as $index => $subscriber) {
|
|
array_push($mjBODY['Recipients'], array(
|
|
'Email' => $subscriber->email_address,
|
|
// 'Name' => $subscriber->subscriber,
|
|
'Vars' => array(
|
|
'new_tab_url' => "e/workshop/".base64_encode($subscriber->email_recipient_id),
|
|
'email_address' => $subscriber->email_address
|
|
)
|
|
));
|
|
|
|
//prepare processed emails
|
|
array_push($emails, array(
|
|
"email_recipient_id" => $subscriber->email_recipient_id,
|
|
"email_address" => $subscriber->email_address,
|
|
"email_reference_id" => null,
|
|
"email_date_time" => date('Y-m-d H:i:s'),
|
|
"email_tpl_id" => $value["event_email_tpl"]->email_tpl_id,
|
|
"email_number_of_send_attempt" => $subscriber->email_number_of_send_attempt,
|
|
"email_status" => 0,
|
|
));
|
|
}
|
|
|
|
$sent = 0;
|
|
$failed = 0;
|
|
$response = $this->mj->post(Resources::$Email, array('body' => $mjBODY));
|
|
|
|
if ($response->success()) {
|
|
$msgSent = (object) $response->getData();
|
|
if($msgSent->Sent){
|
|
$processed_emails = array_column($msgSent->Sent, 'MessageID', 'Email');
|
|
foreach($emails as $idx => $val){
|
|
//sent emails
|
|
if(isset($processed_emails[$val["email_address"]]) && !empty($processed_emails[$val["email_address"]])){
|
|
$val["email_reference_id"] = $processed_emails[$val["email_address"]];
|
|
$val["email_number_of_send_attempt"] +=1;
|
|
$val["email_status"] = 1;//we need to set this to 5 instead of one, description matters here which is the "Sent!"
|
|
$val["email_description"] = "Sent!";
|
|
unset($val["email_address"]);
|
|
$sent++;
|
|
array_push($sent_emails, $val);
|
|
} else { //failed emails
|
|
$val["email_number_of_send_attempt"] += 1;
|
|
$val["email_status"] = 0;
|
|
$val["email_description"] = "Failed!";
|
|
unset($val["email_address"]);
|
|
$failed++;
|
|
array_push($failed_emails, $val);
|
|
}
|
|
}
|
|
unset($processed_emails);
|
|
$emails = array();
|
|
$mjLog .="Email type : Workshop Informer, Sent : ".$sent.", Failed : ".$failed.", Event_id : ".$value["event"]->event_id."\n";
|
|
} else {
|
|
$mjLog .="Email type : Workshop Informer, Mj E-Code : ".$response->getStatus()." Event_id : ".$value["event"]->event_id."\n";
|
|
}
|
|
} else {
|
|
$mjLog .="Email type : Workshop Informer, Mj E-Code : ".$response->getStatus()." Event_id : ".$value["event"]->event_id."\n";
|
|
}
|
|
unset($response);
|
|
} //end of main loop
|
|
|
|
return array("success" => true, "sent_emails" => $sent_emails, "failed_emails" => $failed_emails, "logs" => $mjLog);
|
|
}
|
|
|
|
private function send_reminder_email($maildata){
|
|
$emails = array();
|
|
$sent_emails = array();
|
|
$failed_emails = array();
|
|
$mjLog = "";
|
|
|
|
foreach ($maildata["maildata"] as $key => $value) {
|
|
|
|
//initialize variables
|
|
$value["event"] = $this->initialize_event_vars($value["event"]);
|
|
|
|
if(isset($value['event']->event_reminder_specific_date) && !empty($value['event']->event_reminder_specific_date)) {
|
|
$value['event']->event_reminder_date = secondsToTime($value['event']->event_reminder_specific_date);
|
|
} else {
|
|
unset($value['event']->event_reminder_specific_date);
|
|
}
|
|
|
|
$mjBODY = array(
|
|
'FromEmail' => $this->cfg["sender"],
|
|
'FromName' => $this->cfg["fromName"],
|
|
'Subject' => str_replace($this->search, $this->replacements, $value["event_email_tpl"]->email_tpl_subject),
|
|
'Html-part' => customEmailFormat($value["event_email_tpl"]->email_tpl_detail, $value["event"]),
|
|
'Vars' => (array) $value["event"]
|
|
);
|
|
|
|
$mjBODY['Vars'] = array_merge($mjBODY['Vars'], $maildata["addVars"]);
|
|
$mjBODY['Vars']['event_url'] = $mjBODY['Vars']['event_url'].$value["event"]->event_id;
|
|
$mjBODY['Vars']['event_picture'] = $maildata["addVars"]['event_picture'].$value["event"]->event_picture;
|
|
$mjBODY['Recipients'] = array();
|
|
|
|
foreach ($value["subscribers"] as $index => $subscriber) {
|
|
array_push($mjBODY['Recipients'], array(
|
|
'Email' => $subscriber->email_address,
|
|
'Name' => $subscriber->subscriber,
|
|
'Vars' => array(
|
|
'subscriber' => $subscriber->subscriber,
|
|
'subs_prenom' => $subscriber->subs_prenom,
|
|
'subs_nom' => $subscriber->subs_nom,
|
|
'new_tab_url' => "e/r/".base64_encode($subscriber->email_recipient_id."_".$subscriber->subscriber_id),
|
|
'email_address' => $subscriber->email_address
|
|
)
|
|
));
|
|
|
|
//prepare processed emails
|
|
array_push($emails, array(
|
|
"email_recipient_id" => $subscriber->email_recipient_id,
|
|
"email_address" => $subscriber->email_address,
|
|
"email_reference_id" => null,
|
|
"email_date_time" => date('Y-m-d H:i:s'),
|
|
"email_tpl_id" => $value["event_email_tpl"]->email_tpl_id,
|
|
"email_number_of_send_attempt" => $subscriber->email_number_of_send_attempt,
|
|
"email_status" => 0,
|
|
));
|
|
}
|
|
|
|
$sent = 0;
|
|
$failed = 0;
|
|
$response = $this->mj->post(Resources::$Email, array('body' => $mjBODY));
|
|
if ($response->success()) {
|
|
$msgSent = (object) $response->getData();
|
|
if($msgSent->Sent){
|
|
$processed_emails = array_column($msgSent->Sent, 'MessageID', 'Email');
|
|
foreach($emails as $idx => $val){
|
|
//sent emails
|
|
if(isset($processed_emails[$val["email_address"]]) && !empty($processed_emails[$val["email_address"]])){
|
|
$val["email_reference_id"] = $processed_emails[$val["email_address"]];
|
|
$val["email_number_of_send_attempt"] +=1;
|
|
$val["email_status"] = 1;//we need to set this to 5 instead of one, description matters here which is the "Sent!"
|
|
$val["email_description"] = "Sent!";
|
|
unset($val["email_address"]);
|
|
$sent++;
|
|
array_push($sent_emails, $val);
|
|
} else { //failed emails
|
|
$val["email_number_of_send_attempt"] += 1;
|
|
$val["email_status"] = 0;
|
|
$val["email_description"] = "Failed!";
|
|
unset($val["email_address"]);
|
|
$failed++;
|
|
array_push($failed_emails, $val);
|
|
}
|
|
}
|
|
unset($processed_emails);
|
|
$emails = array();
|
|
$mjLog .="Email type : Reminder, Sent : ".$sent.", Failed : ".$failed.", Event_id : ".$value["event"]->event_id.", Event_schedule_id : ".$value["event"]->event_schedule_id."\n";
|
|
} else {
|
|
$mjLog .="Email type : Reminder, Mj E-Code : ".$response->getStatus()." Event_id : ".$value["event"]->event_id.", Event_schedule_id : ".$value["event"]->event_schedule_id."\n";
|
|
}
|
|
} else {
|
|
$mjLog .="Email type : Reminder, Mj E-Code : ".$response->getStatus()." Event_id : ".$value["event"]->event_id.", Event_schedule_id : ".$value["event"]->event_schedule_id."\n";
|
|
}
|
|
unset($response);
|
|
} //end of main loop
|
|
|
|
return array("success" => true, "sent_emails" => $sent_emails, "failed_emails" => $failed_emails, "logs" => $mjLog);
|
|
}
|
|
|
|
private function send_waiting_list_reinvitation_email($maildata){
|
|
$emails = array();
|
|
$sent_emails = array();
|
|
$failed_emails = array();
|
|
$mjLog = "";
|
|
|
|
foreach ($maildata["maildata"] as $key => $value) {
|
|
|
|
//initialize variables
|
|
$value["event"] = $this->initialize_event_vars($value["event"]);
|
|
|
|
$mjBODY = array(
|
|
'FromEmail' => $this->cfg["sender"],
|
|
'FromName' => $this->cfg["fromName"],
|
|
'Subject' => str_replace($this->search, $this->replacements, $value["event_email_tpl"]->email_tpl_subject),
|
|
'Html-part' => customEmailFormat($value["event_email_tpl"]->email_tpl_detail, $value["event"]),
|
|
'Vars' => (array) $value["event"]
|
|
);
|
|
|
|
$mjBODY['Vars'] = array_merge($mjBODY['Vars'], $maildata["addVars"]);
|
|
$mjBODY['Vars']['event_url'] = $mjBODY['Vars']['event_url'].$value["event"]->event_id;
|
|
$mjBODY['Vars']['event_picture'] = $maildata["addVars"]['event_picture'].$value["event"]->event_picture;
|
|
$mjBODY['Recipients'] = array();
|
|
|
|
foreach ($value["subscribers"] as $index => $subscriber) {
|
|
array_push($mjBODY['Recipients'], array(
|
|
'Email' => $subscriber->email_address,
|
|
'Name' => $subscriber->subscriber,
|
|
'Vars' => array(
|
|
'subscriber' => $subscriber->subscriber,
|
|
'subs_prenom' => $subscriber->subs_prenom,
|
|
'subs_nom' => $subscriber->subs_nom,
|
|
'new_tab_url' => "e/wri/".base64_encode($subscriber->email_recipient_id."_".$subscriber->subscriber_id),
|
|
'email_address' => $subscriber->email_address
|
|
)
|
|
));
|
|
|
|
//prepare processed emails
|
|
array_push($emails, array(
|
|
"email_recipient_id" => $subscriber->email_recipient_id,
|
|
"email_address" => $subscriber->email_address,
|
|
"email_reference_id" => null,
|
|
"email_date_time" => date('Y-m-d H:i:s'),
|
|
"email_tpl_id" => $value["event_email_tpl"]->email_tpl_id,
|
|
"email_number_of_send_attempt" => $subscriber->email_number_of_send_attempt,
|
|
"email_status" => 0,
|
|
));
|
|
}
|
|
|
|
$sent=0;
|
|
$failed = 0;
|
|
$response = $this->mj->post(Resources::$Email, array('body' => $mjBODY));
|
|
if ($response->success()) {
|
|
$msgSent = (object) $response->getData();
|
|
if($msgSent->Sent){
|
|
$processed_emails = array_column($msgSent->Sent, 'MessageID', 'Email');
|
|
foreach($emails as $idx => $val){
|
|
//sent emails
|
|
if(isset($processed_emails[$val["email_address"]]) && !empty($processed_emails[$val["email_address"]])){
|
|
$val["email_reference_id"] = $processed_emails[$val["email_address"]];
|
|
$val["email_number_of_send_attempt"] +=1;
|
|
$val["email_status"] = 1;
|
|
$val["email_description"] = "Sent!";
|
|
unset($val["email_address"]);
|
|
$sent++;
|
|
array_push($sent_emails, $val);
|
|
} else { //failed emails
|
|
$val["email_number_of_send_attempt"] += 1;
|
|
$val["email_status"] = 0;
|
|
$val["email_description"] = "Failed!";
|
|
unset($val["email_address"]);
|
|
$failed++;
|
|
array_push($failed_emails, $val);
|
|
}
|
|
}
|
|
unset($processed_emails);
|
|
$emails = array();
|
|
$mjLog .="Email type : Waitinglist Reinvitation, Sent : ".$sent.", Failed : ".$failed.", Event_id : ".$value["event"]->event_id.", Event_schedule_id : ".$value["event"]->event_schedule_id."\n";
|
|
} else {
|
|
$mjLog .="Email type : Waitinglist Reinvitation, Mj E-Code : ".$response->getStatus()." Event_id : ".$value["event"]->event_id.", Event_schedule_id : ".$value["event"]->event_schedule_id."\n";
|
|
}
|
|
} else {
|
|
$mjLog .="Email type : Waitinglist Reinvitation, Mj E-Code : ".$response->getStatus()." Event_id : ".$value["event"]->event_id.", Event_schedule_id : ".$value["event"]->event_schedule_id."\n";
|
|
}
|
|
unset($response);
|
|
} //end of main loop
|
|
|
|
return array("success" => true, "sent_emails" => $sent_emails, "failed_emails" => $failed_emails, "logs" => $mjLog);
|
|
}
|
|
|
|
private function send_push_event_emails($maildata){
|
|
$emails = array();
|
|
$sent_emails = array();
|
|
$failed_emails = array();
|
|
$mjLog = "";
|
|
foreach ($maildata["maildata"] as $key => $value) {
|
|
|
|
//initialize variables
|
|
$value["event"] = $this->initialize_event_vars($value["event"]);
|
|
|
|
$mjBODY = array(
|
|
'FromEmail' => $this->cfg["sender"],
|
|
'FromName' => $this->cfg["fromName"],
|
|
'Subject' => str_replace($this->search, $this->replacements, $value["event_email_tpl"]->email_tpl_subject),
|
|
'Html-part' => urldecode($value["event_email_tpl"]->email_tpl_detail),
|
|
'Vars' => (array) $value["event"]
|
|
);
|
|
|
|
$mjBODY['Vars'] = array_merge($mjBODY['Vars'], $maildata["addVars"]);
|
|
$mjBODY['Vars']['event_url'] = $mjBODY['Vars']['event_url'].$value["event"]->event_id;
|
|
$mjBODY['Vars']['event_picture'] = $maildata["addVars"]['event_picture'].$value["event"]->event_picture;
|
|
$mjBODY['Recipients'] = array();
|
|
|
|
foreach ($value["subscribers"] as $index => $subscriber) {
|
|
array_push($mjBODY['Recipients'], array(
|
|
'Email' => $subscriber->email_address,
|
|
'Name' => $subscriber->subscriber,
|
|
'Vars' => array(
|
|
'subscriber' => $subscriber->subscriber,
|
|
'subs_prenom' => $subscriber->subs_prenom,
|
|
'subs_nom' => $subscriber->subs_nom,
|
|
'new_tab_url' => "e/epe/".base64_encode($subscriber->email_recipient_id."_".$subscriber->subscriber_id),
|
|
'email_address' => $subscriber->email_address
|
|
)
|
|
));
|
|
|
|
//prepare processed emails
|
|
array_push($emails, array(
|
|
"email_recipient_id" => $subscriber->email_recipient_id,
|
|
"email_address" => $subscriber->email_address,
|
|
"email_date_time" => date('Y-m-d H:i:s'),
|
|
"email_tpl_id" => $value["event_email_tpl"]->email_tpl_id,
|
|
"email_number_of_send_attempt" => $subscriber->email_number_of_send_attempt,
|
|
"email_status" => 0,
|
|
));
|
|
}
|
|
|
|
$sent=0;
|
|
$failed = 0;
|
|
$response = $this->mj->post(Resources::$Email, array('body' => $mjBODY));
|
|
if ($response->success()) {
|
|
$msgSent = (object) $response->getData();
|
|
if($msgSent->Sent){
|
|
$processed_emails = array_column($msgSent->Sent, 'MessageID', 'Email');
|
|
foreach($emails as $idx => $val){
|
|
//sent emails
|
|
if(isset($processed_emails[$val["email_address"]]) && !empty($processed_emails[$val["email_address"]])){
|
|
$val["email_reference_id"] = $processed_emails[$val["email_address"]];
|
|
$val["email_number_of_send_attempt"] +=1;
|
|
$val["email_status"] = 1;
|
|
$val["email_description"] = "Sent!";
|
|
unset($val["email_address"]);
|
|
$sent++;
|
|
array_push($sent_emails, $val);
|
|
} else { //failed emails
|
|
$val["email_number_of_send_attempt"] += 1;
|
|
$val["email_status"] = 0;
|
|
$val["email_description"] = "Failed!";
|
|
unset($val["email_address"]);
|
|
$failed++;
|
|
array_push($failed_emails, $val);
|
|
}
|
|
}
|
|
unset($processed_emails);
|
|
$emails = array();
|
|
$mjLog .="Email type : Push event, Sent : ".$sent.", Failed : ".$failed.", Event_id : ".$value["event"]->event_id."\n";
|
|
} else {
|
|
$mjLog .="Email type : Push event, Mj E-Code : ".$response->getStatus()." Event_id : ".$value["event"]->event_id."\n";
|
|
}
|
|
} else {
|
|
$mjLog .="Email type : Push event, Mj E-Code : ".$response->getStatus()." Event_id : ".$value["event"]->event_id."\n";
|
|
}
|
|
unset($response);
|
|
} //end of main loop
|
|
|
|
return array("success" => true, "sent_emails" => $sent_emails, "failed_emails" => $failed_emails, "logs" => $mjLog);
|
|
}
|
|
|
|
public function _call(){
|
|
// use your saved credentials
|
|
|
|
// Resources are all located in the Resources class
|
|
$response = $this->mj->get(Resources::$Contact);
|
|
|
|
/*
|
|
Read the response
|
|
*/
|
|
if ($response->success())
|
|
var_dump($response->getData());
|
|
else
|
|
var_dump($response->getStatus());
|
|
}
|
|
|
|
private function send_frontoffice_emails($maildata){
|
|
$emails = array();
|
|
$sent_emails = array();
|
|
$failed_emails = array();
|
|
$mjLog = "";
|
|
|
|
foreach ($maildata["maildata"] as $key => $value) {
|
|
|
|
//initialize variables
|
|
$value["event"] = $this->initialize_event_vars($value["event"]);
|
|
|
|
$mjBODY = array(
|
|
'FromEmail' => $this->cfg["sender"],
|
|
'FromName' => $this->cfg["fromName"],
|
|
'Subject' => str_replace($this->search, $this->replacements, $value["event_email_tpl"]->email_tpl_subject),
|
|
'Html-part' => customEmailFormat($value["event_email_tpl"]->email_tpl_detail, $value["event"]),
|
|
'Vars' => (array) $value["event"]
|
|
);
|
|
|
|
$mjBODY['Vars'] = array_merge($mjBODY['Vars'], $maildata["addVars"]);
|
|
$mjBODY['Vars']['event_url'] = $mjBODY['Vars']['event_url'].$value["event"]->event_id;
|
|
$mjBODY['Vars']['event_picture'] = $maildata["addVars"]['event_picture'].$value["event"]->event_picture;
|
|
$mjBODY['Recipients'] = array();
|
|
$email_type = "";
|
|
if ($value['event']->event_status !== 'CANCEL') {
|
|
if($value["event_email_tpl"]->email_type_id == 3){
|
|
$email_type = "foer";
|
|
} else if($value["event_email_tpl"]->email_type_id == 5){
|
|
$email_type = "four";
|
|
} else if($value["event_email_tpl"]->email_type_id == 8){
|
|
$email_type = "pscl";
|
|
} else {
|
|
$email_type = "forwl";
|
|
}
|
|
} else {
|
|
$email_type = "evcl";
|
|
}
|
|
foreach ($value["subscribers"] as $index => $subscriber) {
|
|
array_push($mjBODY['Recipients'], array(
|
|
'Email' => $subscriber->email_address,
|
|
'Name' => $subscriber->subscriber,
|
|
'Vars' => array(
|
|
'subscriber' => $subscriber->subscriber,
|
|
'subs_prenom' => $subscriber->subs_prenom,
|
|
'subs_nom' => $subscriber->subs_nom,
|
|
'new_tab_url' => "e/".$email_type."/".base64_encode($subscriber->subscriber_id."_".$value["event"]->event_id."_".$value["event"]->event_schedule_id."_".$subscriber->seats_reserved),
|
|
'email_address' => $subscriber->email_address,
|
|
'seats_reserved' => (($subscriber->seats_reserved > 1)?$subscriber->seats_reserved." places":$subscriber->seats_reserved." place")
|
|
)
|
|
));
|
|
|
|
array_push($emails, array(
|
|
"email_recipient_id" => $subscriber->email_recipient_id,
|
|
"email_address" => $subscriber->email_address,
|
|
"email_reference_id" => null,
|
|
"email_date_time" => date('Y-m-d H:i:s'),
|
|
"email_tpl_id" => $value["event_email_tpl"]->email_tpl_id,
|
|
"email_number_of_send_attempt" => $subscriber->email_number_of_send_attempt,
|
|
"email_status" => 0,
|
|
));
|
|
}
|
|
|
|
$sent = 0;
|
|
$failed = 0;
|
|
$response = $this->mj->post(Resources::$Email, array('body' => $mjBODY));
|
|
if ($response->success()) {
|
|
$msgSent = (object) $response->getData();
|
|
if($msgSent->Sent){
|
|
$processed_emails = array_column($msgSent->Sent, 'MessageID', 'Email');
|
|
foreach($emails as $idx => $val){
|
|
//sent emails
|
|
if(isset($processed_emails[$val["email_address"]]) && !empty($processed_emails[$val["email_address"]])){
|
|
$val["email_reference_id"] = $processed_emails[$val["email_address"]];
|
|
$val["email_number_of_send_attempt"] +=1;
|
|
$val["email_status"] = 1;//we need to set this to 5 instead of one, description matters here which is the "Sent!"
|
|
$val["email_description"] = "Resent!";
|
|
unset($val["email_address"]);
|
|
$sent++;
|
|
array_push($sent_emails, $val);
|
|
} else { //failed emails
|
|
$val["email_number_of_send_attempt"] += 1;
|
|
$val["email_status"] = 0;
|
|
$val["email_description"] = "Failed!";
|
|
unset($val["email_address"]);
|
|
$failed++;
|
|
array_push($failed_emails, $val);
|
|
}
|
|
}
|
|
unset($processed_emails);
|
|
$emails = array();
|
|
$mjLog .="Email type : ".($email_type == "evcl" ? "Cancelled Event" : "Resend || Paid Event, Sent")." : ".$sent.", Failed : ".$failed.", Event_id : ".$value["event"]->event_id.", Event_schedule_id : ".$value["event"]->event_schedule_id."\n";
|
|
} else {
|
|
$mjLog .="Email type : ".($email_type == "evcl" ? "Cancelled Event" : "Resend || Paid Event, Mj E-Code")." : ".$response->getStatus()." Event_id : ".$value["event"]->event_id.", Event_schedule_id : ".$value["event"]->event_schedule_id."\n";
|
|
}
|
|
} else {
|
|
$mjLog .="Email type : ".($email_type == "evcl" ? "Cancelled Event" : "Resend, Mj E-Code")." : ".$response->getStatus()." Event_id : ".$value["event"]->event_id.", Event_schedule_id : ".$value["event"]->event_schedule_id."\n";
|
|
}
|
|
unset($response);
|
|
} //end of main loop
|
|
return array("success" => true, "sent_emails" => $sent_emails, "failed_emails" => $failed_emails, "logs" => $mjLog);
|
|
}
|
|
|
|
public function send_success_email($event, $paymentFormData, $emailTemplate){
|
|
|
|
//initialize variables
|
|
$event = $this->initialize_event_vars($event);
|
|
$mjBODY = array(
|
|
'FromEmail' => $this->cfg["sender"],
|
|
'FromName' => $this->cfg["fromName"],
|
|
'Subject' => str_replace($this->search, $this->replacements, $emailTemplate->email_tpl_subject),
|
|
'Html-part' => urldecode($emailTemplate->email_tpl_detail),
|
|
'Vars' => (array) $event
|
|
);
|
|
$mjBODY['Recipients'] = array();
|
|
array_push($mjBODY['Recipients'], array(
|
|
'Email' => $paymentFormData->email,
|
|
'Name' =>$paymentFormData->fname .' '.$paymentFormData->name,
|
|
'Vars' => array(
|
|
//'subscriber' => $subscriber->subscriber,
|
|
'subs_prenom' => $paymentFormData->fname,
|
|
'subs_nom' => $paymentFormData->name,
|
|
'email_address' => $paymentFormData->email
|
|
)
|
|
));
|
|
|
|
$response = $this->mj->post(Resources::$Email, array('body' => $mjBODY));
|
|
return $response->getStatus();
|
|
}
|
|
|
|
public function send_distance_reminder_email($data){
|
|
//initialize variables
|
|
$event = $this->initialize_event_vars($data["event"]);
|
|
$emailTemplate = $data["event_email_tpl"];
|
|
$user = $data["subscriber"];
|
|
|
|
$mjBODY = array(
|
|
'FromEmail' => $this->cfg["sender"],
|
|
'FromName' => $this->cfg["fromName"],
|
|
'Subject' => str_replace($this->search, $this->replacements, $emailTemplate->email_tpl_subject),
|
|
'Html-part' => urldecode($emailTemplate->email_tpl_detail),
|
|
'Vars' => ['video_link' => $event->video_link, 'event_title' => $event->title]
|
|
);
|
|
$mjBODY['Recipients'] = array();
|
|
array_push($mjBODY['Recipients'], array(
|
|
'Email' => $user->email_address,
|
|
'Name' => $user->subs_prenom .' '.$user->subs_nom,
|
|
'Vars' => array(
|
|
'subscriber' => $user->subscriber,
|
|
'subs_prenom' => $user->subs_prenom,
|
|
'subs_nom' => $user->subs_nom,
|
|
'email_address' => $user->email_address
|
|
)
|
|
));
|
|
|
|
|
|
$response = $this->mj->post(Resources::$Email, array('body' => $mjBODY));
|
|
return $response->getStatus();
|
|
|
|
}
|
|
|
|
private function send_cancel_email($maildata){
|
|
$emails = array();
|
|
$sent_emails = array();
|
|
$failed_emails = array();
|
|
$mjLog = "";
|
|
|
|
foreach ($maildata["maildata"] as $key => $value) {
|
|
$s_r = 0;
|
|
//initialize variables
|
|
foreach ($value["subscribers"] as $index => $subscriber) {
|
|
$s_r += $subscriber->seats_reserved;
|
|
}
|
|
$value["event"] = $this->initialize_event_vars(array(
|
|
"seats_reserved" => $s_r,
|
|
"workshop_author" => $value["event"]->workshop_author,
|
|
"event_id" => $value["event"]->event_id
|
|
));
|
|
|
|
$mjBODY = array(
|
|
'FromEmail' => $this->cfg["sender"],
|
|
'FromName' => $this->cfg["fromName"],
|
|
'Subject' => str_replace($this->search, $this->replacements, $value["event_email_tpl"]->email_tpl_subject),
|
|
'Html-part' => customEmailFormat($value["event_email_tpl"]->email_tpl_detail, $value["event"]),
|
|
'Vars' => (array) $value["event"]
|
|
);
|
|
|
|
//$mjBODY['Vars'] = array_merge($mjBODY['Vars'], $maildata["addVars"]);
|
|
//$mjBODY['Vars']['event_url'] = $mjBODY['Vars']['event_url'].$value["event"]->event_id;
|
|
//$mjBODY['Vars']['event_picture'] = $maildata["addVars"]['event_picture'].$value["event"]->event_picture;
|
|
$mjBODY['Recipients'] = array();
|
|
|
|
foreach ($value["subscribers"] as $index => $subscriber) {
|
|
array_push($mjBODY['Recipients'], array(
|
|
'Email' => $subscriber->email_address,
|
|
'Name' => $subscriber->subscriber,
|
|
'Vars' => array(
|
|
//'subscriber' => $subscriber->subscriber,
|
|
'subs_prenom' => $subscriber->subscriber_first_name,
|
|
'subs_nom' => $subscriber->subscriber_last_name,
|
|
'email_address' => $subscriber->email_address
|
|
)
|
|
));
|
|
|
|
//prepare processed emails
|
|
array_push($emails, array(
|
|
//"email_recipient_id" => $subscriber->email_recipient_id,
|
|
"email_address" => $subscriber->email_address,
|
|
//"email_reference_id" => null,
|
|
"email_date_time" => date('Y-m-d H:i:s'),
|
|
"email_tpl_id" => $value["event_email_tpl"]->email_tpl_id,
|
|
//"email_number_of_send_attempt" => $subscriber->email_number_of_send_attempt,
|
|
"email_status" => 0,
|
|
));
|
|
}
|
|
|
|
$sent = 0;
|
|
$failed = 0;
|
|
$response = $this->mj->post(Resources::$Email, array('body' => $mjBODY));
|
|
if ($response->success()) {
|
|
$msgSent = (object) $response->getData();
|
|
if($msgSent->Sent){
|
|
$processed_emails = array_column($msgSent->Sent, 'MessageID', 'Email');
|
|
//return $processed_emails;
|
|
foreach($emails as $idx => $val){
|
|
if(isset($processed_emails[$val["email_address"]]) && !empty($processed_emails[$val["email_address"]])){
|
|
//$val["email_reference_id"] = $processed_emails[$val["email_address"]];
|
|
//$val["email_number_of_send_attempt"] +=1;
|
|
$val["email_status"] = 1;//we need to set this to 5 instead of one, description matters here which is the "Sent!"
|
|
//$val["email_description"] = "Sent!";
|
|
unset($val["email_address"]);
|
|
$sent++;
|
|
array_push($sent_emails, $val);
|
|
} else { //failed emails
|
|
//$val["email_number_of_send_attempt"] += 1;
|
|
$val["email_status"] = 0;
|
|
//$val["email_description"] = "Failed!";
|
|
unset($val["email_address"]);
|
|
$failed++;
|
|
array_push($failed_emails, $val);
|
|
}
|
|
}
|
|
unset($processed_emails);
|
|
$emails = array();
|
|
$mjLog .="Email type : Reminder, Sent : ".$sent.", Failed : ".$failed."\n";
|
|
} else {
|
|
$mjLog .="Email type : Reminder, Mj E-Code : ".$response->getStatus()."\n";
|
|
}
|
|
} else {
|
|
$mjLog .="Email type : Reminder, Mj E-Code : ".$response->getStatus()."\n";
|
|
}
|
|
unset($response);
|
|
} //end of main loop
|
|
|
|
return array("success" => true, "sent_emails" => $sent_emails, "failed_emails" => $failed_emails, "logs" => $mjLog);
|
|
}
|
|
|
|
protected function initialize_event_vars($vars){
|
|
$CI =& get_instance();
|
|
$this->search = array();
|
|
$this->replacements = array();
|
|
$Vars = array('event_reminder_date', 'subscriber','email_address','event_title',
|
|
'event_start_day_name','event_start_day','event_start_month',
|
|
'event_start_month_name','event_start_year','event_start_hour',
|
|
'seats_reserved','event_start_day_name', 'city', 'event_description',
|
|
'event_venue', 'event_place_name', 'event_address',
|
|
'event_postal_code', 'event_rate', 'day', 'addressee', 'subscriber_address',
|
|
'start_day', 'start_month', 'start_year',
|
|
'start_date_hour', 'event_url',
|
|
'new_tab_url', 'event_picture', 'workshop_author',
|
|
'subscriber_last_name', 'subscriber_first_name', 'order_number','event_rate',
|
|
'service_charge', 'mode_of_payment', 'order_date',
|
|
'vat','no_vat_amount','total_amount','start_date_time', 'commencement_de_lheure', 'date_complete', 'video_link');
|
|
|
|
//for translation
|
|
$toFR = array('day', 'event_start_month_name', 'event_start_day_name');
|
|
|
|
foreach ($vars as $key => $value) {
|
|
if(is_null($value) || empty(trim($value))) {
|
|
$value = "";
|
|
}
|
|
|
|
if (in_array($key, $Vars)) {
|
|
//translate to french
|
|
if(in_array($key, $toFR)){
|
|
$value = $CI->lang->line($value);
|
|
$vars->{$key} = $value;
|
|
}
|
|
|
|
if($key == 'date_complete') {
|
|
$month = ucfirst($CI->lang->line(date('F', strtotime($value))));
|
|
$day_name = ucfirst($CI->lang->line(date('l', strtotime($value))));
|
|
$day_num = date('j', strtotime($value));
|
|
$year = date('Y', strtotime($value));
|
|
$value = $day_name. ' '. $day_num. ' '. $month. ' '. $year;
|
|
$vars->{$key} = $value;
|
|
}
|
|
|
|
$this->search[] = "[[var:" . $key . "]]";
|
|
$this->replacements[] = $value;
|
|
}
|
|
}
|
|
|
|
return $vars;
|
|
}
|
|
}
|
|
|