--- loncom/interface/lonrequestcourse.pm 2010/08/11 13:24:21 1.54.2.3 +++ loncom/interface/lonrequestcourse.pm 2014/05/06 20:42:27 1.80 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.54.2.3 2010/08/11 13:24:21 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.80 2014/05/06 20:42:27 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -128,13 +128,62 @@ sub handler { } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['action','showdom','cnum','state','crstype','queue']); + ['action','showdom','cnum','state','crstype','queue','tabs']); &Apache::lonhtmlcommon::clear_breadcrumbs(); my $dom = &get_course_dom(); 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,%can_request, + %request_domains,@incdoms); + my %domdefs = &Apache::lonnet::get_domain_defaults($dom); + if ($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'}) { + $showcredits = 1; + } + + my $canreq = + &Apache::lonnet::check_can_request($dom,\%can_request,\%request_domains); + + foreach my $item (keys(%request_domains)) { + if (ref($request_domains{$item}) eq 'ARRAY') { + foreach my $possdom (@{$request_domains{$item}}) { + unless(grep(/^\Q$possdom\E$/,@incdoms)) { + push(@incdoms,$possdom); + } + } + } + } + + if ($canreq) { + if (($env{'form.crstype'} eq 'textbook') || + (scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) { + my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom); + if ($action eq 'log') { + my $usetabs; + if ((scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) { + $usetabs = 1; + } elsif ($env{'form.tabs'} eq 'on') { + $usetabs = 1; + } + &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'}); + my $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'); + &print_request_logs($r,$dom,undef,undef,$crumb,$usetabs); + } elsif ($action eq 'process') { + if ($can_request{'textbook'}) { + &process_textbook_request($r,$dom,$action,\%domdefs,\%domconfig,\%can_request); + } else { + &textbook_request_disabled($r,$dom,\%can_request); + } + } else { + if ($can_request{'textbook'}) { + &print_textbook_form($r,$dom,\@incdoms,\%domdefs,$domconfig{'requestcourses'},\%can_request); + } else { + &textbook_request_disabled($r,$dom,\%can_request); + } + } + return OK; + } + } $states{'display'} = ['details']; $states{'view'} = ['pick_request','details','cancel','removal']; @@ -147,6 +196,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'); @@ -155,13 +210,14 @@ sub handler { my @invalidcrosslist; my %trail = ( - crstype => 'Request Action', + crstype => 'Pick Action', codepick => 'Category', courseinfo => 'Description', enrollment => 'Access Dates', personnel => 'Personnel', review => 'Review', process => 'Result', + reqauthor => 'Authoring Space Result', pick_request => 'Display Summary', details => 'Request Details', cancel => 'Cancel Request', @@ -173,7 +229,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 +318,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 '')) { @@ -288,19 +344,16 @@ sub handler { my $loaditems = &onload_action($action,$state); - my (%can_request,%request_domains); - my $canreq = - &Apache::lonnet::check_can_request($dom,\%can_request,\%request_domains); if ($action eq 'new') { if ($canreq) { if ($state eq 'crstype') { &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems, - $crumb,\%request_domains); + $crumb,\@incdoms); } else { &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. @@ -310,10 +363,10 @@ sub handler { } } elsif ($action eq 'view') { if ($state eq 'crstype') { - &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\%request_domains); + &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\@incdoms); } else { &request_administration($r,$action,$state,$page,\%states,$dom,$jscript, - $loaditems,$crumb); + $loaditems,$crumb,'','','','',$showcredits); } } elsif ($action eq 'display') { if ($warning ne '') { @@ -324,11 +377,12 @@ 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') { - &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains); + &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\@incdoms); } else { $jscript .= < '/adm/requestcourse', text => "$trail->{$states->{$action}[$i]}", @@ -488,7 +542,8 @@ sub header { } sub form_elements { - my ($dom) = @_; + my ($dom,$showcredits) = @_; + my $instcredits; my %elements = ( new => { @@ -556,7 +611,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 +626,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') || ($env{'form.crstype'} eq 'textbook')) { + if ($showcredits) { + $extras{'coursecredits'} = 'text'; } } my $crosslisttotal = $env{'form.crosslisttotal'}; @@ -587,7 +668,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 +705,7 @@ sub form_elements { } my %personnelhash = (%{$elements{'new'}{'personnel'}},%people); %{$elements{'new'}{'personnel'}} = %personnelhash; - return %elements; + return (\%elements,$instcredits);; } sub onload_action { @@ -645,13 +725,9 @@ sub onload_action { } sub print_main_menu { - my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$request_domains) = @_; + my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$incdoms) = @_; 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})) { @@ -687,7 +763,8 @@ $nextstate_setter function check_can_request(crschoice,actionchoice) { var official = ''; var unofficial = ''; - var community = ''; + var community = ''; + var textbook = ''; END if (ref($can_request) eq 'HASH') { foreach my $item (keys(%{$can_request})) { @@ -699,8 +776,10 @@ END my %lt = &Apache::lonlocal::texthash( official => 'You are not permitted to request creation of an official course in this domain.', unofficial => 'You are not permitted to request creation of an unofficial course in this domain.', - community => 'You are not permitted to request creation of a community this domain.', - all => 'You must choose a specific course type when making a new course request.\\n\"All types\" is not allowed.', + community => 'You are not permitted to request creation of a community in this domain.', + textbook => 'You are not permitted to request creation of a textbook course in this domain', + all => 'You must choose a specific course type when making a new course request.', + allt => '"All types" is not allowed.', ); $js .= <{'official'}) || ($can_request->{'unofficial'})) { + if (($can_request->{'official'}) || ($can_request->{'unofficial'}) || $can_request->{'textbook'}) { if ($can_request->{'community'}) { $pagetitle = 'Course/Community Requests'; $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.'); @@ -747,37 +833,34 @@ END $pagetitle = 'Community Requests'; $pageinfo = &mt('Request creation of a new course, or review your pending requests.'); $domaintitle = &mt('Community Domain'); - } else { + } elsif ((ref($incdoms) eq 'ARRAY') && ((@{$incdoms} > 1) || + ((@{$incdoms} == 1) && ($incdoms->[0] ne $dom)))) { $pagetitle = 'Course/Community Requests'; $pageinfo = &mt('You do not have rights to request creation of courses in this domain; please choose a different domain.'); $domaintitle = &mt('Course/Community Domain'); - } - } - my @incdoms; - if (ref($request_domains) eq 'HASH') { - foreach my $item (keys(%{$request_domains})) { - if (ref($request_domains->{$item}) eq 'ARRAY') { - foreach my $possdom (@{$request_domains->{$item}}) { - unless(grep(/^\Q$possdom\E$/,@incdoms)) { - push(@incdoms,$possdom); - } - } - } + } else { + $pagetitle = 'Course/Community Requests'; + $pageinfo = &mt('You do not have rights to request creation of courses or communities.'); + $earlyout = 1; } } $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb. - '

'.$pageinfo.'

'. - '
'. + '

'.$pageinfo.'

'); + if ($earlyout) { + $r->print(&Apache::loncommon::end_page()); + return; + } + $r->print('
'. &Apache::lonhtmlcommon::start_pick_box(). &Apache::lonhtmlcommon::row_title($domaintitle). '
'. - &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,\@incdoms)); + &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,$incdoms)); if (!$onchange) { $r->print(' '); } unless ((ref($can_request) eq 'HASH') && (keys(%{$can_request}) > 0)) { - $r->print(&Apache::lonhtmlcommon::row_closure(1)."\n". + $r->print('
'.&Apache::lonhtmlcommon::row_closure(1)."\n". &Apache::lonhtmlcommon::end_pick_box().'
'."\n". &Apache::loncommon::end_page()); return; @@ -835,8 +918,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'; @@ -909,6 +993,8 @@ END $title = &mt('Pending requests for official courses'); } elsif ($env{'form.crstype'} eq 'unofficial') { $title = &mt('Pending requests for unofficial courses'); + } elsif ($env{'form.crstype'} eq 'textbook') { + $title = &mt('Pending requests for textbook courses'); } else { $title = &mt('Pending course/community requests'); } @@ -932,9 +1018,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 +1043,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 +1121,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 +1316,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 +1389,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 +1415,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,8 +1505,17 @@ 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). ''); + my $fullname = &Apache::loncommon::plainname($env{'user.name'}, + $env{'user.domain'}); + my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'review',$env{'user.name'}, + $env{'user.domain'},$fullname,$env{'form.cdescr'}); + if (ref($postprocess) eq 'HASH') { + if ($postprocess->{'reviewweb'}) { + $r->print($postprocess->{'reviewweb'}); + } + } if ($crstype eq 'community') { $navtxt{'next'} = &mt('Submit community request'); } else { @@ -1406,20 +1526,62 @@ sub print_request_form { &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles, \%cat_order,\@code_order); } - my ($storeresult,$result) = &print_request_outcome($dom,\@codetitles, - \@code_order); + my $lonhost = $r->dir_config('lonHostID'); + my ($storeresult,$result) = &print_request_outcome($lonhost,$dom,\@codetitles, + \@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()) { + &print_author_prompt($r,$env{'form.action'},$env{'form.cnum'},$env{'form.showdom'}, + $env{'form.crstype'},$storeresult); + } elsif ($storeresult eq 'created') { + $r->print('

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

'); } - $r->print(''.&mt('Make another request').'

'); - return; + } + } 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).'')); + } + } + 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 +1608,51 @@ 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 print_author_prompt { + my ($r,$action,$cnum,$showdom,$crstype,$storeresult) = @_; + $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). + ''. + '

'. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + '
'); +} + +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 +1660,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 +1682,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 +1731,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 +1745,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 +1804,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 +1825,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') || ($env{'form.crstype'} eq 'textbook')) { + 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 +1866,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 +1939,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 +1950,9 @@ sub date_setting_table { $perpetual = ' '; - $closure = '1'; + unless ($hascredits) { + $closure = '1'; + } } my %help_item = ( @@ -1782,6 +2042,7 @@ sub print_personnel_menu { official => 'Requestor is automatically assigned Course Coordinator role.', ); $lt{'unofficial'} = $lt{'official'}; + $lt{'textbook'} = $lt{'textbook'}; $output .= &Apache::lonhtmlcommon::row_headline(). '

'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'

'; } @@ -1899,6 +2160,7 @@ sub sorted_request_history { my $crstype = $history{'crstype'}; my $disposition = $history{'disposition'}; my $status = $history{'status'}; + my $uniquecode = $history{'code'}; if ($action eq 'view') { next if ((exists($history{'status'})) && ($history{'status'} eq 'created')); } else { @@ -1914,7 +2176,7 @@ sub sorted_request_history { $entry = $requestkey.':'.$crstype.':'. &escape($history{'details'}{'cdescr'}); if ($action eq 'log') { - $entry .= ':'.$lastupdate.':'; + $entry .= ':'.$uniquecode.':'.$lastupdate.':'; if ($statusinfo{$key} ne '') { $entry .= $statusinfo{$key}; } elsif ($status ne '') { @@ -2112,8 +2374,8 @@ ENDJS } sub viewcancel_javascript { - my $alert = &mt('Are you sure you want to cancel this request?\\n'. - 'Your request will be removed.'); + my $alert = &mt('Are you sure you want to cancel this request?').'\\n'. + &mt('Your request will be removed.'); return << "ENDJS"; function nextPage(formname,nextstate) { if (confirm('$alert')) { @@ -2127,7 +2389,7 @@ ENDJS } sub print_request_logs { - my ($r,$dom,$jscript,$loaditems,$crumb) = @_; + my ($r,$dom,$jscript,$loaditems,$crumb,$usetabs) = @_; my $title; if ($env{'form.crstype'} eq 'community') { $title = 'Community Request Logs'; @@ -2137,6 +2399,9 @@ sub print_request_logs { $title = 'Course Request Logs'; } $r->print(&header($title,$jscript,$loaditems).$crumb); + if ($usetabs) { + &startContentScreen($r,'textbooklogs'); + } my $formname = 'requestcrs'; $r->print('
'."\n". ''."\n". @@ -2181,6 +2446,28 @@ sub print_request_logs { if (($curr{'crstype'} eq 'official') || ($curr{'crstype'} eq 'any')) { $tablehdr .= ''.&mt('Institutional Code').''; } + my $showuniquecode; + my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom); + if (($curr{'status'} eq 'any') || ($curr{'status'} eq 'created')) { + if (ref($domconfig{'requestcourses'}) eq 'HASH') { + if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') { + if ($curr{'crstype'} eq 'any') { + my @types = qw(official unofficial community textbook); + foreach my $type (@types) { + if ($domconfig{'requestcourses'}{'uniquecode'}{$type}) { + $showuniquecode = 1; + last; + } + } + } elsif ($domconfig{'requestcourses'}{'uniquecode'}{$curr{'crstype'}}) { + $showuniquecode = 1; + } + } + } + } + if ($showuniquecode) { + $tablehdr .= ''.&mt('Unique Code').''; + } if ($curr{'status'} eq 'any') { $tablehdr .= ''.&mt('Status').''; } elsif ($curr{'status'} eq 'created') { @@ -2218,7 +2505,7 @@ sub print_request_logs { my $showtime = &Apache::lonlocal::locallocaltime($item); if (ref($queue_by_date{$item}) eq 'ARRAY') { foreach my $request (sort(@{$queue_by_date{$item}})) { - my ($key,$crstype,$desc,$timestamp,$status,$instcode) = split(':',$request); + my ($key,$crstype,$desc,$uniquecode,$timestamp,$status,$instcode) = split(':',$request); my ($cdom,$cnum) = split('_',$key); my $output = &Apache::loncommon::start_data_table_row(). ''.$count.''. @@ -2244,6 +2531,13 @@ sub print_request_logs { } $output .= ''.$showinstcode.''; } + if ($showuniquecode) { + if ($status eq 'created') { + $output .= ''.$uniquecode.''; + } else { + $output .= ''.&mt('Not applicable').''; + } + } if ($curr{'status'} eq 'any') { my $statusname = &mt('Unknown status'); if (ref($statusnames) eq 'HASH') { @@ -2304,8 +2598,14 @@ ENDSCRIPT &mt('There are no records to display'). '

'); } - $r->print('
'. - &Apache::loncommon::end_page()); + if ($usetabs) { + $r->print(''); + } + $r->print(''); + if ($usetabs) { + &endContentScreen($r); + } + $r->print(&Apache::loncommon::end_page()); return; } @@ -2320,7 +2620,7 @@ sub reqstatus_names { rejected => 'Request rejected', cancelled => 'Request cancelled', ); - if (($crstype eq 'official') || ($crstype eq 'unofficial')) { + if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook')) { $statusnames{'created'} = &mt('Course created'); } elsif ($crstype eq 'community') { $statusnames{'created'} = &mt('Community created'); @@ -2414,7 +2714,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 +2762,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 +2837,9 @@ sub print_review { $section_values .= $xlistinfo; } $section_values .= ''; + } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) { + $inst_headers .= ''.&mt('Credits').''; + $inst_values .= ''.$env{'form.coursecredits'}.''; } my %ctxt = &clone_text(); @@ -2707,6 +3016,7 @@ sub courseinfo_form { community => 'You must provide a (brief) community description.' ); $lt{'unofficial'} = $lt{'official'}; + $lt{'textbook'} = $lt{'official'}; my $js_validate = <<"ENDJS";