%s group has been created.", 'groups' ), stripslashes( wp_filter_nohtml_kses( $group->name ) ) ) ); } break; case 'edit' : if ( !( $group_id = groups_admin_groups_edit_submit() ) ) { return groups_admin_groups_edit( $_POST['group-id-field'] ); } else { $group = Groups_Group::read( $group_id ); Groups_Admin::add_message( sprintf( __( 'The %s group has been updated.', 'groups' ), stripslashes( wp_filter_nohtml_kses( $group->name ) ) ) ); } break; case 'remove' : if ( $group_id = groups_admin_groups_remove_submit() ) { Groups_Admin::add_message( __( 'The group has been deleted.', 'groups' ) ); } break; // bulk actions on groups: add capabilities, remove capabilities, remove groups case 'groups-action' : if ( wp_verify_nonce( $_POST[GROUPS_ADMIN_GROUPS_ACTION_NONCE], 'admin' ) ) { $group_ids = isset( $_POST['group_ids'] ) ? $_POST['group_ids'] : null; $bulk_action = null; if ( isset( $_POST['bulk'] ) ) { $bulk_action = $_POST['bulk-action']; } if ( is_array( $group_ids ) && ( $bulk_action !== null ) ) { foreach ( $group_ids as $group_id ) { switch ( $bulk_action ) { case 'add-capability' : $capabilities_id = isset( $_POST['capability_id'] ) ? $_POST['capability_id'] : null; if ( $capabilities_id !== null ) { foreach ( $capabilities_id as $capability_id ) { Groups_Group_Capability::create( array( 'group_id' => $group_id, 'capability_id' => $capability_id ) ); } } break; case 'remove-capability' : $capabilities_id = isset( $_POST['capability_id'] ) ? $_POST['capability_id'] : null; if ( $capabilities_id !== null ) { foreach ( $capabilities_id as $capability_id ) { Groups_Group_Capability::delete( $group_id, $capability_id ); } } break; case 'remove-group' : $bulk_confirm = isset( $_POST['confirm'] ) ? true : false; if ( $bulk_confirm ) { groups_admin_groups_bulk_remove_submit(); } else { return groups_admin_groups_bulk_remove(); } break; } } } } break; } } else if ( isset ( $_GET['action'] ) ) { // handle action request - show form switch( $_GET['action'] ) { case 'add' : return groups_admin_groups_add(); break; case 'edit' : if ( isset( $_GET['group_id'] ) ) { return groups_admin_groups_edit( $_GET['group_id'] ); } break; case 'remove' : if ( isset( $_GET['group_id'] ) ) { return groups_admin_groups_remove( $_GET['group_id'] ); } break; } } // // group table // if ( isset( $_POST['clear_filters'] ) || isset( $_POST['group_id'] ) || isset( $_POST['group_name'] ) ) { if ( !wp_verify_nonce( $_POST[GROUPS_ADMIN_GROUPS_FILTER_NONCE], 'admin' ) ) { wp_die( __( 'Access denied.', 'groups' ) ); } } // filters $group_id = Groups_Options::get_user_option( 'groups_group_id', null ); $group_name = Groups_Options::get_user_option( 'groups_group_name', null ); if ( isset( $_POST['clear_filters'] ) ) { Groups_Options::delete_user_option( 'groups_group_id' ); Groups_Options::delete_user_option( 'groups_group_name' ); $group_id = null; $group_name = null; } else if ( isset( $_POST['submitted'] ) ) { // filter by name if ( !empty( $_POST['group_name'] ) ) { $group_name = $_POST['group_name']; Groups_Options::update_user_option( 'groups_group_name', $group_name ); } // filter by group id if ( !empty( $_POST['group_id'] ) ) { $group_id = intval( $_POST['group_id'] ); Groups_Options::update_user_option( 'groups_group_id', $group_id ); } else if ( isset( $_POST['group_id'] ) ) { // empty && isset => '' => all $group_id = null; Groups_Options::delete_user_option( 'groups_group_id' ); } } if ( isset( $_POST['row_count'] ) ) { if ( !wp_verify_nonce( $_POST[GROUPS_ADMIN_GROUPS_NONCE_1], 'admin' ) ) { wp_die( __( 'Access denied.', 'groups' ) ); } } if ( isset( $_POST['paged'] ) ) { if ( !wp_verify_nonce( $_POST[GROUPS_ADMIN_GROUPS_NONCE_2], 'admin' ) ) { wp_die( __( 'Access denied.', 'groups' ) ); } } $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $current_url = remove_query_arg( 'paged', $current_url ); $current_url = remove_query_arg( 'action', $current_url ); $current_url = remove_query_arg( 'group_id', $current_url ); $group_table = _groups_get_tablename( 'group' ); $output .= '
' . '

