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

2,767 lines 90.8 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 'dtt-access' => true, // Deleted ticket access.
926 'eci-access' => true, // Edit customer info.
927 'dash-access' => true, // Dashboard access.
928 'at-access' => true, // Archive tickets menu access.
929 'at-delete-access' => true, // Archive tickets delete access.
930
931 'tt-unassigned' => true, // Ticket tags.
932 'tt-assigned-me' => true,
933 'tt-assigned-others' => true,
934
935 'at-unassigned' => true, // Archive ticket permissions.
936 'at-assigned-me' => true,
937 'at-assigned-others' => true,
938 ),
939 ),
940 2 => array(
941 'label' => 'Agent',
942 'caps' => array(
943
944 'view-unassigned' => true,
945 'view-assigned-me' => true,
946 'view-assigned-others' => false,
947
948 'reply-unassigned' => true,
949 'reply-assigned-me' => true,
950 'reply-assigned-others' => false,
951
952 'pn-unassigned' => true,
953 'pn-assigned-me' => true,
954 'pn-assigned-others' => false,
955
956 'aa-unassigned' => true,
957 'aa-assigned-me' => true,
958 'aa-assigned-others' => false,
959
960 'cs-unassigned' => true,
961 'cs-assigned-me' => true,
962 'cs-assigned-others' => false,
963
964 'ctf-unassigned' => true,
965 'ctf-assigned-me' => true,
966 'ctf-assigned-others' => false,
967
968 'caof-unassigned' => true,
969 'caof-assigned-me' => true,
970 'caof-assigned-others' => false,
971
972 'crb-unassigned' => false,
973 'crb-assigned-me' => false,
974 'crb-assigned-others' => false,
975
976 'eth-unassigned' => false,
977 'eth-assigned-me' => false,
978 'eth-assigned-others' => false,
979
980 'dth-unassigned' => false,
981 'dth-assigned-me' => false,
982 'dth-assigned-others' => false,
983
984 'vl-unassigned' => true,
985 'vl-assigned-me' => true,
986 'vl-assigned-others' => true,
987
988 'dtt-unassigned' => false,
989 'dtt-assigned-me' => false,
990 'dtt-assigned-others' => false,
991
992 'dt-unassigned' => true,
993 'dt-assigned-me' => true,
994 'dt-assigned-others' => true,
995
996 'ar-unassigned' => true,
997 'ar-assigned-me' => true,
998 'ar-assigned-others' => false,
999
1000 'backend-access' => true,
1001 'create-as' => true,
1002 'dtt-access' => false,
1003 'eci-access' => false,
1004 'dash-access' => true, // Dashboard access.
1005 'at-access' => false, // Archive tickets menu access.
1006 'at-delete-access' => false, // Archive tickets delete access.
1007
1008 'tt-unassigned' => true, // Ticket tags.
1009 'tt-assigned-me' => true,
1010 'tt-assigned-others' => false,
1011
1012 'at-unassigned' => false, // Archive ticket permissions.
1013 'at-assigned-me' => false,
1014 'at-assigned-others' => false,
1015 ),
1016 ),
1017 )
1018 );
1019
1020 // default agents.
1021 $users = get_users( array( 'role' => 'administrator' ) );
1022 foreach ( $users as $user ) {
1023 // customer record.
1024 $wpdb->insert(
1025 $wpdb->prefix . 'psmsc_customers',
1026 array(
1027 'user' => $user->ID,
1028 'name' => $user->display_name,
1029 'email' => $user->user_email,
1030 )
1031 );
1032 // agent record.
1033 $wpdb->insert(
1034 $wpdb->prefix . 'psmsc_agents',
1035 array(
1036 'user' => $user->ID,
1037 'customer' => $wpdb->insert_id,
1038 'role' => 1,
1039 'name' => $user->display_name,
1040 'is_active' => 1,
1041 )
1042 );
1043 // agent working hrs.
1044 $agent_id = $wpdb->insert_id;
1045 for ( $i = 1; $i <= 7; $i++ ) {
1046 $wpdb->insert(
1047 $wpdb->prefix . 'psmsc_working_hrs',
1048 array(
1049 'agent' => $agent_id,
1050 'day' => $i,
1051 'start_time' => '00:00:00',
1052 'end_time' => '23:59:59',
1053 )
1054 );
1055 }
1056 if ( ! is_multisite() && ! $user->has_cap( 'wpsc_agent' ) ) {
1057 $user->add_cap( 'wpsc_agent' );
1058 }
1059 }
1060
1061 // ticket form fields.
1062 update_option(
1063 'wpsc-tff',
1064 array(
1065 'name' => array(
1066 'is-required' => 1,
1067 'width' => 'half',
1068 'visibility' => '',
1069 ),
1070 'email' => array(
1071 'is-required' => 1,
1072 'width' => 'half',
1073 'visibility' => '',
1074 ),
1075 'subject' => array(
1076 'is-required' => 1,
1077 'width' => 'full',
1078 'visibility' => '',
1079 'relation' => 'AND',
1080 ),
1081 'description' => array(
1082 'is-required' => 1,
1083 'width' => 'full',
1084 'visibility' => '',
1085 'relation' => 'AND',
1086 ),
1087 'category' => array(
1088 'is-required' => 1,
1089 'width' => 'half',
1090 'visibility' => '',
1091 'relation' => 'AND',
1092 ),
1093 )
1094 );
1095
1096 // agent ticket list.
1097 update_option(
1098 'wpsc-atl-list-items',
1099 array( 'id', 'status', 'subject', 'name', 'category', 'priority', 'assigned_agent', 'date_updated' )
1100 );
1101 update_option(
1102 'wpsc-atl-filter-items',
1103 array( 'id', 'status', 'customer', 'subject', 'category', 'priority', 'assigned_agent', 'date_updated', 'date_created' )
1104 );
1105 $labels = array(
1106 'all' => __( 'All', 'supportcandy' ),
1107 'unresolved' => __( 'Unresolved', 'supportcandy' ),
1108 'unassigned' => __( 'Unassigned', 'supportcandy' ),
1109 'mine' => __( 'Mine', 'supportcandy' ),
1110 'closed' => __( 'Closed', 'supportcandy' ),
1111 'deleted' => __( 'Deleted', 'supportcandy' ),
1112 );
1113 foreach ( $labels as $key => $string ) {
1114 $string_translations[ 'wpsc-atl-' . $key ] = $string;
1115 }
1116 update_option(
1117 'wpsc-atl-default-filters',
1118 array(
1119 'all' => array(
1120 'label' => $labels['all'],
1121 'is_enable' => 1,
1122 ),
1123 'unresolved' => array(
1124 'label' => $labels['unresolved'],
1125 'is_enable' => 1,
1126 ),
1127 'unassigned' => array(
1128 'label' => $labels['unassigned'],
1129 'is_enable' => 1,
1130 ),
1131 'mine' => array(
1132 'label' => $labels['mine'],
1133 'is_enable' => 1,
1134 ),
1135 'closed' => array(
1136 'label' => $labels['closed'],
1137 'is_enable' => 1,
1138 ),
1139 'deleted' => array(
1140 'label' => $labels['deleted'],
1141 'is_enable' => 1,
1142 ),
1143 )
1144 );
1145
1146 // customer ticket list.
1147 update_option(
1148 'wpsc-ctl-list-items',
1149 array( 'id', 'status', 'subject', 'category', 'date_created', 'date_updated' )
1150 );
1151 update_option(
1152 'wpsc-ctl-filter-items',
1153 array( 'id', 'status', 'subject', 'category', 'date_updated', 'date_created' )
1154 );
1155 $labels = array(
1156 'all' => __( 'All', 'supportcandy' ),
1157 'unresolved' => __( 'Unresolved', 'supportcandy' ),
1158 'closed' => __( 'Closed', 'supportcandy' ),
1159 );
1160 foreach ( $labels as $key => $string ) {
1161 $string_translations[ 'wpsc-ctl-' . $key ] = $string;
1162 }
1163 update_option(
1164 'wpsc-ctl-default-filters',
1165 array(
1166 'all' => array(
1167 'label' => $labels['all'],
1168 'is_enable' => 1,
1169 ),
1170 'unresolved' => array(
1171 'label' => $labels['unresolved'],
1172 'is_enable' => 1,
1173 ),
1174 'closed' => array(
1175 'label' => $labels['closed'],
1176 'is_enable' => 1,
1177 ),
1178 )
1179 );
1180
1181 // ticket list more settings.
1182 update_option(
1183 'wpsc-tl-ms-agent-view',
1184 array(
1185 'default-sort-by' => 'date_updated',
1186 'default-sort-order' => 'DESC',
1187 'number-of-tickets' => 20,
1188 'unresolved-ticket-statuses' => array( 1, 2, 3 ),
1189 'default-filter' => 'all',
1190 'ticket-reply-redirect' => 'no-redirect',
1191 )
1192 );
1193 update_option(
1194 'wpsc-tl-ms-customer-view',
1195 array(
1196 'default-sort-by' => 'date_updated',
1197 'default-sort-order' => 'DESC',
1198 'number-of-tickets' => 20,
1199 'unresolved-ticket-statuses' => array( 1, 2, 3 ),
1200 'default-filter' => 'all',
1201 'ticket-reply-redirect' => 'no-redirect',
1202 )
1203 );
1204 update_option(
1205 'wpsc-tl-ms-advanced',
1206 array(
1207 'closed-ticket-statuses' => array( 4 ),
1208 'auto-refresh-list-status' => 0,
1209 )
1210 );
1211
1212 // email notifications.
1213 update_option(
1214 'wpsc-en-general',
1215 array(
1216 'from-name' => '',
1217 'from-email' => '',
1218 'reply-to' => '',
1219 'cron-email-count' => 5,
1220 'blocked-emails' => array(),
1221 'attachments-in-notification' => 'actual-files',
1222 )
1223 );
1224 $translations = array(
1225 1 => array(
1226 'subject' => 'Your ticket has been created successfully!',
1227 'body' => '<p>Thanks for reaching out, we\'ve received your request!</p>',
1228 ),
1229 2 => array(
1230 'body' => '<p>You have received a new ticket!</p><p><strong>{{customer}}</strong><em>reported</em></p><p>{{description}}</p><p>{{ticket_url}}</p>',
1231 ),
1232 3 => array(
1233 'body' => '<p><strong>{{last_reply_user_name}}</strong> <em>replied</em></p><p>{{last_reply}}</p><p>{{ticket_url}}</p><p>{{ticket_history}}</p>',
1234 ),
1235 4 => array(
1236 'subject' => 'Your ticket has been closed!',
1237 'body' => '<p>Dear {{customer}},</p><p>Your ticket #{{id}} has been closed.</p>',
1238 ),
1239 );
1240 foreach ( $translations as $index => $translation ) {
1241 if ( isset( $translation['subject'] ) ) {
1242 $string_translations[ 'wpsc-en-tn-subject-' . $index ] = $translation['subject'];
1243 }
1244 $string_translations[ 'wpsc-en-tn-body-' . $index ] = $translation['body'];
1245 }
1246 update_option(
1247 'wpsc-email-templates',
1248 array(
1249 '1' => array(
1250 'title' => 'New ticket customer confirmation',
1251 'event' => 'create-ticket',
1252 'is_enable' => 1,
1253 'subject' => $translations[1]['subject'],
1254 'body' => array(
1255 'text' => $translations[1]['body'],
1256 'editor' => 'html',
1257 ),
1258 'to' => array(
1259 'general-recipients' => array( 'customer' ),
1260 'agent-roles' => array(),
1261 'custom' => array(),
1262 ),
1263 'cc' => array(
1264 'general-recipients' => array(),
1265 'agent-roles' => array(),
1266 'custom' => array(),
1267 ),
1268 'bcc' => array(
1269 'general-recipients' => array(),
1270 'agent-roles' => array(),
1271 'custom' => array(),
1272 ),
1273 'conditions' => '',
1274 ),
1275 '2' => array(
1276 'title' => 'New ticket staff notification',
1277 'event' => 'create-ticket',
1278 'is_enable' => 1,
1279 'subject' => '{{subject}}',
1280 'body' => array(
1281 'text' => $translations[2]['body'],
1282 'editor' => 'html',
1283 ),
1284 'to' => array(
1285 'general-recipients' => array( 'assignee' ),
1286 'agent-roles' => array( 1 ),
1287 'custom' => array(),
1288 ),
1289 'cc' => array(
1290 'general-recipients' => array(),
1291 'agent-roles' => array(),
1292 'custom' => array(),
1293 ),
1294 'bcc' => array(
1295 'general-recipients' => array(),
1296 'agent-roles' => array(),
1297 'custom' => array(),
1298 ),
1299 'conditions' => '',
1300 ),
1301 '3' => array(
1302 'title' => 'Reply ticket notification',
1303 'event' => 'reply-ticket',
1304 'is_enable' => 1,
1305 'subject' => '{{subject}}',
1306 'body' => array(
1307 'text' => $translations[3]['body'],
1308 'editor' => 'html',
1309 ),
1310 'to' => array(
1311 'general-recipients' => array( 'customer', 'assignee' ),
1312 'agent-roles' => array( 1 ),
1313 'custom' => array(),
1314 ),
1315 'cc' => array(
1316 'general-recipients' => array(),
1317 'agent-roles' => array(),
1318 'custom' => array(),
1319 ),
1320 'bcc' => array(
1321 'general-recipients' => array(),
1322 'agent-roles' => array(),
1323 'custom' => array(),
1324 ),
1325 'conditions' => '',
1326 ),
1327 '4' => array(
1328 'title' => 'Close ticket customer notification',
1329 'event' => 'change-ticket-status',
1330 'is_enable' => 1,
1331 'subject' => $translations[4]['subject'],
1332 'body' => array(
1333 'text' => $translations[4]['body'],
1334 'editor' => 'html',
1335 ),
1336 'to' => array(
1337 'general-recipients' => array( 'customer' ),
1338 'agent-roles' => array(),
1339 'custom' => array(),
1340 ),
1341 'cc' => array(
1342 'general-recipients' => array(),
1343 'agent-roles' => array(),
1344 'custom' => array(),
1345 ),
1346 'bcc' => array(
1347 'general-recipients' => array(),
1348 'agent-roles' => array(),
1349 'custom' => array(),
1350 ),
1351 'conditions' => '[[{"slug":"status","operator":"=","operand_val_1":"4"}]]',
1352 ),
1353 )
1354 );
1355
1356 // user registration otp.
1357 $subject = 'User registration OTP - {{otp}}';
1358 $body = '<p>Hello {{firstname}},</p><p>Below is your one time password for user registration:</p><p><strong>{{otp}}</strong></p>';
1359 update_option(
1360 'wpsc-en-user-reg',
1361 array(
1362 'subject' => $subject,
1363 'body' => $body,
1364 'editor' => 'html',
1365 )
1366 );
1367 $string_translations['wpsc-user-otp-subject'] = $subject;
1368 $string_translations['wpsc-user-otp-body'] = $body;
1369
1370 // guest login otp.
1371 $subject = 'Guest Login - {{otp}}';
1372 $body = '<p>Hello {{name}},</p><p>Below is your one time password for guest login:</p><p><strong>{{otp}}</strong></p>';
1373 update_option(
1374 'wpsc-en-guest-login',
1375 array(
1376 'subject' => $subject,
1377 'body' => $body,
1378 'editor' => 'html',
1379 )
1380 );
1381 $string_translations['wpsc-guest-otp-subject'] = $subject;
1382 $string_translations['wpsc-guest-otp-body'] = $body;
1383
1384 // General settings.
1385 update_option(
1386 'wpsc-gs-general',
1387 array(
1388 'ticket-status-after-customer-reply' => 3,
1389 'ticket-status-after-agent-reply' => 2,
1390 'close-ticket-status' => 4,
1391 'reply-form-position' => 'top',
1392 'default-date-format' => 'Y-m-d H:i:s',
1393 'ticket-alice' => 'Ticket #',
1394 'allow-close-ticket' => array( 'customer', 1, 2 ),
1395 'allow-ar-thread-email' => array( 1, 2 ),
1396 'allow-create-ticket' => array( 'registered-user', 1, 2 ),
1397 'allowed-search-fields' => array( 'id', 'customer', 'subject', 'threads' ),
1398 )
1399 );
1400
1401 update_option(
1402 'wpsc-gs-page-settings',
1403 array(
1404 'support-page' => 0,
1405 'open-ticket-page' => 0,
1406 'ticket-url-page' => 'support-page',
1407 'new-ticket-page' => 'default',
1408 'new-ticket-url' => '',
1409 'user-login' => 'default',
1410 'custom-login-url' => '',
1411 'user-registration' => 'disable',
1412 'custom-registration-url' => '',
1413 'otp-login' => 1,
1414 'load-scripts' => 'all-pages',
1415 'load-script-pages' => array(),
1416 )
1417 );
1418
1419 // File attachment settings.
1420 require_once WPSC_ABSPATH . 'includes/class-wpsc-mime-types.php';
1421
1422 $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';
1423 $exts = $extensions ? explode( ',', $extensions ) : array();
1424 $exts = array_map( 'trim', $exts );
1425 $mimes = array();
1426 foreach ( $exts as $key => $value ) {
1427 $mime = WPSC_MIME_TYPES::get_mime_type( $value );
1428 if ( $mime ) {
1429 $mimes[ $value ] = $mime;
1430 }
1431 }
1432
1433 update_option(
1434 'wpsc-gs-file-attachments',
1435 array(
1436 'attachments-max-filesize' => 20,
1437 'allowed-file-extensions' => $extensions,
1438 'allowed-file-ext-mimes' => $mimes,
1439 'mime-exceptions' => array(),
1440 'image-download-behaviour' => 'open-browser',
1441 )
1442 );
1443
1444 $translation = '<p>Thanks for reaching out, we\'ve received your request!</p><p>{{ticket_url}}</p>';
1445 $string_translations['wpsc-thankyou-html'] = $translation;
1446 $string_translations['wpsc-thankyou-html-agent'] = $translation;
1447 update_option(
1448 'wpsc-gs-thankyou-page-settings',
1449 array(
1450 'action-agent' => 'text',
1451 'action-customer' => 'text',
1452 'html-agent' => $translation,
1453 'html-customer' => $translation,
1454 'page-url-agent' => '',
1455 'page-url-customer' => '',
1456 'editor-agent' => 'html',
1457 'editor-customer' => 'html',
1458 )
1459 );
1460
1461 // misc settings.
1462 $translation = '<p>I understand my personal information like Name, Email address, IP address, etc. will be stored in database.</p>';
1463 $string_translations['wpsc-gdpr'] = $translation;
1464 $string_translations['wpsc-gdpr-reg-user'] = $translation;
1465 update_option(
1466 'wpsc-gdpr-settings',
1467 array(
1468 'allow-gdpr' => 1,
1469 'gdpr-text' => $translation,
1470 'personal-data-retention-time' => 0,
1471 'personal-data-retention-unit' => 'days',
1472 'editor' => 'html',
1473 'allow-gdpr-reg-user' => 1,
1474 'gdpr-text-reg-user' => $translation,
1475 'editor-reg-user' => 'html',
1476 'ip-address-collection' => 1,
1477 )
1478 );
1479
1480 update_option(
1481 'wpsc-recaptcha-settings',
1482 array(
1483 'allow-recaptcha' => 0,
1484 'recaptcha-version' => 3,
1485 'recaptcha-site-key' => '',
1486 'recaptcha-secret-key' => '',
1487 )
1488 );
1489
1490 update_option(
1491 'wpsc-ms-advanced-settings',
1492 array(
1493 'public-mode' => 0,
1494 'public-mode-reply' => 0,
1495 'reply-confirmation' => 1,
1496 'note-confirmation' => 0,
1497 'thread-date-display-as' => 'diff',
1498 'thread-date-format' => 'F d, Y h:i A',
1499 'do-not-notify-owner' => 1,
1500 'do-not-notify-owner-status' => 1,
1501 'ticket-id-format' => 'sequential',
1502 'starting-ticket-id' => 1,
1503 'random-id-length' => 8,
1504 'ticket-history-macro-threads' => 5,
1505 'register-user-if-not-exist' => 0,
1506 'auto-archive-tickets-time' => 0,
1507 'auto-archive-tickets-unit' => 'days',
1508 'permanent-archive-tickets-time' => 0,
1509 'permanent-archive-tickets-unit' => 'days',
1510 'allow-bcc' => 0,
1511 'allow-cc' => 0,
1512 'view-more' => 1,
1513 'allow-reply-to-close-ticket' => array( 'customer', 'agent' ),
1514 'raised-by-user' => 'customer',
1515 'allow-my-profile' => 1,
1516 'allow-agent-profile' => 1,
1517 'ticket-url-auth' => 0,
1518 'rest-api' => 1,
1519 'agent-collision' => 1,
1520 'self-assign' => 1,
1521 'reply-close' => 0,
1522 )
1523 );
1524
1525 $translation = '<p>I agree to the terms and conditions</p>';
1526 $string_translations['wpsc-term-and-conditions'] = $translation;
1527 $string_translations['wpsc-term-and-conditions-reg-user'] = $translation;
1528 update_option(
1529 'wpsc-term-and-conditions',
1530 array(
1531 'allow-term-and-conditions' => 1,
1532 'tandc-text' => $translation,
1533 'editor' => 'html',
1534 'allow-term-and-conditions-reg-user' => 1,
1535 'tandc-text-reg-user' => $translation,
1536 'editor-reg-user' => 'html',
1537 )
1538 );
1539
1540 // ticket widgets.
1541 $labels = array(
1542 'change-status' => __( 'Ticket status', 'supportcandy' ),
1543 'raised-by' => __( 'Customer', 'supportcandy' ),
1544 'ticket-info' => __( 'Ticket info', 'supportcandy' ),
1545 'assignee' => __( 'Assignee', 'supportcandy' ),
1546 'ticket-fields' => __( 'Ticket fields', 'supportcandy' ),
1547 'agentonly-fields' => __( 'Agent only fields', 'supportcandy' ),
1548 'additional-recipients' => __( 'Additional recipients', 'supportcandy' ),
1549 'biographical-info' => __( 'Biographical Info', 'supportcandy' ),
1550 'tags' => __( 'Tags', 'supportcandy' ),
1551 );
1552 foreach ( $labels as $key => $string ) {
1553 $string_translations[ 'wpsc-twt-' . $key ] = $string;
1554 }
1555 update_option(
1556 'wpsc-ticket-widget',
1557 array(
1558 'change-status' => array(
1559 'title' => $labels['change-status'],
1560 'is_enable' => 1,
1561 'allow-customer' => 1,
1562 'allowed-agent-roles' => array( 1, 2 ),
1563 'show-priority-to-customer' => 0,
1564 'callback' => 'wpsc_get_tw_ticket_status()',
1565 'class' => 'WPSC_ITW_Change_Status',
1566 ),
1567 'raised-by' => array(
1568 'title' => $labels['raised-by'],
1569 'is_enable' => 1,
1570 'allow-customer' => 0,
1571 'allowed-agent-roles' => array( 1, 2 ),
1572 'callback' => 'wpsc_get_tw_raised_by()',
1573 'class' => 'WPSC_ITW_Raisedby',
1574 ),
1575 'ticket-info' => array(
1576 'title' => $labels['ticket-info'],
1577 'is_enable' => 1,
1578 'allow-customer' => 0,
1579 'allowed-agent-roles' => array( 1, 2 ),
1580 'callback' => 'wpsc_get_tw_ticket_info()',
1581 'class' => 'WPSC_ITW_Ticket_Info',
1582 ),
1583 'assignee' => array(
1584 'title' => $labels['assignee'],
1585 'is_enable' => 1,
1586 'allow-customer' => 0,
1587 'allowed-agent-roles' => array( 1, 2 ),
1588 'callback' => 'wpsc_get_tw_agents()',
1589 'class' => 'WPSC_ITW_Assigned_Agents',
1590 ),
1591 'ticket-fields' => array(
1592 'title' => $labels['ticket-fields'],
1593 'is_enable' => 1,
1594 'allow-customer' => 1,
1595 'allowed-agent-roles' => array( 1, 2 ),
1596 'callback' => 'wpsc_get_tw_ticket_fields()',
1597 'class' => 'WPSC_ITW_Ticket_Fields',
1598 ),
1599 'agentonly-fields' => array(
1600 'title' => $labels['agentonly-fields'],
1601 'is_enable' => 1,
1602 'allow-customer' => 0,
1603 'allowed-agent-roles' => array( 1, 2 ),
1604 'callback' => 'wpsc_get_tw_agentonly_fields()',
1605 'class' => 'WPSC_ITW_Agentonly_Fields',
1606 ),
1607 'additional-recipients' => array(
1608 'title' => $labels['additional-recipients'],
1609 'is_enable' => 1,
1610 'allow-customer' => 1,
1611 'allowed-agent-roles' => array( 1, 2 ),
1612 'callback' => 'wpsc_get_tw_additional_recipients()',
1613 'class' => 'WPSC_ITW_Additional_Recipients',
1614 ),
1615 'biographical-info' => array(
1616 'title' => $labels['biographical-info'],
1617 'is_enable' => 0,
1618 'allow-customer' => 1,
1619 'allowed-agent-roles' => array( 1, 2 ),
1620 'callback' => 'wpsc_get_tw_biographical_info()',
1621 'class' => 'WPSC_ITW_Biographical_Info',
1622 ),
1623 'tags' => array(
1624 'title' => $labels['tags'],
1625 'is_enable' => 1,
1626 'allow-customer' => 0,
1627 'allowed-agent-roles' => array( 1, 2 ),
1628 'callback' => 'wpsc_get_tw_ticket_tags()',
1629 'class' => 'WPSC_ITW_Ticket_Tags',
1630 ),
1631 )
1632 );
1633
1634 // Rich text editor.
1635 $notice = sprintf(
1636 /* translators: %1$s: attachment max file size, %2$s: allowed file extenstions. */
1637 __( 'You can upload files maximum size %1$s mb of types %2$s.', 'supportcandy' ),
1638 20,
1639 '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'
1640 );
1641 update_option(
1642 'wpsc-te-agent',
1643 array(
1644 'enable' => 1,
1645 'allow-attachments' => 1,
1646 'toolbar' => array( 'bold', 'italic', 'underline', 'blockquote', 'alignleft aligncenter alignright', 'bullist', 'numlist', 'rtl', 'link', 'wpsc_insert_editor_img' ),
1647 'file-attachment-notice' => 0,
1648 'file-attachment-notice-text' => $notice,
1649 )
1650 );
1651 update_option(
1652 'wpsc-te-registered-user',
1653 array(
1654 'enable' => 1,
1655 'allow-attachments' => 1,
1656 'toolbar' => array( 'bold', 'italic', 'underline', 'blockquote', 'alignleft aligncenter alignright', 'bullist', 'numlist', 'rtl', 'link', 'wpsc_insert_editor_img' ),
1657 'file-attachment-notice' => 0,
1658 'file-attachment-notice-text' => $notice,
1659 )
1660 );
1661 update_option(
1662 'wpsc-te-guest-user',
1663 array(
1664 'enable' => 0,
1665 'allow-attachments' => 0,
1666 'toolbar' => array( 'bold', 'italic', 'underline', 'blockquote', 'alignleft aligncenter alignright', 'bullist', 'numlist', 'rtl', 'link', 'wpsc_insert_editor_img' ),
1667 'file-attachment-notice' => 0,
1668 'file-attachment-notice-text' => $notice,
1669 )
1670 );
1671 update_option( 'wpsc-te-advanced', array( 'html-pasting' => 0 ) );
1672
1673 // working hrs settings.
1674 update_option(
1675 'wpsc-wh-settings',
1676 array(
1677 'allow-agent-modify-wh' => 0,
1678 'allow-agent-modify-leaves' => 0,
1679 )
1680 );
1681
1682 // appearence settings.
1683 update_option(
1684 'wpsc-ap-general',
1685 array(
1686 'primary-color' => '#313042',
1687 'menu-link-color' => '#fff',
1688 'main-background-color' => '#fff',
1689 'main-text-color' => '#2c3e50',
1690 'link-color' => '#2271b1',
1691 )
1692 );
1693 update_option(
1694 'wpsc-ap-individual-ticket',
1695 array(
1696 'reply-primary-color' => '#2c3e50',
1697 'reply-secondary-color' => '#777777',
1698 'reply-icon-color' => '#777777',
1699 'note-primary-color' => '#8e6600',
1700 'note-secondary-color' => '#8e8d45',
1701 'note-icon-color' => '#8e8d45',
1702 'log-text' => '#2c3e50',
1703 'widget-header-bg-color' => '#fff8e5',
1704 'widget-header-text-color' => '#ff8f2b',
1705 'widget-body-bg-color' => '#f9f9f9',
1706 'widget-body-label-color' => '#777',
1707 'widget-body-text-color' => '#2c3e50',
1708 'reply-close-bg-color' => '#fff',
1709 'reply-close-text-color' => '#707070',
1710 )
1711 );
1712 update_option(
1713 'wpsc-ap-modal',
1714 array(
1715 'header-bg-color' => '#fff8e5',
1716 'header-text-color' => '#ff8f2b',
1717 'body-bg-color' => '#fff',
1718 'body-label-color' => '#777',
1719 'body-text-color' => '#2c3e50',
1720 'footer-bg-color' => '#fff',
1721 'z-index' => 900000000,
1722 )
1723 );
1724 update_option(
1725 'wpsc-ap-agent-collision',
1726 array(
1727 'header-bg-color' => '#e6e6e6',
1728 'header-text-color' => '#2c3e50',
1729 )
1730 );
1731 update_option(
1732 'wpsc-ap-ticket-list',
1733 array(
1734 'list-header-background-color' => '#2c3e50',
1735 'list-header-text-color' => '#fff',
1736 'list-item-odd-background-color' => '#fff',
1737 'list-item-odd-text-color' => '#2c3e50',
1738 'list-item-even-background-color' => '#f2f2f2',
1739 'list-item-even-text-color' => '#2c3e50',
1740 'list-item-hover-background-color' => '#dfe4ea',
1741 'list-item-hover-text-color' => '#2c3e50',
1742 )
1743 );
1744
1745 // ticket tags general setting.
1746 update_option(
1747 'wpsc-ticket-tags-general-settings',
1748 array(
1749 'color' => '#000000',
1750 'bg-color' => '#ffc300',
1751 )
1752 );
1753
1754 // dashboard general setting.
1755 update_option(
1756 'wpsc-ap-dashboard',
1757 array(
1758 'card-body-bg-color' => '#f9f9f9',
1759 'card-body-svg-color' => '#777',
1760 'card-body-text-color' => '#2c3e50',
1761 'widget-body-bg-color' => '#f9f9f9',
1762 'widget-body-svg-color' => '#777',
1763 'widget-body-text-color' => '#2c3e50',
1764 )
1765 );
1766
1767 // upload directory.
1768 $upload_dir = wp_upload_dir();
1769 $filepath = $upload_dir['basedir'] . '/wpsc';
1770 if ( ! file_exists( $filepath ) ) {
1771 mkdir( $filepath, 0755, true );
1772 }
1773
1774 // Dashboard cards.
1775 $labels = array(
1776 'new-tickets' => __( 'New Tickets', 'supportcandy' ),
1777 'unresolved' => __( 'Unresolved', 'supportcandy' ),
1778 'unassigned' => __( 'Unassigned', 'supportcandy' ),
1779 'closed' => __( 'Closed', 'supportcandy' ),
1780 'mine' => __( 'Mine', 'supportcandy' ),
1781 );
1782 foreach ( $labels as $key => $string ) {
1783 $string_translations[ 'wpsc-dashboard-card-' . $key ] = $string;
1784 }
1785 update_option(
1786 'wpsc-dashboard-cards',
1787 array(
1788 'new-tickets' => array(
1789 'title' => $labels['new-tickets'],
1790 'is_enable' => 1,
1791 'allowed-agent-roles' => array( 1, 2 ),
1792 'callback' => 'wpsc_dbc_new_tickets()',
1793 'class' => 'WPSC_DBC_New_Tickets',
1794 'type' => 'default',
1795 ),
1796 'unresolved' => array(
1797 'title' => $labels['unresolved'],
1798 'is_enable' => 1,
1799 'allowed-agent-roles' => array( 1, 2 ),
1800 'callback' => 'wpsc_dbc_unresolved_tickets()',
1801 'class' => 'WPSC_DBC_Unresolved_Tickets',
1802 'type' => 'default',
1803 ),
1804 'unassigned' => array(
1805 'title' => $labels['unassigned'],
1806 'is_enable' => 1,
1807 'allowed-agent-roles' => array( 1 ),
1808 'callback' => 'wpsc_dbc_unassigned_tickets()',
1809 'class' => 'WPSC_DBC_Unassigned_Tickets',
1810 'type' => 'default',
1811 ),
1812 'closed' => array(
1813 'title' => $labels['closed'],
1814 'is_enable' => 1,
1815 'allowed-agent-roles' => array( 1, 2 ),
1816 'callback' => 'wpsc_dbc_closed_tickets()',
1817 'class' => 'WPSC_DBC_Closed_Tickets',
1818 'type' => 'default',
1819 ),
1820 'mine' => array(
1821 'title' => $labels['mine'],
1822 'is_enable' => 1,
1823 'allowed-agent-roles' => array( 1, 2 ),
1824 'callback' => 'wpsc_dbc_mine_tickets()',
1825 'class' => 'WPSC_DBC_Mine_Tickets',
1826 'type' => 'default',
1827 ),
1828 )
1829 );
1830
1831 // Dashboard widget.
1832 $labels = array(
1833 'ticket-statistics' => __( 'Ticket Statistics', 'supportcandy' ),
1834 'todays-trends' => __( 'Todays Trends', 'supportcandy' ),
1835 'agent-list' => __( 'Agent Workload', 'supportcandy' ),
1836 'recent-activities' => __( 'Recent Activities', 'supportcandy' ),
1837 'recent-tickets' => __( 'Recent Tickets', 'supportcandy' ),
1838 'category-report' => __( 'Tickets by Category', 'supportcandy' ),
1839 'unresolved-priorities' => __( 'Tickets by Priority', 'supportcandy' ),
1840 'unresolved-statuses' => __( 'Tickets by Status', 'supportcandy' ),
1841 'week-trends' => __( 'Ticket statistics by day of week', 'supportcandy' ),
1842 );
1843 foreach ( $labels as $key => $string ) {
1844 $string_translations[ 'wpsc-dashboard-widget-' . $key ] = $string;
1845 }
1846 update_option(
1847 'wpsc-dashboard-widgets',
1848 array(
1849 'ticket-statistics' => array(
1850 'title' => $labels['ticket-statistics'],
1851 'is_enable' => 1,
1852 'allowed-agent-roles' => array( 1, 2 ),
1853 'callback' => 'wpsc_dbw_ticket_statistics()',
1854 'class' => 'WPSC_DBW_Ticket_Statistics',
1855 'type' => 'default',
1856 'chart-type' => '',
1857 ),
1858 'todays-trends' => array(
1859 'title' => $labels['todays-trends'],
1860 'is_enable' => 1,
1861 'allowed-agent-roles' => array( 1, 2 ),
1862 'callback' => 'wpsc_dbw_todays_trends()',
1863 'class' => 'WPSC_DBW_Todays_Trends',
1864 'type' => 'default',
1865 'chart-type' => '',
1866 ),
1867 'agent-list' => array(
1868 'title' => $labels['agent-list'],
1869 'is_enable' => 1,
1870 'allowed-agent-roles' => array( 1 ),
1871 'callback' => 'wpsc_dbw_agent_list()',
1872 'class' => 'WPSC_DBW_Agent_List',
1873 'type' => 'default',
1874 'chart-type' => '',
1875 ),
1876 'recent-activities' => array(
1877 'title' => $labels['recent-activities'],
1878 'is_enable' => 1,
1879 'allowed-agent-roles' => array( 1, 2 ),
1880 'callback' => 'wpsc_dbw_recent_activities()',
1881 'class' => 'WPSC_DBW_Recent_Activities',
1882 'type' => 'default',
1883 'chart-type' => '',
1884 ),
1885 'recent-tickets' => array(
1886 'title' => $labels['recent-tickets'],
1887 'is_enable' => 1,
1888 'allowed-agent-roles' => array( 1, 2 ),
1889 'callback' => 'wpsc_dbw_recent_tickets()',
1890 'class' => 'WPSC_DBW_Recent_Tickets',
1891 'type' => 'default',
1892 'chart-type' => '',
1893 ),
1894 'category-report' => array(
1895 'title' => $labels['category-report'],
1896 'is_enable' => 1,
1897 'allowed-agent-roles' => array( 1, 2 ),
1898 'callback' => 'wpsc_dbw_category_reports()',
1899 'class' => 'WPSC_DBW_Category_Reports',
1900 'type' => 'default',
1901 'chart-type' => 'doughnut',
1902 ),
1903 'unresolved-priorities' => array(
1904 'title' => $labels['unresolved-priorities'],
1905 'is_enable' => 1,
1906 'allowed-agent-roles' => array( 1, 2 ),
1907 'callback' => 'wpsc_dbw_unresolved_priorities()',
1908 'class' => 'WPSC_DBW_Unresolved_Priorities',
1909 'type' => 'default',
1910 'chart-type' => 'horizontal-bar',
1911 ),
1912 'unresolved-statuses' => array(
1913 'title' => $labels['unresolved-statuses'],
1914 'is_enable' => 1,
1915 'allowed-agent-roles' => array( 1, 2 ),
1916 'callback' => 'wpsc_dbw_unresolved_statuses()',
1917 'class' => 'WPSC_DBW_Unresolved_Statuses',
1918 'type' => 'default',
1919 'chart-type' => 'vertical-bar',
1920 ),
1921 'week-trends' => array(
1922 'title' => $labels['week-trends'],
1923 'is_enable' => 1,
1924 'allowed-agent-roles' => array( 1, 2 ),
1925 'callback' => 'WPSC_dbw_week_trend_tickets()',
1926 'class' => 'WPSC_DBW_Week_Trend_Tickets',
1927 'type' => 'default',
1928 'chart-type' => 'vertical-bar',
1929 ),
1930 )
1931 );
1932
1933 // Add dashboard general settings.
1934 update_option(
1935 'wpsc-db-gs-settings',
1936 array(
1937 'default-date-range' => 'last-week',
1938 'allowed-recent-activity-logs' => array( 'report', 'reply', 'note', 'assigned_agent' ),
1939 'dash-auto-refresh' => 0,
1940 )
1941 );
1942
1943 self::attachment_security_file();
1944
1945 // Create required database indexes.
1946 self::create_indexing();
1947
1948 // update string translations.
1949 update_option( 'wpsc-string-translation', $string_translations );
1950 }
1951
1952 /**
1953 * Upgrade the version
1954 */
1955 public static function upgrade() {
1956
1957 global $wpdb;
1958
1959 $string_translations = get_option( 'wpsc-string-translation' );
1960
1961 if ( version_compare( self::$current_version, '3.0.4', '<' ) ) {
1962
1963 $advanced = get_option( 'wpsc-ms-advanced-settings' );
1964 $advanced['allow-my-profile'] = 1;
1965 $advanced['allow-agent-profile'] = 1;
1966 update_option( 'wpsc-ms-advanced-settings', $advanced );
1967 }
1968
1969 if ( version_compare( self::$current_version, '3.0.5', '<' ) ) {
1970
1971 $advanced = get_option( 'wpsc-ms-advanced-settings' );
1972 $page_settings = get_option( 'wpsc-gs-page-settings' );
1973 if ( ! isset( $advanced['allow-my-profile'] ) ) {
1974 $advanced['allow-my-profile'] = 1;
1975 $advanced['allow-agent-profile'] = 1;
1976 }
1977 $page_settings['otp-login'] = 1;
1978 update_option( 'wpsc-gs-page-settings', $page_settings );
1979 $advanced['ticket-url-auth'] = 0;
1980 update_option( 'wpsc-ms-advanced-settings', $advanced );
1981 }
1982
1983 if ( version_compare( self::$current_version, '3.0.7', '<' ) ) {
1984
1985 $page_settings = get_option( 'wpsc-gs-page-settings' );
1986 $page_settings['load-scripts'] = 'all-pages';
1987 $page_settings['load-script-pages'] = array();
1988 update_option( 'wpsc-gs-page-settings', $page_settings );
1989 }
1990
1991 if ( version_compare( self::$current_version, '3.1.1', '<' ) ) {
1992
1993 $ap_general = get_option( 'wpsc-ap-general' );
1994 $ap_general['menu-link-color'] = '#fff';
1995 update_option( 'wpsc-ap-general', $ap_general );
1996 }
1997
1998 if ( version_compare( self::$current_version, '3.1.3', '<' ) ) {
1999
2000 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2001 $advanced['rest-api'] = 1;
2002 update_option( 'wpsc-ms-advanced-settings', $advanced );
2003 }
2004
2005 if ( version_compare( self::$current_version, '3.1.4', '<' ) ) {
2006
2007 // add scheduled task for ticket data upgrade.
2008 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='update_ticket_attachment_path'" ) ) {
2009 $wpdb->insert(
2010 $wpdb->prefix . 'psmsc_scheduled_tasks',
2011 array(
2012 'class' => 'WPSC_SC_Upgrade',
2013 'method' => 'update_ticket_attachment_path',
2014 'is_manual' => 1,
2015 'warning_text' => 'SupportCandy - Database attachment paths upgrade needed.',
2016 'warning_link_text' => 'Upgrade Now',
2017 'progressbar_text' => 'Updating attachment paths...',
2018 )
2019 );
2020 }
2021
2022 self::attachment_security_file();
2023 }
2024
2025 if ( version_compare( self::$current_version, '3.1.5', '<' ) ) {
2026
2027 // scheduled task for setting conditions upgrade.
2028 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='upgrade_setting_conditions'" ) ) {
2029 $wpdb->insert(
2030 $wpdb->prefix . 'psmsc_scheduled_tasks',
2031 array(
2032 'class' => 'WPSC_SC_Upgrade',
2033 'method' => 'upgrade_setting_conditions',
2034 'is_manual' => 0,
2035 )
2036 );
2037 }
2038
2039 // scheduled task for saved filter conditions upgrade.
2040 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='upgrade_saved_filter_conditions'" ) ) {
2041 $wpdb->insert(
2042 $wpdb->prefix . 'psmsc_scheduled_tasks',
2043 array(
2044 'class' => 'WPSC_SC_Upgrade',
2045 'method' => 'upgrade_saved_filter_conditions',
2046 'is_manual' => 1,
2047 'warning_text' => 'SupportCandy - Filters database upgrade needed.',
2048 'warning_link_text' => 'Upgrade Now',
2049 'progressbar_text' => 'Upgrading filters...',
2050 )
2051 );
2052 }
2053 }
2054
2055 if ( version_compare( self::$current_version, '3.1.6', '<' ) ) {
2056
2057 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='repaire_setting_conditions'" ) ) {
2058 $wpdb->insert(
2059 $wpdb->prefix . 'psmsc_scheduled_tasks',
2060 array(
2061 'class' => 'WPSC_SC_Upgrade',
2062 'method' => 'repaire_setting_conditions',
2063 'is_manual' => 0,
2064 )
2065 );
2066 }
2067
2068 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='repaire_saved_filter_conditions'" ) ) {
2069 $wpdb->insert(
2070 $wpdb->prefix . 'psmsc_scheduled_tasks',
2071 array(
2072 'class' => 'WPSC_SC_Upgrade',
2073 'method' => 'repaire_saved_filter_conditions',
2074 'is_manual' => 1,
2075 'warning_text' => 'SupportCandy - Filters database upgrade needed.',
2076 'warning_link_text' => 'Upgrade Now',
2077 'progressbar_text' => 'Upgrading filters...',
2078 )
2079 );
2080 }
2081 }
2082
2083 if ( version_compare( self::$current_version, '3.1.7', '<' ) ) {
2084
2085 $gs = get_option( 'wpsc-gs-general' );
2086 $gs['allowed-search-fields'] = array( 'id', 'customer', 'subject', 'threads' );
2087 update_option( 'wpsc-gs-general', $gs );
2088
2089 $en = get_option( 'wpsc-en-general' );
2090 $en['attachments-in-notification'] = 'actual-files';
2091 update_option( 'wpsc-en-general', $en );
2092 }
2093
2094 if ( version_compare( self::$current_version, '3.1.9', '<' ) ) {
2095
2096 // add scheduled task for attachment status upgrade.
2097 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='update_ticket_attachment_status'" ) ) {
2098 $wpdb->insert(
2099 $wpdb->prefix . 'psmsc_scheduled_tasks',
2100 array(
2101 'class' => 'WPSC_SC_Upgrade',
2102 'method' => 'update_ticket_attachment_status',
2103 'is_manual' => 1,
2104 'warning_text' => 'SupportCandy - Database attachment status upgrade needed.',
2105 'warning_link_text' => 'Upgrade Now',
2106 'progressbar_text' => 'Updating attachment status...',
2107 )
2108 );
2109 }
2110 }
2111
2112 if ( version_compare( self::$current_version, '3.2.0', '<' ) ) {
2113
2114 $roles = get_option( 'wpsc-agent-roles' );
2115 foreach ( $roles as $key => $role ) {
2116 $role['caps']['dt-unassigned'] = true;
2117 $role['caps']['dt-assigned-me'] = true;
2118 $role['caps']['dt-assigned-others'] = true;
2119
2120 $roles[ $key ] = $role;
2121 }
2122 update_option( 'wpsc-agent-roles', $roles );
2123
2124 // set customer custom fields as personal info.
2125 $wpdb->update(
2126 $wpdb->prefix . 'psmsc_custom_fields',
2127 array( 'is_personal_info' => 1 ),
2128 array( 'field' => 'customer' )
2129 );
2130 }
2131
2132 if ( version_compare( self::$current_version, '3.2.1', '<' ) ) {
2133
2134 $thankyou = get_option( 'wpsc-gs-thankyou-page-settings' );
2135 if ( $thankyou['thank-you-page-url'] ) {
2136 $action = 'url';
2137 } else {
2138 $action = 'text';
2139 }
2140
2141 update_option(
2142 'wpsc-gs-thankyou-page-settings',
2143 array(
2144 'action-agent' => $action,
2145 'action-customer' => $action,
2146 'html-agent' => $thankyou['thankyou-html'],
2147 'html-customer' => $thankyou['thankyou-html'],
2148 'page-url-agent' => $thankyou['thank-you-page-url'],
2149 'page-url-customer' => $thankyou['thank-you-page-url'],
2150 'editor-agent' => $thankyou['editor'],
2151 'editor-customer' => $thankyou['editor'],
2152 )
2153 );
2154 $string_translations['wpsc-thankyou-html-agent'] = $thankyou['thankyou-html'];
2155
2156 update_option( 'wpsc-string-translation', $string_translations );
2157
2158 // ticket tags.
2159 $widgets = get_option( 'wpsc-ticket-widget', array() );
2160 if ( ! isset( $widgets['tags'] ) ) {
2161
2162 $agent_roles = array_keys( get_option( 'wpsc-agent-roles', array() ) );
2163 $label = esc_attr( wpsc__( 'Tags', 'supportcandy' ) );
2164 $widgets['tags'] = array(
2165 'title' => $label,
2166 'is_enable' => 1,
2167 'allow-customer' => 0,
2168 'allowed-agent-roles' => $agent_roles,
2169 'callback' => 'wpsc_get_tw_ticket_tags()',
2170 'class' => 'WPSC_ITW_Ticket_Tags',
2171 );
2172 update_option( 'wpsc-ticket-widget', $widgets );
2173
2174 $string_translations['wpsc-twt-tags'] = $label;
2175
2176 }
2177
2178 $tag_exists = $wpdb->get_results( "SELECT id from {$wpdb->prefix}psmsc_custom_fields WHERE slug = 'tags'" );
2179 if ( empty( $tag_exists ) ) {
2180 $name = __( 'Tags', 'supportcandy' );
2181 $wpdb->insert(
2182 $wpdb->prefix . 'psmsc_custom_fields',
2183 array(
2184 'name' => $name,
2185 'slug' => 'tags',
2186 'field' => 'ticket',
2187 'type' => 'df_tags',
2188 'is_personal_info' => 0,
2189 'tl_width' => 100,
2190 'load_order' => 24,
2191 )
2192 );
2193 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
2194 }
2195
2196 $roles = get_option( 'wpsc-agent-roles' );
2197 foreach ( $roles as $key => $role ) {
2198 $role['caps']['tt-unassigned'] = true;
2199 $role['caps']['tt-assigned-me'] = true;
2200 $role['caps']['tt-assigned-others'] = true;
2201
2202 $roles[ $key ] = $role;
2203 }
2204 update_option( 'wpsc-agent-roles', $roles );
2205
2206 // ticket tags general setting.
2207 update_option(
2208 'wpsc-ticket-tags-general-settings',
2209 array(
2210 'color' => '#000000',
2211 'bg-color' => '#ffc300',
2212 )
2213 );
2214
2215 // Add agent collision appearance setting.
2216 update_option(
2217 'wpsc-ap-agent-collision',
2218 array(
2219 'header-bg-color' => '#e6e6e6',
2220 'header-text-color' => '#2c3e50',
2221 )
2222 );
2223
2224 // Add agent collision setting.
2225 $ms_advanced = get_option( 'wpsc-ms-advanced-settings' );
2226 $ms_advanced['agent-collision'] = 1;
2227 update_option( 'wpsc-ms-advanced-settings', $ms_advanced );
2228 }
2229
2230 if ( version_compare( self::$current_version, '3.2.2', '<' ) ) {
2231
2232 // add anonymuos customer to customer table.
2233 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_customers WHERE email='anonymous@anonymous.anonymous'" ) ) {
2234
2235 $success = $wpdb->insert(
2236 $wpdb->prefix . 'psmsc_customers',
2237 array(
2238 'name' => 'Anonymous',
2239 'email' => 'anonymous@anonymous.anonymous',
2240 )
2241 );
2242 if ( $success ) {
2243 update_option( 'wpsc-anonymous-user-id', $wpdb->insert_id );
2244 }
2245 }
2246
2247 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2248 $advanced['self-assign'] = 0;
2249 update_option( 'wpsc-ms-advanced-settings', $advanced );
2250 }
2251
2252 if ( version_compare( self::$current_version, '3.2.4', '<' ) ) {
2253
2254 // add default true to admin and agent dashboard access.
2255 $roles = get_option( 'wpsc-agent-roles' );
2256 $role_keys = array();
2257 foreach ( $roles as $key => $role ) {
2258 $role['caps']['dash-access'] = true;
2259 $roles[ $key ] = $role;
2260 $role_keys[] = $key;
2261 }
2262
2263 // Dashboard cards.
2264 $labels = array(
2265 'new-tickets' => __( 'New Tickets', 'supportcandy' ),
2266 'unresolved' => __( 'Unresolved', 'supportcandy' ),
2267 'unassigned' => __( 'Unassigned', 'supportcandy' ),
2268 'closed' => __( 'Closed', 'supportcandy' ),
2269 'mine' => __( 'Mine', 'supportcandy' ),
2270 );
2271 foreach ( $labels as $key => $string ) {
2272 $string_translations[ 'wpsc-dashboard-card-' . $key ] = $string;
2273 }
2274 update_option(
2275 'wpsc-dashboard-cards',
2276 array(
2277 'new-tickets' => array(
2278 'title' => $labels['new-tickets'],
2279 'is_enable' => 1,
2280 'allowed-agent-roles' => $role_keys,
2281 'callback' => 'wpsc_dbc_new_tickets()',
2282 'class' => 'WPSC_DBC_New_Tickets',
2283 'type' => 'default',
2284 ),
2285 'unresolved' => array(
2286 'title' => $labels['unresolved'],
2287 'is_enable' => 1,
2288 'allowed-agent-roles' => $role_keys,
2289 'callback' => 'wpsc_dbc_unresolved_tickets()',
2290 'class' => 'WPSC_DBC_Unresolved_Tickets',
2291 'type' => 'default',
2292 ),
2293 'unassigned' => array(
2294 'title' => $labels['unassigned'],
2295 'is_enable' => 1,
2296 'allowed-agent-roles' => array( 1 ),
2297 'callback' => 'wpsc_dbc_unassigned_tickets()',
2298 'class' => 'WPSC_DBC_Unassigned_Tickets',
2299 'type' => 'default',
2300 ),
2301 'closed' => array(
2302 'title' => $labels['closed'],
2303 'is_enable' => 1,
2304 'allowed-agent-roles' => $role_keys,
2305 'callback' => 'wpsc_dbc_closed_tickets()',
2306 'class' => 'WPSC_DBC_Closed_Tickets',
2307 'type' => 'default',
2308 ),
2309 'mine' => array(
2310 'title' => $labels['mine'],
2311 'is_enable' => 1,
2312 'allowed-agent-roles' => $role_keys,
2313 'callback' => 'wpsc_dbc_mine_tickets()',
2314 'class' => 'WPSC_DBC_Mine_Tickets',
2315 'type' => 'default',
2316 ),
2317 )
2318 );
2319
2320 // Dashboard widget.
2321 $labels = array(
2322 'ticket-statistics' => __( 'Ticket Statistics', 'supportcandy' ),
2323 'todays-trends' => __( 'Todays Trends', 'supportcandy' ),
2324 'agent-list' => __( 'Agent Workload', 'supportcandy' ),
2325 'recent-activities' => __( 'Recent Activities', 'supportcandy' ),
2326 'recent-tickets' => __( 'Recent Tickets', 'supportcandy' ),
2327 'category-report' => __( 'Unresolved tickets by Category', 'supportcandy' ),
2328 'unresolved-priorities' => __( 'Unresolved tickets by Priority', 'supportcandy' ),
2329 'unresolved-statuses' => __( 'Unresolved tickets by Status', 'supportcandy' ),
2330 );
2331 foreach ( $labels as $key => $string ) {
2332 $string_translations[ 'wpsc-dashboard-widget-' . $key ] = $string;
2333 }
2334 update_option(
2335 'wpsc-dashboard-widgets',
2336 array(
2337 'ticket-statistics' => array(
2338 'title' => $labels['ticket-statistics'],
2339 'is_enable' => 1,
2340 'allowed-agent-roles' => $role_keys,
2341 'callback' => 'wpsc_dbw_ticket_statistics()',
2342 'class' => 'WPSC_DBW_Ticket_Statistics',
2343 'type' => 'default',
2344 'chart-type' => '',
2345 ),
2346 'todays-trends' => array(
2347 'title' => $labels['todays-trends'],
2348 'is_enable' => 1,
2349 'allowed-agent-roles' => $role_keys,
2350 'callback' => 'wpsc_dbw_todays_trends()',
2351 'class' => 'WPSC_DBW_Todays_Trends',
2352 'type' => 'default',
2353 'chart-type' => '',
2354 ),
2355 'agent-list' => array(
2356 'title' => $labels['agent-list'],
2357 'is_enable' => 1,
2358 'allowed-agent-roles' => array( 1 ),
2359 'callback' => 'wpsc_dbw_agent_list()',
2360 'class' => 'WPSC_DBW_Agent_List',
2361 'type' => 'default',
2362 'chart-type' => '',
2363 ),
2364 'recent-activities' => array(
2365 'title' => $labels['recent-activities'],
2366 'is_enable' => 1,
2367 'allowed-agent-roles' => $role_keys,
2368 'callback' => 'wpsc_dbw_recent_activities()',
2369 'class' => 'WPSC_DBW_Recent_Activities',
2370 'type' => 'default',
2371 'chart-type' => '',
2372 ),
2373 'recent-tickets' => array(
2374 'title' => $labels['recent-tickets'],
2375 'is_enable' => 1,
2376 'allowed-agent-roles' => $role_keys,
2377 'callback' => 'wpsc_dbw_recent_tickets()',
2378 'class' => 'WPSC_DBW_Recent_Tickets',
2379 'type' => 'default',
2380 'chart-type' => '',
2381 ),
2382 'category-report' => array(
2383 'title' => $labels['category-report'],
2384 'is_enable' => 1,
2385 'allowed-agent-roles' => $role_keys,
2386 'callback' => 'wpsc_dbw_category_reports()',
2387 'class' => 'WPSC_DBW_Category_Reports',
2388 'type' => 'default',
2389 'chart-type' => 'doughnut',
2390 ),
2391 'unresolved-priorities' => array(
2392 'title' => $labels['unresolved-priorities'],
2393 'is_enable' => 1,
2394 'allowed-agent-roles' => $role_keys,
2395 'callback' => 'wpsc_dbw_unresolved_priorities()',
2396 'class' => 'WPSC_DBW_Unresolved_Priorities',
2397 'type' => 'default',
2398 'chart-type' => 'horizontal-bar',
2399 ),
2400 'unresolved-statuses' => array(
2401 'title' => $labels['unresolved-statuses'],
2402 'is_enable' => 1,
2403 'allowed-agent-roles' => $role_keys,
2404 'callback' => 'wpsc_dbw_unresolved_statuses()',
2405 'class' => 'WPSC_DBW_Unresolved_Statuses',
2406 'type' => 'default',
2407 'chart-type' => 'vertical-bar',
2408 ),
2409 )
2410 );
2411
2412 // dashboard appreance general setting.
2413 update_option(
2414 'wpsc-ap-dashboard',
2415 array(
2416 'card-body-bg-color' => '#f9f9f9',
2417 'card-body-svg-color' => '#777',
2418 'card-body-text-color' => '#2c3e50',
2419 'widget-body-bg-color' => '#f9f9f9',
2420 'widget-body-svg-color' => '#777',
2421 'widget-body-text-color' => '#2c3e50',
2422 )
2423 );
2424
2425 // Add dashboard general settings.
2426 update_option(
2427 'wpsc-db-gs-settings',
2428 array(
2429 'default-date-range' => 'last-week',
2430 'allowed-recent-activity-logs' => array( 'report', 'reply', 'note', 'assigned_agent' ),
2431 )
2432 );
2433 update_option( 'wpsc-agent-roles', $roles );
2434 }
2435
2436 if ( version_compare( self::$current_version, '3.2.5', '<' ) ) {
2437
2438 $file_attachments = get_option( 'wpsc-gs-file-attachments' );
2439
2440 require_once WPSC_ABSPATH . 'includes/class-wpsc-mime-types.php';
2441
2442 $exts = $file_attachments['allowed-file-extensions'] ? explode( ',', $file_attachments['allowed-file-extensions'] ) : array();
2443 $exts = array_map( 'trim', $exts );
2444 $mimes = array();
2445 foreach ( $exts as $key => $value ) {
2446 $mime = WPSC_MIME_TYPES::get_mime_type( $value );
2447 if ( $mime ) {
2448 $mimes[ $value ] = $mime;
2449 }
2450 }
2451 $file_attachments['allowed-file-ext-mimes'] = $mimes;
2452 $file_attachments['mime-exceptions'] = array();
2453
2454 update_option( 'wpsc-gs-file-attachments', $file_attachments );
2455 }
2456
2457 if ( version_compare( self::$current_version, '3.2.6', '<' ) ) {
2458
2459 // Add dashboard general settings.
2460 $db_gs = get_option( 'wpsc-db-gs-settings', array() );
2461 $db_gs['dash-auto-refresh'] = 0;
2462 update_option( 'wpsc-db-gs-settings', $db_gs );
2463
2464 $wpdb->update(
2465 $wpdb->prefix . 'psmsc_custom_fields',
2466 array( 'number_type' => 'integer' ),
2467 array( 'type' => 'cf_number' )
2468 );
2469 }
2470
2471 if ( version_compare( self::$current_version, '3.2.7', '<' ) ) {
2472
2473 $ms_advanced = get_option( 'wpsc-ms-advanced-settings' );
2474 $ms_advanced['reply-close'] = 1;
2475 update_option( 'wpsc-ms-advanced-settings', $ms_advanced );
2476
2477 $appearance = get_option( 'wpsc-ap-individual-ticket' );
2478 $appearance['reply-close-bg-color'] = '#fff';
2479 $appearance['reply-close-text-color'] = '#707070';
2480 update_option( 'wpsc-ap-individual-ticket', $appearance );
2481
2482 $lrs_exists = $wpdb->get_results( "SELECT id from {$wpdb->prefix}psmsc_custom_fields WHERE slug = 'last_reply_source'" );
2483 if ( empty( $lrs_exists ) ) {
2484
2485 $name = __( 'Last Reply Source', 'supportcandy' );
2486 $wpdb->insert(
2487 $wpdb->prefix . 'psmsc_custom_fields',
2488 array(
2489 'name' => $name,
2490 'slug' => 'last_reply_source',
2491 'field' => 'ticket',
2492 'type' => 'df_last_reply_source',
2493 'is_personal_info' => 0,
2494 'tl_width' => 100,
2495 'load_order' => 26,
2496 )
2497 );
2498 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $name;
2499 }
2500
2501 // GDPR option in user registration.
2502 $gdpr = get_option( 'wpsc-gdpr-settings', array() );
2503 $gdpr_text = '<p>I understand my personal information like Name, Email address, IP address, etc. will be stored in database.</p>';
2504 $gdpr['allow-gdpr-reg-user'] = 0;
2505 $gdpr['gdpr-text-reg-user'] = $gdpr_text;
2506 $gdpr['editor-reg-user'] = 'html';
2507 update_option( 'wpsc-gdpr-settings', $gdpr );
2508 $string_translations['wpsc-gdpr-reg-user'] = $gdpr_text;
2509
2510 // T&C option in user registration.
2511 $tandc = get_option( 'wpsc-term-and-conditions', array() );
2512 $tandc_text = '<p>I agree to the terms and conditions</p>';
2513 $tandc['allow-term-and-conditions-reg-user'] = 0;
2514 $tandc['tandc-text-reg-user'] = $tandc_text;
2515 $tandc['editor-reg-user'] = 'html';
2516 update_option( 'wpsc-term-and-conditions', $tandc );
2517 $string_translations['wpsc-term-and-conditions-reg-user'] = $tandc_text;
2518 }
2519
2520 if ( version_compare( self::$current_version, '3.2.8', '<' ) ) {
2521
2522 $widgets = get_option( 'wpsc-dashboard-widgets', array() );
2523 if ( ! isset( $widgets['week-trends'] ) ) {
2524 $label = __( 'Ticket statistics by day of week', 'supportcandy' );
2525 $string_translations['wpsc-dashboard-widget-week-trends'] = $label;
2526 $widgets['week-trends'] = array(
2527 'title' => $label,
2528 'is_enable' => 1,
2529 'allowed-agent-roles' => array( 1 ),
2530 'callback' => 'wpsc_dbw_week_trend_tickets()',
2531 'class' => 'WPSC_DBW_Week_Trend_Tickets',
2532 'type' => 'default',
2533 'chart-type' => 'vertical-bar',
2534 );
2535 }
2536 update_option( 'wpsc-dashboard-widgets', $widgets );
2537 }
2538
2539 if ( version_compare( self::$current_version, '3.2.9', '<' ) ) {
2540
2541 // scheduled task for updating image editor attachment path in thread body.
2542 if ( ! $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_scheduled_tasks WHERE class='WPSC_SC_Upgrade' AND method='upgrade_ie_attachment_path'" ) ) {
2543 $wpdb->insert(
2544 $wpdb->prefix . 'psmsc_scheduled_tasks',
2545 array(
2546 'class' => 'WPSC_SC_Upgrade',
2547 'method' => 'upgrade_ie_attachment_path',
2548 'is_manual' => 1,
2549 'warning_text' => 'SupportCandy - attachment security upgrade needed.',
2550 'warning_link_text' => 'Upgrade Now',
2551 'progressbar_text' => 'Updating attachment ...',
2552 )
2553 );
2554 }
2555
2556 // unschedule old upgrade task.
2557 $upgrade = get_option( 'wpsc_upgrade_cleanup', array() );
2558 if ( empty( $upgrade ) ) {
2559
2560 $timestamp = wp_next_scheduled( 'wpsc_v1_upgrade_cleanup' );
2561 if ( $timestamp ) {
2562 wp_unschedule_event( $timestamp, 'wpsc_v1_upgrade_cleanup' );
2563 }
2564 $timestamp = wp_next_scheduled( 'wpsc_v2_upgrade_cleanup' );
2565 if ( $timestamp ) {
2566 wp_unschedule_event( $timestamp, 'wpsc_v2_upgrade_cleanup' );
2567 }
2568 }
2569 }
2570
2571 if ( version_compare( self::$current_version, '3.3.7', '<' ) ) {
2572 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2573 $advanced['note-confirmation'] = 0;
2574 update_option( 'wpsc-ms-advanced-settings', $advanced );
2575 }
2576
2577 if ( version_compare( self::$current_version, '3.3.8', '<' ) ) {
2578
2579 $gdpr = get_option( 'wpsc-gdpr-settings', array() );
2580 $gdpr['ip-address-collection'] = 1;
2581 update_option( 'wpsc-gdpr-settings', $gdpr );
2582
2583 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_email_otp MODIFY otp VARCHAR(10) NOT NULL" );
2584 }
2585
2586 if ( version_compare( self::$current_version, '3.4.0', '<' ) ) {
2587 // Create required database indexes.
2588 self::create_indexing();
2589 }
2590
2591 if ( version_compare( self::$current_version, '3.4.2', '<' ) ) {
2592
2593 // add advanced settings for archive tickets.
2594 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2595 $advanced['auto-archive-tickets-time'] = $advanced['auto-delete-tickets-time'] ?? 0;
2596 $advanced['auto-archive-tickets-unit'] = $advanced['auto-delete-tickets-unit'] ?? 'days';
2597 $advanced['permanent-archive-tickets-time'] = $advanced['permanent-delete-tickets-time'] ?? 0;
2598 $advanced['permanent-archive-tickets-unit'] = $advanced['permanent-delete-tickets-unit'] ?? 'days';
2599 unset(
2600 $advanced['auto-delete-tickets-time'],
2601 $advanced['auto-delete-tickets-unit'],
2602 );
2603 update_option( 'wpsc-ms-advanced-settings', $advanced );
2604
2605 // Remove 'dtt-access' and set new capabilities while preserving role keys.
2606 $roles = get_option( 'wpsc-agent-roles', array() );
2607 if ( ! empty( $roles ) && is_array( $roles ) ) {
2608 foreach ( $roles as $key => &$role ) {
2609 // Ensure caps array exists.
2610 if ( empty( $role['caps'] ) || ! is_array( $role['caps'] ) ) {
2611 $role['caps'] = array();
2612 }
2613 // Bydefault only Admin (1) has access to archive tickets.
2614 $is_enabled = ( $key == 1 );
2615 // Set new capabilities.
2616 $role['caps']['at-unassigned'] = $is_enabled;
2617 $role['caps']['at-assigned-me'] = $is_enabled;
2618 $role['caps']['at-assigned-others'] = $is_enabled;
2619 $role['caps']['at-access'] = $is_enabled;
2620 $role['caps']['at-delete-access'] = $is_enabled;
2621 }
2622 update_option( 'wpsc-agent-roles', $roles );
2623 }
2624 }
2625
2626 if ( version_compare( self::$current_version, '3.4.4', '<' ) ) {
2627
2628 $atl_filters = get_option( 'wpsc-atl-default-filters', array() );
2629 $atl_filters['deleted'] = array(
2630 'label' => __( 'Deleted', 'supportcandy' ),
2631 'is_enable' => 1,
2632 );
2633 update_option( 'wpsc-atl-default-filters', $atl_filters );
2634
2635 // Add capability for delete ticket filter access.
2636 $roles = get_option( 'wpsc-agent-roles', array() );
2637 foreach ( $roles as $key => &$role ) {
2638 $is_enabled = ( $key == 1 );
2639 $roles[ $key ]['caps']['dtt-access'] = $is_enabled;
2640 }
2641 update_option( 'wpsc-agent-roles', $roles );
2642
2643 // permanently delete tickets.
2644 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2645 $advanced['permanent-delete-tickets-time'] = $advanced['permanent-archive-tickets-time'] ?? 0;
2646 $advanced['permanent-delete-tickets-unit'] = $advanced['permanent-archive-tickets-unit'] ?? 'days';
2647 update_option( 'wpsc-ms-advanced-settings', $advanced );
2648
2649 // clear old scheduled task.
2650 wp_clear_scheduled_hook( 'wpsc_permanently_delete_archive_tickets' );
2651 wp_clear_scheduled_hook( 'wpsc_permenently_delete_tickets' );
2652 wp_clear_scheduled_hook( 'wpsc_auto_archive_closed_tickets' );
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