From f319113e66ac7df857fe99cda096939ca737af59 Mon Sep 17 00:00:00 2001 From: Daniel Mejia Date: Mon, 14 Sep 2026 11:18:34 -0400 Subject: [PATCH] com_courses: draw every page of a form whose PDF was re-uploaded A re-uploaded PDF renders its page images into forms///, but saving the layout bumps the question version every time. Once the layout is saved twice after an upload, the latest version no longer has a matching directory and PdfForm::eachPage() falls back to the newest older one. That fallback set $version_dir, so the image URLs pointed at the new PDF, but left $base at the form root. The page count therefore came from the original upload's PNGs. When the new PDF has more pages, the extra pages are never rendered, yet getQuestionAnswerMap() still requires their questions -- so students get "Please ensure you have selected an answer for each question" with no incomplete marker on screen, and a timed form only accepts the submit once the limit expires, scoring the hidden questions as unanswered. The layout editor and results view share eachPage() and lose the same pages. $base is now taken from whichever version dir was chosen, so the page count and the image URLs always read the same directory. The fallback also read the natsorted list by position, but natsort() keeps the scandir keys, so it could pick the wrong older directory. The list is now reindexed and walked in order. Co-Authored-By: Claude Opus 5 (1M context) --- core/components/com_courses/models/form.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/components/com_courses/models/form.php b/core/components/com_courses/models/form.php index b954bab8a45..3899ebeb2fa 100644 --- a/core/components/com_courses/models/form.php +++ b/core/components/com_courses/models/form.php @@ -237,26 +237,32 @@ public function eachPage($fun, $version=null) } } - // Sort + // Sort (reindexed, since natsort keeps the scandir keys) natsort($versions); + $versions = array_values($versions); // If there's a dir for the given version, just use that if (in_array($version, $versions)) { - $base = $this->base . $this->id . DS . $version; $version_dir = $version; } else // Otherwise, see if there's a version dir for a previous version { - for ($i=0; $i < count($versions); $i++) + foreach ($versions as $v) { - if ($versions[$i] < $version) + if ($v < $version) { - $version_dir = $versions[$i]; + $version_dir = $v; } } } + // Count the page images in the same dir the image URLs point at + if (isset($version_dir)) + { + $base = $this->base . $this->id . DS . $version_dir; + } + $dir = opendir($base); $images = array();