AIEO_DMM::MENU_SLUG,
'dmm_tab' => 'product_requests',
), admin_url( 'admin.php' ) );
$aieo_pr_display_url = add_query_arg( array(
'page' => AIEO_DMM::MENU_SLUG,
'dmm_tab' => 'product_requests_display',
), admin_url( 'admin.php' ) );
$aieo_pr_types = AIEO_Product_Request_Settings::types();
$aieo_pr_statuses = array(
'new' => __( 'New', 'ai-eshop-optimizer' ),
'in_progress' => __( 'In progress', 'ai-eshop-optimizer' ),
'quoted' => __( 'Quoted', 'ai-eshop-optimizer' ),
'closed' => __( 'Closed', 'ai-eshop-optimizer' ),
'spam' => __( 'Spam', 'ai-eshop-optimizer' ),
);
if ( function_exists( 'rooster_admin_band_open' ) ) { rooster_admin_band_open( array( 'cols' => 1 ) ); }
require_once AIEO_DIR . 'includes/dmm/product-requests/class-aieo-product-request-overview.php';
AIEO_Product_Request_Overview::render( 'product-requests-overview' );
list( $aieo_pr_open, $aieo_pr_close ) = AIEO_DMM_UI::card( array(
'anchor' => 'product-requests',
'icon' => 'inbox',
'title' => __( 'Requests', 'ai-eshop-optimizer' ) . ' (' . (int) $total . ')',
'description' => __( 'Every quote and contact request, newest first. "Items" is what they asked to be quoted; "Viewed" is what else they looked at while the request was open. Context, never demand.', 'ai-eshop-optimizer' ),
'flush' => true,
) );
echo $aieo_pr_open;
$aieo_pr_pointer = wp_kses_post( sprintf(
__( 'The form copy, the display rule and the appearance live under %1$sFrontend → Product Requests Display%2$s.', 'ai-eshop-optimizer' ),
'',
''
) );
echo \Rooster\Admin\Ui::notice( $aieo_pr_pointer, 'mono', array( 'inline' => true ) );
$aieo_pr_to = '' . esc_html__( 'New requests are emailed to:', 'ai-eshop-optimizer' ) . ' ';
if ( ! empty( $recipients['emails'] ) ) {
echo \Rooster\Admin\Ui::notice(
$aieo_pr_to . '' . esc_html( implode( ', ', $recipients['emails'] ) ) . ' — ' . esc_html( $recipients['label'] ),
'mono',
array( 'inline' => true )
);
} else {
echo \Rooster\Admin\Ui::notice(
$aieo_pr_to . esc_html__( 'nobody. Set a recipient below, or the notice goes nowhere.', 'ai-eshop-optimizer' ),
'warning',
array( 'inline' => true )
);
}
$aieo_pr_filter = static function ( $label, $control, $id ) {
return \Rooster\Admin\Ui::filter( (string) $label, $control, $id );
};
$aieo_pr_status_opts = array( '' => __( 'All', 'ai-eshop-optimizer' ) );
foreach ( $aieo_pr_statuses as $aieo_pr_k => $aieo_pr_label ) {
$aieo_pr_status_opts[ $aieo_pr_k ] = $aieo_pr_label . ( ! empty( $status_counts[ $aieo_pr_k ] ) ? ' (' . (int) $status_counts[ $aieo_pr_k ] . ')' : '' );
}
$aieo_pr_type_opts = array( '' => __( 'All', 'ai-eshop-optimizer' ) ) + $aieo_pr_types;
$aieo_pr_status_select = \Rooster\Admin\Ui::select( 'pr_status', $aieo_pr_status_opts, (string) $filters['status'], array( 'id' => 'aieo-pr-f-status' ) );
$aieo_pr_type_select = \Rooster\Admin\Ui::select( 'pr_type', $aieo_pr_type_opts, (string) $filters['type'], array( 'id' => 'aieo-pr-f-type' ) );
$aieo_pr_campaign = \Rooster\Admin\Ui::input( 'pr_campaign', (string) $filters['campaign'], array( 'id' => 'aieo-pr-f-campaign', 'medium' => true ) );
$aieo_pr_from = \Rooster\Admin\Ui::input( 'pr_from', (string) $filters['from'], array( 'id' => 'aieo-pr-f-from', 'type' => 'date' ) );
$aieo_pr_to_date = \Rooster\Admin\Ui::input( 'pr_to', (string) $filters['to'], array( 'id' => 'aieo-pr-f-to', 'type' => 'date' ) );
$aieo_pr_search = \Rooster\Admin\Ui::input( 'pr_s', (string) $filters['search'], array( 'id' => 'aieo-pr-f-s', 'type' => 'search', 'medium' => true, 'placeholder' => __( 'name, email or phone', 'ai-eshop-optimizer' ) ) );
$aieo_pr_filtered = '' !== trim( (string) $filters['status'] . $filters['type'] . $filters['campaign'] . $filters['from'] . $filters['to'] . $filters['search'] );
$aieo_pr_export_url = wp_nonce_url( add_query_arg( array_merge(
array( 'action' => 'aieo_product_requests_export' ),
array_filter( array(
'pr_status' => $filters['status'],
'pr_type' => $filters['type'],
'pr_from' => $filters['from'],
'pr_to' => $filters['to'],
'pr_s' => $filters['search'],
) )
), admin_url( 'admin-post.php' ) ), 'aieo_product_requests_export' );
?>
__( 'match', 'ai-eshop-optimizer' ),
'facts' => $aieo_pr_facts,
'actions' => \Rooster\Admin\Ui::button( __( 'Clear filters', 'ai-eshop-optimizer' ), array( 'href' => $aieo_pr_base, 'variant' => 'ghost', 'size' => 'sm', 'icon' => 'x' ) ),
) );
echo $aieo_pr_head;
}
if ( 0 === (int) $total ) {
if ( $aieo_pr_filtered ) {
echo \Rooster\Admin\States::state( 'no-results', array( 'items' => __( 'requests', 'ai-eshop-optimizer' ), 'clear' => $aieo_pr_base ) );
} else {
$aieo_pr_first = \Rooster\Admin\States::state( 'first-use', array(
'title' => __( 'No requests yet.', 'ai-eshop-optimizer' ),
'text' => __( 'Quote and contact requests from your product pages appear here, newest first.', 'ai-eshop-optimizer' ),
) );
echo $aieo_pr_first;
}
}
?>
first_product;
$aieo_pr_who = array_filter( array_map( 'trim', array( (string) $r->name, (string) $r->email ) ) );
if ( ! $aieo_pr_who ) {
$aieo_pr_who = array_filter( array( trim( (string) $r->phone ) ) );
}
$aieo_pr_rows[] = array(
'id' => (int) $r->id,
'created' => AIEO_Product_Request_Store::local_datetime( (string) $r->created_at ),
'type' => isset( $aieo_pr_types[ (string) $r->request_type ] ) ? $aieo_pr_types[ (string) $r->request_type ] : (string) $r->request_type,
'status' => (string) $r->status,
'who' => implode( ' · ', $aieo_pr_who ),
'detail_url' => add_query_arg( 'request_id', (int) $r->id, $aieo_pr_base ),
'product' => $pid > 0 ? ( get_the_title( $pid ) ?: '#' . $pid ) : '—',
'items' => (int) $r->item_count,
'views' => (int) $r->view_count,
'campaign' => (string) ( $a['utm_campaign'] ?? '' ) !== '' ? (string) $a['utm_campaign'] : '—',
);
}
if ( (int) $total > 0 ) : AIEO_Table::render( array(
'page_id' => 'product_requests',
'row_key' => 'id',
'rows' => $aieo_pr_rows,
'sortable' => false,
'empty' => __( 'No requests yet.', 'ai-eshop-optimizer' ),
'columns' => array(
array( 'key' => 'created', 'label' => sprintf( __( 'Date (%s)', 'ai-eshop-optimizer' ), wp_timezone_string() ), 'nowrap' => true ),
array( 'key' => 'type', 'label' => __( 'Type', 'ai-eshop-optimizer' ) ),
array(
'key' => 'status',
'label' => __( 'Status', 'ai-eshop-optimizer' ),
'type' => 'badge',
'format' => array(
'map' => array(
'new' => 'warning',
'in_progress' => 'secondary',
'quoted' => 'success',
'closed' => 'muted',
'spam' => 'danger',
),
'labels' => $aieo_pr_statuses,
),
),
array( 'key' => 'who', 'label' => __( 'Who', 'ai-eshop-optimizer' ), 'type' => 'link', 'format' => array( 'href' => 'detail_url' ) ),
array( 'key' => 'product', 'label' => __( 'Asked about', 'ai-eshop-optimizer' ) ),
array( 'key' => 'items', 'label' => __( 'Items', 'ai-eshop-optimizer' ), 'type' => 'number' ),
array( 'key' => 'views', 'label' => __( 'Viewed while open', 'ai-eshop-optimizer' ), 'type' => 'number' ),
array( 'key' => 'campaign', 'label' => __( 'Campaign', 'ai-eshop-optimizer' ) ),
),
'actions' => array(
array( 'id' => 'open', 'label' => __( 'Open', 'ai-eshop-optimizer' ), 'class' => 'rooster-admin-button rooster-admin-button--sm aieo-pr-open', 'href' => '{detail_url}' ),
array( 'id' => 'delete', 'label' => __( 'Delete', 'ai-eshop-optimizer' ), 'class' => 'rooster-admin-button rooster-admin-button--sm aieo-pr-delete', 'data' => array( 'ra-confirm' => 'aieo-pr-delete-ask' ) ),
),
) );
$aieo_pr_ask = \Rooster\Admin\States::confirm(
'aieo-pr-delete-ask',
'delete',
__( 'Delete the request?', 'ai-eshop-optimizer' ),
esc_html__( 'Its items, its campaign attribution and its browsing trail go with it. This cannot be undone.', 'ai-eshop-optimizer' ),
array( 'confirm' => __( 'Delete request', 'ai-eshop-optimizer' ) )
);
echo $aieo_pr_ask;
endif;
$aieo_pr_pages = max( 1, (int) ceil( $total / max( 1, $per_page ) ) );
if ( $aieo_pr_pages > 1 ) :
$aieo_pr_page_base = add_query_arg( array_filter( array(
'pr_status' => $filters['status'],
'pr_type' => $filters['type'],
'pr_campaign' => $filters['campaign'],
'pr_from' => $filters['from'],
'pr_to' => $filters['to'],
'pr_s' => $filters['search'],
) ), $aieo_pr_base );
$aieo_pr_page_url = static function ( $n ) use ( $aieo_pr_page_base ) {
return add_query_arg( 'pr_paged', (int) $n, $aieo_pr_page_base );
};
$aieo_pr_pager = \Rooster\Admin\Ui::pager( (int) $current_page, $aieo_pr_pages, $aieo_pr_page_url, array( 'total' => (int) $total, 'label' => __( 'Request pages', 'ai-eshop-optimizer' ) ) );
echo $aieo_pr_pager;
endif;
?>
'product-requests-pages',
'icon' => 'map-pin',
'title' => __( 'Where quotes start', 'ai-eshop-optimizer' ),
'description' => __( 'The pages the quote requests were started on, how many of them were then sent, and the pages they were sent from. Counted by Rooster One for each page, apart from the campaign reports.', 'ai-eshop-optimizer' ),
) );
echo $aieo_pr_pa_open;
\Rooster\Admin\Markup::out( AIEO_Page_Actions::form_pages( 'product_request', array(
'caption' => __( 'Where quotes start', 'ai-eshop-optimizer' ),
'empty' => __( 'No quote request counted yet: each one started from now on is counted on the page it was started on.', 'ai-eshop-optimizer' ),
) ) );
echo $aieo_pr_pa_close;
}
?>
'aieo-pr-recipients',
'label' => __( 'Send new requests to', 'ai-eshop-optimizer' ),
'control' => \Rooster\Admin\Ui::input( 'recipients', (string) $settings['recipients'], array( 'id' => 'aieo-pr-recipients', 'placeholder' => __( 'comma separated. Blank falls back to your shop managers', 'ai-eshop-optimizer' ) ) ),
'help' => __( 'Blank is fine: with nothing here the notice goes to your shop managers and administrators, then to the Rooster One contact, then to the WordPress administration address. Whatever it resolves to is printed at the top of this screen.', 'ai-eshop-optimizer' ),
) );
foreach ( $aieo_pr_types as $aieo_pr_k => $aieo_pr_label ) {
$aieo_pr_nrows .= \Rooster\Admin\Ui::field_row( array(
'id' => 'aieo-pr-recipients-' . $aieo_pr_k,
'label' => sprintf( __( 'Override for: %s', 'ai-eshop-optimizer' ), $aieo_pr_label ),
'control' => \Rooster\Admin\Ui::input( 'recipients_' . $aieo_pr_k, (string) ( $settings[ 'recipients_' . $aieo_pr_k ] ?? '' ), array( 'id' => 'aieo-pr-recipients-' . $aieo_pr_k, 'placeholder' => __( 'optional', 'ai-eshop-optimizer' ) ) ),
) );
}
$aieo_pr_nrows .= \Rooster\Admin\Ui::field_row( array(
'id' => 'aieo-pr-notify_delay_minutes',
'label' => __( 'Quiet window', 'ai-eshop-optimizer' ),
'control' => \Rooster\Admin\Ui::input( 'notify_delay_minutes', (string) (int) $settings['notify_delay_minutes'], array( 'id' => 'aieo-pr-notify_delay_minutes', 'type' => 'number', 'xs' => true, 'min' => 0, 'max' => 1440, 'step' => 1, 'unit' => __( 'minutes', 'ai-eshop-optimizer' ) ) ),
'help' => __( 'A quote grows. Sending instantly can list one product when the visitor ended up wanting four. Set a few minutes here and you get exactly one email, listing everything they added inside the window. 0 sends immediately.', 'ai-eshop-optimizer' ),
) );
$aieo_pr_nrows .= \Rooster\Admin\Ui::field_row( array(
'id' => 'aieo-pr-trail_lookback_hours',
'label' => __( 'Browsing trail window', 'ai-eshop-optimizer' ),
'control' => \Rooster\Admin\Ui::input( 'trail_lookback_hours', (string) (int) $settings['trail_lookback_hours'], array( 'id' => 'aieo-pr-trail_lookback_hours', 'type' => 'number', 'xs' => true, 'min' => 1, 'max' => 168, 'step' => 1, 'unit' => __( 'hours either side of the request', 'ai-eshop-optimizer' ) ) ),
'help' => __( 'This bound is not optional. The visitor id behind the session stream lives for thirty days, so an unbounded trail would show a month of browsing under the heading “viewed before asking”.', 'ai-eshop-optimizer' ),
) );
$aieo_pr_nrows .= ''
. \Rooster\Admin\Ui::field_row( array(
'id' => 'aieo-pr-ack_enabled',
'label' => __( 'Acknowledge the customer', 'ai-eshop-optimizer' ),
'control' => \Rooster\Admin\Ui::toggle( 'ack_enabled', 'yes' === (string) $settings['ack_enabled'], array( 'id' => 'aieo-pr-ack_enabled', 'hidden' => false, 'label' => __( 'Email the person who asked, confirming we received it', 'ai-eshop-optimizer' ) ) ),
'help' => __( 'Always sent immediately, never held by the quiet window. Leave the wording blank to use the translated text in each visitor’s own language.', 'ai-eshop-optimizer' ),
) )
. \Rooster\Admin\Ui::field_row( array(
'id' => 'aieo-pr-ack_subject',
'label' => __( 'Subject', 'ai-eshop-optimizer' ),
'control' => \Rooster\Admin\Ui::input( 'ack_subject', (string) $settings['ack_subject'], array( 'id' => 'aieo-pr-ack_subject', 'placeholder' => (string) $i18n_defaults['ack_subject'] ) ),
) )
. \Rooster\Admin\Ui::field_row( array(
'id' => 'aieo-pr-ack_message',
'label' => __( 'Message', 'ai-eshop-optimizer' ),
'control' => \Rooster\Admin\Ui::textarea( 'ack_message', (string) $settings['ack_message'], array( 'id' => 'aieo-pr-ack_message', 'rows' => 3, 'placeholder' => (string) $i18n_defaults['ack_message'] ) ),
) );
list( $aieo_pr_open, $aieo_pr_close ) = AIEO_DMM_UI::card( array(
'anchor' => 'product-requests-notifications',
'icon' => 'bell',
'title' => __( 'Notifications', 'ai-eshop-optimizer' ),
'description' => __( 'Exactly one staff email goes out per request. Adding more products to an open quote never re-sends it.', 'ai-eshop-optimizer' ),
'footer' => \Rooster\Admin\States::save_button( $aieo_pr_nf ),
) );
echo $aieo_pr_open;
echo AIEO_DMM_UI::card_form( 'aieo_dmm_product_requests_save', 'product_requests', $aieo_pr_nf, '' . $aieo_pr_nrows . '
' );
echo $aieo_pr_close;
?>