--- loncom/interface/lonrequestcourse.pm 2013/12/25 20:43:46 1.71 +++ loncom/interface/lonrequestcourse.pm 2013/12/27 14:34:52 1.72 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.71 2013/12/25 20:43:46 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.72 2013/12/27 14:34:52 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -134,12 +134,42 @@ sub handler { my $action = $env{'form.action'}; my $state = $env{'form.state'}; my (%states,%stored); - my ($jscript,$uname,$udom,$result,$warning,$showcredits,$instcredits); + 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 ((scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) { + my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom); + if ($action eq 'log') { + &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'}); + my $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'); + &print_request_logs($r,$dom,undef,undef,$crumb); + } elsif ($action eq 'process') { + &process_textbook_request($r,$dom,$action,\%domdefs,\%domconfig); + } else { + &print_textbook_form($r,$dom,\@incdoms,\%domdefs,$domconfig{'requestcourses'}); + } + return OK; + } + } + $states{'display'} = ['details']; $states{'view'} = ['pick_request','details','cancel','removal']; $states{'log'} = ['display']; @@ -299,14 +329,11 @@ 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, @@ -321,7 +348,7 @@ 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,'','','','',$showcredits); @@ -340,7 +367,7 @@ sub handler { } } 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 .= <{$item}) eq 'ARRAY') { - foreach my $possdom (@{$request_domains->{$item}}) { - unless(grep(/^\Q$possdom\E$/,@incdoms)) { - push(@incdoms,$possdom); - } - } - } - } - } $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb. '

'.$pageinfo.'

'. '
'. &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; @@ -1488,25 +1503,8 @@ sub print_request_form { ''.&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). - ''. - '

'. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - '
'); + &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').'

