--- loncom/interface/lonuserutils.pm 2007/12/22 17:33:26 1.27 +++ loncom/interface/lonuserutils.pm 2007/12/22 22:42:58 1.29 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.27 2007/12/22 17:33:26 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.29 2007/12/22 22:42:58 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2841,8 +2841,8 @@ sub viewable_section { ################################################# ################################################# sub show_drop_list { - my ($r,$classlist,$keylist,$nosort,$permission)=@_; - my $cid=$env{'request.course.id'}; + my ($r,$classlist,$keylist,$nosort,$permission) = @_; + my $cid = $env{'request.course.id'}; my ($cnum,$cdom) = &get_course_identity($cid); if (! exists($env{'form.sortby'})) { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, @@ -2971,13 +2971,13 @@ END # $r->print(&Apache::loncommon::start_data_table_row()); $r->print(<<"END"); - + $username $domain $id $name $section - $start + $start $startitem $end $active_groups END @@ -2985,7 +2985,7 @@ END } $r->print(&Apache::loncommon::end_data_table().'
'); %lt=&Apache::lonlocal::texthash( - 'dp' => "Expire Users' Roles", + 'dp' => "Drop Students", 'ca' => "check all", 'ua' => "uncheck all", ); @@ -3042,6 +3042,10 @@ sub upfile_drop_add { $fields{$env{'form.f'.$i}}=$keyfields[$i]; } } + if ($env{'form.fullup'} ne 'yes') { + $r->print('
'."\n". + ''); + } # # Store the field choices away foreach my $field (qw/username names @@ -3467,7 +3471,7 @@ sub upfile_drop_add { } } if (!$multiple) { - ($userresult,$authresult,$roleresult) = + ($userresult,$authresult,$roleresult,$idresult) = &modifyuserrole($context,$setting, $changeauth,$cid,$domain,$username, $id,$amode,$password,$fname, @@ -3487,8 +3491,8 @@ sub upfile_drop_add { } else { $flushc = &user_change_result($r,$userresult,$authresult, - $roleresult,\%counts,$flushc, - $username,%userchg); + $roleresult,$idresult,\%counts,$flushc, + $username,\%userchg); } } else { if ($context eq 'course') { @@ -3510,11 +3514,13 @@ sub upfile_drop_add { } # end of foreach (@userdata) # Flush the course logs so reverse user roles immediately updated &Apache::lonnet::flushcourselogs(); - $r->print("

\n

\n".&mt('Processed [_1] user(s).',$counts{'user'}). + $r->print("

\n

\n".&mt('Processed [quant,_1,user].',$counts{'user'}). "

\n"); if ($counts{'role'} > 0) { $r->print("

\n". - &mt('Roles added for [_1] users. If user is active, the new role will be available when the user next logs in to LON-CAPA.',$counts{'role'})."

\n"); + &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.&mt('If a user is currently logged-in to LON-CAPA, any new roles which are active will be available when the user next logs in.')."

\n"); + } else { + $r->print('

'.&mt('No roles added').'

'); } if ($counts{'auth'} > 0) { $r->print("

\n". @@ -3522,19 +3528,18 @@ sub upfile_drop_add { $counts{'auth'})."

\n"); } $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules)); - $r->print(''); - $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','prevphase','currstate'])); - $r->print('
'); ##################################### - # Drop students # + # Display list of students to drop # ##################################### if ($env{'form.fullup'} eq 'yes') { - $r->print('

'.&mt('Dropping Students')."

\n"); + $r->print('

'.&mt('Students to Drop')."

\n"); # Get current classlist my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist(); if (! defined($classlist)) { - $r->print(&mt('There are no students currently enrolled.'). - "\n"); + $r->print('
'. + ''. + &mt('There are no students with current/future access to the course.'). + '
'."\n"); } else { # Remove the students we just added from the list of students. foreach (@userdata) { @@ -3546,10 +3551,13 @@ sub upfile_drop_add { } } # Print out list of dropped students. - &show_drop_list($r,$classlist,$keylist,'nosort'); + &show_drop_list($r,$classlist,$keylist,'nosort',$permission); } } } # end of unless + if ($env{'form.fullup'} ne 'yes') { + $r->print(''); + } } sub print_namespacing_alerts { @@ -3593,8 +3601,8 @@ sub print_namespacing_alerts { } sub user_change_result { - my ($r,$userresult,$authresult,$roleresult,$counts,$flushc,$username, - $userchg) = @_; + my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc, + $username,$userchg) = @_; my $okresult = 0; if ($userresult ne 'ok') { if ($userresult =~ /^error:(.+)$/) { @@ -3635,6 +3643,9 @@ sub user_change_result { $flushc=0; } } + if ($idresult) { + $r->print($idresult); + } return $flushc; } @@ -3662,10 +3673,10 @@ sub update_user_list { my $now = time; my $count=0; my @changelist; - if ($choice ne '') { - @changelist = &Apache::loncommon::get_env_multiple('form.actionlist'); - } else { + if ($choice eq 'drop') { @changelist = &Apache::loncommon::get_env_multiple('form.droplist'); + } else { + @changelist = &Apache::loncommon::get_env_multiple('form.actionlist'); } my %result_text = ( ok => { 'revoke' => 'Revoked', 'delete' => 'Deleted', @@ -3732,7 +3743,6 @@ sub update_user_list { } } my $plrole = &Apache::lonnet::plaintext($role); - my ($uid,$first,$middle,$last,$gene,$sec); my $start = $env{'form.'.$item.'_start'}; my $end = $env{'form.'.$item.'_end'}; if ($choice eq 'drop') { @@ -3752,16 +3762,12 @@ sub update_user_list { &Apache::lonnet::revokerole($udom,$uname,$scope,$role); } } elsif ($choice eq 'delete') { - $start = -1; - $end = -1; if ($role eq 'st') { -# FIXME - how does role deletion affect classlist? - &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid); - } else { - $result = - &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now, - 0,1); - } + &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid); + } + $result = + &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now, + $start,1); } else { #reenable, activate, change access dates or change section if ($choice ne 'chgsec') { @@ -3803,27 +3809,36 @@ sub update_user_list { $nochg = 1; } } else { - if (!grep(/^\Q$sec\E$/,@newsecs)) { - $revresult = - &Apache::lonnet::revokerole($udom,$uname,$scope,$role); + if (@newsecs > 0) { + if (grep(/^\Q$sec\E$/,@newsecs)) { + push(@retained,$sec); + } else { + $revresult = + &Apache::lonnet::revokerole($udom,$uname, + $scope,$role); + } } else { - push(@retained,$sec); + $revresult = + &Apache::lonnet::revokerole($udom,$uname, + $scope,$role); } } } else { - push(@retained,$sec); + if ($sec eq '') { + $nochg = 1; + } else { + push(@retained,$sec); + } } # add new sections if (@newsecs == 0) { if (!$nochg) { - if ($sec ne '') { - if ($role eq 'st') { - $result = - &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid); - } else { - my $newscope = $scopestem; - $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start); - } + if ($role eq 'st') { + $result = + &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid); + } else { + my $newscope = $scopestem; + $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start); } } } else { @@ -3857,11 +3872,11 @@ sub update_user_list { $count++; } else { $r->print( - &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]:[_4]", + &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].", $plrole,$extent,$uname.':'.$udom,$result).'
'); } } - $r->print('

'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,users].",$count).'

'); + $r->print('

'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'

'); if ($count > 0) { if ($choice eq 'revoke' || $choice eq 'drop') { $r->print('

'.&mt('Re-enabling will re-activate data for the role.

')); @@ -3871,23 +3886,20 @@ sub update_user_list { } if ($env{'form.makedatesdefault'}) { if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') { - $r->print(&make_dates_default($startdate,$enddate)); + $r->print(&make_dates_default($startdate,$enddate,$context)); } } } sub classlist_drop { - my ($scope,$uname,$udom,$now,$action) = @_; + my ($scope,$uname,$udom,$now) = @_; my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)}); - my $cid=$cdom.'_'.$cnum; - my $user = $uname.':'.$udom; - if ($action eq 'drop') { + if (&Apache::lonnet::is_course($cdom,$cnum)) { + my $user = $uname.':'.$udom; if (!&active_student_roles($cnum,$cdom,$uname,$udom)) { my $result = &Apache::lonnet::cput('classlist', - { $user => $now }, - $env{'course.'.$cid.'.domain'}, - $env{'course.'.$cid.'.num'}); + { $user => $now },$cdom,$cnum); return &mt('Drop from classlist: [_1]', ''.$result.'').'
'; } @@ -3957,16 +3969,26 @@ sub course_sections { my ($sections_count,$role) = @_; my $output = ''; my @sections = (sort {$a <=> $b} keys %{$sections_count}); - if (scalar(@sections) == 1) { + my $numsec = scalar(@sections); + if ($numsec <= 1) { $output = ''."\n"; + if ($role eq 'st') { + $output .= '>'."\n". + ' '."\n". + ' \n"; + } else { + $output .= 'multiple="multiple" size="'.$multiple.'">'."\n"; + } foreach my $sec (@sections) { $output .= '\n"; } @@ -3986,16 +4008,27 @@ sub get_groupslist { } sub setsections_javascript { - my ($form,$groupslist) = @_; - my ($checkincluded,$finish,$roleplace,$setsection_js); - if ($form eq 'cu') { + my ($formname,$groupslist,$mode) = @_; + my ($checkincluded,$finish,$rolecode,$setsection_js); + if ($mode eq 'upload') { + $checkincluded = 'formname.name == "'.$formname.'"'; + $finish = "return 'ok';"; + $rolecode = "var role = formname.defaultrole.options[formname.defaultrole.selectedIndex].value;\n"; + } elsif ($formname eq 'cu') { $checkincluded = 'formname.elements[i-1].checked == true'; $finish = 'formname.submit()'; - $roleplace = 3; + $rolecode = "var match = str.split('_'); + var role = match[3];\n"; + } elsif ($formname eq 'enrollstudent') { + $checkincluded = 'formname.name == "'.$formname.'"'; + $finish = 'formname.submit()'; + $rolecode = "var match = str.split('_'); + var role = match[1];\n"; } else { - $checkincluded = 'formname.name == "'.$form.'"'; + $checkincluded = 'formname.name == "'.$formname.'"'; $finish = "seccheck = 'ok';"; - $roleplace = 1; + $rolecode = "var match = str.split('_'); + var role = match[1];\n"; $setsection_js = "var seccheck = 'alert';"; } my %alerts = &Apache::lonlocal::texthash( @@ -4020,8 +4053,7 @@ function setSections(formname) { var checkcurr = str.match(re1); if (checkcurr != null) { if ($checkincluded) { - var match = str.split('_'); - var role = match[$roleplace]; + $rolecode if (role == 'cc') { alert("$alerts{'secd'}\\n$alerts{'accr'}"); } @@ -4096,6 +4128,9 @@ sub can_create_user { my ($dom,$context,$usertype) = @_; my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom); my $cancreate = 1; + if (&Apache::lonnet::allowed('mau',$dom)) { + return $cancreate; + } if (ref($domconf{'usercreation'}) eq 'HASH') { if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') { if ($context eq 'course' || $context eq 'author') { @@ -4250,7 +4285,8 @@ sub get_permission { } else { my @allroles = &roles_by_context($context); foreach my $role (@allroles) { - if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) { $permission{'cusr'} = 1; + if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) { + $permission{'cusr'} = 1; last; } } @@ -4459,6 +4495,5 @@ sub sectioncheck_alerts { return %alerts; } - 1;