--- loncom/interface/Attic/londropadd.pm 2007/05/21 23:38:40 1.160
+++ loncom/interface/Attic/londropadd.pm 2007/07/26 23:56:35 1.165
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# $Id: londropadd.pm,v 1.160 2007/05/21 23:38:40 albertel Exp $
+# $Id: londropadd.pm,v 1.165 2007/07/26 23:56:35 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -133,8 +133,7 @@ sub domain_form {
###############################################################
# Menu Phase One
sub print_main_menu {
- my ($r,$enrl_permission,$view_permission,$grp_manage_permission,
- $grp_view_permission)=@_;
+ my ($r,$permission)=@_;
#
my $cid =$env{'request.course.id'};
my $cdom=$env{'course.'.$cid.'.domain'};
@@ -144,55 +143,56 @@ sub print_main_menu {
{ text => 'Upload a class list',
help => 'Course_Create_Class_List',
action => 'upload',
- permission => $enrl_permission,
+ permission => $permission->{'enrl'},
},
{ text => 'Enroll a single student',
help => 'Course_Add_Student',
action => 'enrollstudent',
- permission => $enrl_permission,
+ permission => $permission->{'enrl'},
},
{ text => 'Modify student data',
help => 'Course_Modify_Student_Data',
action => 'modifystudent',
- permission => $enrl_permission,
+ permission => $permission->{'enrl'},
},
{ text => 'View Class List',
help => 'Course_View_Class_List',
action => 'classlist',
- permission => $view_permission,
+ permission => $permission->{'view'},
},
{ text => 'Drop Students',
help => 'Course_Drop_Student',
action => 'drop',
- permission => $enrl_permission,
+ permission => $permission->{'enrl'},
},
{ text => 'Automated Enrollment Manager',
- permission => &Apache::lonnet::auto_run($cnum,$cdom),
+ permission => (&Apache::lonnet::auto_run($cnum,$cdom)
+ && $permission->{'enrl'}),
url => '/adm/populate',
},
{ text => 'Create a new group',
help => 'Course_Create_Group',
- permission => $grp_manage_permission,
+ permission => $permission->{'grp_manage'},
url => '/adm/coursegroups?refpage=enrl&action=create',
},
{ text => 'Modify an existing group',
help => 'Course_Modify_Group',
- permission => $grp_manage_permission,
+ permission => $permission->{'grp_manage'},
url => '/adm/coursegroups?refpage=enrl&action=modify',
},
{ text => 'Delete an existing group',
help => 'Course_Delete_Group',
- permission => $grp_manage_permission,
+ permission => $permission->{'grp_manage'},
url => '/adm/coursegroups?refpage=enrl&action=delete',
},
{ text => 'Re-enable a deleted group',
help => 'Course_Reenable_Group',
- permission => $grp_manage_permission,
+ permission => $permission->{'grp_manage'},
url => '/adm/coursegroups?refpage=enrl&action=reenable',
},
{ text => 'Enter an existing group',
help => 'Course_Display_Group',
- permission => $grp_view_permission,
+ permission => $permission->{'grp_view'},
url => '/adm/coursegroups?refpage=enrl&action=view',
},
);
@@ -752,8 +752,8 @@ sub enroll_single_student {
}
$r->print('
'.&mt('Enrolling Student').'
');
- $r->print(''.&mt('Enrolling').' '.$env{'form.cuname'}." \@ ".
- $env{'form.lcdomain'}.'
');
+ $r->print(''.&mt('Enrolling [_1] : [_2]',$env{'form.cuname'},
+ $env{'form.lcdomain'}).'
');
if (($env{'form.cuname'})
&& ($env{'form.cuname'}
eq &LONCAPA::clean_username($env{'form.cuname'}))
@@ -1064,15 +1064,15 @@ END
END
}
@@ -1169,7 +1169,7 @@ sub print_drop_menu {
# ============================================== view classlist
sub print_html_classlist {
- my ($r,$mode) = @_;
+ my ($r,$mode,$permission) = @_;
if (! exists($env{'form.sortby'})) {
$env{'form.sortby'} = 'username';
}
@@ -1233,6 +1233,16 @@ sub print_html_classlist {
# Print the classlist
$r->print(''.&mt('Current Class List').'
');
my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
+
+ if (exists($permission->{'view_section'})) {
+ my $sec = &Apache::loncoursedata::CL_SECTION();
+ foreach my $student (keys(%{$classlist})) {
+ if ($classlist->{$student}[$sec] ne $permission->{'view_section'}) {
+ delete($classlist->{$student});
+ }
+ }
+ }
+
if (! defined($classlist)) {
$r->print(&mt('There are no students currently enrolled.')."\n");
} else {
@@ -1296,6 +1306,7 @@ END
'start' => "start date",
'end' => "end date",
'type' => "enroll type/action",
+ 'email' => "email address",
'photo' => "photo",
);
unless ($mode eq 'autoenroll') {
@@ -1348,6 +1359,8 @@ function photowindow(photolink) {
$lt{'end'}
$lt{'grp'}
+ |
+ $lt{'email'}
|
END
if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
@@ -1391,13 +1404,15 @@ END
print $CSVfile '"'.join('","',map {
&Apache::loncommon::csv_translate(&mt($_))
} ("username","domain","ID","student name",
- "section","start date","end date","status","active groups"))
+ "section","start date","end date","status",
+ "active groups","email address"))
.'"'."\n";
} else {
print $CSVfile '"'.join('","',map {
&Apache::loncommon::csv_translate(&mt($_))
} ("username","domain","ID","student name",
- "section","start date","end date","active groups")).'"'."\n";
+ "section","start date","end date",
+ "active groups","email address")).'"'."\n";
}
} elsif ($mode eq 'excel') {
# Create the excel spreadsheet
@@ -1413,7 +1428,7 @@ END
$excel_sheet->write($row++,0,["username","domain","ID",
"student name","section",
"start date","end date","status",
- "active groups"],
+ "active groups","email address"],
$format->{'bold'});
}
#
@@ -1452,10 +1467,21 @@ END
my $name = $sdata->[$index{'fullname'}];
my $id = $sdata->[$index{'id'}];
my $status = $sdata->[$index{'status'}];
+ next if (($statusmode ne 'Any') && ($status ne $statusmode));
my $start = $sdata->[$index{'start'}];
my $end = $sdata->[$index{'end'}];
my $type = $sdata->[$index{'type'}];
- next if (($statusmode ne 'Any') && ($status ne $statusmode));
+
+ my %emails = &Apache::loncommon::getemails($username,$domain);
+ my $email;
+ foreach my $type ('critnotification', 'permanentemail',
+ 'notification') {
+ if ($emails{$type} =~ /\S/) {
+ $email = $emails{$type};
+ last;
+ }
+ }
+
if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
if (! defined($start) || $start == 0) {
$start = &mt('none');
@@ -1515,6 +1541,7 @@ END
$start |
$end |
$active_groups |
+ $email |
END
if ($env{'course.'.$env{'request.course.id'}.
'.internal.showphoto'}) {
@@ -1551,6 +1578,7 @@ END
push @line,&Apache::loncommon::csv_translate($status);
}
push @line,&Apache::loncommon::csv_translate($active_groups);
+ push @line,&Apache::loncommon::csv_translate($email);
print $CSVfile '"'.join('","',@line).'"'."\n";
} elsif ($mode eq 'excel') {
$excel_sheet->write($row,0,[$username,$domain,$id,
@@ -1567,6 +1595,7 @@ END
}
$excel_sheet->write($row,$col++,$status);
$excel_sheet->write($row,$col++,$active_groups);
+ $excel_sheet->write($row,$col++,$email);
$row++;
}
}
@@ -1688,7 +1717,7 @@ $lt{'odcc'}
$lt{'mef'} $info{'firstname'} $info{'middlename'}
-$info{'lastname'} $info{'generation'}, $sname\@$sdom
+$info{'lastname'} $info{'generation'}, $sname:$sdom
$lt{'sn'}
@@ -1749,7 +1778,7 @@ sub modify_single_student {
$env{'request.course.id'});
my ($tmp) = keys(%old);
if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
- $r->print(&mt('There was an error determining the environment values for')." $slogin \@ $sdom.");
+ $r->print(&mt('There was an error determining the environment values for')." $slogin : $sdom.");
return;
}
undef $tmp;
@@ -1789,7 +1818,7 @@ sub modify_single_student {
'et' => "End Time",
);
$r->print(<$lt{'mdu'} $slogin \@ $sdom
+ $lt{'mdu'} $slogin : $sdom
$lt{'si'}
@@ -1849,8 +1878,8 @@ END
&mt('The error reported was')." ".
$roleresults);
&Apache::lonnet::logthis("londropadd:failed attempt to modify student".
- " data for ".$slogin." \@ ".$sdom." by ".
- $env{'user.name'}." \@ ".$env{'user.domain'}.
+ " data for ".$slogin." : ".$sdom." by ".
+ $env{'user.name'}." : ".$env{'user.domain'}.
":".$roleresults);
} else { # everything is okay!
$r->print(&mt('Student information updated successfully.')."
".
@@ -2400,6 +2429,32 @@ function validate(caller) {
END
}
+sub get_permission {
+ my %permission;
+ $permission{'view'} =
+ &Apache::lonnet::allowed('vcl',$env{'request.course.id'});
+ if (!$permission{'view'}) {
+ my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
+ $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
+ if ($permission{'view'}) {
+ $permission{'view_section'} = $env{'request.course.sec'};
+ }
+ }
+
+ $permission{'enrl'} =
+ &Apache::lonnet::allowed('cst',$env{'request.course.id'});
+
+ $permission{'grp_view'} =
+ &Apache::lonnet::allowed('vcg',$env{'request.course.id'});
+ $permission{'grp_manage'} =
+ &Apache::lonnet::allowed('mdg',$env{'request.course.id'});
+ my $allowed = 0;
+ foreach my $perm (values(%permission)) {
+ if ($perm) { $allowed=1; last; }
+ }
+ return (\%permission,$allowed);
+}
+
###################################################################
###################################################################
@@ -2458,22 +2513,13 @@ sub handler {
return HTTP_NOT_ACCEPTABLE;
}
#
- my $view_permission =
- &Apache::lonnet::allowed('vcl',$env{'request.course.id'});
- my $enrl_permission =
- &Apache::lonnet::allowed('cst',$env{'request.course.id'});
-
- my $grp_view_permission =
- &Apache::lonnet::allowed('vcg',$env{'request.course.id'});
- my $grp_manage_permission =
- &Apache::lonnet::allowed('mdg',$env{'request.course.id'});
+ my ($permission,$allowed) = &get_permission();
- if (! $grp_view_permission && ! $grp_manage_permission &&
- ! $view_permission && ! $enrl_permission) {
+ if (!$allowed) {
$env{'user.error.msg'}=
- "/adm/coursegroups:cst:0:0:Cannot manage or view course groups, ".
- "or drop or add students";
+ "/adm/dropadd:cst:0:0:Cannot manage or view course groups, ".
+ "or drop or add students";
return HTTP_NOT_ACCEPTABLE;
}
@@ -2488,9 +2534,8 @@ sub handler {
# Main switch on form.action and form.state, as appropriate
if (! exists($env{'form.action'})) {
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment Manager'));
- &print_main_menu($r,$enrl_permission,$view_permission,$grp_manage_permission,
- $grp_view_permission);
- } elsif ($env{'form.action'} eq 'upload' && $enrl_permission) {
+ my $action = &print_main_menu($r,$permission);
+ } elsif ($env{'form.action'} eq 'upload' && $permission->{'enrl'}) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>'/adm/dropadd?action=upload&state=',
text=>"Upload Classlist"});
@@ -2509,7 +2554,7 @@ sub handler {
} else {
&print_first_courselist_upload_form($r);
}
- } elsif ($env{'form.action'} eq 'drop' && $enrl_permission) {
+ } elsif ($env{'form.action'} eq 'drop' && $permission->{'enrl'}) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>'/adm/dropadd?action=drop',
text=>"Drop Students"});
@@ -2522,7 +2567,7 @@ sub handler {
} else {
&print_drop_menu($r);
}
- } elsif ($env{'form.action'} eq 'enrollstudent' && $enrl_permission) {
+ } elsif ($env{'form.action'} eq 'enrollstudent' && $permission->{'enrl'}) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>'/adm/dropadd?action=enrollstudent',
text=>"Enroll Student"});
@@ -2537,35 +2582,35 @@ sub handler {
} else {
&get_student_username_domain_form($r);
}
- } elsif ($env{'form.action'} eq 'classlist' && $view_permission) {
+ } elsif ($env{'form.action'} eq 'classlist' && $permission->{'view'}) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>'/adm/dropadd?action=classlist',
text=>"View Classlist"});
$r->print(&Apache::lonhtmlcommon::breadcrumbs('View Classlist',
'Course_View_Class_List'));
if (! exists($env{'form.state'})) {
- &print_html_classlist($r,undef);
+ &print_html_classlist($r,undef,$permission);
} elsif ($env{'form.state'} eq 'csv') {
- &print_html_classlist($r,'csv');
+ &print_html_classlist($r,'csv',$permission);
} elsif ($env{'form.state'} eq 'excel') {
- &print_html_classlist($r,'excel');
+ &print_html_classlist($r,'excel',$permission);
} else {
- &print_html_classlist($r,undef);
+ &print_html_classlist($r,undef,$permission);
}
- } elsif ($env{'form.action'} eq 'modifystudent' && $enrl_permission) {
+ } elsif ($env{'form.action'} eq 'modifystudent' && $permission->{'enrl'}) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>'/adm/dropadd?action=modifystudent',
text=>"Modify Student Data"});
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Modify Student Data',
'Course_Modify_Student_Data'));
if (! exists($env{'form.state'})) {
- &print_html_classlist($r);
+ &print_html_classlist($r,undef,$permission);
} elsif ($env{'form.state'} eq 'selected') {
&print_modify_student_form($r);
} elsif ($env{'form.state'} eq 'done') {
&modify_single_student($r);
} else {
- &print_html_classlist($r);
+ &print_html_classlist($r,undef,$permission);
}
} else {
# We should not end up here, but I guess it is possible
@@ -2573,7 +2618,7 @@ sub handler {
"form.action = ".$env{'form.action'}.
"Someone should fix this.");
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment Manager'));
- &print_main_menu($r,$enrl_permission,$view_permission);
+ &print_main_menu($r,$permission);
}
#
# Finish up