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