--- loncom/interface/loncreateuser.pm 2005/06/23 21:59:13 1.107
+++ 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.107 2005/06/23 21:59:13 www 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 '.$userpicker.' '
+ .&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 .= '
',$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 .= ''."\n".
+ ' '."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$titles{$name}.' '."\n".
+ ' '.
+ &mt('Current quota: [_1] MB',$currquota).' '.
+ $defaultinfo.' '."\n".
+ &Apache::loncommon::end_data_table_row()."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ''.$lt{'chqu'}.
+ ': '.
+ ' '.
+ ' '.&mt('MB').' '."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
}
- return %returnhash;
+ return $output;
}
-# ==================================================== Figure out author access
+sub user_quota_js {
+ return <<"END_SCRIPT";
+
+END_SCRIPT
-sub authorpriv {
- my ($auname,$audom)=@_;
- unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
- || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; }
- return 1;
}
-# =================================================================== Phase one
+sub set_custom_js {
+ return <<"END_SCRIPT";
-sub print_username_entry_form {
- my $r=shift;
- my $defdom=$env{'request.role.domain'};
- my @domains = &Apache::loncommon::get_domains();
- my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
- my $html=&Apache::lonxml::xmlbegin();
- my $bodytag =&Apache::loncommon::bodytag('Create Users, Change User Privileges').&Apache::loncommon::help_open_menu('',undef,undef,'',282,'Instructor Interface');
- my $selscript=&Apache::loncommon::studentbrowser_javascript();
- my $sellink=&Apache::loncommon::selectstudent_link
- ('crtuser','ccuname','ccdomain');
- my %existingroles=&my_custom_roles();
- my $choice=&Apache::loncommon::select_form('make new role','rolename',
- ('make new role' => 'Generate new role ...',%existingroles));
- my %lt=&Apache::lonlocal::texthash(
- 'siur' => "Set Individual User Roles",
- 'usr' => "Username",
- 'dom' => "Domain",
- 'usrr' => "User Roles",
- 'ecrp' => "Edit Custom Role Privileges",
- 'nr' => "Name of Role",
- 'cre' => "Custom Role Editor"
- );
- my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
- my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
- $r->print(<<"ENDDOCUMENT");
-$html
-
-$lt{'ecrp'}$helpecpr
-$lt{'nr'}: $choice
-
-
-ENDCUSTOM
+
-# =================================================================== Phase two
-sub print_user_modification_page {
- my $r=shift;
- my $ccuname=$env{'form.ccuname'};
- my $ccdomain=$env{'form.ccdomain'};
+END_SCRIPT
- $ccuname=~s/\W//g;
- $ccdomain=~s/\W//g;
+}
- unless (($ccuname) && ($ccdomain)) {
- &print_username_entry_form($r);
- return;
+sub build_tools_display {
+ my ($ccuname,$ccdomain,$context) = @_;
+ my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
+ $colspan,$isadv,%domconfig,@defaulteditors,@customeditors,@custommanagers,
+ @possmanagers);
+ my %lt = &Apache::lonlocal::texthash (
+ 'blog' => "Personal User Blog",
+ 'aboutme' => "Personal Information Page",
+ 'webdav' => "WebDAV access to Authoring Spaces (https)",
+ 'editors' => "Available Editors",
+ 'managers' => "Co-authors who can add/revoke roles",
+ 'archive' => "Managers can download tar.gz file of Authoring Space",
+ 'portfolio' => "Personal User Portfolio",
+ 'portaccess' => "Portfolio Shareable",
+ 'timezone' => "Can set Time Zone",
+ 'avai' => "Available",
+ 'cusa' => "availability",
+ 'chse' => "Change setting",
+ 'usde' => "Use default",
+ 'uscu' => "Use custom",
+ 'official' => 'Can request creation of official courses',
+ 'unofficial' => 'Can request creation of unofficial courses',
+ 'community' => 'Can request creation of communities',
+ 'textbook' => 'Can request creation of textbook courses',
+ 'placement' => 'Can request creation of placement tests',
+ 'lti' => 'Can request creation of LTI courses',
+ 'requestauthor' => 'Can request author space',
+ 'edit' => 'Standard editor (Edit)',
+ 'xml' => 'Text editor (EditXML)',
+ 'daxe' => 'Daxe editor (Daxe)',
+ );
+ $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
+ if ($context eq 'requestcourses') {
+ %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
+ 'requestcourses.official','requestcourses.unofficial',
+ 'requestcourses.community','requestcourses.textbook',
+ 'requestcourses.placement','requestcourses.lti');
+ @usertools = ('official','unofficial','community','textbook','placement','lti');
+ @options =('norequest','approval','autolimit','validate');
+ %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
+ %reqtitles = &courserequest_titles();
+ %reqdisplay = &courserequest_display();
+ %domconfig =
+ &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
+ } elsif ($context eq 'requestauthor') {
+ %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,'requestauthor');
+ @usertools = ('requestauthor');
+ @options =('norequest','approval','automatic');
+ %reqtitles = &requestauthor_titles();
+ %reqdisplay = &requestauthor_display();
+ %domconfig =
+ &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
+ } elsif ($context eq 'authordefaults') {
+ %domconfig =
+ &Apache::lonnet::get_dom('configuration',['quotas','authordefaults'],$ccdomain);
+ %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,'tools.webdav',
+ 'authoreditors','authormanagers',
+ 'authorarchive','domcoord.author');
+ @usertools = ('webdav','editors','managers','archive');
+ $colspan = ' colspan="2"';
+ } else {
+ %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
+ 'tools.aboutme','tools.portfolio','tools.blog',
+ 'tools.timezone','tools.portaccess');
+ @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
+ $colspan = ' colspan="2"';
+ }
+ foreach my $item (@usertools) {
+ my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
+ $currdisp,$custdisp,$custradio,$onclick,$customsty,$editorsty);
+ $cust_off = 'checked="checked" ';
+ $tool_on = 'checked="checked" ';
+ unless (($context eq 'authordefaults') || ($item eq 'webdav')) {
+ $curr_access =
+ &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
+ $context,\%userenv,'',
+ {'is_adv' => $isadv});
+ }
+ if ($context eq 'requestauthor') {
+ if ($userenv{$context} ne '') {
+ $cust_on = ' checked="checked" ';
+ $cust_off = '';
+ }
+ } elsif ($context eq 'authordefaults') {
+ if (($item eq 'editors') || ($item eq 'archive')) {
+ if ($userenv{'author'.$item} ne '') {
+ $cust_on = ' checked="checked" ';
+ $cust_off = '';
+ if ($item eq 'archive') {
+ $curr_access = $userenv{'author'.$item};
+ }
+ } elsif ($item eq 'archive') {
+ $curr_access = 0;
+ if (ref($domconfig{'authordefaults'}) eq 'HASH') {
+ $curr_access = $domconfig{'authordefaults'}{'archive'};
+ }
+ }
+ } elsif ($item eq 'webdav') {
+ if ($userenv{'tools.'.$item} ne '') {
+ $cust_on = ' checked="checked" ';
+ $cust_off = '';
+ $curr_access = $userenv{'tools.'.$item};
+ } else {
+ $curr_access =
+ &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,'reload',
+ undef,\%userenv,'',
+ {'is_adv' => $isadv});
+ }
+ }
+ } elsif ($userenv{$context.'.'.$item} ne '') {
+ $cust_on = ' checked="checked" ';
+ $cust_off = '';
+ }
+ if ($context eq 'requestcourses') {
+ if ($userenv{$context.'.'.$item} eq '') {
+ $custom_access = &mt('Currently from default setting.');
+ $customsty = ' style="display:none;"';
+ } else {
+ $custom_access = &mt('Currently from custom setting.');
+ $customsty = ' style="display:block;"';
+ }
+ } elsif ($context eq 'requestauthor') {
+ if ($userenv{$context} eq '') {
+ $custom_access = &mt('Currently from default setting.');
+ $customsty = ' style="display:none;"';
+ } else {
+ $custom_access = &mt('Currently from custom setting.');
+ $customsty = ' style="display:block;"';
+ }
+ } elsif ($item eq 'editors') {
+ if ($userenv{'author'.$item} eq '') {
+ if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
+ @defaulteditors = @{$domconfig{'authordefaults'}{'editors'}};
+ } else {
+ @defaulteditors = ('edit','xml');
+ }
+ $custom_access = &mt('Can use: [_1]',
+ join(', ', map { $lt{$_} } @defaulteditors));
+ $editorsty = ' style="display:none;"';
+ } else {
+ $custom_access = &mt('Currently from custom setting.');
+ foreach my $editor (split(/,/,$userenv{'author'.$item})) {
+ if ($editor =~ /^(edit|daxe|xml)$/) {
+ push(@customeditors,$editor);
+ }
+ }
+ if (@customeditors) {
+ if (@customeditors > 1) {
+ $custom_access .= '
';
+ } else {
+ $custom_access .= ' ';
+ }
+ $custom_access .= &mt('Can use: [_1]',
+ join(', ', map { $lt{$_} } @customeditors)).
+ '';
+ } else {
+ $custom_access .= ' '.&mt('No available editors');
+ }
+ $editorsty = ' style="display:block;"';
+ }
+ } elsif ($item eq 'managers') {
+ my %ca_roles = &Apache::lonnet::get_my_roles($ccuname,$ccdomain,undef,
+ ['active','future'],['ca']);
+ if (keys(%ca_roles)) {
+ foreach my $entry (sort(keys(%ca_roles))) {
+ if ($entry =~ /^($match_username\:$match_domain):ca$/) {
+ my $user = $1;
+ unless ($user eq "$ccuname:$ccdomain") {
+ push(@possmanagers,$user);
+ }
+ }
+ }
+ }
+ if ($userenv{'author'.$item} eq '') {
+ $custom_access = &mt('Currently author manages co-author roles');
+ } else {
+ if (keys(%ca_roles)) {
+ foreach my $user (split(/,/,$userenv{'author'.$item})) {
+ if ($user =~ /^($match_username):($match_domain)$/) {
+ if (exists($ca_roles{$user.':ca'})) {
+ unless ($user eq "$ccuname:$ccdomain") {
+ push(@custommanagers,$user);
+ }
+ }
+ }
+ }
+ }
+ if (@custommanagers) {
+ $custom_access = &mt('Co-authors who manage co-author roles: [_1]',
+ join(', ',@custommanagers));
+ } else {
+ $custom_access = &mt('Currently author manages co-author roles');
+ }
+ }
+ } else {
+ my $current = $userenv{$context.'.'.$item};
+ if ($item eq 'webdav') {
+ $current = $userenv{'tools.webdav'};
+ } elsif ($item eq 'archive') {
+ $current = $userenv{'author'.$item};
+ }
+ if ($current eq '') {
+ $custom_access =
+ &mt('Availability determined currently from default setting.');
+ if (!$curr_access) {
+ $tool_off = 'checked="checked" ';
+ $tool_on = '';
+ }
+ $customsty = ' style="display:none;"';
+ } else {
+ $custom_access =
+ &mt('Availability determined currently from custom setting.');
+ if ($current == 0) {
+ $tool_off = 'checked="checked" ';
+ $tool_on = '';
+ }
+ $customsty = ' style="display:inline;"';
+ }
+ }
+ $output .= ' '."\n".
+ ' '."\n".
+ &Apache::loncommon::start_data_table_row()."\n";
+ if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
+ my ($curroption,$currlimit);
+ my $envkey = $context.'.'.$item;
+ if ($context eq 'requestauthor') {
+ $envkey = $context;
+ }
+ if ($userenv{$envkey} ne '') {
+ $curroption = $userenv{$envkey};
+ } else {
+ my (@inststatuses);
+ if ($context eq 'requestcourses') {
+ $curroption =
+ &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
+ $isadv,$ccdomain,$item,
+ \@inststatuses,\%domconfig);
+ } else {
+ $curroption =
+ &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
+ $isadv,$ccdomain,undef,
+ \@inststatuses,\%domconfig);
+ }
+ }
+ if (!$curroption) {
+ $curroption = 'norequest';
+ }
+ my $name = 'crsreq_'.$item;
+ if ($context eq 'requestauthor') {
+ $name = $item;
+ }
+ $onclick = ' onclick="javascript:toggleCustom(this.form,'."'customtext_$item','custom$item'".');"';
+ if ($curroption =~ /^autolimit=(\d*)$/) {
+ $currlimit = $1;
+ if ($currlimit eq '') {
+ $currdisp = &mt('Yes, automatic creation');
+ } else {
+ $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
+ }
+ } else {
+ $currdisp = $reqdisplay{$curroption};
+ }
+ $custdisp = '';
+ }
+ $custdisp .= ' ';
+ }
+ $custdisp .= '';
+ $custradio = ''.$lt{$item}.' '."\n".
+ '
'.$custdisp;
+ } elsif ($item eq 'editors') {
+ $output .= ''.$custom_access.' '."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
+ unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
+ $output .= &Apache::loncommon::start_data_table_row()."\n".
+ ''.
+ $lt{'chse'}.': '.(' ' x3).
+ ' '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ } elsif ($item eq 'managers') {
+ $output .= '
'.
+ ''.$custom_access.' '."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
+ unless ((&Apache::lonnet::allowed('udp',$ccdomain)) ||
+ (($userenv{'domcoord.author'} eq 'blocked') &&
+ (($env{'user.name'} ne $ccuname) || ($env{'user.domain'} ne $ccdomain)))) {
+ $output .=
+ &Apache::loncommon::start_data_table_row()."\n".
+ '';
+ if (@possmanagers) {
+ $output .= &mt('Select manager(s)').': ';
+ foreach my $user (@possmanagers) {
+ my $checked;
+ if (grep(/^\Q$user\E$/,@custommanagers)) {
+ $checked = ' checked="checked"';
+ }
+ $output .= ' ';
+ }
+ } else {
+ $output .= &mt('No co-author roles assignable as manager');
+ }
+ $output .= ' '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ } else {
+ $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
+ my $name = $context.'_'.$item;
+ $onclick = 'onclick="javascript:toggleCustom(this.form,'."'customtext_$item','custom$item'".');" ';
+ $custdisp = ' ';
+ $custradio = ''.
+ '--'.$lt{'cusa'}.': '.$custdisp.'';
+ }
+ unless (($item eq 'editors') || ($item eq 'managers')) {
+ $output .= ' '.$custom_access.(' 'x4).
+ $lt{'avai'}.': '.$currdisp.' '."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
+ unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
+ $output .=
+ &Apache::loncommon::start_data_table_row()."\n".
+ ''.
+ $lt{'chse'}.': '.(' ' x3).
+ '';
+ if ($colspan) {
+ $output .= ' ';
+ }
+ $output .= $custradio.' '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ }
}
+ return $output;
+}
- my $defdom=$env{'request.role.domain'};
+sub coursereq_externaluser {
+ my ($ccuname,$ccdomain,$cdom) = @_;
+ my (@usertools,@options,%validations,%userenv,$output);
+ my %lt = &Apache::lonlocal::texthash (
+ 'official' => 'Can request creation of official courses',
+ 'unofficial' => 'Can request creation of unofficial courses',
+ 'community' => 'Can request creation of communities',
+ 'textbook' => 'Can request creation of textbook courses',
+ 'placement' => 'Can request creation of placement tests',
+ );
- my ($krbdef,$krbdefdom) =
- &Apache::loncommon::get_kerberos_defaults($defdom);
+ %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
+ 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
+ 'reqcrsotherdom.community','reqcrsotherdom.textbook',
+ 'reqcrsotherdom.placement');
+ @usertools = ('official','unofficial','community','textbook','placement');
+ @options = ('approval','validate','autolimit');
+ %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
+ my $optregex = join('|',@options);
+ my %reqtitles = &courserequest_titles();
+ foreach my $item (@usertools) {
+ my ($curroption,$currlimit,$tooloff);
+ if ($userenv{'reqcrsotherdom.'.$item} ne '') {
+ my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
+ foreach my $req (@curr) {
+ if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
+ $curroption = $1;
+ $currlimit = $2;
+ last;
+ }
+ }
+ if (!$curroption) {
+ $curroption = 'norequest';
+ $tooloff = ' checked="checked"';
+ }
+ } else {
+ $curroption = 'norequest';
+ $tooloff = ' checked="checked"';
+ }
+ $output.= &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$lt{$item}.': '.
+ ' '."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ return $output;
+}
- 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);
+sub domainrole_req {
+ my ($ccuname,$ccdomain) = @_;
+ return ''."\n".
+ ' ';
+ foreach my $option (@options) {
+ if ($option eq 'validate') {
+ my $canvalidate = 0;
+ if (ref($validations{$item}) eq 'HASH') {
+ if ($validations{$item}{'_external_'}) {
+ $canvalidate = 1;
+ }
+ }
+ next if (!$canvalidate);
+ }
+ my $checked = '';
+ if ($option eq $curroption) {
+ $checked = ' checked="checked"';
+ }
+ $output .= '';
+ if ($option eq 'autolimit') {
+ $output .= ' '.
+ ' ';
+ }
+ $output .= '
'.$reqtitles{'unlimited'};
+ } else {
+ $output .= '';
+ }
+ $output .= ''.
+ &mt('Can Request Assignment of Domain Roles?').
+ '
'."\n".
+ &Apache::loncommon::start_data_table().
+ &build_tools_display($ccuname,$ccdomain,
+ 'requestauthor').
+ &Apache::loncommon::end_data_table();
+}
- $ccuname=~s/\W//g;
- $ccdomain=~s/\W//g;
- my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
- my $dc_setcourse_code = '';
- my $loaditem;
- if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
- my $dcdom = $1;
- $loaditem = qq|OnLoad="document.cu.coursedesc.value=''"|;
- $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;
- for (var i=0; i'.
+ &mt('Authoring Space defaults (if role assigned)').
+ '
'."\n".
+ &Apache::loncommon::start_data_table().
+ &build_tools_display($ccuname,$ccdomain,
+ 'authordefaults').
+ &user_quotas($ccuname,$ccdomain,'author').
+ &Apache::loncommon::end_data_table();
+}
+
+sub courserequest_titles {
+ my %titles = &Apache::lonlocal::texthash (
+ official => 'Official',
+ unofficial => 'Unofficial',
+ community => 'Communities',
+ textbook => 'Textbook',
+ placement => 'Placement Tests',
+ lti => 'LTI Provider',
+ norequest => 'Not allowed',
+ approval => 'Approval by Dom. Coord.',
+ validate => 'With validation',
+ autolimit => 'Numerical limit',
+ unlimited => '(blank for unlimited)',
+ );
+ return %titles;
+}
+
+sub courserequest_display {
+ my %titles = &Apache::lonlocal::texthash (
+ approval => 'Yes, need approval',
+ validate => 'Yes, with validation',
+ norequest => 'No',
+ );
+ return %titles;
+}
+
+sub requestauthor_titles {
+ my %titles = &Apache::lonlocal::texthash (
+ norequest => 'Not allowed',
+ approval => 'Approval by Dom. Coord.',
+ automatic => 'Automatic approval',
+ );
+ return %titles;
+
+}
+
+sub requestauthor_display {
+ my %titles = &Apache::lonlocal::texthash (
+ approval => 'Yes, need approval',
+ automatic => 'Yes, automatic approval',
+ norequest => 'No',
+ );
+ return %titles;
+}
+
+sub requestchange_display {
+ my %titles = &Apache::lonlocal::texthash (
+ approval => "availability set to 'on' (approval required)",
+ automatic => "availability set to 'on' (automatic approval)",
+ norequest => "availability set to 'off'",
+ );
+ return %titles;
+}
+
+sub curr_requestauthor {
+ my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
+ return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
+ if ($uname eq '' || $udom eq '') {
+ $uname = $env{'user.name'};
+ $udom = $env{'user.domain'};
+ $isadv = $env{'user.adv'};
+ }
+ my (%userenv,%settings,$val);
+ my @options = ('automatic','approval');
+ %userenv =
+ &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
+ if ($userenv{'requestauthor'}) {
+ $val = $userenv{'requestauthor'};
+ @{$inststatuses} = ('_custom_');
+ } else {
+ my %alltasks;
+ if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
+ %settings = %{$domconfig->{'requestauthor'}};
+ if (($isadv) && ($settings{'_LC_adv'} ne '')) {
+ $val = $settings{'_LC_adv'};
+ @{$inststatuses} = ('_LC_adv_');
+ } else {
+ if ($userenv{'inststatus'} ne '') {
+ @{$inststatuses} = split(',',$userenv{'inststatus'});
+ } else {
+ @{$inststatuses} = ('default');
+ }
+ foreach my $status (@{$inststatuses}) {
+ if (exists($settings{$status})) {
+ my $value = $settings{$status};
+ next unless ($value);
+ unless (exists($alltasks{$value})) {
+ if (ref($alltasks{$value}) eq 'ARRAY') {
+ unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
+ push(@{$alltasks{$value}},$status);
+ }
+ } else {
+ @{$alltasks{$value}} = ($status);
+ }
}
}
}
- }
- 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
+ foreach my $option (@options) {
+ if ($alltasks{$option}) {
+ $val = $option;
+ last;
+ }
}
- var numsplit = document.cu.newsec.value.split(/,/g);
- numsections = numsections + numsplit.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;
+ }
+ }
+ return $val;
+}
+
+# =================================================================== Phase one
+
+sub print_username_entry_form {
+ my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
+ $permission) = @_;
+ my $defdom=$env{'request.role.domain'};
+ my $formtoset = 'crtuser';
+ if (exists($env{'form.startrolename'})) {
+ $formtoset = 'docustom';
+ $env{'form.rolename'} = $env{'form.startrolename'};
+ } elsif ($env{'form.origform'} eq 'crtusername') {
+ $formtoset = $env{'form.origform'};
+ }
+
+ my ($jsback,$elements) = &crumb_utilities();
+
+ my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
+ ''."\n";
+
+ my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
+ if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
+ && (&Apache::lonnet::allowed('mcr','/'))) {
+ $jscript .= &customrole_javascript();
+ }
+ my $helpitem = 'Course_Change_Privileges';
+ if ($env{'form.action'} eq 'custom') {
+ if ($context eq 'course') {
+ $helpitem = 'Course_Editing_Custom_Roles';
+ } elsif ($context eq 'domain') {
+ $helpitem = 'Domain_Editing_Custom_Roles';
+ }
+ } elsif ($env{'form.action'} eq 'singlestudent') {
+ $helpitem = 'Course_Add_Student';
+ } elsif ($env{'form.action'} eq 'accesslogs') {
+ $helpitem = 'Domain_User_Access_Logs';
+ } elsif ($context eq 'author') {
+ $helpitem = 'Author_Change_Privileges';
+ } elsif ($context eq 'domain') {
+ if ($permission->{'cusr'}) {
+ $helpitem = 'Domain_Change_Privileges';
+ } elsif ($permission->{'view'}) {
+ $helpitem = 'Domain_View_Privileges';
+ } else {
+ undef($helpitem);
+ }
+ }
+ my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
+ if ($env{'form.action'} eq 'custom') {
+ push(@{$brcrum},
+ {href=>"javascript:backPage(document.crtuser)",
+ text=>"Pick custom role",
+ help => $helpitem,}
+ );
+ } else {
+ push (@{$brcrum},
+ {href => "javascript:backPage(document.crtuser)",
+ text => $breadcrumb_text{'search'},
+ help => $helpitem,
+ faq => 282,
+ bug => 'Instructor Interface',}
+ );
+ }
+ my %loaditems = (
+ 'onload' => "javascript:setFormElements(document.$formtoset)",
+ );
+ my $args = {bread_crumbs => $brcrum,
+ bread_crumbs_component => 'User Management',
+ add_entries => \%loaditems,};
+ $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
+
+ my %lt=&Apache::lonlocal::texthash(
+ 'srst' => 'Search for a user and enroll as a student',
+ 'srme' => 'Search for a user and enroll as a member',
+ 'srad' => 'Search for a user and modify/add user information or roles',
+ 'srvu' => 'Search for a user and view user information and roles',
+ 'srva' => 'Search for a user and view access log information',
+ 'usr' => "Username",
+ 'dom' => "Domain",
+ 'ecrp' => "Define or Edit Custom Role",
+ 'nr' => "role name",
+ 'cre' => "Next",
+ );
+
+ if ($env{'form.action'} eq 'custom') {
+ if (&Apache::lonnet::allowed('mcr','/')) {
+ my $newroletext = &mt('Define new custom role:');
+ $r->print('');
+ }
+ } else {
+ my $actiontext = $lt{'srad'};
+ my $fixeddom;
+ if ($env{'form.action'} eq 'singlestudent') {
+ if ($crstype eq 'Community') {
+ $actiontext = $lt{'srme'};
+ } else {
+ $actiontext = $lt{'srst'};
}
- else {
- var coursename = "_$dcdom"+"_"+course+"_"+userrole
- document.cu.elements[numcourse].name = "act"+coursename
- document.cu.elements[numcourse+4].name = "sec"+coursename
- document.cu.elements[numcourse+4].value = section
- document.cu.elements[numcourse+5].name = "start"+coursename
- document.cu.elements[numcourse+6].name = "end"+coursename
+ } elsif ($env{'form.action'} eq 'accesslogs') {
+ $actiontext = $lt{'srva'};
+ $fixeddom = 1;
+ } elsif (($env{'form.action'} eq 'singleuser') &&
+ ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
+ $actiontext = $lt{'srvu'};
+ $fixeddom = 1;
+ }
+ $r->print("$actiontext
");
+ if ($env{'form.origform'} ne 'crtusername') {
+ if ($response) {
+ $r->print("\n
');
}
}
- document.cu.submit();
+ $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
}
+}
- function getIndex(caller) {
- for (var i=0;i
+
+ENDDOCUMENT
+ }
+ return $output;
+}
+
+sub user_modification_js {
+ my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
+
+ return <
");
+ } else {
+ $r->print("$lt{'usrch'}
");
+ }
+ $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
+ if ($readonly) {
+ $r->print(''.$lt{'suvr'}.'
');
+ } else {
+ $r->print(''.$lt{'usel'}.'
');
+ }
+ } elsif ($env{'form.action'} eq 'singlestudent') {
+ $r->print($jscript."");
+ if ($crstype eq 'Community') {
+ $r->print($lt{'memsrch'});
+ } else {
+ $r->print($lt{'stusrch'});
+ }
+ $r->print("
");
+ $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
+ $r->print('');
+ if ($crstype eq 'Community') {
+ $r->print($lt{'memsel'});
+ } else {
+ $r->print($lt{'stusel'});
+ }
+ $r->print('
');
+ } elsif ($env{'form.action'} eq 'accesslogs') {
+ $r->print("$lt{'srcva'}
");
+ $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
+ $r->print(''.$lt{'vacsel'}.'
');
+ }
+ }
+ $r->print('
';
+ }
+ $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 };
+ $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');
}
+ $env{'form.phase'} = '';
+ &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
+ $permission);
+ return;
}
}
}
- document.cu.submit();
+ } else {
+ $newuser = 0;
}
-
-
-ENDDOCHEAD
- $r->print(&Apache::loncommon::bodytag(
- 'Create Users, Change User Privileges',undef,$loaditem));
+ if ($response) {
+ $response = '
'.$response;
+ }
+
+ my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
+ my $dc_setcourse_code = '';
+ my $nondc_setsection_code = '';
+ my %loaditem;
+
+ 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') {
+ 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";
-
$generalrule
-$authformkrb
-$authformint
-$authformfsys
-$authformloc
-ENDNEWUSER +ENDTITLE + if ($env{'form.action'} eq 'singlestudent') { + if ($crstype eq 'Community') { + $title = &mt('Create New User [_1] in domain [_2] as a member', + '"'.$ccuname.'"','"'.$ccdomain.'"'); + } else { + $title = &mt('Create New User [_1] in domain [_2] as a student', + '"'.$ccuname.'"','"'.$ccdomain.'"'); + } + } else { + $title = &mt('Create New User [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); + } + $r->print('$lt{'fn'} | $lt{'mn'} | $lt{'ln'} | $lt{'gen'} | -
---|---|---|---|
-END - } else { - $r->print(' | '.$userenv{$_}.' | '); - } + $r->print($start_page.$forminfo); + if ($env{'form.action'} eq 'singlestudent') { + if ($crstype eq 'Community') { + $title = &mt('Enroll one member: [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); + } else { + $title = &mt('Enroll one student: [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); + } + } else { + if ($permission->{'cusr'}) { + $title = &mt('Modify existing user: [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); + } else { + $title = &mt('Existing user: [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); + } } - $r->print(<
$lt{'rev'} | $lt{'ren'} | $lt{'del'} | $lt{'rol'} | $lt{'e -xt'} | $lt{'sta'} | $lt{'end'} | -END - foreach my $type ('Construction Space','Course','Domain','System','Unknown') { - if ($output{$type}) { - $r->print($output{$type}."\n"); - } - } - $r->print('
---|
$generalrule
-$authformkrb
-$authformint
-$authformfsys
-$authformloc
-ENDBADAUTH - } else { - # This user is not allowed to modify the users - # 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(<$authformint
\n". - "$authformfsys
$authformloc
"; - } - elsif ($currentauth=~/^internal:/) { - $authformcurrent=$authformint; - $authform_other="$authformkrb
". - "$authformfsys
$authformloc
"; - } - elsif ($currentauth=~/^unix:/) { - $authformcurrent=$authformfsys; - $authform_other="$authformkrb
". - "$authformint
$authformloc;
"; - } - elsif ($currentauth=~/^localauth:/) { - $authformcurrent=$authformloc; - $authform_other="$authformkrb
". - "$authformint
$authformfsys
"; - } - $authformcurrent.=' (will override current values)$generalrule
-$authformnop
-$authformcurrent
-$lt{'act'} | $lt{'rol'} | $lt{'ext'} | -$lt{'sta'} | $lt{'end'} | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
- | $lt{'cau'} | -$cudom\_$cuname | -
+ );
+ $r->print(''.$lt{'cs'}.''."\n". + &Apache::loncommon::start_data_table()."\n". + &Apache::loncommon::start_data_table_header_row()."\n". + ' | '.$lt{'act'}.' | '.$lt{'rol'}.' | '. + ''.$lt{'ext'}.' | '.$lt{'sta'}.' | '. + ''.$lt{'end'}.' | '."\n". + &Apache::loncommon::end_data_table_header_row()."\n". + &Apache::loncommon::start_data_table_row().' ++ + | +'.$lt{'cau'}.' | +'.$cudom.'_'.$cuname.' | ++ '.$lt{'ssd'}.' | +$lt{'ssd'} | -+"javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.' | '."\n". + &Apache::loncommon::end_data_table_row()."\n". + &Apache::loncommon::start_data_table_row()."\n". +'+ | '.$lt{'caa'}.' | +'.$cudom.'_'.$cuname.' | +$lt{'sed'} | -
- | $lt{'caa'} | -$cudom\_$cuname | -+"javascript:pjump('."'date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'ssd'}.' | +$lt{'ssd'} | --$lt{'sed'} | -
'.&mt('Activate').' | '.&mt('Role').' | '.&mt('Extent').' | '. - ''.&mt('Start').' | '.&mt('End').' | '.&mt('Activate').' | '.&mt('Role').' | '. + &mt('Extent').' | '. + ''.&mt('Start').' | '.&mt('End').' | '. + &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 (@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( 'ssd' => "Set Start Date", 'sed' => "Set End Date" - ); + ); $num_domain_level ++; - $domaintext .= <<"ENDDROW"; -
---|---|---|---|---|---|---|---|---|---|
- | $plrole | -$thisdomain | -+ $domaintext .= +&Apache::loncommon::start_data_table_row(). +' | + | '.$plrole.' | +'.$thisdomain.' | +$lt{'ssd'} | -+"javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.' | +$lt{'sed'} | -
'.$authformcurrent. + ' | ||
'. + ' | '.&mt('Currently in use').' | '. + ''. + &mt('will override current values'). + ' |