--- loncom/interface/loncreateuser.pm 2006/05/09 17:21:13 1.116
+++ loncom/interface/loncreateuser.pm 2007/11/10 03:51:46 1.193
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.116 2006/05/09 17:21:13 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.193 2007/11/10 03:51:46 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -64,9 +64,11 @@ use Apache::Constants qw(:common :http);
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonlocal;
+use Apache::longroup;
+use Apache::lonuserutils;
+use LONCAPA qw(:DEFAULT :match);
my $loginscript; # piece of javascript used in two separate instances
-my $generalrule;
my $authformnop;
my $authformkrb;
my $authformint;
@@ -74,14 +76,24 @@ my $authformfsys;
my $authformloc;
sub initialize_authen_forms {
+ my ($dom,$curr_authtype) = @_;
my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
$krbdefdom= uc($krbdefdom);
my %param = ( formname => 'document.cu',
- kerb_def_dom => $krbdefdom
- );
+ kerb_def_dom => $krbdefdom,
+ domain => $dom,
+ );
+ my %abv_auth = &auth_abbrev();
+ if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):$/) {
+ my $long_auth = $1;
+ my %abv_auth = &auth_abbrev();
+ $param{'curr_authtype'} = $abv_auth{$long_auth};
+ if ($long_auth =~ /^krb(4|5)$/) {
+ $param{'curr_kerb_ver'} = $1;
+ }
+ }
# no longer static due to configurable kerberos defaults
# $loginscript = &Apache::loncommon::authform_header(%param);
- $generalrule = &Apache::loncommon::authform_authorwarning(%param);
$authformnop = &Apache::loncommon::authform_nochange(%param);
# no longer static due to configurable kerberos defaults
# $authformkrb = &Apache::loncommon::authform_kerberos(%param);
@@ -90,18 +102,14 @@ sub initialize_authen_forms {
$authformloc = &Apache::loncommon::authform_local(%param);
}
-
-# ======================================================= Existing Custom Roles
-
-sub my_custom_roles {
- my %returnhash=();
- my %rolehash=&Apache::lonnet::dump('roles');
- foreach (keys %rolehash) {
- if ($_=~/^rolesdef\_(\w+)$/) {
- $returnhash{$1}=$1;
- }
- }
- return %returnhash;
+sub auth_abbrev {
+ my %abv_auth = (
+ krb4 => 'krb',
+ internal => 'int',
+ localuth => 'loc',
+ unix => 'fsys',
+ );
+ return %abv_auth;
}
# ==================================================== Figure out author access
@@ -113,61 +121,181 @@ sub authorpriv {
return 1;
}
+# ====================================================
+
+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",
+ );
+ my ($currquota,$quotatype,$inststatus,$defquota) =
+ &Apache::loncommon::get_user_quota($ccuname,$ccdomain);
+ my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
+ my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo);
+ if ($inststatus ne '') {
+ if ($usertypes->{$inststatus} ne '') {
+ $longinsttype = $usertypes->{$inststatus};
+ }
+ }
+ $custom_on = ' ';
+ $custom_off = ' checked="checked" ';
+ my $quota_javascript = <<"END_SCRIPT";
+
+END_SCRIPT
+ 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);
+ }
+ }
+ my $output = $quota_javascript.
+ '
'.$lt{'disk'}.'
'.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_row().
+ ''.$lt{'cuqu'}.': '.$currquota.' Mb. '.
+ $defaultinfo.' | '.
+ &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::start_data_table_row().
+ ''.$lt{'chqu'}.
+ ': '.
+ ' '.
+ ' Mb | '.
+ &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::end_data_table();
+ return $output;
+}
+
# =================================================================== Phase one
sub print_username_entry_form {
- my ($r) = @_;
+ my ($r,$response,$srch,$forcenewuser) = @_;
my $defdom=$env{'request.role.domain'};
- my @domains = &Apache::loncommon::get_domains();
- my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
- my $selscript=&Apache::loncommon::studentbrowser_javascript();
+ my $formtoset = 'crtuser';
+ if (exists($env{'form.startrolename'})) {
+ $formtoset = 'docustom';
+ $env{'form.rolename'} = $env{'form.startrolename'};
+ }
+
+ my ($jsback,$elements) = &crumb_utilities();
+
+ my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
+ ''."\n";
+
+ my %loaditems = (
+ 'onload' => "javascript:setFormElements(document.$formtoset)",
+ );
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();
+ &Apache::loncommon::start_page('User Management',
+ $jscript,{'add_entries' => \%loaditems,});
+ if ($env{'form.action'} eq 'singleuser') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.crtuser)",
+ text=>"Single user search",
+ faq=>282,bug=>'Instructor Interface',});
+ } elsif ($env{'form.action'} eq 'custom') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.crtuser)",
+ text=>"Pick custom role",});
+ }
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
+ my %existingroles=&Apache::lonuserutils::my_custom_roles();
my $choice=&Apache::loncommon::select_form('make new role','rolename',
('make new role' => 'Generate new role ...',%existingroles));
my %lt=&Apache::lonlocal::texthash(
- 'siur' => "Set Individual User Roles",
+ 'srch' => "User Search",
+ or => "or",
'usr' => "Username",
'dom' => "Domain",
- 'usrr' => "User Roles",
'ecrp' => "Edit Custom Role Privileges",
'nr' => "Name of Role",
- 'cre' => "Custom Role Editor"
+ 'cre' => "Custom Role Editor",
+ 'mod' => "to add/modify roles",
);
- my $help = &Apache::loncommon::help_open_menu('',undef,undef,'',282,'Instructor Interface');
+ 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
-
-ENDDOCUMENT
- if (&Apache::lonnet::allowed('mcr','/')) {
- $r->print(<print($start_page."\n".$crumbs);
+ if ($env{'form.action'} eq 'singleuser') {
+ $r->print("
+$lt{'srch'} $sellink $lt{'mod'}$helpsiur
+$response");
+ $r->print(&entry_form($defdom,$srch,$forcenewuser));
+ } elsif ($env{'form.action'} eq 'custom') {
+ if (&Apache::lonnet::allowed('mcr','/')) {
+ $r->print(<
-
-$lt{'ecrp'}$helpecpr
+
+
+$lt{'ecrp'}$helpecpr
$lt{'nr'}: $choice
ENDCUSTOM
+ }
}
$r->print(&Apache::loncommon::end_page());
}
+sub entry_form {
+ my ($dom,$srch,$forcenewuser) = @_;
+ my $userpicker =
+ &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
+ 'document.crtuser');
+ my $srchbutton = &mt('Search');
+ my $output = <<"ENDDOCUMENT";
+
+ENDDOCUMENT
+ return $output;
+}
sub user_modification_js {
my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
@@ -192,99 +320,174 @@ sub user_modification_js {
$nondc_setsection_code
- 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 newseclist = document.cu.elements[i+1].value;
- var newsecs = new Array();
- if (newseclist != null && newseclist != "") {
- newsecs = newseclist.split(/,/g);
- numsec = numsec + newsecs.length;
- }
- if ((role == 'st') && (numsec > 1)) {
- alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.")
- return;
- }
- else {
- for (var j=0; j
END
}
# =================================================================== Phase two
-sub print_user_modification_page {
- my $r=shift;
- my $ccuname=$env{'form.ccuname'};
- my $ccdomain=$env{'form.ccdomain'};
+sub print_user_selection_page {
+ my ($r,$response,$srch,$srch_results,$operation,$srcharray) = @_;
+ my @fields = ('username','domain','lastname','firstname','permanentemail');
+ my $sortby = $env{'form.sortby'};
+
+ if (!grep(/^\Q$sortby\E$/,@fields)) {
+ $sortby = 'lastname';
+ }
+
+ my ($jsback,$elements) = &crumb_utilities();
+
+ my $jscript = (<
+function pickuser(uname,udom) {
+ document.usersrchform.seluname.value=uname;
+ document.usersrchform.seludom.value=udom;
+ document.usersrchform.phase.value="userpicked";
+ document.usersrchform.submit();
+}
- $ccuname=~s/\W//g;
- $ccdomain=~s/\W//g;
+$jsback
+
+ENDSCRIPT
- unless (($ccuname) && ($ccdomain)) {
- &print_username_entry_form($r);
- return;
+ my %lt=&Apache::lonlocal::texthash(
+ 'usrch' => "User Search to add/modify roles",
+ 'stusrch' => "User Search to enroll student",
+ 'usel' => "Select a user to add/modify roles",
+ 'stusel' => "Select a user to enroll as a student",
+ 'username' => "username",
+ 'domain' => "domain",
+ 'lastname' => "last name",
+ 'firstname' => "first name",
+ 'permanentemail' => "permanent e-mail",
+ );
+ if ($operation eq 'createuser') {
+ $r->print(&Apache::loncommon::start_page('User Management',$jscript));
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.usersrchform,'','')",
+ text=>"Create/modify user",
+ faq=>282,bug=>'Instructor Interface',},
+ {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
+ text=>"Select User",
+ faq=>282,bug=>'Instructor Interface',});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
+ $r->print("$lt{'usrch'}
");
+ $r->print(&entry_form($srch->{'srchdomain'},$srch));
+ $r->print(''.$lt{'usel'}.'
');
+ } else {
+ $r->print($jscript."$lt{'stusrch'}
");
+ $r->print(&Apache::londropadd::single_user_entry_form($srch->{'srchdomain'},$srch));
+ $r->print(''.$lt{'stusel'}.'
');
+ }
+ $r->print(''.&Apache::loncommon::end_page());
+ } else {
+ $r->print(''."\n".
+ ''."\n");
}
+}
+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) = @_;
+ if (($ccuname eq '') || ($ccdomain eq '')) {
+ my $usermsg = &mt('No username and/or domain provided.');
+ &print_username_entry_form($r,$usermsg);
+ return;
+ }
+ my %abv_auth = &auth_abbrev();
+ my ($curr_authtype,%rulematch,%inst_results,$curr_kerb_ver,$newuser,
+ %alerts,%curr_rules);
+ my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
+ if ($uhome eq 'no_host') {
+ $newuser = 1;
+ my $checkhash;
+ my $checks = { 'username' => 1 };
+ $checkhash->{$ccuname.':'.$ccdomain} = { 'status' => 'new' };
+ &Apache::loncommon::user_rule_check($checkhash,$checks,
+ \%alerts,\%rulematch,\%inst_results,\%curr_rules);
+ if (ref($alerts{$ccuname.':'.$ccdomain}) eq 'HASH') {
+ if ($alerts{$ccuname.':'.$ccdomain}{'username'}) {
+ my $domdesc =
+ &Apache::lonnet::domain($ccdomain,'description');
+ 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');
+ }
+ &print_username_entry_form($r,$userchkmsg);
+ return;
+ }
+ }
+ } else {
+ $newuser = 0;
+ my $currentauth =
+ &Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
+ if ($currentauth =~ /^(krb4|krb5|unix|internal|localauth):/) {
+ $curr_authtype = $abv_auth{$1};
+ if ($currentauth =~ /^krb(4|5)/) {
+ $curr_kerb_ver = $1;
+ }
+ }
+ }
+ if ($response) {
+ $response = '
'.$response
+ }
my $defdom=$env{'request.role.domain'};
my ($krbdef,$krbdefdom) =
@@ -292,28 +495,41 @@ sub print_user_modification_page {
my %param = ( formname => 'document.cu',
kerb_def_dom => $krbdefdom,
- kerb_def_auth => $krbdef
- );
+ kerb_def_auth => $krbdef,
+ curr_authtype => $curr_authtype,
+ curr_kerb_ver => $curr_kerb_ver,
+ domain => $ccdomain,
+ );
$loginscript = &Apache::loncommon::authform_header(%param);
$authformkrb = &Apache::loncommon::authform_kerberos(%param);
- $ccuname=~s/\W//g;
- $ccdomain=~s/\W//g;
my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
my $dc_setcourse_code = '';
- my $nondc_setsection_code = '';
+ my $nondc_setsection_code = '';
+
my %loaditem;
my $groupslist;
- my %curr_groups = &Apache::loncommon::coursegroups();
+ my %curr_groups = &Apache::longroup::coursegroups();
if (%curr_groups) {
$groupslist = join('","',sort(keys(%curr_groups)));
$groupslist = '"'.$groupslist.'"';
}
- if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
+ if ($env{'request.role'} =~ m-^dc\./($match_domain)/$-) {
my $dcdom = $1;
- $loaditem{'onload'} = "document.cu.coursedesc.value=''";
+ $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;
@@ -373,18 +589,27 @@ sub print_user_modification_page {
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
}
- else {
- var coursename = "_$dcdom"+"_"+course+"_"+userrole
- document.cu.elements[numcourse].name = "act"+coursename
- document.cu.elements[numcourse+4].name = "sec"+coursename
- document.cu.elements[numcourse+4].value = section
- document.cu.elements[numcourse+5].name = "start"+coursename
- document.cu.elements[numcourse+6].name = "end"+coursename
+ else {
+ document.cu.elements[numcourse].name = "act"+coursename;
+ var numnewsec = getIndex(document.cu.newsec);
+ if (numnewsec != "-1") {
+ document.cu.elements[numnewsec].name = "sec"+coursename;
+ document.cu.elements[numnewsec].value = section;
+ }
+ var numstart = getIndex(document.cu.start);
+ if (numstart != "-1") {
+ document.cu.elements[numstart].name = "start"+coursename;
+ }
+ var numend = getIndex(document.cu.end);
+ if (numend != "-1") {
+ document.cu.elements[numend].name = "end"+coursename
+ }
}
}
document.cu.submit();
@@ -408,11 +633,9 @@ ENDSCRIPT
var str = document.cu.elements[i].name;
var checkcurr = str.match(re1);
if (checkcurr != null) {
- var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;
if (document.cu.elements[i-1].checked == true) {
- var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;
- match = re2.exec(str);
- var role = match[1];
+ var match = str.split('_');
+ var role = match[3];
if (role == 'cc') {
alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
}
@@ -445,15 +668,17 @@ ENDSCRIPT
sections = document.cu.elements[i+1].value;
}
var newsecs = document.cu.elements[i+1].value;
+ var numsplit;
if (newsecs != null && newsecs != "") {
- var numsplit = newsecs.split(/,/g);
+ 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 {
+ else if (numsplit != null) {
for (var j=0; j'."\n".$jsback."\n".
+ $javascript_validations.'';
my $start_page =
- &Apache::loncommon::start_page('Create Users, Change User Privileges',
+ &Apache::loncommon::start_page('User Management',
$js,{'add_entries' => \%loaditem,});
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.cu)",
+ text=>"Create/modify user",
+ faq=>282,bug=>'Instructor Interface',});
+
+ if ($env{'form.phase'} eq 'userpicked') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.cu,'get_user_info','select')",
+ text=>"Select a user",
+ faq=>282,bug=>'Instructor Interface',});
+ }
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.cu,'$env{'form.phase'}','modify')",
+ text=>"Set user role",
+ faq=>282,bug=>'Instructor Interface',});
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
my $forminfo =<<"ENDFORMINFO";