--- loncom/interface/loncreateuser.pm 2006/05/08 21:40:20 1.113
+++ 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.113 2006/05/08 21:40:20 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
@@ -64,122 +67,1140 @@ use Apache::Constants qw(:common :http);
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 .= '
');
+ } 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 (%curr_groups,$groupslist,$numgroups);
- if (exists($env{'request.course.id'})) {
- my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
- my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- $numgroups = &Apache::loncommon::coursegroups(\%curr_groups,$cdom,
- $cnum);
+
+ my $groupslist = &Apache::lonuserutils::get_groupslist();
+
+ my $js = &validation_javascript($context,$ccdomain,$pjump_def,
+ $crstype,$groupslist,$newuser,
+ $formname,\%loaditem,$permission);
+ my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
+ my $helpitem = 'Course_Change_Privileges';
+ if ($env{'form.action'} eq 'singlestudent') {
+ $helpitem = 'Course_Add_Student';
+ } elsif ($context eq 'author') {
+ $helpitem = 'Author_Change_Privileges';
+ } elsif ($context eq 'domain') {
+ $helpitem = 'Domain_Change_Privileges';
+ $js .= &set_custom_js();
+ }
+ push (@{$brcrum},
+ {href => "javascript:backPage($form)",
+ text => $breadcrumb_text{'search'},
+ faq => 282,
+ bug => 'Instructor Interface',});
+ if ($env{'form.phase'} eq 'userpicked') {
+ push(@{$brcrum},
+ {href => "javascript:backPage($form,'get_user_info','select')",
+ text => $breadcrumb_text{'userpicked'},
+ faq => 282,
+ bug => 'Instructor Interface',});
+ }
+ push(@{$brcrum},
+ {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
+ text => $breadcrumb_text{'modify'},
+ faq => 282,
+ bug => 'Instructor Interface',
+ help => $helpitem});
+ my $args = {'add_entries' => \%loaditem,
+ 'bread_crumbs' => $brcrum,
+ 'bread_crumbs_component' => 'User Management'};
+ if ($env{'form.popup'}) {
+ $args->{'no_nav_bar'} = 1;
+ $args->{'add_modal'} = 1;
+ }
+ if (($context eq 'domain') && ($env{'request.role.domain'} eq $ccdomain)) {
+ my @toggles;
+ if (&Apache::lonnet::allowed('cau',$ccdomain)) {
+ my ($isadv,$isauthor) =
+ &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
+ unless ($isauthor) {
+ push(@toggles,'requestauthor');
+ }
+ push(@toggles,('webdav','editors','archive'));
+ }
+ if (&Apache::lonnet::allowed('mut',$ccdomain)) {
+ push(@toggles,('aboutme','blog','portfolio','portaccess','timezone'));
+ }
+ if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
+ push(@toggles,('official','unofficial','community','textbook','placement','lti'));
+ }
+ if (@toggles) {
+ my $onload;
+ foreach my $item (@toggles) {
+ $onload .= "toggleCustom(document.cu,'customtext_$item','custom$item');";
+ }
+ $args->{'add_entries'} = {
+ 'onload' => $onload,
+ };
+ }
}
- if ($numgroups > 0) {
- $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;
- for (var i=0; i
+
+
+
+
+
+
+ENDFORMINFO
+ my (%inccourses,$roledom,$defaultcredits);
+ if ($context eq 'course') {
+ $inccourses{$env{'request.course.id'}}=1;
+ $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ if ($showcredits) {
+ $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
+ }
+ } elsif ($context eq 'author') {
+ $roledom = $env{'request.role.domain'};
+ } elsif ($context eq 'domain') {
+ foreach my $key (keys(%env)) {
+ $roledom = $env{'request.role.domain'};
+ if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
+ $inccourses{$1.'_'.$2}=1;
+ }
+ }
+ } else {
+ foreach my $key (keys(%env)) {
+ if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
+ $inccourses{$1.'_'.$2}=1;
+ }
+ }
+ }
+ my $title = '';
+ my $need_quota_js;
+ if ($newuser) {
+ my ($portfolioform,$domroleform);
+ if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
+ (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
+ # Current user has quota or user tools modification privileges
+ $portfolioform = '
'.
+ &mt('User Tools').
+ '
'."\n".
+ &Apache::loncommon::start_data_table();
+ if (&Apache::lonnet::allowed('mut',$ccdomain)) {
+ $portfolioform .= &build_tools_display($ccuname,$ccdomain,'tools');
+ }
+ if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
+ $portfolioform .= &user_quotas($ccuname,$ccdomain,'portfolio');
+ $need_quota_js = 1;
+ }
+ $portfolioform .= &Apache::loncommon::end_data_table();
+ }
+ if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
+ ($ccdomain eq $env{'request.role.domain'})) {
+ $domroleform = &domainrole_req($ccuname,$ccdomain).
+ &authoring_defaults($ccuname,$ccdomain);
+ $need_quota_js = 1;
+ }
+ my $readonly;
+ unless ($permission->{'cusr'}) {
+ $readonly = 1;
+ }
+ &initialize_authen_forms($ccdomain,$formname,'','',$readonly);
+ my %lt=&Apache::lonlocal::texthash(
+ 'lg' => 'Login Data',
+ 'hs' => "Home Server",
+ );
+ $r->print(<
+//
+
+
+ENDTITLE
+ if ($env{'form.action'} eq 'singlestudent') {
+ if ($crstype eq 'Community') {
+ $title = &mt('Create New User [_1] in domain [_2] as a member',
+ '"'.$ccuname.'"','"'.$ccdomain.'"');
+ } else {
+ $title = &mt('Create New User [_1] in domain [_2] as a student',
+ '"'.$ccuname.'"','"'.$ccdomain.'"');
+ }
+ } else {
+ $title = &mt('Create New User [_1] in domain [_2]',
+ '"'.$ccuname.'"','"'.$ccdomain.'"');
+ }
+ $r->print('
'.$title.'
'."\n");
+ $r->print('
');
+ $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
+ $inst_results{$ccuname.':'.$ccdomain},$readonly));
+ # Option to disable student/employee ID conflict checking not offerred for new users.
+ my ($home_server_pick,$numlib) =
+ &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
+ 'default','hide');
+ if ($numlib > 1) {
+ $r->print("
+
+$lt{'hs'}: $home_server_pick
+ ");
+ } else {
+ $r->print($home_server_pick);
+ }
+ if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
+ $r->print('
'.
+ &mt('Can Request Creation of Courses/Communities in this Domain?').'
'."\n".
+ &Apache::loncommon::start_data_table();
+ if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
+ (&Apache::lonnet::allowed('udp',$ccdomain))) {
+ $user_text{'quota'} .= &build_tools_display($ccuname,$ccdomain,'tools');
+ }
+ # Current user has quota modification privileges
+ if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
+ (&Apache::lonnet::allowed('udp',$ccdomain))) {
+ $user_text{'quota'} .= &user_quotas($ccuname,$ccdomain,'portfolio');
+ $need_quota_js = 1;
+ }
+ $user_text{'quota'} .= &Apache::loncommon::end_data_table();
+ }
+ if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
+ if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
+ my %lt=&Apache::lonlocal::texthash(
+ 'dska' => "Disk quotas for user's portfolio",
+ 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
+ 'ichr' => "If a change is required, contact a domain coordinator for the domain",
+ );
+ $user_text{'quota'} = <$lt{'dska'}
+$lt{'youd'} $lt{'ichr'}: $ccdomain
+ENDNOPORTPRIV
+ }
+ }
+ if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
+ if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
+ my %lt=&Apache::lonlocal::texthash(
+ 'utav' => "User Tools Availability",
+ 'yodo' => "You do not have privileges to modify Portfolio, Blog, Personal Information Page, or Time Zone settings for this user.",
+ 'ifch' => "If a change is required, contact a domain coordinator for the domain",
+ );
+ $user_text{'tools'} = <$lt{'utav'}
+$lt{'yodo'} $lt{'ifch'}: $ccdomain
+ENDNOTOOLSPRIV
+ }
+ }
+ my $gotdiv = 0;
+ foreach my $item (@order) {
+ if ($user_text{$item} ne '') {
+ unless ($gotdiv) {
+ $r->print('
');
}
- if ((userrole == 'cc') && (numsections > 0)) {
- alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
- section = "";
+ my $credits;
+ if ($showcredits) {
+ $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
+ if ($credits eq '') {
+ $credits = $defaultcredits;
+ }
}
- var numcourse = getIndex(document.cu.dccourse);
- if (numcourse == "-1") {
- alert("There was a problem with your course selection");
- return
+ $r->print(&date_sections_select($context,$newuser,$formname,
+ $permission,$crstype,$ccuname,
+ $ccdomain,$showcredits));
+ }
+ if ($gotdiv) {
+ $r->print('
');
+ }
+ my $statuses;
+ if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
+ (!&Apache::lonnet::allowed('mau',$ccdomain))) {
+ $statuses = ['active'];
+ } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
+ ($env{'request.course.sec'} &&
+ &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
+ $statuses = ['active'];
+ }
+ if ($env{'form.action'} ne 'singlestudent') {
+ &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
+ $roledom,$crstype,$showcredits,$statuses);
+ }
+ } ## End of new user/old user logic
+ if ($env{'form.action'} eq 'singlestudent') {
+ my $btntxt;
+ if ($crstype eq 'Community') {
+ $btntxt = &mt('Enroll Member');
+ } else {
+ $btntxt = &mt('Enroll Student');
+ }
+ $r->print(' '."\n");
+ } elsif ($permission->{'cusr'}) {
+ $r->print('
');
+ 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";
-
-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
- 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="
+"javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'
+"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'}.'
-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";
-
+"javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'
';
+ $domaintext.= &Apache::loncommon::end_data_table();
if ($num_domain_level > 0) {
$r->print($domaintext);
+ $addrolesdisplay = 1;
}
-#
-# Course level
-#
- my $num_sections;
+ return $addrolesdisplay;
+}
+
+sub user_authentication {
+ my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
+ my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
+ my $outcome;
+ my %lt=&Apache::lonlocal::texthash(
+ 'err' => "ERROR",
+ 'uuas' => "This user has an unrecognized authentication scheme",
+ 'adcs' => "Please alert a domain coordinator of this situation",
+ 'sldb' => "Please specify login data below",
+ 'ld' => "Login Data"
+ );
+ # Check for a bad authentication type
+ if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth|lti):/) {
+ # bad authentication scheme
+ if (&Apache::lonnet::allowed('mau',$ccdomain)) {
+ &initialize_authen_forms($ccdomain,$formname);
+
+ my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
+ $outcome = <
+//
+
+$lt{'err'}:
+$lt{'uuas'} ($currentauth). $lt{'sldb'}.
+
$lt{'ld'}
+$choices
+ENDBADAUTH
+ } else {
+ # This user is not allowed to modify the user's
+ # authentication scheme, so just notify them of the problem
+ $outcome = < $lt{'err'}:
+$lt{'uuas'} ($currentauth). $lt{'adcs'}.
+
+ENDBADAUTH
+ }
+ } else { # Authentication type is valid
+
+ &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
+ my ($authformcurrent,$can_modify,@authform_others) =
+ &modify_login_block($ccdomain,$currentauth);
+ if (&Apache::lonnet::allowed('mau',$ccdomain)) {
+ # Current user has login modification privileges
+ $outcome =
+ ''."\n".
+ '
';
+ }
+ return $output;
+}
+
+sub selfcreate_canmodify {
+ my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
+ if (ref($inst_results) eq 'HASH') {
+ my @inststatuses = &get_inststatuses($inst_results);
+ if (@inststatuses == 0) {
+ @inststatuses = ('default');
+ }
+ $rolesarray = \@inststatuses;
}
- $r->print("".&Apache::loncommon::end_page());
+ 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;
}
}
@@ -1053,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
@@ -1060,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('
");
- }
- } 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");
-
'
+ .&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('[_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.').'
');
-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 {
@@ -1504,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 {
@@ -1521,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('