PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.10.4
Fluent Support – Helpdesk & Customer Support Ticket System v1.10.4
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.4, at app/Services/EmailNotification/Settings.php

416 lines 20.6 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 // translators: %1$s is opening paragraph tag, %2$s is closing paragraph tag
77 'login_message' => sprintf(__('%1$sPlease login or create an account to access the Customer Support Portal%2$s [fluent_support_auth]', 'fluent-support'), '<p>', '</p>'),
78 'disable_public_ticket' => 'no',
79 'accepted_file_types' => ['images', 'csv', 'documents', 'zip', 'json'],
80 'max_file_size' => 2,
81 'max_file_upload' => 3,
82 'del_files_on_close' => 'no',
83 'enable_admin_bar_summary' => 'no',
84 'enable_draft_mode' => 'no',
85 'agent_feedback_rating' => 'no',
86 'keyboard_shortcuts' => 'no'
87 ];
88
89 //Get default/existing settings from database using the key global_business_settings
90 $existingSettings = Helper::getOption('global_business_settings', []);
91
92 if (!$existingSettings) {
93 $settings = $defaults;
94 return $settings;
95 }
96
97 $settings = wp_parse_args($existingSettings, $defaults);
98
99 return $settings;
100 }
101
102
103 /**
104 * getGlobalBusinessSettingsFields method will prepare the list of field, and it's property that will be used in global settings form
105 * @return array
106 */
107 private function getGlobalBusinessSettingsFields()
108 {
109
110 $mimeGroups = Helper::getMimeGroups();
111
112 $formattedMimeGroups = [];
113
114 foreach ($mimeGroups as $mimeGroup => $mime) {
115 $formattedMimeGroups[$mimeGroup] = $mime['title'];
116 }
117
118 $customRegistrationFormOptions = array(
119 'address_line_1' => 'Address Line 1',
120 'address_line_2' => 'Address Line 2',
121 'city' => 'City',
122 'zip' => 'Zip Code',
123 'state' => 'State',
124 'country' => 'Country',
125 );
126
127 $fields = [
128 'portal_page_id' => [
129 'type' => 'input-options',
130 'label' => __('Portal Page', 'fluent-support'),
131 'show_id' => true,
132 'placeholder' => __('Select Portal Page', 'fluent-support'),
133 'options' => Helper::getWPPages(),//Get list of published pages
134 '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')
135 ],
136 'login_message' => [
137 'type' => 'wp-editor',
138 'label' => __('Message for non logged in users', 'fluent-support'),
139 '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')
140 ],
141 'disable_public_ticket' => [
142 'type' => 'inline-checkbox',
143 'true_label' => 'yes',
144 'false-label' => 'no',
145 'checkbox_label' => __('Disable Public Ticket interaction', 'fluent-support'),
146 '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')
147 ],
148 'accepted_file_types' => [
149 'wrapper_class' => 'fs_half_field',
150 'type' => 'checkbox-group',
151 'label' => __('Accepted File Types', 'fluent-support'),
152 'options' => $formattedMimeGroups
153 ],
154 'max_file_size' => [
155 'wrapper_class' => 'fs_half_field',
156 'type' => 'input-text',
157 'data_type' => 'number',
158 'label' => __('Max File Size (in MegaByte)', 'fluent-support'),
159 ],
160 'max_file_upload' => [
161 'wrapper_class' => 'fs_half_field',
162 'type' => 'input-text',
163 'data_type' => 'number',
164 'label' => __('Maximum File Upload', 'fluent-support'),
165 ],
166 'del_files_on_close' => [
167 'type' => 'inline-checkbox',
168 'true_label' => 'yes',
169 'false-label' => 'no',
170 'checkbox_label' => __('Delete all attachments on ticket close', 'fluent-support'),
171 'inline_help' => __('If you enable this feature, all attachments associated with a ticket will be deleted when the ticket is closed.', 'fluent-support')
172 ],
173 'enable_admin_bar_summary' => [
174 'type' => 'inline-checkbox',
175 'true_label' => 'yes',
176 'false-label' => 'no',
177 'checkbox_label' => __('Enable Fluent Summary In Admin Bar', 'fluent-support'),
178 'inline_help' => __('If you enable this, logged in user can see the ticket summary from top nav bar.', 'fluent-support')
179 ],
180 'enable_draft_mode' => [
181 'type' => 'inline-checkbox',
182 'true_label' => 'yes',
183 'false-label' => 'no',
184 'checkbox_label' => __('Enable Draft Mode', 'fluent-support'),
185 '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')
186 ],
187 'custom_registration_form_field' => [
188 'wrapper_class' => 'inline-checkbox',
189 'type' => 'checkbox-group',
190 'label' => __('Custom Registration Form Field', 'fluent-support'),
191 'options' => $customRegistrationFormOptions
192 ],
193 'enable_two_fa' => [
194 'type' => 'inline-checkbox',
195 'true_label' => 'yes',
196 'false-label' => 'no',
197 'checkbox_label' => __('Enable Two-Factor Authentication', 'fluent-support'),
198 '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')
199 ],
200 'keyboard_shortcuts' => [
201 'type' => 'inline-checkbox',
202 'true_label' => 'yes',
203 'false-label' => 'no',
204 'checkbox_label' => __('Enable Keyboard Shortcuts', 'fluent-support'),
205 'inline_help' => __("If you enable this, agents can use keyboard shortcuts for faster actions.", 'fluent-support')
206 ]
207 ];
208
209 if (defined('FLUENTSUPPORTPRO_PLUGIN_VERSION')) {
210 $fields['agent_feedback_rating'] = [
211 'type' => 'inline-checkbox',
212 'true_label' => 'yes',
213 'false-label' => 'no',
214 'checkbox_label' => __('Agent Feedback Rating', 'fluent-support'),
215 'inline_help' => __("If you enable this setting, users will have the option to provide feedback on an agent's response.", 'fluent-support')
216 ];
217
218 $fields['agent_time_tracking'] = [
219 'type' => 'inline-checkbox',
220 'true_label' => 'yes',
221 'false-label' => 'no',
222 'checkbox_label' => __('Agent Time Tracking', 'fluent-support'),
223 'inline_help' => __("If you enable this setting, the agent can specify the amount of time needed to complete a ticket.", 'fluent-support')
224 ];
225
226 if (defined('FLUENTCART_VERSION')) {
227 $fields['enable_fc_menu'] = [
228 'type' => 'inline-checkbox',
229 'checkbox_label' => 'Add support link to Fluent Cart account navigation',
230 'inline_help' => __("If you enable this setting, support link will be added to Fluent Cart account navigation.", 'fluent-support'),
231 'true_label' => 'yes',
232 'false_label' => 'no'
233 ];
234 }
235 }
236
237 return $fields;
238 }
239
240 public function saveBoxEmailSettings($box, $emailKey, $settings)
241 {
242 return $box->saveMeta('_email_' . $emailKey, $settings);
243 }
244
245 /**
246 * getBoxEmailSettings method will reply the email settings
247 * @param $box
248 * @param $emailKey
249 * @return array|false
250 */
251 public function getBoxEmailSettings($box, $emailKey)
252 {
253 if (!$box) {
254 return false;
255 }
256
257 #ticket_closed_by_agent_email_to_customer 2 times, is it wrong or right!!!
258 $strictSubjectKeys = apply_filters('fluent_support/strict_subjects', [
259 'ticket_replied_by_agent_email_to_customer',
260 'ticket_closed_by_agent_email_to_customer',
261 'ticket_created_email_to_customer'
262 ]);
263
264 $settingsDefaults = [
265 'ticket_created_email_to_customer' => [
266 'key' => 'ticket_created_email_to_customer',
267 'title' => __('Ticket Created (To Customer)', 'fluent-support'),
268 'description' => __('This email will be sent when a customer submit a support ticket', 'fluent-support'),
269 'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}',
270 'default_status' => 'no',
271 'send_attachments'=> 'no'
272 ],
273 'ticket_replied_by_agent_email_to_customer' => [
274 'key' => 'ticket_replied_by_agent_email_to_customer',
275 'title' => __('Replied by Agent (To Customer)', 'fluent-support'),
276 'description' => __('This email will be sent when an agent reply to a ticket', 'fluent-support'),
277 'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}',
278 'default_status' => 'yes',
279 'send_attachments'=> 'no'
280 ],
281 'ticket_closed_by_agent_email_to_customer' => [
282 'key' => 'ticket_closed_by_agent_email_to_customer',
283 'title' => __('Ticket Closed by Agent (To Customer)', 'fluent-support'),
284 'description' => __('This email will be sent when an agent close a ticket', 'fluent-support'),
285 'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}',
286 'default_status' => 'no',
287 'send_attachments'=> 'no'
288 ],
289 'ticket_created_email_to_admin' => [
290 'key' => 'ticket_created_email_to_admin',
291 'title' => __('Ticket Created (To Admin)', 'fluent-support'),
292 'description' => __('This email will be sent when the business when a new ticket has been submitted', 'fluent-support'),
293 'email_subject' => 'New Ticket: {{ticket.title}} #{{ticket.id}}',
294 'default_status' => 'yes',
295 'send_attachments'=> 'no'
296 ],
297 'ticket_replied_by_customer_email_to_admin' => [
298 'key' => 'ticket_replied_by_customer_email_to_admin',
299 'title' => __('Replied by Customer (To Agent/Admin)', 'fluent-support'),
300 'description' => __('This email will be sent to Assigned Agent or Admin when a customer reply to a ticket', 'fluent-support'),
301 'email_subject' => 'New Response: {{ticket.title}} #{{ticket.id}}',
302 'default_status' => 'yes',
303 'send_attachments'=> 'no'
304 ],
305 'ticket_agent_on_change' => [
306 'key' => 'ticket_agent_on_change',
307 'title' => __('Ticket Agent Change (To Agent)', 'fluent-support'),
308 'description' => __('This email will be sent to newly assigned agent', 'fluent-support'),
309 'email_subject' => 'Ticket Agent Change: {{ticket.title}} #{{ticket.id}}',
310 'default_status' => 'yes',
311 'send_attachments'=> 'no'
312 ],
313 'ticket_created_by_agent_email_to_customer' => [
314 'key' => 'ticket_created_by_agent_email_to_customer',
315 'title' => __('Ticket Created by Agent (To Customer)', 'fluent-support'),
316 'description' => __('This email will be sent when an agent create a ticket for a customer', 'fluent-support'),
317 'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}',
318 'default_status' => 'no',
319 'send_attachments'=> 'no'
320 ]
321 ];
322
323 if (!isset($settingsDefaults[$emailKey])) {
324 return false;
325 }
326
327 $savedSettings = (array)$box->getMeta('_email_' . $emailKey, []);
328
329
330 if (!$savedSettings) {
331 $savedSettings = [
332 'key' => $settingsDefaults[$emailKey]['key'],
333 'title' => $settingsDefaults[$emailKey]['title'],
334 'email_subject' => $settingsDefaults[$emailKey]['email_subject'],
335 'email_body' => $this->getDefaultEmailBody($emailKey, $box->box_type),
336 'status' => $settingsDefaults[$emailKey]['default_status'],
337 'can_edit_subject' => (in_array($emailKey, $strictSubjectKeys) && $box->box_type == 'email') ? 'no' : 'yes',
338 'send_attachments' => $settingsDefaults[$emailKey]['send_attachments']
339 ];
340
341 if ($box->box_type == 'email' && in_array($emailKey, $strictSubjectKeys)) {
342 $savedSettings['email_subject'] = 'Re: {{ticket.title}}';
343 $savedSettings['can_edit_subject'] = 'no';
344 }
345
346 return $savedSettings;
347 }
348
349 $savedSettings['key'] = $settingsDefaults[$emailKey]['key'];
350 $savedSettings['title'] = $settingsDefaults[$emailKey]['title'];
351 $savedSettings['description'] = $settingsDefaults[$emailKey]['description'];
352
353 if ($box->box_type == 'email' && in_array($emailKey, $strictSubjectKeys)) {
354 $savedSettings['email_subject'] = 'Re: {{ticket.title}}';
355 $savedSettings['can_edit_subject'] = 'no';
356 }
357
358 if (empty($savedSettings['email_subject'])) {
359 $savedSettings['email_subject'] = $settingsDefaults[$emailKey]['email_subject'];
360 }
361
362 if (empty($savedSettings['status'])) {
363 $savedSettings['status'] = $settingsDefaults[$emailKey]['default_status'];
364 }
365
366 if (empty($savedSettings['email_body'])) {
367 $savedSettings['email_body'] = $this->getDefaultEmailBody($emailKey, $box->box_type);
368 }
369
370 if (empty($savedSettings['send_attachments'])) {
371 $savedSettings['send_attachments'] = $settingsDefaults[$emailKey]['send_attachments'];
372 }
373
374 return $savedSettings;
375 }
376
377 /**
378 * getDefaultEmailBody method will return html for email body
379 * @param $emailKey
380 * @param string $type
381 * @return string
382 */
383 private function getDefaultEmailBody($emailKey, $type = 'web')
384 {
385 if ($emailKey == 'ticket_created_email_to_customer') {
386 if ($type == 'web') {
387 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>';
388 } else {
389 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>';
390 }
391 } else if ($emailKey == 'ticket_replied_by_agent_email_to_customer') {
392 if ($type == 'web') {
393 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>';
394 } else {
395 return '{{response.full_content}}<p>Regards,<br />{{agent.full_name}}</p>';
396 }
397 } else if ($emailKey == 'ticket_closed_by_agent_email_to_customer') {
398 if ($type == 'web') {
399 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>';
400 } else {
401 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>';
402 }
403 } else if ($emailKey == 'ticket_created_email_to_admin') {
404 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>';
405 } else if ($emailKey == 'ticket_replied_by_customer_email_to_admin') {
406 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>';
407 } else if($emailKey == 'ticket_agent_on_change') {
408 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>';
409 } else if($emailKey == 'ticket_created_by_agent_email_to_customer') {
410 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>.';
411 }
412
413 return '';
414 }
415 }
416