diff --git a/Sources/Actions/Admin/Subscriptions.php b/Sources/Actions/Admin/Subscriptions.php index 6805965ea4..bf378721d8 100644 --- a/Sources/Actions/Admin/Subscriptions.php +++ b/Sources/Actions/Admin/Subscriptions.php @@ -846,6 +846,7 @@ public function modifyUser(): void // Setup the template. Utils::$context['sub_template'] = 'modify_user_subscription'; Utils::$context['page_title'] = Lang::$txt[Utils::$context['action_type'] . '_subscriber']; + Theme::loadJavaScriptFile('paidsubs.js', ['defer' => true, 'minimize' => true], 'smf_paidsubs'); // If we haven't been passed the subscription ID get it. if (Utils::$context['log_id'] && !Utils::$context['sub_id']) { diff --git a/Themes/default/Admin.template.php b/Themes/default/Admin.template.php index 7ccda036d9..c6f1c6f75d 100644 --- a/Themes/default/Admin.template.php +++ b/Themes/default/Admin.template.php @@ -725,7 +725,7 @@ function template_not_done()
'; // Do we have a token? - if (isset(Utils::$context['not_done_token']) && isset(Utils::$context[Utils::$context['not_done_token'] . '_token'], Utils::$context[Utils::$context['not_done_token'] . '_token_var'])) + if (isset(Utils::$context['not_done_token'], Utils::$context[Utils::$context['not_done_token'] . '_token'], Utils::$context[Utils::$context['not_done_token'] . '_token_var'])) echo ' '; @@ -735,21 +735,7 @@ function template_not_done()
'; } @@ -1526,21 +1512,7 @@ function template_repair_boards() { echo ' '; } } diff --git a/Themes/default/ManageNews.template.php b/Themes/default/ManageNews.template.php index 36661ec935..660af358f9 100644 --- a/Themes/default/ManageNews.template.php +++ b/Themes/default/ManageNews.template.php @@ -384,7 +384,7 @@ function template_email_members_send()

