(int) $aieo_erp_c['id'], 'name' => (string) $aieo_erp_c['name'], 'hostport' => (string) $aieo_erp_c['host'] . ':' . (int) $aieo_erp_c['port'], 'host' => (string) $aieo_erp_c['host'], 'port' => (int) $aieo_erp_c['port'], 'db_name' => (string) $aieo_erp_c['db_name'], 'db_user' => (string) $aieo_erp_c['db_user'], 'is_default' => !empty($aieo_erp_c['is_default']), 'last_test' => empty($aieo_erp_c['last_tested_at']) ? '' : (!empty($aieo_erp_c['last_test_ok']) ? '✓ ' : '✗ ') . mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $aieo_erp_c['last_tested_at']), 'table_prefix' => (string) ($aieo_erp_c['table_prefix'] ?? 'wp_'), 'erp_orders_table' => (string) ($aieo_erp_c['erp_orders_table'] ?? ''), 'erp_customers_table' => (string) ($aieo_erp_c['erp_customers_table'] ?? ''), 'erp_products_table' => (string) ($aieo_erp_c['erp_products_table'] ?? ''), 'predictor_table' => (string) ($aieo_erp_c['predictor_table'] ?? ''), 'ssl_mode' => (string) ($aieo_erp_c['ssl_mode'] ?? 'prefer'), 'notes' => (string) ($aieo_erp_c['notes'] ?? ''), ); } rooster_admin_band_open(array('cols' => 1)); AIEO_Table::card(array( 'anchor' => 'erp-database-connections', 'title' => __('Connections', 'ai-eshop-optimizer'), 'heading' => 'h2', 'description' => __('Stored connections to external MariaDB databases — typically the ERP / physical-store database holding wp_s1erp_*, wp_product_sales_predictor, and a peer Rooster One install. Other Rooster One modules will use these connections to import sales data and compute cross-store metrics.', 'ai-eshop-optimizer'), 'id' => 'aieo-erp-connections-table', 'page_id' => 'erp_database', 'row_key' => 'id', 'rows' => $aieo_erp_rows, 'empty' => __('No connections yet. Add one below.', 'ai-eshop-optimizer'), 'row_data' => array( 'table_prefix' => 'table_prefix', 'erp_orders_table' => 'erp_orders_table', 'erp_customers_table' => 'erp_customers_table', 'erp_products_table' => 'erp_products_table', 'predictor_table' => 'predictor_table', 'ssl_mode' => 'ssl_mode', 'notes' => 'notes', 'host' => 'host', 'port' => 'port', 'name' => 'name', 'db_name' => 'db_name', 'db_user' => 'db_user', 'is_default' => static function ($r) { return !empty($r['is_default']) ? '1' : ''; }, ), 'columns' => array( array('key' => 'name', 'label' => __('Name', 'ai-eshop-optimizer')), array('key' => 'hostport', 'label' => __('Host', 'ai-eshop-optimizer'), 'type' => 'code'), array('key' => 'db_name', 'label' => __('Database', 'ai-eshop-optimizer'), 'type' => 'code'), array('key' => 'db_user', 'label' => __('User', 'ai-eshop-optimizer'), 'type' => 'code'), array('key' => 'is_default', 'label' => __('Default', 'ai-eshop-optimizer'), 'type' => 'boolean'), array('key' => 'last_test', 'label' => __('Last test', 'ai-eshop-optimizer'), 'nowrap' => true, 'empty' => __('never tested', 'ai-eshop-optimizer')), ), 'actions' => array( array('id' => 'test', 'label' => __('Test', 'ai-eshop-optimizer'), 'description' => __('Connects with the saved credentials and says whether the database answers.', 'ai-eshop-optimizer'), 'class' => 'button button-small aieo-erp-test'), array('id' => 'edit', 'label' => __('Edit', 'ai-eshop-optimizer'), 'description' => __('Loads this connection into the form below to change it.', 'ai-eshop-optimizer'), 'class' => 'button button-small aieo-erp-edit'), array( 'id' => 'delete', 'label' => __('Delete', 'ai-eshop-optimizer'), 'description' => __('Removes the saved credentials; the remote database is untouched.', 'ai-eshop-optimizer'), 'class' => 'button button-small button-link-delete aieo-erp-delete', 'destructive' => true, 'confirm_noun' => __('connection', 'ai-eshop-optimizer'), 'confirm' => __('This does not affect the remote database, only the saved credentials here.', 'ai-eshop-optimizer'), ), ), )); ?> __('Save connection', 'ai-eshop-optimizer')), array('attrs' => $key_ok ? array('id' => 'aieo-erp-save') : array('id' => 'aieo-erp-save', 'disabled' => true, 'aria-describedby' => 'aieo-erp-save-reason')) ) ) . ($key_ok ? '' : '' . esc_html__('Encryption key missing.', 'ai-eshop-optimizer') . '') . \Rooster\Admin\Ui::button(__('Test connection', 'ai-eshop-optimizer'), array('attrs' => array('id' => 'aieo-erp-test-form'))) . \Rooster\Admin\Ui::button(__('Cancel edit', 'ai-eshop-optimizer'), array('attrs' => array('id' => 'aieo-erp-reset', 'hidden' => true))); list($aieo_erp_open, $aieo_erp_close) = AIEO_DMM_UI::card(array( 'anchor' => 'erp-database-add-a-connection', 'description' => __('Enter the address and sign-in of a remote ERP database, test it, and save it for Rooster One to read.', 'ai-eshop-optimizer'), 'icon' => 'plus', 'title' => __('Add a connection', 'ai-eshop-optimizer'), 'footer' => $aieo_erp_footer, )); echo $aieo_erp_open; if (!$key_ok) { $aieo_erp_key_detail = '
define( \'AIEO_ERP_ENCRYPTION_KEY\', \'' . esc_html($suggested) . '\' );'
. '' . esc_html__('Treat this constant like a database password — keep it out of version control. If you rotate it later, every saved password will need to be re-entered.', 'ai-eshop-optimizer') . '
'; $aieo_erp_key_notice = \Rooster\Admin\Ui::notice( esc_html__('Passwords cannot be stored until you add the AIEO_ERP_ENCRYPTION_KEY constant to your wp-config.php. Add the suggested line below (just above the "/* That\'s all, stop editing! */" line):', 'ai-eshop-optimizer'), 'warning', array('title' => __('Encryption key missing.', 'ai-eshop-optimizer'), 'inline' => true, 'detail' => $aieo_erp_key_detail) ); echo $aieo_erp_key_notice; } $aieo_erp_row = static function ($id, $label, $control, $help = '') { return \Rooster\Admin\Ui::field_row(array('id' => $id, 'label' => $label, 'control' => $control, 'help' => $help)); }; ob_start(); ?>