= 1 && class_exists( 'ADVK_Winners' ) ) { if ( $flag ) { ADVK_Winners::set_prize_for_winner( $entry_day, $entry, $prize ); } else { ADVK_Winners::clear_prize_for_winner( $entry_day, $entry ); } } } $day = isset( $_POST['advk_day'] ) ? (int) $_POST['advk_day'] : 0; $paged = isset( $_POST['paged'] ) ? max( 1, (int) $_POST['paged'] ) : 1; $url = add_query_arg( array( 'page' => 'advk-entries', 'cal' => $this->current_calendar(), 'advk_day' => $day, 'paged' => $paged, 'advk_notice' => $flag ? 'won' : 'unwon', ), admin_url( 'admin.php' ) ); wp_safe_redirect( $url ); exit; } /** * Manually create a participation entry from the admin * (admin-post.php?action=advk_add_entry). */ public function add_entry() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Keine Berechtigung.', 'adventura-interactive-advent-calendar' ) ); } check_admin_referer( 'advk_add_entry' ); $opts = ADVK_Settings::get_options(); $cal = $this->current_calendar(); $day = isset( $_POST['advk_new_day'] ) ? (int) $_POST['advk_new_day'] : 0; $first = sanitize_text_field( wp_unslash( $_POST['advk_new_first'] ?? '' ) ); $last = sanitize_text_field( wp_unslash( $_POST['advk_new_last'] ?? '' ) ); $email = sanitize_email( wp_unslash( $_POST['advk_new_email'] ?? '' ) ); $consent = ! empty( $_POST['advk_new_consent'] ); $send_mail = ! empty( $_POST['advk_new_sendmail'] ); $amount = isset( $_POST['advk_new_donation'] ) ? (float) str_replace( ',', '.', (string) wp_unslash( $_POST['advk_new_donation'] ) ) : 0; $notice = 'added'; if ( $day < 1 || $day > ADVK_Data::door_count( $cal ) || '' === $first || ! is_email( $email ) ) { $notice = 'add_error'; } elseif ( ! empty( $opts['prevent_duplicates'] ) && ADVK_Entries::email_exists_for_day( $email, $day, $cal ) ) { $notice = 'add_dupe'; } if ( 'added' === $notice ) { $losnr = 'ADV-' . str_pad( (string) $day, 2, '0', STR_PAD_LEFT ) . '-' . wp_rand( 1000, 9999 ); $ref_code = ! empty( $opts['referral_enabled'] ) ? ADVK_Entries::generate_ref_code() : ''; // Pro: collect the extra form fields, sanitised per declared type. $extra_defs = class_exists( 'ADVK_Shortcode' ) ? ADVK_Shortcode::extra_fields() : array(); $extra_vals = array(); if ( ! empty( $extra_defs ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitised per field type below; nonce verified above. $raw = isset( $_POST['advk_extra'] ) ? (array) wp_unslash( $_POST['advk_extra'] ) : array(); foreach ( $extra_defs as $xkey => $xdef ) { $val = isset( $raw[ $xkey ] ) ? $raw[ $xkey ] : ''; switch ( $xdef['type'] ) { case 'checkbox': $val = ( $val && 'false' !== $val && '0' !== $val ) ? '1' : ''; break; case 'email': $val = sanitize_email( (string) $val ); break; case 'number': $val = is_numeric( $val ) ? (string) ( $val + 0 ) : ''; break; case 'textarea': $val = sanitize_textarea_field( (string) $val ); break; case 'select': $val = (string) $val; if ( ! empty( $xdef['options'] ) && ! in_array( $val, $xdef['options'], true ) ) { $val = ''; } break; default: $val = sanitize_text_field( (string) $val ); } if ( '' !== $val ) { $extra_vals[ $xkey ] = $val; } } } $id = ADVK_Entries::insert( array( 'day' => $day, 'calendar' => $cal, 'first_name' => $first, 'last_name' => $last, 'email' => $email, 'consent' => $consent, 'losnr' => $losnr, 'answers' => array(), 'social' => array(), 'correct_count' => 0, 'total_questions' => 0, 'ref_code' => $ref_code, 'referred_by' => '', 'ip' => '', 'consent_ref' => __( 'Manuell im Admin angelegt', 'adventura-interactive-advent-calendar' ), 'extra_fields' => ! empty( $extra_vals ) ? wp_json_encode( $extra_vals ) : '', ) ); if ( $id ) { if ( $amount > 0 ) { ADVK_Entries::set_donation( $id, $amount ); } if ( $send_mail ) { // Fire the standard hook so the participant confirmation (and any // admin notification) is sent. No newsletter/reminder opt-in here. $extra = array( 'first' => $first, 'last' => $last, 'newsletter' => false, 'reminder' => false, 'ref' => '', ); do_action( 'advk_entry_created', $id, $day, $email, $losnr, $extra ); } } else { $notice = 'add_error'; } } $url = add_query_arg( array( 'page' => 'advk-entries', 'cal' => $cal, 'advk_day' => ( 'added' === $notice ) ? $day : 0, 'advk_notice' => $notice, ), admin_url( 'admin.php' ) ); wp_safe_redirect( $url ); exit; } /** * Record a donation amount for an entry (admin-post.php?action=advk_save_donation). */ public function save_donation() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Keine Berechtigung.', 'adventura-interactive-advent-calendar' ) ); } $entry = isset( $_POST['entry'] ) ? (int) $_POST['entry'] : 0; check_admin_referer( 'advk_save_donation_' . $entry ); $amount = isset( $_POST['amount'] ) ? (float) str_replace( ',', '.', (string) wp_unslash( $_POST['amount'] ) ) : 0; if ( $entry ) { ADVK_Entries::set_donation( $entry, $amount ); } $day = isset( $_POST['advk_day'] ) ? (int) $_POST['advk_day'] : 0; $paged = isset( $_POST['paged'] ) ? max( 1, (int) $_POST['paged'] ) : 1; $url = add_query_arg( array( 'page' => 'advk-entries', 'cal' => $this->current_calendar(), 'advk_day' => $day, 'paged' => $paged ), admin_url( 'admin.php' ) ); wp_safe_redirect( $url ); exit; } /** * Handle deletion of a single entry (admin-post.php?action=advk_delete_entry). */ public function delete_entry() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Keine Berechtigung.', 'adventura-interactive-advent-calendar' ) ); } $id = isset( $_GET['entry'] ) ? (int) $_GET['entry'] : 0; check_admin_referer( 'advk_delete_entry_' . $id ); $deleted = $id > 0 ? ADVK_Entries::delete( $id ) : false; $redirect = add_query_arg( array( 'page' => 'advk-entries', 'cal' => $this->current_calendar(), 'advk_day' => isset( $_GET['advk_day'] ) ? (int) $_GET['advk_day'] : 0, 'paged' => isset( $_GET['paged'] ) ? max( 1, (int) $_GET['paged'] ) : 1, 'advk_notice' => $deleted ? 'deleted' : 'delete_failed', ), admin_url( 'admin.php' ) ); wp_safe_redirect( $redirect ); exit; } public function add_menu() { add_submenu_page( ADVK_Dashboard::SLUG, __( 'Teilnahmen', 'adventura-interactive-advent-calendar' ), __( 'Teilnahmen', 'adventura-interactive-advent-calendar' ), 'manage_options', 'advk-entries', array( $this, 'render_page' ) ); } /** * Map of day => quiz (with correct indices + option text). Cached per request. * * @return array */ private function quiz_map( $cal = '' ) { static $map = null; if ( null !== $map ) { return $map; } $map = array(); foreach ( ADVK_Data::get_calendar( $cal ) as $d ) { $map[ (int) $d['day'] ] = isset( $d['quiz'] ) ? (array) $d['quiz'] : array(); } return $map; } /** * Map of day => list of prize titles (for the manual winner prize picker). * Cached per request. * * @return array */ private function prizes_map( $cal = '' ) { static $map = null; if ( null !== $map ) { return $map; } $map = array(); foreach ( ADVK_Data::get_calendar( $cal ) as $d ) { $titles = array(); if ( ! empty( $d['prizes'] ) && is_array( $d['prizes'] ) ) { foreach ( $d['prizes'] as $p ) { $t = isset( $p['title'] ) ? trim( (string) $p['title'] ) : ''; if ( '' !== $t ) { $titles[] = $t; } } } $map[ (int) $d['day'] ] = $titles; } return $map; } public function render_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $opts = ADVK_Settings::get_options(); $cal = $this->current_calendar(); $door_count = ADVK_Data::door_count( $cal ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only list filter via bookmarkable GET link; page is capability-guarded above. $day_filter = isset( $_GET['advk_day'] ) ? (int) $_GET['advk_day'] : 0; if ( $day_filter < 1 || $day_filter > $door_count ) { $day_filter = 0; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only search via GET; page is capability-guarded above. $search = isset( $_GET['advk_s'] ) ? sanitize_text_field( wp_unslash( $_GET['advk_s'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only pagination via GET; page is capability-guarded above. $paged = isset( $_GET['paged'] ) ? max( 1, (int) $_GET['paged'] ) : 1; $per_page = 25; $offset = ( $paged - 1 ) * $per_page; $total = ADVK_Entries::count( $day_filter, $cal, $search ); $entries = ADVK_Entries::query( array( 'per_page' => $per_page, 'offset' => $offset, 'day' => $day_filter, 'calendar' => $cal, 'search' => $search, ) ); $total_pages = max( 1, (int) ceil( $total / $per_page ) ); $quiz_map = $this->quiz_map( $cal ); $prizes_map = $this->prizes_map( $cal ); $cal_stats = ADVK_Entries::stats( $cal ); $export_url = wp_nonce_url( add_query_arg( array( 'cal' => $cal, 'advk_day' => $day_filter, 'advk_s' => $search ), admin_url( 'admin-post.php?action=advk_export' ) ), 'advk_export' ); ?>
losnr ); ?>
·
—