--- loncom/interface/loncoursedata.pm 2006/12/28 21:01:39 1.178 +++ loncom/interface/loncoursedata.pm 2008/11/17 14:16:55 1.189 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: loncoursedata.pm,v 1.178 2006/12/28 21:01:39 albertel Exp $ +# $Id: loncoursedata.pm,v 1.189 2008/11/17 14:16:55 jms Exp $ # # Copyright Michigan State University Board of Trustees # @@ -30,7 +30,7 @@ =head1 NAME -loncoursedata +Apache::loncoursedata =head1 SYNOPSIS @@ -38,26 +38,24 @@ Set of functions that download and proce =head1 PACKAGES USED - Apache::Constants qw(:common :http) - Apache::lonnet() - Apache::lonhtmlcommon - HTML::TokeParser - GDBM_File - + Apache::lonnet + Apache::longroup + Time::HiRes + Apache::lonmysql + LONCAPA + Digest::MD5 + =cut package Apache::loncoursedata; use strict; use Apache::lonnet; -use Apache::lonhtmlcommon; -use Apache::longroup; -use Time::HiRes; -use Apache::lonmysql; -use HTML::TokeParser; -use GDBM_File; -use lib '/home/httpd/lib/perl/'; +use Apache::longroup(); +use Time::HiRes(); +use Apache::lonmysql(); use LONCAPA; +use Digest::MD5(); =pod @@ -66,13 +64,6 @@ use LONCAPA; This section contains all the functions that get data from other servers and/or itself. -=cut - -################################################ -################################################ - -=pod - =item &make_into_hash($values); Returns a reference to a hash as described by $values. $values is @@ -932,7 +923,7 @@ sub populate_student_table { $dbh->do($request); if ($dbh->err()) { &Apache::lonnet::logthis("error ".$dbh->errstr(). - " occured executing \n". + " occurred executing \n". $request); } return; @@ -985,7 +976,7 @@ sub populate_groupnames_table { $dbh->do($request); if ($dbh->err()) { &Apache::lonnet::logthis("error ".$dbh->errstr(). - " occured executing \n". + " occurred executing \n". $request); } return; @@ -1055,7 +1046,7 @@ sub populate_students_groups_table { $dbh->do($request); if ($dbh->err()) { &Apache::lonnet::logthis("error ".$dbh->errstr(). - " occured executing \n". + " occurred executing \n". $request); } return; @@ -1114,7 +1105,7 @@ Input: $sname, $sdom, $courseid Output: $returnstatus -$returnstatus is a string describing any errors that occured. 'okay' is the +$returnstatus is a string describing any errors that occurred. 'okay' is the default. This subroutine loads a students data using lonnet::dump and inserts @@ -1128,7 +1119,7 @@ a description of the error. Once the "fulldump" tables are updated, the tables used for chart and spreadsheet (which hold only the current state of the student on their -homework, not historical data) are updated. If all updates have occured +homework, not historical data) are updated. If all updates have occurred successfully, $student_table is updated to reflect the time of the update. Notice we do not insert the data and immediately query it. This means it @@ -1177,6 +1168,8 @@ sub update_full_student_data { while (my ($key,$value) = each(%studentdata)) { next if ($key =~ /^(\d+):(resource$|subnum$|keys:)/); my ($transaction,$symb,$parameter) = split(':',$key); + $symb = &unescape($symb); + $parameter = &unescape($parameter); my $symb_id = &get_symb_id($symb); if ($parameter eq 'timestamp') { # We can deal with 'timestamp' right away @@ -1316,7 +1309,7 @@ sub update_full_student_data { chop($store_command); $dbh->do($store_command); if ($dbh->err) { - $returnstatus = 'error storing part data'; + $returnstatus = 'error saving part data'; &Apache::lonnet::logthis('insert error '.$dbh->errstr()); &Apache::lonnet::logthis("While attempting\n".$store_command); } @@ -1356,7 +1349,7 @@ sub update_full_student_data { chop($store_command); $dbh->do($store_command); if ($dbh->err) { - $returnstatus = 'error storing response data'; + $returnstatus = 'error saving response data'; &Apache::lonnet::logthis('insert error '.$dbh->errstr()); &Apache::lonnet::logthis("While attempting\n".$store_command); } @@ -1368,9 +1361,9 @@ sub update_full_student_data { ($sname,$sdom,$courseid, &Apache::lonnet::convert_dump_to_currentdump(\%studentdata)); if ($returnstatus eq 'okay' && $status ne 'okay') { - $returnstatus = 'error storing current data:'.$status; + $returnstatus = 'error saving current data:'.$status; } elsif ($status ne 'okay') { - $returnstatus .= ' error storing current data:'.$status; + $returnstatus .= ' error saving current data:'.$status; } ## ## Update the students time...... @@ -1398,7 +1391,7 @@ Input: $sname, $sdom, $courseid Output: $returnstatus, \%student_data -$returnstatus is a string describing any errors that occured. 'okay' is the +$returnstatus is a string describing any errors that occurred. 'okay' is the default. \%student_data is the data returned by a call to lonnet::currentdump. @@ -1669,9 +1662,9 @@ sub ensure_current_data { # # Get the update time for the user my $updatetime = 0; + my $getuserdir = 1; my $modifiedtime = &Apache::lonnet::GetFileTimestamp - ($sdom,$sname,$courseid.'.db', - $Apache::lonnet::perlvar{'lonUsersDir'}); + ($sdom,$sname,$courseid.'.db',$getuserdir); # if ($modifiedtime == -1) { return ('no data',undef); @@ -1682,7 +1675,7 @@ sub ensure_current_data { "student_id ='$student_id'"); my $data = undef; if (@Result) { - $updatetime = $Result[0]->[5]; # Ack! This is dumb! + $updatetime = $Result[0]->[6]; # Ack! This is dumb! } if ($modifiedtime > $updatetime) { ($status,$data) = &update_student_data($sname,$sdom,$courseid); @@ -1721,16 +1714,16 @@ sub ensure_current_full_data { &ensure_tables_are_set_up($courseid); # # Get the update time for the user + my $getuserdir = 1; my $modifiedtime = &Apache::lonnet::GetFileTimestamp - ($sdom,$sname,$courseid.'.db', - $Apache::lonnet::perlvar{'lonUsersDir'}); + ($sdom,$sname,$courseid.'.db',$getuserdir); # my $student_id = &get_student_id($sname,$sdom); my @Result = &Apache::lonmysql::get_rows($student_table, "student_id ='$student_id'"); my $updatetime; if (@Result && ref($Result[0]) eq 'ARRAY') { - $updatetime = $Result[0]->[6]; + $updatetime = $Result[0]->[7]; } if (! defined($updatetime) || $modifiedtime > $updatetime) { $status = &update_full_student_data($sname,$sdom,$courseid); @@ -2005,7 +1998,7 @@ sub get_problem_statistics { &setup_table_names($courseid); my $symb_id = &get_symb_id($symb); my $part_id = &get_part_id($part); - my $stats_table = $courseid.'_problem_stats'; + my $stats_table = &temp_table_name($courseid,'problem_stats'); # my $dbh = &Apache::lonmysql::get_dbh(); return undef if (! defined($dbh)); @@ -2209,7 +2202,7 @@ sub populate_weight_table { $dbh->do($request); if ($dbh->err()) { &Apache::lonnet::logthis("error ".$dbh->errstr(). - " occured executing \n". + " occurred executing \n". $request); } return; @@ -2518,7 +2511,7 @@ sub score_stats { my $time_limits = &limit_by_start_end_time($starttime,$endtime,'a'); my @Symbids = map { &get_symb_id($_); } @{$symbs}; # - my $stats_table = $courseid.'_problem_stats'; + my $stats_table = &temp_table_name($courseid,'problem_stats'); my $symb_restriction = join(' OR ',map {'a.symb_id='.$_;} @Symbids); my $request = 'DROP TABLE '.$stats_table; $dbh->do($request); @@ -2597,7 +2590,7 @@ sub count_stats { my $time_limits = &limit_by_start_end_time($starttime,$endtime,'a'); my @Symbids = map { &get_symb_id($_); } @{$symbs}; # - my $stats_table = $courseid.'_problem_stats'; + my $stats_table = &temp_table_name($courseid,'problem_stats'); my $symb_restriction = join(' OR ',map {'a.symb_id='.$_;} @Symbids); my $request = 'DROP TABLE '.$stats_table; $dbh->do($request); @@ -2895,7 +2888,7 @@ sub get_student_scores { &setup_table_names($courseid); my $dbh = &Apache::lonmysql::get_dbh(); return (undef) if (! defined($dbh)); - my $tmptable = $courseid.'_temp_'.time; + my $tmptable = &temp_table_name($courseid,'temp_'.time); my $request = 'DROP TABLE IF EXISTS '.$tmptable; # &Apache::lonnet::logthis('request = '.$/.$request); $dbh->do($request); @@ -3007,7 +3000,7 @@ sub setup_table_names { } # # Set up database names - my $base_id = $courseid; + my $base_id = 'md5_'.&Digest::MD5::md5_hex($courseid); $symb_table = $base_id.'_'.'symb'; $part_table = $base_id.'_'.'part'; $student_table = $base_id.'_'.'student'; @@ -3036,6 +3029,12 @@ sub setup_table_names { return; } +sub temp_table_name { + my ($courseid,$affix) = @_; + my $base_id = 'md5_'.&Digest::MD5::md5_hex($courseid); + return $base_id.'_'.$affix; +} + ################################################ ################################################ @@ -3093,6 +3092,12 @@ sub CL_FULLNAME { return 6; } sub CL_STATUS { return 7; } sub CL_TYPE { return 8; } sub CL_LOCKEDTYPE { return 9; } +sub CL_GROUP { return 10; } +sub CL_PERMANENTEMAIL { return 11; } +sub CL_ROLE { return 12; } +sub CL_EXTENT { return 13; } +sub CL_PHOTO { return 14; } +sub CL_THUMBNAIL { return 15; } sub get_classlist { my ($cdom,$cnum) = @_; @@ -3179,7 +3184,7 @@ sub get_group_memberships { my $access_end = $env{'course.'.$cid.'.default_enrollment_end_date'}; my %curr_groups =&Apache::longroup::coursegroups($cdom,$cnum); if (%curr_groups) { - my $grpindex = scalar(@{$keylist}); + my $grpindex = &CL_GROUP(); my %groupmemberhash = &Apache::lonnet::get_group_membership($cdom,$cnum); foreach my $student (keys(%{$classlist})) {