(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(); ?>
'aieo-erp-name', 'medium' => true, 'required' => true, 'placeholder' => __('e.g. Athens store ERP', 'ai-eshop-optimizer')))); echo $aieo_erp_row('aieo-erp-host', __('Host', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('host', '', array('id' => 'aieo-erp-host', 'medium' => true, 'code' => true, 'required' => true, 'placeholder' => 'db.example.com'))); echo $aieo_erp_row('aieo-erp-port', __('Port', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('port', '3306', array('id' => 'aieo-erp-port', 'type' => 'number', 'xs' => true, 'min' => 1, 'max' => 65535))); echo $aieo_erp_row('aieo-erp-db_name', __('Database', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('db_name', '', array('id' => 'aieo-erp-db_name', 'medium' => true, 'code' => true, 'required' => true))); echo $aieo_erp_row('aieo-erp-db_user', __('User', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('db_user', '', array('id' => 'aieo-erp-db_user', 'medium' => true, 'code' => true, 'required' => true, 'autocomplete' => 'off'))); echo $aieo_erp_row('aieo-erp-db_pass', __('Password', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('db_pass', '', array('id' => 'aieo-erp-db_pass', 'type' => 'password', 'autocomplete' => 'new-password')), __('Encrypted at rest. Leave empty when editing to keep the stored password unchanged.', 'ai-eshop-optimizer')); echo $aieo_erp_row('aieo-erp-table_prefix', __('Table prefix', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('table_prefix', 'wp_', array('id' => 'aieo-erp-table_prefix', 'short' => true, 'code' => true)), __('Used by helpers like $remote->prefix . "s1erp_temp_store_orders_table". Most installs use "wp_".', 'ai-eshop-optimizer')); ?>
' . $aieo_erp_row('aieo-erp-erp_orders_table', __('ERP orders table', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('erp_orders_table', '', array('id' => 'aieo-erp-erp_orders_table', 'code' => true, 'placeholder' => 'wp_s1erp_temp_store_orders_table')), __('Physical-store orders. Letters, digits, underscores only.', 'ai-eshop-optimizer')) . $aieo_erp_row('aieo-erp-erp_customers_table', __('ERP customers table', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('erp_customers_table', '', array('id' => 'aieo-erp-erp_customers_table', 'code' => true, 'placeholder' => 'wp_s1erp_temp_customers_table'))) . $aieo_erp_row('aieo-erp-erp_products_table', __('ERP products table', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('erp_products_table', '', array('id' => 'aieo-erp-erp_products_table', 'code' => true, 'placeholder' => 'wp_s1erp_temp_products_table'))) . $aieo_erp_row('aieo-erp-predictor_table', __('Sales-predictor table', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::input('predictor_table', '', array('id' => 'aieo-erp-predictor_table', 'code' => true, 'placeholder' => 'wp_product_sales_predictor')), __('Output of the stock-requirements predictor model. Pull-only on this side.', 'ai-eshop-optimizer')) . '', array('id' => 'aieo-erp-logical') ); ?>
__('off — plaintext only (LAN/VPN)', 'ai-eshop-optimizer'), 'prefer' => __('prefer — try TLS, accept plain', 'ai-eshop-optimizer'), 'require' => __('require — refuse to connect without TLS', 'ai-eshop-optimizer'), ), 'prefer', array('id' => 'aieo-erp-ssl_mode') ) ); echo $aieo_erp_ssl_row; $aieo_erp_default_row = $aieo_erp_row( 'aieo-erp-is_default', __('Default', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::toggle('is_default', false, array('id' => 'aieo-erp-is_default', 'hidden' => false, 'label' => __('This is the default connection (used when no specific connection is requested).', 'ai-eshop-optimizer'))) ); echo $aieo_erp_default_row; echo $aieo_erp_row('aieo-erp-notes', __('Notes', 'ai-eshop-optimizer'), \Rooster\Admin\Ui::textarea('notes', '', array('id' => 'aieo-erp-notes', 'rows' => 3, 'placeholder' => __('Free-text — purpose, contact person, etc.', 'ai-eshop-optimizer')))); ?>