--- loncom/interface/Attic/londropadd.pm 2007/07/02 21:12:06 1.162
+++ loncom/interface/Attic/londropadd.pm 2008/12/05 19:19:28 1.177
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# $Id: londropadd.pm,v 1.162 2007/07/02 21:12:06 albertel Exp $
+# $Id: londropadd.pm,v 1.177 2008/12/05 19:19:28 schafran 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;
@@ -42,10 +57,14 @@ use Apache::lonlocal;
use Apache::longroup;
use LONCAPA();
-###############################################################
-###############################################################
sub header {
- my $start_page=&Apache::loncommon::start_page('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(< 'Upload a class list',
help => 'Course_Create_Class_List',
action => 'upload',
- permission => $enrl_permission,
+ permission => $permission->{'enrl'},
},
{ text => 'Enroll a single student',
help => 'Course_Add_Student',
action => 'enrollstudent',
- permission => $enrl_permission,
+ permission => $permission->{'enrl'},
},
{ text => 'Modify student data',
help => 'Course_Modify_Student_Data',
action => 'modifystudent',
- permission => $enrl_permission,
+ permission => $permission->{'enrl'},
},
{ text => 'View Class List',
help => 'Course_View_Class_List',
action => 'classlist',
- permission => $view_permission,
+ permission => $permission->{'view'},
},
{ text => 'Drop Students',
help => 'Course_Drop_Student',
action => 'drop',
- permission => $enrl_permission,
+ permission => $permission->{'enrl'},
},
{ text => 'Automated Enrollment Manager',
- permission => &Apache::lonnet::auto_run($cnum,$cdom),
+ permission => (&Apache::lonnet::auto_run($cnum,$cdom)
+ && $permission->{'enrl'}),
url => '/adm/populate',
},
{ text => 'Create a new group',
help => 'Course_Create_Group',
- permission => $grp_manage_permission,
- url => '/adm/coursegroups?refpage=enrl&action=create',
+ permission => $permission->{'grp_manage'},
+ url => '/adm/coursegroups?refpage=enrl&action=create',
},
{ text => 'Modify an existing group',
help => 'Course_Modify_Group',
- permission => $grp_manage_permission,
- url => '/adm/coursegroups?refpage=enrl&action=modify',
+ permission => $permission->{'grp_manage'},
+ url => '/adm/coursegroups?refpage=enrl&action=modify',
},
{ text => 'Delete an existing group',
help => 'Course_Delete_Group',
- permission => $grp_manage_permission,
- url => '/adm/coursegroups?refpage=enrl&action=delete',
+ permission => $permission->{'grp_manage'},
+ url => '/adm/coursegroups?refpage=enrl&action=delete',
},
{ text => 'Re-enable a deleted group',
help => 'Course_Reenable_Group',
- permission => $grp_manage_permission,
- url => '/adm/coursegroups?refpage=enrl&action=reenable',
+ permission => $permission->{'grp_manage'},
+ url => '/adm/coursegroups?refpage=enrl&action=reenable',
},
{ text => 'Enter an existing group',
help => 'Course_Display_Group',
- permission => $grp_view_permission,
- url => '/adm/coursegroups?refpage=enrl&action=view',
+ permission => $permission->{'grp_view'},
+ url => '/adm/coursegroups?refpage=enrl&action=view',
},
);
my $menu_html = '';
@@ -218,13 +252,15 @@ sub print_main_menu {
return;
}
-###############################################################
-###############################################################
+
+
sub hidden_input {
my ($name,$value) = @_;
return ''."\n";
}
+
+
sub print_upload_manager_header {
my ($r,$datatoken,$distotal,$krbdefdom)=@_;
my $javascript;
@@ -256,8 +292,9 @@ sub print_upload_manager_header {
$password_choice = 'int';
}
#
- my $javascript_validations=&javascript_validations('auth',$krbdefdom,
- $password_choice);
+ my $javascript_validations =
+ &javascript_validations('auth',$krbdefdom,$password_choice,undef,
+ $env{'request.role.domain'});
my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
$r->print('
'.&mt('Uploading Class List')."
\n".
"\n".
@@ -284,10 +321,12 @@ sub print_upload_manager_header {
$javascript."\n".$javascript_validations.'');
}
-###############################################################
-###############################################################
+
+
+
+
sub javascript_validations {
- my ($mode,$krbdefdom,$curr_authtype,$curr_authfield)=@_;
+ my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain)=@_;
my $authheader;
if ($mode eq 'auth') {
my %param = ( formname => 'studentform',
@@ -296,7 +335,7 @@ sub javascript_validations {
$authheader = &Apache::loncommon::authform_header(%param);
} elsif ($mode eq 'createcourse') {
my %param = ( formname => 'ccrs',
- kerb_def_dom => $krbdefdom,
+ kerb_def_dom => $krbdefdom,
curr_authtype => $curr_authtype );
$authheader = &Apache::loncommon::authform_header(%param);
} elsif ($mode eq 'modifycourse') {
@@ -317,7 +356,7 @@ sub javascript_validations {
name => 'The optional name field was not specified.',
snum => 'The optional student number field was not specified.',
section => 'The optional section field was not specified.',
- email => 'The optional email address field was not specified.',
+ email => 'The optional e-mail address field was not specified.',
continue => 'Continue enrollment?',
);
@@ -325,6 +364,7 @@ sub javascript_validations {
my $function_name =(< 1) {
+ $auth_checks .= (<".&mt("Enroll another student")."
");
+ 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 {
@@ -932,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",
@@ -946,34 +1032,49 @@ sub get_student_username_domain_form {
'been' => "Begin Enrollment",
);
$r->print(<
-
+$jscript
$lt{'eos'}
-
-
:
-
-
:
-
$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 = &LONCAPA::clean_username($env{'form.cuname'});
- my $domain = &LONCAPA::clean_domain($env{'form.cudomain'});
- 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') {
@@ -983,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
@@ -998,7 +1122,7 @@ sub print_enroll_single_student_form {
#
# Set up domain selection form
my $homeserver_form = '';
- my %servers = &Apache::lonnet::get_servers($domain,'library');
+ my %servers = &Apache::lonnet::get_servers($ccdomain,'library');
$homeserver_form = '