--- loncom/interface/loncreateuser.pm 2002/04/29 14:47:57 1.35
+++ loncom/interface/loncreateuser.pm 2016/02/17 19:15:48 1.408
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.35 2002/04/29 14:47:57 matthew Exp $
+# $Id: loncreateuser.pm,v 1.408 2016/02/17 19:15:48 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,818 +25,7855 @@
#
# http://www.lon-capa.org/
#
-# (Create a course
-# (My Desk
-#
-# (Internal Server Error Handler
-#
-# (Login Screen
-# 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
-# 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
-#
-# YEAR=2001
-# 3/1/1 Gerd Kortemeyer)
-#
-# 3/1 Gerd Kortemeyer)
-#
-# 2/14 Gerd Kortemeyer)
-#
-# 2/14,2/17,2/19,2/20,2/21,2/22,2/23,3/2,3/17,3/24,04/12 Gerd Kortemeyer
-# April Guy Albertelli
-# 05/10,10/16 Gerd Kortemeyer
-# 11/12,11/13,11/15 Scott Harrison
-# 02/11/02 Matthew Hall
-#
-# $Id: loncreateuser.pm,v 1.35 2002/04/29 14:47:57 matthew Exp $
###
package Apache::loncreateuser;
+=pod
+
+=head1 NAME
+
+Apache::loncreateuser.pm
+
+=head1 SYNOPSIS
+
+ 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.
+
+=head1 OVERVIEW
+
+=head2 Custom Roles
+
+In LON-CAPA, roles are actually collections of privileges. "Teaching
+Assistant", "Course Coordinator", and other such roles are really just
+collection of privileges that are useful in many circumstances.
+
+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 '
+ .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
+ .' '
+ .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
+ ,'','')
+ .'Create User, Change User Privileges
-
-
-
-ENDDOCUMENT
+# ====================================================
+
+sub user_quotas {
+ my ($ccuname,$ccdomain) = @_;
+ my %lt = &Apache::lonlocal::texthash(
+ 'usrt' => "User Tools",
+ 'cust' => "Custom quota",
+ 'chqu' => "Change quota",
+ );
+
+ my $quota_javascript = <<"END_SCRIPT";
+
+END_SCRIPT
+ my $longinsttype;
+ my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
+ my $output = $quota_javascript."\n".
+ ''.$lt{'usrt'}.'
'."\n".
+ &Apache::loncommon::start_data_table();
-# =================================================================== Phase two
-sub phase_two {
- my $r=shift;
- my $ccuname=$ENV{'form.ccuname'};
- my $ccdomain=$ENV{'form.ccdomain'};
-
- $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
- my $krbdefdom=$1;
- $krbdefdom=~tr/a-z/A-Z/;
- my %param = ( formname => 'document.cu',
- kerb_def_dom => $krbdefdom
+ if (&Apache::lonnet::allowed('mut',$ccdomain)) {
+ $output .= &build_tools_display($ccuname,$ccdomain,'tools');
+ }
+
+ my %titles = &Apache::lonlocal::texthash (
+ portfolio => "Disk space allocated to user's portfolio files",
+ author => "Disk space allocated to user's Authoring Space (if role assigned)",
+ );
+ foreach my $name ('portfolio','author') {
+ 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);
+ $custom_on = ' ';
+ $custom_off = ' checked="checked" ';
+ 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, as determined by the user's institutional".
+ " affiliation ([_2]).",$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, is determined by the user's institutional".
+ " affiliation ([_2]).",$defquota,$longinsttype);
+ }
+ }
+
+ if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
+ $output .= ''."\n".
+ ' '."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$titles{$name}.' '."\n".
+ ' '.
+ &mt('Current quota: [_1] MB',$currquota).' '.
+ $defaultinfo.' '."\n".
+ &Apache::loncommon::end_data_table_row()."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$lt{'chqu'}.
+ ': '.
+ ' '.
+ ' '.&mt('MB').' '."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ }
+ $output .= &Apache::loncommon::end_data_table();
+ return $output;
+}
+
+sub build_tools_display {
+ my ($ccuname,$ccdomain,$context) = @_;
+ my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
+ $colspan,$isadv,%domconfig);
+ my %lt = &Apache::lonlocal::texthash (
+ 'blog' => "Personal User Blog",
+ 'aboutme' => "Personal Information Page",
+ 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
+ 'portfolio' => "Personal User Portfolio",
+ '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',
+ 'requestauthor' => 'Can request author space',
+ );
+ if ($context eq 'requestcourses') {
+ %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
+ 'requestcourses.official','requestcourses.unofficial',
+ 'requestcourses.community','requestcourses.textbook');
+ @usertools = ('official','unofficial','community','textbook');
+ @options =('norequest','approval','autolimit','validate');
+ %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
+ %reqtitles = &courserequest_titles();
+ %reqdisplay = &courserequest_display();
+ $colspan = ' colspan="2"';
+ %domconfig =
+ &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
+ $isadv = &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
+ } elsif ($context eq 'requestauthor') {
+ %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
+ 'requestauthor');
+ @usertools = ('requestauthor');
+ @options =('norequest','approval','automatic');
+ %reqtitles = &requestauthor_titles();
+ %reqdisplay = &requestauthor_display();
+ $colspan = ' colspan="2"';
+ %domconfig =
+ &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
+ } else {
+ %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
+ 'tools.aboutme','tools.portfolio','tools.blog',
+ 'tools.webdav');
+ @usertools = ('aboutme','blog','webdav','portfolio');
+ }
+ foreach my $item (@usertools) {
+ my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
+ $currdisp,$custdisp,$custradio);
+ $cust_off = 'checked="checked" ';
+ $tool_on = 'checked="checked" ';
+ $curr_access =
+ &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
+ $context);
+ if ($context eq 'requestauthor') {
+ if ($userenv{$context} ne '') {
+ $cust_on = ' checked="checked" ';
+ $cust_off = '';
+ }
+ } 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.');
+ } else {
+ $custom_access = &mt('Currently from custom setting.');
+ }
+ } elsif ($context eq 'requestauthor') {
+ if ($userenv{$context} eq '') {
+ $custom_access = &mt('Currently from default setting.');
+ } else {
+ $custom_access = &mt('Currently from custom setting.');
+ }
+ } else {
+ if ($userenv{$context.'.'.$item} eq '') {
+ $custom_access =
+ &mt('Availability determined currently from default setting.');
+ if (!$curr_access) {
+ $tool_off = 'checked="checked" ';
+ $tool_on = '';
+ }
+ } else {
+ $custom_access =
+ &mt('Availability determined currently from custom setting.');
+ if ($userenv{$context.'.'.$item} == 0) {
+ $tool_off = 'checked="checked" ';
+ $tool_on = '';
+ }
+ }
+ }
+ $output .= ' '."\n".
+ ' '."\n".
+ &Apache::loncommon::start_data_table_row()."\n";
+ if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
+ my ($curroption,$currlimit);
+ my $envkey = $context.'.'.$item;
+ if ($context eq 'requestauthor') {
+ $envkey = $context;
+ }
+ if ($userenv{$envkey} ne '') {
+ $curroption = $userenv{$envkey};
+ } else {
+ my (@inststatuses);
+ if ($context eq 'requestcourses') {
+ $curroption =
+ &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
+ $isadv,$ccdomain,$item,
+ \@inststatuses,\%domconfig);
+ } else {
+ $curroption =
+ &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
+ $isadv,$ccdomain,undef,
+ \@inststatuses,\%domconfig);
+ }
+ }
+ if (!$curroption) {
+ $curroption = 'norequest';
+ }
+ 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 = ''.$lt{$item}.' '."\n".
+ ' ';
+ 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"';
+ }
+ }
+ my $name = 'crsreq_'.$item;
+ if ($context eq 'requestauthor') {
+ $name = $item;
+ }
+ $custdisp .= '
';
+ $custradio = ' ';
+ }
+ $custdisp .= ' ';
+ if ($option eq 'autolimit') {
+ $custdisp .= '
'.
+ $reqtitles{'unlimited'};
+ } else {
+ $custdisp .= '';
+ }
+ $custdisp .= ''.&mt('Custom setting').'
'.$custdisp;
+ } else {
+ $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
+ my $name = $context.'_'.$item;
+ if ($context eq 'requestauthor') {
+ $name = $context;
+ }
+ $custdisp = ' ';
+ $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
+ '';
+ }
+ $output .= ' '.$custom_access.(' 'x4).
+ $lt{'avai'}.': '.$currdisp.' '."\n".
+ &Apache::loncommon::end_data_table_row()."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.
+ $lt{'chse'}.': '.(' ' x3).
+ ''.$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',
+ );
+
+ %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
+ 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
+ 'reqcrsotherdom.community','reqcrsotherdom.textbook');
+ @usertools = ('official','unofficial','community','textbook');
+ @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 ''."\n".
+ ' ';
+ foreach my $option (@options) {
+ if ($option eq 'validate') {
+ my $canvalidate = 0;
+ if (ref($validations{$item}) eq 'HASH') {
+ if ($validations{$item}{'_external_'}) {
+ $canvalidate = 1;
+ }
+ }
+ next if (!$canvalidate);
+ }
+ my $checked = '';
+ if ($option eq $curroption) {
+ $checked = ' checked="checked"';
+ }
+ $output .= '';
+ if ($option eq 'autolimit') {
+ $output .= ' '.
+ ' ';
+ }
+ $output .= '
'.$reqtitles{'unlimited'};
+ } else {
+ $output .= '';
+ }
+ $output .= ''.
+ &mt('User Can Request Assignment of Domain Roles?').
+ '
'."\n".
+ &Apache::loncommon::start_data_table().
+ &build_tools_display($ccuname,$ccdomain,
+ 'requestauthor').
+ &Apache::loncommon::end_data_table();
+}
+
+sub courserequest_titles {
+ my %titles = &Apache::lonlocal::texthash (
+ official => 'Official',
+ unofficial => 'Unofficial',
+ community => 'Communities',
+ textbook => 'Textbook',
+ norequest => 'Not allowed',
+ approval => 'Approval by Dom. Coord.',
+ validate => 'With validation',
+ autolimit => 'Numerical limit',
+ unlimited => '(blank for unlimited)',
+ );
+ return %titles;
+}
+
+sub courserequest_display {
+ my %titles = &Apache::lonlocal::texthash (
+ approval => 'Yes, need approval',
+ validate => 'Yes, with validation',
+ norequest => 'No',
+ );
+ return %titles;
+}
+
+sub requestauthor_titles {
+ my %titles = &Apache::lonlocal::texthash (
+ norequest => 'Not allowed',
+ approval => 'Approval by Dom. Coord.',
+ automatic => 'Automatic approval',
+ );
+ return %titles;
+
+}
+
+sub requestauthor_display {
+ my %titles = &Apache::lonlocal::texthash (
+ approval => 'Yes, need approval',
+ automatic => 'Yes, automatic approval',
+ norequest => 'No',
+ );
+ return %titles;
+}
+
+sub requestchange_display {
+ my %titles = &Apache::lonlocal::texthash (
+ approval => "availability set to 'on' (approval required)",
+ automatic => "availability set to 'on' (automatic approval)",
+ norequest => "availability set to 'off'",
+ );
+ return %titles;
+}
+
+sub curr_requestauthor {
+ my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
+ return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
+ if ($uname eq '' || $udom eq '') {
+ $uname = $env{'user.name'};
+ $udom = $env{'user.domain'};
+ $isadv = $env{'user.adv'};
+ }
+ my (%userenv,%settings,$val);
+ my @options = ('automatic','approval');
+ %userenv =
+ &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
+ if ($userenv{'requestauthor'}) {
+ $val = $userenv{'requestauthor'};
+ @{$inststatuses} = ('_custom_');
+ } else {
+ my %alltasks;
+ if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
+ %settings = %{$domconfig->{'requestauthor'}};
+ if (($isadv) && ($settings{'_LC_adv'} ne '')) {
+ $val = $settings{'_LC_adv'};
+ @{$inststatuses} = ('_LC_adv_');
+ } else {
+ if ($userenv{'inststatus'} ne '') {
+ @{$inststatuses} = split(',',$userenv{'inststatus'});
+ } else {
+ @{$inststatuses} = ('default');
+ }
+ foreach my $status (@{$inststatuses}) {
+ if (exists($settings{$status})) {
+ my $value = $settings{$status};
+ next unless ($value);
+ unless (exists($alltasks{$value})) {
+ if (ref($alltasks{$value}) eq 'ARRAY') {
+ unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
+ push(@{$alltasks{$value}},$status);
+ }
+ } else {
+ @{$alltasks{$value}} = ($status);
+ }
+ }
+ }
+ }
+ foreach my $option (@options) {
+ if ($alltasks{$option}) {
+ $val = $option;
+ last;
+ }
+ }
+ }
+ }
+ }
+ return $val;
+}
+
+# =================================================================== Phase one
+
+sub print_username_entry_form {
+ my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum) = @_;
+ my $defdom=$env{'request.role.domain'};
+ my $formtoset = 'crtuser';
+ if (exists($env{'form.startrolename'})) {
+ $formtoset = 'docustom';
+ $env{'form.rolename'} = $env{'form.startrolename'};
+ } elsif ($env{'form.origform'} eq 'crtusername') {
+ $formtoset = $env{'form.origform'};
+ }
+
+ my ($jsback,$elements) = &crumb_utilities();
+
+ my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
+ ''."\n";
+
+ my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
+ if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
+ && (&Apache::lonnet::allowed('mcr','/'))) {
+ $jscript .= &customrole_javascript();
+ }
+ my $helpitem = 'Course_Change_Privileges';
+ if ($env{'form.action'} eq 'custom') {
+ $helpitem = 'Course_Editing_Custom_Roles';
+ } elsif ($env{'form.action'} eq 'singlestudent') {
+ $helpitem = 'Course_Add_Student';
+ }
+ my %breadcrumb_text = &singleuser_breadcrumb($crstype);
+ 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',}
);
- $loginscript = &Apache::loncommon::authform_header(%param);
+ }
+ 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 $defdom=$ENV{'user.domain'};
+ my %lt=&Apache::lonlocal::texthash(
+ 'srst' => 'Search for a user and enroll as a student',
+ 'srme' => 'Search for a user and enroll as a member',
+ 'srad' => 'Search for a user and modify/add user information or roles',
+ 'usr' => "Username",
+ 'dom' => "Domain",
+ 'ecrp' => "Define or Edit Custom Role",
+ 'nr' => "role name",
+ 'cre' => "Next",
+ );
- $ccuname=~s/\W//g;
- $ccdomain=~s/\W//g;
- my $dochead =<<"ENDDOCHEAD";
-
-
-
+
+ENDDOCUMENT
+ }
+ return $output;
+}
+
+sub user_modification_js {
+ my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
+
+ return <
");
+ $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
+ $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('
');
+ }
+ }
+ $r->print('
';
+ }
+ $response .= '
';
+ $env{'form.phase'} = '';
+ &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
+ 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);
+ return;
+ }
+ }
+ }
+ } else {
+ $newuser = 0;
+ }
+ if ($response) {
+ $response = '
'.$response;
+ }
+
+ my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
+ my $dc_setcourse_code = '';
+ my $nondc_setsection_code = '';
+ my %loaditem;
+
+ my $groupslist = &Apache::lonuserutils::get_groupslist();
+
+ my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
+ $groupslist,$newuser,$formname,\%loaditem);
+ my %breadcrumb_text = &singleuser_breadcrumb($crstype);
+ my $helpitem = 'Course_Change_Privileges';
+ if ($env{'form.action'} eq 'singlestudent') {
+ $helpitem = 'Course_Add_Student';
+ }
+ 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;
+ }
+ my $start_page =
+ &Apache::loncommon::start_page('User Management',$js,$args);
+
my $forminfo =<<"ENDFORMINFO";
-
$generalrule
-$authformkrb
-$authformint
-$authformfsys
-$authformloc
-ENDNEWUSER +ENDTITLE + if ($env{'form.action'} eq 'singlestudent') { + if ($crstype eq 'Community') { + $title = &mt('Create New User [_1] in domain [_2] as a member', + '"'.$ccuname.'"','"'.$ccdomain.'"'); + } else { + $title = &mt('Create New User [_1] in domain [_2] as a student', + '"'.$ccuname.'"','"'.$ccdomain.'"'); + } + } else { + $title = &mt('Create New User [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); + } + $r->print('first name | middle name | last name | generation | -
---|---|---|---|
-END - } else { - $r->print(' | '.$userenv{$_}.' | '); - } + $r->print($start_page.$forminfo); + if ($env{'form.action'} eq 'singlestudent') { + if ($crstype eq 'Community') { + $title = &mt('Enroll one member: [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); + } else { + $title = &mt('Enroll one student: [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); + } + } else { + $title = &mt('Modify existing user: [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); } - $r->print(<
Revoke | Role | Extent | '. - 'Start | End | '); - foreach my $area (keys(%rolesdump)) { - if ($area!~/^rolesdef/) { - my $role = $rolesdump{$area}; - my $thisrole=$area; - $area=~s/\_\w\w$//; - my ($role_code,$role_end_time,$role_start_time) = - split(/_/,$role); - my $bgcol='ffffff'; - my $allows=0; - if ($area=~/^\/(\w+)\/(\d\w+)/) { - my %coursedata= - &Apache::lonnet::coursedescription($1.'_'.$2); - my $carea='Course: '.$coursedata{'description'}; - $inccourses{$1.'_'.$2}=1; - if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) { - $allows=1; - } - # Compute the background color based on $area - $bgcol=$1.'_'.$2; - $bgcol=~s/[^8-9b-e]//g; - $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6); - if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) { - $carea.='
---|---|---|---|---|
'); - my $active=1; - $active=0 if (($role_end_time) && ($now>$role_end_time)); - if (($active) && ($allows)) { - $r->print(''); - } else { - $r->print(' '); - } - $r->print(' | '. - &Apache::lonnet::plaintext($role_code). - ' | '.$area.' | '. - ($role_start_time ? localtime($role_start_time) - : ' ' ) - .' | '. - ($role_end_time ? localtime($role_end_time) - : ' ' ) - ." |
$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 - $r->print(<$authformint
\n". - "$authformfsys
$authformloc
"; - } - elsif ($currentauth=~/^internal:/) { - $authformcurrent=$authformint; - $authform_other="$authformkrb
". - "$authformfsys
$authformloc
"; - } - elsif ($currentauth=~/^unix:/) { - $authformcurrent=$authformfsys; - $authform_other="$authformkrb
". - "$authformint
$authformloc;
"; - } - elsif ($currentauth=~/^localauth:/) { - $authformcurrent=$authformloc; - $authform_other="$authformkrb
". - "$authformint
$authformfsys
"; - } - $authformcurrent=<$generalrule
-$authformnop
-$authformcurrent
-Activate | Role | Extent | -Start | End | ||||||
---|---|---|---|---|---|---|---|---|---|---|
- | Co-Author | -$cudom\_$cuname | -
+sub validation_javascript {
+ my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
+ $loaditem) = @_;
+ my $dc_setcourse_code = '';
+ my $nondc_setsection_code = '';
+ if ($context eq 'domain') {
+ my $dcdom = $env{'request.role.domain'};
+ $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
+ $dc_setcourse_code =
+ &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
+ } else {
+ my $checkauth;
+ if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
+ $checkauth = 1;
+ }
+ if ($context eq 'course') {
+ $nondc_setsection_code =
+ &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
+ undef,$checkauth,
+ $crstype);
+ }
+ if ($checkauth) {
+ $nondc_setsection_code .=
+ &Apache::lonuserutils::verify_authen($formname,$context);
+ }
+ }
+ my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
+ $nondc_setsection_code,$groupslist);
+ my ($jsback,$elements) = &crumb_utilities();
+ $js .= "\n".
+ ''."\n";
+ return $js;
+}
+
+sub display_existing_roles {
+ my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
+ $showcredits) = @_;
+ my $now=time;
+ my %lt=&Apache::lonlocal::texthash(
+ 'rer' => "Existing Roles",
+ 'rev' => "Revoke",
+ 'del' => "Delete",
+ 'ren' => "Re-Enable",
+ 'rol' => "Role",
+ 'ext' => "Extent",
+ 'crd' => "Credits",
+ 'sta' => "Start",
+ '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') {
+ 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);
+# Is this a custom role? Get role owner and title.
+ my ($croleudom,$croleuname,$croletitle)=
+ ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
+ my $allowed=0;
+ my $delallowed=0;
+ my $sortkey=$role_code;
+ my $class='Unknown';
+ my $credits='';
+ 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).
+ 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',$coursedom.'/'.$coursedir)) { + $allowed=1; + $thisrole.='.'.$role_code; + } + } + if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) { + $carea.=' '.&mt('Section: [_1]',$3); + $sortkey.="\0$3"; + if (!$allowed) { + if ($env{'request.course.sec'} eq $3) { + if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) { + $allowed = 1; + } + } + } + } + $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; + } else { + $allowed=0; + } + } + my $row = ''; + $row.= ' | '; + my $active=1; + $active=0 if (($role_end_time) && ($now>$role_end_time)); + if (($active) && ($allowed)) { + $row.= ''; + } else { + if ($active) { + $row.=' '; + } else { + $row.=&mt('expired or revoked'); + } + } + $row.=' | '; + if ($allowed && !$active) { + $row.= ''; + } else { + $row.=' '; + } + $row.=' | ';
+ if ($delallowed) {
+ $row.= '';
+ } else {
+ $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; + $rolepriv{$envkey}=$allowed; + } # 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)." | '.$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'}.' | +Set Start Date | -+"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.' | +Set End Date | - -
Activate | Role | Extent | '. - 'Start | End | - | $plrole | -$thisdomain | -
+ return $addrolesdisplay;;
+}
+
+sub new_domain_roles {
+ my ($r,$ccdomain) = @_;
+ my $addrolesdisplay = 0;
+ #
+ # Domain level
+ #
+ my $num_domain_level = 0;
+ my $domaintext =
+ ''.&mt('Domain Level').''. + &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'); + 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)) { + my $plrole=&Apache::lonnet::plaintext($role); + my %lt=&Apache::lonlocal::texthash( + 'ssd' => "Set Start Date", + 'sed' => "Set End Date" + ); + $num_domain_level ++; + $domaintext .= +&Apache::loncommon::start_data_table_row(). +'+ | '.$plrole.' | +'.$thisdomain.' | +Set Start Date | -+"javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.' | +Set End Date | - -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(); } - } + } } - $r->print('
---|
'.$authformcurrent. + ' | ||
'. + ' | '.&mt('Currently in use').' | '. + ''. + &mt('will override current values'). + ' |
'. + ' | '; + } + } + $output .= '