--- loncom/interface/lonrequestcourse.pm 2014/01/04 02:10:36 1.74 +++ loncom/interface/lonrequestcourse.pm 2022/01/01 17:40:20 1.95.2.7.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.74 2014/01/04 02:10:36 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.95.2.7.2.1 2022/01/01 17:40:20 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -119,6 +119,10 @@ use Apache::loncoursequeueadmin; use Apache::lonuserutils; use LONCAPA qw(:DEFAULT :match); +my $registered_flush; +my $registered_instcats; +my $modified_dom; + sub handler { my ($r) = @_; &Apache::loncommon::content_type($r,'text/html'); @@ -127,6 +131,10 @@ sub handler { return OK; } + $registered_flush = 0; + $registered_instcats = 0; + $modified_dom = ''; + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['action','showdom','cnum','state','crstype','queue','tabs']); &Apache::lonhtmlcommon::clear_breadcrumbs(); @@ -172,13 +180,29 @@ sub handler { if ($can_request{'textbook'}) { &process_textbook_request($r,$dom,$action,\%domdefs,\%domconfig,\%can_request); } else { - &textbook_request_disabled($r,$dom,\%can_request); + &textbook_request_disabled($r,$dom,$action,\%can_request); + } + } elsif ($action eq 'display') { + my ($uname,$udom,$result,$warning) = &domcoord_display($dom); + if ($warning ne '') { + my $args = { only_body => 1 }; + $r->print(&header('Course/Community Requests','','' ,'',$args). + '

'.&mt('Course/Community Request Details').'

'. + '
'.$warning.'
'. + &close_popup_form()); + } else { + $states{'display'} = ['details']; + my $loaditems = &onload_action($action,$state); + my $page = 0; + &request_administration($r,$action,$state,$page,\%states,$dom,$jscript, + $loaditems,'','','','','',$showcredits,'','', + $uname,$udom); } } else { if ($can_request{'textbook'}) { &print_textbook_form($r,$dom,\@incdoms,\%domdefs,$domconfig{'requestcourses'},\%can_request); } else { - &textbook_request_disabled($r,$dom,\%can_request); + &textbook_request_disabled($r,$dom,$action,\%can_request); } } return OK; @@ -232,46 +256,7 @@ sub handler { 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))) { - if ($env{'form.cnum'} ne '') { - my $cnum = $env{'form.cnum'}; - my $queue = $env{'form.queue'}; - my $reqkey = $cnum.'_'.$queue; - my $namespace = 'courserequestqueue'; - my $domconfig = &Apache::lonnet::get_domainconfiguser($dom); - my %queued = - &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig); - if (ref($queued{$reqkey}) eq 'HASH') { - $uname = $queued{$reqkey}{'ownername'}; - $udom = $queued{$reqkey}{'ownerdom'}; - if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) { - $result = &retrieve_settings($dom,$cnum,$udom,$uname); - } else { - if ($env{'form.crstype'} eq 'community') { - $warning = &mt('Invalid username or domain for community requestor'); - } else { - $warning = &mt('Invalid username or domain for course requestor'); - } - } - } else { - if ($env{'form.crstype'} eq 'community') { - $warning = &mt('No information was found for this community request.'); - } else { - $warning = &mt('No information was found for this course request.'); - } - } - } else { - $warning = &mt('No course request ID provided.'); - } - } else { - if ($env{'form.crstype'} eq 'any') { - $warning = &mt('You do not have rights to view course or community request information.'); - } elsif ($env{'form.crstype'} eq 'community') { - $warning = &mt('You do not have rights to view community request information.'); - } else { - $warning = &mt('You do not have rights to view course request information.'); - } - } + ($uname,$udom,$result,$warning) = &domcoord_display($dom); } elsif ((defined($state)) && (defined($action))) { if (($action eq 'view') && ($state eq 'details')) { if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) { @@ -334,6 +319,8 @@ sub handler { $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored); if ($state eq 'courseinfo') { $jscript .= &cloning_javascript(); + } elsif ($state eq 'process') { + $jscript .= &processing_javascript(); } } } @@ -436,7 +423,7 @@ function setCloneDisplay(courseForm) { for (var i=0; i{$action}}; $i++) { - if ($$state eq $states->{$action}[$i]) { - &Apache::lonhtmlcommon::add_breadcrumb( - {text=>"$trail->{$$state}"}); - $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests'); - last; - } else { - if (($$state eq 'process') || ($$state eq 'removal') || ($$state eq 'reqauthor')) { + if (ref($states->{$action}) eq 'ARRAY') { + for (my $i=0; $i<@{$states->{$action}}; $i++) { + if ($$state eq $states->{$action}[$i]) { &Apache::lonhtmlcommon::add_breadcrumb( - { href => '/adm/requestcourse', - text => "$trail->{$states->{$action}[$i]}", - } - ); + {text=>"$trail->{$$state}"}); + $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests'); + last; } else { - &Apache::lonhtmlcommon::add_breadcrumb( + if (($$state eq 'process') || ($$state eq 'removal') || ($$state eq 'reqauthor')) { + &Apache::lonhtmlcommon::add_breadcrumb( + { href => '/adm/requestcourse', + text => "$trail->{$states->{$action}[$i]}", + } + ); + } else { + &Apache::lonhtmlcommon::add_breadcrumb( { href => "javascript:backPage(document.requestcrs,'$states->{$action}[$i]')", text => "$trail->{$states->{$action}[$i]}", } - ); - } - } - } + ); + } + } + } + } } else { &Apache::lonhtmlcommon::add_breadcrumb( {text=>'Pick Action'}); @@ -559,6 +559,7 @@ sub form_elements { clonedom => 'selectbox', datemode => 'radio', dateshift => 'text', + tinyurls => 'radio', }, enrollment => { accessstart_month => 'selectbox', @@ -720,6 +721,9 @@ sub onload_action { if ($state eq 'courseinfo') { $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);'; } + if ($state eq 'process') { + $loaditems{'onload'} .= 'javascript:hideProcessing();'; + } } return \%loaditems; } @@ -773,7 +777,7 @@ END "; } } - my %lt = &Apache::lonlocal::texthash( + my %js_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 in this domain.', @@ -781,33 +785,34 @@ END all => 'You must choose a specific course type when making a new course request.', allt => '"All types" is not allowed.', ); + &js_escape(\%js_lt); $js .= <{'official'}) || ($can_request->{'unofficial'}) || $can_request->{'textbook'}) { if ($can_request->{'community'}) { @@ -833,15 +838,24 @@ 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'); + } 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). '
'. @@ -935,7 +949,8 @@ END if ($action eq 'new') { my $jsextra; if (($state eq 'courseinfo') || ($state eq 'codepick')) { - $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom); + $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom,'','','','','', + $newinstcode); } elsif ($state eq 'enrollment') { if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) { @@ -1120,10 +1135,58 @@ END return; } +sub domcoord_display { + my ($dom) = @_; + my ($uname,$udom,$result,$warning); + if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) { + if ($env{'form.cnum'} ne '') { + my $cnum = $env{'form.cnum'}; + my $queue = $env{'form.queue'}; + my $reqkey = $cnum.'_'.$queue; + my $namespace = 'courserequestqueue'; + my $domconfig = &Apache::lonnet::get_domainconfiguser($dom); + my %queued = + &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig); + if (ref($queued{$reqkey}) eq 'HASH') { + $uname = $queued{$reqkey}{'ownername'}; + $udom = $queued{$reqkey}{'ownerdom'}; + if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) { + $result = &retrieve_settings($dom,$cnum,$udom,$uname); + } else { + if ($env{'form.crstype'} eq 'community') { + $warning = &mt('Invalid username or domain for community requestor'); + } else { + $warning = &mt('Invalid username or domain for course requestor'); + } + } + } else { + if ($env{'form.crstype'} eq 'community') { + $warning = &mt('No information was found for this community request.'); + } else { + $warning = &mt('No information was found for this course request.'); + } + } + } else { + $warning = &mt('No course request ID provided.'); + } + } else { + if ($env{'form.crstype'} eq 'any') { + $warning = &mt('You do not have rights to view course or community request information.'); + } elsif ($env{'form.crstype'} eq 'community') { + $warning = &mt('You do not have rights to view community request information.'); + } else { + $warning = &mt('You do not have rights to view course request information.'); + } + } + return ($uname,$udom,$result,$warning); +} + sub enrollment_lcsec_js { my %alerts = §ion_check_alerts(); my $secname = $alerts{'badsec'}; my $secnone = $alerts{'reserved'}; + &js_escape(\$secname); + &js_escape(\$secnone); my $output = ' function validateEnrollSections(formname,nextstate) { var badsectotal = 0; @@ -1181,8 +1244,10 @@ function validateEnrollSections(formname sub personnel_lcsec_js { my %alerts = §ion_check_alerts(); - my $secname = $alerts{'badsec'}.'\\n'.$alerts{'separate'}; + my $secname = $alerts{'badsec'}."\n".$alerts{'separate'}; my $secnone = $alerts{'reserved'}; + &js_escape(\$secname); + &js_escape(\$secnone); my $output = ' function validatePersonnelSections(formname,nextstate) { var badsectotal = 0; @@ -1517,8 +1582,9 @@ 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,$instcredits); + my $lonhost = $r->dir_config('lonHostID'); + my ($storeresult,$result,$customized) = &print_request_outcome($r,$lonhost,$dom,\@codetitles, + \@code_order,$instcredits); $r->print($result); if (($storeresult eq 'ok') || ($storeresult eq 'created')) { if ($storeresult eq 'ok') { @@ -1527,10 +1593,14 @@ sub print_request_form { ''.&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); + unless ($customized) { + &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').'

'); + unless ($customized) { + $r->print('

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

'); + } } } } elsif ($state eq 'reqauthor') { @@ -1540,7 +1610,7 @@ sub print_request_form { if ($result eq 'created') { my $role = 'au'; my $spec = "$role./$env{'form.showdom'}/"; - push(@links,&mt('Enter your authoring space with role: [_1]', + push(@links,&mt('Enter your Authoring Space with role: [_1]', ''. &Apache::lonnet::plaintext($role).'')); } @@ -1615,12 +1685,12 @@ sub print_request_form { sub print_author_prompt { my ($r,$action,$cnum,$showdom,$crstype,$storeresult) = @_; - $r->print('

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

'. + $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?'). + &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). @@ -2036,6 +2106,18 @@ sub print_personnel_menu { $output .= &Apache::lonhtmlcommon::row_headline(). '

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

'; } + my $cansearch = 1; + my @alldoms = &Apache::lonnet::all_domains(); + if (@alldoms == 1) { + my %domsrch = &Apache::lonnet::get_dom('configuration', + ['directorysrch'],$alldoms[0]); + if (ref($domsrch{'directorysrch'}) eq 'HASH') { + if ((!$domsrch{'directorysrch'}{'available'}) && + ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) { + $cansearch = 0; + } + } + } for (my $i=0; $i<$persontotal; $i++) { my @linkargs = map { 'person_'.$i.'_'.$_ } (@items); my $linkargstr = join("','",@linkargs); @@ -2060,9 +2142,14 @@ sub print_personnel_menu { } $sectionselector .= $newtitle. ''."\n"; - my $usersrchlinktxt = &mt('Search for user'); - my $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom, - $usersrchlinktxt); + my $usersrchlink; + if ($cansearch) { + my $usersrchlinktxt = &mt('Search for user'); + $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom, + $usersrchlinktxt); + } else { + $usersrchlink = ' '; + } my $userchklinktxt = &mt('Check username'); my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom, $userchklinktxt,'checkusername'); @@ -2309,7 +2396,7 @@ sub print_cancel_request { &Apache::loncommon::start_data_table_row(). ''.$history{details}{'cdescr'}.''. &Apache::lonlocal::locallocaltime($timestamp).''. - ''.$showtype.''. + ''.&mt($showtype).''. &Apache::loncommon::end_data_table_row(). &Apache::loncommon::end_data_table(). '
'; @@ -2364,8 +2451,9 @@ ENDJS } sub viewcancel_javascript { - my $alert = &mt('Are you sure you want to cancel this request?').'\\n'. + my $alert = &mt('Are you sure you want to cancel this request?')."\n". &mt('Your request will be removed.'); + &js_escape(\$alert); return << "ENDJS"; function nextPage(formname,nextstate) { if (confirm('$alert')) { @@ -2662,7 +2750,7 @@ sub requestlog_display_filter { $typename = $typenames->{$crstype}; } } - $output .= ''."\n"; + $output .= ''."\n"; } $output .= ''; } @@ -2737,6 +2825,7 @@ sub print_review { my $enrollrow_title = &mt('Default Access Dates').'
'. '('.&Apache::lonnet::plaintext('st',$category).')'; + my $instcode; if ($env{'form.crstype'} eq 'official') { if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) { foreach my $title (@{$codetitles}) { @@ -2752,6 +2841,11 @@ sub print_review { } } } + if (ref($code_order) eq 'ARRAY') { + foreach my $item (@{$code_order}) { + $instcode .= $env{'form.instcode_'.$item}; + } + } $inst_headers .= ''.&mt('Credits').''; if ($instcredits) { $inst_values .= ''.$instcredits.''; @@ -2832,19 +2926,20 @@ sub print_review { $inst_values .= ''.$env{'form.coursecredits'}.''; } - my %ctxt = &clone_text(); + my %ctxt = &clone_text($env{'form.crstype'}); $inst_headers .= ''.&mt('Clone From').''; if (($env{'form.cloning'}) && ($env{'form.clonecrs'} =~ /^$match_name$/) && ($env{'form.clonedom'} =~ /^$match_domain$/)) { my $canclone = &Apache::loncoursequeueadmin::can_clone_course($uname, $udom,$env{'form.clonecrs'},$env{'form.clonedom'}, - $env{'form.crstype'}); + $env{'form.crstype'},$dom,$instcode); if ($canclone) { my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'}, $env{'form.clonecrs'},('description','internal.coursecode')); if (keys(%courseenv) > 0) { - $inst_headers .= ''.$ctxt{'dsh'}.''; + $inst_headers .= ''.$ctxt{'dsh'}.''. + ''.$ctxt{'dpl'}.''; $inst_values .= ''.$courseenv{'description'}.' '; my $cloneinst = $courseenv{'internal.coursecode'}; if ($cloneinst ne '') { @@ -2860,6 +2955,14 @@ sub print_review { } else { $inst_values .= $ctxt{'ncd'}; } + $inst_values .= ''; + if ($env{'form.tinyurls'} eq 'delete') { + $inst_values .= $ctxt{'nsl'}; + } elsif ($env{'form.tinyurls'} eq 'transfer') { + $inst_values .= $ctxt{'tsl'}; + } else { + $inst_values .= $ctxt{'csl'}; + } $inst_values .= ''; } else { $inst_values .= ''.&mt('Unknown').''; @@ -3001,19 +3104,20 @@ sub dates_from_form { sub courseinfo_form { my ($dom,$formname,$crstype,$next,$description) = @_; - my %lt = &Apache::lonlocal::texthash( + my %js_lt = &Apache::lonlocal::texthash( official => 'You must provide a (brief) course description.', community => 'You must provide a (brief) community description.' ); - $lt{'unofficial'} = $lt{'official'}; - $lt{'textbook'} = $lt{'official'}; + &js_escape(\%js_lt); + $js_lt{'unofficial'} = $js_lt{'official'}; + $js_lt{'textbook'} = $js_lt{'official'}; my $js_validate = <<"ENDJS";