--- loncom/interface/lonuserutils.pm 2010/05/22 13:33:09 1.97.2.17 +++ loncom/interface/lonuserutils.pm 2010/01/05 22:08:48 1.109.2.2 @@ -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.109.2.2 2010/01/05 22:08:48 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1185,8 +1185,10 @@ sub default_role_selector { 'exs' => "Existing sections", 'new' => "New section", ); - $options = ''."\n"; + unless (($context eq 'course') && (&Apache::loncommon::needs_gci_custom())) { + $options .= ' '."\n"; + } if ($context eq 'course') { $options .= &default_course_roles($context,$checkpriv,$crstype,%customroles); } elsif ($context eq 'author') { @@ -1447,18 +1449,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" - ); + (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) { + $r->print(' '.&list_submit_button(&mt('Update Display')). + "\n

\n"); } my ($indexhash,$keylist) = &make_keylist_array(); my (%userlist,%userinfo,$clearcoursepick); 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') { @@ -1732,7 +1730,7 @@ sub section_group_filter { } if (@options > 0) { my $currsel; - $markup = ''."\n"; foreach my $option ('all','none',@options) { $currsel = ''; if ($env{'form.'.$name{$item}} eq $option) { @@ -1747,9 +1745,7 @@ sub section_group_filter { $markup .= ''."\n"; } $markup .= ''."\n"; - $output .= (' 'x3).'' - .'' - .' '; + $output .= (' 'x3).''; } } return $output; @@ -2277,7 +2273,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 +2284,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,7 +2305,6 @@ 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); @@ -2331,7 +2326,7 @@ END END if ($actionselect) { $output .= <<"END"; -
$lt{'ac'} +
$lt{'ac'} $actionselect

 
@@ -2376,7 +2371,7 @@ END } } } - $output .= '
'.$lt{'link'}.''. + $output .= '
'.$lt{'link'}.''. ''; my @linkdests = ('aboutme'); if ($permission->{'cusr'}) { @@ -2387,6 +2382,7 @@ END $env{'request.course.sec'})) { push(@linkdests,'track'); } + $output .= '
'; my $usernamelink = $env{'form.usernamelink'}; if ($usernamelink eq '') { @@ -2403,7 +2399,7 @@ END if ($env{'form.userwin'}) { $checkwin = ' checked="checked"'; } - $output .= ''.$lt{'owin'}.'
'; + $output .= ''.$lt{'owin'}.'
'; } $output .= "\n".''."\n". &Apache::loncommon::start_data_table(). @@ -2656,7 +2652,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 +2939,7 @@ sub print_username_link { $output = $in->{'username'}; } else { $output = '{'username'}','$in->{'domain'}'".')">'. + "'$in->{'username'}','$in->{'domain'}'".')" />'. $in->{'username'}.''; } return $output; @@ -3173,8 +3169,8 @@ 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).', ); @@ -3193,13 +3189,14 @@ ENDJS $permission,$crstype); } $output .= '

'.$headertext.'

'. - '
'."\n". + ''."\n". $date_items; if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') { my ($cnum,$cdom) = &get_course_identity(); + my $crstype = &Apache::loncommon::course_type(); if ($crstype eq 'Community') { - $lt{'fors'} = &mt('For member roles, changing the section will result in a section switch, as members may only be in one section of a community at a time.'); - $lt{'forn'} = &mt('For a community role that is not "member", users may have roles in more than one section at a time.'); + $lt{'fors'} = &mt('For member roles changing the section, will result in a section switch as members may only be in one section of a community at a time.'); + $lt{'forn'} = &mt('For a role in a community that is not a member role, a user may have roles in more than one section of a community at a time.'); $lt{'dnap'} = &mt('(Does not apply to member roles).'); } my $info; @@ -3240,7 +3237,7 @@ sub section_picker { my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype) = @_; my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum); my $sections_select .= &course_sections(\%sections_count,$role); - my $secbox = '
'.&Apache::lonhtmlcommon::start_pick_box()."\n"; + my $secbox = '

