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

275 lines 13.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
5 use FluentSupport\App\Services\Helper;
6
7 class Settings
8 {
9
10 public function getEmailSettingsKeys()
11 {
12 $key = apply_filters('fluent_support/email_setting_keys', [
13 'ticket_created_email_to_customer',
14 'ticket_replied_by_agent_email_to_customer',
15 'ticket_closed_by_agent_email_to_customer',
16 'ticket_created_email_to_admin',
17 'ticket_replied_by_customer_email_to_admin',
18 'ticket_agent_on_change'
19 ]);
20 return $key;
21 }
22
23 public function get($settingsKey)
24 {
25 if ($settingsKey == 'global_business_settings') {
26 return [
27 'settings' => $this->globalBusinessSettings(),
28 'fields' => $this->getGlobalBusinessSettingsFields()
29 ];
30 }
31
32 return [
33 'settings' => [],
34 'fields' => []
35 ];
36 }
37
38 public function save($settingsKey, $settings)
39 {
40 if ($settingsKey == 'global_business_settings' && empty($settings['accepted_file_types'])) {
41 $settings['accepted_file_types'] = [];
42 }
43
44 return Helper::updateOption($settingsKey, $settings);
45 }
46
47 public function globalBusinessSettings($cached = true)
48 {
49 static $settings;
50
51 if($cached && $settings) {
52 return $settings;
53 }
54
55 $defaults = [
56 'portal_page_id' => '',
57 'login_message' => sprintf(__('%1sPlease login or create an account to access the Customer Support Portal%2s [fluent_support_auth]', 'fluent-support'), '<p>', '</p>'),
58 'disable_public_ticket' => 'no',
59 'accepted_file_types' => ['images', 'csv', 'documents', 'zip', 'json'],
60 'max_file_size' => 2,
61 'del_files_on_close' => 'no'
62 ];
63
64 $existingSettings = Helper::getOption('global_business_settings', []);
65
66 if (!$existingSettings) {
67 $settings = $defaults;
68 return $settings;
69 }
70
71 $settings = wp_parse_args($existingSettings, $defaults);
72
73 return $settings;
74 }
75
76 private function getGlobalBusinessSettingsFields()
77 {
78
79 $mimeGroups = Helper::getMimeGroups();
80
81 $formattedMimeGroups = [];
82
83 foreach ($mimeGroups as $mimeGroup => $mime) {
84 $formattedMimeGroups[$mimeGroup] = $mime['title'];
85 }
86
87
88 $fields = [
89 'portal_page_id' => [
90 'type' => 'input-options',
91 'label' => __('Portal Page', 'fluent-support'),
92 'show_id' => true,
93 'placeholder' => __('Select Portal Page', 'fluent-support'),
94 'options' => Helper::getWPPages(),
95 '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')
96 ],
97 'login_message' => [
98 'type' => 'wp-editor',
99 'label' => __('Message for non logged in users', 'fluent-support'),
100 '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>'
101 ],
102 'disable_public_ticket' => [
103 'type' => 'inline-checkbox',
104 'true_label' => 'yes',
105 'false-label' => 'no',
106 'checkbox_label' => __('Disable Public Ticket interaction', 'fluent-support'),
107 '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')
108 ],
109 'accepted_file_types' => [
110 'wrapper_class' => 'fs_half_field',
111 'type' => 'checkbox-group',
112 'label' => __('Accepted File Types', 'fluent-support'),
113 'options' => $formattedMimeGroups
114 ],
115 'max_file_size' => [
116 'wrapper_class' => 'fs_half_field',
117 'type' => 'input-text',
118 'data_type' => 'number',
119 'label' => 'Max File Size (in MegaByte)',
120 ],
121 'del_files_on_close' => [
122 'type' => 'inline-checkbox',
123 'true_label' => 'yes',
124 'false-label' => 'no',
125 'checkbox_label' => __('Delete all attachments on ticket close', 'fluent-support'),
126 'inline_help' => __('If you enable this then when a ticket get closed it will delete all the attachments associated with the particular ticket.', 'fluent-support')
127 ]
128 ];
129
130 return $fields;
131 }
132
133 public function saveBoxEmailSettings($box, $emailKey, $settings)
134 {
135 return $box->saveMeta('_email_' . $emailKey, $settings);
136 }
137
138 public function getBoxEmailSettings($box, $emailKey)
139 {
140 if (!$box) {
141 return false;
142 }
143
144 $strictSubjectKeys = apply_filters('fluent_support/strict_subjects', [
145 'ticket_replied_by_agent_email_to_customer',
146 'ticket_closed_by_agent_email_to_customer',
147 'ticket_closed_by_agent_email_to_customer'
148 ]);
149
150 $settingsDefaults = [
151 'ticket_created_email_to_customer' => [
152 'key' => 'ticket_created_email_to_customer',
153 'title' => __('Ticket Created (To Customer)', 'fluent-support'),
154 'description' => __('This email will be sent when a customer submit a support ticket', 'fluent-support'),
155 'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}',
156 'default_status' => 'no'
157 ],
158 'ticket_replied_by_agent_email_to_customer' => [
159 'key' => 'ticket_replied_by_agent_email_to_customer',
160 'title' => __('Replied by Agent (To Customer)', 'fluent-support'),
161 'description' => __('This email will be sent when an agent reply to a ticket', 'fluent-support'),
162 'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}',
163 'default_status' => 'yes'
164 ],
165 'ticket_closed_by_agent_email_to_customer' => [
166 'key' => 'ticket_closed_by_agent_email_to_customer',
167 'title' => __('Ticket Closed by Agent (To Customer)', 'fluent-support'),
168 'description' => __('This email will be sent when an agent close a ticket', 'fluent-support'),
169 'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}',
170 'default_status' => 'yes'
171 ],
172 'ticket_created_email_to_admin' => [
173 'key' => 'ticket_created_email_to_admin',
174 'title' => __('Ticket Created (To Admin)', 'fluent-support'),
175 'description' => __('This email will be sent when the business when a new ticket has been submitted', 'fluent-support'),
176 'email_subject' => 'New Ticket: {{ticket.title}} #{{ticket.id}}',
177 'default_status' => 'yes'
178 ],
179 'ticket_replied_by_customer_email_to_admin' => [
180 'key' => 'ticket_replied_by_customer_email_to_admin',
181 'title' => __('Replied by Customer (To Agent/Admin)', 'fluent-support'),
182 'description' => __('This email will be sent to Assigned Agent or Admin when a customer reply to a ticket', 'fluent-support'),
183 'email_subject' => 'New Response: {{ticket.title}} #{{ticket.id}}',
184 'default_status' => 'yes'
185 ],
186 'ticket_agent_on_change' => [
187 'key' => 'ticket_agent_on_change',
188 'title' => __('Ticket Agent Change (To Agent)', 'fluent-support'),
189 'description' => __('This email will be sent to newly assigned agent', 'fluent-support'),
190 'email_subject' => 'Ticket Agent Change: {{ticket.title}} #{{ticket.id}}',
191 'default_status' => 'yes'
192 ]
193 ];
194
195 if (!isset($settingsDefaults[$emailKey])) {
196 return false;
197 }
198
199 $savedSettings = (array)$box->getMeta('_email_' . $emailKey, []);
200
201
202 if (!$savedSettings) {
203 $savedSettings = [
204 'key' => $settingsDefaults[$emailKey]['key'],
205 'title' => $settingsDefaults[$emailKey]['title'],
206 'email_subject' => $settingsDefaults[$emailKey]['email_subject'],
207 'email_body' => $this->getDefaultEmailBody($emailKey, $box->box_type),
208 'status' => $settingsDefaults[$emailKey]['default_status'],
209 'can_edit_subject' => (in_array($emailKey, $strictSubjectKeys) && $box->box_type == 'email') ? 'no' : 'yes'
210 ];
211
212 if ($box->box_type == 'email' && in_array($emailKey, $strictSubjectKeys)) {
213 $savedSettings['email_subject'] = 'Re: {{ticket.title}}';
214 $savedSettings['can_edit_subject'] = 'no';
215 }
216
217 return $savedSettings;
218 }
219
220 $savedSettings['key'] = $settingsDefaults[$emailKey]['key'];
221 $savedSettings['title'] = $settingsDefaults[$emailKey]['title'];
222 $savedSettings['description'] = $settingsDefaults[$emailKey]['description'];
223
224 if ($box->box_type == 'email' && in_array($emailKey, $strictSubjectKeys)) {
225 $savedSettings['email_subject'] = 'Re: {{ticket.title}}';
226 $savedSettings['can_edit_subject'] = 'no';
227 }
228
229 if (empty($savedSettings['email_subject'])) {
230 $savedSettings['email_subject'] = $settingsDefaults[$emailKey]['email_subject'];
231 }
232
233 if (empty($savedSettings['status'])) {
234 $savedSettings['status'] = $settingsDefaults[$emailKey]['default_status'];
235 }
236
237 if (empty($savedSettings['email_body'])) {
238 $savedSettings['email_body'] = $this->getDefaultEmailBody($emailKey, $box->box_type);
239 }
240
241 return $savedSettings;
242 }
243
244 private function getDefaultEmailBody($emailKey, $type = 'web')
245 {
246 if ($emailKey == 'ticket_created_email_to_customer') {
247 if ($type == 'web') {
248 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>';
249 } else {
250 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>';
251 }
252 } else if ($emailKey == 'ticket_replied_by_agent_email_to_customer') {
253 if ($type == 'web') {
254 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>';
255 } else {
256 return '{{response.full_content}}<p>Regards,<br />{{agent.full_name}}</p>';
257 }
258 } else if ($emailKey == 'ticket_closed_by_agent_email_to_customer') {
259 if ($type == 'web') {
260 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>';
261 } else {
262 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>';
263 }
264 } else if ($emailKey == 'ticket_created_email_to_admin') {
265 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>';
266 } else if ($emailKey == 'ticket_replied_by_customer_email_to_admin') {
267 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>';
268 } else if($emailKey == 'ticket_agent_on_change') {
269 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>';
270 }
271
272 return '';
273 }
274 }
275