--- loncom/interface/lonuserutils.pm 2008/03/06 21:57:33 1.51 +++ loncom/interface/lonuserutils.pm 2009/12/20 01:49:42 1.109 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.51 2008/03/06 21:57:33 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.109 2009/12/20 01:49:42 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,7 +42,7 @@ use LONCAPA qw(:DEFAULT :match); ############################################################### # Drop student from all sections of a course, except optional $csec sub modifystudent { - my ($udom,$unam,$courseid,$csec,$desiredhost)=@_; + my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_; # if $csec is undefined, drop the student from all the courses matching # this one. If $csec is defined, drop them from all other sections of # this course and add them to section $csec @@ -69,7 +69,7 @@ sub modifystudent { # dom name id mode pass f m l g ($udom,$unam,'', '', '',undef,undef,undef,undef, $section,time,undef,undef,$desiredhost,'','manual', - '',$courseid); + '',$courseid,'',$context); $result .= $reply.':'; } } @@ -86,12 +86,12 @@ sub modifystudent { sub modifyuserrole { my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass, $first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role, - $end,$start,$checkid) = @_; + $end,$start,$checkid,$inststatus) = @_; my ($scope,$userresult,$authresult,$roleresult,$idresult); if ($setting eq 'course' || $context eq 'course') { $scope = '/'.$cid; $scope =~ s/\_/\//g; - if ($role ne 'cc' && $sec ne '') { + if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) { $scope .='/'.$sec; } } elsif ($context eq 'domain') { @@ -124,12 +124,13 @@ sub modifyuserrole { $userresult = &Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first, $middle,$last,$gene,$forceid,$desiredhome, - $email,$role,$start,$end); + $email,$inststatus); if ($userresult eq 'ok') { if ($role ne '') { $role =~ s/_/\//g; $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope, - $role,$end,$start); + $role,$end,$start,'', + '',$context); } } return ($userresult,$authresult,$roleresult,$idresult); @@ -168,7 +169,7 @@ sub propagate_id_change { } sub update_classlist { - my ($cdom,$cnum,$udom,$uname,$user) = @_; + my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_; my ($uid,$classlistentry); my $fullname = &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'}, @@ -179,15 +180,37 @@ sub update_classlist { my @classinfo = split(/:/,$classhash{$uname.':'.$udom}); my $ididx=&Apache::loncoursedata::CL_ID() - 2; my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2; + my $endidx = &Apache::loncoursedata::CL_END() - 2; + my $startidx = &Apache::loncoursedata::CL_START() - 2; for (my $i=0; $i<@classinfo; $i++) { - if ($i == $ididx) { + if ($i == $endidx) { + if ($newend ne '') { + $classlistentry .= $newend.':'; + } else { + $classlistentry .= $classinfo[$i].':'; + } + } elsif ($i == $startidx) { + if ($newend ne '') { + if ($classinfo[$i] > $newend) { + $classlistentry .= $newend.':'; + } else { + $classlistentry .= $classinfo[$i].':'; + } + } else { + $classlistentry .= $classinfo[$i].':'; + } + } elsif ($i == $ididx) { if (defined($user->{'id'})) { $classlistentry .= $user->{'id'}.':'; } else { $classlistentry .= $classinfo[$i].':'; } } elsif ($i == $nameidx) { - $classlistentry .= $fullname.':'; + if (defined($user->{'lastname'})) { + $classlistentry .= $fullname.':'; + } else { + $classlistentry .= $classinfo[$i].':'; + } } else { $classlistentry .= $classinfo[$i].':'; } @@ -212,7 +235,7 @@ sub domain_roles_select { # domain context # # Role types - my @roletypes = ('domain','author','course'); + my @roletypes = ('domain','author','course','community'); my %lt = &role_type_names(); # # build up the menu information to be passed to @@ -224,6 +247,10 @@ sub domain_roles_select { foreach my $roletype (@roletypes) { # set up the text for this domain $select_menus{$roletype}->{'text'}= $lt{$roletype}; + my $crstype; + if ($roletype eq 'community') { + $crstype = 'Community'; + } # we want a choice of 'default' as the default in the second menu if ($env{'form.roletype'} ne '') { $select_menus{$roletype}->{'default'} = $env{'form.showrole'}; @@ -238,7 +265,7 @@ sub domain_roles_select { @roles = &construction_space_roles(); } else { my $custom = 1; - @roles = &course_roles('domain',undef,$custom); + @roles = &course_roles('domain',undef,$custom,$roletype); } my $order = ['Any',@roles]; $select_menus{$roletype}->{'order'} = $order; @@ -248,14 +275,15 @@ sub domain_roles_select { &mt('Custom role'); } else { $select_menus{$roletype}->{'select2'}->{$role} = - &Apache::lonnet::plaintext($role); + &Apache::lonnet::plaintext($role,$crstype); } } $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any'); } my $result = &Apache::loncommon::linked_select_forms ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'}, - 'roletype','showrole',\%select_menus,['domain','author','course']); + 'roletype','showrole',\%select_menus, + ['domain','author','course','community']); return $result; } @@ -267,7 +295,7 @@ sub hidden_input { } sub print_upload_manager_header { - my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission)=@_; + my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype)=@_; my $javascript; # if (! exists($env{'form.upfile_associate'})) { @@ -304,10 +332,12 @@ sub print_upload_manager_header { my $javascript_validations = &javascript_validations('upload',$krbdefdom,$password_choice,undef, $env{'request.role.domain'},$context, - $groupslist); - my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':''); - $r->print(&mt('Total number of records found in file: [_1].',$distotal). - "
\n"); + $groupslist,$crstype); + my $checked=(($env{'form.noFirstLine'})?' checked="checked"':''); + $r->print('

