Diff for /loncom/interface/loncoursedata.pm between versions 1.200 and 1.201

version 1.200, 2016/08/14 16:13:21 version 1.201, 2016/08/16 00:46:58
Line 1423  sub ensure_current_sections { Line 1423  sub ensure_current_sections {
         $updatetime = $tableinfo{'Update_time'};          $updatetime = $tableinfo{'Update_time'};
     }      }
     if ((!defined($updatetime)) || ($modifiedtime > $updatetime)) {      if ((!defined($updatetime)) || ($modifiedtime > $updatetime)) {
         if (&Apache::lonmysql::drop_table($student_table)) {          &update_student_table($cdom,$cnum);
             if (&init_dbs($courseid)) {      }
                 return "error creating $student_table\n";      return;
             } else {  }
                 &populate_student_table($courseid);  
   sub update_student_table {
       my ($cdom,$cnum) = @_;
       return unless (($cdom ne '') && ($cnum ne ''));
       my (%roster,%sqldata);
       my $classlist = &get_classlist($cdom,$cnum);
       while (my ($student,$data) = each (%$classlist)) {
           my ($section,$start,$end) = ($data->[&CL_SECTION()],
                                        $data->[&CL_START()],
                                        $data->[&CL_END()]);
           if ($section eq '' || $section =~ /^\s*$/) {
               $section = 'none';
           }
           if ($start eq '') { $start = 0; }
           if ($end eq '')   { $end   = 0; }
           $roster{$student}{'section'} = $section;
           $roster{$student}{'start'} = $start;
           $roster{$student}{'end'} = $end;
       }
       my $dbh = &Apache::lonmysql::get_dbh();
       my $statement = "SELECT student_id,student,section,start,end FROM $student_table";
       my $sth = $dbh->prepare($statement);
       $sth->execute();
       if ($sth->err()) {
           &Apache::lonnet::logthis("Unable to execute MySQL request:");
           &Apache::lonnet::logthis("\n".$statement."\n");
           &Apache::lonnet::logthis("error is:".$sth->errstr());
           return undef;
       }
       foreach my $row (@{$sth->fetchall_arrayref}) {
           my ($id,$student,$section,$start,$end) = (@$row);
           if (ref($roster{$student}) eq 'HASH') {
               if (($roster{$student}{'section'} ne $section) ||
                   ($roster{$student}{'start'} ne $start) ||
                   ($roster{$student}{'end'} ne $end)) {
                   $sqldata{$id} = {
                                     section => $roster{$student}{'section'},
                                     start   => $roster{$student}{'start'},
                                     end     => $roster{$student}{'end'},
                                   };
             }              }
         }          }
     }      }
       $sth->finish();
       if (keys(%sqldata)) { 
           foreach my $id (sort { $a <=> $b } keys(%sqldata)) {
               my $request = "UPDATE $student_table SET section='$sqldata{$id}{section}'".
                             ", start='$sqldata{$id}{start}'".
                             ", end='$sqldata{$id}{end}' WHERE student_id='$id'";
               $dbh->do($request);
           }
       }
     return;      return;
 }  }
   

Removed from v.1.200  
changed lines
  Added in v.1.201


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>