$viewhiddensections = $this->cache->canviewhiddensections;
$selectedstructure = optional_param($activeparam,false,PARAM_INT);
+
+ // This is required to make sure that if people have reduced the number
+ // of sections after adding activities to sections that no longer exist
+ // we dont show them
+ // MDL-20242
+ $sections = array_slice($sections, 0, $course->numsections, true);
+
foreach ($sections as $section) {
if ((!$viewhiddensections && !$section->visible) || (!$this->showemptybranches && !array_key_exists($section->section, $modinfo->sections))) {
continue;