--- loncom/interface/loncreateuser.pm 2007/07/20 23:57:06 1.159
+++ loncom/interface/loncreateuser.pm 2010/04/14 13:58:11 1.340
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.159 2007/07/20 23:57:06 albertel Exp $
+# $Id: loncreateuser.pm,v 1.340 2010/04/14 13:58:11 wenzelju 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,10 +68,11 @@ use Apache::lonnet;
use Apache::loncommon;
use Apache::lonlocal;
use Apache::longroup;
+use Apache::lonuserutils;
+use Apache::loncoursequeueadmin;
use LONCAPA qw(:DEFAULT :match);
my $loginscript; # piece of javascript used in two separate instances
-my $generalrule;
my $authformnop;
my $authformkrb;
my $authformint;
@@ -76,43 +80,44 @@ my $authformfsys;
my $authformloc;
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) = @_;
+ 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):(.*)$/) {
+ 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;
+ }
+ }
+ $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);
}
-
-# ======================================================= Existing Custom Roles
-
-sub my_custom_roles {
- my %returnhash=();
- my %rolehash=&Apache::lonnet::dump('roles');
- foreach my $key (keys %rolehash) {
- if ($key=~/^rolesdef\_(\w+)$/) {
- $returnhash{$1}=$1;
- }
- }
- return %returnhash;
-}
-
-# ==================================================== Figure out author access
-
-sub authorpriv {
- my ($auname,$audom)=@_;
- unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
- || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; }
- return 1;
+sub auth_abbrev {
+ my %abv_auth = (
+ krb5 => 'krb',
+ krb4 => 'krb',
+ internal => 'int',
+ localuth => 'loc',
+ unix => 'fsys',
+ );
+ return %abv_auth;
}
# ====================================================
@@ -120,11 +125,12 @@ sub authorpriv {
sub portfolio_quota {
my ($ccuname,$ccdomain) = @_;
my %lt = &Apache::lonlocal::texthash(
- 'disk' => "Disk space allocated to user's portfolio files",
- 'cuqu' => "Current quota",
- 'cust' => "Custom quota",
- 'defa' => "Default",
- 'chqu' => "Change quota",
+ 'usrt' => "User Tools",
+ 'disk' => "Disk space allocated to user's portfolio files",
+ 'cuqu' => "Current quota",
+ 'cust' => "Custom quota",
+ 'defa' => "Default",
+ 'chqu' => "Change quota",
);
my ($currquota,$quotatype,$inststatus,$defquota) =
&Apache::loncommon::get_user_quota($ccuname,$ccdomain);
@@ -139,6 +145,7 @@ sub portfolio_quota {
$custom_off = ' checked="checked" ';
my $quota_javascript = <<"END_SCRIPT";
END_SCRIPT
if ($quotatype eq 'custom') {
@@ -156,100 +164,579 @@ END_SCRIPT
$custom_off = ' ';
$showquota = $currquota;
if ($longinsttype eq '') {
- $defaultinfo = &mt('For this user, the default quota would be [_1]
- Mb.',$defquota);
+ $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);
+ $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);
+ $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);
+ }
+ }
+
+ my $output = $quota_javascript."\n".
+ '
'."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ return $output;
+}
+
+sub courserequest_titles {
+ my %titles = &Apache::lonlocal::texthash (
+ official => 'Official',
+ unofficial => 'Unofficial',
+ community => 'Communities',
+ 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;
+}
+
# =================================================================== Phase one
sub print_username_entry_form {
- my ($r) = @_;
+ my ($r,$context,$response,$srch,$forcenewuser,$crstype) = @_;
my $defdom=$env{'request.role.domain'};
- my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
- my $selscript=&Apache::loncommon::studentbrowser_javascript();
+ 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 %loaditems = (
+ 'onload' => "javascript:setFormElements(document.$formtoset)",
+ );
+ my %breadcrumb_text = &singleuser_breadcrumb($crstype);
my $start_page =
- &Apache::loncommon::start_page('Create Users, Change User Privileges',
- $selscript);
-
- 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));
+ &Apache::loncommon::start_page('User Management',
+ $jscript,{'add_entries' => \%loaditems,});
+ if ($env{'form.action'} eq 'custom') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.crtuser)",
+ text=>"Pick custom role",});
+ } else {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.crtuser)",
+ text=>$breadcrumb_text{'search'},
+ faq=>282,bug=>'Instructor Interface',});
+ }
+ 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 $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
+ $helpitem);
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',
'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
+ $r->print($start_page."\n".$crumbs);
+ 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'};
+ if ($env{'form.action'} eq 'singlestudent') {
+ if ($crstype eq 'Community') {
+ $actiontext = $lt{'srme'};
+ } else {
+ $actiontext = $lt{'srst'};
+ }
+ }
+ $r->print("
$actiontext
");
+ if ($env{'form.origform'} ne 'crtusername') {
+ $r->print("\n".$response);
+ }
+ $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype));
+ }
+ $r->print(&Apache::loncommon::end_page());
+}
+
+sub customrole_javascript {
+ my $js = <<"END";
+
+END
+ return $js;
+}
+
+sub entry_form {
+ my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_;
+ my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
+ 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 ($rules,$ruleorder) =
+ &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
+ $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules);
+ } else {
+ $inexact = 1;
+ }
+ }
+ my $cancreate =
+ &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
+ my $userpicker =
+ &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
+ 'document.crtuser',$cancreate,$usertype);
+ my $srchbutton = &mt('Search');
+ if ($env{'form.action'} eq 'singlestudent') {
+ $srchbutton = &mt('Search and Enroll');
+ } elsif ($cancreate && $responsemsg ne '' && $inexact) {
+ $srchbutton = &mt('Search or Add New User');
+ }
+ my $output = <<"ENDBLOCK";
+ENDBLOCK
+ if ($env{'form.phase'} eq '') {
+ my $defdom=$env{'request.role.domain'};
+ my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
+ 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 <
+//
END
}
# =================================================================== Phase two
-sub print_user_modification_page {
- my $r=shift;
- my $ccuname =&LONCAPA::clean_username($env{'form.ccuname'});
- my $ccdomain=&LONCAPA::clean_domain($env{'form.ccdomain'});
+sub print_user_selection_page {
+ my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype) = @_;
+ my @fields = ('username','domain','lastname','firstname','permanentemail');
+ my $sortby = $env{'form.sortby'};
- unless (($ccuname) && ($ccdomain)) {
- &print_username_entry_form($r);
- return;
+ if (!grep(/^\Q$sortby\E$/,@fields)) {
+ $sortby = 'lastname';
}
- my $defdom=$env{'request.role.domain'};
-
- my ($krbdef,$krbdefdom) =
- &Apache::loncommon::get_kerberos_defaults($defdom);
+ my ($jsback,$elements) = &crumb_utilities();
- my %param = ( formname => 'document.cu',
- kerb_def_dom => $krbdefdom,
- kerb_def_auth => $krbdef
- );
- $loginscript = &Apache::loncommon::authform_header(%param);
- $authformkrb = &Apache::loncommon::authform_kerberos(%param);
+ my $jscript = (<
+//
+
+ENDSCRIPT
- my %loaditem;
+ my %lt=&Apache::lonlocal::texthash(
+ 'usrch' => "User Search to add/modify roles",
+ 'stusrch' => "User Search to enroll student",
+ 'memsrch' => "User Search to enroll member",
+ 'usel' => "Select a user to add/modify roles",
+ 'stusel' => "Select a user to enroll as a student",
+ 'memsel' => "Select a user to enroll as a member",
+ 'username' => "username",
+ 'domain' => "domain",
+ 'lastname' => "last name",
+ 'firstname' => "first name",
+ 'permanentemail' => "permanent e-mail",
+ );
+ if ($context eq 'requestcrs') {
+ $r->print('
');
+ } else {
+ $r->print(&Apache::loncommon::start_page('User Management',$jscript));
- my $groupslist;
- my %curr_groups = &Apache::longroup::coursegroups();
- if (%curr_groups) {
- $groupslist = join('","',sort(keys(%curr_groups)));
- $groupslist = '"'.$groupslist.'"';
- }
-
- if ($env{'request.role'} =~ m-^dc\./($match_domain)/$-) {
- my $dcdom = $1;
- $loaditem{'onload'} = "document.cu.coursedesc.value='';";
- my @rolevals = ('st','ta','ep','in','cc');
- my (@crsroles,@grproles);
- for (my $i=0; $i<@rolevals; $i++) {
- $crsroles[$i]=&Apache::lonnet::plaintext($rolevals[$i],'Course');
- $grproles[$i]=&Apache::lonnet::plaintext($rolevals[$i],'Group');
- }
- my $rolevalslist = join('","',@rolevals);
- my $crsrolenameslist = join('","',@crsroles);
- my $grprolenameslist = join('","',@grproles);
- my $pickcrsfirst = '<--'.&mt('Pick course first');
- my $pickgrpfirst = '<--'.&mt('Pick group first');
- $dc_setcourse_code = <<"ENDSCRIPT";
- function setCourse() {
- var course = document.cu.dccourse.value;
- if (course != "") {
- if (document.cu.dcdomain.value != document.cu.origdom.value) {
- alert("You must select a course in the current domain");
- return;
- }
- var userrole = document.cu.role.options[document.cu.role.selectedIndex].value
- var section="";
- var numsections = 0;
- var newsecs = new Array();
- for (var i=0; i 1)) {
- alert("In each course, each user may only have one student role at a time. You had selected "+numsections+" sections.\\nPlease modify your selections so they include no more than one section.")
- return;
- }
- for (var j=0; j 0)) {
- alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
- section = "";
- }
- var coursename = "_$dcdom"+"_"+course+"_"+userrole
- var numcourse = getIndex(document.cu.dccourse);
- if (numcourse == "-1") {
- alert("There was a problem with your course selection");
- return
+ my %breadcrumb_text = &singleuser_breadcrumb($crstype);
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({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',});
+ if ($env{'form.action'} eq 'singleuser') {
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
+ 'Course_Change_Privileges'));
+ $r->print("$lt{'usrch'} ");
+ $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
+ $r->print('
');
}
- document.cu.submit();
}
-
- function getIndex(caller) {
- for (var i=0;iprint('
');
} else {
- $nondc_setsection_code = <<"ENDSECCODE";
- function setSections() {
- var re1 = /^currsec_/;
- var groups = new Array($groupslist);
- for (var i=0;i 0) {
- if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) {
- sections = sections + "," + document.cu.elements[i+1].value;
- }
- }
- else {
- sections = document.cu.elements[i+1].value;
- }
- var newsecs = document.cu.elements[i+1].value;
- var numsplit;
- if (newsecs != null && newsecs != "") {
- numsplit = newsecs.split(/,/g);
- numsec = numsec + numsplit.length;
- }
-
- if ((role == 'st') && (numsec > 1)) {
- alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.")
- return;
- }
- else if (numsplit != null) {
- for (var j=0; jprint($response.''.&Apache::loncommon::end_page());
+ }
+}
+
+sub print_user_query_page {
+ my ($r,$caller) = @_;
+# 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;
+}
+
+sub print_user_modification_page {
+ my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype) = @_;
+ 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);
+ 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);
+ 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.")
+ .' '
+ .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
+ ,'','')
+ .'
';
+ $env{'form.phase'} = '';
+ &print_username_entry_form($r,$context,$response,undef,undef,$crstype);
+ 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);
+ return;
}
}
}
- document.cu.submit();
+ } else {
+ $newuser = 0;
}
-ENDSECCODE
+ 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,
+ $groupslist,$newuser,$formname,\%loaditem);
+ my $args = {'add_entries' => \%loaditem};
+ if ($env{'form.popup'}) {
+ $args->{'no_nav_bar'} = 1;
}
- 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,});
+ &Apache::loncommon::start_page('User Management',$js,$args);
+ my %breadcrumb_text = &singleuser_breadcrumb($crstype);
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage($form)",
+ text=>$breadcrumb_text{'search'},
+ faq=>282,bug=>'Instructor Interface',});
+
+ if ($env{'form.phase'} eq 'userpicked') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage($form,'get_user_info','select')",
+ text=>$breadcrumb_text{'userpicked'},
+ faq=>282,bug=>'Instructor Interface',});
+ }
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage($form,'$env{'form.phase'}','modify')",
+ text=>$breadcrumb_text{'modify'},
+ faq=>282,bug=>'Instructor Interface',});
+ my $helpitem = 'Course_Change_Privileges';
+ if ($env{'form.action'} eq 'singlestudent') {
+ $helpitem = 'Course_Add_Student';
+ }
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
+ $helpitem);
my $forminfo =<<"ENDFORMINFO";
-
');
+ my $user_auth_text = &user_authentication($ccuname,$ccdomain,$formname);
+ my ($user_quota_text,$user_tools_text,$user_reqcrs_text);
+ if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
+ (&Apache::lonnet::allowed('mut',$ccdomain))) {
+ # Current user has quota modification privileges
+ $user_quota_text = &portfolio_quota($ccuname,$ccdomain);
+ }
+ if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
+ if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
+ # Get the user's portfolio information
+ my %portq = &Apache::lonnet::get('environment',['portfolioquota'],
+ $ccdomain,$ccuname);
+ my %lt=&Apache::lonlocal::texthash(
+ 'dska' => "Disk space allocated to user's portfolio files",
+ '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_quota_text = <$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 or Personal Information Page settings for this user.",
+ 'ifch' => "If a change is required, contact a domain coordinator for the domain",
+ );
+ $user_tools_text = <$lt{'utav'}
+$lt{'yodo'} $lt{'ifch'}: $ccdomain
+ENDNOTOOLSPRIV
+ }
+ }
+ if ($user_auth_text ne '') {
+ $r->print('
'.$user_auth_text);
+ if ($user_quota_text ne '') {
+ $r->print($user_quota_text);
+ }
+ if ($user_tools_text ne '') {
+ $r->print($user_tools_text);
+ }
+ if ($env{'form.action'} eq 'singlestudent') {
+ $r->print(&date_sections_select($context,$newuser,$formname));
+ }
+ } elsif ($user_quota_text ne '') {
+ $r->print('
'.$user_quota_text);
+ if ($user_tools_text ne '') {
+ $r->print($user_tools_text);
+ }
+ if ($env{'form.action'} eq 'singlestudent') {
+ $r->print(&date_sections_select($context,$newuser,$formname));
+ }
+ } elsif ($user_tools_text ne '') {
+ $r->print('
'.
&Apache::loncommon::end_data_table_header_row());
- foreach my $type ('Construction Space','Course','Group','Domain','System','Unknown') {
- if ($output{$type}) {
- $r->print($output{$type}."\n");
- }
- }
- $r->print(&Apache::loncommon::end_data_table());
- }
- } # End of unless
- my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
- if ($currentauth=~/^krb(4|5):/) {
- $currentauth=~/^krb(4|5):(.*)/;
- my $krbdefdom=$2;
- my %param = ( formname => 'document.cu',
- kerb_def_dom => $krbdefdom
- );
- $loginscript = &Apache::loncommon::authform_header(%param);
- }
- # Check for a bad authentication type
- unless ($currentauth=~/^krb(4|5):/ or
- $currentauth=~/^unix:/ or
- $currentauth=~/^internal:/ or
- $currentauth=~/^localauth:/
- ) { # bad authentication scheme
- if (&Apache::lonnet::allowed('mau',$ccdomain)) {
- &initialize_authen_forms();
- my %lt=&Apache::lonlocal::texthash(
- 'err' => "ERROR",
- 'uuas' => "This user has an unrecognized authentication scheme",
- 'sldb' => "Please specify login data below",
- 'ld' => "Login Data"
- );
- $r->print(<
-
-$lt{'err'}:
-$lt{'uuas'} ($currentauth). $lt{'sldb'}.
-
$lt{'ld'}
-
$generalrule
-
$authformkrb
-
$authformint
-
$authformfsys
-
$authformloc
-ENDBADAUTH
- } else {
- # This user is not allowed to modify the user's
- # authentication scheme, so just notify them of the problem
- my %lt=&Apache::lonlocal::texthash(
- 'err' => "ERROR",
- 'uuas' => "This user has an unrecognized authentication scheme",
- 'adcs' => "Please alert a domain coordinator of this situation"
- );
- $r->print(<
- $lt{'err'}:
-$lt{'uuas'} ($currentauth). $lt{'adcs'}.
-
-ENDBADAUTH
- }
- } else { # Authentication type is valid
- my $authformcurrent='';
- my $authform_other='';
- &initialize_authen_forms();
- if ($currentauth=~/^krb(4|5):/) {
- $authformcurrent=$authformkrb;
- $authform_other="
";
- }
- $authformcurrent.=' (will override current values) ';
- if (&Apache::lonnet::allowed('mau',$ccdomain)) {
- # Current user has login modification privileges
- my %lt=&Apache::lonlocal::texthash(
- 'ccld' => "Change Current Login Data",
- 'enld' => "Enter New Login Data"
- );
- $r->print(<
-
-
$lt{'ccld'}
-
$generalrule
-
$authformnop
-
$authformcurrent
-
$lt{'enld'}
-$authform_other
-ENDOTHERAUTHS
- } else {
- if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
- my %lt=&Apache::lonlocal::texthash(
- 'ccld' => "Change Current Login Data",
- 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
- 'ifch' => "If a change is required, contact a domain coordinator for the domain",
- );
- $r->print(<
-
$lt{'ccld'}
-$lt{'yodo'} $lt{'ifch'}: $ccdomain
-ENDNOPRIV
- }
+ foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') {
+ if ($output{$type}) {
+ $r->print($output{$type}."\n");
}
- if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
- # Current user has quota modification privileges
- $r->print(&portfolio_quota($ccuname,$ccdomain));
- }
- } ## 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'}) &&
+ }
+ $r->print(&Apache::loncommon::end_data_table());
+ }
+ return;
+}
+
+sub new_coauthor_roles {
+ my ($r,$ccuname,$ccdomain) = @_;
+ my $addrolesdisplay = 0;
+ #
+ # Co-Author
+ #
+ if (&Apache::lonuserutils::authorpriv($env{'user.name'},
+ $env{'request.role.domain'}) &&
($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
# No sense in assigning co-author role to yourself
- my $cuname=$env{'user.name'};
+ $addrolesdisplay = 1;
+ my $cuname=$env{'user.name'};
my $cudom=$env{'request.role.domain'};
- my %lt=&Apache::lonlocal::texthash(
- 'cs' => "Construction Space",
- 'act' => "Activate",
+ my %lt=&Apache::lonlocal::texthash(
+ 'cs' => "Construction Space",
+ 'act' => "Activate",
'rol' => "Role",
'ext' => "Extent",
'sta' => "Start",
@@ -940,45 +1703,61 @@ ENDNOPRIV
'caa' => "Assistant Co-Author",
'ssd' => "Set Start Date",
'sed' => "Set End Date"
- );
- $r->print('
'.
&Apache::loncommon::end_data_table_row();
}
- }
+ }
}
$domaintext.= &Apache::loncommon::end_data_table();
if ($num_domain_level > 0) {
$r->print($domaintext);
+ $addrolesdisplay = 1;
}
-#
-# Course and group levels
-#
+ return $addrolesdisplay;
+}
+
+sub user_authentication {
+ my ($ccuname,$ccdomain,$formname) = @_;
+ my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
+ my $outcome;
+ # Check for a bad authentication type
+ if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
+ # bad authentication scheme
+ 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"
+ );
+ if (&Apache::lonnet::allowed('mau',$ccdomain)) {
+ &initialize_authen_forms($ccdomain,$formname);
- if ($env{'request.role'} =~ m{^dc\./($match_domain)/$}) {
- $r->print(&course_level_dc($1,'Course'));
- $r->print(''."\n");
+ 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
+ my %lt=&Apache::lonlocal::texthash (
+ 'ld' => "Login Data",
+ 'ccld' => "Change Current Login Data",
+ 'enld' => "Enter New Login Data"
+ );
+ $outcome =
+ ''."\n".
+ '
");
- }
- } else { # End of if ($env ... ) logic
- my $putresult;
- if ($quotachanged) {
- $putresult = &Apache::lonnet::put
- ('environment',\%changeHash,
- $env{'form.ccdomain'},$env{'form.ccuname'});
+ $r->print(''.&mt('Unable to successfully change environment for').' '.
+ $env{'form.ccuname'}.' '.&mt('in domain').' '.
+ $env{'form.ccdomain'}.' ');
}
- # 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",
- 'disk' => "Disk space allocated to user's portfolio files",
- );
- $r->print(<<"END");
-
');
- &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'});
+ } 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,\%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 = &mt('course');
+ } elsif ($context eq 'author') {
+ $contextname = &mt('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 [_1] roles:",$contextname));
+ } else {
+ $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles:",$contextname));
+ }
+ 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)
+ .'');
+ }
+ if ($env{'form.action'} eq 'singlestudent') {
+ &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype);
+ $r->print('
'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key));
+ $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.',''.$key.''));
} else {
- $r->print('
'.&mt('[_1] may not be used as the name for a section, as it is the name of a course group.',$key));
+ $r->print(&mt('[_1] may not be used as the name for a section, as it is the name of a course group.',''.$key.''));
}
- $r->print(' '.&mt('Please go back and choose a different section name.').'
');
+
+ # Remove non alphanumeric values from section
+ $env{'form.sections'}=~s/\W//g;
+
+ # 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 ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
+ 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);
+ 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 will be available when the member next logs in.'));
+ } else {
+ $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.'));
+ }
+ $r->print('
');
+ }
+ } else {
+ $r->print(&mt('unable to enroll').": ".$enroll_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 =
+ ''."\n";
+ foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
+ $outcome .= ''."\n";
+ }
+ if ($env{'form.origname'} ne '') {
+ $outcome .= ''."\n";
+ }
+ foreach my $item ('sortby','seluname','seludom') {
+ if (exists($env{'form.'.$item})) {
+ $outcome .= ''."\n";
+ }
+ }
+ if ($uhome eq 'no_host') {
+ $outcome .= ''."\n";
+ }
+ $outcome .= ''."\n".
+ ''."\n".
+ ''."\n".
+ '';
+ return $outcome;
}
sub quota_admin {
@@ -1554,12 +3544,39 @@ sub quota_admin {
my $quotachanged;
if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
# Current user has quota modification privileges
- $quotachanged = 1;
- $changeHash->{'portfolioquota'} = $setquota;
+ if (ref($changeHash) eq 'HASH') {
+ $quotachanged = 1;
+ $changeHash->{'portfolioquota'} = $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 (&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;
+ $changeHash->{$context.'.'.$tool} = $settool;
+ }
+ }
+ return $toolchanged;
+}
+
sub build_roles {
my ($sectionstr,$sections,$role) = @_;
my $num_sections = 0;
@@ -1596,19 +3613,28 @@ sub build_roles {
# ========================================================== Custom Role Editor
sub custom_role_editor {
- my $r=shift;
- my $rolename=$env{'form.rolename'};
-
- if ($rolename eq 'make new role') {
- $rolename=$env{'form.newrolename'};
+ my ($r) = @_;
+ my $action = $env{'form.customroleaction'};
+ my $rolename;
+ if ($action eq 'new') {
+ $rolename=$env{'form.newrolename'};
+ } else {
+ $rolename=$env{'form.rolename'};
}
$rolename=~s/[^A-Za-z0-9]//gs;
-
- if (!$rolename) {
+ if (!$rolename || $env{'form.phase'} eq 'pickrole') {
&print_username_entry_form($r);
return;
}
+ my ($crstype,$context);
+ if ($env{'request.course.id'}) {
+ $crstype = &Apache::loncommon::course_type();
+ $context = 'course';
+ } else {
+ $context = 'domain';
+ $crstype = $env{'form.templatecrstype'};
+ }
# ------------------------------------------------------- What can be assigned?
my %full=();
my %courselevel=();
@@ -1617,7 +3643,6 @@ sub custom_role_editor {
my $dompriv='';
my $coursepriv='';
my $body_top;
- my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
my ($rdummy,$roledef)=
&Apache::lonnet::get('roles',["rolesdef_$rolename"]);
# ------------------------------------------------------- Does this role exist?
@@ -1626,6 +3651,9 @@ sub custom_role_editor {
$body_top .= &mt('Existing Role').' "';
# ------------------------------------------------- Get current role privileges
($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
+ if ($crstype eq 'Community') {
+ $syspriv =~ s/bre\&S//;
+ }
} else {
$body_top .= &mt('New Role').' "';
$roledef='';
@@ -1662,28 +3690,95 @@ sub custom_role_editor {
}
$full{$priv}=1;
}
+ my ($jsback,$elements) = &crumb_utilities();
my $button_code = "\n";
my $head_script = "\n";
- $head_script .= ''."\n";
+
+ $head_script .= "\n".$jsback."\n"
+ .'// ]]>'."\n"
+ .''."\n";
$r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.form1,'pickrole','')",
+ text=>"Pick custom role",
+ faq=>282,bug=>'Instructor Interface',},
+ {href=>"javascript:backPage(document.form1,'','')",
+ text=>"Edit custom role",
+ faq=>282,bug=>'Instructor Interface',});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
+ 'Course_Editing_Custom_Roles'));
+
$r->print($body_top);
my %lt=&Apache::lonlocal::texthash(
'prv' => "Privilege",
'crl' => "Course Level",
'dml' => "Domain Level",
'ssl' => "System Level");
- $r->print('Select a Template ');
- $r->print('');
+
+
+ $r->print('
'
+ .'
');
+ if ($context_code) {
+ $r->print('
'
+ .''
+ .'
'
+ );
+ }
+ $r->print(' ');
+
$r->print(<
+'.
+ ''.
+ ''."\n".''."\n".
+ ''."\n".
+ ''.
&Apache::loncommon::end_page());
}
# --------------------------------------------------------
sub make_script_template {
- my ($role) = @_;
+ my ($role,$crstype) = @_;
my %full_c=();
my %full_d=();
my %full_s=();
@@ -1727,6 +3830,7 @@ sub make_script_template {
$full_d{$priv}=1;
}
foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
+ next if (($crstype eq 'Community') && ($item eq 'bre&S'));
my ($priv,$restrict)=split(/\&/,$item);
$full_s{$priv}=1;
}
@@ -1737,34 +3841,35 @@ sub make_script_template {
my ($priv_item, $dummy) = split(/\&/,$priv);
$role_c{$priv_item} = 1;
}
+ my %role_d;
+ @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
+ foreach my $priv(@temp) {
+ my ($priv_item, $dummy) = split(/\&/,$priv);
+ $role_d{$priv_item} = 1;
+ }
+ my %role_s;
+ @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
+ foreach my $priv(@temp) {
+ my ($priv_item, $dummy) = split(/\&/,$priv);
+ $role_s{$priv_item} = 1;
+ }
foreach my $priv_item (keys(%full_c)) {
my ($priv, $dummy) = split(/\&/,$priv_item);
- if (exists($role_c{$priv})) {
+ if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
+ (exists($role_s{$priv}))) {
$return_script .= "document.form1.$priv"."_c.checked = true;\n";
} else {
$return_script .= "document.form1.$priv"."_c.checked = false;\n";
}
}
- my %role_d;
- @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
- foreach my $priv(@temp) {
- my ($priv_item, $dummy) = split(/\&/,$priv);
- $role_d{$priv_item} = 1;
- }
foreach my $priv_item (keys(%full_d)) {
my ($priv, $dummy) = split(/\&/,$priv_item);
- if (exists($role_d{$priv})) {
+ if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
$return_script .= "document.form1.$priv"."_d.checked = true;\n";
} else {
$return_script .= "document.form1.$priv"."_d.checked = false;\n";
}
}
- my %role_s;
- @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
- foreach my $priv(@temp) {
- my ($priv_item, $dummy) = split(/\&/,$priv);
- $role_s{$priv_item} = 1;
- }
foreach my $priv_item (keys(%full_s)) {
my ($priv, $dummy) = split(/\&/,$priv_item);
if (exists($role_s{$priv})) {
@@ -1778,36 +3883,53 @@ sub make_script_template {
}
# ----------------------------------------------------------
sub make_button_code {
- my ($role) = @_;
- my $label = &Apache::lonnet::plaintext($role);
- my $button_code = '';
+ my ($role,$crstype) = @_;
+ my $label = &Apache::lonnet::plaintext($role,$crstype);
+ my $button_code = '';
return ($button_code);
}
# ---------------------------------------------------------- Call to definerole
sub set_custom_role {
- my ($r) = @_;
-
+ my ($r,$context) = @_;
my $rolename=$env{'form.rolename'};
-
$rolename=~s/[^A-Za-z0-9]//gs;
-
if (!$rolename) {
- &print_username_entry_form($r);
+ &custom_role_editor($r);
return;
}
+ my ($jsback,$elements) = &crumb_utilities();
+ my $jscript = ''."\n";
+
+ $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.customresult,'pickrole','')",
+ text=>"Pick custom role",
+ faq=>282,bug=>'Instructor Interface',},
+ {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
+ text=>"Edit custom role",
+ faq=>282,bug=>'Instructor Interface',},
+ {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
+ text=>"Result",
+ faq=>282,bug=>'Instructor Interface',});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
+ 'Course_Editing_Custom_Roles'));
- $r->print(&Apache::loncommon::start_page('Save Custom Role').'
');
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').' "');
} else {
$r->print(&mt('New Role').' "');
$roledef='';
}
- $r->print($rolename.'"
');
+ $r->print($rolename.'"');
# ------------------------------------------------------- What can be assigned?
my $sysrole='';
my $domrole='';
@@ -1847,57 +3969,2076 @@ sub set_custom_role {
$url,
$env{'user.domain'},
$env{'user.name'},
- $rolename));
+ $rolename,undef,undef,undef,$context));
}
- $r->print('
';
+ }
+ $output .= '';
+ }
+ }
+ $output .= '';
+ $r->print($output);
+ return;
+}
+
+sub visible_in_cat {
+ my ($cdom,$cnum) = @_;
+ my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
+ my ($cathash,%settable,@vismsgs,$cansetvis);
+ my %visactions = &Apache::lonlocal::texthash(
+ vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.',
+ gen => 'Courses can be both self-cataloging, based on an institutional code (e.g., fs08phy231), or can be assigned categories from a hierarchy defined for the domain.',
+ miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.',
+ yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
+ coca => 'Courses can be absent from the Catalog, because they do not have an institutional code, have no assigned category, or have been specifically excluded.',
+ make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
+ take => 'Take the following action to ensure the course appears in the Catalog:',
+ dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
+ dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
+ dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
+ dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
+ dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
+ dc_chgcat => 'Ask a domain coordinator to change the category assigned to the course, as the one currently assigned is no longer used in the domain',
+ dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
+ );
+ $visactions{'unhide'} = &mt('Use [_1]Set course environment[_2] to change the "Exclude from course catalog" setting.','"','"');
+ $visactions{'chgcat'} = &mt('Use [_1]Set course environment[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','"','"');
+ $visactions{'addcat'} = &mt('Use [_1]Set course environment[_2] to assign a category to the course.','"','"');
+ if (ref($domconf{'coursecategories'}) eq 'HASH') {
+ if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
+ $settable{'togglecats'} = 1;
+ }
+ if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
+ $settable{'categorize'} = 1;
+ }
+ $cathash = $domconf{'coursecategories'}{'cats'};
+ }
+ if ($settable{'togglecats'} && $settable{'categorize'}) {
+ $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
+ } elsif ($settable{'togglecats'}) {
+ $cansetvis = &mt('You are able to choose to exclude this course from the catalog, but only a Domain Coordinator may assign a course category.');
+ } elsif ($settable{'categorize'}) {
+ $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
+ } else {
+ $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
+ }
+
+ my %currsettings =
+ &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
+ $cdom,$cnum);
+ my $visible = 0;
+ if ($currsettings{'internal.coursecode'} ne '') {
+ if (ref($domconf{'coursecategories'}) eq 'HASH') {
+ $cathash = $domconf{'coursecategories'}{'cats'};
+ if (ref($cathash) eq 'HASH') {
+ if ($cathash->{'instcode::0'} eq '') {
+ push(@vismsgs,'dc_addinst');
+ } else {
+ $visible = 1;
+ }
+ } else {
+ $visible = 1;
+ }
+ } else {
+ $visible = 1;
+ }
+ } else {
+ if (ref($cathash) eq 'HASH') {
+ if ($cathash->{'instcode::0'} ne '') {
+ push(@vismsgs,'dc_instcode');
+ }
+ } else {
+ push(@vismsgs,'dc_instcode');
+ }
+ }
+ if ($currsettings{'categories'} ne '') {
+ my $cathash;
+ if (ref($domconf{'coursecategories'}) eq 'HASH') {
+ $cathash = $domconf{'coursecategories'}{'cats'};
+ if (ref($cathash) eq 'HASH') {
+ if (keys(%{$cathash}) == 0) {
+ push(@vismsgs,'dc_catalog');
+ } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
+ push(@vismsgs,'dc_categories');
+ } else {
+ my @currcategories = split('&',$currsettings{'categories'});
+ my $matched = 0;
+ foreach my $cat (@currcategories) {
+ if ($cathash->{$cat} ne '') {
+ $visible = 1;
+ $matched = 1;
+ last;
+ }
+ }
+ if (!$matched) {
+ if ($settable{'categorize'}) {
+ push(@vismsgs,'chgcat');
+ } else {
+ push(@vismsgs,'dc_chgcat');
+ }
+ }
+ }
+ }
+ }
+ } else {
+ if (ref($cathash) eq 'HASH') {
+ if ((keys(%{$cathash}) > 1) ||
+ (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
+ if ($settable{'categorize'}) {
+ push(@vismsgs,'addcat');
+ } else {
+ push(@vismsgs,'dc_addcat');
+ }
+ }
+ }
+ }
+ if ($currsettings{'hidefromcat'} eq 'yes') {
+ $visible = 0;
+ if ($settable{'togglecats'}) {
+ unshift(@vismsgs,'unhide');
+ } else {
+ unshift(@vismsgs,'dc_unhide')
+ }
+ }
+ return ($visible,$cansetvis,\@vismsgs,\%visactions);
+}
+
+sub new_selfenroll_dom_row {
+ my ($newdom,$num) = @_;
+ my $domdesc = &Apache::lonnet::domain($newdom);
+ my $output;
+ if ($domdesc ne '') {
+ $output .= &Apache::loncommon::start_data_table_row()
+ .'
';
+ my $startform =
+ &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
+ $curr->{'rolelog_start_date'},undef,
+ undef,undef,undef,undef,undef,undef,$nolink);
+ my $endform =
+ &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
+ $curr->{'rolelog_end_date'},undef,
+ undef,undef,undef,undef,undef,undef,$nolink);
+ my %lt = &rolechg_contexts($crstype);
+ $output .= '
'.&mt('Window during which changes occurred:').' '.
+ '
'.&mt('After:').
+ '
'.$startform.'
'.
+ '
'.&mt('Before:').'
'.
+ '
'.$endform.'
'.
+ '
'.
+ '
'.
+ '
'.&mt('Role:').' '.
+ '
'.
+ '
'.
+ '
'.
+ &mt('Context:').'
'
+ .'
';
+
+ # Update Display button
+ $output .= '
'
+ .''
+ .'
';
+
+ # Server version info
+ $output .= '
'
+ .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
+ ,'2.6.99.0');
+ if ($version) {
+ $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
+ }
+ $output .= '
';
+ return $output;
+}
+
+sub rolechg_contexts {
+ my ($crstype) = @_;
+ my %lt = &Apache::lonlocal::texthash (
+ any => 'Any',
+ auto => 'Automated enrollment',
+ updatenow => 'Roster Update',
+ createcourse => 'Course Creation',
+ course => 'User Management in course',
+ domain => 'User Management in domain',
+ selfenroll => 'Self-enrolled',
+ requestcourses => 'Course Request',
+ );
+ if ($crstype eq 'Community') {
+ $lt{'createcourse'} = &mt('Community Creation');
+ $lt{'course'} = &mt('User Management in community');
+ $lt{'requestcourses'} = &mt('Community Request');
+ }
+ return %lt;
+}
#-------------------------------------------------- functions for &phase_two
+sub user_search_result {
+ my ($context,$srch) = @_;
+ my %allhomes;
+ my %inst_matches;
+ my %srch_results;
+ my ($response,$currstate,$forcenewuser,$dirsrchres);
+ $srch->{'srchterm'} =~ s/\s+/ /g;
+ if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
+ $response = &mt('Invalid search.');
+ }
+ if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
+ $response = &mt('Invalid search.');
+ }
+ if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
+ $response = &mt('Invalid search.');
+ }
+ if ($srch->{'srchterm'} eq '') {
+ $response = &mt('You must enter a search term.');
+ }
+ if ($srch->{'srchterm'} =~ /^\s+$/) {
+ $response = &mt('Your search term must contain more than just spaces.');
+ }
+ if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
+ if (($srch->{'srchdomain'} eq '') ||
+ ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
+ $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
+ }
+ }
+ if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
+ ($srch->{'srchin'} eq 'alc')) {
+ if ($srch->{'srchby'} eq 'uname') {
+ my $unamecheck = $srch->{'srchterm'};
+ if ($srch->{'srchtype'} eq 'contains') {
+ if ($unamecheck !~ /^\w/) {
+ $unamecheck = 'a'.$unamecheck;
+ }
+ }
+ if ($unamecheck !~ /^$match_username$/) {
+ $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
+ }
+ }
+ }
+ if ($response ne '') {
+ $response = ''.$response.'';
+ }
+ if ($srch->{'srchin'} eq 'instd') {
+ my $instd_chk = &directorysrch_check($srch);
+ if ($instd_chk ne 'ok') {
+ $response = ''.$instd_chk.''.
+ ' '.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'
';
+ }
+ }
+ if ($response ne '') {
+ return ($currstate,$response);
+ }
+ if ($srch->{'srchby'} eq 'uname') {
+ if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
+ if ($env{'form.forcenew'}) {
+ if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
+ my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
+ if ($uhome eq 'no_host') {
+ my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
+ my $showdom = &display_domain_info($env{'request.role.domain'});
+ $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
+ } else {
+ $currstate = 'modify';
+ }
+ } else {
+ $currstate = 'modify';
+ }
+ } else {
+ if ($srch->{'srchin'} eq 'dom') {
+ if ($srch->{'srchtype'} eq 'exact') {
+ my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
+ if ($uhome eq 'no_host') {
+ ($currstate,$response,$forcenewuser) =
+ &build_search_response($context,$srch,%srch_results);
+ } else {
+ $currstate = 'modify';
+ my $uname = $srch->{'srchterm'};
+ my $udom = $srch->{'srchdomain'};
+ $srch_results{$uname.':'.$udom} =
+ { &Apache::lonnet::get('environment',
+ ['firstname',
+ 'lastname',
+ 'permanentemail'],
+ $udom,$uname)
+ };
+ }
+ } else {
+ %srch_results = &Apache::lonnet::usersearch($srch);
+ ($currstate,$response,$forcenewuser) =
+ &build_search_response($context,$srch,%srch_results);
+ }
+ } else {
+ my $courseusers = &get_courseusers();
+ if ($srch->{'srchtype'} eq 'exact') {
+ if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
+ $currstate = 'modify';
+ } else {
+ ($currstate,$response,$forcenewuser) =
+ &build_search_response($context,$srch,%srch_results);
+ }
+ } else {
+ foreach my $user (keys(%$courseusers)) {
+ my ($cuname,$cudomain) = split(/:/,$user);
+ if ($cudomain eq $srch->{'srchdomain'}) {
+ my $matched = 0;
+ if ($srch->{'srchtype'} eq 'begins') {
+ if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
+ $matched = 1;
+ }
+ } else {
+ if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
+ $matched = 1;
+ }
+ }
+ if ($matched) {
+ $srch_results{$user} =
+ {&Apache::lonnet::get('environment',
+ ['firstname',
+ 'lastname',
+ 'permanentemail'],
+ $cudomain,$cuname)};
+ }
+ }
+ }
+ ($currstate,$response,$forcenewuser) =
+ &build_search_response($context,$srch,%srch_results);
+ }
+ }
+ }
+ } elsif ($srch->{'srchin'} eq 'alc') {
+ $currstate = 'query';
+ } elsif ($srch->{'srchin'} eq 'instd') {
+ ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
+ if ($dirsrchres eq 'ok') {
+ ($currstate,$response,$forcenewuser) =
+ &build_search_response($context,$srch,%srch_results);
+ } else {
+ my $showdom = &display_domain_info($srch->{'srchdomain'});
+ $response = ''.
+ &mt('Institutional directory search is not available in domain: [_1]',$showdom).
+ ' '.
+ &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
+ '
';
+ }
+ }
+ }
+ return ($currstate,$response,$forcenewuser,\%srch_results);
+}
+
+sub directorysrch_check {
+ my ($srch) = @_;
+ my $can_search = 0;
+ my $response;
+ my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
+ ['directorysrch'],$srch->{'srchdomain'});
+ my $showdom = &display_domain_info($srch->{'srchdomain'});
+ if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
+ if (!$dom_inst_srch{'directorysrch'}{'available'}) {
+ return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
+ }
+ if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
+ if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
+ return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
+ }
+ my @usertypes = split(/:/,$env{'environment.inststatus'});
+ if (!@usertypes) {
+ push(@usertypes,'default');
+ }
+ if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
+ foreach my $type (@usertypes) {
+ if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
+ $can_search = 1;
+ last;
+ }
+ }
+ }
+ if (!$can_search) {
+ my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
+ my @longtypes;
+ foreach my $item (@usertypes) {
+ if (defined($insttypes->{$item})) {
+ push (@longtypes,$insttypes->{$item});
+ } elsif ($item eq 'default') {
+ push (@longtypes,&mt('other'));
+ }
+ }
+ my $insttype_str = join(', ',@longtypes);
+ return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
+ }
+ } else {
+ $can_search = 1;
+ }
+ } else {
+ return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
+ }
+ my %longtext = &Apache::lonlocal::texthash (
+ uname => 'username',
+ lastfirst => 'last name, first name',
+ lastname => 'last name',
+ contains => 'contains',
+ exact => 'as exact match to',
+ begins => 'begins with',
+ );
+ if ($can_search) {
+ if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
+ if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
+ return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
+ }
+ } else {
+ return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
+ }
+ }
+ if ($can_search) {
+ if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
+ if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
+ return 'ok';
+ } else {
+ return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
+ }
+ } else {
+ if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
+ ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
+ ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
+ return 'ok';
+ } else {
+ return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
+ }
+ }
+ }
+}
+
+sub get_courseusers {
+ my %advhash;
+ my $classlist = &Apache::loncoursedata::get_classlist();
+ my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
+ foreach my $role (sort(keys(%coursepersonnel))) {
+ foreach my $user (split(/\,/,$coursepersonnel{$role})) {
+ if (!exists($classlist->{$user})) {
+ $classlist->{$user} = [];
+ }
+ }
+ }
+ return $classlist;
+}
+
+sub build_search_response {
+ my ($context,$srch,%srch_results) = @_;
+ my ($currstate,$response,$forcenewuser);
+ my %names = (
+ 'uname' => 'username',
+ 'lastname' => 'last name',
+ 'lastfirst' => 'last name, first name',
+ 'crs' => 'this course',
+ 'dom' => 'LON-CAPA domain',
+ 'instd' => 'the institutional directory for domain',
+ );
+
+ my %single = (
+ begins => 'A match',
+ contains => 'A match',
+ exact => 'An exact match',
+ );
+ my %nomatch = (
+ begins => 'No match',
+ contains => 'No match',
+ exact => 'No exact match',
+ );
+ if (keys(%srch_results) > 1) {
+ $currstate = 'select';
+ } else {
+ if (keys(%srch_results) == 1) {
+ $currstate = 'modify';
+ $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
+ if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
+ $response .= ': '.&display_domain_info($srch->{'srchdomain'});
+ }
+ } else { # Search has nothing found. Prepare message to user.
+ $response = '';
+ if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
+ $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
+ ''.$srch->{'srchterm'}.'',
+ &display_domain_info($srch->{'srchdomain'}));
+ } else {
+ $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
+ ''.$srch->{'srchterm'}.'');
+ }
+ $response .= '';
+
+ if ($srch->{'srchin'} ne 'alc') {
+ $forcenewuser = 1;
+ my $cansrchinst = 0;
+ if ($srch->{'srchdomain'}) {
+ my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
+ if (ref($domconfig{'directorysrch'}) eq 'HASH') {
+ if ($domconfig{'directorysrch'}{'available'}) {
+ $cansrchinst = 1;
+ }
+ }
+ }
+ if ((($srch->{'srchby'} eq 'lastfirst') ||
+ ($srch->{'srchby'} eq 'lastname')) &&
+ ($srch->{'srchin'} eq 'dom')) {
+ if ($cansrchinst) {
+ $response .= ' '.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
+ }
+ }
+ if ($srch->{'srchin'} eq 'crs') {
+ $response .= ' '.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
+ }
+ }
+ my $createdom = $env{'request.role.domain'};
+ if ($context eq 'requestcrs') {
+ if ($env{'form.coursedom'} ne '') {
+ $createdom = $env{'form.coursedom'};
+ }
+ }
+ if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $createdom)) {
+ my $cancreate =
+ &Apache::lonuserutils::can_create_user($createdom,$context);
+ my $targetdom = ''.$createdom.'';
+ if ($cancreate) {
+ my $showdom = &display_domain_info($createdom);
+ $response .= '
'
+ .''.&mt('To add a new user:').''
+ .' ';
+ if ($context eq 'requestcrs') {
+ $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
+ } else {
+ $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
+ }
+ $response .='
'
+ .&mt("Set 'Domain/institution to search' to: [_1]",''.$showdom.'')
+ .'
'
+ .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'','')
+ .'
';
+ if ($context eq 'requestcrs') {
+ $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
+ } else {
+ $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
+ }
+ $response .= ' '
+ .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
+ ,' '
+ ,'')
+ .'
';
+ }
+ }
+ }
+ }
+ return ($currstate,$response,$forcenewuser);
+}
+
+sub display_domain_info {
+ my ($dom) = @_;
+ my $output = $dom;
+ if ($dom ne '') {
+ my $domdesc = &Apache::lonnet::domain($dom,'description');
+ if ($domdesc ne '') {
+ $output .= ' ('.$domdesc.')';
+ }
+ }
+ return $output;
+}
+
+sub crumb_utilities {
+ my %elements = (
+ crtuser => {
+ srchterm => 'text',
+ srchin => 'selectbox',
+ srchby => 'selectbox',
+ srchtype => 'selectbox',
+ srchdomain => 'selectbox',
+ },
+ crtusername => {
+ srchterm => 'text',
+ srchdomain => 'selectbox',
+ },
+ docustom => {
+ rolename => 'selectbox',
+ newrolename => 'textbox',
+ },
+ studentform => {
+ srchterm => 'text',
+ srchin => 'selectbox',
+ srchby => 'selectbox',
+ srchtype => 'selectbox',
+ srchdomain => 'selectbox',
+ },
+ );
+
+ my $jsback .= qq|
+function backPage(formname,prevphase,prevstate) {
+ if (typeof prevphase == 'undefined') {
+ formname.phase.value = '';
+ }
+ else {
+ formname.phase.value = prevphase;
+ }
+ if (typeof prevstate == 'undefined') {
+ formname.currstate.value = '';
+ }
+ else {
+ formname.currstate.value = prevstate;
+ }
+ formname.submit();
+}
+|;
+ return ($jsback,\%elements);
+}
+
sub course_level_table {
my (%inccourses) = @_;
my $table = '';
# Custom Roles?
- my %customroles=&my_custom_roles();
+ my %customroles=&Apache::lonuserutils::my_custom_roles();
my %lt=&Apache::lonlocal::texthash(
'exs' => "Existing sections",
'new' => "Define new section",
@@ -1912,12 +6053,13 @@ sub course_level_table {
'end' => "End"
);
- foreach my $protectedcourse (sort( keys(%inccourses))) {
+ foreach my $protectedcourse (sort(keys(%inccourses))) {
my $thiscourse=$protectedcourse;
$thiscourse=~s:_:/:g;
my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
+ my $isowner = &is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
my $area=$coursedata{'description'};
- my $type=$coursedata{'type'};
+ my $crstype=$coursedata{'type'};
if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
my ($domain,$cnum)=split(/\//,$thiscourse);
my %sections_count;
@@ -1927,86 +6069,37 @@ sub course_level_table {
&Apache::loncommon::get_sections($domain,$cnum);
}
}
- foreach my $role ('st','ta','ep','in','cc') {
- if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
- my $plrole=&Apache::lonnet::plaintext($role);
- $table .= &Apache::loncommon::start_data_table_row().
-'
-
'.$plrole.'
-
'.$area.' Domain: '.$domain.'
'."\n";
- if ($role ne 'cc') {
- if (%sections_count) {
- my $currsec = &course_sections(\%sections_count,$protectedcourse.'_'.$role);
- $table .=
- '