' . __('Do you want to delete the selected items?','teachpress') . '

' . __('Cancel','teachpress') . '

'; } // delete tags - part 2 if ( isset( $_GET['delete_ok'] ) ) { TP_Authors_Page::check_nonce_field(); TP_Authors::delete_authors($checkbox); get_tp_message( __('Removing successful','teachpress') ); } } /** * This function prints the page * @param string $action * @since 6.0.0 */ public static function get_page ($action) { $search = isset( $_GET['search'] ) ? htmlspecialchars($_GET['search']) : ''; $checkbox = isset( $_GET['checkbox'] ) ? $_GET['checkbox'] : array(); $filter = isset( $_GET['filter'] ) ? htmlspecialchars($_GET['filter']) : ''; $only_zero = ( $filter === 'only_zero' ) ? true : false; $page = 'teachpress/authors.php'; /** * Screen options */ // items per page $user = get_current_user_id(); $screen = get_current_screen(); $screen_option = $screen->get_option('per_page', 'option'); $per_page = get_user_meta($user, $screen_option, true); if ( empty ( $per_page) || $per_page < 1 ) { $per_page = $screen->get_option( 'per_page', 'default' ); } // sorting $option = get_user_meta($user, 'tp_authors_sorting', true); $order = 'a.sort_name ASC, a.name ASC'; if ( $option == 'firstname' ) { $order = 'a.name ASC, a.sort_name ASC'; } // Handle limits $number_messages = $per_page; if (isset($_GET['limit'])) { $curr_page = intval($_GET['limit']) ; if ( $curr_page <= 0 ) { $curr_page = 1; } $entry_limit = ( $curr_page - 1 ) * $number_messages; } else { $entry_limit = 0; $curr_page = 1; } echo '
'; echo '

' . __('Authors','teachpress') . '

'; echo '
'; echo ''; echo wp_nonce_field( 'verify_teachpress_author_edit', 'tp_nonce', false, false ); // actions self::actions($action, $checkbox, $page, $search, $curr_page); // Searchbox echo ''; // END Searchbox // Tablenav actions echo '
'; echo '
'; echo ''; echo ''; echo ''; echo '
'; $test = TP_Authors::get_authors_occurence( array( 'count' => true, 'search' => $search, 'only_zero' => $only_zero )); $args = array( 'number_entries' => $test, 'entries_per_page' => $number_messages, 'current_page' => $curr_page, 'entry_limit' => $entry_limit, 'page_link' => "admin.php?page=$page&", 'link_attributes' => "search=$search"); echo tp_page_menu($args); echo '
'; // END Tablenav actions // Main table echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; if ( intval($test) === 0 ) { echo ''; } else { $link = 'admin.php?page=' . $page . '&search=' . $search . '&limit=' . $curr_page . '&action=delete&filter=' . $filter; $results = TP_Authors::get_authors_occurence(array( 'search' => $search, 'limit' => $entry_limit . ',' . $number_messages, 'order' => $order, 'only_zero' => $only_zero, )); self::get_table($results, $action, $checkbox, $link); } echo ''; echo '
' . __('Name','teachpress') . '' . __('ID','teachpress') . '' . __('Number publications','teachpress') . '
' . __('Sorry, no entries matched your criteria.','teachpress') . '
'; // END Main Table // Tablenav actions echo '
'; echo '
'; if ( $test > $number_messages ) { $args = array( 'number_entries' => $test, 'entries_per_page' => $number_messages, 'current_page' => $curr_page, 'entry_limit' => $entry_limit, 'page_link' => "admin.php?page=$page&", 'link_attributes' => "search=$search", 'mode' => 'bottom'); echo tp_page_menu($args); } else { if ( $test === 1 ) { echo $test . ' ' . __('entry','teachpress'); } else { echo $test . ' ' . __('entries','teachpress'); } } echo '
'; echo '
'; // END Tablenav actions echo '
'; self::print_scripts(); echo '
'; } /** * Prints the authors table * @param array $results * @param string action * @param array $checkbox * @param string link * @since 6.0.0 * @access private */ private static function get_table ($results, $action, $checkbox, $link) { $class_alternate = true; foreach ( $results as $row ) { // Alternate line style if ( $class_alternate === true ) { $tr_class = 'alternate'; $class_alternate = false; } else { $tr_class = ''; $class_alternate = true; } $checked = ''; if ( $action === "delete") { $checked = in_array($row['author_id'], $checkbox ) ? 'checked="checked"' : ''; } TP_HTML::line(''); TP_HTML::line(''); TP_HTML::line('' . TP_Bibtex::parse_author_simple($row['name']) . ''); // Row actions TP_HTML::line('
'); TP_HTML::line('' . __('Delete', 'teachpress') . ''); TP_HTML::line('
'); // END Row actions TP_HTML::line(''); TP_HTML::line('' . $row['author_id'] . ''); TP_HTML::line('' . $row['count'] . ''); TP_HTML::line(''); } } /** * Adds the screen options (items per page, authors_sorting) * @global string $tp_admin_show_authors_page * @since 8.1 */ public static function add_screen_options() { global $tp_admin_show_authors_page; $screen = get_current_screen(); if( !is_object($screen) || $screen->id != $tp_admin_show_authors_page ) { return; } $args = array( 'label' => __('Items per page', 'teachpress'), 'default' => 50, 'option' => 'tp_authors_per_page' ); add_screen_option( 'per_page', $args ); $args = array( 'default' => 'lastname', 'option' => 'tp_authors_sorting' ); add_screen_option( 'tp_authors_sorting', $args ); } /** * Prints the custom screen options fo this page * @since 8.1 */ public static function print_screen_options() { $user = get_current_user_id(); $option = get_user_meta($user, 'tp_authors_sorting', true); $value = ( $option ) ? $option : 'lastname'; // Available options $options[] = array( 'key' => 'firstname', 'label' => __('First name', 'teachpress') ); $options[] = array( 'key' => 'lastname', 'label' => __('Last name', 'teachpress') ); $r = '
'; $r .= ''; return $r; } /** * Saves the custom screen options * @since 8.1 */ public static function save_screen_options () { $sorting = htmlspecialchars($_POST['tp_authors_sorting']); if ( $sorting === 'firstname' || $sorting === 'lastname' ) { update_user_meta(get_current_user_id(), 'tp_authors_sorting', $sorting); } } /** * Checks the nonce field of the form. If the check fails wp_die() will be executed * @since 9.0.5 */ private static function check_nonce_field () { if ( ! isset( $_GET['tp_nonce'] ) || ! wp_verify_nonce( $_GET['tp_nonce'], 'verify_teachpress_author_edit' ) ) { wp_die('teachPress error: This request could not be verified!'); exit; } } /** * Prints js scripts for the page * @since 6.0.0 */ private static function print_scripts () { ?>