--- loncom/interface/lonuserutils.pm 2012/10/02 18:08:12 1.142 +++ loncom/interface/lonuserutils.pm 2014/02/05 18:02:15 1.161 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.142 2012/10/02 18:08:12 bisitz Exp $ +# $Id: lonuserutils.pm,v 1.161 2014/02/05 18:02:15 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -237,6 +237,8 @@ sub domain_roles_select { # Role types my @roletypes = ('domain','author','course','community'); my %lt = &role_type_names(); + my $onchangefirst = "updateCols('showrole')"; + my $onchangesecond = "updateCols('showrole')"; # # build up the menu information to be passed to # &Apache::loncommon::linked_select_forms @@ -283,7 +285,8 @@ sub domain_roles_select { my $result = &Apache::loncommon::linked_select_forms ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'}, 'roletype','showrole',\%select_menus, - ['domain','author','course','community']); + ['domain','author','course','community'],$onchangefirst, + $onchangesecond); return $result; } @@ -335,13 +338,22 @@ sub print_upload_manager_header { $env{'request.role.domain'},$context, $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"); + $r->print( + '

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

\n". + '

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

\n" + ); + if ($distotal == 0) { + $r->print('

'.&mt('None found').'

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

'. + &mt('Enter as many fields as you can.').'
'. + &mt('The system will inform you and bring you back to this page,[_1]if the data selected are insufficient to add users.','
'). + "

\n" + ); $r->print(&hidden_input('action','upload'). &hidden_input('state','got_file'). &hidden_input('associate',''). @@ -349,17 +361,23 @@ 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('
print( + '
'. + '
'.&mt('Functions').''. + ''. + ' '); - $r->print("

\n". - ''); + 'onclick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />'. + '

' + ); + $r->print( + '' + ); } ############################################################### @@ -381,6 +399,12 @@ sub javascript_validations { $param{'curr_autharg'} = $curr_authfield; } + my $showcredits; + my %domdefaults = &Apache::lonnet::get_domain_defaults($domain); + if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) { + $showcredits = 1; + } + my ($setsection_call,$setsections_js); my $finish = " vf.submit();\n"; if ($mode eq 'upload') { @@ -390,13 +414,14 @@ sub javascript_validations { $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');'; $setsections_js = &setsections_javascript($param{'formname'},$groupslist, - $mode,'',$crstype); + $mode,'',$crstype,$showcredits); } else { $setsection_call = "'ok'"; } } elsif ($context eq 'domain') { $setsection_call = 'setCourse()'; - $setsections_js = &dc_setcourse_js($param{'formname'},$mode,$context); + $setsections_js = &dc_setcourse_js($param{'formname'},$mode, + $context,$showcredits); } $finish = " var checkSec = $setsection_call\n". " if (checkSec == 'ok') {\n". @@ -419,13 +444,16 @@ sub javascript_validations { domain => 'The optional domain field was not specified.', continue => 'Continue adding users?', ); + if ($showcredits) { + $alert{'credits'} = &mt('The optional credits field was not specified'); + } 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,foundrole,founddomain,foundinststatus) { +function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits) { END my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain); my $auth_checks; @@ -482,6 +510,7 @@ END return; } } +/* regexp here to check for non \d \. in credits */ END } else { $auth_checks .= (<{'int'}) { - my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.\n'). + my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.').'\n'. &mt('Your current role does not have rights to create users with that authentication type.'); $auth_update = <<"END"; // Currently the initial password field is only supported for internal auth @@ -638,6 +677,7 @@ function verify(vf,sec_caller) { var foundrole=0; var founddomain=0; var foundinststatus=0; + var foundcredits=0; var tw; for (i=0;i<=vf.nfields.value;i++) { tw=eval('vf.f'+i+'.selectedIndex'); @@ -650,8 +690,9 @@ function verify(vf,sec_caller) { if (tw==11) { foundrole=1; } if (tw==12) { founddomain=1; } if (tw==13) { foundinststatus=1; } + if (tw==14) { foundcredits=1; } } - verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus); + verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits); } // @@ -674,6 +715,7 @@ function verify(vf,sec_caller) { // 11 = role // 12 = domain // 13 = inststatus +// 14 = foundcredits function flip(vf,tf) { var nw=eval('vf.f'+tf+'.selectedIndex'); @@ -771,6 +813,7 @@ function verify(vf,sec_caller) { var foundrole=0; var founddomain=0; var foundinststatus=0; + var foundcredits=0; var tw; for (i=0;i<=vf.nfields.value;i++) { tw=eval('vf.f'+i+'.selectedIndex'); @@ -783,8 +826,9 @@ function verify(vf,sec_caller) { if (i==10 && tw!=0) { foundrole=1; } if (i==11 && tw!=0) { founddomain=1; } if (i==12 && tw!=0) { foundinstatus=1; } + if (i==13 && tw!=0) { foundcredits=1; } } - verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus); + verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus,foundcredits); } function flip(vf,tf) { @@ -816,7 +860,8 @@ ENDPICK ############################################################### ############################################################### sub print_upload_manager_footer { - my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype) = @_; + my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype, + $showcredits) = @_; my $form = 'document.studentform'; my $formname = 'studentform'; my ($krbdef,$krbdefdom) = @@ -905,9 +950,15 @@ sub print_upload_manager_footer { &mt('Default role')) .&mt('Choose the role to assign to users without a value specified in the uploaded file.') } elsif ($context eq 'course') { - $Str .= &Apache::lonhtmlcommon::row_title( + if ($showcredits) { + $Str .= &Apache::lonhtmlcommon::row_title( + &mt('Default role, section and credits')) + .&mt('Choose the role and/or section(s) and/or credits to assign to users without values specified in the uploaded file.'); + } else { + $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.'); + .&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)')) @@ -915,7 +966,8 @@ sub print_upload_manager_footer { } if (($context eq 'domain') || ($context eq 'author')) { $Str .= '
'; - my ($options,$cb_script,$coursepick) = &default_role_selector($context,1); + my ($options,$cb_script,$coursepick) = + &default_role_selector($context,1,'',$showcredits); if ($context eq 'domain') { $Str .= '

