--- loncom/interface/loncreateuser.pm 2006/04/10 19:59:53 1.112 +++ loncom/interface/loncreateuser.pm 2006/05/08 21:40:20 1.113 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.112 2006/04/10 19:59:53 albertel Exp $ +# $Id: loncreateuser.pm,v 1.113 2006/05/08 21:40:20 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -170,7 +170,8 @@ ENDCUSTOM sub user_modification_js { - my ($pjump_def, $dc_setcourse_code)=@_; + my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_; + return < @@ -189,8 +190,11 @@ sub user_modification_js { pclose(); } + $nondc_setsection_code + function setSections() { var re1 = /^currsec_/; + var groups = new Array($groupslist); for (var i=0;i 0) { if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) { sections = sections + "," + document.cu.elements[i+1].value; - } + } } else { sections = document.cu.elements[i+1].value; @@ -240,7 +244,20 @@ sub user_modification_js { alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.") return; } - else { + else { + for (var j=0; j 0) { + $groupslist = join('","',sort(keys(%curr_groups))); + $groupslist = '"'.$groupslist.'"'; + } if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) { my $dcdom = $1; $loaditem{'onload'} = "document.cu.coursedesc.value=''"; @@ -326,6 +355,21 @@ sub print_user_modification_page { alert("In each course, each user may only have one student role at a time. You had selected "+numsections+" sections.\\nPlease modify your selections so they include no more than one section.") return; } + for (var j=0; j 0)) { alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections."); section = ""; @@ -356,9 +400,86 @@ sub print_user_modification_page { return -1; } ENDSCRIPT + } else { + $nondc_setsection_code = <<"ENDSECCODE"; + function setSections() { + var re1 = /^currsec_/; + var groups = new Array($groupslist); + for (var i=0;i 0) { + if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) { + sections = sections + "," + document.cu.elements[i+1].value; + } + } + else { + sections = document.cu.elements[i+1].value; + } + var newsecs = document.cu.elements[i+1].value; + if (newsecs != null && newsecs != "") { + var numsplit = newsecs.split(/,/g); + numsec = numsec + numsplit.length; + } + if ((role == 'st') && (numsec > 1)) { + alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.") + return; + } + else { + for (var j=0; j \%loaditem,}); @@ -548,7 +669,7 @@ END $bgcol=~s/[^7-9a-e]//g; $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6); if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) { - $carea.='
Section/Group: '.$3; + $carea.='
Section: '.$3; $sortkey.="\0$3"; } $area=$carea; @@ -884,6 +1005,7 @@ sub update_user_data { $title='Modify User Privileges'; } $r->print(&Apache::loncommon::start_page($title)); + my %disallowed; # Check Inputs if (! $env{'form.ccuname'} ) { $r->print($error.&mt('No login name specified').'.'.$end); @@ -1087,6 +1209,7 @@ END } } ## + my %curr_groups; my $now=time; $r->print('

'.&mt('Modifying Roles').'

'); foreach (keys (%env)) { @@ -1113,7 +1236,7 @@ END } if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) { # Revoke custom role - $r->print(&mt('Revoking custom role'). + $r->print(&mt('Revoking custom role:'). ' '.$4.' by '.$3.'@'.$2.' in '.$1.': '. &Apache::lonnet::revokecustomrole($env{'form.ccdomain'}, $env{'form.ccuname'},$1,$2,$3,$4). @@ -1136,7 +1259,7 @@ END &Apache::lonnet::escape($now.':'), $env{'course.'.$cid.'.home'}).'
'); } - } + } } elsif ($_=~/^form\.ren/) { my $udom = $env{'form.ccdomain'}; my $uname = $env{'form.ccuname'}; @@ -1164,7 +1287,7 @@ END $role,$url,$result).'
'; } $r->print($output); - } + } } elsif ($_=~/^form\.act/) { my $udom = $env{'form.ccdomain'}; my $uname = $env{'form.ccuname'}; @@ -1187,8 +1310,15 @@ END if ($num_sections == 0) { $r->print(&commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end)); } else { - foreach (sort {$a cmp $b} keys %sections) { - my $securl = $url.'/'.$_; + my $numgrp=&Apache::loncommon::coursegroups(\%curr_groups, + $one,$two); + foreach my $sec (sort {$a cmp $b} keys %sections) { + if (($sec eq 'none') || ($sec eq 'all') || + exists($curr_groups{$sec})) { + $disallowed{$sec} = $url; + next; + } + my $securl = $url.'/'.$sec; $r->print(&commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end)); } } @@ -1210,10 +1340,17 @@ END if ($num_sections == 0) { $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'')); } else { + my $numgrp=&Apache::loncommon::coursegroups(\%curr_groups, + $one,$two); my $emptysec = 0; foreach my $sec (sort {$a cmp $b} keys %sections) { $sec =~ s/\W//g; - if ($sec ne '') { + if ($sec ne '') { + if (($sec eq 'none') || ($sec eq 'all') || + exists($curr_groups{$sec})) { + $disallowed{$sec} = $url; + next; + } my $securl = $url.'/'.$sec; $r->print(&commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec)); } else { @@ -1256,7 +1393,15 @@ END } else { $r->print('

'.&mt('ERROR').': '.&mt('Unknown command').' '.$_.'


'); } - } + foreach my $key (sort(keys(%disallowed))) { + if (($key eq 'none') || ($key eq 'all')) { + $r->print('

'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key)); + } else { + $r->print('

'.&mt('[_1] may not be used as the name for a section, as it is the name of a course group.',$key)); + } + $r->print(' '.&mt('Please go back and choose a different section name.').'


'); + } + } } # End of foreach (keys(%env)) # Flush the course logs so reverse user roles immediately updated &Apache::lonnet::flushcourselogs(); @@ -1342,7 +1487,7 @@ sub commit_studentrole { } } else { $$logmsg .= "Incomplete course id defined. Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed"; - $result = "Error: incomplete course id\n"; + $result = "error: incomplete course id\n"; } return $result; } @@ -1604,7 +1749,7 @@ sub course_level_table { 'act' => "Activate", 'rol' => "Role", 'ext' => "Extent", - 'grs' => "Group/Section", + 'grs' => "Section", 'sta' => "Start", 'end' => "End" ); @@ -1753,7 +1898,7 @@ sub course_level_dc { 'crl' => "Course Level", 'crt' => "Course Title", 'rol' => "Role", - 'grs' => "Group/Section", + 'grs' => "Section", 'exs' => "Existing sections", 'new' => "Define new section", 'sta' => "Start", @@ -1782,7 +1927,8 @@ sub course_level_dc { '