PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.4
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.4
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / class-wpsc-installation.php

class-wpsc-installation.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.5.4, at class-wpsc-installation.php

3,188 lines 106.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_Installation' ) ) :
7
8 final class WPSC_Installation {
9
10 /**
11 * Currently installed version
12 *
13 * @var string
14 */
15 public static $current_version;
16
17 /**
18 * Current database version
19 *
20 * @var string
21 */
22 public static $current_db_version;
23
24 /**
25 * For checking whether upgrade available or not
26 *
27 * @var boolean
28 */
29 public static $is_upgrade = false;
30
31 /**
32 * Initialize installation
33 */
34 public static function init() {
35
36 self::get_current_version();
37 self::check_upgrade();
38
39 // database upgrade available.
40 if ( self::$current_version > 0 && self::$current_db_version < WPSC_DB_VERSION ) {
41
42 define( 'WPSC_DB_UPGRADING', true );
43 return;
44 }
45
46 // fresh installation or regular update.
47 if ( self::$is_upgrade ) {
48
49 define( 'WPSC_INSTALLING', true );
50
51 // Do not allow parallel process to run.
52 if ( 'yes' === get_transient( 'wpsc_installing' ) ) {
53 return;
54 }
55
56 // Set transient.
57 set_transient( 'wpsc_installing', 'yes', MINUTE_IN_SECONDS * 10 );
58
59 // Create or update database tables.
60 self::create_db_tables();
61
62 // Run installation.
63 if ( self::$current_version == 0 ) {
64
65 add_action( 'init', array( __CLASS__, 'initial_setup' ), 1 );
66 add_action( 'init', array( __CLASS__, 'set_upgrade_complete' ), 1 );
67
68 } else {
69
70 add_action( 'init', array( __CLASS__, 'upgrade' ), 1 );
71 }
72
73 // Delete transient.
74 delete_transient( 'wpsc_installing' );
75 }
76
77 // Deactivate functionality.
78 register_deactivation_hook( WPSC_PLUGIN_FILE, array( __CLASS__, 'deactivate' ) );
79 }
80
81 /**
82 * Check version
83 */
84 public static function get_current_version() {
85
86 self::$current_version = get_option( 'wpsc_current_version', '0' );
87 self::$current_db_version = get_option( 'wpsc_db_version', '1.0' );
88 }
89
90 /**
91 * Check for upgrade
92 */
93 public static function check_upgrade() {
94
95 if ( self::$current_version != WPSC_VERSION ) {
96 self::$is_upgrade = true;
97 }
98 }
99
100 /**
101 * Create database tables
102 */
103 public static function create_db_tables() {
104
105 global $wpdb;
106
107 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
108
109 $collate = '';
110 if ( $wpdb->has_cap( 'collation' ) ) {
111 $collate = $wpdb->get_charset_collate();
112 }
113
114 $tables = "
115 CREATE TABLE {$wpdb->prefix}psmsc_tickets (
116 id BIGINT NOT NULL AUTO_INCREMENT,
117 is_active INT(1) NOT NULL DEFAULT '1',
118 customer BIGINT NOT NULL,
119 subject TEXT NOT NULL,
120 status INT NOT NULL,
121 priority INT NOT NULL,
122 category INT NOT NULL,
123 assigned_agent TEXT NULL,
124 date_created DATETIME NOT NULL,
125 date_updated DATETIME NOT NULL,
126 agent_created INT DEFAULT NULL,
127 ip_address VARCHAR(50) DEFAULT NULL,
128 source VARCHAR(50) DEFAULT NULL,
129 browser VARCHAR(50) DEFAULT NULL,
130 os VARCHAR(50) DEFAULT NULL,
131 add_recipients TEXT NULL,
132 prev_assignee TEXT NULL,
133 date_closed DATETIME DEFAULT NULL,
134 user_type VARCHAR(100) NOT NULL,
135 last_reply_on DATETIME DEFAULT NULL,
136 last_reply_by BIGINT NOT NULL,
137 last_reply_source VARCHAR(50) DEFAULT NULL,
138 auth_code VARCHAR(50) DEFAULT NULL,
139 tags TINYTEXT NULL DEFAULT NULL,
140 live_agents TINYTEXT NULL DEFAULT NULL,
141 misc LONGTEXT NULL DEFAULT NULL,
142 PRIMARY KEY (id)
143 ) $collate;
144 CREATE TABLE {$wpdb->prefix}psmsc_customers (
145 id BIGINT NOT NULL AUTO_INCREMENT,
146 user BIGINT NOT NULL,
147 ticket_count INT NOT NULL DEFAULT '0',
148 name VARCHAR(200) NOT NULL,
149 email VARCHAR(200) NOT NULL,
150 PRIMARY KEY (id)
151 ) $collate;
152 CREATE TABLE {$wpdb->prefix}psmsc_custom_fields (
153 id INT NOT NULL AUTO_INCREMENT,
154 name VARCHAR(200) NOT NULL,
155 extra_info TEXT NULL,
156 slug VARCHAR(200) NULL,
157 field VARCHAR(50) NULL,
158 type VARCHAR(100) NULL,
159 default_value TEXT NULL,
160 placeholder_text TEXT NULL,
161 char_limit INT NULL,
162 date_display_as VARCHAR(50) NULL,
163 date_format VARCHAR(50) NULL,
164 date_range VARCHAR(50) NULL,
165 start_range DATETIME NULL,
166 end_range DATETIME NULL,
167 time_format INT NULL,
168 is_personal_info INT(1) NOT NULL DEFAULT 0,
169 is_auto_fill INT(1) NULL,
170 allow_ticket_form INT(1) NULL DEFAULT 1,
171 allow_my_profile INT(1) NULL DEFAULT 1,
172 tl_width INT(3) NOT NULL DEFAULT 100,
173 load_order INT NOT NULL DEFAULT 1,
174 number_type VARCHAR(50) NULL,
175 PRIMARY KEY (id)
176 ) $collate;
177 CREATE TABLE {$wpdb->prefix}psmsc_options (
178 id INT NOT NULL AUTO_INCREMENT,
179 name VARCHAR(200) NOT NULL,
180 custom_field INT NOT NULL DEFAULT 0,
181 date_created DATETIME NOT NULL,
182 load_order INT NOT NULL DEFAULT 1,
183 PRIMARY KEY (id)
184 ) $collate;
185 CREATE TABLE {$wpdb->prefix}psmsc_threads (
186 id BIGINT NOT NULL AUTO_INCREMENT,
187 ticket BIGINT NOT NULL,
188 is_active INT(1) NOT NULL DEFAULT 1,
189 customer BIGINT NULL DEFAULT NULL,
190 type VARCHAR(50) NOT NULL,
191 body LONGTEXT NOT NULL,
192 attachments TEXT NULL DEFAULT NULL,
193 ip_address VARCHAR(50) NULL DEFAULT NULL,
194 source VARCHAR(50) NULL DEFAULT NULL,
195 os VARCHAR(50) NULL DEFAULT NULL,
196 browser VARCHAR(100) NULL DEFAULT NULL,
197 seen DATETIME NULL DEFAULT NULL,
198 date_created DATETIME NOT NULL,
199 date_updated DATETIME NOT NULL,
200 PRIMARY KEY (id)
201 ) $collate;
202 CREATE TABLE {$wpdb->prefix}psmsc_statuses (
203 id BIGINT NOT NULL AUTO_INCREMENT,
204 name VARCHAR(200) NOT NULL,
205 color VARCHAR(50) NOT NULL,
206 bg_color VARCHAR(50) NOT NULL,
207 load_order INT NOT NULL DEFAULT 1,
208 PRIMARY KEY (id)
209 ) $collate;
210 CREATE TABLE {$wpdb->prefix}psmsc_categories (
211 id BIGINT NOT NULL AUTO_INCREMENT,
212 name VARCHAR(200) NOT NULL,
213 load_order INT NOT NULL DEFAULT 1,
214 PRIMARY KEY (id)
215 ) $collate;
216 CREATE TABLE {$wpdb->prefix}psmsc_priorities (
217 id BIGINT NOT NULL AUTO_INCREMENT,
218 name VARCHAR(200) NOT NULL,
219 color VARCHAR(50) NOT NULL,
220 bg_color VARCHAR(50) NOT NULL,
221 load_order INT NOT NULL DEFAULT 1,
222 PRIMARY KEY (id)
223 ) $collate;
224 CREATE TABLE {$wpdb->prefix}psmsc_attachments (
225 id BIGINT NOT NULL AUTO_INCREMENT,
226 name VARCHAR(200) NOT NULL,
227 file_path TEXT NOT NULL,
228 is_image INT(1) NOT NULL DEFAULT 0,
229 is_active INT(1) NOT NULL DEFAULT 0,
230 is_uploaded INT(1) NOT NULL DEFAULT 0,
231 date_created DATETIME NOT NULL,
232 source VARCHAR(200) NOT NULL,
233 source_id BIGINT NOT NULL DEFAULT 0,
234 ticket_id BIGINT NOT NULL DEFAULT 0,
235 customer_id BIGINT NOT NULL DEFAULT 0,
236 uploaded_by VARCHAR(64) NOT NULL DEFAULT '',
237 PRIMARY KEY (id)
238 ) $collate;
239 CREATE TABLE {$wpdb->prefix}psmsc_agents (
240 id BIGINT NOT NULL AUTO_INCREMENT,
241 user BIGINT NULL DEFAULT 0,
242 customer BIGINT NULL DEFAULT 0,
243 role INT NOT NULL DEFAULT 0,
244 name VARCHAR(200) NOT NULL,
245 workload INT NULL DEFAULT NULL,
246 unresolved_count INT NULL DEFAULT NULL,
247 is_agentgroup INT(1) NOT NULL DEFAULT 0,
248 is_active INT(1) NOT NULL DEFAULT 0,
249 PRIMARY KEY (id)
250 ) $collate;
251 CREATE TABLE {$wpdb->prefix}psmsc_logs (
252 id BIGINT NOT NULL AUTO_INCREMENT,
253 type VARCHAR(200) NOT NULL,
254 ref_id BIGINT NOT NULL,
255 modified_by BIGINT NOT NULL,
256 body LONGTEXT NOT NULL,
257 date_created DATETIME NOT NULL,
258 PRIMARY KEY (id)
259 ) $collate;
260 CREATE TABLE {$wpdb->prefix}psmsc_working_hrs (
261 id INT NOT NULL AUTO_INCREMENT,
262 agent BIGINT NOT NULL,
263 day TINYINT NOT NULL,
264 start_time VARCHAR(20) NOT NULL,
265 end_time VARCHAR(20) NOT NULL,
266 PRIMARY KEY (id)
267 ) $collate;
268 CREATE TABLE {$wpdb->prefix}psmsc_holidays (
269 id INT NOT NULL AUTO_INCREMENT,
270 agent BIGINT NOT NULL,
271 holiday DATETIME NOT NULL,
272 is_recurring TINYINT NOT NULL,
273 PRIMARY KEY (id)
274 ) $collate;
275 CREATE TABLE {$wpdb->prefix}psmsc_wh_exceptions (
276 id INT NOT NULL AUTO_INCREMENT,
277 agent BIGINT NOT NULL,
278 title VARCHAR(200) NOT NULL,
279 exception_date DATETIME NOT NULL,
280 start_time VARCHAR(20) NOT NULL,
281 end_time VARCHAR(20) NOT NULL,
282 PRIMARY KEY (id)
283 ) $collate;
284 CREATE TABLE {$wpdb->prefix}psmsc_email_otp (
285 id INT NOT NULL AUTO_INCREMENT,
286 email VARCHAR(200) NOT NULL,
287 otp VARCHAR(10) NOT NULL,
288 date_expiry DATETIME NOT NULL,
289 data LONGTEXT NULL DEFAULT NULL,
290 PRIMARY KEY (id)
291 ) $collate;
292 CREATE TABLE {$wpdb->prefix}psmsc_email_notifications (
293 id INT NOT NULL AUTO_INCREMENT,
294 from_name VARCHAR(200) NULL DEFAULT NULL,
295 from_email VARCHAR(200) NULL DEFAULT NULL,
296 reply_to VARCHAR(200) NULL DEFAULT NULL,
297 subject TEXT NULL DEFAULT NULL,
298 body LONGTEXT NULL DEFAULT NULL,
299 to_email TEXT NULL DEFAULT NULL,
300 cc_email TEXT NULL DEFAULT NULL,
301 bcc_email TEXT NULL DEFAULT NULL,
302 attachments TEXT NULL DEFAULT NULL,
303 priority INT(1) NOT NULL DEFAULT 1,
304 attempt INT(1) DEFAULT 0,
305 PRIMARY KEY (id)
306 ) $collate;
307 CREATE TABLE {$wpdb->prefix}psmsc_scheduled_tasks (
308 id INT NOT NULL AUTO_INCREMENT,
309 class VARCHAR(200) NOT NULL,
310 method VARCHAR(200) NOT NULL,
311 args TINYTEXT NULL DEFAULT NULL,
312 is_manual INT(1) NOT NULL DEFAULT 0,
313 warning_text TINYTEXT NULL DEFAULT NULL,
314 warning_link_text TINYTEXT NULL DEFAULT NULL,
315 progressbar_text TINYTEXT NULL DEFAULT NULL,
316 pages INT NOT NULL DEFAULT 0,
317 PRIMARY KEY (id)
318 ) $collate;
319 CREATE TABLE {$wpdb->prefix}psmsc_ticket_tags (
320 id INT NOT NULL AUTO_INCREMENT,
321 name VARCHAR(200) NOT NULL,
322 description TINYTEXT NOT NULL,
323 color VARCHAR(50) NOT NULL,
324 bg_color VARCHAR(50) NOT NULL,
325 PRIMARY KEY (id)
326 ) $collate;
327 CREATE TABLE {$wpdb->prefix}psmsc_ai_logs (
328 id BIGINT NOT NULL AUTO_INCREMENT,
329 customer BIGINT NOT NULL,
330 ticket BIGINT NOT NULL,
331 provider VARCHAR(100) NOT NULL,
332 model VARCHAR(100) NOT NULL,
333 feature VARCHAR(50) NOT NULL,
334 tokens INT NOT NULL,
335 prompt LONGTEXT NOT NULL,
336 date_created DATETIME NOT NULL,
337 PRIMARY KEY (id),
338 KEY customer (customer),
339 KEY date_created (date_created)
340 ) $collate;
341 CREATE TABLE {$wpdb->prefix}psmsc_ai_training (
342 id BIGINT NOT NULL AUTO_INCREMENT,
343 status VARCHAR(20) NOT NULL,
344 provider VARCHAR(50) NOT NULL,
345 source VARCHAR(50) NOT NULL,
346 source_id BIGINT NOT NULL,
347 doc_source VARCHAR(255) NULL,
348 name VARCHAR(255) NOT NULL,
349 file_path VARCHAR(500) NOT NULL,
350 provider_file_id VARCHAR(255) NULL,
351 meta_data LONGTEXT NULL,
352 post_updated_on DATETIME NOT NULL,
353 date_updated DATETIME NOT NULL,
354 date_created DATETIME NOT NULL,
355 PRIMARY KEY (id),
356 INDEX idx_status (status),
357 INDEX idx_source (source),
358 INDEX idx_status_source (status, source)
359 ) $collate;
360 CREATE TABLE {$wpdb->prefix}psmsc_acb_sessions (
361 id BIGINT NOT NULL AUTO_INCREMENT,
362 session_id CHAR(36) NOT NULL,
363 visitor_id CHAR(36) NOT NULL,
364 subject LONGTEXT NULL,
365 provider VARCHAR(20) NOT NULL DEFAULT '',
366 reaction tinyint(1) NULL,
367 ticket_id BIGINT NULL,
368 status tinyint(1) NOT NULL,
369 token_count INT UNSIGNED NOT NULL,
370 last_activity DATETIME NOT NULL,
371 date_created DATETIME NOT NULL,
372 PRIMARY KEY (id),
373 UNIQUE KEY session_id (session_id),
374 KEY visitor_id (visitor_id),
375 KEY status (status),
376 KEY date_created (date_created)
377 ) $collate;
378 CREATE TABLE {$wpdb->prefix}psmsc_acb_messages (
379 id BIGINT NOT NULL AUTO_INCREMENT,
380 session_id CHAR(36) NOT NULL,
381 sender VARCHAR(10) NOT NULL,
382 message LONGTEXT NULL,
383 token_count INT UNSIGNED NOT NULL,
384 date_created DATETIME NOT NULL,
385 PRIMARY KEY (id),
386 KEY session_id (session_id),
387 KEY session_messages (session_id, date_created)
388 ) $collate;
389 ";
390
391 dbDelta( $tables );
392
393 // Copy structure of psmsc_ticket table to psmsc_archived_tickets table.
394 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}psmsc_archived_tickets'" ) !== "{$wpdb->prefix}psmsc_archived_tickets" ) {
395 $wpdb->query( "CREATE TABLE {$wpdb->prefix}psmsc_archived_tickets LIKE {$wpdb->prefix}psmsc_tickets" );
396 }
397
398 // Copy structure of psmsc_thread table to psmsc_archived_threads table.
399 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}psmsc_archived_threads'" ) !== "{$wpdb->prefix}psmsc_archived_threads" ) {
400 $wpdb->query( "CREATE TABLE {$wpdb->prefix}psmsc_archived_threads LIKE {$wpdb->prefix}psmsc_threads" );
401 }
402
403 // AI assistant feature: add 'ticket_summary' column to tickets and archived tickets table.
404 $column_exists = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}psmsc_tickets LIKE 'ticket_summary'" );
405 if ( empty( $column_exists ) ) {
406 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD ticket_summary TEXT NULL" );
407 }
408 $column_exists = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}psmsc_archived_tickets LIKE 'ticket_summary'" );
409 if ( empty( $column_exists ) ) {
410 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD ticket_summary TEXT NULL" );
411 }
412
413 // Attachment ownership: add 'uploaded_by' column to attachments table.
414 $column_exists = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}psmsc_attachments LIKE 'uploaded_by'" );
415 if ( empty( $column_exists ) ) {
416 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_attachments ADD uploaded_by VARCHAR(64) NOT NULL DEFAULT ''" );
417 }
418 }
419
420 /**
421 * First time installation
422 */
423 public static function initial_setup() {
424
425 global $wpdb;
426
427 // string translations.
428 $string_translations = array();
429
430 // Insert default custom fields.
431 $name = __( 'ID', 'supportcandy' );
432 $wpdb->insert(
433 $wpdb->prefix . 'psmsc_custom_fields',
434 array(
435 'name' => $name,
436 'slug' => 'id',
437 'field' => 'ticket',
438 'type' => 'df_id',
439 'tl_width' => 50,
440 'load_order' => 1,
441 )
442 );
443 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
444
445 $name = __( 'Customer', 'supportcandy' );
446 $extra_info = __( 'Select customer for whom you wish to create a ticket', 'supportcandy' );
447 $wpdb->insert(
448 $wpdb->prefix . 'psmsc_custom_fields',
449 array(
450 'name' => $name,
451 'extra_info' => $extra_info,
452 'slug' => 'customer',
453 'field' => 'ticket',
454 'type' => 'df_customer',
455 'load_order' => 2,
456 )
457 );
458 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
459 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
460
461 $name = __( 'Name', 'supportcandy' );
462 $extra_info = __( 'Please insert your name', 'supportcandy' );
463 $wpdb->insert(
464 $wpdb->prefix . 'psmsc_custom_fields',
465 array(
466 'name' => $name,
467 'extra_info' => $extra_info,
468 'slug' => 'name',
469 'field' => 'customer',
470 'type' => 'df_customer_name',
471 'tl_width' => 150,
472 'load_order' => 3,
473 'is_personal_info' => 1,
474 )
475 );
476 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
477 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
478
479 $name = __( 'Email Address', 'supportcandy' );
480 $extra_info = __( 'Please insert your email address', 'supportcandy' );
481 $wpdb->insert(
482 $wpdb->prefix . 'psmsc_custom_fields',
483 array(
484 'name' => $name,
485 'extra_info' => $extra_info,
486 'slug' => 'email',
487 'field' => 'customer',
488 'type' => 'df_customer_email',
489 'tl_width' => 150,
490 'load_order' => 4,
491 'is_personal_info' => 1,
492 )
493 );
494 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
495 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
496
497 $name = __( 'Subject', 'supportcandy' );
498 $extra_info = __( 'Short description of the ticket', 'supportcandy' );
499 $wpdb->insert(
500 $wpdb->prefix . 'psmsc_custom_fields',
501 array(
502 'name' => $name,
503 'extra_info' => $extra_info,
504 'slug' => 'subject',
505 'field' => 'ticket',
506 'type' => 'df_subject',
507 'tl_width' => 200,
508 'default_value' => 'Not Applicable',
509 'load_order' => 5,
510 )
511 );
512 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
513 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
514
515 $name = __( 'Description', 'supportcandy' );
516 $extra_info = __( 'Detailed description of the ticket', 'supportcandy' );
517 $wpdb->insert(
518 $wpdb->prefix . 'psmsc_custom_fields',
519 array(
520 'name' => $name,
521 'extra_info' => $extra_info,
522 'slug' => 'description',
523 'field' => 'ticket',
524 'type' => 'df_description',
525 'default_value' => 'Not Applicable',
526 'load_order' => 6,
527 )
528 );
529 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
530 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
531
532 $name = __( 'Status', 'supportcandy' );
533 $extra_info = __( 'Please select status', 'supportcandy' );
534 $wpdb->insert(
535 $wpdb->prefix . 'psmsc_custom_fields',
536 array(
537 'name' => $name,
538 'extra_info' => $extra_info,
539 'slug' => 'status',
540 'field' => 'ticket',
541 'type' => 'df_status',
542 'tl_width' => 100,
543 'default_value' => 1,
544 'load_order' => 7,
545 )
546 );
547 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
548 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
549
550 $name = __( 'Priority', 'supportcandy' );
551 $extra_info = __( 'Please select priority', 'supportcandy' );
552 $wpdb->insert(
553 $wpdb->prefix . 'psmsc_custom_fields',
554 array(
555 'name' => $name,
556 'extra_info' => $extra_info,
557 'slug' => 'priority',
558 'field' => 'ticket',
559 'type' => 'df_priority',
560 'tl_width' => 100,
561 'default_value' => 1,
562 'load_order' => 8,
563 )
564 );
565 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
566 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
567
568 $name = __( 'Category', 'supportcandy' );
569 $extra_info = __( 'Please select category', 'supportcandy' );
570 $wpdb->insert(
571 $wpdb->prefix . 'psmsc_custom_fields',
572 array(
573 'name' => $name,
574 'extra_info' => $extra_info,
575 'slug' => 'category',
576 'field' => 'ticket',
577 'type' => 'df_category',
578 'tl_width' => 100,
579 'default_value' => 1,
580 'load_order' => 9,
581 )
582 );
583 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
584 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
585
586 $name = __( 'Assignee', 'supportcandy' );
587 $extra_info = __( 'Please select an agent', 'supportcandy' );
588 $wpdb->insert(
589 $wpdb->prefix . 'psmsc_custom_fields',
590 array(
591 'name' => $name,
592 'extra_info' => $extra_info,
593 'slug' => 'assigned_agent',
594 'field' => 'ticket',
595 'type' => 'df_assigned_agent',
596 'tl_width' => 150,
597 'load_order' => 10,
598 )
599 );
600 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
601 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
602
603 $name = __( 'Date Created', 'supportcandy' );
604 $wpdb->insert(
605 $wpdb->prefix . 'psmsc_custom_fields',
606 array(
607 'name' => $name,
608 'slug' => 'date_created',
609 'field' => 'ticket',
610 'type' => 'df_date_created',
611 'date_display_as' => 'date',
612 'tl_width' => 165,
613 'load_order' => 11,
614 )
615 );
616 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
617
618 $name = __( 'Date Updated', 'supportcandy' );
619 $wpdb->insert(
620 $wpdb->prefix . 'psmsc_custom_fields',
621 array(
622 'name' => $name,
623 'slug' => 'date_updated',
624 'field' => 'ticket',
625 'type' => 'df_date_updated',
626 'date_display_as' => 'diff',
627 'tl_width' => 165,
628 'load_order' => 12,
629 )
630 );
631 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
632
633 $name = __( 'Agent Created', 'supportcandy' );
634 $wpdb->insert(
635 $wpdb->prefix . 'psmsc_custom_fields',
636 array(
637 'name' => $name,
638 'slug' => 'agent_created',
639 'field' => 'ticket',
640 'type' => 'df_agent_created',
641 'tl_width' => 100,
642 'load_order' => 13,
643 )
644 );
645 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
646
647 $name = __( 'IP Address', 'supportcandy' );
648 $wpdb->insert(
649 $wpdb->prefix . 'psmsc_custom_fields',
650 array(
651 'name' => $name,
652 'slug' => 'ip_address',
653 'field' => 'ticket',
654 'type' => 'df_ip_address',
655 'tl_width' => 100,
656 'load_order' => 14,
657 'is_personal_info' => 1,
658 )
659 );
660 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
661
662 $name = __( 'Source', 'supportcandy' );
663 $wpdb->insert(
664 $wpdb->prefix . 'psmsc_custom_fields',
665 array(
666 'name' => $name,
667 'slug' => 'source',
668 'field' => 'ticket',
669 'type' => 'df_source',
670 'tl_width' => 100,
671 'load_order' => 15,
672 )
673 );
674 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
675
676 $name = __( 'Browser', 'supportcandy' );
677 $wpdb->insert(
678 $wpdb->prefix . 'psmsc_custom_fields',
679 array(
680 'name' => $name,
681 'slug' => 'browser',
682 'field' => 'ticket',
683 'type' => 'df_browser',
684 'tl_width' => 100,
685 'load_order' => 16,
686 )
687 );
688 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
689
690 $name = __( 'Operating System', 'supportcandy' );
691 $wpdb->insert(
692 $wpdb->prefix . 'psmsc_custom_fields',
693 array(
694 'name' => $name,
695 'slug' => 'os',
696 'field' => 'ticket',
697 'type' => 'df_os',
698 'tl_width' => 100,
699 'load_order' => 17,
700 )
701 );
702 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
703
704 $name = __( 'Additional Recipients', 'supportcandy' );
705 $extra_info = __( 'Please insert email addresses (one per line)', 'supportcandy' );
706 $wpdb->insert(
707 $wpdb->prefix . 'psmsc_custom_fields',
708 array(
709 'name' => $name,
710 'extra_info' => $extra_info,
711 'slug' => 'add_recipients',
712 'field' => 'ticket',
713 'type' => 'df_add_recipients',
714 'is_personal_info' => 1,
715 'load_order' => 18,
716 )
717 );
718 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
719 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
720
721 $name = __( 'Previous Assignee', 'supportcandy' );
722 $wpdb->insert(
723 $wpdb->prefix . 'psmsc_custom_fields',
724 array(
725 'name' => $name,
726 'slug' => 'prev_assignee',
727 'field' => 'ticket',
728 'type' => 'df_prev_assignee',
729 'tl_width' => 100,
730 'is_personal_info' => 0,
731 'load_order' => 19,
732 )
733 );
734 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
735
736 $name = __( 'Date Closed', 'supportcandy' );
737 $wpdb->insert(
738 $wpdb->prefix . 'psmsc_custom_fields',
739 array(
740 'name' => $name,
741 'slug' => 'date_closed',
742 'field' => 'ticket',
743 'type' => 'df_date_closed',
744 'date_display_as' => 'date',
745 'is_personal_info' => 0,
746 'tl_width' => 165,
747 'load_order' => 20,
748 )
749 );
750 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
751
752 $name = __( 'User Type', 'supportcandy' );
753 $wpdb->insert(
754 $wpdb->prefix . 'psmsc_custom_fields',
755 array(
756 'name' => $name,
757 'slug' => 'user_type',
758 'field' => 'ticket',
759 'type' => 'df_user_type',
760 'tl_width' => 100,
761 'is_personal_info' => 0,
762 'load_order' => 21,
763 )
764 );
765 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
766
767 $name = __( 'Last Reply On', 'supportcandy' );
768 $wpdb->insert(
769 $wpdb->prefix . 'psmsc_custom_fields',
770 array(
771 'name' => $name,
772 'slug' => 'last_reply_on',
773 'field' => 'ticket',
774 'type' => 'df_last_reply_on',
775 'date_display_as' => 'date',
776 'is_personal_info' => 0,
777 'tl_width' => 165,
778 'load_order' => 22,
779 )
780 );
781 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
782
783 $name = __( 'Last Reply By', 'supportcandy' );
784 $wpdb->insert(
785 $wpdb->prefix . 'psmsc_custom_fields',
786 array(
787 'name' => $name,
788 'slug' => 'last_reply_by',
789 'field' => 'ticket',
790 'type' => 'df_last_reply_by',
791 'is_personal_info' => 0,
792 'tl_width' => 100,
793 'load_order' => 23,
794 )
795 );
796 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
797
798 $name = __( 'Tags', 'supportcandy' );
799 $wpdb->insert(
800 $wpdb->prefix . 'psmsc_custom_fields',
801 array(
802 'name' => $name,
803 'slug' => 'tags',
804 'field' => 'ticket',
805 'type' => 'df_tags',
806 'is_personal_info' => 0,
807 'tl_width' => 100,
808 'load_order' => 24,
809 )
810 );
811 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
812
813 $name = __( 'Last Reply Source', 'supportcandy' );
814 $wpdb->insert(
815 $wpdb->prefix . 'psmsc_custom_fields',
816 array(
817 'name' => $name,
818 'slug' => 'last_reply_source',
819 'field' => 'ticket',
820 'type' => 'df_last_reply_source',
821 'is_personal_info' => 0,
822 'tl_width' => 100,
823 'load_order' => 26,
824 )
825 );
826 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
827
828 // Insert default category, guarded against re-running initial_setup().
829 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_categories LIMIT 1" ) ) {
830 $name = __( 'General', 'supportcandy' );
831 $wpdb->insert(
832 $wpdb->prefix . 'psmsc_categories',
833 array(
834 'name' => $name,
835 'load_order' => 1,
836 )
837 );
838 $string_translations[ 'wpsc-category-' . $wpdb->insert_id ] = $name;
839 }
840
841 // Insert default statuses, guarded against re-running initial_setup().
842 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_statuses LIMIT 1" ) ) {
843 $name = __( 'Open', 'supportcandy' );
844 $wpdb->insert(
845 $wpdb->prefix . 'psmsc_statuses',
846 array(
847 'name' => $name,
848 'color' => '#ec1010',
849 'bg_color' => '#ffe7e1',
850 'load_order' => 1,
851 )
852 );
853 $string_translations[ 'wpsc-status-' . $wpdb->insert_id ] = $name;
854
855 $name = __( 'Awaiting customer reply', 'supportcandy' );
856 $wpdb->insert(
857 $wpdb->prefix . 'psmsc_statuses',
858 array(
859 'name' => $name,
860 'color' => '#8222E6',
861 'bg_color' => '#E9D3FF',
862 'load_order' => 2,
863 )
864 );
865 $string_translations[ 'wpsc-status-' . $wpdb->insert_id ] = $name;
866
867 $name = __( 'Awaiting agent reply', 'supportcandy' );
868 $wpdb->insert(
869 $wpdb->prefix . 'psmsc_statuses',
870 array(
871 'name' => $name,
872 'color' => '#EB961C',
873 'bg_color' => '#FFEBCE',
874 'load_order' => 3,
875 )
876 );
877 $string_translations[ 'wpsc-status-' . $wpdb->insert_id ] = $name;
878
879 $name = __( 'Closed', 'supportcandy' );
880 $wpdb->insert(
881 $wpdb->prefix . 'psmsc_statuses',
882 array(
883 'name' => $name,
884 'color' => '#22940d',
885 'bg_color' => '#c1ffcf',
886 'load_order' => 4,
887 )
888 );
889 $string_translations[ 'wpsc-status-' . $wpdb->insert_id ] = $name;
890 }
891
892 // Insert default priorities, guarded against re-running initial_setup().
893 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_priorities LIMIT 1" ) ) {
894 $name = __( 'Low', 'supportcandy' );
895 $wpdb->insert(
896 $wpdb->prefix . 'psmsc_priorities',
897 array(
898 'name' => $name,
899 'color' => '#22940d',
900 'bg_color' => '#c1ffcf',
901 'load_order' => 1,
902 )
903 );
904 $string_translations[ 'wpsc-priority-' . $wpdb->insert_id ] = $name;
905
906 $name = __( 'Medium', 'supportcandy' );
907 $wpdb->insert(
908 $wpdb->prefix . 'psmsc_priorities',
909 array(
910 'name' => $name,
911 'color' => '#EB961C',
912 'bg_color' => '#FFEBCE',
913 'load_order' => 2,
914 )
915 );
916 $string_translations[ 'wpsc-priority-' . $wpdb->insert_id ] = $name;
917
918 $name = __( 'High', 'supportcandy' );
919 $wpdb->insert(
920 $wpdb->prefix . 'psmsc_priorities',
921 array(
922 'name' => $name,
923 'color' => '#ec1010',
924 'bg_color' => '#ffe7e1',
925 'load_order' => 3,
926 )
927 );
928 $string_translations[ 'wpsc-priority-' . $wpdb->insert_id ] = $name;
929 }
930
931 // company working hrs.
932 for ( $i = 1; $i <= 7; $i++ ) {
933 $wpdb->insert(
934 $wpdb->prefix . 'psmsc_working_hrs',
935 array(
936 'agent' => 0,
937 'day' => $i,
938 'start_time' => '00:00:00',
939 'end_time' => '23:59:59',
940 )
941 );
942 }
943
944 // Agent roles.
945 update_option(
946 'wpsc-agent-roles',
947 array(
948 1 => array(
949 'label' => 'Administrator',
950 'caps' => array(
951
952 'view-unassigned' => true, // View ticket.
953 'view-assigned-me' => true,
954 'view-assigned-others' => true,
955
956 'reply-unassigned' => true, // Reply ticket.
957 'reply-assigned-me' => true,
958 'reply-assigned-others' => true,
959
960 'pn-unassigned' => true, // Private notes.
961 'pn-assigned-me' => true,
962 'pn-assigned-others' => true,
963
964 'aa-unassigned' => true, // Assignee.
965 'aa-assigned-me' => true,
966 'aa-assigned-others' => true,
967
968 'cs-unassigned' => true, // Change status.
969 'cs-assigned-me' => true,
970 'cs-assigned-others' => true,
971
972 'ctf-unassigned' => true, // Change ticket fields.
973 'ctf-assigned-me' => true,
974 'ctf-assigned-others' => true,
975
976 'caof-unassigned' => true, // Change agent only fields.
977 'caof-assigned-me' => true,
978 'caof-assigned-others' => true,
979
980 'crb-unassigned' => true, // Change raised by.
981 'crb-assigned-me' => true,
982 'crb-assigned-others' => true,
983
984 'eth-unassigned' => true, // Edit thread.
985 'eth-assigned-me' => true,
986 'eth-assigned-others' => true,
987
988 'dth-unassigned' => true, // Delete thread.
989 'dth-assigned-me' => true,
990 'dth-assigned-others' => true,
991
992 'vl-unassigned' => true, // View logs.
993 'vl-assigned-me' => true,
994 'vl-assigned-others' => true,
995
996 'dtt-unassigned' => true, // Delete ticket.
997 'dtt-assigned-me' => true,
998 'dtt-assigned-others' => true,
999
1000 'dt-unassigned' => true, // Duplicate ticket.
1001 'dt-assigned-me' => true,
1002 'dt-assigned-others' => true,
1003
1004 'ar-unassigned' => true, // Additional recipients.
1005 'ar-assigned-me' => true,
1006 'ar-assigned-others' => true,
1007
1008 'backend-access' => true, // Dashboard support menu access.
1009 'create-as' => true, // Create ticket on others behalf.
1010 'dtt-access' => true, // Deleted ticket access.
1011 'eci-access' => true, // Edit customer info.
1012 'dash-access' => true, // Dashboard access.
1013 'at-access' => true, // Archive tickets menu access.
1014 'at-delete-access' => true, // Archive tickets delete access.
1015
1016 'tt-unassigned' => true, // Ticket tags.
1017 'tt-assigned-me' => true,
1018 'tt-assigned-others' => true,
1019
1020 'at-unassigned' => true, // Archive ticket permissions.
1021 'at-assigned-me' => true,
1022 'at-assigned-others' => true,
1023 ),
1024 ),
1025 2 => array(
1026 'label' => 'Agent',
1027 'caps' => array(
1028
1029 'view-unassigned' => true,
1030 'view-assigned-me' => true,
1031 'view-assigned-others' => false,
1032
1033 'reply-unassigned' => true,
1034 'reply-assigned-me' => true,
1035 'reply-assigned-others' => false,
1036
1037 'pn-unassigned' => true,
1038 'pn-assigned-me' => true,
1039 'pn-assigned-others' => false,
1040
1041 'aa-unassigned' => true,
1042 'aa-assigned-me' => true,
1043 'aa-assigned-others' => false,
1044
1045 'cs-unassigned' => true,
1046 'cs-assigned-me' => true,
1047 'cs-assigned-others' => false,
1048
1049 'ctf-unassigned' => true,
1050 'ctf-assigned-me' => true,
1051 'ctf-assigned-others' => false,
1052
1053 'caof-unassigned' => true,
1054 'caof-assigned-me' => true,
1055 'caof-assigned-others' => false,
1056
1057 'crb-unassigned' => false,
1058 'crb-assigned-me' => false,
1059 'crb-assigned-others' => false,
1060
1061 'eth-unassigned' => false,
1062 'eth-assigned-me' => false,
1063 'eth-assigned-others' => false,
1064
1065 'dth-unassigned' => false,
1066 'dth-assigned-me' => false,
1067 'dth-assigned-others' => false,
1068
1069 'vl-unassigned' => true,
1070 'vl-assigned-me' => true,
1071 'vl-assigned-others' => true,
1072
1073 'dtt-unassigned' => false,
1074 'dtt-assigned-me' => false,
1075 'dtt-assigned-others' => false,
1076
1077 'dt-unassigned' => true,
1078 'dt-assigned-me' => true,
1079 'dt-assigned-others' => true,
1080
1081 'ar-unassigned' => true,
1082 'ar-assigned-me' => true,
1083 'ar-assigned-others' => false,
1084
1085 'backend-access' => true,
1086 'create-as' => true,
1087 'dtt-access' => false,
1088 'eci-access' => false,
1089 'dash-access' => true, // Dashboard access.
1090 'at-access' => false, // Archive tickets menu access.
1091 'at-delete-access' => false, // Archive tickets delete access.
1092
1093 'tt-unassigned' => true, // Ticket tags.
1094 'tt-assigned-me' => true,
1095 'tt-assigned-others' => false,
1096
1097 'at-unassigned' => false, // Archive ticket permissions.
1098 'at-assigned-me' => false,
1099 'at-assigned-others' => false,
1100 ),
1101 ),
1102 )
1103 );
1104
1105 // default agents.
1106 $users = get_users( array( 'role' => 'administrator' ) );
1107 foreach ( $users as $user ) {
1108 // customer record.
1109 $wpdb->insert(
1110 $wpdb->prefix . 'psmsc_customers',
1111 array(
1112 'user' => $user->ID,
1113 'name' => $user->display_name,
1114 'email' => $user->user_email,
1115 )
1116 );
1117 // agent record.
1118 $wpdb->insert(
1119 $wpdb->prefix . 'psmsc_agents',
1120 array(
1121 'user' => $user->ID,
1122 'customer' => $wpdb->insert_id,
1123 'role' => 1,
1124 'name' => $user->display_name,
1125 'is_active' => 1,
1126 )
1127 );
1128 // agent working hrs.
1129 $agent_id = $wpdb->insert_id;
1130 for ( $i = 1; $i <= 7; $i++ ) {
1131 $wpdb->insert(
1132 $wpdb->prefix . 'psmsc_working_hrs',
1133 array(
1134 'agent' => $agent_id,
1135 'day' => $i,
1136 'start_time' => '00:00:00',
1137 'end_time' => '23:59:59',
1138 )
1139 );
1140 }
1141 if ( ! is_multisite() && ! $user->has_cap( 'wpsc_agent' ) ) {
1142 $user->add_cap( 'wpsc_agent' );
1143 }
1144 }
1145
1146 // ticket form fields.
1147 update_option(
1148 'wpsc-tff',
1149 array(
1150 'name' => array(
1151 'is-required' => 1,
1152 'width' => 'half',
1153 'visibility' => '',
1154 ),
1155 'email' => array(
1156 'is-required' => 1,
1157 'width' => 'half',
1158 'visibility' => '',
1159 ),
1160 'subject' => array(
1161 'is-required' => 1,
1162 'width' => 'full',
1163 'visibility' => '',
1164 'relation' => 'AND',
1165 ),
1166 'description' => array(
1167 'is-required' => 1,
1168 'width' => 'full',
1169 'visibility' => '',
1170 'relation' => 'AND',
1171 ),
1172 'category' => array(
1173 'is-required' => 1,
1174 'width' => 'half',
1175 'visibility' => '',
1176 'relation' => 'AND',
1177 ),
1178 )
1179 );
1180
1181 // agent ticket list.
1182 update_option(
1183 'wpsc-atl-list-items',
1184 array( 'id', 'status', 'subject', 'name', 'category', 'priority', 'assigned_agent', 'date_updated' )
1185 );
1186 update_option(
1187 'wpsc-atl-filter-items',
1188 array( 'id', 'status', 'customer', 'subject', 'category', 'priority', 'assigned_agent', 'date_updated', 'date_created' )
1189 );
1190 $labels = array(
1191 'all' => __( 'All', 'supportcandy' ),
1192 'unresolved' => __( 'Unresolved', 'supportcandy' ),
1193 'unassigned' => __( 'Unassigned', 'supportcandy' ),
1194 'mine' => __( 'Mine', 'supportcandy' ),
1195 'closed' => __( 'Closed', 'supportcandy' ),
1196 'deleted' => __( 'Deleted', 'supportcandy' ),
1197 );
1198 foreach ( $labels as $key => $string ) {
1199 $string_translations[ 'wpsc-atl-' . $key ] = $string;
1200 }
1201 update_option(
1202 'wpsc-atl-default-filters',
1203 array(
1204 'all' => array(
1205 'label' => $labels['all'],
1206 'is_enable' => 1,
1207 ),
1208 'unresolved' => array(
1209 'label' => $labels['unresolved'],
1210 'is_enable' => 1,
1211 ),
1212 'unassigned' => array(
1213 'label' => $labels['unassigned'],
1214 'is_enable' => 1,
1215 ),
1216 'mine' => array(
1217 'label' => $labels['mine'],
1218 'is_enable' => 1,
1219 ),
1220 'closed' => array(
1221 'label' => $labels['closed'],
1222 'is_enable' => 1,
1223 ),
1224 'deleted' => array(
1225 'label' => $labels['deleted'],
1226 'is_enable' => 1,
1227 ),
1228 )
1229 );
1230
1231 // customer ticket list.
1232 update_option(
1233 'wpsc-ctl-list-items',
1234 array( 'id', 'status', 'subject', 'category', 'date_created', 'date_updated' )
1235 );
1236 update_option(
1237 'wpsc-ctl-filter-items',
1238 array( 'id', 'status', 'subject', 'category', 'date_updated', 'date_created' )
1239 );
1240 $labels = array(
1241 'all' => __( 'All', 'supportcandy' ),
1242 'unresolved' => __( 'Unresolved', 'supportcandy' ),
1243 'closed' => __( 'Closed', 'supportcandy' ),
1244 );
1245 foreach ( $labels as $key => $string ) {
1246 $string_translations[ 'wpsc-ctl-' . $key ] = $string;
1247 }
1248 update_option(
1249 'wpsc-ctl-default-filters',
1250 array(
1251 'all' => array(
1252 'label' => $labels['all'],
1253 'is_enable' => 1,
1254 ),
1255 'unresolved' => array(
1256 'label' => $labels['unresolved'],
1257 'is_enable' => 1,
1258 ),
1259 'closed' => array(
1260 'label' => $labels['closed'],
1261 'is_enable' => 1,
1262 ),
1263 )
1264 );
1265
1266 // ticket list more settings.
1267 update_option(
1268 'wpsc-tl-ms-agent-view',
1269 array(
1270 'default-sort-by' => 'date_updated',
1271 'default-sort-order' => 'DESC',
1272 'number-of-tickets' => 20,
1273 'unresolved-ticket-statuses' => array( 1, 2, 3 ),
1274 'default-filter' => 'all',
1275 'ticket-reply-redirect' => 'no-redirect',
1276 )
1277 );
1278 update_option(
1279 'wpsc-tl-ms-customer-view',
1280 array(
1281 'default-sort-by' => 'date_updated',
1282 'default-sort-order' => 'DESC',
1283 'number-of-tickets' => 20,
1284 'unresolved-ticket-statuses' => array( 1, 2, 3 ),
1285 'default-filter' => 'all',
1286 'ticket-reply-redirect' => 'no-redirect',
1287 )
1288 );
1289 update_option(
1290 'wpsc-tl-ms-advanced',
1291 array(
1292 'closed-ticket-statuses' => array( 4 ),
1293 'auto-refresh-list-status' => 0,
1294 )
1295 );
1296
1297 // email notifications.
1298 update_option(
1299 'wpsc-en-general',
1300 array(
1301 'from-name' => '',
1302 'from-email' => '',
1303 'reply-to' => '',
1304 'cron-email-count' => 5,
1305 'blocked-emails' => array(),
1306 'attachments-in-notification' => 'actual-files',
1307 )
1308 );
1309 $translations = array(
1310 1 => array(
1311 'subject' => 'Your ticket has been created successfully!',
1312 'body' => '<p>Thanks for reaching out, we\'ve received your request!</p>',
1313 ),
1314 2 => array(
1315 'body' => '<p>You have received a new ticket!</p><p><strong>{{customer}}</strong><em>reported</em></p><p>{{description}}</p><p>{{ticket_url}}</p>',
1316 ),
1317 3 => array(
1318 'body' => '<p><strong>{{last_reply_user_name}}</strong> <em>replied</em></p><p>{{last_reply}}</p><p>{{ticket_url}}</p><p>{{ticket_history}}</p>',
1319 ),
1320 4 => array(
1321 'subject' => 'Your ticket has been closed!',
1322 'body' => '<p>Dear {{customer}},</p><p>Your ticket #{{id}} has been closed.</p>',
1323 ),
1324 );
1325 foreach ( $translations as $index => $translation ) {
1326 if ( isset( $translation['subject'] ) ) {
1327 $string_translations[ 'wpsc-en-tn-subject-' . $index ] = $translation['subject'];
1328 }
1329 $string_translations[ 'wpsc-en-tn-body-' . $index ] = $translation['body'];
1330 }
1331 update_option(
1332 'wpsc-email-templates',
1333 array(
1334 '1' => array(
1335 'title' => 'New ticket customer confirmation',
1336 'event' => 'create-ticket',
1337 'is_enable' => 1,
1338 'subject' => $translations[1]['subject'],
1339 'body' => array(
1340 'text' => $translations[1]['body'],
1341 'editor' => 'html',
1342 ),
1343 'to' => array(
1344 'general-recipients' => array( 'customer' ),
1345 'agent-roles' => array(),
1346 'custom' => array(),
1347 ),
1348 'cc' => array(
1349 'general-recipients' => array(),
1350 'agent-roles' => array(),
1351 'custom' => array(),
1352 ),
1353 'bcc' => array(
1354 'general-recipients' => array(),
1355 'agent-roles' => array(),
1356 'custom' => array(),
1357 ),
1358 'conditions' => '',
1359 ),
1360 '2' => array(
1361 'title' => 'New ticket staff notification',
1362 'event' => 'create-ticket',
1363 'is_enable' => 1,
1364 'subject' => '{{subject}}',
1365 'body' => array(
1366 'text' => $translations[2]['body'],
1367 'editor' => 'html',
1368 ),
1369 'to' => array(
1370 'general-recipients' => array( 'assignee' ),
1371 'agent-roles' => array( 1 ),
1372 'custom' => array(),
1373 ),
1374 'cc' => array(
1375 'general-recipients' => array(),
1376 'agent-roles' => array(),
1377 'custom' => array(),
1378 ),
1379 'bcc' => array(
1380 'general-recipients' => array(),
1381 'agent-roles' => array(),
1382 'custom' => array(),
1383 ),
1384 'conditions' => '',
1385 ),
1386 '3' => array(
1387 'title' => 'Reply ticket notification',
1388 'event' => 'reply-ticket',
1389 'is_enable' => 1,
1390 'subject' => '{{subject}}',
1391 'body' => array(
1392 'text' => $translations[3]['body'],
1393 'editor' => 'html',
1394 ),
1395 'to' => array(
1396 'general-recipients' => array( 'customer', 'assignee' ),
1397 'agent-roles' => array( 1 ),
1398 'custom' => array(),
1399 ),
1400 'cc' => array(
1401 'general-recipients' => array(),
1402 'agent-roles' => array(),
1403 'custom' => array(),
1404 ),
1405 'bcc' => array(
1406 'general-recipients' => array(),
1407 'agent-roles' => array(),
1408 'custom' => array(),
1409 ),
1410 'conditions' => '',
1411 ),
1412 '4' => array(
1413 'title' => 'Close ticket customer notification',
1414 'event' => 'change-ticket-status',
1415 'is_enable' => 1,
1416 'subject' => $translations[4]['subject'],
1417 'body' => array(
1418 'text' => $translations[4]['body'],
1419 'editor' => 'html',
1420 ),
1421 'to' => array(
1422 'general-recipients' => array( 'customer' ),
1423 'agent-roles' => array(),
1424 'custom' => array(),
1425 ),
1426 'cc' => array(
1427 'general-recipients' => array(),
1428 'agent-roles' => array(),
1429 'custom' => array(),
1430 ),
1431 'bcc' => array(
1432 'general-recipients' => array(),
1433 'agent-roles' => array(),
1434 'custom' => array(),
1435 ),
1436 'conditions' => '[[{"slug":"status","operator":"=","operand_val_1":"4"}]]',
1437 ),
1438 )
1439 );
1440
1441 // user registration otp.
1442 $subject = 'User registration OTP - {{otp}}';
1443 $body = '<p>Hello {{firstname}},</p><p>Below is your one time password for user registration:</p><p><strong>{{otp}}</strong></p>';
1444 update_option(
1445 'wpsc-en-user-reg',
1446 array(
1447 'subject' => $subject,
1448 'body' => $body,
1449 'editor' => 'html',
1450 )
1451 );
1452 $string_translations['wpsc-user-otp-subject'] = $subject;
1453 $string_translations['wpsc-user-otp-body'] = $body;
1454
1455 // guest login otp.
1456 $subject = 'Guest Login - {{otp}}';
1457 $body = '<p>Hello {{name}},</p><p>Below is your one time password for guest login:</p><p><strong>{{otp}}</strong></p>';
1458 update_option(
1459 'wpsc-en-guest-login',
1460 array(
1461 'subject' => $subject,
1462 'body' => $body,
1463 'editor' => 'html',
1464 )
1465 );
1466 $string_translations['wpsc-guest-otp-subject'] = $subject;
1467 $string_translations['wpsc-guest-otp-body'] = $body;
1468
1469 // General settings.
1470 update_option(
1471 'wpsc-gs-general',
1472 array(
1473 'ticket-status-after-customer-reply' => 3,
1474 'ticket-status-after-agent-reply' => 2,
1475 'close-ticket-status' => 4,
1476 'reply-form-position' => 'top',
1477 'default-date-format' => 'Y-m-d H:i:s',
1478 'ticket-alice' => 'Ticket #',
1479 'allow-close-ticket' => array( 'customer', 1, 2 ),
1480 'allow-ar-thread-email' => array( 1, 2 ),
1481 'allow-create-ticket' => array( 'registered-user', 1, 2 ),
1482 'allowed-search-fields' => array( 'id', 'customer', 'subject', 'threads' ),
1483 )
1484 );
1485
1486 update_option(
1487 'wpsc-gs-page-settings',
1488 array(
1489 'support-page' => 0,
1490 'open-ticket-page' => 0,
1491 'ticket-url-page' => 'support-page',
1492 'new-ticket-page' => 'default',
1493 'new-ticket-url' => '',
1494 'user-login' => 'default',
1495 'custom-login-url' => '',
1496 'user-registration' => 'disable',
1497 'custom-registration-url' => '',
1498 'otp-login' => 1,
1499 'load-scripts' => 'all-pages',
1500 'load-script-pages' => array(),
1501 )
1502 );
1503
1504 // File attachment settings.
1505 require_once WPSC_ABSPATH . 'includes/class-wpsc-mime-types.php';
1506
1507 $extensions = 'jpg, jpeg, png, gif, pdf, doc, docx, ppt, pptx, pps, ppsx, odt, xls, xlsx, mp3, m4a, ogg, wav, mp4, m4v, mov, wmv, avi, mpg, ogv, 3gp, 3g2, zip, eml';
1508 $exts = $extensions ? explode( ',', $extensions ) : array();
1509 $exts = array_map( 'trim', $exts );
1510 $mimes = array();
1511 foreach ( $exts as $key => $value ) {
1512 $mime = WPSC_MIME_TYPES::get_mime_type( $value );
1513 if ( $mime ) {
1514 $mimes[ $value ] = $mime;
1515 }
1516 }
1517
1518 update_option(
1519 'wpsc-gs-file-attachments',
1520 array(
1521 'attachments-max-filesize' => 20,
1522 'allowed-file-extensions' => $extensions,
1523 'allowed-file-ext-mimes' => $mimes,
1524 'mime-exceptions' => array(),
1525 'image-download-behaviour' => 'open-browser',
1526 )
1527 );
1528
1529 $translation = '<p>Thanks for reaching out, we\'ve received your request!</p><p>{{ticket_url}}</p>';
1530 $string_translations['wpsc-thankyou-html'] = $translation;
1531 $string_translations['wpsc-thankyou-html-agent'] = $translation;
1532 update_option(
1533 'wpsc-gs-thankyou-page-settings',
1534 array(
1535 'action-agent' => 'text',
1536 'action-customer' => 'text',
1537 'html-agent' => $translation,
1538 'html-customer' => $translation,
1539 'page-url-agent' => '',
1540 'page-url-customer' => '',
1541 'editor-agent' => 'html',
1542 'editor-customer' => 'html',
1543 )
1544 );
1545
1546 // misc settings.
1547 $translation = '<p>I understand my personal information like Name, Email address, IP address, etc. will be stored in database.</p>';
1548 $string_translations['wpsc-gdpr'] = $translation;
1549 $string_translations['wpsc-gdpr-reg-user'] = $translation;
1550 update_option(
1551 'wpsc-gdpr-settings',
1552 array(
1553 'allow-gdpr' => 1,
1554 'gdpr-text' => $translation,
1555 'personal-data-retention-time' => 0,
1556 'personal-data-retention-unit' => 'days',
1557 'editor' => 'html',
1558 'allow-gdpr-reg-user' => 1,
1559 'gdpr-text-reg-user' => $translation,
1560 'editor-reg-user' => 'html',
1561 'ip-address-collection' => 1,
1562 )
1563 );
1564
1565 update_option(
1566 'wpsc-recaptcha-settings',
1567 array(
1568 'captcha-provider' => 0,
1569 'recaptcha-version' => 3,
1570 'recaptcha-site-key' => '',
1571 'recaptcha-secret-key' => '',
1572 'cloudflare-site-key' => '',
1573 'cloudflare-secret-key' => '',
1574 )
1575 );
1576
1577 update_option(
1578 'wpsc-ms-advanced-settings',
1579 array(
1580 'public-mode' => 0,
1581 'public-mode-reply' => 0,
1582 'reply-confirmation' => 1,
1583 'note-confirmation' => 0,
1584 'thread-date-display-as' => 'diff',
1585 'thread-date-format' => 'F d, Y h:i A',
1586 'do-not-notify-owner' => 1,
1587 'do-not-notify-owner-status' => 1,
1588 'ticket-id-format' => 'sequential',
1589 'starting-ticket-id' => 1,
1590 'random-id-length' => 8,
1591 'ticket-history-macro-threads' => 5,
1592 'register-user-if-not-exist' => 0,
1593 'auto-archive-tickets-time' => 0,
1594 'auto-archive-tickets-unit' => 'days',
1595 'permanent-archive-tickets-time' => 0,
1596 'permanent-archive-tickets-unit' => 'days',
1597 'permanent-delete-tickets-time' => 0,
1598 'permanent-delete-tickets-unit' => 'days',
1599 'allow-bcc' => 0,
1600 'allow-cc' => 0,
1601 'view-more' => 1,
1602 'allow-reply-to-close-ticket' => array( 'customer', 'agent' ),
1603 'raised-by-user' => 'customer',
1604 'allow-my-profile' => 1,
1605 'allow-agent-profile' => 1,
1606 'ticket-url-auth' => 0,
1607 'rest-api' => 1,
1608 'agent-collision' => 1,
1609 'self-assign' => 1,
1610 'reply-close' => 0,
1611 )
1612 );
1613
1614 $translation = '<p>I agree to the terms and conditions</p>';
1615 $string_translations['wpsc-term-and-conditions'] = $translation;
1616 $string_translations['wpsc-term-and-conditions-reg-user'] = $translation;
1617 update_option(
1618 'wpsc-term-and-conditions',
1619 array(
1620 'allow-term-and-conditions' => 1,
1621 'tandc-text' => $translation,
1622 'editor' => 'html',
1623 'allow-term-and-conditions-reg-user' => 1,
1624 'tandc-text-reg-user' => $translation,
1625 'editor-reg-user' => 'html',
1626 )
1627 );
1628
1629 // ticket widgets.
1630 $labels = array(
1631 'agent-collision' => __( 'Currently viewing', 'supportcandy' ),
1632 'change-status' => __( 'Ticket status', 'supportcandy' ),
1633 'raised-by' => __( 'Customer', 'supportcandy' ),
1634 'ticket-info' => __( 'Ticket info', 'supportcandy' ),
1635 'assignee' => __( 'Assignee', 'supportcandy' ),
1636 'ticket-fields' => __( 'Ticket fields', 'supportcandy' ),
1637 'agentonly-fields' => __( 'Agent only fields', 'supportcandy' ),
1638 'additional-recipients' => __( 'Additional recipients', 'supportcandy' ),
1639 'biographical-info' => __( 'Biographical Info', 'supportcandy' ),
1640 'tags' => __( 'Tags', 'supportcandy' ),
1641 );
1642 foreach ( $labels as $key => $string ) {
1643 $string_translations[ 'wpsc-twt-' . $key ] = $string;
1644 }
1645 update_option(
1646 'wpsc-ticket-widget',
1647 array(
1648 'agent-collision' => array(
1649 'title' => $labels['agent-collision'],
1650 'is_enable' => 1,
1651 'allow-customer' => 0,
1652 'allowed-agent-roles' => array( 1, 2 ),
1653 'show-priority-to-customer' => 0,
1654 'callback' => 'wpsc_get_tw_agent_collision()',
1655 'class' => 'WPSC_ITW_Agent_Collision',
1656 ),
1657 'change-status' => array(
1658 'title' => $labels['change-status'],
1659 'is_enable' => 1,
1660 'allow-customer' => 1,
1661 'allowed-agent-roles' => array( 1, 2 ),
1662 'callback' => 'wpsc_get_tw_ticket_status()',
1663 'class' => 'WPSC_ITW_Change_Status',
1664 ),
1665 'raised-by' => array(
1666 'title' => $labels['raised-by'],
1667 'is_enable' => 1,
1668 'allow-customer' => 0,
1669 'allowed-agent-roles' => array( 1, 2 ),
1670 'callback' => 'wpsc_get_tw_raised_by()',
1671 'class' => 'WPSC_ITW_Raisedby',
1672 ),
1673 'ticket-info' => array(
1674 'title' => $labels['ticket-info'],
1675 'is_enable' => 1,
1676 'allow-customer' => 0,
1677 'allowed-agent-roles' => array( 1, 2 ),
1678 'callback' => 'wpsc_get_tw_ticket_info()',
1679 'class' => 'WPSC_ITW_Ticket_Info',
1680 ),
1681 'assignee' => array(
1682 'title' => $labels['assignee'],
1683 'is_enable' => 1,
1684 'allow-customer' => 0,
1685 'allowed-agent-roles' => array( 1, 2 ),
1686 'callback' => 'wpsc_get_tw_agents()',
1687 'class' => 'WPSC_ITW_Assigned_Agents',
1688 ),
1689 'ticket-fields' => array(
1690 'title' => $labels['ticket-fields'],
1691 'is_enable' => 1,
1692 'allow-customer' => 1,
1693 'allowed-agent-roles' => array( 1, 2 ),
1694 'callback' => 'wpsc_get_tw_ticket_fields()',
1695 'class' => 'WPSC_ITW_Ticket_Fields',
1696 ),
1697 'agentonly-fields' => array(
1698 'title' => $labels['agentonly-fields'],
1699 'is_enable' => 1,
1700 'allow-customer' => 0,
1701 'allowed-agent-roles' => array( 1, 2 ),
1702 'callback' => 'wpsc_get_tw_agentonly_fields()',
1703 'class' => 'WPSC_ITW_Agentonly_Fields',
1704 ),
1705 'additional-recipients' => array(
1706 'title' => $labels['additional-recipients'],
1707 'is_enable' => 1,
1708 'allow-customer' => 1,
1709 'allowed-agent-roles' => array( 1, 2 ),
1710 'callback' => 'wpsc_get_tw_additional_recipients()',
1711 'class' => 'WPSC_ITW_Additional_Recipients',
1712 ),
1713 'biographical-info' => array(
1714 'title' => $labels['biographical-info'],
1715 'is_enable' => 0,
1716 'allow-customer' => 1,
1717 'allowed-agent-roles' => array( 1, 2 ),
1718 'callback' => 'wpsc_get_tw_biographical_info()',
1719 'class' => 'WPSC_ITW_Biographical_Info',
1720 ),
1721 'tags' => array(
1722 'title' => $labels['tags'],
1723 'is_enable' => 1,
1724 'allow-customer' => 0,
1725 'allowed-agent-roles' => array( 1, 2 ),
1726 'callback' => 'wpsc_get_tw_ticket_tags()',
1727 'class' => 'WPSC_ITW_Ticket_Tags',
1728 ),
1729 )
1730 );
1731
1732 // Rich text editor.
1733 $notice = sprintf(
1734 /* translators: %1$s: attachment max file size, %2$s: allowed file extenstions. */
1735 __( 'You can upload files maximum size %1$s mb of types %2$s.', 'supportcandy' ),
1736 20,
1737 'jpg, jpeg, png, gif, pdf, doc, docx, ppt, pptx, pps, ppsx, odt, xls, xlsx, mp3, m4a, ogg, wav, mp4, m4v, mov, wmv, avi, mpg, ogv, 3gp, 3g2, zip, eml'
1738 );
1739 update_option(
1740 'wpsc-te-agent',
1741 array(
1742 'enable' => 1,
1743 'allow-attachments' => 1,
1744 'toolbar' => array( 'bold', 'italic', 'underline', 'blockquote', 'alignleft aligncenter alignright', 'bullist', 'numlist', 'rtl', 'link', 'wpsc_insert_editor_img' ),
1745 'file-attachment-notice' => 0,
1746 'file-attachment-notice-text' => $notice,
1747 )
1748 );
1749 update_option(
1750 'wpsc-te-registered-user',
1751 array(
1752 'enable' => 1,
1753 'allow-attachments' => 1,
1754 'toolbar' => array( 'bold', 'italic', 'underline', 'blockquote', 'alignleft aligncenter alignright', 'bullist', 'numlist', 'rtl', 'link', 'wpsc_insert_editor_img' ),
1755 'file-attachment-notice' => 0,
1756 'file-attachment-notice-text' => $notice,
1757 )
1758 );
1759 update_option(
1760 'wpsc-te-guest-user',
1761 array(
1762 'enable' => 0,
1763 'allow-attachments' => 0,
1764 'toolbar' => array( 'bold', 'italic', 'underline', 'blockquote', 'alignleft aligncenter alignright', 'bullist', 'numlist', 'rtl', 'link', 'wpsc_insert_editor_img' ),
1765 'file-attachment-notice' => 0,
1766 'file-attachment-notice-text' => $notice,
1767 )
1768 );
1769 update_option( 'wpsc-te-advanced', array( 'html-pasting' => 0 ) );
1770
1771 // working hrs settings.
1772 update_option(
1773 'wpsc-wh-settings',
1774 array(
1775 'allow-agent-modify-wh' => 0,
1776 'allow-agent-modify-leaves' => 0,
1777 )
1778 );
1779
1780 // appearence settings.
1781 update_option(
1782 'wpsc-ap-general',
1783 array(
1784 'primary-color' => '#313042',
1785 'menu-link-color' => '#fff',
1786 'main-background-color' => '#fff',
1787 'main-text-color' => '#2c3e50',
1788 'link-color' => '#2271b1',
1789 )
1790 );
1791 update_option(
1792 'wpsc-ap-individual-ticket',
1793 array(
1794 'reply-primary-color' => '#2c3e50',
1795 'reply-secondary-color' => '#777777',
1796 'reply-icon-color' => '#777777',
1797 'note-primary-color' => '#8e6600',
1798 'note-secondary-color' => '#8e8d45',
1799 'note-icon-color' => '#8e8d45',
1800 'log-text' => '#2c3e50',
1801 'widget-header-bg-color' => '#fff8e5',
1802 'widget-header-text-color' => '#ff8f2b',
1803 'widget-body-bg-color' => '#f9f9f9',
1804 'widget-body-label-color' => '#777',
1805 'widget-body-text-color' => '#2c3e50',
1806 'reply-close-bg-color' => '#fff',
1807 'reply-close-text-color' => '#707070',
1808 )
1809 );
1810 update_option(
1811 'wpsc-ap-modal',
1812 array(
1813 'header-bg-color' => '#fff8e5',
1814 'header-text-color' => '#ff8f2b',
1815 'body-bg-color' => '#fff',
1816 'body-label-color' => '#777',
1817 'body-text-color' => '#2c3e50',
1818 'footer-bg-color' => '#fff',
1819 'z-index' => 900000000,
1820 )
1821 );
1822 update_option(
1823 'wpsc-ap-ticket-list',
1824 array(
1825 'list-header-background-color' => '#2c3e50',
1826 'list-header-text-color' => '#fff',
1827 'list-item-odd-background-color' => '#fff',
1828 'list-item-odd-text-color' => '#2c3e50',
1829 'list-item-even-background-color' => '#f2f2f2',
1830 'list-item-even-text-color' => '#2c3e50',
1831 'list-item-hover-background-color' => '#dfe4ea',
1832 'list-item-hover-text-color' => '#2c3e50',
1833 )
1834 );
1835
1836 // ticket tags general setting.
1837 update_option(
1838 'wpsc-ticket-tags-general-settings',
1839 array(
1840 'color' => '#000000',
1841 'bg-color' => '#ffc300',
1842 )
1843 );
1844
1845 // dashboard general setting.
1846 update_option(
1847 'wpsc-ap-dashboard',
1848 array(
1849 'card-body-bg-color' => '#ffffff',
1850 'card-body-svg-color' => '#777',
1851 'card-body-text-color' => '#2c3e50',
1852 'widget-body-bg-color' => '#ffffff',
1853 'widget-body-svg-color' => '#777',
1854 'widget-body-text-color' => '#2c3e50',
1855 )
1856 );
1857
1858 // upload directory.
1859 $upload_dir = wp_upload_dir();
1860 $filepath = $upload_dir['basedir'] . '/wpsc';
1861 if ( ! file_exists( $filepath ) ) {
1862 mkdir( $filepath, 0755, true );
1863 }
1864
1865 // Dashboard cards.
1866 $labels = array(
1867 'new-tickets' => __( 'New Tickets', 'supportcandy' ),
1868 'unresolved' => __( 'Unresolved', 'supportcandy' ),
1869 'unassigned' => __( 'Unassigned', 'supportcandy' ),
1870 'closed' => __( 'Closed', 'supportcandy' ),
1871 'mine' => __( 'Mine', 'supportcandy' ),
1872 );
1873 foreach ( $labels as $key => $string ) {
1874 $string_translations[ 'wpsc-dashboard-card-' . $key ] = $string;
1875 }
1876 update_option(
1877 'wpsc-dashboard-cards',
1878 array(
1879 'new-tickets' => array(
1880 'title' => $labels['new-tickets'],
1881 'is_enable' => 1,
1882 'allowed-agent-roles' => array( 1, 2 ),
1883 'callback' => 'wpsc_dbc_new_tickets()',
1884 'class' => 'WPSC_DBC_New_Tickets',
1885 'type' => 'default',
1886 ),
1887 'unresolved' => array(
1888 'title' => $labels['unresolved'],
1889 'is_enable' => 1,
1890 'allowed-agent-roles' => array( 1, 2 ),
1891 'callback' => 'wpsc_dbc_unresolved_tickets()',
1892 'class' => 'WPSC_DBC_Unresolved_Tickets',
1893 'type' => 'default',
1894 ),
1895 'unassigned' => array(
1896 'title' => $labels['unassigned'],
1897 'is_enable' => 1,
1898 'allowed-agent-roles' => array( 1 ),
1899 'callback' => 'wpsc_dbc_unassigned_tickets()',
1900 'class' => 'WPSC_DBC_Unassigned_Tickets',
1901 'type' => 'default',
1902 ),
1903 'closed' => array(
1904 'title' => $labels['closed'],
1905 'is_enable' => 1,
1906 'allowed-agent-roles' => array( 1, 2 ),
1907 'callback' => 'wpsc_dbc_closed_tickets()',
1908 'class' => 'WPSC_DBC_Closed_Tickets',
1909 'type' => 'default',
1910 ),
1911 'mine' => array(
1912 'title' => $labels['mine'],
1913 'is_enable' => 1,
1914 'allowed-agent-roles' => array( 1, 2 ),
1915 'callback' => 'wpsc_dbc_mine_tickets()',
1916 'class' => 'WPSC_DBC_Mine_Tickets',
1917 'type' => 'default',
1918 ),
1919 )
1920 );
1921
1922 // Dashboard widget.
1923 $labels = array(
1924 'ticket-statistics' => __( 'Ticket Statistics', 'supportcandy' ),
1925 'todays-trends' => __( 'Todays Trends', 'supportcandy' ),
1926 'agent-list' => __( 'Agent Workload', 'supportcandy' ),
1927 'recent-activities' => __( 'Recent Activities', 'supportcandy' ),
1928 'recent-tickets' => __( 'Recent Tickets', 'supportcandy' ),
1929 'category-report' => __( 'Tickets by Category', 'supportcandy' ),
1930 'unresolved-priorities' => __( 'Tickets by Priority', 'supportcandy' ),
1931 'unresolved-statuses' => __( 'Tickets by Status', 'supportcandy' ),
1932 'week-trends' => __( 'Ticket statistics by day of week', 'supportcandy' ),
1933 );
1934 foreach ( $labels as $key => $string ) {
1935 $string_translations[ 'wpsc-dashboard-widget-' . $key ] = $string;
1936 }
1937 update_option(
1938 'wpsc-dashboard-widgets',
1939 array(
1940 'ticket-statistics' => array(
1941 'title' => $labels['ticket-statistics'],
1942 'is_enable' => 1,
1943 'allowed-agent-roles' => array( 1, 2 ),
1944 'callback' => 'wpsc_dbw_ticket_statistics()',
1945 'class' => 'WPSC_DBW_Ticket_Statistics',
1946 'type' => 'default',
1947 'chart-type' => '',
1948 ),
1949 'todays-trends' => array(
1950 'title' => $labels['todays-trends'],
1951 'is_enable' => 1,
1952 'allowed-agent-roles' => array( 1, 2 ),
1953 'callback' => 'wpsc_dbw_todays_trends()',
1954 'class' => 'WPSC_DBW_Todays_Trends',
1955 'type' => 'default',
1956 'chart-type' => '',
1957 ),
1958 'agent-list' => array(
1959 'title' => $labels['agent-list'],
1960 'is_enable' => 1,
1961 'allowed-agent-roles' => array( 1 ),
1962 'callback' => 'wpsc_dbw_agent_list()',
1963 'class' => 'WPSC_DBW_Agent_List',
1964 'type' => 'default',
1965 'chart-type' => '',
1966 ),
1967 'recent-activities' => array(
1968 'title' => $labels['recent-activities'],
1969 'is_enable' => 1,
1970 'allowed-agent-roles' => array( 1, 2 ),
1971 'callback' => 'wpsc_dbw_recent_activities()',
1972 'class' => 'WPSC_DBW_Recent_Activities',
1973 'type' => 'default',
1974 'chart-type' => '',
1975 ),
1976 'recent-tickets' => array(
1977 'title' => $labels['recent-tickets'],
1978 'is_enable' => 1,
1979 'allowed-agent-roles' => array( 1, 2 ),
1980 'callback' => 'wpsc_dbw_recent_tickets()',
1981 'class' => 'WPSC_DBW_Recent_Tickets',
1982 'type' => 'default',
1983 'chart-type' => '',
1984 ),
1985 'category-report' => array(
1986 'title' => $labels['category-report'],
1987 'is_enable' => 1,
1988 'allowed-agent-roles' => array( 1, 2 ),
1989 'callback' => 'wpsc_dbw_category_reports()',
1990 'class' => 'WPSC_DBW_Category_Reports',
1991 'type' => 'default',
1992 'chart-type' => 'doughnut',
1993 ),
1994 'unresolved-priorities' => array(
1995 'title' => $labels['unresolved-priorities'],
1996 'is_enable' => 1,
1997 'allowed-agent-roles' => array( 1, 2 ),
1998 'callback' => 'wpsc_dbw_unresolved_priorities()',
1999 'class' => 'WPSC_DBW_Unresolved_Priorities',
2000 'type' => 'default',
2001 'chart-type' => 'horizontal-bar',
2002 ),
2003 'unresolved-statuses' => array(
2004 'title' => $labels['unresolved-statuses'],
2005 'is_enable' => 1,
2006 'allowed-agent-roles' => array( 1, 2 ),
2007 'callback' => 'wpsc_dbw_unresolved_statuses()',
2008 'class' => 'WPSC_DBW_Unresolved_Statuses',
2009 'type' => 'default',
2010 'chart-type' => 'vertical-bar',
2011 ),
2012 'week-trends' => array(
2013 'title' => $labels['week-trends'],
2014 'is_enable' => 1,
2015 'allowed-agent-roles' => array( 1, 2 ),
2016 'callback' => 'WPSC_dbw_week_trend_tickets()',
2017 'class' => 'WPSC_DBW_Week_Trend_Tickets',
2018 'type' => 'default',
2019 'chart-type' => 'vertical-bar',
2020 ),
2021 )
2022 );
2023
2024 // Add dashboard general settings.
2025 update_option(
2026 'wpsc-db-gs-settings',
2027 array(
2028 'default-date-range' => 'last-week',
2029 'allowed-recent-activity-logs' => array( 'report', 'reply', 'note', 'assigned_agent' ),
2030 'dash-auto-refresh' => 0,
2031 )
2032 );
2033
2034 self::attachment_security_file();
2035
2036 // Create required database indexes.
2037 self::create_indexing();
2038
2039 // update string translations.
2040 update_option( 'wpsc-string-translation', $string_translations );
2041
2042 // Add AI assistant option.
2043 update_option(
2044 'wpsc-ps-ai-assistant-settings',
2045 array(
2046 'status' => '0',
2047 'provider' => 'openai',
2048 'api_key' => '',
2049 'model' => 'gpt-4o-mini',
2050 'max-tokens' => 500,
2051 'auto-delete-ai-logs-time' => 1,
2052 'auto-delete-ai-logs-unit' => 'year',
2053 'custom-prompt' => '',
2054 'summary-custom-prompt' => '',
2055 'auto-draft-custom-prompt' => '',
2056 'is-active' => 0,
2057 'last-error' => '',
2058 'ai-max-upload-file-size' => 10,
2059 )
2060 );
2061
2062 // update AI training options.
2063 update_option(
2064 'wpsc-ps-ai-training-sources',
2065 array(
2066 array(
2067 'slug' => 'local',
2068 'type' => 'localhost',
2069 'name' => 'Local',
2070 'api-url' => rest_url(),
2071 'post-types' => array(),
2072 ),
2073 ),
2074 );
2075
2076 // default AI chatbot settings.
2077 update_option(
2078 'wpsc-ps-acb-chatbot-settings',
2079 array(
2080 'status' => '0',
2081 'delete-acb-session-time' => 1,
2082 'delete-acb-session-unit' => 'year',
2083 'show-footer-branding' => '1',
2084 'sessions-per-page' => 30,
2085 'popup-delay-status' => '0',
2086 'popup-delay' => 10,
2087 'popup-display-limit' => 3,
2088 'custom-prompt' => '',
2089 )
2090 );
2091
2092 // default chatbot appearance settings.
2093 update_option(
2094 'wpsc-acb-appearance-general',
2095 array(
2096 'background-color' => '#2271b1',
2097 'icon-color' => '#ffffff',
2098 'header-text' => __( 'AI Chatbot', 'supportcandy' ),
2099 'greeting-text' => __( 'Hey, I\'m your assistant. How can I help you today?', 'supportcandy' ),
2100 'warning-text' => __( 'AI can make mistakes. Check important info.', 'supportcandy' ),
2101 )
2102 );
2103
2104 // Onboarding wizard: seed pending state for this fresh install and flag a
2105 // one-time redirect so WPSC_Onboarding shows the wizard on the next admin
2106 // page load. Existing sites being upgraded never reach this method, so the
2107 // wizard never auto-appears for them.
2108 update_option(
2109 'wpsc-onboarding-wizard',
2110 array(
2111 'status' => 'pending',
2112 'steps' => array(),
2113 )
2114 );
2115 set_transient( 'wpsc_onboarding_redirect', 1, 5 * MINUTE_IN_SECONDS );
2116 }
2117
2118 /**
2119 * Upgrade the version
2120 */
2121 public static function upgrade() {
2122
2123 global $wpdb;
2124
2125 $string_translations = get_option( 'wpsc-string-translation' );
2126
2127 if ( version_compare( self::$current_version, '3.0.4', '<' ) ) {
2128
2129 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2130 $advanced['allow-my-profile'] = 1;
2131 $advanced['allow-agent-profile'] = 1;
2132 update_option( 'wpsc-ms-advanced-settings', $advanced );
2133 }
2134
2135 if ( version_compare( self::$current_version, '3.0.5', '<' ) ) {
2136
2137 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2138 $page_settings = get_option( 'wpsc-gs-page-settings' );
2139 if ( ! isset( $advanced['allow-my-profile'] ) ) {
2140 $advanced['allow-my-profile'] = 1;
2141 $advanced['allow-agent-profile'] = 1;
2142 }
2143 $page_settings['otp-login'] = 1;
2144 update_option( 'wpsc-gs-page-settings', $page_settings );
2145 $advanced['ticket-url-auth'] = 0;
2146 update_option( 'wpsc-ms-advanced-settings', $advanced );
2147 }
2148
2149 if ( version_compare( self::$current_version, '3.0.7', '<' ) ) {
2150
2151 $page_settings = get_option( 'wpsc-gs-page-settings' );
2152 $page_settings['load-scripts'] = 'all-pages';
2153 $page_settings['load-script-pages'] = array();
2154 update_option( 'wpsc-gs-page-settings', $page_settings );
2155 }
2156
2157 if ( version_compare( self::$current_version, '3.1.1', '<' ) ) {
2158
2159 $ap_general = get_option( 'wpsc-ap-general' );
2160 $ap_general['menu-link-color'] = '#fff';
2161 update_option( 'wpsc-ap-general', $ap_general );
2162 }
2163
2164 if ( version_compare( self::$current_version, '3.1.3', '<' ) ) {
2165
2166 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2167 $advanced['rest-api'] = 1;
2168 update_option( 'wpsc-ms-advanced-settings', $advanced );
2169 }
2170
2171 if ( version_compare( self::$current_version, '3.1.4', '<' ) ) {
2172
2173 // add scheduled task for ticket data upgrade.
2174 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='update_ticket_attachment_path'" ) ) {
2175 $wpdb->insert(
2176 $wpdb->prefix . 'psmsc_scheduled_tasks',
2177 array(
2178 'class' => 'WPSC_SC_Upgrade',
2179 'method' => 'update_ticket_attachment_path',
2180 'is_manual' => 1,
2181 'warning_text' => 'SupportCandy - Database attachment paths upgrade needed.',
2182 'warning_link_text' => 'Upgrade Now',
2183 'progressbar_text' => 'Updating attachment paths...',
2184 )
2185 );
2186 }
2187
2188 self::attachment_security_file();
2189 }
2190
2191 if ( version_compare( self::$current_version, '3.1.5', '<' ) ) {
2192
2193 // scheduled task for setting conditions upgrade.
2194 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='upgrade_setting_conditions'" ) ) {
2195 $wpdb->insert(
2196 $wpdb->prefix . 'psmsc_scheduled_tasks',
2197 array(
2198 'class' => 'WPSC_SC_Upgrade',
2199 'method' => 'upgrade_setting_conditions',
2200 'is_manual' => 0,
2201 )
2202 );
2203 }
2204
2205 // scheduled task for saved filter conditions upgrade.
2206 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='upgrade_saved_filter_conditions'" ) ) {
2207 $wpdb->insert(
2208 $wpdb->prefix . 'psmsc_scheduled_tasks',
2209 array(
2210 'class' => 'WPSC_SC_Upgrade',
2211 'method' => 'upgrade_saved_filter_conditions',
2212 'is_manual' => 1,
2213 'warning_text' => 'SupportCandy - Filters database upgrade needed.',
2214 'warning_link_text' => 'Upgrade Now',
2215 'progressbar_text' => 'Upgrading filters...',
2216 )
2217 );
2218 }
2219 }
2220
2221 if ( version_compare( self::$current_version, '3.1.6', '<' ) ) {
2222
2223 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='repaire_setting_conditions'" ) ) {
2224 $wpdb->insert(
2225 $wpdb->prefix . 'psmsc_scheduled_tasks',
2226 array(
2227 'class' => 'WPSC_SC_Upgrade',
2228 'method' => 'repaire_setting_conditions',
2229 'is_manual' => 0,
2230 )
2231 );
2232 }
2233
2234 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='repaire_saved_filter_conditions'" ) ) {
2235 $wpdb->insert(
2236 $wpdb->prefix . 'psmsc_scheduled_tasks',
2237 array(
2238 'class' => 'WPSC_SC_Upgrade',
2239 'method' => 'repaire_saved_filter_conditions',
2240 'is_manual' => 1,
2241 'warning_text' => 'SupportCandy - Filters database upgrade needed.',
2242 'warning_link_text' => 'Upgrade Now',
2243 'progressbar_text' => 'Upgrading filters...',
2244 )
2245 );
2246 }
2247 }
2248
2249 if ( version_compare( self::$current_version, '3.1.7', '<' ) ) {
2250
2251 $gs = get_option( 'wpsc-gs-general' );
2252 $gs['allowed-search-fields'] = array( 'id', 'customer', 'subject', 'threads' );
2253 update_option( 'wpsc-gs-general', $gs );
2254
2255 $en = get_option( 'wpsc-en-general' );
2256 $en['attachments-in-notification'] = 'actual-files';
2257 update_option( 'wpsc-en-general', $en );
2258 }
2259
2260 if ( version_compare( self::$current_version, '3.1.9', '<' ) ) {
2261
2262 // add scheduled task for attachment status upgrade.
2263 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='update_ticket_attachment_status'" ) ) {
2264 $wpdb->insert(
2265 $wpdb->prefix . 'psmsc_scheduled_tasks',
2266 array(
2267 'class' => 'WPSC_SC_Upgrade',
2268 'method' => 'update_ticket_attachment_status',
2269 'is_manual' => 1,
2270 'warning_text' => 'SupportCandy - Database attachment status upgrade needed.',
2271 'warning_link_text' => 'Upgrade Now',
2272 'progressbar_text' => 'Updating attachment status...',
2273 )
2274 );
2275 }
2276 }
2277
2278 if ( version_compare( self::$current_version, '3.2.0', '<' ) ) {
2279
2280 $roles = get_option( 'wpsc-agent-roles' );
2281 foreach ( $roles as $key => $role ) {
2282 $role['caps']['dt-unassigned'] = true;
2283 $role['caps']['dt-assigned-me'] = true;
2284 $role['caps']['dt-assigned-others'] = true;
2285
2286 $roles[ $key ] = $role;
2287 }
2288 update_option( 'wpsc-agent-roles', $roles );
2289
2290 // set customer custom fields as personal info.
2291 $wpdb->update(
2292 $wpdb->prefix . 'psmsc_custom_fields',
2293 array( 'is_personal_info' => 1 ),
2294 array( 'field' => 'customer' )
2295 );
2296 }
2297
2298 if ( version_compare( self::$current_version, '3.2.1', '<' ) ) {
2299
2300 $thankyou = get_option( 'wpsc-gs-thankyou-page-settings' );
2301 if ( $thankyou['thank-you-page-url'] ) {
2302 $action = 'url';
2303 } else {
2304 $action = 'text';
2305 }
2306
2307 update_option(
2308 'wpsc-gs-thankyou-page-settings',
2309 array(
2310 'action-agent' => $action,
2311 'action-customer' => $action,
2312 'html-agent' => $thankyou['thankyou-html'],
2313 'html-customer' => $thankyou['thankyou-html'],
2314 'page-url-agent' => $thankyou['thank-you-page-url'],
2315 'page-url-customer' => $thankyou['thank-you-page-url'],
2316 'editor-agent' => $thankyou['editor'],
2317 'editor-customer' => $thankyou['editor'],
2318 )
2319 );
2320 $string_translations['wpsc-thankyou-html-agent'] = $thankyou['thankyou-html'];
2321
2322 update_option( 'wpsc-string-translation', $string_translations );
2323
2324 // ticket tags.
2325 $widgets = get_option( 'wpsc-ticket-widget', array() );
2326 if ( ! isset( $widgets['tags'] ) ) {
2327
2328 $agent_roles = array_keys( get_option( 'wpsc-agent-roles', array() ) );
2329 $label = esc_attr( wpsc__( 'Tags', 'supportcandy' ) );
2330 $widgets['tags'] = array(
2331 'title' => $label,
2332 'is_enable' => 1,
2333 'allow-customer' => 0,
2334 'allowed-agent-roles' => $agent_roles,
2335 'callback' => 'wpsc_get_tw_ticket_tags()',
2336 'class' => 'WPSC_ITW_Ticket_Tags',
2337 );
2338 update_option( 'wpsc-ticket-widget', $widgets );
2339
2340 $string_translations['wpsc-twt-tags'] = $label;
2341
2342 }
2343
2344 $tag_exists = $wpdb->get_results( "SELECT id from {$wpdb->prefix}psmsc_custom_fields WHERE slug = 'tags'" );
2345 if ( empty( $tag_exists ) ) {
2346 $name = __( 'Tags', 'supportcandy' );
2347 $wpdb->insert(
2348 $wpdb->prefix . 'psmsc_custom_fields',
2349 array(
2350 'name' => $name,
2351 'slug' => 'tags',
2352 'field' => 'ticket',
2353 'type' => 'df_tags',
2354 'is_personal_info' => 0,
2355 'tl_width' => 100,
2356 'load_order' => 24,
2357 )
2358 );
2359 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
2360 }
2361
2362 $roles = get_option( 'wpsc-agent-roles' );
2363 foreach ( $roles as $key => $role ) {
2364 $role['caps']['tt-unassigned'] = true;
2365 $role['caps']['tt-assigned-me'] = true;
2366 $role['caps']['tt-assigned-others'] = true;
2367
2368 $roles[ $key ] = $role;
2369 }
2370 update_option( 'wpsc-agent-roles', $roles );
2371
2372 // ticket tags general setting.
2373 update_option(
2374 'wpsc-ticket-tags-general-settings',
2375 array(
2376 'color' => '#000000',
2377 'bg-color' => '#ffc300',
2378 )
2379 );
2380
2381 // Add agent collision appearance setting.
2382 update_option(
2383 'wpsc-ap-agent-collision',
2384 array(
2385 'header-bg-color' => '#e6e6e6',
2386 'header-text-color' => '#2c3e50',
2387 )
2388 );
2389
2390 // Add agent collision setting.
2391 $ms_advanced = get_option( 'wpsc-ms-advanced-settings' );
2392 $ms_advanced['agent-collision'] = 1;
2393 update_option( 'wpsc-ms-advanced-settings', $ms_advanced );
2394 }
2395
2396 if ( version_compare( self::$current_version, '3.2.2', '<' ) ) {
2397
2398 // add anonymuos customer to customer table.
2399 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_customers WHERE email='[email protected]'" ) ) {
2400
2401 $success = $wpdb->insert(
2402 $wpdb->prefix . 'psmsc_customers',
2403 array(
2404 'name' => 'Anonymous',
2405 'email' => '[email protected]',
2406 )
2407 );
2408 if ( $success ) {
2409 update_option( 'wpsc-anonymous-user-id', $wpdb->insert_id );
2410 }
2411 }
2412
2413 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2414 $advanced['self-assign'] = 0;
2415 update_option( 'wpsc-ms-advanced-settings', $advanced );
2416 }
2417
2418 if ( version_compare( self::$current_version, '3.2.4', '<' ) ) {
2419
2420 // add default true to admin and agent dashboard access.
2421 $roles = get_option( 'wpsc-agent-roles', array() );
2422 $role_keys = array();
2423 foreach ( $roles as $key => $role ) {
2424 $role['caps']['dash-access'] = true;
2425 $roles[ $key ] = $role;
2426 $role_keys[] = $key;
2427 }
2428
2429 // Dashboard cards.
2430 $labels = array(
2431 'new-tickets' => __( 'New Tickets', 'supportcandy' ),
2432 'unresolved' => __( 'Unresolved', 'supportcandy' ),
2433 'unassigned' => __( 'Unassigned', 'supportcandy' ),
2434 'closed' => __( 'Closed', 'supportcandy' ),
2435 'mine' => __( 'Mine', 'supportcandy' ),
2436 );
2437 foreach ( $labels as $key => $string ) {
2438 $string_translations[ 'wpsc-dashboard-card-' . $key ] = $string;
2439 }
2440 update_option(
2441 'wpsc-dashboard-cards',
2442 array(
2443 'new-tickets' => array(
2444 'title' => $labels['new-tickets'],
2445 'is_enable' => 1,
2446 'allowed-agent-roles' => $role_keys,
2447 'callback' => 'wpsc_dbc_new_tickets()',
2448 'class' => 'WPSC_DBC_New_Tickets',
2449 'type' => 'default',
2450 ),
2451 'unresolved' => array(
2452 'title' => $labels['unresolved'],
2453 'is_enable' => 1,
2454 'allowed-agent-roles' => $role_keys,
2455 'callback' => 'wpsc_dbc_unresolved_tickets()',
2456 'class' => 'WPSC_DBC_Unresolved_Tickets',
2457 'type' => 'default',
2458 ),
2459 'unassigned' => array(
2460 'title' => $labels['unassigned'],
2461 'is_enable' => 1,
2462 'allowed-agent-roles' => array( 1 ),
2463 'callback' => 'wpsc_dbc_unassigned_tickets()',
2464 'class' => 'WPSC_DBC_Unassigned_Tickets',
2465 'type' => 'default',
2466 ),
2467 'closed' => array(
2468 'title' => $labels['closed'],
2469 'is_enable' => 1,
2470 'allowed-agent-roles' => $role_keys,
2471 'callback' => 'wpsc_dbc_closed_tickets()',
2472 'class' => 'WPSC_DBC_Closed_Tickets',
2473 'type' => 'default',
2474 ),
2475 'mine' => array(
2476 'title' => $labels['mine'],
2477 'is_enable' => 1,
2478 'allowed-agent-roles' => $role_keys,
2479 'callback' => 'wpsc_dbc_mine_tickets()',
2480 'class' => 'WPSC_DBC_Mine_Tickets',
2481 'type' => 'default',
2482 ),
2483 )
2484 );
2485
2486 // Dashboard widget.
2487 $labels = array(
2488 'ticket-statistics' => __( 'Ticket Statistics', 'supportcandy' ),
2489 'todays-trends' => __( 'Todays Trends', 'supportcandy' ),
2490 'agent-list' => __( 'Agent Workload', 'supportcandy' ),
2491 'recent-activities' => __( 'Recent Activities', 'supportcandy' ),
2492 'recent-tickets' => __( 'Recent Tickets', 'supportcandy' ),
2493 'category-report' => __( 'Unresolved tickets by Category', 'supportcandy' ),
2494 'unresolved-priorities' => __( 'Unresolved tickets by Priority', 'supportcandy' ),
2495 'unresolved-statuses' => __( 'Unresolved tickets by Status', 'supportcandy' ),
2496 );
2497 foreach ( $labels as $key => $string ) {
2498 $string_translations[ 'wpsc-dashboard-widget-' . $key ] = $string;
2499 }
2500 update_option(
2501 'wpsc-dashboard-widgets',
2502 array(
2503 'ticket-statistics' => array(
2504 'title' => $labels['ticket-statistics'],
2505 'is_enable' => 1,
2506 'allowed-agent-roles' => $role_keys,
2507 'callback' => 'wpsc_dbw_ticket_statistics()',
2508 'class' => 'WPSC_DBW_Ticket_Statistics',
2509 'type' => 'default',
2510 'chart-type' => '',
2511 ),
2512 'todays-trends' => array(
2513 'title' => $labels['todays-trends'],
2514 'is_enable' => 1,
2515 'allowed-agent-roles' => $role_keys,
2516 'callback' => 'wpsc_dbw_todays_trends()',
2517 'class' => 'WPSC_DBW_Todays_Trends',
2518 'type' => 'default',
2519 'chart-type' => '',
2520 ),
2521 'agent-list' => array(
2522 'title' => $labels['agent-list'],
2523 'is_enable' => 1,
2524 'allowed-agent-roles' => array( 1 ),
2525 'callback' => 'wpsc_dbw_agent_list()',
2526 'class' => 'WPSC_DBW_Agent_List',
2527 'type' => 'default',
2528 'chart-type' => '',
2529 ),
2530 'recent-activities' => array(
2531 'title' => $labels['recent-activities'],
2532 'is_enable' => 1,
2533 'allowed-agent-roles' => $role_keys,
2534 'callback' => 'wpsc_dbw_recent_activities()',
2535 'class' => 'WPSC_DBW_Recent_Activities',
2536 'type' => 'default',
2537 'chart-type' => '',
2538 ),
2539 'recent-tickets' => array(
2540 'title' => $labels['recent-tickets'],
2541 'is_enable' => 1,
2542 'allowed-agent-roles' => $role_keys,
2543 'callback' => 'wpsc_dbw_recent_tickets()',
2544 'class' => 'WPSC_DBW_Recent_Tickets',
2545 'type' => 'default',
2546 'chart-type' => '',
2547 ),
2548 'category-report' => array(
2549 'title' => $labels['category-report'],
2550 'is_enable' => 1,
2551 'allowed-agent-roles' => $role_keys,
2552 'callback' => 'wpsc_dbw_category_reports()',
2553 'class' => 'WPSC_DBW_Category_Reports',
2554 'type' => 'default',
2555 'chart-type' => 'doughnut',
2556 ),
2557 'unresolved-priorities' => array(
2558 'title' => $labels['unresolved-priorities'],
2559 'is_enable' => 1,
2560 'allowed-agent-roles' => $role_keys,
2561 'callback' => 'wpsc_dbw_unresolved_priorities()',
2562 'class' => 'WPSC_DBW_Unresolved_Priorities',
2563 'type' => 'default',
2564 'chart-type' => 'horizontal-bar',
2565 ),
2566 'unresolved-statuses' => array(
2567 'title' => $labels['unresolved-statuses'],
2568 'is_enable' => 1,
2569 'allowed-agent-roles' => $role_keys,
2570 'callback' => 'wpsc_dbw_unresolved_statuses()',
2571 'class' => 'WPSC_DBW_Unresolved_Statuses',
2572 'type' => 'default',
2573 'chart-type' => 'vertical-bar',
2574 ),
2575 )
2576 );
2577
2578 // dashboard appreance general setting.
2579 update_option(
2580 'wpsc-ap-dashboard',
2581 array(
2582 'card-body-bg-color' => '#ffffff',
2583 'card-body-svg-color' => '#777',
2584 'card-body-text-color' => '#2c3e50',
2585 'widget-body-bg-color' => '#ffffff',
2586 'widget-body-svg-color' => '#777',
2587 'widget-body-text-color' => '#2c3e50',
2588 )
2589 );
2590
2591 // Add dashboard general settings.
2592 update_option(
2593 'wpsc-db-gs-settings',
2594 array(
2595 'default-date-range' => 'last-week',
2596 'allowed-recent-activity-logs' => array( 'report', 'reply', 'note', 'assigned_agent' ),
2597 )
2598 );
2599 update_option( 'wpsc-agent-roles', $roles );
2600 }
2601
2602 if ( version_compare( self::$current_version, '3.2.5', '<' ) ) {
2603
2604 $file_attachments = get_option( 'wpsc-gs-file-attachments' );
2605
2606 require_once WPSC_ABSPATH . 'includes/class-wpsc-mime-types.php';
2607
2608 $exts = $file_attachments['allowed-file-extensions'] ? explode( ',', $file_attachments['allowed-file-extensions'] ) : array();
2609 $exts = array_map( 'trim', $exts );
2610 $mimes = array();
2611 foreach ( $exts as $key => $value ) {
2612 $mime = WPSC_MIME_TYPES::get_mime_type( $value );
2613 if ( $mime ) {
2614 $mimes[ $value ] = $mime;
2615 }
2616 }
2617 $file_attachments['allowed-file-ext-mimes'] = $mimes;
2618 $file_attachments['mime-exceptions'] = array();
2619
2620 update_option( 'wpsc-gs-file-attachments', $file_attachments );
2621 }
2622
2623 if ( version_compare( self::$current_version, '3.2.6', '<' ) ) {
2624
2625 // Add dashboard general settings.
2626 $db_gs = get_option( 'wpsc-db-gs-settings', array() );
2627 $db_gs['dash-auto-refresh'] = 0;
2628 update_option( 'wpsc-db-gs-settings', $db_gs );
2629
2630 $wpdb->update(
2631 $wpdb->prefix . 'psmsc_custom_fields',
2632 array( 'number_type' => 'integer' ),
2633 array( 'type' => 'cf_number' )
2634 );
2635 }
2636
2637 if ( version_compare( self::$current_version, '3.2.7', '<' ) ) {
2638
2639 $ms_advanced = get_option( 'wpsc-ms-advanced-settings' );
2640 $ms_advanced['reply-close'] = 1;
2641 update_option( 'wpsc-ms-advanced-settings', $ms_advanced );
2642
2643 $appearance = get_option( 'wpsc-ap-individual-ticket' );
2644 $appearance['reply-close-bg-color'] = '#fff';
2645 $appearance['reply-close-text-color'] = '#707070';
2646 update_option( 'wpsc-ap-individual-ticket', $appearance );
2647
2648 $lrs_exists = $wpdb->get_results( "SELECT id from {$wpdb->prefix}psmsc_custom_fields WHERE slug = 'last_reply_source'" );
2649 if ( empty( $lrs_exists ) ) {
2650
2651 $name = __( 'Last Reply Source', 'supportcandy' );
2652 $wpdb->insert(
2653 $wpdb->prefix . 'psmsc_custom_fields',
2654 array(
2655 'name' => $name,
2656 'slug' => 'last_reply_source',
2657 'field' => 'ticket',
2658 'type' => 'df_last_reply_source',
2659 'is_personal_info' => 0,
2660 'tl_width' => 100,
2661 'load_order' => 26,
2662 )
2663 );
2664 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
2665 }
2666
2667 // GDPR option in user registration.
2668 $gdpr = get_option( 'wpsc-gdpr-settings', array() );
2669 $gdpr_text = '<p>I understand my personal information like Name, Email address, IP address, etc. will be stored in database.</p>';
2670 $gdpr['allow-gdpr-reg-user'] = 0;
2671 $gdpr['gdpr-text-reg-user'] = $gdpr_text;
2672 $gdpr['editor-reg-user'] = 'html';
2673 update_option( 'wpsc-gdpr-settings', $gdpr );
2674 $string_translations['wpsc-gdpr-reg-user'] = $gdpr_text;
2675
2676 // T&C option in user registration.
2677 $tandc = get_option( 'wpsc-term-and-conditions', array() );
2678 $tandc_text = '<p>I agree to the terms and conditions</p>';
2679 $tandc['allow-term-and-conditions-reg-user'] = 0;
2680 $tandc['tandc-text-reg-user'] = $tandc_text;
2681 $tandc['editor-reg-user'] = 'html';
2682 update_option( 'wpsc-term-and-conditions', $tandc );
2683 $string_translations['wpsc-term-and-conditions-reg-user'] = $tandc_text;
2684 }
2685
2686 if ( version_compare( self::$current_version, '3.2.8', '<' ) ) {
2687
2688 $widgets = get_option( 'wpsc-dashboard-widgets', array() );
2689 if ( ! isset( $widgets['week-trends'] ) ) {
2690 $label = __( 'Ticket statistics by day of week', 'supportcandy' );
2691 $string_translations['wpsc-dashboard-widget-week-trends'] = $label;
2692 $widgets['week-trends'] = array(
2693 'title' => $label,
2694 'is_enable' => 1,
2695 'allowed-agent-roles' => array( 1 ),
2696 'callback' => 'wpsc_dbw_week_trend_tickets()',
2697 'class' => 'WPSC_DBW_Week_Trend_Tickets',
2698 'type' => 'default',
2699 'chart-type' => 'vertical-bar',
2700 );
2701 }
2702 update_option( 'wpsc-dashboard-widgets', $widgets );
2703 }
2704
2705 if ( version_compare( self::$current_version, '3.2.9', '<' ) ) {
2706
2707 // scheduled task for updating image editor attachment path in thread body.
2708 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='upgrade_ie_attachment_path'" ) ) {
2709 $wpdb->insert(
2710 $wpdb->prefix . 'psmsc_scheduled_tasks',
2711 array(
2712 'class' => 'WPSC_SC_Upgrade',
2713 'method' => 'upgrade_ie_attachment_path',
2714 'is_manual' => 1,
2715 'warning_text' => 'SupportCandy - attachment security upgrade needed.',
2716 'warning_link_text' => 'Upgrade Now',
2717 'progressbar_text' => 'Updating attachment ...',
2718 )
2719 );
2720 }
2721
2722 // unschedule old upgrade task.
2723 $upgrade = get_option( 'wpsc_upgrade_cleanup', array() );
2724 if ( empty( $upgrade ) ) {
2725
2726 $timestamp = wp_next_scheduled( 'wpsc_v1_upgrade_cleanup' );
2727 if ( $timestamp ) {
2728 wp_unschedule_event( $timestamp, 'wpsc_v1_upgrade_cleanup' );
2729 }
2730 $timestamp = wp_next_scheduled( 'wpsc_v2_upgrade_cleanup' );
2731 if ( $timestamp ) {
2732 wp_unschedule_event( $timestamp, 'wpsc_v2_upgrade_cleanup' );
2733 }
2734 }
2735 }
2736
2737 if ( version_compare( self::$current_version, '3.3.7', '<' ) ) {
2738 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2739 $advanced['note-confirmation'] = 0;
2740 update_option( 'wpsc-ms-advanced-settings', $advanced );
2741 }
2742
2743 if ( version_compare( self::$current_version, '3.3.8', '<' ) ) {
2744
2745 $gdpr = get_option( 'wpsc-gdpr-settings', array() );
2746 $gdpr['ip-address-collection'] = 1;
2747 update_option( 'wpsc-gdpr-settings', $gdpr );
2748
2749 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_email_otp MODIFY otp VARCHAR(10) NOT NULL" );
2750 }
2751
2752 if ( version_compare( self::$current_version, '3.4.0', '<' ) ) {
2753 // Create required database indexes.
2754 self::create_indexing();
2755 }
2756
2757 if ( version_compare( self::$current_version, '3.4.2', '<' ) ) {
2758
2759 // add advanced settings for archive tickets.
2760 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2761 $advanced['auto-archive-tickets-time'] = $advanced['auto-delete-tickets-time'] ?? 0;
2762 $advanced['auto-archive-tickets-unit'] = $advanced['auto-delete-tickets-unit'] ?? 'days';
2763 $advanced['permanent-archive-tickets-time'] = $advanced['permanent-delete-tickets-time'] ?? 0;
2764 $advanced['permanent-archive-tickets-unit'] = $advanced['permanent-delete-tickets-unit'] ?? 'days';
2765 unset(
2766 $advanced['auto-delete-tickets-time'],
2767 $advanced['auto-delete-tickets-unit'],
2768 );
2769 update_option( 'wpsc-ms-advanced-settings', $advanced );
2770
2771 // Remove 'dtt-access' and set new capabilities while preserving role keys.
2772 $roles = get_option( 'wpsc-agent-roles', array() );
2773 if ( ! empty( $roles ) && is_array( $roles ) ) {
2774 foreach ( $roles as $key => &$role ) {
2775 // Ensure caps array exists.
2776 if ( empty( $role['caps'] ) || ! is_array( $role['caps'] ) ) {
2777 $role['caps'] = array();
2778 }
2779 // Bydefault only Admin (1) has access to archive tickets.
2780 $is_enabled = ( $key == 1 );
2781 // Set new capabilities.
2782 $role['caps']['at-unassigned'] = $is_enabled;
2783 $role['caps']['at-assigned-me'] = $is_enabled;
2784 $role['caps']['at-assigned-others'] = $is_enabled;
2785 $role['caps']['at-access'] = $is_enabled;
2786 $role['caps']['at-delete-access'] = $is_enabled;
2787 }
2788 update_option( 'wpsc-agent-roles', $roles );
2789 }
2790 }
2791
2792 if ( version_compare( self::$current_version, '3.4.4', '<' ) ) {
2793
2794 $atl_filters = get_option( 'wpsc-atl-default-filters', array() );
2795 $atl_filters['deleted'] = array(
2796 'label' => __( 'Deleted', 'supportcandy' ),
2797 'is_enable' => 1,
2798 );
2799 update_option( 'wpsc-atl-default-filters', $atl_filters );
2800
2801 // Add capability for delete ticket filter access.
2802 $roles = get_option( 'wpsc-agent-roles', array() );
2803 foreach ( $roles as $key => &$role ) {
2804 $is_enabled = ( $key == 1 );
2805 $roles[ $key ]['caps']['dtt-access'] = $is_enabled;
2806 }
2807 update_option( 'wpsc-agent-roles', $roles );
2808
2809 // permanently delete tickets.
2810 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2811 $advanced['permanent-delete-tickets-time'] = $advanced['permanent-archive-tickets-time'] ?? 0;
2812 $advanced['permanent-delete-tickets-unit'] = $advanced['permanent-archive-tickets-unit'] ?? 'days';
2813 update_option( 'wpsc-ms-advanced-settings', $advanced );
2814
2815 // clear old scheduled task.
2816 wp_clear_scheduled_hook( 'wpsc_permanently_delete_archive_tickets' );
2817 wp_clear_scheduled_hook( 'wpsc_permenently_delete_tickets' );
2818 wp_clear_scheduled_hook( 'wpsc_auto_archive_closed_tickets' );
2819 }
2820
2821 if ( version_compare( self::$current_version, '3.4.7', '<' ) ) {
2822
2823 $widgets = get_option( 'wpsc-ticket-widget', array() );
2824 if ( ! isset( $widgets['agent-collision'] ) ) {
2825
2826 $roles = get_option( 'wpsc-agent-roles', array() );
2827 $role_keys = array();
2828 foreach ( $roles as $key => $role ) {
2829 $role_keys[] = $key;
2830 }
2831
2832 $label = esc_attr__( 'Currently viewing', 'supportcandy' );
2833 $agent_collision = array(
2834 'agent-collision' => array(
2835 'title' => $label,
2836 'is_enable' => 1,
2837 'allow-customer' => 0,
2838 'allowed-agent-roles' => $role_keys,
2839 'show-priority-to-customer' => 0,
2840 'callback' => 'wpsc_get_tw_agent_collision()',
2841 'class' => 'WPSC_ITW_Agent_Collision',
2842 ),
2843 );
2844
2845 // append the widget on the top.
2846 $widgets = array_merge( $agent_collision, $widgets );
2847 update_option( 'wpsc-ticket-widget', $widgets );
2848
2849 // string translations.
2850 $string_translations = get_option( 'wpsc-string-translation' );
2851 $string_translations['wpsc-twt-agent-collision'] = $label;
2852 update_option( 'wpsc-string-translation', $string_translations );
2853 }
2854 }
2855
2856 if ( version_compare( self::$current_version, '3.4.8', '<' ) ) {
2857
2858 $recaptcha = get_option( 'wpsc-recaptcha-settings' );
2859 $recaptcha['captcha-provider'] = $recaptcha['allow-recaptcha'] ? 'google-recaptcha' : '0';
2860 $recaptcha['cloudflare-site-key'] = '';
2861 $recaptcha['cloudflare-secret-key'] = '';
2862 unset( $recaptcha['allow-recaptcha'] );
2863 update_option( 'wpsc-recaptcha-settings', $recaptcha );
2864 }
2865
2866 if ( version_compare( self::$current_version, '3.5.1', '<' ) ) {
2867
2868 // AI assistant feature moved into core - seed defaults for sites upgrading from an older core version.
2869 if ( false === get_option( 'wpsc-ps-ai-assistant-settings', false ) ) {
2870 update_option(
2871 'wpsc-ps-ai-assistant-settings',
2872 array(
2873 'status' => '0',
2874 'provider' => 'openai',
2875 'api_key' => '',
2876 'model' => 'gpt-4o-mini',
2877 'max-tokens' => 500,
2878 'auto-delete-ai-logs-time' => 1,
2879 'auto-delete-ai-logs-unit' => 'year',
2880 'custom-prompt' => '',
2881 'summary-custom-prompt' => '',
2882 'auto-draft-custom-prompt' => '',
2883 'is-active' => 0,
2884 'last-error' => '',
2885 'ai-max-upload-file-size' => 10,
2886 )
2887 );
2888 }
2889
2890 if ( false === get_option( 'wpsc-ps-ai-training-sources', false ) ) {
2891 update_option(
2892 'wpsc-ps-ai-training-sources',
2893 array(
2894 array(
2895 'slug' => 'local',
2896 'type' => 'localhost',
2897 'name' => 'Local',
2898 'api-url' => rest_url(),
2899 'post-types' => array(),
2900 ),
2901 ),
2902 );
2903 }
2904
2905 // AI chatbot feature moved into core - seed defaults for sites upgrading from an older core version.
2906 if ( false === get_option( 'wpsc-ps-acb-chatbot-settings', false ) ) {
2907 update_option(
2908 'wpsc-ps-acb-chatbot-settings',
2909 array(
2910 'status' => '0',
2911 'delete-acb-session-time' => 1,
2912 'delete-acb-session-unit' => 'year',
2913 'show-footer-branding' => '1',
2914 'sessions-per-page' => 30,
2915 'popup-delay-status' => '0',
2916 'popup-delay' => 10,
2917 'popup-display-limit' => 3,
2918 'custom-prompt' => '',
2919 )
2920 );
2921 }
2922
2923 if ( false === get_option( 'wpsc-acb-appearance-general', false ) ) {
2924 update_option(
2925 'wpsc-acb-appearance-general',
2926 array(
2927 'background-color' => '#2271b1',
2928 'icon-color' => '#ffffff',
2929 'header-text' => __( 'AI Chatbot', 'supportcandy' ),
2930 'greeting-text' => __( 'Hey, I\'m your assistant. How can I help you today?', 'supportcandy' ),
2931 'warning-text' => __( 'AI can make mistakes. Check important info.', 'supportcandy' ),
2932 )
2933 );
2934 }
2935
2936 // Migrate legacy AI training data - only for sites that already used AI assistant / AI chatbot via Productivity Suite.
2937 $ps_settings = get_option( 'wpsc-ps-settings', array() );
2938
2939 $wpdb->query( "UPDATE {$wpdb->prefix}psmsc_ai_training SET doc_source = 'local' WHERE source NOT IN ( 'file', 'url', 'ticket' )" );
2940 $wpdb->query( "UPDATE {$wpdb->prefix}psmsc_ai_training SET doc_source = '' WHERE source IN ( 'file', 'url', 'ticket' )" );
2941
2942 // update AI training options.
2943 $local_post_types = array(
2944 array(
2945 'slug' => 'post',
2946 'name' => 'Posts',
2947 'status' => 0,
2948 'endpoint' => rest_url( 'wp/v2/posts' ),
2949 ),
2950 array(
2951 'slug' => 'page',
2952 'name' => 'Pages',
2953 'status' => 0,
2954 'endpoint' => rest_url( 'wp/v2/pages' ),
2955 ),
2956 );
2957
2958 $bd_settings = get_option( 'wpsc-ps-ai-bd-settings', array() );
2959 if ( isset( $bd_settings['bd-status'] ) && $bd_settings['bd-status'] == 1 ) {
2960 $local_post_types[] = array(
2961 'slug' => 'docs',
2962 'name' => 'Betterdocs',
2963 'status' => 1,
2964 'endpoint' => rest_url( 'wp/v2/docs' ),
2965 );
2966
2967 // Update source column for betterdocs source.
2968 $wpdb->query( "UPDATE {$wpdb->prefix}psmsc_ai_training SET source = 'docs' WHERE source = 'betterdocs'" );
2969 }
2970
2971 update_option(
2972 'wpsc-ps-ai-training-sources',
2973 array(
2974 array(
2975 'slug' => 'local',
2976 'type' => 'localhost',
2977 'name' => 'Local',
2978 'api-url' => rest_url(),
2979 'post-types' => $local_post_types,
2980 ),
2981 ),
2982 );
2983
2984 // wpsc_ps_ai_categories is no longer used - post-type training sources are
2985 // now routed directly by source type instead of through a categories registry.
2986 delete_option( 'wpsc_ps_ai_categories' );
2987
2988 // remove 'category', 'is_expire' and 'expiry_date' columns from AI training table.
2989 foreach ( array( 'category', 'is_expire', 'expiry_date' ) as $column ) {
2990 $column_exists = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}psmsc_ai_training LIKE '{$column}'" );
2991 if ( ! empty( $column_exists ) ) {
2992 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_ai_training DROP COLUMN {$column}" );
2993 }
2994 }
2995
2996 // unschedule expired training cleanup cron, this feature has been removed.
2997 wp_clear_scheduled_hook( 'wpsc_auto_delete_ai_training_expired_records' );
2998
2999 // remove 'manage-ai-training' capability, this is no longer used.
3000 $roles = get_option( 'wpsc-agent-roles', array() );
3001 foreach ( $roles as $key => $role ) {
3002 unset( $role['caps']['manage-ai-training'] );
3003 $roles[ $key ] = $role;
3004 }
3005 update_option( 'wpsc-agent-roles', $roles );
3006
3007 if ( isset( $ai_assistant['is-active'] ) ) {
3008 $ai_assistant = get_option( 'wpsc-ps-ai-assistant-settings' );
3009 $ai_assistant['status'] = $ai_assistant['is-active'] ? 1 : 0;
3010 update_option( 'wpsc-ps-ai-assistant-settings', $ai_assistant );
3011 }
3012
3013 // enable chatbot feature.
3014 if ( isset( $ps_settings['ai-chatbot'] ) ) {
3015 $chatbot = get_option( 'wpsc-ps-acb-chatbot-settings' );
3016 $chatbot['status'] = $ps_settings['ai-chatbot'] ? 1 : 0;
3017 update_option( 'wpsc-ps-acb-chatbot-settings', $chatbot );
3018 }
3019 }
3020
3021 if ( version_compare( self::$current_version, '3.5.2', '<' ) ) {
3022
3023 $chatbot = get_option( 'wpsc-ps-acb-chatbot-settings' );
3024 $chatbot['popup-delay-status'] = '0';
3025 $chatbot['popup-delay'] = 10;
3026 $chatbot['popup-display-limit'] = 3;
3027 update_option( 'wpsc-ps-acb-chatbot-settings', $chatbot );
3028 }
3029
3030 if ( version_compare( self::$current_version, '3.5.3', '<' ) ) {
3031
3032 $chatbot = get_option( 'wpsc-ps-acb-chatbot-settings' );
3033 $chatbot['custom-prompt'] = '';
3034 update_option( 'wpsc-ps-acb-chatbot-settings', $chatbot );
3035 }
3036
3037 if ( version_compare( self::$current_version, '3.5.4', '<' ) ) {
3038
3039 $appearance = get_option( 'wpsc-acb-appearance-general' );
3040 if ( is_array( $appearance ) ) {
3041 if ( ! isset( $appearance['header-text'] ) ) {
3042 $appearance['header-text'] = __( 'AI Chatbot', 'supportcandy' );
3043 }
3044 if ( ! isset( $appearance['greeting-text'] ) ) {
3045 $appearance['greeting-text'] = __( 'Hey, I\'m your assistant. How can I help you today?', 'supportcandy' );
3046 }
3047 if ( ! isset( $appearance['warning-text'] ) ) {
3048 $appearance['warning-text'] = __( 'AI can make mistakes. Check important info.', 'supportcandy' );
3049 }
3050 update_option( 'wpsc-acb-appearance-general', $appearance );
3051 }
3052
3053 self::create_indexing();
3054
3055 update_option(
3056 'wpsc-onboarding-wizard',
3057 array(
3058 'status' => 'completed',
3059 'steps' => array(),
3060 )
3061 );
3062 }
3063
3064 update_option( 'wpsc-string-translation', $string_translations );
3065 self::set_upgrade_complete();
3066 }
3067
3068 /**
3069 * Mark upgrade as complete
3070 */
3071 public static function set_upgrade_complete() {
3072
3073 update_option( 'wpsc_current_version', WPSC_VERSION );
3074 update_option( 'wpsc_db_version', WPSC_DB_VERSION );
3075 self::$current_version = WPSC_VERSION;
3076 self::$is_upgrade = false;
3077 }
3078
3079 /**
3080 * Actions to perform after plugin deactivated
3081 *
3082 * @return void
3083 */
3084 public static function deactivate() {
3085
3086 // Remove cron jobs.
3087 WPSC_Cron::unschedule_events();
3088 }
3089
3090 /**
3091 * Add htaccess file in supportcandy attachment folder
3092 *
3093 * @return void
3094 */
3095 public static function attachment_security_file() {
3096
3097 $upload_dir = wp_upload_dir();
3098 $wpsc_dir = $upload_dir['basedir'] . '/wpsc';
3099 if ( ! is_file( $wpsc_dir . '/.htaccess' ) ) {
3100 @file_put_contents( $wpsc_dir . '/.htaccess', 'deny from all' ); //phpcs:ignore
3101 }
3102 }
3103
3104 /**
3105 * Create required database indexes
3106 *
3107 * @return void
3108 */
3109 private static function create_indexing() {
3110
3111 global $wpdb;
3112
3113 $column_slugs = array( 'status', 'customer', 'category', 'priority', 'date_updated', 'date_created', 'date_closed' );
3114 foreach ( $column_slugs as $slug ) {
3115 $index_name = "idx_cf_{$slug}";
3116
3117 // Check if index already exists.
3118 $index_exists = $wpdb->get_var(
3119 $wpdb->prepare(
3120 "SHOW INDEX FROM {$wpdb->prefix}psmsc_tickets WHERE Key_name = %s",
3121 $index_name
3122 )
3123 );
3124
3125 if ( ! $index_exists ) {
3126 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD INDEX {$index_name} (`{$slug}`)" );
3127 }
3128 }
3129
3130 // create index on thread table.
3131 $index_name = 'idx_ticket_id';
3132 $index_exists = $wpdb->get_var(
3133 $wpdb->prepare(
3134 "SHOW INDEX FROM {$wpdb->prefix}psmsc_threads WHERE Key_name = %s",
3135 $index_name
3136 )
3137 );
3138 if ( ! $index_exists ) {
3139 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_threads ADD INDEX {$index_name} (ticket)" );
3140 }
3141
3142 // create index on archive ticket table.
3143 $column_slugs = array( 'status', 'customer', 'category', 'priority', 'date_updated', 'date_created', 'date_closed' );
3144 foreach ( $column_slugs as $slug ) {
3145 $index_name = "idx_cf_{$slug}";
3146
3147 // Check if index already exists.
3148 $index_exists = $wpdb->get_var(
3149 $wpdb->prepare(
3150 "SHOW INDEX FROM {$wpdb->prefix}psmsc_archived_tickets WHERE Key_name = %s",
3151 $index_name
3152 )
3153 );
3154
3155 if ( ! $index_exists ) {
3156 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD INDEX {$index_name} (`{$slug}`)" );
3157 }
3158 }
3159
3160 // create index on thread table.
3161 $index_name = 'idx_ticket_id';
3162 $index_exists = $wpdb->get_var(
3163 $wpdb->prepare(
3164 "SHOW INDEX FROM {$wpdb->prefix}psmsc_archived_threads WHERE Key_name = %s",
3165 $index_name
3166 )
3167 );
3168 if ( ! $index_exists ) {
3169 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_threads ADD INDEX {$index_name} (ticket)" );
3170 }
3171
3172 // Create index on AI training table.
3173 $index_name = 'idx_doc_source_source_provider_source_id';
3174 $index_exists = $wpdb->get_var(
3175 $wpdb->prepare(
3176 "SHOW INDEX FROM {$wpdb->prefix}psmsc_ai_training WHERE Key_name = %s",
3177 $index_name
3178 )
3179 );
3180 if ( ! $index_exists ) {
3181 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_ai_training ADD INDEX {$index_name} (doc_source, source, provider, source_id)" );
3182 }
3183 }
3184 }
3185 endif;
3186
3187 WPSC_Installation::init();
3188