' + .&mt('Total number of records found in file: [_1]' + ,''.$distotal.'') + ."

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

'. &mt('Identify fields in uploaded list')."

\n"); $r->print(&mt('Enter as many fields as you can.
The system will inform you and bring you back to this page,
if the data selected are insufficient to add users.')."
\n"); @@ -318,21 +348,24 @@ sub print_upload_manager_header { &hidden_input('fileupload',$env{'form.fileupload'}). &hidden_input('upfiletype',$env{'form.upfiletype'}). &hidden_input('upfile_associate',$env{'form.upfile_associate'})); - $r->print('
'); - $r->print(''); + $r->print('

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

\n". ''); + '// '."\n". + ''); } ############################################################### ############################################################### sub javascript_validations { my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain, - $context,$groupslist)=@_; + $context,$groupslist,$crstype)=@_; my %param = ( kerb_def_dom => $krbdefdom, curr_authtype => $curr_authtype, @@ -353,10 +386,10 @@ sub javascript_validations { if (($context eq 'course') || ($context eq 'domain')) { if ($context eq 'course') { if ($env{'request.course.sec'} eq '') { - $setsection_call = 'setSections(document.'.$param{'formname'}.');'; + $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');'; $setsections_js = &setsections_javascript($param{'formname'},$groupslist, - $mode); + $mode,'',$crstype); } else { $setsection_call = "'ok'"; } @@ -378,16 +411,20 @@ sub javascript_validations { krb => 'You need to specify the Kerberos domain.', ipass => 'You need to specify the initial password.', name => 'The optional name field was not specified.', - snum => 'The optional ID number field was not specified.', + snum => 'The optional student/employee ID field was not specified.', section => 'The optional section field was not specified.', - email => 'The optional email address field was not specified.', + email => 'The optional e-mail address field was not specified.', role => 'The optional role field was not specified.', + domain => 'The optional domain field was not specified.', continue => 'Continue adding users?', ); + if (($mode eq 'upload') && ($context eq 'domain')) { + $alert{'inststatus'} = &mt('The optional affiliation field was not specified'); + } my $function_name = <<"END"; $setsections_js -function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail) { +function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus) { END my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain); my $auth_checks; @@ -502,6 +539,32 @@ END } message+='$alert{'email'}'; } + if (foundrole==0) { + if (message!='') { + message+='\\n'; + } + message+='$alert{'role'}'; + } + if (founddomain==0) { + if (message!='') { + message+='\\n'; + } + message+='$alert{'domain'}'; + } +END + if (($mode eq 'upload') && ($context eq 'domain')) { + $optional_checks .= (<'; $Str .= &hidden_input('nfields',$i); $Str .= &hidden_input('keyfields',$keyfields); - $Str .= "

