--- loncom/interface/Attic/londropadd.pm 2006/02/08 23:47:23 1.136
+++ loncom/interface/Attic/londropadd.pm 2009/02/04 13:21:48 1.178
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# $Id: londropadd.pm,v 1.136 2006/02/08 23:47:23 raeburn Exp $
+# $Id: londropadd.pm,v 1.178 2009/02/04 13:21:48 hauer Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,8 +26,23 @@
# http://www.lon-capa.org/
#
#
-###############################################################
-##############################################################
+
+=head1 NAME
+
+Apache::londropadd.pm
+
+=head1 SYNOPSIS
+
+drop & add students
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+=head1 SUBROUTINES
+
+=over
+
+=cut
package Apache::londropadd;
@@ -39,34 +54,39 @@ use Apache::Constants qw(:common :http R
use Spreadsheet::WriteExcel;
use Apache::lonstathelpers();
use Apache::lonlocal;
+use Apache::longroup;
+use LONCAPA();
-###############################################################
-###############################################################
sub header {
- my $html=&Apache::lonxml::xmlbegin();
- my $bodytag=&Apache::loncommon::bodytag('Enrollment Manager');
- my $title = &mt('LON-CAPA Enrollment Manager');
+ my ($jscript,$loaditems) = @_;
+ my $start_page;
+ if (ref($loaditems) eq 'HASH') {
+ $start_page=&Apache::loncommon::start_page('Enrollment Manager',$jscript,{'add_entries' => $loaditems,});
+ } else {
+ $start_page=&Apache::loncommon::start_page('Enrollment Manager',$jscript);
+ }
return(<
-$title
-
-$bodytag
+$start_page
\n";
- $Str .= ''." \n";
$Str .= &mt('Note: for large courses, this operation may be time '.
'consuming');
@@ -654,8 +708,9 @@ sub print_upload_manager_footer {
return;
}
-###############################################################
-###############################################################
+
+
+
sub print_upload_manager_form {
my $r=shift;
@@ -707,9 +762,9 @@ sub print_upload_manager_form {
['lname',&mt('Last Name'), $env{'form.lname_choice'}],
['gen', &mt('Generation'), $env{'form.gen_choice'}],
['id', &mt('ID/Student Number'),$env{'form.id_choice'}],
- ['sec', &mt('Group/Section'), $env{'form.sec_choice'}],
+ ['sec', &mt('Section'), $env{'form.sec_choice'}],
['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
- ['email',&mt('EMail Address'), $env{'form.email_choice'}]);
+ ['email',&mt('E-mail Address'), $env{'form.email_choice'}]);
if ($env{'form.upfile_associate'} eq 'reverse') {
&Apache::loncommon::csv_print_samples($r,\@records);
$i=&Apache::loncommon::csv_print_select_table($r,\@records,
@@ -729,10 +784,12 @@ sub print_upload_manager_form {
&print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear);
}
-###############################################################
-###############################################################
+
+
+
+
sub enroll_single_student {
- my $r=shift;
+ my ($r,$srcharray) = @_;
# Remove non alphanumeric values from section
$env{'form.csec'}=~s/\W//g;
#
@@ -740,23 +797,28 @@ sub enroll_single_student {
# in the course is entirely separate from the action of enrolling the
# student. Also, a failure in setting the dates as default is not fatal
# to the process of enrolling / modifying a student.
- my ($startdate,$enddate) = &get_dates_from_form();
+ my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
if ($env{'form.makedatesdefault'}) {
- $r->print(&make_dates_default($startdate,$enddate));
+ $r->print(&Apache::lonuserutils::make_dates_default($startdate,
+ $enddate));
}
$r->print('
');
+ if (($env{'form.cuname'})
+ && ($env{'form.cuname'}
+ eq &LONCAPA::clean_username($env{'form.cuname'}))
+ && ($env{'form.lcdomain'})
+ && ($env{'form.lcdomain'}
+ eq &LONCAPA::clean_domain($env{'form.lcdomain'}))) {
# Deal with home server selection
my $domain=$env{'form.lcdomain'};
my $desiredhost = $env{'form.lcserver'};
if (lc($desiredhost) eq 'default') {
$desiredhost = undef;
} else {
- my %home_servers =&Apache::loncommon::get_library_servers($domain);
+ my %home_servers =&Apache::lonnet::get_servers($domain,'library');
if (! exists($home_servers{$desiredhost})) {
$r->print(''.&mt('Error').':'.
&mt('Invalid home server specified'));
@@ -783,7 +845,7 @@ sub enroll_single_student {
$env{'form.lcdomain'});
if ((($amode) && ($genpwd)) || ($home ne 'no_host')) {
# Clean out any old roles the student has in this class.
- &modifystudent($env{'form.lcdomain'},$env{'form.cuname'},
+ &Apache::lonuserutils::modifystudent($env{'form.lcdomain'},$env{'form.cuname'},
$env{'request.course.id'},$env{'form.csec'},
$desiredhost);
my $login_result = &Apache::lonnet::modifystudent
@@ -812,6 +874,22 @@ sub enroll_single_student {
} else {
$r->print(&mt('Invalid username or domain'));
}
+ $r->print("
");
+ if (ref($srcharray) eq 'ARRAY') {
+ foreach my $item (@{$srcharray},'ccuname','ccdomain') {
+ $r->print(''."\n");
+ }
+ }
+ foreach my $item ('sortby','seluname','seludom') {
+ if (exists($env{'form.'.$item})) {
+ $r->print(''."\n");
+ }
+ }
+ $r->print(''."\n".
+ ''."\n".
+ ''."\n".
+ ''."\n".
+ '');
}
sub setup_date_selectors {
@@ -875,7 +953,8 @@ sub date_setting_table {
my ($startform,$endform)=&setup_date_selectors($starttime,$endtime,$mode);
my $dateDefault = ''.
'';
+ &mt('make these dates the default for future enrollment').
+ '';
if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
$dateDefault = ' ';
}
@@ -911,7 +990,8 @@ sub make_dates_default {
$result .= "Set default start and end dates for course ";
#
# Refresh the course environment
- &Apache::lonnet::coursedescription($env{'request.course.id'});
+ &Apache::lonnet::coursedescription($env{'request.course.id'},
+ {'freshen_cache' => 1});
} else {
$result .= &mt('Unable to set default dates for course').":".$put_result.
' ';
@@ -919,13 +999,32 @@ sub make_dates_default {
return $result;
}
-##
-## Single student enrollment routines (some of them)
-##
+=pod
+
+=item get_student_username_domain_form()
+
+ Single student enrollment routines (some of them)
+
+=cut
+
sub get_student_username_domain_form {
- my $r = shift;
- my $domform = &Apache::loncommon::select_dom_form
- ($env{'course.'.$env{'request.course.id'}.'.domain'},'cudomain',0);
+ my ($r,$elements,$response,$srch,$forcenewuser) = @_;
+ my $loaditems = {
+ 'onload' => "javascript:setFormElements(document.studentform)",
+ };
+ $r->print(&header(undef,$loaditems));
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.studentform,'','')",
+ text=>"Single user search"});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student',
+ 'Course_Add_Student'));
+ my $defdom=$env{'request.role.domain'};
+
+ my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
+ ''."\n";
+
my %lt=&Apache::lonlocal::texthash(
'eos' => "Enroll One Student",
'usr' => "Username",
@@ -933,36 +1032,49 @@ sub get_student_username_domain_form {
'been' => "Begin Enrollment",
);
$r->print(<
-
+$jscript
$lt{'eos'}
-
-
$lt{'usr'}:
-
-
$lt{'dom'}:
-
$domform
-
-
-
-
-
-
END
+ $r->print($response);
+ $r->print(&single_user_entry_form($defdom,$srch,$forcenewuser));
return;
}
+sub single_user_entry_form {
+ my ($dom,$srch,$forcenewuser) = @_;
+ my $userpicker =
+ &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
+ 'document.studentform');
+ my $srchbutton = &mt('Search');
+ my $output = <<"ENDDOCUMENT";
+
+
+
+$userpicker
+
+ENDDOCUMENT
+ return $output;
+}
+
sub print_enroll_single_student_form {
- my $r=shift;
+ my ($r,$jscript,$ccuname,$ccdomain,$srch) = @_;
+ $r->print(&header($jscript));
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.studentform,'','')",
+ text=>"Single user search"});
+ if ($env{'form.phase'} eq 'userpicked') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.studentform,'get_user_info','select')",
+ text=>"Select user",});
+ }
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.studentform,'$env{'form.phase'}','modify')",
+ text=>"Set enrollment",});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student',
+ 'Course_Add_Student'));
$r->print("
".&mt('Enroll One Student')."
");
#
- my $username = $env{'form.cuname'};
- my $domain = $env{'form.cudomain'};
- $username=~s/\W//gs;
- $domain=~s/\W//gs;
- my $home = &Apache::lonnet::homeserver($username,$domain);
+ my $home = &Apache::lonnet::homeserver($ccuname,$ccdomain);
# $new_user flags whether we are creating a new user or using an old one
my $new_user = 1;
if ($home ne 'no_host') {
@@ -972,11 +1084,34 @@ sub print_enroll_single_student_form {
my $user_data_html = '';
my $javascript_validations = '';
if ($new_user) {
+ my $usertoadd;
+ my $instsrch = {
+ srchin => 'instd',
+ srchby => 'uname',
+ srchtype => 'exact',
+ srchterm => $ccuname,
+ srchdomain => $ccdomain,
+ };
+ if (($instsrch->{'srchterm'} ne '') && ($instsrch->{'srchdomain'} ne '')) {
+ $usertoadd = $instsrch->{'srchterm'}.':'.$instsrch->{'srchdomain'};
+ }
+ my (%dirsrch_results,%inst_results);
+ if ($usertoadd) {
+ if (&Apache::loncreateuser::directorysrch_check($instsrch) eq 'ok') {
+ %dirsrch_results = &Apache::lonnet::inst_directory_query($instsrch);
+ if (ref($dirsrch_results{$usertoadd}) eq 'HASH') {
+ %inst_results = %{$dirsrch_results{$usertoadd}};
+ }
+ }
+ }
+
my $defdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
# Set up authentication forms
my ($krbdef,$krbdefdom) =
- &Apache::loncommon::get_kerberos_defaults($domain);
- $javascript_validations=&javascript_validations('auth',$krbdefdom);
+ &Apache::loncommon::get_kerberos_defaults($ccdomain);
+ $javascript_validations =
+ &Apache::lonuserutils::javascript_validations('auth',$krbdefdom,
+ undef,undef,$ccdomain);
my %param = ( formname => 'document.studentform',
kerb_def_dom => $krbdefdom,
kerb_def_auth => $krbdef
@@ -987,7 +1122,7 @@ sub print_enroll_single_student_form {
#
# Set up domain selection form
my $homeserver_form = '';
- my %servers = &Apache::loncommon::get_library_servers($domain);
+ my %servers = &Apache::lonnet::get_servers($ccdomain,'library');
$homeserver_form = '