PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.2
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.2
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.2, at class-wpsc-installation.php

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