--- loncom/interface/Attic/londropadd.pm 2002/09/17 15:52:44 1.50 +++ loncom/interface/Attic/londropadd.pm 2002/09/24 18:24:43 1.52 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to drop and add students in courses # -# $Id: londropadd.pm,v 1.50 2002/09/17 15:52:44 matthew Exp $ +# $Id: londropadd.pm,v 1.52 2002/09/24 18:24:43 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -728,48 +728,33 @@ END # =================================================== get the current classlist sub get_current_classlist { - my ($domain,$identifier) = @_; - # domain is the domain the class is being run in - # identifier is the internal, unique identifier for the class. - my %currentlist=(); - my $now=time; - my %results=&Apache::lonnet::dump('classlist',$domain,$identifier); - my ($tmp) = keys(%results); - if ($tmp !~ /^(con_lost|error|no_such_host)/i) { - foreach my $student (keys(%results)) { - # Extract the start and end dates - my ($end,$start)=split(/\:/,$results{$student}); - # If the class isn't over, put it in the list - unless (($end) && ($now>$end)) { - $currentlist{$student}=1; - } - } - return (undef,%currentlist); - } else { - $tmp =~ s/^error://; - return ($tmp,undef); - } + my $r = shift; + # Call DownloadClasslist + my $cid = $ENV{'request.course.id'}; + my $c = $r->connection; + my $classlisthash = &Apache::loncoursedata::DownloadClasslist + ($cid,'Not downloaded',$c); + # Call ProcessClasslist + my %cache; + my @students = &Apache::loncoursedata::ProcessClasslist(\%cache, + $classlisthash, + $cid,$c); + return (\@students,\%cache); } # ========================================================= Menu Phase Two Drop -sub menu_phase_two_drop { +sub print_drop_menu { my $r=shift; $r->print("

Drop Students

"); my $cid=$ENV{'request.course.id'}; - my ($error,%currentlist)=&get_current_classlist - ($ENV{'course.'.$cid.'.domain'},$ENV{'course.'.$cid.'.num'}); - if (defined($error)) { - if ($error =~ /^No such file or directory/) { - $r->print("There are no students currently enrolled.\n"); - } else { - $r->print("
ERROR:$error
"); - } - } elsif (!defined(%currentlist)) { + my ($student_array,$student_data)=&get_current_classlist($r); + if (! scalar(@$student_array)) { $r->print("There are no students currently enrolled.\n"); - } else { - # Print out the available choices - &show_drop_list($r,%currentlist); + return; } + # Print out the available choices + &show_drop_list($student_array,$student_data,$r); + return; } # ============================================== view classlist @@ -782,22 +767,15 @@ sub print_html_classlist {

