1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3 require_once dirname(__FILE__) . '/external/class.phpmailer.php';
4
5 6 7 8 9 10 11
12 class Notifications {
13 private $ci;
14
15 16 17
18 public function __construct() {
19 $this->ci =& get_instance();
20 }
21
22 23 24 25 26 27 28 29 30 31 32 33 34
35 private function replace_template_variables($replace_array, $email_html) {
36 foreach($replace_array as $var=>$value) {
37 $email_html = str_replace($var, $value, $email_html);
38 }
39
40 return $email_html;
41 }
42
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
63 public function send_appointment_details($appointment_data, $provider_data, $service_data,
64 $customer_data, $company_settings, $title, $message, $appointment_link,
65 $receiver_address) {
66
67
68 $replace_array = array(
69 '$email_title' => $title,
70 '$email_message' => $message,
71
72 '$appointment_service' => $service_data['name'],
73 '$appointment_provider' => $provider_data['first_name'] . ' ' . $provider_data['last_name'],
74 '$appointment_start_date' => date('d/m/Y H:i', strtotime($appointment_data['start_datetime'])),
75 '$appointment_end_date' => date('d/m/Y H:i', strtotime($appointment_data['end_datetime'])),
76 '$appointment_link' => $appointment_link,
77
78 '$company_link' => $company_settings['company_link'],
79 '$company_name' => $company_settings['company_name'],
80
81 '$customer_name' => $customer_data['first_name'] . ' ' . $customer_data['last_name'],
82 '$customer_email' => $customer_data['email'],
83 '$customer_phone' => $customer_data['phone_number'],
84 '$customer_address' => $customer_data['address'],
85
86
87 'Appointment Details' => $this->ci->lang->line('appointment_details_title'),
88 'Service' => $this->ci->lang->line('service'),
89 'Provider' => $this->ci->lang->line('provider'),
90 'Start' => $this->ci->lang->line('start'),
91 'End' => $this->ci->lang->line('end'),
92 'Customer Details' => $this->ci->lang->line('customer_details_title'),
93 'Name' => $this->ci->lang->line('name'),
94 'Email' => $this->ci->lang->line('email'),
95 'Phone' => $this->ci->lang->line('phone'),
96 'Address' => $this->ci->lang->line('address'),
97 'Appointment Link' => $this->ci->lang->line('appointment_link_title')
98 );
99
100 $email_html = file_get_contents(dirname(dirname(__FILE__))
101 . '/views/emails/appointment_details.php');
102 $email_html = $this->replace_template_variables($replace_array, $email_html);
103
104
105 $mail = new PHPMailer();
106 $mail->From = $company_settings['company_email'];
107 $mail->FromName = $company_settings['company_name'];
108 $mail->AddAddress($receiver_address);
109 $mail->IsHTML(true);
110 $mail->CharSet = 'UTF-8';
111 $mail->Subject = $title;
112 $mail->Body = $email_html;
113
114 if (!$mail->Send()) {
115 throw new Exception('Email could not been sent. Mailer Error (Line '
116 . __LINE__ . '): ' . $mail->ErrorInfo);
117 }
118
119 return TRUE;
120 }
121
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
141 public function send_delete_appointment($appointment_data, $provider_data,
142 $service_data, $customer_data, $company_settings, $to_address, $reason) {
143
144 $replace_array = array(
145 '$email_title' => $this->ci->lang->line('appointment_cancelled_title'),
146 '$email_message' => $this->ci->lang->line('appointment_removed_from_schedule'),
147 '$appointment_service' => $service_data['name'],
148 '$appointment_provider' => $provider_data['first_name'] . ' ' . $provider_data['last_name'],
149 '$appointment_date' => date('d/m/Y H:i', strtotime($appointment_data['start_datetime'])),
150 '$appointment_duration' => $service_data['duration'] . ' minutes',
151 '$company_link' => $company_settings['company_link'],
152 '$company_name' => $company_settings['company_name'],
153 '$customer_name' => $customer_data['first_name'] . ' ' . $customer_data['last_name'],
154 '$customer_email' => $customer_data['email'],
155 '$customer_phone' => $customer_data['phone_number'],
156 '$customer_address' => $customer_data['address'],
157 '$reason' => $reason,
158
159
160 'Appointment Details' => $this->ci->lang->line('appointment_details_title'),
161 'Service' => $this->ci->lang->line('service'),
162 'Provider' => $this->ci->lang->line('provider'),
163 'Date' => $this->ci->lang->line('start'),
164 'Duration' => $this->ci->lang->line('duration'),
165 'Customer Details' => $this->ci->lang->line('customer_details_title'),
166 'Name' => $this->ci->lang->line('name'),
167 'Email' => $this->ci->lang->line('email'),
168 'Phone' => $this->ci->lang->line('phone'),
169 'Address' => $this->ci->lang->line('address'),
170 'Reason' => $this->ci->lang->line('reason')
171 );
172
173 $email_html = file_get_contents(dirname(dirname(__FILE__))
174 . '/views/emails/delete_appointment.php');
175 $email_html = $this->replace_template_variables($replace_array, $email_html);
176
177
178 $mail = new PHPMailer();
179 $mail->From = $company_settings['company_email'];
180 $mail->FromName = $company_settings['company_name'];
181 $mail->AddAddress($to_address);
182 $mail->IsHTML(true);
183 $mail->CharSet = 'UTF-8';
184 $mail->Subject = $this->ci->lang->line('appointment_cancelled_title');
185 $mail->Body = $email_html;
186
187 if (!$mail->Send()) {
188 throw new Exception('Email could not been sent. '
189 . 'Mailer Error (Line ' . __LINE__ . '): ' . $mail->ErrorInfo);
190 }
191
192 return TRUE;
193 }
194
195 196 197 198 199 200
201 public function send_password($password, $email, $company_settings) {
202 $replace_array = array(
203 '$email_title' => $this->ci->lang->line('new_account_password'),
204 '$email_message' => $this->ci->lang->line('new_password_is'),
205 '$company_name' => $company_settings['company_name'],
206 '$company_email' => $company_settings['company_email'],
207 '$company_link' => $company_settings['company_link'],
208 '$password' => '<strong>' . $password . '</strong>'
209 );
210
211 $email_html = file_get_contents(dirname(dirname(__FILE__))
212 . '/views/emails/new_password.php');
213 $email_html = $this->replace_template_variables($replace_array, $email_html);
214
215
216 $mail = new PHPMailer();
217 $mail->From = $company_settings['company_email'];
218 $mail->FromName = $company_settings['company_name'];
219 $mail->AddAddress($email);
220 $mail->IsHTML(true);
221 $mail->CharSet = 'UTF-8';
222 $mail->Subject = $this->ci->lang->line('new_account_password');
223 $mail->Body = $email_html;
224
225 if (!$mail->Send()) {
226 throw new Exception('Email could not been sent. '
227 . 'Mailer Error (Line ' . __LINE__ . '): ' . $mail->ErrorInfo);
228 }
229
230 return TRUE;
231 }
232
233 234 235 236 237 238 239 240
241 public function send_new_installation($company_name, $company_email, $company_link) {
242 $mail = new PHPMailer();
243 $mail->From = $company_email;
244 $mail->FromName = 'New Installation: ' . $company_name ;
245 $mail->AddAddress('info@easyappointments.org');
246 $mail->IsHTML(true);
247 $mail->CharSet = 'UTF-8';
248 $mail->Subject = 'New Easy!Appointments Installation';
249 $mail->Body = 'Base URL: ' . $this->ci->config->item('base_url') . '<br>'
250 . 'E!A Version: ' . $this->ci->config->item('ea_version') . '<br>'
251 . 'Company Name: ' . $company_name . '<br>'
252 . 'Company Email: ' . $company_email . '<br>'
253 . 'Company Link: ' . $company_link . '<br>';
254 return $mail->Send();
255 }
256 }
257
258
259