--- loncom/interface/loncreateuser.pm 2006/03/21 18:51:28 1.111 +++ 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.111 2006/03/21 18:51:28 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 <<END; <script type="text/javascript" language="Javascript"> @@ -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<document.cu.elements.length;i++) { var str = document.cu.elements[i].name; var checkcurr = str.match(re1); @@ -226,7 +230,7 @@ sub user_modification_js { if (numsec > 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<numsplit.length; j++) { + if ((numsplit[j] == 'all') || + (numsplit[j] == 'none')) { + alert("'"+numsplit[j]+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name."); + return; + } + for (var k=0; k<groups.length; k++) { + if (numsplit[j] == groups[k]) { + alert("'"+numsplit[j]+"' may not be used as a section name, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name."); + return; + } + } + } document.cu.elements[i+2].value = sections; } } @@ -283,10 +300,22 @@ sub print_user_modification_page { $ccdomain=~s/\W//g; my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition(); my $dc_setcourse_code = ''; - my $loaditem; + my $nondc_setsection_code = ''; + my %loaditem; + my (%curr_groups,$groupslist,$numgroups); + if (exists($env{'request.course.id'})) { + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + $numgroups = &Apache::loncommon::coursegroups(\%curr_groups,$cdom, + $cnum); + } + if ($numgroups > 0) { + $groupslist = join('","',sort(keys(%curr_groups))); + $groupslist = '"'.$groupslist.'"'; + } if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) { my $dcdom = $1; - $loaditem = qq|OnLoad="document.cu.coursedesc.value=''"|; + $loaditem{'onload'} = "document.cu.coursedesc.value=''"; $dc_setcourse_code = <<"ENDSCRIPT"; function setCourse() { var course = document.cu.dccourse.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<numsplit.length; j++) { + if ((numsplit[j] == 'all') || (numsplit[j] == 'none')) { + alert("'"+numsplit[j]+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name."); + return; + } + if (document.cu.groups.value != '') { + var groups = document.cu.groups.value.split(/,/g); + for (var k=0; k<groups.length; k++) { + if (numsplit[j] == groups[k]) { + alert("'"+numsplit[j]+"' may not be used as the name for a section, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name."); + return; + } + } + } + } if ((userrole == 'cc') && (numsections > 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,12 +400,89 @@ 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<document.cu.elements.length;i++) { + var str = document.cu.elements[i].name; + var checkcurr = str.match(re1); + if (checkcurr != null) { + var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/; + if (document.cu.elements[i-1].checked == true) { + var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/; + match = re2.exec(str); + var role = match[1]; + if (role == 'cc') { + alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections."); + } + else { + var sections = ''; + var numsec = 0; + var sections; + for (var j=0; j<document.cu.elements[i].length; j++) { + if (document.cu.elements[i].options[j].selected == true ) { + if (document.cu.elements[i].options[j].value != "") { + if (numsec == 0) { + if (document.cu.elements[i].options[j].value != "") { + sections = document.cu.elements[i].options[j].value; + numsec ++; + } + } + else { + sections = sections + "," + document.cu.elements[i].options[j].value + numsec ++; + } + } + } + } + if (numsec > 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<numsplit.length; j++) { + if ((numsplit[j] == 'all') || + (numsplit[j] == 'none')) { + alert("'"+numsplit[j]+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name."); + return; + } + for (var k=0; k<groups.length; k++) { + if (numsplit[j] == groups[k]) { + alert("'"+numsplit[j]+"' may not be used as a section name, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name."); + return; + } + } + } + document.cu.elements[i+2].value = sections; + } + } + } + } + } + document.cu.submit(); } - - my $js = &user_modification_js($pjump_def, $dc_setcourse_code); +ENDSECCODE + } + my $js = &user_modification_js($pjump_def,$dc_setcourse_code, + $nondc_setsection_code,$groupslist); my $start_page = &Apache::loncommon::start_page('Create Users, Change User Privileges', - $js,{'add_entries' => $loaditem,}); + $js,{'add_entries' => \%loaditem,}); my $forminfo =<<"ENDFORMINFO"; <form action="/adm/createuser" method="post" name="cu"> @@ -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.='<br />Section/Group: '.$3; + $carea.='<br />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('<h3>'.&mt('Modifying Roles').'</h3>'); 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.': <b>'. &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'}).'</b><br />'); } - } + } } elsif ($_=~/^form\.ren/) { my $udom = $env{'form.ccdomain'}; my $uname = $env{'form.ccuname'}; @@ -1164,7 +1287,7 @@ END $role,$url,$result).'<br />'; } $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('<p>'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$_.'</tt></p><br />'); } - } + foreach my $key (sort(keys(%disallowed))) { + if (($key eq 'none') || ($key eq 'all')) { + $r->print('<p>'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key)); + } else { + $r->print('<p>'.&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 <a href="javascript:history.go(-1)">go back</a> and choose a different section name.').'</p><br />'); + } + } } # 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 { ' <option value=""><--'.&mt('Pick course first').'</select></td>'. '<td> </td>'. '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'. - '<input type="text" name="newsec" value="" /></td>'. + '<input type="text" name="newsec" value="" />'. + '<input type="hidden" name="groups" value="" /></td>'. '</tr></table></td>'; $otheritems .= <<ENDTIMEENTRY; <td><input type=hidden name="start" value=''>