--- loncom/interface/loncreateuser.pm 2007/12/23 15:50:23 1.223 +++ loncom/interface/loncreateuser.pm 2007/12/31 01:58:17 1.225 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.223 2007/12/23 15:50:23 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.225 2007/12/31 01:58:17 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -233,7 +233,14 @@ sub print_username_entry_form { text=>"Single user search", faq=>282,bug=>'Instructor Interface',}); } - my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management'); + my $helpitem = 'Course_Change_Privileges'; + if ($env{'form.action'} eq 'custom') { + $helpitem = 'Course_Editing_Custom_Roles'; + } elsif ($env{'form.action'} eq 'singlestudent') { + $helpitem = 'Course_Add_Student'; + } + my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management', + $helpitem); my %existingroles=&Apache::lonuserutils::my_custom_roles(); my $choice=&Apache::loncommon::select_form('make new role','rolename', ('make new role' => 'Generate new role ...',%existingroles)); @@ -249,9 +256,6 @@ sub print_username_entry_form { 'enrl' => "to enroll one student", ); my $help = &Apache::loncommon::help_open_menu(undef,undef,282,'Instructor Interface'); - my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges'); - my $helpsist=&Apache::loncommon::help_open_topic('Course_Add_Student'); - my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles'); my $sellink=&Apache::loncommon::selectstudent_link('crtuser','srchterm','srchdomain'); if ($sellink) { $sellink = "$lt{'or'} ".$sellink; @@ -263,16 +267,16 @@ sub print_username_entry_form {
-

$lt{'ecrp'}$helpecpr

+

$lt{'ecrp'}

$lt{'nr'}: $choice
ENDCUSTOM } } else { - my $actiontext = $lt{'mod'}.$helpsiur; + my $actiontext = $lt{'mod'}; if ($env{'form.action'} eq 'singlestudent') { - $actiontext = $lt{'enrl'}.$helpsist; + $actiontext = $lt{'enrl'}; } $r->print("

$lt{'srch'} $sellink $actiontext

"); @@ -420,7 +424,8 @@ ENDSCRIPT {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')", text=>"Select User", faq=>282,bug=>'Instructor Interface',}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management')); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management', + 'Course_Change_Privileges')); $r->print("$lt{'usrch'}
"); $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context)); $r->print('

'.$lt{'usel'}.'

'); @@ -432,7 +437,8 @@ ENDSCRIPT {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')", text=>"Select Student", faq=>282,bug=>'Instructor Interface',}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management')); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management', + 'Course_Add_Student')); $r->print($jscript."$lt{'stusrch'}
"); $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context)); $r->print('

'.$lt{'stusel'}.'

'); @@ -620,7 +626,12 @@ sub print_user_modification_page { ({href=>"javascript:backPage($form,'$env{'form.phase'}','modify')", text=>$breadcrumb_text{'modify'}, faq=>282,bug=>'Instructor Interface',}); - my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management'); + my $helpitem = 'Course_Change_Privileges'; + if ($env{'form.action'} eq 'singlestudent') { + $helpitem = 'Course_Add_Student'; + } + my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management', + $helpitem); my $forminfo =<<"ENDFORMINFO";
@@ -1508,7 +1519,12 @@ sub update_user_data { {href=>"/adm/createuser", text=>"Result", faq=>282,bug=>'Instructor Interface',}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management')); + my $helpitem = 'Course_Change_Privileges'; + if ($env{'form.action'} eq 'singlestudent') { + $helpitem = 'Course_Add_Student'; + } + $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management', + $helpitem)); $r->print(&update_result_form($uhome)); # Check Inputs if (! $env{'form.ccuname'} ) { @@ -2014,15 +2030,18 @@ END if ($env{'form.action'} eq 'singlestudent') { &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser); } else { - my $rolechanges = &update_roles($r); - if (!$rolechanges && $namechanged) { + my @rolechanges = &update_roles($r); + if ($namechanged) { if ($context eq 'course') { if (@userroles > 0) { - if (grep(/^st$/,@userroles)) { - my $classlistupdated = - &Apache::lonuserutils::update_classlist($cdom, + if ((@rolechanges == 0) || + (!(grep(/^st$/,@rolechanges)))) { + if (grep(/^st$/,@userroles)) { + my $classlistupdated = + &Apache::lonuserutils::update_classlist($cdom, $cnum,$env{'form.ccdomain'}, $env{'form.ccuname'},\%userupdate); + } } } } @@ -2034,7 +2053,7 @@ END sub update_roles { my ($r) = @_; my $now=time; - my $rolechanges = 0; + my @rolechanges; my %disallowed; $r->print('

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

