--- loncom/interface/loncreateuser.pm 2004/09/23 22:51:24 1.87 +++ loncom/interface/loncreateuser.pm 2004/11/23 18:03:04 1.88 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.87 2004/09/23 22:51:24 albertel Exp $ +# $Id: loncreateuser.pm,v 1.88 2004/11/23 18:03:04 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -197,6 +197,79 @@ sub print_user_modification_page { $ccuname=~s/\W//g; $ccdomain=~s/\W//g; my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition(); + my $dc_setcourse_code = ''; + my $loaditem; + if ($ENV{'request.role'} =~ m-^dc\./(\w+)/$-) { + my $dcdom = $1; + $loaditem = qq|OnLoad="document.cu.coursedesc.value=''"|; + $dc_setcourse_code = <<"ENDSCRIPT"; + function setCourse() { + var course = document.cu.dccourse.value; + if (course != "") { + if (document.cu.dcdomain.value != document.cu.origdom.value) { + alert("You must select a course in the current domain"); + return; + } + var userrole = document.cu.role.options[document.cu.role.selectedIndex].value + var section; + var numsections = 0; + if (document.cu.role.value != "cc") { + for (var i=0; i @@ -210,6 +283,7 @@ sub print_user_modification_page { } $pjump_def + $dc_setcourse_code function dateset() { eval("document.cu."+document.cu.pres_marker.value+ @@ -221,7 +295,7 @@ sub print_user_modification_page { ENDDOCHEAD $r->print(&Apache::loncommon::bodytag( - 'Create Users, Change User Privileges')); + 'Create Users, Change User Privileges',undef,$loaditem)); my $forminfo =<<"ENDFORMINFO";
@@ -682,8 +756,14 @@ ENDDROW # # Course level # - $r->print(&course_level_table(%inccourses)); - $r->print("
\n"); + + if ($ENV{'request.role'} =~ m-^dc\./(\w+)/$-) { + $r->print(&course_level_dc($1)); + $r->print('
'."\n"); + } else { + $r->print(&course_level_table(%inccourses)); + $r->print("
\n"); + } $r->print("
"); } @@ -989,24 +1069,25 @@ END my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5); my $url='/'.$one.'/'.$two; my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five; - $ENV{'form.sec_'.$full}=~s/\W//g; - if ($ENV{'form.sec_'.$full}) { - $url.='/'.$ENV{'form.sec_'.$full}; - } - my $start = ( $ENV{'form.start_'.$full} ? - $ENV{'form.start_'.$full} : - $now ); - my $end = ( $ENV{'form.end_'.$full} ? - $ENV{'form.end_'.$full} : - 0 ); - - $r->print(&mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url. - ($start?', '.&mt('starting').' '.localtime($start):''). - ($end?', ending '.localtime($end):'').': '. - &Apache::lonnet::assigncustomrole( - $ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$three,$four,$five,$end,$start). - '
'); + my $start = ( $ENV{'form.start_'.$full} ? + $ENV{'form.start_'.$full} : + $now ); + my $end = ( $ENV{'form.end_'.$full} ? + $ENV{'form.end_'.$full} : + 0 ); + + # split multiple sections + my %sections = (); + my $num_sections = &build_roles($ENV{'form.sec_'.$full},\%sections); + if ($num_sections == 0) { + $r->print(&commit_customrole($url,$three,$four,$five,$start,$end)); + } else { + foreach (sort {$a cmp $b} keys %sections) { + my $securl = $url.'/'.$_; + $r->print(&commit_customrole($securl,$three,$four,$five,$start,$end)); + } + } } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) { # Activate roles for sections with 3 id numbers # set start, end times, and the url for the class @@ -1018,33 +1099,27 @@ END $ENV{'form.end_'.$one.'_'.$two.'_'.$three} : 0 ); my $url='/'.$one.'/'.$two; - $ENV{'form.sec_'.$one.'_'.$two.'_'.$three}=~s/\W//g; - if ($ENV{'form.sec_'.$one.'_'.$two.'_'.$three}) { - $url.='/'.$ENV{'form.sec_'.$one.'_'.$two.'_'.$three}; - } - # Assign the role and report it - $r->print(&mt('Assigning').' '.$three.' in '.$url. - ($start?', '.&mt('starting').' '.localtime($start):''). - ($end?', '.&mt('ending').' '.localtime($end):'').': '. - &Apache::lonnet::assignrole( - $ENV{'form.ccdomain'},$ENV{'form.ccuname'}, - $url,$three,$end,$start). - '
'); - # Handle students differently - if ($three eq 'st') { - $url=~/^\/(\w+)\/(\w+)/; - my $cid=$one.'_'.$two; - $r->print(&mt('Add to classlist').': '. - &Apache::lonnet::critical( - 'put:'.$ENV{'course.'.$cid.'.domain'}.':'. - $ENV{'course.'.$cid.'.num'}.':classlist:'. - &Apache::lonnet::escape( - $ENV{'form.ccuname'}.':'. - $ENV{'form.ccdomain'} ).'='. - &Apache::lonnet::escape($end.':'.$start), - $ENV{'course.'.$cid.'.home'}) - .'
'); - } + my $type = 'three'; + # split multiple sections + my %sections = (); + my $num_sections = &build_roles($ENV{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections); + if ($num_sections == 0) { + $r->print(&commit_standardrole($url,$three,$start,$end,$one,$two)); + } else { + my $emptysec = 0; + foreach my $sec (sort {$a cmp $b} keys %sections) { + $sec =~ s/\W//g; + if ($sec ne '') { + my $securl = $url.'/'.$sec; + $r->print(&commit_standardrole($securl,$three,$start,$end,$one,$two)); + } else { + $emptysec = 1; + } + } + if ($emptysec) { + $r->print(&commit_standardrole($url,$three,$start,$end,$one,$two)); + } + } } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) { # Activate roles for sections with two id numbers # set start, end times, and the url for the class @@ -1055,6 +1130,25 @@ END $ENV{'form.end_'.$1.'_'.$2} : 0 ); my $url='/'.$1.'/'; + # split multiple sections + my %sections = (); + my $num_sections = &build_roles($ENV{'form.sec_'.$1.'_'.$2},\%sections); + if ($num_sections == 0) { + $r->print(&commit_standardrole($url,$2,$start,$end,$1)); + } else { + my $emptysec = 0; + foreach my $sec (sort {$a cmp $b} keys %sections) { + if ($sec ne '') { + my $securl = $url.'/'.$sec; + $r->print(&commit_standardrole($securl,$2,$start,$end,$1)); + } else { + $emptysec = 1; + } + } + if ($emptysec) { + $r->print(&commit_standardrole($url,$2,$start,$end,$1)); + } + } # Assign the role and report it. $r->print(&mt('Assigning').' '.$2.' in '.$url.': '. ($start?', '.&mt('starting').' '.localtime($start):''). @@ -1073,6 +1167,73 @@ END $r->print(''); } +sub commit_customrole { + my ($url,$three,$four,$five,$end,$start) = @_; + my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url. + ($start?', '.&mt('starting').' '.localtime($start):''). + ($end?', ending '.localtime($end):'').': '. + &Apache::lonnet::assigncustomrole( + $ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$three,$four,$five,$end,$start). + '
'; + return $output; +} + +sub commit_standardrole { + my ($url,$three,$start,$end,$one,$two) = @_; + my $output = (&mt('Assigning').' '.$three.' in '.$url. + ($start?', '.&mt('starting').' '.localtime($start):''). + ($end?', '.&mt('ending').' '.localtime($end):'').': '. + &Apache::lonnet::assignrole( + $ENV{'form.ccdomain'},$ENV{'form.ccuname'}, + $url,$three,$end,$start). + '
'); + +# Handle students differently + if (($three eq 'st') && defined($one) && defined($two)) { + $url=~/^\/(\w+)\/(\w+)/; + my $cid=$one.'_'.$two; + $output .= (&mt('Add to classlist').': '. + &Apache::lonnet::critical( + 'put:'.$ENV{'course.'.$cid.'.domain'}.':'. + $ENV{'course.'.$cid.'.num'}.':classlist:'. + &Apache::lonnet::escape( + $ENV{'form.ccuname'}.':'. + $ENV{'form.ccdomain'} ).'='. + &Apache::lonnet::escape($end.':'.$start), + $ENV{'course.'.$cid.'.home'}) + .'
'); + } + return $output; +} + + +sub build_roles { + my ($sectionstr,$sections) = @_; + my $num_sections = 0; + if ($sectionstr=~ /,/) { + my @secnums = split/,/,$sectionstr; + foreach my $sec (@secnums) { + $sec =~ ~s/\W//g; + unless ($sec eq "") { + if (exists($$sections{$sec})) { + $$sections{$sec} ++; + } else { + $$sections{$sec} = 1; + $num_sections ++; + } + } + } + } else { + $sectionstr=~s/\W//g; + unless ($sectionstr eq '') { + $$sections{$sectionstr} = 1; + $num_sections ++; + } + } + + return $num_sections; +} + # ========================================================== Custom Role Editor sub custom_role_editor { @@ -1376,6 +1537,64 @@ $table ENDTABLE return $result; } + +sub course_level_dc { + my ($dcdom) = @_; + my %customroles=&my_custom_roles(); + my $hiddenitems = ''. + ''. + ''; + my $courseform=''.&Apache::loncommon::selectcourse_link + ('cu','dccourse','dcdomain','coursedesc').''; + + my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,$dcdom); + my %lt=&Apache::lonlocal::texthash( + 'crl' => "Course Level", + 'crt' => "Course Title", + 'rol' => "Role", + 'grs' => "Group/Section", + 'exs' => "Existing sections", + 'new' => "Define new section", + 'sta' => "Start", + 'end' => "End", + 'ssd' => "Set Start Date", + 'sed' => "Set End Date" + ); + my $header = '

'.$lt{'crl'}.'

'. + ''; + my $otheritems = ''. + ''; + $otheritems .= < +$lt{'ssd'} + +ENDTIMEENTRY + $otheritems .= "
'.$courseform.''.$lt{'rol'}.''.$lt{'grs'}.''.$lt{'sta'}.''.$lt{'end'}.'
'. + ''. + ''. + ''. + ''. + '
'.$lt{'exs'}.'
   '.$lt{'new'}.'
'. + '
+$lt{'sed'}
\n"; + return $cb_jscript.$header.$hiddenitems.$otheritems; +} + #---------------------------------------------- end functions for &phase_two #--------------------------------- functions for &phase_two and &phase_three