".&mt('Login Type')."

\n"; + + $Str .= '

'.&mt('Options').'

' + .&Apache::lonhtmlcommon::start_pick_box(); + + $Str .= &Apache::lonhtmlcommon::row_title(&mt('Login Type')); if ($context eq 'domain') { - $Str .= '

'.&mt('Change authentication for existing users to these settings?').'   

'; + $Str .= '

' + .&mt('Change authentication for existing users in domain "[_1]" to these settings?' + ,$defdom) + .' ' + .'  ' + .'

'; } else { - $Str .= "

\n". - &mt('Note: this will not take effect if the user already exists'). + $Str .= '

'."\n". + &mt('This will not take effect if the user already exists.'). &Apache::loncommon::help_open_topic('Auth_Options'). "

\n"; } $Str .= &set_login($defdom,$krbform,$intform,$locform); + my ($home_server_pick,$numlib) = &Apache::loncommon::home_server_form_item($defdom,'lcserver', 'default','hide'); if ($numlib > 1) { - $Str .= '

'.&mt('LON-CAPA Home Server for New Users')."

\n". - &mt('LON-CAPA domain: [_1] with home server: [_2]',$defdom, - $home_server_pick).'
'; - } else { - $Str .= $home_server_pick; - } - $Str .= '

'.&mt('Starting and Ending Dates'). - "

\n"; - $Str .= "

\n".$date_table."

\n"; + $Str .= &Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title( + &mt('LON-CAPA Home Server for New Users')) + .&mt('LON-CAPA domain: [_1] with home server:','"'.$defdom.'"') + .$home_server_pick + .&Apache::lonhtmlcommon::row_closure(); + } else { + $Str .= $home_server_pick. + &Apache::lonhtmlcommon::row_closure(); + } + + $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain')) + .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1) + .&Apache::lonhtmlcommon::row_closure(); + + $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates')) + ."

\n".$date_table."

\n" + .&Apache::lonhtmlcommon::row_closure(); + if ($context eq 'domain') { - $Str .= '

'.&mt('Settings for assigning roles:').'

'."\n". - &mt('Pick the action to take on roles for these users:').'
      '; - } - if ($context eq 'author') { - $Str .= '

'.&mt('Default role')."

\n". - &mt('Choose the role to assign to users without a value specified in the uploaded file'); + $Str .= &Apache::lonhtmlcommon::row_title( + &mt('Settings for assigning roles')) + .&mt('Pick the action to take on roles for these users:').'
' + .'' + .'   ' + .'   ' + .''; + } elsif ($context eq 'author') { + $Str .= &Apache::lonhtmlcommon::row_title( + &mt('Default role')) + .&mt('Choose the role to assign to users without a value specified in the uploaded file.') } elsif ($context eq 'course') { - $Str .= '

'.&mt('Default role and section')."

\n". - &mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file'); - } else { - $Str .= '

'.&mt('Default role and/or section(s)')."
\n". - &mt('Role and/or section(s) for users without values specified in the uploaded file.'); + $Str .= &Apache::lonhtmlcommon::row_title( + &mt('Default role and section')) + .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.'); + } else { + $Str .= &Apache::lonhtmlcommon::row_title( + &mt('Default role and/or section(s)')) + .&mt('Role and/or section(s) for users without values specified in the uploaded file.'); } - $Str .= '
'; if (($context eq 'domain') || ($context eq 'author')) { + $Str .= '
'; my ($options,$cb_script,$coursepick) = &default_role_selector($context,1); if ($context eq 'domain') { - $Str .= ''.&mt('Domain Level').'
'.$options.'

'.&mt('Course Level').'
'.$cb_script.$coursepick; + $Str .= '

