--- loncom/interface/Attic/londropadd.pm 2007/03/03 01:40:28 1.157 +++ loncom/interface/Attic/londropadd.pm 2007/10/09 17:33:57 1.171 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to drop and add students in courses # -# $Id: londropadd.pm,v 1.157 2007/03/03 01:40:28 albertel Exp $ +# $Id: londropadd.pm,v 1.171 2007/10/09 17:33:57 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -45,7 +45,13 @@ 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 = ''; @@ -256,8 +262,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". @@ -287,7 +294,7 @@ sub print_upload_manager_header { ############################################################### ############################################################### 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 +303,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') { @@ -325,6 +332,7 @@ sub javascript_validations { my $function_name =(< 1) { + $auth_checks .= (<'); + $r->print('

'.&mt('Enrolling [_1] : [_2]',$env{'form.cuname'}, + $env{'form.lcdomain'}).'

'); if (($env{'form.cuname'}) && ($env{'form.cuname'} eq &LONCAPA::clean_username($env{'form.cuname'})) @@ -823,6 +836,21 @@ sub enroll_single_student { $r->print(&mt('Invalid username or domain')); } $r->print("

".&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 { @@ -886,7 +914,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 = ' '; } @@ -935,9 +964,23 @@ sub make_dates_default { ## Single student enrollment routines (some of them) ## 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", @@ -945,34 +988,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 = &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') { @@ -982,11 +1040,33 @@ 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 = + &javascript_validations('auth',$krbdefdom,undef,undef,$ccdomain); my %param = ( formname => 'document.studentform', kerb_def_dom => $krbdefdom, kerb_def_auth => $krbdef @@ -997,7 +1077,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 = ' -$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); + my %uenv = &Apache::lonnet::dump('environment',$ccdomain,$ccuname); $javascript_validations = &javascript_validations('noauth'); my %lt=&Apache::lonlocal::texthash( 'udf' => "User Data for", @@ -1059,29 +1142,19 @@ END 'mail' => "Email Address", ); $user_data_html = <$lt{'udf'} $username\@$domain +

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

- - - - - - - - - - + + + + + + + + + +
$lt{'fn'}: - -
$lt{'mn'}: - -
$lt{'ln'}: - -
$lt{'gen'}: - -
$lt{'mail'}: - -
:
:
:
:
:
END } @@ -1096,9 +1169,9 @@ END ); $r->print(< - - - + + + '; + if ($env{'form.state'} eq 'gotusername') { + my $srch; + foreach my $item (@search) { + $srch->{$item} = $env{'form.'.$item}; + } + 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); + } } 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); } - } 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