--- loncom/interface/Attic/londropadd.pm 2006/05/11 20:09:47 1.142 +++ loncom/interface/Attic/londropadd.pm 2012/04/24 21:05:15 1.179 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to drop and add students in courses # -# $Id: londropadd.pm,v 1.142 2006/05/11 20:09:47 raeburn Exp $ +# $Id: londropadd.pm,v 1.179 2012/04/24 21:05:15 droeschl 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,11 +54,17 @@ use Apache::Constants qw(:common :http R use Spreadsheet::WriteExcel; use Apache::lonstathelpers(); 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(<$end))) { - my $reply=&Apache::lonnet::modifystudent - # dom name id mode pass f m l g - ($udom,$unam,'', '', '',undef,undef,undef,undef, - $section,time,undef,undef,$desiredhost); - $result .= $reply.':'; - } - } - } - } - if ($result eq '') { - $result = 'Unable to find section for this student'; - } else { - $result =~ s/(ok:)+/ok/g; - } - return $result; -} +=pod + +=item domain_form() + + build a domain and server selection form + +=cut -############################################################### -############################################################### -# build a domain and server selection form sub domain_form { my ($defdom) = @_; # Set up domain and server selection forms # # Get the domains - my @domains = &Apache::loncommon::get_domains(); + my @domains = &Apache::lonnet::all_domains(); # build up the menu information to be passed to # &Apache::loncommon::linked_select_forms my %select_menus; @@ -115,7 +96,7 @@ sub domain_form { $select_menus{$dom}->{'default'}= 'default'; $select_menus{$dom}->{'select2'}->{'default'} = 'default'; # Now build up the other items in the second menu - my %servers = &Apache::loncommon::get_library_servers($dom); + my %servers = &Apache::lonnet::get_servers($dom,'library'); foreach my $server (keys(%servers)) { $select_menus{$dom}->{'select2'}->{$server} = "$server $servers{$server}"; @@ -127,64 +108,76 @@ sub domain_form { return $result; } -############################################################### -############################################################### -# Menu Phase One +=pod + +=item print_main_menu() + + Menu Phase One + +=cut + sub print_main_menu { - my ($r,$enrl_permission,$view_permission,$grp_manage_permission, - $grp_view_permission)=@_; + my ($r,$permission)=@_; # - my ($cdom,$cnum) = split/_/,$env{'request.course.id'}; + my $cid =$env{'request.course.id'}; + my $cdom=$env{'course.'.$cid.'.domain'}; + my $cnum=$env{'course.'.$cid.'.num'}; my @menu = ( { text => '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 => $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 = ''; @@ -209,13 +202,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; @@ -247,9 +242,10 @@ sub print_upload_manager_header { $password_choice = 'int'; } # - my $javascript_validations=&javascript_validations('auth',$krbdefdom, - $password_choice); - my $checked=(($env{'form.noFirstLine'})?' checked="1"':''); + 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". '

'.&mt('Identify fields')."

\n"); @@ -268,17 +264,19 @@ sub print_upload_manager_header { $r->print(''); - $r->print(''; if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') { $dateDefault = ' '; } @@ -917,13 +949,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", @@ -931,36 +982,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') { @@ -970,11 +1034,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 @@ -985,7 +1072,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 = ' -$lt{'mn'}: - -$lt{'ln'}: - -$lt{'gen'}: - -$lt{'hs'}: +: + +: + +: + +: + +: $homeserver_form -$lt{'mail'}: - +: +

$lt{'pswd'}

$lt{'psam'}$authhelp -

-$krbform -
-$intform -
-$locform -

