[LON-CAPA-cvs] cvs: loncom /interface loncreateuser.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Fri, 21 Dec 2007 18:16:40 -0000
This is a MIME encoded message
--raeburn1198261000
Content-Type: text/plain
raeburn Fri Dec 21 13:16:40 2007 EDT
Modified files:
/loncom/interface loncreateuser.pm
Log:
- Remove superfluous code used to find $cnum and $cdom - already got with lonuserutils::get_course_identity()
- Add -1 as final arg in split to force blank entry for $role if last item absent from key for user's roles hash.
- Move processing of role addition to subroutine: &uopdate_roles()
- Subroutine: &enroll_single_student() adds student if in "singlestudent" mode
- Only show quota information on results screen, after updating user, if viewer
has 'mpq' priv in the domain.
--raeburn1198261000
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071221131640.txt"
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.219 loncom/interface/loncreateuser.pm:1.220
--- loncom/interface/loncreateuser.pm:1.219 Fri Dec 21 12:27:57 2007
+++ loncom/interface/loncreateuser.pm Fri Dec 21 13:16:39 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.219 2007/12/21 17:27:57 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.220 2007/12/21 18:16:39 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1509,7 +1509,6 @@
text=>"Result",
faq=>282,bug=>'Instructor Interface',});
$r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
- my %disallowed;
$r->print(&update_result_form($uhome));
# Check Inputs
if (! $env{'form.ccuname'} ) {
@@ -1681,22 +1680,12 @@
my @statuses = ('active','future');
my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
my ($auname,$audom);
- if ($context eq 'course') {
- $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
- if ($cnum eq '' || $cdom eq '') {
- my $cid = $env{'request.course.id'};
- my %coursehash =
- &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
- $cdom = $coursehash{'domain'};
- $cnum = $coursehash{'num'};
- }
- } elsif ($context eq 'author') {
+ if ($context eq 'author') {
$auname = $env{'user.name'};
$audom = $env{'user.domain'};
}
foreach my $item (keys(%roles)) {
- my ($rolenum,$roledom,$role) = split(/:/,$item);
+ my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
if ($context eq 'course') {
if ($cnum ne '' && $cdom ne '') {
if ($rolenum eq $cnum && $roledom eq $cdom) {
@@ -1713,27 +1702,33 @@
}
}
}
- # Check for course or co-author roles being activated or re-enabled
- if ($context eq 'author' || $context eq 'course') {
- foreach my $key (keys(%env)) {
- if ($context eq 'author') {
- if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
- if (!grep(/^\Q$1\E$/,@userroles)) {
- push(@userroles,$1);
- }
- } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
- if (!grep(/^\Q$1\E$/,@userroles)) {
- push(@userroles,$1);
- }
- }
- } elsif ($context eq 'course') {
- if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
- if (!grep(/^\Q$1\E$/,@userroles)) {
- push(@userroles,$1);
+ if ($env{'form.action'} eq 'singlestudent') {
+ if (!grep(/^st$/,@userroles)) {
+ push(@userroles,'st');
+ }
+ } else {
+ # Check for course or co-author roles being activated or re-enabled
+ if ($context eq 'author' || $context eq 'course') {
+ foreach my $key (keys(%env)) {
+ if ($context eq 'author') {
+ if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
+ if (!grep(/^\Q$1\E$/,@userroles)) {
+ push(@userroles,$1);
+ }
+ } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
+ if (!grep(/^\Q$1\E$/,@userroles)) {
+ push(@userroles,$1);
+ }
}
- } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
- if (!grep(/^\Q$1\E$/,@userroles)) {
- push(@userroles,$1);
+ } elsif ($context eq 'course') {
+ if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
+ if (!grep(/^\Q$1\E$/,@userroles)) {
+ push(@userroles,$1);
+ }
+ } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
+ if (!grep(/^\Q$1\E$/,@userroles)) {
+ push(@userroles,$1);
+ }
}
}
}
@@ -1765,7 +1760,6 @@
# 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 (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
$env{'form.ccuname'});
@@ -1797,6 +1791,10 @@
$newdefquotatext);
my ($defquota,$settingstatus) =
&Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
+ my $showquota;
+ if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
+ $showquota = 1;
+ }
my %changeHash;
$changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
if ($userenv{'portfolioquota'} ne '') {
@@ -1867,6 +1865,13 @@
$changeHash{'firstname'},$changeHash{'middlename'},
$changeHash{'lastname'},$changeHash{'generation'},
$changeHash{'id'},undef,$changeHash{'permanentemail'});
+ %userupdate = (
+ lastname => $env{'form.clastname'},
+ middlename => $env{'form.cmiddlename'},
+ firstname => $env{'form.cfirstname'},
+ generation => $env{'form.cgeneration'},
+ id => $env{'form.cid'},
+ );
}
if (($namechanged && $namechgresult eq 'ok') ||
($quotachanged && $quotachgresult eq 'ok')) {
@@ -1894,8 +1899,11 @@
<th>$lt{'gen'}</th>
<th>$lt{'id'}</th>
<th>$lt{'mail'}</th>
- <th>$lt{'disk'}</th>
END
+ if ($showquota) {
+ $r->print("
+ <th>$lt{'disk'}</th>\n");
+ }
$r->print(&Apache::loncommon::end_data_table_header_row().
&Apache::loncommon::start_data_table_row());
$r->print(<<"END");
@@ -1906,8 +1914,11 @@
<td>$userenv{'generation'} </td>
<td>$userenv{'id'}</td>
<td>$userenv{'permanentemail'} </td>
- <td>$oldportfolioquota Mb $olddefquotatext </td>
END
+ if ($showquota) {
+ $r->print("
+ <td>$oldportfolioquota Mb $olddefquotatext </td>\n");
+ }
$r->print(&Apache::loncommon::end_data_table_row().
&Apache::loncommon::start_data_table_row());
$r->print(<<"END");
@@ -1918,8 +1929,11 @@
<td>$env{'form.cgeneration'} </td>
<td>$env{'form.cid'} </td>
<td>$env{'form.cpermanentemail'} </td>
- <td>$newportfolioquota Mb $newdefquotatext </td>
END
+ if ($showquota) {
+ $r->print("
+ <td>$newportfolioquota Mb $newdefquotatext </td>\n");
+ }
$r->print(&Apache::loncommon::end_data_table_row().
&Apache::loncommon::end_data_table().'<br />');
if ($env{'form.cid'} ne $userenv{'id'}) {
@@ -1927,13 +1941,6 @@
($env{'form.ccuname'} => $env{'form.cid'}));
if (($recurseid) &&
(&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
- %userupdate = (
- lastname => $env{'form.clasaname'},
- middlename => $env{'form.cmiddlename'},
- firstname => $env{'form.cfirstname'},
- generation => $env{'fora.cgeneration'},
- id => $env{'form.cid'},
- );
my $idresult =
&Apache::lonuserutils::propagate_id_change(
$env{'form.ccuname'},$env{'form.ccdomain'},
@@ -1969,8 +1976,11 @@
$r->print('<br />['.$lt{'mail'}.': '.
$userenv{'permanentemail'}.']');
}
- $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
- $olddefquotatext.']</h4>');
+ if ($showquota) {
+ $r->print('<br />['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
+ $olddefquotatext.']');
+ }
+ $r->print('</h4>');
}
if (@mod_disallowed) {
my ($rolestr,$contextname);
@@ -2001,9 +2011,31 @@
$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);
+ } else {
+ my $rolechanges = &update_roles($r);
+ if (!$rolechanges && $namechanged) {
+ if ($context eq 'course') {
+ if (@userroles > 0) {
+ if (grep(/^st$/,@userroles)) {
+ my $classlistupdated =
+ &Apache::lonuserutils::update_classlist($cdom,
+ $cnum,$env{'form.ccdomain'},
+ $env{'form.ccuname'},\%userupdate);
+ }
+ }
+ }
+ }
+ }
+ $r->print(&Apache::loncommon::end_page());
+}
+
+sub update_roles {
+ my ($r) = @_;
my $now=time;
my $rolechanges = 0;
+ my %disallowed;
$r->print('<h3>'.&mt('Modifying Roles').'</h3>');
foreach my $key (keys (%env)) {
next if (! $env{$key});
@@ -2076,7 +2108,7 @@
if ($role eq 'st') {
if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
- if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
+ if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
$output = "Error: $result\n";
} else {
$output = &mt('Assigning').' '.$role.' in '.$url.
@@ -2224,7 +2256,50 @@
if (!$rolechanges) {
$r->print(&mt('No roles to modify'));
}
- $r->print(&Apache::loncommon::end_page());
+ return $rolechanges;
+}
+
+sub enroll_single_student {
+ my ($r,$uhome,$amode,$genpwd,$now,$newuser) = @_;
+ $r->print('<h3>'.&mt('Enrolling Student').'</h3>');
+
+ # 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'});
+ if ($enroll_result =~ /^ok/) {
+ $r->print(&mt('<b>[_1]</b> 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('.<br />'.$showstart.'; '.$showend);
+ if ($startdate <= $now && !$newuser) {
+ $r->print("<p> ".&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.')."</p>");
+ }
+ } else {
+ $r->print(&mt('unable to enroll').": ".$enroll_result);
+ }
+ return;
}
sub get_defaultquota_text {
@@ -2264,7 +2339,7 @@
}
$outcome .= '<input type="hidden" name="phase" value="" />'."\n".
'<input type ="hidden" name="currstate" value="" />'."\n".
- '<input type ="hidden" name="action" value="singleuser" />'."\n".
+ '<input type ="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
'</form>';
return $outcome;
}
--raeburn1198261000--