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

3,097 lines 102.5 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 )
2077 );
2078
2079 // default chatbot appearance settings.
2080 update_option(
2081 'wpsc-acb-appearance-general',
2082 array(
2083 'background-color' => '#2271b1',
2084 'icon-color' => '#ffffff',
2085 )
2086 );
2087 }
2088
2089 /**
2090 * Upgrade the version
2091 */
2092 public static function upgrade() {
2093
2094 global $wpdb;
2095
2096 $string_translations = get_option( 'wpsc-string-translation' );
2097
2098 if ( version_compare( self::$current_version, '3.0.4', '<' ) ) {
2099
2100 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2101 $advanced['allow-my-profile'] = 1;
2102 $advanced['allow-agent-profile'] = 1;
2103 update_option( 'wpsc-ms-advanced-settings', $advanced );
2104 }
2105
2106 if ( version_compare( self::$current_version, '3.0.5', '<' ) ) {
2107
2108 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2109 $page_settings = get_option( 'wpsc-gs-page-settings' );
2110 if ( ! isset( $advanced['allow-my-profile'] ) ) {
2111 $advanced['allow-my-profile'] = 1;
2112 $advanced['allow-agent-profile'] = 1;
2113 }
2114 $page_settings['otp-login'] = 1;
2115 update_option( 'wpsc-gs-page-settings', $page_settings );
2116 $advanced['ticket-url-auth'] = 0;
2117 update_option( 'wpsc-ms-advanced-settings', $advanced );
2118 }
2119
2120 if ( version_compare( self::$current_version, '3.0.7', '<' ) ) {
2121
2122 $page_settings = get_option( 'wpsc-gs-page-settings' );
2123 $page_settings['load-scripts'] = 'all-pages';
2124 $page_settings['load-script-pages'] = array();
2125 update_option( 'wpsc-gs-page-settings', $page_settings );
2126 }
2127
2128 if ( version_compare( self::$current_version, '3.1.1', '<' ) ) {
2129
2130 $ap_general = get_option( 'wpsc-ap-general' );
2131 $ap_general['menu-link-color'] = '#fff';
2132 update_option( 'wpsc-ap-general', $ap_general );
2133 }
2134
2135 if ( version_compare( self::$current_version, '3.1.3', '<' ) ) {
2136
2137 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2138 $advanced['rest-api'] = 1;
2139 update_option( 'wpsc-ms-advanced-settings', $advanced );
2140 }
2141
2142 if ( version_compare( self::$current_version, '3.1.4', '<' ) ) {
2143
2144 // add scheduled task for ticket data upgrade.
2145 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='update_ticket_attachment_path'" ) ) {
2146 $wpdb->insert(
2147 $wpdb->prefix . 'psmsc_scheduled_tasks',
2148 array(
2149 'class' => 'WPSC_SC_Upgrade',
2150 'method' => 'update_ticket_attachment_path',
2151 'is_manual' => 1,
2152 'warning_text' => 'SupportCandy - Database attachment paths upgrade needed.',
2153 'warning_link_text' => 'Upgrade Now',
2154 'progressbar_text' => 'Updating attachment paths...',
2155 )
2156 );
2157 }
2158
2159 self::attachment_security_file();
2160 }
2161
2162 if ( version_compare( self::$current_version, '3.1.5', '<' ) ) {
2163
2164 // scheduled task for setting conditions upgrade.
2165 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='upgrade_setting_conditions'" ) ) {
2166 $wpdb->insert(
2167 $wpdb->prefix . 'psmsc_scheduled_tasks',
2168 array(
2169 'class' => 'WPSC_SC_Upgrade',
2170 'method' => 'upgrade_setting_conditions',
2171 'is_manual' => 0,
2172 )
2173 );
2174 }
2175
2176 // scheduled task for saved filter conditions upgrade.
2177 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='upgrade_saved_filter_conditions'" ) ) {
2178 $wpdb->insert(
2179 $wpdb->prefix . 'psmsc_scheduled_tasks',
2180 array(
2181 'class' => 'WPSC_SC_Upgrade',
2182 'method' => 'upgrade_saved_filter_conditions',
2183 'is_manual' => 1,
2184 'warning_text' => 'SupportCandy - Filters database upgrade needed.',
2185 'warning_link_text' => 'Upgrade Now',
2186 'progressbar_text' => 'Upgrading filters...',
2187 )
2188 );
2189 }
2190 }
2191
2192 if ( version_compare( self::$current_version, '3.1.6', '<' ) ) {
2193
2194 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='repaire_setting_conditions'" ) ) {
2195 $wpdb->insert(
2196 $wpdb->prefix . 'psmsc_scheduled_tasks',
2197 array(
2198 'class' => 'WPSC_SC_Upgrade',
2199 'method' => 'repaire_setting_conditions',
2200 'is_manual' => 0,
2201 )
2202 );
2203 }
2204
2205 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='repaire_saved_filter_conditions'" ) ) {
2206 $wpdb->insert(
2207 $wpdb->prefix . 'psmsc_scheduled_tasks',
2208 array(
2209 'class' => 'WPSC_SC_Upgrade',
2210 'method' => 'repaire_saved_filter_conditions',
2211 'is_manual' => 1,
2212 'warning_text' => 'SupportCandy - Filters database upgrade needed.',
2213 'warning_link_text' => 'Upgrade Now',
2214 'progressbar_text' => 'Upgrading filters...',
2215 )
2216 );
2217 }
2218 }
2219
2220 if ( version_compare( self::$current_version, '3.1.7', '<' ) ) {
2221
2222 $gs = get_option( 'wpsc-gs-general' );
2223 $gs['allowed-search-fields'] = array( 'id', 'customer', 'subject', 'threads' );
2224 update_option( 'wpsc-gs-general', $gs );
2225
2226 $en = get_option( 'wpsc-en-general' );
2227 $en['attachments-in-notification'] = 'actual-files';
2228 update_option( 'wpsc-en-general', $en );
2229 }
2230
2231 if ( version_compare( self::$current_version, '3.1.9', '<' ) ) {
2232
2233 // add scheduled task for attachment status upgrade.
2234 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='update_ticket_attachment_status'" ) ) {
2235 $wpdb->insert(
2236 $wpdb->prefix . 'psmsc_scheduled_tasks',
2237 array(
2238 'class' => 'WPSC_SC_Upgrade',
2239 'method' => 'update_ticket_attachment_status',
2240 'is_manual' => 1,
2241 'warning_text' => 'SupportCandy - Database attachment status upgrade needed.',
2242 'warning_link_text' => 'Upgrade Now',
2243 'progressbar_text' => 'Updating attachment status...',
2244 )
2245 );
2246 }
2247 }
2248
2249 if ( version_compare( self::$current_version, '3.2.0', '<' ) ) {
2250
2251 $roles = get_option( 'wpsc-agent-roles' );
2252 foreach ( $roles as $key => $role ) {
2253 $role['caps']['dt-unassigned'] = true;
2254 $role['caps']['dt-assigned-me'] = true;
2255 $role['caps']['dt-assigned-others'] = true;
2256
2257 $roles[ $key ] = $role;
2258 }
2259 update_option( 'wpsc-agent-roles', $roles );
2260
2261 // set customer custom fields as personal info.
2262 $wpdb->update(
2263 $wpdb->prefix . 'psmsc_custom_fields',
2264 array( 'is_personal_info' => 1 ),
2265 array( 'field' => 'customer' )
2266 );
2267 }
2268
2269 if ( version_compare( self::$current_version, '3.2.1', '<' ) ) {
2270
2271 $thankyou = get_option( 'wpsc-gs-thankyou-page-settings' );
2272 if ( $thankyou['thank-you-page-url'] ) {
2273 $action = 'url';
2274 } else {
2275 $action = 'text';
2276 }
2277
2278 update_option(
2279 'wpsc-gs-thankyou-page-settings',
2280 array(
2281 'action-agent' => $action,
2282 'action-customer' => $action,
2283 'html-agent' => $thankyou['thankyou-html'],
2284 'html-customer' => $thankyou['thankyou-html'],
2285 'page-url-agent' => $thankyou['thank-you-page-url'],
2286 'page-url-customer' => $thankyou['thank-you-page-url'],
2287 'editor-agent' => $thankyou['editor'],
2288 'editor-customer' => $thankyou['editor'],
2289 )
2290 );
2291 $string_translations['wpsc-thankyou-html-agent'] = $thankyou['thankyou-html'];
2292
2293 update_option( 'wpsc-string-translation', $string_translations );
2294
2295 // ticket tags.
2296 $widgets = get_option( 'wpsc-ticket-widget', array() );
2297 if ( ! isset( $widgets['tags'] ) ) {
2298
2299 $agent_roles = array_keys( get_option( 'wpsc-agent-roles', array() ) );
2300 $label = esc_attr( wpsc__( 'Tags', 'supportcandy' ) );
2301 $widgets['tags'] = array(
2302 'title' => $label,
2303 'is_enable' => 1,
2304 'allow-customer' => 0,
2305 'allowed-agent-roles' => $agent_roles,
2306 'callback' => 'wpsc_get_tw_ticket_tags()',
2307 'class' => 'WPSC_ITW_Ticket_Tags',
2308 );
2309 update_option( 'wpsc-ticket-widget', $widgets );
2310
2311 $string_translations['wpsc-twt-tags'] = $label;
2312
2313 }
2314
2315 $tag_exists = $wpdb->get_results( "SELECT id from {$wpdb->prefix}psmsc_custom_fields WHERE slug = 'tags'" );
2316 if ( empty( $tag_exists ) ) {
2317 $name = __( 'Tags', 'supportcandy' );
2318 $wpdb->insert(
2319 $wpdb->prefix . 'psmsc_custom_fields',
2320 array(
2321 'name' => $name,
2322 'slug' => 'tags',
2323 'field' => 'ticket',
2324 'type' => 'df_tags',
2325 'is_personal_info' => 0,
2326 'tl_width' => 100,
2327 'load_order' => 24,
2328 )
2329 );
2330 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
2331 }
2332
2333 $roles = get_option( 'wpsc-agent-roles' );
2334 foreach ( $roles as $key => $role ) {
2335 $role['caps']['tt-unassigned'] = true;
2336 $role['caps']['tt-assigned-me'] = true;
2337 $role['caps']['tt-assigned-others'] = true;
2338
2339 $roles[ $key ] = $role;
2340 }
2341 update_option( 'wpsc-agent-roles', $roles );
2342
2343 // ticket tags general setting.
2344 update_option(
2345 'wpsc-ticket-tags-general-settings',
2346 array(
2347 'color' => '#000000',
2348 'bg-color' => '#ffc300',
2349 )
2350 );
2351
2352 // Add agent collision appearance setting.
2353 update_option(
2354 'wpsc-ap-agent-collision',
2355 array(
2356 'header-bg-color' => '#e6e6e6',
2357 'header-text-color' => '#2c3e50',
2358 )
2359 );
2360
2361 // Add agent collision setting.
2362 $ms_advanced = get_option( 'wpsc-ms-advanced-settings' );
2363 $ms_advanced['agent-collision'] = 1;
2364 update_option( 'wpsc-ms-advanced-settings', $ms_advanced );
2365 }
2366
2367 if ( version_compare( self::$current_version, '3.2.2', '<' ) ) {
2368
2369 // add anonymuos customer to customer table.
2370 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_customers WHERE email='anonymous@anonymous.anonymous'" ) ) {
2371
2372 $success = $wpdb->insert(
2373 $wpdb->prefix . 'psmsc_customers',
2374 array(
2375 'name' => 'Anonymous',
2376 'email' => 'anonymous@anonymous.anonymous',
2377 )
2378 );
2379 if ( $success ) {
2380 update_option( 'wpsc-anonymous-user-id', $wpdb->insert_id );
2381 }
2382 }
2383
2384 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2385 $advanced['self-assign'] = 0;
2386 update_option( 'wpsc-ms-advanced-settings', $advanced );
2387 }
2388
2389 if ( version_compare( self::$current_version, '3.2.4', '<' ) ) {
2390
2391 // add default true to admin and agent dashboard access.
2392 $roles = get_option( 'wpsc-agent-roles', array() );
2393 $role_keys = array();
2394 foreach ( $roles as $key => $role ) {
2395 $role['caps']['dash-access'] = true;
2396 $roles[ $key ] = $role;
2397 $role_keys[] = $key;
2398 }
2399
2400 // Dashboard cards.
2401 $labels = array(
2402 'new-tickets' => __( 'New Tickets', 'supportcandy' ),
2403 'unresolved' => __( 'Unresolved', 'supportcandy' ),
2404 'unassigned' => __( 'Unassigned', 'supportcandy' ),
2405 'closed' => __( 'Closed', 'supportcandy' ),
2406 'mine' => __( 'Mine', 'supportcandy' ),
2407 );
2408 foreach ( $labels as $key => $string ) {
2409 $string_translations[ 'wpsc-dashboard-card-' . $key ] = $string;
2410 }
2411 update_option(
2412 'wpsc-dashboard-cards',
2413 array(
2414 'new-tickets' => array(
2415 'title' => $labels['new-tickets'],
2416 'is_enable' => 1,
2417 'allowed-agent-roles' => $role_keys,
2418 'callback' => 'wpsc_dbc_new_tickets()',
2419 'class' => 'WPSC_DBC_New_Tickets',
2420 'type' => 'default',
2421 ),
2422 'unresolved' => array(
2423 'title' => $labels['unresolved'],
2424 'is_enable' => 1,
2425 'allowed-agent-roles' => $role_keys,
2426 'callback' => 'wpsc_dbc_unresolved_tickets()',
2427 'class' => 'WPSC_DBC_Unresolved_Tickets',
2428 'type' => 'default',
2429 ),
2430 'unassigned' => array(
2431 'title' => $labels['unassigned'],
2432 'is_enable' => 1,
2433 'allowed-agent-roles' => array( 1 ),
2434 'callback' => 'wpsc_dbc_unassigned_tickets()',
2435 'class' => 'WPSC_DBC_Unassigned_Tickets',
2436 'type' => 'default',
2437 ),
2438 'closed' => array(
2439 'title' => $labels['closed'],
2440 'is_enable' => 1,
2441 'allowed-agent-roles' => $role_keys,
2442 'callback' => 'wpsc_dbc_closed_tickets()',
2443 'class' => 'WPSC_DBC_Closed_Tickets',
2444 'type' => 'default',
2445 ),
2446 'mine' => array(
2447 'title' => $labels['mine'],
2448 'is_enable' => 1,
2449 'allowed-agent-roles' => $role_keys,
2450 'callback' => 'wpsc_dbc_mine_tickets()',
2451 'class' => 'WPSC_DBC_Mine_Tickets',
2452 'type' => 'default',
2453 ),
2454 )
2455 );
2456
2457 // Dashboard widget.
2458 $labels = array(
2459 'ticket-statistics' => __( 'Ticket Statistics', 'supportcandy' ),
2460 'todays-trends' => __( 'Todays Trends', 'supportcandy' ),
2461 'agent-list' => __( 'Agent Workload', 'supportcandy' ),
2462 'recent-activities' => __( 'Recent Activities', 'supportcandy' ),
2463 'recent-tickets' => __( 'Recent Tickets', 'supportcandy' ),
2464 'category-report' => __( 'Unresolved tickets by Category', 'supportcandy' ),
2465 'unresolved-priorities' => __( 'Unresolved tickets by Priority', 'supportcandy' ),
2466 'unresolved-statuses' => __( 'Unresolved tickets by Status', 'supportcandy' ),
2467 );
2468 foreach ( $labels as $key => $string ) {
2469 $string_translations[ 'wpsc-dashboard-widget-' . $key ] = $string;
2470 }
2471 update_option(
2472 'wpsc-dashboard-widgets',
2473 array(
2474 'ticket-statistics' => array(
2475 'title' => $labels['ticket-statistics'],
2476 'is_enable' => 1,
2477 'allowed-agent-roles' => $role_keys,
2478 'callback' => 'wpsc_dbw_ticket_statistics()',
2479 'class' => 'WPSC_DBW_Ticket_Statistics',
2480 'type' => 'default',
2481 'chart-type' => '',
2482 ),
2483 'todays-trends' => array(
2484 'title' => $labels['todays-trends'],
2485 'is_enable' => 1,
2486 'allowed-agent-roles' => $role_keys,
2487 'callback' => 'wpsc_dbw_todays_trends()',
2488 'class' => 'WPSC_DBW_Todays_Trends',
2489 'type' => 'default',
2490 'chart-type' => '',
2491 ),
2492 'agent-list' => array(
2493 'title' => $labels['agent-list'],
2494 'is_enable' => 1,
2495 'allowed-agent-roles' => array( 1 ),
2496 'callback' => 'wpsc_dbw_agent_list()',
2497 'class' => 'WPSC_DBW_Agent_List',
2498 'type' => 'default',
2499 'chart-type' => '',
2500 ),
2501 'recent-activities' => array(
2502 'title' => $labels['recent-activities'],
2503 'is_enable' => 1,
2504 'allowed-agent-roles' => $role_keys,
2505 'callback' => 'wpsc_dbw_recent_activities()',
2506 'class' => 'WPSC_DBW_Recent_Activities',
2507 'type' => 'default',
2508 'chart-type' => '',
2509 ),
2510 'recent-tickets' => array(
2511 'title' => $labels['recent-tickets'],
2512 'is_enable' => 1,
2513 'allowed-agent-roles' => $role_keys,
2514 'callback' => 'wpsc_dbw_recent_tickets()',
2515 'class' => 'WPSC_DBW_Recent_Tickets',
2516 'type' => 'default',
2517 'chart-type' => '',
2518 ),
2519 'category-report' => array(
2520 'title' => $labels['category-report'],
2521 'is_enable' => 1,
2522 'allowed-agent-roles' => $role_keys,
2523 'callback' => 'wpsc_dbw_category_reports()',
2524 'class' => 'WPSC_DBW_Category_Reports',
2525 'type' => 'default',
2526 'chart-type' => 'doughnut',
2527 ),
2528 'unresolved-priorities' => array(
2529 'title' => $labels['unresolved-priorities'],
2530 'is_enable' => 1,
2531 'allowed-agent-roles' => $role_keys,
2532 'callback' => 'wpsc_dbw_unresolved_priorities()',
2533 'class' => 'WPSC_DBW_Unresolved_Priorities',
2534 'type' => 'default',
2535 'chart-type' => 'horizontal-bar',
2536 ),
2537 'unresolved-statuses' => array(
2538 'title' => $labels['unresolved-statuses'],
2539 'is_enable' => 1,
2540 'allowed-agent-roles' => $role_keys,
2541 'callback' => 'wpsc_dbw_unresolved_statuses()',
2542 'class' => 'WPSC_DBW_Unresolved_Statuses',
2543 'type' => 'default',
2544 'chart-type' => 'vertical-bar',
2545 ),
2546 )
2547 );
2548
2549 // dashboard appreance general setting.
2550 update_option(
2551 'wpsc-ap-dashboard',
2552 array(
2553 'card-body-bg-color' => '#f9f9f9',
2554 'card-body-svg-color' => '#777',
2555 'card-body-text-color' => '#2c3e50',
2556 'widget-body-bg-color' => '#f9f9f9',
2557 'widget-body-svg-color' => '#777',
2558 'widget-body-text-color' => '#2c3e50',
2559 )
2560 );
2561
2562 // Add dashboard general settings.
2563 update_option(
2564 'wpsc-db-gs-settings',
2565 array(
2566 'default-date-range' => 'last-week',
2567 'allowed-recent-activity-logs' => array( 'report', 'reply', 'note', 'assigned_agent' ),
2568 )
2569 );
2570 update_option( 'wpsc-agent-roles', $roles );
2571 }
2572
2573 if ( version_compare( self::$current_version, '3.2.5', '<' ) ) {
2574
2575 $file_attachments = get_option( 'wpsc-gs-file-attachments' );
2576
2577 require_once WPSC_ABSPATH . 'includes/class-wpsc-mime-types.php';
2578
2579 $exts = $file_attachments['allowed-file-extensions'] ? explode( ',', $file_attachments['allowed-file-extensions'] ) : array();
2580 $exts = array_map( 'trim', $exts );
2581 $mimes = array();
2582 foreach ( $exts as $key => $value ) {
2583 $mime = WPSC_MIME_TYPES::get_mime_type( $value );
2584 if ( $mime ) {
2585 $mimes[ $value ] = $mime;
2586 }
2587 }
2588 $file_attachments['allowed-file-ext-mimes'] = $mimes;
2589 $file_attachments['mime-exceptions'] = array();
2590
2591 update_option( 'wpsc-gs-file-attachments', $file_attachments );
2592 }
2593
2594 if ( version_compare( self::$current_version, '3.2.6', '<' ) ) {
2595
2596 // Add dashboard general settings.
2597 $db_gs = get_option( 'wpsc-db-gs-settings', array() );
2598 $db_gs['dash-auto-refresh'] = 0;
2599 update_option( 'wpsc-db-gs-settings', $db_gs );
2600
2601 $wpdb->update(
2602 $wpdb->prefix . 'psmsc_custom_fields',
2603 array( 'number_type' => 'integer' ),
2604 array( 'type' => 'cf_number' )
2605 );
2606 }
2607
2608 if ( version_compare( self::$current_version, '3.2.7', '<' ) ) {
2609
2610 $ms_advanced = get_option( 'wpsc-ms-advanced-settings' );
2611 $ms_advanced['reply-close'] = 1;
2612 update_option( 'wpsc-ms-advanced-settings', $ms_advanced );
2613
2614 $appearance = get_option( 'wpsc-ap-individual-ticket' );
2615 $appearance['reply-close-bg-color'] = '#fff';
2616 $appearance['reply-close-text-color'] = '#707070';
2617 update_option( 'wpsc-ap-individual-ticket', $appearance );
2618
2619 $lrs_exists = $wpdb->get_results( "SELECT id from {$wpdb->prefix}psmsc_custom_fields WHERE slug = 'last_reply_source'" );
2620 if ( empty( $lrs_exists ) ) {
2621
2622 $name = __( 'Last Reply Source', 'supportcandy' );
2623 $wpdb->insert(
2624 $wpdb->prefix . 'psmsc_custom_fields',
2625 array(
2626 'name' => $name,
2627 'slug' => 'last_reply_source',
2628 'field' => 'ticket',
2629 'type' => 'df_last_reply_source',
2630 'is_personal_info' => 0,
2631 'tl_width' => 100,
2632 'load_order' => 26,
2633 )
2634 );
2635 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
2636 }
2637
2638 // GDPR option in user registration.
2639 $gdpr = get_option( 'wpsc-gdpr-settings', array() );
2640 $gdpr_text = '<p>I understand my personal information like Name, Email address, IP address, etc. will be stored in database.</p>';
2641 $gdpr['allow-gdpr-reg-user'] = 0;
2642 $gdpr['gdpr-text-reg-user'] = $gdpr_text;
2643 $gdpr['editor-reg-user'] = 'html';
2644 update_option( 'wpsc-gdpr-settings', $gdpr );
2645 $string_translations['wpsc-gdpr-reg-user'] = $gdpr_text;
2646
2647 // T&C option in user registration.
2648 $tandc = get_option( 'wpsc-term-and-conditions', array() );
2649 $tandc_text = '<p>I agree to the terms and conditions</p>';
2650 $tandc['allow-term-and-conditions-reg-user'] = 0;
2651 $tandc['tandc-text-reg-user'] = $tandc_text;
2652 $tandc['editor-reg-user'] = 'html';
2653 update_option( 'wpsc-term-and-conditions', $tandc );
2654 $string_translations['wpsc-term-and-conditions-reg-user'] = $tandc_text;
2655 }
2656
2657 if ( version_compare( self::$current_version, '3.2.8', '<' ) ) {
2658
2659 $widgets = get_option( 'wpsc-dashboard-widgets', array() );
2660 if ( ! isset( $widgets['week-trends'] ) ) {
2661 $label = __( 'Ticket statistics by day of week', 'supportcandy' );
2662 $string_translations['wpsc-dashboard-widget-week-trends'] = $label;
2663 $widgets['week-trends'] = array(
2664 'title' => $label,
2665 'is_enable' => 1,
2666 'allowed-agent-roles' => array( 1 ),
2667 'callback' => 'wpsc_dbw_week_trend_tickets()',
2668 'class' => 'WPSC_DBW_Week_Trend_Tickets',
2669 'type' => 'default',
2670 'chart-type' => 'vertical-bar',
2671 );
2672 }
2673 update_option( 'wpsc-dashboard-widgets', $widgets );
2674 }
2675
2676 if ( version_compare( self::$current_version, '3.2.9', '<' ) ) {
2677
2678 // scheduled task for updating image editor attachment path in thread body.
2679 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='upgrade_ie_attachment_path'" ) ) {
2680 $wpdb->insert(
2681 $wpdb->prefix . 'psmsc_scheduled_tasks',
2682 array(
2683 'class' => 'WPSC_SC_Upgrade',
2684 'method' => 'upgrade_ie_attachment_path',
2685 'is_manual' => 1,
2686 'warning_text' => 'SupportCandy - attachment security upgrade needed.',
2687 'warning_link_text' => 'Upgrade Now',
2688 'progressbar_text' => 'Updating attachment ...',
2689 )
2690 );
2691 }
2692
2693 // unschedule old upgrade task.
2694 $upgrade = get_option( 'wpsc_upgrade_cleanup', array() );
2695 if ( empty( $upgrade ) ) {
2696
2697 $timestamp = wp_next_scheduled( 'wpsc_v1_upgrade_cleanup' );
2698 if ( $timestamp ) {
2699 wp_unschedule_event( $timestamp, 'wpsc_v1_upgrade_cleanup' );
2700 }
2701 $timestamp = wp_next_scheduled( 'wpsc_v2_upgrade_cleanup' );
2702 if ( $timestamp ) {
2703 wp_unschedule_event( $timestamp, 'wpsc_v2_upgrade_cleanup' );
2704 }
2705 }
2706 }
2707
2708 if ( version_compare( self::$current_version, '3.3.7', '<' ) ) {
2709 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2710 $advanced['note-confirmation'] = 0;
2711 update_option( 'wpsc-ms-advanced-settings', $advanced );
2712 }
2713
2714 if ( version_compare( self::$current_version, '3.3.8', '<' ) ) {
2715
2716 $gdpr = get_option( 'wpsc-gdpr-settings', array() );
2717 $gdpr['ip-address-collection'] = 1;
2718 update_option( 'wpsc-gdpr-settings', $gdpr );
2719
2720 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_email_otp MODIFY otp VARCHAR(10) NOT NULL" );
2721 }
2722
2723 if ( version_compare( self::$current_version, '3.4.0', '<' ) ) {
2724 // Create required database indexes.
2725 self::create_indexing();
2726 }
2727
2728 if ( version_compare( self::$current_version, '3.4.2', '<' ) ) {
2729
2730 // add advanced settings for archive tickets.
2731 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2732 $advanced['auto-archive-tickets-time'] = $advanced['auto-delete-tickets-time'] ?? 0;
2733 $advanced['auto-archive-tickets-unit'] = $advanced['auto-delete-tickets-unit'] ?? 'days';
2734 $advanced['permanent-archive-tickets-time'] = $advanced['permanent-delete-tickets-time'] ?? 0;
2735 $advanced['permanent-archive-tickets-unit'] = $advanced['permanent-delete-tickets-unit'] ?? 'days';
2736 unset(
2737 $advanced['auto-delete-tickets-time'],
2738 $advanced['auto-delete-tickets-unit'],
2739 );
2740 update_option( 'wpsc-ms-advanced-settings', $advanced );
2741
2742 // Remove 'dtt-access' and set new capabilities while preserving role keys.
2743 $roles = get_option( 'wpsc-agent-roles', array() );
2744 if ( ! empty( $roles ) && is_array( $roles ) ) {
2745 foreach ( $roles as $key => &$role ) {
2746 // Ensure caps array exists.
2747 if ( empty( $role['caps'] ) || ! is_array( $role['caps'] ) ) {
2748 $role['caps'] = array();
2749 }
2750 // Bydefault only Admin (1) has access to archive tickets.
2751 $is_enabled = ( $key == 1 );
2752 // Set new capabilities.
2753 $role['caps']['at-unassigned'] = $is_enabled;
2754 $role['caps']['at-assigned-me'] = $is_enabled;
2755 $role['caps']['at-assigned-others'] = $is_enabled;
2756 $role['caps']['at-access'] = $is_enabled;
2757 $role['caps']['at-delete-access'] = $is_enabled;
2758 }
2759 update_option( 'wpsc-agent-roles', $roles );
2760 }
2761 }
2762
2763 if ( version_compare( self::$current_version, '3.4.4', '<' ) ) {
2764
2765 $atl_filters = get_option( 'wpsc-atl-default-filters', array() );
2766 $atl_filters['deleted'] = array(
2767 'label' => __( 'Deleted', 'supportcandy' ),
2768 'is_enable' => 1,
2769 );
2770 update_option( 'wpsc-atl-default-filters', $atl_filters );
2771
2772 // Add capability for delete ticket filter access.
2773 $roles = get_option( 'wpsc-agent-roles', array() );
2774 foreach ( $roles as $key => &$role ) {
2775 $is_enabled = ( $key == 1 );
2776 $roles[ $key ]['caps']['dtt-access'] = $is_enabled;
2777 }
2778 update_option( 'wpsc-agent-roles', $roles );
2779
2780 // permanently delete tickets.
2781 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2782 $advanced['permanent-delete-tickets-time'] = $advanced['permanent-archive-tickets-time'] ?? 0;
2783 $advanced['permanent-delete-tickets-unit'] = $advanced['permanent-archive-tickets-unit'] ?? 'days';
2784 update_option( 'wpsc-ms-advanced-settings', $advanced );
2785
2786 // clear old scheduled task.
2787 wp_clear_scheduled_hook( 'wpsc_permanently_delete_archive_tickets' );
2788 wp_clear_scheduled_hook( 'wpsc_permenently_delete_tickets' );
2789 wp_clear_scheduled_hook( 'wpsc_auto_archive_closed_tickets' );
2790 }
2791
2792 if ( version_compare( self::$current_version, '3.4.7', '<' ) ) {
2793
2794 $widgets = get_option( 'wpsc-ticket-widget', array() );
2795 if ( ! isset( $widgets['agent-collision'] ) ) {
2796
2797 $roles = get_option( 'wpsc-agent-roles', array() );
2798 $role_keys = array();
2799 foreach ( $roles as $key => $role ) {
2800 $role_keys[] = $key;
2801 }
2802
2803 $label = esc_attr__( 'Currently viewing', 'supportcandy' );
2804 $agent_collision = array(
2805 'agent-collision' => array(
2806 'title' => $label,
2807 'is_enable' => 1,
2808 'allow-customer' => 0,
2809 'allowed-agent-roles' => $role_keys,
2810 'show-priority-to-customer' => 0,
2811 'callback' => 'wpsc_get_tw_agent_collision()',
2812 'class' => 'WPSC_ITW_Agent_Collision',
2813 ),
2814 );
2815
2816 // append the widget on the top.
2817 $widgets = array_merge( $agent_collision, $widgets );
2818 update_option( 'wpsc-ticket-widget', $widgets );
2819
2820 // string translations.
2821 $string_translations = get_option( 'wpsc-string-translation' );
2822 $string_translations['wpsc-twt-agent-collision'] = $label;
2823 update_option( 'wpsc-string-translation', $string_translations );
2824 }
2825 }
2826
2827 if ( version_compare( self::$current_version, '3.4.8', '<' ) ) {
2828
2829 $recaptcha = get_option( 'wpsc-recaptcha-settings' );
2830 $recaptcha['captcha-provider'] = $recaptcha['allow-recaptcha'] ? 'google-recaptcha' : '0';
2831 $recaptcha['cloudflare-site-key'] = '';
2832 $recaptcha['cloudflare-secret-key'] = '';
2833 unset( $recaptcha['allow-recaptcha'] );
2834 update_option( 'wpsc-recaptcha-settings', $recaptcha );
2835 }
2836
2837 if ( version_compare( self::$current_version, '3.5.1', '<' ) ) {
2838
2839 // AI assistant feature moved into core - seed defaults for sites upgrading from an older core version.
2840 if ( false === get_option( 'wpsc-ps-ai-assistant-settings', false ) ) {
2841 update_option(
2842 'wpsc-ps-ai-assistant-settings',
2843 array(
2844 'status' => '0',
2845 'provider' => 'openai',
2846 'api_key' => '',
2847 'model' => 'gpt-4o-mini',
2848 'max-tokens' => 500,
2849 'auto-delete-ai-logs-time' => 1,
2850 'auto-delete-ai-logs-unit' => 'year',
2851 'custom-prompt' => '',
2852 'summary-custom-prompt' => '',
2853 'auto-draft-custom-prompt' => '',
2854 'is-active' => 0,
2855 'last-error' => '',
2856 'ai-max-upload-file-size' => 10,
2857 )
2858 );
2859 }
2860
2861 if ( false === get_option( 'wpsc-ps-ai-training-sources', false ) ) {
2862 update_option(
2863 'wpsc-ps-ai-training-sources',
2864 array(
2865 array(
2866 'slug' => 'local',
2867 'type' => 'localhost',
2868 'name' => 'Local',
2869 'api-url' => rest_url(),
2870 'post-types' => array(),
2871 ),
2872 ),
2873 );
2874 }
2875
2876 // AI chatbot feature moved into core - seed defaults for sites upgrading from an older core version.
2877 if ( false === get_option( 'wpsc-ps-acb-chatbot-settings', false ) ) {
2878 update_option(
2879 'wpsc-ps-acb-chatbot-settings',
2880 array(
2881 'status' => '0',
2882 'delete-acb-session-time' => 1,
2883 'delete-acb-session-unit' => 'year',
2884 'show-footer-branding' => '1',
2885 'sessions-per-page' => 30,
2886 )
2887 );
2888 }
2889
2890 if ( false === get_option( 'wpsc-acb-appearance-general', false ) ) {
2891 update_option(
2892 'wpsc-acb-appearance-general',
2893 array(
2894 'background-color' => '#2271b1',
2895 'icon-color' => '#ffffff',
2896 )
2897 );
2898 }
2899
2900 // Migrate legacy AI training data - only for sites that already used AI assistant / AI chatbot via Productivity Suite.
2901 $ps_settings = get_option( 'wpsc-ps-settings', array() );
2902
2903 $wpdb->query( "UPDATE {$wpdb->prefix}psmsc_ai_training SET doc_source = 'local' WHERE source NOT IN ( 'file', 'url', 'ticket' )" );
2904 $wpdb->query( "UPDATE {$wpdb->prefix}psmsc_ai_training SET doc_source = '' WHERE source IN ( 'file', 'url', 'ticket' )" );
2905
2906 // update AI training options.
2907 $local_post_types = array(
2908 array(
2909 'slug' => 'post',
2910 'name' => 'Posts',
2911 'status' => 0,
2912 'endpoint' => rest_url( 'wp/v2/posts' ),
2913 ),
2914 array(
2915 'slug' => 'page',
2916 'name' => 'Pages',
2917 'status' => 0,
2918 'endpoint' => rest_url( 'wp/v2/pages' ),
2919 ),
2920 );
2921
2922 $bd_settings = get_option( 'wpsc-ps-ai-bd-settings', array() );
2923 if ( isset( $bd_settings['bd-status'] ) && $bd_settings['bd-status'] == 1 ) {
2924 $local_post_types[] = array(
2925 'slug' => 'docs',
2926 'name' => 'Betterdocs',
2927 'status' => 1,
2928 'endpoint' => rest_url( 'wp/v2/docs' ),
2929 );
2930
2931 // Update source column for betterdocs source.
2932 $wpdb->query( "UPDATE {$wpdb->prefix}psmsc_ai_training SET source = 'docs' WHERE source = 'betterdocs'" );
2933 }
2934
2935 update_option(
2936 'wpsc-ps-ai-training-sources',
2937 array(
2938 array(
2939 'slug' => 'local',
2940 'type' => 'localhost',
2941 'name' => 'Local',
2942 'api-url' => rest_url(),
2943 'post-types' => $local_post_types,
2944 ),
2945 ),
2946 );
2947
2948 // wpsc_ps_ai_categories is no longer used - post-type training sources are
2949 // now routed directly by source type instead of through a categories registry.
2950 delete_option( 'wpsc_ps_ai_categories' );
2951
2952 // remove 'category', 'is_expire' and 'expiry_date' columns from AI training table.
2953 foreach ( array( 'category', 'is_expire', 'expiry_date' ) as $column ) {
2954 $column_exists = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}psmsc_ai_training LIKE '{$column}'" );
2955 if ( ! empty( $column_exists ) ) {
2956 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_ai_training DROP COLUMN {$column}" );
2957 }
2958 }
2959
2960 // unschedule expired training cleanup cron, this feature has been removed.
2961 wp_clear_scheduled_hook( 'wpsc_auto_delete_ai_training_expired_records' );
2962
2963 // remove 'manage-ai-training' capability, this is no longer used.
2964 $roles = get_option( 'wpsc-agent-roles', array() );
2965 foreach ( $roles as $key => $role ) {
2966 unset( $role['caps']['manage-ai-training'] );
2967 $roles[ $key ] = $role;
2968 }
2969 update_option( 'wpsc-agent-roles', $roles );
2970
2971 if ( isset( $ai_assistant['is-active'] ) ) {
2972 $ai_assistant = get_option( 'wpsc-ps-ai-assistant-settings' );
2973 $ai_assistant['status'] = $ai_assistant['is-active'] ? 1 : 0;
2974 update_option( 'wpsc-ps-ai-assistant-settings', $ai_assistant );
2975 }
2976
2977 // enable chatbot feature.
2978 if ( isset( $ps_settings['ai-chatbot'] ) ) {
2979 $chatbot = get_option( 'wpsc-ps-acb-chatbot-settings' );
2980 $chatbot['status'] = $ps_settings['ai-chatbot'] ? 1 : 0;
2981 update_option( 'wpsc-ps-acb-chatbot-settings', $chatbot );
2982 }
2983 }
2984
2985 update_option( 'wpsc-string-translation', $string_translations );
2986 self::set_upgrade_complete();
2987 }
2988
2989 /**
2990 * Mark upgrade as complete
2991 */
2992 public static function set_upgrade_complete() {
2993
2994 update_option( 'wpsc_current_version', WPSC_VERSION );
2995 update_option( 'wpsc_db_version', WPSC_DB_VERSION );
2996 self::$current_version = WPSC_VERSION;
2997 self::$is_upgrade = false;
2998 }
2999
3000 /**
3001 * Actions to perform after plugin deactivated
3002 *
3003 * @return void
3004 */
3005 public static function deactivate() {
3006
3007 // Remove cron jobs.
3008 WPSC_Cron::unschedule_events();
3009 }
3010
3011 /**
3012 * Add htaccess file in supportcandy attachment folder
3013 *
3014 * @return void
3015 */
3016 public static function attachment_security_file() {
3017
3018 $upload_dir = wp_upload_dir();
3019 $wpsc_dir = $upload_dir['basedir'] . '/wpsc';
3020 if ( ! is_file( $wpsc_dir . '/.htaccess' ) ) {
3021 @file_put_contents( $wpsc_dir . '/.htaccess', 'deny from all' ); //phpcs:ignore
3022 }
3023 }
3024
3025 /**
3026 * Create required database indexes
3027 *
3028 * @return void
3029 */
3030 private static function create_indexing() {
3031
3032 global $wpdb;
3033
3034 $column_slugs = array( 'status', 'customer', 'category', 'priority', 'date_updated', 'date_created', 'date_closed' );
3035 foreach ( $column_slugs as $slug ) {
3036 $index_name = "idx_cf_{$slug}";
3037
3038 // Check if index already exists.
3039 $index_exists = $wpdb->get_var(
3040 $wpdb->prepare(
3041 "SHOW INDEX FROM {$wpdb->prefix}psmsc_tickets WHERE Key_name = %s",
3042 $index_name
3043 )
3044 );
3045
3046 if ( ! $index_exists ) {
3047 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD INDEX {$index_name} (`{$slug}`)" );
3048 }
3049 }
3050
3051 // create index on thread table.
3052 $index_name = 'idx_ticket_id';
3053 $index_exists = $wpdb->get_var(
3054 $wpdb->prepare(
3055 "SHOW INDEX FROM {$wpdb->prefix}psmsc_threads WHERE Key_name = %s",
3056 $index_name
3057 )
3058 );
3059 if ( ! $index_exists ) {
3060 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_threads ADD INDEX {$index_name} (ticket)" );
3061 }
3062
3063 // create index on archive ticket table.
3064 $column_slugs = array( 'status', 'customer', 'category', 'priority', 'date_updated', 'date_created', 'date_closed' );
3065 foreach ( $column_slugs as $slug ) {
3066 $index_name = "idx_cf_{$slug}";
3067
3068 // Check if index already exists.
3069 $index_exists = $wpdb->get_var(
3070 $wpdb->prepare(
3071 "SHOW INDEX FROM {$wpdb->prefix}psmsc_archived_tickets WHERE Key_name = %s",
3072 $index_name
3073 )
3074 );
3075
3076 if ( ! $index_exists ) {
3077 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD INDEX {$index_name} (`{$slug}`)" );
3078 }
3079 }
3080
3081 // create index on thread table.
3082 $index_name = 'idx_ticket_id';
3083 $index_exists = $wpdb->get_var(
3084 $wpdb->prepare(
3085 "SHOW INDEX FROM {$wpdb->prefix}psmsc_archived_threads WHERE Key_name = %s",
3086 $index_name
3087 )
3088 );
3089 if ( ! $index_exists ) {
3090 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_threads ADD INDEX {$index_name} (ticket)" );
3091 }
3092 }
3093 }
3094 endif;
3095
3096 WPSC_Installation::init();
3097