--- loncom/interface/loncreateuser.pm 2007/09/12 23:42:37 1.185
+++ loncom/interface/loncreateuser.pm 2025/01/13 01:00:58 1.483
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.185 2007/09/12 23:42:37 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.483 2025/01/13 01:00:58 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,215 +68,1130 @@ use Apache::lonnet;
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 $generalrule;
my $authformnop;
my $authformkrb;
my $authformint;
my $authformfsys;
my $authformloc;
+my $authformlti;
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,$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|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;
+ }
+ }
+ 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);
}
-
-# ======================================================= 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',
+ localauth => 'loc',
+ unix => 'fsys',
+ lti => 'lti',
+ );
+ return %abv_auth;
}
# ====================================================
-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.
@@ -419,375 +1395,302 @@ sub print_user_query_page {
}
sub print_user_modification_page {
- my ($r,$ccuname,$ccdomain,$srch,$response) = @_;
+ 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 ($instsrch,$rulematch,$rules,%inst_results);
+ 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 (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
if ($uhome eq 'no_host') {
- $instsrch =
- {
- srchin => 'instd',
- srchby => 'uname',
- srchtype => 'exact',
- srchterm => $ccuname,
- srchdomain => $ccdomain,
- };
- (my $usercheckmsg,$rulematch,$rules,%inst_results) =
- &Apache::loncommon::username_rule_check($instsrch,'new');
- if ($usercheckmsg) {
- &print_username_entry_form($r,$usercheckmsg);
+ 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;
}
- }
- if ($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
- );
- $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 };
+ $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,
+ $crstype,$groupslist,$newuser,
+ $formname,\%loaditem,$permission);
+ my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
+ 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';
+ $js .= &set_custom_js();
+ }
+ 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;
+ $args->{'add_modal'} = 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','archive'));
+ }
+ 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,
+ };
+ }
+ }
+ 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;
}
- $r->print(&Apache::loncommon::end_data_table_row().
- &Apache::loncommon::end_data_table());
- # Build up table of user roles to allow revocation of a role.
- my ($tmp) = keys(%rolesdump);
- unless ($tmp =~ /^(con_lost|error)/i) {
- my $now=time;
- my %lt=&Apache::lonlocal::texthash(
- 'rer' => "Revoke Existing Roles",
- 'rev' => "Revoke",
+ if ($showexpired && $showactive) {
+ $showall = 1;
+ }
+ }
+ my %lt=&Apache::lonlocal::texthash(
+ 'rer' => "Existing Roles",
+ 'rev' => "Revoke",
'del' => "Delete",
- 'ren' => "Re-Enable",
+ 'ren' => "Re-Enable",
'rol' => "Role",
'ext' => "Extent",
+ 'crd' => "Credits",
'sta' => "Start",
- 'end' => "End"
- );
- my (%roletext,%sortrole,%roleclass,%rolepriv);
- foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
- my $b1=join('_',(split('_',$b))[1,0]);
- return $a1 cmp $b1;
- } keys(%rolesdump)) {
- next if ($area =~ /^rolesdef/);
- my $envkey=$area;
- my $role = $rolesdump{$area};
- my $thisrole=$area;
- $area =~ s/\_\w\w$//;
- my ($role_code,$role_end_time,$role_start_time) =
- split(/_/,$role);
+ 'end' => "End",
+ );
+ my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
+ if ($context eq 'course' || $context eq 'author') {
+ my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
+ my %roleshash =
+ &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
+ ['active','previous','future'],\@roles,$roledom,1);
+ foreach my $key (keys(%roleshash)) {
+ my ($start,$end) = split(':',$roleshash{$key});
+ next if ($start eq '-1' || $end eq '-1');
+ my ($rnum,$rdom,$role,$sec) = split(':',$key);
+ if ($context eq 'course') {
+ next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
+ && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
+ } elsif ($context eq 'author') {
+ if ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
+ my ($audom,$auname) = ($1,$2);
+ next unless (($rnum eq $auname) && ($rdom eq $audom));
+ } else {
+ next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
+ }
+ }
+ my ($newkey,$newvalue,$newrole);
+ $newkey = '/'.$rdom.'/'.$rnum;
+ if ($sec ne '') {
+ $newkey .= '/'.$sec;
+ }
+ $newvalue = $role;
+ if ($role =~ /^cr/) {
+ $newrole = 'cr';
+ } else {
+ $newrole = $role;
+ }
+ $newkey .= '_'.$newrole;
+ if ($start ne '' && $end ne '') {
+ $newvalue .= '_'.$end.'_'.$start;
+ } elsif ($end ne '') {
+ $newvalue .= '_'.$end;
+ }
+ $rolesdump{$newkey} = $newvalue;
+ }
+ } else {
+ %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
+ }
+ # Build up table of user roles to allow revocation and re-enabling of roles.
+ my ($tmp) = keys(%rolesdump);
+ return if ($tmp =~ /^(con_lost|error)/i);
+ foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
+ my $b1=join('_',(split('_',$b))[1,0]);
+ return $a1 cmp $b1;
+ } keys(%rolesdump)) {
+ next if ($area =~ /^rolesdef/);
+ my $envkey=$area;
+ my $role = $rolesdump{$area};
+ my $thisrole=$area;
+ $area =~ s/\_\w\w$//;
+ my ($role_code,$role_end_time,$role_start_time) =
+ split(/_/,$role);
+ my $active=1;
+ $active=0 if (($role_end_time) && ($now>$role_end_time));
+ if ($active) {
+ next unless($showall || $showactive);
+ } else {
+ next unless($showall || $showexpired);
+ }
# Is this a custom role? Get role owner and title.
- my ($croleudom,$croleuname,$croletitle)=
- ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
- my $allowed=0;
- my $delallowed=0;
- my $sortkey=$role_code;
- my $class='Unknown';
- if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
- $class='Course';
- my ($coursedom,$coursedir) = ($1,$2);
- $sortkey.="\0$coursedom";
- # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
- my %coursedata=
- &Apache::lonnet::coursedescription($1.'_'.$2);
- my $carea;
- if (defined($coursedata{'description'})) {
- $carea=$coursedata{'description'}.
- ' '.&mt('Domain').': '.$coursedom.(' 'x8).
- &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
- $sortkey.="\0".$coursedata{'description'};
- $class=$coursedata{'type'};
- } else {
- $carea=&mt('Unavailable course').': '.$area;
- $sortkey.="\0".&mt('Unavailable course').': '.$area;
- }
- $sortkey.="\0$coursedir";
- $inccourses{$1.'_'.$2}=1;
- if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
- (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
- $allowed=1;
- }
- if ((&Apache::lonnet::allowed('dro',$1)) ||
- (&Apache::lonnet::allowed('dro',$ccdomain))) {
- $delallowed=1;
- }
+ my ($croleudom,$croleuname,$croletitle)=
+ ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
+ my $allowed=0;
+ my $delallowed=0;
+ my $sortkey=$role_code;
+ my $class='Unknown';
+ my $credits='';
+ my $csec;
+ if ($area =~ m{^/($match_domain)/($match_courseid)}) {
+ $class='Course';
+ my ($coursedom,$coursedir) = ($1,$2);
+ my $cid = $1.'_'.$2;
+ # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
+ next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
+ my %coursedata=
+ &Apache::lonnet::coursedescription($cid);
+ if ($coursedir =~ /^$match_community$/) {
+ $class='Community';
+ }
+ $sortkey.="\0$coursedom";
+ my $carea;
+ if (defined($coursedata{'description'})) {
+ $carea=$coursedata{'description'}.
+ ' '.&mt('Domain').': '.$coursedom.(' 'x8).
+ &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
+ $sortkey.="\0".$coursedata{'description'};
+ } else {
+ if ($class eq 'Community') {
+ $carea=&mt('Unavailable community').': '.$area;
+ $sortkey.="\0".&mt('Unavailable community').': '.$area;
+ } else {
+ $carea=&mt('Unavailable course').': '.$area;
+ $sortkey.="\0".&mt('Unavailable course').': '.$area;
+ }
+ }
+ $sortkey.="\0$coursedir";
+ $inccourses->{$cid}=1;
+ if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
+ my $defaultcredits = $coursedata{'internal.defaultcredits'};
+ $credits =
+ &get_user_credits($ccuname,$ccdomain,$defaultcredits,
+ $coursedom,$coursedir);
+ if ($credits eq '') {
+ $credits = $defaultcredits;
+ }
+ }
+ if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
+ (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
+ $allowed=1;
+ }
+ unless ($allowed) {
+ my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
+ if ($isowner) {
+ if (($role_code eq 'co') && ($class eq 'Community')) {
+ $allowed = 1;
+ } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
+ $allowed = 1;
+ }
+ }
+ }
+ if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
+ (&Apache::lonnet::allowed('dro',$ccdomain))) {
+ $delallowed=1;
+ }
# - custom role. Needs more info, too
- if ($croletitle) {
- if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
- $allowed=1;
- $thisrole.='.'.$role_code;
- }
- }
- # Compute the background color based on $area
- if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
- $carea.=' Section: '.$3;
- $sortkey.="\0$3";
- }
- $area=$carea;
- } else {
- $sortkey.="\0".$area;
- # Determine if current user is able to revoke privileges
- if ($area=~m{^/($match_domain)/}) {
- if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
- (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
- $allowed=1;
- }
- if (((&Apache::lonnet::allowed('dro',$1)) ||
- (&Apache::lonnet::allowed('dro',$ccdomain))) &&
- ($role_code ne 'dc')) {
- $delallowed=1;
- }
- } else {
- if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
- $allowed=1;
- }
- }
- if ($role_code eq 'ca' || $role_code eq 'au') {
- $class='Construction Space';
- } elsif ($role_code eq 'su') {
- $class='System';
- } else {
- $class='Domain';
- }
- }
- if (($role_code eq 'ca') || ($role_code eq 'aa')) {
- $area=~m{/($match_domain)/($match_username)};
- if (&authorpriv($2,$1)) {
- $allowed=1;
- } else {
- $allowed=0;
- }
- }
- my $row = '';
- $row.= '
';
- my $active=1;
- $active=0 if (($role_end_time) && ($now>$role_end_time));
- if (($active) && ($allowed)) {
- $row.= '';
- } else {
- if ($active) {
- $row.=' ';
- } else {
- $row.=&mt('expired or revoked');
- }
- }
- $row.='
'.
-&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
+ if ($croletitle) {
+ if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
+ $allowed=1;
+ $thisrole.='.'.$role_code;
+ }
}
- } 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 ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
+ $csec = $2;
+ $carea.=' '.&mt('Section: [_1]',$csec);
+ $sortkey.="\0$csec";
+ if (!$allowed) {
+ if ($env{'request.course.sec'} eq $csec) {
+ if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
+ $allowed = 1;
+ }
+ }
+ }
}
- if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
- # Current user has quota modification privileges
- $r->print(&portfolio_quota($ccuname,$ccdomain));
+ $area=$carea;
+ } else {
+ $sortkey.="\0".$area;
+ # Determine if current user is able to revoke privileges
+ if ($area=~m{^/($match_domain)/}) {
+ if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
+ (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
+ $allowed=1;
+ }
+ if (((&Apache::lonnet::allowed('dro',$1)) ||
+ (&Apache::lonnet::allowed('dro',$ccdomain))) &&
+ ($role_code ne 'dc')) {
+ $delallowed=1;
+ }
+ } else {
+ if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
+ $allowed=1;
+ }
}
- } ## End of "check for bad authentication type" logic
- } ## End of new user/old user logic
- $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 (!(&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) &&
+ ($env{'user.domain'} eq $ccdomain)) {
+ $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 =
'
'.
&Apache::loncommon::end_data_table_header_row();
+ my @allroles = &Apache::lonuserutils::roles_by_context('domain');
+ my $uprimary = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
+ my $uintdom = &Apache::lonnet::internet_dom($uprimary);
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)) {
+ if ($role eq 'dc') {
+ unless ($thisdomain eq $env{'request.role.domain'}) {
+ my $domprim = &Apache::lonnet::domain($thisdomain,'primary');
+ my $intdom = &Apache::lonnet::internet_dom($domprim);
+ next unless ($uintdom eq $intdom);
+ }
+ }
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.'
@@ -1263,110 +2523,718 @@ 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;
+ }
+ return $addrolesdisplay;
+}
+
+sub user_authentication {
+ my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
+ my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
+ my $outcome;
+ 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"
+ );
+ # Check for a bad authentication type
+ if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth|lti):/) {
+ # bad authentication scheme
+ if (&Apache::lonnet::allowed('mau',$ccdomain)) {
+ &initialize_authen_forms($ccdomain,$formname);
+
+ 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
+ $outcome =
+ ''."\n".
+ '
';
+ }
+ 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
- my $error = ''.&mt('Error').':';
- my $end = &Apache::loncommon::end_page();
-
+ my $error = ''.&mt('Error').': ';
+ my $end = '
';
+ my $rtnlink = ''.
+ &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=>"User modify/custom role edit",
- 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'} ) {
- $r->print($error.&mt('No login name specified').'.'.$end);
+ $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
return;
}
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').'.'.
- $end);
+ $r->print($error.&mt('Invalid login name.').' '.
+ &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
+ $end.$rtnlink);
return;
}
if (! $env{'form.ccdomain'} ) {
- $r->print($error.&mt('No domain specified').'.'.$end);
+ $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
return;
}
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').'.'.
- $end);
+ $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;
}
}
@@ -1387,6 +3255,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
@@ -1394,19 +3265,31 @@ 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);
- 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'}).'
");
- }
- } 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 [_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(
- '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 = '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(&mt("You do not have the authority to change these fields given the user's current set of active/future $contextname roles:"));
+ }
+ 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)
+ .'');
+ }
+ &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+ if ($env{'form.action'} eq 'singlestudent') {
+ &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
+ $crstype,$showcredits,$defaultcredits);
+ my $linktext = ($crstype eq 'Community' ?
+ &mt('Enroll Another Member') : &mt('Enroll Another Student'));
+ $r->print(
+ &Apache::lonhtmlcommon::actionbox([
+ ''
+ .($crstype eq 'Community' ?
+ &mt('Enroll Another Member') : &mt('Enroll Another Student'))
+ .'']));
+ } else {
+ my @rolechanges = &update_roles($r,$context,$showcredits);
+ if (keys(%namechanged) > 0) {
+ if ($context eq 'course') {
+ if (@userroles > 0) {
+ if ((@rolechanges == 0) ||
+ (!(grep(/^st$/,@rolechanges)))) {
+ if (grep(/^st$/,@userroles)) {
+ my $classlistupdated =
+ &Apache::lonuserutils::update_classlist($cdom,
+ $cnum,$env{'form.ccdomain'},
+ $env{'form.ccuname'},\%userupdate);
+ }
+ }
}
}
}
+ my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
+ $env{'form.ccdomain'});
+ if ($env{'form.popup'}) {
+ $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;
+
+ my $credits;
+ if (($showcredits) && ($env{'form.credits'} ne '')) {
+ $credits = $env{'form.credits'};
+ $credits =~ s/[^\d\.]//g;
+ if ($credits ne '') {
+ if ($credits eq $defaultcredits) {
+ undef($credits);
+ }
}
}
- $r->print(''."\n".
- ''."\n".
- '');
- $r->print(&Apache::loncommon::end_page());
+ my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
+ my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,%pending,%reject,%notifydc,
+ %status,%unauthorized,%currqueued);
+ unless ($env{'form.ccdomain'} eq $env{'course.'.$env{'request.course.id'}.'.domain'}) {
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $csec = $env{'form.sections'};
+ my $id = "/$cdom/$cnum";
+ if ($csec ne '') {
+ $id .= "/$csec";
+ }
+ $id .= '_st';
+ if (&Apache::lonuserutils::restricted_dom($context,$id,$env{'form.ccdomain'},$env{'form.ccuname'},
+ 'st',$startdate,$enddate,$cdom,$cnum,$csec,$credits,
+ \%process_by,\%instdoms,\%got_role_approvals,\%got_instdoms,
+ \%reject,\%pending,\%notifydc,\%status,\%unauthorized,\%currqueued)) {
+ if ((keys(%reject)) || (keys(%unauthorized))) {
+ $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
+ }
+ if ((keys(%pending)) || (keys(%currqueued))) {
+ $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
+ }
+ return;
+ }
+ }
+
+ # 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 $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,
+ $credits);
+ 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 can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
+ } else {
+ $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
+ }
+ $r->print('
');
+ }
+ } else {
+ $r->print(&mt('unable to enroll').": ".$enroll_result);
+ }
+ 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 =
+ '';
+ return $outcome;
}
sub quota_admin {
- my ($setquota,$changeHash) = @_;
+ my ($setquota,$changeHash,$name) = @_;
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->{$name.'quota'} = $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 ($context eq 'authordefaults') {
+ 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;
+ } elsif (($tool eq 'managers') || ($tool eq 'editors') || ($tool eq 'archive')) {
+ $changeHash->{'author'.$tool} = $settool;
+ } elsif ($tool eq 'webdav') {
+ $changeHash->{'tools.'.$tool} = $settool;
+ } else {
+ $changeHash->{$context.'.'.$tool} = $settool;
+ }
+ }
+ }
+ return $toolchanged;
+}
+
sub build_roles {
my ($sectionstr,$sections,$role) = @_;
my $num_sections = 0;
@@ -1913,370 +5351,4550 @@ sub build_roles {
# ========================================================== Custom Role Editor
sub custom_role_editor {
- my ($r) = @_;
- my $rolename=$env{'form.rolename'};
+ my ($r,$context,$brcrum,$prefix,$permission) = @_;
+ my $action = $env{'form.customroleaction'};
+ my ($rolename,$helpitem);
+ 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';
+ $helpitem = 'Course_Editing_Custom_Roles';
+ } else {
+ $context = 'domain';
+ $crstype = 'course';
+ $helpitem = 'Domain_Editing_Custom_Roles';
}
$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,$context,undef,undef,undef,$crstype,$brcrum,
+ $permission);
return;
}
-# ------------------------------------------------------- What can be assigned?
- my %full=();
- my %courselevel=();
- my %courselevelcurrent=();
- my $syspriv='';
- my $dompriv='';
- my $coursepriv='';
- my $body_top;
- my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
+
+ my $formname = 'form1';
+ my %privs=();
+ my $body_top = '
';
+# ------------------------------------------------------- Does this role exist?
my ($rdummy,$roledef)=
&Apache::lonnet::get('roles',["rolesdef_$rolename"]);
-# ------------------------------------------------------- Does this role exist?
- $body_top .= '
';
+ }
+ $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;
@@ -2306,19 +9924,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 '') {
@@ -2345,14 +9985,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();
@@ -2361,7 +10013,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)) {
@@ -2382,12 +10034,13 @@ sub user_search_result {
{&Apache::lonnet::get('environment',
['firstname',
'lastname',
- 'permanentemail'])};
+ 'permanentemail'],
+ $cudomain,$cuname)};
}
}
}
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
}
}
}
@@ -2397,21 +10050,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)) {
@@ -2463,27 +10116,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;
@@ -2514,11 +10187,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;
}
@@ -2576,15 +10253,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 = (
@@ -2601,21 +10278,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'}) {
@@ -2634,9 +10321,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]",'','')
+ .'