2020-10-21 21:37:47 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
|
|
|
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.4.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
use EA\Engine\Notifications\Email as EmailClient;
|
|
|
|
use EA\Engine\Types\Email;
|
|
|
|
use EA\Engine\Types\Text;
|
|
|
|
use EA\Engine\Types\Url;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Notifications
|
|
|
|
*
|
|
|
|
* Handles the system notifications (mostly related to scheduling changes).
|
|
|
|
*/
|
|
|
|
class Notifications {
|
|
|
|
/**
|
2020-11-16 11:29:36 +03:00
|
|
|
* @var EA_Controller
|
2020-10-21 21:37:47 +03:00
|
|
|
*/
|
|
|
|
protected $CI;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifications constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->CI =& get_instance();
|
2020-11-16 12:47:10 +03:00
|
|
|
|
2020-10-21 21:37:47 +03:00
|
|
|
$this->CI->load->model('providers_model');
|
|
|
|
$this->CI->load->model('secretaries_model');
|
|
|
|
$this->CI->load->model('secretaries_model');
|
|
|
|
$this->CI->load->model('admins_model');
|
|
|
|
$this->CI->load->model('appointments_model');
|
|
|
|
$this->CI->load->model('settings_model');
|
2020-11-16 12:47:10 +03:00
|
|
|
|
2020-10-21 21:37:47 +03:00
|
|
|
$this->CI->load->library('ics_file');
|
2020-11-16 12:47:10 +03:00
|
|
|
$this->CI->load->library('timezones');
|
|
|
|
|
|
|
|
$this->CI->config->load('email');
|
2020-10-21 21:37:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send the required notifications, related to an appointment creation/modification.
|
|
|
|
*
|
|
|
|
* @param array $appointment Appointment record.
|
|
|
|
* @param array $service Service record.
|
|
|
|
* @param array $provider Provider record.
|
|
|
|
* @param array $customer Customer record.
|
|
|
|
* @param array $settings Required settings for the notification content.
|
|
|
|
* @param bool|false $manage_mode
|
|
|
|
*/
|
|
|
|
public function notify_appointment_saved($appointment, $service, $provider, $customer, $settings, $manage_mode = FALSE)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$email = new EmailClient($this->CI, $this->CI->config->config);
|
|
|
|
|
2020-11-16 12:47:10 +03:00
|
|
|
if ($manage_mode)
|
2020-10-21 21:37:47 +03:00
|
|
|
{
|
|
|
|
$customer_title = new Text(lang('appointment_changes_saved'));
|
|
|
|
$customer_message = new Text('');
|
|
|
|
$provider_title = new Text(lang('appointment_details_changed'));
|
|
|
|
$provider_message = new Text('');
|
|
|
|
}
|
2020-11-16 12:47:10 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$customer_title = new Text(lang('appointment_booked'));
|
|
|
|
$customer_message = new Text(lang('thank_you_for_appointment'));
|
|
|
|
$provider_title = new Text(lang('appointment_added_to_your_plan'));
|
|
|
|
$provider_message = new Text(lang('appointment_link_description'));
|
|
|
|
}
|
2020-10-21 21:37:47 +03:00
|
|
|
|
|
|
|
$customer_link = new Url(site_url('appointments/index/' . $appointment['hash']));
|
|
|
|
$provider_link = new Url(site_url('backend/index/' . $appointment['hash']));
|
|
|
|
|
2020-11-16 12:47:10 +03:00
|
|
|
$ics_stream = $this->CI->ics_file->get_stream($appointment, $service, $provider, $customer);
|
|
|
|
|
2020-10-21 21:37:47 +03:00
|
|
|
$send_customer = filter_var(
|
|
|
|
$this->CI->settings_model->get_setting('customer_notifications'),
|
|
|
|
FILTER_VALIDATE_BOOLEAN);
|
|
|
|
|
|
|
|
if ($send_customer === TRUE)
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$email->send_appointment_details($appointment, $provider,
|
2020-10-21 21:37:47 +03:00
|
|
|
$service, $customer, $settings, $customer_title,
|
2020-11-16 12:47:10 +03:00
|
|
|
$customer_message, $customer_link, new Email($customer['email']), new Text($ics_stream), $customer['timezone']);
|
2020-10-21 21:37:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$send_provider = filter_var(
|
|
|
|
$this->CI->providers_model->get_setting('notifications', $provider['id']),
|
|
|
|
FILTER_VALIDATE_BOOLEAN);
|
|
|
|
|
|
|
|
if ($send_provider === TRUE)
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$email->send_appointment_details($appointment, $provider,
|
2020-10-21 21:37:47 +03:00
|
|
|
$service, $customer, $settings, $provider_title,
|
2020-11-16 12:47:10 +03:00
|
|
|
$provider_message, $provider_link, new Email($provider['email']), new Text($ics_stream), $provider['timezone']);
|
2020-10-21 21:37:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Notify admins
|
|
|
|
$admins = $this->CI->admins_model->get_batch();
|
|
|
|
|
|
|
|
foreach ($admins as $admin)
|
|
|
|
{
|
2020-11-16 12:47:10 +03:00
|
|
|
if ($admin['settings']['notifications'] === '0')
|
2020-10-21 21:37:47 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-16 12:54:59 +03:00
|
|
|
$email->send_appointment_details($appointment, $provider,
|
2020-10-21 21:37:47 +03:00
|
|
|
$service, $customer, $settings, $provider_title,
|
2020-11-16 12:47:10 +03:00
|
|
|
$provider_message, $provider_link, new Email($admin['email']), new Text($ics_stream), $admin['timezone']);
|
2020-10-21 21:37:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Notify secretaries
|
|
|
|
$secretaries = $this->CI->secretaries_model->get_batch();
|
|
|
|
|
|
|
|
foreach ($secretaries as $secretary)
|
|
|
|
{
|
2020-11-16 12:47:10 +03:00
|
|
|
if ($secretary['settings']['notifications'] === '0')
|
2020-10-21 21:37:47 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-01-08 13:07:08 +03:00
|
|
|
if (!in_array($provider['id'], $secretary['providers']))
|
2020-10-21 21:37:47 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-16 12:54:59 +03:00
|
|
|
$email->send_appointment_details($appointment, $provider,
|
2020-10-21 21:37:47 +03:00
|
|
|
$service, $customer, $settings, $provider_title,
|
2020-11-16 12:47:10 +03:00
|
|
|
$provider_message, $provider_link, new Email($secretary['email']), new Text($ics_stream), $secretary['timezone']);
|
2020-10-21 21:37:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception $exception)
|
|
|
|
{
|
|
|
|
log_message('error', $exception->getMessage());
|
|
|
|
log_message('error', $exception->getTraceAsString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send the required notifications, related to an appointment removal.
|
|
|
|
*
|
|
|
|
* @param array $appointment Appointment record.
|
|
|
|
* @param array $service Service record.
|
|
|
|
* @param array $provider Provider record.
|
|
|
|
* @param array $customer Customer record.
|
|
|
|
* @param array $settings Required settings for the notification content.
|
|
|
|
*/
|
|
|
|
public function notify_appointment_deleted($appointment, $service, $provider, $customer, $settings)
|
|
|
|
{
|
|
|
|
// Send email notification to customer and provider.
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$email = new EmailClient($this->CI, $this->CI->config->config);
|
|
|
|
|
|
|
|
$send_provider = filter_var($this->CI->providers_model->get_setting('notifications', $provider['id']),
|
|
|
|
FILTER_VALIDATE_BOOLEAN);
|
|
|
|
|
|
|
|
if ($send_provider === TRUE)
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$email->send_delete_appointment($appointment, $provider,
|
2020-10-21 21:37:47 +03:00
|
|
|
$service, $customer, $settings, new Email($provider['email']),
|
|
|
|
new Text($this->CI->input->post('cancel_reason')));
|
|
|
|
}
|
|
|
|
|
|
|
|
$send_customer = filter_var(
|
|
|
|
$this->CI->settings_model->get_setting('customer_notifications'),
|
|
|
|
FILTER_VALIDATE_BOOLEAN);
|
|
|
|
|
|
|
|
if ($send_customer === TRUE)
|
|
|
|
{
|
2020-11-16 12:54:59 +03:00
|
|
|
$email->send_delete_appointment($appointment, $provider,
|
2020-10-21 21:37:47 +03:00
|
|
|
$service, $customer, $settings, new Email($customer['email']),
|
|
|
|
new Text($this->CI->input->post('cancel_reason')));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify admins
|
|
|
|
$admins = $this->CI->admins_model->get_batch();
|
|
|
|
|
|
|
|
foreach ($admins as $admin)
|
|
|
|
{
|
2021-05-17 13:57:06 +03:00
|
|
|
if ($admin['settings']['notifications'] === '0')
|
2020-10-21 21:37:47 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-16 12:54:59 +03:00
|
|
|
$email->send_delete_appointment($appointment, $provider,
|
2020-10-21 21:37:47 +03:00
|
|
|
$service, $customer, $settings, new Email($admin['email']),
|
|
|
|
new Text($this->CI->input->post('cancel_reason')));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify secretaries
|
|
|
|
$secretaries = $this->CI->secretaries_model->get_batch();
|
|
|
|
|
|
|
|
foreach ($secretaries as $secretary)
|
|
|
|
{
|
2021-03-12 21:48:19 +03:00
|
|
|
if ($secretary['settings']['notifications'] === '0')
|
2020-10-21 21:37:47 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-01-08 13:07:08 +03:00
|
|
|
if (!in_array($provider['id'], $secretary['providers']))
|
2020-10-21 21:37:47 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-16 12:54:59 +03:00
|
|
|
$email->send_delete_appointment($appointment, $provider,
|
2020-10-21 21:37:47 +03:00
|
|
|
$service, $customer, $settings, new Email($secretary['email']),
|
|
|
|
new Text($this->CI->input->post('cancel_reason')));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception $exception)
|
|
|
|
{
|
|
|
|
$exceptions[] = $exception;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|