--- loncom/interface/lonuserutils.pm 2010/11/15 17:37:47 1.109.2.9
+++ loncom/interface/lonuserutils.pm 2016/10/10 03:02:47 1.176
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.109.2.9 2010/11/15 17:37:47 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.176 2016/10/10 03:02:47 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,13 +30,29 @@
package Apache::lonuserutils;
+=pod
+
+=head1 NAME
+
+Apache::lonuserutils.pm
+
+=head1 SYNOPSIS
+
+ Utilities for management of users and custom roles
+
+ Provides subroutines called by loncreateuser.pm
+
+=head1 OVERVIEW
+
+=cut
+
use strict;
use Apache::lonnet;
use Apache::loncommon();
use Apache::lonhtmlcommon;
use Apache::lonlocal;
use Apache::longroup;
-use Apache::lonnavmaps;
+use HTML::Entities;
use LONCAPA qw(:DEFAULT :match);
###############################################################
@@ -238,6 +254,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
@@ -284,7 +302,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;
}
@@ -296,7 +315,7 @@ sub hidden_input {
}
sub print_upload_manager_header {
- my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,$formname,
+ my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
$can_assign)=@_;
my $javascript;
#
@@ -327,66 +346,55 @@ sub print_upload_manager_header {
$password_choice = 'int';
}
#
- my ($sectionjs,$groupslist);
+ my $groupslist;
if ($context eq 'course') {
$groupslist = &get_groupslist();
- if ($env{'form.context'} eq 'requestcrs') {
- $sectionjs = <<"ENDJS";
-
-function toggleSectionsDefault() {
- var usingsecs;
- if (document.$formname.usesection.length > 1) {
- for (var i=0; iprint('
'
- .&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.').' '.
- &mt('The system will inform you and bring you back to this page,').
- ' '.&mt('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(
+ ''
+ );
}
###############################################################
@@ -408,6 +416,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') {
@@ -415,19 +429,16 @@ sub javascript_validations {
if ($context eq 'course') {
if ($env{'request.course.sec'} eq '') {
$setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
- if ($env{'form.context'} eq 'requestcrs') {
- $setsections_js = &newsections_javascript($param{'formname'});
- } else {
- $setsections_js =
- &setsections_javascript($param{'formname'},$groupslist,
- $mode,'',$crstype);
- }
+ $setsections_js =
+ &setsections_javascript($param{'formname'},$groupslist,
+ $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".
@@ -450,13 +461,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;
@@ -513,6 +528,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).
- if (nw==2) {
+ if (nw==9) {
eval('vf.f'+tf+'.selectedIndex=0;')
alert('$warning');
}
@@ -659,7 +675,7 @@ END
$auth_update = <<"END";
// If we set the password, make the password form below correspond to
// the new value.
- if (nw==2) {
+ if (nw==9) {
changed_radio('int',document.studentform);
set_auth_radio_buttons('int',document.studentform);
$argreset
@@ -680,20 +696,22 @@ 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');
if (tw==1) { founduname=1; }
- if (tw==2) { foundpwd=1; }
- if ((tw>=3) && (tw<=7)) { foundname=1; }
- if (tw==8) { foundid=1; }
- if (tw==9) { foundsec=1; }
+ if ((tw>=2) && (tw<=6)) { foundname=1; }
+ if (tw==7) { foundid=1; }
+ if (tw==8) { foundsec=1; }
+ if (tw==9) { foundpwd=1; }
if (tw==10) { foundemail=1; }
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);
}
//
@@ -704,18 +722,19 @@ function verify(vf,sec_caller) {
//
// 0 = none
// 1 = username
-// 2 = ipwd (password)
-// 3 = names (lastname, firstnames)
-// 4 = fname (firstname)
-// 5 = mname (middlename)
-// 6 = lname (lastname)
-// 7 = gen (generation)
-// 8 = id
-// 9 = section
+// 2 = names (lastname, firstnames)
+// 3 = fname (firstname)
+// 4 = mname (middlename)
+// 5 = lname (lastname)
+// 6 = gen (generation)
+// 7 = id
+// 8 = section
+// 9 = ipwd (password)
// 10 = email address
// 11 = role
// 12 = domain
// 13 = inststatus
+// 14 = foundcredits
function flip(vf,tf) {
var nw=eval('vf.f'+tf+'.selectedIndex');
@@ -727,20 +746,20 @@ function flip(vf,tf) {
}
}
// If we set this to 'lastname, firstnames', clear out all the ones
- // set to 'fname','mname','lname','gen' (4,5,6,7) currently.
- if (nw==3) {
+ // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
+ if (nw==2) {
for (i=0;i<=vf.nfields.value;i++) {
- if ((eval('vf.f'+i+'.selectedIndex')>=4) &&
- (eval('vf.f'+i+'.selectedIndex')<=7)) {
+ if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
+ (eval('vf.f'+i+'.selectedIndex')<=6)) {
eval('vf.f'+i+'.selectedIndex=0;')
}
}
}
- // If we set this to one of 'fname','mname','lname','gen' (4,5,6,7),
- // clear out any that are set to 'lastname, firstnames' (3)
- if ((nw>=4) && (nw<=7)) {
+ // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
+ // clear out any that are set to 'lastname, firstnames' (2)
+ if ((nw>=3) && (nw<=6)) {
for (i=0;i<=vf.nfields.value;i++) {
- if (eval('vf.f'+i+'.selectedIndex')==3) {
+ if (eval('vf.f'+i+'.selectedIndex')==2) {
eval('vf.f'+i+'.selectedIndex=0;')
}
}
@@ -751,7 +770,7 @@ function flip(vf,tf) {
function clearpwd(vf) {
var i;
for (i=0;i<=vf.nfields.value;i++) {
- if (eval('vf.f'+i+'.selectedIndex')==2) {
+ if (eval('vf.f'+i+'.selectedIndex')==9) {
eval('vf.f'+i+'.selectedIndex=0;')
}
}
@@ -781,10 +800,11 @@ 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).
- if (tf==1 && nw!=0) {
+ if (tf==8 && nw!=0) {
eval('vf.f'+tf+'.selectedIndex=0;')
alert('$warning');
}
@@ -792,7 +812,7 @@ END
} elsif ($numbuttons > 1) {
$auth_update = <<"END";
// initial password specified, pick internal authentication
- if (tf==1 && nw!=0) {
+ if (tf==8 && nw!=0) {
changed_radio('int',document.studentform);
set_auth_radio_buttons('int',document.studentform);
$argreset
@@ -813,43 +833,45 @@ 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');
if (i==0 && tw!=0) { founduname=1; }
- if (i==1 && tw!=0) { foundpwd=1; }
- if (((i>=2) && (i<=6)) && tw!=0 ) { foundname=1; }
- if (i==7 && tw!=0) { foundid=1; }
- if (i==8 && tw!=0) { foundsec=1; }
+ if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
+ if (i==6 && tw!=0) { foundid=1; }
+ if (i==7 && tw!=0) { foundsec=1; }
+ if (i==8 && tw!=0) { foundpwd=1; }
if (i==9 && tw!=0) { foundemail=1; }
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) {
var nw=eval('vf.f'+tf+'.selectedIndex');
var i;
// picked the all one name field, reset the other name ones to blank
- if (tf==2 && nw!=0) {
- for (i=3;i<=6;i++) {
+ if (tf==1 && nw!=0) {
+ for (i=2;i<=5;i++) {
eval('vf.f'+i+'.selectedIndex=0;')
}
}
//picked one of the piecewise name fields, reset the all in
//one field to blank
- if ((tf>=3) && (tf<=6) && (nw!=0)) {
- eval('vf.f2.selectedIndex=0;')
+ if ((tf>=2) && (tf<=5) && (nw!=0)) {
+ eval('vf.f1.selectedIndex=0;')
}
$auth_update
}
function clearpwd(vf) {
var i;
- if (eval('vf.f1.selectedIndex')!=0) {
- eval('vf.f1.selectedIndex=0;')
+ if (eval('vf.f8.selectedIndex')!=0) {
+ eval('vf.f8.selectedIndex=0;')
}
}
ENDPICK
@@ -858,7 +880,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) =
@@ -872,9 +895,6 @@ sub print_upload_manager_footer {
$env{'form.ipwd_choice'} ne '') {
$param{'curr_authtype'} = 'int';
}
- if ($env{'form.context'} eq 'requestcrs') {
- $param{'context'} = $env{'form.context'};
- }
my $krbform = &Apache::loncommon::authform_kerberos(%param);
my $intform = &Apache::loncommon::authform_internal(%param);
my $locform = &Apache::loncommon::authform_local(%param);
@@ -887,11 +907,8 @@ sub print_upload_manager_footer {
$Str .= '
'
.&mt('Change authentication for existing users in domain "[_1]" to these settings?'
@@ -905,17 +922,12 @@ sub print_upload_manager_footer {
.'
';
} else {
$Str .= '
'."\n".
- &mt('This will not take effect if the user already exists.');
- my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($defdom);
- if ($authnum > 1) {
- $Str .= &Apache::loncommon::help_open_topic('Auth_Options');
- }
- $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);
- if ($env{'form.context'} eq 'requestcrs') {
- $Str .= '';
- }
+
my ($home_server_pick,$numlib) =
&Apache::loncommon::home_server_form_item($defdom,'lcserver',
'default','hide');
@@ -931,14 +943,14 @@ sub print_upload_manager_footer {
&Apache::lonhtmlcommon::row_closure();
}
- unless ($env{'form.context'} eq 'requestcrs') {
- $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
- .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1)
- .&Apache::lonhtmlcommon::row_closure()
- .&Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
- ."
\n"
+ .&Apache::lonhtmlcommon::row_closure();
+
if ($context eq 'domain') {
$Str .= &Apache::lonhtmlcommon::row_title(
&mt('Settings for assigning roles'))
@@ -958,22 +970,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') {
- if ($env{'form.context'} eq 'requestcrs') {
- $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default section')).
- &mt('Students can be assigned to different sections.').' '.
- &mt('Will you be using sections?').' '.
- ''.
- ' '.&mt('Yes').''.
- ' ';
- } else {
+ 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.');
- }
+ }
} else {
$Str .= &Apache::lonhtmlcommon::row_title(
&mt('Default role and/or section(s)'))
@@ -981,7 +986,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 .= '
');
}
$r->rflush();
if ($context eq 'course') {
@@ -1676,6 +1730,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') {
@@ -1761,33 +1821,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('