--- loncom/interface/lonuserutils.pm 2010/02/02 06:05:03 1.97.2.15 +++ 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.15 2010/02/02 06:05:03 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 = '<select name="defaultrole">'."\n". - ' <option value="">'.&mt('Please select').'</option>'."\n"; + $options = '<select name="defaultrole">'."\n"; + unless (($context eq 'course') && (&Apache::loncommon::needs_gci_custom())) { + $options .= ' <option value="">'.&mt('Please select').'</option>'."\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</p>\n" - .'<p>' - .&list_submit_button(&mt('Update Display')) - ."</p>\n" - ); + (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) { + $r->print(' '.&list_submit_button(&mt('Update Display')). + "\n</p>\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') { @@ -1562,7 +1560,8 @@ sub print_userlist { } } } - } elsif ($env{'form.roletype'} eq 'course') { + } elsif (($env{'form.roletype'} eq 'course') || + ($env{'form.roletype'} eq 'community')) { if (($env{'form.coursepick'}) && (!$clearcoursepick)) { my %courses = &process_coursepick(); my %allusers; @@ -1731,7 +1730,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) { @@ -1746,9 +1745,7 @@ sub section_group_filter { $markup .= '</option>'."\n"; } $markup .= '</select>'."\n"; - $output .= (' 'x3).'<span class="LC_nobreak">' - .'<label>'.$title{$item}.': '.$markup.'</label>' - .'</span> '; + $output .= (' 'x3).'<label>'.$title{$item}.': '.$markup.'</label>'; } } return $output; @@ -2276,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') { @@ -2287,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'); @@ -2302,13 +2299,12 @@ END if ($env{'form.showrole'} eq 'cr') { $rolefilter = &mt('custom'); } elsif ($env{'form.showrole'} ne 'Any') { - $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'}); + $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'},$crstype); } my $results_description; 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); @@ -2330,7 +2326,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> @@ -2375,7 +2371,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'}) { @@ -2386,6 +2382,7 @@ END $env{'request.course.sec'})) { push(@linkdests,'track'); } + $output .= '<td>'; my $usernamelink = $env{'form.usernamelink'}; if ($usernamelink eq '') { @@ -2655,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 { @@ -2942,7 +2939,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; @@ -2954,7 +2951,6 @@ sub role_type_names { 'author' => 'Co-Author Roles', 'course' => 'Course Roles', 'community' => 'Community Roles', - ); return %lt; } @@ -3409,7 +3405,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') { @@ -3662,8 +3657,7 @@ sub print_first_users_upload_form { $str .= '<input type="hidden" name="action" value="upload" />'; $str .= '<input type="hidden" name="state" value="got_file" />'; - - $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n"; + $str .= '<h3>'.&mt('Upload a file containing information about users').'</h3>'."\n"; # Excel and CSV Help $str .= '<div class="LC_left_float">' @@ -3809,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') { @@ -4161,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) { @@ -4820,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.', @@ -4828,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<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') { @@ -4854,60 +4843,38 @@ function setSections(formname,crstype) { } else { var sections = ''; var numsec = 0; - 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); + 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 != "") { if (numsec == 0) { - sections = addsec; - } else { - sections = sections + "," + addsec; - } - numsec ++; - } - } - } - var newsecs = formname.elements[num+1].value; - var validsecs = new Array(); - var validsecstr = ''; - var badsecs = new Array(); - if (newsecs != null && newsecs != "") { - 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 (formname.elements[i].options[j].value != "") { + sections = formname.elements[i].options[j].value; + numsec ++; } } + else { + sections = sections + "," + formname.elements[i].options[j].value + numsec ++; + } } } - if (badsecs.length > 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'}"); @@ -4915,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<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'}"); + } + 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'}"); return; } for (var k=0; k<groups.length; k++) { - if (validsecs[j] == groups[k]) { - alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}"); + if (numsplit[j] == groups[k]) { + alert("'"+numsplit[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; } } } @@ -5069,14 +5025,22 @@ sub roles_by_context { if ($env{'request.role'} =~ m{^dc\./}) { push(@allroles,'ad'); } - push(@allroles,('ta','ep','in')); - if ($crstype eq 'Community') { - push(@allroles,'co'); + if (&Apache::loncommon::needs_gci_custom()) { + if ($crstype eq 'Community') { + push(@allroles,'co'); + } else { + push(@allroles,'cc'); + } } else { - push(@allroles,'cc'); - } - if ($custom) { - push(@allroles,'cr'); + push(@allroles,('ta','ep','in')); + if ($crstype eq 'Community') { + push(@allroles,'co'); + } else { + push(@allroles,'cc'); + } + if ($custom) { + push(@allroles,'cr'); + } } } elsif ($context eq 'author') { @allroles = ('ca','aa'); @@ -5400,7 +5364,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',