admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'tsfs_admin_nonce' ), ) ); $screen_scripts = array( 'tsfs-entries' => 'tsfs-entries', 'tsfs-forms' => 'tsfs-forms-list', 'tsfs-settings' => 'tsfs-settings', ); if ( isset( $screen_scripts[ $page ] ) ) { $handle = $screen_scripts[ $page ] . '-js'; wp_enqueue_script( $handle, TSFS_URL . 'admin/assets/js/' . $screen_scripts[ $page ] . '.js', array( 'jquery', 'wp-i18n', 'tsfs-admin-js' ), TSFS_VERSION, true ); wp_set_script_translations( $handle, 'techsolution-form-studio' ); } if ( 'tsfs-builder' !== $page ) { return; } TSFS_Public::register_assets(); wp_enqueue_editor(); // Visual editor for section notes. wp_enqueue_style( 'tsfs-country-css' ); wp_enqueue_script( 'tsfs-country-js' ); wp_enqueue_script( 'tsfs-builder-js', TSFS_URL . 'admin/assets/js/tsfs-builder.js', array( 'jquery', 'tsfs-admin-js', 'tsfs-country-js' ), TSFS_VERSION, true ); $form_id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $current_form = $form_id ? TSFS_DB::get_form( $form_id ) : null; wp_localize_script( 'tsfs-builder-js', 'tsfsBuilderData', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'tsfs_admin_nonce' ), 'countries' => TSFS_Form::get_countries(), 'field_types' => TSFS_Form::get_supported_field_types(), 'core_types' => TSFS_Form::get_core_field_types(), 'form' => $current_form, 'forms_list_url' => admin_url( 'admin.php?page=tsfs-forms' ), 'max_upload_mb' => max( 1, (int) floor( wp_max_upload_size() / MB_IN_BYTES ) ), 'i18n' => array( 'preview_title' => __( 'Form preview', 'techsolution-form-studio' ), 'preview_description' => __( 'Test your form before publishing. Preview submissions are not saved.', 'techsolution-form-studio' ), 'preview_fields' => __( 'fields', 'techsolution-form-studio' ), /* translators: %shown% and %total% are replaced in the browser with the number of matching and total fields. Keep both tokens. */ 'outline_count' => __( '%shown% of %total% fields', 'techsolution-form-studio' ), 'outline_empty' => __( 'Your form has no fields. Choose Add fields to get started.', 'techsolution-form-studio' ), 'outline_no_matches' => __( 'No fields match. Try a different label or field type.', 'techsolution-form-studio' ), 'outline_required' => __( 'Required', 'techsolution-form-studio' ), 'outline_conditions' => __( 'Conditional', 'techsolution-form-studio' ), 'outline_untitled' => __( 'Untitled field', 'techsolution-form-studio' ), 'field_position' => __( 'Field %position% of %total%', 'techsolution-form-studio' ), 'country_label' => __( 'Country', 'techsolution-form-studio' ), 'nationality_label' => __( 'Nationality (country)', 'techsolution-form-studio' ), 'country_placeholder' => __( 'Select a country', 'techsolution-form-studio' ), 'country_find' => __( 'Find a country', 'techsolution-form-studio' ), 'country_search' => __( 'Type a country name…', 'techsolution-form-studio' ), 'country_info' => __( 'The country list is included automatically. Change the label to ask for country of residence or nationality. Answers are saved as country names.', 'techsolution-form-studio' ), 'unavailable_type' => __( 'This field type is provided by an add-on that is not active. It is kept in the form but not shown to visitors.', 'techsolution-form-studio' ), 'status_saved' => __( 'All changes saved', 'techsolution-form-studio' ), 'status_unsaved' => __( 'Unsaved changes', 'techsolution-form-studio' ), 'status_saving' => __( 'Saving…', 'techsolution-form-studio' ), 'status_error' => __( 'Save failed — try again', 'techsolution-form-studio' ), 'save_success' => __( 'Form saved successfully!', 'techsolution-form-studio' ), 'save_error' => __( 'Error saving form.', 'techsolution-form-studio' ), 'confirm_del' => __( 'Are you sure you want to remove this field?', 'techsolution-form-studio' ), 'copied' => __( 'Copied to clipboard!', 'techsolution-form-studio' ), ), ) ); /** * Fires after the builder scripts are enqueued, so add-ons can extend the builder. */ do_action( 'tsfs_enqueue_builder_assets' ); } /** * Render the plugin home dashboard. */ public function render_dashboard_page() { $forms = TSFS_DB::get_forms(); include TSFS_DIR . 'admin/views/dashboard.php'; } /** * Render the Forms List page. */ public function render_forms_list_page() { $forms = TSFS_DB::get_forms(); include TSFS_DIR . 'admin/views/forms-list.php'; } /** * Render the Visual Form Builder page. */ // phpcs:disable WordPress.Security.NonceVerification.Recommended -- the screens below only read GET values to choose what to display; every change goes through nonce-checked AJAX actions. public function render_form_builder_page() { $form_id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : 0; $form = $form_id ? TSFS_DB::get_form( $form_id ) : null; include TSFS_DIR . 'admin/views/form-builder.php'; } /** * Render the Submissions / Entries page. */ public function render_entries_page() { $selected_form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0; $status = isset( $_GET['status'] ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : ''; $date_from = isset( $_GET['date_from'] ) ? sanitize_text_field( wp_unslash( $_GET['date_from'] ) ) : ''; $date_to = isset( $_GET['date_to'] ) ? sanitize_text_field( wp_unslash( $_GET['date_to'] ) ) : ''; $search = isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : ''; $paged = isset( $_GET['paged'] ) ? max( 1, absint( $_GET['paged'] ) ) : 1; $per_page = isset( $_GET['per_page'] ) ? absint( $_GET['per_page'] ) : 20; if ( ! in_array( $per_page, array( 10, 20, 50, 100 ), true ) ) { $per_page = 20; } $filters = array( 'form_id' => $selected_form_id, 'status' => $status, 'date_from' => $date_from, 'date_to' => $date_to, 'search' => $search, ); $total_entries = TSFS_DB::get_entries_count( $filters ); $total_pages = max( 1, (int) ceil( $total_entries / $per_page ) ); if ( $paged > $total_pages && $total_entries > 0 ) { $paged = $total_pages; } $offset = ( $paged - 1 ) * $per_page; $filters['limit'] = $per_page; $filters['offset'] = $offset; $forms = TSFS_DB::get_forms(); $entries = TSFS_DB::get_entries( $filters ); $status_counts = TSFS_DB::get_status_counts( $selected_form_id ); include TSFS_DIR . 'admin/views/entries-list.php'; } // phpcs:enable WordPress.Security.NonceVerification.Recommended /** * Render the settings page. */ public function render_settings_page() { include TSFS_DIR . 'admin/views/settings.php'; } /** * Add dedicated body class on builder screen. */ public function filter_admin_body_class( $classes ) { if ( isset( $_GET['page'] ) && 'tsfs-builder' === sanitize_key( wp_unslash( $_GET['page'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $classes .= ' tsfs-builder-view'; } return $classes; } }