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

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