prefix . 'school_teachers'; // Bulk delete handler if ( isset( $_POST['bulk_action'] ) && 'delete' === $_POST['bulk_action'] && !empty( $_POST['teacher_ids'] ) ) { check_admin_referer( 'schoolslots_bulk_teachers_action_nonce' ); $t_ids = array_map( 'intval', (array) wp_unslash( $_POST['teacher_ids'] ) ); $del_cnt = 0; foreach ( $t_ids as $tid ) { if ( $wpdb->delete( $table, array( 'id' => $tid, ) ) ) { ++$del_cnt; } } if ( $del_cnt > 0 ) { /* translators: %d: number of teachers deleted */ $del_msg = sprintf( _n( '%d teacher deleted successfully.', '%d teachers deleted successfully.', (int) $del_cnt, 'schoolslots' ), (int) $del_cnt ); echo '

' . esc_html( $del_msg ) . '

'; } } $edit_teacher = ( isset( $_GET['edit'] ) ? $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$table} WHERE id = %d", intval( $_GET['edit'] ) ) ) : null ); if ( isset( $_POST['schoolslots_save_teacher'] ) ) { check_admin_referer( 'schoolslots_teacher_nonce' ); $name = ( isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '' ); $email = ( isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : '' ); $room_number = ( isset( $_POST['room_number'] ) ? sanitize_text_field( wp_unslash( $_POST['room_number'] ) ) : '' ); $raw_day = ( isset( $_POST['consultation_day'] ) ? sanitize_text_field( wp_unslash( $_POST['consultation_day'] ) ) : '' ); $consultation_day = ucfirst( mb_strtolower( trim( $raw_day ) ) ); $consultation_period = ( isset( $_POST['consultation_period'] ) ? sanitize_text_field( wp_unslash( $_POST['consultation_period'] ) ) : '' ); $consultation_start = ( !empty( $_POST['consultation_start'] ) ? sanitize_text_field( wp_unslash( $_POST['consultation_start'] ) ) : null ); $consultation_end = ( !empty( $_POST['consultation_end'] ) ? sanitize_text_field( wp_unslash( $_POST['consultation_end'] ) ) : null ); $break_start = ( !empty( $_POST['break_start'] ) ? sanitize_text_field( wp_unslash( $_POST['break_start'] ) ) : null ); $break_end = ( !empty( $_POST['break_end'] ) ? sanitize_text_field( wp_unslash( $_POST['break_end'] ) ) : null ); $buffer_minutes = ( isset( $_POST['buffer_minutes'] ) ? intval( $_POST['buffer_minutes'] ) : 0 ); $t_id = ( isset( $_POST['teacher_id'] ) ? intval( $_POST['teacher_id'] ) : 0 ); $user = get_user_by( 'email', $email ); $user_id = ( $user ? $user->ID : 0 ); if ( !empty( $name ) && !empty( $email ) ) { $data_array = compact( 'user_id', 'name', 'email', 'room_number', 'consultation_day', 'consultation_period', 'consultation_start', 'consultation_end', 'break_start', 'break_end', 'buffer_minutes' ); if ( $t_id > 0 ) { $wpdb->update( $table, $data_array, array( 'id' => $t_id, ) ); echo '

' . esc_html__( 'Teacher updated successfully.', 'schoolslots' ) . '

'; $edit_teacher = null; } else { $wpdb->insert( $table, $data_array ); echo '

' . esc_html__( 'Teacher added successfully.', 'schoolslots' ) . '

'; } } } if ( isset( $_GET['delete'] ) ) { $del_t_id = intval( $_GET['delete'] ); check_admin_referer( 'schoolslots_delete_teacher_' . $del_t_id ); $wpdb->delete( $table, array( 'id' => $del_t_id, ) ); echo '

' . esc_html__( 'Teacher deleted successfully.', 'schoolslots' ) . '

'; } $t_orderby = ( isset( $_GET['t_orderby'] ) ? sanitize_text_field( wp_unslash( $_GET['t_orderby'] ) ) : 'name' ); $t_order = ( isset( $_GET['t_order'] ) && 'DESC' === strtoupper( sanitize_text_field( wp_unslash( $_GET['t_order'] ) ) ) ? 'DESC' : 'ASC' ); $allowed_t_cols = array( 'name' => 'name', 'email' => 'email', 'room_number' => 'room_number', 'subjects' => 'subjects', 'consultation_day' => 'consultation_day', 'consultation_start' => 'consultation_start', ); $order_sql = ( isset( $allowed_t_cols[$t_orderby] ) ? $allowed_t_cols[$t_orderby] : 'name' ); $teachers = $wpdb->get_results( "SELECT * FROM {$table} ORDER BY {$order_sql} {$t_order}" ); ?>

'schoolslots-teachers', 'delete' => $t->id, ), admin_url( 'admin.php' ) ); $delete_url = wp_nonce_url( $delete_raw_url, 'schoolslots_delete_teacher_' . $t->id ); ?>
name ); ?> email ); ?> room_number ) ) { /* translators: %s: Room designation or number */ echo esc_html( sprintf( __( 'Room: %s', 'schoolslots' ), $t->room_number ) ); } else { echo '-'; } ?> consultation_day . ' ' . $t->consultation_period ); ?> consultation_start && $t->consultation_end ? substr( $t->consultation_start, 0, 5 ) . '-' . substr( $t->consultation_end, 0, 5 ) : '-' ) ); ?> break_start && $t->break_end ? substr( $t->break_start, 0, 5 ) . '-' . substr( $t->break_end, 0, 5 ) : '-' ) ); ?> buffer_minutes ) ) { /* translators: %d: Buffer time in minutes */ echo esc_html( sprintf( __( '%d min', 'schoolslots' ), (int) $t->buffer_minutes ) ); } else { echo '0'; } ?> ✏️ 🗑️