[LON-CAPA-cvs] cvs: loncom /enrollment Enrollment.pm /interface loncommon.pm loncreateuser.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Fri, 11 Aug 2006 21:55:19 -0000
This is a MIME encoded message
--albertel1155333319
Content-Type: text/plain
albertel Fri Aug 11 17:55:19 2006 EDT
Modified files:
/loncom/enrollment Enrollment.pm
/loncom/interface loncommon.pm loncreateuser.pm
Log:
- prep work for BUG#4965 moving some routines around so usable not in a webserver
--albertel1155333319
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20060811175519.txt"
Index: loncom/enrollment/Enrollment.pm
diff -u loncom/enrollment/Enrollment.pm:1.31 loncom/enrollment/Enrollment.pm:1.32
--- loncom/enrollment/Enrollment.pm:1.31 Wed Feb 8 18:47:26 2006
+++ loncom/enrollment/Enrollment.pm Fri Aug 11 17:55:15 2006
@@ -1,5 +1,5 @@
# Automated Enrollment manager
-# $Id: Enrollment.pm,v 1.31 2006/02/08 23:47:26 raeburn Exp $
+# $Id: Enrollment.pm,v 1.32 2006/08/11 21:55:15 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -27,6 +27,7 @@
use Apache::loncoursedata;
use Apache::lonnet;
+use Apache::loncommon();
use Apache::lonmsg;
use Apache::lonlocal;
use HTML::Entities;
@@ -502,7 +503,7 @@
if ($context eq 'createowner' || $context eq 'createcourse') {
my $result = &Apache::lonnet::modifyuser($udom,$uname,$pid,$auth,$authparam,$first,$middle,$last,$gene,'1',undef,$emailaddr);
if ($result eq 'ok' && $context eq 'createcourse') {
- $outcome = &Apache::loncreateuser::commit_standardrole($udom,$uname,$userurl,$role,$start,$end,$cdom,$crs,$usec);
+ $outcome = &Apache::loncommon::commit_standardrole($udom,$uname,$userurl,$role,$start,$end,$cdom,$crs,$usec);
unless ($outcome =~ /^Error:/) {
$outcome = 'ok';
}
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.442 loncom/interface/loncommon.pm:1.443
--- loncom/interface/loncommon.pm:1.442 Fri Aug 4 14:56:20 2006
+++ loncom/interface/loncommon.pm Fri Aug 11 17:55:19 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.442 2006/08/04 18:56:20 albertel Exp $
+# $Id: loncommon.pm,v 1.443 2006/08/11 21:55:19 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -5505,6 +5505,92 @@
############################################################
############################################################
+sub commit_customrole {
+ my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
+ my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
+ ($start?', '.&mt('starting').' '.localtime($start):'').
+ ($end?', ending '.localtime($end):'').': <b>'.
+ &Apache::lonnet::assigncustomrole(
+ $udom,$uname,$url,$three,$four,$five,$end,$start).
+ '</b><br />';
+ return $output;
+}
+
+sub commit_standardrole {
+ my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
+ my $output;
+ my $logmsg;
+ if ($three eq 'st') {
+ my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec);
+ if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
+ $output = "Error: $result\n";
+ } else {
+ $output = &mt('Assigning').' '.$three.' in '.$url.
+ ($start?', '.&mt('starting').' '.localtime($start):'').
+ ($end?', '.&mt('ending').' '.localtime($end):'').
+ ': <b>'.$result.'</b><br />'.
+ &mt('Add to classlist').': <b>ok</b><br />';
+ }
+ } else {
+ $output = &mt('Assigning').' '.$three.' in '.$url.
+ ($start?', '.&mt('starting').' '.localtime($start):'').
+ ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
+ &Apache::lonnet::assignrole(
+ $udom,$uname,$url,$three,$end,$start).
+ '</b><br />';
+ }
+ return $output;
+}
+
+sub commit_studentrole {
+ my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
+ my $linefeed = '<br />'."\n";
+ my $result;
+ if (defined($one) && defined($two)) {
+ my $cid=$one.'_'.$two;
+ my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
+ my $secchange = 0;
+ my $expire_role_result;
+ my $modify_section_result;
+ unless ($oldsec eq '-1') {
+ unless ($sec eq $oldsec) {
+ $secchange = 1;
+ my $uurl='/'.$cid;
+ $uurl=~s/\_/\//g;
+ if ($oldsec) {
+ $uurl.='/'.$oldsec;
+ }
+ $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);
+ $result = $expire_role_result;
+ }
+ }
+ if (($expire_role_result eq 'ok') || ($secchange == 0)) {
+ $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
+ if ($modify_section_result =~ /^ok/) {
+ if ($secchange == 1) {
+ $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;
+ } elsif ($oldsec eq '-1') {
+ $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;
+ } else {
+ $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;
+ }
+ } else {
+ $$logmsg .= "Error when attempting section change for $uname from old section $oldsec to new section: $sec in course $cid -error: $modify_section_result".$linefeed;
+ }
+ $result = $modify_section_result;
+ } elsif ($secchange == 1) {
+ $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;
+ }
+ } else {
+ $$logmsg .= "Incomplete course id defined. Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";
+ $result = "error: incomplete course id\n";
+ }
+ return $result;
+}
+
+############################################################
+############################################################
+
sub course_type {
my ($cid) = @_;
if (!defined($cid)) {
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.128 loncom/interface/loncreateuser.pm:1.129
--- loncom/interface/loncreateuser.pm:1.128 Sun Jul 2 08:18:01 2006
+++ loncom/interface/loncreateuser.pm Fri Aug 11 17:55:19 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.128 2006/07/02 12:18:01 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.129 2006/08/11 21:55:19 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1250,7 +1250,7 @@
my $output;
if ($role eq 'st') {
if ($url =~ m-^/(\w+)/(\w+)/?(\w*)$-) {
- my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
+ 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')) {
$output = "Error: $result\n";
} else {
@@ -1297,7 +1297,7 @@
my %sections = ();
my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
if ($num_sections == 0) {
- $r->print(&commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
+ $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
} else {
my %curr_groups =
&Apache::longroup::coursegroups($one,$two);
@@ -1308,7 +1308,7 @@
next;
}
my $securl = $url.'/'.$sec;
- $r->print(&commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
+ $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
}
}
} elsif ($_=~/^form\.act\_([^\_]+)\_(\w+)\_([^\_]+)$/) {
@@ -1327,7 +1327,7 @@
my %sections = ();
my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
if ($num_sections == 0) {
- $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
} else {
my %curr_groups =
&Apache::longroup::coursegroups($one,$two);
@@ -1341,13 +1341,13 @@
next;
}
my $securl = $url.'/'.$sec;
- $r->print(&commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
} else {
$emptysec = 1;
}
}
if ($emptysec) {
- $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
}
}
} elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
@@ -1364,19 +1364,19 @@
my %sections = ();
my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
if ($num_sections == 0) {
- $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
} else {
my $emptysec = 0;
foreach my $sec (sort {$a cmp $b} keys %sections) {
if ($sec ne '') {
my $securl = $url.'/'.$sec;
- $r->print(&commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
} else {
$emptysec = 1;
}
}
if ($emptysec) {
- $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
}
}
} else {
@@ -1398,89 +1398,6 @@
$r->print(&Apache::loncommon::end_page());
}
-sub commit_customrole {
- my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
- my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
- ($start?', '.&mt('starting').' '.localtime($start):'').
- ($end?', ending '.localtime($end):'').': <b>'.
- &Apache::lonnet::assigncustomrole(
- $udom,$uname,$url,$three,$four,$five,$end,$start).
- '</b><br />';
- return $output;
-}
-
-sub commit_standardrole {
- my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
- my $output;
- my $logmsg;
- if ($three eq 'st') {
- my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec);
- if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
- $output = "Error: $result\n";
- } else {
- $output = &mt('Assigning').' '.$three.' in '.$url.
- ($start?', '.&mt('starting').' '.localtime($start):'').
- ($end?', '.&mt('ending').' '.localtime($end):'').
- ': <b>'.$result.'</b><br />'.
- &mt('Add to classlist').': <b>ok</b><br />';
- }
- } else {
- $output = &mt('Assigning').' '.$three.' in '.$url.
- ($start?', '.&mt('starting').' '.localtime($start):'').
- ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
- &Apache::lonnet::assignrole(
- $udom,$uname,$url,$three,$end,$start).
- '</b><br />';
- }
- return $output;
-}
-
-sub commit_studentrole {
- my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;
- my $linefeed = '<br />'."\n";
- my $result;
- if (defined($one) && defined($two)) {
- my $cid=$one.'_'.$two;
- my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
- my $secchange = 0;
- my $expire_role_result;
- my $modify_section_result;
- unless ($oldsec eq '-1') {
- unless ($sec eq $oldsec) {
- $secchange = 1;
- my $uurl='/'.$cid;
- $uurl=~s/\_/\//g;
- if ($oldsec) {
- $uurl.='/'.$oldsec;
- }
- $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);
- $result = $expire_role_result;
- }
- }
- if (($expire_role_result eq 'ok') || ($secchange == 0)) {
- $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
- if ($modify_section_result =~ /^ok/) {
- if ($secchange == 1) {
- $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;
- } elsif ($oldsec eq '-1') {
- $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;
- } else {
- $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;
- }
- } else {
- $$logmsg .= "Error when attempting section change for $uname from old section $oldsec to new section: $sec in course $cid -error: $modify_section_result".$linefeed;
- }
- $result = $modify_section_result;
- } elsif ($secchange == 1) {
- $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;
- }
- } else {
- $$logmsg .= "Incomplete course id defined. Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";
- $result = "error: incomplete course id\n";
- }
- return $result;
-}
-
sub build_roles {
my ($sectionstr,$sections,$role) = @_;
my $num_sections = 0;
@@ -1510,7 +1427,7 @@
$num_sections ++;
}
}
-
+
return $num_sections;
}
--albertel1155333319--