' .''.&mt('Domain Level').'
' @@ -932,8 +984,13 @@ sub print_upload_manager_footer { } else { my ($cnum,$cdom) = &get_course_identity(); my $rowtitle = &mt('section'); - my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle, - $permission,$context,'upload',$crstype); + my $defaultcredits; + if ($showcredits) { + $defaultcredits = &get_defaultcredits(); + } + my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,$permission, + $context,'upload',$crstype,$showcredits, + $defaultcredits); $Str .= $secbox .&Apache::lonhtmlcommon::row_closure(); my %lt; @@ -956,7 +1013,9 @@ sub print_upload_manager_footer { .&Apache::lonhtmlcommon::row_closure(); } if ($context eq 'course' || $context eq 'domain') { - $Str .= &forceid_change($context); + $Str .= &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID')) + .&forceid_change($context) + .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box } $Str .= &Apache::lonhtmlcommon::end_pick_box(); @@ -979,11 +1038,49 @@ sub print_upload_manager_footer { return; } +sub get_defaultcredits { + my ($cdom,$cnum) = @_; + + if ($cdom eq '' || $cnum eq '') { + return unless ($env{'request.course.id'}); + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + } + return unless(($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/)); + my ($defaultcredits,$domdefcredits); + my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom); + if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) { + my $instcode = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'}; + if ($instcode) { + $domdefcredits = $domdefaults{'officialcredits'}; + } elsif ($env{'course.'.$cdom.'_'.$cnum.'.internal.textbook'}) { + $domdefcredits = $domdefaults{'textbookcredits'}; + } else { + $domdefcredits = $domdefaults{'unofficialcredits'}; + } + } else { + return; + } + + if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { + $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'}; + } elsif (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'})) { + $defaultcredits = $env{'course.'.$cdom.'_'.$cnum.'.internal.defaultcredits'}; + } else { + my %crsinfo = + &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1}); + $defaultcredits = $crsinfo{'internal.defaultcredits'}; + } + if ($defaultcredits eq '') { + $defaultcredits = $domdefcredits; + } + return $defaultcredits; +} + sub forceid_change { my ($context) = @_; my $output = - &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID')) - .''."\n"; } - $output .= &Apache::lonhtmlcommon::row_closure(1); # last row in pick_box return $output; } ############################################################### ############################################################### sub print_upload_manager_form { - my ($r,$context,$permission,$crstype) = @_; + my ($r,$context,$permission,$crstype,$showcredits) = @_; my $firstLine; my $datatoken; if (!$env{'form.datatoken'}) { @@ -1033,7 +1129,9 @@ sub print_upload_manager_form { 'domain_choice' => 'scalar', 'inststatus_choice' => 'scalar', }; - my $defdom = $env{'request.role.domain'}; + if ($showcredits) { + $col_setting_names->{'credits_choice'} = 'scalar'; + } if ($context eq 'course') { &Apache::loncommon::restore_course_settings('enrollment_upload', $col_setting_names); @@ -1041,6 +1139,7 @@ sub print_upload_manager_form { &Apache::loncommon::restore_settings($context,'user_upload', $col_setting_names); } + my $defdom = $env{'request.role.domain'}; # # Determine kerberos parameters as appropriate my ($krbdef,$krbdefdom) = @@ -1066,6 +1165,10 @@ sub print_upload_manager_form { ['role',&mt('Role'), $env{'form.role_choice'}], ['domain',&mt('Domain'), $env{'form.domain_choice'}], ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]); + if ($showcredits) { + push(@field, + ['credits',&mt('Student Credits'), $env{'form.credits_choice'}]); + } if ($env{'form.upfile_associate'} eq 'reverse') { &Apache::loncommon::csv_print_samples($r,\@records); $i=&Apache::loncommon::csv_print_select_table($r,\@records, @@ -1082,9 +1185,8 @@ sub print_upload_manager_form { $keyfields=join(',',sort(keys(%sone))); } } - $r->print('

