PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.1
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / pages / page-mainwp-client.php

page-mainwp-client.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.1, at pages/page-mainwp-client.php

2,038 lines 108.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Clients Page
4 *
5 * This page is used to Manage Clients.
6 *
7 * @package MainWP/Dashboard
8 */
9
10 namespace MainWP\Dashboard;
11
12 /**
13 * Class MainWP_client
14 *
15 * @uses page-mainwp-bulk-add::MainWP_Bulk_Add()
16 */
17 class MainWP_Client { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
18
19 /**
20 * Get Class Name
21 *
22 * @return string __CLASS__
23 */
24 public static function get_class_name() {
25 return __CLASS__;
26 }
27
28 /**
29 * Current page.
30 *
31 * @static
32 * @var string $page Current page.
33 */
34 public static $page;
35
36 /**
37 * Public static varable to hold Subpages information.
38 *
39 * @var array $subPages
40 */
41 public static $subPages;
42
43
44 /**
45 * Magage Sites table
46 *
47 * @var $itemsTable Magage Sites table.
48 */
49 public static $itemsTable;
50
51 /**
52 * Method init()
53 *
54 * Initiate hooks for the clients page.
55 */
56 public static function init() {
57 /**
58 * This hook allows you to render the client page header via the 'mainwp_pageheader_client' action.
59 *
60 * This hook is normally used in the same context of 'mainwp_pageheader_client'
61 *
62 * @see \MainWP_client::render_header
63 */
64 add_action( 'mainwp_pageheader_client', array( static::get_class_name(), 'render_header' ) );
65
66 /**
67 * This hook allows you to render the client page footer via the 'mainwp_pagefooter_client' action.
68 *
69 * This hook is normally used in the same context of 'mainwp_pagefooter_client'
70 *
71 * @see \MainWP_client::render_footer
72 */
73 add_action( 'mainwp_pagefooter_client', array( static::get_class_name(), 'render_footer' ) );
74
75 add_action( 'mainwp_help_sidebar_content', array( static::get_class_name(), 'mainwp_help_content' ) );
76 MainWP_Post_Handler::instance()->add_action( 'mainwp_add_edit_client_upload_client_icon', array( static::class, 'ajax_upload_client_icon' ) );
77 MainWP_Post_Handler::instance()->add_action( 'mainwp_add_edit_contact_upload_contact_icon', array( static::class, 'ajax_upload_contact_icon' ) );
78 }
79
80 /**
81 * Method init_menu()
82 *
83 * Initiate menu.
84 *
85 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
86 */
87 public static function init_menu() {
88 static::$page = add_submenu_page(
89 'mainwp_tab',
90 esc_html__( 'Clients', 'mainwp' ),
91 '<span id="mainwp-clients">' . esc_html__( 'Clients', 'mainwp' ) . '</span>',
92 'read',
93 'ManageClients',
94 array(
95 static::get_class_name(),
96 'render_manage_clients',
97 )
98 );
99
100 add_submenu_page(
101 'mainwp_tab',
102 esc_html__( 'Clients', 'mainwp' ),
103 '<div class="mainwp-hidden">' . esc_html__( 'Add Client', 'mainwp' ) . '</div>',
104 'read',
105 'ClientAddNew',
106 array(
107 static::get_class_name(),
108 'render_add_client',
109 )
110 );
111
112 add_submenu_page(
113 'mainwp_tab',
114 esc_html__( 'Clients', 'mainwp' ),
115 '<div class="mainwp-hidden">' . esc_html__( 'Client Fields', 'mainwp' ) . '</div>',
116 'read',
117 'ClientAddField',
118 array(
119 static::get_class_name(),
120 'render_client_fields',
121 )
122 );
123
124 /**
125 * This hook allows you to add extra sub pages to the client page via the 'mainwp-getsubpages-client' filter.
126 *
127 * @link http://codex.mainwp.com/#mainwp-getsubpages-client
128 */
129 $sub_pages = array();
130 static::$subPages = apply_filters( 'mainwp_getsubpages_client', $sub_pages );
131
132 if ( isset( static::$subPages ) && is_array( static::$subPages ) ) {
133 foreach ( static::$subPages as $subPage ) {
134 if ( MainWP_Menu::is_disable_menu_item( 3, 'ManageClients' . $subPage['slug'] ) ) {
135 continue;
136 }
137 add_submenu_page( 'mainwp_tab', $subPage['title'], '<div class="mainwp-hidden">' . esc_html( $subPage['title'] ) . '</div>', 'read', 'ManageClients' . $subPage['slug'], $subPage['callback'] );
138 }
139 }
140
141 static::init_left_menu( static::$subPages );
142
143 add_action( 'load-' . static::$page, array( static::get_class_name(), 'on_load_page' ) );
144 }
145
146 /**
147 * Method on_load_page()
148 *
149 * Run on page load.
150 */
151 public static function on_load_page() {
152
153 if ( isset( $_GET['client_id'] ) && ! empty( $_GET['client_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
154 MainWP_Client_Overview::instance()->on_load_page( static::$page );
155 return;
156 }
157
158 add_filter( 'mainwp_header_actions_right', array( static::get_class_name(), 'screen_options' ), 10, 2 );
159
160 static::$itemsTable = new MainWP_Client_List_Table();
161 }
162
163 /**
164 * Method screen_options()
165 *
166 * Create Page Settings button.
167 *
168 * @param mixed $input Page Settings button HTML.
169 *
170 * @return mixed Screen sptions button.
171 */
172 public static function screen_options( $input ) {
173 return $input .
174 '<a class="ui button basic icon" onclick="mainwp_manage_clients_screen_options(); return false;" data-inverted="" data-position="bottom right" href="#" target="_blank" data-tooltip="' . esc_html__( 'Page Settings', 'mainwp' ) . '" aria-label="' . esc_html__( 'Page Settings', 'mainwp' ) . '">
175 <i class="cog icon"></i>
176 </a>';
177 }
178
179 /**
180 * Initiates sub pages menu.
181 *
182 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
183 */
184 public static function init_subpages_menu() {
185 ?>
186 <div id="menu-mainwp-Clients" class="mainwp-submenu-wrapper">
187 <div class="wp-submenu sub-open" style="">
188 <div class="mainwp_boxout">
189 <div class="mainwp_boxoutin"></div>
190 <?php if ( mainwp_current_user_have_right( 'dashboard', 'manage_clients' ) ) { ?>
191 <a href="<?php echo esc_url( admin_url( 'admin.php?page=ManageClients' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Clients', 'mainwp' ); ?></a>
192 <?php } ?>
193 <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'ClientAddNew' ) ) { ?>
194 <a href="<?php echo esc_url( admin_url( 'admin.php?page=ClientAddNew' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Add Client', 'mainwp' ); ?></a>
195 <?php } ?>
196 <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'ClientAddField' ) ) { ?>
197 <a href="<?php echo esc_url( admin_url( 'admin.php?page=ClientAddField' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Client Properties', 'mainwp' ); ?></a>
198 <?php } ?>
199 <?php
200 if ( isset( static::$subPages ) && is_array( static::$subPages ) ) {
201 foreach ( static::$subPages as $subPage ) {
202 if ( MainWP_Menu::is_disable_menu_item( 3, 'ManageClients' . $subPage['slug'] ) ) {
203 continue;
204 }
205 ?>
206 <a href="<?php echo esc_url( admin_url( 'admin.php?page=ManageClients' . $subPage['slug'] ) ); ?>" class="mainwp-submenu"><?php echo esc_html( $subPage['title'] ); ?></a>
207 <?php
208 }
209 }
210 ?>
211 </div>
212 </div>
213 </div>
214 <?php
215 }
216
217 /**
218 * Initiates Clients menu.
219 *
220 * @param array $subPages Sub pages array.
221 *
222 * @uses \MainWP\Dashboard\MainWP_Menu::add_left_menu()
223 * @uses \MainWP\Dashboard\MainWP_Menu::init_subpages_left_menu()
224 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
225 */
226 public static function init_left_menu( $subPages = array() ) {
227 MainWP_Menu::add_left_menu(
228 array(
229 'title' => esc_html__( 'Clients', 'mainwp' ),
230 'parent_key' => 'mainwp_tab',
231 'slug' => 'ManageClients',
232 'href' => 'admin.php?page=ManageClients',
233 'icon' => '<i class="users icon"></i>',
234 'desc' => 'Manage clients on your child sites',
235 ),
236 0
237 );
238
239 $init_sub_subleftmenu = array(
240 array(
241 'title' => esc_html__( 'Clients', 'mainwp' ),
242 'parent_key' => 'ManageClients',
243 'href' => 'admin.php?page=ManageClients',
244 'slug' => 'ManageClients',
245 'right' => 'manage_clients',
246 'leftsub_order_level2' => 1,
247 ),
248 array(
249 'title' => esc_html__( 'Add Client', 'mainwp' ),
250 'parent_key' => 'ManageClients',
251 'href' => 'admin.php?page=ClientAddNew',
252 'slug' => 'ClientAddNew',
253 'right' => '',
254 'leftsub_order_level2' => 2,
255 ),
256 array(
257 'title' => esc_html__( 'Client Fields', 'mainwp' ),
258 'parent_key' => 'ManageClients',
259 'href' => 'admin.php?page=ClientAddField',
260 'slug' => 'ClientAddField',
261 'right' => '',
262 'leftsub_order_level2' => 3,
263 ),
264 );
265
266 MainWP_Menu::init_subpages_left_menu( $subPages, $init_sub_subleftmenu, 'ManageClients', 'ManageClients' );
267
268 foreach ( $init_sub_subleftmenu as $item ) {
269 if ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) {
270 continue;
271 }
272 MainWP_Menu::add_left_menu( $item, 2 );
273 }
274 }
275
276 /**
277 * Method ajax_upload_client_icon()
278 */
279 public static function ajax_upload_client_icon() { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR - complexity.
280 MainWP_Post_Handler::instance()->secure_request( 'mainwp_add_edit_client_upload_client_icon' );
281
282 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
283 $iconfile_slug = isset( $_POST['iconFileSlug'] ) ? sanitize_text_field( wp_unslash( $_POST['iconFileSlug'] ) ) : '';
284 $delete = isset( $_POST['delete'] ) ? intval( $_POST['delete'] ) : 0;
285 $client_id = isset( $_POST['iconItemId'] ) ? intval( $_POST['iconItemId'] ) : 0;
286
287 if ( $delete ) {
288 if ( $client_id ) {
289 $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $client_id );
290 if ( $client && ! empty( $client->image ) ) {
291 $update = array(
292 'image' => '',
293 'client_id' => $client_id,
294 );
295 MainWP_DB_Client::instance()->update_client( $update );
296 MainWP_Utility::instance()->delete_uploaded_icon_file( 'client-images', $client->image );
297 }
298 } elseif ( ! empty( $iconfile_slug ) ) {
299 MainWP_Utility::instance()->delete_uploaded_icon_file( 'client-images', $iconfile_slug );
300 }
301 wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
302 }
303
304 $output = isset( $_FILES['mainwp_upload_icon_uploader'] ) ? MainWP_System_Utility::handle_upload_image( 'client-images', $_FILES['mainwp_upload_icon_uploader'] ) : null;
305 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
306
307 $uploaded_icon = 'NOTCHANGE';
308 if ( is_array( $output ) && isset( $output['filename'] ) && ! empty( $output['filename'] ) ) {
309 $uploaded_icon = $output['filename'];
310 }
311
312 if ( 'NOTCHANGE' !== $uploaded_icon ) {
313 $dirs = MainWP_System_Utility::get_mainwp_dir( 'client-images', true );
314 $icon_url = $dirs[1] . $uploaded_icon;
315 wp_die(
316 wp_json_encode(
317 array(
318 'result' => 'success',
319 'iconfile' => esc_html( $uploaded_icon ),
320 'iconsrc' => esc_html( $icon_url ),
321 'iconimg' => '<img class="ui mini circular image" src="' . esc_attr( $icon_url ) . '" style="width:32px;height:auto;display:inline-block;" alt="Client custom icon">',
322 )
323 )
324 );
325 } else {
326 wp_die( wp_json_encode( array( 'result' => 'failed' ) ) );
327 }
328 }
329
330
331 /**
332 * Method ajax_upload_contact_icon()
333 */
334 public static function ajax_upload_contact_icon() { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR - complexity.
335 MainWP_Post_Handler::instance()->secure_request( 'mainwp_add_edit_contact_upload_contact_icon' );
336 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
337 $iconfile_slug = isset( $_POST['iconFileSlug'] ) ? sanitize_text_field( wp_unslash( $_POST['iconFileSlug'] ) ) : '';
338 $delete = isset( $_POST['delete'] ) ? intval( $_POST['delete'] ) : 0;
339 $contact_id = isset( $_POST['iconItemId'] ) ? intval( $_POST['iconItemId'] ) : 0;
340
341 if ( $delete ) {
342 if ( $contact_id ) {
343 $contact_data = MainWP_DB_Client::instance()->get_wp_client_contact_by( 'contact_id', $contact_id );
344 if ( $contact_data && ! empty( $contact_data->contact_image ) ) {
345 $update = array(
346 'contact_image' => '',
347 'contact_id' => $contact_id,
348 );
349 MainWP_DB_Client::instance()->update_client_contact( $update );
350 MainWP_Utility::instance()->delete_uploaded_icon_file( 'client-images', $contact_data->contact_image );
351 }
352 } elseif ( ! empty( $iconfile_slug ) ) {
353 MainWP_Utility::instance()->delete_uploaded_icon_file( 'client-images', $iconfile_slug );
354 }
355 wp_die( wp_json_encode( array( 'result' => 'success' ) ) );
356 }
357
358 $output = isset( $_FILES['mainwp_upload_icon_uploader'] ) ? MainWP_System_Utility::handle_upload_image( 'client-images', $_FILES['mainwp_upload_icon_uploader'] ) : null;
359 // phpcs:enable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
360
361 $uploaded_icon = 'NOTCHANGE';
362 if ( is_array( $output ) && isset( $output['filename'] ) && ! empty( $output['filename'] ) ) {
363 $uploaded_icon = $output['filename'];
364 }
365
366 if ( 'NOTCHANGE' !== $uploaded_icon ) {
367 $dirs = MainWP_System_Utility::get_mainwp_dir( 'client-images', true );
368 $icon_url = $dirs[1] . $uploaded_icon;
369 wp_die(
370 wp_json_encode(
371 array(
372 'result' => 'success',
373 'iconfile' => esc_html( $uploaded_icon ),
374 'iconsrc' => esc_html( $icon_url ),
375 'iconimg' => '<img class="ui mini circular image" src="' . esc_attr( $icon_url ) . '" style="width:32px;height:auto;display:inline-block;" alt="Client custom icon">',
376 )
377 )
378 );
379 } else {
380 wp_die( wp_json_encode( array( 'result' => 'failed' ) ) );
381 }
382 }
383
384
385 /**
386 * Method render_header()
387 *
388 * Render Clients page header.
389 *
390 * @param string $shownPage The page slug shown at this moment.
391 *
392 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
393 * @uses \MainWP\Dashboard\MainWP_UI::render_top_header()
394 * @uses \MainWP\Dashboard\MainWP_UI::render_page_navigation()
395 */
396 public static function render_header( $shownPage = '' ) { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
397 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
398 $client_id = isset( $_GET['client_id'] ) ? intval( $_GET['client_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
399
400 $params = array(
401 'title' => esc_html__( 'Clients', 'mainwp' ),
402 'which' => 'overview' === $shownPage ? 'page_clients_overview' : '',
403 );
404
405 $client = false;
406 if ( $client_id ) {
407 $client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $client_id );
408 if ( $client ) {
409 $arr_client = MainWP_Utility::map_fields( $client, array( 'image', 'selected_icon_info' ), false ); // array map.
410 $client_pic = MainWP_Client_Handler::get_client_contact_image( $arr_client );
411 $params['title'] = $client_pic . '<div class="content">' . $client->name . '<div class="sub header"><a href="mailto:' . $client->client_email . '" target="_blank" style="font-weight:normal!important;">' . $client->client_email . '</a> </div></div>';
412 }
413 }
414
415 MainWP_UI::render_top_header( $params );
416
417 $renderItems = array();
418
419 if ( mainwp_current_user_have_right( 'dashboard', 'manage_clients' ) ) {
420 $renderItems[] = array(
421 'title' => esc_html__( 'Clients', 'mainwp' ),
422 'href' => 'admin.php?page=ManageClients',
423 'active' => ( '' === $shownPage ) ? true : false,
424 );
425 }
426
427 if ( $client_id ) {
428 $renderItems[] = array(
429 'title' => $client ? $client->name : esc_html__( 'Overview', 'mainwp' ),
430 'href' => 'admin.php?page=ManageClients&client_id=' . $client_id,
431 'active' => ( 'overview' === $shownPage ),
432 );
433 $renderItems[] = array(
434 'title' => $client ? esc_html__( 'Edit', 'mainwp' ) . ' ' . $client->name : esc_html__( 'Edit Client', 'mainwp' ),
435 'href' => 'admin.php?page=ClientAddNew&client_id=' . $client_id,
436 'active' => ( 'Edit' === $shownPage ) ? true : false,
437 );
438 }
439
440 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'ClientAddNew' ) ) {
441 $renderItems[] = array(
442 'title' => esc_html__( 'Add Client', 'mainwp' ),
443 'href' => 'admin.php?page=ClientAddNew',
444 'active' => ( 'Add' === $shownPage ) ? true : false,
445 );
446 }
447
448 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'ClientAddField' ) ) {
449 $renderItems[] = array(
450 'title' => esc_html__( 'Client Fields', 'mainwp' ),
451 'href' => 'admin.php?page=ClientAddField',
452 'active' => ( 'AddField' === $shownPage ) ? true : false,
453 );
454 }
455
456 if ( isset( static::$subPages ) && is_array( static::$subPages ) ) {
457 foreach ( static::$subPages as $subPage ) {
458 if ( MainWP_Menu::is_disable_menu_item( 3, 'ManageClients' . $subPage['slug'] ) ) {
459 continue;
460 }
461
462 if ( ! empty( $subPage['individual_settings'] ) && empty( $client_id ) ) {
463 continue;
464 }
465
466 $client_param = $client_id ? '&client_id=' . $client_id : '';
467 $item = array();
468 $item['title'] = $subPage['title'];
469 $item['href'] = 'admin.php?page=ManageClients' . $subPage['slug'] . $client_param;
470 $item['active'] = ( $subPage['slug'] === $shownPage ) ? true : false;
471 $renderItems[] = $item;
472 }
473 }
474 // phpcs:enable
475 MainWP_UI::render_page_navigation( $renderItems );
476 }
477
478 /**
479 * Method render_footer()
480 *
481 * Render Clients page footer. Closes the page container.
482 */
483 public static function render_footer() {
484 echo '</div>';
485 }
486
487 /**
488 * Renders manage clients dashboard.
489 *
490 * @return void
491 */
492 public static function render_manage_clients() {
493
494 if ( isset( $_GET['client_id'] ) && ! empty( $_GET['client_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
495 MainWP_Client_Overview::instance()->on_show_page( intval( $_GET['client_id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
496 return;
497 }
498
499 if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_clients' ) ) {
500 mainwp_do_not_have_permissions( esc_html__( 'manage clients', 'mainwp' ) );
501 return;
502 }
503
504 static::$itemsTable->prepare_items();
505
506 static::render_header( '' );
507 static::render_second_top_header();
508
509 ?>
510 <div id="mainwp-manage-sites-content" class="ui segment">
511 <div id="mainwp-message-zone" style="display:none;" class="ui message"></div>
512 <form method="post" class="mainwp-table-container">
513 <?php
514 wp_nonce_field( 'mainwp-admin-nonce' );
515 static::$itemsTable->display();
516 static::$itemsTable->clear_items();
517 ?>
518 </form>
519 </div>
520 <?php
521 static::render_footer( '' );
522 static::render_screen_options();
523 }
524
525 /**
526 * Method render_second_top_header()
527 *
528 * Render second top header.
529 *
530 * @return void Render second top header html.
531 */
532 public static function render_second_top_header() {
533 ?>
534 <div class="mainwp-sub-header ui mini form">
535 <?php
536 do_action( 'mainwp_manageclients_tabletop' );
537 ?>
538 </div>
539 <?php
540 }
541
542
543 /**
544 * Renders Edit Clients Modal window.
545 */
546 public static function render_update_clients() {
547
548 ?>
549 <div id="mainwp-edit-clients-modal" class="ui modal">
550 <i class="close icon"></i>
551 <div class="header"><?php esc_html_e( 'Edit client', 'mainwp' ); ?></div>
552 <div class="ui message"><?php esc_html_e( 'Empty fields will not be passed to child sites.', 'mainwp' ); ?></div>
553 <form id="update_client_profile">
554 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
555 <div class="ui segment">
556 <div class="ui form">
557 <h3><?php esc_html_e( 'Name', 'mainwp' ); ?></h3>
558 <div class="ui grid field">
559 <label class="six wide column middle aligned"><?php esc_html_e( 'First Name', 'mainwp' ); ?></label>
560 <div class="ui six wide column">
561 <div class="ui left labeled input">
562 <input type="text" name="first_name" id="first_name" value="" class="regular-text" />
563 </div>
564 </div>
565 </div>
566
567 <div class="ui grid field">
568 <label class="six wide column middle aligned"><?php esc_html_e( 'Last Name', 'mainwp' ); ?></label>
569 <div class="ui six wide column">
570 <div class="ui left labeled input">
571 <input type="text" name="last_name" id="last_name" value="" class="regular-text" />
572 </div>
573 </div>
574 </div>
575
576 <div class="ui grid field">
577 <label class="six wide column middle aligned"><?php esc_html_e( 'Nickname', 'mainwp' ); ?></label>
578 <div class="ui six wide column">
579 <div class="ui left labeled input">
580 <input type="text" name="nickname" id="nickname" value="" class="regular-text" />
581 </div>
582 </div>
583 </div>
584
585 <div class="ui grid field">
586 <label class="six wide column middle aligned"><?php esc_html_e( 'Display name publicly as', 'mainwp' ); ?></label>
587 <div class="ui six wide column">
588 <div class="ui left labeled input">
589 <select name="display_name" id="display_name"></select>
590 </div>
591 </div>
592 </div>
593
594 <h3><?php esc_html_e( 'Contact Info', 'mainwp' ); ?></h3>
595
596 <div class="ui grid field">
597 <label class="six wide column middle aligned"><?php esc_html_e( 'Email', 'mainwp' ); ?></label>
598 <div class="ui six wide column">
599 <div class="ui left labeled input">
600 <input type="email" name="email" id="email" value="" class="regular-text ltr" />
601 </div>
602 </div>
603 </div>
604
605 <div class="ui grid field">
606 <label class="six wide column middle aligned"><?php esc_html_e( 'Website', 'mainwp' ); ?></label>
607 <div class="ui six wide column">
608 <div class="ui left labeled input">
609 <input type="url" name="url" id="url" value="" class="regular-text code" />
610 </div>
611 </div>
612 </div>
613
614 <h3><?php esc_html_e( 'About the client', 'mainwp' ); ?></h3>
615
616 <div class="ui grid field">
617 <label class="six wide column middle aligned"><?php esc_html_e( 'Biographical Info', 'mainwp' ); ?></label>
618 <div class="ui six wide column">
619 <div class="ui left labeled input">
620 <textarea name="description" id="description" rows="5" cols="30"></textarea>
621 <p class="description"><?php esc_html_e( 'Share a little biographical information to fill out your profile. This may be shown publicly.', 'mainwp' ); ?></p>
622 </div>
623 </div>
624 </div>
625
626 <h3><?php esc_html_e( 'Account Management', 'mainwp' ); ?></h3>
627
628 <div class="ui grid field">
629 <label class="six wide column middle aligned"><?php esc_html_e( 'Password', 'mainwp' ); ?></label>
630 <div class="ui six wide column">
631 <div class="ui left labeled action input">
632 <input class="hidden" value=" "/>
633 <input type="text" id="password" name="password" autocomplete="off" value="">
634 </div>
635 </div>
636 </div>
637 </div>
638 </div>
639 </form>
640 <div class="actions">
641 <div id="mainwp_update_password_error" style="display: none"></div>
642 <span id="mainwp_clients_updating"><i class="ui active inline loader tiny"></i></span>
643 <input type="button" class="ui green button" id="mainwp_btn_update_client" value="<?php esc_attr_e( 'Update', 'mainwp' ); ?>">
644 </div>
645 </div>
646 <?php
647 }
648
649
650 /**
651 * Method render_screen_options()
652 *
653 * Render Page Settings Modal.
654 */
655 public static function render_screen_options() { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
656
657 $columns = static::$itemsTable->get_columns();
658
659 if ( isset( $columns['cb'] ) ) {
660 unset( $columns['cb'] );
661 }
662
663 $sites_per_page = get_option( 'mainwp_default_manage_clients_per_page', 25 );
664
665 if ( isset( $columns['site_actions'] ) && empty( $columns['site_actions'] ) ) {
666 $columns['site_actions'] = esc_html__( 'Actions', 'mainwp' );
667 }
668
669 $show_cols = get_user_option( 'mainwp_settings_show_manage_clients_columns' );
670
671 if ( false === $show_cols ) { // to backwards.
672 $show_cols = array();
673 foreach ( $columns as $name => $title ) {
674 $show_cols[ $name ] = 1;
675 }
676 $user = wp_get_current_user();
677 if ( $user ) {
678 update_user_option( $user->ID, 'mainwp_settings_show_manage_clients_columns', $show_cols, true );
679 }
680 }
681
682 if ( ! is_array( $show_cols ) ) {
683 $show_cols = array();
684 }
685
686 ?>
687 <div class="ui modal" id="mainwp-manage-sites-screen-options-modal">
688 <i class="close icon"></i>
689 <div class="header"><?php esc_html_e( 'Page Settings', 'mainwp' ); ?></div>
690 <div class="scrolling content ui form">
691 <form method="POST" action="" id="manage-sites-screen-options-form" name="manage_sites_screen_options_form">
692 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
693 <input type="hidden" name="wp_nonce" value="<?php echo esc_attr( wp_create_nonce( 'ManageClientsScrOptions' ) ); ?>" />
694 <div class="ui grid field">
695 <label class="six wide column"><?php esc_html_e( 'Default items per page value', 'mainwp' ); ?></label>
696 <div class="ten wide column">
697 <div class="ui info message">
698 <ul>
699 <li><?php esc_html_e( 'Based on your Dashboard server default large numbers can severely impact page load times.', 'mainwp' ); ?></li>
700 <li><?php esc_html_e( 'Do not add commas for thousands (ex 1000).', 'mainwp' ); ?></li>
701 <li><?php esc_html_e( '-1 to default to All of your Child Sites.', 'mainwp' ); ?></li>
702 </ul>
703 </div>
704 <input type="text" name="mainwp_default_manage_clients_per_page" id="mainwp_default_manage_clients_per_page" saved-value="<?php echo intval( $sites_per_page ); ?>" value="<?php echo intval( $sites_per_page ); ?>"/>
705 </div>
706 </div>
707 <div class="ui grid field">
708 <label class="six wide column"><?php esc_html_e( 'Show columns', 'mainwp' ); ?></label>
709 <div class="ten wide column">
710 <ul class="mainwp_hide_wpmenu_checkboxes">
711 <?php
712 foreach ( $columns as $name => $title ) {
713 if ( empty( $title ) ) {
714 continue;
715 }
716 ?>
717 <li>
718 <div class="ui checkbox <?php echo ( 'site_preview' === $name ) ? 'site_preview not-auto-init' : ''; ?>">
719 <input type="checkbox"
720 <?php
721 $show_col = ! isset( $show_cols[ $name ] ) || ( 1 === (int) $show_cols[ $name ] );
722 if ( $show_col ) {
723 echo 'checked="checked"';
724 }
725 ?>
726 id="mainwp_show_column_<?php echo esc_attr( $name ); ?>" name="mainwp_show_column_<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $name ); ?>">
727 <label for="mainwp_show_column_<?php echo esc_attr( $name ); ?>" ><?php echo $title; // phpcs:ignore WordPress.Security.EscapeOutput ?></label>
728 <input type="hidden" value="<?php echo esc_attr( $name ); ?>" name="show_columns_name[]" />
729 </div>
730 </li>
731 <?php
732 }
733 ?>
734 </ul>
735 </div>
736 </div>
737 </div>
738 <div class="actions">
739 <div class="ui two columns grid">
740 <div class="left aligned column">
741 <span data-tooltip="<?php esc_attr_e( 'Resets the page to its original layout and reinstates relocated columns.', 'mainwp' ); ?>" data-inverted="" data-position="top center"><input type="button" class="ui button" name="reset" id="reset-manageclients-settings" value="<?php esc_attr_e( 'Reset Page', 'mainwp' ); ?>" /></span>
742 </div>
743 <div class="ui right aligned column">
744 <input type="submit" class="ui green button" name="btnSubmit" id="submit-manageclients-settings" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>" />
745 </div>
746 </div>
747 </div>
748 <input type="hidden" name="reset_manageclients_columns_order" value="0">
749 </form>
750 </div>
751 <div class="ui small modal" id="mainwp-monitoring-sites-site-preview-screen-options-modal">
752 <div class="header"><?php esc_html_e( 'Page Settings', 'mainwp' ); ?></div>
753 <div class="scrolling content ui form">
754 <span><?php esc_html_e( 'Would you like to turn on home screen previews? This function queries WordPress.com servers to capture a screenshot of your site the same way comments shows you preview of URLs.', 'mainwp' ); ?>
755 </div>
756 <div class="actions">
757 <div class="ui ok button"><?php esc_html_e( 'Yes', 'mainwp' ); ?></div>
758 <div class="ui cancel button"><?php esc_html_e( 'No', 'mainwp' ); ?></div>
759 </div>
760 </div>
761 <script type="text/javascript">
762 jQuery( document ).ready( function () {
763 jQuery( '.ui.checkbox.not-auto-init.site_preview' ).checkbox( {
764 onChecked : function() {
765 let $chk = jQuery( this );
766 jQuery( '#mainwp-monitoring-sites-site-preview-screen-options-modal' ).modal( {
767 allowMultiple: true, // multiple modals.
768 width: 100,
769 onDeny: function () {
770 $chk.prop('checked', false);
771 }
772 } ).modal( 'show' );
773 }
774 } );
775 jQuery('#reset-manageclients-settings').on( 'click', function () {
776 mainwp_confirm(__( 'Are you sure.' ), function(){
777 jQuery('input[name=mainwp_default_manage_clients_per_page]').val(25);
778 jQuery('.mainwp_hide_wpmenu_checkboxes input[id^="mainwp_show_column_"]').prop( 'checked', false );
779 //default columns.
780 let cols = ['name','email','phone','websites'];
781 jQuery.each( cols, function ( index, value ) {
782 jQuery('.mainwp_hide_wpmenu_checkboxes input[id="mainwp_show_column_' + value + '"]').prop( 'checked', true );
783 } );
784 jQuery('input[name=reset_manageclients_columns_order]').attr('value',1);
785 jQuery('#submit-manageclients-settings').click();
786 }, false, false, true );
787 return false;
788 });
789 } );
790 </script>
791 <?php
792 }
793
794 /**
795 * Renders the Add New Client form.
796 */
797 public static function render_add_client() {
798 $show = 'Add';
799 $client_id = 0;
800 $selected_sites = array();
801 $edit_client = false;
802
803 if ( isset( $_GET['client_id'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.NonceVerification.Recommended
804 $show = 'Edit';
805 $client_id = intval( $_GET['client_id'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.NonceVerification.Recommended
806 $edit_client = $client_id ? MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $client_id ) : false;
807 $client_sites = MainWP_DB_Client::instance()->get_websites_by_client_ids( $client_id );
808
809 if ( $client_sites ) {
810 foreach ( $client_sites as $site ) {
811 $selected_sites[] = $site->id;
812 }
813 }
814 }
815
816 static::render_header( $show );
817 ?>
818 <div class="ui alt segment" id="mainwp-add-clients">
819 <form action="" method="post" enctype="multipart/form-data" name="createclient_form" id="createclient_form" class="add:clients: validate">
820 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
821 <div class="mainwp-main-content">
822 <div class="ui segment">
823 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-add-client-info-message' ) ) : ?>
824 <div class="ui info message">
825 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-add-client-info-message"></i>
826 <?php printf( esc_html__( 'use the provided form to create a new client on your child site(). for additional help, please check this %1$shelp documentation %2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/create-a-new-client/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); // NOSONAR - noopener - open safe. ?>
827 </div>
828 <?php endif; ?>
829 <div class="ui message" id="mainwp-message-zone-client" style="display:none;"></div>
830 <div id="mainwp-add-new-client-form" >
831 <?php
832 static::render_add_client_content( $edit_client );
833 ?>
834 </div>
835 </div>
836 </div>
837 <div class="mainwp-side-content mainwp-no-padding">
838
839 <?php if ( $client_id ) : ?>
840 <div class="mainwp-select-sites ui accordion mainwp-sidebar-accordion">
841 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Tokens Info', 'mainwp' ); ?></div>
842 <div class="content active">
843 <div class="ui info message">
844 <?php esc_html_e( 'Client info is available as tokens for reports and boilerplate content. Toggle the switch to see available tokens.', 'mainwp' ); ?>
845 </div>
846 <div class="ui toggle checkbox">
847 <input type="checkbox" name="mainwp_toggle_tokens_info" id="mainwp_toggle_tokens_info">
848 <label><?php esc_html_e( 'Toggle available tokens', 'mainwp' ); ?></label>
849 </div>
850 </div>
851 </div>
852 <script type="text/javascript">
853 jQuery( document ).ready( function() {
854 jQuery( '#mainwp_toggle_tokens_info' ).on( 'change', function() {
855 jQuery( '.hidden.token.column' ).toggle();
856 } );
857 } );
858 </script>
859 <div class="ui fitted divider"></div>
860 <?php endif; ?>
861
862 <div class="mainwp-select-sites ui accordion mainwp-sidebar-accordion">
863 <div class="title active"><i class="dropdown icon"></i>
864 <?php esc_html_e( 'Select Sites', 'mainwp' ); ?></div>
865 <div class="content active">
866 <?php
867 $sel_params = array(
868 'selected_sites' => $selected_sites,
869 'show_group' => false,
870 'add_edit_client_id' => $client_id,
871 'enable_offline_sites' => $client_id ? true : false,
872 );
873
874 MainWP_UI_Select_Sites::select_sites_box( $sel_params );
875 ?>
876 </div>
877 </div>
878 <div class="ui fitted divider"></div>
879 <div class="mainwp-search-submit">
880 <input type="button" name="createclient" current-page="add-new" id="bulk_add_createclient" class="ui big green fluid button" value="<?php echo $client_id ? esc_attr__( 'Update Client', 'mainwp' ) : esc_attr__( 'Add Client', 'mainwp' ); ?> "/>
881 </div>
882 </div>
883 <div style="clear:both"></div>
884 </form>
885
886
887 </div>
888 <?php
889 static::render_footer( $show );
890 static::render_add_field_modal( $client_id );
891 MainWP_UI::render_modal_upload_icon();
892 }
893
894
895 /**
896 * Renders the Add New Client Fields form.
897 */
898 public static function render_client_fields() {
899
900 static::render_header( 'AddField' );
901 ?>
902 <div class="ui segment" id="mainwp-add-client-fields">
903 <?php
904 $fields = MainWP_DB_Client::instance()->get_client_fields();
905 ?>
906 <div class="ui info message" <?php echo ! MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-clients-manage-fields' ) ? 'style="display: none"' : ''; ?>>
907 <?php esc_html_e( 'Create and manage custom Client fields.', 'mainwp' ); ?>
908 <i class="ui close icon mainwp-notice-dismiss" notice-id="mainwp-clients-manage-fields"></i>
909 </div>
910 <div class="ui message" id="mainwp-message-zone-client" style="display:none;"></div>
911 <table id="mainwp-clients-custom-fields-table" class="ui selectable compact table" style="width:100%">
912 <thead>
913 <tr>
914 <th scope="col" ><?php esc_html_e( 'Field Name', 'mainwp' ); ?></th>
915 <th scope="col" ><?php esc_html_e( 'Field Description', 'mainwp' ); ?></th>
916 <th scope="col" class="no-sort collapsing"><?php esc_html_e( '', 'mainwp' ); ?></th>
917 </tr>
918 </thead>
919 <tbody>
920 <?php if ( is_array( $fields ) && ! empty( $fields ) ) : ?>
921 <?php foreach ( $fields as $field ) : ?>
922 <?php
923 if ( ! $field ) {
924 continue;
925 }
926 ?>
927 <tr class="mainwp-field none-selected-color" field-id="<?php echo intval( $field->field_id ); ?>">
928 <td class="field-name">[<?php echo esc_html( stripslashes( $field->field_name ) ); ?>]</td>
929 <td class="field-description"><?php echo esc_html( stripslashes( $field->field_desc ) ); ?></td>
930 <td>
931 <div class="ui right pointing dropdown icon mini basic green button">
932 <i class="ellipsis horizontal icon"></i>
933 <div class="menu">
934 <a class="item" id="mainwp-clients-edit-custom-field" href="#"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a>
935 <a class="item" id="mainwp-clients-delete-general-field" href="#"><?php esc_html_e( 'Delete', 'mainwp' ); ?></a>
936 </div>
937 </div>
938 </td>
939 </tr>
940 <?php endforeach; ?>
941 <?php endif; ?>
942 </tbody>
943 <tfoot>
944 <tr>
945 <th scope="col" ><a class="ui mini green button" href="javascript:void(0);" id="mainwp-clients-new-custom-field-button"><?php esc_html_e( 'New Field', 'mainwp' ); ?></a></th>
946 <th scope="col" ><?php esc_html_e( '', 'mainwp' ); ?></th>
947 <th scope="col" ><?php esc_html_e( '', 'mainwp' ); ?></th>
948 </tr>
949 </tfoot>
950 </table>
951
952 <script type="text/javascript">
953 // Init datatables
954 jQuery( '#mainwp-clients-custom-fields-table' ).DataTable( {
955 "stateSave": true,
956 "stateDuration": 0,
957 "lengthMenu": [ [10, 25, 50, 100, -1], [10, 25, 50, 100, "All"] ],
958 "columnDefs": [ { "orderable": false, "targets": "no-sort" } ],
959 "order": [ [ 0, "asc" ] ],
960 "language": { "emptyTable": "No fields found." },
961 "drawCallback" : function( settings ) {
962 jQuery( '#mainwp-clients-custom-fields-table .ui.dropdown').dropdown();
963 },
964 } );
965 </script>
966 </div>
967
968 <?php
969 static::render_add_field_modal();
970 static::render_footer( 'AddField' );
971 }
972
973 /**
974 * Method render_add_field_modal()
975 *
976 * Render add custom field modal.
977 *
978 * @param int $client_id The client id.
979 */
980 public static function render_add_field_modal( $client_id = 0 ) {
981 ?>
982 <div class="ui modal" id="mainwp-clients-custom-field-modal">
983 <i class="close icon"></i>
984 <div class="header"><?php esc_html_e( 'Custom Field', 'mainwp' ); ?></div>
985 <div class="content ui mini form">
986 <div class="ui yellow message" style="display:none"></div>
987 <div class="field">
988 <label><?php esc_html_e( 'Field Name', 'mainwp' ); ?></label>
989 <input type="text" value="" class="field-name" name="field-name" placeholder="<?php esc_attr_e( 'Enter field name (without of square brackets)', 'mainwp' ); ?>">
990 </div>
991 <div class="field">
992 <label><?php esc_html_e( 'Field Description', 'mainwp' ); ?></label>
993 <input type="text" value="" class="field-description" name="field-description" placeholder="<?php esc_attr_e( 'Enter field description', 'mainwp' ); ?>">
994 </div>
995 </div>
996 <div class="actions">
997 <input type="button" class="ui green button" client-id="<?php echo intval( $client_id ); ?>" id="mainwp-clients-save-new-custom-field" value="<?php esc_attr_e( 'Save Field', 'mainwp' ); ?>">
998 </div>
999 <input type="hidden" value="0" name="field-id">
1000 </div>
1001 <?php
1002 }
1003
1004 /**
1005 * Method add_client()
1006 *
1007 * Bulk client addition $_POST Handler.
1008 */
1009 public static function add_client() { // phpcs:ignore -- NOSONAR -Current complexity is required to achieve desired results. Pull request solutions appreciated.
1010
1011 $selected_sites = ( isset( $_POST['selected_sites'] ) && is_array( $_POST['selected_sites'] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['selected_sites'] ) ) : array(); //phpcs:ignore WordPress.Security.NonceVerification.Missing
1012 $client_fields = isset( $_POST['client_fields'] ) ? wp_unslash( $_POST['client_fields'] ) : array(); //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1013
1014 if ( ! is_array( $client_fields ) ) {
1015 $client_fields = array();
1016 }
1017
1018 if ( ! isset( $client_fields['default_field']['client.name'] ) || empty( $client_fields['default_field']['client.name'] ) ) {
1019 echo wp_json_encode( array( 'error' => esc_html__( 'Client name are empty. Please try again.', 'mainwp' ) ) );
1020 return;
1021 }
1022
1023 $add_new = true;
1024
1025 $default_client_fields = MainWP_Client_Handler::get_default_client_fields();
1026 $client_to_add = array();
1027 foreach ( $default_client_fields as $field_name => $item ) {
1028 if ( ! empty( $item['db_field'] ) && isset( $client_fields['default_field'][ $field_name ] ) ) {
1029 $client_to_add[ $item['db_field'] ] = sanitize_text_field( wp_unslash( $client_fields['default_field'][ $field_name ] ) );
1030 }
1031 }
1032
1033 $client_to_add['primary_contact_id'] = isset( $client_fields['default_field']['primary_contact_id'] ) ? intval( $client_fields['default_field']['primary_contact_id'] ) : 0;
1034
1035 $client_id = isset( $client_fields['client_id'] ) ? intval( $client_fields['client_id'] ) : 0;
1036
1037 $new_suspended = isset( $client_to_add['suspended'] ) ? (int) $client_to_add['suspended'] : 0;
1038 $old_suspended = $new_suspended;
1039
1040 if ( $client_id ) {
1041 $current_client = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $client_id );
1042 $old_suspended = $current_client->suspended;
1043
1044 $client_to_add['client_id'] = $client_id; // update client.
1045 if ( isset( $client_to_add['created'] ) && ! empty( $client_to_add['created'] ) ) {
1046 $client_to_add['created'] = strtotime( $client_to_add['created'] );
1047 }
1048 $add_new = false;
1049 } else {
1050 $client_to_add['created'] = time();
1051 }
1052
1053 try {
1054 $inserted = MainWP_DB_Client::instance()->update_client( $client_to_add, true );
1055 } catch ( \Exception $e ) {
1056 echo wp_json_encode( array( 'error' => $e->getMessage() ) );
1057 return;
1058 }
1059
1060 if ( $client_id ) {
1061 MainWP_DB_Client::instance()->update_selected_sites_for_client( $client_id, $selected_sites );
1062 } elseif ( is_object( $inserted ) ) {
1063 MainWP_DB_Client::instance()->update_selected_sites_for_client( $inserted->client_id, $selected_sites );
1064 $client_id = $inserted->client_id;
1065 }
1066
1067 if ( is_object( $inserted ) ) {
1068 /**
1069 * Add client
1070 *
1071 * Fires after add a client.
1072 *
1073 * @param object $inserted client data.
1074 * @param bool $add_new true add new, false updated.
1075 *
1076 * @since 4.5.1.1
1077 */
1078 do_action( 'mainwp_client_updated', $inserted, $add_new );
1079
1080 if ( ! $add_new && $new_suspended != $old_suspended ) { //phpcs:ignore -- to valid.
1081 /**
1082 * Fires immediately after update client suspend/unsuspend.
1083 *
1084 * @since 4.5.1.1
1085 *
1086 * @param object $client client data.
1087 * @param bool $new_suspended true|false.
1088 */
1089 do_action( 'mainwp_client_suspend', $inserted, $new_suspended );
1090 }
1091 }
1092
1093 if ( $client_id && isset( $client_fields['custom_fields'] ) && is_array( $client_fields['custom_fields'] ) ) {
1094 foreach ( $client_fields['custom_fields'] as $field_val ) {
1095 $field_id = array_key_first( $field_val );
1096 // update custom field value for client.
1097 if ( $field_id ) {
1098 $val = $field_val[ $field_id ];
1099 MainWP_DB_Client::instance()->update_client_field_value( $field_id, $val, $client_id );
1100 }
1101 }
1102 }
1103
1104 $client_image = '';
1105 if ( isset( $_POST['mainwp_add_edit_client_uploaded_icon_hidden'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1106 $client_image = sanitize_text_field( wp_unslash( $_POST['mainwp_add_edit_client_uploaded_icon_hidden'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
1107 }
1108
1109 // compatible with quick setup.
1110 if ( isset( $_FILES['mainwp_client_image_uploader'] ) && isset( $_FILES['mainwp_client_image_uploader']['error']['client_field'] ) && UPLOAD_ERR_OK === $_FILES['mainwp_client_image_uploader']['error']['client_field'] ) { // phpcs:ignore WordPress.Security.NonceVerification
1111 $output = MainWP_System_Utility::handle_upload_image( 'client-images', $_FILES['mainwp_client_image_uploader'], 'client_field' ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1112 if ( is_array( $output ) && isset( $output['filename'] ) && ! empty( $output['filename'] ) ) {
1113 $client_image = $output['filename'];
1114 }
1115 }
1116
1117 $client_data = MainWP_DB_Client::instance()->get_wp_client_by( 'client_id', $client_id );
1118 if ( $client_data && $client_data->image !== $client_image && $client_id ) {
1119 $old_file = $client_data->image;
1120 if ( $old_file !== $client_image && ! empty( $old_file ) ) {
1121 MainWP_Utility::instance()->delete_uploaded_icon_file( 'client-images', $old_file );
1122 }
1123 $update = array(
1124 'client_id' => $client_id,
1125 'image' => $client_image,
1126 );
1127 MainWP_DB_Client::instance()->update_client( $update );
1128 }
1129
1130 if ( $client_id && isset( $client_fields['default_field']['selected_icon'] ) ) {
1131 $cust_icon = sanitize_text_field( wp_unslash( $client_fields['default_field']['selected_icon'] ) );
1132 $cust_color = sanitize_hex_color( wp_unslash( $client_fields['default_field']['selected_color'] ) );
1133 $update = array(
1134 'client_id' => $client_id,
1135 'selected_icon_info' => 'selected:' . $cust_icon . ';color:' . $cust_color,
1136 );
1137 MainWP_DB_Client::instance()->update_client( $update );
1138 }
1139
1140 $is_first_contact = true;
1141 $auto_assign_contact_id = 0;
1142
1143 if ( $client_id && isset( $client_fields['contacts_field'] ) ) {
1144
1145 foreach ( $client_fields['contacts_field']['client.contact.name'] as $indx => $contact_name ) {
1146 $contact_to_add = array();
1147 if ( empty( $contact_name ) ) {
1148 continue;
1149 }
1150 $contact_to_add['contact_name'] = $contact_name;
1151
1152 $contact_email = $client_fields['contacts_field']['contact.email'][ $indx ];
1153 if ( empty( $contact_email ) ) {
1154 continue;
1155 }
1156
1157 $contact_id = isset( $client_fields['contacts_field']['contact_id'][ $indx ] ) ? intval( $client_fields['contacts_field']['contact_id'][ $indx ] ) : 0;
1158
1159 if ( empty( $contact_id ) ) {
1160 continue;
1161 }
1162
1163 $contact_to_add['contact_email'] = $contact_email;
1164
1165 $contact_to_add['contact_phone'] = $client_fields['contacts_field']['contact.phone'][ $indx ];
1166 $contact_to_add['contact_role'] = $client_fields['contacts_field']['contact.role'][ $indx ];
1167 $contact_to_add['facebook'] = $client_fields['contacts_field']['contact.facebook'][ $indx ];
1168 $contact_to_add['twitter'] = $client_fields['contacts_field']['contact.twitter'][ $indx ];
1169 $contact_to_add['instagram'] = $client_fields['contacts_field']['contact.instagram'][ $indx ];
1170 $contact_to_add['linkedin'] = $client_fields['contacts_field']['contact.linkedin'][ $indx ];
1171
1172 $cust_icon = sanitize_text_field( wp_unslash( $client_fields['contacts_field']['selected_icon'][ $indx ] ) );
1173 $cust_color = sanitize_hex_color( wp_unslash( $client_fields['contacts_field']['selected_color'][ $indx ] ) );
1174
1175 $contact_to_add['contact_icon_info'] = 'selected:' . $cust_icon . ';color:' . $cust_color;
1176
1177 $contact_to_add['contact_client_id'] = $client_id;
1178 $contact_to_add['contact_id'] = $contact_id;
1179
1180 $updated = MainWP_DB_Client::instance()->update_client_contact( $contact_to_add );
1181
1182 $is_first_contact = false;
1183
1184 if ( $updated ) {
1185 $contact_data = MainWP_DB_Client::instance()->get_wp_client_contact_by( 'contact_id', $contact_id );
1186 $contact_image = '';
1187 if ( isset( $_POST['mainwp_add_edit_contact_uploaded_icon_hidden']['contacts_field'][ $indx ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1188 $contact_image = sanitize_text_field( wp_unslash( $_POST['mainwp_add_edit_contact_uploaded_icon_hidden']['contacts_field'][ $indx ] ) ); // phpcs:ignore WordPress.Security.NonceVerification
1189 }
1190 if ( $contact_data && $contact_data->contact_image !== $contact_image && $contact_id ) {
1191 $old_file = $contact_data->contact_image;
1192 if ( $old_file !== $contact_image && ! empty( $old_file ) ) {
1193 MainWP_Utility::instance()->delete_uploaded_icon_file( 'client-images', $old_file );
1194 }
1195 $update = array(
1196 'contact_id' => $contact_id,
1197 'contact_image' => $contact_image,
1198 );
1199 MainWP_DB_Client::instance()->update_client_contact( $update );
1200 }
1201 }
1202 }
1203 }
1204
1205 if ( $client_id && isset( $client_fields['new_contacts_field'] ) ) {
1206
1207 foreach ( $client_fields['new_contacts_field']['client.contact.name'] as $indx => $contact_name ) {
1208 $contact_to_add = array();
1209 if ( empty( $contact_name ) ) {
1210 continue;
1211 }
1212 $contact_to_add['contact_name'] = $contact_name;
1213
1214 $contact_email = $client_fields['new_contacts_field']['contact.email'][ $indx ];
1215 if ( empty( $contact_email ) ) {
1216 continue;
1217 }
1218 $contact_to_add['contact_email'] = $contact_email;
1219
1220 $contact_to_add['contact_phone'] = isset( $client_fields['new_contacts_field']['contact.phone'][ $indx ] ) ? $client_fields['new_contacts_field']['contact.phone'][ $indx ] : '';
1221 $contact_to_add['contact_role'] = $client_fields['new_contacts_field']['contact.role'][ $indx ];
1222 $contact_to_add['facebook'] = isset( $client_fields['new_contacts_field']['contact.facebook'][ $indx ] ) ? $client_fields['new_contacts_field']['contact.facebook'][ $indx ] : '';
1223 $contact_to_add['twitter'] = isset( $client_fields['new_contacts_field']['contact.twitter'][ $indx ] ) ? $client_fields['new_contacts_field']['contact.twitter'][ $indx ] : '';
1224 $contact_to_add['instagram'] = isset( $client_fields['new_contacts_field']['contact.instagram'][ $indx ] ) ? $client_fields['new_contacts_field']['contact.instagram'][ $indx ] : '';
1225 $contact_to_add['linkedin'] = isset( $client_fields['new_contacts_field']['contact.linkedin'][ $indx ] ) ? $client_fields['new_contacts_field']['contact.linkedin'][ $indx ] : '';
1226
1227 $cust_icon = isset( $client_fields['new_contacts_field']['selected_icon'][ $indx ] ) ? sanitize_text_field( wp_unslash( $client_fields['new_contacts_field']['selected_icon'][ $indx ] ) ) : '';
1228 $cust_color = isset( $client_fields['new_contacts_field']['selected_color'][ $indx ] ) ? sanitize_hex_color( wp_unslash( $client_fields['new_contacts_field']['selected_color'][ $indx ] ) ) : '';
1229
1230 $contact_to_add['contact_icon_info'] = 'selected:' . $cust_icon . ';color:' . $cust_color;
1231
1232 $contact_to_add['contact_client_id'] = $client_id;
1233
1234 $inserted = MainWP_DB_Client::instance()->update_client_contact( $contact_to_add );
1235
1236 if ( $inserted ) {
1237
1238 $contact_id = $inserted->contact_id;
1239 $contact_image = '';
1240 if ( isset( $_POST['mainwp_add_edit_contact_uploaded_icon_hidden']['new_contacts_field'][ $indx ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1241 $contact_image = sanitize_text_field( wp_unslash( $_POST['mainwp_add_edit_contact_uploaded_icon_hidden']['new_contacts_field'][ $indx ] ) ); // phpcs:ignore WordPress.Security.NonceVerification
1242 }
1243
1244 if ( '' !== $contact_image && $contact_id ) {
1245 $update = array(
1246 'contact_id' => $contact_id,
1247 'contact_image' => $contact_image,
1248 );
1249 MainWP_DB_Client::instance()->update_client_contact( $update );
1250 }
1251
1252 if ( $is_first_contact && empty( $auto_assign_contact_id ) ) {
1253 $auto_assign_contact_id = $contact_id;
1254 }
1255 }
1256 }
1257 }
1258
1259 if ( $client_id && isset( $client_fields['delele_contacts'] ) && is_array( $client_fields['delele_contacts'] ) ) {
1260 foreach ( $client_fields['delele_contacts'] as $delete_id ) {
1261 MainWP_DB_Client::instance()->delete_client_contact( $client_id, $delete_id );
1262 $is_first_contact = false;
1263 }
1264 }
1265
1266 if ( $is_first_contact && $auto_assign_contact_id && $client_id ) {
1267 // auto assign.
1268 $update = array(
1269 'client_id' => $client_id,
1270 'primary_contact_id' => $auto_assign_contact_id,
1271 );
1272 MainWP_DB_Client::instance()->update_client( $update );
1273 }
1274
1275 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1276 if ( isset( $_POST['is_first_client'] ) && ! empty( $_POST['is_first_client'] ) ) {
1277 delete_transient( 'mainwp_transient_just_connected_site_id' );
1278 }
1279 //phpcs:enable
1280
1281 echo wp_json_encode(
1282 array(
1283 'success' => 'yes',
1284 'client_id' => $client_id,
1285 )
1286 );
1287 }
1288
1289 /**
1290 * Method render_add_client_modal().
1291 *
1292 * Renders add client Modal window.
1293 */
1294 public static function render_add_client_modal() {
1295 ?>
1296 <div id="mainwp-creating-new-client-modal" class="ui modal">
1297 <i class="close icon"></i>
1298 <div class="header"><?php esc_html_e( 'New client', 'mainwp' ); ?></div>
1299 <div class="ui message" id="mainwp-message-zone-client" style="display:none;"></div>
1300 <div class="scrolling content mainwp-modal-content">
1301 <form action="" method="post" enctype="multipart/form-data" name="createclient_form" id="createclient_form" class="add:clients: validate">
1302 <?php
1303 static::render_add_client_content();
1304 ?>
1305 </form>
1306 </div>
1307 <div class="actions">
1308 <div class="ui button green" current-page="modal-add" id="bulk_add_createclient"><?php esc_html_e( 'Add Client', 'mainwp' ); ?></div>
1309 </div>
1310 </div>
1311
1312 <script type="text/javascript">
1313 jQuery(document).on('click', '.edit-site-new-client-button', function () {
1314 jQuery('#mainwp-creating-new-client-modal').modal({
1315 allowMultiple: true,
1316 }).modal('show');
1317 return false;
1318 });
1319 </script>
1320 <?php
1321 }
1322
1323 /**
1324 * Method render_add_client_content().
1325 *
1326 * Renders add client content window.
1327 *
1328 * @param mixed $edit_client The client data.
1329 */
1330 public static function render_add_client_content( $edit_client = false ) { // phpcs:ignore -- NOSONAR -Current complexity is required to achieve desired results. Pull request solutions appreciated.
1331 $client_id = $edit_client ? $edit_client->client_id : 0;
1332 $default_client_fields = MainWP_Client_Handler::get_default_client_fields();
1333 $custom_fields = MainWP_DB_Client::instance()->get_client_fields( true, $client_id, true );
1334 $client_image = $edit_client ? $edit_client->image : '';
1335
1336 $icon_info_array = array();
1337 if ( $edit_client ) {
1338 $arr_fields = array(
1339 'image',
1340 'selected_icon_info',
1341 );
1342 $icon_info_array = MainWP_Utility::map_fields( $edit_client, $arr_fields, false );
1343 }
1344
1345 $uploaded_icon_src = '';
1346 if ( ! empty( $client_image ) ) {
1347 $uploaded_icon_src = MainWP_Client_Handler::get_client_contact_image( $icon_info_array, 'client', 'uploaded_icon' );
1348 }
1349
1350 ?>
1351 <h3 class="ui dividing header">
1352 <?php if ( $client_id ) : ?>
1353 <?php MainWP_Settings_Indicator::render_indicator( 'header', 'settings-field-indicator-edit-client' ); ?>
1354 <?php echo esc_html__( 'Edit Client', 'mainwp' ); ?>
1355 <div class="sub header"><?php esc_html_e( 'Edit client information.', 'mainwp' ); ?></div>
1356 <?php else : ?>
1357 <?php esc_html_e( 'Add New Client', 'mainwp' ); ?>
1358 <div class="sub header"><?php esc_html_e( 'Enter the client information.', 'mainwp' ); ?></div>
1359 <?php endif; ?>
1360 </h3>
1361 <div class="ui form">
1362 <?php
1363
1364 foreach ( $default_client_fields as $field_name => $field ) {
1365 $db_field = isset( $field['db_field'] ) ? $field['db_field'] : '';
1366 $val = $edit_client && '' !== $db_field && property_exists( $edit_client, $db_field ) ? $edit_client->{$db_field} : '';
1367 $tip = isset( $field['tooltip'] ) ? $field['tooltip'] : '';
1368 ?>
1369 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-client">
1370 <label class="six wide column middle aligned" for="client_fields[default_field][<?php echo esc_attr( $field_name ); ?>]" <?php echo ! empty( $tip ) ? 'data-tooltip="' . esc_attr( $tip ) . '" data-inverted="" data-position="top left"' : ''; // phpcs:ignore WordPress.Security.EscapeOutput ?>>
1371 <?php
1372 $indi_val = $val && $edit_client ? 1 : 0;
1373 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $indi_val );
1374 echo esc_html( $field['title'] );
1375 ?>
1376 </label>
1377 <div class="ui six wide column">
1378 <div class="ui left labeled input">
1379 <?php
1380 if ( 'client.note' === $field_name ) {
1381 ?>
1382 <div class="editor">
1383 <textarea class="code settings-field-value-change-handler" cols="80" rows="10" id="client_fields[default_field][<?php echo esc_attr( $field_name ); ?>]" name="client_fields[default_field][<?php echo esc_attr( $field_name ); ?>]"><?php echo esc_html( $val ); ?></textarea>
1384 </div>
1385 <?php
1386 } elseif ( 'client.suspended' === $field_name ) {
1387 ?>
1388 <select class="ui dropdown settings-field-value-change-handler" name="client_fields[default_field][<?php echo esc_attr( $field_name ); ?>]" id="client_fields[default_field][<?php echo esc_attr( $field_name ); ?>]" >
1389 <option value="0" <?php echo '0' === $val ? 'selected' : ''; ?>><?php esc_html_e( 'Active', 'mainwp' ); ?></option>
1390 <option value="1" <?php echo '1' === $val ? 'selected' : ''; ?>><?php esc_html_e( 'Suspended', 'mainwp' ); ?></option>
1391 <option value="2" <?php echo '2' === $val ? 'selected' : ''; ?>><?php esc_html_e( 'Lead', 'mainwp' ); ?></option>
1392 <option value="3" <?php echo '3' === $val ? 'selected' : ''; ?>><?php esc_html_e( 'Lost', 'mainwp' ); ?></option>
1393 </select>
1394 <?php
1395 } elseif ( $client_id && 'client.created' === $field_name ) {
1396 $created = empty( $val ) ? time() : $val;
1397 ?>
1398 <div class="ui calendar mainwp_datepicker" >
1399 <div class="ui input left icon">
1400 <i class="calendar icon"></i>
1401 <input type="text" autocomplete="off" name="client_fields[default_field][<?php echo esc_attr( $field_name ); ?>]" placeholder="<?php esc_attr_e( 'Added date', 'mainwp' ); ?>" id="client_fields[default_field][<?php echo esc_attr( $field_name ); ?>]" value="<?php echo esc_attr( date( 'Y-m-d', $created ) ); // phpcs:ignore -- local time. ?>"/>
1402 </div>
1403 </div>
1404 <?php
1405 } else {
1406 ?>
1407 <input type="text" id="client_fields[default_field][<?php echo esc_attr( $field_name ); ?>]" class="regular-text settings-field-value-change-handler" value="<?php echo esc_html( $val ); ?>" name="client_fields[default_field][<?php echo esc_attr( $field_name ); ?>]"/>
1408 <?php
1409 }
1410 ?>
1411 </div>
1412 </div>
1413 <?php if ( $client_id ) : ?>
1414 <div class="ui four wide middle aligned hidden token column" style="display:none">
1415 <?php if ( 'client.suspended' !== $field_name ) { ?>
1416 [<?php echo esc_html( $field_name ); ?>]
1417 <?php } ?>
1418 </div>
1419 <?php endif; ?>
1420 </div>
1421 <?php
1422
1423 if ( 'client.email' === $field_name ) {
1424 ?>
1425 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-client">
1426 <label class="six wide column middle aligned">
1427 <?php
1428 $indi_val = $client_image && $edit_client ? 1 : 0;
1429 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $indi_val );
1430 ?>
1431 <?php esc_html_e( 'Client photo', 'mainwp' ); ?>
1432 </label>
1433 <input type="hidden" name="mainwp_add_edit_client_uploaded_icon_hidden" class="settings-field-value-change-handler" id="mainwp_add_edit_client_uploaded_icon_hidden" value="<?php echo esc_attr( $client_image ); ?>">
1434 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Upload a client photo.', 'mainwp' ); ?>" data-inverted="" data-position="left center">
1435 <div class="ui green button basic mainwp-add-edit-client-icon-customable" iconItemId="<?php echo intval( $client_id ); ?>" iconFileSlug="<?php echo esc_attr( $client_image ); ?>" icon-src="<?php echo esc_attr( $uploaded_icon_src ); ?>"><?php esc_html_e( 'Upload Icon', 'mainwp' ); ?></div>
1436 <?php if ( ! empty( $client_image ) ) { ?>
1437 <?php echo MainWP_Client_Handler::get_client_contact_image( $icon_info_array, 'client', 'display_edit' ); //phpcs:ignore --ok. ?>
1438 <?php } else { ?>
1439 <div style="display:inline-block;" id="mainwp_add_edit_client_upload_custom_icon"></div> <?php // used for icon holder. ?>
1440 <?php } ?>
1441 </div>
1442 </div>
1443 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-client" default-indi-indi-value="wordpress">
1444 <label class="six wide column middle aligned">
1445 <?php
1446 $default_icons = MainWP_UI::get_default_icons();
1447 $selected_icon = 'wordpress'; //phpcs:ignore -- WP icon.
1448 $selected_color = '#34424D';
1449
1450 $icon_info = $edit_client ? $edit_client->selected_icon_info : '';
1451 if ( ! empty( $icon_info ) ) {
1452 $selected_icon = static::get_cust_client_icon( $icon_info, 'selected' );
1453 $selected_color = static::get_cust_client_icon( $icon_info, 'color' );
1454 }
1455
1456 $indi_val = 'wordpress' !== $selected_icon ? 1 : 0; //phpcs:ignore -- WP icon.
1457 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $indi_val );
1458 esc_html_e( 'Select icon', 'mainwp' );
1459 ?>
1460 </label>
1461 <input type="hidden" name="client_fields[default_field][selected_icon]" class="settings-field-value-change-handler" id="client_fields[default_field][selected_icon]" value="<?php echo esc_attr( $selected_icon ); ?>">
1462 <div class="six wide column" data-tooltip="<?php esc_attr_e( 'Select an icon if not using original client icon.', 'mainwp' ); ?>" data-inverted="" data-position="left center">
1463 <div class="ui left action input mainwp-dropdown-color-picker-field">
1464 <div class="ui five column selection search dropdown not-auto-init" id="mainwp_edit_clients_icon_select">
1465 <div class="text">
1466 <span style="color:<?php echo esc_attr( $selected_color ); ?>" ><?php echo ! empty( $selected_icon ) ? '<i class="' . esc_attr( $selected_icon ) . ' icon"></i>' : ''; ?></span>
1467 </div>
1468 <i class="dropdown icon"></i>
1469 <div class="menu">
1470 <?php foreach ( $default_icons as $icon ) : ?>
1471 <?php echo '<div class="item" style="color:' . esc_attr( $selected_color ) . '" data-value="' . esc_attr( $icon ) . '"><i class="' . esc_attr( $icon ) . ' icon"></i></div>'; ?>
1472 <?php endforeach; ?>
1473 </div>
1474 </div>
1475 <input type="color" data-tooltip="Color will update on save" data-position="top center" data-inverted="" name="client_fields[default_field][selected_color]" class="mainwp-color-picker-input" id="client_fields[default_field][selected_color]" value="<?php echo esc_attr( $selected_color ); ?>" />
1476 </div>
1477 </div>
1478 <div class="one wide column"></div>
1479 </div>
1480 <?php
1481 }
1482 }
1483
1484 $client_contacts = array();
1485 if ( $client_id ) {
1486 $client_contacts = MainWP_DB_Client::instance()->get_wp_client_contact_by( 'client_id', $client_id );
1487 ?>
1488 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-client">
1489 <label class="six wide column middle aligned">
1490 <?php
1491 $indi_val = $edit_client && $client_contacts ? 1 : 0;
1492 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $indi_val );
1493 echo esc_html_e( 'Client primary contact', 'mainwp' );
1494 ?>
1495 </label>
1496 <div class="ui six wide column">
1497 <div class="ui left labeled">
1498 <div class="ui search selection dropdown" init-value="" id="client_fields[default_field][primary_contact_id]">
1499 <input type="hidden" name="client_fields[default_field][primary_contact_id]" value="<?php echo $edit_client ? intval( $edit_client->primary_contact_id ) : 0; ?>">
1500 <i class="dropdown icon"></i>
1501 <div class="default text"><?php esc_attr_e( 'Select primary contact', 'mainwp' ); ?></div>
1502 <div class="menu">
1503 <div class="item" data-value="0"><?php esc_attr_e( 'Select primary contact', 'mainwp' ); ?></div>
1504 <?php if ( $client_contacts ) : ?>
1505 <?php foreach ( $client_contacts as $contact ) { ?>
1506 <div class="item" data-value="<?php echo intval( $contact->contact_id ); ?>"><?php echo esc_html( stripslashes( $contact->contact_name ) ); ?></div>
1507 <?php } ?>
1508 <?php endif; ?>
1509 </div>
1510 </div>
1511 </div>
1512 </div>
1513 <div class="ui four wide column">
1514 </div>
1515 </div>
1516 <div class="ui section hidden divider"></div>
1517 <?php
1518 }
1519
1520 if ( is_array( $custom_fields ) && count( $custom_fields ) > 0 ) {
1521 $compatible_tokens = MainWP_Client_Handler::get_compatible_tokens();
1522 foreach ( $custom_fields as $field ) {
1523 if ( isset( $default_client_fields[ $field->field_name ] ) ) {
1524 continue;
1525 }
1526 // do not show these tokens.
1527 if ( isset( $compatible_tokens[ $field->field_name ] ) ) {
1528 continue;
1529 }
1530 $field_val = ( property_exists( $field, 'field_value' ) && '' !== $field->field_value ) ? esc_html( $field->field_value ) : '';
1531 ?>
1532 <div class="ui grid field mainwp-field settings-field-indicator-wrapper settings-field-indicator-edit-client" field-id="<?php echo intval( $field->field_id ); ?>">
1533 <label class="six wide column middle aligned field-description">
1534 <?php
1535 $indi_val = $edit_client && $field_val ? 1 : 0;
1536 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $indi_val );
1537 echo esc_html( $field->field_desc );
1538 ?>
1539 </label>
1540 <div class="ui six wide column">
1541 <div class="ui left labeled input">
1542 <input type="text" value="<?php echo esc_attr( $field_val ); ?>" class="regular-text" name="client_fields[custom_fields][<?php echo esc_html( $field->field_name ); ?>][<?php echo esc_html( $field->field_id ); ?>]"/>
1543 </div>
1544 </div>
1545 <div class="ui four wide column">
1546 <?php if ( $client_id > 0 && $field->client_id > 0 ) { // edit client and it is individual field, then show to edit/delete field buttons. ?>
1547 <div class="ui left pointing dropdown icon mini basic green button">
1548 <i class="ellipsis horizontal icon"></i>
1549 <div class="menu">
1550 <a class="item" id="mainwp-clients-edit-custom-field" href="#"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a>
1551 <a class="item" client-id="<?php echo intval( $client_id ); ?>" id="mainwp-clients-delete-individual-field" href="#"><?php esc_html_e( 'Delete', 'mainwp' ); ?></a>
1552 </div>
1553 </div>
1554 <?php } ?>
1555 <span class="field-name">[<?php echo esc_html( $field->field_name ); ?>]</span>
1556 </div>
1557 </div>
1558 <?php
1559 }
1560 }
1561
1562 $temp = static::get_add_contact_temp( false, false );
1563
1564 if ( $client_id && $client_contacts ) {
1565 foreach ( $client_contacts as $client_contact ) {
1566 static::get_add_contact_temp( $client_contact, true );
1567 }
1568 }
1569 ?>
1570 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-edit-client">
1571 <label class="six wide column middle aligned"><?php esc_html_e( 'Create a new contact for this client', 'mainwp' ); ?></label>
1572 <div class="ui six wide column">
1573 <div class="ui left labeled input">
1574 <a href="javascript:void(0);" class="ui green button mainwp-client-add-contact" add-contact-temp="<?php echo esc_attr( $temp ); ?>"><?php esc_html_e( 'Add Additional Contact', 'mainwp' ); ?></a>
1575 </div>
1576 </div>
1577 </div>
1578 <div class="ui section hidden divider after-add-contact-field"></div>
1579 </div>
1580 <input type="hidden" name="client_fields[client_id]" value="<?php echo intval( $client_id ); ?>">
1581 <script type="text/javascript">
1582 jQuery( document ).ready( function () {
1583 // to fix issue not loaded calendar js library
1584 if (jQuery('.ui.calendar').length > 0) {
1585 if (mainwpParams.use_wp_datepicker == 1) {
1586 jQuery('#mainwp-add-new-client-form .ui.calendar input[type=text]').datepicker({ dateFormat: "yy-mm-dd" });
1587 } else {
1588 mainwp_init_ui_calendar( '#mainwp-add-new-client-form .ui.calendar' );
1589 }
1590 }
1591
1592 let current_iconObj;
1593
1594 jQuery(document).on('click', '.mainwp-add-edit-client-icon-customable', function () {
1595 current_iconObj = jQuery(this);
1596 jQuery('#mainwp_delete_image_field').hide();
1597 jQuery('#mainwp-upload-custom-icon-modal').modal({
1598 allowMultiple: true, // multiple modals.
1599 closable: false,
1600 }).modal('show');
1601 jQuery('#update_custom_icon_btn').attr('uploading-icon', 'client');
1602 jQuery('#update_custom_icon_btn').removeAttr('disabled');
1603 jQuery('#mainwp_delete_image_field').find('#mainwp_delete_image_chk').attr('iconItemId', current_iconObj.attr('iconItemId') ); // @see used by mainwp_upload_custom_types_icon().
1604 jQuery('#mainwp_delete_image_field').find('#mainwp_delete_image_chk').attr('iconFileSlug', current_iconObj.attr('iconFileSlug') ); // @see used by mainwp_upload_custom_types_icon().
1605
1606 if (current_iconObj.attr('icon-src') != '') {
1607 jQuery('#mainwp_delete_image_field').find('.ui.image').attr('src', current_iconObj.attr('icon-src'));
1608 jQuery('#mainwp_delete_image_field').show();
1609 }
1610 });
1611
1612 jQuery(document).on('click', '.mainwp-add-edit-contact-icon-customable', function () {
1613 current_iconObj = jQuery(this);
1614 jQuery('#mainwp_delete_image_field').hide();
1615 jQuery('#mainwp-upload-custom-icon-modal').modal({
1616 allowMultiple: true, // multiple modals.
1617 closable: false,
1618 }).modal('show');
1619 jQuery('#update_custom_icon_btn').attr('uploading-icon', 'contact');
1620 jQuery('#update_custom_icon_btn').removeAttr('disabled');
1621 jQuery('#mainwp_delete_image_field').find('#mainwp_delete_image_chk').attr('iconItemId', current_iconObj.attr('iconItemId') ); // @see used by mainwp_upload_custom_types_icon().
1622 jQuery('#mainwp_delete_image_field').find('#mainwp_delete_image_chk').attr('iconFileSlug', current_iconObj.attr('iconFileSlug') ); // @see used by mainwp_upload_custom_types_icon().
1623
1624 if (current_iconObj.attr('icon-src') != '') {
1625 jQuery('#mainwp_delete_image_field').find('.ui.image').attr('src', current_iconObj.attr('icon-src'));
1626 jQuery('#mainwp_delete_image_field').show();
1627 }
1628 });
1629
1630 // to fix conflict with other update custom icon click event.
1631 jQuery(document).on('click', '#update_custom_icon_btn', function () {
1632 if( 'client' === jQuery(this).attr( 'uploading-icon' ) ){
1633 mainwp_update_custom_icon_client( current_iconObj );
1634 } else if( 'contact' === jQuery(this).attr( 'uploading-icon' ) ){
1635 mainwp_update_custom_icon_contact( current_iconObj );
1636 }
1637 });
1638
1639 mainwp_update_custom_icon_client = function( iconObj ){
1640 let deleteIcon = jQuery('#mainwp_delete_image_chk').is(':checked');
1641 let iconItemId = iconObj.attr('iconItemId');
1642 let iconFileSlug = iconObj.attr('iconFileSlug'); // to support delete file when iconItemId = 0.
1643
1644 // upload/delete lient icon action.
1645 mainwp_upload_custom_types_icon(iconObj, 'mainwp_add_edit_client_upload_client_icon', iconItemId, iconFileSlug, deleteIcon, function(response){
1646 if (jQuery('#mainwp_add_edit_client_uploaded_icon_hidden').length > 0) {
1647 if (typeof response.iconfile !== undefined) {
1648 jQuery('#mainwp_add_edit_client_uploaded_icon_hidden').val(response.iconfile);
1649 } else {
1650 jQuery('#mainwp_add_edit_client_uploaded_icon_hidden').val('');
1651 }
1652 jQuery( '#mainwp_add_edit_client_uploaded_icon_hidden' ).trigger('change');
1653 }
1654 let deleteIcon = jQuery('#mainwp_delete_image_chk').is(':checked'); // to delete.
1655 if(deleteIcon){
1656 jQuery('#mainwp_add_edit_client_upload_custom_icon').hide();
1657 } else if (jQuery('#mainwp_add_edit_client_upload_custom_icon').length > 0) {
1658 if (typeof response.iconfile !== undefined) {
1659 let icon_img = typeof response.iconimg !== undefined ? response.iconimg : '';
1660 let icon_src = typeof response.iconsrc !== undefined ? response.iconsrc : '';
1661 iconObj.attr('icon-src', icon_src);
1662 iconObj.attr('iconFileSlug', response.iconfile); // to support delete file when iconItemId = 0.
1663 jQuery('#mainwp_delete_image_field').find('.ui.image').attr('src', icon_src);
1664 jQuery('#mainwp_add_edit_client_upload_custom_icon').html(icon_img);
1665 jQuery('#mainwp_add_edit_client_upload_custom_icon').show();
1666 }
1667 }
1668 setTimeout(function () {
1669 //window.location.href = location.href;
1670 jQuery('#mainwp-upload-custom-icon-modal').modal('hide')
1671 }, 1000);
1672 });
1673 return false;
1674 }
1675
1676 mainwp_update_custom_icon_contact = function( iconObj ){
1677 let deleteIcon = jQuery('#mainwp_delete_image_chk').is(':checked');
1678 let iconItemId = iconObj.attr('iconItemId');
1679 let iconFileSlug = iconObj.attr('iconFileSlug'); // to support delete file when iconItemId = 0.
1680
1681 // upload/delete lient icon action.
1682 mainwp_upload_custom_types_icon(iconObj, 'mainwp_add_edit_contact_upload_contact_icon', iconItemId, iconFileSlug, deleteIcon, function(response){
1683 let parent = jQuery(iconObj).closest('.mainwp_edit_clients_contact_uploaded_icon_wrapper');
1684
1685 if (jQuery('#mainwp_add_edit_client_uploaded_icon_hidden').length > 0) {
1686 if (typeof response.iconfile !== undefined) {
1687 jQuery(parent).find('.mainwp_add_edit_contact_uploaded_icon_hidden').val(response.iconfile);
1688 } else {
1689 jQuery(parent).find('.mainwp_add_edit_contact_uploaded_icon_hidden').val('');
1690 }
1691 jQuery(parent).find( '.mainwp_add_edit_contact_uploaded_icon_hidden' ).trigger('change');
1692 }
1693 let deleteIcon = jQuery('#mainwp_delete_image_chk').is(':checked'); // to delete.
1694 if(deleteIcon){
1695 jQuery(parent).find('.mainwp_add_edit_contact_upload_custom_icon').hide();
1696 } else if (jQuery(parent).find('.mainwp_add_edit_contact_upload_custom_icon').length > 0) {
1697 if (typeof response.iconfile !== undefined) {
1698 let icon_img = typeof response.iconimg !== undefined ? response.iconimg : '';
1699 let icon_src = typeof response.iconsrc !== undefined ? response.iconsrc : '';
1700 iconObj.attr('icon-src', icon_src);
1701 iconObj.attr('iconFileSlug', response.iconfile); // to support delete file when iconItemId = 0.
1702 jQuery('#mainwp_delete_image_field').find('.ui.image').attr('src', icon_src);
1703 jQuery(parent).find('.mainwp_add_edit_contact_upload_custom_icon').html(icon_img).show();
1704 }
1705 }
1706 setTimeout(function () {
1707 //window.location.href = location.href;
1708 jQuery('#mainwp-upload-custom-icon-modal').modal('hide')
1709 }, 1000);
1710 });
1711 return false;
1712 }
1713
1714 } );
1715 </script>
1716 <?php
1717 }
1718
1719 /**
1720 * Method get_cust_client_icon()
1721 *
1722 * Get site icon.
1723 *
1724 * @param string $icon_data icon data.
1725 * @param string $type Type: selected|color|display.
1726 * @param string $what Icon display for what.
1727 */
1728 public static function get_cust_client_icon( $icon_data, $type = 'display', $what = 'default' ) {
1729 if ( empty( $icon_data ) ) {
1730 return '';
1731 }
1732 $data = explode( ';', $icon_data );
1733 $selected_icon = str_replace( 'selected:', '', $data[0] );
1734 $color = str_replace( 'color:', '', $data[1] );
1735
1736 if ( empty( $color ) ) {
1737 $color = '#34424D';
1738 }
1739
1740 $icon_cls = 'large icon custom-icon';
1741 if ( 'card' === $what ) {
1742 $icon_cls = 'icon huge custom-icon';
1743 }
1744
1745 $output = '';
1746 if ( 'selected' === $type ) {
1747 $output = $selected_icon;
1748 } elseif ( 'color' === $type ) {
1749 $output = $color;
1750 } elseif ( 'display' === $type || 'display_edit' === $what ) {
1751 $color_style = '';
1752 if ( ! empty( $color ) ) {
1753 $color_style = 'color:' . esc_attr( $color ) . ';';
1754 }
1755 $icon_wrapper_attr = 'class="mainwp_client_icon_display"';
1756 if ( 'display_edit' === $what ) {
1757 $icon_wrapper_attr = ' id="mainwp_add_edit_client_upload_custom_icon" ' . $icon_wrapper_attr;
1758 }
1759 $output = '<div style="display:inline-block;' . $color_style . '" ' . $icon_wrapper_attr . ' ><i class="' . esc_attr( $selected_icon ) . ' ' . $icon_cls . '" ></i></div>';
1760 }
1761 return $output;
1762 }
1763
1764 /**
1765 * Method get_add_contact_temp().
1766 *
1767 * Get add contact template.
1768 *
1769 * @param mixed $edit_contact The contact data to edit.
1770 * @param bool $echo_out Echo template or not.
1771 */
1772 public static function get_add_contact_temp( $edit_contact = false, $echo_out = false ) { //phpcs:ignore -- NOSONAR - complex.
1773
1774 $input_name = 'new_contacts_field';
1775 $contact_id = 0;
1776 $contact_image = '';
1777 if ( $edit_contact ) {
1778 $input_name = 'contacts_field';
1779 $contact_id = $edit_contact->contact_id;
1780 $contact_image = $edit_contact->contact_image;
1781 }
1782
1783 $uploaded_icon_src = '';
1784 if ( ! empty( $contact_image ) ) {
1785 $arr_fields = array(
1786 'contact_image',
1787 'contact_icon_info',
1788 );
1789 $icon_info_array = MainWP_Utility::map_fields( $edit_contact, $arr_fields, false );
1790 $uploaded_icon_src = MainWP_Client_Handler::get_client_contact_image( $icon_info_array, 'contact', 'uploaded_icon' );
1791 }
1792
1793 ob_start();
1794 ?>
1795 <h3 class="ui dividing header top-contact-fields"> <?php // must have class: top-contact-fields. ?>
1796 <?php if ( $edit_contact ) : ?>
1797 <?php echo esc_html__( 'Edit Contact', 'mainwp' ); ?>
1798 <div class="sub header"><?php esc_html_e( 'Edit contact person information.', 'mainwp' ); ?></div>
1799 <?php else : ?>
1800 <?php esc_html_e( 'Add Contact', 'mainwp' ); ?>
1801 <div class="sub header"><?php esc_html_e( 'Enter contact person information.', 'mainwp' ); ?></div>
1802 <?php endif; ?>
1803 </h3>
1804 <?php
1805 $default_icons = MainWP_UI::get_default_icons();
1806 $contact_fields = MainWP_Client_Handler::get_default_contact_fields();
1807 foreach ( $contact_fields as $field_name => $field ) {
1808 $db_field = isset( $field['db_field'] ) ? $field['db_field'] : '';
1809 $val = $edit_contact && '' !== $db_field && property_exists( $edit_contact, $db_field ) ? $edit_contact->{$db_field} : '';
1810 $contact_id = $edit_contact && property_exists( $edit_contact, 'contact_id' ) ? $edit_contact->contact_id : '';
1811 ?>
1812 <div class="ui grid field settings-field-indicator-wrapper">
1813 <label class="six wide column middle aligned">
1814 <?php
1815 $indi_val = $edit_contact && $val ? 1 : 0;
1816 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $indi_val );
1817 echo esc_html( $field['title'] );
1818 ?>
1819 </label>
1820 <div class="ui six wide column">
1821 <div class="ui left labeled input">
1822 <input type="text" value="<?php echo esc_attr( $val ); ?>" class="regular-text settings-field-value-change-handler" name="client_fields[<?php echo esc_attr( $input_name ); ?>][<?php echo esc_attr( $field_name ); ?>][]"/>
1823 </div>
1824 </div>
1825 <?php if ( $edit_contact ) : ?>
1826 <div class="ui four wide middle aligned hidden token column" style="display:none">
1827 [<?php echo esc_html( $field_name ); ?>]
1828 </div>
1829 <?php endif; ?>
1830 </div>
1831 <?php
1832 if ( 'contact.role' === $field_name ) {
1833 ?>
1834 <div class="ui grid field mainwp_edit_clients_contact_uploaded_icon_wrapper settings-field-indicator-wrapper">
1835 <label class="six wide column middle aligned">
1836 <?php
1837 $indi_val = $edit_contact && $contact_image ? 1 : 0;
1838 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $indi_val );
1839 ?>
1840 <?php esc_html_e( 'Contact photo', 'mainwp' ); ?>
1841 </label>
1842 <input type="hidden" name="mainwp_add_edit_contact_uploaded_icon_hidden[<?php echo esc_html( $input_name ); ?>][]" class="settings-field-value-change-handler mainwp_add_edit_contact_uploaded_icon_hidden" value="<?php echo esc_attr( $contact_image ); ?>">
1843 <div class="three wide middle aligned column" data-tooltip="<?php esc_attr_e( 'Upload a contact photo.', 'mainwp' ); ?>" data-inverted="" data-position="left center">
1844 <div class="ui green button basic mainwp-add-edit-contact-icon-customable" iconItemId="<?php echo intval( $contact_id ); ?>" iconFileSlug="<?php echo esc_attr( $contact_image ); ?>" icon-src="<?php echo esc_attr( $uploaded_icon_src ); ?>"><?php esc_html_e( 'Upload Icon', 'mainwp' ); ?></div>
1845 <?php
1846 if ( ! empty( $contact_image ) ) {
1847 ?>
1848 <?php echo MainWP_Client_Handler::get_client_contact_image( $icon_info_array, 'contact', 'display_edit' ); //phpcs:ignore --ok. ?>
1849 <?php } else { ?>
1850 <div style="display:inline-block;" class="mainwp_add_edit_contact_upload_custom_icon"></div> <?php // used for icon holder. ?>
1851 <?php } ?>
1852 </div>
1853 </div>
1854 <div class="ui grid field mainwp_edit_clients_contact_icon_wrapper settings-field-indicator-wrapper" input-name="<?php echo esc_attr( $input_name ); ?>" default-indi-indi-value="wordpress">
1855 <label class="six wide column middle aligned">
1856 <?php
1857 $selected_icon = 'wordpress'; //phpcs:ignore -- WP icon.
1858 $selected_color = '#34424D';
1859 $icon_info = $edit_contact ? $edit_contact->contact_icon_info : '';
1860
1861 if ( ! empty( $icon_info ) ) {
1862 $selected_icon = static::get_cust_client_icon( $icon_info, 'selected' );
1863 $selected_color = static::get_cust_client_icon( $icon_info, 'color' );
1864 }
1865 $indi_val = 'wordpress' !== $selected_icon ? 1 : 0; //phpcs:ignore -- WP icon.
1866 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $indi_val );
1867 esc_html_e( 'Select icon', 'mainwp' );
1868 ?>
1869 </label>
1870 <div class="six wide column" data-tooltip="<?php esc_attr_e( 'Select an icon if not using original contact icon.', 'mainwp' ); ?>" data-inverted="" data-position="left center">
1871 <input type="hidden" class="settings-field-value-change-handler" name="client_fields[<?php echo esc_html( $input_name ); ?>][selected_icon][]" id="client_fields[<?php echo esc_attr( $input_name ); ?>][selected_icon][]" value="<?php echo esc_attr( $selected_icon ); ?>">
1872 <div class="ui left action input mainwp-dropdown-color-picker-field">
1873 <div class="ui five column selection search dropdown not-auto-init mainwp-edit-clients-select-contact-icon" style="min-width:21em">
1874 <div class="text">
1875 <span style="color:<?php echo esc_attr( $selected_color ); ?>" ><?php echo ! empty( $selected_icon ) ? '<i class="' . esc_attr( $selected_icon ) . ' icon"></i>' : ''; ?></span>
1876 </div>
1877 <i class="dropdown icon"></i>
1878 <div class="menu">
1879 <?php foreach ( $default_icons as $icon ) : ?>
1880 <?php echo '<div class="item" style="color:' . esc_attr( $selected_color ) . '" data-value="' . esc_attr( $icon ) . '"><i class="' . esc_attr( $icon ) . ' icon"></i></div>'; ?>
1881 <?php endforeach; ?>
1882 </div>
1883 </div>
1884 <input type="color" data-tooltip="Color will update on save" data-position="top center" data-inverted="" name="client_fields[<?php echo esc_html( $input_name ); ?>][selected_color][]" class="mainwp-color-picker-input" id="client_fields[<?php echo esc_html( $input_name ); ?>][selected_color][]" value="<?php echo esc_attr( $selected_color ); ?>" />
1885 </div>
1886 </div>
1887 <div class="one wide column"></div>
1888 </div>
1889 <?php
1890 }
1891 }
1892
1893 ?>
1894 <div class="ui grid field remove-contact-field-parent">
1895 <label class="six wide column middle aligned"><?php esc_html_e( 'Remove contact', 'mainwp' ); ?></label>
1896 <div class="ui six wide column">
1897 <div class="ui left labeled input">
1898 <a href="javascript:void(0);" contact-id="<?php echo intval( $contact_id ); ?>" class="ui basic button mainwp-client-remove-contact"><?php esc_html_e( 'Remove contact', 'mainwp' ); ?></a>
1899 </div>
1900 <?php
1901 if ( $edit_contact ) {
1902 ?>
1903 <input type="hidden" value="<?php echo intval( $edit_contact->contact_id ); ?>" name="client_fields[contacts_field][contact_id][]"/>
1904 <?php
1905 }
1906 ?>
1907 </div>
1908 </div>
1909 <div class="ui section hidden divider bottom-contact-fields"></div>
1910 <?php
1911 $html = ob_get_clean();
1912
1913 if ( $echo_out ) {
1914 echo $html; //phpcs:ignore -- validated content.
1915 }
1916
1917 return $html;
1918 }
1919
1920 /**
1921 * Method save_client_field().
1922 *
1923 * Save custom fields.
1924 */
1925 public static function save_client_field() { //phpcs:ignore -- NOSONAR - complex.
1926
1927 $return = array(
1928 'success' => false,
1929 'error' => '',
1930 'message' => '',
1931 );
1932
1933 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1934 $client_id = isset( $_POST['client_id'] ) ? intval( $_POST['client_id'] ) : 0; // 0 is global client's field.
1935 $field_id = isset( $_POST['field_id'] ) ? intval( $_POST['field_id'] ) : 0;
1936 $field_desc = isset( $_POST['field_desc'] ) ? sanitize_text_field( wp_unslash( $_POST['field_desc'] ) ) : '';
1937 $field_name = isset( $_POST['field_name'] ) ? sanitize_text_field( wp_unslash( $_POST['field_name'] ) ) : '';
1938 $field_name = trim( $field_name, '[]' );
1939 // phpcs:enable
1940
1941 // update general or individual client field.
1942 if ( $field_id ) {
1943 $current = MainWP_DB_Client::instance()->get_client_fields_by( 'field_id', $field_id );
1944 if ( $current && $current->field_name === $field_name && $current->field_desc === $field_desc ) {
1945 $return['success'] = true;
1946 $return['message'] = esc_html__( 'Field has been saved without changes.', 'mainwp' );
1947 } else {
1948 $current = MainWP_DB_Client::instance()->get_client_fields_by( 'field_name', $field_name, $client_id ); // check if other field with the same name existed.
1949 if ( $current && (int) $current->field_id !== $field_id ) {
1950 $return['error'] = esc_html__( 'Field already exists, try different field name.', 'mainwp' );
1951 } else {
1952 // update general or individual field name.
1953 $field = MainWP_DB_Client::instance()->update_client_field(
1954 $field_id,
1955 array(
1956 'field_name' => $field_name,
1957 'field_desc' => $field_desc,
1958 'client_id' => $client_id,
1959 )
1960 );
1961 if ( $field ) {
1962 $return['success'] = true;
1963 }
1964 }
1965 }
1966 } else { // add new.
1967 $current = MainWP_DB_Client::instance()->get_client_fields_by( 'field_name', $field_name, $client_id );
1968 if ( $current ) { // checking general or individual field name.
1969 $return['error'] = esc_html__( 'Field already exists, try different field name.', 'mainwp' );
1970 } else {
1971 // insert general or individual field name.
1972 $field = MainWP_DB_Client::instance()->add_client_field(
1973 array(
1974 'field_name' => $field_name,
1975 'field_desc' => $field_desc,
1976 'client_id' => $client_id,
1977 )
1978 );
1979
1980 if ( $field ) {
1981 $return['success'] = true;
1982 } else {
1983 $return['error'] = esc_html__( 'Undefined error occurred. Please try again.', 'mainwp' );
1984 }
1985 }
1986 }
1987 echo wp_json_encode( $return );
1988 exit;
1989 }
1990
1991 /**
1992 * Method save_note()
1993 *
1994 * Save Client Note.
1995 */
1996 public static function save_note() {
1997 if ( isset( $_POST['clientid'] ) && ! empty( $_POST['clientid'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1998 $note = isset( $_POST['note'] ) ? wp_unslash( $_POST['note'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1999 $esc_note = MainWP_Utility::esc_content( $note );
2000 $update = array(
2001 'client_id' => intval( $_POST['clientid'] ), // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2002 'note' => $esc_note,
2003 );
2004 MainWP_DB_Client::instance()->update_client( $update );
2005 die( wp_json_encode( array( 'result' => 'SUCCESS' ) ) );
2006 }
2007 die( wp_json_encode( array( 'undefined_error' => true ) ) );
2008 }
2009
2010 /**
2011 * Hooks the section help content to the Help Sidebar element.
2012 */
2013 public static function mainwp_help_content() {
2014 if ( isset( $_GET['page'] ) && ( 'ManageClients' === $_GET['page'] || 'ClientAddNew' === $_GET['page'] || 'UpdateAdminPasswords' === $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2015 ?>
2016 <p><?php esc_html_e( 'If you need help with managing clients, please review following help documents', 'mainwp' ); ?></p>
2017 <div class="ui relaxed bulleted list">
2018 <div class="item"><a href="https://kb.mainwp.com/docs/manage-clients/" target="_blank">Manage Clients</a> <i class="external alternate icon"></i></div> <?php // NOSONAR - noopener - open safe. ?>
2019 <?php
2020 /**
2021 * Action: mainwp_clients_help_item
2022 *
2023 * Fires at the bottom of the help articles list in the Help sidebar on the Clients page.
2024 *
2025 * Suggested HTML markup:
2026 *
2027 * <div class="item"><a href="Your custom URL">Your custom text</a></div>
2028 *
2029 * @since 4.1
2030 */
2031 do_action( 'mainwp_clients_help_item' );
2032 ?>
2033 </div>
2034 <?php
2035 }
2036 }
2037 }
2038