'); foreach my $key (keys (%env)) { @@ -2058,6 +2077,9 @@ sub update_roles { $now); $r->print($result); } + if (!grep(/^\Q$role\E$/,@rolechanges)) { + push(@rolechanges,$role); + } } if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) { # Revoke custom role @@ -2066,8 +2088,10 @@ sub update_roles { &Apache::lonnet::revokecustomrole($env{'form.ccdomain'}, $env{'form.ccuname'},$1,$2,$3,$4). '
'); + if (!grep(/^cr$/,@rolechanges)) { + push(@rolechanges,'cr'); + } } - $rolechanges ++; } elsif ($key=~/^form\.del/) { if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) { # Delete standard role @@ -2085,6 +2109,9 @@ sub update_roles { $now); $r->print($result); } + if (!grep(/^\Q$role\E$/,@rolechanges)) { + push(@rolechanges,$role); + } } if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) { my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4); @@ -2094,8 +2121,10 @@ sub update_roles { &Apache::lonnet::assigncustomrole($env{'form.ccdomain'}, $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now, 0,1).'
'); + if (!grep(/^cr$/,@rolechanges)) { + push(@rolechanges,'cr'); + } } - $rolechanges ++; } elsif ($key=~/^form\.ren/) { my $udom = $env{'form.ccdomain'}; my $uname = $env{'form.ccuname'}; @@ -2128,6 +2157,9 @@ sub update_roles { $role,$url,$result).'
'; } $r->print($output); + if (!grep(/^\Q$role\E$/,@rolechanges)) { + push(@rolechanges,$role); + } } # Re-enable custom role if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) { @@ -2137,8 +2169,10 @@ sub update_roles { $url,$rdom,$rnam,$rolename,0,$now); $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : [_5]', $rolename,$rnam,$rdom,$url,$result).'
'); + if (!grep(/^cr$/,@rolechanges)) { + push(@rolechanges,'cr'); + } } - $rolechanges ++; } elsif ($key=~/^form\.act/) { my $udom = $env{'form.ccdomain'}; my $uname = $env{'form.ccuname'}; @@ -2173,6 +2207,9 @@ sub update_roles { $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end)); } } + if (!grep(/^cr$/,@rolechanges)) { + push(@rolechanges,'cr'); + } } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) { # Activate roles for sections with 3 id numbers # set start, end times, and the url for the class @@ -2211,7 +2248,10 @@ sub update_roles { if ($emptysec) { $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'')); } - } + } + if (!grep(/^\Q$three\E$/,@rolechanges)) { + push(@rolechanges,$three); + } } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) { # Activate roles for sections with two id numbers # set start, end times, and the url for the class @@ -2221,26 +2261,31 @@ sub update_roles { my $end = ( $env{'form.end_'.$1.'_'.$2} ? $env{'form.end_'.$1.'_'.$2} : 0 ); - my $url='/'.$1.'/'; + my $one = $1; + my $two = $2; + my $url='/'.$one.'/'; # split multiple sections my %sections = (); - my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2); + my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two); if ($num_sections == 0) { - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,'')); + $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'')); } else { my $emptysec = 0; foreach my $sec (sort {$a cmp $b} keys %sections) { if ($sec ne '') { my $securl = $url.'/'.$sec; - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec)); + $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec)); } else { $emptysec = 1; } } if ($emptysec) { - $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,'')); + $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'')); } } + if (!grep(/^\Q$two\E$/,@rolechanges)) { + push(@rolechanges,$two); + } } else { $r->print('

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


'); } @@ -2252,15 +2297,14 @@ sub update_roles { } $r->print(' '.&mt('Please go back and choose a different section name.').'


'); } - $rolechanges ++; } } # End of foreach (keys(%env)) # Flush the course logs so reverse user roles immediately updated &Apache::lonnet::flushcourselogs(); - if (!$rolechanges) { + if (@rolechanges == 0) { $r->print(&mt('No roles to modify')); } - return $rolechanges; + return @rolechanges; } sub enroll_single_student { @@ -2479,7 +2523,8 @@ sub custom_role_editor { {href=>"javascript:backPage(document.form1,'','')", text=>"Edit custom role", faq=>282,bug=>'Instructor Interface',}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management')); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management', + 'Course_Editing_Custom_Roles')); $r->print($body_top); my %lt=&Apache::lonlocal::texthash( @@ -2619,7 +2664,8 @@ sub set_custom_role { {href=>"javascript:backPage(document.customresult,'set_custom_roles','')", text=>"Result", faq=>282,bug=>'Instructor Interface',}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management')); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management', + 'Course_Editing_Custom_Roles')); my ($rdummy,$roledef)= &Apache::lonnet::get('roles',["rolesdef_$rolename"]); @@ -2727,7 +2773,7 @@ sub handler { ({href=>'/adm/createuser?action=upload&state=', text=>"Upload Users List"}); $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List', - 'User_Management_Upload')); + 'Course_Create_Class_List')); $r->print(''."\n"); @@ -2837,7 +2883,7 @@ sub handler { my $choice = $env{'form.bulkaction'}; $r->print(&header()); $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users", - 'User_Management_List')); + 'Course_View_Class_List')); if ($permission->{'cusr'}) { &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice); $r->print(&Apache::loncommon::end_page()); @@ -2869,7 +2915,7 @@ sub handler { $r->print(&header(&add_script(&verify_user_display()))); } $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users", - 'User_Management_List')); + 'Course_View_Class_List')); &Apache::lonuserutils::print_userlist($r,undef,$permission,$context, $formname,$totcodes,$codetitles,$idlist,$idlist_titles); $r->print(&Apache::loncommon::end_page()); @@ -2969,24 +3015,24 @@ sub print_main_menu { my @menu = ( { text => $links{$context}{'upload'}, - help => 'User_Management_Upload', + help => 'Course_Create_Class_List', action => 'upload', permission => $permission->{'cusr'}, }, { text => $links{$context}{'singleuser'}, - help => 'User_Management_Single_User', + help => 'Course_Change_Privileges', action => 'singleuser', permission => $permission->{'cusr'}, }, { text => $links{$context}{'listusers'}, - help => 'User_Management_List', + help => 'Course_View_Class_List', action => 'listusers', permission => ($permission->{'view'} || $permission->{'cusr'}), }, ); if ($context eq 'domain' || $context eq 'course') { my $customlink = { text => 'Edit Custom Roles', - help => 'Custom_Role_Edit', + help => 'Course_Editing_Custom_Roles', action => 'custom', permission => $permission->{'custom'}, }; @@ -2997,7 +3043,7 @@ sub print_main_menu { my @courselinks = ( { text => 'Enroll a Single Student', - help => 'Course_Single_Student', + help => 'Course_Add_Student', action => 'singlestudent', permission => $permission->{'cusr'}, },