--- loncom/interface/loncreateuser.pm 2007/12/05 17:40:29 1.201
+++ loncom/interface/loncreateuser.pm 2023/11/04 00:06:00 1.472
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.201 2007/12/05 17:40:29 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.472 2023/11/04 00:06:00 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
@@ -66,7 +69,10 @@ use Apache::loncommon;
use Apache::lonlocal;
use Apache::longroup;
use Apache::lonuserutils;
+use Apache::loncoursequeueadmin;
+use Apache::lonviewcoauthors;
use LONCAPA qw(:DEFAULT :match);
+use HTML::Entities;
my $loginscript; # piece of javascript used in two separate instances
my $authformnop;
@@ -74,226 +80,1096 @@ my $authformkrb;
my $authformint;
my $authformfsys;
my $authformloc;
+my $authformlti;
sub initialize_authen_forms {
- my ($dom,$curr_authtype) = @_;
- my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
- $krbdefdom= uc($krbdefdom);
- my %param = ( formname => 'document.cu',
+ my ($dom,$formname,$curr_authtype,$mode,$readonly) = @_;
+ 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):$/) {
+ if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix|lti):(.*)$/) {
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;
}
}
-# no longer static due to configurable kerberos defaults
-# $loginscript = &Apache::loncommon::authform_header(%param);
+ if ($readonly) {
+ $param{'readonly'} = 1;
+ }
+ $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);
+ $authformlti = &Apache::loncommon::authform_lti(%param);
}
sub auth_abbrev {
my %abv_auth = (
- krb4 => 'krb',
- internal => 'int',
- localuth => 'loc',
- unix => 'fsys',
+ krb5 => 'krb',
+ krb4 => 'krb',
+ internal => 'int',
+ localauth => 'loc',
+ unix => 'fsys',
+ lti => 'lti',
);
return %abv_auth;
}
-# ==================================================== 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 portfolio_quota {
- my ($ccuname,$ccdomain) = @_;
+sub user_quotas {
+ my ($ccuname,$ccdomain,$name) = @_;
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",
+ 'cust' => "Custom quota",
+ 'chqu' => "Change quota",
);
- my ($currquota,$quotatype,$inststatus,$defquota) =
- &Apache::loncommon::get_user_quota($ccuname,$ccdomain);
+ my ($output,$longinsttype);
my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
- my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo);
- if ($inststatus ne '') {
- if ($usertypes->{$inststatus} ne '') {
- $longinsttype = $usertypes->{$inststatus};
+ my %titles = &Apache::lonlocal::texthash (
+ portfolio => "Disk space allocated to user's portfolio files",
+ author => "Disk space allocated to user's Authoring Space",
+ );
+ my ($currquota,$quotatype,$inststatus,$defquota) =
+ &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
+ if ($longinsttype eq '') {
+ if ($inststatus ne '') {
+ if ($usertypes->{$inststatus} ne '') {
+ $longinsttype = $usertypes->{$inststatus};
+ }
}
}
+ my ($showquota,$custom_on,$custom_off,$defaultinfo,$colspan);
$custom_on = ' ';
$custom_off = ' checked="checked" ';
- my $quota_javascript = <<"END_SCRIPT";
+ $colspan = ' colspan="2"';
+ if ($quotatype eq 'custom') {
+ $custom_on = $custom_off;
+ $custom_off = ' ';
+ $showquota = $currquota;
+ if ($longinsttype eq '') {
+ $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,[_2]as determined by the user's institutional".
+ " affiliation ([_3]).",$defquota,' ',$longinsttype);
+ }
+ } else {
+ if ($longinsttype eq '') {
+ $defaultinfo = &mt('For this user, the default quota is [_1]'
+ .' MB.',$defquota);
+ } else {
+ $defaultinfo = &mt("For this user, the default quota of [_1]".
+ " MB,[_2]is determined by the user's institutional".
+ " affiliation ([_3]).",$defquota,' '.$longinsttype);
+ }
+ }
+
+ if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
+ $output .= '
');
} 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.
@@ -440,17 +1373,65 @@ sub print_user_query_page {
}
sub print_user_modification_page {
- my ($r,$ccuname,$ccdomain,$srch,$response,$context) = @_;
+ my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
+ $brcrum,$showcredits) = @_;
if (($ccuname eq '') || ($ccdomain eq '')) {
- my $usermsg = &mt('No username and/or domain provided.');
- &print_username_entry_form($r,$usermsg);
+ my $usermsg = &mt('No username and/or domain provided.');
+ $env{'form.phase'} = '';
+ &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
+ $permission);
return;
}
+ my ($form,$formname);
+ if ($env{'form.action'} eq 'singlestudent') {
+ $form = 'document.enrollstudent';
+ $formname = 'enrollstudent';
+ } else {
+ $form = 'document.cu';
+ $formname = 'cu';
+ }
my %abv_auth = &auth_abbrev();
- my ($curr_authtype,%rulematch,%inst_results,$curr_kerb_ver,$newuser,
- %alerts,%curr_rules,%got_rules);
+ my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
if ($uhome eq 'no_host') {
+ my $usertype;
+ my ($rules,$ruleorder) =
+ &Apache::lonnet::inst_userrules($ccdomain,'username');
+ $usertype =
+ &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
+ \%curr_rules,\%got_rules);
+ my $cancreate =
+ &Apache::lonuserutils::can_create_user($ccdomain,$context,
+ $usertype);
+ if (!$cancreate) {
+ my $helplink = 'javascript:helpMenu('."'display'".')';
+ my %usertypetext = (
+ official => '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.")
+ .' ';
+ if ($context eq 'domain') {
+ $response .= &mt('Please contact a [_1] for assistance.',
+ &Apache::lonnet::plaintext('dc'));
+ } else {
+ $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
+ ,'','');
+ }
+ $response .= '
';
+ $env{'form.phase'} = '';
+ &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
+ $permission);
+ return;
+ }
$newuser = 1;
my $checkhash;
my $checks = { 'username' => 1 };
@@ -471,202 +1452,95 @@ sub print_user_modification_page {
$domdesc,$curr_rules{$ccdomain}{'username'},
'username');
}
- &print_username_entry_form($r,$userchkmsg);
+ $env{'form.phase'} = '';
+ &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
+ $permission);
return;
- }
+ }
}
}
} else {
$newuser = 0;
- my $currentauth =
- &Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
- if ($currentauth =~ /^(krb4|krb5|unix|internal|localauth):/) {
- $curr_authtype = $abv_auth{$1};
- if ($currentauth =~ /^krb(4|5)/) {
- $curr_kerb_ver = $1;
- }
- }
}
if ($response) {
- $response = ' '.$response
+ $response = ' '.$response;
}
- 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,
- curr_authtype => $curr_authtype,
- curr_kerb_ver => $curr_kerb_ver,
- domain => $ccdomain,
- );
- $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 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();
- }
+ my $groupslist = &Apache::lonuserutils::get_groupslist();
- function getIndex(caller) {
- for (var i=0;i "javascript:backPage($form)",
+ text => $breadcrumb_text{'search'},
+ faq => 282,
+ bug => 'Instructor Interface',});
+ if ($env{'form.phase'} eq 'userpicked') {
+ 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;
+ }
+ if (($context eq 'domain') && ($env{'request.role.domain'} eq $ccdomain)) {
+ my @toggles;
+ if (&Apache::lonnet::allowed('cau',$ccdomain)) {
+ my ($isadv,$isauthor) =
+ &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
+ unless ($isauthor) {
+ push(@toggles,'requestauthor');
+ }
+ push(@toggles,('webdav','editors'));
+ }
+ if (&Apache::lonnet::allowed('mut',$ccdomain)) {
+ push(@toggles,('aboutme','blog','portfolio','portaccess','timezone'));
+ }
+ if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
+ push(@toggles,('official','unofficial','community','textbook','placement','lti'));
+ }
+ if (@toggles) {
+ my $onload;
+ foreach my $item (@toggles) {
+ $onload .= "toggleCustom(document.cu,'customtext_$item','custom$item');";
+ }
+ $args->{'add_entries'} = {
+ 'onload' => $onload,
+ };
}
- return -1;
}
-ENDSCRIPT
- } else {
- $nondc_setsection_code =
- &Apache::lonuserutils::setsections_javascript('cu',$groupslist);
- }
- my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
- $nondc_setsection_code,$groupslist);
-
- my ($jsback,$elements) = &crumb_utilities();
- my $javascript_validations;
- if ((&Apache::lonnet::allowed('mau',$ccdomain)) || ($uhome eq 'no_host')) {
- my ($krbdef,$krbdefdom) =
- &Apache::loncommon::get_kerberos_defaults($ccdomain);
- $javascript_validations =
- &Apache::lonuserutils::javascript_validations('auth',$krbdefdom,undef,
- undef,$ccdomain);
- }
- $js .= "\n".
- '';
- my $start_page =
- &Apache::loncommon::start_page('User Management',
- $js,{'add_entries' => \%loaditem,});
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.cu)",
- text=>"Create/modify user",
- 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');
+ my $start_page =
+ &Apache::loncommon::start_page('User Management',$js,$args);
my $forminfo =<<"ENDFORMINFO";
-
');
+ if ($need_quota_js) {
+ $r->print(&user_quota_js());
+ }
+ return;
+}
+
+sub singleuser_breadcrumb {
+ my ($crstype,$context,$domain) = @_;
+ my %breadcrumb_text;
+ if ($env{'form.action'} eq 'singlestudent') {
+ if ($crstype eq 'Community') {
+ $breadcrumb_text{'search'} = 'Enroll a member';
+ } else {
+ $breadcrumb_text{'search'} = 'Enroll a student';
+ }
+ $breadcrumb_text{'userpicked'} = 'Select a user';
+ $breadcrumb_text{'modify'} = 'Set section/dates';
+ } elsif ($env{'form.action'} eq 'accesslogs') {
+ $breadcrumb_text{'search'} = 'View access logs for a user';
+ $breadcrumb_text{'userpicked'} = 'Select a user';
+ $breadcrumb_text{'activity'} = 'Activity';
+ } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
+ (!&Apache::lonnet::allowed('mau',$domain))) {
+ $breadcrumb_text{'search'} = "View user's roles";
+ $breadcrumb_text{'userpicked'} = 'Select a user';
+ $breadcrumb_text{'modify'} = 'User roles';
+ } else {
+ $breadcrumb_text{'search'} = 'Create/modify a user';
+ $breadcrumb_text{'userpicked'} = 'Select a user';
+ $breadcrumb_text{'modify'} = 'Set user role';
+ }
+ return %breadcrumb_text;
+}
+
+sub date_sections_select {
+ my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
+ $showcredits) = @_;
+ my $credits;
+ if ($showcredits) {
+ my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
+ $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
+ if ($credits eq '') {
+ $credits = $defaultcredits;
+ }
+ }
+ my $cid = $env{'request.course.id'};
+ my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
+ my $date_table = '
'.&mt('Starting and Ending Dates').'
'."\n".
+ &Apache::lonuserutils::date_setting_table(undef,undef,$context,
+ undef,$formname,$permission);
+ my $rowtitle = 'Section';
+ my $secbox = '
'.&mt('Section and Credits').'
'."\n".
+ &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
+ $permission,$context,'',$crstype,
+ $showcredits,$credits);
+ my $output = $date_table.$secbox;
+ return $output;
+}
+
+sub validation_javascript {
+ my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
+ $loaditem,$permission) = @_;
+ my $dc_setcourse_code = '';
+ my $nondc_setsection_code = '';
+ if ($context eq 'domain') {
+ if ((ref($permission) eq 'HASH') && ($permission->{'cusr'})) {
+ my $dcdom = $env{'request.role.domain'};
+ $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
+ $dc_setcourse_code =
+ &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
+ }
+ } else {
+ my $checkauth;
+ if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
+ $checkauth = 1;
+ }
+ if ($context eq 'course') {
+ $nondc_setsection_code =
+ &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
+ undef,$checkauth,
+ $crstype);
+ }
+ if ($checkauth) {
+ $nondc_setsection_code .=
+ &Apache::lonuserutils::verify_authen($formname,$context);
+ }
+ }
+ my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
+ $nondc_setsection_code,$groupslist);
+ my ($jsback,$elements) = &crumb_utilities();
+ $js .= "\n".
+ ''."\n";
+ return $js;
+}
+
+sub display_existing_roles {
+ my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
+ $showcredits,$statuses) = @_;
+ my $now=time;
+ my $showall = 1;
+ my ($showexpired,$showactive);
+ if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
+ $showall = 0;
+ if (grep(/^expired$/,@{$statuses})) {
+ $showexpired = 1;
+ }
+ if (grep(/^active$/,@{$statuses})) {
+ $showactive = 1;
}
- if ($user_auth_text ne '') {
- $r->print('
'.$user_auth_text);
- if ($user_quota_text ne '') {
- $r->print($user_quota_text);
- }
- $r->print('
'."\n".
- &Apache::loncommon::end_data_table_row()."\n".
- &Apache::loncommon::end_data_table());
+ &Apache::loncommon::end_data_table_row()."\n".
+ &Apache::loncommon::end_data_table());
} elsif ($env{'request.role'} =~ /^au\./) {
- if (!(&authorpriv($env{'user.name'},$env{'request.role.domain'}))) {
+ if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
+ $env{'request.role.domain'}))) {
+ $r->print(''.
+ &mt('You do not have privileges to assign co-author roles.').
+ '');
+ } elsif (($env{'user.name'} eq $ccuname) &&
+ ($env{'user.domain'} eq $ccdomain)) {
+ $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Authoring Space is not permitted'));
+ }
+ } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
+ if (!(&Apache::lonuserutils::coauthorpriv($2,$1))) {
$r->print(''.
&mt('You do not have privileges to assign co-author roles.').
'');
- } elsif (($env{'user.name'} eq $ccuname) &&
+ } elsif (($env{'user.name'} eq $ccuname) &&
($env{'user.domain'} eq $ccdomain)) {
- $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));
+ $r->print(&mt('Assigning yourself a co-author or assistant co-author role in an author area in Authoring Space in which you already have a co-author role is not permitted'));
+ } elsif (($cudom eq $ccdomain) && ($cuname eq $ccuname)) {
+ $r->print(&mt("Assigning a co-author or assistant co-author role to an Authoring Space's author is not permitted"));
}
}
-#
-# Domain level
-#
+ return $addrolesdisplay;;
+}
+
+sub new_domain_roles {
+ my ($r,$ccdomain) = @_;
+ my $addrolesdisplay = 0;
+ #
+ # Domain level
+ #
my $num_domain_level = 0;
- my $domaintext =
+ my $domaintext =
'
';
+ }
return $output;
}
+sub selfcreate_canmodify {
+ my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
+ if (ref($inst_results) eq 'HASH') {
+ my @inststatuses = &get_inststatuses($inst_results);
+ if (@inststatuses == 0) {
+ @inststatuses = ('default');
+ }
+ $rolesarray = \@inststatuses;
+ }
+ my %canmodify =
+ &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
+ $rolesarray);
+ return %canmodify;
+}
+
+sub get_inststatuses {
+ my ($insthashref) = @_;
+ my @inststatuses = ();
+ if (ref($insthashref) eq 'HASH') {
+ if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
+ @inststatuses = @{$insthashref->{'inststatus'}};
+ }
+ }
+ return @inststatuses;
+}
+
# ================================================================= Phase Three
sub update_user_data {
- my ($r) = @_;
+ my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
$env{'form.ccdomain'});
# Error messages
@@ -1398,39 +3096,60 @@ sub update_user_data {
my $end = '
';
my $rtnlink = ''.
- &mt('Return to previous page').''.&Apache::loncommon::end_page();
+ &mt('Return to previous page').''.
+ &Apache::loncommon::end_page();
+ my $now = time;
my $title;
if (exists($env{'form.makeuser'})) {
$title='Set Privileges for New User';
} else {
$title='Modify User Privileges';
}
-
+ my $newuser = 0;
my ($jsback,$elements) = &crumb_utilities();
my $jscript = ''."\n";
-
- $r->print(&Apache::loncommon::start_page($title,$jscript));
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.userupdate)",
- text=>"Create/modify user",
- faq=>282,bug=>'Instructor Interface',});
+ '// '."\n".
+ ''."\n";
+ my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
+ push (@{$brcrum},
+ {href => "javascript:backPage(document.userupdate)",
+ text => $breadcrumb_text{'search'},
+ faq => 282,
+ bug => 'Instructor Interface',}
+ );
if ($env{'form.prevphase'} eq 'userpicked') {
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')",
- text=>"Select a user",
- faq=>282,bug=>'Instructor Interface',});
- }
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
- text=>"Set user role",
- faq=>282,bug=>'Instructor Interface',},
- {href=>"/adm/createuser",
- text=>"Result",
- faq=>282,bug=>'Instructor Interface',});
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
-
- my %disallowed;
+ push(@{$brcrum},
+ {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
+ text => $breadcrumb_text{'userpicked'},
+ faq => 282,
+ bug => 'Instructor Interface',});
+ }
+ my $helpitem = 'Course_Change_Privileges';
+ if ($env{'form.action'} eq 'singlestudent') {
+ $helpitem = 'Course_Add_Student';
+ } elsif ($context eq 'author') {
+ $helpitem = 'Author_Change_Privileges';
+ } elsif ($context eq 'domain') {
+ $helpitem = 'Domain_Change_Privileges';
+ }
+ push(@{$brcrum},
+ {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
+ text => $breadcrumb_text{'modify'},
+ faq => 282,
+ bug => 'Instructor Interface',},
+ {href => "/adm/createuser",
+ text => "Result",
+ faq => 282,
+ bug => 'Instructor Interface',
+ help => $helpitem});
+ my $args = {bread_crumbs => $brcrum,
+ bread_crumbs_component => 'User Management'};
+ if ($env{'form.popup'}) {
+ $args->{'no_nav_bar'} = 1;
+ }
+ $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
$r->print(&update_result_form($uhome));
# Check Inputs
if (! $env{'form.ccuname'} ) {
@@ -1439,8 +3158,8 @@ sub update_user_data {
}
if ( $env{'form.ccuname'} ne
&LONCAPA::clean_username($env{'form.ccuname'}) ) {
- $r->print($error.&mt('Invalid login name').'. '.
- &mt('Only letters, numbers, periods, dashes, @, and underscores are valid').'.'.
+ $r->print($error.&mt('Invalid login name.').' '.
+ &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
$end.$rtnlink);
return;
}
@@ -1450,17 +3169,23 @@ sub update_user_data {
}
if ( $env{'form.ccdomain'} ne
&LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
- $r->print($error.&mt ('Invalid domain name').'. '.
- &mt('Only letters, numbers, periods, dashes, and underscores are valid').'.'.
+ $r->print($error.&mt('Invalid domain name.').' '.
+ &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
$end.$rtnlink);
return;
}
+ if ($uhome eq 'no_host') {
+ $newuser = 1;
+ }
if (! exists($env{'form.makeuser'})) {
# Modifying an existing user, so check the validity of the name
if ($uhome eq 'no_host') {
- $r->print($error.&mt('Unable to determine home server for ').
- $env{'form.ccuname'}.&mt(' in domain ').
- $env{'form.ccdomain'}.'.');
+ $r->print(
+ $error
+ .'
'
+ .&mt('Unable to determine home server for [_1] in domain [_2].',
+ '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
+ .'
');
return;
}
}
@@ -1481,6 +3206,9 @@ sub update_user_data {
$amode='localauth';
$genpwd=$env{'form.locarg'};
$genpwd=" " if (!$genpwd);
+ } elsif ($env{'form.login'} eq 'lti') {
+ $amode='lti';
+ $genpwd=" ";
} elsif (($env{'form.login'} eq 'nochange') ||
($env{'form.login'} eq '' )) {
# There is no need to tell the user we did not change what they
@@ -1488,14 +3216,26 @@ sub update_user_data {
# If they are creating a new user but have not specified login
# information this will be caught below.
} else {
- $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
- return;
+ $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
+ return;
}
-
$r->print('
'.&mt('User [_1] in domain [_2]',
- $env{'form.ccuname'}, $env{'form.ccdomain'}).'
');
+ $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
+ $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'');
+ my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
+
my (%alerts,%rulematch,%inst_results,%curr_rules);
+ my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
+ my @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
+ my @requestcourses = ('official','unofficial','community','textbook','placement','lti');
+ my @requestauthor = ('requestauthor');
+ my @authordefaults = ('webdav','editors');
+ my ($othertitle,$usertypes,$types) =
+ &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
+ my %canmodify_status =
+ &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
+ ['inststatus']);
if ($env{'form.makeuser'}) {
$r->print('
'.&mt('Creating new account.').'
');
# Check for the authentication mode and password
@@ -1519,7 +3259,7 @@ sub update_user_data {
my %checkhash;
my %checks = ('id' => 1);
%{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
- 'newuser' => 1,
+ 'newuser' => $newuser,
'id' => $env{'form.cid'},
);
if ($env{'form.cid'} ne '') {
@@ -1545,6 +3285,7 @@ sub update_user_data {
}
}
}
+ &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
# Call modifyuser
my $result = &Apache::lonnet::modifyuser
($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
@@ -1553,10 +3294,95 @@ sub update_user_data {
$env{'form.cgeneration'},undef,$desiredhost,
$env{'form.cpermanentemail'});
$r->print(&mt('Generating user').': '.$result);
- my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
+ $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
$env{'form.ccdomain'});
- $r->print(' '.&mt('Home server').': '.$home.' '.
- &Apache::lonnet::hostname($home));
+ my (%changeHash,%newcustom,%changed,%changedinfo);
+ if ($uhome ne 'no_host') {
+ if ($context eq 'domain') {
+ foreach my $name ('portfolio','author') {
+ if ($env{'form.custom_'.$name.'quota'} == 1) {
+ if ($env{'form.'.$name.'quota'} eq '') {
+ $newcustom{$name.'quota'} = 0;
+ } else {
+ $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
+ $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
+ }
+ if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
+ $changed{$name.'quota'} = 1;
+ }
+ }
+ }
+ foreach my $item (@usertools) {
+ if ($env{'form.custom'.$item} == 1) {
+ $newcustom{$item} = $env{'form.tools_'.$item};
+ $changed{$item} = &tool_admin($item,$newcustom{$item},
+ \%changeHash,'tools');
+ }
+ }
+ foreach my $item (@requestcourses) {
+ if ($env{'form.custom'.$item} == 1) {
+ $newcustom{$item} = $env{'form.crsreq_'.$item};
+ if ($env{'form.crsreq_'.$item} eq 'autolimit') {
+ $newcustom{$item} .= '=';
+ $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
+ if ($env{'form.crsreq_'.$item.'_limit'}) {
+ $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
+ }
+ }
+ $changed{$item} = &tool_admin($item,$newcustom{$item},
+ \%changeHash,'requestcourses');
+ }
+ }
+ if ($env{'form.customrequestauthor'} == 1) {
+ $newcustom{'requestauthor'} = $env{'form.requestauthor'};
+ $changed{'requestauthor'} = &tool_admin('requestauthor',
+ $newcustom{'requestauthor'},
+ \%changeHash,'requestauthor');
+ }
+ if ($env{'form.customeditors'} == 1) {
+ my @editors;
+ my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
+ if (@posseditors) {
+ foreach my $editor (@posseditors) {
+ if (grep(/^\Q$editor\E$/,@posseditors)) {
+ unless (grep(/^\Q$editor\E$/,@editors)) {
+ push(@editors,$editor);
+ }
+ }
+ }
+ }
+ if (@editors) {
+ @editors = sort(@editors);
+ $changed{'editors'} = &tool_admin('editors',join(',',@editors),
+ \%changeHash,'authordefaults');
+ }
+ }
+ if ($env{'form.customwebdav'} == 1) {
+ $newcustom{'webdav'} = $env{'form.authordefaults_webdav'};
+ $changed{'webdav'} = &tool_admin('webdav',$newcustom{'webdav'},
+ \%changeHash,'authordefaults');
+ }
+ }
+ if ($canmodify_status{'inststatus'}) {
+ if (exists($env{'form.inststatus'})) {
+ my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
+ if (@inststatuses > 0) {
+ $changeHash{'inststatus'} = join(',',@inststatuses);
+ $changed{'inststatus'} = $changeHash{'inststatus'};
+ }
+ }
+ }
+ if (keys(%changed)) {
+ foreach my $item (@userinfo) {
+ $changeHash{$item} = $env{'form.c'.$item};
+ }
+ my $chgresult =
+ &Apache::lonnet::put('environment',\%changeHash,
+ $env{'form.ccdomain'},$env{'form.ccuname'});
+ }
+ }
+ $r->print(' '.&mt('Home Server').': '.$uhome.' '.
+ &Apache::lonnet::hostname($uhome));
} elsif (($env{'form.login'} ne 'nochange') &&
($env{'form.login'} ne '' )) {
# Modify user privileges
@@ -1564,44 +3390,164 @@ sub update_user_data {
$r->print($error.'Invalid login mode or password'.$end.$rtnlink);
return;
}
- # Only allow authentification modification if the person has authority
+ # Only allow authentication modification if the person has authority
if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
$r->print('Modifying authentication: '.
&Apache::lonnet::modifyuserauth(
$env{'form.ccdomain'},$env{'form.ccuname'},
$amode,$genpwd));
- $r->print(' '.&mt('Home server').': '.&Apache::lonnet::homeserver
+ $r->print(' '.&mt('Home Server').': '.&Apache::lonnet::homeserver
($env{'form.ccuname'},$env{'form.ccdomain'}));
} else {
# Okay, this is a non-fatal error.
- $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
+ $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
}
+ } elsif (($env{'form.intarg'} ne '') &&
+ (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
+ (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
+ $r->print('Modifying authentication: '.
+ &Apache::lonnet::modifyuserauth(
+ $env{'form.ccdomain'},$env{'form.ccuname'},
+ 'internal',$env{'form.intarg'}));
}
+ $r->rflush(); # Finish display of header before time consuming actions start
+ &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
##
+ my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
+ if ($context eq 'course') {
+ ($cnum,$cdom) =
+ &Apache::lonuserutils::get_course_identity();
+ $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
+ if ($showcredits) {
+ $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
+ }
+ }
if (! $env{'form.makeuser'} ) {
# Check for need to change
my %userenv = &Apache::lonnet::get
('environment',['firstname','middlename','lastname','generation',
- 'id','permanentemail','portfolioquota','inststatus'],
+ 'id','permanentemail','portfolioquota','authorquota','inststatus',
+ 'tools.aboutme','tools.blog','tools.webdav',
+ 'tools.portfolio','tools.timezone','tools.portaccess',
+ 'authormanagers','authoreditors','requestauthor',
+ 'requestcourses.official','requestcourses.unofficial',
+ 'requestcourses.community','requestcourses.textbook',
+ 'requestcourses.placement','requestcourses.lti',
+ 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
+ 'reqcrsotherdom.community','reqcrsotherdom.textbook',
+ 'reqcrsotherdom.placement','domcoord.author'],
$env{'form.ccdomain'},$env{'form.ccuname'});
my ($tmp) = keys(%userenv);
if ($tmp =~ /^(con_lost|error)/i) {
%userenv = ();
}
- # Check to see if we need to change user information
- foreach my $item ('firstname','middlename','lastname','generation','permanentemail','id') {
+ unless (($userenv{'domcoord.author'} eq 'blocked') &&
+ (($env{'user.name'} ne $env{'form.ccuname'}) ||
+ ($env{'user.domain'} ne $env{'form.ccdomain'}))) {
+ push(@authordefaults,'managers');
+ }
+ my $no_forceid_alert;
+ # Check to see if user information can be changed
+ my %domconfig =
+ &Apache::lonnet::get_dom('configuration',['usermodification'],
+ $env{'form.ccdomain'});
+ my @statuses = ('active','future');
+ my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
+ my ($auname,$audom);
+ if ($context eq 'author') {
+ $auname = $env{'user.name'};
+ $audom = $env{'user.domain'};
+ }
+ foreach my $item (keys(%roles)) {
+ my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
+ if ($context eq 'course') {
+ if ($cnum ne '' && $cdom ne '') {
+ if ($rolenum eq $cnum && $roledom eq $cdom) {
+ if (!grep(/^\Q$role\E$/,@userroles)) {
+ push(@userroles,$role);
+ }
+ }
+ }
+ } elsif ($context eq 'author') {
+ if ($rolenum eq $auname && $roledom eq $audom) {
+ if (!grep(/^\Q$role\E$/,@userroles)) {
+ push(@userroles,$role);
+ }
+ }
+ }
+ }
+ if ($env{'form.action'} eq 'singlestudent') {
+ if (!grep(/^st$/,@userroles)) {
+ push(@userroles,'st');
+ }
+ } else {
+ # Check for course or co-author roles being activated or re-enabled
+ if ($context eq 'author' || $context eq 'course') {
+ foreach my $key (keys(%env)) {
+ if ($context eq 'author') {
+ if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
+ if (!grep(/^\Q$1\E$/,@userroles)) {
+ push(@userroles,$1);
+ }
+ } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
+ if (!grep(/^\Q$1\E$/,@userroles)) {
+ push(@userroles,$1);
+ }
+ }
+ } elsif ($context eq 'course') {
+ if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
+ if (!grep(/^\Q$1\E$/,@userroles)) {
+ push(@userroles,$1);
+ }
+ } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
+ if (!grep(/^\Q$1\E$/,@userroles)) {
+ push(@userroles,$1);
+ }
+ }
+ }
+ }
+ }
+ }
+ #Check to see if we can change personal data for the user
+ my (@mod_disallowed,@longroles);
+ foreach my $role (@userroles) {
+ if ($role eq 'cr') {
+ push(@longroles,'Custom');
+ } else {
+ push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
+ }
+ }
+ my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
+ foreach my $item (@userinfo) {
# Strip leading and trailing whitespace
- $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
+ $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
+ if (!$canmodify{$item}) {
+ if (defined($env{'form.c'.$item})) {
+ if ($env{'form.c'.$item} ne $userenv{$item}) {
+ push(@mod_disallowed,$item);
+ }
+ }
+ $env{'form.c'.$item} = $userenv{$item};
+ }
}
- # Check to see if we can change the ID/student number
+ # Check to see if we can change the Student/Employee ID
my $forceid = $env{'form.forceid'};
my $recurseid = $env{'form.recurseid'};
- my $newuser = 0;
- my $disallowed_id = 0;
my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
- if (!$forceid) {
- $env{'form.cid'} = $userenv{'id'};
- } elsif ($env{'form.cid'} ne $userenv{'id'}) {
+ my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
+ $env{'form.ccuname'});
+ if (($uidhash{$env{'form.ccuname'}}) &&
+ ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
+ (!$forceid)) {
+ if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
+ $env{'form.cid'} = $userenv{'id'};
+ $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
+ .' '
+ .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
+ .' '."\n";
+ }
+ }
+ if ($env{'form.cid'} ne $userenv{'id'}) {
my $checkhash;
my $checks = { 'id' => 1 };
$checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
@@ -1612,145 +3558,330 @@ sub update_user_data {
\%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
if (ref($alerts{'id'}) eq 'HASH') {
if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
- $disallowed_id = 1;
+ $env{'form.cid'} = $userenv{'id'};
}
}
}
- my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota,
- $inststatus,$isdefault,$defquotatext);
- my ($defquota,$settingstatus) =
- &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
- my %changeHash;
- if ($userenv{'portfolioquota'} ne '') {
- $oldportfolioquota = $userenv{'portfolioquota'};
- if ($env{'form.customquota'} == 1) {
- if ($env{'form.portfolioquota'} eq '') {
- $newportfolioquota = 0;
- } else {
- $newportfolioquota = $env{'form.portfolioquota'};
- $newportfolioquota =~ s/[^\d\.]//g;
- }
- if ($newportfolioquota != $userenv{'portfolioquota'}) {
- $quotachanged = "a_admin($newportfolioquota,\%changeHash);
+ my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
+ $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
+ %oldsettingstext,%newsettings,%newsettingstext,@disporder,
+ %oldsettingstatus,%newsettingstatus);
+ @disporder = ('inststatus');
+ if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
+ push(@disporder,('requestcourses','requestauthor','authordefaults'));
+ } else {
+ push(@disporder,'reqcrsotherdom');
+ }
+ push(@disporder,('quota','tools'));
+ $oldinststatus = $userenv{'inststatus'};
+ foreach my $name ('portfolio','author') {
+ ($olddefquota{$name},$oldsettingstatus{$name}) =
+ &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
+ ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
+ }
+ my %canshow;
+ if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
+ $canshow{'quota'} = 1;
+ }
+ if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
+ $canshow{'tools'} = 1;
+ }
+ if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
+ $canshow{'requestcourses'} = 1;
+ } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
+ $canshow{'reqcrsotherdom'} = 1;
+ }
+ if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
+ $canshow{'inststatus'} = 1;
+ }
+ if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
+ $canshow{'requestauthor'} = 1;
+ $canshow{'authordefaults'} = 1;
+ }
+ my (%changeHash,%changed);
+ if ($oldinststatus eq '') {
+ $oldsettings{'inststatus'} = $othertitle;
+ } else {
+ if (ref($usertypes) eq 'HASH') {
+ $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
+ } else {
+ $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
+ }
+ }
+ $changeHash{'inststatus'} = $userenv{'inststatus'};
+ if ($canmodify_status{'inststatus'}) {
+ $canshow{'inststatus'} = 1;
+ if (exists($env{'form.inststatus'})) {
+ my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
+ if (@inststatuses > 0) {
+ $newinststatus = join(':',map { &escape($_); } @inststatuses);
+ $changeHash{'inststatus'} = $newinststatus;
+ if ($newinststatus ne $oldinststatus) {
+ $changed{'inststatus'} = $newinststatus;
+ foreach my $name ('portfolio','author') {
+ ($newdefquota{$name},$newsettingstatus{$name}) =
+ &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
+ }
+ }
+ if (ref($usertypes) eq 'HASH') {
+ $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
+ } else {
+ $newsettings{'inststatus'} = join(', ',@inststatuses);
+ }
}
} else {
- $quotachanged = "a_admin('',\%changeHash);
- $newportfolioquota = $defquota;
- $isdefault = 1;
+ $newinststatus = '';
+ $changeHash{'inststatus'} = $newinststatus;
+ $newsettings{'inststatus'} = $othertitle;
+ if ($newinststatus ne $oldinststatus) {
+ $changed{'inststatus'} = $changeHash{'inststatus'};
+ foreach my $name ('portfolio','author') {
+ ($newdefquota{$name},$newsettingstatus{$name}) =
+ &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
+ }
+ }
}
- } else {
- $oldportfolioquota = $defquota;
- if ($env{'form.customquota'} == 1) {
- if ($env{'form.portfolioquota'} eq '') {
- $newportfolioquota = 0;
+ } elsif ($context ne 'selfcreate') {
+ $canshow{'inststatus'} = 1;
+ $newsettings{'inststatus'} = $oldsettings{'inststatus'};
+ }
+ foreach my $name ('portfolio','author') {
+ $changeHash{$name.'quota'} = $userenv{$name.'quota'};
+ }
+ if ($context eq 'domain') {
+ foreach my $name ('portfolio','author') {
+ if ($userenv{$name.'quota'} ne '') {
+ $oldquota{$name} = $userenv{$name.'quota'};
+ if ($env{'form.custom_'.$name.'quota'} == 1) {
+ if ($env{'form.'.$name.'quota'} eq '') {
+ $newquota{$name} = 0;
+ } else {
+ $newquota{$name} = $env{'form.'.$name.'quota'};
+ $newquota{$name} =~ s/[^\d\.]//g;
+ }
+ if ($newquota{$name} != $oldquota{$name}) {
+ if ("a_admin($newquota{$name},\%changeHash,$name)) {
+ $changed{$name.'quota'} = 1;
+ }
+ }
+ } else {
+ if ("a_admin('',\%changeHash,$name)) {
+ $changed{$name.'quota'} = 1;
+ $newquota{$name} = $newdefquota{$name};
+ $newisdefault{$name} = 1;
+ }
+ }
+ } else {
+ $oldisdefault{$name} = 1;
+ $oldquota{$name} = $olddefquota{$name};
+ if ($env{'form.custom_'.$name.'quota'} == 1) {
+ if ($env{'form.'.$name.'quota'} eq '') {
+ $newquota{$name} = 0;
+ } else {
+ $newquota{$name} = $env{'form.'.$name.'quota'};
+ $newquota{$name} =~ s/[^\d\.]//g;
+ }
+ if ("a_admin($newquota{$name},\%changeHash,$name)) {
+ $changed{$name.'quota'} = 1;
+ }
+ } else {
+ $newquota{$name} = $newdefquota{$name};
+ $newisdefault{$name} = 1;
+ }
+ }
+ if ($oldisdefault{$name}) {
+ $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
+ } else {
+ $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
+ }
+ if ($newisdefault{$name}) {
+ $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
} else {
- $newportfolioquota = $env{'form.portfolioquota'};
- $newportfolioquota =~ s/[^\d\.]//g;
+ $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
}
- $quotachanged = "a_admin($newportfolioquota,\%changeHash);
+ }
+ &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
+ \%changeHash,\%changed,\%newsettings,\%newsettingstext);
+ if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
+ &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
+ \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
+ my ($isadv,$isauthor) =
+ &Apache::lonnet::is_advanced_user($env{'form.ccdomain'},$env{'form.ccuname'});
+ unless ($isauthor) {
+ &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
+ \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
+ }
+ &tool_changes('authordefaults',\@authordefaults,\%oldsettings,\%oldsettingstext,
+ \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
} else {
- $newportfolioquota = $defquota;
- $isdefault = 1;
+ &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
+ \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
}
}
- if ($isdefault) {
- 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});
- }
+ foreach my $item (@userinfo) {
+ if ($env{'form.c'.$item} ne $userenv{$item}) {
+ $namechanged{$item} = 1;
}
}
- if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
- ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
- $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
- $env{'form.clastname'} ne $userenv{'lastname'} ||
- $env{'form.cgeneration'} ne $userenv{'generation'} ||
- $env{'form.cid'} ne $userenv{'id'} ||
- $env{'form.cpermanentemail'} ne $userenv{'permanentemail'} )) {
- $namechanged = 1;
+ foreach my $name ('portfolio','author') {
+ $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
+ $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
}
- if ($namechanged) {
- # Make the change
- $changeHash{'firstname'} = $env{'form.cfirstname'};
- $changeHash{'middlename'} = $env{'form.cmiddlename'};
- $changeHash{'lastname'} = $env{'form.clastname'};
- $changeHash{'generation'} = $env{'form.cgeneration'};
- $changeHash{'id'} = $env{'form.cid'};
- $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
- my $putresult = &Apache::lonnet::put
- ('environment',\%changeHash,
- $env{'form.ccdomain'},$env{'form.ccuname'});
- if ($putresult eq 'ok') {
- # Tell the user we changed the name
- my %lt=&Apache::lonlocal::texthash(
- 'uic' => "User Information Changed",
- 'frst' => "first",
- 'mddl' => "middle",
- 'lst' => "last",
- 'gen' => "generation",
- 'id' => "ID/Student number",
- 'mail' => "permanent e-mail",
- 'disk' => "disk space allocated to portfolio files",
- 'prvs' => "Previous",
- 'chto' => "Changed To"
- );
- $r->print('
'
+ .&mt('Unable to successfully change environment for [_1] in domain [_2].',
+ '"'.$env{'form.ccuname'}.'"',
+ '"'.$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(
- 'id' => "ID/Student number",
- 'mail' => "Permanent e-mail",
- 'disk' => "Disk space allocated to user's portfolio files",
- );
- $r->print(<<"END");
-
');
+ if ($context eq 'course') {
+ $contextname = 'course';
+ } elsif ($context eq 'author') {
+ $contextname = '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 $contextname roles:"));
} else {
- $r->print(' ('.$lt{'mail'}.': '.
- $userenv{'permanentemail'}.')');
+ $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future $contextname roles:"));
}
- if ($putresult eq 'ok') {
- if ($oldportfolioquota != $newportfolioquota) {
- $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.').'
';
+ }
+ $output .= '';
+ }
+ }
+ }
+ my $actionhref = '/adm/createuser';
+ if ($context eq 'domain') {
+ $actionhref = '/adm/modifycourse';
+ }
+
+ my %noedit;
+ unless ($context eq 'domain') {
+ %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
+ }
+ $output .= '';
+ $r->print($output);
+ return;
+}
+
+sub get_noedit_fields {
+ my ($cdom,$cnum,$crstype,$row) = @_;
+ my %noedit;
+ if (ref($row) eq 'ARRAY') {
+ my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
+ 'internal.selfenrollmgrdc',
+ 'internal.selfenrollmgrcc'],$cdom,$cnum);
+ my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
+ my (%specific_managebydc,%specific_managebycc,%default_managebydc);
+ map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
+ map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
+ map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
+
+ foreach my $item (@{$row}) {
+ next if ($specific_managebycc{$item});
+ if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
+ $noedit{$item} = 1;
+ }
+ }
+ }
+ return %noedit;
+}
+
+sub visible_in_stdcat {
+ my ($cdom,$cnum,$domconf) = @_;
+ my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
+ unless (ref($domconf) eq 'HASH') {
+ return ($visible,$cansetvis,\@vismsgs);
+ }
+ if (ref($domconf->{'coursecategories'}) eq 'HASH') {
+ if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
+ $settable{'togglecats'} = 1;
+ }
+ if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
+ $settable{'categorize'} = 1;
+ }
+ $cathash = $domconf->{'coursecategories'}{'cats'};
+ }
+ if ($settable{'togglecats'} && $settable{'categorize'}) {
+ $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
+ } elsif ($settable{'togglecats'}) {
+ $cansetvis = &mt('You are able to choose to exclude this course from the catalog, but only a Domain Coordinator may assign a course category.');
+ } elsif ($settable{'categorize'}) {
+ $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
+ } else {
+ $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
+ }
+
+ my %currsettings =
+ &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
+ $cdom,$cnum);
+ $visible = 0;
+ if ($currsettings{'internal.coursecode'} ne '') {
+ if (ref($domconf->{'coursecategories'}) eq 'HASH') {
+ $cathash = $domconf->{'coursecategories'}{'cats'};
+ if (ref($cathash) eq 'HASH') {
+ if ($cathash->{'instcode::0'} eq '') {
+ push(@vismsgs,'dc_addinst');
+ } else {
+ $visible = 1;
+ }
+ } else {
+ $visible = 1;
+ }
+ } else {
+ $visible = 1;
+ }
+ } else {
+ if (ref($cathash) eq 'HASH') {
+ if ($cathash->{'instcode::0'} ne '') {
+ push(@vismsgs,'dc_instcode');
+ }
+ } else {
+ push(@vismsgs,'dc_instcode');
+ }
+ }
+ if ($currsettings{'categories'} ne '') {
+ my $cathash;
+ if (ref($domconf->{'coursecategories'}) eq 'HASH') {
+ $cathash = $domconf->{'coursecategories'}{'cats'};
+ if (ref($cathash) eq 'HASH') {
+ if (keys(%{$cathash}) == 0) {
+ push(@vismsgs,'dc_catalog');
+ } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
+ push(@vismsgs,'dc_categories');
+ } else {
+ my @currcategories = split('&',$currsettings{'categories'});
+ my $matched = 0;
+ foreach my $cat (@currcategories) {
+ if ($cathash->{$cat} ne '') {
+ $visible = 1;
+ $matched = 1;
+ last;
+ }
+ }
+ if (!$matched) {
+ if ($settable{'categorize'}) {
+ push(@vismsgs,'chgcat');
+ } else {
+ push(@vismsgs,'dc_chgcat');
+ }
+ }
+ }
+ }
+ }
+ } else {
+ if (ref($cathash) eq 'HASH') {
+ if ((keys(%{$cathash}) > 1) ||
+ (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
+ if ($settable{'categorize'}) {
+ push(@vismsgs,'addcat');
+ } else {
+ push(@vismsgs,'dc_addcat');
+ }
+ }
+ }
+ }
+ if ($currsettings{'hidefromcat'} eq 'yes') {
+ $visible = 0;
+ if ($settable{'togglecats'}) {
+ unshift(@vismsgs,'unhide');
+ } else {
+ unshift(@vismsgs,'dc_unhide')
+ }
+ }
+ return ($visible,$cansetvis,\@vismsgs);
+}
+
+sub cat_visibility {
+ my ($cdom) = @_;
+ my %visactions = &Apache::lonlocal::texthash(
+ vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
+ gen => 'Courses can be both self-cataloging, based on an institutional code (e.g., fs08phy231), or can be assigned categories from a hierarchy defined for the domain.',
+ miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
+ none => 'Display of a course catalog is disabled for this domain.',
+ yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
+ coca => 'Courses can be absent from the Catalog, because they do not have an institutional code, have no assigned category, or have been specifically excluded.',
+ make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
+ take => 'Take the following action to ensure the course appears in the Catalog:',
+ dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
+ dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
+ dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
+ dc_addinst => 'Ask a domain coordinator to enable catalog display of "Official courses (with institutional codes)".',
+ dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
+ dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
+ dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
+ dc_chgcat => 'Ask a domain coordinator to change the category assigned to the course, as the one currently assigned is no longer used in the domain',
+ dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
+ );
+ if ($env{'request.role'} eq "dc./$cdom/") {
+ $visactions{'dc_chgconf'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the Catalog type for this domain.','»');
+ $visactions{'dc_setcode'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to assign a six character code to the course.','»');
+ $visactions{'dc_unhide'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the "Exclude from course catalog" setting.','»');
+ $visactions{'dc_addinst'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to enable catalog display of "Official courses (with institutional codes)".','»');
+ $visactions{'dc_instcode'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify course owner, institutional code ... " to assign an institutional code (if this is an official course).','»');
+ $visactions{'dc_catalog'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to enable or create at least one course category in the domain.','»');
+ $visactions{'dc_categories'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to create a hierarchy of categories and sub categories for courses in the domain.','»');
+ $visactions{'dc_chgcat'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify catalog settings for course" to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','»');
+ $visactions{'dc_addcat'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify catalog settings for course" to assign a category to the course.','»');
+ }
+ $visactions{'unhide'} = &mt('Use [_1]Categorize course[_2] to change the "Exclude from course catalog" setting.','','"');
+ $visactions{'chgcat'} = &mt('Use [_1]Categorize course[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','"','"');
+ $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"','"');
+ return \%visactions;
+}
+
+sub new_selfenroll_dom_row {
+ my ($newdom,$num) = @_;
+ my $domdesc = &Apache::lonnet::domain($newdom);
+ my $output;
+ if ($domdesc ne '') {
+ $output .= &Apache::loncommon::start_data_table_row()
+ .'
'
+ .&mt('You need to be a privileged user to display user access logs for [_1]',
+ &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
+ $uname,$udom))
+ .'
';
+ my $startform =
+ &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
+ $curr->{'rolelog_start_date'},undef,
+ undef,undef,undef,undef,undef,undef,$nolink);
+ my $endform =
+ &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
+ $curr->{'rolelog_end_date'},undef,
+ undef,undef,undef,undef,undef,undef,$nolink);
+ my %lt = &rolechg_contexts($context,$crstype);
+ $output .= '
'.&mt('Window during which changes occurred:').' '.
+ '
'.&mt('After:').
+ '
'.$startform.'
'.
+ '
'.&mt('Before:').'
'.
+ '
'.$endform.'
'.
+ '
'.
+ '
'.
+ '
'.&mt('Role:').' '.
+ '
'.
+ '
'.
+ '
'.
+ &mt('Context:').'
'.
+ '
'.
+ '
'.
+ &mt('Approvals:').'
';
+
+ # Update Display button
+ $output .= '
'
+ .''
+ .'
';
+
+ # Server version info
+ my $needsrev = '2.11.0';
+ if ($context eq 'course') {
+ $needsrev = '2.7.0';
+ }
+
+ $output .= '
'
+ .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
+ ,$needsrev);
+ if ($version) {
+ $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
+ }
+ $output .= '
';
+ return $output;
+}
+
+sub rolechg_contexts {
+ my ($context,$crstype) = @_;
+ my %lt;
+ if ($context eq 'course') {
+ %lt = &Apache::lonlocal::texthash (
+ any => 'Any',
+ automated => 'Automated Enrollment',
+ chgtype => 'Enrollment Type/Lock Change',
+ updatenow => 'Roster Update',
+ createcourse => 'Course Creation',
+ course => 'User Management in course',
+ domain => 'User Management in domain',
+ selfenroll => 'Self-enrolled',
+ requestcourses => 'Course Request',
+ ltienroll => 'Enrollment via LTI',
+ );
+ if ($crstype eq 'Community') {
+ $lt{'createcourse'} = &mt('Community Creation');
+ $lt{'course'} = &mt('User Management in community');
+ $lt{'requestcourses'} = &mt('Community Request');
+ }
+ } elsif ($context eq 'domain') {
+ %lt = &Apache::lonlocal::texthash (
+ any => 'Any',
+ domain => 'User Management in domain',
+ requestauthor => 'Authoring Request',
+ server => 'Command line script (DC role)',
+ domconfig => 'Self-enrolled',
+ );
+ } else {
+ %lt = &Apache::lonlocal::texthash (
+ any => 'Any',
+ domain => 'User Management in domain',
+ author => 'User Management by author',
+ coauthor => 'User Management by coauthor',
+ );
+ }
+ return %lt;
+}
+
+sub approval_types {
+ return &Apache::lonlocal::texthash (
+ any => 'Any',
+ none => 'No approval needed',
+ user => 'Role recipient approval',
+ domain => 'Domain coordinator approval',
+ );
+}
+
+sub print_helpdeskaccess_display {
+ my ($r,$permission,$brcrum) = @_;
+ my $formname = 'helpdeskaccess';
+ my $helpitem = 'Course_Helpdesk_Access';
+ push (@{$brcrum},
+ {href => '/adm/createuser?action=helpdesk',
+ text => 'Helpdesk Access',
+ help => $helpitem});
+ my $bread_crumbs_component = 'Helpdesk Staff Access';
+ my $args = { bread_crumbs => $brcrum,
+ bread_crumbs_component => $bread_crumbs_component};
+
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $confname = $cdom.'-domainconfig';
+ my $crstype = &Apache::loncommon::course_type();
+
+ my @accesstypes = ('all','dh','da','none');
+ my ($numstatustypes,@jsarray);
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
+ if (ref($types) eq 'ARRAY') {
+ if (@{$types} > 0) {
+ $numstatustypes = scalar(@{$types});
+ push(@accesstypes,'status');
+ @jsarray = ('bystatus');
+ }
+ }
+ my %customroles = &get_domain_customroles($cdom,$confname);
+ my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
+ if (keys(%domhelpdesk)) {
+ push(@accesstypes,('inc','exc'));
+ push(@jsarray,('notinc','notexc'));
+ }
+ push(@jsarray,'privs');
+ my $hiddenstr = join("','",@jsarray);
+ my $rolestr = join("','",sort(keys(%customroles)));
+
+ my $jscript;
+ my (%settings,%overridden);
+ if (keys(%customroles)) {
+ &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
+ $types,\%customroles,\%settings,\%overridden);
+ my %jsfull=();
+ my %jslevels= (
+ course => {},
+ domain => {},
+ system => {},
+ );
+ my %jslevelscurrent=(
+ course => {},
+ domain => {},
+ system => {},
+ );
+ my (%privs,%jsprivs);
+ &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
+ foreach my $priv (keys(%jsfull)) {
+ if ($jslevels{'course'}{$priv}) {
+ $jsprivs{$priv} = 1;
+ }
+ }
+ my (%elements,%stored);
+ foreach my $role (keys(%customroles)) {
+ $elements{$role.'_access'} = 'radio';
+ $elements{$role.'_incrs'} = 'radio';
+ if ($numstatustypes) {
+ $elements{$role.'_status'} = 'checkbox';
+ }
+ if (keys(%domhelpdesk) > 0) {
+ $elements{$role.'_staff_inc'} = 'checkbox';
+ $elements{$role.'_staff_exc'} = 'checkbox';
+ }
+ $elements{$role.'_override'} = 'checkbox';
+ if (ref($settings{$role}) eq 'HASH') {
+ if ($settings{$role}{'access'} ne '') {
+ my $curraccess = $settings{$role}{'access'};
+ $stored{$role.'_access'} = $curraccess;
+ $stored{$role.'_incrs'} = 1;
+ if ($curraccess eq 'status') {
+ if (ref($settings{$role}{'status'}) eq 'ARRAY') {
+ $stored{$role.'_status'} = $settings{$role}{'status'};
+ }
+ } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
+ if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
+ $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
+ }
+ }
+ } else {
+ $stored{$role.'_incrs'} = 0;
+ }
+ $stored{$role.'_override'} = [];
+ if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
+ if (ref($settings{$role}{'off'}) eq 'ARRAY') {
+ foreach my $priv (@{$settings{$role}{'off'}}) {
+ push(@{$stored{$role.'_override'}},$priv);
+ }
+ }
+ if (ref($settings{$role}{'on'}) eq 'ARRAY') {
+ foreach my $priv (@{$settings{$role}{'on'}}) {
+ unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
+ push(@{$stored{$role.'_override'}},$priv);
+ }
+ }
+ }
+ }
+ } else {
+ $stored{$role.'_incrs'} = 0;
+ }
+ }
+ $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
+ }
+
+ my $js = <<"ENDJS";
+
+ENDJS
+
+ $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
+
+ # print page header
+ $r->print(&header($js,$args));
+ # print form header
+ $r->print('');
+ return;
+}
+
+sub print_queued_roles {
+ my ($r,$context,$permission,$brcrum) = @_;
+ push (@{$brcrum},
+ {href => '/adm/createuser?action=rolerequests',
+ text => 'Role Requests (other domains)',
+ help => ''});
+ my $bread_crumbs_component = 'Role Requests';
+ my $args = { bread_crumbs => $brcrum,
+ bread_crumbs_component => $bread_crumbs_component};
+ # print page header
+ $r->print(&header('',$args));
+ my ($dom,$cnum);
+ $dom = $env{'request.role.domain'};
+ if ($context eq 'course') {
+ if ($env{'request.course.id'}) {
+ if (&Apache::loncommon::course_type() eq 'Community') {
+ $context = 'community';
+ }
+ $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ }
+ } elsif ($context eq 'author') {
+ $cnum = $env{'user.name'};
+ }
+ $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomqueue',$dom,$cnum,$context));
+ return;
+}
+
+sub print_pendingroles {
+ my ($r,$context,$permission,$brcrum) = @_;
+ push (@{$brcrum},
+ {href => '/adm/createuser?action=queuedroles',
+ text => 'Queued Role Assignments (users in this domain)',
+ help => ''});
+ my $bread_crumbs_component = 'Queued Role Assignments';
+ my $args = { bread_crumbs => $brcrum,
+ bread_crumbs_component => $bread_crumbs_component};
+ # print page header
+ $r->print(&header('',$args));
+ $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomaction',$env{'request.role.domain'},'','domain'));
+ return;
+}
+
+sub process_pendingroles {
+ my ($r,$context,$permission,$brcrum) = @_;
+ push (@{$brcrum},
+ {href => '/adm/createuser?action=queuedroles',
+ text => 'Queued Role Assignments (users in this domain)',
+ help => ''},
+ {href => '/adm/createuser?action=processrolereq',
+ text => 'Process Queue',
+ help => ''});
+ my $bread_crumbs_component = 'Queued Role Assignments';
+ my $args = { bread_crumbs => $brcrum,
+ bread_crumbs_component => $bread_crumbs_component};
+ # print page header
+ $r->print(&header('',$args));
+ $r->print(&Apache::loncoursequeueadmin::update_request_queue('othdombydc',
+ $env{'request.role.domain'}));
+ return;
+}
+
+sub domain_adhoc_access {
+ my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
+ my %domusage;
+ return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
+ foreach my $role (keys(%{$roles})) {
+ if (ref($domcurrent->{$role}) eq 'HASH') {
+ my $access = $domcurrent->{$role}{'access'};
+ if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
+ $access = 'all';
+ $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
+ &Apache::lonnet::plaintext('da'));
+ } elsif ($access eq 'status') {
+ if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
+ my @shown;
+ foreach my $type (@{$domcurrent->{$role}{$access}}) {
+ unless ($type eq 'default') {
+ if ($usertypes->{$type}) {
+ push(@shown,$usertypes->{$type});
+ }
+ }
+ }
+ if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
+ push(@shown,$othertitle);
+ }
+ if (@shown) {
+ my $shownstatus = join(' '.&mt('or').' ',@shown);
+ $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
+ &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
+ } else {
+ $domusage{$role} = &mt('No one in the domain');
+ }
+ }
+ } elsif ($access eq 'inc') {
+ my @dominc = ();
+ if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
+ foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
+ my ($uname,$udom) = split(/:/,$user);
+ push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
+ }
+ my $showninc = join(', ',@dominc);
+ if ($showninc ne '') {
+ $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
+ &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
+ } else {
+ $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
+ &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
+ }
+ }
+ } elsif ($access eq 'exc') {
+ my @domexc = ();
+ if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
+ foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
+ my ($uname,$udom) = split(/:/,$user);
+ push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
+ }
+ }
+ my $shownexc = join(', ',@domexc);
+ if ($shownexc ne '') {
+ $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
+ &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
+ } else {
+ $domusage{$role} = &mt('No one in the domain');
+ }
+ } elsif ($access eq 'none') {
+ $domusage{$role} = &mt('No one in the domain');
+ } elsif ($access eq 'dh') {
+ $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
+ } elsif ($access eq 'da') {
+ $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
+ } elsif ($access eq 'all') {
+ $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
+ &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
+ }
+ } else {
+ $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
+ &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
+ }
+ }
+ return %domusage;
+}
+
+sub get_domain_customroles {
+ my ($cdom,$confname) = @_;
+ my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
+ my %customroles;
+ foreach my $key (keys(%existing)) {
+ if ($key=~/^rolesdef\_(\w+)$/) {
+ my $rolename = $1;
+ my %privs;
+ ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
+ $customroles{$rolename} = \%privs;
+ }
+ }
+ return %customroles;
+}
+
+sub role_priv_table {
+ my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
+ return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
+ (ref($levelscurrent) eq 'HASH'));
+ my %lt=&Apache::lonlocal::texthash (
+ 'crl' => 'Course Level Privilege',
+ 'def' => 'Domain Defaults',
+ 'ove' => 'Override in Course',
+ 'ine' => 'In effect',
+ 'dis' => 'Disabled',
+ 'ena' => 'Enabled',
+ );
+ if ($crstype eq 'Community') {
+ $lt{'ove'} = 'Override in Community',
+ }
+ my @status = ('Disabled','Enabled');
+ my (%on,%off);
+ if (ref($overridden) eq 'HASH') {
+ if (ref($overridden->{'on'}) eq 'ARRAY') {
+ map { $on{$_} = 1; } (@{$overridden->{'on'}});
+ }
+ if (ref($overridden->{'off'}) eq 'ARRAY') {
+ map { $off{$_} = 1; } (@{$overridden->{'off'}});
+ }
+ }
+ my $output=&Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ '
'.$lt{'crl'}.'
'.$lt{'def'}.'
'.$lt{'ove'}.
+ '
'.$lt{'ine'}.'
'.
+ &Apache::loncommon::end_data_table_header_row();
+ foreach my $priv (sort(keys(%{$full}))) {
+ next unless ($levels->{'course'}{$priv});
+ my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
+ my ($default,$ineffect);
+ if ($levelscurrent->{'course'}{$priv}) {
+ $default = '';
+ $ineffect = $default;
+ }
+ my ($customstatus,$checked);
+ $output .= &Apache::loncommon::start_data_table_row().
+ '
');
+ if ($env{'form.'.$role.'_incrs'}) {
+ if ($newsettings{$role}{'access'} eq 'all') {
+ $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
+ } elsif ($newsettings{$role}{'access'} eq 'dh') {
+ $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
+ &Apache::lonnet::plaintext('dh')));
+ } elsif ($newsettings{$role}{'access'} eq 'da') {
+ $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
+ &Apache::lonnet::plaintext('da')));
+ } elsif ($newsettings{$role}{'access'} eq 'none') {
+ $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
+ } elsif ($newsettings{$role}{'access'} eq 'status') {
+ if ($newsettings{$role}{'status'}) {
+ my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
+ if (split(/,/,$rest) > 1) {
+ $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
+ $newsettings{$role}{'status'}));
+ } else {
+ $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
+ $newsettings{$role}{'status'}));
+ }
+ } else {
+ $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
+ }
+ } elsif ($newsettings{$role}{'access'} eq 'exc') {
+ if ($newsettings{$role}{'exc'}) {
+ $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
+ } else {
+ $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
+ }
+ } elsif ($newsettings{$role}{'access'} eq 'inc') {
+ if ($newsettings{$role}{'inc'}) {
+ $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
+ } else {
+ $r->print(&mt('All helpdesk staff may use this role.'));
+ }
+ }
+ } else {
+ $r->print(&mt('Default access set in the domain now applies.').' '.
+ ''.$domusage{$role}.'');
+ }
+ $r->print('
');
+ }
+ unless ($newsettings{$role}{'access'} eq 'none') {
+ if ($changed{$role}{'off'}) {
+ if ($newsettings{$role}{'off'}) {
+ $r->print('
'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
+ '
'.$newsettings{$role}{'off'}.'
');
+ } else {
+ $r->print('
'.&mt('All privileges available by default for this ad hoc role are enabled.').'
');
+ }
+ }
+ if ($changed{$role}{'on'}) {
+ if ($newsettings{$role}{'on'}) {
+ $r->print('
'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
+ '
'.$newsettings{$role}{'on'}.'
');
+ } else {
+ $r->print('
'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'
');
+ }
+ }
+ }
+ $r->print('
');
+ }
+ $r->print('
');
+ }
+ } else {
+ $r->print(&mt('No changes made to helpdesk access settings.'));
+ }
+ }
+ return;
+}
+
#-------------------------------------------------- functions for &phase_two
sub user_search_result {
- my ($srch) = @_;
+ my ($context,$srch) = @_;
my %allhomes;
my %inst_matches;
my %srch_results;
@@ -2724,19 +9767,41 @@ sub user_search_result {
if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
($srch->{'srchin'} eq 'alc')) {
if ($srch->{'srchby'} eq 'uname') {
- if ($srch->{'srchterm'} !~ /^$match_username$/) {
+ my $unamecheck = $srch->{'srchterm'};
+ if ($srch->{'srchtype'} eq 'contains') {
+ if ($unamecheck !~ /^\w/) {
+ $unamecheck = 'a'.$unamecheck;
+ }
+ }
+ if ($unamecheck !~ /^$match_username$/) {
$response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
}
}
}
if ($response ne '') {
- $response = ''.$response.'';
+ $response = ''.$response.' ';
}
if ($srch->{'srchin'} eq 'instd') {
- my $instd_chk = &directorysrch_check($srch);
+ my $instd_chk = &instdirectorysrch_check($srch);
if ($instd_chk ne 'ok') {
- $response = ''.$instd_chk.''.
- ' '.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'
';
+ my $domd_chk = &domdirectorysrch_check($srch);
+ $response .= ''.$instd_chk.' ';
+ if ($domd_chk eq 'ok') {
+ $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
+ }
+ $response .= ' ';
+ }
+ } else {
+ unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
+ my $domd_chk = &domdirectorysrch_check($srch);
+ if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
+ my $instd_chk = &instdirectorysrch_check($srch);
+ $response .= ''.$domd_chk.' ';
+ if ($instd_chk eq 'ok') {
+ $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
+ }
+ $response .= ' ';
+ }
}
}
if ($response ne '') {
@@ -2763,14 +9828,26 @@ sub user_search_result {
my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
if ($uhome eq 'no_host') {
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} else {
$currstate = 'modify';
+ if ($env{'form.action'} eq 'accesslogs') {
+ $currstate = 'activity';
+ }
+ my $uname = $srch->{'srchterm'};
+ my $udom = $srch->{'srchdomain'};
+ $srch_results{$uname.':'.$udom} =
+ { &Apache::lonnet::get('environment',
+ ['firstname',
+ 'lastname',
+ 'permanentemail'],
+ $udom,$uname)
+ };
}
} else {
%srch_results = &Apache::lonnet::usersearch($srch);
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
}
} else {
my $courseusers = &get_courseusers();
@@ -2779,7 +9856,7 @@ sub user_search_result {
$currstate = 'modify';
} else {
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
}
} else {
foreach my $user (keys(%$courseusers)) {
@@ -2806,7 +9883,7 @@ sub user_search_result {
}
}
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
}
}
}
@@ -2816,21 +9893,21 @@ sub user_search_result {
($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
if ($dirsrchres eq 'ok') {
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} else {
my $showdom = &display_domain_info($srch->{'srchdomain'});
$response = ''.
&mt('Institutional directory search is not available in domain: [_1]',$showdom).
' '.
- &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
- '
';
+ &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
+ ' ';
}
}
} else {
if ($srch->{'srchin'} eq 'dom') {
%srch_results = &Apache::lonnet::usersearch($srch);
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} elsif ($srch->{'srchin'} eq 'crs') {
my $courseusers = &get_courseusers();
foreach my $user (keys(%$courseusers)) {
@@ -2882,27 +9959,47 @@ sub user_search_result {
}
}
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} elsif ($srch->{'srchin'} eq 'alc') {
$currstate = 'query';
} elsif ($srch->{'srchin'} eq 'instd') {
($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
if ($dirsrchres eq 'ok') {
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} else {
- my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = ''.
+ my $showdom = &display_domain_info($srch->{'srchdomain'});
+ $response = ''.
&mt('Institutional directory search is not available in domain: [_1]',$showdom).
' '.
- &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
- '
';
+ &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
+ ' ';
}
}
}
return ($currstate,$response,$forcenewuser,\%srch_results);
}
-sub directorysrch_check {
+sub domdirectorysrch_check {
+ my ($srch) = @_;
+ my $response;
+ my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
+ ['directorysrch'],$srch->{'srchdomain'});
+ my $showdom = &display_domain_info($srch->{'srchdomain'});
+ if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
+ if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
+ return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
+ }
+ if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
+ if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
+ return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
+ }
+ }
+ }
+ return 'ok';
+}
+
+sub instdirectorysrch_check {
my ($srch) = @_;
my $can_search = 0;
my $response;
@@ -2933,11 +10030,15 @@ sub directorysrch_check {
my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
my @longtypes;
foreach my $item (@usertypes) {
- push (@longtypes,$insttypes->{$item});
+ if (defined($insttypes->{$item})) {
+ push (@longtypes,$insttypes->{$item});
+ } elsif ($item eq 'default') {
+ push (@longtypes,&mt('other'));
+ }
}
my $insttype_str = join(', ',@longtypes);
return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
- }
+ }
} else {
$can_search = 1;
}
@@ -2995,15 +10096,15 @@ sub get_courseusers {
}
sub build_search_response {
- my ($srch,%srch_results) = @_;
+ my ($context,$srch,%srch_results) = @_;
my ($currstate,$response,$forcenewuser);
my %names = (
- 'uname' => 'username',
- 'lastname' => 'last name',
+ 'uname' => 'username',
+ 'lastname' => 'last name',
'lastfirst' => 'last name, first name',
- 'crs' => 'this course',
- 'dom' => 'LON-CAPA domain: ',
- 'instd' => 'the institutional directory for domain: ',
+ 'crs' => 'this course',
+ 'dom' => 'LON-CAPA domain',
+ 'instd' => 'the institutional directory for domain',
);
my %single = (
@@ -3020,21 +10121,31 @@ sub build_search_response {
$currstate = 'select';
} else {
if (keys(%srch_results) == 1) {
- $currstate = 'modify';
+ if ($env{'form.action'} eq 'accesslogs') {
+ $currstate = 'activity';
+ } else {
+ $currstate = 'modify';
+ }
$response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
- $response .= &display_domain_info($srch->{'srchdomain'});
+ $response .= ': '.&display_domain_info($srch->{'srchdomain'});
}
- } else {
- $response = ''.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
+ } else { # Search has nothing found. Prepare message to user.
+ $response = '';
if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
- $response .= &display_domain_info($srch->{'srchdomain'});
+ $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
+ ''.$srch->{'srchterm'}.'',
+ &display_domain_info($srch->{'srchdomain'}));
+ } else {
+ $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
+ ''.$srch->{'srchterm'}.'');
}
$response .= '';
+
if ($srch->{'srchin'} ne 'alc') {
$forcenewuser = 1;
my $cansrchinst = 0;
- if ($srch->{'srchdomain'}) {
+ if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
if (ref($domconfig{'directorysrch'}) eq 'HASH') {
if ($domconfig{'directorysrch'}{'available'}) {
@@ -3053,9 +10164,52 @@ sub build_search_response {
$response .= ' '.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
}
}
- if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
- my $showdom = &display_domain_info($env{'request.role.domain'});
- $response .= '
'.&mt("To add a new user (you can only create new users in your current role's domain - [_1]):",$env{'request.role.domain'}).'
'.&mt("Set 'Domain/institution to search' to: [_1]",$showdom).'
'.&mt("Set 'Search criteria' to: 'username is ...... in selected LON-CAPA domain'").'
'.&mt('Provide the proposed username').'
'.&mt('Search').'
';
+ my $createdom = $env{'request.role.domain'};
+ if ($context eq 'requestcrs') {
+ if ($env{'form.coursedom'} ne '') {
+ $createdom = $env{'form.coursedom'};
+ }
+ }
+ unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
+ ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
+ my $cancreate =
+ &Apache::lonuserutils::can_create_user($createdom,$context);
+ my $targetdom = ''.$createdom.'';
+ if ($cancreate) {
+ my $showdom = &display_domain_info($createdom);
+ $response .= '
'
+ .''.&mt('To add a new user:').''
+ .' ';
+ if ($context eq 'requestcrs') {
+ $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
+ } else {
+ $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
+ }
+ $response .='
'
+ .&mt("Set 'Domain/institution to search' to: [_1]",''.$showdom.'')
+ .'
'
+ .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'','')
+ .'
'.&mt('"[_1]" set to "[_2]".',$title,$newval));
+ if ($newnotify) {
+ $r->print(' '.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
+ } else {
+ $r->print(' '.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
+ }
+ $r->print('