PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.4.7
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.4.7
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 / includes / admin / agent-settings / class-wpsc-support-agents.php

class-wpsc-support-agents.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.4.7, at includes/admin/agent-settings/class-wpsc-support-agents.php

232 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_Support_Agents' ) ) :
7
8 final class WPSC_Support_Agents {
9
10 /**
11 * Set if current screen is agents page
12 *
13 * @var boolean
14 */
15 public static $is_current_page;
16
17 /**
18 * Sections for this view
19 *
20 * @var array
21 */
22 private static $sections = array();
23
24 /**
25 * Current section to load
26 *
27 * @var string
28 */
29 private static $current_section;
30
31 /**
32 * Initialize this class
33 *
34 * @return void
35 */
36 public static function init() {
37
38 // Load sections for this screen.
39 add_action( 'admin_init', array( __CLASS__, 'load_sections' ) );
40
41 // Add current section to admin localization data.
42 add_filter( 'wpsc_admin_localizations', array( __CLASS__, 'localizations' ) );
43
44 // Humbargar modal.
45 add_action( 'admin_footer', array( __CLASS__, 'humbargar_menu' ) );
46
47 // Register ready function.
48 add_action( 'wpsc_js_ready', array( __CLASS__, 'register_js_ready_function' ) );
49 }
50
51 /**
52 * Load section (nav elements) for this screen
53 *
54 * @return void
55 */
56 public static function load_sections() {
57
58 self::$is_current_page = isset( $_REQUEST['page'] ) && $_REQUEST['page'] === 'wpsc-support-agents' ? true : false; // phpcs:ignore
59
60 if ( ! self::$is_current_page ) {
61 return;
62 }
63
64 self::$sections = apply_filters(
65 'wpsc_support_agents_sections',
66 array(
67 'agents' => array(
68 'slug' => 'agents',
69 'icon' => 'headset',
70 'label' => esc_attr__( 'Agents', 'supportcandy' ),
71 'callback' => 'wpsc_get_agent_list',
72 ),
73 'agent-roles' => array(
74 'slug' => 'agent_roles',
75 'icon' => 'shield',
76 'label' => esc_attr__( 'Agent Roles', 'supportcandy' ),
77 'callback' => 'wpsc_get_agent_roles',
78 ),
79 'working-hrs' => array(
80 'slug' => 'working_hrs',
81 'icon' => 'clock',
82 'label' => esc_attr__( 'Working Hours', 'supportcandy' ),
83 'callback' => 'wpsc_get_agents_working_hrs',
84 ),
85 'leaves' => array(
86 'slug' => 'leaves',
87 'icon' => 'calendar-times',
88 'label' => esc_attr__( 'Leaves', 'supportcandy' ),
89 'callback' => 'wpsc_get_agent_leaves',
90 ),
91 )
92 );
93
94 self::$current_section = isset( $_REQUEST['section'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['section'] ) ) : 'agents'; // phpcs:ignore
95 }
96
97 /**
98 * Add localizations to local JS
99 *
100 * @param array $localizations - localizations.
101 * @return array
102 */
103 public static function localizations( $localizations ) {
104
105 if ( ! self::$is_current_page ) {
106 return $localizations;
107 }
108
109 // Humbargar Titles.
110 $localizations['humbargar_titles'] = self::get_humbargar_titles();
111
112 // Current section.
113 $localizations['current_section'] = self::$current_section;
114
115 return $localizations;
116 }
117
118 /**
119 * UI foundation for this screen
120 *
121 * @return void
122 */
123 public static function layout() {
124 ?>
125 <div class="wrap">
126 <hr class="wp-header-end">
127 <div id="wpsc-container" style="display:none;">
128 <div class="wpsc-header wpsc-setting-header-xs wpsc-visible-xs">
129 <div class="wpsc-humbargar-title">
130 <?php WPSC_Icons::get( self::$sections[ self::$current_section ]['icon'] ); ?>
131 <label><?php echo esc_attr( self::$sections[ self::$current_section ]['label'] ); ?></label>
132 </div>
133 <div class="wpsc-humbargar" onclick="wpsc_toggle_humbargar();">
134 <?php WPSC_Icons::get( 'bars' ); ?>
135 </div>
136 </div>
137 <div class="wpsc-settings-page">
138 <div class="wpsc-setting-section-container wpsc-hidden-xs">
139 <h2><?php esc_attr_e( 'Support Agents', 'supportcandy' ); ?></h2>
140 <?php
141 foreach ( self::$sections as $key => $section ) {
142 $active = self::$current_section === $key ? 'active' : '';
143 ?>
144 <div
145 class="wpsc-setting-nav <?php echo esc_attr( $key ) . ' ' . esc_attr( $active ); ?>"
146 onclick="<?php echo esc_attr( $section['callback'] ) . '();'; ?>">
147 <?php WPSC_Icons::get( $section['icon'] ); ?>
148 <label><?php echo esc_attr( $section['label'] ); ?></label>
149 </div>
150 <?php
151 }
152 ?>
153 </div>
154 <div class="wpsc-setting-body"></div>
155 </div>
156 </div>
157 </div>
158 <?php
159 }
160
161 /**
162 * Print humbargar menu in footer
163 *
164 * @return void
165 */
166 public static function humbargar_menu() {
167
168 if ( ! self::$is_current_page ) {
169 return;
170 }
171 ?>
172
173 <div class="wpsc-humbargar-overlay" onclick="wpsc_toggle_humbargar();" style="display:none"></div>
174 <div class="wpsc-humbargar-menu" style="display:none">
175 <div class="box-inner">
176 <div class="wpsc-humbargar-close" onclick="wpsc_toggle_humbargar();">
177 <?php WPSC_Icons::get( 'times' ); ?>
178 </div>
179 <?php
180 foreach ( self::$sections as $key => $section ) :
181
182 $active = self::$current_section === $key ? 'active' : '';
183 ?>
184 <div
185 class="wpsc-humbargar-menu-item <?php echo esc_attr( $key ) . ' ' . esc_attr( $active ); ?>"
186 onclick="<?php echo esc_attr( $section['callback'] ) . '(true);'; ?>">
187 <?php WPSC_Icons::get( $section['icon'] ); ?>
188 <label><?php echo esc_attr( $section['label'] ); ?></label>
189 </div>
190 <?php
191 endforeach;
192 ?>
193 </div>
194 </div>
195 <?php
196 }
197
198 /**
199 * Humbargar mobile titles to be used in localizations
200 *
201 * @return array
202 */
203 private static function get_humbargar_titles() {
204
205 $titles = array();
206 foreach ( self::$sections as $section ) {
207
208 ob_start();
209 WPSC_Icons::get( $section['icon'] );
210 echo '<label>' . esc_attr( $section['label'] ) . '</label>';
211 $titles[ $section['slug'] ] = ob_get_clean();
212 }
213 return $titles;
214 }
215
216 /**
217 * Register JS functions to call on document ready
218 *
219 * @return void
220 */
221 public static function register_js_ready_function() {
222
223 if ( ! self::$is_current_page ) {
224 return;
225 }
226 echo esc_attr( self::$sections[ self::$current_section ]['callback'] ) . '();' . PHP_EOL;
227 }
228 }
229 endif;
230
231 WPSC_Support_Agents::init();
232