--- loncom/interface/loncreateuser.pm 2006/05/18 01:08:51 1.117
+++ 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.117 2006/05/18 01:08:51 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,122 +68,1139 @@ 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);
}
+sub auth_abbrev {
+ my %abv_auth = (
+ krb5 => 'krb',
+ krb4 => 'krb',
+ internal => 'int',
+ localauth => 'loc',
+ unix => 'fsys',
+ lti => 'lti',
+ );
+ return %abv_auth;
+}
-# ======================================================= Existing Custom Roles
+# ====================================================
-sub my_custom_roles {
- my %returnhash=();
- my %rolehash=&Apache::lonnet::dump('roles');
- foreach (keys %rolehash) {
- if ($_=~/^rolesdef\_(\w+)$/) {
- $returnhash{$1}=$1;
- }
+sub user_quotas {
+ my ($ccuname,$ccdomain,$name) = @_;
+ my %lt = &Apache::lonlocal::texthash(
+ 'cust' => "Custom quota",
+ 'chqu' => "Change quota",
+ );
+ my ($output,$longinsttype);
+ my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
+ 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" ';
+ $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 .= ''."\n".
+ ' '.$titles{$name}.' '."\n".
+ ' '."\n".
+ &Apache::loncommon::start_data_table_row()."\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('Default ([_1] MB)',$defquota).' '.
+ ' '.$lt{'cust'}.': '.
+ ' '.&mt('MB').' '."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ return $output;
+}
+
+sub user_quota_js {
+ return <<"END_SCRIPT";
+
+END_SCRIPT
+
+}
+
+sub set_custom_js {
+ return <<"END_SCRIPT";
+
+
+
+END_SCRIPT
+
+}
+
+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".
+ ' '.$lt{$item}.' '."\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 = '';
+ foreach my $option (@options) {
+ my $val = $option;
+ if ($option eq 'norequest') {
+ $val = 0;
+ }
+ if ($option eq 'validate') {
+ my $canvalidate = 0;
+ if (ref($validations{$item}) eq 'HASH') {
+ if ($validations{$item}{'_custom_'}) {
+ $canvalidate = 1;
+ }
+ }
+ next if (!$canvalidate);
+ }
+ my $checked = '';
+ if ($option eq $curroption) {
+ $checked = ' checked="checked"';
+ } elsif ($option eq 'autolimit') {
+ if ($curroption =~ /^autolimit/) {
+ $checked = ' checked="checked"';
+ }
+ }
+ if ($option eq 'autolimit') {
+ $custdisp .= ' ';
+ }
+ $custdisp .= ''.
+ ' '.
+ $reqtitles{$option}.' ';
+ if ($option eq 'autolimit') {
+ $custdisp .= ' '.
+ $reqtitles{'unlimited'}.' ';
+ } else {
+ $custdisp .= ' ';
+ }
+ $custdisp .= ' ';
+ }
+ $custdisp .= '';
+ $custradio = ' '.$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'}.': '.
+ ' '.
+ $lt{'usde'}.' '.(' ' x3).
+ ' '.
+ $lt{'uscu'}.' '.
+ '';
+ foreach my $editor ('edit','xml','daxe') {
+ my $checked;
+ if ($userenv{'author'.$item} eq '') {
+ if (grep(/^\Q$editor\E$/,@defaulteditors)) {
+ $checked = ' checked="checked"';
+ }
+ } elsif (grep(/^\Q$editor\E$/,@customeditors)) {
+ $checked = ' checked="checked"';
+ }
+ $output .= ''.
+ ' '.
+ $lt{$editor}.' ';
+ }
+ $output .= ' '.
+ &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 .= ''.
+ ' "&').'"'.$checked.' />'.
+ $user.' ';
+ }
+ } 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 = ''.
+ ' '.&mt('On').' '.
+ ' '.&mt('Off').' ';
+ $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'}.': '.
+ ' '.$lt{'usde'}.' '.(' ' x3).
+ ' '.$lt{'uscu'}.' ';
+ if ($colspan) {
+ $output .= '';
+ }
+ $output .= $custradio.' '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ }
+ }
+ return $output;
+}
+
+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',
+ );
+
+ %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;
+}
+
+sub domainrole_req {
+ my ($ccuname,$ccdomain) = @_;
+ return ''.
+ &mt('Can Request Assignment of Domain Roles?').
+ ' '."\n".
+ &Apache::loncommon::start_data_table().
+ &build_tools_display($ccuname,$ccdomain,
+ 'requestauthor').
+ &Apache::loncommon::end_data_table();
+}
+
+sub authoring_defaults {
+ my ($ccuname,$ccdomain) = @_;
+ return ''.
+ &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;
}
-# ==================================================== Figure out author access
+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 authorpriv {
- my ($auname,$audom)=@_;
- unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
- || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; }
- return 1;
+}
+
+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);
+ }
+ }
+ }
+ }
+ foreach my $option (@options) {
+ if ($alltasks{$option}) {
+ $val = $option;
+ last;
+ }
+ }
+ }
+ }
+ }
+ return $val;
}
# =================================================================== Phase one
sub print_username_entry_form {
- my ($r) = @_;
+ my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
+ $permission) = @_;
my $defdom=$env{'request.role.domain'};
- my @domains = &Apache::loncommon::get_domains();
- my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
- my $selscript=&Apache::loncommon::studentbrowser_javascript();
- my $start_page =
- &Apache::loncommon::start_page('Create Users, Change User Privileges',
- $selscript);
+ 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 $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",
+ '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",
- 'usrr' => "User Roles",
- 'ecrp' => "Edit Custom Role Privileges",
- 'nr' => "Name of Role",
- 'cre' => "Custom Role Editor"
+ 'ecrp' => "Define or Edit Custom Role",
+ 'nr' => "role name",
+ 'cre' => "Next",
);
- my $help = &Apache::loncommon::help_open_menu('',undef,undef,'',282,'Instructor Interface');
- my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
- my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
- $r->print(<<"ENDDOCUMENT");
-$start_page
+
+ 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'};
+ }
+ } 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$response
".
+ ' ');
+ }
+ }
+ $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
+ }
+}
+
+sub customrole_javascript {
+ my $js = <<"END";
+
+END
+ return $js;
+}
+
+sub entry_form {
+ my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
+ my ($usertype,$inexact);
+ if (ref($srch) eq 'HASH') {
+ if (($srch->{'srchin'} eq 'dom') &&
+ ($srch->{'srchby'} eq 'uname') &&
+ ($srch->{'srchtype'} eq 'exact') &&
+ ($srch->{'srchdomain'} ne '') &&
+ ($srch->{'srchterm'} ne '')) {
+ my (%curr_rules,%got_rules);
+ my ($rules,$ruleorder) =
+ &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
+ $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
+ } else {
+ $inexact = 1;
+ }
+ }
+ my ($cancreate,$noinstd);
+ if ($env{'form.action'} eq 'accesslogs') {
+ $noinstd = 1;
+ } else {
+ $cancreate =
+ &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
+ }
+ my ($userpicker,$cansearch) =
+ &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
+ 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
+ my $srchbutton = &mt('Search');
+ if ($env{'form.action'} eq 'singlestudent') {
+ $srchbutton = &mt('Search and Enroll');
+ } elsif ($env{'form.action'} eq 'accesslogs') {
+ $srchbutton = &mt('Search');
+ } elsif ($cancreate && $responsemsg ne '' && $inexact) {
+ $srchbutton = &mt('Search or Add New User');
+ }
+ my $output;
+ if ($cansearch) {
+ $output = <<"ENDBLOCK";
+ENDBLOCK
+ } else {
+ $output = ''.$userpicker.'
';
+ }
+ if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
+ (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
+ (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
+ my $defdom=$env{'request.role.domain'};
+ my ($trusted,$untrusted);
+ if ($context eq 'course') {
+ ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
+ } elsif ($context eq 'author') {
+ ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
+ } elsif ($context eq 'domain') {
+ ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
+ }
+ my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trusted,$untrusted);
+ my %lt=&Apache::lonlocal::texthash(
+ 'enro' => 'Enroll one student',
+ 'enrm' => 'Enroll one member',
+ 'admo' => 'Add/modify a single user',
+ 'crea' => 'create new user if required',
+ 'uskn' => "username is known",
+ 'crnu' => 'Create a new user',
+ 'usr' => 'Username',
+ 'dom' => 'in domain',
+ 'enrl' => 'Enroll',
+ 'cram' => 'Create/Modify user',
+ );
+ my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
+ my ($title,$buttontext,$showresponse);
+ if ($env{'form.action'} eq 'singlestudent') {
+ if ($crstype eq 'Community') {
+ $title = $lt{'enrm'};
+ } else {
+ $title = $lt{'enro'};
+ }
+ $buttontext = $lt{'enrl'};
+ } else {
+ $title = $lt{'admo'};
+ $buttontext = $lt{'cram'};
+ }
+ if ($cancreate) {
+ $title .= ' ('.$lt{'crea'}.') ';
+ } else {
+ $title .= ' ('.$lt{'uskn'}.') ';
+ }
+ if ($env{'form.origform'} eq 'crtusername') {
+ $showresponse = $responsemsg;
+ }
+ $output .= <<"ENDDOCUMENT";
+
+
ENDDOCUMENT
- if (&Apache::lonnet::allowed('mcr','/')) {
- $r->print(<
-
-$lt{'ecrp'}$helpecpr
-$lt{'nr'}: $choice
-
-
-ENDCUSTOM
}
- $r->print(&Apache::loncommon::end_page());
+ return $output;
}
-
sub user_modification_js {
my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
return <
-
- function pclose() {
- parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
- "height=350,width=350,scrollbars=no,menubar=no");
- parmwin.close();
- }
+// 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 newseclist = document.cu.elements[i+1].value;
- var newsecs = new Array();
- if (newseclist != null && newseclist != "") {
- newsecs = newseclist.split(/,/g);
- numsec = numsec + newsecs.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 {
- for (var j=0; j
END
}
# =================================================================== Phase two
-sub print_user_modification_page {
- my $r=shift;
- my $ccuname=$env{'form.ccuname'};
- my $ccdomain=$env{'form.ccdomain'};
+sub print_user_selection_page {
+ my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
+ my @fields = ('username','domain','lastname','firstname','permanentemail');
+ my $sortby = $env{'form.sortby'};
+
+ if (!grep(/^\Q$sortby\E$/,@fields)) {
+ $sortby = 'lastname';
+ }
+
+ my ($jsback,$elements) = &crumb_utilities();
+
+ my $jscript = (<
+//
+
+ENDSCRIPT
- unless (($ccuname) && ($ccdomain)) {
- &print_username_entry_form($r);
- return;
+ my %lt=&Apache::lonlocal::texthash(
+ 'usrch' => "User Search to add/modify roles",
+ 'stusrch' => "User Search to enroll student",
+ 'memsrch' => "User Search to enroll member",
+ 'srcva' => "Search for a user and view access log information",
+ 'usrvu' => "User Search to view user roles",
+ 'usel' => "Select a user to add/modify roles",
+ 'suvr' => "Select a user to view roles",
+ 'stusel' => "Select a user to enroll as a student",
+ 'memsel' => "Select a user to enroll as a member",
+ 'vacsel' => "Select a user to view access log",
+ 'username' => "username",
+ 'domain' => "domain",
+ 'lastname' => "last name",
+ 'firstname' => "first name",
+ 'permanentemail' => "permanent e-mail",
+ );
+ if ($context eq 'requestcrs') {
+ $r->print('');
+ } else {
+ my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
+ my $helpitem;
+ if ($env{'form.action'} eq 'singleuser') {
+ $helpitem = 'Course_Change_Privileges';
+ } elsif ($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.usersrchform,'','')",
+ text => $breadcrumb_text{'search'},
+ faq => 282,
+ bug => 'Instructor Interface',},
+ {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
+ text => $breadcrumb_text{'userpicked'},
+ faq => 282,
+ bug => 'Instructor Interface',
+ help => $helpitem}
+ );
+ $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
+ if ($env{'form.action'} eq 'singleuser') {
+ my $readonly;
+ if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
+ $readonly = 1;
+ $r->print("
$lt{'usrvu'} ");
+ } 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('
');
+ } else {
+ $r->print($response.'');
+ }
+}
- my $defdom=$env{'request.role.domain'};
-
- my ($krbdef,$krbdefdom) =
- &Apache::loncommon::get_kerberos_defaults($defdom);
+sub print_user_query_page {
+ 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.
+ return;
+}
- 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 print_user_modification_page {
+ 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.');
+ $env{'form.phase'} = '';
+ &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
+ $permission);
+ return;
+ }
+ my ($form,$formname);
+ if ($env{'form.action'} eq 'singlestudent') {
+ $form = 'document.enrollstudent';
+ $formname = 'enrollstudent';
+ } else {
+ $form = 'document.cu';
+ $formname = 'cu';
+ }
+ my %abv_auth = &auth_abbrev();
+ my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
+ my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
+ if ($uhome eq 'no_host') {
+ my $usertype;
+ my ($rules,$ruleorder) =
+ &Apache::lonnet::inst_userrules($ccdomain,'username');
+ $usertype =
+ &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
+ \%curr_rules,\%got_rules);
+ my $cancreate =
+ &Apache::lonuserutils::can_create_user($ccdomain,$context,
+ $usertype);
+ if (!$cancreate) {
+ my $helplink = 'javascript:helpMenu('."'display'".')';
+ my %usertypetext = (
+ official => 'institutional',
+ unofficial => 'non-institutional',
+ );
+ my $response;
+ if ($env{'form.origform'} eq 'crtusername') {
+ $response = ''.
+ &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
+ ''.$ccuname.' ',$ccdomain).
+ ' ';
+ }
+ $response .= ''
+ .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
+ .' ';
+ if ($context eq 'domain') {
+ $response .= &mt('Please contact a [_1] for assistance.',
+ &Apache::lonnet::plaintext('dc'));
+ } else {
+ $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
+ ,'',' ');
+ }
+ $response .= '
';
+ $env{'form.phase'} = '';
+ &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
+ $permission);
+ return;
+ }
+ $newuser = 1;
+ my $checkhash;
+ my $checks = { 'username' => 1 };
+ $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;
+ }
+ }
+ }
+ } else {
+ $newuser = 0;
+ }
+ if ($response) {
+ $response = ' '.$response;
+ }
- $ccuname=~s/\W//g;
- $ccdomain=~s/\W//g;
my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
my $dc_setcourse_code = '';
- my $nondc_setsection_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\./(\w+)/$-) {
- my $dcdom = $1;
- $loaditem{'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;
- var newsecs = new Array();
- for (var i=0; i "javascript:backPage($form)",
+ text => $breadcrumb_text{'search'},
+ faq => 282,
+ bug => 'Instructor Interface',});
+ if ($env{'form.phase'} eq 'userpicked') {
+ push(@{$brcrum},
+ {href => "javascript:backPage($form,'get_user_info','select')",
+ text => $breadcrumb_text{'userpicked'},
+ faq => 282,
+ bug => 'Instructor Interface',});
+ }
+ push(@{$brcrum},
+ {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
+ text => $breadcrumb_text{'modify'},
+ faq => 282,
+ bug => 'Instructor Interface',
+ help => $helpitem});
+ my $args = {'add_entries' => \%loaditem,
+ 'bread_crumbs' => $brcrum,
+ 'bread_crumbs_component' => 'User Management'};
+ if ($env{'form.popup'}) {
+ $args->{'no_nav_bar'} = 1;
+ $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;
+}
- 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;
- if (newsecs != null && newsecs != "") {
- var 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 {
- for (var j=0; j'.&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 $start_page =
- &Apache::loncommon::start_page('Create Users, Change User Privileges',
- $js,{'add_entries' => \%loaditem,});
+ my ($jsback,$elements) = &crumb_utilities();
+ $js .= "\n".
+ ''."\n";
+ return $js;
+}
- my $forminfo =<<"ENDFORMINFO";
-
-$lt{'hs'}: $home_server_list
-
-$lt{'lg'}
-$generalrule
-$authformkrb
-$authformint
-$authformfsys
-$authformloc
-ENDNEWUSER
- } else { # user already exists
- my %lt=&Apache::lonlocal::texthash(
- 'cup' => "Change User Privileges",
- 'usr' => "User",
- 'id' => "in domain",
- 'fn' => "first name",
- 'mn' => "middle name",
- 'ln' => "last name",
- 'gen' => "generation"
- );
- $r->print(<$lt{'cup'}
-$forminfo
-$lt{'usr'} "$ccuname" $lt{'id'} "$ccdomain"
-ENDCHANGEUSER
- # Get the users information
- my %userenv = &Apache::lonnet::get('environment',
- ['firstname','middlename','lastname','generation'],
- $ccdomain,$ccuname);
- my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
- $r->print(<
-
-END
- # 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=~/^cr\/(\w+)\/(\w+)\/(\w+)$/);
- my $bgcol='ffffff';
- my $allowed=0;
- my $delallowed=0;
- my $sortkey=$role_code;
- my $class='Unknown';
- if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
- $class='Course';
- my ($coursedom,$coursedir) = ($1,$2);
- $sortkey.="\0$1";
- # $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'};
- } else {
- $carea=&mt('Unavailable course').': '.$area;
- $sortkey.="\0".&mt('Unavailable course').': '.$area;
- }
- $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
- $bgcol=$1.'_'.$2;
- $bgcol=~s/[^7-9a-e]//g;
- $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',2,6);
- if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
- $carea.=' Section: '.$3;
- $sortkey.="\0$3";
- }
- $area=$carea;
- } else {
- $sortkey.="\0".$area;
- # Determine if current user is able to revoke privileges
- if ($area=~ /^\/(\w+)\//) {
- 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=~/\/(\w+)\/(\w+)/;
- if (&authorpriv($2,$1)) {
- $allowed=1;
- } else {
- $allowed=0;
- }
- }
- $bgcol='77FF77';
- 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.=' ';
- if ($allowed && !$active) {
- $row.= ' ';
- } else {
- $row.=' ';
- }
- $row.=' ';
- if ($delallowed) {
- $row.= ' ';
- } else {
- $row.=' ';
- }
- my $plaintext='';
- unless ($croletitle) {
- $plaintext=&Apache::lonnet::plaintext($role_code);
- } else {
- $plaintext=
- "Customrole '$croletitle' defined by $croleuname\@$croleudom";
- }
- $row.= ' '.$plaintext.
- ' '.$area.
- ' '.($role_start_time?localtime($role_start_time)
- : ' ' ).
- ' '.($role_end_time ?localtime($role_end_time)
- : ' ' )
- ." \n";
- $sortrole{$sortkey}=$envkey;
- $roletext{$envkey}=$row;
- $roleclass{$envkey}=$class;
- $rolepriv{$envkey}=$allowed;
- #$r->print($row);
- } # end of foreach (table building loop)
- my $rolesdisplay = 0;
- my %output = ();
- foreach my $type ('Construction Space','Course','Domain','System','Unknown') {
- $output{$type} = '';
- foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
- if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
- $output{$type}.=$roletext{$sortrole{$which}};
- }
- }
- unless($output{$type} eq '') {
- $output{$type} = "".
- "".&mt($type)." ".
- $output{$type};
- $rolesdisplay = 1;
- }
- }
- if ($rolesdisplay == 1) {
- $r->print(<
-$lt{'rer'}
-
-$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('
');
- }
- } # 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',$env{'request.role.domain'})) {
- &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 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(<
-
- $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="$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) ';
- if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
- # 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
+ 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;
+ }
+ }
+ }
}
- } ## End of "check for bad authentication type" logic
- } ## End of new user/old user logic
- $r->print(''.&mt('Add Roles').' ');
-#
-# Co-Author
-#
- if (&authorpriv($env{'user.name'},$env{'request.role.domain'}) &&
- ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $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;
+ }
+ }
+ if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
+ $class='Authoring 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 (&Apache::lonuserutils::authorpriv($2,$1)) {
+ $allowed=1;
+ } elsif (&Apache::lonuserutils::coauthorpriv($2,$1)) {
+ $allowed=1;
+ } else {
+ $allowed=0;
+ }
+ }
+ my $row = '';
+ if ($showall) {
+ $row.= '';
+ if (($active) && ($allowed)) {
+ $row.= ' ';
+ } else {
+ if ($active) {
+ $row.=' ';
+ } else {
+ $row.=&mt('expired or revoked');
+ }
+ }
+ $row.=' ';
+ if ($allowed && !$active) {
+ $row.= ' ';
+ } else {
+ $row.=' ';
+ }
+ $row.=' ';
+ if ($delallowed) {
+ $row.= ' ';
+ } else {
+ $row.=' ';
+ }
+ $row.= ' ';
+ }
+ my $plaintext='';
+ if (!$croletitle) {
+ $plaintext=&Apache::lonnet::plaintext($role_code,$class);
+ if (($showcredits) && ($credits ne '')) {
+ $plaintext .= ''.
+ ''.
+ &mt('Credits: [_1]',$credits).
+ ' ';
+ }
+ } else {
+ $plaintext=
+ &mt('Custom role [_1][_2]defined by [_3]',
+ '"'.$croletitle.'"',
+ ' ',
+ $croleuname.':'.$croleudom);
+ }
+ $row.= ''.$plaintext.' '.
+ ''.$area.' '.
+ ''.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
+ : ' ' ).' '.
+ ''.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
+ : ' ' ).' ';
+ $sortrole{$sortkey}=$envkey;
+ $roletext{$envkey}=$row;
+ $roleclass{$envkey}=$class;
+ if ($allowed) {
+ $rolepriv{$envkey}='edit';
+ } else {
+ if ($context eq 'domain') {
+ if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
+ ($envkey=~m{^/$ccdomain/})) {
+ $rolepriv{$envkey}='view';
+ }
+ } elsif ($context eq 'course') {
+ if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
+ ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
+ &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
+ $rolepriv{$envkey}='view';
+ }
+ }
+ }
+ } # end of foreach (table building loop)
+
+ my $rolesdisplay = 0;
+ my %output = ();
+ foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
+ $output{$type} = '';
+ foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
+ if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
+ $output{$type}.=
+ &Apache::loncommon::start_data_table_row().
+ $roletext{$sortrole{$which}}.
+ &Apache::loncommon::end_data_table_row();
+ }
+ }
+ unless($output{$type} eq '') {
+ $output{$type} = ' '.
+ "".&mt($type)." ".
+ $output{$type};
+ $rolesdisplay = 1;
+ }
+ }
+ if ($rolesdisplay == 1) {
+ my $contextrole='';
+ if ($env{'request.course.id'}) {
+ if (&Apache::loncommon::course_type() eq 'Community') {
+ $contextrole = &mt('Existing Roles in this Community');
+ } else {
+ $contextrole = &mt('Existing Roles in this Course');
+ }
+ } elsif ($env{'request.role'} =~ /^au\./) {
+ $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
+ } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)/$}) {
+ $contextrole = &mt('Existing Co-Author Roles in [_1] Authoring Space',
+ ''.$1.'_'.$2.' ');
+ } else {
+ if ($showall) {
+ $contextrole = &mt('Existing Roles in this Domain');
+ } elsif ($showactive) {
+ $contextrole = &mt('Unexpired Roles in this Domain');
+ } elsif ($showexpired) {
+ $contextrole = &mt('Expired or Revoked Roles in this Domain');
+ }
+ }
+ $r->print(''.
+'
'.$contextrole.' '.
+&Apache::loncommon::start_data_table("LC_createuser").
+&Apache::loncommon::start_data_table_header_row());
+ if ($showall) {
+ $r->print(
+''.$lt{'rev'}.' '.$lt{'ren'}.' '.$lt{'del'}.' '
+ );
+ } elsif ($showexpired) {
+ $r->print(''.$lt{'rev'}.' ');
+ }
+ $r->print(
+''.$lt{'rol'}.' '.$lt{'ext'}.' '.
+''.$lt{'sta'}.' '.$lt{'end'}.' '.
+&Apache::loncommon::end_data_table_header_row());
+ foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
+ if ($output{$type}) {
+ $r->print($output{$type}."\n");
+ }
+ }
+ $r->print(&Apache::loncommon::end_data_table().
+ ' ');
+ }
+ return;
+}
+
+sub new_coauthor_roles {
+ my ($r,$ccuname,$ccdomain) = @_;
+ my $addrolesdisplay = 0;
+ #
+ # Co-Author
+ #
+ my ($cuname,$cudom);
+ if (($env{'request.role'} eq "au./$env{'user.domain'}/") ||
+ ($env{'request.role'} eq "dc./$env{'user.domain'}/")) {
+ $cuname=$env{'user.name'};
+ $cudom=$env{'request.role.domain'};
# No sense in assigning co-author role to yourself
- my $cuname=$env{'user.name'};
- my $cudom=$env{'request.role.domain'};
- my %lt=&Apache::lonlocal::texthash(
- 'cs' => "Construction Space",
- 'act' => "Activate",
+ if ((&Apache::lonuserutils::authorpriv($cuname,$cudom)) &&
+ ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
+ $addrolesdisplay = 1;
+ }
+ } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
+ ($cudom,$cuname) = ($1,$2);
+ if ((&Apache::lonuserutils::coauthorpriv($cuname,$cudom)) &&
+ ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain) &&
+ ($cudom ne $ccdomain || $cuname ne $ccuname)) {
+ $addrolesdisplay = 1;
+ }
+ }
+ if ($addrolesdisplay) {
+ my %lt=&Apache::lonlocal::texthash(
+ 'cs' => "Authoring Space",
+ 'act' => "Activate",
'rol' => "Role",
'ext' => "Extent",
'sta' => "Start",
@@ -906,132 +2416,825 @@ ENDOTHERAUTHS
'caa' => "Assistant Co-Author",
'ssd' => "Set Start Date",
'sed' => "Set End Date"
- );
- $r->print(<$lt{'cs'}
-$lt{'act'} $lt{'rol'} $lt{'ext'}
-$lt{'sta'} $lt{'end'}
-
-
-$lt{'cau'}
-$cudom\_$cuname
-
-$lt{'ssd'}
-
+ );
+ $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{'sed'}
-
-
-
-$lt{'caa'}
-$cudom\_$cuname
-
+"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{'ssd'}
-
+"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{'sed'}
-
-
-ENDCOAUTH
+"javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.''."\n".
+ &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 =
''.&mt('Domain Level').' '.
- ''.&mt('Activate').' '.&mt('Role').' '.&mt('Extent').' '.
- ''.&mt('Start').' '.&mt('End').' ';
- foreach ( sort( keys(%incdomains))) {
- my $thisdomain=$_;
- foreach ('dc','li','dg','au','sc') {
- if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
- my $plrole=&Apache::lonnet::plaintext($_);
- my %lt=&Apache::lonlocal::texthash(
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ ''.&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'}
-
-ENDDROW
+"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.='
';
+ $domaintext.= &Apache::loncommon::end_data_table();
if ($num_domain_level > 0) {
$r->print($domaintext);
+ $addrolesdisplay = 1;
}
-#
-# Course level
-#
+ 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".
+ ''.$lt{'ld'}.' '.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_row().
+ ''.$authformnop;
+ if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
+ $outcome .= ' '."\n".
+ &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::start_data_table_row().
+ ''.$authformcurrent.' '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ } else {
+ $outcome .= ' ('.$authformcurrent.')'.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ if (&Apache::lonnet::allowed('mau',$ccdomain)) {
+ foreach my $item (@authform_others) {
+ $outcome .= &Apache::loncommon::start_data_table_row().
+ ''.$item.' '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ }
+ $outcome .= &Apache::loncommon::end_data_table();
+ } else {
+ if (($currentauth =~ /^internal:/) &&
+ (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
+ $outcome = <<"ENDJS";
+
+ENDJS
+
+ $outcome .= ''.$lt{'ld'}.' '.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_row().
+ ''.&mt('Internally authenticated').' '.&mt("Change user's password?").
+ ' '.
+ &mt('No').' '.(' 'x2).
+ ' '.&mt('Yes').' '.
+ ''.
+ ' '.&mt('Password').' '.
+ ' '.&mt('Visible input').'
'.
+ &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::end_data_table();
+ }
+ if (&Apache::lonnet::allowed('udp',$ccdomain)) {
+ # Current user has rights to view domain preferences for user's domain
+ my $result;
+ if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
+ my ($krbver,$krbrealm) = ($1,$2);
+ if ($krbrealm eq '') {
+ $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
+ } else {
+ $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
+ $krbrealm,$krbver);
+ }
+ } elsif ($currentauth =~ /^internal:/) {
+ $result = &mt('Currently internally authenticated.');
+ } elsif ($currentauth =~ /^localauth:/) {
+ $result = &mt('Currently using local (institutional) authentication.');
+ } elsif ($currentauth =~ /^unix:/) {
+ $result = &mt('Currently Filesystem Authenticated.');
+ } elsif ($currentauth =~ /^lti:/) {
+ $result = &mt('Currently LTI authenticated.');
+ }
+ $outcome = ''.$lt{'ld'}.' '.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_row().
+ ''.$result.' '.
+ &Apache::loncommon::end_data_table_row()."\n".
+ &Apache::loncommon::end_data_table();
+ } elsif (&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",
+ );
+ $outcome .= <$lt{'ccld'}
+$lt{'yodo'} $lt{'ifch'}: $ccdomain
+
+ENDNOPRIV
+ }
+ }
+ } ## End of "check for bad authentication type" logic
+ return $outcome;
+}
+
+sub modify_login_block {
+ my ($dom,$currentauth) = @_;
+ my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
+ my ($authnum,%can_assign) =
+ &Apache::loncommon::get_assignable_auth($dom);
+ my ($authformcurrent,@authform_others,$show_override_msg);
+ if ($currentauth=~/^krb(4|5):/) {
+ $authformcurrent=$authformkrb;
+ if ($can_assign{'int'}) {
+ push(@authform_others,$authformint);
+ }
+ if ($can_assign{'loc'}) {
+ push(@authform_others,$authformloc);
+ }
+ if ($can_assign{'lti'}) {
+ push(@authform_others,$authformlti);
+ }
+ if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
+ $show_override_msg = 1;
+ }
+ } elsif ($currentauth=~/^internal:/) {
+ $authformcurrent=$authformint;
+ if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
+ push(@authform_others,$authformkrb);
+ }
+ if ($can_assign{'loc'}) {
+ push(@authform_others,$authformloc);
+ }
+ if ($can_assign{'lti'}) {
+ push(@authform_others,$authformlti);
+ }
+ if ($can_assign{'int'}) {
+ $show_override_msg = 1;
+ }
+ } elsif ($currentauth=~/^unix:/) {
+ $authformcurrent=$authformfsys;
+ if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
+ push(@authform_others,$authformkrb);
+ }
+ if ($can_assign{'int'}) {
+ push(@authform_others,$authformint);
+ }
+ if ($can_assign{'loc'}) {
+ push(@authform_others,$authformloc);
+ }
+ if ($can_assign{'lti'}) {
+ push(@authform_others,$authformlti);
+ }
+ if ($can_assign{'fsys'}) {
+ $show_override_msg = 1;
+ }
+ } elsif ($currentauth=~/^localauth:/) {
+ $authformcurrent=$authformloc;
+ if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
+ push(@authform_others,$authformkrb);
+ }
+ if ($can_assign{'int'}) {
+ push(@authform_others,$authformint);
+ }
+ if ($can_assign{'lti'}) {
+ push(@authform_others,$authformlti);
+ }
+ if ($can_assign{'loc'}) {
+ $show_override_msg = 1;
+ }
+ } elsif ($currentauth=~/^lti:/) {
+ $authformcurrent=$authformlti;
+ if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
+ push(@authform_others,$authformkrb);
+ }
+ if ($can_assign{'int'}) {
+ push(@authform_others,$authformint);
+ }
+ if ($can_assign{'loc'}) {
+ push(@authform_others,$authformloc);
+ }
+ }
+ if ($show_override_msg) {
+ $authformcurrent = ''.$authformcurrent.
+ ' '."\n".
+ ' '.
+ ''.&mt('Currently in use').' '.
+ ''.
+ &mt('will override current values').
+ '
';
+ }
+ return ($authformcurrent,$show_override_msg,@authform_others);
+}
+
+sub personal_data_display {
+ my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$readonly,$rolesarray,$now,
+ $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
+ my ($output,%userenv,%canmodify,%canmodify_status,$disabled);
+ my @userinfo = ('firstname','middlename','lastname','generation',
+ 'permanentemail','id');
+ my $rowcount = 0;
+ my $editable = 0;
+ my %textboxsize = (
+ firstname => '15',
+ middlename => '15',
+ lastname => '15',
+ generation => '5',
+ permanentemail => '25',
+ id => '15',
+ );
- if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
- $r->print(&course_level_dc($1));
- $r->print(' '."\n");
+ my %lt=&Apache::lonlocal::texthash(
+ 'pd' => "Personal Data",
+ 'firstname' => "First Name",
+ 'middlename' => "Middle Name",
+ 'lastname' => "Last Name",
+ 'generation' => "Generation",
+ 'permanentemail' => "Permanent e-mail address",
+ 'id' => "Student/Employee ID",
+ 'lg' => "Login Data",
+ 'inststatus' => "Affiliation",
+ 'email' => 'E-mail address',
+ 'valid' => 'Validation',
+ 'username' => 'Username',
+ );
+
+ %canmodify_status =
+ &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
+ ['inststatus'],$rolesarray);
+ if (!$newuser) {
+ # Get the users information
+ %userenv = &Apache::lonnet::get('environment',
+ ['firstname','middlename','lastname','generation',
+ 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
+ %canmodify =
+ &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
+ \@userinfo,$rolesarray);
+ } elsif ($context eq 'selfcreate') {
+ if ($newuser eq 'email') {
+ if (ref($emailusername) eq 'HASH') {
+ if (ref($emailusername->{$usertype}) eq 'HASH') {
+ my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
+ @userinfo = ();
+ if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
+ foreach my $field (@{$infofields}) {
+ if ($emailusername->{$usertype}->{$field}) {
+ push(@userinfo,$field);
+ $canmodify{$field} = 1;
+ unless ($textboxsize{$field}) {
+ $textboxsize{$field} = 25;
+ }
+ unless ($lt{$field}) {
+ $lt{$field} = $infotitles->{$field};
+ }
+ if ($emailusername->{$usertype}->{$field} eq 'required') {
+ $lt{$field} .= '* ';
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
+ $inst_results,$rolesarray);
+ }
+ } elsif ($readonly) {
+ $disabled = ' disabled="disabled"';
+ }
+
+ my $genhelp=&Apache::loncommon::help_open_topic('Generation');
+ $output = ''.$lt{'pd'}.' '.
+ &Apache::lonhtmlcommon::start_pick_box();
+ if (($context eq 'selfcreate') && ($newuser eq 'email')) {
+ my $size = 25;
+ if ($condition) {
+ if ($condition =~ /^\@[^\@]+$/) {
+ $size = 10;
+ } else {
+ undef($condition);
+ }
+ }
+ if ($excluded) {
+ unless ($excluded =~ /^\@[^\@]+$/) {
+ undef($condition);
+ }
+ }
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'* ',undef,
+ 'LC_oddrow_value')."\n".
+ ' ';
+ if ($condition) {
+ $output .= $condition;
+ } elsif ($excluded) {
+ $output .= ''.&mt('You must use an e-mail address that does not end with [_1]',
+ $excluded).' ';
+ }
+ if ($usernameset eq 'first') {
+ $output .= '';
+ if ($condition) {
+ $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
+ $condition);
+ } else {
+ $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
+ }
+ $output .= ' ';
+ }
+ $rowcount ++;
+ $output .= &Apache::lonhtmlcommon::row_closure(1);
+ my $upassone = ' ';
+ my $upasstwo = ' ';
+ $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'* ',
+ 'LC_pick_box_title',
+ 'LC_oddrow_value')."\n".
+ $upassone."\n".
+ &Apache::lonhtmlcommon::row_closure(1)."\n".
+ &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'* ',
+ 'LC_pick_box_title',
+ 'LC_oddrow_value')."\n".
+ $upasstwo.
+ &Apache::lonhtmlcommon::row_closure()."\n";
+ if ($usernameset eq 'free') {
+ my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
+ ''.&mt('Use e-mail address: ').
+ ' '.
+ &mt('Yes').' '.(' 'x2).
+ ' '.
+ &mt('No').' '."\n".
+ ''.
+ ''.&mt('Preferred username').
+ ' '.
+ '
'."\n".&Apache::lonhtmlcommon::row_closure(1);
+ $rowcount ++;
+ }
+ }
+ my %shownfields;
+ if ($env{'request.role.domain'} ne $ccdomain) {
+ my %shownfields_by_type =
+ &Apache::lonuserutils::get_othdom_shownfields($ccdomain,\@userinfo);
+ my @types = split(/:/,$userenv{'inststatus'});
+ if (@types == 0) {
+ @types = ('default');
+ }
+ foreach my $type (@types) {
+ if (ref($shownfields_by_type{$type}) eq 'HASH') {
+ foreach my $field (keys(%{$shownfields_by_type{$type}})) {
+ if ($shownfields_by_type{$type}{$field}) {
+ $shownfields{$field} = 1;
+ }
+ }
+ }
+ }
+ }
+ foreach my $item (@userinfo) {
+ my $rowtitle = $lt{$item};
+ my $hiderow = 0;
+ if ($item eq 'generation') {
+ $rowtitle = $genhelp.$rowtitle;
+ }
+ my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
+ if ($newuser) {
+ if (ref($inst_results) eq 'HASH') {
+ if ($inst_results->{$item} ne '') {
+ $row .= ' '.$inst_results->{$item};
+ } else {
+ if ($context eq 'selfcreate') {
+ if ($canmodify{$item}) {
+ $row .= ' ';
+ $editable ++;
+ } else {
+ $hiderow = 1;
+ }
+ } else {
+ $row .= ' ';
+ }
+ }
+ } else {
+ if ($context eq 'selfcreate') {
+ if ($canmodify{$item}) {
+ if ($newuser eq 'email') {
+ $row .= ' ';
+ } else {
+ $row .= ' ';
+ }
+ $editable ++;
+ } else {
+ $hiderow = 1;
+ }
+ } else {
+ $row .= ' ';
+ }
+ }
+ } else {
+ if ($canmodify{$item}) {
+ $row .= ' ';
+ if (($item eq 'id') && (!$newuser)) {
+ $row .= ' '.&Apache::lonuserutils::forceid_change($context);
+ }
+ } else {
+ if ($env{'request.role.domain'} ne $ccdomain) {
+ if ($shownfields{$item}) {
+ $row .= $userenv{$item};
+ } else {
+ $row .= &mt('not shown');
+ }
+ } else {
+ $row .= $userenv{$item};
+ }
+ }
+ }
+ $row .= &Apache::lonhtmlcommon::row_closure(1);
+ if (!$hiderow) {
+ $output .= $row;
+ $rowcount ++;
+ }
+ }
+ if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
+ if (ref($types) eq 'ARRAY') {
+ if (@{$types} > 0) {
+ my ($hiderow,$shown);
+ if ($canmodify_status{'inststatus'}) {
+ $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
+ } else {
+ if ($userenv{'inststatus'} eq '') {
+ $hiderow = 1;
+ } else {
+ my @showitems;
+ foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
+ if (exists($usertypes->{$item})) {
+ push(@showitems,$usertypes->{$item});
+ } else {
+ push(@showitems,$item);
+ }
+ }
+ if (@showitems) {
+ $shown = join(', ',@showitems);
+ } else {
+ $hiderow = 1;
+ }
+ }
+ }
+ if (!$hiderow) {
+ my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
+ $shown.&Apache::lonhtmlcommon::row_closure(1);
+ if ($context eq 'selfcreate') {
+ $rowcount ++;
+ }
+ $output .= $row;
+ }
+ }
+ }
+ }
+ if (($context eq 'selfcreate') && ($newuser eq 'email')) {
+ if ($captchaform) {
+ $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
+ 'LC_pick_box_title')."\n".
+ $captchaform."\n".' '.
+ &Apache::lonhtmlcommon::row_closure(1);
+ $rowcount ++;
+ }
+ if ($showsubmit) {
+ my $submit_text = &mt('Create account');
+ $output .= &Apache::lonhtmlcommon::row_title()."\n".
+ ' ';
+ if ($usertype ne '') {
+ $output .= ' ';
+ }
+ $output .= &Apache::lonhtmlcommon::row_closure(1);
+ }
+ }
+ $output .= &Apache::lonhtmlcommon::end_pick_box();
+ if (wantarray) {
+ if ($context eq 'selfcreate') {
+ return($output,$rowcount,$editable);
+ } else {
+ return $output;
+ }
} else {
- $r->print(&course_level_table(%inccourses));
- $r->print(' '."\n");
+ return $output;
}
- $r->print("".&Apache::loncommon::end_page());
+}
+
+sub pick_inst_statuses {
+ my ($curr,$usertypes,$types) = @_;
+ my ($output,$rem,@currtypes);
+ if ($curr ne '') {
+ @currtypes = map { &unescape($_); } split(/:/,$curr);
+ }
+ my $numinrow = 2;
+ if (ref($types) eq 'ARRAY') {
+ $output = '';
+ }
+ 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=shift;
+ 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';
}
- $r->print(&Apache::loncommon::start_page($title));
- my %disallowed;
+ my $newuser = 0;
+ my ($jsback,$elements) = &crumb_utilities();
+ my $jscript = ''."\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') {
+ 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'} =~/\W/) {
- $r->print($error.&mt('Invalid login name').'. '.
- &mt('Only letters, numbers, and underscores are valid').'.'.
- $end);
+ 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.$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'} =~/\W/) {
- $r->print($error.&mt ('Invalid domain name').'. '.
- &mt('Only letters, numbers, and underscores are valid').'.'.
- $end);
+ 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.$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;
}
}
@@ -1052,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
@@ -1059,21 +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'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
+ $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).' ');
+ my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
+
+ my (%alerts,%rulematch,%inst_results,%curr_rules);
+ my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
+ my @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
+ my @requestcourses = ('official','unofficial','community','textbook','placement','lti');
+ my @requestauthor = ('requestauthor');
+ my @authordefaults = ('webdav','editors','archive');
+ my ($othertitle,$usertypes,$types) =
+ &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
+ my %canmodify_status =
+ &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
+ ['inststatus']);
if ($env{'form.makeuser'}) {
- # Create a new user
- my %lt=&Apache::lonlocal::texthash(
- 'cru' => "Creating user",
- 'id' => "in domain"
- );
- $r->print(<$lt{'cru'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"
-ENDNEWUSERHEAD
+ $r->print(''.&mt('Creating new account.').' ');
# Check for the authentication mode and password
if (! $amode || ! $genpwd) {
- $r->print($error.&mt('Invalid login mode or password').$end);
+ $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
return;
}
# Determine desired host
@@ -1081,238 +3297,1587 @@ ENDNEWUSERHEAD
if (lc($desiredhost) eq 'default') {
$desiredhost = undef;
} else {
- my %home_servers = &Apache::loncommon::get_library_servers
- ($env{'form.ccdomain'});
+ my %home_servers =
+ &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
if (! exists($home_servers{$desiredhost})) {
- $r->print($error.&mt('Invalid home server specified'));
+ $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
return;
}
}
+ # Check ID format
+ my %checkhash;
+ my %checks = ('id' => 1);
+ %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
+ 'newuser' => $newuser,
+ 'id' => $env{'form.cid'},
+ );
+ if ($env{'form.cid'} ne '') {
+ &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
+ \%rulematch,\%inst_results,\%curr_rules);
+ if (ref($alerts{'id'}) eq 'HASH') {
+ if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
+ my $domdesc =
+ &Apache::lonnet::domain($env{'form.ccdomain'},'description');
+ if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
+ my $userchkmsg;
+ if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
+ $userchkmsg =
+ &Apache::loncommon::instrule_disallow_msg('id',
+ $domdesc,1).
+ &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
+ $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
+ }
+ $r->print($error.&mt('Invalid ID format').$end.
+ $userchkmsg.$rtnlink);
+ return;
+ }
+ }
+ }
+ }
+ &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
# Call modifyuser
my $result = &Apache::lonnet::modifyuser
- ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cstid'},
- $amode,$genpwd,$env{'form.cfirst'},
- $env{'form.cmiddle'},$env{'form.clast'},$env{'form.cgen'},
- undef,$desiredhost
- );
+ ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
+ $amode,$genpwd,$env{'form.cfirstname'},
+ $env{'form.cmiddlename'},$env{'form.clastname'},
+ $env{'form.cgeneration'},undef,$desiredhost,
+ $env{'form.cpermanentemail'});
$r->print(&mt('Generating user').': '.$result);
- my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
+ $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
$env{'form.ccdomain'});
- $r->print(' '.&mt('Home server').': '.$home.' '.
- $Apache::lonnet::libserv{$home});
+ my (%changeHash,%newcustom,%changed,%changedinfo);
+ if ($uhome ne 'no_host') {
+ if ($context eq 'domain') {
+ foreach my $name ('portfolio','author') {
+ if ($env{'form.custom_'.$name.'quota'} == 1) {
+ if ($env{'form.'.$name.'quota'} eq '') {
+ $newcustom{$name.'quota'} = 0;
+ } else {
+ $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
+ $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
+ }
+ if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
+ $changed{$name.'quota'} = 1;
+ }
+ }
+ }
+ foreach my $item (@usertools) {
+ if ($env{'form.custom'.$item} == 1) {
+ $newcustom{$item} = $env{'form.tools_'.$item};
+ $changed{$item} = &tool_admin($item,$newcustom{$item},
+ \%changeHash,'tools');
+ }
+ }
+ foreach my $item (@requestcourses) {
+ if ($env{'form.custom'.$item} == 1) {
+ $newcustom{$item} = $env{'form.crsreq_'.$item};
+ if ($env{'form.crsreq_'.$item} eq 'autolimit') {
+ $newcustom{$item} .= '=';
+ $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
+ if ($env{'form.crsreq_'.$item.'_limit'}) {
+ $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
+ }
+ }
+ $changed{$item} = &tool_admin($item,$newcustom{$item},
+ \%changeHash,'requestcourses');
+ }
+ }
+ if ($env{'form.customrequestauthor'} == 1) {
+ $newcustom{'requestauthor'} = $env{'form.requestauthor'};
+ $changed{'requestauthor'} = &tool_admin('requestauthor',
+ $newcustom{'requestauthor'},
+ \%changeHash,'requestauthor');
+ }
+ if ($env{'form.customeditors'} == 1) {
+ my @editors;
+ my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
+ if (@posseditors) {
+ foreach my $editor (@posseditors) {
+ if (grep(/^\Q$editor\E$/,@posseditors)) {
+ unless (grep(/^\Q$editor\E$/,@editors)) {
+ push(@editors,$editor);
+ }
+ }
+ }
+ }
+ if (@editors) {
+ @editors = sort(@editors);
+ $changed{'editors'} = &tool_admin('editors',join(',',@editors),
+ \%changeHash,'authordefaults');
+ }
+ }
+ if ($env{'form.customwebdav'} == 1) {
+ $newcustom{'webdav'} = $env{'form.authordefaults_webdav'};
+ $changed{'webdav'} = &tool_admin('webdav',$newcustom{'webdav'},
+ \%changeHash,'authordefaults');
+ }
+ if ($env{'form.customarchive'} == 1) {
+ $newcustom{'archive'} = $env{'form.authordefaults_archive'};
+ $changed{'archive'} = &tool_admin('archive',$newcustom{'archive'},
+ \%changeHash,'authordefaults');
+
+ }
+ }
+ if ($canmodify_status{'inststatus'}) {
+ if (exists($env{'form.inststatus'})) {
+ my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
+ if (@inststatuses > 0) {
+ $changeHash{'inststatus'} = join(',',@inststatuses);
+ $changed{'inststatus'} = $changeHash{'inststatus'};
+ }
+ }
+ }
+ if (keys(%changed)) {
+ foreach my $item (@userinfo) {
+ $changeHash{$item} = $env{'form.c'.$item};
+ }
+ my $chgresult =
+ &Apache::lonnet::put('environment',\%changeHash,
+ $env{'form.ccdomain'},$env{'form.ccuname'});
+ }
+ }
+ $r->print(' '.&mt('Home Server').': '.$uhome.' '.
+ &Apache::lonnet::hostname($uhome));
} elsif (($env{'form.login'} ne 'nochange') &&
($env{'form.login'} ne '' )) {
# Modify user privileges
- my %lt=&Apache::lonlocal::texthash(
- 'usr' => "User",
- 'id' => "in domain"
- );
- $r->print(<$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"
-ENDMODIFYUSERHEAD
if (! $amode || ! $genpwd) {
- $r->print($error.'Invalid login mode or password'.$end);
+ $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
return;
}
- # Only allow authentification modification if the person has authority
+ # Only allow authentication modification if the person has authority
if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
$r->print('Modifying authentication: '.
&Apache::lonnet::modifyuserauth(
$env{'form.ccdomain'},$env{'form.ccuname'},
$amode,$genpwd));
- $r->print(' '.&mt('Home server').': '.&Apache::lonnet::homeserver
+ $r->print(' '.&mt('Home Server').': '.&Apache::lonnet::homeserver
($env{'form.ccuname'},$env{'form.ccdomain'}));
} else {
# Okay, this is a non-fatal error.
- $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');
+ $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
}
+ } elsif (($env{'form.intarg'} ne '') &&
+ (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
+ (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
+ $r->print('Modifying authentication: '.
+ &Apache::lonnet::modifyuserauth(
+ $env{'form.ccdomain'},$env{'form.ccuname'},
+ 'internal',$env{'form.intarg'}));
}
+ $r->rflush(); # Finish display of header before time consuming actions start
+ &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
##
+ my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
+ if ($context eq 'course') {
+ ($cnum,$cdom) =
+ &Apache::lonuserutils::get_course_identity();
+ $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
+ if ($showcredits) {
+ $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
+ }
+ }
if (! $env{'form.makeuser'} ) {
# Check for need to change
my %userenv = &Apache::lonnet::get
- ('environment',['firstname','middlename','lastname','generation'],
- $env{'form.ccdomain'},$env{'form.ccuname'});
+ ('environment',['firstname','middlename','lastname','generation',
+ 'id','permanentemail','portfolioquota','authorquota','inststatus',
+ 'tools.aboutme','tools.blog','tools.webdav',
+ 'tools.portfolio','tools.timezone','tools.portaccess',
+ 'authormanagers','authoreditors','authorarchive','requestauthor',
+ 'requestcourses.official','requestcourses.unofficial',
+ 'requestcourses.community','requestcourses.textbook',
+ 'requestcourses.placement','requestcourses.lti',
+ 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
+ 'reqcrsotherdom.community','reqcrsotherdom.textbook',
+ 'reqcrsotherdom.placement','domcoord.author'],
+ $env{'form.ccdomain'},$env{'form.ccuname'});
my ($tmp) = keys(%userenv);
if ($tmp =~ /^(con_lost|error)/i) {
%userenv = ();
}
- # Check to see if we need to change user information
- foreach ('firstname','middlename','lastname','generation') {
+ unless (($userenv{'domcoord.author'} eq 'blocked') &&
+ (($env{'user.name'} ne $env{'form.ccuname'}) ||
+ ($env{'user.domain'} ne $env{'form.ccdomain'}))) {
+ push(@authordefaults,'managers');
+ }
+ my $no_forceid_alert;
+ # Check to see if user information can be changed
+ my %domconfig =
+ &Apache::lonnet::get_dom('configuration',['usermodification'],
+ $env{'form.ccdomain'});
+ my @statuses = ('active','future');
+ my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
+ my ($auname,$audom);
+ if ($context eq 'author') {
+ $auname = $env{'user.name'};
+ $audom = $env{'user.domain'};
+ }
+ foreach my $item (keys(%roles)) {
+ my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
+ if ($context eq 'course') {
+ if ($cnum ne '' && $cdom ne '') {
+ if ($rolenum eq $cnum && $roledom eq $cdom) {
+ if (!grep(/^\Q$role\E$/,@userroles)) {
+ push(@userroles,$role);
+ }
+ }
+ }
+ } elsif ($context eq 'author') {
+ if ($rolenum eq $auname && $roledom eq $audom) {
+ if (!grep(/^\Q$role\E$/,@userroles)) {
+ push(@userroles,$role);
+ }
+ }
+ }
+ }
+ if ($env{'form.action'} eq 'singlestudent') {
+ if (!grep(/^st$/,@userroles)) {
+ push(@userroles,'st');
+ }
+ } else {
+ # Check for course or co-author roles being activated or re-enabled
+ if ($context eq 'author' || $context eq 'course') {
+ foreach my $key (keys(%env)) {
+ if ($context eq 'author') {
+ if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
+ if (!grep(/^\Q$1\E$/,@userroles)) {
+ push(@userroles,$1);
+ }
+ } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
+ if (!grep(/^\Q$1\E$/,@userroles)) {
+ push(@userroles,$1);
+ }
+ }
+ } elsif ($context eq 'course') {
+ if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
+ if (!grep(/^\Q$1\E$/,@userroles)) {
+ push(@userroles,$1);
+ }
+ } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
+ if (!grep(/^\Q$1\E$/,@userroles)) {
+ push(@userroles,$1);
+ }
+ }
+ }
+ }
+ }
+ }
+ #Check to see if we can change personal data for the user
+ my (@mod_disallowed,@longroles);
+ foreach my $role (@userroles) {
+ if ($role eq 'cr') {
+ push(@longroles,'Custom');
+ } else {
+ push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
+ }
+ }
+ my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
+ foreach my $item (@userinfo) {
# Strip leading and trailing whitespace
- $env{'form.c'.$_} =~ s/(\s+$|^\s+)//g;
+ $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
+ if (!$canmodify{$item}) {
+ if (defined($env{'form.c'.$item})) {
+ if ($env{'form.c'.$item} ne $userenv{$item}) {
+ push(@mod_disallowed,$item);
+ }
+ }
+ $env{'form.c'.$item} = $userenv{$item};
+ }
}
- if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
- ($env{'form.cfirstname'} ne $userenv{'firstname'} ||
- $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
- $env{'form.clastname'} ne $userenv{'lastname'} ||
- $env{'form.cgeneration'} ne $userenv{'generation'} )) {
- # Make the change
- my %changeHash;
- $changeHash{'firstname'} = $env{'form.cfirstname'};
- $changeHash{'middlename'} = $env{'form.cmiddlename'};
- $changeHash{'lastname'} = $env{'form.clastname'};
- $changeHash{'generation'} = $env{'form.cgeneration'};
- my $putresult = &Apache::lonnet::put
- ('environment',\%changeHash,
- $env{'form.ccdomain'},$env{'form.ccuname'});
- if ($putresult eq 'ok') {
+ # Check to see if we can change the Student/Employee ID
+ my $forceid = $env{'form.forceid'};
+ my $recurseid = $env{'form.recurseid'};
+ my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
+ my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
+ $env{'form.ccuname'});
+ if (($uidhash{$env{'form.ccuname'}}) &&
+ ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
+ (!$forceid)) {
+ if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
+ $env{'form.cid'} = $userenv{'id'};
+ $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
+ .' '
+ .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
+ .' '."\n";
+ }
+ }
+ if ($env{'form.cid'} ne $userenv{'id'}) {
+ my $checkhash;
+ my $checks = { 'id' => 1 };
+ $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
+ { 'newuser' => $newuser,
+ 'id' => $env{'form.cid'},
+ };
+ &Apache::loncommon::user_rule_check($checkhash,$checks,
+ \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
+ if (ref($alerts{'id'}) eq 'HASH') {
+ if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
+ $env{'form.cid'} = $userenv{'id'};
+ }
+ }
+ }
+ my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
+ $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
+ %oldsettingstext,%newsettings,%newsettingstext,@disporder,
+ %oldsettingstatus,%newsettingstatus);
+ @disporder = ('inststatus');
+ if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
+ push(@disporder,('requestcourses','requestauthor','authordefaults'));
+ } else {
+ push(@disporder,'reqcrsotherdom');
+ }
+ push(@disporder,('quota','tools'));
+ $oldinststatus = $userenv{'inststatus'};
+ foreach my $name ('portfolio','author') {
+ ($olddefquota{$name},$oldsettingstatus{$name}) =
+ &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
+ ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
+ }
+ my %canshow;
+ if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
+ $canshow{'quota'} = 1;
+ }
+ if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
+ $canshow{'tools'} = 1;
+ }
+ if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
+ $canshow{'requestcourses'} = 1;
+ } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
+ $canshow{'reqcrsotherdom'} = 1;
+ }
+ if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
+ $canshow{'inststatus'} = 1;
+ }
+ if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
+ $canshow{'requestauthor'} = 1;
+ $canshow{'authordefaults'} = 1;
+ }
+ my (%changeHash,%changed);
+ if ($oldinststatus eq '') {
+ $oldsettings{'inststatus'} = $othertitle;
+ } else {
+ if (ref($usertypes) eq 'HASH') {
+ $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
+ } else {
+ $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
+ }
+ }
+ $changeHash{'inststatus'} = $userenv{'inststatus'};
+ if ($canmodify_status{'inststatus'}) {
+ $canshow{'inststatus'} = 1;
+ if (exists($env{'form.inststatus'})) {
+ my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
+ if (@inststatuses > 0) {
+ $newinststatus = join(':',map { &escape($_); } @inststatuses);
+ $changeHash{'inststatus'} = $newinststatus;
+ if ($newinststatus ne $oldinststatus) {
+ $changed{'inststatus'} = $newinststatus;
+ foreach my $name ('portfolio','author') {
+ ($newdefquota{$name},$newsettingstatus{$name}) =
+ &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
+ }
+ }
+ if (ref($usertypes) eq 'HASH') {
+ $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
+ } else {
+ $newsettings{'inststatus'} = join(', ',@inststatuses);
+ }
+ }
+ } else {
+ $newinststatus = '';
+ $changeHash{'inststatus'} = $newinststatus;
+ $newsettings{'inststatus'} = $othertitle;
+ if ($newinststatus ne $oldinststatus) {
+ $changed{'inststatus'} = $changeHash{'inststatus'};
+ foreach my $name ('portfolio','author') {
+ ($newdefquota{$name},$newsettingstatus{$name}) =
+ &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
+ }
+ }
+ }
+ } elsif ($context ne 'selfcreate') {
+ $canshow{'inststatus'} = 1;
+ $newsettings{'inststatus'} = $oldsettings{'inststatus'};
+ }
+ foreach my $name ('portfolio','author') {
+ $changeHash{$name.'quota'} = $userenv{$name.'quota'};
+ }
+ if ($context eq 'domain') {
+ foreach my $name ('portfolio','author') {
+ if ($userenv{$name.'quota'} ne '') {
+ $oldquota{$name} = $userenv{$name.'quota'};
+ if ($env{'form.custom_'.$name.'quota'} == 1) {
+ if ($env{'form.'.$name.'quota'} eq '') {
+ $newquota{$name} = 0;
+ } else {
+ $newquota{$name} = $env{'form.'.$name.'quota'};
+ $newquota{$name} =~ s/[^\d\.]//g;
+ }
+ if ($newquota{$name} != $oldquota{$name}) {
+ if ("a_admin($newquota{$name},\%changeHash,$name)) {
+ $changed{$name.'quota'} = 1;
+ }
+ }
+ } else {
+ if ("a_admin('',\%changeHash,$name)) {
+ $changed{$name.'quota'} = 1;
+ $newquota{$name} = $newdefquota{$name};
+ $newisdefault{$name} = 1;
+ }
+ }
+ } else {
+ $oldisdefault{$name} = 1;
+ $oldquota{$name} = $olddefquota{$name};
+ if ($env{'form.custom_'.$name.'quota'} == 1) {
+ if ($env{'form.'.$name.'quota'} eq '') {
+ $newquota{$name} = 0;
+ } else {
+ $newquota{$name} = $env{'form.'.$name.'quota'};
+ $newquota{$name} =~ s/[^\d\.]//g;
+ }
+ if ("a_admin($newquota{$name},\%changeHash,$name)) {
+ $changed{$name.'quota'} = 1;
+ }
+ } else {
+ $newquota{$name} = $newdefquota{$name};
+ $newisdefault{$name} = 1;
+ }
+ }
+ if ($oldisdefault{$name}) {
+ $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
+ } else {
+ $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
+ }
+ if ($newisdefault{$name}) {
+ $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
+ } else {
+ $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
+ }
+ }
+ &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
+ \%changeHash,\%changed,\%newsettings,\%newsettingstext);
+ if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
+ &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
+ \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
+ my ($isadv,$isauthor) =
+ &Apache::lonnet::is_advanced_user($env{'form.ccdomain'},$env{'form.ccuname'});
+ unless ($isauthor) {
+ &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
+ \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
+ }
+ &tool_changes('authordefaults',\@authordefaults,\%oldsettings,\%oldsettingstext,
+ \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
+ } else {
+ &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
+ \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
+ }
+ }
+ foreach my $item (@userinfo) {
+ if ($env{'form.c'.$item} ne $userenv{$item}) {
+ $namechanged{$item} = 1;
+ }
+ }
+ foreach my $name ('portfolio','author') {
+ $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
+ $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
+ }
+ if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
+ my ($chgresult,$namechgresult);
+ if (keys(%changed) > 0) {
+ $chgresult =
+ &Apache::lonnet::put('environment',\%changeHash,
+ $env{'form.ccdomain'},$env{'form.ccuname'});
+ if ($chgresult eq 'ok') {
+ my ($ca_mgr_del,%ca_mgr_add);
+ if ($changed{'managers'}) {
+ my (@adds,@dels);
+ if ($changeHash{'authormanagers'} eq '') {
+ @dels = split(/,/,$userenv{'authormanagers'});
+ } elsif ($userenv{'authormanagers'} eq '') {
+ @adds = split(/,/,$changeHash{'authormanagers'});
+ } else {
+ my @old = split(/,/,$userenv{'authormanagers'});
+ my @new = split(/,/,$changeHash{'authormanagers'});
+ my @diffs = &Apache::loncommon::compare_arrays(\@old,\@new);
+ if (@diffs) {
+ foreach my $user (@diffs) {
+ if (grep(/^\Q$user\E$/,@old)) {
+ push(@dels,$user);
+ } elsif (grep(/^\Q$user\E$/,@new)) {
+ push(@adds,$user);
+ }
+ }
+ }
+ }
+ my $key = "internal.manager./$env{'form.ccdomain'}/$env{'form.ccuname'}";
+ if (@dels) {
+ foreach my $user (@dels) {
+ if ($user =~ /^($match_username):($match_domain)$/) {
+ &Apache::lonnet::del('environment',[$key],$2,$1);
+ }
+ }
+ my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
+ if (grep(/^\Q$curruser\E$/,@dels)) {
+ $ca_mgr_del = $key;
+ }
+ }
+ if (@adds) {
+ foreach my $user (@adds) {
+ if ($user =~ /^($match_username):($match_domain)$/) {
+ &Apache::lonnet::put('environment',{$key => 1},$2,$1);
+ }
+ }
+ my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
+ if (grep(/^\Q$curruser\E$/,@adds)) {
+ $ca_mgr_add{$key} = 1;
+ }
+ }
+ }
+ if (($env{'user.name'} eq $env{'form.ccuname'}) &&
+ ($env{'user.domain'} eq $env{'form.ccdomain'})) {
+ my (%newenvhash,$got_domdefs,%domdefaults,$got_userenv,
+ %userenv);
+ my @fromenv = keys(%changed);
+ push(@fromenv,'inststatus');
+ foreach my $key (keys(%changed)) {
+ if (($key eq 'official') || ($key eq 'unofficial') ||
+ ($key eq 'community') || ($key eq 'textbook') ||
+ ($key eq 'placement') || ($key eq 'lti')) {
+ $newenvhash{'environment.requestcourses.'.$key} =
+ $changeHash{'requestcourses.'.$key};
+ if ($changeHash{'requestcourses.'.$key}) {
+ $newenvhash{'environment.canrequest.'.$key} = 1;
+ } else {
+ unless ($got_domdefs) {
+ %domdefaults =
+ &Apache::lonnet::get_domain_defaults($env{'user.domain'});
+ $got_domdefs = 1;
+ }
+ unless ($got_userenv) {
+ %userenv =
+ &Apache::lonnet::userenvironment($env{'user.domain'},
+ $env{'user.name'},@fromenv);
+ $got_userenv = 1;
+ }
+ $newenvhash{'environment.canrequest.'.$key} =
+ &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
+ $key,'reload','requestcourses',\%userenv,\%domdefaults);
+ }
+ } elsif ($key eq 'requestauthor') {
+ $newenvhash{'environment.'.$key} = $changeHash{$key};
+ if ($changeHash{$key}) {
+ $newenvhash{'environment.canrequest.author'} = 1;
+ } else {
+ unless ($got_domdefs) {
+ %domdefaults =
+ &Apache::lonnet::get_domain_defaults($env{'user.domain'});
+ $got_domdefs = 1;
+ }
+ unless ($got_userenv) {
+ %userenv =
+ &Apache::lonnet::userenvironment($env{'user.domain'},
+ $env{'user.name'},@fromenv);
+ $got_userenv = 1;
+ }
+ $newenvhash{'environment.canrequest.author'} =
+ &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
+ $key,'reload','requestauthor',\%userenv,\%domdefaults);
+ }
+ } elsif ($key eq 'editors') {
+ $newenvhash{'environment.author'.$key} = $changeHash{'author'.$key};
+ if ($env{'form.customeditors'}) {
+ $newenvhash{'environment.editors'} = $changeHash{'author'.$key};
+ } else {
+ unless ($got_domdefs) {
+ %domdefaults =
+ &Apache::lonnet::get_domain_defaults($env{'user.domain'});
+ $got_domdefs = 1;
+ }
+ if ($domdefaults{'editors'} ne '') {
+ $newenvhash{'environment.editors'} = $domdefaults{'editors'};
+ } else {
+ $newenvhash{'environment.editors'} = 'edit,xml';
+ }
+ }
+ } elsif ($key eq 'archive') {
+ $newenvhash{'environment.author.'.$key} =
+ $changeHash{'author.'.$key};
+ if ($changeHash{'author.'.$key} ne '') {
+ $newenvhash{'environment.canarchive'} =
+ $changeHash{'author.'.$key};
+ } else {
+ unless ($got_domdefs) {
+ %domdefaults =
+ &Apache::lonnet::get_domain_defaults($env{'user.domain'});
+ $got_domdefs = 1;
+ }
+ $newenvhash{'environment.canarchive'} =
+ $domdefaults{'archive'};
+ }
+ } elsif ($key ne 'quota') {
+ $newenvhash{'environment.tools.'.$key} =
+ $changeHash{'tools.'.$key};
+ if ($changeHash{'tools.'.$key} ne '') {
+ $newenvhash{'environment.availabletools.'.$key} =
+ $changeHash{'tools.'.$key};
+ } else {
+ unless ($got_domdefs) {
+ %domdefaults =
+ &Apache::lonnet::get_domain_defaults($env{'user.domain'});
+ $got_domdefs = 1;
+ }
+ unless ($got_userenv) {
+ %userenv =
+ &Apache::lonnet::userenvironment($env{'user.domain'},
+ $env{'user.name'},@fromenv);
+ $got_userenv = 1;
+ }
+ $newenvhash{'environment.availabletools.'.$key} =
+ &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
+ $key,'reload','tools',\%userenv,\%domdefaults);
+ }
+ }
+ }
+ if (keys(%newenvhash)) {
+ &Apache::lonnet::appenv(\%newenvhash);
+ }
+ } else {
+ if ($ca_mgr_del) {
+ &Apache::lonnet::delenv($ca_mgr_del);
+ }
+ if (keys(%ca_mgr_add)) {
+ &Apache::lonnet::appenv(\%ca_mgr_add);
+ }
+ }
+ if ($changed{'aboutme'}) {
+ &Apache::loncommon::devalidate_aboutme_cache($env{'form.ccuname'},
+ $env{'form.ccdomain'});
+ }
+ }
+ }
+ if (keys(%namechanged) > 0) {
+ foreach my $field (@userinfo) {
+ $changeHash{$field} = $env{'form.c'.$field};
+ }
+# Make the change
+ $namechgresult =
+ &Apache::lonnet::modifyuser($env{'form.ccdomain'},
+ $env{'form.ccuname'},$changeHash{'id'},undef,undef,
+ $changeHash{'firstname'},$changeHash{'middlename'},
+ $changeHash{'lastname'},$changeHash{'generation'},
+ $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
+ %userupdate = (
+ lastname => $env{'form.clastname'},
+ middlename => $env{'form.cmiddlename'},
+ firstname => $env{'form.cfirstname'},
+ generation => $env{'form.cgeneration'},
+ id => $env{'form.cid'},
+ );
+ }
+ if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
+ ((keys(%changed) > 0) && $chgresult eq 'ok')) {
# Tell the user we changed the name
- my %lt=&Apache::lonlocal::texthash(
- 'uic' => "User Information Changed",
- 'frst' => "first",
- 'mddl' => "middle",
- 'lst' => "last",
- 'gen' => "generation",
- 'prvs' => "Previous",
- 'chto' => "Changed To"
- );
- $r->print(<<"END");
-
-$lt{'uic'}
-
- $lt{'frst'}
- $lt{'mddl'}
- $lt{'lst'}
- $lt{'gen'}
-$lt{'prvs'}
- $userenv{'firstname'}
- $userenv{'middlename'}
- $userenv{'lastname'}
- $userenv{'generation'}
-$lt{'chto'}
- $env{'form.cfirstname'}
- $env{'form.cmiddlename'}
- $env{'form.clastname'}
- $env{'form.cgeneration'}
-
-END
+ &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
+ \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
+ \%oldsettings, \%oldsettingstext,\%newsettings,
+ \%newsettingstext);
+ if ($env{'form.cid'} ne $userenv{'id'}) {
+ &Apache::lonnet::idput($env{'form.ccdomain'},
+ {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
+ if (($recurseid) &&
+ (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
+ my $idresult =
+ &Apache::lonuserutils::propagate_id_change(
+ $env{'form.ccuname'},$env{'form.ccdomain'},
+ \%userupdate);
+ $r->print(' '.$idresult.' ');
+ }
+ }
+ if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
+ ($env{'form.ccuname'} eq $env{'user.name'})) {
+ my %newenvhash;
+ foreach my $key (keys(%changeHash)) {
+ $newenvhash{'environment.'.$key} = $changeHash{$key};
+ }
+ &Apache::lonnet::appenv(\%newenvhash);
+ }
} else { # error occurred
- $r->print("".&mt('Unable to successfully change environment for')." ".
- $env{'form.ccuname'}." ".&mt('in domain')." ".
- $env{'form.ccdomain'}." ");
- }
- } else { # End of if ($env ... ) logic
- # They did not want to change the users name but we can
- # still tell them what the name is
- my %lt=&Apache::lonlocal::texthash(
- 'usr' => "User",
- 'id' => "in domain",
- 'gen' => "Generation"
- );
- $r->print(<<"END");
-$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"
-$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'}
-$lt{'gen'}: $userenv{'generation'}
-END
+ $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');
+ }
+ 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('Close window').'
');
+ } else {
+ $r->print(' '.&Apache::lonhtmlcommon::actionbox([''
+ .&mt('Modify this user: [_1]',''.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.') ').' ',
+ ''.&mt('Create/Modify Another User').' ']));
}
}
- ##
+}
+
+sub display_userinfo {
+ my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
+ $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
+ $newsetting,$newsettingtext) = @_;
+ return unless (ref($order) eq 'ARRAY' &&
+ ref($canshow) eq 'HASH' &&
+ ref($requestcourses) eq 'ARRAY' &&
+ ref($requestauthor) eq 'ARRAY' &&
+ ref($usertools) eq 'ARRAY' &&
+ ref($userenv) eq 'HASH' &&
+ ref($changedhash) eq 'HASH' &&
+ ref($oldsetting) eq 'HASH' &&
+ ref($oldsettingtext) eq 'HASH' &&
+ ref($newsetting) eq 'HASH' &&
+ ref($newsettingtext) eq 'HASH');
+ my %lt=&Apache::lonlocal::texthash(
+ 'ui' => 'User Information',
+ 'uic' => 'User Information Changed',
+ 'firstname' => 'First Name',
+ 'middlename' => 'Middle Name',
+ 'lastname' => 'Last Name',
+ 'generation' => 'Generation',
+ 'id' => 'Student/Employee ID',
+ 'permanentemail' => 'Permanent e-mail address',
+ 'portfolioquota' => 'Disk space allocated to portfolio files',
+ 'authorquota' => 'Disk space allocated to Authoring Space',
+ 'blog' => 'Blog Availability',
+ 'webdav' => 'WebDAV Availability',
+ 'aboutme' => 'Personal Information Page Availability',
+ 'portfolio' => 'Portfolio Availability',
+ 'portaccess' => 'Portfolio Shareable',
+ 'timezone' => 'Can set own Time Zone',
+ 'official' => 'Can Request Official Courses',
+ 'unofficial' => 'Can Request Unofficial Courses',
+ 'community' => 'Can Request Communities',
+ 'textbook' => 'Can Request Textbook Courses',
+ 'placement' => 'Can Request Placement Tests',
+ 'lti' => 'Can Request LTI Courses',
+ 'requestauthor' => 'Can Request Author Role',
+ 'inststatus' => "Affiliation",
+ 'prvs' => 'Previous Value:',
+ 'chto' => 'Changed To:',
+ 'editors' => "Available Editors in Authoring Space",
+ 'managers' => "Co-authors who can add/revoke roles",
+ 'archive' => "Managers can download tar.gz file of Authoring Space",
+ 'edit' => 'Standard editor (Edit)',
+ 'xml' => 'Text editor (EditXML)',
+ 'daxe' => 'Daxe editor (Daxe)',
+ );
+ if ($changed) {
+ $r->print(''.$lt{'uic'}.' '.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row());
+ $r->print(" \n");
+ $r->print(''.$lt{'prvs'}.' ');
+ $r->print(''.$lt{'chto'}.' ');
+ $r->print(&Apache::loncommon::end_data_table_header_row());
+ my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
+
+ foreach my $item (@userinfo) {
+ my $value = $env{'form.c'.$item};
+ #show changes only:
+ unless ($value eq $userenv->{$item}){
+ $r->print(&Apache::loncommon::start_data_table_row());
+ $r->print("$lt{$item} \n");
+ $r->print("".$userenv->{$item}." \n");
+ $r->print("$value \n");
+ $r->print(&Apache::loncommon::end_data_table_row());
+ }
+ }
+ foreach my $entry (@{$order}) {
+ if ($canshow->{$entry}) {
+ if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') ||
+ ($entry eq 'requestauthor') || ($entry eq 'authordefaults')) {
+ my @items;
+ if ($entry eq 'requestauthor') {
+ @items = ($entry);
+ } elsif ($entry eq 'authordefaults') {
+ @items = ('webdav','managers','editors','archive');
+ } else {
+ @items = @{$requestcourses};
+ }
+ foreach my $item (@items) {
+ if (($newsetting->{$item} ne $oldsetting->{$item}) ||
+ ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
+ $r->print(&Apache::loncommon::start_data_table_row()."\n");
+ $r->print("$lt{$item} \n");
+ unless ($item eq 'managers') {
+ $r->print($oldsetting->{$item});
+ }
+ if ($oldsettingtext->{$item}) {
+ if ($oldsetting->{$item}) {
+ unless ($item eq 'managers') {
+ $r->print(' -- ');
+ }
+ }
+ $r->print($oldsettingtext->{$item});
+ }
+ $r->print(" \n");
+ unless ($item eq 'managers') {
+ $r->print($newsetting->{$item});
+ }
+ if ($newsettingtext->{$item}) {
+ if ($newsetting->{$item}) {
+ unless ($item eq 'managers') {
+ $r->print(' -- ');
+ }
+ }
+ $r->print($newsettingtext->{$item});
+ }
+ $r->print(" \n");
+ $r->print(&Apache::loncommon::end_data_table_row()."\n");
+ }
+ }
+ } elsif ($entry eq 'tools') {
+ foreach my $item (@{$usertools}) {
+ if ($newsetting->{$item} ne $oldsetting->{$item}) {
+ $r->print(&Apache::loncommon::start_data_table_row()."\n");
+ $r->print("$lt{$item} \n");
+ $r->print("".$oldsetting->{$item}.' '.$oldsettingtext->{$item}." \n");
+ $r->print("".$newsetting->{$item}.' '.$newsettingtext->{$item}." \n");
+ $r->print(&Apache::loncommon::end_data_table_row()."\n");
+ }
+ }
+ } elsif ($entry eq 'quota') {
+ if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
+ (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
+ foreach my $name ('portfolio','author') {
+ if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
+ $r->print(&Apache::loncommon::start_data_table_row()."\n");
+ $r->print("$lt{$name.$entry} \n");
+ $r->print("".$oldsettingtext->{$entry}->{$name}." \n");
+ $r->print("".$newsettingtext->{$entry}->{$name}." \n");
+ $r->print(&Apache::loncommon::end_data_table_row()."\n");
+ }
+ }
+ }
+ } else {
+ if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
+ $r->print(&Apache::loncommon::start_data_table_row()."\n");
+ $r->print("$lt{$entry} \n");
+ $r->print("".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}." \n");
+ $r->print("".$newsetting->{$entry}.' '.$newsettingtext->{$entry}." \n");
+ $r->print(&Apache::loncommon::end_data_table_row()."\n");
+ }
+ }
+ }
+ }
+ $r->print(&Apache::loncommon::end_data_table().' ');
+ } else {
+ $r->print(''.$lt{'ui'}.' '.
+ ''.&mt('No changes made to user information').'
');
+ }
+ return;
+}
+
+sub tool_changes {
+ my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
+ $changed,$newaccess,$newaccesstext) = @_;
+ if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
+ (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
+ (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
+ (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
+ return;
+ }
+ my %reqdisplay = &requestchange_display();
+ if ($context eq 'reqcrsotherdom') {
+ my @options = ('approval','validate','autolimit');
+ my $optregex = join('|',@options);
+ my $cdom = $env{'request.role.domain'};
+ foreach my $tool (@{$usertools}) {
+ $oldaccesstext->{$tool} = &mt("availability set to 'off'");
+ $newaccesstext->{$tool} = $oldaccesstext->{$tool};
+ $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
+ my ($newop,$limit);
+ if ($env{'form.'.$context.'_'.$tool}) {
+ $newop = $env{'form.'.$context.'_'.$tool};
+ if ($newop eq 'autolimit') {
+ $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
+ $limit =~ s/\D+//g;
+ $newop .= '='.$limit;
+ }
+ }
+ if ($userenv->{$context.'.'.$tool} eq '') {
+ if ($newop) {
+ $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
+ $changeHash,$context);
+ if ($changed->{$tool}) {
+ if ($newop =~ /^autolimit/) {
+ if ($limit) {
+ $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
+ } else {
+ $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
+ }
+ } else {
+ $newaccesstext->{$tool} = $reqdisplay{$newop};
+ }
+ } else {
+ $newaccesstext->{$tool} = $oldaccesstext->{$tool};
+ }
+ }
+ } else {
+ my @curr = split(',',$userenv->{$context.'.'.$tool});
+ my @new;
+ my $changedoms;
+ foreach my $req (@curr) {
+ if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
+ my $oldop = $1;
+ if ($oldop =~ /^autolimit=(\d*)/) {
+ my $limit = $1;
+ if ($limit) {
+ $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
+ } else {
+ $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
+ }
+ } else {
+ $oldaccesstext->{$tool} = $reqdisplay{$oldop};
+ }
+ if ($oldop ne $newop) {
+ $changedoms = 1;
+ foreach my $item (@curr) {
+ my ($reqdom,$option) = split(':',$item);
+ unless ($reqdom eq $cdom) {
+ push(@new,$item);
+ }
+ }
+ if ($newop) {
+ push(@new,$cdom.':'.$newop);
+ }
+ @new = sort(@new);
+ }
+ last;
+ }
+ }
+ if ((!$changedoms) && ($newop)) {
+ $changedoms = 1;
+ @new = sort(@curr,$cdom.':'.$newop);
+ }
+ if ($changedoms) {
+ my $newdomstr;
+ if (@new) {
+ $newdomstr = join(',',@new);
+ }
+ $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
+ $context);
+ if ($changed->{$tool}) {
+ if ($env{'form.'.$context.'_'.$tool}) {
+ if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
+ my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
+ $limit =~ s/\D+//g;
+ if ($limit) {
+ $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
+ } else {
+ $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
+ }
+ } else {
+ $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
+ }
+ } else {
+ $newaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ }
+ }
+ }
+ }
+ return;
+ }
+ my %tooldesc = &Apache::lonlocal::texthash(
+ 'edit' => 'Standard editor (Edit)',
+ 'xml' => 'Text editor (EditXML)',
+ 'daxe' => 'Daxe editor (Daxe)',
+ );
+ foreach my $tool (@{$usertools}) {
+ my ($newval,$limit,$envkey);
+ $envkey = $context.'.'.$tool;
+ if ($context eq 'requestcourses') {
+ $newval = $env{'form.crsreq_'.$tool};
+ if ($newval eq 'autolimit') {
+ $limit = $env{'form.crsreq_'.$tool.'_limit'};
+ $limit =~ s/\D+//g;
+ $newval .= '='.$limit;
+ }
+ } elsif ($context eq 'requestauthor') {
+ $newval = $env{'form.'.$context};
+ $envkey = $context;
+ } elsif ($context eq 'authordefaults') {
+ if ($tool eq 'editors') {
+ $envkey = 'authoreditors';
+ if ($env{'form.customeditors'} == 1) {
+ my @editors;
+ my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
+ if (@posseditors) {
+ foreach my $editor (@posseditors) {
+ if (grep(/^\Q$editor\E$/,@posseditors)) {
+ unless (grep(/^\Q$editor\E$/,@editors)) {
+ push(@editors,$editor);
+ }
+ }
+ }
+ }
+ if (@editors) {
+ $newval = join(',',(sort(@editors)));
+ }
+ }
+ } elsif ($tool eq 'managers') {
+ $envkey = 'authormanagers';
+ my @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
+ if (@possibles) {
+ my %ca_roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},
+ undef,['active','future'],['ca']);
+ if (keys(%ca_roles)) {
+ my @custommanagers;
+ foreach my $user (@possibles) {
+ if ($user =~ /^($match_username):($match_domain)$/) {
+ if (exists($ca_roles{$user.':ca'})) {
+ unless ($user eq $env{'form.ccuname'}.':'.$env{'form.ccdomain'}) {
+ push(@custommanagers,$user);
+ }
+ }
+ }
+ }
+ if (@custommanagers) {
+ $newval = join(',',sort(@custommanagers));
+ }
+ }
+ }
+ } elsif ($tool eq 'webdav') {
+ $envkey = 'tools.webdav';
+ $newval = $env{'form.'.$context.'_'.$tool};
+ } elsif ($tool eq 'archive') {
+ $envkey = 'authorarchive';
+ $newval = $env{'form.'.$context.'_'.$tool};
+ }
+ } else {
+ $newval = $env{'form.'.$context.'_'.$tool};
+ }
+ if ($userenv->{$envkey} ne '') {
+ $oldaccess->{$tool} = &mt('custom');
+ if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
+ if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
+ my $currlimit = $1;
+ if ($currlimit eq '') {
+ $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
+ } else {
+ $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
+ }
+ } elsif ($userenv->{$envkey}) {
+ $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
+ } else {
+ $oldaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ } elsif ($context eq 'authordefaults') {
+ if ($tool eq 'managers') {
+ if ($userenv->{$envkey} eq '') {
+ $oldaccesstext->{$tool} = &mt('Only author may manage co-author roles');
+ } else {
+ my $managers = $userenv->{$envkey};
+ $managers =~ s/,/, /g;
+ $oldaccesstext->{$tool} = $managers;
+ }
+ } elsif ($tool eq 'editors') {
+ $oldaccesstext->{$tool} = &mt('can use: [_1]',
+ join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
+ } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
+ if ($userenv->{$envkey}) {
+ $oldaccesstext->{$tool} = &mt("availability set to 'on'");
+ } else {
+ $oldaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ }
+ } else {
+ if ($userenv->{$envkey}) {
+ $oldaccesstext->{$tool} = &mt("availability set to 'on'");
+ } else {
+ $oldaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ }
+ $changeHash->{$envkey} = $userenv->{$envkey};
+ if (($env{'form.custom'.$tool} == 1) ||
+ (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
+ if ($newval ne $userenv->{$envkey}) {
+ $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
+ $context);
+ if ($changed->{$tool}) {
+ $newaccess->{$tool} = &mt('custom');
+ if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
+ if ($newval =~ /^autolimit/) {
+ if ($limit) {
+ $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
+ } else {
+ $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
+ }
+ } elsif ($newval) {
+ $newaccesstext->{$tool} = $reqdisplay{$newval};
+ } else {
+ $newaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ } elsif ($context eq 'authordefaults') {
+ if ($tool eq 'editors') {
+ $newaccesstext->{$tool} = &mt('can use: [_1]',
+ join(', ', map { $tooldesc{$_} } split(/,/,$changeHash->{$envkey})));
+ } elsif ($tool eq 'managers') {
+ if ($changeHash->{$envkey} eq '') {
+ $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
+ } else {
+ my $managers = $changeHash->{$envkey};
+ $managers =~ s/,/, /g;
+ $newaccesstext->{$tool} = $managers;
+ }
+ } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
+ if ($newval) {
+ $newaccesstext->{$tool} = &mt("availability set to 'on'");
+ } else {
+ $newaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ }
+ } else {
+ if ($newval) {
+ $newaccesstext->{$tool} = &mt("availability set to 'on'");
+ } else {
+ $newaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ }
+ } else {
+ $newaccess->{$tool} = $oldaccess->{$tool};
+ if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
+ if ($userenv->{$envkey} =~ /^autolimit/) {
+ if ($limit) {
+ $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
+ } else {
+ $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
+ }
+ } elsif ($userenv->{$envkey}) {
+ $newaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
+ } else {
+ $newaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ } elsif ($context eq 'authordefaults') {
+ if ($tool eq 'editors') {
+ $newaccesstext->{$tool} = &mt('can use: [_1]',
+ join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
+ } elsif ($tool eq 'managers') {
+ if ($userenv->{$envkey} eq '') {
+ $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
+ } else {
+ my $managers = $userenv->{$envkey};
+ $managers =~ s/,/, /g;
+ $newaccesstext->{$tool} = $managers;
+ }
+ } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
+ if ($userenv->{$envkey}) {
+ $newaccesstext->{$tool} = &mt("availability set to 'on'");
+ } else {
+ $newaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ }
+ } else {
+ if ($userenv->{$context.'.'.$tool}) {
+ $newaccesstext->{$tool} = &mt("availability set to 'on'");
+ } else {
+ $newaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ }
+ }
+ } else {
+ $newaccess->{$tool} = $oldaccess->{$tool};
+ $newaccesstext->{$tool} = $oldaccesstext->{$tool};
+ }
+ } else {
+ $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
+ if ($changed->{$tool}) {
+ $newaccess->{$tool} = &mt('default');
+ } else {
+ $newaccess->{$tool} = $oldaccess->{$tool};
+ if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
+ if ($newval =~ /^autolimit/) {
+ if ($limit) {
+ $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
+ } else {
+ $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
+ }
+ } elsif ($newval) {
+ $newaccesstext->{$tool} = $reqdisplay{$newval};
+ } else {
+ $newaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ } elsif ($context eq 'authordefaults') {
+ if ($tool eq 'editors') {
+ $newaccesstext->{$tool} = &mt('can use: [_1]',
+ join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
+ } elsif ($tool eq 'managers') {
+ if ($newval eq '') {
+ $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
+ } else {
+ my $managers = $newval;
+ $managers =~ s/,/, /g;
+ $newaccesstext->{$tool} = $managers;
+ }
+ } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
+ if ($userenv->{$envkey}) {
+ $newaccesstext->{$tool} = &mt("availability set to 'on'");
+ } else {
+ $newaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ }
+ } else {
+ if ($userenv->{$context.'.'.$tool}) {
+ $newaccesstext->{$tool} = &mt("availability set to 'on'");
+ } else {
+ $newaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ }
+ }
+ }
+ } else {
+ $oldaccess->{$tool} = &mt('default');
+ if (($env{'form.custom'.$tool} == 1) ||
+ (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
+ $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
+ $context);
+ if ($changed->{$tool}) {
+ $newaccess->{$tool} = &mt('custom');
+ if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
+ if ($newval =~ /^autolimit/) {
+ if ($limit) {
+ $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
+ } else {
+ $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
+ }
+ } elsif ($newval) {
+ $newaccesstext->{$tool} = $reqdisplay{$newval};
+ } else {
+ $newaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ } elsif ($context eq 'authordefaults') {
+ if ($tool eq 'managers') {
+ if ($newval eq '') {
+ $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
+ } else {
+ my $managers = $newval;
+ $managers =~ s/,/, /g;
+ $newaccesstext->{$tool} = $managers;
+ }
+ } elsif ($tool eq 'editors') {
+ $newaccesstext->{$tool} = &mt('can use: [_1]',
+ join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
+ } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
+ if ($newval) {
+ $newaccesstext->{$tool} = &mt("availability set to 'on'");
+ } else {
+ $newaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ }
+ } else {
+ if ($newval) {
+ $newaccesstext->{$tool} = &mt("availability set to 'on'");
+ } else {
+ $newaccesstext->{$tool} = &mt("availability set to 'off'");
+ }
+ }
+ } else {
+ $newaccess->{$tool} = $oldaccess->{$tool};
+ }
+ } else {
+ $newaccess->{$tool} = $oldaccess->{$tool};
+ }
+ }
+ }
+ return;
+}
+
+sub update_roles {
+ my ($r,$context,$showcredits) = @_;
my $now=time;
+ my @rolechanges;
+ my (%disallowed,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
+ %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
+ $got_role_approvals{$context} = '';
+ $process_by{$context} = {};
+ my @domroles = &Apache::lonuserutils::domain_roles();
+ my @cstrroles = &Apache::lonuserutils::construction_space_roles();
+ my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
$r->print(''.&mt('Modifying Roles').' ');
- foreach (keys (%env)) {
- next if (! $env{$_});
+ foreach my $key (keys(%env)) {
+ next if (! $env{$key});
+ next if ($key eq 'form.action');
# Revoke roles
- if ($_=~/^form\.rev/) {
- if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
+ if ($key=~/^form\.rev/) {
+ if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
# Revoke standard role
- $r->print(&mt('Revoking').' '.$2.' in '.$1.': '.
- &Apache::lonnet::revokerole($env{'form.ccdomain'},
- $env{'form.ccuname'},$1,$2).' ');
- if ($2 eq 'st') {
- $1=~/^\/(\w+)\/(\w+)/;
- my $cid=$1.'_'.$2;
- $r->print(&mt('Drop from classlist').': '.
- &Apache::lonnet::critical('put:'.
- $env{'course.'.$cid.'.domain'}.':'.
- $env{'course.'.$cid.'.num'}.':classlist:'.
- &Apache::lonnet::escape($env{'form.ccuname'}.':'.
- $env{'form.ccdomain'}).'='.
- &Apache::lonnet::escape($now.':'),
- $env{'course.'.$cid.'.home'}).' ');
+ my ($scope,$role) = ($1,$2);
+ my $result =
+ &Apache::lonnet::revokerole($env{'form.ccdomain'},
+ $env{'form.ccuname'},
+ $scope,$role,'','',$context);
+ $r->print(&Apache::lonhtmlcommon::confirm_success(
+ &mt('Revoking [_1] in [_2]',
+ &Apache::lonnet::plaintext($role),
+ &Apache::loncommon::show_role_extent($scope,$context,$role)),
+ $result ne "ok").' ');
+ if ($result ne "ok") {
+ $r->print(&mt('Error: [_1]',$result).' ');
+ }
+ if ($role eq 'st') {
+ my $result =
+ &Apache::lonuserutils::classlist_drop($scope,
+ $env{'form.ccuname'},$env{'form.ccdomain'},
+ $now);
+ $r->print(&Apache::lonhtmlcommon::confirm_success($result));
}
- }
- if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
+ if (!grep(/^\Q$role\E$/,@rolechanges)) {
+ push(@rolechanges,$role);
+ }
+ }
+ if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
# Revoke custom role
- $r->print(&mt('Revoking custom role:').
- ' '.$4.' by '.$3.'@'.$2.' in '.$1.': '.
- &Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
- $env{'form.ccuname'},$1,$2,$3,$4).
- ' ');
+ my $result = &Apache::lonnet::revokecustomrole(
+ $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
+ $r->print(&Apache::lonhtmlcommon::confirm_success(
+ &mt('Revoking custom role [_1] by [_2] in [_3]',
+ $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
+ $result ne 'ok').' ');
+ if ($result ne "ok") {
+ $r->print(&mt('Error: [_1]',$result).' ');
+ }
+ if (!grep(/^cr$/,@rolechanges)) {
+ push(@rolechanges,'cr');
+ }
}
- } elsif ($_=~/^form\.del/) {
- if ($_=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
+ } elsif ($key=~/^form\.del/) {
+ if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
# Delete standard role
- $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
- &Apache::lonnet::assignrole($env{'form.ccdomain'},
- $env{'form.ccuname'},$1,$2,$now,0,1).' ');
- if ($2 eq 'st') {
- $1=~/^\/(\w+)\/(\w+)/;
- my $cid=$1.'_'.$2;
- $r->print(&mt('Drop from classlist').': '.
- &Apache::lonnet::critical('put:'.
- $env{'course.'.$cid.'.domain'}.':'.
- $env{'course.'.$cid.'.num'}.':classlist:'.
- &Apache::lonnet::escape($env{'form.ccuname'}.':'.
- $env{'form.ccdomain'}).'='.
- &Apache::lonnet::escape($now.':'),
- $env{'course.'.$cid.'.home'}).' ');
+ my ($scope,$role) = ($1,$2);
+ my $result =
+ &Apache::lonnet::assignrole($env{'form.ccdomain'},
+ $env{'form.ccuname'},
+ $scope,$role,$now,0,1,'',
+ $context);
+ $r->print(&Apache::lonhtmlcommon::confirm_success(
+ &mt('Deleting [_1] in [_2]',
+ &Apache::lonnet::plaintext($role),
+ &Apache::loncommon::show_role_extent($scope,$context,$role)),
+ $result ne 'ok').' ');
+ if ($result ne "ok") {
+ $r->print(&mt('Error: [_1]',$result).' ');
+ }
+
+ if ($role eq 'st') {
+ my $result =
+ &Apache::lonuserutils::classlist_drop($scope,
+ $env{'form.ccuname'},$env{'form.ccdomain'},
+ $now);
+ $r->print(&Apache::lonhtmlcommon::confirm_success($result));
}
+ if (!grep(/^\Q$role\E$/,@rolechanges)) {
+ push(@rolechanges,$role);
+ }
}
- if ($_=~/^form\.del\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
+ if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
# Delete custom role
- $r->print(&mt('Deleting custom role [_1] by [_2]@[_3] in [_4]',
- $rolename,$rnam,$rdom,$url).': '.
- &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
- $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
- 0,1).' ');
+ my $result =
+ &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
+ $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
+ 0,1,$context);
+ $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
+ $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
+ $result ne "ok").' ');
+ if ($result ne "ok") {
+ $r->print(&mt('Error: [_1]',$result).' ');
+ }
+
+ if (!grep(/^cr$/,@rolechanges)) {
+ push(@rolechanges,'cr');
+ }
}
- } elsif ($_=~/^form\.ren/) {
+ } elsif ($key=~/^form\.ren/) {
my $udom = $env{'form.ccdomain'};
my $uname = $env{'form.ccuname'};
# Re-enable standard role
- if ($_=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
+ if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
my $url = $1;
my $role = $2;
+ my $id = $url.'_'.$role;
my $logmsg;
my $output;
if ($role eq 'st') {
- if ($url =~ m-^/(\w+)/(\w+)/?(\w*)$-) {
- my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
- if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
- $output = "Error: $result\n";
- } else {
- $output = &mt('Assigning').' '.$role.' in '.$url.
- &mt('starting').' '.localtime($now).
- ': '.$logmsg.' '.
- &mt('Add to classlist').': ok ';
+ if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
+ my ($cdom,$cnum,$csec) = ($1,$2,$3);
+ my $credits;
+ if ($showcredits) {
+ my $defaultcredits =
+ &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
+ $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
+ }
+ unless ($udom eq $cdom) {
+ next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
+ $uname,$role,$now,0,$cdom,$cnum,$csec,$credits,
+ \%process_by,\%instdoms,\%got_role_approvals,
+ \%got_instdoms,\%reject,\%pending,\%notifydc,
+ \%status,\%unauthorized,\%currqueued));
+ }
+ my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
+ if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
+ if ($result eq 'refused' && $logmsg) {
+ $output = $logmsg;
+ } else {
+ $output = &mt('Error: [_1]',$result)."\n";
+ }
+ } else {
+ $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
+ &Apache::lonnet::plaintext($role),
+ &Apache::loncommon::show_role_extent($url,$context,'st'),
+ &Apache::lonlocal::locallocaltime($now))).' '.$logmsg.' ';
}
}
} else {
+ my ($cdom,$cnum,$csec);
+ if (grep(/^\Q$role\E$/,@cstrroles)) {
+ ($cdom,$cnum) = ($url =~ m{^/($match_domain)/($match_username)$});
+ } elsif (grep(/^\Q$role\E$/,@domroles)) {
+ ($cdom) = ($url =~ m{^/($match_domain)/$});
+ } elsif ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
+ ($cdom,$cnum,$csec) = ($1,$2,$3);
+ }
+ if ($cdom ne '') {
+ unless ($udom eq $cdom) {
+ next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
+ $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
+ \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
+ \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
+ }
+ }
my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
- $env{'form.ccuname'},$url,$role,0,$now);
- $output = &mt('Re-enabling [_1] in [_2]: [_3] ',
- $role,$url,$result).' ';
- }
+ $env{'form.ccuname'},$url,$role,0,$now,'','',
+ $context);
+ $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
+ &Apache::lonnet::plaintext($role),
+ &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").' ';
+ if ($result ne "ok") {
+ $output .= &mt('Error: [_1]',$result).' ';
+ }
+ }
$r->print($output);
+ if (!grep(/^\Q$role\E$/,@rolechanges)) {
+ push(@rolechanges,$role);
+ }
}
# Re-enable custom role
- if ($_=~/^form\.ren\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
+ if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
+ my $id = $url.'_cr'."/$rdom/$rnam/$rolename";
+ my $role = "cr/$rdom/$rnam/$rolename";
+ if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
+ my ($cdom,$cnum,$csec) = ($1,$2,$3);
+ unless ($udom eq $cdom) {
+ next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
+ $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
+ \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
+ \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
+ }
+ }
my $result = &Apache::lonnet::assigncustomrole(
$env{'form.ccdomain'}, $env{'form.ccuname'},
- $url,$rdom,$rnam,$rolename,0,$now);
- $r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : [_5] ',
- $rolename,$rnam,$rdom,$url,$result).' ');
+ $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
+ $r->print(&Apache::lonhtmlcommon::confirm_success(
+ &mt('Re-enabling custom role [_1] by [_2] in [_3]',
+ $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
+ $result ne "ok").' ');
+ if ($result ne "ok") {
+ $r->print(&mt('Error: [_1]',$result).' ');
+ }
+ if (!grep(/^cr$/,@rolechanges)) {
+ push(@rolechanges,'cr');
+ }
}
- } elsif ($_=~/^form\.act/) {
+ } elsif ($key=~/^form\.act/) {
my $udom = $env{'form.ccdomain'};
my $uname = $env{'form.ccuname'};
- if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
+ if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
# Activate a custom role
my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
my $url='/'.$one.'/'.$two;
+ my $id = $url.'_cr/'."$three/$four/$five";
+ my $role = "cr/$three/$four/$five";
my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
my $start = ( $env{'form.start_'.$full} ?
@@ -1321,47 +4886,87 @@ END
my $end = ( $env{'form.end_'.$full} ?
$env{'form.end_'.$full} :
0 );
-
+
# split multiple sections
my %sections = ();
- my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
+ my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$five);
if ($num_sections == 0) {
- $r->print(&commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
+ unless ($udom eq $one) {
+ next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
+ $uname,$role,$start,$end,$one,$two,'','',\%process_by,
+ \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
+ \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
+ }
+ $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
} else {
my %curr_groups =
&Apache::longroup::coursegroups($one,$two);
- foreach my $sec (sort {$a cmp $b} keys %sections) {
+ my ($restricted,$numchanges);
+ foreach my $sec (sort {$a cmp $b} keys(%sections)) {
if (($sec eq 'none') || ($sec eq 'all') ||
exists($curr_groups{$sec})) {
$disallowed{$sec} = $url;
next;
}
my $securl = $url.'/'.$sec;
- $r->print(&commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
+ my $secid = $securl.'_cr'."/$three/$four/$five";
+ undef($restricted);
+ unless ($udom eq $one) {
+ next if (&Apache::lonuserutils::restricted_dom($context,$secid,$udom,
+ $uname,$role,$start,$end,$one,$two,$sec,'',\%process_by,
+ \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
+ \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
+ }
+ $numchanges ++;
+ $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
}
+ next unless ($numchanges);
}
- } elsif ($_=~/^form\.act\_([^\_]+)\_(\w+)\_([^\_]+)$/) {
+ if (!grep(/^cr$/,@rolechanges)) {
+ push(@rolechanges,'cr');
+ }
+ } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
# Activate roles for sections with 3 id numbers
# set start, end times, and the url for the class
my ($one,$two,$three)=($1,$2,$3);
- my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
- $env{'form.start_'.$one.'_'.$two.'_'.$three} :
+ my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
+ $env{'form.start_'.$one.'_'.$two.'_'.$three} :
$now );
- my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
+ my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
$env{'form.end_'.$one.'_'.$two.'_'.$three} :
0 );
my $url='/'.$one.'/'.$two;
- my $type = 'three';
+ my $id = $url.'_'.$three;
# split multiple sections
my %sections = ();
my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
+ my ($credits,$numchanges);
+ if ($three eq 'st') {
+ if ($showcredits) {
+ my $defaultcredits =
+ &Apache::lonuserutils::get_defaultcredits($one,$two);
+ $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
+ $credits =~ s/[^\d\.]//g;
+ if ($credits eq $defaultcredits) {
+ undef($credits);
+ }
+ }
+ }
if ($num_sections == 0) {
- $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
+ unless ($udom eq $one) {
+ next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
+ $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
+ \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
+ \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
+ }
+ $numchanges ++;
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
} else {
my %curr_groups =
&Apache::longroup::coursegroups($one,$two);
my $emptysec = 0;
- foreach my $sec (sort {$a cmp $b} keys %sections) {
+ my $restricted;
+ foreach my $sec (sort {$a cmp $b} keys(%sections)) {
$sec =~ s/\W//g;
if ($sec ne '') {
if (($sec eq 'none') || ($sec eq 'all') ||
@@ -1370,144 +4975,344 @@ END
next;
}
my $securl = $url.'/'.$sec;
- $r->print(&commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
+ my $secid = $securl.'_'.$three;
+ unless ($udom eq $one) {
+ undef($restricted);
+ $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
+ $uname,$three,$start,$end,$one,$two,$sec,$credits,\%process_by,
+ \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
+ \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
+ next if ($restricted);
+ }
+ $numchanges ++;
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
} else {
$emptysec = 1;
}
}
if ($emptysec) {
- $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
+ unless ($udom eq $one) {
+ undef($restricted);
+ $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
+ $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
+ \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
+ \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
+ next if ($restricted);
+ }
+ $numchanges ++;
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
}
- }
- } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
+ next unless ($numchanges);
+ }
+ if (!grep(/^\Q$three\E$/,@rolechanges)) {
+ push(@rolechanges,$three);
+ }
+ } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
# Activate roles for sections with two id numbers
# set start, end times, and the url for the class
- my $start = ( $env{'form.start_'.$1.'_'.$2} ?
- $env{'form.start_'.$1.'_'.$2} :
+ my $start = ( $env{'form.start_'.$1.'_'.$2} ?
+ $env{'form.start_'.$1.'_'.$2} :
$now );
- my $end = ( $env{'form.end_'.$1.'_'.$2} ?
+ my $end = ( $env{'form.end_'.$1.'_'.$2} ?
$env{'form.end_'.$1.'_'.$2} :
0 );
- my $url='/'.$1.'/';
+ my $one = $1;
+ my $two = $2;
+ my $url='/'.$one.'/';
+ my $id = $url.'_'.$two;
+ my ($cdom,$cnum) = split(/\//,$one);
# split multiple sections
my %sections = ();
- my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
+ my ($restricted,$numchanges);
+ my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
if ($num_sections == 0) {
- $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
+ unless ($udom eq $one) {
+ $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
+ $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
+ \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
+ \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
+ next if ($restricted);
+ }
+ $numchanges ++;
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
} else {
my $emptysec = 0;
- foreach my $sec (sort {$a cmp $b} keys %sections) {
+ foreach my $sec (sort {$a cmp $b} keys(%sections)) {
if ($sec ne '') {
my $securl = $url.'/'.$sec;
- $r->print(&commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
+ my $secid = $securl.'_'.$two;
+ unless ($udom eq $one) {
+ undef($restricted);
+ $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
+ $uname,$two,$start,$end,$cdom,$cnum,$sec,'',\%process_by,
+ \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
+ \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
+ next if ($restricted);
+ }
+ $numchanges ++;
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
} else {
$emptysec = 1;
}
}
if ($emptysec) {
- $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
+ unless ($udom eq $one) {
+ undef($restricted);
+ $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
+ $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
+ \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
+ \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
+ next if ($restricted);
+ }
+ $numchanges ++;
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
}
+ next unless ($numchanges);
+ }
+ if (!grep(/^\Q$two\E$/,@rolechanges)) {
+ push(@rolechanges,$two);
}
} else {
- $r->print(''.&mt('ERROR').': '.&mt('Unknown command').' '.$_.'
');
+ $r->print(''.&mt('ERROR').': '.&mt('Unknown command').' '.$key.'
');
}
foreach my $key (sort(keys(%disallowed))) {
+ $r->print('');
if (($key eq 'none') || ($key eq 'all')) {
- $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.').'
');
+ $r->print(''
+ .&mt('Please [_1]go back[_2] and choose a different section name.'
+ ,'Create/Modify Another User
');
- $r->print(&Apache::loncommon::end_page());
+ $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
+ if (@rolechanges == 0) {
+ $r->print(''.&mt('No roles to modify').'
');
+ }
+ return @rolechanges;
}
-sub commit_customrole {
- my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
- my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
- ($start?', '.&mt('starting').' '.localtime($start):'').
- ($end?', ending '.localtime($end):'').': '.
- &Apache::lonnet::assigncustomrole(
- $udom,$uname,$url,$three,$four,$five,$end,$start).
- ' ';
- return $output;
+sub get_user_credits {
+ my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
+ if ($cdom eq '' || $cnum eq '') {
+ return unless ($env{'request.course.id'});
+ $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ }
+ my $credits;
+ my %currhash =
+ &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
+ if (keys(%currhash) > 0) {
+ my @items = split(/:/,$currhash{$uname.':'.$udom});
+ my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
+ $credits = $items[$crdidx];
+ $credits =~ s/[^\d\.]//g;
+ }
+ if ($credits eq $defaultcredits) {
+ undef($credits);
+ }
+ return $credits;
}
-sub commit_standardrole {
- my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
- my $output;
- my $logmsg;
- if ($three eq 'st') {
- my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec);
- if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
- $output = "Error: $result\n";
- } else {
- $output = &mt('Assigning').' '.$three.' in '.$url.
- ($start?', '.&mt('starting').' '.localtime($start):'').
- ($end?', '.&mt('ending').' '.localtime($end):'').
- ': '.$result.' '.
- &mt('Add to classlist').': ok ';
- }
- } else {
- $output = &mt('Assigning').' '.$three.' in '.$url.
- ($start?', '.&mt('starting').' '.localtime($start):'').
- ($end?', '.&mt('ending').' '.localtime($end):'').': '.
- &Apache::lonnet::assignrole(
- $udom,$uname,$url,$three,$end,$start).
- ' ';
+sub enroll_single_student {
+ my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
+ $showcredits,$defaultcredits) = @_;
+ $r->print('');
+ if ($crstype eq 'Community') {
+ $r->print(&mt('Enrolling Member'));
+ } else {
+ $r->print(&mt('Enrolling Student'));
}
- return $output;
-}
+ $r->print(' ');
-sub commit_studentrole {
- my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
- my $linefeed = ' '."\n";
- my $result;
- if (defined($one) && defined($two)) {
- my $cid=$one.'_'.$two;
- my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
- my $secchange = 0;
- my $expire_role_result;
- my $modify_section_result;
- unless ($oldsec eq '-1') {
- unless ($sec eq $oldsec) {
- $secchange = 1;
- my $uurl='/'.$cid;
- $uurl=~s/\_/\//g;
- if ($oldsec) {
- $uurl.='/'.$oldsec;
- }
- $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);
- $result = $expire_role_result;
- }
- }
- if (($expire_role_result eq 'ok') || ($secchange == 0)) {
- $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
- if ($modify_section_result =~ /^ok/) {
- if ($secchange == 1) {
- $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;
- } elsif ($oldsec eq '-1') {
- $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;
- } else {
- $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;
- }
- } else {
- $$logmsg .= "Error when attempting section change for $uname from old section $oldsec to new section: $sec in course $cid -error: $modify_section_result".$linefeed;
- }
- $result = $modify_section_result;
- } elsif ($secchange == 1) {
- $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;
+ # 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);
+ }
+ }
+ }
+ 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 {
- $$logmsg .= "Incomplete course id defined. Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";
- $result = "error: incomplete course id\n";
+ $r->print(&mt('unable to enroll').": ".$enroll_result);
}
- return $result;
+ return;
+}
+
+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 update_result_form {
+ my ($uhome) = @_;
+ my $outcome =
+ '';
+ return $outcome;
+}
+
+sub quota_admin {
+ my ($setquota,$changeHash,$name) = @_;
+ my $quotachanged;
+ if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
+ # Current user has quota modification privileges
+ 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 {
@@ -1522,7 +5327,7 @@ sub build_roles {
} else {
foreach my $sec (@secnums) {
$sec =~ ~s/\W//g;
- unless ($sec eq "") {
+ if (!($sec eq "")) {
if (exists($$sections{$sec})) {
$$sections{$sec} ++;
} else {
@@ -1539,225 +5344,5100 @@ sub build_roles {
$num_sections ++;
}
}
-
+
return $num_sections;
}
# ========================================================== Custom Role Editor
sub custom_role_editor {
- my $r=shift;
- 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;
-
- unless ($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;
}
- $r->print(&Apache::loncommon::start_page('Custom Role Editor'));
- my $syspriv='';
- my $dompriv='';
- my $coursepriv='';
+ 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?
- $r->print('');
if (($rdummy ne 'con_lost') && ($roledef ne '')) {
- $r->print(&mt('Existing Role').' "');
+ $body_top .= &mt('Existing Role').' "';
# ------------------------------------------------- Get current role privileges
- ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
+ ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
+ if ($privs{'system'} =~ /bre\&S/) {
+ if ($context eq 'domain') {
+ $crstype = 'Course';
+ } elsif ($crstype eq 'Community') {
+ $privs{'system'} =~ s/bre\&S//;
+ }
+ } elsif ($context eq 'domain') {
+ $crstype = 'Course';
+ }
} else {
- $r->print(&mt('New Role').' "');
- $roledef='';
+ $body_top .= &mt('New Role').' "';
+ $roledef='';
}
- $r->print($rolename.'" ');
+ $body_top .= $rolename.'" ';
+
# ------------------------------------------------------- What can be assigned?
my %full=();
- my %courselevel=();
- my %courselevelcurrent=();
- foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
- my ($priv,$restrict)=split(/\&/,$_);
- unless ($restrict) { $restrict='F'; }
- $courselevel{$priv}=$restrict;
- if ($coursepriv=~/\:$priv/) {
- $courselevelcurrent{$priv}=1;
- }
- $full{$priv}=1;
- }
- my %domainlevel=();
- my %domainlevelcurrent=();
- foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
- my ($priv,$restrict)=split(/\&/,$_);
- unless ($restrict) { $restrict='F'; }
- $domainlevel{$priv}=$restrict;
- if ($dompriv=~/\:$priv/) {
- $domainlevelcurrent{$priv}=1;
- }
- $full{$priv}=1;
- }
- my %systemlevel=();
- my %systemlevelcurrent=();
- foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
- my ($priv,$restrict)=split(/\&/,$_);
- unless ($restrict) { $restrict='F'; }
- $systemlevel{$priv}=$restrict;
- if ($syspriv=~/\:$priv/) {
- $systemlevelcurrent{$priv}=1;
- }
- $full{$priv}=1;
- }
- my %lt=&Apache::lonlocal::texthash(
- 'prv' => "Privilege",
- 'crl' => "Course Level",
- 'dml' => "Domain Level",
- 'ssl' => "System Level"
- );
+ my %levels=(
+ course => {},
+ domain => {},
+ system => {},
+ );
+ my %levelscurrent=(
+ course => {},
+ domain => {},
+ system => {},
+ );
+ &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
+ my ($jsback,$elements) = &crumb_utilities();
+ my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
+ my $head_script =
+ &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
+ \%full,\@templateroles,$jsback);
+ push (@{$brcrum},
+ {href => "javascript:backPage(document.$formname,'pickrole','')",
+ text => "Pick custom role",
+ faq => 282,bug=>'Instructor Interface',},
+ {href => "javascript:backPage(document.$formname,'','')",
+ text => "Edit custom role",
+ faq => 282,
+ bug => 'Instructor Interface',
+ help => $helpitem}
+ );
+ my $args = { bread_crumbs => $brcrum,
+ bread_crumbs_component => 'User Management'};
+ $r->print(&Apache::loncommon::start_page('Custom Role Editor',
+ $head_script,$args).
+ $body_top);
+ $r->print('