| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Services\EmailNotification; |
| 4 |
use FluentSupportPro\Database\Migrations\TimeTrackMigrator; |
| 5 |
|
| 6 |
use FluentSupport\App\Services\Helper; |
| 7 |
use FluentSupport\App\Services\Notifications\NotificationSettings; |
| 8 |
use FluentSupport\Framework\Support\Arr; |
| 9 |
|
| 10 |
class Settings |
| 11 |
{ |
| 12 |
public function getEmailSettingsKeys() |
| 13 |
{ |
| 14 |
$key = apply_filters('fluent_support/email_setting_keys', [ |
| 15 |
'ticket_created_email_to_customer', |
| 16 |
'ticket_replied_by_agent_email_to_customer', |
| 17 |
'ticket_closed_by_agent_email_to_customer', |
| 18 |
'ticket_created_email_to_admin', |
| 19 |
'ticket_replied_by_customer_email_to_admin', |
| 20 |
'ticket_agent_on_change', |
| 21 |
'ticket_created_by_agent_email_to_customer', |
| 22 |
'ticket_created_by_agent_on_behalf_email_to_customer' |
| 23 |
]); |
| 24 |
return $key; |
| 25 |
} |
| 26 |
|
| 27 |
public function get($settingsKey) |
| 28 |
{ |
| 29 |
if ($settingsKey == 'global_business_settings') { |
| 30 |
return [ |
| 31 |
'settings' => $this->globalBusinessSettings(), |
| 32 |
'fields' => $this->getGlobalBusinessSettingsFields() |
| 33 |
]; |
| 34 |
} |
| 35 |
|
| 36 |
if ($settingsKey == NotificationSettings::OPTION_KEY) { |
| 37 |
$notificationSettings = new NotificationSettings(); |
| 38 |
|
| 39 |
return [ |
| 40 |
'settings' => $notificationSettings->get(false), |
| 41 |
'fields' => $notificationSettings->getFields() |
| 42 |
]; |
| 43 |
} |
| 44 |
|
| 45 |
return [ |
| 46 |
'settings' => [], |
| 47 |
'fields' => [] |
| 48 |
]; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* save method will save the requested settings by settings key |
| 53 |
* @param $settingsKey |
| 54 |
* @param $settings |
| 55 |
* @return mixed |
| 56 |
*/ |
| 57 |
public function save($settingsKey, $settings) |
| 58 |
{ |
| 59 |
if ($settingsKey == 'global_business_settings' && is_array($settings) && array_key_exists('internal_notifications_enabled', $settings)) { |
| 60 |
$notificationSettings = new NotificationSettings(); |
| 61 |
$savedNotificationSettings = $notificationSettings->get(false); |
| 62 |
$savedNotificationSettings['enabled'] = $settings['internal_notifications_enabled']; |
| 63 |
$notificationSettings->save($savedNotificationSettings); |
| 64 |
} |
| 65 |
|
| 66 |
if ($settingsKey == 'global_business_settings' && empty($settings['accepted_file_types'])) { |
| 67 |
$settings['accepted_file_types'] = []; |
| 68 |
} |
| 69 |
|
| 70 |
if ($settingsKey == 'global_business_settings') { |
| 71 |
$settings['ticket_link_portal_migrated'] = 'yes'; |
| 72 |
if (isset($settings['min_serial_number'])) { |
| 73 |
$settings['min_serial_number'] = max(1, (int) $settings['min_serial_number']); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
if ($settingsKey == 'global_business_settings' && !empty($settings['agent_time_tracking'])) { |
| 78 |
if (class_exists(TimeTrackMigrator::class) && $settings['agent_time_tracking'] === 'yes') { |
| 79 |
TimeTrackMigrator::migrate(); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
if ($settingsKey == NotificationSettings::OPTION_KEY) { |
| 84 |
return (new NotificationSettings())->save($settings); |
| 85 |
} |
| 86 |
|
| 87 |
$result = Helper::updateOption($settingsKey, $settings); |
| 88 |
|
| 89 |
return $result; |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* globalBusinessSettings method will fetch global settings from database, parse and return |
| 94 |
* @param bool $cached |
| 95 |
* @return array|mixed |
| 96 |
*/ |
| 97 |
public function globalBusinessSettings($cached = true) |
| 98 |
{ |
| 99 |
static $settings; |
| 100 |
|
| 101 |
if($cached && $settings) { |
| 102 |
return $settings; |
| 103 |
} |
| 104 |
|
| 105 |
$defaults = [ |
| 106 |
'portal_page_id' => '', |
| 107 |
'ticket_link_portal' => 'default', |
| 108 |
'ticket_link_portal_migrated' => 'no', |
| 109 |
// translators: %1$s is opening paragraph tag, %2$s is closing paragraph tag |
| 110 |
'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>'), |
| 111 |
'disable_public_ticket' => 'no', |
| 112 |
'accepted_file_types' => ['images', 'csv', 'documents', 'zip', 'json'], |
| 113 |
'max_file_size' => 2, |
| 114 |
'max_file_upload' => 3, |
| 115 |
'del_files_on_close' => 'no', |
| 116 |
'enable_admin_bar_summary' => 'no', |
| 117 |
'internal_notifications_enabled' => 'no', |
| 118 |
'enable_draft_mode' => 'no', |
| 119 |
'agent_feedback_rating' => 'no', |
| 120 |
'keyboard_shortcuts' => 'yes', |
| 121 |
'enable_min_serial_number' => 'no', |
| 122 |
'ticket_prefix' => '', |
| 123 |
'min_serial_number' => 1, |
| 124 |
'enable_fluent_booking_integration' => 'no', |
| 125 |
]; |
| 126 |
|
| 127 |
//Get default/existing settings from database using the key global_business_settings |
| 128 |
$existingSettings = Helper::getOption('global_business_settings', []); |
| 129 |
|
| 130 |
if (!$existingSettings) { |
| 131 |
$settings = $defaults; |
| 132 |
return $settings; |
| 133 |
} |
| 134 |
|
| 135 |
$settings = wp_parse_args($existingSettings, $defaults); |
| 136 |
$settings['ticket_link_portal'] = $settings['ticket_link_portal'] ?: 'default'; |
| 137 |
|
| 138 |
if (Arr::get($settings, 'ticket_link_portal_migrated') !== 'yes') { |
| 139 |
$settings['ticket_link_portal'] = $this->resolveLegacyTicketLinkPortal($settings); |
| 140 |
$settings['ticket_link_portal_migrated'] = 'yes'; |
| 141 |
Helper::updateOption('global_business_settings', $settings); |
| 142 |
} |
| 143 |
|
| 144 |
return $settings; |
| 145 |
} |
| 146 |
|
| 147 |
private function resolveLegacyTicketLinkPortal($settings) |
| 148 |
{ |
| 149 |
$selectedPortal = Arr::get($settings, 'ticket_link_portal', 'default'); |
| 150 |
|
| 151 |
if ($selectedPortal && $selectedPortal !== 'default') { |
| 152 |
return $selectedPortal; |
| 153 |
} |
| 154 |
|
| 155 |
$ticketFormSettings = Helper::getOption('_ticket_form_settings', []); |
| 156 |
|
| 157 |
if (Arr::get($settings, 'enable_fc_menu') === 'yes') { |
| 158 |
return 'fluent_cart'; |
| 159 |
} |
| 160 |
|
| 161 |
// The legacy pro plugin defaulted enable_woo_menu to 'yes', so treat an |
| 162 |
// absent value the same as 'yes' — only skip migration if explicitly 'no'. |
| 163 |
// WC portal was always Pro-only, so require Pro to be active as well. |
| 164 |
if (defined('FLUENTSUPPORTPRO_PLUGIN_VERSION') && defined('WC_PLUGIN_FILE') && Arr::get($ticketFormSettings, 'enable_woo_menu', 'yes') !== 'no') { |
| 165 |
return 'woocommerce'; |
| 166 |
} |
| 167 |
|
| 168 |
return 'default'; |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
/** |
| 173 |
* getGlobalBusinessSettingsFields method will prepare the list of field, and it's property that will be used in global settings form |
| 174 |
* @return array |
| 175 |
*/ |
| 176 |
private function getGlobalBusinessSettingsFields() |
| 177 |
{ |
| 178 |
$nextSerialNumber = \FluentSupport\App\Models\Ticket::getNextSerialNumber(); |
| 179 |
|
| 180 |
$mimeGroups = Helper::getMimeGroups(); |
| 181 |
|
| 182 |
$formattedMimeGroups = []; |
| 183 |
|
| 184 |
foreach ($mimeGroups as $mimeGroup => $mime) { |
| 185 |
$formattedMimeGroups[$mimeGroup] = $mime['title']; |
| 186 |
} |
| 187 |
|
| 188 |
$customRegistrationFormOptions = array( |
| 189 |
'address_line_1' => 'Address Line 1', |
| 190 |
'address_line_2' => 'Address Line 2', |
| 191 |
'city' => 'City', |
| 192 |
'zip' => 'Zip Code', |
| 193 |
'state' => 'State', |
| 194 |
'country' => 'Country', |
| 195 |
); |
| 196 |
|
| 197 |
$fields = [ |
| 198 |
'ticket_link_portal_description' => [ |
| 199 |
'type' => 'html-viewer', |
| 200 |
'label' => __('Customer Portal', 'fluent-support'), |
| 201 |
'wrapper_class' => 'fs_portal_destination_description', |
| 202 |
], |
| 203 |
'ticket_link_portal' => [ |
| 204 |
'type' => 'input-radio', |
| 205 |
'wrapper_class' => 'fs_portal_destination_options', |
| 206 |
'options' => $this->getTicketLinkPortalOptions(), |
| 207 |
], |
| 208 |
'fluent_community_portal_link' => [ |
| 209 |
'type' => 'html-viewer', |
| 210 |
'wrapper_class' => 'fs_fluent_community_portal_link', |
| 211 |
'html' => $this->getFluentCommunityPortalLinkHtml(), |
| 212 |
'dependency' => [ |
| 213 |
'depends_on' => 'ticket_link_portal', |
| 214 |
'operator' => '=', |
| 215 |
'value' => 'fluent_community' |
| 216 |
], |
| 217 |
], |
| 218 |
'portal_page_id' => [ |
| 219 |
'type' => 'input-options', |
| 220 |
'label' => __('Select a Page', 'fluent-support'), |
| 221 |
'wrapper_class' => 'fs_portal_page_selector', |
| 222 |
'show_id' => true, |
| 223 |
'placeholder' => __('Select Portal Page', 'fluent-support'), |
| 224 |
'options' => Helper::getWPPages(),//Get list of published pages |
| 225 |
'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'), |
| 226 |
'admin_url' => admin_url(), |
| 227 |
'home_url' => home_url('/'), |
| 228 |
'dependency' => [ |
| 229 |
'depends_on' => 'ticket_link_portal', |
| 230 |
'operator' => '=', |
| 231 |
'value' => 'default' |
| 232 |
], |
| 233 |
], |
| 234 |
'login_message' => [ |
| 235 |
'type' => 'wp-editor', |
| 236 |
'label' => __('Message for non logged in users', 'fluent-support'), |
| 237 |
'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') |
| 238 |
], |
| 239 |
'disable_public_ticket' => [ |
| 240 |
'wrapper_class' => '', |
| 241 |
'type' => 'inline-checkbox', |
| 242 |
'label' => __('Public Ticket Interaction', 'fluent-support'), |
| 243 |
'true_label' => 'yes', |
| 244 |
'false-label' => 'no', |
| 245 |
'checkbox_label' => __('Disable Public Ticket interaction', 'fluent-support'), |
| 246 |
'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') |
| 247 |
], |
| 248 |
'accepted_file_types' => [ |
| 249 |
'wrapper_class' => '', |
| 250 |
'type' => 'checkbox-group', |
| 251 |
'label' => __('Accepted File Types', 'fluent-support'), |
| 252 |
'options' => $formattedMimeGroups |
| 253 |
], |
| 254 |
'max_file_size' => [ |
| 255 |
'wrapper_class' => 'fs_settings_half_field', |
| 256 |
'type' => 'input-text', |
| 257 |
'data_type' => 'number', |
| 258 |
'label' => __('Max File Size (in MegaByte)', 'fluent-support'), |
| 259 |
], |
| 260 |
'max_file_upload' => [ |
| 261 |
'wrapper_class' => 'fs_settings_half_field', |
| 262 |
'type' => 'input-text', |
| 263 |
'data_type' => 'number', |
| 264 |
'label' => __('Maximum File Upload', 'fluent-support'), |
| 265 |
], |
| 266 |
'del_files_on_close' => [ |
| 267 |
'wrapper_class' => '', |
| 268 |
'type' => 'inline-checkbox', |
| 269 |
'true_label' => 'yes', |
| 270 |
'false-label' => 'no', |
| 271 |
'checkbox_label' => __('Delete all attachments on ticket close', 'fluent-support'), |
| 272 |
'inline_help' => __('If you enable this feature, all attachments associated with a ticket will be deleted when the ticket is closed.', 'fluent-support') |
| 273 |
], |
| 274 |
'enable_admin_bar_summary' => [ |
| 275 |
'wrapper_class' => '', |
| 276 |
'type' => 'inline-checkbox', |
| 277 |
'true_label' => 'yes', |
| 278 |
'false-label' => 'no', |
| 279 |
'checkbox_label' => __('Enable Fluent Summary In Admin Bar', 'fluent-support'), |
| 280 |
'inline_help' => __('If you enable this, logged in user can see the ticket summary from top nav bar.', 'fluent-support') |
| 281 |
], |
| 282 |
'internal_notifications_enabled' => [ |
| 283 |
'wrapper_class' => '', |
| 284 |
'type' => 'inline-checkbox', |
| 285 |
'true_label' => 'yes', |
| 286 |
'false-label' => 'no', |
| 287 |
'checkbox_label' => __('Enable Internal Notifications', 'fluent-support'), |
| 288 |
'inline_help' => sprintf( |
| 289 |
'<ul><li>%1$s</li><li>%2$s</li></ul>', |
| 290 |
__('Enable the in-app notification bell, unread counts, and notification event storage for agents.', 'fluent-support'), |
| 291 |
__('Notification data older than 15 days will be removed automatically.', 'fluent-support') |
| 292 |
) |
| 293 |
], |
| 294 |
'enable_draft_mode' => [ |
| 295 |
'wrapper_class' => '', |
| 296 |
'type' => 'inline-checkbox', |
| 297 |
'true_label' => 'yes', |
| 298 |
'false-label' => 'no', |
| 299 |
'checkbox_label' => __('Enable Draft Mode', 'fluent-support'), |
| 300 |
'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') |
| 301 |
], |
| 302 |
'custom_registration_form_field' => [ |
| 303 |
'wrapper_class' => '', |
| 304 |
'type' => 'checkbox-group', |
| 305 |
'label' => __('Custom Registration Form Field', 'fluent-support'), |
| 306 |
'options' => $customRegistrationFormOptions |
| 307 |
], |
| 308 |
'enable_two_fa' => [ |
| 309 |
'wrapper_class' => '', |
| 310 |
'type' => 'inline-checkbox', |
| 311 |
'true_label' => 'yes', |
| 312 |
'false-label' => 'no', |
| 313 |
'checkbox_label' => __('Enable Two-Factor Authentication', 'fluent-support'), |
| 314 |
'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') |
| 315 |
], |
| 316 |
'keyboard_shortcuts' => [ |
| 317 |
'wrapper_class' => '', |
| 318 |
'type' => 'inline-checkbox', |
| 319 |
'true_label' => 'yes', |
| 320 |
'false-label' => 'no', |
| 321 |
'checkbox_label' => __('Enable Keyboard Shortcuts', 'fluent-support'), |
| 322 |
'inline_help' => __("If you enable this, agents can use keyboard shortcuts for faster actions.", 'fluent-support'), |
| 323 |
'shortcut_modal' => $this->getKeyboardShortcutModalData() |
| 324 |
], |
| 325 |
'enable_min_serial_number' => [ |
| 326 |
'wrapper_class' => '', |
| 327 |
'type' => 'inline-checkbox', |
| 328 |
'true_label' => 'yes', |
| 329 |
'false-label' => 'no', |
| 330 |
'checkbox_label' => __('Enable Minimum Ticket Number', 'fluent-support'), |
| 331 |
'inline_help' => __('Enable this to start public ticket numbers from a custom minimum number.', 'fluent-support') |
| 332 |
], |
| 333 |
'min_serial_number' => [ |
| 334 |
'wrapper_class' => 'fs_settings_half_field', |
| 335 |
'type' => 'input-text', |
| 336 |
'data_type' => 'number', |
| 337 |
'label' => __('Minimum Ticket Number', 'fluent-support'), |
| 338 |
'help' => __('Once a ticket is created, you cannot lower this value below the current highest ticket number. Set this carefully — raising it is easy, but lowering it below an existing ticket number is not allowed.', 'fluent-support'), |
| 339 |
'inline_help' => sprintf( |
| 340 |
__('Next Ticket Number: %d', 'fluent-support'), |
| 341 |
$nextSerialNumber |
| 342 |
), |
| 343 |
'next_serial_number' => $nextSerialNumber, |
| 344 |
'dependency' => [ |
| 345 |
'depends_on' => 'enable_min_serial_number', |
| 346 |
'operator' => '=', |
| 347 |
'value' => 'yes' |
| 348 |
] |
| 349 |
], |
| 350 |
'ticket_prefix' => [ |
| 351 |
'wrapper_class' => 'fs_settings_half_field', |
| 352 |
'type' => 'input-text', |
| 353 |
'data_type' => 'text', |
| 354 |
'label' => __('Ticket Prefix', 'fluent-support'), |
| 355 |
'inline_help' => __('Optional prefix for newly created public ticket numbers.', 'fluent-support'), |
| 356 |
'dependency' => [ |
| 357 |
'depends_on' => 'enable_min_serial_number', |
| 358 |
'operator' => '=', |
| 359 |
'value' => 'yes' |
| 360 |
] |
| 361 |
] |
| 362 |
]; |
| 363 |
if (defined('FLUENT_BOOKING_VERSION')) { |
| 364 |
$fields['enable_fluent_booking_integration'] = [ |
| 365 |
'wrapper_class' => '', |
| 366 |
'type' => 'inline-checkbox', |
| 367 |
'true_label' => 'yes', |
| 368 |
'false-label' => 'no', |
| 369 |
'checkbox_label' => __('Enable Fluent Booking Integration', 'fluent-support'), |
| 370 |
'inline_help' => __('If you enable this, agents can create booking links and view meeting details inside tickets.', 'fluent-support') |
| 371 |
]; |
| 372 |
} |
| 373 |
|
| 374 |
if (defined('FLUENTSUPPORTPRO_PLUGIN_VERSION')) { |
| 375 |
$fields['agent_feedback_rating'] = [ |
| 376 |
'wrapper_class' => '', |
| 377 |
'type' => 'inline-checkbox', |
| 378 |
'true_label' => 'yes', |
| 379 |
'false-label' => 'no', |
| 380 |
'checkbox_label' => __('Agent Feedback Rating', 'fluent-support'), |
| 381 |
'inline_help' => __("If you enable this setting, users will have the option to provide feedback on an agent's response.", 'fluent-support') |
| 382 |
]; |
| 383 |
|
| 384 |
$fields['agent_time_tracking'] = [ |
| 385 |
'wrapper_class' => '', |
| 386 |
'type' => 'inline-checkbox', |
| 387 |
'true_label' => 'yes', |
| 388 |
'false-label' => 'no', |
| 389 |
'checkbox_label' => __('Agent Time Tracking', 'fluent-support'), |
| 390 |
'inline_help' => __("If you enable this setting, the agent can specify the amount of time needed to complete a ticket.", 'fluent-support') |
| 391 |
]; |
| 392 |
|
| 393 |
} |
| 394 |
|
| 395 |
return $fields; |
| 396 |
} |
| 397 |
|
| 398 |
private function getTicketLinkPortalOptions() |
| 399 |
{ |
| 400 |
$options = [ |
| 401 |
[ |
| 402 |
'id' => 'default', |
| 403 |
'label' => __('Default Portal Page', 'fluent-support'), |
| 404 |
], |
| 405 |
]; |
| 406 |
|
| 407 |
if (Helper::isPortalActive('fluent_cart')) { |
| 408 |
$options[] = [ |
| 409 |
'id' => 'fluent_cart', |
| 410 |
'label' => __('FluentCart Account Navigation', 'fluent-support'), |
| 411 |
]; |
| 412 |
} |
| 413 |
|
| 414 |
if (Helper::isPortalActive('woocommerce')) { |
| 415 |
$options[] = [ |
| 416 |
'id' => 'woocommerce', |
| 417 |
'label' => __('WooCommerce Account Navigation', 'fluent-support'), |
| 418 |
]; |
| 419 |
} |
| 420 |
|
| 421 |
if (Helper::isPortalActive('fluent_community')) { |
| 422 |
$options[] = [ |
| 423 |
'id' => 'fluent_community', |
| 424 |
'label' => __('FluentCommunity Portal', 'fluent-support'), |
| 425 |
]; |
| 426 |
} |
| 427 |
|
| 428 |
return apply_filters('fluent_support/ticket_link_portal_options', $options); |
| 429 |
} |
| 430 |
|
| 431 |
private function getFluentCommunityPortalLinkHtml() |
| 432 |
{ |
| 433 |
if (!defined('FLUENT_COMMUNITY_PLUGIN_VERSION') || !class_exists('\FluentCommunity\App\Services\Helper')) { |
| 434 |
return ''; |
| 435 |
} |
| 436 |
|
| 437 |
$portalLink = rtrim(\FluentCommunity\App\Services\Helper::baseUrl('support/'), '/\\') . '/'; |
| 438 |
|
| 439 |
return '<div class="fs_portal_link_content">' |
| 440 |
. '<span class="fs_portal_link_label">' . esc_html__('FluentCommunity Portal URL', 'fluent-support') . '</span>' |
| 441 |
. '<button type="button" class="fs_portal_link_token" data-portal-link="' . esc_attr($portalLink) . '">' |
| 442 |
. '<span class="fs_portal_link_text">' . esc_html($portalLink) . '</span>' |
| 443 |
. '<span class="fs_portal_link_action">' . esc_html__('Copy', 'fluent-support') . '</span>' |
| 444 |
. '</button>' |
| 445 |
. '<p class="fc_inline_help">' . esc_html__('Copy this URL and add it to your FluentCommunity menu.', 'fluent-support') . '</p>' |
| 446 |
. '</div>'; |
| 447 |
} |
| 448 |
|
| 449 |
/** |
| 450 |
* Returns translatable keyboard shortcut modal data for the settings form. |
| 451 |
* |
| 452 |
* @return array{title: string, mac_label: string, win_label: string, action_label: string, shortcut_label: string, mac_shortcuts: array, win_shortcuts: array} |
| 453 |
*/ |
| 454 |
public function getKeyboardShortcutModalData() |
| 455 |
{ |
| 456 |
$actionLabel = __('Action', 'fluent-support'); |
| 457 |
$shortcutLabel = __('Shortcut', 'fluent-support'); |
| 458 |
|
| 459 |
$macShortcuts = [ |
| 460 |
['action' => __('Tickets – Advanced filter toggle', 'fluent-support'), 'shortcut' => '⌘ + ⌥ + f'], |
| 461 |
['action' => __('Tickets – Refresh', 'fluent-support'), 'shortcut' => '⌘ + ⌥ + q'], |
| 462 |
['action' => __('Tickets – Create Ticket', 'fluent-support'), 'shortcut' => '⌘ + ⌥ + n'], |
| 463 |
['action' => __('Tickets – Reset filter', 'fluent-support'), 'shortcut' => '⌘ + ⌥ + r'], |
| 464 |
['action' => __('Tickets – All Tickets', 'fluent-support'), 'shortcut' => '⌘ + ⇧ + a'], |
| 465 |
['action' => __('Tickets – My Tickets', 'fluent-support'), 'shortcut' => '⌘ + ⇧ + m'], |
| 466 |
['action' => __('Tickets – Unassigned', 'fluent-support'), 'shortcut' => '⌘ + ⇧ + u'], |
| 467 |
['action' => __('Tickets – Waiting for reply', 'fluent-support'), 'shortcut' => '⌘ + ⌥ + w'], |
| 468 |
['action' => __('Tickets – Bookmarks', 'fluent-support'), 'shortcut' => '⌘ + ⇧ + b'], |
| 469 |
['action' => __('Tickets – Toggle (Open, active, close, all)', 'fluent-support'), 'shortcut' => '⌘ + ⇧ + → / ←'], |
| 470 |
['action' => __('Ticket Reply – Reply', 'fluent-support'), 'shortcut' => '⌘ + ⌥ + r'], |
| 471 |
['action' => __('Ticket Reply – Personal note', 'fluent-support'), 'shortcut' => '⌘ + ⌥ + n'], |
| 472 |
['action' => __('Ticket Reply – Merge', 'fluent-support'), 'shortcut' => '⌘ + ⌥ + m'], |
| 473 |
['action' => __('Ticket Reply – Bookmarks', 'fluent-support'), 'shortcut' => '⌘ + ⌥ + b'], |
| 474 |
['action' => __('Ticket Reply – Refresh', 'fluent-support'), 'shortcut' => '⌘ + ⌥ + q'], |
| 475 |
]; |
| 476 |
|
| 477 |
$winShortcuts = [ |
| 478 |
['action' => __('Tickets – Advanced filter toggle', 'fluent-support'), 'shortcut' => 'Alt + Win + Shift + f'], |
| 479 |
['action' => __('Tickets – Refresh', 'fluent-support'), 'shortcut' => 'Alt + Win + q'], |
| 480 |
['action' => __('Tickets – Create Ticket', 'fluent-support'), 'shortcut' => 'Alt + Win + n'], |
| 481 |
['action' => __('Tickets – Reset filter', 'fluent-support'), 'shortcut' => 'Alt + Win + Shift + r'], |
| 482 |
['action' => __('Tickets – All Tickets', 'fluent-support'), 'shortcut' => 'Win + Shift + a'], |
| 483 |
['action' => __('Tickets – My Tickets', 'fluent-support'), 'shortcut' => 'Alt + Win + Shift + m'], |
| 484 |
['action' => __('Tickets – Unassigned', 'fluent-support'), 'shortcut' => 'Win + Shift + u'], |
| 485 |
['action' => __('Tickets – Waiting for reply', 'fluent-support'), 'shortcut' => 'Alt + Win + Shift + w'], |
| 486 |
['action' => __('Tickets – Bookmarks', 'fluent-support'), 'shortcut' => 'Win + Shift + b'], |
| 487 |
['action' => __('Ticket Reply – Reply', 'fluent-support'), 'shortcut' => 'Alt + Win + Shift + r'], |
| 488 |
['action' => __('Ticket Reply – Personal note', 'fluent-support'), 'shortcut' => 'Alt + Win + n'], |
| 489 |
['action' => __('Ticket Reply – Merge', 'fluent-support'), 'shortcut' => 'Ctrl + Alt + Win + m'], |
| 490 |
['action' => __('Ticket Reply – Bookmarks', 'fluent-support'), 'shortcut' => 'Ctrl + Alt + Win + b'], |
| 491 |
['action' => __('Ticket Reply – Refresh', 'fluent-support'), 'shortcut' => 'Alt + Win + q'], |
| 492 |
]; |
| 493 |
|
| 494 |
return [ |
| 495 |
'title' => __('Keyboard Shortcuts', 'fluent-support'), |
| 496 |
'mac_label' => __('macOS', 'fluent-support'), |
| 497 |
'win_label' => __('Windows', 'fluent-support'), |
| 498 |
'action_label' => $actionLabel, |
| 499 |
'shortcut_label'=> $shortcutLabel, |
| 500 |
'mac_shortcuts' => $macShortcuts, |
| 501 |
'win_shortcuts' => $winShortcuts, |
| 502 |
]; |
| 503 |
} |
| 504 |
|
| 505 |
public function saveBoxEmailSettings($box, $emailKey, $settings) |
| 506 |
{ |
| 507 |
return $box->saveMeta('_email_' . $emailKey, $settings); |
| 508 |
} |
| 509 |
|
| 510 |
/** |
| 511 |
* getBoxEmailSettings method will reply the email settings |
| 512 |
* @param $box |
| 513 |
* @param $emailKey |
| 514 |
* @return array|false |
| 515 |
*/ |
| 516 |
public function getBoxEmailSettings($box, $emailKey) |
| 517 |
{ |
| 518 |
if (!$box) { |
| 519 |
return false; |
| 520 |
} |
| 521 |
|
| 522 |
#ticket_closed_by_agent_email_to_customer 2 times, is it wrong or right!!! |
| 523 |
$strictSubjectKeys = apply_filters('fluent_support/strict_subjects', [ |
| 524 |
'ticket_replied_by_agent_email_to_customer', |
| 525 |
'ticket_closed_by_agent_email_to_customer', |
| 526 |
'ticket_created_email_to_customer' |
| 527 |
]); |
| 528 |
|
| 529 |
$settingsDefaults = [ |
| 530 |
'ticket_created_email_to_customer' => [ |
| 531 |
'key' => 'ticket_created_email_to_customer', |
| 532 |
'title' => __('Ticket Created (To Customer)', 'fluent-support'), |
| 533 |
'description' => __('This email will be sent when a customer submit a support ticket', 'fluent-support'), |
| 534 |
'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}', |
| 535 |
'default_status' => 'no', |
| 536 |
'send_attachments'=> 'no' |
| 537 |
], |
| 538 |
'ticket_replied_by_agent_email_to_customer' => [ |
| 539 |
'key' => 'ticket_replied_by_agent_email_to_customer', |
| 540 |
'title' => __('Replied by Agent (To Customer)', 'fluent-support'), |
| 541 |
'description' => __('This email will be sent when an agent reply to a ticket', 'fluent-support'), |
| 542 |
'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}', |
| 543 |
'default_status' => 'yes', |
| 544 |
'send_attachments'=> 'no' |
| 545 |
], |
| 546 |
'ticket_closed_by_agent_email_to_customer' => [ |
| 547 |
'key' => 'ticket_closed_by_agent_email_to_customer', |
| 548 |
'title' => __('Ticket Closed by Agent (To Customer)', 'fluent-support'), |
| 549 |
'description' => __('This email will be sent when an agent close a ticket', 'fluent-support'), |
| 550 |
'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}', |
| 551 |
'default_status' => 'no', |
| 552 |
'send_attachments'=> 'no' |
| 553 |
], |
| 554 |
'ticket_created_email_to_admin' => [ |
| 555 |
'key' => 'ticket_created_email_to_admin', |
| 556 |
'title' => __('Ticket Created (To Admin)', 'fluent-support'), |
| 557 |
'description' => __('This email will be sent when the business when a new ticket has been submitted', 'fluent-support'), |
| 558 |
'email_subject' => 'New Ticket: {{ticket.title}} #{{ticket.id}}', |
| 559 |
'default_status' => 'yes', |
| 560 |
'send_attachments'=> 'no' |
| 561 |
], |
| 562 |
'ticket_replied_by_customer_email_to_admin' => [ |
| 563 |
'key' => 'ticket_replied_by_customer_email_to_admin', |
| 564 |
'title' => __('Replied by Customer (To Agent/Admin)', 'fluent-support'), |
| 565 |
'description' => __('This email will be sent to Assigned Agent or Admin when a customer reply to a ticket', 'fluent-support'), |
| 566 |
'email_subject' => 'New Response: {{ticket.title}} #{{ticket.id}}', |
| 567 |
'default_status' => 'yes', |
| 568 |
'send_attachments'=> 'no' |
| 569 |
], |
| 570 |
'ticket_agent_on_change' => [ |
| 571 |
'key' => 'ticket_agent_on_change', |
| 572 |
'title' => __('Ticket Agent Change (To Agent)', 'fluent-support'), |
| 573 |
'description' => __('This email will be sent to newly assigned agent', 'fluent-support'), |
| 574 |
'email_subject' => 'Ticket Agent Change: {{ticket.title}} #{{ticket.id}}', |
| 575 |
'default_status' => 'yes', |
| 576 |
'send_attachments'=> 'no' |
| 577 |
], |
| 578 |
'ticket_created_by_agent_email_to_customer' => [ |
| 579 |
'key' => 'ticket_created_by_agent_email_to_customer', |
| 580 |
'title' => __('Ticket Logged by Agent (To Customer)', 'fluent-support'), |
| 581 |
'description' => __('This email will be sent when an agent logs a ticket on behalf of a customer (e.g. from a phone call or email received outside the system)', 'fluent-support'), |
| 582 |
'email_subject' => 'Re: {{ticket.title}} #{{ticket.id}}', |
| 583 |
'default_status' => 'no', |
| 584 |
'send_attachments'=> 'no' |
| 585 |
], |
| 586 |
'ticket_created_by_agent_on_behalf_email_to_customer' => [ |
| 587 |
'key' => 'ticket_created_by_agent_on_behalf_email_to_customer', |
| 588 |
'title' => __('Agent Outreach Ticket (To Customer)', 'fluent-support'), |
| 589 |
'description' => __('This email will be sent when an agent creates a ticket using the "Agent Initiated" option to proactively reach out to a customer — includes the agent\'s message content', 'fluent-support'), |
| 590 |
'email_subject' => 'Your ticket has been created (#{{ticket.id}})', |
| 591 |
'default_status' => 'yes', |
| 592 |
'send_attachments'=> 'no' |
| 593 |
] |
| 594 |
]; |
| 595 |
|
| 596 |
if (!isset($settingsDefaults[$emailKey])) { |
| 597 |
return false; |
| 598 |
} |
| 599 |
|
| 600 |
$savedSettings = (array)$box->getMeta('_email_' . $emailKey, []); |
| 601 |
|
| 602 |
|
| 603 |
if (!$savedSettings) { |
| 604 |
$savedSettings = [ |
| 605 |
'key' => $settingsDefaults[$emailKey]['key'], |
| 606 |
'title' => $settingsDefaults[$emailKey]['title'], |
| 607 |
'email_subject' => $settingsDefaults[$emailKey]['email_subject'], |
| 608 |
'email_body' => $this->getDefaultEmailBody($emailKey, $box->box_type), |
| 609 |
'status' => $settingsDefaults[$emailKey]['default_status'], |
| 610 |
'can_edit_subject' => (in_array($emailKey, $strictSubjectKeys) && $box->box_type == 'email') ? 'no' : 'yes', |
| 611 |
'send_attachments' => $settingsDefaults[$emailKey]['send_attachments'] |
| 612 |
]; |
| 613 |
|
| 614 |
if ($box->box_type == 'email' && in_array($emailKey, $strictSubjectKeys)) { |
| 615 |
$savedSettings['email_subject'] = 'Re: {{ticket.title}}'; |
| 616 |
$savedSettings['can_edit_subject'] = 'no'; |
| 617 |
} |
| 618 |
|
| 619 |
return $savedSettings; |
| 620 |
} |
| 621 |
|
| 622 |
$savedSettings['key'] = $settingsDefaults[$emailKey]['key']; |
| 623 |
$savedSettings['title'] = $settingsDefaults[$emailKey]['title']; |
| 624 |
$savedSettings['description'] = $settingsDefaults[$emailKey]['description']; |
| 625 |
|
| 626 |
if ($box->box_type == 'email' && in_array($emailKey, $strictSubjectKeys)) { |
| 627 |
$savedSettings['email_subject'] = 'Re: {{ticket.title}}'; |
| 628 |
$savedSettings['can_edit_subject'] = 'no'; |
| 629 |
} |
| 630 |
|
| 631 |
if (empty($savedSettings['email_subject'])) { |
| 632 |
$savedSettings['email_subject'] = $settingsDefaults[$emailKey]['email_subject']; |
| 633 |
} |
| 634 |
|
| 635 |
if (empty($savedSettings['status'])) { |
| 636 |
$savedSettings['status'] = $settingsDefaults[$emailKey]['default_status']; |
| 637 |
} |
| 638 |
|
| 639 |
if (empty($savedSettings['email_body'])) { |
| 640 |
$savedSettings['email_body'] = $this->getDefaultEmailBody($emailKey, $box->box_type); |
| 641 |
} |
| 642 |
|
| 643 |
if (empty($savedSettings['send_attachments'])) { |
| 644 |
$savedSettings['send_attachments'] = $settingsDefaults[$emailKey]['send_attachments']; |
| 645 |
} |
| 646 |
|
| 647 |
return $savedSettings; |
| 648 |
} |
| 649 |
|
| 650 |
/** |
| 651 |
* getDefaultEmailBody method will return html for email body |
| 652 |
* @param $emailKey |
| 653 |
* @param string $type |
| 654 |
* @return string |
| 655 |
*/ |
| 656 |
private function getDefaultEmailBody($emailKey, $type = 'web') |
| 657 |
{ |
| 658 |
if ($emailKey == 'ticket_created_email_to_customer') { |
| 659 |
if ($type == 'web') { |
| 660 |
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> </p><p>or follow this link: {{ticket.public_url}}</p><hr /><p>{{business.name}}</p>'; |
| 661 |
} else { |
| 662 |
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>'; |
| 663 |
} |
| 664 |
} else if ($emailKey == 'ticket_replied_by_agent_email_to_customer') { |
| 665 |
if ($type == 'web') { |
| 666 |
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>'; |
| 667 |
} else { |
| 668 |
return '{{response.full_content}}<p>Regards,<br />{{agent.full_name}}</p>'; |
| 669 |
} |
| 670 |
} else if ($emailKey == 'ticket_closed_by_agent_email_to_customer') { |
| 671 |
if ($type == 'web') { |
| 672 |
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>'; |
| 673 |
} else { |
| 674 |
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>'; |
| 675 |
} |
| 676 |
} else if ($emailKey == 'ticket_created_email_to_admin') { |
| 677 |
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>'; |
| 678 |
} else if ($emailKey == 'ticket_replied_by_customer_email_to_admin') { |
| 679 |
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>'; |
| 680 |
} else if($emailKey == 'ticket_agent_on_change') { |
| 681 |
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>'; |
| 682 |
} else if($emailKey == 'ticket_created_by_agent_email_to_customer') { |
| 683 |
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>.'; |
| 684 |
} else if($emailKey == 'ticket_created_by_agent_on_behalf_email_to_customer') { |
| 685 |
if ($type == 'web') { |
| 686 |
return '<p>Hi <strong><em>{{customer.full_name}}</em>,</strong></p><p>A support agent has created a new ticket on your behalf titled "{{ticket.title}}" (#{{ticket.id}}).</p><p>You can review the details, track progress, or add additional comments by clicking the button below:</p><h4><a href="{{ticket.public_url}}">View Ticket</a></h4><p>Or follow this link: {{ticket.public_url}}</p><p>Best regards,<br />{{agent.full_name}}</p>'; |
| 687 |
} else { |
| 688 |
return '{{response.full_content}}<p>Regards,<br />{{agent.full_name}}</p>'; |
| 689 |
} |
| 690 |
} |
| 691 |
|
| 692 |
return ''; |
| 693 |
} |
| 694 |
} |
| 695 |
|