--- loncom/interface/loncreateuser.pm 2007/12/05 17:40:29 1.201
+++ loncom/interface/loncreateuser.pm 2007/12/07 23:09:30 1.204
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.201 2007/12/05 17:40:29 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.204 2007/12/07 23:09:30 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -627,7 +627,7 @@ sub print_user_modification_page {
}
ENDSCRIPT
} else {
- $nondc_setsection_code =
+ $nondc_setsection_code =
&Apache::lonuserutils::setsections_javascript('cu',$groupslist);
}
my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
@@ -787,7 +787,7 @@ ENDCHANGEUSER
&personal_data_display($ccuname,$ccdomain,$newuser,
%inst_results));
if ($context eq 'domain') {
- $r->print(&Apache::lonuserutils::forceid_change());
+ $r->print(&Apache::lonuserutils::forceid_change($context));
}
$r->print('');
my $user_auth_text =
@@ -1198,7 +1198,7 @@ ENDBADAUTH
}
} else { # Authentication type is valid
&initialize_authen_forms($ccdomain,$currentauth);
- my $authformnop_row;
+ my $authformnop_row;
if (&Apache::lonnet::allowed('mau',$ccdomain)) {
$authformnop_row = &Apache::loncommon::start_data_table_row();
}
@@ -1591,17 +1591,23 @@ sub update_user_data {
# Check to see if we need to change user information
foreach my $item ('firstname','middlename','lastname','generation','permanentemail','id') {
# Strip leading and trailing whitespace
- $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
+ $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
}
# Check to see if we can change the ID/student number
my $forceid = $env{'form.forceid'};
my $recurseid = $env{'form.recurseid'};
my $newuser = 0;
- my $disallowed_id = 0;
my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
- if (!$forceid) {
- $env{'form.cid'} = $userenv{'id'};
- } elsif ($env{'form.cid'} ne $userenv{'id'}) {
+ my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
+ $env{'form.ccuname'});
+ if (($uidhash{$env{'form.ccuname'}}) &&
+ ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
+ (!$forceid)) {
+ if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
+ $env{'form.cid'} = $userenv{'id'};
+ }
+ }
+ if ($env{'form.cid'} ne $userenv{'id'}) {
my $checkhash;
my $checks = { 'id' => 1 };
$checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
@@ -1612,15 +1618,17 @@ sub update_user_data {
\%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
if (ref($alerts{'id'}) eq 'HASH') {
if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
- $disallowed_id = 1;
+ $env{'form.cid'} = $userenv{'id'};
}
}
}
my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota,
- $inststatus,$isdefault,$defquotatext);
+ $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
+ $newdefquotatext);
my ($defquota,$settingstatus) =
&Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
my %changeHash;
+ $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
if ($userenv{'portfolioquota'} ne '') {
$oldportfolioquota = $userenv{'portfolioquota'};
if ($env{'form.customquota'} == 1) {
@@ -1630,15 +1638,16 @@ sub update_user_data {
$newportfolioquota = $env{'form.portfolioquota'};
$newportfolioquota =~ s/[^\d\.]//g;
}
- if ($newportfolioquota != $userenv{'portfolioquota'}) {
+ if ($newportfolioquota != $oldportfolioquota) {
$quotachanged = "a_admin($newportfolioquota,\%changeHash);
}
} else {
$quotachanged = "a_admin('',\%changeHash);
$newportfolioquota = $defquota;
- $isdefault = 1;
+ $newisdefault = 1;
}
} else {
+ $oldisdefault = 1;
$oldportfolioquota = $defquota;
if ($env{'form.customquota'} == 1) {
if ($env{'form.portfolioquota'} eq '') {
@@ -1650,21 +1659,14 @@ sub update_user_data {
$quotachanged = "a_admin($newportfolioquota,\%changeHash);
} else {
$newportfolioquota = $defquota;
- $isdefault = 1;
+ $newisdefault = 1;
}
}
- if ($isdefault) {
- 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});
- }
- }
+ if ($oldisdefault) {
+ $olddefquotatext = &get_defaultquota_text($settingstatus);
+ }
+ if ($newisdefault) {
+ $newdefquotatext = &get_defaultquota_text($settingstatus);
}
if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
($env{'form.cfirstname'} ne $userenv{'firstname'} ||
@@ -1675,18 +1677,30 @@ sub update_user_data {
$env{'form.cpermanentemail'} ne $userenv{'permanentemail'} )) {
$namechanged = 1;
}
- if ($namechanged) {
- # Make the change
+ if ($namechanged || $quotachanged) {
$changeHash{'firstname'} = $env{'form.cfirstname'};
$changeHash{'middlename'} = $env{'form.cmiddlename'};
$changeHash{'lastname'} = $env{'form.clastname'};
$changeHash{'generation'} = $env{'form.cgeneration'};
$changeHash{'id'} = $env{'form.cid'};
$changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
- my $putresult = &Apache::lonnet::put
- ('environment',\%changeHash,
- $env{'form.ccdomain'},$env{'form.ccuname'});
- if ($putresult eq 'ok') {
+ my ($quotachgresult,$namechgresult);
+ if ($quotachanged) {
+ $quotachgresult =
+ &Apache::lonnet::put('environment',\%changeHash,
+ $env{'form.ccdomain'},$env{'form.ccuname'});
+ }
+ if ($namechanged) {
+ # Make the change
+ $namechgresult =
+ &Apache::lonnet::modifyuser($env{'form.ccdomain'},
+ $env{'form.ccuname'},$changeHash{'id'},undef,undef,
+ $changeHash{'firstname'},$changeHash{'middlename'},
+ $changeHash{'lastname'},$changeHash{'generation'},
+ $changeHash{'id'},undef,$changeHash{'permanentemail'});
+ }
+ if (($namechanged && $namechgresult eq 'ok') ||
+ ($quotachanged && $quotachgresult eq 'ok')) {
# Tell the user we changed the name
my %lt=&Apache::lonlocal::texthash(
'uic' => "User Information Changed",
@@ -1723,7 +1737,7 @@ END
$userenv{'generation'} |
$userenv{'id'} |
$userenv{'permanentemail'} |
- $oldportfolioquota Mb |
+ $oldportfolioquota Mb $olddefquotatext |
END
$r->print(&Apache::loncommon::end_data_table_row().
&Apache::loncommon::start_data_table_row());
@@ -1735,22 +1749,28 @@ END
$env{'form.cgeneration'} |
$env{'form.cid'} |
$env{'form.cpermanentemail'} |
- $newportfolioquota Mb $defquotatext |
+ $newportfolioquota Mb $newdefquotatext |
END
$r->print(&Apache::loncommon::end_data_table_row().
&Apache::loncommon::end_data_table());
- if (($forceid) && ($recurseid) && (!$disallowed_id) &&
- (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
- my %userupdate = (
+ if ($env{'form.cid'} ne $userenv{'id'}) {
+ &Apache::lonnet::idput($env{'form.ccdomain'},
+ ($env{'form.ccuname'} => $env{'form.cid'}));
+ if (($recurseid) &&
+ (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
+ my %userupdate = (
lastname => $env{'form.clasaname'},
middlename => $env{'form.cmiddlename'},
firstname => $env{'form.cfirstname'},
generation => $env{'fora.cgeneration'},
id => $env{'form.cid'},
);
- my $idresult = &propagate_id_change($env{'form.ccname'},
- $env{'form.ccdomain'},\%userupdate);
- $r->print('
'.$idresult.'
');
+ my $idresult =
+ &Apache::lonuserutils::propagate_id_change(
+ $env{'form.ccuname'},$env{'form.ccdomain'},
+ \%userupdate);
+ $r->print('
'.$idresult.'
');
+ }
}
if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
($env{'form.ccuname'} eq $env{'user.name'})) {
@@ -1766,14 +1786,8 @@ END
$env{'form.ccdomain'}.'');
}
} else { # End of if ($env ... ) logic
- my $putresult;
- if ($quotachanged) {
- $putresult = &Apache::lonnet::put
- ('environment',\%changeHash,
- $env{'form.ccdomain'},$env{'form.ccuname'});
- }
- # They did not want to change the users name but we can
- # still tell them what the name is
+ # They did not want to change the users name or quota but we can
+ # still tell them what the name and quota are
my %lt=&Apache::lonlocal::texthash(
'id' => "ID/Student number",
'mail' => "Permanent e-mail",
@@ -1782,19 +1796,12 @@ END
$r->print(<<"END");
$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
END
- if ($userenv{'permanentemail'} eq '') {
- $r->print('
');
- } else {
- $r->print(' ('.$lt{'mail'}.': '.
- $userenv{'permanentemail'}.')');
- }
- if ($putresult eq 'ok') {
- if ($oldportfolioquota != $newportfolioquota) {
- $r->print(''.$lt{'disk'}.': '.$newportfolioquota.' Mb '.
- $defquotatext.'
');
- &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'});
- }
+ if ($userenv{'permanentemail'} ne '') {
+ $r->print('
['.$lt{'mail'}.': '.
+ $userenv{'permanentemail'}.']');
}
+ $r->print('
['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
+ $olddefquotatext.']');
}
}
##
@@ -1816,10 +1823,10 @@ END
$r->print(&mt('Revoking [_1] in [_2]: [_3]',
$role,$scope,''.$result.'').'
');
if ($role eq 'st') {
- my $result =
+ my $result =
&Apache::lonuserutils::classlist_drop($scope,
$env{'form.ccuname'},$env{'form.ccdomain'},
- $now);
+ $now);
$r->print($result);
}
}
@@ -1843,10 +1850,10 @@ END
$r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
''.$result.'').'
');
if ($role eq 'st') {
- my $result =
+ my $result =
&Apache::lonuserutils::classlist_drop($scope,
$env{'form.ccuname'},$env{'form.ccdomain'},
- $now);
+ $now);
$r->print($result);
}
}
@@ -2023,6 +2030,23 @@ END
$r->print(&Apache::loncommon::end_page());
}
+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 =
@@ -2393,11 +2417,13 @@ sub handler {
$context = 'domain';
}
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['action','state']);
+ ['action','state','callingform','roletype','showrole','bulkaction']);
&Apache::lonhtmlcommon::clear_breadcrumbs();
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"/adm/createuser",
- text=>"User Management"});
+ if ($env{'form.action'} ne 'dateselect') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"/adm/createuser",
+ text=>"User Management"});
+ }
my ($permission,$allowed) = &get_permission($context);
if (!$allowed) {
$env{'user.error.msg'}=
@@ -2447,7 +2473,7 @@ sub handler {
if (! exists($env{'form.state'})) {
&Apache::lonuserutils::print_expire_menu($r,$context);
} elsif ($env{'form.state'} eq 'done') {
- &Apache::lonuserutils::expire_user_list($r);
+ &Apache::lonuserutils::expire_user_list($r,$context);
} else {
&Apache::lonuserutils::print_expire_menu($r,$context);
}
@@ -2512,31 +2538,46 @@ sub handler {
&custom_role_editor($r);
}
} elsif ($env{'form.action'} eq 'listusers' && $permission->{'view'}) {
- my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
- my $formname = 'studentform';
- if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
- ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
- &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
- $formname);
- my $js = &add_script($jscript).$cb_jscript;
- my $loadcode =
- &Apache::lonuserutils::course_selector_loadcode($formname);
- if ($loadcode ne '') {
- $r->print(&header($js,{'onload' => $loadcode,}));
+ if ($env{'form.phase'} eq 'bulkchange') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'backPage(document.studentform)',
+ text=>"List Users"});
+ my $setting = $env{'form.roletype'};
+ my $choice = $env{'form.bulkaction'};
+ $r->print(&header());
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
+ 'User_Management_List'));
+ if ($permission->{'cusr'}) {
+ &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
+ }
+ } else {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/createuser?action=listusers',
+ text=>"List Users"});
+ my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
+ my $formname = 'studentform';
+ if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
+ ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
+ &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
+ $formname);
+ $jscript .= &verify_user_display();
+ my $js = &add_script($jscript).$cb_jscript;
+ my $loadcode =
+ &Apache::lonuserutils::course_selector_loadcode($formname);
+ if ($loadcode ne '') {
+ $r->print(&header($js,{'onload' => $loadcode,}));
+ } else {
+ $r->print(&header($js));
+ }
} else {
- $r->print(&header($js));
+ $r->print(&header(&add_script(&verify_user_display())));
}
- } else {
- $r->print(&header());
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
+ 'User_Management_List'));
+ &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
+ $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
+ $r->print(&Apache::loncommon::end_page());
}
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>'/adm/createuser?action=listusers',
- text=>"List Users"});
- $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
- 'User_Management_List'));
- &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
- $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
- $r->print(&Apache::loncommon::end_page());
} elsif ($env{'form.action'} eq 'expire' && $permission->{'cusr'}) {
$r->print(&header());
&Apache::lonhtmlcommon::add_breadcrumb
@@ -2547,26 +2588,37 @@ sub handler {
if (! exists($env{'form.state'})) {
&Apache::lonuserutils::print_expire_menu($r,$context);
} elsif ($env{'form.state'} eq 'done') {
- &Apache::lonuserutiles::expire_user_list($r);
+ &Apache::lonuserutiles::expire_user_list($r,$context);
} else {
&print_expire_menu($r,$context);
}
$r->print(&Apache::loncommon::end_page());
+ } elsif ($env{'form.action'} eq 'dateselect') {
+ if ($permission->{'cusr'}) {
+ $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
+ &Apache::lonuserutils::date_section_selector($context).
+ &Apache::loncommon::end_page());
+ } else {
+ $r->print(&header().
+ ''.&mt('You do not have permission to modify dates or sections for users').''.
+ &Apache::loncommon::end_page());
+ }
} else {
$r->print(&header());
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management')); $r->print(&print_main_menu($permission));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
+ $r->print(&print_main_menu($permission));
$r->print(&Apache::loncommon::end_page());
}
return OK;
}
sub header {
- my ($jscript,$loaditems) = @_;
+ my ($jscript,$loaditems,$args) = @_;
my $start_page;
if (ref($loaditems) eq 'HASH') {
- $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems,});
+ $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
} else {
- $start_page=&Apache::loncommon::start_page('User Management',$jscript);
+ $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
}
return $start_page;
}
@@ -2576,6 +2628,20 @@ sub add_script {
return '';
}
+sub verify_user_display {
+ my $output = <<"END";
+
+function display_update() {
+ document.studentform.action.value = 'listusers';
+ document.studentform.phase.value = 'display';
+ document.studentform.submit();
+}
+
+END
+ return $output;
+
+}
+
###############################################################
###############################################################
# Menu Phase One
@@ -3150,9 +3216,9 @@ sub course_level_table {
'.$area.' Domain: '.$domain.' | '."\n";
if ($role ne 'cc') {
if (%sections_count) {
- my $currsec =
+ my $currsec =
&Apache::lonuserutils::course_sections(\%sections_count,
- $protectedcourse.'_'.$role);
+ $protectedcourse.'_'.$role);
$table .=
''.
'
@@ -3192,7 +3258,7 @@ ENDTIMEENTRY
'.$plrole.' |
'.$area.' | '."\n";
if (%sections_count) {
- my $currsec =
+ my $currsec =
&Apache::lonuserutils::course_sections(\%sections_count,
$customrole);
$table.=
|