my_parent_controller(); //load language files $this->load_language_frontoffice(); $this->lang->load('frontoffice/subscribe', 'fr'); //load model $this->load->model("event_model"); $this->load->model("event_schedule_model"); $this->load->model('event_concurrent_process_model'); $this->load->model("user_activity_log_model"); $this->load->library("mailjet_libr"); } private function determine_action_type($event_id, $action_type){ Response::handleSessionTimeout("fo"); if($this->session->userdata('first_logged_in')) { $this->data["logged_in"]['rs_action'] = array( "process_type" => $action_type, "process_reference" => $event_id ); $this->session->set_userdata('first_logged_in', $this->data["logged_in"]); } else if($this->session->userdata('logged_in')) { $this->data["logged_in"]['rs_action'] = array( "process_type" => $action_type, "process_reference" => $event_id ); $this->session->set_userdata('logged_in', $this->data["logged_in"]); } } public function exitp(){ Response::handleSessionTimeout("fo"); if($this->input->post('event_id') && $this->input->post('process_id')) { $this->load->model('event_concurrent_process_model'); $check = $this->event_concurrent_process_model->update_process($this->data["logged_in"]['user_id'], $this->data["logged_in"]['login_id'], $this->input->post('event_id'), $this->input->post('process_type'), $this->input->post('process_id')); if($check) output_to_json($this, true); else output_to_json($this, false); } output_to_json($this, false); } public function validate(){ Response::handleSessionTimeout("fo"); $eventCategory = array_keys(EVENT_CATEGORY); // Input is not empty and category is valid if($this->input->post() && in_array($this->input->post('event_category'), $eventCategory)) { //check if process_id exists : bug fixed for #24568 if(!$this->isPaidEvent() && $this->input->post('process_id')) { //close previous process $rest = $this->event_concurrent_process_model->unlock_action_by_process_id($this->data['logged_in']['login_id'], $this->input->post('process_type'), $this->input->post('process_id')); unset($_POST['process_id']); } // Check if event is an online event! if( $this->event_schedule_model->is_online_event($this->input->post("event_id")) ) { return output_to_json($this, array( 'mtype' => "error", 'message' => "Cannot reserve in an online event" )); } if ($this->input->post("action") == "cancel") { $this->check_before_cancelling(); } else if($this->input->post("action") == "register" || $this->input->post("action") == "modify") { $this->check_before_register_or_modify(); } else { output_to_json($this, array( 'mtype' => "error", 'message' => "Unknown action." )); } } else { output_to_json($this, array( 'mtype' => "error", 'message' => "Unable to proceed." )); } } private function checkIfReservationCanBeByPassed() { if($this->input->post('bp') === "true") { //by pass validation, so user can reserve in wl in advanced! return true; } return false; } // Do not allow regular registration on paid event, they must register to La Botique private function isPaidEvent() { $process_types = [1, 2, 6]; // register, cancel registration return $this->input->post('event_category') && $this->input->post('event_category') == 'PAID_EVENT' && in_array((int) $this->input->post('process_type'), $process_types); } private function check_before_cancelling() { if($this->input->post() && $this->input->post('action') == "cancel" && ($this->input->post('process_type') == 2 || $this->input->post('process_type') == 4)) { $is_locked = $this->event_concurrent_process_model->has_activity($this->data['logged_in']['user_id'], $this->data['logged_in']['login_id'], $this->input->post('process_type'), $this->input->post('event_id')); /* if cancellation process is being done at the same time, on the same account with different login session */ if($is_locked) { output_to_json($this, array( 'mtype' => "info", 'message' => $this->lang->line('logged_on_another_device') )); } else { //check if process_id is still valid $this->check_process_id_validity(); $event_details = $this->event_schedule_model->event_schedule_details($this->input->post('event_id'), $this->input->post('event_schedule_id'), $this->input->post('action')); /* check if event exists */ if(countVal($event_details) > 0) { if(($event_details->back_office_status >= BO_STAT['fer']) && !(UserAuth::isLoggedInAsSubscriber())){ //check if event arent locked, closed, terminated, archived or deleted output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line("button_not_updated") )); } else { /* check if user has selected number of seats to be cancelled */ if($this->input->post("seats_cancelled") && $this->input->post("seats_cancelled") > 0) { /* check whether seats to be cancelled are up to date or not First, Check what type of registration is about to be cancelled through process_type reg_type = 1, for normal registration reg_type = 2, for waiting list registration reg_type = 3, Cancellation Process Type 1 = Event Registration, 2 = Cancel Event Registration, 3 = Register to Wait list, 4 = Cancel Wait list Registration, 5 = Update Profile Now, check the current reserved seats before proceeding */ $this->load->model('event_registration_model'); $this->load->model('event_wait_list_model'); $current_seats_reserved = $this->input->post("process_type") == PROCESS_TYPE['cancel_reg'] ? $this->event_registration_model->count_all_event_subscription( $this->data['logged_in']['user_id'], $this->input->post('event_schedule_id'), $this->input->post('event_id'), 2, $this->input->post("seats_reserved")) : ( ($this->input->post("process_type") == PROCESS_TYPE['cancel_wl_reg']) ? $this->event_wait_list_model->count_all_waitlist_subscription( $this->data['logged_in']['user_id'], $this->input->post('event_schedule_id'), $this->input->post('event_id'), 2, $this->input->post("seats_reserved")) : 0 ); /* check if there stil seats to be cancelled */ if($current_seats_reserved > 0 && $current_seats_reserved >= $this->input->post("seats_cancelled")) { //determine action type $this->determine_action_type($this->input->post('event_id'), $this->input->post("process_type")); // finally, if validated, proceed to cancellation $this->deregister(); } else { output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line("button_not_updated") )); } } else { $this->get_all_registration_details(); } // end of else if seats cancelled not defined }//end of else if seats cancelled is not defined } else{ output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line("button_not_updated") )); } } } else{ output_to_json($this, array( 'mtype' => "session_timeout", 'message' => "Vous n'êtes pas connecté" )); } } private function check_before_register_or_modify() { if($this->input->post() && ($this->input->post('action') == "register" || $this->input->post('action') == "modify" ) && ($this->input->post('process_type') == 1 || $this->input->post('process_type') == 3 || $this->input->post('process_type') == 6 || $this->input->post('process_type') == 7)) { // We do not appply button lock on paid_event $is_locked = $this->event_concurrent_process_model->has_activity($this->data['logged_in']['user_id'], $this->data['logged_in']['login_id'], $this->input->post('process_type'), $this->input->post('event_id')); /* if cancellation process is being done at the same time, on the same account with different login session */ if($is_locked) { output_to_json($this, array( 'mtype' => "info", 'message' => $this->lang->line('logged_on_another_device') )); } else {//locked action when not locked //check if process_id is still valid $this->check_process_id_validity(); //check if user is allowed to book for more than 1 date per event if($this->event_schedule_model->continue_registration($this->input->post('event_id'), $this->data['logged_in']['user_id'], $this->input->post('action'), $this->input->post('reg_type'))) { //check if can still reserved $can_still_reserved = $this->event_model->check_seats($this->input->post('event_id'), $this->input->post('reg_type'), $this->checkIfReservationCanBeByPassed(), $this->input->post('session_type')); if($can_still_reserved) { //get event details seats_reserved_orig //$event_sched_details = $this->event_schedule_model->event_schedule_details($this->input->post('event_id'), $this->input->post('event_schedule_id'), $this->input->post('request_type')); $event_sched_details = $this->event_schedule_model->event_schedule_details($this->input->post('event_id'), $this->input->post('request_type')); //get reservation information $reservation_details = $this->get_reservation_details($this->input->post('action'), $this->input->post('reg_type'), $this->input->post('event_id')); /* check if event exists */ if(countVal($event_sched_details) > 0) { //check if event arent locked, closed, terminated, archived or deleted if( $event_sched_details->back_office_status >= 3 || ($event_sched_details->event_status == 'FULL' && $event_sched_details->remaining_seat >=0 && $this->input->post('process_type') == 1) || ($event_sched_details->event_status == 'FULL' && $this->input->post('process_type') == 3) ){ output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line("button_not_updated") )); } else { if($this->input->post("seats_reserved") && $this->input->post("seats_reserved") > 0) { //check subscription $subscribed = $this->check_subscription($this->input->post('event_id'), $this->input->post('event_schedule_id'), $this->input->post("check_subscription"), 0); if($this->input->post("action") == "register"){ if($subscribed){ output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line('already_registered') )); } else { //if registration is valid if($this->revalidate_reservation($this->input->post('event_id'), $this->input->post('event_schedule_id'), $this->input->post("seats_reserved"), $this->input->post("reg_type"), $this->checkIfReservationCanBeByPassed())) { //continue with the reservation if($this->input->post("reg_type") == 1 || $this->input->post("reg_type") == 2){ //determine action type $this->determine_action_type($this->input->post('event_id'), $this->input->post("process_type")); //finally, got to reserve $this->register(); } else{ output_to_json($this, array( 'mtype' => "error", 'message' => "Unknown registration type!" )); } } } //not yet registered } else if($this->input->post("action") == "modify"){ if(!$subscribed){ output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line('already_registered'), )); } else { //do not allow modification of reservation once reg_type did not match with the subcription in the DB if($subscribed != $this->input->post("reg_type")){ output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line("button_not_updated") )); } else { //if action is valid if($this->revalidate_reservation($this->input->post('event_id'), $this->input->post('event_schedule_id'), $this->input->post("seats_reserved"), $this->input->post("reg_type"), $this->checkIfReservationCanBeByPassed())) { //continue with modification of reservation if($this->input->post("reg_type") == 1 || $this->input->post("reg_type") == 2){ //determine action type $this->determine_action_type($this->input->post('event_id'), $this->input->post("process_type")); //finally, got to reserve $this->register(); } else{ //check subscription $subscribed = $this->check_subscription($this->input->post('event_id'), $this->input->post('event_schedule_id'), $this->input->post("check_subscription"), $this->input->post('seats_reserved_orig')); if(!$subsribed) { output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line("button_not_updated") )); } else { output_to_json($this, array( 'mtype' => "error", 'message' => "Unknown registration type!" )); } } } } } } else { output_to_json($this, array( 'mtype' => "error", 'message' => "Undefined action! Try again later." )); } } else{ //locked action when not locked $check_process = $this->event_concurrent_process_model->lock_or_add_process($this->data['logged_in']['user_id'], $this->data['logged_in']['login_id'], $this->input->post('process_type'), $this->input->post('event_id')); if($check_process['status']){ //determine action type $this->determine_action_type($this->input->post('event_id'), $this->input->post("process_type")); output_to_json($this, array( "mtype" => "success", "message" => "Vous n'êtes pas connecté", 'mdata' => ($reservation_details)? array("event_schedule" => $event_sched_details, "reservations" =>$reservation_details):$event_sched_details, 'process_id' => $check_process['process_id'] ?? null, 'logged_out' => !UserAuth::isAuth() )); } else { output_to_json($this, array( 'mtype' => "info", 'message' => $this->lang->line('logged_on_another_device') )); } } } //event is not closed } else{ output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line("button_not_updated") )); } //end of else event exists } else { //subscriber cannot reserved due to no available seats output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line("button_not_updated") )); } } else { output_to_json($this, array( 'mtype' => "error", 'message' => "You have reached the maximum reservation allowed per subscriber in this event." )); } }//end of else not locked } else { output_to_json($this, array( 'mtype' => "session_timeout", 'message' => "Vous n'êtes pas connecté" )); } } private function check_process_id_validity(){ if(isset($_POST['process_id']) && !empty($_POST['process_id'])){ //check if process_id is still active; $check = $this->event_concurrent_process_model->check_process_id_validity($this->data["logged_in"]['login_id'], $this->input->post('process_id'), $this->input->post('process_type'), $this->input->post('event_id')); if($check<=0){ output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line("button_not_updated") )); } } } private function revalidate_reservation($event_id, $event_schedule_id, $seats_reserved, $reg_type, $byPassRegularReservation){ $availability = $this->event_model->check_availability($event_id, $event_schedule_id, $seats_reserved, $reg_type, $byPassRegularReservation); if($availability == 4){ output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line("button_not_updated") )); } else if($availability == 5) { output_to_json($this, array( 'mtype' => "error", 'message' => "Registration to this event is disabled!", )); } else if($availability == $reg_type){ return true; } else if($availability == 3) { output_to_json($this, array( 'mtype' => "error", 'message' => "You cannot register to waiting list yet! Please reload." )); } else if($availability == 6){ output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line('waiting_list'), 'mdata' => 1 )); } else { output_to_json($this, array( 'mtype' => "error", 'message' => "Registration is not allowed at the moment!" )); } } public function check_subscription($event_id, $event_schedule_id, $check_subscription=2, $seats_reserved_orig=0) { $this->load->model('event_registration_model'); $this->load->model('event_wait_list_model'); $subscribed = $this->event_registration_model->count_all_event_subscription($this->data['logged_in']['user_id'], $event_schedule_id, $event_id, 2, $seats_reserved_orig); if($subscribed) { return 1; } else { if($check_subscription < 2){ $subscribed_waitlist = $this->event_wait_list_model->count_all_waitlist_subscription($this->data['logged_in']['user_id'], $event_schedule_id, $event_id, 2, $seats_reserved_orig); if($subscribed_waitlist) { return 2; }else { return false; } } return false; } } private function get_reservation_details($action=false, $reg_type=false, $event_id){ $this->load->model('event_wait_list_model'); $this->load->model('event_registration_model'); $user_id = $this->data['logged_in']['user_id']; if($action && $reg_type){ if($reg_type == 1 && $action == "modify") { return $this->event_registration_model->get_registration_details($user_id, $event_id); } else if($reg_type == 2 && $action == "modify"){ return $this->event_wait_list_model->get_waitlist_registration_details($user_id, $event_id); } } return false; } public function get_all_registration_details(){ if(!UserAuth::isAuth()) { output_to_json($this, array( 'mtype' => "session_timeout", 'message' => "Vous n'êtes pas connecté", )); } else { if($this->input->post('event_id')){ $event_status = $this->event_schedule_model->get_all_registration_details($this->input->post('event_id'), $this->input->post('event_schedule_id'), $this->input->post('reg_type'), $this->data['logged_in']['user_id']); if($event_status) { //locked action when not locked $check_process = $this->event_concurrent_process_model->lock_or_add_process($this->data['logged_in']['user_id'], $this->data['logged_in']['login_id'], $this->input->post('process_type'), $this->input->post('event_id')); if($check_process['status']) { //determine action type $this->determine_action_type($this->input->post('event_id'), $this->input->post("process_type")); output_to_json($this, array( 'mtype' => "success", 'message' => "Got Current Event", 'mdata' => $event_status, 'process_id' => $check_process['process_id'] ?? null )); } else { output_to_json($this, array( 'mtype' => "info", 'message' => $this->lang->line('logged_on_another_device') )); } } else { output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line("button_not_updated") )); } } else { output_to_json($this, array( 'mtype' => "error", 'message' => $this->lang->line("button_not_updated") )); } } } private function deregister() { if( $this->event_schedule_model->is_paid_event($this->input->post("event_id")) && $this->isPaidEvent() ) { return output_to_json($this, array( 'mtype' => "error", 'message' => "Cannot cancel reservation for Paid event" )); } if($this->input->post() && $this->input->post('seats_cancelled') && $this->data['logged_in']['user_id']){ $this->load->model("event_deregistration_model"); $client_session = $this->data['logged_in']; $cancellation_info =$this->input->post(); $this->set_user_data(); $cancellation_info["login_id"] = $client_session['login_id']; $cancellation_info["user_id"] = $client_session['user_id']; $cancellation_info['user_agent'] = $this->data['agent']; $data = array(); if($cancellation_info["reg_type"] == REG_TYPE['normal_reg']) { $data = $this->email_unregistered($cancellation_info); } else if($cancellation_info["reg_type"] == REG_TYPE['waitlist_reg']) { $data = $this->email_unregistered_waitlist($cancellation_info); } if($data["mtype"] == false) { //unlock process $this->unlock_process($cancellation_info); output_to_json($this, array( "mtype" => "error", "message" => "Reservation not cancelled. Please try again!", "mdata" => $data["message"] )); }else { if($cancellation_info["seats_reserved"]==$cancellation_info["seats_cancelled"]){ output_to_json($this, array( "mtype" => "success", "message" => ($cancellation_info["reg_type"]==1)?$this->lang->line('unsubscribed'):$this->lang->line('unsubscribed_waitlist') )); }else{ output_to_json($this, array( "mtype" => "success", "message" => ($cancellation_info["reg_type"]==1)?$this->lang->line('partial_unsubscribed'):$this->lang->line('partial_unsubscribed_waitlist') )); } } }else { //unlock process $this->unlock_process($cancellation_info); output_to_json($this, array( "mtype" => "error", "message" => "Reservation not cancelled. Please try again!" )); } } private function register() { if( $this->event_schedule_model->is_paid_event($this->input->post("event_id")) && $this->isPaidEvent()) { return output_to_json($this, array( 'mtype' => "error", 'message' => "Cannot reserve in Paid event" )); } $this->set_user_data(); $registration = array( "event_id" => $this->input->post('event_id'), "process_type" => $this->input->post('process_type'), "process_id" => $this->input->post('process_id'), "seat_feature" => $this->input->post('seat_feature'), "action" => $this->input->post('action'), "reg_type" => $this->input->post('reg_type'), "user_id" => $this->data['logged_in']['user_id'], "login_id" => $this->data['logged_in']['login_id'], "seats_reserved" => $this->input->post('seats_reserved'), //"event_schedule_id" => $this->input->post('event_schedule_id'), "guest_emails" => $this->input->post('guest_emails') ?? '', "user_agent" => $this->data['agent'], "is_user_moderated" => $this->input->post('is_user_moderated')?? 0 ); if($this->input->post("reg_type") == 1){ $this->load->model("event_registration_model"); if($registration['action'] == "register"){ $this->email_registered($registration); } else { $this->modify_email_registered($registration); } } else if($this->input->post("reg_type") == 2){ $this->load->model('event_wait_list_model'); //check if the waitinglist reservation is from Moderation(Moderated but can reserve in WL in advanced) if($this->checkIfReservationCanBeByPassed()){ $registration["isModeratedButAllowedInWL"] = 1; } if($registration['action'] == "register"){ $this->email_registered_waitlist($registration); } else { //modify $this->modify_email_registered_waitlist($registration); } } } private function email_registered($registration) { $this->load->model("user_subscriber_model"); $this->load->model("event_registration_model"); $this->load->model('event_email_template_model'); $this->load->model('event_email_recipient_model'); $event_info = $this->event_model->event_details_email($registration['event_id']); $user_info = $this->user_subscriber_model->email_registered($registration['user_id']); if(countVal($user_info) > 0 && countVal($event_info) >0) { $registered = $this->event_registration_model->register($registration); //send email when reservation is successfull if($registered){ $email_tpl = $this->event_email_template_model->get_current_event_email_template($registration['event_id'], 3, true); $mailjet_response = false; if(countVal($email_tpl) > 0) { $mailjet_response = $this->mailjet_libr->fo_send_template_email(array( "message" => $email_tpl, "vars" => $this->add_email_vars('foer', $user_info, $event_info, $registration['seats_reserved']) )); if($mailjet_response){ //add email logs $mailjet_response["event_id"] = $registration['event_id']; $mailjet_response["reference_id"] = $registered; $mailjet_response["email_type_id"] = 3; $mailjet_response["email_tpl_id"] = $email_tpl->email_tpl_id; $result = $this->event_email_recipient_model->add_email_logs($mailjet_response); } } $result = array ( 'mtype' => "success", 'message' => $this->lang->line('subscribed'), // 'mdata' => $mailjet_response//array()// ); } else { //unlock process $this->unlock_process($registration); $result = array ( 'mtype' => "error", 'message' => "Error - Not registered", 'mdata' => $mailjet_response//array() ); } output_to_json($this, $result); } else { //unlock process $this->unlock_process($registration); output_to_json($this, array ( 'mtype' => "error", 'message' => "No email to send!" )); } } /*modify email registration*/ private function modify_email_registered($registration) { $this->load->model("event_registration_model"); $this->set_user_data(); $registered = $this->event_registration_model->register($registration); if($registered) { $send_mod_email = $this->email_modified($registration); $act_log = $this->user_activity_log_model->add_activity_log(array( "description" => "Modified event reservations", "user_id" => $registration["user_id"], "action" => "EDIT", "table_origin" => "event_resgitration", "reference_id" => $registered )); output_to_json($this, array ( 'mtype' => "success", 'message' => "Vous avez ajouté des places à votre réservation.", 'mdata' => 5 )); } else { //unlock process $this->unlock_process($registration); output_to_json($this, array ( 'mtype' => "error", 'message' => "Something went wrong!", 'mdata' => 5 )); } } private function email_modified($modification) { $this->load->model('user_subscriber_model'); $this->load->model('event_registration_model'); $this->load->model('event_deregistration_model'); $this->load->model('event_email_template_model'); $seats_reserved = $this->event_registration_model->seats_reserved($modification['user_id'], $modification['event_schedule_id']); if($seats_reserved <= 0){ return array ( 'mtype' => false, 'message' => "No reservation to cancel. Please try again!" ); } else { return $this->send_email_on_modification_partial($modification, $seats_reserved); } } private function email_unregistered($cancellation) { $this->load->model('user_subscriber_model'); $this->load->model('event_registration_model'); $this->load->model('event_deregistration_model'); $this->load->model('event_email_template_model'); $seats_reserved = $this->event_registration_model->seats_reserved($cancellation['user_id'], $cancellation['event_schedule_id']); if($seats_reserved <= 0){ return array ( 'mtype' => false, 'message' => "No reservation to cancel. Please try again!" ); } else { if($cancellation["seats_cancelled"] != $seats_reserved){ $this->send_email_on_deregistration_partial($cancellation, $seats_reserved); return array ( 'mtype' => true, 'message' => $this->lang->line('unsubscribed') ); } else { $this->send_email_on_deregistration($cancellation, $seats_reserved); return array ( 'mtype' => true, 'message' => $this->lang->line('unsubscribed') ); } } } private function send_email_on_modification_partial($modification, $seats_reserved){ $this->load->model('event_email_recipient_model'); $event_info = $this->event_model->event_details_email($modification["event_schedule_id"]); $user_info = $this->user_subscriber_model->email_registered($modification['user_id']); if(countVal($user_info) > 0 && countVal($event_info) >0){ $email_tpl = $this->event_email_template_model->get_current_event_email_template($modification['event_id'], $modification["event_schedule_id"], 5, true, 8); $mailjet_response = false; if(countVal($email_tpl) > 0){ $mailjet_response = $this->mailjet_libr->fo_send_template_email(array( "message" => $email_tpl, "vars" => $this->add_email_vars('pscl', $user_info, $event_info, ($seats_reserved)) )); } //send email even when email template is dissabled if($mailjet_response || countVal($email_tpl) <=0) { } else { //unlock process $this->unlock_process($modification); return array ( 'mtype' => false, 'message' => "Something went wrong. Email not sent!" ); } } else { //unlock process $this->unlock_process($modification); return array ( 'mtype' => false, 'message' => "No email to send!" ); } } private function send_email_on_deregistration_partial($cancellation, $seats_reserved) { $update_status = UserAuth::isLoggedInAsSubscriber()? false:true; $this->load->model('event_email_recipient_model'); $deregistered = $this->event_deregistration_model->deregister($cancellation, $update_status); $event_info = $this->event_model->event_details_email($cancellation["event_schedule_id"]); $user_info = $this->user_subscriber_model->email_registered($cancellation['user_id']); if(countVal($user_info) > 0 && countVal($event_info) >0){ $seats_reserved -= $cancellation["seats_cancelled"]; //send email after deregistration is successfull if($deregistered){ $email_tpl = $this->event_email_template_model->get_current_event_email_template($cancellation['event_id'], $cancellation["event_schedule_id"], 5, true, 8); $mailjet_response = false; if(countVal($email_tpl) > 0) { $mailjet_response = $this->mailjet_libr->fo_send_template_email(array( "message" => $email_tpl, "vars" => $this->add_email_vars('pscl', $user_info, $event_info, ($seats_reserved)) )); if($mailjet_response){ //add email logs $mailjet_response["event_schedule_id"] = $cancellation['event_schedule_id']; $mailjet_response["reference_id"] = $deregistered; $mailjet_response["email_type_id"] = 5; $mailjet_response["email_tpl_id"] = $email_tpl->email_tpl_id; $result = $this->event_email_recipient_model->add_email_logs($mailjet_response); } } $this->event_model->reopen_event($cancellation['event_schedule_id']); return array ( 'mtype' => true, 'message' => $this->lang->line('unsubscribed') ); } else { //unlock process $this->unlock_process($cancellation); return array ( 'mtype' => false, 'message' => "Reservation not cancelled. Please try again!" ); } } else { //unlock process $this->unlock_process($cancellation); return array ( 'mtype' => false, 'message' => "No email to send!" ); } } private function send_email_on_deregistration($cancellation, $seats_reserved){ $this->load->model('event_email_recipient_model'); $event_info = $this->event_model->event_details_email($cancellation["event_schedule_id"]); $user_info = $this->user_subscriber_model->email_registered($cancellation['user_id']); if(countVal($user_info) > 0 && countVal($event_info) >0) { $update_status = UserAuth::isLoggedInAsSubscriber()? false:true; $deregistered = $this->event_deregistration_model->deregister($cancellation, $update_status); //send email when deregistration is successfull if($deregistered){ $email_tpl = $this->event_email_template_model->get_current_event_email_template($cancellation['event_id'], $cancellation["event_schedule_id"], 5, true); $mailjet_response = false; if(countVal($email_tpl) > 0) { $mailjet_response = $this->mailjet_libr->fo_send_template_email(array( "message" => $email_tpl, "vars" => $this->add_email_vars('four', $user_info, $event_info, $seats_reserved) )); if($mailjet_response){ //add email logs $mailjet_response["event_schedule_id"] = $cancellation['event_schedule_id']; $mailjet_response["reference_id"] = $deregistered; $mailjet_response["email_type_id"] = 5; $mailjet_response["email_tpl_id"] = $email_tpl->email_tpl_id; $result = $this->event_email_recipient_model->add_email_logs($mailjet_response); } } $this->event_model->reopen_event($cancellation['event_schedule_id']); return array ( 'mtype' => true, 'message' => $this->lang->line('unsubscribed') ); } else { //unlock process $this->unlock_process($cancellation); return array ( 'mtype' => false, 'message' => "Reservation not cancelled. Please try again!" ); } } else { //unlock process $this->unlock_process($cancellation); return array ( 'mtype' => false, 'message' => "No email to send!" ); } } private function email_registered_waitlist($registration) { $this->load->model("user_subscriber_model"); $this->load->model("user_model"); $this->load->model('event_email_template_model'); $this->load->model('event_wait_list_model'); $this->load->model('event_email_recipient_model'); $event_info = $this->event_model->event_details_email($registration['event_schedule_id']); $user_info = $this->user_subscriber_model->email_registered($registration['user_id']); if(countVal($user_info) > 0 && countVal($event_info) >0) { $registered = $this->event_wait_list_model->register_waitlist($registration); //send email when registration to waitlist is successfull if($registered) { $email_tpl = $this->event_email_template_model->get_current_event_email_template($registration['event_id'], $registration['event_schedule_id'], 6, true); $mailjet_response = false; if(countVal($email_tpl) > 0) { $mailjet_response = $this->mailjet_libr->fo_send_template_email(array( "message" => $email_tpl, "vars" => $this->add_email_vars('forwl', $user_info, $event_info, $registration['seats_reserved']) )); if($mailjet_response){ //add email logs $mailjet_response["event_schedule_id"] = $registration['event_schedule_id']; $mailjet_response["reference_id"] = $registered; $mailjet_response["email_type_id"] = 6; $mailjet_response["email_tpl_id"] = $email_tpl->email_tpl_id; $result = $this->event_email_recipient_model->add_email_logs($mailjet_response); } } $result = array ( 'mtype' => "success", 'message' => $this->lang->line('subscribed_waitlist'), 'mdata' => 5 ); } else { //unlock process $this->unlock_process($registration); $result = array ( 'mtype' => "error", 'message' => "Something went wron!", 'mdata' => 5 ); } output_to_json($this, $result); } else { //unlock process $this->unlock_process($registration); output_to_json($this, array ( 'mtype' => "error", 'message' => "No email to send!", 'mdata' => 5 )); } } private function email_unregistered_waitlist($cancellation) { $update_status = UserAuth::isLoggedInAsSubscriber()? false:true; $this->load->model('event_wait_list_deregistration_model'); $deregistered = $this->event_wait_list_deregistration_model->deregister_waitlist($cancellation, $update_status); if($deregistered){ return array( 'mtype' => true, 'message' => $this->lang->line('unsubscribed_waitlist') ); } else { //unlock process $this->unlock_process($cancellation); return array( 'mtype' => false, 'message' => "Reservation for waiting list not cancelled. Please try again!" ); } } /*modify email waiting list registration*/ private function modify_email_registered_waitlist($registration) { $this->load->model("event_wait_list_model"); $registered = $this->event_wait_list_model->register_waitlist($registration); if($registered) { $act_log = $this->user_activity_log_model->add_activity_log(array( "description" => "Modified event waiting list reservations", "user_id" => $registration["user_id"], "action" => "EDIT", "table_origin" => "event_wait_list", "reference_id" => $registered )); output_to_json($this, array ( 'mtype' => "success", 'message' => "Vous avez ajouté des places à votre inscription sur liste d'attente.", 'mdata' => 5 )); } else { //unlock process $this->unlock_process($registration); output_to_json($this, array ( 'mtype' => "error", 'message' => "Something went wrong!", 'mdata' => 5 )); } } public function revalidate(){ Response::handleSessionTimeout("fo"); if((isset($_POST['action']) && !empty($_POST['action'])) && (isset($_POST['event_id']) && !empty($_POST['event_id'])) && (isset($_POST['process_type']) && !empty($_POST['process_type'])) && (isset($_POST['process_id']) && !empty($_POST['process_id']))){ $this->lock_or_unlock_process(); } else{ output_to_json($this, array ( 'mtype' => "error", 'message' => "Not allowed to continue the process!" )); } } private function lock_or_unlock_process(){ if($this->input->post("action") == 1){ //LOCKED output_to_json($this, $this->event_concurrent_process_model->lock_or_add_process($this->data['logged_in']['user_id'], $this->data['logged_in']['login_id'], $this->input->post('process_type'), $this->input->post('event_id'))); } else if($this->input->post("action") == 2){ //UNLOCKED output_to_json($this, array ($this->event_concurrent_process_model->unlock_action($this->data['logged_in']['user_id'], $this->data['logged_in']['login_id'], $this->input->post('event_id'), $this->input->post('process_type'), $this->input->post('process_id')))); } } private function unlock_process($data){ Response::handleSessionTimeout("fo"); $this->event_concurrent_process_model->unlock_action($data['user_id'], $data['login_id'], $data['event_id'], $data['process_type'], $data['process_id']); } private function set_user_data(){ // User Agent if ($this->agent->is_browser()){ $this->data['agent'] = $this->agent->browser().' '.$this->agent->version(); } elseif ($this->agent->is_robot()){ $this->data['agent'] = $this->agent->robot(); } elseif ($this->agent->is_mobile()){ $this->data['agent'] = $this->agent->mobile(); } else { $this->data['agent'] = 'Unidentified User Agent'; } } public function page_visit() { $this->load->model('event_page_visit_model'); $event_id = $this->input->post('event_id'); $client_session = $this->data["logged_in"]; if(!UserAuth::isAuth()) $page_visitor = NULL; else $page_visitor = $client_session["user_id"]; $this->event_page_visit_model->page_visit($event_id, $page_visitor); } public function save_link_to_cookie() { $this->load->helper('cookie'); $this->delete_link_cookie(); $event_id = $this->input->post('event_id'); $event_type = $this->event_model->save_link_to_cookie($event_id); $cookie_eventpage = array( 'name' => 'eventpage', 'value' => json_encode(array( "event_link" => base_url('event_details?event_id='.$event_id), "event_type" => $event_type )), 'expire' => 0, // time() + (86400 * 30), 'prefix' => $this->config->item('sess_cookie_name').'_' ); set_cookie($cookie_eventpage); output_to_json($this, array( "mtype" => "success", "message" => "Link Cookie Created!" )); } public function clear_link_cookie() { $this->delete_link_cookie(); } private function delete_link_cookie() { delete_cookie($this->config->item('sess_cookie_name').'_eventpage'); } private function add_email_vars($action, $user_info, $event_info, $seats_reserved){ $event_info->{"subscriber"} = $user_info->first_name." ".$user_info->last_name; $event_info->{"subs_prenom"} = $user_info->first_name; $event_info->{"subs_nom"} = $user_info->last_name; $event_info->{"seats_reserved"} = ($seats_reserved <= 1)?$seats_reserved.' place': $seats_reserved.' places '; $event_info->{"event_url"} = 'event_details?event_id='.$event_info->event_id; $event_info->{"new_tab_url"} = "e/".$action."/".base64_encode($user_info->user_id."_".$event_info->event_id."_".$event_info->event_schedule_id."_".$seats_reserved); $event_info->{"event_picture"} = 'resources/images/frontoffice/events/'.$event_info->event_picture; $event_info->{"email_address"} = $user_info->email_address; return $event_info; } }