| 1 |
<?php |
| 2 |
/** |
| 3 |
* Clients List Table. |
| 4 |
* |
| 5 |
* @package MainWP/Dashboard |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace MainWP\Dashboard; |
| 9 |
|
| 10 |
/** |
| 11 |
* Class MainWP_Client_List_Table |
| 12 |
* |
| 13 |
* @package MainWP\Dashboard |
| 14 |
* |
| 15 |
* MainWP sites client list. |
| 16 |
* |
| 17 |
* @devtodo The only variables that seam to be used are $column_headers. |
| 18 |
* |
| 19 |
* @uses \MainWP\Dashboard\MainWP_Manage_Sites_List_Table |
| 20 |
*/ |
| 21 |
class MainWP_Client_List_Table extends MainWP_Manage_Sites_List_Table { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. |
| 22 |
|
| 23 |
/** |
| 24 |
* Protected variable to hold columns headers |
| 25 |
* |
| 26 |
* @var array |
| 27 |
*/ |
| 28 |
protected $column_headers; |
| 29 |
|
| 30 |
/** |
| 31 |
* MainWP_Client_List_Table constructor. |
| 32 |
* |
| 33 |
* Run each time the class is called. |
| 34 |
* Add action to generate tabletop. |
| 35 |
*/ |
| 36 |
public function __construct() { |
| 37 |
add_action( 'mainwp_manageclients_tabletop', array( &$this, 'generate_tabletop' ) ); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Get the default primary column name. |
| 42 |
* |
| 43 |
* @return string Child site name. |
| 44 |
*/ |
| 45 |
protected function get_default_primary_column_name() { |
| 46 |
return 'site'; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
/** |
| 51 |
* Set the column names. |
| 52 |
* |
| 53 |
* @param mixed $item MainWP site table item. |
| 54 |
* @param string $column_name Column name to use. |
| 55 |
* |
| 56 |
* @return string Column name. |
| 57 |
*/ |
| 58 |
public function column_default( $item, $column_name ) { // phpcs:ignore -- NOSONAR - complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 59 |
|
| 60 |
/** |
| 61 |
* Filter: mainwp_clients_sitestable_item |
| 62 |
* |
| 63 |
* Filters the Clients table column items. Allows user to create new column item. |
| 64 |
* |
| 65 |
* @param array $item Array containing child site data. |
| 66 |
* |
| 67 |
* @since 4.1 |
| 68 |
*/ |
| 69 |
$item = apply_filters( 'mainwp_clients_sitestable_item', $item, $item ); |
| 70 |
return isset( $item[ $column_name ] ) && ! empty( $item[ $column_name ] ) ? $item[ $column_name ] : 'N/A'; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Get sortable columns. |
| 75 |
* |
| 76 |
* @return array $sortable_columns Array of sortable column names. |
| 77 |
*/ |
| 78 |
public function get_sortable_columns() { |
| 79 |
return array( |
| 80 |
'name' => array( 'name', false ), |
| 81 |
'client_email' => array( 'client_email', false ), |
| 82 |
'client_phone' => array( 'client_phone', false ), |
| 83 |
'client_facebook' => array( 'client_facebook', false ), |
| 84 |
'client_twitter' => array( 'client_twitter', false ), |
| 85 |
'client_instagram' => array( 'client_instagram', false ), |
| 86 |
'client_linkedin' => array( 'client_linkedin', false ), |
| 87 |
'suspended' => array( 'suspended', false ), |
| 88 |
'tags' => array( 'tags', false ), |
| 89 |
'websites' => array( 'websites', false ), |
| 90 |
'contact_name' => array( 'contact_name', false ), |
| 91 |
'address_1' => array( 'address_1', false ), |
| 92 |
'address_2' => array( 'address_2', false ), |
| 93 |
'city' => array( 'city', false ), |
| 94 |
'zip' => array( 'zip', false ), |
| 95 |
'state' => array( 'state', false ), |
| 96 |
'created' => array( 'created', false ), |
| 97 |
'country' => array( 'country', false ), |
| 98 |
); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Gets default columns. |
| 103 |
* |
| 104 |
* @return array Array of default column names. |
| 105 |
*/ |
| 106 |
public function get_default_columns() { |
| 107 |
return array( |
| 108 |
'cb' => '<input type="checkbox" />', |
| 109 |
'name' => esc_html__( 'Client', 'mainwp' ), |
| 110 |
'image' => esc_html__( 'Image', 'mainwp' ), |
| 111 |
'tags' => esc_html__( 'Tags', 'mainwp' ), |
| 112 |
'contact_name' => esc_html__( 'Contact Name', 'mainwp' ), |
| 113 |
'client_email' => esc_html__( 'Client Email', 'mainwp' ), |
| 114 |
'suspended' => esc_html__( 'Status', 'mainwp' ), |
| 115 |
'client_phone' => esc_html__( 'Phone', 'mainwp' ), |
| 116 |
'client_facebook' => esc_html__( 'Facebook', 'mainwp' ), |
| 117 |
'client_twitter' => esc_html__( 'X', 'mainwp' ), |
| 118 |
'client_instagram' => esc_html__( 'Instagram', 'mainwp' ), |
| 119 |
'client_linkedin' => esc_html__( 'LinkedIn', 'mainwp' ), |
| 120 |
'websites' => esc_html__( 'Websites', 'mainwp' ), |
| 121 |
'address_1' => esc_html__( 'Address 1', 'mainwp' ), |
| 122 |
'address_2' => esc_html__( 'Address 2', 'mainwp' ), |
| 123 |
'city' => esc_html__( 'City', 'mainwp' ), |
| 124 |
'zip' => esc_html__( 'Zip', 'mainwp' ), |
| 125 |
'state' => esc_html__( 'State', 'mainwp' ), |
| 126 |
'country' => esc_html__( 'Country', 'mainwp' ), |
| 127 |
'created' => esc_html__( 'Added on', 'mainwp' ), |
| 128 |
'notes' => esc_html__( 'Notes', 'mainwp' ), |
| 129 |
); |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Method get_columns() |
| 134 |
* |
| 135 |
* Combine all columns. |
| 136 |
* |
| 137 |
* @return array $columns Array of column names. |
| 138 |
*/ |
| 139 |
public function get_columns() { |
| 140 |
|
| 141 |
$columns = $this->get_default_columns(); |
| 142 |
|
| 143 |
/** |
| 144 |
* Filter: mainwp_clients_sitestable_getcolumns |
| 145 |
* |
| 146 |
* Filters the Clients table columns. Allows user to create a new column. |
| 147 |
* |
| 148 |
* @param array $columns Array containing table columns. |
| 149 |
* |
| 150 |
* @since 4.1 |
| 151 |
*/ |
| 152 |
$columns = apply_filters( 'mainwp_clients_sitestable_getcolumns', $columns, $columns ); |
| 153 |
|
| 154 |
$columns['client_actions'] = ''; |
| 155 |
|
| 156 |
return $columns; |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Instantiate Columns. |
| 161 |
* |
| 162 |
* @return array $init_cols |
| 163 |
*/ |
| 164 |
public function get_columns_init() { |
| 165 |
$cols = $this->get_columns(); |
| 166 |
$init_cols = array(); |
| 167 |
foreach ( $cols as $key => $val ) { |
| 168 |
$init_cols[] = array( 'data' => esc_html( $key ) ); |
| 169 |
} |
| 170 |
return $init_cols; |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Method generate_tabletop() |
| 175 |
* |
| 176 |
* Run the render_manage_sites_table_top menthod. |
| 177 |
*/ |
| 178 |
public function generate_tabletop() { |
| 179 |
$this->render_manage_sites_table_top(); |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* Create bulk actions drop down. |
| 184 |
* |
| 185 |
* @return array $actions Return actions through the mainwp_manageclients_bulk_actions filter. |
| 186 |
*/ |
| 187 |
public function get_bulk_actions() { |
| 188 |
|
| 189 |
$actions = array( |
| 190 |
'delete' => esc_html__( 'Delete', 'mainwp' ), |
| 191 |
); |
| 192 |
|
| 193 |
/** |
| 194 |
* Filter: mainwp_manageclients_bulk_actions |
| 195 |
* |
| 196 |
* Filters bulk actions on the Clients page. Allows user to hook in new actions or remove default ones. |
| 197 |
* |
| 198 |
* @since 4.1 |
| 199 |
*/ |
| 200 |
return apply_filters( 'mainwp_manageclients_bulk_actions', $actions ); |
| 201 |
} |
| 202 |
|
| 203 |
/** |
| 204 |
* Render manage sites table top. |
| 205 |
* |
| 206 |
* @uses \MainWP\Dashboard\MainWP_DB_Common::get_groups_for_manage_sites() |
| 207 |
*/ |
| 208 |
public function render_manage_sites_table_top() { |
| 209 |
$items_bulk = $this->get_bulk_actions(); |
| 210 |
|
| 211 |
$selected_group = isset( $_REQUEST['tags'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tags'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 212 |
$default_filter = empty( $selected_group ) ? true : false; |
| 213 |
?> |
| 214 |
<div class="ui grid"> |
| 215 |
<div class="equal width row ui mini form"> |
| 216 |
<div class="middle aligned column"> |
| 217 |
<div id="mainwp-clients-bulk-actions-menu" class="ui selection dropdown"> |
| 218 |
<div class="default text"><?php esc_html_e( 'Bulk actions', 'mainwp' ); ?></div> |
| 219 |
<i class="dropdown icon"></i> |
| 220 |
<div class="menu"> |
| 221 |
<?php |
| 222 |
foreach ( $items_bulk as $value => $title ) { |
| 223 |
if ( 'seperator_' === substr( $value, 0, 10 ) ) { |
| 224 |
?> |
| 225 |
<div class="ui divider"></div> |
| 226 |
<?php |
| 227 |
} else { |
| 228 |
?> |
| 229 |
<div class="item" data-value="<?php echo esc_attr( $value ); ?>"><?php echo esc_html( $title ); ?></div> |
| 230 |
<?php |
| 231 |
} |
| 232 |
} |
| 233 |
?> |
| 234 |
</div> |
| 235 |
</div> |
| 236 |
<button class="ui tiny basic button" id="mainwp-do-clients-bulk-actions"><?php esc_html_e( 'Apply', 'mainwp' ); ?></button> |
| 237 |
</div> |
| 238 |
<div class="right aligned middle aligned column"> |
| 239 |
<?php esc_html_e( 'Filter clients: ', 'mainwp' ); ?> |
| 240 |
<div id="mainwp-filter-clients-group" class="ui selection multiple dropdown" style="vertical-align:bottom"> |
| 241 |
<input type="hidden" value="<?php echo esc_html( $selected_group ); ?>"> |
| 242 |
<i class="dropdown icon"></i> |
| 243 |
<div class="default text"><?php esc_html_e( 'All tags', 'mainwp' ); ?></div> |
| 244 |
<div class="menu"> |
| 245 |
<?php |
| 246 |
$groups = MainWP_DB_Common::instance()->get_groups_for_manage_sites(); |
| 247 |
|
| 248 |
foreach ( $groups as $group ) { |
| 249 |
?> |
| 250 |
<div class="item" data-value="<?php echo intval( $group->id ); ?>"><?php echo esc_html( stripslashes( $group->name ) ); ?></div> |
| 251 |
<?php |
| 252 |
} |
| 253 |
?> |
| 254 |
<div class="item" data-value="nogroups"><?php esc_html_e( 'No Tags', 'mainwp' ); ?></div> |
| 255 |
</div> |
| 256 |
</div> |
| 257 |
<button onclick="mainwp_manage_clients_filter()" class="ui mini green button"><?php esc_html_e( 'Filter Clients', 'mainwp' ); ?></button> |
| 258 |
<a href="admin.php?page=ManageClients" class="ui mini button" <?php echo $default_filter ? 'disabled="disabled"' : ''; ?>><?php esc_html_e( 'Reset Filters', 'mainwp' ); ?></a> |
| 259 |
</div> |
| 260 |
</div> |
| 261 |
</div> |
| 262 |
<script type="text/javascript"> |
| 263 |
jQuery( document ).ready( function () { |
| 264 |
mainwp_manage_clients_filter = function() { |
| 265 |
let group = jQuery( "#mainwp-filter-clients-group" ).dropdown( "get value" ); |
| 266 |
let isNot = jQuery( "#mainwp-is-not-client" ).dropdown( "get value" ); |
| 267 |
let params = ''; |
| 268 |
params += '&tags=' + group; |
| 269 |
|
| 270 |
window.location = 'admin.php?page=ManageClients' + params; |
| 271 |
return false; |
| 272 |
} |
| 273 |
} ); |
| 274 |
</script> |
| 275 |
<?php |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
/** |
| 280 |
* Prepair the items to be listed. |
| 281 |
* |
| 282 |
* @param bool $optimize true|false Whether or not to optimize. |
| 283 |
*/ |
| 284 |
public function prepare_items( $optimize = false ) { // phpcs:ignore -- NOSONAR - complex. |
| 285 |
|
| 286 |
$params = array( |
| 287 |
'with_selected_sites' => true, |
| 288 |
'with_tags' => true, |
| 289 |
); |
| 290 |
|
| 291 |
if ( isset( $_GET['tags'] ) && ! empty( $_GET['tags'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 292 |
$tags = sanitize_text_field( rawurldecode( wp_unslash( $_GET['tags'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 293 |
if ( ! empty( $tags ) ) { |
| 294 |
if ( false !== strpos( $tags, ',' ) ) { |
| 295 |
$tags = explode( ',', $tags ); |
| 296 |
} else { |
| 297 |
$tags = explode( ';', $tags ); |
| 298 |
} |
| 299 |
$params['by_tags'] = array_filter( $tags ); |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
$clients = MainWP_DB_Client::instance()->get_wp_client_by( 'all', null, ARRAY_A, $params ); |
| 304 |
|
| 305 |
$totalRecords = ( $clients ? count( $clients ) : 0 ); |
| 306 |
|
| 307 |
$clients_ids = array(); |
| 308 |
if ( is_array( $clients ) ) { |
| 309 |
foreach ( $clients as $item ) { |
| 310 |
if ( ! empty( $item['client_id'] ) ) { |
| 311 |
$clients_ids[] = $item['client_id']; |
| 312 |
} |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
// for compatible. |
| 317 |
$optimize = $optimize ? true : false; |
| 318 |
|
| 319 |
do_action( 'mainwp_clientstable_prepared_items', $clients, $clients_ids ); |
| 320 |
|
| 321 |
$this->items = $clients; |
| 322 |
$this->total_items = $totalRecords; |
| 323 |
} |
| 324 |
|
| 325 |
/** |
| 326 |
* Display the table. |
| 327 |
* |
| 328 |
* @param bool $optimize true|false Whether or not to optimize. |
| 329 |
*/ |
| 330 |
public function display( $optimize = false ) { |
| 331 |
|
| 332 |
// for compatible. |
| 333 |
$optimize = $optimize ? true : false; |
| 334 |
|
| 335 |
$sites_per_page = get_option( 'mainwp_default_manage_clients_per_page', 25 ); |
| 336 |
|
| 337 |
$sites_per_page = intval( $sites_per_page ); |
| 338 |
|
| 339 |
$pages_length = array( |
| 340 |
25 => '25', |
| 341 |
10 => '10', |
| 342 |
50 => '50', |
| 343 |
100 => '100', |
| 344 |
300 => '300', |
| 345 |
); |
| 346 |
|
| 347 |
$pages_length = $pages_length + array( $sites_per_page => $sites_per_page ); |
| 348 |
ksort( $pages_length ); |
| 349 |
|
| 350 |
if ( isset( $pages_length[-1] ) ) { |
| 351 |
unset( $pages_length[-1] ); |
| 352 |
} |
| 353 |
|
| 354 |
$pagelength_val = implode( ',', array_keys( $pages_length ) ); |
| 355 |
$pagelength_title = implode( ',', array_values( $pages_length ) ); |
| 356 |
|
| 357 |
?> |
| 358 |
<?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-client-info-message' ) ) : ?> |
| 359 |
<div class="ui info message"> |
| 360 |
<i class="close icon mainwp-notice-dismiss" notice-id="mainwp-client-info-message"></i> |
| 361 |
<?php printf( esc_html__( 'Manage your clients. For additional help, please check this %1$shelp documentation%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/manage-clients/" target="_blank">', '</a> <i class="external alternate icon"></i>' ); // NOSONAR - noopener - open safe. ?> |
| 362 |
</div> |
| 363 |
<?php endif; ?> |
| 364 |
<?php |
| 365 |
MainWP_Client_Handler::show_notice_existed_contact_emails(); |
| 366 |
?> |
| 367 |
<table id="mainwp-manage-clients-table" style="width:100%" class="ui single line selectable unstackable table mainwp-with-preview-table mainwp-manage-wpsites-table"> |
| 368 |
<thead> |
| 369 |
<tr> |
| 370 |
<?php $this->print_column_headers( $optimize, true ); ?> |
| 371 |
</tr> |
| 372 |
</thead> |
| 373 |
<tbody id="mainwp-manage-sites-body-table"> |
| 374 |
<?php $this->display_rows_or_placeholder(); ?> |
| 375 |
</tbody> |
| 376 |
<tfoot> |
| 377 |
<tr> |
| 378 |
<?php $this->print_column_headers( $optimize, false ); ?> |
| 379 |
</tr> |
| 380 |
</tfoot> |
| 381 |
</table> |
| 382 |
<div id="mainwp-loading-sites" style="display: none;"> |
| 383 |
<div class="ui active inverted dimmer"> |
| 384 |
<div class="ui indeterminate large text loader"><?php esc_html_e( 'Loading ...', 'mainwp' ); ?></div> |
| 385 |
</div> |
| 386 |
</div> |
| 387 |
<?php MainWP_UI::render_modal_edit_notes( 'client' ); ?> |
| 388 |
<?php |
| 389 |
|
| 390 |
$table_features = array( |
| 391 |
'searching' => 'true', |
| 392 |
'paging' => 'true', |
| 393 |
'pagingType' => 'full_numbers', |
| 394 |
'info' => 'true', |
| 395 |
'colReorder' => '{columns:":not(.check-column):not(.manage-client_actions-column)"}', |
| 396 |
'stateSave' => 'true', |
| 397 |
'stateDuration' => '0', |
| 398 |
'order' => '[]', |
| 399 |
'scrollX' => 'true', |
| 400 |
'responsive' => 'true', |
| 401 |
); |
| 402 |
|
| 403 |
/** |
| 404 |
* Filter: mainwp_clients_table_features |
| 405 |
* |
| 406 |
* Filter the Clients table features. |
| 407 |
* |
| 408 |
* @since 4.1 |
| 409 |
*/ |
| 410 |
$table_features = apply_filters( 'mainwp_clients_table_features', $table_features ); |
| 411 |
?> |
| 412 |
<script type="text/javascript"> |
| 413 |
jQuery( document ).ready( function( $ ) { |
| 414 |
window.mainwp_manage_clients_screen_options = function () { |
| 415 |
jQuery( '#mainwp-manage-sites-screen-options-modal' ).modal( { |
| 416 |
allowMultiple: true, |
| 417 |
onHide: function () { |
| 418 |
let val = jQuery( '#mainwp_default_manage_clients_per_page' ).val(); |
| 419 |
let saved = jQuery( '#mainwp_default_manage_clients_per_page' ).attr( 'saved-value' ); |
| 420 |
if ( saved != val ) { |
| 421 |
jQuery( '#mainwp-manage-clients-table' ).DataTable().page.len( val ); |
| 422 |
jQuery( '#mainwp-manage-clients-table' ).DataTable().state.save(); |
| 423 |
} |
| 424 |
} |
| 425 |
} ).modal( 'show' ); |
| 426 |
|
| 427 |
jQuery( '#manage-sites-screen-options-form' ).submit( function() { |
| 428 |
if ( jQuery('input[name=reset_manageclients_columns_order]').attr('value') == 1 ) { |
| 429 |
$manage_sites_table.colReorder.reset(); |
| 430 |
} |
| 431 |
jQuery( '#mainwp-manage-sites-screen-options-modal' ).modal( 'hide' ); |
| 432 |
} ); |
| 433 |
return false; |
| 434 |
}; |
| 435 |
|
| 436 |
let responsive = <?php echo esc_js( $table_features['responsive'] ); ?>; |
| 437 |
if( jQuery( window ).width() > 1140 ) { |
| 438 |
responsive = false; |
| 439 |
} |
| 440 |
|
| 441 |
try { |
| 442 |
$manage_sites_table = jQuery( '#mainwp-manage-clients-table' ).DataTable( { |
| 443 |
"responsive" : responsive, |
| 444 |
"searching" : <?php echo esc_js( $table_features['searching'] ); ?>, |
| 445 |
"paging" : <?php echo esc_js( $table_features['paging'] ); ?>, |
| 446 |
"pagingType" : "<?php echo esc_js( $table_features['pagingType'] ); ?>", |
| 447 |
"info" : <?php echo esc_js( $table_features['info'] ); ?>, |
| 448 |
"colReorder" : <?php echo $table_features['colReorder']; // phpcs:ignore -- specical chars. ?>, |
| 449 |
"stateSave" : <?php echo esc_js( $table_features['stateSave'] ); ?>, |
| 450 |
"stateDuration" : <?php echo esc_js( $table_features['stateDuration'] ); ?>, |
| 451 |
"order" : <?php echo $table_features['order']; // phpcs:ignore -- specical chars. ?>, |
| 452 |
"scrollX" : <?php echo esc_js( $table_features['scrollX'] ); ?>, |
| 453 |
"columnDefs": [ |
| 454 |
{ |
| 455 |
"targets": 'no-sort', |
| 456 |
"orderable": false |
| 457 |
}, |
| 458 |
{ |
| 459 |
"targets": 'manage-site-column', |
| 460 |
"type": 'natural-nohtml' |
| 461 |
}, |
| 462 |
<?php do_action( 'mainwp_manage_sites_table_columns_defs' ); ?> |
| 463 |
], |
| 464 |
"lengthMenu" : [ [<?php echo esc_js( $pagelength_val ); ?>, -1 ], [<?php echo esc_js( $pagelength_title ); ?>, "All" ] ], |
| 465 |
"pageLength": <?php echo intval( $sites_per_page ); ?>, |
| 466 |
"drawCallback": function( settings ) { |
| 467 |
}, |
| 468 |
select: { |
| 469 |
items: 'row', |
| 470 |
style: 'multi+shift', |
| 471 |
selector: 'tr>td:not(.not-selectable)' |
| 472 |
} |
| 473 |
} ).on( 'columns-reordered', function () { |
| 474 |
console.log('columns-reorderede'); |
| 475 |
setTimeout(() => { |
| 476 |
$( '#mainwp-manage-clients-table .ui.dropdown' ).dropdown(); |
| 477 |
$( '#mainwp-manage-clients-table .ui.checkbox' ).checkbox(); |
| 478 |
mainwp_datatable_fix_menu_overflow(); |
| 479 |
}, 1000 ); |
| 480 |
} ).on('select', function (e, dt, type, indexes) { |
| 481 |
if( 'row' == type ){ |
| 482 |
dt.rows(indexes) |
| 483 |
.nodes() |
| 484 |
.to$().find('td.check-column .ui.checkbox' ).checkbox('set checked'); |
| 485 |
} |
| 486 |
}).on('deselect', function (e, dt, type, indexes) { |
| 487 |
if( 'row' == type ){ |
| 488 |
dt.rows(indexes) |
| 489 |
.nodes() |
| 490 |
.to$().find('td.check-column .ui.checkbox' ).checkbox('set unchecked'); |
| 491 |
} |
| 492 |
}); |
| 493 |
} catch(err) { |
| 494 |
// to fix js error. |
| 495 |
} |
| 496 |
mainwp_datatable_fix_menu_overflow(); |
| 497 |
_init_manage_sites_screen = function() { |
| 498 |
jQuery( '#mainwp-manage-sites-screen-options-modal input[type=checkbox][id^="mainwp_show_column_"]' ).each( function() { |
| 499 |
let col_id = jQuery( this ).attr( 'id' ); |
| 500 |
col_id = col_id.replace( "mainwp_show_column_", "" ); |
| 501 |
try { |
| 502 |
$manage_sites_table.column( '#' + col_id ).visible( jQuery(this).is( ':checked' ) ); |
| 503 |
} catch(err) { |
| 504 |
// to fix js error. |
| 505 |
} |
| 506 |
} ); |
| 507 |
}; |
| 508 |
_init_manage_sites_screen(); |
| 509 |
} ); |
| 510 |
</script> |
| 511 |
<?php |
| 512 |
} |
| 513 |
|
| 514 |
/** |
| 515 |
* Echo the column headers. |
| 516 |
* |
| 517 |
* @param bool $optimize true|false Whether or not to optimize. |
| 518 |
* @param bool $top true|false. |
| 519 |
*/ |
| 520 |
public function print_column_headers( $optimize, $top = true ) { |
| 521 |
// for compatible. |
| 522 |
$optimize = $optimize ? true : false; |
| 523 |
|
| 524 |
list( $columns, $sortable ) = $this->get_column_info(); |
| 525 |
|
| 526 |
if ( ! empty( $columns['cb'] ) ) { |
| 527 |
$columns['cb'] = '<div class="ui checkbox"><input id="' . ( $top ? 'cb-select-all-top' : 'cb-select-all-bottom' ) . '" type="checkbox" aria-label="Select all clients." /></div>'; |
| 528 |
} |
| 529 |
|
| 530 |
$def_columns = $this->get_default_columns(); |
| 531 |
$def_columns['client_actions'] = ''; |
| 532 |
|
| 533 |
foreach ( $columns as $column_client_key => $column_display_name ) { |
| 534 |
|
| 535 |
$class = array( 'manage-' . $column_client_key . '-column' ); |
| 536 |
$attr = ''; |
| 537 |
if ( ! isset( $def_columns[ $column_client_key ] ) ) { |
| 538 |
$class[] = 'extra-column'; |
| 539 |
|
| 540 |
} |
| 541 |
|
| 542 |
if ( 'cb' === $column_client_key ) { |
| 543 |
$class[] = 'check-column'; |
| 544 |
$class[] = 'collapsing'; |
| 545 |
} |
| 546 |
|
| 547 |
if ( ! isset( $sortable[ $column_client_key ] ) ) { |
| 548 |
$class[] = 'no-sort'; |
| 549 |
} |
| 550 |
|
| 551 |
$tag = 'th'; |
| 552 |
$id = "id='$column_client_key'"; |
| 553 |
|
| 554 |
if ( ! empty( $class ) ) { |
| 555 |
$class = "class='" . join( ' ', $class ) . "'"; |
| 556 |
} |
| 557 |
|
| 558 |
echo "<$tag $id $class $attr>$column_display_name</$tag>"; // phpcs:ignore WordPress.Security.EscapeOutput |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
/** |
| 563 |
* Get column info. |
| 564 |
*/ |
| 565 |
protected function get_column_info() { |
| 566 |
|
| 567 |
if ( isset( $this->column_headers ) && is_array( $this->column_headers ) ) { |
| 568 |
$column_headers = array( array(), array(), array(), $this->get_default_primary_column_name() ); |
| 569 |
foreach ( $this->column_headers as $key => $value ) { |
| 570 |
$column_headers[ $key ] = $value; |
| 571 |
} |
| 572 |
|
| 573 |
return $column_headers; |
| 574 |
} |
| 575 |
|
| 576 |
$columns = $this->get_columns(); |
| 577 |
|
| 578 |
$sortable_columns = $this->get_sortable_columns(); |
| 579 |
|
| 580 |
$_sortable = $sortable_columns; |
| 581 |
|
| 582 |
$sortable = array(); |
| 583 |
foreach ( $_sortable as $id => $data ) { |
| 584 |
if ( empty( $data ) ) { |
| 585 |
continue; |
| 586 |
} |
| 587 |
|
| 588 |
$data = (array) $data; |
| 589 |
if ( ! isset( $data[1] ) ) { |
| 590 |
$data[1] = false; |
| 591 |
} |
| 592 |
|
| 593 |
$sortable[ $id ] = $data; |
| 594 |
} |
| 595 |
|
| 596 |
$primary = $this->get_default_primary_column_name(); |
| 597 |
$this->column_headers = array( $columns, $sortable, $primary ); |
| 598 |
|
| 599 |
return $this->column_headers; |
| 600 |
} |
| 601 |
|
| 602 |
/** |
| 603 |
* Fetch single row item. |
| 604 |
* |
| 605 |
* @return mixed Single Row Item. |
| 606 |
*/ |
| 607 |
public function display_rows() { |
| 608 |
if ( $this->items ) { |
| 609 |
foreach ( $this->items as $item ) { |
| 610 |
$this->single_row( $item ); |
| 611 |
} |
| 612 |
} |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
/** |
| 617 |
* Single row. |
| 618 |
* |
| 619 |
* @param mixed $item Object containing the client info. |
| 620 |
*/ |
| 621 |
public function single_row( $item ) { |
| 622 |
echo '<tr id="client-site-' . intval( $item['client_id'] ) . '" clientid=' . intval( $item['client_id'] ) . ' >'; |
| 623 |
$this->single_row_columns( $item ); |
| 624 |
echo '</tr>'; |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
/** |
| 629 |
* Columns for a single row. |
| 630 |
* |
| 631 |
* @param mixed $item Object containing the client info. |
| 632 |
* @param bool $compatible to compatible param - DO NOT remove. |
| 633 |
*/ |
| 634 |
protected function single_row_columns( $item, $compatible = true ) { // phpcs:ignore -- NOSONAR - complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 635 |
|
| 636 |
list( $columns ) = $this->get_column_info(); |
| 637 |
|
| 638 |
foreach ( $columns as $column_name => $column_display_name ) { |
| 639 |
|
| 640 |
$classes = "collapsing $column_name column-$column_name"; |
| 641 |
|
| 642 |
if ( 'client_actions' === $column_name ) { |
| 643 |
$classes .= ' center aligned '; |
| 644 |
} |
| 645 |
|
| 646 |
$attributes = "class='$classes'"; |
| 647 |
?> |
| 648 |
<?php if ( 'cb' === $column_name ) { ?> |
| 649 |
<td class="check-column"> |
| 650 |
<div class="ui checkbox"> |
| 651 |
<input type="checkbox" value="<?php echo intval( $item['client_id'] ); ?>" name="" aria-label="<?php esc_attr_e( 'Select the site.', 'mainwp' ); ?>"/> |
| 652 |
</div> |
| 653 |
</td> |
| 654 |
<?php |
| 655 |
} elseif ( 'client_actions' === $column_name ) { |
| 656 |
$selected_sites = isset( $item['selected_sites'] ) ? trim( $item['selected_sites'] ) : ''; |
| 657 |
?> |
| 658 |
<td class="collapsing manage-clients-actions not-selectable"> |
| 659 |
<div class="ui right pointing dropdown icon mini basic green button" style="z-index:999;"> |
| 660 |
<i class="ellipsis horizontal icon"></i> |
| 661 |
<div class="menu" clientid=<?php echo intval( $item['client_id'] ); ?>> |
| 662 |
<a class="item client_getedit" href="admin.php?page=ClientAddNew&client_id=<?php echo intval( $item['client_id'] ); ?>"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a> |
| 663 |
<a class="item" href="admin.php?page=managesites&client=<?php echo intval( $item['client_id'] ); ?>"><?php esc_html_e( 'View Sites', 'mainwp' ); ?></a> |
| 664 |
<?php if ( is_plugin_active( 'mainwp-pro-reports-extension/mainwp-pro-reports-extension.php' ) ) { ?> |
| 665 |
<a class="item" href="admin.php?page=Extensions-Mainwp-Pro-Reports-Extension&tab=report&action=newreport&selected_sites=<?php echo esc_html( $selected_sites ); ?>"><?php esc_html_e( 'Create Report', 'mainwp' ); ?></a> |
| 666 |
<?php } ?> |
| 667 |
<a class="item client_deleteitem" href="#"><?php esc_html_e( 'Delete', 'mainwp' ); ?></a> |
| 668 |
</div> |
| 669 |
</div> |
| 670 |
</td> |
| 671 |
<?php |
| 672 |
} elseif ( 'image' === $column_name ) { |
| 673 |
echo "<td $attributes>"; // phpcs:ignore WordPress.Security.EscapeOutput |
| 674 |
?> |
| 675 |
<?php $client_display_image = MainWP_Client_Handler::get_client_contact_image( $item ); ?> |
| 676 |
<a class="item" href="admin.php?page=ManageClients&client_id=<?php echo intval( $item['client_id'] ); ?>"><?php echo $client_display_image; //phpcs:ignore --- ok.?></a> |
| 677 |
<?php |
| 678 |
echo '</td>'; |
| 679 |
} elseif ( 'name' === $column_name ) { |
| 680 |
echo "<td $attributes>"; // phpcs:ignore WordPress.Security.EscapeOutput |
| 681 |
?> |
| 682 |
<a class="item" href="admin.php?page=ManageClients&client_id=<?php echo intval( $item['client_id'] ); ?>"><?php echo esc_html( $item['name'] ); ?></a> |
| 683 |
<?php |
| 684 |
echo '</td>'; |
| 685 |
} elseif ( 'client_email' === $column_name ) { |
| 686 |
echo "<td $attributes>"; // phpcs:ignore WordPress.Security.EscapeOutput |
| 687 |
?> |
| 688 |
<a class="item" href="admin.php?page=ClientAddNew&client_id=<?php echo intval( $item['client_id'] ); ?>"><?php echo esc_html( $item['client_email'] ); ?></a> |
| 689 |
<?php |
| 690 |
echo '</td>'; |
| 691 |
} elseif ( 'tags' === $column_name ) { |
| 692 |
?> |
| 693 |
<td class="collapsing"><?php echo MainWP_System_Utility::get_site_tags( $item, true ); // phpcs:ignore WordPress.Security.EscapeOutput ?></td> |
| 694 |
<?php |
| 695 |
} elseif ( 'suspended' === $column_name ) { |
| 696 |
$client_status = ''; |
| 697 |
if ( 0 === intval( $item['suspended'] ) ) { |
| 698 |
$client_status = '<span class="ui green mini fluid center aligned label">' . esc_html__( 'Active', 'mainwp' ) . '</span>'; |
| 699 |
} elseif ( 1 === intval( $item['suspended'] ) ) { |
| 700 |
$client_status = '<span class="ui yellow mini fluid center aligned label">' . esc_html__( 'Suspended', 'mainwp' ) . '</span>'; |
| 701 |
} elseif ( 2 === intval( $item['suspended'] ) ) { |
| 702 |
$client_status = '<span class="ui blue mini fluid center aligned label">' . esc_html__( 'Lead', 'mainwp' ) . '</span>'; |
| 703 |
} elseif ( 3 === intval( $item['suspended'] ) ) { |
| 704 |
$client_status = '<span class="ui red mini fluid center aligned label">' . esc_html__( 'Lost', 'mainwp' ) . '</span>'; |
| 705 |
} |
| 706 |
?> |
| 707 |
<td class="collapsing"><?php echo $client_status; //phpcs:ignore -- ok. ?></td> |
| 708 |
<?php |
| 709 |
} elseif ( 'websites' === $column_name ) { |
| 710 |
$selected_sites = isset( $item['selected_sites'] ) ? trim( $item['selected_sites'] ) : ''; |
| 711 |
$selected_ids = ( '' !== $selected_sites ) ? explode( ',', $selected_sites ) : array(); |
| 712 |
|
| 713 |
$count = count( $selected_ids ); |
| 714 |
echo "<td $attributes>"; // phpcs:ignore WordPress.Security.EscapeOutput |
| 715 |
?> |
| 716 |
<a class="item" href="admin.php?page=managesites&client=<?php echo intval( $item['client_id'] ); ?>"><?php echo intval( $count ); ?></a> |
| 717 |
<?php |
| 718 |
echo '</td>'; |
| 719 |
} elseif ( 'notes' === $column_name ) { |
| 720 |
|
| 721 |
$note = html_entity_decode( $item['note'] ); |
| 722 |
$esc_note = MainWP_Utility::esc_content( $note ); |
| 723 |
$strip_note = wp_strip_all_tags( $esc_note ); |
| 724 |
echo "<td $attributes>"; // phpcs:ignore WordPress.Security.EscapeOutput |
| 725 |
if ( empty( $item['note'] ) ) : |
| 726 |
?> |
| 727 |
<a href="javascript:void(0)" class="mainwp-edit-client-note" id="mainwp-notes-<?php echo intval( $item['client_id'] ); ?>" data-tooltip="<?php esc_attr_e( 'Edit client notes.', 'mainwp' ); ?>" data-position="left center" data-inverted=""><i class="sticky note outline icon"></i></a> |
| 728 |
<?php else : ?> |
| 729 |
<a href="javascript:void(0)" class="mainwp-edit-client-note" id="mainwp-notes-<?php echo intval( $item['client_id'] ); ?>" data-tooltip="<?php echo substr( wp_unslash( $strip_note ), 0, 100 ); // phpcs:ignore WordPress.Security.EscapeOutput ?>" data-position="left center" data-inverted=""><i class="sticky green note icon"></i></a> |
| 730 |
<?php endif; ?> |
| 731 |
<span style="display: none" id="mainwp-notes-<?php echo intval( $item['client_id'] ); ?>-note"><?php echo wp_unslash( $esc_note ); // phpcs:ignore WordPress.Security.EscapeOutput ?></span> |
| 732 |
<?php |
| 733 |
echo '</td>'; |
| 734 |
} elseif ( 'created' === $column_name ) { |
| 735 |
?> |
| 736 |
<td class="collapsing" sort-value="<?php echo intval( $item['created'] ); ?>"><?php echo esc_html( 0 !== intval( $item['created'] ) ? MainWP_Utility::format_date( $item['created'] ) : 'N/A' ); ?></td> |
| 737 |
<?php |
| 738 |
} elseif ( method_exists( $this, 'column_' . $column_name ) ) { |
| 739 |
echo "<td $attributes>"; // phpcs:ignore WordPress.Security.EscapeOutput |
| 740 |
echo call_user_func( array( $this, 'column_' . $column_name ), $item ); // phpcs:ignore WordPress.Security.EscapeOutput |
| 741 |
echo '</td>'; |
| 742 |
} else { |
| 743 |
echo "<td $attributes>"; // phpcs:ignore WordPress.Security.EscapeOutput |
| 744 |
echo $this->column_default( $item, $column_name ); // phpcs:ignore WordPress.Security.EscapeOutput |
| 745 |
echo '</td>'; |
| 746 |
} |
| 747 |
} |
| 748 |
|
| 749 |
if ( ! $compatible ) { |
| 750 |
$compatible = true; |
| 751 |
} |
| 752 |
} |
| 753 |
} |
| 754 |
|