--- loncom/interface/Attic/londropadd.pm 2001/01/15 14:51:18 1.9
+++ loncom/interface/Attic/londropadd.pm 2008/11/17 15:48:46 1.175
@@ -1,217 +1,588 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# (Handler to set parameters for assessments
+# $Id: londropadd.pm,v 1.175 2008/11/17 15:48:46 jms Exp $
#
-# (Handler to resolve ambiguous file locations
+# Copyright Michigan State University Board of Trustees
#
-# (TeX Content Handler
+# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
-# 05/29/00,05/30,10/11 Gerd Kortemeyer)
+# LON-CAPA is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
#
-# 10/11,10/12,10/16 Gerd Kortemeyer)
+# LON-CAPA is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-# 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28,
-# 12/08,12/12 Gerd Kortemeyer)
+# You should have received a copy of the GNU General Public License
+# along with LON-CAPA; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# 12/26,12/27,12/28,
-# 01/01/01,01/15 Gerd Kortemeyer
+# /home/httpd/html/adm/gpl.txt
+#
+# http://www.lon-capa.org/
+#
+#
+
+=head1 NAME
+
+Apache::londropadd
+
+=head1 SYNOPSIS
+
+drop & add students
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+=head1 SUBROUTINES
+
+=over
+
+=cut
package Apache::londropadd;
use strict;
use Apache::lonnet;
+use Apache::loncommon();
+use Apache::lonhtmlcommon();
use Apache::Constants qw(:common :http REDIRECT);
+use Spreadsheet::WriteExcel;
+use Apache::lonstathelpers();
+use Apache::lonlocal;
+use Apache::longroup;
+use LONCAPA();
+
+sub header {
+ my ($jscript,$loaditems) = @_;
+ my $start_page;
+ if (ref($loaditems) eq 'HASH') {
+ $start_page=&Apache::loncommon::start_page('Enrollment Manager',$jscript,{'add_entries' => $loaditems,});
+ } else {
+ $start_page=&Apache::loncommon::start_page('Enrollment Manager',$jscript);
+ }
+ return(<
+ENDHEAD
+}
+=pod
-# ================================================================ Main Handler
+=item modifystudent()
-sub handler {
- my $r=shift;
+ Drop student from all sections of a course, except optional $csec
- if ($r->header_only) {
- $r->content_type('text/html');
- $r->send_http_header;
- return OK;
- }
+=cut
-# ----------------------------------------------------- Needs to be in a course
+sub modifystudent {
+ my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
+ # if $csec is undefined, drop the student from all the courses matching
+ # this one. If $csec is defined, drop them from all other sections of
+ # this course and add them to section $csec
+ my $cdom = $env{'course.'.$courseid.'.domain'};
+ my $cnum = $env{'course.'.$courseid.'.num'};
+ my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
+ my ($tmp) = keys(%roles);
+ # Bail out if we were unable to get the students roles
+ return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
+ # Go through the roles looking for enrollment in this course
+ my $result = '';
+ foreach my $course (keys(%roles)) {
+ if ($course=~m{^/\Q$cdom\E/\Q$cnum\E(?:\/)*(?:\s+)*(\w+)*\_st$}) {
+ # We are in this course
+ my $section=$1;
+ $section='' if ($course eq "/$cdom/$cnum".'_st');
+ if (defined($csec) && $section eq $csec) {
+ $result .= 'ok:';
+ } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
+ my (undef,$end,$start)=split(/\_/,$roles{$course});
+ my $now=time;
+ # if this is an active role
+ if (!($start && ($now<$start)) || !($end && ($now>$end))) {
+ my $reply=&Apache::lonnet::modifystudent
+ # dom name id mode pass f m l g
+ ($udom,$unam,'', '', '',undef,undef,undef,undef,
+ $section,time,undef,undef,$desiredhost);
+ $result .= $reply.':';
+ }
+ }
+ }
+ }
+ if ($result eq '') {
+ $result = 'Unable to find section for this student';
+ } else {
+ $result =~ s/(ok:)+/ok/g;
+ }
+ return $result;
+}
- if (($ENV{'request.course.fn'}) &&
- (&Apache::lonnet::allowed('cst',$ENV{'request.course.id'}))) {
+=pod
-# ------------------------------------------------------------------ Start page
- $r->content_type('text/html');
- $r->send_http_header;
- $r->print(<
-
-LON-CAPA Student Drop/Add
-
-
-
-Drop/Add Students
-
\n\n".&mt('Processed [_1] student(s).',$count).
+ "
\n");
+ $r->print("\n".
+ &mt('If active, the new role will be available when the '.
+ 'students next log in to LON-CAPA.')."
\n");
+ #####################################
+ # Drop students #
+ #####################################
+ if ($env{'form.fullup'} eq 'yes') {
+ $r->print(''.&mt('Dropping Students')."
\n");
+ # Get current classlist
+ my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
+ if (! defined($classlist)) {
+ $r->print(&mt('There are no students currently enrolled.').
+ "\n");
+ } else {
+ # Remove the students we just added from the list of students.
+ foreach (@studentdata) {
+ my %entries=&Apache::loncommon::record_sep($_);
+ unless (($entries{$fields{'username'}} eq '') ||
+ (!defined($entries{$fields{'username'}}))) {
+ delete($classlist->{$entries{$fields{'username'}}.
+ ':'.$domain});
+ }
+ }
+ # Print out list of dropped students.
+ &show_drop_list($r,$classlist,$keylist,'nosort');
+ }
+ }
+ } # end of unless
+}
- } else {
- $r->print(
- 'Could not access classlist: '.$classlst.
- '
');
- }
- }
-# ------------------------------------------------------------------------ Done
- }
+# ================================================================== Phase four
+sub drop_student_list {
+ my $r=shift;
+ my $count=0;
+ my @droplist = &Apache::loncommon::get_env_multiple('form.droplist');
+ foreach (@droplist) {
+ my ($uname,$udom)=split(/\:/,$_);
+ # drop student
+ my $result = &Apache::lonuserutils::modifystudent($udom,$uname,
+ $env{'request.course.id'});
+ if ($result eq 'ok' || $result eq 'ok:') {
+ $r->print(&mt('Dropped [_1]',$uname.'@'.$udom).'
');
+ $count++;
+ } else {
+ $r->print(
+ &mt('Error dropping [_1]:[_2]',$uname.'@'.$udom,$result).
+ '
');
}
- }
-# ------------------------------------------------------------------------- End
- $r->print('