--- loncom/interface/loncreateuser.pm 2004/02/01 20:42:01 1.78 +++ 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.78 2004/02/01 20:42:01 www Exp $ +# $Id: loncreateuser.pm,v 1.88 2004/11/23 18:03:04 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -123,10 +123,7 @@ sub print_username_entry_form { my $defdom=$ENV{'request.role.domain'}; my @domains = &Apache::loncommon::get_domains(); my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain'); - my $bodytag =&Apache::loncommon::bodytag( - 'Create Users, Change User Privileges'). - &Apache::loncommon::help_open_faq(282). - &Apache::loncommon::help_open_bug('Instructor Interface'); + my $bodytag =&Apache::loncommon::bodytag('Create Users, Change User Privileges').&Apache::loncommon::help_open_menu('',undef,undef,'',282,'Instructor Interface'); my $selscript=&Apache::loncommon::studentbrowser_javascript(); my $sellink=&Apache::loncommon::selectstudent_link ('crtuser','ccuname','ccdomain'); @@ -177,8 +174,8 @@ sub print_user_modification_page { my $ccuname=$ENV{'form.ccuname'}; my $ccdomain=$ENV{'form.ccdomain'}; - $ccuname=~s/\W//gs; - $ccdomain=~s/\W//gs; + $ccuname=~s/[\W|_]//gs; + $ccdomain=~s/[\W|_]//gs; unless (($ccuname) && ($ccdomain)) { &print_username_entry_form($r); @@ -200,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 @@ -213,6 +283,7 @@ sub print_user_modification_page { } $pjump_def + $dc_setcourse_code function dateset() { eval("document.cu."+document.cu.pres_marker.value+ @@ -224,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";
@@ -250,7 +321,7 @@ ENDFORMINFO ''."\n". &Apache::loncommon::home_server_option_list($ccdomain); - my %lt=&Apache::lonlocal::texthash( + my %lt=&Apache::lonlocal::texthash( 'cnu' => "Create New User", 'nu' => "New User", 'id' => "in domain", @@ -296,7 +367,7 @@ $lt{'hs'}: '; + } else { + $row.=' '; + } + $row.=''; if ($delallowed) { $row.= ''; } else { @@ -468,8 +564,24 @@ END ''.($role_end_time ?localtime($role_end_time) : ' ' ) ."\n"; - $r->print($row); + $sortrole{$sortkey}=$envkey; + $roletext{$envkey}=$row; + $roleclass{$envkey}=$class; + #$r->print($row); } # end of foreach (table building loop) + foreach my $type ('Construction Space','Course','Domain','System','Unknown') { + my $output; + foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) { + if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) { + $output.=$roletext{$sortrole{$which}}; + } + } + if (defined($output)) { + $r->print("". + "".&mt($type).""); + } + $r->print($output); + } $r->print(''); } # End of unless my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain); @@ -586,7 +698,7 @@ ENDOTHERAUTHS 'rol' => "Role", 'ext' => "Extent", 'sta' => "Start", - 'end' => "End". + 'end' => "End", 'cau' => "Co-Author", 'ssd' => "Set Start Date", 'sed' => "Set End Date" @@ -596,13 +708,13 @@ ENDOTHERAUTHS - + - - @@ -644,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(""); } @@ -924,54 +1042,14 @@ END $ENV{'course.'.$cid.'.home'}).'
'); } } - } elsif ($_=~/^form\.act/) { - if -($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) { - # Activate a custom role - my $url='/'.$1.'/'.$2; - my $full=$1.'_'.$2.'_cr_cr_'.$3.'_'.$4.'_'.$5; - 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').' "'.$5.'" by '.$4.'@'.$3.' in '.$url. - ($start?', '.&mt('starting').' '.localtime($start):''). - ($end?', ending '.localtime($end):'').': '. - &Apache::lonnet::assigncustomrole( - $ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$3,$4,$5,$end,$start). - '
'); - } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) { - # Activate roles for sections with 3 id numbers - # set start, end times, and the url for the class - - my $start = ( $ENV{'form.start_'.$1.'_'.$2.'_'.$3} ? - $ENV{'form.start_'.$1.'_'.$2.'_'.$3} : - $now ); - my $end = ( $ENV{'form.end_'.$1.'_'.$2.'_'.$3} ? - $ENV{'form.end_'.$1.'_'.$2.'_'.$3} : - 0 ); - my $url='/'.$1.'/'.$2; - if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) { - $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3}; - } - # Assign the role and report it - $r->print(&mt('Assigning').' '.$3.' in '.$url. - ($start?', '.&mt('starting').' '.localtime($start):''). - ($end?', '.&mt('ending').' '.localtime($end):'').': '. - &Apache::lonnet::assignrole( - $ENV{'form.ccdomain'},$ENV{'form.ccuname'}, - $url,$3,$end,$start). - '
'); - # Handle students differently - if ($3 eq 'st') { - $url=~/^\/(\w+)\/(\w+)/; + } elsif ($_=~/^form\.ren/) { + if ($_=~/^form\.ren\:([^\_]+)\_([^\_]+)$/) { + my $result=&Apache::lonnet::assignrole($ENV{'form.ccdomain'}, + $ENV{'form.ccuname'},$1,$2,0,$now); + $r->print(&mt('Re-Enabling [_1] in [_2]: [_3]', + $2,$1,$result).'
'); + if ($2 eq 'st') { + $1=~/^\/(\w+)\/(\w+)/; my $cid=$1.'_'.$2; $r->print(&mt('Add to classlist').': '. &Apache::lonnet::critical( @@ -980,10 +1058,68 @@ END &Apache::lonnet::escape( $ENV{'form.ccuname'}.':'. $ENV{'form.ccdomain'} ).'='. - &Apache::lonnet::escape($end.':'.$start), + &Apache::lonnet::escape(':'.$now), $ENV{'course.'.$cid.'.home'}) .'
'); } + } + } elsif ($_=~/^form\.act/) { + if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) { + # Activate a custom role + my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5); + my $url='/'.$one.'/'.$two; + my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five; + + 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 + my ($one,$two,$three)=($1,$2,$3); + my $start = ( $ENV{'form.start_'.$one.'_'.$two.'_'.$three} ? + $ENV{'form.start_'.$one.'_'.$two.'_'.$three} : + $now ); + my $end = ( $ENV{'form.end_'.$one.'_'.$two.'_'.$three} ? + $ENV{'form.end_'.$one.'_'.$two.'_'.$three} : + 0 ); + my $url='/'.$one.'/'.$two; + 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 @@ -994,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):''). @@ -1012,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 { @@ -1236,6 +1458,7 @@ sub course_level_table { my $bgcol=$thiscourse; $bgcol=~s/[^7-9a-e]//g; $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6); + my ($domain)=split(/\//,$thiscourse); foreach ('st','ta','ep','ad','in','cc') { if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) { my $plrole=&Apache::lonnet::plaintext($_); @@ -1243,7 +1466,7 @@ sub course_level_table { - + ENDEXTENT if ($_ ne 'cc') { $table .= <'. + ''. + ''; + 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'}.'

'. + '
$lt{'act'}$lt{'rol'}$lt{'ext'} $lt{'sta'}$lt{'end'}
$lt{'cau'} $cudom\_$cuname + $lt{'ssd'} + $lt{'sed'}
$plrole$area$area
Domain: $domain
'; + 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