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.
 
 
 
 
 
 

243 lines
9.6 KiB

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
use app\core\utils\Response;
class Event_assign_email_template extends MY_Controller {
protected $search = array();
protected $replacements = array();
public function __construct()
{
//parent::__construct();
$this->my_parent_controller();
Response::handleSessionTimeout("bo");
//load language files
$this->load_language_backoffice();
$this->lang->load('backoffice/events', 'fr');
$this->lang->load('backoffice/events_template_schedule', 'fr');
//for test email translations
$this->lang->load('frontoffice/subscribe', 'fr');
//load models
$this->load->model("event_email_template_mapping_model");
$this->load->model("event_email_template_mapping_by_event_schedule_model");
$this->load->model("user_model");
$this->load->model("event_email_template_model");
$this->load->model("event_registration_model");
}
//function to send test email
public function send_test_email($email, $email_type_id, $event_id, $event_schedule_id)
{
$this->load->library("mailjet_libr");
$this->load->model("event_model");
$event_info = $this->event_model->get_event_detail_for_test_email($event_schedule_id, $email_type_id);
$email_tpl = $this->event_email_template_model->get_current_event_email_template($event_id, $email_type_id, true);
if($email_tpl && countVal($event_info) > 0) {
$mailjet_response = $this->mailjet_libr->fo_send_template_email(array(
"message" => $email_tpl,
"vars" => $this->add_email_vars($email_type_id, $email, $event_info, 1)
));
if( $mailjet_response ){
output_to_json($this, array(
"mtype" => "success",
"message" => $this->lang->line("test_email_sent_success")
));
} else {
output_to_json($this, array(
"mtype" => "error",
"message" => $this->lang->line("test_email_sent_error")
));
}
} else {
output_to_json($this, array(
"mtype" => "error",
"message" => "Aucun template n'a été assigné"
));
}
}
private function add_email_vars($email_type_id, $email, $event_info, $seats_reserved){
$event_info->{"subscriber"} = "Test Account";
$event_info->{"subs_prenom"} = "Test";
$event_info->{"subs_nom"} = "Account";
$event_info->{"seats_reserved"} = ($seats_reserved <= 1)?$seats_reserved.' place': $seats_reserved.' places ';
$event_info->{"event_url"} = base_url('event_details?event_id='.$event_info->event_id);
switch ($email_type_id) {
case 3:
$email_type = "foer";
break;
case 5:
$email_type = "four";
break;
case 7:
$email_type = "evcl";
break;
case 8:
$email_type = "pscl";
break;
default:
$email_type = "pte";
break;
}
if ($email_type == "pte") {
$event_info->{"new_tab_url"} = "e/".$email_type."/".base64_encode($email."_".$email_type_id."_".$event_info->event_id."_".$event_info->event_schedule_id);
} else {
$event_info->{"new_tab_url"} = "e/".$email_type."/".base64_encode($email."_".$event_info->event_id."_".$event_info->event_schedule_id."_2");
}
$event_info->{"event_picture"} = 'resources/images/frontoffice/events/'.$event_info->event_picture;
$event_info->{"email_address"} = $email;
if (!isset($event_info->email_tpl_setting_sched) || !isset($event_info->email_tpl_setting_sched_by)) {
$event_info->email_tpl_setting_sched = '';
$event_info->email_tpl_setting_sched_by = '';
}
switch ($event_info->email_tpl_setting_sched_by) {
case 'DAYS':
$event_info->email_tpl_setting_sched_by = 'jour';
break;
case 'HOURS':
$event_info->email_tpl_setting_sched_by = 'heurs';
break;
case 'MINUTES':
$event_info->email_tpl_setting_sched_by = 'minutes';
break;
default:
$event_info->email_tpl_setting_sched_by = '';
break;
}
$event_info->{"event_reminder_date"} = $event_info->email_tpl_setting_sched.' '.$event_info->email_tpl_setting_sched_by;
return $event_info;
}
//update radio buttons for default event "YES or NO"
public function update_set_default_template( $event_id = null )
{
return output_to_json($this, array(
'updated' => $this->event_email_template_mapping_model->update_set_default_templates( $event_id ) ,
'mtype' => 'success',
'message' => "La mise à jour été prise en compte"
) );
}
//check radio buttons for default event email templates
public function get_set_default_template( $event_id = null )
{
$result = $this->event_email_template_mapping_model->get_set_default_templates( $event_id );
if( $result[0]->status > 0 )
$arr = array( 'active' => true );
else
$arr = array( 'active' => false );
return output_to_json($this, $arr );
}
public function remove_template_event_schedule($email_status_id, $type, $status)
{
switch($type)
{
case 'events' :
return output_to_json($this, array(
'updated' => $this->event_email_template_mapping_model->remove_template_event_schedules($email_status_id) ,
'mtype' => 'success',
'message' => "La mise à jour été prise en compte"
));
break;
case 'schedule' :
return output_to_json($this, array(
'updated' => $this->event_email_template_mapping_by_event_schedule_model->remove_template_event_schedules($email_status_id,$status) ,
'mtype' => 'success',
'message' => "La mise à jour été prise en compte"
));
break;
default :
echo "Aucune action n'a été spécifiée.";
exit(0);
break;
};
}
//create autocomplete search to choose email templates
public function search_by_template_id($email_type_id)
{
return output_to_json($this, $this->event_email_template_mapping_model->search_by_template_ids($email_type_id));
}
//insert or assign email templates for main event or event schedule(per date)
public function assign_template_event_schedule($type)
{
$message = array("mtype" => "error", "message" => "Quelque chose s'est mal passé!");
switch($type)
{
case 'events' :
$result = $this->event_email_template_mapping_model->assign_template_events();
if($result){
$message["mtype"]="success";
$message["message"]="Modèle assigné avec succès!";
}
return output_to_json($this, $message);
break;
case 'schedule' :
$result = $this->event_email_template_mapping_by_event_schedule_model->assign_template_events();
if($result){
$message["mtype"]="success";
$message["message"]="Modèle assigné avec succès!";
}
return output_to_json($this, $message);
break;
default :
return output_to_json($this, $message);
exit(0);
break;
};
}
public function reset_template_event_schedule($event_id_schedule,$email_type_id,$type, $event_id)
{
switch($type)
{
case 'one' :
return output_to_json($this, $this->event_email_template_mapping_by_event_schedule_model->_get_resetquerycount( $event_id_schedule,$email_type_id,$type, $event_id ) );
break;
case 'activate' :
return output_to_json($this, $this->event_email_template_mapping_by_event_schedule_model->reset_template_event_schedules( $event_id_schedule,$email_type_id,$type, $event_id ) );
break;
case 'schedule' :
return output_to_json($this, $this->event_email_template_mapping_by_event_schedule_model->reset_template_event_schedules( $event_id_schedule,$email_type_id,$type, $event_id ) );
break;
default :
echo "Aucune action n'a été spécifiée.";
exit(0);
break;
};
}
//create datatable and list of templates for events or event schedule
public function by_event($event_id_schedule_id, $type)
{
switch($type)
{
case 'events' :
return output_to_json($this, $this->event_email_template_mapping_model->get_table_event($event_id_schedule_id));
break;
case 'schedule' :
return output_to_json($this, $this->event_email_template_mapping_by_event_schedule_model->get_table_event($event_id_schedule_id));
break;
default :
echo "Aucune action n'a été spécifiée.";
exit(0);
break;
};
}
}