--- loncom/interface/lonrequestcourse.pm 2010/11/13 14:10:40 1.54.2.5 +++ loncom/interface/lonrequestcourse.pm 2013/03/01 04:48:59 1.66 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.54.2.5 2010/11/13 14:10:40 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.66 2013/03/01 04:48:59 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -134,7 +134,11 @@ sub handler { my $action = $env{'form.action'}; my $state = $env{'form.state'}; my (%states,%stored); - my ($jscript,$uname,$udom,$result,$warning); + my ($jscript,$uname,$udom,$result,$warning,$showcredits,$instcredits); + my %domdefs = &Apache::lonnet::get_domain_defaults($dom); + if ($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'}) { + $showcredits = 1; + } $states{'display'} = ['details']; $states{'view'} = ['pick_request','details','cancel','removal']; @@ -147,6 +151,12 @@ sub handler { } } + if (($action eq 'new') && (&Apache::loncoursequeueadmin::author_prompt())) { + if (ref($states{$action}) eq 'ARRAY') { + push(@{$states{$action}},'reqauthor'); + } + } + foreach my $key (keys(%states)) { if (ref($states{$key}) eq 'ARRAY') { unshift (@{$states{$key}},'crstype'); @@ -162,6 +172,7 @@ sub handler { personnel => 'Personnel', review => 'Review', process => 'Result', + reqauthor => 'Authoring Space Result', pick_request => 'Display Summary', details => 'Request Details', cancel => 'Cancel Request', @@ -173,7 +184,7 @@ sub handler { $trail{'enrollment'} = 'Enrollment'; } - my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) = + my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) = &get_breadcrumbs($dom,$action,\$state,\%states,\%trail); if ($action eq 'display') { if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) { @@ -262,11 +273,11 @@ sub handler { } } } - my %elements = &form_elements($dom); + (my $elements,$instcredits) = &form_elements($dom,$showcredits); my $elementsref = {}; - if (ref($elements{$action}) eq 'HASH') { - if (ref($elements{$action}{$state}) eq 'HASH') { - $elementsref = $elements{$action}{$state}; + if ((ref($elements) eq 'HASH') && (ref($elements->{$action}) eq 'HASH')) { + if (ref($elements->{$action}{$state}) eq 'HASH') { + $elementsref = $elements->{$action}{$state}; } } if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) { @@ -300,7 +311,7 @@ sub handler { &request_administration($r,$action,$state,$page,\%states,$dom, $jscript,$loaditems,$crumb,$newinstcode, $codechk,$checkedcode,$description, - \@invalidcrosslist); + $showcredits,$instcredits,\@invalidcrosslist); } } else { $r->print(&header('Course/Community Requests').$crumb. @@ -313,7 +324,7 @@ sub handler { &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\%request_domains); } else { &request_administration($r,$action,$state,$page,\%states,$dom,$jscript, - $loaditems,$crumb); + $loaditems,$crumb,'','','','',$showcredits); } } elsif ($action eq 'display') { if ($warning ne '') { @@ -324,7 +335,8 @@ sub handler { &close_popup_form()); } else { &request_administration($r,$action,$state,$page,\%states,$dom,$jscript, - $loaditems,$crumb,'','','','','',$uname,$udom); + $loaditems,$crumb,'','','','',$showcredits,'','', + $uname,$udom); } } elsif ($action eq 'log') { if ($state eq 'crstype') { @@ -439,7 +451,7 @@ sub get_breadcrumbs { $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests'); last; } else { - if (($$state eq 'process') || ($$state eq 'removal')) { + if (($$state eq 'process') || ($$state eq 'removal') || ($$state eq 'reqauthor')) { &Apache::lonhtmlcommon::add_breadcrumb( { href => '/adm/requestcourse', text => "$trail->{$states->{$action}[$i]}", @@ -488,7 +500,8 @@ sub header { } sub form_elements { - my ($dom) = @_; + my ($dom,$showcredits) = @_; + my $instcredits; my %elements = ( new => { @@ -556,7 +569,6 @@ sub form_elements { } if (&Apache::lonnet::auto_run('',$dom)) { my %extras = ( - sectotal => 'hidden', enrollstart_month => 'selectbox', enrollstart_hour => 'selectbox', enrollend_month => 'selectbox', @@ -572,12 +584,39 @@ sub form_elements { addcrosslist => 'checkbox', autoadds => 'radio', autodrops => 'radio', - ); - if ($env{'form.sectotal'} > 0) { - for (my $i=0; $i<$env{'form.sectotal'}; $i++) { - $extras{'sec_'.$i} = 'radio'; - $extras{'secnum_'.$i} = 'text'; - $extras{'loncapasec_'.$i} = 'text'; + ); + my ($instcode,$titlescount) = &get_instcode($dom); + if ($instcode) { + my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode); + if (@sections) { + $extras{'sectotal'} = 'hidden'; + if ($env{'form.sectotal'} > 0) { + for (my $i=0; $i<$env{'form.sectotal'}; $i++) { + $extras{'sec_'.$i} = 'radio'; + $extras{'secnum_'.$i} = 'text'; + $extras{'loncapasec_'.$i} = 'text'; + } + } + } else { + $extras{'addsection'} = 'checkbox'; + my $sectotal = $env{'form.sectotal'}; + if ($env{'form.addsection'}) { + $sectotal ++; + } + for (my $i=0; $i<$sectotal; $i++) { + $extras{'sec_'.$i} = 'checkbox'; + $extras{'secnum_'.$i} = 'text', + $extras{'loncapasec_'.$i} = 'text', + } + } + (my $outcome,my $desc,$instcredits) = + &Apache::lonnet::auto_validate_instcode(undef,$dom,$instcode); + if ($showcredits && $instcredits eq '') { + $extras{'coursecredits'} = 'text'; + } + } elsif ($env{'form.crstype'} eq 'unofficial') { + if ($showcredits) { + $extras{'coursecredits'} = 'text'; } } my $crosslisttotal = $env{'form.crosslisttotal'}; @@ -587,7 +626,6 @@ sub form_elements { if (!$crosslisttotal) { $crosslisttotal = 1; } - for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) { if ($numtitles) { $extras{'crosslist_'.$i.'_'.$lastitem} = 'text'; @@ -625,7 +663,7 @@ sub form_elements { } my %personnelhash = (%{$elements{'new'}{'personnel'}},%people); %{$elements{'new'}{'personnel'}} = %personnelhash; - return %elements; + return (\%elements,$instcredits);; } sub onload_action { @@ -647,11 +685,7 @@ sub onload_action { sub print_main_menu { my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$request_domains) = @_; my ($types,$typename) = &Apache::loncommon::course_types(); - my $onchange; - unless ($env{'form.interface'} eq 'textual') { - $onchange = 'this.form.submit()'; - } - + my $onchange = 'this.form.submit()'; my $nextstate_setter = "\n"; if (ref($states) eq 'HASH') { foreach my $key (keys(%{$states})) { @@ -835,8 +869,8 @@ END sub request_administration { my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb, - $newinstcode,$codechk,$checkedcode,$description,$invalidcrosslist, - $uname,$udom) = @_; + $newinstcode,$codechk,$checkedcode,$description,$showcredits, + $instcredits,$invalidcrosslist,$uname,$udom) = @_; my $js; if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) { $js = <print(&header($title,$js.$jscript,$loaditems,$jsextra).$crumb); &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode, - $codechk,$checkedcode,$description,$invalidcrosslist); + $codechk,$checkedcode,$description,$showcredits, + $instcredits,$invalidcrosslist); } elsif ($action eq 'view') { my $jsextra; my $formname = 'requestcrs'; @@ -932,9 +967,10 @@ END } $r->print('

'.$title.'

'."\n".$form."\n". &print_review($dom,\@codetitles,\%cat_titles,\%cat_order, - \@code_order)."\n". + \@code_order,'','','','',$instcredits)."\n". ''."\n"); - my @excluded = &get_excluded_elements($dom,$states,'new','review'); + my @excluded = &get_excluded_elements($dom,$states,'new','review', + $showcredits); push(@excluded,'origcnum'); $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'
'); my $other = 'modify'; @@ -956,7 +992,8 @@ END my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'}); $r->print('

'.$title.'

'."\n".$form."\n". $output); - my @excluded = &get_excluded_elements($dom,$states,'view','cancel'); + my @excluded = &get_excluded_elements($dom,$states,'view','cancel', + $showcredits); $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'
'); my %navtxt = &Apache::lonlocal::texthash ( prev => 'Back', @@ -1033,7 +1070,8 @@ END $r->print(&header($title,'','','',{ 'only_body' => 1}). $crumb."\n".'

'.$header.'

'. &print_review($dom,\@codetitles,\%cat_titles,\%cat_order, - \@code_order,$uname,$udom)."\n".''. + \@code_order,$uname,$udom,'','',$instcredits)."\n". + ''. &close_popup_form()); } $r->print(&Apache::loncommon::end_page()); @@ -1227,7 +1265,7 @@ sub get_instcode { sub print_request_form { my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode, - $description,$invalidcrosslist) = @_; + $description,$showcredits,$instcredits,$invalidcrosslist) = @_; my $formname = 'requestcrs'; my ($next,$prev,$message,$output,$codepicker,$crstype); $prev = $states->{$action}[$page-1]; @@ -1300,7 +1338,7 @@ sub print_request_form { } $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles, \%cat_titles,\%cat_order,\@code_order, - $invalidcrosslist)); + $showcredits,$instcredits,$invalidcrosslist)); } elsif ($state eq 'personnel') { $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist)); } elsif ($state eq 'review') { @@ -1326,16 +1364,38 @@ sub print_request_form { } if ($skipuser) { push(@disallowed,$i); - $disallowmsg{$i} = &mt('[_1] was excluded because new users need be from the course domain',''.$personname.':'.$persondom.''); + $disallowmsg{$i} = &mt('[_1] was excluded because new users need to be from the course domain',''.$personname.':'.$persondom.''); next; } } - if (&get_cancreate_status($persondom,$personname,$dom)) { - my ($allowed,$msg) = + my $usertype = &get_usertype($persondom,$personname,\%curr_rules,\%got_rules); + if (&Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype)) { + my ($allowed,$msg,$authtype,$authparam) = &check_newuser_rules($persondom,$personname, \%alerts,\%rulematch,\%inst_results, \%curr_rules,\%got_rules); if ($allowed) { + my %domdefaults = &Apache::lonnet::get_domain_defaults($persondom); + if ($usertype eq 'official') { + if ($authtype eq '') { + $authtype = $domdefaults{'auth_def'}; + $authparam = $domdefaults{'auth_arg_def'}; + } + } elsif ($usertype eq 'unofficial') { + if ($authtype eq '') { + $authtype = 'internal'; + $authparam = ''; + } + } else { + $authtype = $domdefaults{'auth_def'}; + $authparam = $domdefaults{'auth_arg_def'}; + } + if (($authtype eq '') || + (($authtype =~/^krb/) && ($authparam eq ''))) { + push(@disallowed,$i); + $disallowmsg{$i} = &mt('[_1] was excluded because institutional information is incomplete for this new user.',''.$personname.':'.$persondom.''); + next; + } if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') { if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') { $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'}; @@ -1394,7 +1454,7 @@ sub print_request_form { } else { $r->print('

'.&mt('Review course request details before submission').'

'); } - $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg). + $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg,$instcredits). ''); if ($crstype eq 'community') { $navtxt{'next'} = &mt('Submit community request'); @@ -1407,19 +1467,77 @@ sub print_request_form { \%cat_order,\@code_order); } my ($storeresult,$result) = &print_request_outcome($dom,\@codetitles, - \@code_order); + \@code_order,$instcredits); $r->print($result); if (($storeresult eq 'ok') || ($storeresult eq 'created')) { - $r->print('

'); if ($storeresult eq 'ok') { - $r->print(''. - &mt('Modify this request').''.(' 'x4)); + $r->print('

'. + &mt('Modify this request').''.(' 'x4). + ''.&mt('Make another request').'

'); + } + if (&Apache::loncoursequeueadmin::author_prompt()) { + $r->print('

'.&mt('Access to authoring space').'

'. + '

'. + &mt('Although assessment items can be created directly inside a course, such items only use part of the assessment capabilities of LON-CAPA.'). + '
'. + &mt('By contrast, items created in authoring space, then imported into a course, can use all of the features of the assessment engine.').'

'. + '

'.&mt('Request authoring space access now?'). + ' '. + ''. + (' 'x2). + ''. + '

'. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + '
'); + } elsif ($storeresult eq 'created') { + $r->print('

'.&mt('Make another request').'

'); + } + } + } elsif ($state eq 'reqauthor') { + my ($result,@links); + if ($env{'form.requestauthor'}) { + $r->print(&Apache::loncoursequeueadmin::process_reqauthor(\$result)); + if ($result eq 'created') { + my $role = 'au'; + my $spec = "$role./$env{'form.showdom'}/"; + push(@links,&mt('Enter your authoring space with role: [_1]', + ''. + &Apache::lonnet::plaintext($role).'')); } - $r->print(''.&mt('Make another request').'

'); - return; + } + if (($env{'form.disposition'} eq 'created') && + ($env{'form.cnum'} =~ /^$match_courseid$/) && + ($env{'form.showdom'} =~ /^$match_domain$/)) { + my ($spec,$area,$role,$type); + my $role = 'cc'; + my $spec = "$role./$env{'form.showdom'}/$env{'form.cnum'}"; + my $type = 'Course'; + if ($env{'form.crstype'} eq 'community') { + $type = 'Community'; + } + my $showrole = &Apache::lonnet::plaintext($role,$type); + unshift(@links,&mt('Enter new course with role: [_1]', + ''.$showrole.'')); + } + if (@links > 1) { + $r->print(&mt('New roles will be listed on your [_1]Roles[_2] page.', + '','').' '.&mt('Choose a role:'). + ''); + } elsif (@links == 1) { + $r->print('

'.$links[0].'

'); } } - my @excluded = &get_excluded_elements($dom,$states,$action,$state); + my @excluded = &get_excluded_elements($dom,$states,$action,$state,$showcredits); if ($state eq 'personnel') { push(@excluded,'persontotal'); } @@ -1446,25 +1564,28 @@ sub print_request_form { $count ++; } $env{'form.persontotal'} = $count; - } } if ($state eq 'enrollment') { - push(@excluded,'crosslisttotal'); + push(@excluded,('sectotal','crosslisttotal')); + } + if (($state eq 'process') || ($state eq 'reqauthor')) { + $r->print(''); + } else { + $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).''); + &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next, + $navtxt{'next'},$state); } - $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).''); - &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next, - $navtxt{'next'},$state); return; } -sub get_cancreate_status { - my ($persondom,$personname,$dom) = @_; +sub get_usertype { + my ($persondom,$personname,$curr_rules,$got_rules) = @_; my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($persondom,'username'); my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname, - $rules); - return &Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype); + $rules,$curr_rules,$got_rules); + return $usertype; } sub check_newuser_rules { @@ -1472,7 +1593,7 @@ sub check_newuser_rules { $got_rules) = @_; my $allowed = 1; my $newuser = 1; - my ($checkhash,$userchkmsg); + my ($checkhash,$userchkmsg,$authtype,$authparam); my $checks = { 'username' => 1 }; $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser }; &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch, @@ -1494,22 +1615,38 @@ sub check_newuser_rules { } } } - return ($allowed,$userchkmsg); + if ($allowed) { + if (ref($rulematch) eq 'HASH') { + if (ref($rulematch->{$personname.':'.$persondom}) eq 'HASH') { + my $matchedrule = $rulematch->{$personname.':'.$persondom}{'username'}; + my ($rules,$ruleorder) = + &Apache::lonnet::inst_userrules($persondom,'username'); + if (ref($rules) eq 'HASH') { + if (ref($rules->{$matchedrule}) eq 'HASH') { + $authtype = $rules->{$matchedrule}{'authtype'}; + $authparam = $rules->{$matchedrule}{'authparm'}; + } + } + } + } + } + return ($allowed,$userchkmsg,$authtype,$authparam); } sub get_excluded_elements { - my ($dom,$states,$action,$state) = @_; + my ($dom,$states,$action,$state,$showcredits) = @_; my @excluded = ('counter'); - my %elements = &form_elements($dom); + my ($elements,$instcredits) = &form_elements($dom,$showcredits); if (ref($states) eq 'HASH') { if (ref($states->{$action}) eq 'ARRAY') { my @items = @{$states->{$action}}; my $numitems = scalar(@items); if ($numitems) { for (my $i=$numitems-1; $i>=0; $i--) { - if (ref($elements{$action}) eq 'HASH') { - if (ref($elements{$action}{$items[$i]}) eq 'HASH') { - foreach my $key (keys(%{$elements{$action}{$items[$i]}})) { + if ((ref($elements) eq 'HASH') && + (ref($elements->{$action}) eq 'HASH')) { + if (ref($elements->{$action}{$items[$i]}) eq 'HASH') { + foreach my $key (keys(%{$elements->{$action}{$items[$i]}})) { push(@excluded,$key); } } @@ -1527,8 +1664,9 @@ sub get_excluded_elements { sub print_enrollment_menu { my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order, - $invalidcrosslist) =@_; - my ($sections,$autoenroll,$access_dates,$output,$hasauto); + $showcredits,$instcredits,$invalidcrosslist) =@_; + my ($sections,$autoenroll,$access_dates,$output,$hasauto,$hascredits, + $creditsrow,$domdefcredits); my $starttime = time; my $endtime = time+(6*30*24*60*60); # 6 months from now, approx @@ -1540,11 +1678,39 @@ sub print_enrollment_menu { 'start' => 'Start auto-enrollment', 'end' => 'End auto-enrollment', ); + if ($showcredits) { + unless ($env{'form.crstype'} eq 'community') { + my %domdefs = &Apache::lonnet::get_domain_defaults($dom); + $domdefcredits = $domdefs{$env{'form.crstype'}.'credits'}; + } + } if ($env{'form.crstype'} eq 'official') { if (&Apache::lonnet::auto_run('',$dom)) { $output = &show_invalid_crosslists($invalidcrosslist); my ($section_form,$crosslist_form); - $section_form = &inst_section_selector($dom,$instcode); + if ($instcode ne '') { + $section_form = &inst_section_selector($dom,$instcode); + if ($section_form eq '') { + my $sectotal = $env{'form.sectotal'}; + if (!$sectotal) { + $sectotal = 1; + } + if ($env{'form.addsection'}) { + $sectotal ++; + } + for (my $i=0; $i<$sectotal; $i++) { + $section_form .= §ions_form($dom,$instcode,$i); + } + if ($section_form) { + $section_form .= + &Apache::lonhtmlcommon::row_title(&mt('Add another')). + ''. + ''.&mt('Add?').&Apache::lonhtmlcommon::row_closure(); + } + } + } if ($section_form) { $sections = &Apache::lonhtmlcommon::row_headline(). '

'.&Apache::loncommon::help_open_topic('Course_Request_Sections'). @@ -1571,7 +1737,7 @@ sub print_enrollment_menu { ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}. "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(); $sections .= &Apache::lonhtmlcommon::row_headline. - '

'.&mt('Crosslisted courses for auto-enrollment').'

'. + '

'.&Apache::loncommon::help_open_topic('Course_Request_Crosslist').' '.&mt('Crosslisted courses for auto-enrollment').'

'. &Apache::lonhtmlcommon::row_closure(1). $crosslist_form; } @@ -1592,12 +1758,29 @@ sub print_enrollment_menu { &mt('No').''. &Apache::lonhtmlcommon::row_closure(1). &date_setting_table($starttime,$endtime,$formname,'enroll', - $hasauto,%enrolltitles); + $hasauto,undef,%enrolltitles); + if ($showcredits) { + if ($instcredits) { + $creditsrow = &mt('[quant,_1,credit]',$instcredits); + } else { + $creditsrow = ''. + ''; + } + $hascredits = 1; + } + } + } elsif ($env{'form.crstype'} eq 'unofficial') { + if ($showcredits) { + $creditsrow = ''. + ''; + $hascredits = 1; } } my $access_dates = &date_setting_table($starttime,$endtime,$formname,'access',$hasauto, - %accesstitles); + $hascredits,%accesstitles); $output .= &Apache::lonhtmlcommon::start_pick_box(); if ($sections) { $output .= $sections; @@ -1616,7 +1799,15 @@ sub print_enrollment_menu { $output .= &Apache::lonhtmlcommon::row_headline('Access'). '

'.$header.'

'. &Apache::lonhtmlcommon::row_closure(1). - $access_dates + $access_dates; + } + if ($creditsrow) { + $output .= &Apache::lonhtmlcommon::row_headline('Credits'). + '

'.&mt('Credits earned by students').'

'. + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::row_title(&mt('Default credits')). + $creditsrow. + &Apache::lonhtmlcommon::row_closure(1); } return '
'.&Apache::lonhtmlcommon::start_pick_box().$output. &Apache::lonhtmlcommon::end_pick_box().'
'; @@ -1681,7 +1872,7 @@ sub inst_section_selector { } sub date_setting_table { - my ($starttime,$endtime,$formname,$prefix,$hasauto,%datetitles) = @_; + my ($starttime,$endtime,$formname,$prefix,$hasauto,$hascredits,%datetitles)=@_; my ($perpetual,$table); my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start', $starttime,'','','',1,'','','',1); @@ -1692,7 +1883,9 @@ sub date_setting_table { $perpetual = ' '; - $closure = '1'; + unless ($hascredits) { + $closure = '1'; + } } my %help_item = ( @@ -2414,7 +2607,7 @@ sub requestlog_display_filter { sub print_review { my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom, - $disallowed,$disallowmsg) = @_; + $disallowed,$disallowmsg,$instcredits) = @_; my ($types,$typename) = &Apache::loncommon::course_types(); my ($owner,$ownername,$owneremail); if ($uname eq '' || $udom eq '') { @@ -2462,6 +2655,12 @@ sub print_review { } } } + $inst_headers .= ''.&mt('Credits').''; + if ($instcredits) { + $inst_values .= ''.$instcredits.''; + } else { + $inst_values .= ''.$env{'form.coursecredits'}.''; + } if (&Apache::lonnet::auto_run('',$dom)) { $enrollrow_title = &mt('Enrollment'); $enroll_headers = ''.&mt('Automatic Adds').''. @@ -2531,6 +2730,9 @@ sub print_review { $section_values .= $xlistinfo; } $section_values .= ''; + } elsif ($env{'form.crstype'} eq 'unofficial') { + $inst_headers .= ''.&mt('Credits').''; + $inst_values .= ''.$env{'form.coursecredits'}.''; } my %ctxt = &clone_text(); @@ -2829,7 +3031,6 @@ sub coursecode_form { ); my %helpitem = ( instcode => 'Course_Request_Category', - crosslist => 'Course_Request_Crosslist', ); if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') && (ref($cat_order))) { @@ -2846,7 +3047,11 @@ sub coursecode_form { my $lastitem = pop(@{$codetitles}); my $lastinput = ''; if (@{$codetitles} > 0) { - $output = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($helpitem{$context}).' '.$rowtitle{$context}). + my $helplink; + if (defined($helpitem{$context})) { + $helplink = &Apache::loncommon::help_open_topic($helpitem{$context}).' '; + } + $output = &Apache::lonhtmlcommon::row_title($helplink.$rowtitle{$context}). ''; if ($context eq 'crosslist') { $output .= '
'.&mt('Include?').'
'. @@ -2911,6 +3116,26 @@ sub coursecode_form { return $output; } +sub sections_form { + my ($dom,$instcode,$num) = @_; + my $rowtitle; + if ($instcode eq '') { + $rowtitle = &mt('Sections'); + } else { + $rowtitle = &mt('Sections of [_1]',$instcode); + } + return &Apache::lonhtmlcommon::row_title($rowtitle). + '
'. + ''.&mt('Include?'). + ''. + ''.&mt('Institutional section').'
'. + ''. + '
'.&mt('LON-CAPA section').'
'. + ''. + '
'. + &Apache::lonhtmlcommon::row_closure(1); +} + sub get_course_dom { my $codedom = &Apache::lonnet::default_login_domain(); if ($env{'form.showdom'} ne '') { @@ -3003,9 +3228,9 @@ sub display_navbuttons { } sub print_request_outcome { - my ($dom,$codetitles,$code_order) = @_; + my ($dom,$codetitles,$code_order,$instcredits) = @_; my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend, - %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,); + %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig); my $sectotal = $env{'form.sectotal'}; my $crosslisttotal = 0; $cnum = $env{'form.cnum'}; @@ -3069,6 +3294,7 @@ sub print_request_outcome { $enrollstart = ''; $enrollend = ''; } + my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg,%skipped); for (my $i=0; $i<$env{'form.persontotal'}; $i++) { my $uname = $env{'form.person_'.$i.'_uname'}; my $udom = $env{'form.person_'.$i.'_dom'}; @@ -3080,6 +3306,56 @@ sub print_request_outcome { lastname => $env{'form.person_'.$i.'_lastname'}, emailaddr => $env{'form.person_'.$i.'_emailaddr'}, }; + if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') { + my $usertype = &get_usertype($udom,$uname,\%curr_rules,\%got_rules); + if (&Apache::lonuserutils::can_create_user($udom,'requestcrs',$usertype)) { + my ($allowed,$msg,$authtype,$authparam) = + &check_newuser_rules($udom,$uname,\%alerts,\%rulematch, + \%inst_results,\%curr_rules,\%got_rules); + if ($allowed) { + my %domdefaults = &Apache::lonnet::get_domain_defaults($udom); + if ($usertype eq 'official') { + if ($authtype eq '') { + $authtype = $domdefaults{'auth_def'}; + $authparam = $domdefaults{'auth_arg_def'}; + } else { + if ($authtype eq 'loc') { + $authtype = 'localauth'; + } elsif ($authtype eq 'int') { + $authtype = 'internal'; + } + if ($authtype !~ /^(krb4|krb5|internal|localauth)$/) { + $authtype = $domdefaults{'auth_def'}; + $authparam = $domdefaults{'auth_arg_def'}; + } + } + } elsif ($usertype eq 'unofficial') { + if ($authtype eq '') { + $authtype = 'internal'; + $authparam = ''; + } + } else { + $authtype = $domdefaults{'auth_def'}; + $authparam = $domdefaults{'auth_arg_def'}; + } + if (($authtype eq '') || + (($authtype =~/^krb(4|5)$/) && ($authparam eq '')) || + ($authtype !~ /^(krb4|krb5|internal|localauth)$/)) { + $skipped{$uname.':'.$udom} = 1; + next; + } else { + $personnel{$uname.':'.$udom}{'authtype'} = $authtype; + $personnel{$uname.':'.$udom}{'autharg'} = $authparam; + } + } else { + $skipped{$uname.':'.$udom} = 1; + next; + } + } else { + $skipped{$uname.':'.$udom} = 1; + next; + } + } } my $role = $env{'form.person_'.$i.'_role'}; unless ($role eq '') { @@ -3125,6 +3401,11 @@ sub print_request_outcome { push(@baduname,$uname.':'.$udom); } } + if (keys(%skipped)) { + foreach my $key (keys(%skipped)) { + delete($personnel{$key}); + } + } my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend'); my $autodrops = 0; if ($env{'form.autodrops'}) { @@ -3138,6 +3419,12 @@ sub print_request_outcome { if (exists($env{'form.instcode'})) { $instcode = $env{'form.instcode'}; } + my $credits; + if ($instcredits) { + $credits = $instcredits; + } elsif (exists($env{'form.coursecredits'})) { + $credits = $env{'form.coursecredits'}; + } my $clonecrs = ''; my $clonedom = ''; if (($env{'form.cloning'}) && @@ -3165,6 +3452,7 @@ sub print_request_outcome { cdescr => $env{'form.cdescr'}, crstype => $env{'form.crstype'}, instcode => $instcode, + defaultcredits => $credits, clonedom => $clonedom, clonecrs => $clonecrs, datemode => $env{'form.datemode'}, @@ -3183,8 +3471,9 @@ sub print_request_outcome { }; my (@inststatuses,$storeresult,$creationresult); my $val = - &Apache::loncoursequeueadmin::get_processtype($env{'user.name'},$env{'user.domain'}, - $env{'user.adv'},$dom,$crstype,\@inststatuses,\%domconfig); + &Apache::loncoursequeueadmin::get_processtype('course',$env{'user.name'}, + $env{'user.domain'},$env{'user.adv'}, + $dom,$crstype,\@inststatuses,\%domconfig); if ($val eq '') { if ($crstype eq 'official') { $output = &mt('You are not permitted to request creation of official courses.'); @@ -3339,7 +3628,7 @@ sub print_request_outcome { } ($storeresult,my $updateresult) = &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom, - $cnum,$reqstatus,'request'); + $cnum,$reqstatus,'request',$env{'user.domain'},$env{'user.name'}); if ($modified && $queued && $storeresult eq 'ok') { if ($crstype eq 'community') { $output .= '

'.&mt('Your community request has been updated').'

'; @@ -3599,16 +3888,26 @@ sub retrieve_settings { } $env{'form.datemode'} = $reqinfo{'datemode'}; $env{'form.dateshift'} = $reqinfo{'dateshift'}; - if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) { - $env{'form.sectotal'} = $reqinfo{'sectotal'}; - $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'}; - $env{'form.autoadds'} = $reqinfo{'autoadds'}; - $env{'form.autdrops'} = $reqinfo{'autodrops'}; - $env{'form.instcode'} = $reqinfo{'instcode'}; - my $crscode = { - $cnum => $reqinfo{'instcode'}, - }; - &extract_instcode($dom,'instcode',$crscode,$cnum); + if ($reqinfo{'crstype'} eq 'official') { + $env{'form.autoadds'} = $reqinfo{'autoadds'}; + $env{'form.autodrops'} = $reqinfo{'autodrops'}; + if ($reqinfo{'instcode'} ne '') { + $env{'form.sectotal'} = $reqinfo{'sectotal'}; + $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'}; + $env{'form.instcode'} = $reqinfo{'instcode'}; + my $crscode = { + $cnum => $reqinfo{'instcode'}, + }; + &extract_instcode($dom,'instcode',$crscode,$cnum); + (undef,undef,my $instcredits) = + &Apache::lonnet::auto_validate_instcode(undef,$dom, + $reqinfo{'instcode'}); + if ($instcredits ne $reqinfo{'defaultcredits'}) { + $env{'form.coursecredits'} = $reqinfo{'defaultcredits'}; + } + } + } elsif ($reqinfo{'crstype'} eq 'unofficial') { + $env{'form.coursecredits'} = $reqinfo{'defaultcredits'}; } my @currsec; if (ref($reqinfo{'sections'}) eq 'HASH') {