' + .''.&mt('Domain Level').'
' + .$options + .'

' + .''.&mt('Course Level').'' + .'

' + .$cb_script.$coursepick + .&Apache::lonhtmlcommon::row_closure(); } elsif ($context eq 'author') { - $Str .= $options; + $Str .= $options + .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box } } else { my ($cnum,$cdom) = &get_course_identity(); my $rowtitle = &mt('section'); my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle, - $permission,$context,'upload'); - $Str .= $secbox."

".&mt('Full Update')."

\n". - '


'.&mt('Students selected from this list can be dropped.').'

'."\n"; + $permission,$context,'upload',$crstype); + $Str .= $secbox + .&Apache::lonhtmlcommon::row_closure(); + my %lt; + if ($crstype eq 'Community') { + %lt = &Apache::lonlocal::texthash ( + disp => 'Display members with current/future access who are not in the uploaded file', + stus => 'Members selected from this list can be dropped.' + ); + } else { + %lt = &Apache::lonlocal::texthash ( + disp => 'Display students with current/future access who are not in the uploaded file', + stus => 'Students selected from this list can be dropped.' + ); + } + $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update')) + .'
' + .$lt{'stus'} + .&Apache::lonhtmlcommon::row_closure(); } if ($context eq 'course' || $context eq 'domain') { $Str .= &forceid_change($context); } - $Str .= '
'; + + # Footer + $Str .= ''; $r->print($Str); return; } @@ -769,25 +914,25 @@ sub print_upload_manager_footer { sub forceid_change { my ($context) = @_; my $output = - "

".&mt('ID/Student Number')."

\n". - "

\n".'
'."\n". - &mt('(only do if you know what you are doing.)')."\n"; + &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID')) + .'
'."\n" + .&mt('(only do if you know what you are doing.)')."\n"; if ($context eq 'domain') { $output .= '
'."\n"; } - $output .= '

