diff --git a/.claude/settings.local.json b/.claude/settings.local.json deleted file mode 100644 index b7290fb..0000000 --- a/.claude/settings.local.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "permissions": { - "allow": [ - "Skill(gsd:audit-milestone)", - "WebSearch", - "Bash(wp i18n make-pot:*)" - ] - } -} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d6b130c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.claude/settings.local.json diff --git a/includes/class-cpt.php b/includes/class-cpt.php index c85cbcb..15884a1 100644 --- a/includes/class-cpt.php +++ b/includes/class-cpt.php @@ -32,7 +32,7 @@ class Umzugsliste_CPT { * Constructor */ private function __construct() { - // CPT registration is called directly from main plugin init + add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); } /** @@ -68,4 +68,164 @@ class Umzugsliste_CPT { register_post_type( 'umzugsliste_entry', $args ); } + + /** + * Register meta boxes + */ + public function add_meta_boxes() { + add_meta_box( + 'umzugsliste_entry_details', + __( 'Submission Details', 'siegel-umzugsliste' ), + array( $this, 'render_details_meta_box' ), + 'umzugsliste_entry', + 'normal', + 'high' + ); + } + + /** + * Render the submission details meta box + * + * @param WP_Post $post Current post object + */ + public function render_details_meta_box( $post ) { + $data = json_decode( $post->post_content, true ); + + if ( empty( $data ) ) { + echo '

' . esc_html__( 'No submission data found.', 'siegel-umzugsliste' ) . '

'; + return; + } + + // Meta info + $email_sent = get_post_meta( $post->ID, '_umzugsliste_email_sent', true ); + $email_time = get_post_meta( $post->ID, '_umzugsliste_email_sent_at', true ); + $total_cbm = get_post_meta( $post->ID, '_umzugsliste_total_cbm', true ); + + echo ''; + echo '
'; + + // Status bar + echo '

' . esc_html__( 'Email sent:', 'siegel-umzugsliste' ) . ' '; + echo $email_sent ? esc_html__( 'Yes', 'siegel-umzugsliste' ) : esc_html__( 'No', 'siegel-umzugsliste' ); + if ( $email_time ) { + echo ' (' . esc_html( $email_time ) . ')'; + } + echo '   ' . esc_html__( 'Total CBM:', 'siegel-umzugsliste' ) . ' ' . esc_html( $total_cbm ?: '0' ) . '

'; + + // Moving date + $date_str = ( $data['umzug_day'] ?? '' ) . '.' . ( $data['umzug_month'] ?? '' ) . '.' . ( $data['umzug_year'] ?? '' ); + echo '

' . esc_html__( 'Moving Date', 'siegel-umzugsliste' ) . '

'; + echo '

' . esc_html( $date_str ) . '

'; + + // Addresses + echo '

' . esc_html__( 'Addresses', 'siegel-umzugsliste' ) . '

'; + echo ''; + + $address_rows = array( + __( 'Name', 'siegel-umzugsliste' ) => array( 'bName', 'eName' ), + __( 'Street', 'siegel-umzugsliste' ) => array( 'bStrasse', 'eStrasse' ), + __( 'ZIP/City', 'siegel-umzugsliste' ) => array( 'bort', 'eort' ), + __( 'Phone', 'siegel-umzugsliste' ) => array( 'bTelefon', 'eTelefon' ), + ); + + foreach ( $address_rows as $label => $keys ) { + echo ''; + echo ''; + echo ''; + } + + // Info fields with proper label mapping + $info_labels = array( + 'bLift' => __( 'Elevator (Loading)', 'siegel-umzugsliste' ), + 'eLift' => __( 'Elevator (Unloading)', 'siegel-umzugsliste' ), + 'bGeschoss' => __( 'Floor (Loading)', 'siegel-umzugsliste' ), + 'eGeschoss' => __( 'Floor (Unloading)', 'siegel-umzugsliste' ), + 'eE-Mail' => __( 'Email', 'siegel-umzugsliste' ), + 'bTelefax' => __( 'Fax (Loading)', 'siegel-umzugsliste' ), + 'eTelefax' => __( 'Fax (Unloading)', 'siegel-umzugsliste' ), + 'bMobil' => __( 'Mobile (Loading)', 'siegel-umzugsliste' ), + 'eMobil' => __( 'Mobile (Unloading)', 'siegel-umzugsliste' ), + ); + + if ( ! empty( $data['info'] ) && is_array( $data['info'] ) ) { + foreach ( $data['info'] as $key => $value ) { + if ( ! empty( $value ) ) { + $label = isset( $info_labels[ $key ] ) ? $info_labels[ $key ] : $key; + echo ''; + } + } + } + + echo '
' . esc_html__( 'Loading', 'siegel-umzugsliste' ) . '' . esc_html__( 'Unloading', 'siegel-umzugsliste' ) . '
' . esc_html( $label ) . '' . esc_html( $data[ $keys[0] ] ?? '' ) . '' . esc_html( $data[ $keys[1] ] ?? '' ) . '
' . esc_html( $label ) . '' . esc_html( $value ) . '
'; + + // Furniture items + if ( class_exists( 'Umzugsliste_Furniture_Data' ) ) { + $rooms = Umzugsliste_Furniture_Data::get_rooms(); + $has_items = false; + + foreach ( $rooms as $room_key => $room_label ) { + $post_array_name = ucfirst( $room_key ); + if ( 'kueche_esszimmer' === $room_key ) { + $post_array_name = 'Kueche_Esszimmer'; + } + + $room_data = $data[ $post_array_name ] ?? array(); + $room_items = array(); + + foreach ( $room_data as $key => $value ) { + if ( substr( $key, 0, 1 ) === 'v' && ! empty( $value ) && floatval( $value ) > 0 ) { + $item_name = substr( $key, 1 ); + $quantity = $value; + $cbm = $room_data[ 'q' . $item_name ] ?? '0'; + $montage = $room_data[ 'm' . $item_name ] ?? ''; + $room_items[] = array( $item_name, $quantity, $cbm, $montage ); + } + } + + if ( ! empty( $room_items ) ) { + if ( ! $has_items ) { + echo '

' . esc_html__( 'Furniture', 'siegel-umzugsliste' ) . '

'; + echo ''; + $has_items = true; + } + + foreach ( $room_items as $item ) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + } + } + + if ( $has_items ) { + echo '
' . esc_html__( 'Room', 'siegel-umzugsliste' ) . '' . esc_html__( 'Item', 'siegel-umzugsliste' ) . '' . esc_html__( 'Qty', 'siegel-umzugsliste' ) . 'CBM' . esc_html__( 'Assembly', 'siegel-umzugsliste' ) . '
' . esc_html( $room_label ) . '' . esc_html( $item[0] ) . '' . esc_html( $item[1] ) . '' . esc_html( $item[2] ) . '' . esc_html( $item[3] ?: '-' ) . '
'; + } + } + + // Additional work + if ( ! empty( $data['additional_work'] ) && is_array( $data['additional_work'] ) ) { + echo '

' . esc_html__( 'Additional Work', 'siegel-umzugsliste' ) . '

'; + echo ''; + foreach ( $data['additional_work'] as $section => $fields ) { + if ( is_array( $fields ) ) { + foreach ( $fields as $field_key => $value ) { + if ( ! empty( $value ) ) { + echo ''; + } + } + } + } + echo '
' . esc_html( $section ) . '' . esc_html( $field_key ) . ': ' . esc_html( $value ) . '
'; + } + + // Sonstiges + if ( ! empty( $data['sonstiges'] ) ) { + echo '

' . esc_html__( 'Other', 'siegel-umzugsliste' ) . '

'; + echo '

' . esc_html( $data['sonstiges'] ) . '

'; + } + + echo '
'; + } } diff --git a/includes/class-date-helpers.php b/includes/class-date-helpers.php index 7dbd4d2..80faeb0 100644 --- a/includes/class-date-helpers.php +++ b/includes/class-date-helpers.php @@ -27,7 +27,7 @@ class Umzugsliste_Date_Helpers { $selected = (int) current_time( 'j' ); } - $html = '
'; for ( $i = 1; $i <= 31; $i++ ) { $sel = ( $i === $selected ) ? ' selected' : ''; @@ -50,7 +50,7 @@ class Umzugsliste_Date_Helpers { $selected = (int) current_time( 'n' ); } - $html = '
'; for ( $i = 1; $i <= 12; $i++ ) { $sel = ( $i === $selected ) ? ' selected' : ''; @@ -73,7 +73,7 @@ class Umzugsliste_Date_Helpers { $selected = (int) current_time( 'Y' ); } - $html = '
'; // Show current year plus 15 years (matching legacy) $current_year = (int) current_time( 'Y' ); diff --git a/includes/class-email-generator.php b/includes/class-email-generator.php index 24eabdc..b0e7001 100644 --- a/includes/class-email-generator.php +++ b/includes/class-email-generator.php @@ -27,9 +27,9 @@ class Umzugsliste_Email_Generator { // Moving date $content .= self::generate_date_section( - $data['day'] ?? '', - $data['month'] ?? '', - $data['year'] ?? '' + $data['umzug_day'] ?? '', + $data['umzug_month'] ?? '', + $data['umzug_year'] ?? '' ); // Customer info diff --git a/includes/class-form-handler.php b/includes/class-form-handler.php index b99289c..4844620 100644 --- a/includes/class-form-handler.php +++ b/includes/class-form-handler.php @@ -164,7 +164,7 @@ class Umzugsliste_Form_Handler { } // Validate date - if ( empty( $data['day'] ) || empty( $data['month'] ) || empty( $data['year'] ) ) { + if ( empty( $data['umzug_day'] ) || empty( $data['umzug_month'] ) || empty( $data['umzug_year'] ) ) { $errors[] = __( 'Moving date is missing', 'siegel-umzugsliste' ); } @@ -205,7 +205,7 @@ class Umzugsliste_Form_Handler { $sanitized = array(); // Sanitize simple text fields - $text_fields = array( 'bName', 'eName', 'bStrasse', 'eStrasse', 'bort', 'eort', 'bTelefon', 'eTelefon', 'day', 'month', 'year' ); + $text_fields = array( 'bName', 'eName', 'bStrasse', 'eStrasse', 'bort', 'eort', 'bTelefon', 'eTelefon', 'umzug_day', 'umzug_month', 'umzug_year' ); foreach ( $text_fields as $field ) { $sanitized[ $field ] = isset( $data[ $field ] ) ? sanitize_text_field( $data[ $field ] ) : ''; @@ -269,7 +269,7 @@ class Umzugsliste_Form_Handler { */ private function save_to_cpt( $data ) { $customer_name = $data['bName'] ?? 'Unbekannt'; - $date_string = ( $data['day'] ?? '' ) . '.' . ( $data['month'] ?? '' ) . '.' . ( $data['year'] ?? '' ); + $date_string = ( $data['umzug_day'] ?? '' ) . '.' . ( $data['umzug_month'] ?? '' ) . '.' . ( $data['umzug_year'] ?? '' ); // Calculate total CBM $total_cbm = 0; diff --git a/languages/siegel-umzugsliste-de_DE.mo b/languages/siegel-umzugsliste-de_DE.mo index 405e41a..4482dd3 100644 Binary files a/languages/siegel-umzugsliste-de_DE.mo and b/languages/siegel-umzugsliste-de_DE.mo differ diff --git a/languages/siegel-umzugsliste-de_DE.po b/languages/siegel-umzugsliste-de_DE.po index dd7143e..0109a46 100644 --- a/languages/siegel-umzugsliste-de_DE.po +++ b/languages/siegel-umzugsliste-de_DE.po @@ -1065,3 +1065,75 @@ msgstr "Zimmersumme" #: templates/form-page.php:41 msgid "Qty" msgstr "Anz." + +#: includes/class-cpt.php +msgid "Submission Details" +msgstr "Eingangsdetails" + +#: includes/class-cpt.php +msgid "No submission data found." +msgstr "Keine Eingangsdaten gefunden." + +#: includes/class-cpt.php +msgid "Email sent:" +msgstr "E-Mail gesendet:" + +#: includes/class-cpt.php +msgid "Total CBM:" +msgstr "Gesamt-CBM:" + +#: includes/class-cpt.php +msgid "Addresses" +msgstr "Adressen" + +#: includes/class-cpt.php +msgid "Loading" +msgstr "Beladeadresse" + +#: includes/class-cpt.php +msgid "Unloading" +msgstr "Entladeadresse" + +#: includes/class-cpt.php +msgid "Furniture" +msgstr "Möbel" + +#: includes/class-cpt.php +msgid "Room" +msgstr "Raum" + +#: includes/class-cpt.php +msgid "Item" +msgstr "Gegenstand" + +#: includes/class-cpt.php +msgid "Elevator (Loading)" +msgstr "Lift (Beladeadresse)" + +#: includes/class-cpt.php +msgid "Elevator (Unloading)" +msgstr "Lift (Entladeadresse)" + +#: includes/class-cpt.php +msgid "Floor (Loading)" +msgstr "Geschoss (Beladeadresse)" + +#: includes/class-cpt.php +msgid "Floor (Unloading)" +msgstr "Geschoss (Entladeadresse)" + +#: includes/class-cpt.php +msgid "Fax (Loading)" +msgstr "Telefax (Beladeadresse)" + +#: includes/class-cpt.php +msgid "Fax (Unloading)" +msgstr "Telefax (Entladeadresse)" + +#: includes/class-cpt.php +msgid "Mobile (Loading)" +msgstr "Mobil (Beladeadresse)" + +#: includes/class-cpt.php +msgid "Mobile (Unloading)" +msgstr "Mobil (Entladeadresse)" diff --git a/umzugsliste.php b/umzugsliste.php index 4a7e6e8..562fa70 100644 --- a/umzugsliste.php +++ b/umzugsliste.php @@ -93,6 +93,9 @@ class Umzugsliste { private function init_hooks() { add_action( 'init', array( $this, 'init' ) ); add_filter( 'template_include', array( $this, 'maybe_load_form_template' ) ); + + // Form handler must register its init hook before init fires + Umzugsliste_Form_Handler::get_instance(); } /** @@ -106,9 +109,23 @@ class Umzugsliste { return $template; } - $form_page_id = (int) get_option( 'umzugsliste_form_page_id', 0 ); + $use_standalone = false; + // Check configured form page ID + $form_page_id = (int) get_option( 'umzugsliste_form_page_id', 0 ); if ( $form_page_id > 0 && is_page( $form_page_id ) ) { + $use_standalone = true; + } + + // Fallback: check if current page contains the [umzugsliste] shortcode + if ( ! $use_standalone ) { + $post = get_queried_object(); + if ( $post && isset( $post->post_content ) && has_shortcode( $post->post_content, 'umzugsliste' ) ) { + $use_standalone = true; + } + } + + if ( $use_standalone ) { $custom_template = UMZUGSLISTE_PLUGIN_DIR . 'templates/form-page.php'; if ( file_exists( $custom_template ) ) { return $custom_template; @@ -136,9 +153,6 @@ class Umzugsliste { // Initialize shortcode Umzugsliste_Shortcode::get_instance(); - - // Initialize form handler - Umzugsliste_Form_Handler::get_instance(); } }