--- loncom/interface/lonuserutils.pm 2009/12/16 13:00:45 1.108 +++ loncom/interface/lonuserutils.pm 2010/02/02 05:56:09 1.115 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.108 2009/12/16 13:00:45 bisitz Exp $ +# $Id: lonuserutils.pm,v 1.115 2010/02/02 05:56:09 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -386,7 +386,7 @@ 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'}.",'$crstype'".');'; $setsections_js = &setsections_javascript($param{'formname'},$groupslist, $mode,'',$crstype); @@ -1448,8 +1448,12 @@ sub print_userlist { } if (!(($context eq 'domain') && (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) { - $r->print(' '.&list_submit_button(&mt('Update Display')). - "\n</p>\n"); + $r->print( + "\n</p>\n" + .'<p>' + .&list_submit_button(&mt('Update Display')) + ."</p>\n" + ); } my ($indexhash,$keylist) = &make_keylist_array(); my (%userlist,%userinfo,$clearcoursepick); @@ -1688,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; } @@ -1728,7 +1732,7 @@ sub section_group_filter { } if (@options > 0) { my $currsel; - $markup = '<select name="'.$name{$item}.'" />'."\n"; + $markup = '<select name="'.$name{$item}.'">'."\n"; foreach my $option ('all','none',@options) { $currsel = ''; if ($env{'form.'.$name{$item}} eq $option) { @@ -1743,7 +1747,9 @@ sub section_group_filter { $markup .= '</option>'."\n"; } $markup .= '</select>'."\n"; - $output .= (' 'x3).'<label>'.$title{$item}.': '.$markup.'</label>'; + $output .= (' 'x3).'<span class="LC_nobreak">' + .'<label>'.$title{$item}.': '.$markup.'</label>' + .'</span> '; } } return $output; @@ -2397,7 +2403,7 @@ END if ($env{'form.userwin'}) { $checkwin = ' checked="checked"'; } - $output .= '</td><td valign="top"><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(). @@ -2937,7 +2943,7 @@ sub print_username_link { $output = $in->{'username'}; } else { $output = '<a href="javascript:username_display_launch('. - "'$in->{'username'}','$in->{'domain'}'".')" />'. + "'$in->{'username'}','$in->{'domain'}'".')">'. $in->{'username'}.'</a>'; } return $output; @@ -3191,7 +3197,6 @@ ENDJS $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 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.'); @@ -3688,8 +3693,6 @@ sub print_first_users_upload_form { .'<input type="submit" name="fileupload" value="'.&mt('Next').'" />' .'</p>'; - $str .= &Apache::loncommon::end_page(); - $r->print($str); return; } @@ -4829,16 +4832,21 @@ 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<formname.elements.length;i++) { var str = formname.elements[i].name; var checkcurr = str.match(re1); if (checkcurr != null) { + var num = i; if ($checkincluded) { $rolecode if (role == 'cc' || role == 'co') { @@ -4850,38 +4858,60 @@ function setSections(formname,crstype) { } else { var sections = ''; var numsec = 0; - var sections; - for (var j=0; j<formname.elements[i].length; j++) { - if (formname.elements[i].options[j].selected == true ) { - if (formname.elements[i].options[j].value != "") { + var fromexisting = new Array(); + 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 != "") { + fromexisting.push(addsec); if (numsec == 0) { - if (formname.elements[i].options[j].value != "") { - sections = formname.elements[i].options[j].value; - numsec ++; - } - } - else { - sections = sections + "," + formname.elements[i].options[j].value - numsec ++; + sections = addsec; + } else { + sections = sections + "," + addsec; } + numsec ++; } } } - if (numsec > 0) { - if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) { - sections = sections + "," + formname.elements[i+1].value; - } - } - else { - sections = formname.elements[i+1].value; - } - var newsecs = formname.elements[i+1].value; - var numsplit; + var newsecs = formname.elements[num+1].value; + var validsecs = new Array(); + var validsecstr = ''; + var badsecs = new Array(); if (newsecs != null && newsecs != "") { - numsplit = newsecs.split(/,/g); - numsec = numsec + numsplit.length; + var numsplit; + if (newsecs.indexOf(',') == -1) { + numsplit = new Array(newsecs); + } else { + numsplit = newsecs.split(/,/g); + } + 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) { + badsecs.push(newsec); + } else { + if (newsec != '') { + var isnew = 1; + if (fromexisting != null) { + for (var m=0; m<fromexisting.length; m++) { + if (newsec == fromexisting[m]) { + isnew = 0; + } + } + } + if (isnew == 1) { + validsecs.push(newsec); + } + } + } + } + if (badsecs.length > 0) { + alert("$alerts{'nonw'}\\n$alerts{'plch'}"); + return; + } + numsec = numsec + validsecs.length; } - if ((role == 'st') && (numsec > 1)) { if (crstype == 'Community') { alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}"); @@ -4889,25 +4919,36 @@ function setSections(formname,crstype) { alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}"); } return; - } - else { - if (numsplit != null) { - for (var j=0; j<numsplit.length; j++) { - if ((numsplit[j] == 'all') || - (numsplit[j] == 'none')) { - alert("'"+numsplit[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}"); + } else { + if (validsecs != null) { + for (var j=0; j<validsecs.length; j++) { + if (validsecstr == '' || validsecstr == null) { + validsecstr = validsecs[j]; + } else { + validsecstr += ','+validsecs[j]; + } + if ((validsecs[j] == 'all') || + (validsecs[j] == 'none')) { + alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}"); return; } for (var k=0; k<groups.length; k++) { - if (numsplit[j] == groups[k]) { - alert("'"+numsplit[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}"); + if (validsecs[j] == groups[k]) { + alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}"); return; } } } } - formname.elements[i+2].value = sections; } + if ((validsecstr != '') && (validsecstr != null)) { + if (numsec > 0) { + sections = sections + "," + validsecstr; + } else { + sections = validsecstr; + } + } + formname.elements[num+2].value = sections; } } }