'); &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear, - $context,$permission,$crstype); + $context,$permission,$crstype,$showcredits); } sub setup_date_selectors { @@ -1241,7 +1343,7 @@ sub make_dates_default { } sub default_role_selector { - my ($context,$checkpriv,$crstype) = @_; + my ($context,$checkpriv,$crstype,$showcredits) = @_; my %customroles; my ($options,$coursepick,$cb_jscript); if ($context ne 'author') { @@ -1253,6 +1355,7 @@ sub default_role_selector { 'grs' => "Section", 'exs' => "Existing sections", 'new' => "New section", + 'crd' => "Credits", ); $options = ''; + } $cb_jscript = - &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community'); + &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community',$credit_elem); $coursepick = &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(). ''.$courseform.''.$lt{'rol'}.''. ''.$lt{'grs'}.''. + ''.$lt{'crd'}.''. &Apache::loncommon::end_data_table_header_row(). &Apache::loncommon::start_data_table_row()."\n". ''."\n". @@ -1299,7 +1408,7 @@ sub default_role_selector { ''. ''. ''. - ''. + ''.$creditsinput. &Apache::loncommon::end_data_table_row(). &Apache::loncommon::end_data_table()."\n"; } @@ -1436,7 +1545,7 @@ sub my_custom_roles { sub print_userlist { my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles, - $idlist,$idlist_titles) = @_; + $idlist,$idlist_titles,$showcredits) = @_; my $format = $env{'form.output'}; if (! exists($env{'form.sortby'})) { $env{'form.sortby'} = 'username'; @@ -1471,10 +1580,6 @@ sub print_userlist { @statuses = ('future'); } -# if ($context eq 'course') { -# $r->print(&display_adv_courseroles()); -# } - # # Interface output $r->print('
'."\n". ''. - &column_checkboxes($context,$mode,$formname). - '
'); + &column_checkboxes($context,$mode,$formname,$showcredits). + ''); if ($env{'form.phase'} eq '') { - $r->print(&list_submit_button(&mt('Display List of Users'))."\n". + $r->print('
'. + &list_submit_button(&mt('Display List of Users'))."\n". '
'); return; } if (!(($context eq 'domain') && (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) { - $r->print(&list_submit_button(&mt('Update Display'))."\n"); + $r->print('
'. + &list_submit_button(&mt('Update Display'))."\n"); } - my @cols = &infocolumns($context,$mode); + my @cols = &infocolumns($context,$mode,$showcredits); if (!@cols) { - $r->print('
'. + $r->print('
'. &mt('No user information selected for display.').''. ''."\n"); return; } my ($indexhash,$keylist) = &make_keylist_array(); - my (%userlist,%userinfo,$clearcoursepick); + my (%userlist,%userinfo,$clearcoursepick,$needauthorquota,$needauthorusage); if (($context eq 'domain') && ($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')) { @@ -1553,12 +1660,10 @@ sub print_userlist { &Apache::lonhtmlcommon::course_selection($formname,$numcodes, $codetitles,$idlist,$idlist_titles,$crstype, \@standardnames); - $r->print('

'.&Apache::lonhtmlcommon::start_pick_box()."\n". - &Apache::lonhtmlcommon::start_pick_box()."\n". - &Apache::lonhtmlcommon::row_title($title,'LC_oddrow_value')."\n". + $r->print('

'. + '
'.$title.''."\n". $courseform."\n". - &Apache::lonhtmlcommon::row_closure(1). - &Apache::lonhtmlcommon::end_pick_box().'

'. + '

'. '

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

'.$warning.''."\n"); @@ -1568,10 +1673,10 @@ sub print_userlist { $clearcoursepick = 1; } if (($env{'form.coursepick'}) && (!$clearcoursepick)) { - $r->print('
'.&mt('Searching').' ...
 
'); + $r->print('
'.&mt('Searching ...').'
 
'); } } else { - $r->print('
'.&mt('Searching').' ...
'); + $r->print('
'.&mt('Searching ...').'
'); } $r->rflush(); if ($context eq 'course') { @@ -1606,6 +1711,12 @@ sub print_userlist { \%cstr_roles,$permission); } elsif ($context eq 'domain') { if ($env{'form.roletype'} eq 'domain') { + if (grep(/^authorusage$/,@cols)) { + $needauthorusage = 1; + } + if (grep(/^authorquota$/,@cols)) { + $needauthorquota = 1; + } %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'}); foreach my $key (keys(%dom_roles)) { if (ref($dom_roles{$key}) eq 'HASH') { @@ -1707,16 +1818,18 @@ sub print_userlist { } elsif ($context eq 'course') { $r->print(&mt('There are no course users to display.')."\n"); } - $r->print('

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

'.$msg.'

'."\n") if $msg; } else { # Print out the available choices my $usercount; if ($env{'form.action'} eq 'modifystudent') { ($usercount) = &show_users_list($r,$context,'view',$permission, - $env{'form.Status'},\%userlist,$keylist); + $env{'form.Status'},\%userlist,$keylist,'', + $showcredits); } else { ($usercount) = &show_users_list($r,$context,$env{'form.output'}, - $permission,$env{'form.Status'},\%userlist,$keylist); + $permission,$env{'form.Status'},\%userlist, + $keylist,'',$showcredits,$needauthorquota,$needauthorusage); } if (!$usercount) { $r->print('
' @@ -1837,12 +1950,12 @@ sub section_group_filter { } sub infocolumns { - my ($context,$mode) = @_; + my ($context,$mode,$showcredits) = @_; my @cols; if (($mode eq 'pickauthor') || ($mode eq 'autoenroll')) { - @cols = &get_cols_array($context,$mode); + @cols = &get_cols_array($context,$mode,$showcredits); } else { - my @posscols = &get_cols_array($context,$mode); + my @posscols = &get_cols_array($context,$mode,$showcredits); if ($env{'form.phase'} ne '') { my @checkedcols = &Apache::loncommon::get_env_multiple('form.showcol'); foreach my $col (@checkedcols) { @@ -1858,7 +1971,7 @@ sub infocolumns { } sub get_cols_array { - my ($context,$mode) = @_; + my ($context,$mode,$showcredits) = @_; my @cols; if ($mode eq 'pickauthor') { @cols = ('username','fullname','status','email'); @@ -1868,9 +1981,6 @@ sub get_cols_array { push(@cols,'section'); } push(@cols,('start','end','role')); - if ($context eq 'domain') { - push (@cols,'extent'); - } unless (($mode eq 'autoenroll') && ($env{'form.Status'} ne 'Any')) { push(@cols,'status'); } @@ -1879,19 +1989,25 @@ sub get_cols_array { } push(@cols,'email'); if (($context eq 'course') && ($mode ne 'autoenroll')) { + if ($showcredits) { + push(@cols,'credits'); + } push(@cols,'lastlogin','clicker'); } if (($context eq 'course') && ($mode ne 'autoenroll') && ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) { - push(@cols,'photos'); + push(@cols,'photo'); + } + if ($context eq 'domain') { + push (@cols,('authorusage','authorquota','extent')); } } return @cols; } sub column_checkboxes { - my ($context,$mode,$formname) = @_; - my @cols = &get_cols_array($context,$mode); + my ($context,$mode,$formname,$showcredits) = @_; + my @cols = &get_cols_array($context,$mode,$showcredits); my @showncols = &Apache::loncommon::get_env_multiple('form.showcol'); my (%disabledchk,%unchecked); if ($env{'form.phase'} eq '') { @@ -1899,20 +2015,35 @@ sub column_checkboxes { if ($context eq 'course') { $disabledchk{'role'} = 1; $unchecked{'photo'} = 1; + $unchecked{'clicker'} = 1; + if ($showcredits) { + $unchecked{'credits'} = 1; + } + } elsif ($context eq 'domain') { + $unchecked{'extent'} = 1; } - $unchecked{'clicker'} = 1; $unchecked{'start'} = 1; $unchecked{'end'} = 1; } else { if ($env{'form.Status'} ne 'Any') { $disabledchk{'status'} = 1; } - if ($env{'form.showrole'} ne 'Any') { - $disabledchk{'role'} = 1; + if (($env{'form.showrole'} ne 'Any') && ($env{'form.showrole'} ne 'cr')) { + $disabledchk{'role'} = 1; + } + if ($context eq 'domain') { + if (($env{'form.roletype'} eq 'course') || + ($env{'form.roletype'} eq 'community')) { + $disabledchk{'status'} = 1; + $disabledchk{'authorusage'} = 1; + $disabledchk{'authorquota'} = 1; + } elsif ($env{'form.roletype'} eq 'domain') { + $disabledchk{'extent'} = 1; + } } } my $numposs = scalar(@cols); - my $numinrow = 8; + my $numinrow = 7; my %lt = &get_column_names($context); my $output = '
'.&mt('Information to show').''."\n".''. ''. @@ -1952,9 +2083,20 @@ sub column_checkboxes { } else { $output .= ''; } - $output .= ''; - + my $style; + if ($cols[$i] eq 'extent') { + if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) { + $style = ' style="display: none;"'; + } + } elsif (($cols[$i] eq 'authorusage') || ($cols[$i] eq 'authorquota')) { + if ($env{'form.roletype'} ne 'domain') { + $style = ' style="display: none;"'; + } + } + $output .= ''; } $output .= '
'; return $output; @@ -1978,21 +2120,25 @@ sub get_column_names { 'end' => "end date", 'status' => "status", 'role' => "role", + 'credits' => "credits", 'type' => "enroll type/action", 'email' => "e-mail address", 'photo' => "photo", 'lastlogin' => "last login", 'extent' => "extent", + 'authorusage' => "disk usage (%)", + 'authorquota' => "disk quota (MB)", 'ca' => "check all", 'ua' => "uncheck all", 'clicker' => "clicker-ID", ); if ($context eq 'domain' && $env{'form.roletype'} eq 'course') { - $lt{'extent'} = &mt('Course(s): description, section(s), status'); + $lt{'extent'} = &mt('course(s): description, section(s), status'); } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') { - $lt{'extent'} = &mt('Communities: description, section(s), status'); - } elsif ($context eq 'author') { - $lt{'extent'} = &mt('Author'); + $lt{'extent'} = &mt('community(s): description, section(s), status'); + } elsif (($context eq 'author') || + ($context eq 'domain' && $env{'form.roletype'} eq 'author')) { + $lt{'extent'} = &mt('author'); } return %lt; } @@ -2246,29 +2392,6 @@ sub instcode_from_coursefilter { return $instcode; } -sub display_adv_courseroles { - my $output; - # - # List course personnel - my %coursepersonnel = - &Apache::lonnet::get_course_adv_roles($env{'request.course.id'}); - # - $output = '
'.&Apache::loncommon::start_data_table(); - foreach my $role (sort(keys(%coursepersonnel))) { - next if ($role =~ /^\s*$/); - $output .= &Apache::loncommon::start_data_table_row(). - ''.$role.''; - foreach my $user (split(',',$coursepersonnel{$role})) { - my ($puname,$pudom)=split(':',$user); - $output .= ' '.&Apache::loncommon::aboutmewrapper( - &Apache::loncommon::plainname($puname,$pudom), - $puname,$pudom); - } - $output .= ''.&Apache::loncommon::end_data_table_row(); - } - $output .= &Apache::loncommon::end_data_table(); -} - sub make_keylist_array { my ($index,$keylist); $index->{'domain'} = &Apache::loncoursedata::CL_SDOM(); @@ -2287,6 +2410,9 @@ sub make_keylist_array { $index->{'extent'} = &Apache::loncoursedata::CL_EXTENT(); $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO(); $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL(); + $index->{'credits'} = &Apache::loncoursedata::CL_CREDITS(); + $index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA(); + $index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE(); foreach my $key (keys(%{$index})) { $keylist->[$index->{$key}] = $key; } @@ -2335,10 +2461,12 @@ sub process_date_info { } sub show_users_list { - my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname)=@_; + my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname, + $showcredits,$needauthorquota,$needauthorusage)=@_; if ($formname eq '') { $formname = 'studentform'; } + my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; # # Variables for excel output my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format); @@ -2350,21 +2478,31 @@ sub show_users_list { my @sortable = ('username','domain','id','fullname','start','end','email','role'); if ($context eq 'course') { push(@sortable,('section','groups','type')); + if ($showcredits) { + push(@sortable,'credits'); + } } else { push(@sortable,'extent'); + if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') && + (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'au'))) { + push(@sortable,('authorusage','authorquota')); + } } if ($mode eq 'pickauthor') { @sortable = ('username','fullname','email','status'); } - if (!grep(/^\Q$sortby\E$/,@sortable)) { + my %is_sortable; + map { $is_sortable{$_} = 1; } @sortable; + unless ($is_sortable{$sortby}) { $sortby = 'username'; } my $setting = $env{'form.roletype'}; - my ($cid,$cdom,$cnum,$classgroups,$crstype); + my ($cid,$cdom,$cnum,$classgroups,$crstype,$defaultcredits); if ($context eq 'course') { $cid = $env{'request.course.id'}; $crstype = &Apache::loncommon::course_type(); ($cnum,$cdom) = &get_course_identity($cid); + $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'}; ($classgroups) = &Apache::loncoursedata::get_group_memberships( $userlist,$keylist,$cdom,$cnum); if ($mode eq 'autoenroll') { @@ -2457,7 +2595,7 @@ END $r->print(< END - my @cols = &infocolumns($context,$mode); + my @cols = &infocolumns($context,$mode,$showcredits); my %coltxt = &get_column_names($context); my %acttxt = &Apache::lonlocal::texthash( 'pr' => "Proceed", @@ -2579,7 +2717,11 @@ END if ($env{'form.userwin'}) { $checkwin = ' checked="checked"'; } - $output .= ''.$lt{'owin'}.''; + $output .= + '' + .''; } $output .= "\n".'
'."\n". &Apache::loncommon::start_data_table(). @@ -2591,11 +2733,17 @@ END } else { $output .= "\n".' '."\n"; if ($actionselect) { - $output .= ''.&mt('Select').''."\n"; + $output .= ''.&mt('Select').''."\n"; } } foreach my $item (@cols) { - $output .= "$lt{$item}\n"; + $output .= ''; + if ($is_sortable{$item}) { + $output .= "$lt{$item}"; + } else { + $output .= $lt{$item}; + } + $output .= "\n"; } my %role_types = &role_type_names(); $output .= &Apache::loncommon::end_data_table_header_row(); @@ -2755,12 +2903,37 @@ END 'gif','thumbnail'); } } + if (($role eq 'st') && ($defaultcredits)) { + if ($userlist->{$user}->[$index{'credits'}] eq '') { + $userlist->{$user}->[$index{'credits'}] = $defaultcredits; + } + } } } my %emails = &Apache::loncommon::getemails($uname,$udom); if ($emails{'permanentemail'} =~ /\S/) { $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'}; } + if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') && + ($role eq 'au')) { + my ($disk_quota,$current_disk_usage,$percent); + if (($needauthorusage) || ($needauthorquota)) { + $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author'); + } + if ($needauthorusage) { + $current_disk_usage = + &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname"); + if ($disk_quota == 0) { + $percent = 100.0; + } else { + $percent = $current_disk_usage/(10 * $disk_quota); + } + $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent); + } + if ($needauthorquota) { + $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota); + } + } $usercount ++; } my $autocount = 0; @@ -2781,12 +2954,20 @@ END my $index = $index{$sortby}; my $second = $index{'username'}; my $third = $index{'domain'}; - my @sorted_users = sort { - lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index]) - || - lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) || - lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third]) - } (keys(%$userlist)); + my @sorted_users; + if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) { + @sorted_users = sort { + $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index] || + lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) || + lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third]) + } (keys(%$userlist)); + } else { + @sorted_users = sort { + lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index]) || + lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) || + lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third]) + } (keys(%$userlist)); + } my $rowcount = 0; foreach my $user (@sorted_users) { my %in; @@ -2797,7 +2978,7 @@ END } my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1]; if ($clickers!~/\w/) { $clickers='-'; } - $in{'clicker'} = $clickers; + $in{'clicker'} = $clickers; my $role = $in{'role'}; $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype); unless ($mode eq 'excel') { @@ -2872,7 +3053,8 @@ END $checkval .= ':'.$in{'section'}; if ($role eq 'st') { $checkval .= ':'.$in{'type'}.':'. - $in{'lockedtype'}; + $in{'lockedtype'}.':'. + $in{'credits'}; } } } @@ -2919,7 +3101,9 @@ END } else { $r->print(' '."\n"); } - } + } + } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) { + $r->print(''.$in{$item}.''."\n"); } else { $r->print(''.$in{$item}.''."\n"); } @@ -3120,6 +3304,7 @@ sub select_actions { chgdates => "Change starting/ending dates", chgsec => "Change section associated with user roles", ); + # FIXME Add an option to change credits for student roles. my ($output,$options,%choices); # FIXME Disable actions for now for roletype=course in domain context if ($context eq 'domain' && $setting eq 'course') { @@ -3247,11 +3432,13 @@ ENDTWO } sub date_section_selector { - my ($context,$permission,$crstype) = @_; + my ($context,$permission,$crstype,$showcredits) = @_; my $callingform = $env{'form.callingform'}; my $formname = 'dateselect'; my $groupslist = &get_groupslist(); - my $sec_js = &setsections_javascript($formname,$groupslist); + my $sec_js = + &setsections_javascript($formname,$groupslist,undef,undef,$crstype, + $showcredits); my $output = <<"END";