--- loncom/interface/lonuserutils.pm 2012/08/21 01:50:34 1.140
+++ loncom/interface/lonuserutils.pm 2015/06/09 21:22:57 1.170
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.140 2012/08/21 01:50:34 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.170 2015/06/09 21:22:57 damieng 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.',' ').
+ "
'
+ );
+ $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,17 @@ 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');
}
+ &js_escape(\%alert);
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 +511,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.');
+ &js_escape(\$warning);
$auth_update = <<"END";
// Currently the initial password field is only supported for internal auth
// (see bug 6368).
@@ -638,6 +679,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 +692,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 +717,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');
@@ -739,6 +783,7 @@ sub upload_manager_javascript_reverse_as
if (!$can_assign->{'int'}) {
my $warning = &mt('You may not specify an initial password, 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.');
+ &js_escape(\$warning);
$auth_update = <<"END";
// Currently the initial password field is only supported for internal auth
// (see bug 6368).
@@ -771,6 +816,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 +829,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 +863,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 +953,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 +969,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 +987,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 +1016,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,28 +1041,64 @@ 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"
- .&mt('(only do if you know what you are doing.)')."\n";
+ ''.&Apache::loncommon::help_open_topic('ForceIDChange')."\n";
if ($context eq 'domain') {
- $output .= ' '."\n";
+ $output .=
+ ' '
+ .''."\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 +1131,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 +1141,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 +1167,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 +1187,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 +1345,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 +1357,7 @@ sub default_role_selector {
'grs' => "Section",
'exs' => "Existing sections",
'new' => "New section",
+ 'crd' => "Credits",
);
$options = '
'.$warning.''."\n");
@@ -1568,10 +1675,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 +1713,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') {
@@ -1691,33 +1804,37 @@ sub print_userlist {
}
}
if (keys(%userlist) == 0) {
+ my $msg = '';
if ($context eq 'author') {
- $r->print(&mt('There are no co-authors to display.')."\n");
+ $msg = &mt('There are no co-authors to display.');
} elsif ($context eq 'domain') {
if ($env{'form.roletype'} eq 'domain') {
- $r->print(&mt('There are no users with domain roles to display.')."\n");
+ $msg = &mt('There are no users with domain roles to display.');
} elsif ($env{'form.roletype'} eq 'author') {
- $r->print(&mt('There are no authors or co-authors to display.')."\n");
+ $msg = &mt('There are no authors or co-authors to display.');
} elsif ($env{'form.roletype'} eq 'course') {
- $r->print(&mt('There are no course users to display')."\n");
+ $msg = &mt('There are no course users to display');
} elsif ($env{'form.roletype'} eq 'community') {
- $r->print(&mt('There are no community users to display')."\n");
+ $msg = &mt('There are no community users to display');
}
} elsif ($context eq 'course') {
$r->print(&mt('There are no course users to display.')."\n");
}
+ $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(' '
+ $r->print(' '
.&mt('There are no users matching the search criteria.')
.''
);
@@ -1835,12 +1952,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) {
@@ -1856,7 +1973,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');
@@ -1866,9 +1983,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');
}
@@ -1877,19 +1991,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 '') {
@@ -1897,20 +2017,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 = '';
return $output;
@@ -1976,21 +2122,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;
}
@@ -2244,29 +2394,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().
- '
'.&mt('[_1]Your CSV file[_2] is ready for download.', '','')."
\n");
$r->rflush();
}
if ($mode eq 'autoenroll') {
@@ -2973,6 +3176,10 @@ sub bulkaction_javascript {
my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
my $singconfirm = &mt(' for a single user?');
my $multconfirm = &mt(' for multiple users?');
+ &js_escape(\$alert);
+ &js_escape(\$noaction);
+ &js_escape(\$singconfirm);
+ &js_escape(\$multconfirm);
my $output = <<"ENDJS";
function verify_action (field) {
var numchecked = 0;
@@ -3103,6 +3310,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') {
@@ -3110,15 +3318,20 @@ sub select_actions {
}
if ($context eq 'course') {
if ($env{'form.showrole'} ne 'Any') {
- if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},
- $env{'request.course.id'})) {
- if ($env{'request.course.sec'} eq '') {
- return;
- } else {
- if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
- return;
- }
- }
+ my $showactions;
+ if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},
+ $env{'request.course.id'})) {
+ $showactions = 1;
+ } elsif ($env{'request.course.sec'} ne '') {
+ if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
+ $showactions = 1;
+ }
+ }
+ unless ($showactions) {
+ unless (&is_courseowner($env{'request.course.id'},
+ $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
+ return;
+ }
}
}
}
@@ -3225,11 +3438,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";
-
END
my ($indexhash,$keylist) = &make_keylist_array();
@@ -3644,17 +3869,20 @@ END
}
}
if (!$studentcount) {
+ my $msg = '';
if ($crstype eq 'Community') {
- $r->print(&mt('There are no members to drop.'));
+ $msg = &mt('There are no members to drop.');
} else {
- $r->print(&mt('There are no students to drop.'));
+ $msg = &mt('There are no students to drop.');
}
+ $r->print('
'.&mt('Upload a file containing information about users').'
'."\n";
# Excel and CSV Help
- $str .= '
'
+ $str .= '
'
.&Apache::loncommon::help_open_topic("Course_Create_Class_List",
&mt("How do I create a users list from a spreadsheet"))
- .'
'."\n"
- .&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
+ .' '.&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
&mt("How do I create a CSV file from a spreadsheet"))
- .'
'."\n";
+ ."
\n";
$str .= &Apache::lonhtmlcommon::start_pick_box()
.&Apache::lonhtmlcommon::row_title(&mt('File'));
if (&Apache::lonlocal::current_language() ne 'en') {
@@ -3824,7 +4052,8 @@ sub print_first_users_upload_form {
.&Apache::lonhtmlcommon::end_pick_box();
$str .= '
'
- .''
+ .''
.'
';
$r->print($str);
@@ -3833,7 +4062,7 @@ sub print_first_users_upload_form {
# ================================================= Drop/Add from uploaded file
sub upfile_drop_add {
- my ($r,$context,$permission) = @_;
+ my ($r,$context,$permission,$showcredits) = @_;
&Apache::loncommon::load_tmp_file($r);
my @userdata=&Apache::loncommon::upfile_record_sep();
if($env{'form.noFirstLine'}){shift(@userdata);}
@@ -3854,25 +4083,17 @@ sub upfile_drop_add {
}
#
# Store the field choices away
- foreach my $field (qw/username names
- fname mname lname gen id sec ipwd email role domain/) {
+ my @storefields = qw/username names fname mname lname gen id
+ sec ipwd email role domain inststatus/;
+ if ($showcredits) {
+ push (@storefields,'credits');
+ }
+ my %fieldstype;
+ foreach my $field (@storefields) {
$env{'form.'.$field.'_choice'}=$fields{$field};
+ $fieldstype{$field.'_choice'} = 'scalar';
}
- &Apache::loncommon::store_course_settings('enrollment_upload',
- { 'username_choice' => 'scalar',
- 'names_choice' => 'scalar',
- 'fname_choice' => 'scalar',
- 'mname_choice' => 'scalar',
- 'lname_choice' => 'scalar',
- 'gen_choice' => 'scalar',
- 'id_choice' => 'scalar',
- 'sec_choice' => 'scalar',
- 'ipwd_choice' => 'scalar',
- 'email_choice' => 'scalar',
- 'role_choice' => 'scalar',
- 'domain_choice' => 'scalar',
- 'inststatus_choice' => 'scalar'});
- #
+ &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
my ($cid,$crstype,$setting);
if ($context eq 'domain') {
$setting = $env{'form.roleaction'};
@@ -3940,19 +4161,30 @@ sub upfile_drop_add {
$amode = ''; # This causes the loop below to be skipped
}
}
- my ($defaultsec,$defaultrole);
+ my ($defaultsec,$defaultrole,$defaultcredits,$commoncredits);
if ($context eq 'domain') {
if ($setting eq 'domain') {
$defaultrole = $env{'form.defaultrole'};
} elsif ($setting eq 'course') {
$defaultrole = $env{'form.courserole'};
$defaultsec = $env{'form.sections'};
- }
+ if ($showcredits) {
+ $commoncredits = $env{'form.credits'};
+ if ($crstype ne 'Community') {
+ my %coursehash=&Apache::lonnet::coursedescription($cid);
+ $defaultcredits = $coursehash{'internal.defaultcredits'};
+ }
+ }
+ }
} elsif ($context eq 'author') {
$defaultrole = $env{'form.defaultrole'};
} elsif ($context eq 'course') {
$defaultrole = $env{'form.defaultrole'};
$defaultsec = $env{'form.sections'};
+ if ($showcredits) {
+ $commoncredits = $env{'form.credits'};
+ $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'};
+ }
}
# Check to see if user information can be changed
my @userinfo = ('firstname','middlename','lastname','generation',
@@ -4097,18 +4329,23 @@ sub upfile_drop_add {
if ($entries{$fields{'username'}} =~ /\s/) {
$nowhitespace = ' - '.&mt('usernames may not contain spaces.');
}
- $r->print(' '.
- &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
- ''.$entries{$fields{'username'}}.'',$fname,$mname,$lname,$gen).
- $nowhitespace);
+ $r->print(
+ ' '.
+ &mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
+ '"'.$entries{$fields{'username'}}.'"',
+ $fname,$mname,$lname,$gen).
+ $nowhitespace);
next;
} else {
$entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
if ($entries{$fields{'domain'}}
ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
- $r->print(' '. ''.$entries{$fields{'domain'}}.
- ': '.&mt('Unacceptable domain for user [_2] [_3] [_4] [_5]',$fname,$mname,$lname,$gen));
- next;
+ $r->print(
+ ' '.
+ &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
+ '"'.$entries{$fields{'domain'}}.'"',
+ $fname,$mname,$lname,$gen));
+ next;
}
my $username = $entries{$fields{'username'}};
my $userdomain = $entries{$fields{'domain'}};
@@ -4212,6 +4449,21 @@ sub upfile_drop_add {
foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
$$_ =~ s/(\s+$|^\s+)//g;
}
+ my $credits;
+ if ($showcredits) {
+ if (($role eq 'st') && ($crstype ne 'Community')) {
+ $credits = $entries{$fields{'credits'}};
+ if ($credits ne '') {
+ $credits =~ s/[^\d\.]//g;
+ }
+ if ($credits eq '') {
+ $credits = $commoncredits;
+ }
+ if ($credits eq $defaultcredits) {
+ undef($credits);
+ }
+ }
+ }
# check against rules
my $checkid = 0;
my $newuser = 0;
@@ -4342,7 +4594,7 @@ sub upfile_drop_add {
$fname,$mname,$lname,$gen,$sec,$enddate,
$startdate,$env{'form.forceid'},
$desiredhost,$email,'manual','',$cid,
- '',$context,$inststatus);
+ '',$context,$inststatus,$credits);
$userresult = $roleresult;
} else {
if ($role ne '') {
@@ -4437,9 +4689,9 @@ sub upfile_drop_add {
# Get current classlist
my $classlist = &Apache::loncoursedata::get_classlist();
if (! defined($classlist)) {
- $r->print(''.
+ $r->print(''."\n");
} elsif (ref($classlist) eq 'HASH') {
# Remove the students we just added from the list of students.
@@ -4560,18 +4812,20 @@ sub print_drop_menu {
$heading = &mt("Drop Students");
}
$r->print('