'.
+ &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,'textbook');
+ } else {
+ &textbook_request_disabled($r,$dom,$action,\%can_request);
+ }
+ }
+ return OK;
+ }
+ }
$states{'display'} = ['details'];
$states{'view'} = ['pick_request','details','cancel','removal'];
- $states{'log'} = ['filter','display'];
+ $states{'log'} = ['display'];
$states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
- if ($dom eq 'gcitest') {
- $states{'new'} = ['courseinfo','review','process'];
- if ($env{'form.concepttest'} eq 'editmyown') {
- push(@{$states{'new'}},'chooseitems','uploadroster','enrolling');
- } elsif (($env{'form.concepttest'} eq 'defchosen') ||
- (($env{'form.concepttest'} eq 'cloning') && (!$env{'form.cloneroster'}))) {
- push(@{$states{'new'}},'uploadroster','enrolling');
- } else {
- push(@{$states{'new'}},'done');
- }
- }
if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
- unless ($state eq 'crstype') {
+ unless ($env{'form.state'} eq 'crstype') {
unshift(@{$states{'new'}},'codepick');
}
}
+ 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');
@@ -176,74 +252,29 @@ sub generate_page {
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',
removal => 'Outcome',
- chooseitems => 'Saved Test',
- uploadroster => 'Upload Roster',
- enrolling => 'Completed',
- done => 'Completed',
+ display => 'Request Logs',
);
- if ($dom eq 'gcitest') {
- $trail{'crstype'} = 'Building a Test';
- $trail{'courseinfo'} = 'Test Information';
- }
if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
$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))) {
- my $namespace = 'courserequestqueue';
- if ($env{'form.cnum'} ne '') {
- my $cnum = $env{'form.cnum'};
- my $reqkey = $cnum.'_approval';
- 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'}))) {
@@ -290,18 +321,18 @@ sub generate_page {
}
}
}
- 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 '')) {
$env{'form.clonedom'} = $dom;
}
if ($state eq 'crstype') {
- $jscript = &mainmenu_javascript($action);
+ $jscript = &mainmenu_javascript();
} else {
$jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
if ($state eq 'courseinfo') {
@@ -314,25 +345,18 @@ sub generate_page {
$jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
}
- my $loaditems = &onload_action($action,$state,$dom);
+ 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);
- if ($state eq 'chooseitems' || $state eq 'uploadroster' ||
- $state eq 'enrolling') {
- return $canreq;
- }
+ $showcredits,$instcredits,\@invalidcrosslist);
}
} else {
$r->print(&header('Course/Community Requests').$crumb.
@@ -342,32 +366,49 @@ sub generate_page {
}
} 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 '') {
my $args = { only_body => 1 };
- $r->print(&header('Course/Community Requests','','',$args).$crumb.
+ $r->print(&header('Course/Community Requests','','' ,'',$args).$crumb.
'
'.&mt('Course/Community Request Details').'
'.
'
'.$warning.'
'.
&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') {
- &print_request_logs($jscript,$loaditems,$crumb);
+ if ($state eq 'crstype') {
+ &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\@incdoms);
+ } else {
+ $jscript .= < 1) {
+ if (courseForm.cloning.length > 1) {
for (var i=0; i 'requestcrs',
- uploadroster => 'studentform',
- enrolling => 'requestcrs',
- done => 'requestcrs',
- );
- my $lastidx;
- for (my $i=0; $i<@{$states->{$action}}; $i++) {
- if ($$state eq $states->{$action}[$i]) {
- $lastidx = $i;
- last;
- }
- }
- for (my $i=0; $i<@{$states->{$action}}; $i++) {
- if ($$state eq $states->{$action}[$i]) {
- &Apache::lonhtmlcommon::add_breadcrumb(
- {text=>"$trail->{$$state}"});
- $crumb = &Apache::lonhtmlcommon::breadcrumbs($crumbtitle,$crumbhelp);
- last;
- } else {
- if (($$state eq 'process') || ($$state eq 'removal')) {
+ 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 {
- if (($$state eq 'chooseitems') || ($$state eq 'uploadroster') ||
- ($$state eq 'enrolling') || ($$state eq 'done')) {
- if (($states->{$action}[$i] ne 'process') &&
- ($states->{$action}[$i] ne 'chooseitems') &&
- ($states->{$action}[$i] ne 'uploadroster') &&
- ($states->{$action}[$i] ne 'enrolling') &&
- ($states->{$action}[$i] ne 'done')) {
- &Apache::lonhtmlcommon::add_breadcrumb(
- { href => '/adm/requestcourse',
- text => "$trail->{$states->{$action}[$i]}",
- }
- );
- } else {
- my $diff = $i-$lastidx;
- &Apache::lonhtmlcommon::add_breadcrumb(
- { href => "javascript:history.go($diff)",
- text => "$trail->{$states->{$action}[$i]}", }
- );
- }
+ 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]')",
@@ -513,13 +514,13 @@ sub get_breadcrumbs {
}
} else {
&Apache::lonhtmlcommon::add_breadcrumb(
- {text=>$firstcrumb});
- $crumb = &Apache::lonhtmlcommon::breadcrumbs($crumbtitle,$crumbhelp);
+ {text=>'Pick Action'});
+ $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
}
} else {
&Apache::lonhtmlcommon::add_breadcrumb(
- {text=>$firstcrumb});
- $crumb = &Apache::lonhtmlcommon::breadcrumbs($crumbtitle,$crumbhelp);
+ {text=>'Pick Action'});
+ $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
}
return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description);
}
@@ -535,20 +536,19 @@ sub header {
if (ref($args) eq 'HASH') {
my %loadhash = (
'add_entries' => $loaditems,
- 'function' => 'norole',
);
my %arghash = (%loadhash,%{$args});
- $args = \%arghash;
+ $args = \%arghash;
} else {
- $args = {'add_entries' => $loaditems,
- 'function' => 'norole'};
+ $args = {'add_entries' => $loaditems,};
}
}
return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
}
sub form_elements {
- my ($dom) = @_;
+ my ($dom,$showcredits) = @_;
+ my $instcredits;
my %elements =
(
new => {
@@ -559,11 +559,12 @@ sub form_elements {
},
courseinfo => {
cdescr => 'text',
- cloning => 'radio',
+ cloning => 'radio',
clonecrs => 'text',
clonedom => 'selectbox',
datemode => 'radio',
dateshift => 'text',
+ tinyurls => 'radio',
},
enrollment => {
accessstart_month => 'selectbox',
@@ -595,28 +596,12 @@ sub form_elements {
},
);
my %servers = &Apache::lonnet::get_servers($dom,'library');
- if ($dom eq 'gcitest') {
- %{$elements{'new'}{'courseinfo'}} = (
- cdescr => 'text',
- concepttest => 'radio',
- );
- $elements{'new'}{'enrollment'}{'timezone'} = 'selectbox';
- if (&show_cloneable()) {
- $elements{'new'}{'courseinfo'}{'clonecrs'} = 'selectbox';
- $elements{'new'}{'courseinfo'}{'clonedom'} = 'hidden';
- $elements{'new'}{'courseinfo'}{'cloneroster'} = 'checkbox';
- }
- }
my $numlib = keys(%servers);
if ($numlib > 1) {
$elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
} else {
$elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
}
- if ($dom eq 'gcitest') {
- my %mergedhash = (%{$elements{'new'}{'courseinfo'}},%{$elements{'new'}{'enrollment'}});
- %{$elements{'new'}{'courseinfo'}} = %mergedhash;
- }
my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
&Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
\%cat_order,\@code_order);
@@ -632,7 +617,6 @@ sub form_elements {
}
if (&Apache::lonnet::auto_run('',$dom)) {
my %extras = (
- sectotal => 'hidden',
enrollstart_month => 'selectbox',
enrollstart_hour => 'selectbox',
enrollend_month => 'selectbox',
@@ -648,12 +632,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'};
@@ -663,7 +674,6 @@ sub form_elements {
if (!$crosslisttotal) {
$crosslisttotal = 1;
}
-
for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
if ($numtitles) {
$extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
@@ -701,7 +711,7 @@ sub form_elements {
}
my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
%{$elements{'new'}{'personnel'}} = %personnelhash;
- return %elements;
+ return (\%elements,$instcredits);;
}
sub onload_action {
@@ -713,18 +723,17 @@ sub onload_action {
} else {
$loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs);';
}
+ if ($state eq 'courseinfo') {
+ $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);';
+ }
}
return \%loaditems;
}
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})) {
@@ -738,13 +747,11 @@ sub print_main_menu {
}
}
- my $js;
- unless ($dom eq 'gcitest') {
- $js = <<"END";
+ my $js = <<"END";
function nextPage(formname) {
var crschoice = document.mainmenu_coursetype.crstype.value;
- var actionchoice = document.mainmenu_action.reqaction.value;
+ var actionchoice = document.mainmenu_action.action.value;
if (check_can_request(crschoice,actionchoice) == true) {
if ((actionchoice == 'new') && (crschoice == 'official')) {
nextstate = 'codepick';
@@ -752,7 +759,7 @@ function nextPage(formname) {
$nextstate_setter
}
formname.crstype.value = crschoice;
- formname.reqaction.value = actionchoice;
+ formname.action.value = actionchoice;
formname.state.value= nextstate;
formname.submit();
}
@@ -762,43 +769,63 @@ $nextstate_setter
function check_can_request(crschoice,actionchoice) {
var official = '';
var unofficial = '';
- var community = '';
+ var community = '';
+ var textbook = '';
+ var placement = '';
END
- if (ref($can_request) eq 'HASH') {
- foreach my $item (keys(%{$can_request})) {
- $js .= "
- $item = 1;
+ if (ref($can_request) eq 'HASH') {
+ foreach my $item (keys(%{$can_request})) {
+ $js .= "
+ $item = 1;
";
- }
}
- 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.\\nAll types is not allowed.',
- );
- $js .= < '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.',
+ textbook => 'You are not permitted to request creation of a textbook course in this domain',
+ placement => 'You are not permitted to request creation of a placement test in this domain',
+ 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'})) {
+ if (($can_request->{'official'}) || ($can_request->{'unofficial'}) || ($can_request->{'textbook'}) || ($can_request->{'placement'})) {
if ($can_request->{'community'}) {
$pagetitle = 'Course/Community Requests';
$pageinfo = &mt('Request creation of a new course or community, or review your pending requests.');
@@ -823,72 +849,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');
+ } else {
+ $pagetitle = 'Course/Community Requests';
+ $pageinfo = &mt('You do not have rights to request creation of courses or communities.');
+ $earlyout = 1;
}
}
-
- if ($dom eq 'gcitest') {
- my $formname = 'requestcrs';
- my $nexttext = &mt('Continue');
- $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb.
- '
'.&mt('Deployment of a Concept Test requires completion of the following three steps:').'
'.
- '
'.&mt('Creation of a course "container" and setting of access dates').'
'.
- '
'.&mt('Assembly of a valid test from Concept Inventory questions').'
'.
- '
'.&mt('Enrollment of students').'
'.
- '
'.&mt('When assembling a test you may:').
- ' '.&mt('(a) have a valid test built automatically by the WebCenter, or').' '.&mt('(b) select the questions to include by combining questions chosen from eleven bins with four mandatory questions, or').
- ' '.&mt('(c) copy one of your existing tests (including optional copying of the student roster)').'
'.&mt('The most efficient way to enroll students is to upload a text file containing usernames and passwords.').' '.&mt("Students' e-mail addresses must be used as their usernames to ensure uniqueness.").'
'.&mt('The following management tools are available via the "[_1]Manage Tests[_2]" tab, or from the toolbar on the [_3]Concept Test Contents[_4] page.[_5]',
- '','','','',' ').
- '
'.
- '
'.&mt('Concept Test Contents').'
'.
- '
'.&mt('Display the Table of Contents for your Concept Test.').'
'.
- '
'.&mt('Assemble Concept Test').'
'.
- '
'.&mt('If no students have attempted the Concept Test you will be able to modify it. You can also change the start and end date of the test itself.').'
'.
- '
'.
- '
'.&mt('Enrollment and Student Activity').'
'.
- '
'.&mt('Display or download a course roster, and view information about completion status and last login. You can also add new students, or change access dates for existing students.').'
'.
- '
'.&mt("What's New?").'
'.
- '
'.&mt('View information about changes in your Concept Test course.').'
'.
- '
'.
- '
'.&mt('Prepare Printable Concept Test').'
'.
- '
'.&mt('Create a PDF which you can send to a printer to create a hardcopy of the Concept Test.').'
'.
- '
'.&mt('Concept Test Statistics').'
'.
- '
'.&mt('After the closing date of the Concept Test you can view and download statistics for the test, as well as anonymized submission data.').'
'.
+ &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.').'
';
}
my $container = 'Course';
@@ -2590,9 +3106,9 @@ sub print_review {
}
sub dates_from_form {
- my ($startname,$endname,$timezone) = @_;
- my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname,$timezone);
- my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname,$timezone);
+ my ($startname,$endname) = @_;
+ my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
+ my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
if ($endname eq 'accessend') {
if (exists($env{'form.no_end_date'}) ) {
$enddate = 0;
@@ -2602,19 +3118,22 @@ sub dates_from_form {
}
sub courseinfo_form {
- my ($dom,$formname,$state,$crstype,$next,$description) = @_;
- my %lt = &Apache::lonlocal::texthash(
+ my ($dom,$formname,$crstype,$next,$description) = @_;
+ 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'};
+ &js_escape(\%js_lt);
+ $js_lt{'unofficial'} = $js_lt{'official'};
+ $js_lt{'textbook'} = $js_lt{'official'};
+ $js_lt{'placement'} = $js_lt{'official'};
my $js_validate = <<"ENDJS";
+ENDCLOSE
+ my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble);
+ &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Processing ...'));
+ $r->rflush();
+ if (ref($details) eq 'HASH') {
+ if ($details->{'clonecrs'}) {
+ $customitems{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
+ }
+ }
+ $customitems{'_LC_ownerfullname'} = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'},'first');
+ my $owneremail;
+ my %emails = &Apache::loncommon::getemails();
+ foreach my $email ('permanentemail','critnotification','notification') {
+ $owneremail = $emails{$email};
+ last if ($owneremail ne '');
+ }
+ if ($owneremail ne '') {
+ $customitems{'_LC_owneremail'} = $owneremail;
+ }
+ $customitems{'_LC_coursedomainname'} = &Apache::lonnet::domain($dom,'description');
+ $customitems{'_LC_coursedescription'} = $coursedesc;
+ $customitems{'_LC_coursestartdate'} = $accessstart;
+ $customitems{'_LC_courseenddate'} = $accessend;
+ my ($result,$postprocess) = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
+ 'autocreate',$details,\$logmsg,$clonemsg,\$newusermsg,
+ \$addresult,\$enrollcount,\$response,\$keysmsg,\%domdefs,
+ \%longroles,\$code,\%customitems);
+ &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished!'));
+ &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+ $r->print($closure);
+ if (ref($postprocess) eq 'HASH') {
+ $customized = $postprocess->{'createdcustomized'};
+ }
if ($result eq 'created') {
$disposition = 'created';
$reqstatus = 'created';
@@ -3274,79 +3916,59 @@ sub print_request_outcome {
} else {
$output = '
'.&mt('Your course request has been processed and the course has been created.');
}
- if ($dom eq 'gcitest') {
- my $caller = 'requestcrs';
- my $timezone;
- if (&Apache::lonlocal::gettimezone($env{'form.timezone'}) ne 'local') {
- $timezone = $env{'form.timezone'};
- } else {
- $timezone = Apache::lonlocal::gettimezone();
+ if (($code) || ((ref($postprocess) eq 'HASH') &&
+ (($postprocess->{'createdweb'}) || ($postprocess->{'createdmsg'})))) {
+ $output .= ¬ification_information($disposition,$env{'user.name'}.':'.$env{'user.domain'},
+ $dom,$cnum,$now,$code,$postprocess,$crstype);
+ }
+ if ($code) {
+ $reqhash{'code'} = $code;
+ }
+ if (ref($postprocess) eq 'HASH') {
+ if (ref($postprocess->{'createdactions'}) eq 'HASH') {
+ if (ref($postprocess->{'createdactions'}{'environment'}) eq 'HASH') {
+ &Apache::loncoursequeueadmin::postprocess_crsenv($dom,$cnum,
+ $postprocess->{'createdactions'}{'environment'});
+ }
}
- &acquire_cc_role($dom,$cnum,'cc./'.$dom.'/'.$cnum);
- my %parmresult =
- &store_crsparms($dom,$cnum,$now,$accessstart,$accessend);
- &Apache::londocsgci::setdefaults();
- my %crsenvhash = (
- suppress_tries => 'yes',
- timezone => $timezone,
- );
- my $putresult = &Apache::lonnet::put('environment',\%crsenvhash,$dom,$cnum);
- if ($env{'form.concepttest'} eq 'cloning') {
- &Apache::lonuserstate::readmap($dom.'/'.$cnum);
- if (($clonecrs) && ($clonedom eq 'gcitest')) {
- my $cloneid = $clonedom.'/'.$clonecrs;
- my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
- my $oldcdesc = $clonedesc{'description'};
- $output .= ' '.&mt('A concept test has been copied from your existing test: [_1].',''.$oldcdesc.'').'
';
- if ($env{'form.cloneroster'}) {
- $output .= ' '.&mt('You requested copying of the old student roster to the new course.');
- if ($logmsg =~ /\Q\0\E/) {
- my @logging = split("\0",$logmsg);
- if (@logging) {
- $output .= '
';
+ my $user_lh = &Apache::loncommon::user_lang($env{'user.name'},$env{'user.domain'});
+ foreach my $item (@{$clonemsg}) {
+ if (ref($item) eq 'HASH') {
+ $output .= &mt_user($user_lh,$item->{mt},
+ @{$item->{args}}).' '."\n";
}
- $output .= '
';
- &roster_upload_form($r,$output,$formname);
- $output = '';
- } else {
- $output .= ' '.&mt('The next step is to chose which questions are to be included in the Concept Test.').' ';
- $r->print($output);
- &Apache::londocsgci::editor($r,'requestcrs',$dom,$cnum);
- $output = '';
}
- } else {
- $output .= ' '.$role_result.'';
+ $output .= ''."\n";
}
$creationresult = 'created';
+ # Flush the course logs so reverse user roles immediately updated
+ unless ($registered_flush) {
+ my $handlers = $r->get_handlers('PerlCleanupHandler');
+ $r->set_handlers('PerlCleanupHandler' => [\&Apache::lonnet::flushcourselogs,@{$handlers}]);
+ $registered_flush=1;
+ }
+ if ($instcode ne '') {
+ &Apache::lonnet::devalidate_cache_new('instcats',$dom);
+ # Update cache of self-cataloging courses on institution's server(s).
+ if (&Apache::lonnet::shared_institution($dom)) {
+ unless ($registered_instcats) {
+ my $handlers = $r->get_handlers('PerlCleanupHandler');
+ $r->set_handlers('PerlCleanupHandler' => [\&devalidate_remote_instcats,@{$handlers}]);
+ $registered_instcats=1;
+ $modified_dom = $dom;
+ }
+ }
+ }
} else {
$output = '';
if ($crstype eq 'community') {
@@ -3361,15 +3983,19 @@ sub print_request_outcome {
}
} else {
my $requestid = $cnum.'_'.$disposition;
- my $request = {
+ my $request = {
$requestid => {
timestamp => $now,
crstype => $crstype,
ownername => $env{'user.name'},
ownerdom => $env{'user.domain'},
- description => $env{'form.cdescr'},
+ description => $env{'form.cdescr'},
+ lonhost => $lonhost,
},
};
+ if ($crstype eq 'official') {
+ $request->{$requestid}->{'instcode'} = $instcode;
+ }
my $statuskey = 'status:'.$dom.':'.$cnum;
my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
$env{'user.domain'},$env{'user.name'});
@@ -3382,9 +4008,19 @@ sub print_request_outcome {
if (($queuehash{$cnum.'_approval'} ne '') ||
($queuehash{$cnum.'_pending'} ne '')) {
$queued = 1;
+ if (ref($queuehash{$cnum.'_pending'}) eq 'HASH') {
+ $token = $queuehash{$cnum.'_pending'}{'token'};
+ }
}
}
unless ($queued) {
+ if (($disposition eq 'pending') && ($crstype ne 'official')) {
+ my %reqinfo = (
+ $cnum.':'.$dom => $now.':'.$env{'user.name'}.':'.$env{'user.domain'},
+ );
+ $token = &Apache::lonnet::tmpput(\%reqinfo,$lonhost);
+ $request->{$requestid}->{'token'} = $token;
+ }
my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
$dom);
if ($putresult eq 'ok') {
@@ -3393,9 +4029,11 @@ sub print_request_outcome {
} else {
$output .= &mt('Your course request has been recorded.')
}
- $output .= ' '.
- ¬ification_information($disposition,$req_notifylist,
- $cnum,$now);
+ unless ($disposition eq 'pending') {
+ $output .= ' '.
+ ¬ification_information($disposition,$req_notifylist,
+ $dom,$cnum,$now,'','',$crstype);
+ }
} else {
$reqstatus = 'domainerror';
$reqhash{'disposition'} = $disposition;
@@ -3404,45 +4042,106 @@ sub print_request_outcome {
}
}
}
- my ($statusresult);
- if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
- $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
- 'courserequests');
- if ($storeresult eq 'ok') {
- my %status = (
- 'status:'.$dom.':'.$cnum => $reqstatus,
- );
- $statusresult = &Apache::lonnet::put('courserequests',\%status);
+ ($storeresult,my $updateresult) =
+ &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom,
+ $cnum,$reqstatus,'request',$env{'user.domain'},$env{'user.name'});
+ if ($storeresult eq 'ok') {
+ my $postprocess;
+ if (($disposition eq 'approval') || ($disposition eq 'pending')) {
+ my $updateaction = $disposition;
+ if ($disposition eq 'approval') {
+ $updateaction = 'queued';
+ }
+ my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+ $env{'user.domain'});
+ $postprocess =
+ &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,$updateaction,$env{'user.name'},
+ $env{'user.domain'},$fullname,$env{'form.cdescr'});
}
- } else {
- $storeresult = 'error: invalid requestkey format';
- }
- if ($storeresult ne 'ok') {
- $output .= ''.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).' ';
- &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
- } elsif ($statusresult ne 'ok') {
- $output .= ''.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).' ';
- &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
- }
- if ($modified && $queued && $storeresult eq 'ok') {
- if ($crstype eq 'community') {
- $output .= '
'.&mt('Your community request has been updated').'
';
- } else {
- $output .= '
'.&mt('Your course request has been updated').'
';
+ if ($modified && $queued) {
+ if ($crstype eq 'community') {
+ $output .= '
'.&mt('Your community request has been updated').'
';
+ } else {
+ $output .= '
'.&mt('Your course request has been updated').'
';
+ }
+ if ($disposition eq 'approval') {
+ $output .= ¬ification_information($disposition,$req_notifylist,$dom,$cnum,$now,'','',$crstype);
+ }
+ }
+ if ($disposition eq 'approval') {
+ if ((ref($postprocess) eq 'HASH') &&
+ ((ref($postprocess->{'queuedmsg'}) eq 'HASH') || ($postprocess->{'queuedweb'}))) {
+ ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess,$crstype);
+ $customized = $postprocess->{'createdcustomized'};
+ }
+ } elsif ($disposition eq 'pending') {
+ my $pendingform;
+ if ($crstype ne 'official') {
+ $pendingform = &pending_validation_form($r,$dom,$cnum,$crstype,$now,$token,
+ $lonhost,$env{'form.cdescr'});
+ }
+ if ($pendingform) {
+ $output .= $pendingform;
+ } else {
+ $output .= ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess,$crstype);
+ }
+ if (ref($postprocess) eq 'HASH') {
+ $customized = $postprocess->{'createdcustomized'};
+ }
}
- $output .= ¬ification_information($disposition,$req_notifylist,$cnum,$now);
}
if ($validationerror ne '') {
- $output .= ''.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'';
+ $output .= '
'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'
';
+ }
+ if ($updateresult) {
+ $output .= $updateresult;
}
}
if ($creationresult ne '') {
- if ($donedisplay) {
- $r->print(' '.&done_display());
- }
- return ($creationresult,$output);
+ return ($creationresult,$output,$customized);
} else {
- return ($storeresult,$output);
+ return ($storeresult,$output,$customized);
+ }
+}
+
+sub devalidate_remote_instcats {
+ if ($modified_dom ne '') {
+ my %servers = &Apache::lonnet::internet_dom_servers($modified_dom);
+ my %thismachine;
+ map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
+ if (keys(%servers)) {
+ foreach my $server (keys(%servers)) {
+ next if ($thismachine{$server});
+ &Apache::lonnet::remote_devalidate_cache($server,['instcats:'.$modified_dom]);
+ }
+ }
+ $modified_dom = '';
+ }
+ return;
+}
+
+sub custom_formitems {
+ my ($preprocess,$customhash) = @_;
+ return unless ((ref($preprocess) eq 'HASH') && (ref($customhash) eq 'HASH'));
+ if (ref($preprocess->{'formitems'}) eq 'HASH') {
+ foreach my $key (keys(%{$preprocess->{'formitems'}})) {
+ if ($preprocess->{'formitems'}->{$key} eq 'multiple') {
+ if (exists($env{'form.'.$key})) {
+ my @items = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
+ foreach my $item (@items) {
+ $item =~ s/(`)/'/g;
+ $item =~ s/\$/\(\$\)/g;
+ push(@{$customhash->{$key}},$item);
+ }
+ }
+ } else {
+ if (exists($env{'form.'.$key})) {
+ $customhash->{$key} = $env{'form.'.$key};
+ $customhash->{$key} =~ s/(`)/'/g;
+ $customhash->{$key} =~ s/\$/\(\$\)/g;
+ }
+ }
+ }
}
}
@@ -3581,140 +4280,8 @@ sub update_requestors_roles {
return $output;
}
-sub acquire_cc_role {
- my ($cdom,$cnum,$trolecode,$csec) = @_;
- my %coursegroups = &Apache::lonnet::get_active_groups(
- $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
- my $cgrps = join(':',keys(%coursegroups));
- if ($env{'environment.recentroles'}) {
- my %frozen_roles =
- &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
- &Apache::lonhtmlcommon::store_recent('roles',$trolecode,' ',
- $frozen_roles{$trolecode});
- }
-
- &Apache::lonnet::appenv({"request.course.id" => '',
- "request.course.fn" => '',
- "request.course.uri" => '',
- "request.course.sec" => '',
- "request.role" => 'cm',
- "request.role.adv" => $env{'user.adv'},
- "request.role.domain" => $env{'user.domain'}});
-
- &Apache::lonnet::log($env{'user.domain'},
- $env{'user.name'},
- $env{'user.home'},
- "Role ".$trolecode);
-
- &Apache::lonnet::appenv(
- {'request.role' => $trolecode,
- 'request.role.domain' => $cdom,
- 'request.course.sec' => $csec,
- 'request.course.groups' => $cgrps});
- my ($furl,$ferr) = &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
- my $tadv;
- if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
- &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
- return;
-}
-
-sub store_crsparms {
- my ($cdom,$cnum,$now,$accessstart,$accessend) = @_;
- my $topsymb = '___0___uploaded/'.$cdom.'/'.$cnum.'/default.sequence';
- my %crsparms = (
- buttonshide => {
- value => 'yes',
- type => 'string_yesno',
- },
- opendate => {
- value => $accessstart,
- type => 'date_start',
- },
- duedate => {
- value => $accessend,
- type => 'date_end',
- },
- problemstatus => {
- value => 'no',
- type => 'string_problemstatus',
- },
- maxtries => {
- value => '1',
- type => 'intpos',
- },
- discussend => {
- value => $now,
- type => 'date_end',
- },
- discusshide => {
- value => 'yes',
- type => 'string_yesno',
- }
- );
- my %parmresult;
- foreach my $item (keys(%crsparms)) {
- $parmresult{$item} =
- &Apache::lonparmset::storeparm_by_symb($topsymb,
- '0_'.$item,14,$crsparms{$item}{'value'},
- $crsparms{$item}{'type'},undef,$cdom);
- }
- return %parmresult;
-}
-
-sub roster_upload_form {
- my ($r,$output,$formname,$titletext) = @_;
- my $title = &mt('Request Processed');
- if ($titletext ne '') {
- $title = $titletext;
- }
- $r->print(<<"ENDJS");
-
-
-ENDJS
- $r->print('
'.$title.'
'.$output.
- '
'.&mt('Course roster file upload').'
');
- $r->print('
'.&mt('If you have a text file available containing student e-mail addresses and initial passwords, you may upload it now.').' '.
- &mt('You may also enroll students later with the [_1]"Enrollment/Activity"[_2] utility in the management toolbar.','','').'
'.
- '');
-}
-
sub notification_information {
- my ($disposition,$req_notifylist,$cnum,$now) = @_;
+ my ($disposition,$req_notifylist,$dom,$cnum,$now,$code,$postprocess,$crstype) = @_;
my %emails = &Apache::loncommon::getemails();
my $address;
if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
@@ -3730,112 +4297,231 @@ sub notification_information {
if ($address ne '') {
$output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).' ';
}
+ my %possemails;
+ my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+ $env{'user.domain'});
+ my $emailto = &Apache::loncommon::build_recipient_list(undef,'requestsmail',$dom);
+ if ($emailto) {
+ map { $possemails{$_} = 1; } (split(/,/,$emailto));
+ }
if ($req_notifylist) {
- my $fullname = &Apache::loncommon::plainname($env{'user.name'},
- $env{'user.domain'});
+ if ($emailto) {
+ foreach my $recip (split(/,/,$req_notifylist)) {
+ my ($uname,$udom) = split(/:/,$recip);
+ my %emails = &Apache::loncommon::getemails($uname,$udom);
+ foreach my $type ('permanentemail','notification') {
+ if ((exists($emails{$type})) && ($emails{$type} ne '')) {
+ my @to = split(/,/,$emails{$type});
+ foreach my $addr (@to) {
+ if (($addr ne '') && ($addr =~ m/\@/)) {
+ if (exists($possemails{$addr})) {
+ delete($possemails{$addr});
+ }
+ }
+ }
+ }
+ }
+ }
+ }
my $sender = $env{'user.name'}.':'.$env{'user.domain'};
- &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
+ &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",
+ undef,$env{'form.cdescr'},$now,'coursereq',$sender,'','',$crstype);
+ }
+#
+# If domain configuration for "E-mail addresses and helpform" has values set
+# for "E-mail from course requests requiring approval", send email to those
+# addresse(es) when a course request is queued, pending approval, unless
+# the email address will already receive a notification email, because of
+# values set for "Receive notification of course requests requiring approval"
+# in "Request creation of courses" configuration item.
+#
+ if ($emailto && keys(%possemails)) {
+ ¬ify_admin($dom,$crstype,$env{'form.cdescr'},"$fullname ($env{'user.name'}:$env{'user.domain'})",$now,\%possemails);
+ }
+ if (ref($postprocess) eq 'HASH') {
+ if (ref($postprocess->{'queuedmsg'}) eq 'ARRAY') {
+ if (scalar(@{$postprocess->{'queuedmsg'}}) > 0) {
+ my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
+ my $sender = $recipient;
+ my $addmsg = [];
+ foreach my $item (@{$postprocess->{'queuedmsg'}}) {
+ if (ref($item) eq 'HASH') {
+ if ($item->{'mt'} ne '') {
+ push(@{$addmsg},$item);
+ }
+ }
+ }
+ if (scalar(@{$addmsg}) > 0) {
+ &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,undef,
+ $env{'form.cdescr'},$now,
+ 'queuedcrsreq',$sender);
+ }
+ }
+ }
+ if ($postprocess->{'queuedweb'}) {
+ $output .= $postprocess->{'queuedweb'};
+ }
}
} elsif ($disposition eq 'pending') {
- $output .= '
'.
+ my $pending_default = '
'.
&mt('Your request has been placed in a queue pending administrative action.').' '.
&mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").' '.
&mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
- '
';
+ '
';
+ if (ref($postprocess) eq 'HASH') {
+ if ($postprocess->{'pendingweb'}) {
+ $output .= $postprocess->{'pendingweb'};
+ } else {
+ $output .= $pending_default;
+ }
+ } else {
+ $output .= $pending_default;
+ }
+ } elsif ($disposition eq 'created') {
+ if (($code) || ((ref($postprocess) eq 'HASH') &&
+ ((ref($postprocess->{'createdmsg'}) eq 'ARRAY') || ($postprocess->{'createdweb'})))) {
+ my $addmsg = [];
+ my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
+ my $sender = $recipient;
+ if ($code) {
+ push(@{$addmsg},{
+ mt => 'Students can automatically select your course: "[_1]" by entering this code: [_2]',
+ args => [$env{'form.cdescr'},$code],
+ });
+ $output .= '
'.
+ &mt('Students can automatically select your course by entering this code: [_1].',''.$code.'').
+ ' '.
+ &mt('A message has been sent to your LON-CAPA account with this information.');
+ if ($address ne '') {
+ $output.= ' '.&mt('An e-mail has also been sent to: [_1] with this code.',$address);
+ }
+ $output .= '
';
+ }
+ if (ref($postprocess) eq 'HASH') {
+ if (ref($postprocess->{'createdmsg'}) eq 'ARRAY') {
+ foreach my $item (@{$postprocess->{'createdmsg'}}) {
+ if (ref($item) eq 'HASH') {
+ if ($item->{'mt'} ne '') {
+ push(@{$addmsg},$item);
+ }
+ }
+ }
+ }
+ if ($postprocess->{'createdweb'}) {
+ $output .= $postprocess->{'createdweb'}
+ }
+ }
+ if (scalar(@{$addmsg}) > 0) {
+ my $type = 'createdcrsreq';
+ if ($code) {
+ $type = 'uniquecode';
+ }
+ &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,$dom.'_'.$cnum,$env{'form.cdescr'},
+ $now,$type,$sender,'','',$crstype);
+ }
+ }
} else {
$output .= '
'.
- &mt('Your request status is: [_1].',$disposition).
- '
'
+ &mt('Your request status is: [_1].',$disposition).
+ '
';
}
return $output;
}
-sub get_processtype {
- my ($dom,$crstype,$inststatuses,$domconfig) = @_;
- return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
- my (%userenv,%settings,$val);
- my @options = ('autolimit','validate','approval');
- if ($dom eq $env{'user.domain'}) {
- %userenv =
- &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
- 'requestcourses.'.$crstype,'inststatus');
- if ($userenv{'requestcourses.'.$crstype}) {
- $val = $userenv{'requestcourses.'.$crstype};
- @{$inststatuses} = ('_custom_');
- } else {
- my ($task,%alltasks);
- if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
- %settings = %{$domconfig->{'requestcourses'}};
- if (ref($settings{$crstype}) eq 'HASH') {
- if (($env{'user.adv'}) && ($settings{$crstype}{'_LC_adv'} ne '')) {
- $val = $settings{$crstype}{'_LC_adv'};
- @{$inststatuses} = ('_LC_adv_');
- } else {
- if ($userenv{'inststatus'} ne '') {
- @{$inststatuses} = split(',',$userenv{'inststatus'});
- } else {
- @{$inststatuses} = ('default');
- }
- foreach my $status (@{$inststatuses}) {
- if (exists($settings{$crstype}{$status})) {
- my $value = $settings{$crstype}{$status};
- next unless ($value);
- unless (exists($alltasks{$value})) {
- if (ref($alltasks{$value}) eq 'ARRAY') {
- unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
- push(@{$alltasks{$value}},$status);
- }
- } else {
- @{$alltasks{$value}} = ($status);
- }
- }
- }
- }
- my $maxlimit = 0;
-
- foreach my $key (sort(keys(%alltasks))) {
- if ($key =~ /^autolimit=(\d*)$/) {
- if ($1 eq '') {
- $val ='autolimit=';
- last;
- } elsif ($1 > $maxlimit) {
- $maxlimit = $1;
- }
- }
- }
- if ($maxlimit) {
- $val = 'autolimit='.$maxlimit;
- } else {
- foreach my $option (@options) {
- if ($alltasks{$option}) {
- $val = $option;
- last;
- }
- }
- }
- }
+sub notify_admin {
+ my ($dom,$crstype,$contextdesc,$textstr,$timestamp,$emailsref) = @_;
+ if ((ref($emailsref) eq 'HASH') && (keys(%{$emailsref}))) {
+ my $emailto = join(',',sort(keys(%{$emailsref})));
+ my (@rawmsg,$rawsubj,$msgtxt);
+ if ($crstype eq 'community') {
+ $rawsubj = 'Community request to review';
+ $msgtxt = 'Creation of the following community: [_1]was requested by [_2] on [_3].';
+ } else {
+ $rawsubj = 'Course request to review';
+ $msgtxt = 'Creation of the following course: [_1]was requested by [_2] on [_3].';
+ }
+ $timestamp =&Apache::lonlocal::locallocaltime($timestamp);
+ push(@rawmsg,{
+ mt => $msgtxt,
+ args => ["\n $contextdesc\n",$textstr,$timestamp],
+ },
+ {
+ mt =>'[_1]A Domain Coordinator will use: [_2]Main Menu -> Course and community creation -> Approve or reject requests[_3]to display a list of pending requests, which can either be approved or rejected.',
+ args => ["\n","\n\n","\n\n"],
+ });
+
+ my $sender_lh = &Apache::loncommon::user_lang($env{'user.name'},$env{'user.domain'});
+ my $subject = &mt_user($sender_lh,$rawsubj);
+ my $message = '';
+ foreach my $item (@rawmsg) {
+ if (ref($item) eq 'HASH') {
+ if (ref($item->{args}) eq 'ARRAY') {
+ $message .= &mt_user($sender_lh,$item->{mt},@{$item->{args}})."\n";
+ } else {
+ $message .= &mt_user($sender_lh,$item->{mt})."\n";
}
}
}
- } else {
- %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
- $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
- if ($userenv{'reqcrsotherdom.'.$crstype}) {
- my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
- my $optregex = join('|',@options);
- foreach my $item (@doms) {
- my ($extdom,$extopt) = split(':',$item);
- if ($extdom eq $dom) {
- if ($extopt =~ /^($optregex)(=?\d*)$/) {
- $val = $1.$2;
+ my $chgmail = "To: $emailto\n".
+ "Subject: $subject\n".
+ "Content-type: text/plain\; charset=UTF-8\n".
+ "MIME-Version: 1.0\n\n".
+ "$message\n\n";
+ if (open(my $mailh, "|/usr/lib/sendmail -oi -t -odb")) {
+ print $mailh $chgmail;
+ close($mailh);
+ }
+ }
+}
+
+sub pending_validation_form {
+ my ($r,$cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_;
+ my $output;
+ my %postvalues = (
+ 'owner' => $env{'user.name'}.':'.$env{'user.domain'},
+ 'course' => $cdom.'_'.$cnum,
+ 'coursetype' => $crstype,
+ );
+ my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom);
+
+ if (ref($domconfig{'requestcourses'}) eq 'HASH') {
+ my ($url,$buttontext,$code,@fields);
+ if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
+ $postvalues{'description'} = $cdesc;
+ $url = $domconfig{'requestcourses'}{'validation'}{'url'};
+ if (ref($domconfig{'requestcourses'}{'validation'}{'fields'}) eq 'ARRAY') {
+ @fields = @{$domconfig{'requestcourses'}{'validation'}{'fields'}};
+ }
+ $buttontext = $domconfig{'requestcourses'}{'validation'}{'button'};
+ $output .= $domconfig{'requestcourses'}{'validation'}{'markup'};
+ if (($url =~ m{^(https?\://|/)}) && (@fields > 0)) {
+ $output .= '
'."\n";
}
- @{$inststatuses} = ('_external_');
}
}
- return $val;
+ return $output;
}
sub check_autolimit {
@@ -3852,7 +4538,7 @@ sub check_autolimit {
if (($crstype eq 'community') &&
(exists($crsroles{$cnum.':'.$cdom.':co'}))) {
$count ++;
- } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial')) &&
+ } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook') || ($crstype eq 'placement')) &&
(exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
$count ++;
}
@@ -3898,18 +4584,32 @@ sub retrieve_settings {
}
$env{'form.clonecrs'} = $reqinfo{'clonecrs'};
$env{'form.clonedom'} = $reqinfo{'clonedom'};
+ if (($reqinfo{'clonecrs'} ne '') && ($reqinfo{'clonedom'} ne '')) {
+ $env{'form.cloning'} = 1;
+ }
$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);
+ $env{'form.tinyurls'} = $reqinfo{'tinyurls'};
+ 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') || ($reqinfo{'crstype'} eq 'textbook')) {
+ $env{'form.coursecredits'} = $reqinfo{'defaultcredits'};
}
my @currsec;
if (ref($reqinfo{'sections'}) eq 'HASH') {
@@ -4040,16 +4740,821 @@ sub generate_date_items {
return;
}
-sub show_cloneable {
- my $showclone;
- if (&Apache::loncommon::needs_gci_custom()) {
- my %courses = &Apache::loncommon::existing_gcitest_courses('cc');
- my $numcourses = scalar(keys(%courses));
- return $numcourses;
+sub print_textbook_form {
+ my ($r,$dom,$incdoms,$domdefs,$settings,$can_request,$crstype,$formhash) = @_;
+ my (%prefab,%ordered,%numprefab);
+ if ($crstype eq '') {
+ $crstype = 'textbook';
+ }
+#
+# Retrieve list of prefabricated courses (textbook courses and templates) cloneable by user
+#
+ foreach my $type ('textbooks','templates') {
+ $numprefab{$type} = 0;
+ if (ref($settings) eq 'HASH') {
+ $prefab{$type} = $settings->{$type};
+ if (ref($prefab{$type}) eq 'HASH') {
+ foreach my $item (keys(%{$prefab{$type}})) {
+ my ($clonedom,$clonecrs) = split(/_/,$item);
+ if (ref($prefab{$type}{$item}) eq 'HASH') {
+ if (&Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
+ $env{'user.domain'},$clonecrs,$clonedom,$crstype,$dom)) {
+
+ my $num = $prefab{$type}{$item}{'order'};
+ $ordered{$type}{$num} = $item;
+ $numprefab{$type} ++;
+ }
+ }
+ }
+ }
+ }
+ }
+
+#
+# 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
+# Course Coordinator role
+#
+ my $numcurrent;
+ my %cloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.',$env{'user.name'}.':'.$env{'user.domain'},
+ '.',undef,undef,'Course');
+ my %ccroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
+ ['active'],['cc']);
+
+ my $cc_clone = '';
+ foreach my $role (keys(%ccroles)) {
+ my ($cnum,$cdom,$rest) = split(/:/,$role,3);
+ $cc_clone .= $cdom.':'.$cnum.'&';
+ unless (exists($cloneable{$cdom.'_'.$cnum})) {
+ my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{'one_time' => 1});
+ $cloneable{$cdom.'_'.$cnum} = {
+ context => $courseinfo{'internal.creationcontext'},
+ created => $courseinfo{'internal.created'},
+ creator => $courseinfo{'internal.creator'},
+ description => $courseinfo{'description'},
+ inst_code => $courseinfo{'coursecode'},
+ owner => $courseinfo{'internal.courseowner'},
+ releaserequired => $courseinfo{'internal.releaserequired'},
+ type => $courseinfo{'type'},
+ };
+ }
+ }
+
+ my $numcurrent = scalar(keys(%cloneable));
+
+#
+# Retrieve information about courses from user's domain which user can clone, but which not owned
+# or cloneable based on Course Coordinator role.
+#
+ my ($numdomcourses,%domcloneable);
+ my %allcloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',undef,undef,'Course',
+ undef,undef,undef,undef,undef,
+ $env{'user.name'}.':'.$env{'user.domain'},
+ $cc_clone,1);
+ foreach my $cid (keys(%allcloneable)) {
+ unless (exists($cloneable{$cid})) {
+ $domcloneable{$cid} = $allcloneable{$cid};
+ }
+ }
+ $numdomcourses = scalar(keys(%domcloneable));
+
+ my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+ $env{'user.domain'});
+
+#
+# Retrieve any custom form information prior to rendering page
+#
+
+ my $initprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'initializereview',$env{'user.name'},
+ $env{'user.domain'},$fullname);
+ my %custominit;
+ if (ref($initprocess) eq 'HASH') {
+ &custom_formitems($initprocess,\%custominit);
+ }
+
+#
+# Retrieve any custom onload actions or javascript used for page before rendering
+#
+
+ my ($customonload,$customjs,$customvalidationjs);
+ my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'prereview',$env{'user.name'},
+ $env{'user.domain'},$fullname,undef,undef,
+ undef,undef,\%custominit);
+ if (ref($inprocess) eq 'HASH') {
+ $customonload = $inprocess->{'onload'};
+ $customjs = $inprocess->{'javascript'};
+ $customvalidationjs = $inprocess->{'validationjs'};
+ }
+
+ my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'review',
+ $env{'user.name'},
+ $env{'user.domain'},$fullname,undef,undef,
+ undef,undef,\%custominit);
+
+ my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent,$numdomcourses,$customvalidationjs);
+ $jscript .= $customjs;
+ my (%loaditems,$args);
+ $loaditems{'onload'} = 'javascript:uncheckAllRadio();'.$customonload;
+ if ($crstype eq 'lti') {
+ $args = { 'only_body' => 1};
+ }
+ $r->print(&header('Course Request',$jscript,\%loaditems,undef,$args));
+
+ if (ref($can_request) eq 'HASH') {
+ unless (((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) ||
+ ($crstype eq 'lti')) {
+ &Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/requestcourse',
+ text => 'Pick action',
+ });
+ }
+ }
+ unless ($crstype eq 'lti') {
+ &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
+
+ &startContentScreen($r,'textbookrequests');
+#
+# Show domain selector form, if required.
+#
+ if (@{$incdoms} > 1) {
+ my $onchange = 'this.form.submit()';
+ $r->print('