$section = 1;
 $weekofseconds = 604800;
 $course->enddate = $course->startdate + $weekofseconds * $course->numsections;
 $sectionmenu = array();
 //  Calculate the current week based on today's date and the starting date of the course.
 $currentweek = $timenow > $course->startdate ? (int) (($timenow - $course->startdate) / $weekofseconds + 1) : 0;
 $currentweek = min($currentweek, $course->numsections);
 $strftimedateshort = " " . get_string("strftimedateshort");
 /// If the selected_week variable is 0, all weeks are selected.
 if ($selected_week == -1 && $currentweek == 0) {
     $selected_week = 0;
     $section = $selected_week;
     $numsections = $course->numsections;
 } else {
     if ($selected_week == -1) {
         if (isteacher($course->id) || !empty($course->activitytracking) && ($selected_week = $cobject->first_unfinished_section()) === false) {
             $selected_week = $currentweek;
         }
         $selected_week = $selected_week > $currentweek ? $currentweek : $selected_week;
         $section = $selected_week;
         $numsections = MAX($section, 1);
     } else {
         if ($selected_week != 0) {
             /// Teachers can select a future week; students can't.
             if ($selected_week > $currentweek && !$isteacher) {
                 $section = $currentweek;
             } else {
                 $section = $selected_week;
             }
             $numsections = $section;
         } else {