--- loncom/interface/loncreateuser.pm 2006/03/21 18:51:28 1.111
+++ loncom/interface/loncreateuser.pm 2007/06/11 22:13:07 1.154
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.111 2006/03/21 18:51:28 albertel Exp $
+# $Id: loncreateuser.pm,v 1.154 2007/06/11 22:13:07 banghart Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -64,6 +64,9 @@ use Apache::Constants qw(:common :http);
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonlocal;
+use Apache::longroup;
+use lib '/home/httpd/lib/perl/';
+use LONCAPA qw(:DEFAULT :match);
my $loginscript; # piece of javascript used in two separate instances
my $generalrule;
@@ -96,8 +99,8 @@ sub initialize_authen_forms {
sub my_custom_roles {
my %returnhash=();
my %rolehash=&Apache::lonnet::dump('roles');
- foreach (keys %rolehash) {
- if ($_=~/^rolesdef\_(\w+)$/) {
+ foreach my $key (keys %rolehash) {
+ if ($key=~/^rolesdef\_(\w+)$/) {
$returnhash{$1}=$1;
}
}
@@ -113,12 +116,86 @@ 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'}.'
'.
+ $lt{'cuqu'}.': '.$currquota.' Mb. '.
+ $defaultinfo.' '.$lt{'chqu'}.
+ ': '.
+ ' '.
+ ' Mb';
+ return $output;
+}
+
# =================================================================== Phase one
sub print_username_entry_form {
my ($r) = @_;
my $defdom=$env{'request.role.domain'};
- my @domains = &Apache::loncommon::get_domains();
my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
my $selscript=&Apache::loncommon::studentbrowser_javascript();
my $start_page =
@@ -139,7 +216,7 @@ sub print_username_entry_form {
'nr' => "Name of Role",
'cre' => "Custom Role Editor"
);
- 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");
@@ -170,7 +247,8 @@ ENDCUSTOM
sub user_modification_js {
- my ($pjump_def, $dc_setcourse_code)=@_;
+ my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
+
return <
@@ -189,66 +267,8 @@ sub user_modification_js {
pclose();
}
- function setSections() {
- var re1 = /^currsec_/;
- for (var i=0;i 0) {
- if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) {
- sections = sections + "," + document.cu.elements[i+1].value;
- }
- }
- else {
- sections = document.cu.elements[i+1].value;
- }
- var newsecs = document.cu.elements[i+1].value;
- if (newsecs != null && newsecs != "") {
- var numsplit = newsecs.split(/,/g);
- numsec = numsec + numsplit.length;
- }
- if ((role == 'st') && (numsec > 1)) {
- alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.")
- return;
- }
- else {
- document.cu.elements[i+2].value = sections;
- }
- }
- }
- }
- }
- document.cu.submit();
- }
+ $nondc_setsection_code
+
END
}
@@ -256,11 +276,8 @@ END
# =================================================================== Phase two
sub print_user_modification_page {
my $r=shift;
- my $ccuname=$env{'form.ccuname'};
- my $ccdomain=$env{'form.ccdomain'};
-
- $ccuname=~s/\W//g;
- $ccdomain=~s/\W//g;
+ my $ccuname =&LONCAPA::clean_username($env{'form.ccuname'});
+ my $ccdomain=&LONCAPA::clean_domain($env{'form.ccdomain'});
unless (($ccuname) && ($ccdomain)) {
&print_username_entry_form($r);
@@ -279,14 +296,35 @@ sub print_user_modification_page {
$loginscript = &Apache::loncommon::authform_header(%param);
$authformkrb = &Apache::loncommon::authform_kerberos(%param);
- $ccuname=~s/\W//g;
- $ccdomain=~s/\W//g;
+ $ccuname =&LONCAPA::clean_username($ccuname);
+ $ccdomain=&LONCAPA::clean_domain($ccdomain);
my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
my $dc_setcourse_code = '';
- my $loaditem;
- if ($env{'request.role'} =~ m-^dc\./(\w+)/$-) {
+ my $nondc_setsection_code = '';
+
+ my %loaditem;
+
+ my $groupslist;
+ my %curr_groups = &Apache::longroup::coursegroups();
+ if (%curr_groups) {
+ $groupslist = join('","',sort(keys(%curr_groups)));
+ $groupslist = '"'.$groupslist.'"';
+ }
+
+ if ($env{'request.role'} =~ m-^dc\./($match_domain)/$-) {
my $dcdom = $1;
- $loaditem = qq|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;
@@ -298,6 +336,7 @@ sub print_user_modification_page {
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
}
- 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();
@@ -356,12 +419,90 @@ sub print_user_modification_page {
return -1;
}
ENDSCRIPT
- }
+ } 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;
+ }
- my $js = &user_modification_js($pjump_def, $dc_setcourse_code);
+ 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; j $loaditem,});
+ $js,{'add_entries' => \%loaditem,});
my $forminfo =<<"ENDFORMINFO";