2013-05-04 00:26:04 +03:00
|
|
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
|
2013-05-17 16:09:10 +03:00
|
|
|
require_once dirname(__FILE__) . '/external/class.phpmailer.php';
|
2013-05-08 17:31:17 +03:00
|
|
|
|
2013-05-04 00:26:04 +03:00
|
|
|
/**
|
|
|
|
* This library handles all the notification email deliveries
|
|
|
|
* on the system.
|
|
|
|
*
|
|
|
|
* Custom system settings for the notification section are loaded
|
2013-06-03 17:42:19 +03:00
|
|
|
* during the execution of each class methods.
|
2015-07-08 01:40:04 +03:00
|
|
|
*
|
|
|
|
* @package Libraries
|
2013-05-04 00:26:04 +03:00
|
|
|
*/
|
|
|
|
class Notifications {
|
2013-12-18 19:05:39 +02:00
|
|
|
private $ci;
|
2013-05-08 17:31:17 +03:00
|
|
|
|
2013-05-04 00:26:04 +03:00
|
|
|
/**
|
|
|
|
* Class Constructor
|
|
|
|
*/
|
2013-05-17 16:09:10 +03:00
|
|
|
public function __construct() {
|
2013-12-18 19:05:39 +02:00
|
|
|
$this->ci =& get_instance();
|
2013-05-17 16:09:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replace the email template variables.
|
|
|
|
*
|
|
|
|
* This method finds and replaces the html variables of an email
|
|
|
|
* template. It is used to generate dynamic HTML emails that are
|
|
|
|
* send as notifications to the system users.
|
|
|
|
*
|
|
|
|
* @param array $replace_array Array that contains the variables
|
|
|
|
* to be replaced.
|
|
|
|
* @param string $email_html The email template hmtl.
|
2013-06-03 17:42:19 +03:00
|
|
|
* @return string Returns the new email html that contain the
|
|
|
|
* variables of the $replace_array.
|
2013-05-17 16:09:10 +03:00
|
|
|
*/
|
|
|
|
private function replace_template_variables($replace_array, $email_html) {
|
|
|
|
foreach($replace_array as $var=>$value) {
|
|
|
|
$email_html = str_replace($var, $value, $email_html);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $email_html;
|
2013-05-04 00:26:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-06-26 12:31:57 +03:00
|
|
|
* Send an email with the appointment details.
|
2013-05-04 00:26:04 +03:00
|
|
|
*
|
2013-06-26 12:31:57 +03:00
|
|
|
* This email template also needs an email title and an email text in order to complete
|
|
|
|
* the appointment details.
|
2013-05-17 16:09:10 +03:00
|
|
|
*
|
2013-07-03 20:27:00 +03:00
|
|
|
* @expectedException Exception Raises when an unexpected error occures.
|
2013-05-04 00:26:04 +03:00
|
|
|
*
|
2013-06-26 12:31:57 +03:00
|
|
|
* @param array $appointment_data Contains the appointment data.
|
|
|
|
* @param array $provider_data Contains the provider data.
|
|
|
|
* @param array $service_data Contains the service data.
|
|
|
|
* @param array $company_settings Contains settings of the company. By the time the
|
|
|
|
* "company_name", "company_link" and "company_email" values are required in the array.
|
|
|
|
* @param string $title The email title may vary depending the receiver.
|
|
|
|
* @param string $message The email message may vary depending the receiver.
|
|
|
|
* @param string $appointment_link This link is going to enable the receiver to make changes
|
|
|
|
* to the appointment record.
|
|
|
|
* @param string $receiver_address The receiver email address.
|
2013-05-04 00:26:04 +03:00
|
|
|
* @return bool Returns the operation result.
|
|
|
|
*/
|
2013-06-26 12:31:57 +03:00
|
|
|
public function send_appointment_details($appointment_data, $provider_data, $service_data,
|
|
|
|
$customer_data, $company_settings, $title, $message, $appointment_link,
|
|
|
|
$receiver_address) {
|
2013-05-04 00:26:04 +03:00
|
|
|
|
2013-06-26 12:31:57 +03:00
|
|
|
// :: PREPARE THE EMAIL TEMPLATE REPLACE ARRAY
|
2013-05-17 16:09:10 +03:00
|
|
|
$replace_array = array(
|
2013-06-28 17:23:17 +03:00
|
|
|
'$email_title' => $title,
|
|
|
|
'$email_message' => $message,
|
2013-06-26 12:31:57 +03:00
|
|
|
|
2013-06-28 17:23:17 +03:00
|
|
|
'$appointment_service' => $service_data['name'],
|
|
|
|
'$appointment_provider' => $provider_data['first_name'] . ' ' . $provider_data['last_name'],
|
|
|
|
'$appointment_start_date' => date('d/m/Y H:i', strtotime($appointment_data['start_datetime'])),
|
|
|
|
'$appointment_end_date' => date('d/m/Y H:i', strtotime($appointment_data['end_datetime'])),
|
|
|
|
'$appointment_link' => $appointment_link,
|
2013-06-26 12:31:57 +03:00
|
|
|
|
2013-06-28 17:23:17 +03:00
|
|
|
'$company_link' => $company_settings['company_link'],
|
|
|
|
'$company_name' => $company_settings['company_name'],
|
2013-06-26 12:31:57 +03:00
|
|
|
|
2013-06-28 17:23:17 +03:00
|
|
|
'$customer_name' => $customer_data['first_name'] . ' ' . $customer_data['last_name'],
|
|
|
|
'$customer_email' => $customer_data['email'],
|
|
|
|
'$customer_phone' => $customer_data['phone_number'],
|
2013-12-18 17:04:11 +02:00
|
|
|
'$customer_address' => $customer_data['address'],
|
|
|
|
|
|
|
|
// Translations
|
2013-12-20 19:44:44 +02:00
|
|
|
'Appointment Details' => $this->ci->lang->line('appointment_details_title'),
|
|
|
|
'Service' => $this->ci->lang->line('service'),
|
|
|
|
'Provider' => $this->ci->lang->line('provider'),
|
|
|
|
'Start' => $this->ci->lang->line('start'),
|
|
|
|
'End' => $this->ci->lang->line('end'),
|
|
|
|
'Customer Details' => $this->ci->lang->line('customer_details_title'),
|
|
|
|
'Name' => $this->ci->lang->line('name'),
|
|
|
|
'Email' => $this->ci->lang->line('email'),
|
|
|
|
'Phone' => $this->ci->lang->line('phone'),
|
|
|
|
'Address' => $this->ci->lang->line('address'),
|
|
|
|
'Appointment Link' => $this->ci->lang->line('appointment_link_title')
|
2013-05-17 16:09:10 +03:00
|
|
|
);
|
2013-05-04 00:26:04 +03:00
|
|
|
|
2013-06-03 17:42:19 +03:00
|
|
|
$email_html = file_get_contents(dirname(dirname(__FILE__))
|
2013-06-26 12:31:57 +03:00
|
|
|
. '/views/emails/appointment_details.php');
|
2013-05-17 16:09:10 +03:00
|
|
|
$email_html = $this->replace_template_variables($replace_array, $email_html);
|
2013-05-04 00:26:04 +03:00
|
|
|
|
2013-06-26 12:31:57 +03:00
|
|
|
// :: INSTANTIATE EMAIL OBJECT AND SEND EMAIL
|
2013-05-17 16:09:10 +03:00
|
|
|
$mail = new PHPMailer();
|
2013-06-26 12:31:57 +03:00
|
|
|
$mail->From = $company_settings['company_email'];
|
|
|
|
$mail->FromName = $company_settings['company_name'];
|
|
|
|
$mail->AddAddress($receiver_address); // "Name" argument crushes the phpmailer class.
|
2013-05-17 16:09:10 +03:00
|
|
|
$mail->IsHTML(true);
|
|
|
|
$mail->CharSet = 'UTF-8';
|
2013-06-26 12:31:57 +03:00
|
|
|
$mail->Subject = $title;
|
2013-05-17 16:09:10 +03:00
|
|
|
$mail->Body = $email_html;
|
|
|
|
|
2013-06-03 17:42:19 +03:00
|
|
|
if (!$mail->Send()) {
|
2013-10-21 15:36:40 +03:00
|
|
|
throw new Exception('Email could not been sent. Mailer Error (Line '
|
2013-07-03 20:27:00 +03:00
|
|
|
. __LINE__ . '): ' . $mail->ErrorInfo);
|
2013-05-17 16:09:10 +03:00
|
|
|
}
|
2013-05-04 00:26:04 +03:00
|
|
|
|
2013-05-17 16:09:10 +03:00
|
|
|
return TRUE;
|
2013-05-04 00:26:04 +03:00
|
|
|
}
|
2013-06-08 12:54:45 +03:00
|
|
|
|
|
|
|
/**
|
2013-06-24 09:04:30 +03:00
|
|
|
* Send an email notification to both provider and customer on appointment removal.
|
2013-06-08 12:54:45 +03:00
|
|
|
*
|
2013-06-24 09:04:30 +03:00
|
|
|
* Whenever an appointment is cancelled or removed, both the provider and customer
|
|
|
|
* need to be informed. This method sends the same email twice.
|
|
|
|
*
|
|
|
|
* <strong>IMPORTANT!</strong> This method's arguments should be taken
|
|
|
|
* from database before the appointment record is deleted.
|
|
|
|
*
|
|
|
|
* @param array $appointment_data The record data of the removed appointment.
|
|
|
|
* @param array $provider_data The record data of the appointment provider.
|
|
|
|
* @param array $service_data The record data of the appointment service.
|
|
|
|
* @param array $customer_data The record data of the appointment customer.
|
|
|
|
* @param array $company_settings Some settings that are required for this function.
|
|
|
|
* By now this array must contain the following values: "company_link",
|
|
|
|
* "company_name", "company_email".
|
|
|
|
* @param string $to_address The email address of the email receiver.
|
2013-07-03 20:27:00 +03:00
|
|
|
* @param string $reason The reason why the appointment is deleted.
|
2013-06-08 12:54:45 +03:00
|
|
|
*/
|
2013-06-26 12:31:57 +03:00
|
|
|
public function send_delete_appointment($appointment_data, $provider_data,
|
2013-07-03 20:27:00 +03:00
|
|
|
$service_data, $customer_data, $company_settings, $to_address, $reason) {
|
2013-06-24 09:04:30 +03:00
|
|
|
// :: PREPARE EMAIL REPLACE ARRAY
|
2013-06-08 12:54:45 +03:00
|
|
|
$replace_array = array(
|
2013-12-20 19:44:44 +02:00
|
|
|
'$email_title' => $this->ci->lang->line('appointment_cancelled_title'),
|
|
|
|
'$email_message' => $this->ci->lang->line('appointment_removed_from_schedule'),
|
2013-06-08 12:54:45 +03:00
|
|
|
'$appointment_service' => $service_data['name'],
|
|
|
|
'$appointment_provider' => $provider_data['first_name'] . ' ' . $provider_data['last_name'],
|
|
|
|
'$appointment_date' => date('d/m/Y H:i', strtotime($appointment_data['start_datetime'])),
|
|
|
|
'$appointment_duration' => $service_data['duration'] . ' minutes',
|
2013-06-24 12:52:23 +03:00
|
|
|
'$company_link' => $company_settings['company_link'],
|
2013-06-26 12:31:57 +03:00
|
|
|
'$company_name' => $company_settings['company_name'],
|
|
|
|
'$customer_name' => $customer_data['first_name'] . ' ' . $customer_data['last_name'],
|
|
|
|
'$customer_email' => $customer_data['email'],
|
|
|
|
'$customer_phone' => $customer_data['phone_number'],
|
2013-07-03 20:27:00 +03:00
|
|
|
'$customer_address' => $customer_data['address'],
|
2013-12-18 19:05:39 +02:00
|
|
|
'$reason' => $reason,
|
|
|
|
|
|
|
|
// Translations
|
2013-12-20 19:44:44 +02:00
|
|
|
'Appointment Details' => $this->ci->lang->line('appointment_details_title'),
|
|
|
|
'Service' => $this->ci->lang->line('service'),
|
|
|
|
'Provider' => $this->ci->lang->line('provider'),
|
|
|
|
'Date' => $this->ci->lang->line('start'),
|
|
|
|
'Duration' => $this->ci->lang->line('duration'),
|
|
|
|
'Customer Details' => $this->ci->lang->line('customer_details_title'),
|
|
|
|
'Name' => $this->ci->lang->line('name'),
|
|
|
|
'Email' => $this->ci->lang->line('email'),
|
|
|
|
'Phone' => $this->ci->lang->line('phone'),
|
|
|
|
'Address' => $this->ci->lang->line('address'),
|
|
|
|
'Reason' => $this->ci->lang->line('reason')
|
2013-06-08 12:54:45 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
$email_html = file_get_contents(dirname(dirname(__FILE__))
|
2013-06-28 17:23:17 +03:00
|
|
|
. '/views/emails/delete_appointment.php');
|
2013-06-08 12:54:45 +03:00
|
|
|
$email_html = $this->replace_template_variables($replace_array, $email_html);
|
|
|
|
|
2013-06-24 09:04:30 +03:00
|
|
|
// :: SETUP EMAIL OBJECT AND SEND NOTIFICATION
|
2013-06-08 12:54:45 +03:00
|
|
|
$mail = new PHPMailer();
|
2013-06-24 09:04:30 +03:00
|
|
|
$mail->From = $company_settings['company_email'];
|
2013-06-24 12:52:23 +03:00
|
|
|
$mail->FromName = $company_settings['company_name'];
|
2013-06-24 09:04:30 +03:00
|
|
|
$mail->AddAddress($to_address); // "Name" argument crushes the phpmailer class.
|
2013-06-08 12:54:45 +03:00
|
|
|
$mail->IsHTML(true);
|
|
|
|
$mail->CharSet = 'UTF-8';
|
2013-12-20 19:44:44 +02:00
|
|
|
$mail->Subject = $this->ci->lang->line('appointment_cancelled_title');
|
2013-06-08 12:54:45 +03:00
|
|
|
$mail->Body = $email_html;
|
|
|
|
|
|
|
|
if (!$mail->Send()) {
|
2013-07-03 20:27:00 +03:00
|
|
|
throw new Exception('Email could not been sent. '
|
2013-06-08 12:54:45 +03:00
|
|
|
. 'Mailer Error (Line ' . __LINE__ . '): ' . $mail->ErrorInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-10-11 18:58:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method sends an email with the new password of a user.
|
|
|
|
*
|
|
|
|
* @param string $password Contains the new password.
|
|
|
|
* @param string $email The receiver's email address.
|
|
|
|
*/
|
|
|
|
public function send_password($password, $email, $company_settings) {
|
|
|
|
$replace_array = array(
|
2013-12-20 19:44:44 +02:00
|
|
|
'$email_title' => $this->ci->lang->line('new_account_password'),
|
|
|
|
'$email_message' => $this->ci->lang->line('new_password_is'),
|
2013-10-11 18:58:46 +03:00
|
|
|
'$company_name' => $company_settings['company_name'],
|
|
|
|
'$company_email' => $company_settings['company_email'],
|
2013-12-18 19:05:39 +02:00
|
|
|
'$company_link' => $company_settings['company_link'],
|
|
|
|
'$password' => '<strong>' . $password . '</strong>'
|
2013-10-11 18:58:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
$email_html = file_get_contents(dirname(dirname(__FILE__))
|
|
|
|
. '/views/emails/new_password.php');
|
|
|
|
$email_html = $this->replace_template_variables($replace_array, $email_html);
|
|
|
|
|
|
|
|
// :: SETUP EMAIL OBJECT AND SEND NOTIFICATION
|
|
|
|
$mail = new PHPMailer();
|
2013-10-17 18:31:43 +03:00
|
|
|
$mail->From = $company_settings['company_email'];
|
|
|
|
$mail->FromName = $company_settings['company_name'];
|
2013-10-11 18:58:46 +03:00
|
|
|
$mail->AddAddress($email); // "Name" argument crushes the phpmailer class.
|
|
|
|
$mail->IsHTML(true);
|
2013-10-17 18:31:43 +03:00
|
|
|
$mail->CharSet = 'UTF-8';
|
2013-12-20 19:44:44 +02:00
|
|
|
$mail->Subject = $this->ci->lang->line('new_account_password');
|
2013-10-17 18:31:43 +03:00
|
|
|
$mail->Body = $email_html;
|
2013-10-11 18:58:46 +03:00
|
|
|
|
|
|
|
if (!$mail->Send()) {
|
|
|
|
throw new Exception('Email could not been sent. '
|
|
|
|
. 'Mailer Error (Line ' . __LINE__ . '): ' . $mail->ErrorInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-10-17 18:31:43 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a simple email to notify for a new installation.
|
|
|
|
*
|
|
|
|
* This method will be only used for tracking the number of installations. No personal
|
|
|
|
* data will be retrieved for any other cause.
|
|
|
|
*
|
|
|
|
* @returns bool Returns the "send()" method result.
|
|
|
|
*/
|
|
|
|
public function send_new_installation($company_name, $company_email, $company_link) {
|
|
|
|
$mail = new PHPMailer();
|
|
|
|
$mail->From = $company_email;
|
|
|
|
$mail->FromName = 'New Installation: ' . $company_name ;
|
|
|
|
$mail->AddAddress('info@easyappointments.org');
|
|
|
|
$mail->IsHTML(true);
|
|
|
|
$mail->CharSet = 'UTF-8';
|
|
|
|
$mail->Subject = 'New Easy!Appointments Installation';
|
2013-12-18 19:05:39 +02:00
|
|
|
$mail->Body = 'Base URL: ' . $this->ci->config->item('base_url') . '<br>'
|
|
|
|
. 'E!A Version: ' . $this->ci->config->item('ea_version') . '<br>'
|
2013-10-17 18:31:43 +03:00
|
|
|
. 'Company Name: ' . $company_name . '<br>'
|
|
|
|
. 'Company Email: ' . $company_email . '<br>'
|
|
|
|
. 'Company Link: ' . $company_link . '<br>';
|
|
|
|
return $mail->Send();
|
|
|
|
}
|
2013-05-04 00:26:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* End of file notifications.php */
|
|
|
|
/* Location: ./application/libraries/notifications.php */
|