sanitize_text_field($_POST['license_key']), 'max_allowed_domains' => intval($_POST['max_allowed_domains']), 'max_allowed_devices' => intval($_POST['max_allowed_devices']), 'lic_status' => sanitize_text_field($_POST['lic_status']), 'first_name' => sanitize_text_field($_POST['first_name']), 'last_name' => sanitize_text_field($_POST['last_name']), // Validate email 'email' => is_email($_POST['email']) ? sanitize_email($_POST['email']) : '', 'company_name' => sanitize_text_field($_POST['company_name']), 'txn_id' => sanitize_text_field($_POST['txn_id']), 'manual_reset_count' => intval($_POST['manual_reset_count']), 'purchase_id_' => sanitize_text_field($_POST['purchase_id_']), // Date validation 'date_created' => SLM_API_Utility::slm_validate_date($_POST['date_created']), 'date_renewed' => SLM_API_Utility::slm_validate_date($_POST['date_renewed']), 'date_activated' => SLM_API_Utility::slm_validate_date($_POST['date_activated']), 'product_ref' => sanitize_text_field($_POST['product_ref']), 'until' => sanitize_text_field($_POST['until']), 'current_ver' => sanitize_text_field($_POST['current_ver']), 'subscr_id' => sanitize_text_field($_POST['subscr_id']), 'lic_type' => sanitize_text_field($_POST['lic_type']), // Handle 'lifetime' license expiration properly 'date_expiry' => ($_POST['lic_type'] == 'lifetime') ? '0000-00-00' : SLM_API_Utility::slm_validate_date($_POST['date_expiry']), 'item_reference' => sanitize_text_field($_POST['item_reference']), 'slm_billing_length' => sanitize_text_field($_POST['slm_billing_length']), 'slm_billing_interval' => sanitize_text_field($_POST['slm_billing_interval']), 'reminder_sent' => intval($_POST['reminder_sent']), // Reminder date validation 'reminder_sent_date' => SLM_API_Utility::slm_validate_date($_POST['reminder_sent_date']) ]; // Check for required fields if (empty($data['email']) || empty($data['date_created']) || ($data['lic_type'] != 'lifetime' && empty($data['date_expiry'])) || empty($data['lic_type'])) { echo '

' . __('Required fields are missing.', 'slmplus') . '

'; } else { // Insert or update the data in the database if ($id) { $wpdb->update(SLM_TBL_LICENSE_KEYS, $data, ['id' => $id]); echo '

' . __('License updated successfully.', 'slmplus') . '

'; } else { $wpdb->insert(SLM_TBL_LICENSE_KEYS, $data); echo '

' . __('License created successfully.', 'slmplus') . '

'; } } } else { // If editing, load existing data // Ensure the correct data types and default values for new records if ($id) { $license = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . SLM_TBL_LICENSE_KEYS . " WHERE id = %d", $id)); if ($license) { $data = (array) $license; } } else { // Prepare empty data for new record $data = [ 'license_key' => '', 'max_allowed_domains' => SLM_DEFAULT_MAX_DOMAINS, 'max_allowed_devices' => SLM_DEFAULT_MAX_DEVICES, 'lic_status' => 'pending', // Default value 'first_name' => '', 'last_name' => '', 'email' => '', 'company_name' => '', 'txn_id' => '', 'manual_reset_count' => '', 'purchase_id_' => '', 'date_created' => date_i18n($slm_wp_date_format, strtotime('now')), // Use WP date format 'date_renewed' => '0000-00-00', 'date_activated' => '0000-00-00', 'product_ref' => '', 'until' => '', 'current_ver' => '', 'subscr_id' => '', 'lic_type' => 'subscription', 'date_expiry' => date_i18n($slm_wp_date_format, strtotime('+1 year')), // Use WP date format 'item_reference' => '', 'slm_billing_length' => '', 'slm_billing_interval' => 'days', // Default value 'reminder_sent' => '0', 'reminder_sent_date' => '0000-00-00' ]; // Generate a license key if it's a new record if (!isset($editing_record)) { $editing_record = new stdClass(); } $lic_key_prefix = isset($slm_options['lic_prefix']) ? $slm_options['lic_prefix'] : ''; $data['license_key'] = slm_get_license($lic_key_prefix); } } ?>

get_results("SELECT status_key, status_label FROM $lic_status_table ", ARRAY_A); // Create the '; foreach ($statuses as $status) { // Set the selected attribute if the current status matches $selected = selected($data['lic_status'], $status['status_key'], false); echo ''; } echo ''; ?>