END my $cid=$ENV{'request.course.id'}; - my ($error,%currentlist)=&get_current_classlist - ($ENV{'course.'.$cid.'.domain'},$ENV{'course.'.$cid.'.num'}); - if (defined($error)) { - if ($error =~ /^No such file or directory/) { - $r->print("There are no students currently enrolled.\n"); - } else { - $r->print("
ERROR:$error
"); - } - } elsif (!defined(%currentlist)) { + my ($student_array,$student_data)=&get_current_classlist($r); + if (! scalar(@$student_array)) { $r->print("There are no students currently enrolled.\n"); } else { # Print out the available choices if ($ENV{'form.action'} eq 'modifystudent') { - &show_class_list($r,'view','modify',%currentlist); + &show_class_list($r,'view','modify','any',$student_array,$student_data); } else { - &show_class_list($r,'view','aboutme',%currentlist); + &show_class_list($r,'view','aboutme','any',$student_array,$student_data); } } } @@ -806,24 +784,17 @@ END sub print_csv_classlist { my $r=shift; my $cid=$ENV{'request.course.id'}; - my ($error,%currentlist)=&get_current_classlist - ($ENV{'course.'.$cid.'.domain'},$ENV{'course.'.$cid.'.num'}); - if (defined($error)) { - if ($error =~ /^No such file or directory/) { - $r->print("There are no students currently enrolled.\n"); - } else { - $r->print("
ERROR:$error
"); - } - } elsif (!defined(%currentlist)) { + my ($student_array,$student_data)=&get_current_classlist($r); + if (! scalar(@$student_array)) { $r->print("There are no students currently enrolled.\n"); } else { - &show_class_list($r,'csv','nolink',%currentlist); + &show_class_list($r,'csv','nolink','any',$student_array,$student_data); } } # =================================================== Show student list to drop sub show_class_list { - my ($r,$mode,$linkto,%currentlist)=@_; + my ($r,$mode,$linkto,$statusmode,$students,$student_data)=@_; my $cid=$ENV{'request.course.id'}; # Print out header if ($mode eq 'view') { @@ -836,66 +807,63 @@ sub show_class_list {

- + END } elsif ($mode eq 'csv') { - $r->print('"'.join('","',("username","domain","ID","last name", - "first name","middle name","generation", + $r->print('"'.join('","',("username","domain","ID","student name", "section")).'"'."\n"); } - foreach (sort keys %currentlist) { - my ($sname,$sdom)=split(/\:/,$_); - my %reply=&Apache::lonnet::idrget($sdom,$sname); - my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid); - my %info=&Apache::lonnet::get('environment', - ['firstname','middlename', - 'lastname','generation'], - $sdom, $sname); - my ($tmp) = keys(%info); - if ($tmp =~ /^(con_lost|error|no_such_host)/i) { - if ($mode eq 'view') { - $r->print(''); - } else { - $r->print('"Internal error: unable to get environment for '. - $sname.' in domain '.$sdom.'"'); + foreach my $student (@$students) { + my $error; + if (exists($student_data->{$student.':error'})) { + $error = $student_data->{$student.':error'}; + } + if ($error) { + $r->print(''."\n"); + next; + } + my $username = $student_data->{$student.':username'}; + my $domain = $student_data->{$student.':domain'}; + my $section = $student_data->{$student.':section'}; + my $name = $student_data->{$student.':fullname'}; + my $status = $student_data->{$student.':Status'}; + my $id = $student_data->{$student.':id'}; + next if (($statusmode ne 'any') && ($status ne $statusmode)); + if ($mode eq 'view') { + $r->print("\n \n - - - - - + + + + END - } elsif ($mode eq 'csv') { - # no need to bother with $linkto - my @line = (); - foreach ($sname,$sdom,$reply{$sname}, - $info{'lastname'},$info{'firstname'}, - $info{'middlename'},$info{'generation'},$ssec) { - push @line,&Apache::loncommon::csv_translate($_); - } - my $tmp = $"; - $" = '","'; - $r->print("\"@line\"\n"); - $" = $tmp; + } elsif ($mode eq 'csv') { + # no need to bother with $linkto + my @line = (); + foreach ($username,$domain,$id,$name,$section) { + push @line,&Apache::loncommon::csv_translate($_); } + my $tmp = $"; + $" = '","'; + $r->print("\"@line\"\n"); + $" = $tmp; } } $r->print('
usernamedomainIDstudent namegenerationsection
student namesection
'. - 'Internal error: unable to get environment '. - 'for '.$sname.' in domain '.$sdom.'
'. + 'Error'. + 'Error retrieving data for '. + join('@',split(/:/,$student)). + ', '.$error.'
\n "); + if ($linkto eq 'nothing') { + $r->print($username); + } elsif ($linkto eq 'aboutme') { + $r->print(&Apache::loncommon::aboutmewrapper($username, + $username, + $domain)); + } elsif ($linkto eq 'modify') { + $r->print(''.$username."\n"); } - } else { - if ($mode eq 'view') { - $r->print("
\n "); - if ($linkto eq 'nothing') { - $r->print($sname); - } elsif ($linkto eq 'aboutme') { - $r->print(&Apache::loncommon::aboutmewrapper($sname,$sname, - $sdom)); - } elsif ($linkto eq 'modify') { - $r->print(''.$sname."\n"); - } - $r->print(<<"END"); + $r->print(<<"END"); $sdom$reply{$sname}$info{'lastname'}, $info{'firstname'} $info{'middlename'}$info{'generation'}$ssec$domain$id$name$section

') if ($mode eq 'view'); @@ -915,7 +883,7 @@ sub print_modify_student_form { # determine the students name information my %info=&Apache::lonnet::get('environment', ['firstname','middlename', - 'lastname','generation'], + 'lastname','generation','id'], $sdom, $sname); my ($tmp) = keys(%info); if ($tmp =~ /^(con_lost|error|no_such_host)/i) { @@ -938,6 +906,11 @@ sub print_modify_student_form { $endtime); # Make sure student is enrolled in course $r->print(< + +Only domain coordinators can change a users password. + +

@@ -955,6 +928,8 @@ $info{'lastname'} $info{'generation'}, $

+Student ID: +

Section:

@@ -982,6 +957,7 @@ sub modify_single_student { my $courseid = $ENV{'request.course.id'}; my $sname = $ENV{'form.slogin'}; my $sdom = $ENV{'form.sdomain'}; + my $sid = $ENV{'form.id'}; my $starttime = &Apache::lonhtmlcommon::get_date_from_form('startdate', time); my $endtime = &Apache::lonhtmlcommon::get_date_from_form('enddate', @@ -990,7 +966,7 @@ sub modify_single_student { my $displayable_endtime = localtime($endtime); # talk to the user about what we are going to do $r->print(< +

Modifying data for user $sname \@ $sdom

Student Information

@@ -1004,25 +980,30 @@ Modifying data for user: $sname \@ $sdom
First name $firstname
Start Time $displayable_starttime
End Time $displayable_endtime
+

END - # send request(s) to modify data - my $roleresults = 'refused'; - #my $roleresults = &Apache::lonnet::assignrole($sdom,$sname, - # $courseid.'/'.$section, - # 'st', - # $endtime,$starttime); + # Send request(s) to modify data + # The '1' in the call to modifystudent is to force the students + # id to be changed. + my $roleresults = &Apache::lonnet::modifystudent + ($sdom,$sname,$sid,undef,undef,$firstname,$middlename,$lastname, + $generation,$section,$endtime,$starttime,1); if ($roleresults =~/refused/) { $r->print("Your request to change the role information for this ". "student was refused."); } elsif ($roleresults !~ /ok/) { $r->print("An error occurred during the attempt to change the role". - " information for this student. The error reported was ". + " information for this student.
". + "The error reported was ". $roleresults); } else { # everything is okay! - $r->print("Student role updated successfully."); + $r->print("Student information updated successfully.
". + "The student must log out and log in again to see ". + "these changes."); } - # $r->print(<

+Modify another students data END return; @@ -1063,20 +1044,18 @@ sub get_enrollment_data { # =================================================== Show student list to drop sub show_drop_list { - my ($r,%currentlist)=@_; + my ($students,$student_data,$r)=@_; my $cid=$ENV{'request.course.id'}; $r->print(<<'END');