--- loncom/interface/loncreateuser.pm 2007/08/31 17:58:47 1.182
+++ loncom/interface/loncreateuser.pm 2012/08/14 15:45:06 1.362
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.182 2007/08/31 17:58:47 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.362 2012/08/14 15:45:06 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -33,11 +33,13 @@ package Apache::loncreateuser;
=head1 NAME
-Apache::loncreateuser - handler to create users and custom roles
+Apache::loncreateuser.pm
=head1 SYNOPSIS
-Apache::loncreateuser provides an Apache handler for creating users,
+ Handler to create users and custom roles
+
+ Provides an Apache handler for creating users,
editing their login parameters, roles, and removing roles, and
also creating and assigning custom roles.
@@ -49,13 +51,14 @@ In LON-CAPA, roles are actually collecti
Assistant", "Course Coordinator", and other such roles are really just
collection of privileges that are useful in many circumstances.
-Creating custom roles can be done by the Domain Coordinator through
-the Create User functionality. That screen will show all privileges
-that can be assigned to users. For a complete list of privileges,
-please see C.
+Custom roles can be defined by a Domain Coordinator, Course Coordinator
+or Community Coordinator via the Manage User functionality.
+The custom role editor screen will show all privileges which can be
+assigned to users. For a complete list of privileges, please see
+C.
-Custom role definitions are stored in the C file of the role
-author.
+Custom role definitions are stored in the C file of the creator
+of the role.
=cut
@@ -65,10 +68,11 @@ use Apache::lonnet;
use Apache::loncommon;
use Apache::lonlocal;
use Apache::longroup;
+use Apache::lonuserutils;
+use Apache::loncoursequeueadmin;
use LONCAPA qw(:DEFAULT :match);
my $loginscript; # piece of javascript used in two separate instances
-my $generalrule;
my $authformnop;
my $authformkrb;
my $authformint;
@@ -76,43 +80,44 @@ my $authformfsys;
my $authformloc;
sub initialize_authen_forms {
- my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
- $krbdefdom= uc($krbdefdom);
- my %param = ( formname => 'document.cu',
- kerb_def_dom => $krbdefdom
- );
-# no longer static due to configurable kerberos defaults
-# $loginscript = &Apache::loncommon::authform_header(%param);
- $generalrule = &Apache::loncommon::authform_authorwarning(%param);
+ my ($dom,$formname,$curr_authtype,$mode) = @_;
+ my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
+ my %param = ( formname => $formname,
+ kerb_def_dom => $krbdefdom,
+ kerb_def_auth => $krbdef,
+ domain => $dom,
+ );
+ my %abv_auth = &auth_abbrev();
+ if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
+ my $long_auth = $1;
+ my $curr_autharg = $2;
+ my %abv_auth = &auth_abbrev();
+ $param{'curr_authtype'} = $abv_auth{$long_auth};
+ if ($long_auth =~ /^krb(4|5)$/) {
+ $param{'curr_kerb_ver'} = $1;
+ $param{'curr_autharg'} = $curr_autharg;
+ }
+ if ($mode eq 'modifyuser') {
+ $param{'mode'} = $mode;
+ }
+ }
+ $loginscript = &Apache::loncommon::authform_header(%param);
+ $authformkrb = &Apache::loncommon::authform_kerberos(%param);
$authformnop = &Apache::loncommon::authform_nochange(%param);
-# no longer static due to configurable kerberos defaults
-# $authformkrb = &Apache::loncommon::authform_kerberos(%param);
$authformint = &Apache::loncommon::authform_internal(%param);
$authformfsys = &Apache::loncommon::authform_filesystem(%param);
$authformloc = &Apache::loncommon::authform_local(%param);
}
-
-# ======================================================= Existing Custom Roles
-
-sub my_custom_roles {
- my %returnhash=();
- my %rolehash=&Apache::lonnet::dump('roles');
- foreach my $key (keys %rolehash) {
- if ($key=~/^rolesdef\_(\w+)$/) {
- $returnhash{$1}=$1;
- }
- }
- return %returnhash;
-}
-
-# ==================================================== Figure out author access
-
-sub authorpriv {
- my ($auname,$audom)=@_;
- unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
- || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; }
- return 1;
+sub auth_abbrev {
+ my %abv_auth = (
+ krb5 => 'krb',
+ krb4 => 'krb',
+ internal => 'int',
+ localuth => 'loc',
+ unix => 'fsys',
+ );
+ return %abv_auth;
}
# ====================================================
@@ -120,11 +125,12 @@ sub authorpriv {
sub portfolio_quota {
my ($ccuname,$ccdomain) = @_;
my %lt = &Apache::lonlocal::texthash(
- 'disk' => "Disk space allocated to user's portfolio files",
- 'cuqu' => "Current quota",
- 'cust' => "Custom quota",
- 'defa' => "Default",
- 'chqu' => "Change quota",
+ 'usrt' => "User Tools",
+ 'disk' => "Disk space allocated to user's portfolio files",
+ 'cuqu' => "Current quota",
+ 'cust' => "Custom quota",
+ 'defa' => "Default",
+ 'chqu' => "Change quota",
);
my ($currquota,$quotatype,$inststatus,$defquota) =
&Apache::loncommon::get_user_quota($ccuname,$ccdomain);
@@ -139,6 +145,7 @@ sub portfolio_quota {
$custom_off = ' checked="checked" ';
my $quota_javascript = <<"END_SCRIPT";
END_SCRIPT
if ($quotatype eq 'custom') {
@@ -156,124 +164,703 @@ END_SCRIPT
$custom_off = ' ';
$showquota = $currquota;
if ($longinsttype eq '') {
- $defaultinfo = &mt('For this user, the default quota would be [_1]
- Mb.',$defquota);
+ $defaultinfo = &mt('For this user, the default quota would be [_1]'
+ .' Mb.',$defquota);
} else {
- $defaultinfo = &mt("For this user, the default quota would be [_1]
- Mb, as determined by the user's institutional
- affiliation ([_2]).",$defquota,$longinsttype);
+ $defaultinfo = &mt("For this user, the default quota would be [_1]".
+ " Mb, as determined by the user's institutional".
+ " affiliation ([_2]).",$defquota,$longinsttype);
}
} else {
if ($longinsttype eq '') {
- $defaultinfo = &mt('For this user, the default quota is [_1]
- Mb.',$defquota);
+ $defaultinfo = &mt('For this user, the default quota is [_1]'
+ .' Mb.',$defquota);
} else {
- $defaultinfo = &mt("For this user, the default quota of [_1]
- Mb, is determined by the user's institutional
- affiliation ([_2]).",$defquota,$longinsttype);
- }
- }
- my $output = $quota_javascript.
- '
'.$lt{'disk'}.'
'.
- $lt{'cuqu'}.': '.$currquota.' Mb. '.
- $defaultinfo.' '.$lt{'chqu'}.
- ': '.
- ' '.
- ' Mb';
+ $defaultinfo = &mt("For this user, the default quota of [_1]".
+ " Mb, is determined by the user's institutional".
+ " affiliation ([_2]).",$defquota,$longinsttype);
+ }
+ }
+
+ my $output = $quota_javascript."\n".
+ '
');
} else {
- $r->print(''."\n".
- ''."\n");
+ $r->print($response.'');
}
}
sub print_user_query_page {
- my ($r,$caller) = @_;
+ my ($r,$caller,$brcrum) = @_;
# FIXME - this is for a network-wide name search (similar to catalog search)
# To use frames with similar behavior to catalog/portfolio search.
# To be implemented.
@@ -419,718 +1042,796 @@ sub print_user_query_page {
}
sub print_user_modification_page {
- my ($r,$ccuname,$ccdomain,$srch,$response) = @_;
- unless (($ccuname) && ($ccdomain)) {
- &print_username_entry_form($r);
+ my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,$brcrum) = @_;
+ if (($ccuname eq '') || ($ccdomain eq '')) {
+ my $usermsg = &mt('No username and/or domain provided.');
+ $env{'form.phase'} = '';
+ &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum);
return;
}
- if ($response) {
- $response = ' '.$response
+ my ($form,$formname);
+ if ($env{'form.action'} eq 'singlestudent') {
+ $form = 'document.enrollstudent';
+ $formname = 'enrollstudent';
+ } else {
+ $form = 'document.cu';
+ $formname = 'cu';
}
- my $defdom=$env{'request.role.domain'};
-
- my ($krbdef,$krbdefdom) =
- &Apache::loncommon::get_kerberos_defaults($defdom);
-
- my %param = ( formname => 'document.cu',
- kerb_def_dom => $krbdefdom,
- kerb_def_auth => $krbdef
- );
- $loginscript = &Apache::loncommon::authform_header(%param);
- $authformkrb = &Apache::loncommon::authform_kerberos(%param);
-
- my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
- my $dc_setcourse_code = '';
- my $nondc_setsection_code = '';
-
- my %loaditem;
-
- my $groupslist;
- my %curr_groups = &Apache::longroup::coursegroups();
- if (%curr_groups) {
- $groupslist = join('","',sort(keys(%curr_groups)));
- $groupslist = '"'.$groupslist.'"';
- }
-
- if ($env{'request.role'} =~ m-^dc\./($match_domain)/$-) {
- my $dcdom = $1;
- $loaditem{'onload'} = "document.cu.coursedesc.value='';";
- my @rolevals = ('st','ta','ep','in','cc');
- my (@crsroles,@grproles);
- for (my $i=0; $i<@rolevals; $i++) {
- $crsroles[$i]=&Apache::lonnet::plaintext($rolevals[$i],'Course');
- $grproles[$i]=&Apache::lonnet::plaintext($rolevals[$i],'Group');
- }
- my $rolevalslist = join('","',@rolevals);
- my $crsrolenameslist = join('","',@crsroles);
- my $grprolenameslist = join('","',@grproles);
- my $pickcrsfirst = '<--'.&mt('Pick course first');
- my $pickgrpfirst = '<--'.&mt('Pick group first');
- $dc_setcourse_code = <<"ENDSCRIPT";
- function setCourse() {
- var course = document.cu.dccourse.value;
- if (course != "") {
- if (document.cu.dcdomain.value != document.cu.origdom.value) {
- alert("You must select a course in the current domain");
- return;
- }
- var userrole = document.cu.role.options[document.cu.role.selectedIndex].value
- var section="";
- var numsections = 0;
- var newsecs = new Array();
- for (var i=0; i 'institutional',
+ unofficial => 'non-institutional',
+ );
+ my $response;
+ if ($env{'form.origform'} eq 'crtusername') {
+ $response = ''.
+ &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
+ ''.$ccuname.'',$ccdomain).
+ ' ';
+ }
+ $response .= '
'
+ .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
+ .' '
+ .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
+ ,'','')
+ .'
';
+ $env{'form.phase'} = '';
+ &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
+ return;
+ }
+ $newuser = 1;
+ my $checkhash;
+ my $checks = { 'username' => 1 };
+ $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
+ &Apache::loncommon::user_rule_check($checkhash,$checks,
+ \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
+ if (ref($alerts{'username'}) eq 'HASH') {
+ if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
+ my $domdesc =
+ &Apache::lonnet::domain($ccdomain,'description');
+ if ($alerts{'username'}{$ccdomain}{$ccuname}) {
+ my $userchkmsg;
+ if (ref($curr_rules{$ccdomain}) eq 'HASH') {
+ $userchkmsg =
+ &Apache::loncommon::instrule_disallow_msg('username',
+ $domdesc,1).
+ &Apache::loncommon::user_rule_formats($ccdomain,
+ $domdesc,$curr_rules{$ccdomain}{'username'},
+ 'username');
}
- }
- }
- if (document.cu.newsec.value != "" && document.cu.newsec.value != null) {
- if (numsections == 0) {
- section = document.cu.newsec.value
- }
- else {
- section = section + "," + document.cu.newsec.value
- }
- newsecs = document.cu.newsec.value.split(/,/g);
- numsections = numsections + newsecs.length;
- }
- if ((userrole == 'st') && (numsections > 1)) {
- alert("In each course, each user may only have one student role at a time. You had selected "+numsections+" sections.\\nPlease modify your selections so they include no more than one section.")
- return;
- }
- for (var j=0; j 0)) {
- alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
- section = "";
- }
- var coursename = "_$dcdom"+"_"+course+"_"+userrole
- var numcourse = getIndex(document.cu.dccourse);
- if (numcourse == "-1") {
- alert("There was a problem with your course selection");
- return
- }
- else {
- document.cu.elements[numcourse].name = "act"+coursename;
- var numnewsec = getIndex(document.cu.newsec);
- if (numnewsec != "-1") {
- document.cu.elements[numnewsec].name = "sec"+coursename;
- document.cu.elements[numnewsec].value = section;
- }
- var numstart = getIndex(document.cu.start);
- if (numstart != "-1") {
- document.cu.elements[numstart].name = "start"+coursename;
- }
- var numend = getIndex(document.cu.end);
- if (numend != "-1") {
- document.cu.elements[numend].name = "end"+coursename
- }
- }
- }
- document.cu.submit();
- }
-
- function getIndex(caller) {
- for (var i=0;i 0) {
- if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) {
- sections = sections + "," + document.cu.elements[i+1].value;
- }
- }
- else {
- sections = document.cu.elements[i+1].value;
- }
- var newsecs = document.cu.elements[i+1].value;
- var numsplit;
- if (newsecs != null && newsecs != "") {
- numsplit = newsecs.split(/,/g);
- numsec = numsec + numsplit.length;
- }
-
- if ((role == 'st') && (numsec > 1)) {
- alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.")
- return;
- }
- else if (numsplit != null) {
- for (var j=0; j'.$response;
}
- my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
- $nondc_setsection_code,$groupslist);
- my ($jsback,$elements) = &crumb_utilities();
-
- $js .= "\n".
- '';
+ my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
+ my $dc_setcourse_code = '';
+ my $nondc_setsection_code = '';
+ my %loaditem;
- my $start_page =
- &Apache::loncommon::start_page('Create Users, Change User Privileges',
- $js,{'add_entries' => \%loaditem,});
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.cu)",
- text=>"User modify/custom role edit",
- faq=>282,bug=>'Instructor Interface',});
+ my $groupslist = &Apache::lonuserutils::get_groupslist();
+ my $js = &validation_javascript($context,$ccdomain,$pjump_def,
+ $groupslist,$newuser,$formname,\%loaditem);
+ my %breadcrumb_text = &singleuser_breadcrumb($crstype);
+ my $helpitem = 'Course_Change_Privileges';
+ if ($env{'form.action'} eq 'singlestudent') {
+ $helpitem = 'Course_Add_Student';
+ }
+ push (@{$brcrum},
+ {href => "javascript:backPage($form)",
+ text => $breadcrumb_text{'search'},
+ faq => 282,
+ bug => 'Instructor Interface',});
if ($env{'form.phase'} eq 'userpicked') {
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.cu,'get_user_info','select')",
- text=>"Select a user",
- faq=>282,bug=>'Instructor Interface',});
- }
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.cu,'$env{'form.phase'}','modify')",
- text=>"Set user role",
- faq=>282,bug=>'Instructor Interface',});
- my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
+ push(@{$brcrum},
+ {href => "javascript:backPage($form,'get_user_info','select')",
+ text => $breadcrumb_text{'userpicked'},
+ faq => 282,
+ bug => 'Instructor Interface',});
+ }
+ push(@{$brcrum},
+ {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
+ text => $breadcrumb_text{'modify'},
+ faq => 282,
+ bug => 'Instructor Interface',
+ help => $helpitem});
+ my $args = {'add_entries' => \%loaditem,
+ 'bread_crumbs' => $brcrum,
+ 'bread_crumbs_component' => 'User Management'};
+ if ($env{'form.popup'}) {
+ $args->{'no_nav_bar'} = 1;
+ }
+ my $start_page =
+ &Apache::loncommon::start_page('User Management',$js,$args);
my $forminfo =<<"ENDFORMINFO";
-
');
+ my @order = ('auth','quota','tools','requestauthor');
+ my %user_text;
+ my ($isadv,$isauthor) =
+ &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
+ if ((!$isauthor) &&
+ (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
+ $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
+ }
+ $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
+ if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
+ (&Apache::lonnet::allowed('mut',$ccdomain))) {
+ # Current user has quota modification privileges
+ $user_text{'quota'} = &portfolio_quota($ccuname,$ccdomain);
+ }
+ if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
+ if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
+ # Get the user's portfolio information
+ my %portq = &Apache::lonnet::get('environment',['portfolioquota'],
+ $ccdomain,$ccuname);
+ my %lt=&Apache::lonlocal::texthash(
+ 'dska' => "Disk space allocated to user's portfolio files",
+ 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
+ 'ichr' => "If a change is required, contact a domain coordinator for the domain",
+ );
+ $user_text{'quota'} = <$lt{'dska'}
+$lt{'youd'} $lt{'ichr'}: $ccdomain
+ENDNOPORTPRIV
+ }
+ }
+ if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
+ if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
+ my %lt=&Apache::lonlocal::texthash(
+ 'utav' => "User Tools Availability",
+ 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
+ 'ifch' => "If a change is required, contact a domain coordinator for the domain",
+ );
+ $user_text{'tools'} = <$lt{'utav'}
+$lt{'yodo'} $lt{'ifch'}: $ccdomain
+ENDNOTOOLSPRIV
+ }
+ }
+ my $gotdiv = 0;
+ foreach my $item (@order) {
+ if ($user_text{$item} ne '') {
+ unless ($gotdiv) {
+ $r->print('
'.
&Apache::loncommon::end_data_table_header_row());
- foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
- if ($output{$type}) {
- $r->print($output{$type}."\n");
- }
- }
- $r->print(&Apache::loncommon::end_data_table());
- }
- } # End of unless
- my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
- if ($currentauth=~/^krb(4|5):/) {
- $currentauth=~/^krb(4|5):(.*)/;
- my $krbdefdom=$2;
- my %param = ( formname => 'document.cu',
- kerb_def_dom => $krbdefdom
- );
- $loginscript = &Apache::loncommon::authform_header(%param);
- }
- # Check for a bad authentication type
- unless ($currentauth=~/^krb(4|5):/ or
- $currentauth=~/^unix:/ or
- $currentauth=~/^internal:/ or
- $currentauth=~/^localauth:/
- ) { # bad authentication scheme
- if (&Apache::lonnet::allowed('mau',$ccdomain)) {
- &initialize_authen_forms();
- my %lt=&Apache::lonlocal::texthash(
- 'err' => "ERROR",
- 'uuas' => "This user has an unrecognized authentication scheme",
- 'sldb' => "Please specify login data below",
- 'ld' => "Login Data"
- );
- $r->print(<
-
-$lt{'err'}:
-$lt{'uuas'} ($currentauth). $lt{'sldb'}.
-
$lt{'ld'}
-
$generalrule
-
$authformkrb
-
$authformint
-
$authformfsys
-
$authformloc
-ENDBADAUTH
- } else {
- # This user is not allowed to modify the user's
- # authentication scheme, so just notify them of the problem
- my %lt=&Apache::lonlocal::texthash(
- 'err' => "ERROR",
- 'uuas' => "This user has an unrecognized authentication scheme",
- 'adcs' => "Please alert a domain coordinator of this situation"
- );
- $r->print(<
- $lt{'err'}:
-$lt{'uuas'} ($currentauth). $lt{'adcs'}.
-
-ENDBADAUTH
+ foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') {
+ if ($output{$type}) {
+ $r->print($output{$type}."\n");
}
- } else { # Authentication type is valid
- my $authformcurrent='';
- my $authform_other='';
- &initialize_authen_forms();
- if ($currentauth=~/^krb(4|5):/) {
- $authformcurrent=$authformkrb;
- $authform_other="
";
- }
- $authformcurrent.=' (will override current values) ';
- if (&Apache::lonnet::allowed('mau',$ccdomain)) {
- # Current user has login modification privileges
- my %lt=&Apache::lonlocal::texthash(
- 'ccld' => "Change Current Login Data",
- 'enld' => "Enter New Login Data"
- );
- $r->print(<
-
-
$lt{'ccld'}
-
$generalrule
-
$authformnop
-
$authformcurrent
-
$lt{'enld'}
-$authform_other
-ENDOTHERAUTHS
- } else {
- if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
- my %lt=&Apache::lonlocal::texthash(
- 'ccld' => "Change Current Login Data",
- 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
- 'ifch' => "If a change is required, contact a domain coordinator for the domain",
- );
- $r->print(<
-
$lt{'ccld'}
-$lt{'yodo'} $lt{'ifch'}: $ccdomain
-ENDNOPRIV
- }
- }
- if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
- # Current user has quota modification privileges
- $r->print(&portfolio_quota($ccuname,$ccdomain));
- }
- } ## End of "check for bad authentication type" logic
- } ## End of new user/old user logic
- $r->print('
'.&mt('Add Roles').'
');
-#
-# Co-Author
-#
- if (&authorpriv($env{'user.name'},$env{'request.role.domain'}) &&
+ }
+ $r->print(&Apache::loncommon::end_data_table());
+ }
+ return;
+}
+
+sub new_coauthor_roles {
+ my ($r,$ccuname,$ccdomain) = @_;
+ my $addrolesdisplay = 0;
+ #
+ # Co-Author
+ #
+ if (&Apache::lonuserutils::authorpriv($env{'user.name'},
+ $env{'request.role.domain'}) &&
($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
# No sense in assigning co-author role to yourself
- my $cuname=$env{'user.name'};
+ $addrolesdisplay = 1;
+ my $cuname=$env{'user.name'};
my $cudom=$env{'request.role.domain'};
- my %lt=&Apache::lonlocal::texthash(
- 'cs' => "Construction Space",
- 'act' => "Activate",
+ my %lt=&Apache::lonlocal::texthash(
+ 'cs' => "Construction Space",
+ 'act' => "Activate",
'rol' => "Role",
'ext' => "Extent",
'sta' => "Start",
@@ -1139,17 +1840,17 @@ ENDNOPRIV
'caa' => "Assistant Co-Author",
'ssd' => "Set Start Date",
'sed' => "Set End Date"
- );
- $r->print('
'.
&Apache::loncommon::end_data_table_header_row();
+ my @allroles = &Apache::lonuserutils::roles_by_context('domain');
foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
- foreach my $role ('dc','li','dg','au','sc') {
+ foreach my $role (@allroles) {
+ next if ($role eq 'ad');
+ next if (($role eq 'au') && ($ccdomain ne $thisdomain));
if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
my $plrole=&Apache::lonnet::plaintext($role);
- my %lt=&Apache::lonlocal::texthash(
+ my %lt=&Apache::lonlocal::texthash(
'ssd' => "Set Start Date",
'sed' => "Set End Date"
- );
+ );
$num_domain_level ++;
- $domaintext .=
+ $domaintext .=
&Apache::loncommon::start_data_table_row().
-'
+'
'.$plrole.'
'.$thisdomain.'
@@ -1207,93 +1927,478 @@ ENDNOPRIV
"javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'
'.
&Apache::loncommon::end_data_table_row();
}
- }
+ }
}
$domaintext.= &Apache::loncommon::end_data_table();
if ($num_domain_level > 0) {
$r->print($domaintext);
+ $addrolesdisplay = 1;
}
-#
-# Course and group levels
-#
+ return $addrolesdisplay;
+}
+
+sub user_authentication {
+ my ($ccuname,$ccdomain,$formname) = @_;
+ my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
+ my $outcome;
+ # Check for a bad authentication type
+ if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
+ # bad authentication scheme
+ my %lt=&Apache::lonlocal::texthash(
+ 'err' => "ERROR",
+ 'uuas' => "This user has an unrecognized authentication scheme",
+ 'adcs' => "Please alert a domain coordinator of this situation",
+ 'sldb' => "Please specify login data below",
+ 'ld' => "Login Data"
+ );
+ if (&Apache::lonnet::allowed('mau',$ccdomain)) {
+ &initialize_authen_forms($ccdomain,$formname);
- if ($env{'request.role'} =~ m{^dc\./($match_domain)/$}) {
- $r->print(&course_level_dc($1,'Course'));
- $r->print(''."\n");
+ my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
+ $outcome = <
+//
+
+$lt{'err'}:
+$lt{'uuas'} ($currentauth). $lt{'sldb'}.
+
$lt{'ld'}
+$choices
+ENDBADAUTH
+ } else {
+ # This user is not allowed to modify the user's
+ # authentication scheme, so just notify them of the problem
+ $outcome = < $lt{'err'}:
+$lt{'uuas'} ($currentauth). $lt{'adcs'}.
+
+ENDBADAUTH
+ }
+ } else { # Authentication type is valid
+ &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
+ my ($authformcurrent,$can_modify,@authform_others) =
+ &modify_login_block($ccdomain,$currentauth);
+ if (&Apache::lonnet::allowed('mau',$ccdomain)) {
+ # Current user has login modification privileges
+ my %lt=&Apache::lonlocal::texthash (
+ 'ld' => "Login Data",
+ 'ccld' => "Change Current Login Data",
+ 'enld' => "Enter New Login Data"
+ );
+ $outcome =
+ ''."\n".
+ '
");
- }
- } else { # End of if ($env ... ) logic
- my $putresult;
- if ($quotachanged) {
- $putresult = &Apache::lonnet::put
- ('environment',\%changeHash,
- $env{'form.ccdomain'},$env{'form.ccuname'});
+ $r->print(''.&mt('Unable to successfully change environment for').' '.
+ $env{'form.ccuname'}.' '.&mt('in domain').' '.
+ $env{'form.ccdomain'}.' ');
+ }
+ } else { # End of if ($env ... ) logic
+ # They did not want to change the users name, quota, tool availability,
+ # or ability to request creation of courses,
+ # but we can still tell them what the name and quota and availabilities are
+ &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
+ \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
+ \%oldsettingstext,\%newsettings,\%newsettingstext);
+ }
+ if (@mod_disallowed) {
+ my ($rolestr,$contextname);
+ if (@longroles > 0) {
+ $rolestr = join(', ',@longroles);
+ } else {
+ $rolestr = &mt('No roles');
}
- # They did not want to change the users name but we can
- # still tell them what the name is
- my %lt=&Apache::lonlocal::texthash(
- 'mail' => "Permanent e-mail",
- 'disk' => "Disk space allocated to user's portfolio files",
- );
- $r->print(<<"END");
-
');
- &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'});
+ if ($context eq 'course') {
+ $contextname = &mt('course');
+ } elsif ($context eq 'author') {
+ $contextname = &mt('co-author');
+ }
+ $r->print(&mt('The following fields were not updated: ').'
');
+ my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
+ foreach my $field (@mod_disallowed) {
+ $r->print('
'.$fieldtitles{$field}.'
'."\n");
+ }
+ $r->print('
');
+ if (@mod_disallowed == 1) {
+ $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future [_1] roles:",$contextname));
+ } else {
+ $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles:",$contextname));
+ }
+ my $helplink = 'javascript:helpMenu('."'display'".')';
+ $r->print(''.$rolestr.' '
+ .&mt('Please contact your [_1]helpdesk[_2] for more information.'
+ ,'','')
+ .' ');
+ }
+ $r->print(''
+ .$no_forceid_alert
+ .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
+ .'');
+ }
+ if ($env{'form.action'} eq 'singlestudent') {
+ &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype);
+ $r->print('
'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
+ $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.',''.$key.''));
} else {
- $r->print('
'.&mt('[_1] may not be used as the name for a section, as it is the name of a course group.',$key));
+ $r->print(&mt('[_1] may not be used as the name for a section, as it is the name of a course group.',''.$key.''));
}
- $r->print(' '.&mt('Please go back and choose a different section name.').'
');
+
+ # Remove non alphanumeric values from section
+ $env{'form.sections'}=~s/\W//g;
+
+ # Clean out any old student roles the user has in this class.
+ &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
+ $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
+ my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
+ my $enroll_result =
+ &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
+ $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
+ $env{'form.cmiddlename'},$env{'form.clastname'},
+ $env{'form.generation'},$env{'form.sections'},$enddate,
+ $startdate,'manual',undef,$env{'request.course.id'},'',$context);
+ if ($enroll_result =~ /^ok/) {
+ $r->print(&mt('[_1] enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
+ if ($env{'form.sections'} ne '') {
+ $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
+ }
+ my ($showstart,$showend);
+ if ($startdate <= $now) {
+ $showstart = &mt('Access starts immediately');
+ } else {
+ $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
+ }
+ if ($enddate == 0) {
+ $showend = &mt('ends: no ending date');
+ } else {
+ $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
}
+ $r->print('. '.$showstart.'; '.$showend);
+ if ($startdate <= $now && !$newuser) {
+ $r->print('
');
+ if ($crstype eq 'Community') {
+ $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role will be available when the member next logs in.'));
+ } else {
+ $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.'));
+ }
+ $r->print('
');
+ }
+ } else {
+ $r->print(&mt('unable to enroll').": ".$enroll_result);
}
- $r->print(''."\n".
- ''."\n".
- '');
- $r->print(&Apache::loncommon::end_page());
+ return;
}
-sub classlist_drop {
- my ($scope,$uname,$udom,$now) = @_;
- my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
- my $cid=$cdom.'_'.$cnum;
- my $user = $uname.':'.$udom;
- if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
- my $result =
- &Apache::lonnet::cput('classlist',
- { $user => $now },
- $env{'course.'.$cid.'.domain'},
- $env{'course.'.$cid.'.num'});
- return &mt('Drop from classlist: [_1]',
- ''.$result.'').' ';
+sub get_defaultquota_text {
+ my ($settingstatus) = @_;
+ my $defquotatext;
+ if ($settingstatus eq '') {
+ $defquotatext = &mt('(default)');
+ } else {
+ my ($usertypes,$order) =
+ &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
+ if ($usertypes->{$settingstatus} eq '') {
+ $defquotatext = &mt('(default)');
+ } else {
+ $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
+ }
}
+ return $defquotatext;
}
-sub active_student_roles {
- my ($cnum,$cdom,$uname,$udom) = @_;
- my %roles =
- &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
- ['future','active'],['st']);
- return exists($roles{"$cnum:$cdom:st"});
+sub update_result_form {
+ my ($uhome) = @_;
+ my $outcome =
+ ''."\n";
+ foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
+ $outcome .= ''."\n";
+ }
+ if ($env{'form.origname'} ne '') {
+ $outcome .= ''."\n";
+ }
+ foreach my $item ('sortby','seluname','seludom') {
+ if (exists($env{'form.'.$item})) {
+ $outcome .= ''."\n";
+ }
+ }
+ if ($uhome eq 'no_host') {
+ $outcome .= ''."\n";
+ }
+ $outcome .= ''."\n".
+ ''."\n".
+ ''."\n".
+ '';
+ return $outcome;
}
sub quota_admin {
@@ -1804,12 +3719,47 @@ sub quota_admin {
my $quotachanged;
if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
# Current user has quota modification privileges
- $quotachanged = 1;
- $changeHash->{'portfolioquota'} = $setquota;
+ if (ref($changeHash) eq 'HASH') {
+ $quotachanged = 1;
+ $changeHash->{'portfolioquota'} = $setquota;
+ }
}
return $quotachanged;
}
+sub tool_admin {
+ my ($tool,$settool,$changeHash,$context) = @_;
+ my $canchange = 0;
+ if ($context eq 'requestcourses') {
+ if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
+ $canchange = 1;
+ }
+ } elsif ($context eq 'reqcrsotherdom') {
+ if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
+ $canchange = 1;
+ }
+ } elsif ($context eq 'requestauthor') {
+ if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
+ $canchange = 1;
+ }
+ } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
+ # Current user has quota modification privileges
+ $canchange = 1;
+ }
+ my $toolchanged;
+ if ($canchange) {
+ if (ref($changeHash) eq 'HASH') {
+ $toolchanged = 1;
+ if ($tool eq 'requestauthor') {
+ $changeHash->{$context} = $settool;
+ } else {
+ $changeHash->{$context.'.'.$tool} = $settool;
+ }
+ }
+ }
+ return $toolchanged;
+}
+
sub build_roles {
my ($sectionstr,$sections,$role) = @_;
my $num_sections = 0;
@@ -1846,19 +3796,30 @@ sub build_roles {
# ========================================================== Custom Role Editor
sub custom_role_editor {
- my ($r) = @_;
- my $rolename=$env{'form.rolename'};
+ my ($r,$brcrum) = @_;
+ my $action = $env{'form.customroleaction'};
+ my $rolename;
+ if ($action eq 'new') {
+ $rolename=$env{'form.newrolename'};
+ } else {
+ $rolename=$env{'form.rolename'};
+ }
- if ($rolename eq 'make new role') {
- $rolename=$env{'form.newrolename'};
+ my ($crstype,$context);
+ if ($env{'request.course.id'}) {
+ $crstype = &Apache::loncommon::course_type();
+ $context = 'course';
+ } else {
+ $context = 'domain';
+ $crstype = $env{'form.templatecrstype'};
}
$rolename=~s/[^A-Za-z0-9]//gs;
-
- if (!$rolename) {
- &print_username_entry_form($r);
+ if (!$rolename || $env{'form.phase'} eq 'pickrole') {
+ &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
return;
}
+
# ------------------------------------------------------- What can be assigned?
my %full=();
my %courselevel=();
@@ -1867,7 +3828,6 @@ sub custom_role_editor {
my $dompriv='';
my $coursepriv='';
my $body_top;
- my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
my ($rdummy,$roledef)=
&Apache::lonnet::get('roles',["rolesdef_$rolename"]);
# ------------------------------------------------------- Does this role exist?
@@ -1876,6 +3836,9 @@ sub custom_role_editor {
$body_top .= &mt('Existing Role').' "';
# ------------------------------------------------- Get current role privileges
($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
+ if ($crstype eq 'Community') {
+ $syspriv =~ s/bre\&S//;
+ }
} else {
$body_top .= &mt('New Role').' "';
$roledef='';
@@ -1915,33 +3878,93 @@ sub custom_role_editor {
my ($jsback,$elements) = &crumb_utilities();
my $button_code = "\n";
my $head_script = "\n";
- $head_script .= ''."\n";
- $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.form1,'','')",
- text=>"User modify/custom role edit",
- faq=>282,bug=>'Instructor Interface',},
- {href=>"javascript:backPage(document.form1,'','')",
- text=>"Edit custom role",
- faq=>282,bug=>'Instructor Interface',});
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
- $r->print($body_top);
+ $head_script .= "\n".$jsback."\n"
+ .'// ]]>'."\n"
+ .''."\n";
+ push (@{$brcrum},
+ {href => "javascript:backPage(document.form1,'pickrole','')",
+ text => "Pick custom role",
+ faq => 282,bug=>'Instructor Interface',},
+ {href => "javascript:backPage(document.form1,'','')",
+ text => "Edit custom role",
+ faq => 282,
+ bug => 'Instructor Interface',
+ help => 'Course_Editing_Custom_Roles'}
+ );
+ my $args = { bread_crumbs => $brcrum,
+ bread_crumbs_component => 'User Management'};
+
+ $r->print(&Apache::loncommon::start_page('Custom Role Editor',
+ $head_script,$args).
+ $body_top);
my %lt=&Apache::lonlocal::texthash(
'prv' => "Privilege",
'crl' => "Course Level",
'dml' => "Domain Level",
'ssl' => "System Level");
- $r->print('Select a Template ');
- $r->print('');
+
+ $r->print('
'.
+ &Apache::loncommon::end_data_table_row());
}
$r->print(&Apache::loncommon::end_data_table().
+ ''.
''."\n".''."\n".
''."\n".
- ''.
- &Apache::loncommon::end_page());
+ '');
}
# --------------------------------------------------------
sub make_script_template {
- my ($role) = @_;
+ my ($role,$crstype) = @_;
my %full_c=();
my %full_d=();
my %full_s=();
@@ -1990,6 +4017,7 @@ sub make_script_template {
$full_d{$priv}=1;
}
foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
+ next if (($crstype eq 'Community') && ($item eq 'bre&S'));
my ($priv,$restrict)=split(/\&/,$item);
$full_s{$priv}=1;
}
@@ -2000,34 +4028,35 @@ sub make_script_template {
my ($priv_item, $dummy) = split(/\&/,$priv);
$role_c{$priv_item} = 1;
}
+ my %role_d;
+ @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
+ foreach my $priv(@temp) {
+ my ($priv_item, $dummy) = split(/\&/,$priv);
+ $role_d{$priv_item} = 1;
+ }
+ my %role_s;
+ @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
+ foreach my $priv(@temp) {
+ my ($priv_item, $dummy) = split(/\&/,$priv);
+ $role_s{$priv_item} = 1;
+ }
foreach my $priv_item (keys(%full_c)) {
my ($priv, $dummy) = split(/\&/,$priv_item);
- if (exists($role_c{$priv})) {
+ if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
+ (exists($role_s{$priv}))) {
$return_script .= "document.form1.$priv"."_c.checked = true;\n";
} else {
$return_script .= "document.form1.$priv"."_c.checked = false;\n";
}
}
- my %role_d;
- @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
- foreach my $priv(@temp) {
- my ($priv_item, $dummy) = split(/\&/,$priv);
- $role_d{$priv_item} = 1;
- }
foreach my $priv_item (keys(%full_d)) {
my ($priv, $dummy) = split(/\&/,$priv_item);
- if (exists($role_d{$priv})) {
+ if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
$return_script .= "document.form1.$priv"."_d.checked = true;\n";
} else {
$return_script .= "document.form1.$priv"."_d.checked = false;\n";
}
}
- my %role_s;
- @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
- foreach my $priv(@temp) {
- my ($priv_item, $dummy) = split(/\&/,$priv);
- $role_s{$priv_item} = 1;
- }
foreach my $priv_item (keys(%full_s)) {
my ($priv, $dummy) = split(/\&/,$priv_item);
if (exists($role_s{$priv})) {
@@ -2041,52 +4070,57 @@ sub make_script_template {
}
# ----------------------------------------------------------
sub make_button_code {
- my ($role) = @_;
- my $label = &Apache::lonnet::plaintext($role);
- my $button_code = '';
+ my ($role,$crstype) = @_;
+ my $label = &Apache::lonnet::plaintext($role,$crstype);
+ my $button_code = '';
return ($button_code);
}
# ---------------------------------------------------------- Call to definerole
sub set_custom_role {
- my ($r) = @_;
-
+ my ($r,$context,$brcrum) = @_;
my $rolename=$env{'form.rolename'};
-
$rolename=~s/[^A-Za-z0-9]//gs;
-
if (!$rolename) {
- &print_username_entry_form($r);
+ &custom_role_editor($r,$brcrum);
return;
}
-
my ($jsback,$elements) = &crumb_utilities();
- my $jscript = '';
-
- $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.customresult,'','')",
- text=>"User modify/custom role edit",
- faq=>282,bug=>'Instructor Interface',},
- {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
- text=>"Edit custom role",
- faq=>282,bug=>'Instructor Interface',},
- {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
- text=>"Result",
- faq=>282,bug=>'Instructor Interface',});
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
+ my $jscript = ''."\n";
+ push(@{$brcrum},
+ {href => "javascript:backPage(document.customresult,'pickrole','')",
+ text => "Pick custom role",
+ faq => 282,
+ bug => 'Instructor Interface',},
+ {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
+ text => "Edit custom role",
+ faq => 282,
+ bug => 'Instructor Interface',},
+ {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
+ text => "Result",
+ faq => 282,
+ bug => 'Instructor Interface',
+ help => 'Course_Editing_Custom_Roles'},
+ );
+ my $args = { bread_crumbs => $brcrum,
+ bread_crumbs_component => 'User Management'};
+ $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
my ($rdummy,$roledef)=
&Apache::lonnet::get('roles',["rolesdef_$rolename"]);
# ------------------------------------------------------- Does this role exist?
- $r->print('
');
+ $r->print('
');
if (($rdummy ne 'con_lost') && ($roledef ne '')) {
$r->print(&mt('Existing Role').' "');
} else {
$r->print(&mt('New Role').' "');
$roledef='';
}
- $r->print($rolename.'"
');
+ $r->print($rolename.'"');
# ------------------------------------------------------- What can be assigned?
my $sysrole='';
my $domrole='';
@@ -2126,97 +4160,1635 @@ sub set_custom_role {
$url,
$env{'user.domain'},
$env{'user.name'},
- $rolename));
+ $rolename,undef,undef,undef,$context));
}
- $r->print('