'; + $output .= &Apache::lonhtmlcommon::row_closure(1); # last row in pick_box return $output; } ############################################################### ############################################################### sub print_upload_manager_form { - my ($r,$context,$permission) = @_; + my ($r,$context,$permission,$crstype) = @_; my $firstLine; my $datatoken; if (!$env{'form.datatoken'}) { @@ -817,6 +962,8 @@ sub print_upload_manager_form { 'ipwd_choice' => 'scalar', 'email_choice' => 'scalar', 'role_choice' => 'scalar', + 'domain_choice' => 'scalar', + 'inststatus_choice' => 'scalar', }; my $defdom = $env{'request.role.domain'}; if ($context eq 'course') { @@ -832,7 +979,7 @@ sub print_upload_manager_form { &Apache::loncommon::get_kerberos_defaults($defdom); # &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context, - $permission); + $permission,$crstype); my $i; my $keyfields; if ($total>=0) { @@ -843,11 +990,13 @@ sub print_upload_manager_form { ['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}], ['lname',&mt('Last Name'), $env{'form.lname_choice'}], ['gen', &mt('Generation'), $env{'form.gen_choice'}], - ['id', &mt('ID/Student Number'),$env{'form.id_choice'}], + ['id', &mt('Student/Employee ID'),$env{'form.id_choice'}], ['sec', &mt('Section'), $env{'form.sec_choice'}], ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}], ['email',&mt('E-mail Address'), $env{'form.email_choice'}], - ['role',&mt('Role'), $env{'form.role_choice'}]); + ['role',&mt('Role'), $env{'form.role_choice'}], + ['domain',&mt('Domain'), $env{'form.domain_choice'}], + ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]); if ($env{'form.upfile_associate'} eq 'reverse') { &Apache::loncommon::csv_print_samples($r,\@records); $i=&Apache::loncommon::csv_print_select_table($r,\@records, @@ -866,7 +1015,7 @@ sub print_upload_manager_form { } $r->print(''); &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear, - $context,$permission); + $context,$permission,$crstype); } sub setup_date_selectors { @@ -924,8 +1073,15 @@ sub setup_date_selectors { sub get_dates_from_form { - my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate'); - my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate'); + my ($startname,$endname) = @_; + if ($startname eq '') { + $startname = 'startdate'; + } + if ($endname eq '') { + $endname = 'enddate'; + } + my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname); + my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname); if ($env{'form.no_end_date'}) { $enddate = 0; } @@ -933,7 +1089,7 @@ sub get_dates_from_form { } sub date_setting_table { - my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission) = @_; + my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_; my $nolink; if ($bulkaction) { $nolink = 1; @@ -950,15 +1106,19 @@ sub date_setting_table { ($env{'form.action'} eq 'upload')) { if ($env{'request.course.sec'} eq '') { $dateDefault = ''. - ''; + ''; } } } my $perpetual = ''; if ($mode eq 'create_enrolldates') { @@ -981,7 +1141,7 @@ sub date_setting_table { } sub make_dates_default { - my ($startdate,$enddate,$context) = @_; + my ($startdate,$enddate,$context,$crstype) = @_; my $result = ''; if ($context eq 'course') { my ($cnum,$cdom) = &get_course_identity(); @@ -989,26 +1149,34 @@ sub make_dates_default { {'default_enrollment_start_date'=>$startdate, 'default_enrollment_end_date' =>$enddate},$cdom,$cnum); if ($put_result eq 'ok') { - $result .= &mt('Set default start and end access dates for course.'). - '
'."\n"; + if ($crstype eq 'Community') { + $result .= &mt('Set default start and end access dates for community.'); + } else { + $result .= &mt('Set default start and end access dates for course.'); + } + $result .= '
'."\n"; # # Refresh the course environment &Apache::lonnet::coursedescription($env{'request.course.id'}, {'freshen_cache' => 1}); } else { - $result .= &mt('Unable to set default access dates for course.').":".$put_result. - '
'; + if ($crstype eq 'Community') { + $result .= &mt('Unable to set default access dates for community'); + } else { + $result .= &mt('Unable to set default access dates for course'); + } + $result .= ':'.$put_result.'
'; } } return $result; } sub default_role_selector { - my ($context,$checkpriv) = @_; + my ($context,$checkpriv,$crstype) = @_; my %customroles; my ($options,$coursepick,$cb_jscript); if ($context ne 'author') { - %customroles = &my_custom_roles(); + %customroles = &my_custom_roles($crstype); } my %lt=&Apache::lonlocal::texthash( @@ -1020,7 +1188,7 @@ sub default_role_selector { $options = ''."\n". + ''."\n". ''. ''. '
'. @@ -1061,6 +1229,7 @@ sub default_role_selector { $env{'request.role.domain'}.'" />'. ''. ''. + ''. '
'. &Apache::loncommon::end_data_table_row(). &Apache::loncommon::end_data_table()."\n"; @@ -1070,13 +1239,13 @@ sub default_role_selector { } sub default_course_roles { - my ($context,$checkpriv,%customroles) = @_; + my ($context,$checkpriv,$crstype,%customroles) = @_; my $output; my $custom = 1; - my @roles = &course_roles($context,$checkpriv,$custom); + my @roles = &course_roles($context,$checkpriv,$custom,lc($crstype)); foreach my $role (@roles) { if ($role ne 'cr') { - my $plrole=&Apache::lonnet::plaintext($role); + my $plrole=&Apache::lonnet::plaintext($role,$crstype); $output .= ' '; } } @@ -1125,8 +1294,14 @@ sub domain_roles { } sub course_roles { - my ($context,$checkpriv,$custom) = @_; - my @allroles = &roles_by_context('course',$custom); + my ($context,$checkpriv,$custom,$roletype) = @_; + my $crstype; + if ($roletype eq 'community') { + $crstype = 'Community' ; + } else { + $crstype = 'Course'; + } + my @allroles = &roles_by_context('course',$custom,$crstype); my @roles; if ($context eq 'domain') { @roles = @allroles; @@ -1137,7 +1312,7 @@ sub course_roles { if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) { push(@roles,$role); } else { - if ($role ne 'cc' && $env{'request.course.sec'} ne '') { + if ((($role ne 'cc') && ($role ne 'co')) && ($env{'request.course.sec'} ne '')) { if (&Apache::lonnet::allowed('c'.$role, $env{'request.course.id'}.'/'. $env{'request.course.sec'})) { @@ -1155,19 +1330,19 @@ sub course_roles { } sub curr_role_permissions { - my ($context,$setting,$checkpriv) = @_; + my ($context,$setting,$checkpriv,$type) = @_; my $custom = 1; my @roles; if ($context eq 'author') { @roles = &construction_space_roles($checkpriv); } elsif ($context eq 'domain') { if ($setting eq 'course') { - @roles = &course_roles($context,$checkpriv,$custom); + @roles = &course_roles($context,$checkpriv,$custom,$type); } else { @roles = &domain_roles($checkpriv); } } elsif ($context eq 'course') { - @roles = &course_roles($context,$checkpriv,$custom); + @roles = &course_roles($context,$checkpriv,$custom,$type); } return @roles; } @@ -1175,10 +1350,14 @@ sub curr_role_permissions { # ======================================================= Existing Custom Roles sub my_custom_roles { + my ($crstype) = @_; my %returnhash=(); my %rolehash=&Apache::lonnet::dump('roles'); - foreach my $key (keys %rolehash) { + foreach my $key (keys(%rolehash)) { if ($key=~/^rolesdef\_(\w+)$/) { + if ($crstype eq 'Community') { + next if ($rolehash{$key} =~ /bre\&S/); + } $returnhash{$1}=$1; } } @@ -1236,70 +1415,77 @@ sub print_userlist { 'html' => 'HTML'); my $output_selector = ''; - $r->print(''.(' 'x3)); - } - $r->print(''.(' 'x3)."\n"); + $r->print(''.(' 'x3)); + } + $r->print(''.(' 'x3)."\n"); my $roleselected = ''; if ($env{'form.showrole'} eq 'Any') { - $roleselected = ' selected="selected" '; + $roleselected = ' selected="selected"'; } - my ($role_select,$cnum,$cdom); - if ($context eq 'domain') { - $role_select = &domain_roles_select(); - $r->print(''); - } else { - $role_select = ''; - $r->print(''); - if ($context eq 'course') { - ($cnum,$cdom) = &get_course_identity(); - $r->print(§ion_group_filter($cnum,$cdom)); - } + my ($cnum,$cdom); + $r->print(&role_filter($context)); + if ($context eq 'course') { + ($cnum,$cdom) = &get_course_identity(); + $r->print(§ion_group_filter($cnum,$cdom)); + } + if ($env{'form.phase'} eq '') { + $r->print('

'.&list_submit_button(&mt('Display List of Users')). + "\n

\n". + ''); + return; } - if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) { + if (!(($context eq 'domain') && + (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) { $r->print(' '.&list_submit_button(&mt('Update Display')). "\n

\n"); } my ($indexhash,$keylist) = &make_keylist_array(); - my (%userlist,%userinfo); - if ($context eq 'domain' && $env{'form.roletype'} eq 'course') { + my (%userlist,%userinfo,$clearcoursepick); + if (($context eq 'domain') && + ($env{'form.roletype'} eq 'course') || + ($env{'form.roletype'} eq 'community')) { + my ($crstype,$numcodes,$title,$warning); + if ($env{'form.roletype'} eq 'course') { + $crstype = 'Course'; + $numcodes = $totcodes; + $title = &mt('Select Courses'); + $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.'); + } elsif ($env{'form.roletype'} eq 'community') { + $crstype = 'Community'; + $numcodes = 0; + $title = &mt('Select Communities'); + $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.'); + } my $courseform = - &Apache::lonhtmlcommon::course_selection($formname,$totcodes, - $codetitles,$idlist,$idlist_titles); + &Apache::lonhtmlcommon::course_selection($formname,$numcodes, + $codetitles,$idlist,$idlist_titles,$crstype); $r->print('

'.&Apache::lonhtmlcommon::start_pick_box()."\n". &Apache::lonhtmlcommon::start_pick_box()."\n". - &Apache::lonhtmlcommon::row_title(&mt('Select Course(s)'), - 'LC_oddrow_value')."\n". + &Apache::lonhtmlcommon::row_title($title,'LC_oddrow_value')."\n". $courseform."\n". &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::end_pick_box().'

'. - '

'.&list_submit_button(&mt('Update Display')). - "\n".'

'.&mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.').''."\n"); - if ($env{'form.coursepick'}) { + '

'. + &list_submit_button(&mt('Update Display')). + "\n".'

'.$warning.''."\n"); + $clearcoursepick = 0; + if (($env{'form.origroletype'} ne '') && + ($env{'form.origroletype'} ne $env{'form.roletype'})) { + $clearcoursepick = 1; + } + if (($env{'form.coursepick'}) && (!$clearcoursepick)) { $r->print('
'.&mt('Searching').' ...
 
'); } } else { @@ -1309,7 +1495,9 @@ sub print_userlist { if ($context eq 'course') { if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) { my $classlist = &Apache::loncoursedata::get_classlist(); - %userlist = %{$classlist}; + if (ref($classlist) eq 'HASH') { + %userlist = %{$classlist}; + } } if ($env{'form.showrole'} ne 'st') { my $showroles; @@ -1370,8 +1558,9 @@ sub print_userlist { } } } - } elsif ($env{'form.roletype'} eq 'course') { - if ($env{'form.coursepick'}) { + } elsif (($env{'form.roletype'} eq 'course') || + ($env{'form.roletype'} eq 'community')) { + if (($env{'form.coursepick'}) && (!$clearcoursepick)) { my %courses = &process_coursepick(); my %allusers; my $hidepriv = 1; @@ -1382,7 +1571,8 @@ sub print_userlist { my (@roles,@sections,%access,%users,%userdata, %statushash); if ($env{'form.showrole'} eq 'Any') { - @roles = &course_roles($context,undef,$custom); + @roles = &course_roles($context,undef,$custom, + $env{'form.roletype'}); } else { @roles = ($env{'form.showrole'}); } @@ -1428,6 +1618,8 @@ sub print_userlist { $r->print(&mt('There are no authors or co-authors to display.')."\n"); } elsif ($env{'form.roletype'} eq 'course') { $r->print(&mt('There are no course users to display')."\n"); + } elsif ($env{'form.roletype'} eq 'community') { + $r->print(&mt('There are no community users to display')."\n"); } } elsif ($context eq 'course') { $r->print(&mt('There are no course users to display.')."\n"); @@ -1443,13 +1635,64 @@ sub print_userlist { $permission,$env{'form.Status'},\%userlist,$keylist); } if (!$usercount) { - $r->print('
'.&mt('There are no users matching the search criteria.')); + $r->print('
' + .&mt('There are no users matching the search criteria.') + .'' + ); } } $r->print(''); } +sub role_filter { + my ($context) = @_; + my $output; + my $roleselected = ''; + if ($env{'form.showrole'} eq 'Any') { + $roleselected = ' selected="selected"'; + } + my ($role_select); + if ($context eq 'domain') { + $role_select = &domain_roles_select(); + $output = ''; + } else { + $role_select = ''; + $output = ''; + } + return $output; +} + sub section_group_filter { my ($cnum,$cdom) = @_; my @filters; @@ -1474,7 +1717,7 @@ sub section_group_filter { $env{'form.'.$name{$item}} = 'all'; } if ($item eq 'sec') { - if ($env{'form.showrole'} eq 'cc') { + if (($env{'form.showrole'} eq 'cc') || ($env{'form.showrole'} eq 'co')) { $env{'form.'.$name{$item}} = 'none'; } my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum); @@ -1489,7 +1732,7 @@ sub section_group_filter { foreach my $option ('all','none',@options) { $currsel = ''; if ($env{'form.'.$name{$item}} eq $option) { - $currsel = ' selected="selected" '; + $currsel = ' selected="selected"'; } $markup .= '