' . _x( 'Groups', 'page-title', 'groups' ) . sprintf( '', esc_attr( __( 'Click to add a new group', 'groups' ) ), esc_url( $current_url . '&action=add' ) ) . sprintf( '%s', esc_attr( __( 'Add', 'groups' ) ), esc_url( GROUPS_PLUGIN_URL . 'images/add.png' ) ) . sprintf( '%s', stripslashes( wp_filter_nohtml_kses( __( 'New Group', 'groups' ) ) ) ) . '' . '

'; $output .= Groups_Admin::render_messages(); $row_count = isset( $_POST['row_count'] ) ? intval( $_POST['row_count'] ) : 0; if ($row_count <= 0) { $row_count = Groups_Options::get_user_option( 'groups_per_page', GROUPS_GROUPS_PER_PAGE ); } else { Groups_Options::update_user_option('groups_per_page', $row_count ); } $offset = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0; if ( $offset < 0 ) { $offset = 0; } $paged = isset( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 0; if ( $paged < 0 ) { $paged = 0; } $orderby = isset( $_GET['orderby'] ) ? $_GET['orderby'] : null; switch ( $orderby ) { case 'group_id' : case 'name' : case 'description' : break; default: $orderby = 'name'; } $order = isset( $_GET['order'] ) ? $_GET['order'] : null; switch ( $order ) { case 'asc' : case 'ASC' : $switch_order = 'DESC'; break; case 'desc' : case 'DESC' : $switch_order = 'ASC'; break; default: $order = 'ASC'; $switch_order = 'DESC'; } $filters = array( " 1=%d " ); $filter_params = array( 1 ); if ( $group_id ) { $filters[] = " $group_table.group_id = %d "; $filter_params[] = $group_id; } if ( $group_name ) { $filters[] = " $group_table.name LIKE '%%%s%%' "; $filter_params[] = $group_name; } if ( !empty( $filters ) ) { $filters = " WHERE " . implode( " AND ", $filters ); } else { $filters = ''; } $count_query = $wpdb->prepare( "SELECT COUNT(*) FROM $group_table $filters", $filter_params ); $count = $wpdb->get_var( $count_query ); if ( $count > $row_count ) { $paginate = true; } else { $paginate = false; } $pages = ceil ( $count / $row_count ); if ( $paged > $pages ) { $paged = $pages; } if ( $paged != 0 ) { $offset = ( $paged - 1 ) * $row_count; } $query = $wpdb->prepare( "SELECT * FROM $group_table $filters ORDER BY $orderby $order LIMIT $row_count OFFSET $offset", $filter_params ); $results = $wpdb->get_results( $query, OBJECT ); $column_display_names = array( 'group_id' => __( 'ID', 'groups' ), 'name' => __( 'Group', 'groups' ), 'description' => __( 'Description', 'groups' ), 'capabilities' => __( 'Capabilities', 'groups' ) ); $output .= '
'; $output .= '
' . '
' . '
' . '' . __( 'Filters', 'groups' ) . '' . '' . ' ' . '' . ' ' . wp_nonce_field( 'admin', GROUPS_ADMIN_GROUPS_FILTER_NONCE, true, false ) . '' . ' ' . '' . '' . '
' . '
' . '
'; if ( $paginate ) { require_once( GROUPS_CORE_LIB . '/class-groups-pagination.php' ); $pagination = new Groups_Pagination( $count, null, $row_count ); $output .= '
'; $output .= '
'; $output .= wp_nonce_field( 'admin', GROUPS_ADMIN_GROUPS_NONCE_2, true, false ); $output .= '
'; $output .= '
'; $output .= $pagination->pagination( 'top' ); $output .= '
'; $output .= '
'; } $output .= '
'; $output .= '
'; $output .= '
'; $output .= ''; $output .= ''; $output .= wp_nonce_field( 'admin', GROUPS_ADMIN_GROUPS_NONCE_1, true, false ); $output .= ''; $output .= '
'; $output .= '
'; $output .= '
'; $capability_table = _groups_get_tablename( "capability" ); $group_capability_table = _groups_get_tablename( "group_capability" ); // capabilities select $capabilities = $wpdb->get_results( "SELECT * FROM $capability_table ORDER BY capability" ); $capabilities_select = sprintf( ''; $capabilities_select .= Groups_UIE::render_select( '.select.capability' ); $output .= '
'; $output .= '
'; $output .= '
'; $output .= '
'; $output .= $capabilities_select; $output .= wp_nonce_field( 'admin', GROUPS_ADMIN_GROUPS_ACTION_NONCE, true, false ); $output .= '
'; $output .= ''; $output .= sprintf( '', esc_attr( __( 'Apply', 'groups' ) ) ); $output .= ''; $output .= '
'; $output .= '
'; $output .= ''; $output .= ''; $output .= ''; $output .= ''; foreach ( $column_display_names as $key => $column_display_name ) { $options = array( 'orderby' => $key, 'order' => $switch_order ); $class = $key; if ( !in_array( $key, array( 'capabilities' ) ) ) { if ( strcmp( $key, $orderby ) == 0 ) { $lorder = strtolower( $order ); $class = "$key manage-column sorted $lorder"; } else { $class = "$key manage-column sortable"; } $column_display_name = sprintf( '%s', esc_url( add_query_arg( $options, $current_url ) ), esc_html( $column_display_name ) ); } else { $column_display_name = esc_html( $column_display_name ); } $output .= sprintf( '', esc_attr( $class ), $column_display_name ); } $output .= ''; $output .= ''; $output .= ''; if ( count( $results ) > 0 ) { for ( $i = 0; $i < count( $results ); $i++ ) { $result = $results[$i]; // Construct the "edit" URL. $edit_url = add_query_arg( array( 'group_id' => intval( $result->group_id ), 'action' => 'edit', 'paged' => $paged ), $current_url ); // Construct the "delete" URL. $delete_url = add_query_arg( array( 'group_id' => intval( $result->group_id ), 'action' => 'remove', 'paged' => $paged ), $current_url ); // Construct row actions for this group. $row_actions = '
' . '' . '' . '' . __( 'Edit', 'groups' ) . ''; if ( $result->name !== Groups_Registered::REGISTERED_GROUP_NAME ) { $row_actions .= ' | ' . '' . '' . '' . '' . __( 'Remove', 'groups' ) . '' . ''; } $row_actions .= '
'; // .row-actions $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; } } else { $output .= ''; } $output .= ''; $output .= '
%s
'; $output .= ''; $output .= ''; $output .= $result->group_id; $output .= ''; $output .= sprintf( '%s', esc_url( $edit_url ), stripslashes( wp_filter_nohtml_kses( $result->name ) ) ); $output .= $row_actions; $output .= ''; $output .= stripslashes( wp_filter_nohtml_kses( $result->description ) ); $output .= ''; $group = new Groups_Group( $result->group_id ); $group_capabilities = $group->capabilities; $group_capabilities_deep = $group->capabilities_deep; usort( $group_capabilities_deep, array( 'Groups_Utility', 'cmp' ) ); if ( count( $group_capabilities_deep ) > 0 ) { $output .= '
    '; foreach ( $group_capabilities_deep as $group_capability ) { $output .= '
  • '; $class = ''; if ( empty( $group_capabilities ) || !in_array( $group_capability, $group_capabilities ) ) { $class = 'inherited'; } $output .= sprintf( '', $class ); if ( isset( $group_capability->capability ) && isset( $group_capability->capability->capability ) ) { $output .= wp_filter_nohtml_kses( $group_capability->capability->capability ); } $output .= ''; $output .= '
  • '; } $output .= '
'; } else { $output .= __( 'This group has no capabilities.', 'groups' ); } $output .= '
' . __( 'There are no results.', 'groups' ) . '
'; $output .= Groups_UIE::render_add_titles( '.groups-overview table td' ); $output .= '
'; // #groups-action if ( $paginate ) { require_once( GROUPS_CORE_LIB . '/class-groups-pagination.php' ); $pagination = new Groups_Pagination($count, null, $row_count); $output .= '
'; $output .= $pagination->pagination( 'bottom' ); $output .= '
'; } $output .= '
'; // .groups-overview $output .= '
'; // .manage-groups echo $output; } // function groups_admin_groups()