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

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

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