PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.10.0
Fluent Support – Helpdesk & Customer Support Ticket System v1.10.0
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / app / Services / EmailNotification / Settings.php

Settings.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.10.0, at app/Services/EmailNotification/Settings.php

415 lines 20.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Services\EmailNotification;
4 use FluentSupportPro\Database\Migrations\TimeTrackMigrator;
5
6 use FluentSupport\App\Services\Helper;
7
8 class Settings
9 {
10
11 public function getEmailSettingsKeys()
12 {
13 $key = apply_filters('fluent_support/email_setting_keys', [
14 'ticket_created_email_to_customer',
15 'ticket_replied_by_agent_email_to_customer',
16 'ticket_closed_by_agent_email_to_customer',
17 'ticket_created_email_to_admin',
18 'ticket_replied_by_customer_email_to_admin',
19 'ticket_agent_on_change',
20 'ticket_created_by_agent_email_to_customer'
21 ]);
22 return $key;
23 }
24
25 public function get($settingsKey)
26 {
27 if ($settingsKey == 'global_business_settings') {
28 return [
29 'settings' => $this->globalBusinessSettings(),
30 'fields' => $this->getGlobalBusinessSettingsFields()
31 ];
32 }
33
34 return [
35 'settings' => [],
36 'fields' => []
37 ];
38 }
39
40 /**
41 * save method will save the requested settings by settings key
42 * @param $settingsKey
43 * @param $settings
44 * @return mixed
45 */
46 public function save($settingsKey, $settings)
47 {
48 if ($settingsKey == 'global_business_settings' && empty($settings['accepted_file_types'])) {
49 $settings['accepted_file_types'] = [];
50 }
51
52 if ($settingsKey == 'global_business_settings' && !empty($settings['agent_time_tracking'])) {
53 if (class_exists(TimeTrackMigrator::class) && $settings['agent_time_tracking'] === 'yes') {
54 TimeTrackMigrator::migrate();
55 }
56 }
57
58 return Helper::updateOption($settingsKey, $settings);
59 }
60
61 /**
62 * globalBusinessSettings method will fetch global settings from database, parse and return
63 * @param bool $cached
64 * @return array|mixed
65 */
66 public function globalBusinessSettings($cached = true)
67 {
68 static $settings;
69
70 if($cached && $settings) {
71 return $settings;
72 }
73
74 $defaults = [
75 'portal_page_id' => '',
76 'login_message' => sprintf(__('%1sPlease login or create an account to access the Customer Support Portal%2s [fluent_support_auth]', 'fluent-support'), '<p>', '</p>'),
77 'disable_public_ticket' => 'no',
78 'accepted_file_types' => ['images', 'csv', 'documents', 'zip', 'json'],
79 'max_file_size' => 2,
80 'max_file_upload' => 3,
81 'del_files_on_close' => 'no',
82 'enable_admin_bar_summary' => 'no',
83 'enable_draft_mode' => 'no',
84 'agent_feedback_rating' => 'no',
85 'keyboard_shortcuts' => 'no'
86 ];
87
88 //Get default/existing settings from database using the key global_business_settings
89 $existingSettings = Helper::getOption('global_business_settings', []);
90
91 if (!$existingSettings) {
92 $settings = $defaults;
93 return $settings;
94 }
95
96 $settings = wp_parse_args($existingSettings, $defaults);
97
98 return $settings;
99 }
100
101
102 /**
103 * getGlobalBusinessSettingsFields method will prepare the list of field, and it's property that will be used in global settings form
104 * @return array
105 */
106 private function getGlobalBusinessSettingsFields()
107 {
108
109 $mimeGroups = Helper::getMimeGroups();
110
111 $formattedMimeGroups = [];
112
113 foreach ($mimeGroups as $mimeGroup => $mime) {
114 $formattedMimeGroups[$mimeGroup] = $mime['title'];
115 }
116
117 $customRegistrationFormOptions = array(
118 'address_line_1' => 'Address Line 1',
119 'address_line_2' => 'Address Line 2',
120 'city' => 'City',
121 'zip' => 'Zip Code',
122 'state' => 'State',
123 'country' => 'Country',
124 );
125
126 $fields = [
127 'portal_page_id' => [
128 'type' => 'input-options',
129 'label' => __('Portal Page', 'fluent-support'),
130 'show_id' => true,
131 'placeholder' => __('Select Portal Page', 'fluent-support'),
132 'options' => Helper::getWPPages(),//Get list of published pages
133 'inline_help' => __('Please provide the page id where you want to show the tickets for your customers. Use shortcode <code>[fluent_support_portal]</code> in that page', 'fluent-support')
134 ],
135 'login_message' => [
136 'type' => 'wp-editor',
137 'label' => __('Message for non logged in users', 'fluent-support'),
138 'inline_help' => __('Please provide message for not logged in users. You can place login shortcode too. Use shortcode <code>[fluent_support_login]</code> to show built-in login form. For the user registration use this shortcode <code>[fluent_support_signup]</code> and for both form please use <code>[fluent_support_auth]</code>', 'fluent-support')
139 ],
140 'disable_public_ticket' => [
141 'type' => 'inline-checkbox',
142 'true_label' => 'yes',
143 'false-label' => 'no',
144 'checkbox_label' => __('Disable Public Ticket interaction', 'fluent-support'),
145 'inline_help' => __('If you enable this then only logged in user can reply the tickets. Otherwise, url will be signed and intended user can reply without logging in', 'fluent-support')
146 ],
147 'accepted_file_types' => [
148 'wrapper_class' => 'fs_half_field',
149 'type' => 'checkbox-group',
150 'label' => __('Accepted File Types', 'fluent-support'),
151 'options' => $formattedMimeGroups
152 ],
153 'max_file_size' => [
154 'wrapper_class' => 'fs_half_field',
155 'type' => 'input-text',
156 'data_type' => 'number',
157 'label' => __('Max File Size (in MegaByte)', 'fluent-support'),
158 ],
159 'max_file_upload' => [
160 'wrapper_class' => 'fs_half_field',
161 'type' => 'input-text',
162 'data_type' => 'number',
163 'label' => __('Maximum File Upload', 'fluent-support'),
164 ],
165 'del_files_on_close' => [
166 'type' => 'inline-checkbox',
167 'true_label' => 'yes',
168 'false-label' => 'no',
169 'checkbox_label' => __('Delete all attachments on ticket close', 'fluent-support'),
170 'inline_help' => __('If you enable this feature, all attachments associated with a ticket will be deleted when the ticket is closed.', 'fluent-support')
171 ],
172 'enable_admin_bar_summary' => [
173 'type' => 'inline-checkbox',
174 'true_label' => 'yes',
175 'false-label' => 'no',
176 'checkbox_label' => __('Enable Fluent Summary In Admin Bar', 'fluent-support'),
177 'inline_help' => __('If you enable this, logged in user can see the ticket summary from top nav bar.', 'fluent-support')
178 ],
179 'enable_draft_mode' => [
180 'type' => 'inline-checkbox',
181 'true_label' => 'yes',
182 'false-label' => 'no',
183 'checkbox_label' => __('Enable Draft Mode', 'fluent-support'),
184 'inline_help' => __('If you enable this setting, any written response will be saved as a draft if an agent accidentally closes a ticket.', 'fluent-support')
185 ],
186 'custom_registration_form_field' => [
187 'wrapper_class' => 'inline-checkbox',
188 'type' => 'checkbox-group',
189 'label' => __('Custom Registration Form Field', 'fluent-support'),
190 'options' => $customRegistrationFormOptions
191 ],
192 'enable_two_fa' => [
193 'type' => 'inline-checkbox',
194 'true_label' => 'yes',
195 'false-label' => 'no',
196 'checkbox_label' => __('Enable Two-Factor Authentication', 'fluent-support'),
197 'inline_help' => __('If you enable this setting, users will be required to submit a second form of authentication, such as a code sent to their email, to login.', 'fluent-support')
198 ],
199 'keyboard_shortcuts' => [
200 'type' => 'inline-checkbox',
201 'true_label' => 'yes',
202 'false-label' => 'no',
203 'checkbox_label' => __('Enable Keyboard Shortcuts', 'fluent-support'),
204 'inline_help' => __("If you enable this, agents can use keyboard shortcuts for faster actions.", 'fluent-support')
205 ]
206 ];
207
208 if (defined('FLUENTSUPPORTPRO_PLUGIN_VERSION')) {
209 $fields['agent_feedback_rating'] = [
210 'type' => 'inline-checkbox',
211 'true_label' => 'yes',
212 'false-label' => 'no',
213 'checkbox_label' => __('Agent Feedback Rating', 'fluent-support'),
214 'inline_help' => __("If you enable this setting, users will have the option to provide feedback on an agent's response.", 'fluent-support')
215 ];
216
217 $fields['agent_time_tracking'] = [
218 'type' => 'inline-checkbox',
219 'true_label' => 'yes',
220 'false-label' => 'no',
221 'checkbox_label' => __('Agent Time Tracking', 'fluent-support'),
222 'inline_help' => __("If you enable this setting, the agent can specify the amount of time needed to complete a ticket.", 'fluent-support')
223 ];
224
225 if (defined('FLUENTCART_VERSION')) {
226 $fields['enable_fc_menu'] = [
227 'type' => 'inline-checkbox',
228 'checkbox_label' => 'Add support link to Fluent Cart account navigation',
229 'inline_help' => __("If you enable this setting, support link will be added to Fluent Cart account navigation.", 'fluent-support'),
230 'true_label' => 'yes',
231 'false_label' => 'no'
232 ];
233 }
234 }
235
236 return $fields;
237 }
238
239 public function saveBoxEmailSettings($box, $emailKey, $settings)
240 {
241 return $box->saveMeta('_email_' . $emailKey, $settings);
242 }
243
244 /**
245 * getBoxEmailSettings method will reply the email settings
246 * @param $box
247 * @param $emailKey
248 * @return array|false
249 */
250 public function getBoxEmailSettings($box, $emailKey)
251 {
252 if (!$box) {
253 return false;
254 }
255
256 #ticket_closed_by_agent_email_to_customer 2 times, is it wrong or right!!!
257 $strictSubjectKeys = apply_filters('fluent_support/strict_subjects', [
258 'ticket_replied_by_agent_email_to_customer',
259 'ticket_closed_by_agent_email_to_customer',
260 'ticket_created_email_to_customer'
261 ]);
262
263 $settingsDefaults = [
264 'ticket_created_email_to_customer' => [
265 'key' => 'ticket_created_email_to_customer',
266 'title' => __('Ticket Created (To Customer)', 'fluent-support'),
267 'description' => __('This email will be sent when a customer submit a support ticket', 'fluent-support'),
268 'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}',
269 'default_status' => 'no',
270 'send_attachments'=> 'no'
271 ],
272 'ticket_replied_by_agent_email_to_customer' => [
273 'key' => 'ticket_replied_by_agent_email_to_customer',
274 'title' => __('Replied by Agent (To Customer)', 'fluent-support'),
275 'description' => __('This email will be sent when an agent reply to a ticket', 'fluent-support'),
276 'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}',
277 'default_status' => 'yes',
278 'send_attachments'=> 'no'
279 ],
280 'ticket_closed_by_agent_email_to_customer' => [
281 'key' => 'ticket_closed_by_agent_email_to_customer',
282 'title' => __('Ticket Closed by Agent (To Customer)', 'fluent-support'),
283 'description' => __('This email will be sent when an agent close a ticket', 'fluent-support'),
284 'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}',
285 'default_status' => 'no',
286 'send_attachments'=> 'no'
287 ],
288 'ticket_created_email_to_admin' => [
289 'key' => 'ticket_created_email_to_admin',
290 'title' => __('Ticket Created (To Admin)', 'fluent-support'),
291 'description' => __('This email will be sent when the business when a new ticket has been submitted', 'fluent-support'),
292 'email_subject' => 'New Ticket: {{ticket.title}} #{{ticket.id}}',
293 'default_status' => 'yes',
294 'send_attachments'=> 'no'
295 ],
296 'ticket_replied_by_customer_email_to_admin' => [
297 'key' => 'ticket_replied_by_customer_email_to_admin',
298 'title' => __('Replied by Customer (To Agent/Admin)', 'fluent-support'),
299 'description' => __('This email will be sent to Assigned Agent or Admin when a customer reply to a ticket', 'fluent-support'),
300 'email_subject' => 'New Response: {{ticket.title}} #{{ticket.id}}',
301 'default_status' => 'yes',
302 'send_attachments'=> 'no'
303 ],
304 'ticket_agent_on_change' => [
305 'key' => 'ticket_agent_on_change',
306 'title' => __('Ticket Agent Change (To Agent)', 'fluent-support'),
307 'description' => __('This email will be sent to newly assigned agent', 'fluent-support'),
308 'email_subject' => 'Ticket Agent Change: {{ticket.title}} #{{ticket.id}}',
309 'default_status' => 'yes',
310 'send_attachments'=> 'no'
311 ],
312 'ticket_created_by_agent_email_to_customer' => [
313 'key' => 'ticket_created_by_agent_email_to_customer',
314 'title' => __('Ticket Created by Agent (To Customer)', 'fluent-support'),
315 'description' => __('This email will be sent when an agent create a ticket for a customer', 'fluent-support'),
316 'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}',
317 'default_status' => 'no',
318 'send_attachments'=> 'no'
319 ]
320 ];
321
322 if (!isset($settingsDefaults[$emailKey])) {
323 return false;
324 }
325
326 $savedSettings = (array)$box->getMeta('_email_' . $emailKey, []);
327
328
329 if (!$savedSettings) {
330 $savedSettings = [
331 'key' => $settingsDefaults[$emailKey]['key'],
332 'title' => $settingsDefaults[$emailKey]['title'],
333 'email_subject' => $settingsDefaults[$emailKey]['email_subject'],
334 'email_body' => $this->getDefaultEmailBody($emailKey, $box->box_type),
335 'status' => $settingsDefaults[$emailKey]['default_status'],
336 'can_edit_subject' => (in_array($emailKey, $strictSubjectKeys) && $box->box_type == 'email') ? 'no' : 'yes',
337 'send_attachments' => $settingsDefaults[$emailKey]['send_attachments']
338 ];
339
340 if ($box->box_type == 'email' && in_array($emailKey, $strictSubjectKeys)) {
341 $savedSettings['email_subject'] = 'Re: {{ticket.title}}';
342 $savedSettings['can_edit_subject'] = 'no';
343 }
344
345 return $savedSettings;
346 }
347
348 $savedSettings['key'] = $settingsDefaults[$emailKey]['key'];
349 $savedSettings['title'] = $settingsDefaults[$emailKey]['title'];
350 $savedSettings['description'] = $settingsDefaults[$emailKey]['description'];
351
352 if ($box->box_type == 'email' && in_array($emailKey, $strictSubjectKeys)) {
353 $savedSettings['email_subject'] = 'Re: {{ticket.title}}';
354 $savedSettings['can_edit_subject'] = 'no';
355 }
356
357 if (empty($savedSettings['email_subject'])) {
358 $savedSettings['email_subject'] = $settingsDefaults[$emailKey]['email_subject'];
359 }
360
361 if (empty($savedSettings['status'])) {
362 $savedSettings['status'] = $settingsDefaults[$emailKey]['default_status'];
363 }
364
365 if (empty($savedSettings['email_body'])) {
366 $savedSettings['email_body'] = $this->getDefaultEmailBody($emailKey, $box->box_type);
367 }
368
369 if (empty($savedSettings['send_attachments'])) {
370 $savedSettings['send_attachments'] = $settingsDefaults[$emailKey]['send_attachments'];
371 }
372
373 return $savedSettings;
374 }
375
376 /**
377 * getDefaultEmailBody method will return html for email body
378 * @param $emailKey
379 * @param string $type
380 * @return string
381 */
382 private function getDefaultEmailBody($emailKey, $type = 'web')
383 {
384 if ($emailKey == 'ticket_created_email_to_customer') {
385 if ($type == 'web') {
386 return '<p>Hi <strong><em>{{customer.full_name}}</em>,</strong></p><p>Your request (<a href="{{ticket.public_url}}">#{{ticket.id}}</a>) has been received, and is being reviewed by our support staff.</p><p>To add additional comments, follow the link below:</p><h4><a href="{{ticket.public_url}}">View Ticket</a></h4><p>&nbsp;</p><p>or follow this link: {{ticket.public_url}}</p><hr /><p>{{business.name}}</p>';
387 } else {
388 return '<p>Hi <strong><em>{{customer.full_name}}</em>,</strong></p><p>Your request has been received, and is being reviewed by our support staff.</p><p>Our support staff will reply back to you soon</p>';
389 }
390 } else if ($emailKey == 'ticket_replied_by_agent_email_to_customer') {
391 if ($type == 'web') {
392 return '<p>Hi <strong><em>{{customer.full_name}}</em>,</strong></p><p>An agent just replied to your ticket "<strong>{{ticket.title}}</strong>" (<a href="{{ticket.public_url}}">#{{ticket.id}}</a>). To view his reply or add additional comments, click the button below:</p><h4><a href="{{ticket.public_url}}">View Ticket</a></h4><p>or follow this link: {{ticket.public_url}}</p><hr /><p>Regards,<br />{{business.name}}</p>';
393 } else {
394 return '{{response.full_content}}<p>Regards,<br />{{agent.full_name}}</p>';
395 }
396 } else if ($emailKey == 'ticket_closed_by_agent_email_to_customer') {
397 if ($type == 'web') {
398 return '<p>Hi <strong><em>{{customer.full_name}},</strong></p><p>Your ticket - {{ticket.title}}</p><p>We hope that the ticket was resolved to your satisfaction. If you feel that the ticket should not be closed or if the ticket has not been resolved, please reopen the ticket (<a href="{{ticket.public_url}}">#{{ticket.id}}</a>)</p><p>Regards,<br />{{business.name}}</p>';
399 } else {
400 return '<p>Hi <strong><em>{{customer.full_name}},</strong></p><p>Your ticket - {{ticket.title}}</p><p>We hope that the ticket was resolved to your satisfaction. If you feel that the ticket should not be closed or if the ticket has not been resolved, please feel free to reply back.<p>Regards,<br />{{business.name}}</p>';
401 }
402 } else if ($emailKey == 'ticket_created_email_to_admin') {
403 return '<p>A new ticket (<a href="{{ticket.admin_url}}">{{ticket.title}}</a>) as been submitted by {{customer.full_name}}</p><h4>Ticket Body</h4><p>{{ticket.content}}</p><p><b><a href="{{ticket.admin_url}}">View Ticket</a></b></p>';
404 } else if ($emailKey == 'ticket_replied_by_customer_email_to_admin') {
405 return '<p>A new response has been added to "<a href="{{ticket.admin_url}}">{{ticket.title}}</a>" by {{customer.full_name}}</p><h4>Response Body</h4><p>{{response.content}}</p><p><b><a href="{{ticket.admin_url}}">View Ticket</a></b></p>';
406 } else if($emailKey == 'ticket_agent_on_change') {
407 return '<p>Hi <strong><em>{{agent.full_name}}</em>,</strong></p><p>Ticket "<a href="{{ticket.admin_url}}">#{{ticket.id}}</a>" assigned to you.</p>';
408 } else if($emailKey == 'ticket_created_by_agent_email_to_customer') {
409 return '<p>Hi <strong><em>{{customer.full_name}}</em>,</strong></p><p>{{agent.full_name}} created a ticket on behalf of you, you can check it <a href="{{ticket.public_url}}">here</a></p>.';
410 }
411
412 return '';
413 }
414 }
415