'); } @@ -1591,6 +1589,29 @@ sub print_request_form { return; } +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) = @@ -3486,11 +3507,18 @@ sub print_request_outcome { accessend => $accessend, personnel => \%personnel, }; - my (@inststatuses,$storeresult,$creationresult); + my ($result,$output) = &process_request($dom,$cnum,$crstype,$now,$details,$instcode, + $req_notifylist,\@instsections,\%domconfig); + return ($result,$output); +} + +sub process_request { + my ($dom,$cnum,$crstype,$now,$details,$instcode,$req_notifylist,$instsections,$domconfig) = @_; + my (@inststatuses,$storeresult,$creationresult,$output); my $val = &Apache::loncoursequeueadmin::get_processtype('course',$env{'user.name'}, $env{'user.domain'},$env{'user.adv'}, - $dom,$crstype,\@inststatuses,\%domconfig); + $dom,$crstype,\@inststatuses,$domconfig); if ($val eq '') { if ($crstype eq 'official') { $output = &mt('You are not permitted to request creation of official courses.'); @@ -3525,8 +3553,10 @@ sub print_request_outcome { $inststatuslist = join(',',@inststatuses); } my $instseclist; - if (@instsections > 0) { - $instseclist = join(',',@instsections); + if (ref($instsections) eq 'ARRAY') { + if (@{$instsections} > 0) { + $instseclist = join(',',@{$instsections}); + } } $validationchk = &Apache::lonnet::auto_courserequest_validation($dom, @@ -4079,5 +4109,497 @@ sub generate_date_items { return; } +sub print_textbook_form { + my ($r,$dom,$incdoms,$domdefs,$settings) = @_; + my ($bookshash,%ordered); + my $crstype = 'textbook'; +# +# Retrieve list of textbook courses cloneable by user +# + my $numbook; + if (ref($settings) eq 'HASH') { + $bookshash = $settings->{'textbooks'}; + if (ref($bookshash) eq 'HASH') { + foreach my $item (keys(%{$bookshash})) { + my ($clonedom,$clonecrs) = split(/_/,$item); + if (ref($bookshash->{$item}) eq 'HASH') { + my ($clonedom,$clonecrs) = split(/_/,$item); + if (&Apache::loncoursequeueadmin::can_clone_course($env{'user.name'}, + $env{'user.domain'},$clonecrs,$clonedom,$crstype)) { + + my $num = $bookshash->{$item}{'order'}; + $ordered{$num} = $item; + $numbook ++; + } + } + } + } + } + +# +# Check if domain has multiple library servers +# + my ($home_server_pick,$numlib) = + &Apache::loncommon::home_server_form_item($dom,'chome', + 'default','hide'); + if ($numlib > 1) { + $home_server_pick = &mt('Home Server for Course').': '.$home_server_pick.'
'; + } + +# +# Retrieve information about courses owned by user, or in which user has an active or future +# Course Coordinator role +# + my $numcurrent; + my %cloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.',$env{'user.name'}.':'.$env{'user.domain'}, + undef,undef,undef,'Course'); + my %ccroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles', + ['active','future'],['cc']); + foreach my $role (keys(%ccroles)) { + my ($cnum,$cdom,$rest) = split(/:/,$role,3); + unless (exists($cloneable{$cdom.'_'.$cnum})) { + my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{'one_time' => 1}); + $cloneable{$cdom.'_'.$cnum} = \%courseinfo; + } + } + + my $numcurrent = scalar(keys(%cloneable)); + + my $jscript = &textbook_request_javascript($numbook,$numcurrent); + my %loaditems; + $loaditems{'onload'} = 'javascript:uncheckAllRadio();'; + $r->print(&header('Course Request',$jscript,\%loaditems)); + + &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'}); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests')); + +# +# Show domain selector form, if required. +# + if (@{$incdoms} > 1) { + my $onchange = 'this.form.submit()'; + $r->print('
'. + '
'.&mt('Domain').''. + &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,$incdoms). + '
'); + } + +# +# Course request form +# + +# +# Course Title +# + $r->print('
'. + '
'. + '
'. + ''.&mt('Course Information').''. + ''.&mt('Title').': '. + '
'. + $home_server_pick.'
'. + '
'); + +# +# Content source selection, if more than one available +# + if (keys(%cloneable) || keys(%ordered)) { + $r->print('
'. + '
'.&mt('Course Content').''); + if (keys(%ordered)) { + $r->print(''.(' 'x2).' '); + } + if (keys(%cloneable)) { + $r->print(''.(' 'x2).' '); + } + $r->print(''); + } else { + $r->print(''); + } + +# +# Table of cloneable textbook courses +# + if (keys(%ordered)) { + $r->print(''); + } + +# +# Table of user's current courses (owner and/or course coordinator) +# + if (keys(%cloneable)) { + my %lt = &clone_text(); + $r->print(''); + } +# +# End of content selector +# + if (keys(%cloneable) || keys(%ordered)) { + $r->print('
'); + } + + my %accesstitles = ( + 'start' => 'Default start access', + 'end' => 'Default end access', + ); + my %help_item = ( + start => 'Course_Request_Access_Start', + end => 'Course_Request_Access_End', + ); + my $starttime = time; + my $endtime = time+(6*30*24*60*60); # 6 months from now, approx + my $startform = &Apache::lonhtmlcommon::date_setter('requestcourse','accessstart', + $starttime,'','','',1,'','','',1); + my $endform = &Apache::lonhtmlcommon::date_setter('requestcourse','accessend', + $endtime,'','','',1,'','','',1); +# +# Set default start and end dates for student access +# + $r->print('
'. + '
'.&mt('Student Access Dates').''. + &Apache::loncommon::help_open_topic($help_item{'start'}). + ' '.&mt($accesstitles{'start'}).$startform.'
'. + &Apache::loncommon::help_open_topic($help_item{'end'}). + ' '.&mt($accesstitles{'end'}).$endform.'
'); + +# +# Submit button +# + $r->print(''. + ''); + +# +# End request form +# + $r->print('
'. + &Apache::loncommon::end_page()); + return; +} + +sub process_textbook_request { + my ($r,$dom,$action,$domdefs,$domconfig) = @_; + my ($uniquecode,$req_notifylist); + my $crstype = 'textbook'; + if (ref($domconfig) eq 'HASH') { + if (ref($domconfig->{'requestcourses'}) eq 'HASH') { + if (ref($domconfig->{'requestcourses'}{'notify'}) eq 'HASH') { + $req_notifylist = $domconfig->{'requestcourses'}{'notify'}{'approval'}; + } + if (ref($domconfig->{'requestcourses'}{'uniquecode'}) eq 'HASH') { + $uniquecode = $domconfig->{'requestcourses'}{'uniquecode'}{$crstype}; + } + } + } + my $crstype = 'textbook'; + my $now = time; + my $reqtype = $env{'form.cloning'}; + my (@inststatuses,$storeresult,$creationresult); + my $cnum = &Apache::lonnet::generate_coursenum($dom,'Course'); + my ($clonefrom,$clonedom,$clonecrs); + if ($reqtype eq 'textbook') { + $clonefrom = $env{'form.book'}; + } elsif ($reqtype eq 'existing') { + $clonefrom = $env{'form.owned'}; + } + my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend'); + if ($clonefrom) { + ($clonedom,$clonecrs) = split(/_/,$clonefrom); + if (&Apache::lonnet::homeserver($clonecrs,$clonedom) ne 'no_host') { + my $canclone = + &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'}, + $env{'user.domain'},$clonecrs,$clonedom,$crstype); + unless ($canclone) { + undef($clonecrs); + undef($clonedom); + } + } else { + undef($clonecrs); + undef($clonedom); + } + } + $r->print(&header('Course Creation')); + + &Apache::lonhtmlcommon::add_breadcrumb( + { href => '/adm/requestcourse', + text => "Create Course", + } + ); + &Apache::lonhtmlcommon::add_breadcrumb({text=>'Request Processed'}); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests')); + + my $details = { + owner => $env{'user.name'}, + domain => $env{'user.domain'}, + cdom => $dom, + cnum => $cnum, + coursehome => $env{'form.chome'}, + cdescr => $env{'form.cdescr'}, + crstype => $crstype, + uniquecode => $uniquecode, + clonedom => $clonedom, + clonecrs => $clonecrs, + accessstart => $accessstart, + accessend => $accessend, + personnel => {}, + }; + if ($reqtype eq 'existing') { + $details->{datemode} = $env{'form.datemode'}; + $details->{dateshift} = $env{'form.dateshift'}; + } + my ($result,$output) = &process_request($dom,$cnum,$crstype,$now,$details,'',$req_notifylist,[],$domconfig); + $r->print($output); + if (&Apache::loncoursequeueadmin::author_prompt()) { + &print_author_prompt($r,$action,$cnum,$dom,$crstype,$result); + } elsif ($result eq 'created') { + $r->print('

'.&mt('Create another course').'

'); + } + $r->print(&Apache::loncommon::end_page()); +} + +sub textbook_request_javascript { + my ($numbook,$numcurrent) = @_; + my %lt = &Apache::lonlocal::texthash( + choose => 'Please select a content option.', + textbook => 'Please select a textbook, or choose a different option.', + existing => 'Please select one of your existing courses to copy, or choose a different option.', + title => 'Please enter a course title.', + ); + return if (!$numbook && !$numcurrent); + return <<"ENDSCRIPT"; +function cloneChoice() { + if (document.requestcourse.cloning) { + var radioLength = document.requestcourse.cloning.length; + if (radioLength == undefined) { + var val = document.requestcourse.cloning.value; + if ((val == 'textbook') || (val == 'existing')) { + var elem = document.getElementById('show'+val); + if (document.requestcourse.cloning.checked) { + elem.style.display = 'block'; + } else { + uncheckRadio(val); + elem.style.display = 'none'; + } + } + } else { + for (var i=0; i 0) { + uncheckRadio('textbook'); + } + if (numcurrent > 0) { + uncheckRadio('existing'); + } + return; +} + +function validTextbookReq() { + if (document.requestcourse.cloning) { + var cloneChoice = 0; + var radioLength = document.requestcourse.cloning.length; + if (radioLength == undefined) { + if (document.requestcourse.cloning.checked == false) { + alert("$lt{'choose'}"); + return false; + } else { + cloneChoice = document.requestcourse.cloning.value; + } + } else { + for (var i=0; i