'.&Apache::lonhtmlcommon::start_pick_box()."\n"; if ($mode eq 'upload') { my ($options,$cb_script,$coursepick) = &default_role_selector($context,1,$crstype); @@ -3253,7 +3250,7 @@ sub section_picker { ''.&mt('Existing sections')."\n". '
'.$sections_select.''. &mt('New section').'
'."\n". - ''."\n". + ''."\n". ''."\n". ''."\n"; } else { @@ -3262,7 +3259,7 @@ sub section_picker { $env{'request.course.sec'}; } $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n". - &Apache::lonhtmlcommon::end_pick_box().'

'; + &Apache::lonhtmlcommon::end_pick_box().'

'; return $secbox; } @@ -3403,12 +3400,11 @@ sub results_header_row { if ($rolefilter eq 'Any') { $description .= &mt('All users with co-author roles in domain',$showfilter); } else { - $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter); + $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter); } } } elsif (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')) { - my $coursefilter = $env{'form.coursepick'}; if ($env{'form.roletype'} eq 'course') { if ($coursefilter eq 'category') { @@ -3661,7 +3657,7 @@ sub print_first_users_upload_form { $str .= ''; $str .= ''; - $str .= '

'.&mt('Upload a file containing information about users').'

'."\n"; + $str .= '

'.&mt('Upload a file containing information about users').'

'."\n"; # Excel and CSV Help $str .= '
' @@ -3807,7 +3803,7 @@ sub upfile_drop_add { } elsif ($setting eq 'course') { $defaultrole = $env{'form.courserole'}; $defaultsec = $env{'form.sections'}; - } + } } elsif ($context eq 'author') { $defaultrole = $env{'form.defaultrole'}; } elsif ($context eq 'course') { @@ -4159,7 +4155,7 @@ sub upfile_drop_add { $role = 'cr_'.$env{'user.domain'}.'_'. $env{'user.name'}.'_'.$role; } - if (($role ne 'cc') && ($role ne 'co')) { + if (($role ne 'cc') && ($role ne 'co')) { if (@secs > 1) { $multiple = 1; foreach my $sec (@secs) { @@ -4386,9 +4382,10 @@ sub print_drop_menu { # ================================================================== Phase four sub update_user_list { - my ($r,$context,$setting,$choice,$crstype) = @_; + my ($r,$context,$setting,$choice) = @_; my $now = time; my $count=0; + my $crstype; if ($context eq 'course') { $crstype = &Apache::loncommon::course_type(); } @@ -4403,7 +4400,7 @@ sub update_user_list { 'reenable' => 'Re-enabled', 'activate' => 'Activated', 'chgdates' => 'Changed Access Dates for', - 'chgsec' => 'Changed section(s) for', + 'chgsec' => 'Changed section for', 'drop' => 'Dropped', }, error => {'revoke' => 'revoking', @@ -4420,9 +4417,8 @@ sub update_user_list { ($startdate,$enddate) = &get_dates_from_form(); } foreach my $item (@changelist) { - my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype, - @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec, - $nothingtodo,$keepnosection); + my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections, + $scopestem); if ($choice eq 'drop') { ($uname,$udom,$sec) = split(/:/,$item,-1); $role = 'st'; @@ -4521,23 +4517,14 @@ sub update_user_list { } elsif ($choice eq 'chgsec') { my (@newsecs,$revresult,$nochg,@retained); if (($role ne 'cc') && ($role ne 'co')) { - my @secs = sort(split(/,/,$env{'form.newsecs'})); - if (@secs) { - my %curr_groups = &Apache::longroup::coursegroups(); - foreach my $sec (@secs) { - next if (($sec =~ /\W/) || ($sec eq 'none') || - (exists($curr_groups{$sec}))); - push(@newsecs,$sec); - } - } + @newsecs = split(/,/,$env{'form.newsecs'}); } # remove existing section if not to be retained. - if (!$env{'form.retainsec'} || ($role eq 'st')) { + if (!$env{'form.retainsec'}) { if ($sec eq '') { if (@newsecs == 0) { - $result = 'ok'; + $result = &mt('No change in section assignment (none)'); $nochg = 1; - $nothingtodo = 1; } else { $revresult = &Apache::lonnet::revokerole($udom,$uname, @@ -4564,23 +4551,13 @@ sub update_user_list { } else { if ($sec eq '') { $nochg = 1; - $keepnosection = 1; } else { push(@retained,$sec); } } # add new sections - my (@diffs,@shownew); - if (@retained) { - @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs); - } else { - @diffs = @newsecs; - } if (@newsecs == 0) { - if ($nochg) { - $result = 'ok'; - $nothingtodo = 1; - } else { + if (!$nochg) { if ($role eq 'st') { $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context); @@ -4589,41 +4566,15 @@ sub update_user_list { $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context); } } - $showsecs = &mt('No section'); - } elsif (@diffs == 0) { - $result = 'ok'; - $nothingtodo = 1; } else { foreach my $newsec (@newsecs) { if (!grep(/^\Q$newsec\E$/,@retained)) { if ($role eq 'st') { $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context); - if (@newsecs > 1) { - my $showsingle; - if ($newsec eq '') { - $showsingle = &mt('No section'); - } else { - $showsingle = $newsec; - } - if ($crstype eq 'Community') { - $warn_singlesec = &mt('Although more than one section was indicated, a role was only added for the first section - [_1], as each community member may only be in one section at a time.',''.$showsingle.''); - } else { - $warn_singlesec = &mt('Although more than one section was indicated, a role was only added for the first section - [_1], as each student may only be in one section of a course at a time.',''.$showsingle.''); - } - $showsecs = $showsingle; - last; - } else { - if ($newsec eq '') { - $showsecs = &mt('No section'); - } else { - $showsecs = $newsec; - } - } } else { my $newscope = $scopestem; if ($newsec ne '') { $newscope .= '/'.$newsec; - push(@shownew,$newsec); } $result = &Apache::lonnet::assignrole($udom,$uname, $newscope,$role,$end,$start); @@ -4631,15 +4582,6 @@ sub update_user_list { } } } - unless ($role eq 'st') { - unless ($showsecs) { - my @tolist = sort(@shownew,@retained); - if ($keepnosection) { - push(@tolist,&mt('No section')); - } - $showsecs = join(', ',@tolist); - } - } } } my $extent = $scope; @@ -4650,48 +4592,13 @@ sub update_user_list { } } if ($result eq 'ok' || $result eq 'ok:') { - my $dates; - if (($choice eq 'chgsec') || ($choice eq 'chgdates')) { - $dates = &dates_feedback($start,$end,$now); - } - if ($choice eq 'chgsec') { - if ($nothingtodo) { - $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,''. - &Apache::loncommon::plainname($uname,$udom). - '').' '); - if ($sec eq '') { - $r->print(&mt('[_1]No section[_2] - [_3]','','',$dates)); - } else { - $r->print(&mt('Section(s): [_1] - [_2]', - ''.$showsecs.'',$dates)); - } - $r->print('
'); - } else { - $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent, - ''.&Apache::loncommon::plainname($uname,$udom).'', - ''.$showsecs.'',$dates).'
'); - $count ++; - } - if ($warn_singlesec) { - $r->print('
'.$warn_singlesec.'
'); - } - } elsif ($choice eq 'chgdates') { - $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent, - ''.&Apache::loncommon::plainname($uname.':'.$udom).'', - $dates).'
'); - $count ++; - } else { - $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent, - ''.&Apache::loncommon::plainname($uname.':'.$udom).''). - '
'); - $count ++; - } + $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]", + $plrole,$extent,$uname.':'.$udom).'
'); + $count++; } else { $r->print( - &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].", - $plrole,$extent, - ''.&Apache::loncommon::plainname($uname.':'.$udom).'', - $result).'
'); + &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].", + $plrole,$extent,$uname.':'.$udom,$result).'
'); } } $r->print(''."\n"); @@ -4707,7 +4614,7 @@ sub update_user_list { } } } - $r->print('

'.&mt("$result_text{'ok'}{$choice} for [quant,_1,user role,user roles,no user roles].",$count).'

'); + $r->print('

'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'

'); if ($count > 0) { if ($choice eq 'revoke' || $choice eq 'drop') { $r->print('

'.&mt('Re-enabling will re-activate data for the role.').'

'); @@ -4727,27 +4634,6 @@ sub update_user_list { $r->print(''.$linktext.''."\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)}); @@ -4928,7 +4814,7 @@ sub setsections_javascript { 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.', + inec => 'In each community, each user may only have on 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,21 +4822,16 @@ 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) { 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'}"); @@ -5023,36 +4882,25 @@ function setSections(formname,crstype) { alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}"); } return; - } else { - if (validsecs != null) { - for (var j=0; j 'You must select a course or community 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', + 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',