--- loncom/interface/lonuserutils.pm 2010/05/22 13:33:09 1.97.2.17
+++ loncom/interface/lonuserutils.pm 2009/10/31 14:27:48 1.102
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.97.2.17 2010/05/22 13:33:09 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.102 2009/10/31 14:27:48 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -91,7 +91,7 @@ sub modifyuserrole {
if ($setting eq 'course' || $context eq 'course') {
$scope = '/'.$cid;
$scope =~ s/\_/\//g;
- if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
+ if ($role ne 'cc' && $sec ne '') {
$scope .='/'.$sec;
}
} elsif ($context eq 'domain') {
@@ -295,7 +295,7 @@ sub hidden_input {
}
sub print_upload_manager_header {
- my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype)=@_;
+ my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission)=@_;
my $javascript;
#
if (! exists($env{'form.upfile_associate'})) {
@@ -332,7 +332,7 @@ sub print_upload_manager_header {
my $javascript_validations =
&javascript_validations('upload',$krbdefdom,$password_choice,undef,
$env{'request.role.domain'},$context,
- $groupslist,$crstype);
+ $groupslist);
my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
$r->print('
'
.&mt('Total number of records found in file: [_1]'
@@ -365,7 +365,7 @@ sub print_upload_manager_header {
###############################################################
sub javascript_validations {
my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
- $context,$groupslist,$crstype)=@_;
+ $context,$groupslist)=@_;
my %param = (
kerb_def_dom => $krbdefdom,
curr_authtype => $curr_authtype,
@@ -386,10 +386,10 @@ sub javascript_validations {
if (($context eq 'course') || ($context eq 'domain')) {
if ($context eq 'course') {
if ($env{'request.course.sec'} eq '') {
- $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
+ $setsection_call = 'setSections(document.'.$param{'formname'}.');';
$setsections_js =
&setsections_javascript($param{'formname'},$groupslist,
- $mode,'',$crstype);
+ $mode);
} else {
$setsection_call = "'ok'";
}
@@ -830,7 +830,7 @@ sub print_upload_manager_footer {
.' '.&mt('Add a domain role').''
.' '
.' '
- .' '.&mt('Add a course/community role').' '
+ .' '.&mt('Add a course role').''
.'';
} elsif ($context eq 'author') {
$Str .= &Apache::lonhtmlcommon::row_title(
@@ -899,7 +899,7 @@ sub print_upload_manager_footer {
.'
';
if ($context eq 'course') {
$Str .= ''
- .&mt('Note: This operation may be time consuming when adding several users.')
+ .&mt('Note: For large courses, this operation may be time consuming.')
.'
';
}
$Str .= ' =0) {
@@ -1176,7 +1176,7 @@ sub default_role_selector {
my %customroles;
my ($options,$coursepick,$cb_jscript);
if ($context ne 'author') {
- %customroles = &my_custom_roles($crstype);
+ %customroles = &my_custom_roles();
}
my %lt=&Apache::lonlocal::texthash(
@@ -1202,16 +1202,16 @@ sub default_role_selector {
$options .= ' '.$plrole.' ';
}
my $courseform = &Apache::loncommon::selectcourse_link
- ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course/Community');
+ ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course');
$cb_jscript =
- &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community');
+ &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform');
$coursepick = &Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row().
'
'.$courseform.' '.$lt{'rol'}.' '.
''.$lt{'grs'}.' '.
&Apache::loncommon::end_data_table_header_row().
&Apache::loncommon::start_data_table_row()."\n".
- ' '."\n".
+ ' '."\n".
''."\n".
&default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
' '.
@@ -1229,7 +1229,6 @@ sub default_role_selector {
$env{'request.role.domain'}.'" />'.
' '.
' '.
- ' '.
' '.
&Apache::loncommon::end_data_table_row().
&Apache::loncommon::end_data_table()."\n";
@@ -1350,14 +1349,10 @@ sub curr_role_permissions {
# ======================================================= Existing Custom Roles
sub my_custom_roles {
- my ($crstype) = @_;
my %returnhash=();
my %rolehash=&Apache::lonnet::dump('roles');
- foreach my $key (keys(%rolehash)) {
+ foreach my $key (keys %rolehash) {
if ($key=~/^rolesdef\_(\w+)$/) {
- if ($crstype eq 'Community') {
- next if ($rolehash{$key} =~ /bre\&S/);
- }
$returnhash{$1}=$1;
}
}
@@ -1446,19 +1441,14 @@ sub print_userlist {
' ');
return;
}
- if (!(($context eq 'domain') &&
- (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
- $r->print(
- "\n\n"
- .''
- .&list_submit_button(&mt('Update Display'))
- ."
\n"
- );
+ if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
+ $r->print(' '.&list_submit_button(&mt('Update Display')).
+ "\n\n");
}
my ($indexhash,$keylist) = &make_keylist_array();
- my (%userlist,%userinfo,$clearcoursepick);
+ my (%userlist,%userinfo);
if (($context eq 'domain') &&
- ($env{'form.roletype'} eq 'course') ||
+ ($env{'form.roletype'} eq 'course') ||
($env{'form.roletype'} eq 'community')) {
my ($crstype,$numcodes,$title,$warning);
if ($env{'form.roletype'} eq 'course') {
@@ -1481,15 +1471,9 @@ sub print_userlist {
$courseform."\n".
&Apache::lonhtmlcommon::row_closure(1).
&Apache::lonhtmlcommon::end_pick_box().''.
- ' '.
- &list_submit_button(&mt('Update Display')).
+ '
'.&list_submit_button(&mt('Update Display')).
"\n".'
'.$warning.' '."\n");
- $clearcoursepick = 0;
- if (($env{'form.origroletype'} ne '') &&
- ($env{'form.origroletype'} ne $env{'form.roletype'})) {
- $clearcoursepick = 1;
- }
- if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
+ if ($env{'form.coursepick'}) {
$r->print(' '.&mt('Searching').' ... ');
}
} else {
@@ -1564,7 +1548,7 @@ sub print_userlist {
}
} elsif (($env{'form.roletype'} eq 'course') ||
($env{'form.roletype'} eq 'community')) {
- if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
+ if ($env{'form.coursepick'}) {
my %courses = &process_coursepick();
my %allusers;
my $hidepriv = 1;
@@ -1721,7 +1705,7 @@ sub section_group_filter {
$env{'form.'.$name{$item}} = 'all';
}
if ($item eq 'sec') {
- if (($env{'form.showrole'} eq 'cc') || ($env{'form.showrole'} eq 'co')) {
+ if ($env{'form.showrole'} eq 'cc') {
$env{'form.'.$name{$item}} = 'none';
}
my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
@@ -1732,7 +1716,7 @@ sub section_group_filter {
}
if (@options > 0) {
my $currsel;
- $markup = ''."\n";
+ $markup = ' '."\n";
foreach my $option ('all','none',@options) {
$currsel = '';
if ($env{'form.'.$name{$item}} eq $option) {
@@ -1747,9 +1731,7 @@ sub section_group_filter {
$markup .= ''."\n";
}
$markup .= ' '."\n";
- $output .= (' 'x3).''
- .''.$title{$item}.': '.$markup.' '
- .' ';
+ $output .= (' 'x3).''.$title{$item}.': '.$markup.' ';
}
}
return $output;
@@ -1969,17 +1951,13 @@ sub process_coursepick {
my $coursefilter = $env{'form.coursepick'};
my $cdom = $env{'request.role.domain'};
my %courses;
- my $crssrch = 'Course';
- if ($env{'form.roletype'} eq 'community') {
- $crssrch = 'Community';
- }
if ($coursefilter eq 'all') {
%courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
- undef,undef,$crssrch);
+ undef,undef,'Course');
} elsif ($coursefilter eq 'category') {
my $instcode = &instcode_from_coursefilter();
%courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
- undef,undef,$crssrch);
+ undef,undef,'Course');
} elsif ($coursefilter eq 'specific') {
if ($env{'form.coursetotal'} > 1) {
my @course_ids = split(/&&/,$env{'form.courselist'});
@@ -2164,7 +2142,7 @@ END
} elsif ($context eq 'domain') {
if ($setting eq 'community') {
$crstype = 'Community';
- } elsif ($setting eq 'course') {
+ } elsif ($crstype eq 'course') {
$crstype = 'Course';
}
}
@@ -2277,7 +2255,7 @@ END
push(@cols,'section');
}
if (!($context eq 'domain' && ($env{'form.roletype'} eq 'course')
- && ($env{'form.roletype'} eq 'community'))) {
+ && ($env{'form.roletype'} eq 'community'))) {
push(@cols,('start','end'));
}
if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
@@ -2288,7 +2266,7 @@ END
$env{'form.roletype'} eq 'community')) {
push (@cols,'extent');
}
- if (($statusmode eq 'Any') &&
+ if (($statusmode eq 'Any') &&
(!($context eq 'domain' && (($env{'form.roletype'} eq 'course')
|| ($env{'form.roletype'} eq 'community'))))) {
push(@cols,'status');
@@ -2309,18 +2287,13 @@ END
if ($mode ne 'autoenroll') {
$results_description = &results_header_row($rolefilter,$statusmode,
$context,$permission,$mode,$crstype);
-
$r->print(''.$results_description.' ');
}
my ($output,$actionselect,%canchange,%canchangesec);
if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
if ($permission->{'cusr'}) {
- unless (($context eq 'domain') &&
- (($setting eq 'course') || ($setting eq 'community'))) {
- $actionselect =
- &select_actions($context,$setting,$statusmode,$formname);
- }
+ $actionselect = &select_actions($context,$setting,$statusmode,$formname);
}
$r->print(<
@@ -2331,7 +2304,7 @@ END
END
if ($actionselect) {
$output .= <<"END";
-$lt{'ac'}
+
$lt{'ac'}
$actionselect
@@ -2376,7 +2349,7 @@ END
}
}
}
- $output .= '';
}
$output .= "\n".''."\n".
&Apache::loncommon::start_data_table().
@@ -2413,7 +2387,11 @@ END
$lt{'type'}
";
} else {
- $output .= "\n".' '."\n";
+ if ($mode eq 'pickauthor') {
+ $output .= "\n".' '."\n";
+ } else {
+ $output .= "\n".''.&mt('Count').' '."\n";
+ }
if ($actionselect) {
$output .= ''.&mt('Select').' '."\n";
}
@@ -2468,13 +2446,9 @@ END
time.'_'.rand(1000000000).'.csv';
unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
$r->log_error("Couldn't open $CSVfilename for output $!");
- $r->print(
- ''
- .&mt('Problems occurred in writing the CSV file.')
- .' '.&mt('This error has been logged.')
- .' '.&mt('Please alert your LON-CAPA administrator.')
- .'
'
- );
+ $r->print(&mt('Problems occurred in writing the CSV file. '
+ .'This error has been logged. '
+ .'Please alert your LON-CAPA administrator.'));
$CSVfile = undef;
}
#
@@ -2656,7 +2630,7 @@ END
if ($clickers!~/\w/) { $clickers='-'; }
$in{'clicker'} = $clickers;
my $role = $in{'role'};
- $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
+ $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
if (! defined($in{'start'}) || $in{'start'} == 0) {
$in{'start'} = &mt('none');
} else {
@@ -2943,7 +2917,7 @@ sub print_username_link {
$output = $in->{'username'};
} else {
$output = '{'username'}','$in->{'domain'}'".')">'.
+ "'$in->{'username'}','$in->{'domain'}'".')" />'.
$in->{'username'}.' ';
}
return $output;
@@ -3116,7 +3090,7 @@ END
} else {
opener.document.$callingform.retainsec.value = formname.retainsec.value;
}
- setSections(formname,'$crstype');
+ setSections(formname);
if (seccheck == 'ok') {
opener.document.$callingform.newsecs.value = formname.sections.value;
}
@@ -3173,10 +3147,10 @@ ENDJS
my %lt = &Apache::lonlocal::texthash (
chac => 'Access dates to apply for selected users',
chse => 'Changes in section affiliation to apply to selected users',
- fors => 'For student roles, changing the section will result in a section switch as students may only be in one section of a course at a time.',
- forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
+ fors => 'For student roles changing the section, will result in a section switch as students may only be in one section of a course at a time.',
+ forn => 'For a role in a course that is not a student role, a user may have roles in more than one section of a course at a time.',
reta => "Retain each user's current section affiliations?",
- dnap => '(Does not apply to student roles).',
+ dnap => '(Does not apply to student roles).',
);
my ($date_items,$headertext);
if ($env{'form.bulkaction'} eq 'chgsec') {
@@ -3193,15 +3167,11 @@ ENDJS
$permission,$crstype);
}
$output .= ''.$headertext.' '.
- ''."\n");
}
-sub dates_feedback {
- my ($start,$end,$now) = @_;
- my $dates;
- if ($start < $now) {
- if ($end == 0) {
- $dates .= &mt('role(s) active now; no end date');
- } elsif ($end > $now) {
- $dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
- } else {
- $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
- }
- } else {
- if ($end == 0 || $end > $now) {
- $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start));
- } else {
- $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
- }
- }
- return $dates;
-}
-
sub classlist_drop {
my ($scope,$uname,$udom,$now) = @_;
my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
@@ -4885,7 +4750,7 @@ sub get_groupslist {
}
sub setsections_javascript {
- my ($formname,$groupslist,$mode,$checkauth,$crstype) = @_;
+ my ($formname,$groupslist,$mode,$checkauth) = @_;
my ($checkincluded,$finish,$rolecode,$setsection_js);
if ($mode eq 'upload') {
$checkincluded = 'formname.name == "'.$formname.'"';
@@ -4924,11 +4789,8 @@ sub setsections_javascript {
}
my %alerts = &Apache::lonlocal::texthash(
secd => 'Section designations do not apply to Course Coordinator roles.',
- sedn => 'Section designations do not apply to Coordinator roles.',
accr => 'A course coordinator role will be added with access to all sections.',
- acor => 'A coordinator role will be added with access to all sections',
inea => 'In each course, each user may only have one student role at a time.',
- inec => 'In each community, each user may only have one member role at a time.',
youh => 'You had selected ',
secs => 'sections.',
plmo => 'Please modify your selections so they include no more than one section.',
@@ -4936,123 +4798,78 @@ sub setsections_javascript {
plch => 'Please choose a different section name.',
mnot => 'may not be used as a section name, as it is the name of a course group.',
secn => 'Section names and group names must be distinct. Please choose a different section name.',
- nonw => 'Section names may only contain letters or numbers.',
);
$setsection_js .= <<"ENDSECCODE";
-function setSections(formname,crstype) {
+function setSections(formname) {
var re1 = /^currsec_/;
- var re2 =/\\W/;
- var trimleading = /^\\s+/;
- var trimtrailing = /\\s+\$/;
var groups = new Array($groupslist);
for (var i=0;i 0) {
- alert("$alerts{'nonw'}\\n$alerts{'plch'}");
- return;
+ }
+ if (numsec > 0) {
+ if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
+ sections = sections + "," + formname.elements[i+1].value;
}
- numsec = numsec + validsecs.length;
}
+ else {
+ sections = formname.elements[i+1].value;
+ }
+ var newsecs = formname.elements[i+1].value;
+ var numsplit;
+ if (newsecs != null && newsecs != "") {
+ numsplit = newsecs.split(/,/g);
+ numsec = numsec + numsplit.length;
+ }
+
if ((role == 'st') && (numsec > 1)) {
- if (crstype == 'Community') {
- alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
- } else {
- alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
- }
+ alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}")
return;
- } else {
- if (validsecs != null) {
- for (var j=0; j 1)) {
- if (document.$formname.crstype.value == 'Community') {
- alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
- } else {
- alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
- }
+ alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
return;
}
for (var j=0; j 0)) {
- alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
- section = "";
- }
SCRIPTTOP
if ($mode ne 'upload') {
$dc_setcourse_code .= (<<"ENDSCRIPT");
var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
var numcourse = getIndex(document.$formname.dccourse);
if (numcourse == "-1") {
- if (document.$formname.type == 'Community') {
- alert("$alerts{'thwc'}");
- } else {
- alert("$alerts{'thwa'}");
- }
+ alert("$alerts{'thwa'}");
return;
}
else {
@@ -5506,22 +5306,19 @@ ENDSCRIPT
sub sectioncheck_alerts {
my %alerts = &Apache::lonlocal::texthash(
- curd => 'You must select a course or community in the current domain',
+ curd => 'You must select a course in the current domain',
inea => 'In each course, each user may only have one student role at a time',
- inco => 'In each community, each user may only have one member role at a time',
youh => 'You had selected',
sect => 'sections',
plsm => 'Please modify your selections so they include no more than one section',
mayn => 'may not be used as the name for a section, as it is a reserved word',
plsc => 'Please choose a different section name',
mayt => 'may not be used as the name for a section, as it is the name of a course group',
- mayc => 'may not be used as the name for a section, as it is the name of a community group',
secn => 'Section names and group names must be distinct',
secd => 'Section designations do not apply to ',
role => 'roles',
accr => 'role will be added with access to all sections',
- thwa => 'There was a problem with your course selection',
- thwc => 'There was a problem with your community selection',
+ thwa => 'There was a problem with your course selection'
);
return %alerts;
}