- + @@ -404,23 +404,9 @@ function template_email_members_send() - '; + '; } /** diff --git a/Themes/default/ManagePaid.template.php b/Themes/default/ManagePaid.template.php index e9df4973f9..2659f703ac 100644 --- a/Themes/default/ManagePaid.template.php +++ b/Themes/default/ManagePaid.template.php @@ -211,12 +211,6 @@ function template_delete_subscription() */ function template_modify_user_subscription() { - // Some quickly stolen javascript from Post, could do with being more efficient :) - echo ' - '; - echo '
@@ -257,7 +251,7 @@ function template_modify_user_subscription()
', Lang::$txt['start_date_and_time'], ' - '; // Show a list of all the years we allow... for ($year = 2005; $year <= 2030; $year++) @@ -266,7 +260,7 @@ function template_modify_user_subscription() echo ' - '; // There are 12 months per year - ensure that they all get listed. for ($month = 1; $month <= 12; $month++) @@ -291,7 +285,7 @@ function template_modify_user_subscription()
', Lang::$txt['end_date_and_time'], ' - '; // Show a list of all the years we allow... for ($year = 2005; $year <= 2030; $year++) @@ -300,7 +294,7 @@ function template_modify_user_subscription() echo ' - '; // There are 12 months per year - ensure that they all get listed. for ($month = 1; $month <= 12; $month++) @@ -336,6 +330,10 @@ function template_modify_user_subscription() sSearchType: \'member\', sTextDeleteItem: \'', Lang::$txt['autosuggest_delete_item'], '\', }); + document.getElementById("year").addEventListener("change", generateDays); + document.getElementById("month").addEventListener("change", generateDays); + document.getElementById("yearend").addEventListener("change", generateDays.bind(null, "end")); + document.getElementById("monthend").addEventListener("change", generateDays.bind(null, "end")); '; if (!empty(Utils::$context['pending_payments'])) diff --git a/Themes/default/ManageSearch.template.php b/Themes/default/ManageSearch.template.php index 7f660a1e35..64cf9aa796 100644 --- a/Themes/default/ManageSearch.template.php +++ b/Themes/default/ManageSearch.template.php @@ -310,7 +310,7 @@ function template_create_index_progress()

- + @@ -318,23 +318,8 @@ function template_create_index_progress()
'; - } /** diff --git a/Themes/default/Packages.template.php b/Themes/default/Packages.template.php index 256c0c588f..4f520c3d94 100644 --- a/Themes/default/Packages.template.php +++ b/Themes/default/Packages.template.php @@ -1834,21 +1834,7 @@ function template_action_permissions() // Just the countdown stuff echo ' '; } diff --git a/Themes/default/Post.template.php b/Themes/default/Post.template.php index 89d12c5d42..95262ee2ee 100644 --- a/Themes/default/Post.template.php +++ b/Themes/default/Post.template.php @@ -822,7 +822,7 @@ function template_announcement_send()
- + @@ -836,21 +836,7 @@ function template_announcement_send()

'; } diff --git a/Themes/default/scripts/paidsubs.js b/Themes/default/scripts/paidsubs.js new file mode 100644 index 0000000000..0031dfce0a --- /dev/null +++ b/Themes/default/scripts/paidsubs.js @@ -0,0 +1,41 @@ +function generateDays(offset = '') { + // Get the DOM elements + const dayElement = document.getElementById('day' + offset); + const yearElement = document.getElementById('year' + offset); + const monthElement = document.getElementById('month' + offset); + + // Validate the existence of elements + if (!dayElement || !yearElement || !monthElement) { + console.error('One or more elements are missing. Ensure the IDs are correct.'); + return; + } + + // Month lengths (default February to 28 days) + const monthLengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + + // Adjust February for leap years + const year = parseInt(yearElement.options[yearElement.selectedIndex]?.value || 0, 10); + if ((year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0)) { + monthLengths[1] = 29; + } + + // Get selected day before updating options + const selectedDay = dayElement.selectedIndex; + + // Clear current options + dayElement.innerHTML = ''; + + // Get the number of days in the selected month + const daysInMonth = monthLengths[parseInt(monthElement.value, 10) - 1] || 31; + + // Populate day options + for (let i = 1; i <= daysInMonth; i++) { + const option = document.createElement('option'); + option.value = i; + option.textContent = i; + dayElement.appendChild(option); + } + + // Restore the previously selected day if valid + dayElement.selectedIndex = Math.min(selectedDay, daysInMonth - 1); +} diff --git a/Themes/default/scripts/script.js b/Themes/default/scripts/script.js index 960d12a9c0..bb707ad7d7 100644 --- a/Themes/default/scripts/script.js +++ b/Themes/default/scripts/script.js @@ -1485,35 +1485,6 @@ function expandThumb(thumbID) return false; } -function generateDays(offset) -{ - // Work around JavaScript's lack of support for default values... - offset = typeof(offset) != 'undefined' ? offset : ''; - - var days = 0, selected = 0; - var dayElement = document.getElementById("day" + offset), yearElement = document.getElementById("year" + offset), monthElement = document.getElementById("month" + offset); - - var monthLength = [ - 31, 28, 31, 30, - 31, 30, 31, 31, - 30, 31, 30, 31 - ]; - if (yearElement.options[yearElement.selectedIndex].value % 4 == 0) - monthLength[1] = 29; - - selected = dayElement.selectedIndex; - while (dayElement.options.length) - dayElement.options[0] = null; - - days = monthLength[monthElement.value - 1]; - - for (i = 1; i <= days; i++) - dayElement.options[dayElement.length] = new Option(i, i); - - if (selected < days) - dayElement.selectedIndex = selected; -} - function initSearch() { if (document.forms.searchform.search.value.indexOf("%u") != -1) @@ -1992,4 +1963,33 @@ smc_preview_post.prototype.onDocSent = function (XMLDoc) } location.hash = '#' + this.opts.sPreviewSectionContainerID; +} + +function doAutoSubmit(countdown, txtMessage, formName = 'autoSubmit', fieldName = 'cont') { + const form = document.forms[formName]; + + // Ensure the form exists + if (!form) { + console.error('Form with name "' + formName + '" not found.'); + return; + } + + // Handle the countdown completion + if (countdown <= 0) { + form.submit(); + return; + } + + // Update the field if it exists + const contField = form.elements[fieldName]; + if (contField) { + contField.value = txtMessage + ' (' + countdown + ')'; + } else { + console.warn('Field "' + fieldName + '" not found in form "' + formName + '".'); + } + + // Schedule the next countdown tick + setTimeout(() => { + doAutoSubmit(countdown - 1, txtMessage, formName, fieldName); + }, 1000); } \ No newline at end of file