--- loncom/interface/loncoursedata.pm 2006/12/21 02:51:53 1.177 +++ loncom/interface/loncoursedata.pm 2008/01/05 18:36:26 1.185 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: loncoursedata.pm,v 1.177 2006/12/21 02:51:53 albertel Exp $ +# $Id: loncoursedata.pm,v 1.185 2008/01/05 18:36:26 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -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 @@ -369,8 +367,11 @@ sub init_dbs { { name => 'section', type => 'VARCHAR(100) BINARY', restrictions => 'NOT NULL'}, - { name => 'status', - type => 'VARCHAR(15) BINARY', + { name => 'start', + type => 'INT', + restrictions => 'NOT NULL'}, + { name => 'end', + type => 'INT', restrictions => 'NOT NULL'}, { name => 'classification', type => 'VARCHAR(100) BINARY', }, @@ -382,7 +383,8 @@ sub init_dbs { 'PRIMARY KEY' => ['student_id'], 'KEY' => [{ columns => ['student (100)', 'section (100)', - 'status (15)',]},], + 'start', + 'end']},], }; # my $groupnames_table_def = { @@ -906,18 +908,21 @@ sub populate_student_table { &init_dbs($courseid,0); my $dbh = &Apache::lonmysql::get_dbh(); my $request = 'INSERT IGNORE INTO '.$student_table. - "(student,section,status) VALUES "; + "(student,section,start,end) VALUES "; my $cdom = $env{'course.'.$courseid.'.domain'}; my $cnum = $env{'course.'.$courseid.'.num'}; my $classlist = &get_classlist($cdom,$cnum); my $student_count=0; while (my ($student,$data) = each %$classlist) { - my ($section,$status) = ($data->[&CL_SECTION()], - $data->[&CL_STATUS()]); + my ($section,$start,$end) = ($data->[&CL_SECTION()], + $data->[&CL_START()], + $data->[&CL_END()]); if ($section eq '' || $section =~ /^\s*$/) { $section = 'none'; } - $request .= "('".$student."','".$section."','".$status."'),"; + if (!defined($start)) { $start = 0; } + if (!defined($end)) { $end = 0; } + $request .= "('".$student."','".$section."','".$start."','".$end."'),"; $student_count++; } return if ($student_count == 0); @@ -1170,6 +1175,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 @@ -1309,7 +1316,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); } @@ -1349,7 +1356,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); } @@ -1361,9 +1368,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...... @@ -1675,7 +1682,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); @@ -1723,7 +1730,7 @@ sub ensure_current_full_data { "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); @@ -1998,7 +2005,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)); @@ -2022,14 +2029,8 @@ sub get_problem_statistics { $request .= ' WHERE a.symb_id='.$symb_id.' AND a.part_id='.$part_id; # # Limit the students included to those specified - if (defined($Sections) && lc($Sections->[0]) ne 'all') { - $request .= ' AND ('. - join(' OR ', map { "b.section='".$_."'" } @$Sections - ).')'; - } - if (defined($status) && lc($status) ne 'any') { - $request .= " AND b.status='".$status."'"; - } + my ($section_limits,$enrollment_limits)= + &limit_by_section_and_status($Sections,$status,'b'); # # Limit by starttime and endtime my $time_requirements = undef; @@ -2044,6 +2045,12 @@ sub get_problem_statistics { if (defined($time_requirements)) { $request .= ' AND '.$time_requirements; } + if (defined($section_limits)) { + $request .= ' AND '.$section_limits; + } + if (defined($enrollment_limits)) { + $request .= ' AND '.$enrollment_limits; + } # Limit by group, as required if (defined($group_limits)) { $request .= ' AND '.$group_limits; @@ -2270,7 +2277,20 @@ sub limit_by_section_and_status { } my $enrollment_requirements=undef; if (defined($enrollment) && $enrollment ne 'Any') { - $enrollment_requirements = $tablename.".status='".$enrollment."'"; + my $now = time(); + if ( $enrollment eq 'Future' ) { + $enrollment_requirements = + "( $tablename.start > $now AND ". + "( $tablename.end = 0 OR $tablename.end > $now))"; + } elsif ( $enrollment eq 'Active' ) { + $enrollment_requirements = + "(( $tablename.start = 0 OR $tablename.start < $now ) AND ". + " ( $tablename.end = 0 OR $tablename.end > $now ))"; + } elsif ( $enrollment eq 'Expired' ) { + $enrollment_requirements = + "(( $tablename.start < $now ) AND ". + " ( $tablename.end < $now ))"; + } } return ($student_requirements,$enrollment_requirements); } @@ -2498,7 +2518,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); @@ -2577,7 +2597,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); @@ -2875,7 +2895,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); @@ -2987,7 +3007,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'; @@ -3016,6 +3036,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; +} + ################################################ ################################################ @@ -3073,6 +3099,11 @@ 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 get_classlist { my ($cdom,$cnum) = @_; @@ -3159,7 +3190,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})) {