END + if ($krbform ne '') { + $user_data_html .= $krbform.'
'; + } + if ($intform ne '') { + $user_data_html .= $intform.'
'; + } + if ($locform ne '') { + $user_data_html .= $locform.'
'; + } + $user_data_html .= "\n

\n" } else { # User already exists. Do not worry about authentication - my %uenv = &Apache::lonnet::dump('environment',$domain,$username); - $javascript_validations = &javascript_validations('noauth'); + my %uenv = &Apache::lonnet::dump('environment',$ccdomain,$ccuname); + $javascript_validations = &Apache::lonuserutils::javascript_validations('noauth'); my %lt=&Apache::lonlocal::texthash( 'udf' => "User Data for", 'fn' => "First Name", 'mn' => "Middle Name", 'ln' => "Last Name", 'gen' => "Generation", - 'mail' => "Email Address", + 'mail' => "E-mail Address", ); $user_data_html = <$lt{'udf'} $username\@$domain +

$lt{'udf'} $ccuname:$ccdomain

- - - - - - - - - - + + + + + + + + + +
$lt{'fn'}: - -
$lt{'mn'}: - -
$lt{'ln'}: - -
$lt{'gen'}: - -
$lt{'mail'}: - -
:
:
:
:
:
END } - my $date_table = &date_setting_table(); + my $date_table = &Apache::lonuserutils::date_setting_table(); # Print it all out my %lt=&Apache::lonlocal::texthash( 'cd' => "Course Data", @@ -1084,9 +1164,9 @@ END ); $r->print(< - - - + + + '; + &Apache::loncreateuser::restore_prev_selections(); + my $srch; + foreach my $item (@search) { + $srch->{$item} = $env{'form.'.$item}; + } + + if ($env{'form.state'} eq 'gotusername') { + if ($env{'form.phase'} eq 'get_user_info') { + my ($currstate,$response,$forcenewuser,$results) = + &Apache::loncreateuser::user_search_result($srch); + if ($env{'form.currstate'} eq 'modify') { + $currstate = $env{'form.currstate'}; + } + if ($currstate eq 'select') { + $r->print(&header()); + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"javascript:backPage(document.usersrchform,'','')", + text=>"Single user search"}, + {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')", + text=>"Select User",}); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student', + 'Course_Add_Student')); + &Apache::loncreateuser::print_user_selection_page($r, + $response,$srch,$results,'enrollstudent',\@search); + } elsif ($currstate eq 'modify') { + my ($ccuname,$ccdomain); + if (($srch->{'srchby'} eq 'uname') && + ($srch->{'srchtype'} eq 'exact')) { + $ccuname = $srch->{'srchterm'}; + $ccdomain= $srch->{'srchdomain'}; + } else { + my @matchedunames = keys(%{$results}); + ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]); + } + $ccuname =&LONCAPA::clean_username($ccuname); + $ccdomain=&LONCAPA::clean_domain($ccdomain); + &print_enroll_single_student_form($r,$jscript,$ccuname, + $ccdomain,$srch,$response); + } elsif ($currstate eq 'query') { + $r->print(&header($jscript)); + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"javascript:backPage(document.studentform,'','')", + text=>"Single user search"}); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student', + 'Course_Add_Student')); + &Apache::loncreateuser::print_user_query_page($r,'enrollstudent'); + } else { + &get_student_username_domain_form($r,$elements,$response, + $srch,$forcenewuser); + } + } elsif ($env{'form.phase'} eq 'userpicked') { + my $ccuname = &LONCAPA::clean_username($env{'form.seluname'}); + my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'}); + &print_enroll_single_student_form($r,$jscript,$ccuname, + $ccdomain,$srch); + } else { + &get_student_username_domain_form($r,$elements,undef,$srch); + } } elsif ($env{'form.state'} eq 'enrolling') { - &enroll_single_student($r); + $r->print(&header($jscript)); + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"javascript:backPage(document.studentform,'','')", + text=>"Single user search"}); + if ($env{'form.prevphase'} 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.prevphase'}','modify')", + text=>"Set enrollment",}, + {href=>"javascript:backPage(document.studentform,$env{'form.phase'},'')", + text=>"Result",}); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enroll Student', + 'Course_Add_Student')); + &enroll_single_student($r,\@search); } else { - &get_student_username_domain_form($r); + &get_student_username_domain_form($r,$elements,undef,$srch); } - } elsif ($env{'form.action'} eq 'classlist' && $view_permission) { + } elsif ($env{'form.action'} eq 'classlist' && $permission->{'view'}) { + $r->print(&header()); &Apache::lonhtmlcommon::add_breadcrumb ({href=>'/adm/dropadd?action=classlist', text=>"View Classlist"}); $r->print(&Apache::lonhtmlcommon::breadcrumbs('View Classlist', 'Course_View_Class_List')); if (! exists($env{'form.state'})) { - &print_html_classlist($r,undef); + &print_html_classlist($r,undef,$permission); } elsif ($env{'form.state'} eq 'csv') { - &print_html_classlist($r,'csv'); + &print_html_classlist($r,'csv',$permission); } elsif ($env{'form.state'} eq 'excel') { - &print_html_classlist($r,'excel'); + &print_html_classlist($r,'excel',$permission); } else { - &print_html_classlist($r,undef); + &print_html_classlist($r,undef,$permission); } - } elsif ($env{'form.action'} eq 'modifystudent' && $enrl_permission) { + } elsif ($env{'form.action'} eq 'modifystudent' && $permission->{'enrl'}) { + $r->print(&header()); &Apache::lonhtmlcommon::add_breadcrumb ({href=>'/adm/dropadd?action=modifystudent', text=>"Modify Student Data"}); $r->print(&Apache::lonhtmlcommon::breadcrumbs('Modify Student Data', 'Course_Modify_Student_Data')); if (! exists($env{'form.state'})) { - &print_html_classlist($r); + &print_html_classlist($r,undef,$permission); } elsif ($env{'form.state'} eq 'selected') { &print_modify_student_form($r); } elsif ($env{'form.state'} eq 'done') { &modify_single_student($r); } else { - &print_html_classlist($r); + &print_html_classlist($r,undef,$permission); } } else { # We should not end up here, but I guess it is possible &Apache::lonnet::logthis("Undetermined state in londropadd.pm. ". "form.action = ".$env{'form.action'}. "Someone should fix this."); + $r->print(&header()); $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment Manager')); - &print_main_menu($r,$enrl_permission,$view_permission); + &print_main_menu($r,$permission); } # # Finish up @@ -2573,10 +2922,12 @@ sub handler { return OK; } -################################################################### -################################################################### 1; __END__ +=pod +=back + +=cut