-
-Upload a courselist
-
- Type:
-CSV (comma separated values, spreadsheet)
-Space separated
-Tabulator separated
-HTML/XML
-
-
-
-Enroll a single student
-
-
-Drop a student
-
-ENDUPFORM
- }
-# ------------------------------------------------------------------- Phase two
- if ($ENV{'form.phase'} eq 'two') {
- if ($ENV{'form.fileupload'}) {
- my $datatoken=Apache::lonnet::reply(
- 'tmpput:'.Apache::lonnet::escape($ENV{'form.upfile'}),
- $r->dir_config('lonHostID'));
- my $separator='';
- my $remove='';
- if ($ENV{'form.upfiletype'} eq 'csv') {
- $separator='\"\,\s*\"';
- $remove='"';
- } elsif ($ENV{'form.upfiletype'} eq 'space') {
- $separator='\s+';
- } elsif ($ENV{'form.upfiletype'} eq 'tab') {
- $separator='\t+';
- } elsif ($ENV{'form.upfiletype'} eq 'xml') {
- }
- my @lines=split(/\n/,$ENV{'form.upfile'});
- my $total=$#lines+1;
- $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
- my $krbdefdom=$1;
- $krbdefdom=~tr/a-z/A-Z/;
- $r->print(<
-
-
-
-Identify fields
-Total number of students: $total
-
-Field Samples
-ENDPICK
- my @sone; my @stwo; my @sthree; my $nfields=0;
- if ($#lines>=0) {
- $lines[0]=~s/^$remove//;
- $lines[0]=~s/$remove$//;
- @sone=split(/$separator/,$lines[0]);
- $nfields=$#sone;
- if ($#lines>=1) {
- $lines[1]=~s/^$remove//;
- $lines[1]=~s/$remove$//;
- @stwo=split(/$separator/,$lines[1]);
- $nfields=$#stwo;
- }
- if ($#lines>=2) {
- $lines[2]=~s/^$remove//;
- $lines[2]=~s/$remove$//;
- @sthree=split(/$separator/,$lines[2]);
- $nfields=$#sthree;
- }
- my $i;
- for ($i=0;$i<=$nfields;$i++) {
- $r->print('');
- map {
- my ($value,$display)=split(/\:/,$_);
- $r->print(''.$display.
- ' ');
- } ('none: ','username:Username',
- 'names:Last Name, First Names',
- 'fname:First Name','mname:Middle Names/Initials',
- 'lname:Last Name','gen:Generation',
- 'id:ID/Student Number','sec:Group/Section',
- 'ipwd:Initial Password');
- $r->print(' ');
- if (defined($sone[$i])) {
- $r->print($sone[$i]."\n");
- }
- if (defined($stwo[$i])) {
- $r->print($stwo[$i]."\n");
- }
- if (defined($sthree[$i])) {
- $r->print($sthree[$i]."\n");
- }
- $r->print(' ');
- }
- }
- $r->print(<$lt{'cd'}
+
+$lt{'gs'}:
+
+$date_table
+
+$lt{'idsn'}
+
+$lt{'idsn'}:
+
+
+$lt{'disn'}
+
+
+
+END
+ return;
+}
+
+# ========================================================= Menu Phase Two Drop
+sub print_drop_menu {
+ my $r=shift;
+ $r->print("".&mt('Drop Students')." ");
+ my $cid=$ENV{'request.course.id'};
+ my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
+ if (! defined($classlist)) {
+ $r->print(&mt('There are no students currently enrolled.')."\n");
+ return;
+ }
+ # Print out the available choices
+ &show_drop_list($r,$classlist,$keylist);
+ return;
+}
+
+# ============================================== view classlist
+sub print_html_classlist {
+ my $r=shift;
+ if (! exists($ENV{'form.sortby'})) {
+ $ENV{'form.sortby'} = 'username';
+ }
+ if ($ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
+ $ENV{'form.Status'} = 'Active';
+ }
+ my $status_select = &Apache::lonhtmlcommon::StatusOptions
+ ($ENV{'form.Status'},'studentform');
+ my $CCL=&mt('Current Class List');
+ $r->print(<
+
+
+$CCL
+
+END
+ if ($ENV{'form.action'} ne 'modifystudent') {
+ my %lt=&Apache::lonlocal::texthash(
+ 'ef' => "Excel format",
+ 'ss' => "Student Status",
+ );
+ $r->print(<
+CSV format
+
+$lt{'ef'}
+
+
+$lt{'ss'}:
+END
+ }
+ $r->print($status_select."
\n");
+ my $cid=$ENV{'request.course.id'};
+ my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
+ if (! defined($classlist)) {
+ $r->print(&mt('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','modifystudent',
+ $ENV{'form.Status'},$classlist,$keylist);
+ } else {
+ &show_class_list($r,'view','aboutme','classlist',
+ $ENV{'form.Status'},$classlist,$keylist);
+ }
+ }
+}
+
+# ============================================== view classlist
+sub print_formatted_classlist {
+ my $r=shift;
+ my $mode = shift;
+ my $cid=$ENV{'request.course.id'};
+ my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
+ if (! defined($classlist)) {
+ $r->print(&mt('There are no students currently enrolled.')."\n");
+ } else {
+ &show_class_list($r,$mode,'nolink','csv',
+ $ENV{'form.Status'},$classlist,$keylist);
+ }
+}
+
+# =================================================== Show student list to drop
+sub show_class_list {
+ my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_;
+ my $cid=$ENV{'request.course.id'};
+ #
+ # Variables for excel output
+ my ($excel_workbook, $excel_sheet, $excel_filename,$row);
+ #
+ my $sortby = $ENV{'form.sortby'};
+ if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
+ $sortby = 'username';
+ }
+ # Print out header
+ if ($mode eq 'view') {
+ if ($linkto eq 'aboutme') {
+ $r->print(&mt('Select a user name to view the users personal page.'));
+ } elsif ($linkto eq 'modify') {
+ $r->print(&mt('Select a user name to modify the students information'));
+ }
+ my %lt=&Apache::lonlocal::texthash(
+ 'usrn' => "username",
+ 'dom' => "domain",
+ 'sn' => "student name",
+ 'sec' => "section",
+ );
+ $r->print(<
+
+
+
+
+
+ $lt{'usrn'}
+
+ $lt{'dom'}
+
+ ID
+
+ $lt{'sn'}
+
+ $lt{'sec'}
+
+
+END
+ } elsif ($mode eq 'csv') {
+ if($statusmode eq 'Expired') {
+ $r->print(&mt('Students with expired roles'));
+ }
+ if ($statusmode eq 'Any') {
+ $r->print('"'.join('","',(&mt("username"),&mt("domain"),"ID",
+ &mt("student name"),&mt("section"),&mt("status"))).
+ '"'."\n");
+ } else {
+ $r->print('"'.join('","',(&mt("username"),&mt("domain"),"ID",
+ &mt("student name"),&mt("section"))).'"'."\n");
+ }
+ } elsif ($mode eq 'excel') {
+ # Create the excel spreadsheet
+ $excel_filename = '/prtspool/'.
+ $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
+ time.'_'.rand(1000000000).'.xls';
+ $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.
+ $excel_filename);
+ $excel_workbook->set_tempdir('/home/httpd/perl/tmp');
+ $excel_sheet = $excel_workbook->addworksheet('classlist');
+ #
+ my $description = 'Class List for '.
+ $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
+ $excel_sheet->write($row++,0,$description);
+ #
+ $excel_sheet->write($row++,0,["username","domain","ID",
+ "student name","section","status"]);
+ }
+ #
+ # Sort the students
+ my %index;
+ my $i;
+ foreach (@$keylist) {
+ $index{$_} = $i++;
+ }
+ my $index = $index{$sortby};
+ my $second = $index{'username'};
+ my $third = $index{'domain'};
+ my @Sorted_Students = sort {
+ lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
+ ||
+ lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
+ ||
+ lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
+ } (keys(%$classlist));
+ foreach my $student (@Sorted_Students) {
+ my $username = $classlist->{$student}->[$index{'username'}];
+ my $domain = $classlist->{$student}->[$index{'domain'}];
+ my $section = $classlist->{$student}->[$index{'section'}];
+ my $name = $classlist->{$student}->[$index{'fullname'}];
+ my $id = $classlist->{$student}->[$index{'id'}];
+ my $status = $classlist->{$student}->[$index{'status'}];
+ next if (($statusmode ne 'Any') && ($status ne $statusmode));
+ if ($mode eq 'view') {
+ $r->print("\n \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");
+ }
+ $r->print(<<"END");
+
+ $domain
+ $id
+ $name
+ $section
+
+END
+ } elsif ($mode eq 'csv') {
+ # no need to bother with $linkto
+ my @line = ();
+ foreach ($username,$domain,$id,$name,$section) {
+ push @line,&Apache::loncommon::csv_translate($_);
+ }
+ if ($statusmode eq 'Any') {
+ push @line,&Apache::loncommon::csv_translate($status);
+ }
+ my $tmp = $";
+ $" = '","';
+ $r->print("\"@line\"\n");
+ $" = $tmp;
+ } elsif ($mode eq 'excel') {
+ $excel_sheet->write($row++,0,[$username,$domain,$id,
+ $name,$section,$status]);
+ }
+ }
+ if ($mode eq 'view') {
+ $r->print('
');
+ } elsif ($mode eq 'excel') {
+ $excel_workbook->close();
+ $r->print(''.
+ &mt('Your Excel spreadsheet').' '.&mt('is ready for download').'.
'."\n");
+ }
+}
+
+
+#
+# print out form for modification of a single students data
+#
+sub print_modify_student_form {
+ my $r = shift();
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['sdom','sname']);
+ my $sname = $ENV{'form.sname'};
+ my $sdom = $ENV{'form.sdom'};
+ my $sortby = $ENV{'form.sortby'};
+ # determine the students name information
+ my %info=&Apache::lonnet::get('environment',
+ ['firstname','middlename',
+ 'lastname','generation','id'],
+ $sdom, $sname);
+ my ($tmp) = keys(%info);
+ if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
+ $r->print(''.&mt('Error').' '.
+ ''.
+ &mt('Unable to retrieve environment data for').' '.$sname.
+ &mt('in domain').' '.$sdom.'
'.
+ &mt('Please contact your LON-CAPA administrator regarding this situation.').'