Added phpmailer class to the composer dependencies.

This commit is contained in:
Alex Tselegidis 2015-10-21 23:48:35 +02:00
parent f17e6eca4a
commit 663324c8c5
4 changed files with 334 additions and 3209 deletions

View file

@ -15,6 +15,7 @@
"apigen/apigen": "~4.1" "apigen/apigen": "~4.1"
}, },
"require": { "require": {
"gregwar/captcha": "^1.1" "gregwar/captcha": "^1.1",
"phpmailer/phpmailer": "^5.2"
} }
} }

64
composer.lock generated
View file

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "75e06049c3451b1d883c03b8a4fc1a3c", "hash": "568ac1ab5ba507badb0c686bb146eed9",
"content-hash": "500445974aa564048f14ea58a75b9635", "content-hash": "f1caee945fa2c3ffed8c56511645dce9",
"packages": [ "packages": [
{ {
"name": "gregwar/captcha", "name": "gregwar/captcha",
@ -54,6 +54,66 @@
"spam" "spam"
], ],
"time": "2015-09-11 15:23:20" "time": "2015-09-11 15:23:20"
},
{
"name": "phpmailer/phpmailer",
"version": "v5.2.13",
"source": {
"type": "git",
"url": "https://github.com/PHPMailer/PHPMailer.git",
"reference": "45df3a88f7f46071e10d0b600f228d19f95911b3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/45df3a88f7f46071e10d0b600f228d19f95911b3",
"reference": "45df3a88f7f46071e10d0b600f228d19f95911b3",
"shasum": ""
},
"require": {
"php": ">=5.0.0"
},
"require-dev": {
"phpdocumentor/phpdocumentor": "*",
"phpunit/phpunit": "4.7.*"
},
"suggest": {
"league/oauth2-client": "Needed for Gmail's XOAUTH2 authentication system"
},
"type": "library",
"autoload": {
"classmap": [
"class.phpmailer.php",
"class.phpmaileroauth.php",
"class.phpmaileroauthgoogle.php",
"class.smtp.php",
"class.pop3.php",
"extras/EasyPeasyICS.php",
"extras/ntlm_sasl_client.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-2.1"
],
"authors": [
{
"name": "Jim Jagielski",
"email": "jimjag@gmail.com"
},
{
"name": "Marcus Bointon",
"email": "phpmailer@synchromedia.co.uk"
},
{
"name": "Andy Prevost",
"email": "codeworxtech@users.sourceforge.net"
},
{
"name": "Brent R. Matzelle"
}
],
"description": "PHPMailer is a full-featured email creation and transfer class for PHP",
"time": "2015-09-14 09:18:12"
} }
], ],
"packages-dev": [ "packages-dev": [

File diff suppressed because it is too large Load diff

View file

@ -1,272 +1,270 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler * Easy!Appointments - Open Source Web Scheduler
* *
* @package EasyAppointments * @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com> * @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) 2013 - 2015, Alex Tselegidis * @copyright Copyright (c) 2013 - 2015, Alex Tselegidis
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3 * @license http://opensource.org/licenses/GPL-3.0 - GPLv3
* @link http://easyappointments.org * @link http://easyappointments.org
* @since v1.0.0 * @since v1.0.0
* ---------------------------------------------------------------------------- */ * ---------------------------------------------------------------------------- */
require_once dirname(__FILE__) . '/external/class.phpmailer.php'; /**
* This library handles all the notification email deliveries
/** * on the system.
* This library handles all the notification email deliveries *
* on the system. * Custom system settings for the notification section are loaded
* * during the execution of each class methods.
* Custom system settings for the notification section are loaded *
* during the execution of each class methods. * @package Libraries
* */
* @package Libraries class Notifications {
*/ private $ci;
class Notifications {
private $ci; /**
* Class Constructor
/** */
* Class Constructor public function __construct() {
*/ $this->ci =& get_instance();
public function __construct() { }
$this->ci =& get_instance();
} /**
* Replace the email template variables.
/** *
* 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
* This method finds and replaces the html variables of an email * send as notifications to the system users.
* 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 array $replace_array Array that contains the variables * @param string $email_html The email template hmtl.
* to be replaced. * @return string Returns the new email html that contain the
* @param string $email_html The email template hmtl. * variables of the $replace_array.
* @return string Returns the new email html that contain the */
* variables of the $replace_array. private function replace_template_variables($replace_array, $email_html) {
*/ foreach($replace_array as $var=>$value) {
private function replace_template_variables($replace_array, $email_html) { $email_html = str_replace($var, $value, $email_html);
foreach($replace_array as $var=>$value) { }
$email_html = str_replace($var, $value, $email_html);
} return $email_html;
}
return $email_html;
} /**
* Send an email with the appointment details.
/** *
* Send an email with the appointment details. * This email template also needs an email title and an email text in order to complete
* * the appointment details.
* This email template also needs an email title and an email text in order to complete *
* the appointment details. * @expectedException Exception Raises when an unexpected error occures.
* *
* @expectedException Exception Raises when an unexpected error occures. * @param array $appointment_data Contains the appointment data.
* * @param array $provider_data Contains the provider data.
* @param array $appointment_data Contains the appointment data. * @param array $service_data Contains the service data.
* @param array $provider_data Contains the provider data. * @param array $company_settings Contains settings of the company. By the time the
* @param array $service_data Contains the service data. * "company_name", "company_link" and "company_email" values are required in the array.
* @param array $company_settings Contains settings of the company. By the time the * @param string $title The email title may vary depending the receiver.
* "company_name", "company_link" and "company_email" values are required in the array. * @param string $message The email message may vary depending the receiver.
* @param string $title The email title may vary depending the receiver. * @param string $appointment_link This link is going to enable the receiver to make changes
* @param string $message The email message may vary depending the receiver. * to the appointment record.
* @param string $appointment_link This link is going to enable the receiver to make changes * @param string $receiver_address The receiver email address.
* to the appointment record. * @return bool Returns the operation result.
* @param string $receiver_address The receiver email address. */
* @return bool Returns the operation result. public function send_appointment_details($appointment_data, $provider_data, $service_data,
*/ $customer_data, $company_settings, $title, $message, $appointment_link,
public function send_appointment_details($appointment_data, $provider_data, $service_data, $receiver_address) {
$customer_data, $company_settings, $title, $message, $appointment_link,
$receiver_address) { // :: PREPARE THE EMAIL TEMPLATE REPLACE ARRAY
$replace_array = array(
// :: PREPARE THE EMAIL TEMPLATE REPLACE ARRAY '$email_title' => $title,
$replace_array = array( '$email_message' => $message,
'$email_title' => $title,
'$email_message' => $message, '$appointment_service' => $service_data['name'],
'$appointment_provider' => $provider_data['first_name'] . ' ' . $provider_data['last_name'],
'$appointment_service' => $service_data['name'], '$appointment_start_date' => date('d/m/Y H:i', strtotime($appointment_data['start_datetime'])),
'$appointment_provider' => $provider_data['first_name'] . ' ' . $provider_data['last_name'], '$appointment_end_date' => date('d/m/Y H:i', strtotime($appointment_data['end_datetime'])),
'$appointment_start_date' => date('d/m/Y H:i', strtotime($appointment_data['start_datetime'])), '$appointment_link' => $appointment_link,
'$appointment_end_date' => date('d/m/Y H:i', strtotime($appointment_data['end_datetime'])),
'$appointment_link' => $appointment_link, '$company_link' => $company_settings['company_link'],
'$company_name' => $company_settings['company_name'],
'$company_link' => $company_settings['company_link'],
'$company_name' => $company_settings['company_name'], '$customer_name' => $customer_data['first_name'] . ' ' . $customer_data['last_name'],
'$customer_email' => $customer_data['email'],
'$customer_name' => $customer_data['first_name'] . ' ' . $customer_data['last_name'], '$customer_phone' => $customer_data['phone_number'],
'$customer_email' => $customer_data['email'], '$customer_address' => $customer_data['address'],
'$customer_phone' => $customer_data['phone_number'],
'$customer_address' => $customer_data['address'], // Translations
'Appointment Details' => $this->ci->lang->line('appointment_details_title'),
// Translations 'Service' => $this->ci->lang->line('service'),
'Appointment Details' => $this->ci->lang->line('appointment_details_title'), 'Provider' => $this->ci->lang->line('provider'),
'Service' => $this->ci->lang->line('service'), 'Start' => $this->ci->lang->line('start'),
'Provider' => $this->ci->lang->line('provider'), 'End' => $this->ci->lang->line('end'),
'Start' => $this->ci->lang->line('start'), 'Customer Details' => $this->ci->lang->line('customer_details_title'),
'End' => $this->ci->lang->line('end'), 'Name' => $this->ci->lang->line('name'),
'Customer Details' => $this->ci->lang->line('customer_details_title'), 'Email' => $this->ci->lang->line('email'),
'Name' => $this->ci->lang->line('name'), 'Phone' => $this->ci->lang->line('phone'),
'Email' => $this->ci->lang->line('email'), 'Address' => $this->ci->lang->line('address'),
'Phone' => $this->ci->lang->line('phone'), 'Appointment Link' => $this->ci->lang->line('appointment_link_title')
'Address' => $this->ci->lang->line('address'), );
'Appointment Link' => $this->ci->lang->line('appointment_link_title')
); $email_html = file_get_contents(dirname(dirname(__FILE__))
. '/views/emails/appointment_details.php');
$email_html = file_get_contents(dirname(dirname(__FILE__)) $email_html = $this->replace_template_variables($replace_array, $email_html);
. '/views/emails/appointment_details.php');
$email_html = $this->replace_template_variables($replace_array, $email_html); // :: INSTANTIATE EMAIL OBJECT AND SEND EMAIL
$mail = new PHPMailer();
// :: INSTANTIATE EMAIL OBJECT AND SEND EMAIL $mail->From = $company_settings['company_email'];
$mail = new PHPMailer(); $mail->FromName = $company_settings['company_name'];
$mail->From = $company_settings['company_email']; $mail->AddAddress($receiver_address); // "Name" argument crushes the phpmailer class.
$mail->FromName = $company_settings['company_name']; $mail->IsHTML(true);
$mail->AddAddress($receiver_address); // "Name" argument crushes the phpmailer class. $mail->CharSet = 'UTF-8';
$mail->IsHTML(true); $mail->Subject = $title;
$mail->CharSet = 'UTF-8'; $mail->Body = $email_html;
$mail->Subject = $title;
$mail->Body = $email_html; if (!$mail->Send()) {
throw new Exception('Email could not been sent. Mailer Error (Line '
if (!$mail->Send()) { . __LINE__ . '): ' . $mail->ErrorInfo);
throw new Exception('Email could not been sent. Mailer Error (Line ' }
. __LINE__ . '): ' . $mail->ErrorInfo);
} return TRUE;
}
return TRUE;
} /**
* Send an email notification to both provider and customer on appointment removal.
/** *
* Send an email notification to both provider and customer on appointment removal. * Whenever an appointment is cancelled or removed, both the provider and customer
* * need to be informed. This method sends the same email twice.
* 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.
* <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 $appointment_data The record data of the removed appointment. * @param array $service_data The record data of the appointment service.
* @param array $provider_data The record data of the appointment provider. * @param array $customer_data The record data of the appointment customer.
* @param array $service_data The record data of the appointment service. * @param array $company_settings Some settings that are required for this function.
* @param array $customer_data The record data of the appointment customer. * By now this array must contain the following values: "company_link",
* @param array $company_settings Some settings that are required for this function. * "company_name", "company_email".
* By now this array must contain the following values: "company_link", * @param string $to_address The email address of the email receiver.
* "company_name", "company_email". * @param string $reason The reason why the appointment is deleted.
* @param string $to_address The email address of the email receiver. */
* @param string $reason The reason why the appointment is deleted. public function send_delete_appointment($appointment_data, $provider_data,
*/ $service_data, $customer_data, $company_settings, $to_address, $reason) {
public function send_delete_appointment($appointment_data, $provider_data, // :: PREPARE EMAIL REPLACE ARRAY
$service_data, $customer_data, $company_settings, $to_address, $reason) { $replace_array = array(
// :: PREPARE EMAIL REPLACE ARRAY '$email_title' => $this->ci->lang->line('appointment_cancelled_title'),
$replace_array = array( '$email_message' => $this->ci->lang->line('appointment_removed_from_schedule'),
'$email_title' => $this->ci->lang->line('appointment_cancelled_title'), '$appointment_service' => $service_data['name'],
'$email_message' => $this->ci->lang->line('appointment_removed_from_schedule'), '$appointment_provider' => $provider_data['first_name'] . ' ' . $provider_data['last_name'],
'$appointment_service' => $service_data['name'], '$appointment_date' => date('d/m/Y H:i', strtotime($appointment_data['start_datetime'])),
'$appointment_provider' => $provider_data['first_name'] . ' ' . $provider_data['last_name'], '$appointment_duration' => $service_data['duration'] . ' minutes',
'$appointment_date' => date('d/m/Y H:i', strtotime($appointment_data['start_datetime'])), '$company_link' => $company_settings['company_link'],
'$appointment_duration' => $service_data['duration'] . ' minutes', '$company_name' => $company_settings['company_name'],
'$company_link' => $company_settings['company_link'], '$customer_name' => $customer_data['first_name'] . ' ' . $customer_data['last_name'],
'$company_name' => $company_settings['company_name'], '$customer_email' => $customer_data['email'],
'$customer_name' => $customer_data['first_name'] . ' ' . $customer_data['last_name'], '$customer_phone' => $customer_data['phone_number'],
'$customer_email' => $customer_data['email'], '$customer_address' => $customer_data['address'],
'$customer_phone' => $customer_data['phone_number'], '$reason' => $reason,
'$customer_address' => $customer_data['address'],
'$reason' => $reason, // Translations
'Appointment Details' => $this->ci->lang->line('appointment_details_title'),
// Translations 'Service' => $this->ci->lang->line('service'),
'Appointment Details' => $this->ci->lang->line('appointment_details_title'), 'Provider' => $this->ci->lang->line('provider'),
'Service' => $this->ci->lang->line('service'), 'Date' => $this->ci->lang->line('start'),
'Provider' => $this->ci->lang->line('provider'), 'Duration' => $this->ci->lang->line('duration'),
'Date' => $this->ci->lang->line('start'), 'Customer Details' => $this->ci->lang->line('customer_details_title'),
'Duration' => $this->ci->lang->line('duration'), 'Name' => $this->ci->lang->line('name'),
'Customer Details' => $this->ci->lang->line('customer_details_title'), 'Email' => $this->ci->lang->line('email'),
'Name' => $this->ci->lang->line('name'), 'Phone' => $this->ci->lang->line('phone'),
'Email' => $this->ci->lang->line('email'), 'Address' => $this->ci->lang->line('address'),
'Phone' => $this->ci->lang->line('phone'), 'Reason' => $this->ci->lang->line('reason')
'Address' => $this->ci->lang->line('address'), );
'Reason' => $this->ci->lang->line('reason')
); $email_html = file_get_contents(dirname(dirname(__FILE__))
. '/views/emails/delete_appointment.php');
$email_html = file_get_contents(dirname(dirname(__FILE__)) $email_html = $this->replace_template_variables($replace_array, $email_html);
. '/views/emails/delete_appointment.php');
$email_html = $this->replace_template_variables($replace_array, $email_html); // :: SETUP EMAIL OBJECT AND SEND NOTIFICATION
$mail = new PHPMailer();
// :: SETUP EMAIL OBJECT AND SEND NOTIFICATION $mail->From = $company_settings['company_email'];
$mail = new PHPMailer(); $mail->FromName = $company_settings['company_name'];
$mail->From = $company_settings['company_email']; $mail->AddAddress($to_address); // "Name" argument crushes the phpmailer class.
$mail->FromName = $company_settings['company_name']; $mail->IsHTML(true);
$mail->AddAddress($to_address); // "Name" argument crushes the phpmailer class. $mail->CharSet = 'UTF-8';
$mail->IsHTML(true); $mail->Subject = $this->ci->lang->line('appointment_cancelled_title');
$mail->CharSet = 'UTF-8'; $mail->Body = $email_html;
$mail->Subject = $this->ci->lang->line('appointment_cancelled_title');
$mail->Body = $email_html; if (!$mail->Send()) {
throw new Exception('Email could not been sent. '
if (!$mail->Send()) { . 'Mailer Error (Line ' . __LINE__ . '): ' . $mail->ErrorInfo);
throw new Exception('Email could not been sent. ' }
. 'Mailer Error (Line ' . __LINE__ . '): ' . $mail->ErrorInfo);
} return TRUE;
}
return TRUE;
} /**
* This method sends an email with the new password of a user.
/** *
* 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.
* @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(
public function send_password($password, $email, $company_settings) { '$email_title' => $this->ci->lang->line('new_account_password'),
$replace_array = array( '$email_message' => $this->ci->lang->line('new_password_is'),
'$email_title' => $this->ci->lang->line('new_account_password'), '$company_name' => $company_settings['company_name'],
'$email_message' => $this->ci->lang->line('new_password_is'), '$company_email' => $company_settings['company_email'],
'$company_name' => $company_settings['company_name'], '$company_link' => $company_settings['company_link'],
'$company_email' => $company_settings['company_email'], '$password' => '<strong>' . $password . '</strong>'
'$company_link' => $company_settings['company_link'], );
'$password' => '<strong>' . $password . '</strong>'
); $email_html = file_get_contents(dirname(dirname(__FILE__))
. '/views/emails/new_password.php');
$email_html = file_get_contents(dirname(dirname(__FILE__)) $email_html = $this->replace_template_variables($replace_array, $email_html);
. '/views/emails/new_password.php');
$email_html = $this->replace_template_variables($replace_array, $email_html); // :: SETUP EMAIL OBJECT AND SEND NOTIFICATION
$mail = new PHPMailer();
// :: SETUP EMAIL OBJECT AND SEND NOTIFICATION $mail->From = $company_settings['company_email'];
$mail = new PHPMailer(); $mail->FromName = $company_settings['company_name'];
$mail->From = $company_settings['company_email']; $mail->AddAddress($email); // "Name" argument crushes the phpmailer class.
$mail->FromName = $company_settings['company_name']; $mail->IsHTML(true);
$mail->AddAddress($email); // "Name" argument crushes the phpmailer class. $mail->CharSet = 'UTF-8';
$mail->IsHTML(true); $mail->Subject = $this->ci->lang->line('new_account_password');
$mail->CharSet = 'UTF-8'; $mail->Body = $email_html;
$mail->Subject = $this->ci->lang->line('new_account_password');
$mail->Body = $email_html; if (!$mail->Send()) {
throw new Exception('Email could not been sent. '
if (!$mail->Send()) { . 'Mailer Error (Line ' . __LINE__ . '): ' . $mail->ErrorInfo);
throw new Exception('Email could not been sent. ' }
. 'Mailer Error (Line ' . __LINE__ . '): ' . $mail->ErrorInfo);
} return TRUE;
}
return TRUE;
} /**
* Sends a simple email to notify for a new installation.
/** *
* 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.
* 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.
* */
* @returns bool Returns the "send()" method result. public function send_new_installation($company_name, $company_email, $company_link) {
*/ $mail = new PHPMailer();
public function send_new_installation($company_name, $company_email, $company_link) { $mail->From = $company_email;
$mail = new PHPMailer(); $mail->FromName = 'New Installation: ' . $company_name ;
$mail->From = $company_email; $mail->AddAddress('info@easyappointments.org');
$mail->FromName = 'New Installation: ' . $company_name ; $mail->IsHTML(true);
$mail->AddAddress('info@easyappointments.org'); $mail->CharSet = 'UTF-8';
$mail->IsHTML(true); $mail->Subject = 'New Easy!Appointments Installation';
$mail->CharSet = 'UTF-8'; $mail->Body = 'Base URL: ' . $this->ci->config->item('base_url') . '<br>'
$mail->Subject = 'New Easy!Appointments Installation'; . 'E!A Version: ' . $this->ci->config->item('ea_version') . '<br>'
$mail->Body = 'Base URL: ' . $this->ci->config->item('base_url') . '<br>' . 'Company Name: ' . $company_name . '<br>'
. 'E!A Version: ' . $this->ci->config->item('ea_version') . '<br>' . 'Company Email: ' . $company_email . '<br>'
. 'Company Name: ' . $company_name . '<br>' . 'Company Link: ' . $company_link . '<br>';
. 'Company Email: ' . $company_email . '<br>' return $mail->Send();
. 'Company Link: ' . $company_link . '<br>'; }
return $mail->Send(); }
}
} /* End of file notifications.php */
/* Location: ./application/libraries/notifications.php */
/* End of file notifications.php */
/* Location: ./application/libraries/notifications.php */