--- loncom/interface/lonuserutils.pm 2010/05/22 13:33:09 1.97.2.17 +++ loncom/interface/lonuserutils.pm 2010/02/19 15:41:40 1.116 @@ -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.116 2010/02/19 15:41:40 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1447,7 +1447,7 @@ sub print_userlist { return; } if (!(($context eq 'domain') && - (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) { + (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) { $r->print( "\n</p>\n" .'<p>' @@ -1458,7 +1458,7 @@ sub print_userlist { 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') { @@ -1692,7 +1692,7 @@ sub role_filter { $role_select .= '</select>'; $output = '<label><span class="LC_nobreak">' .&mt('Role: [_1]',$role_select) - .'</span></label>'; + .'</span></label> '; } return $output; } @@ -2277,7 +2277,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 +2288,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 +2309,6 @@ END if ($mode ne 'autoenroll') { $results_description = &results_header_row($rolefilter,$statusmode, $context,$permission,$mode,$crstype); - $r->print('<b>'.$results_description.'</b><br /><br />'); } my ($output,$actionselect,%canchange,%canchangesec); @@ -2331,7 +2330,7 @@ END END if ($actionselect) { $output .= <<"END"; -<div class="LC_left_float"><fieldset><legend><b>$lt{'ac'}</b></legend> +<div class="LC_left_float"><fieldset><legend>$lt{'ac'}</legend> $actionselect <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" /> <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.$formname.actionlist)" /><br /><input type="button" value="$lt{'pr'}" onclick="javascript:verify_action('actionlist')" /></fieldset></div> @@ -2376,7 +2375,7 @@ END } } } - $output .= '<div class="LC_left_float"><fieldset><legend><b>'.$lt{'link'}.'</b></legend>'. + $output .= '<div class="LC_left_float"><fieldset><legend>'.$lt{'link'}.'</legend>'. '<table><tr>'; my @linkdests = ('aboutme'); if ($permission->{'cusr'}) { @@ -2387,6 +2386,7 @@ END $env{'request.course.sec'})) { push(@linkdests,'track'); } + $output .= '<td>'; my $usernamelink = $env{'form.usernamelink'}; if ($usernamelink eq '') { @@ -2403,7 +2403,7 @@ END if ($env{'form.userwin'}) { $checkwin = ' checked="checked"'; } - $output .= '</td><td valign="top" style="border-left: 1px solid;><span class="LC_nobreak"><input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}.'</span></td></tr></table></fieldset></div>'; + $output .= '</td><td valign="top" style="border-left: 1px solid;"><span class="LC_nobreak"><input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}.'</span></td></tr></table></fieldset></div>'; } $output .= "\n".'<div class="LC_clear_float_footer"> </div>'."\n". &Apache::loncommon::start_data_table(). @@ -2656,7 +2656,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 { @@ -3173,8 +3173,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 +3193,13 @@ ENDJS $permission,$crstype); } $output .= '<h3>'.$headertext.'</h3>'. - '<form name="'.$formname.'" method="post" action="">'."\n". + '<form name="'.$formname.'" method="post">'."\n". $date_items; if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') { my ($cnum,$cdom) = &get_course_identity(); 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 +3240,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 = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n"; + my $secbox = '<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n"; if ($mode eq 'upload') { my ($options,$cb_script,$coursepick) = &default_role_selector($context,1,$crstype); @@ -3253,7 +3253,7 @@ sub section_picker { '<td align="center">'.&mt('Existing sections')."\n". '<br />'.$sections_select.'</td><td align="center">'. &mt('New section').'<br />'."\n". - '<input type="text" name="newsec" size="15" value="" />'."\n". + '<input type="text" name="newsec" size="15" />'."\n". '<input type="hidden" name="sections" value="" />'."\n". '</td></tr></table>'."\n"; } else { @@ -3262,7 +3262,7 @@ sub section_picker { $env{'request.course.sec'}; } $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n". - &Apache::lonhtmlcommon::end_pick_box().'</div>'; + &Apache::lonhtmlcommon::end_pick_box().'</p>'; return $secbox; } @@ -3408,7 +3408,6 @@ sub results_header_row { } } 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') { @@ -3672,8 +3671,15 @@ sub print_first_users_upload_form { &mt("How do I create a CSV file from a spreadsheet")) .'</div><br clear="all" />'."\n"; $str .= &Apache::lonhtmlcommon::start_pick_box() - .&Apache::lonhtmlcommon::row_title(&mt('File')) - .&Apache::loncommon::upfile_select_html() + .&Apache::lonhtmlcommon::row_title(&mt('File')); + if (&Apache::lonlocal::current_language() ne 'en') { + if ($context eq 'course') { + $str .= '<p class="LC_info">'."\n" + .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n" + .'</p>'."\n"; + } + } + $str .= &Apache::loncommon::upfile_select_html() .&Apache::lonhtmlcommon::row_closure() .&Apache::lonhtmlcommon::row_title( '<label for="noFirstLine">' @@ -3807,7 +3813,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 +4165,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 +4392,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 +4410,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 +4427,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 +4527,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 +4561,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 +4576,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.','<i>'.$showsingle.'</i>'); - } 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.','<i>'.$showsingle.'</i>'); - } - $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 +4592,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 +4602,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,'<i>'. - &Apache::loncommon::plainname($uname,$udom). - '</i>').' '); - if ($sec eq '') { - $r->print(&mt('[_1]No section[_2] - [_3]','<b>','</b>',$dates)); - } else { - $r->print(&mt('Section(s): [_1] - [_2]', - '<b>'.$showsecs.'</b>',$dates)); - } - $r->print('<br />'); - } else { - $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent, - '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>', - '<b>'.$showsecs.'</b>',$dates).'<br />'); - $count ++; - } - if ($warn_singlesec) { - $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>'); - } - } elsif ($choice eq 'chgdates') { - $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent, - '<i>'.&Apache::loncommon::plainname($uname.':'.$udom).'</i>', - $dates).'<br />'); - $count ++; - } else { - $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent, - '<i>'.&Apache::loncommon::plainname($uname.':'.$udom).'</i>'). - '<br />'); - $count ++; - } + $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]", + $plrole,$extent,$uname.':'.$udom).'<br />'); + $count++; } else { $r->print( - &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].", - $plrole,$extent, - '<i>'.&Apache::loncommon::plainname($uname.':'.$udom).'</i>', - $result).'<br />'); + &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].", + $plrole,$extent,$uname.':'.$udom,$result).'<br />'); } } $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n"); @@ -4707,7 +4624,7 @@ sub update_user_list { } } } - $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} for [quant,_1,user role,user roles,no user roles].",$count).'</b></p>'); + $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'</b></p>'); if ($count > 0) { if ($choice eq 'revoke' || $choice eq 'drop') { $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>'); @@ -4727,27 +4644,6 @@ sub update_user_list { $r->print('<a href="javascript:document.studentform.submit()">'.$linktext.'</a></form>'."\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 +4824,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.', @@ -4966,7 +4862,7 @@ function setSections(formname,crstype) { for (var j=0; j<formname.elements[num].length; j++) { if (formname.elements[num].options[j].selected == true ) { var addsec = formname.elements[num].options[j].value; - if ((addsec != "") && (addsec != null)) { + if (addsec != "") { fromexisting.push(addsec); if (numsec == 0) { sections = addsec; @@ -4988,8 +4884,8 @@ function setSections(formname,crstype) { } else { numsplit = newsecs.split(/,/g); } - for (var m=0; m<numsplit.length; m++) { - var newsec = numsplit[m]; + for (var i=0; i<numsplit.length; i++) { + var newsec = numsplit[i]; newsec = newsec.replace(trimleading,''); newsec = newsec.replace(trimtrailing,''); if (re2.test(newsec) == true) { @@ -4998,8 +4894,8 @@ function setSections(formname,crstype) { if (newsec != '') { var isnew = 1; if (fromexisting != null) { - for (var n=0; n<fromexisting.length; n++) { - if (newsec == fromexisting[n]) { + for (var m=0; m<fromexisting.length; m++) { + if (newsec == fromexisting[m]) { isnew = 0; } } @@ -5046,10 +4942,10 @@ function setSections(formname,crstype) { } } if ((validsecstr != '') && (validsecstr != null)) { - if ((sections == '') || (sections == null)) { - sections = validsecstr; - } else { + if (numsec > 0) { sections = sections + "," + validsecstr; + } else { + sections = validsecstr; } } formname.elements[num+2].value = sections; @@ -5508,7 +5404,7 @@ sub sectioncheck_alerts { my %alerts = &Apache::lonlocal::texthash( curd => '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',