--- loncom/interface/lonrequestcourse.pm 2009/07/27 22:58:24 1.1
+++ loncom/interface/lonrequestcourse.pm 2010/11/08 21:16:24 1.41.2.7
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Request a course
#
-# $Id: lonrequestcourse.pm,v 1.1 2009/07/27 22:58:24 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.41.2.7 2010/11/08 21:16:24 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -44,6 +44,68 @@ described at http://www.lon-capa.org.
=item handler()
+=item get_breadcrumbs()
+
+=item header()
+
+=item form_elements()
+
+=item onload_action()
+
+=item print_main_menu()
+
+=item request_administration()
+
+=item close_popup_form()
+
+=item get_instcode()
+
+=item print_request_form()
+
+=item print_enrollment_menu()
+
+=item show_invalid_crosslists()
+
+=item inst_section_selector()
+
+=item date_setting_table()
+
+=item print_personnel_menu()
+
+=item print_request_status()
+
+=item print_request_logs()
+
+=item print_review()
+
+=item dates_from_form()
+
+=item courseinfo_form()
+
+=item clone_form()
+
+=item clone_text()
+
+=item coursecode_form()
+
+=item get_course_dom()
+
+=item display_navbuttons()
+
+=item print_request_outcome()
+
+=item get_processtype()
+
+=item check_autolimit()
+
+=item retrieve_settings()
+
+=item get_request_settings()
+
+=item extract_instcode()
+
+=item generate_date_items()
+
=back
=cut
@@ -55,120 +117,614 @@ use Apache::Constants qw(:common :http);
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonlocal;
-use LONCAPA;
+use Apache::loncoursequeueadmin;
+use Apache::lonuserutils;
+use LONCAPA qw(:DEFAULT :match);
sub handler {
my ($r) = @_;
+ &Apache::loncommon::content_type($r,'text/html');
+ $r->send_http_header;
if ($r->header_only) {
- &Apache::loncommon::content_type($r,'text/html');
- $r->send_http_header;
return OK;
}
- &Apache::loncommon::content_type($r,'text/html');
- $r->send_http_header;
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['action','showdom','cnum','state','crstype']);
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ my $dom = &get_course_dom();
my $action = $env{'form.action'};
my $state = $env{'form.state'};
- my $dom = &get_course_dom();
- my %can_request;
- my $canreq = &check_can_request($dom,\%can_request);
+ my (%states,%stored);
+ my ($jscript,$uname,$udom,$result,$warning);
+
+ $states{'display'} = ['details'];
+ $states{'view'} = ['pick_request','details','cancel','removal'];
+ $states{'log'} = ['filter','display'];
+ $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
+
+ if ($dom eq 'gcitest') {
+ $states{'new'} = ['courseinfo','review','process'];
+ }
+
+ if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
+ unless ($env{'form.state'} eq 'crstype') {
+ unshift(@{$states{'new'}},'codepick');
+ }
+ }
+
+ foreach my $key (keys(%states)) {
+ if (ref($states{$key}) eq 'ARRAY') {
+ unshift (@{$states{$key}},'crstype');
+ }
+ }
+
+ my @invalidcrosslist;
+ my %trail = (
+ crstype => 'Request Action',
+ codepick => 'Category',
+ courseinfo => 'Description',
+ enrollment => 'Access Dates',
+ personnel => 'Personnel',
+ review => 'Review',
+ process => 'Result',
+ pick_request => 'Display Summary',
+ details => 'Request Details',
+ cancel => 'Cancel Request',
+ removal => 'Outcome',
+ );
+ 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) =
+ &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.');
+ }
+ }
+ } elsif ((defined($state)) && (defined($action))) {
+ if (($action eq 'view') && ($state eq 'details')) {
+ if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
+ my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
+ }
+ } elsif ($env{'form.crstype'} eq 'official') {
+ if (&Apache::lonnet::auto_run('',$dom)) {
+ if (($action eq 'new') && (($state eq 'enrollment') ||
+ ($state eq 'personnel'))) {
+ my $checkcrosslist = 0;
+ for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
+ if ($env{'form.crosslist_'.$i}) {
+ $checkcrosslist ++;
+ }
+ }
+ if ($checkcrosslist) {
+ my %codechk;
+ my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
+ &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,
+ \%cat_titles,
+ \%cat_order,
+ \@code_order);
+ my $numtitles = scalar(@codetitles);
+ if ($numtitles) {
+ for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
+ if ($env{'form.crosslist_'.$i}) {
+ my $codecheck;
+ my $crosslistcode = '';
+ foreach my $item (@code_order) {
+ $crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item};
+ }
+ if ($crosslistcode ne '') {
+ ($codechk{$i}, my $rest) =
+ &Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode);
+ }
+ unless ($codechk{$i} eq 'valid') {
+ $env{'form.crosslist_'.$i} = '';
+ push(@invalidcrosslist,$crosslistcode);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ my %elements = &form_elements($dom);
+ my $elementsref = {};
+ if (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();
+ } else {
+ $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
+ if ($state eq 'courseinfo') {
+ $jscript .= &cloning_javascript();
+ }
+ }
+ }
+
+ if ($state eq 'personnel') {
+ $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
+ }
+
+ my $loaditems = &onload_action($action,$state,$dom);
+
+ 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,$dom);
+ &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
+ $crumb,\%request_domains);
} else {
- &request_administration($r,$action,$state,$dom);
+ &request_administration($r,$action,$state,$page,\%states,$dom,
+ $jscript,$loaditems,$crumb,$newinstcode,
+ $codechk,$checkedcode,$description,
+ \@invalidcrosslist);
}
} else {
- $r->print(&Apache::loncommon::start_page('Course Requests').
+ $r->print(&header('Course/Community Requests').$crumb.
'
'.
- &mt('You do not have privileges to request creation of courses.').
- '
'.
- &Apache::loncommon::end_page());
+ &mt('You do not have privileges to request creation of courses or communities.').
+ ''.&Apache::loncommon::end_page());
}
} elsif ($action eq 'view') {
- &print_request_status();
+ if ($state eq 'crstype') {
+ &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\%request_domains);
+ } else {
+ &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
+ $loaditems,$crumb);
+ }
+ } elsif ($action eq 'display') {
+ if ($warning ne '') {
+ my $args = { only_body => 1 };
+ $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);
+ }
} elsif ($action eq 'log') {
- &print_request_logs();
+ &print_request_logs($jscript,$loaditems,$crumb);
} else {
- &print_main_menu($r,\%can_request,$dom);
+ &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains);
}
return OK;
}
-sub check_can_request {
- my ($dom,$can_request) = @_;
- my $canreq = 0;
- if (ref($can_request) eq 'HASH') {
- foreach my $type ('official','unofficial','community') {
- if (&Apache::lonnet::usertools_access($env{'user.name'},
- $env{'user.domain'},
- $type,undef,'requestcourses')) {
- $canreq ++;
- if ($dom eq $env{'user.domain'}) {
- $can_request->{$type} = 1;
+sub mainmenu_javascript {
+ return <<"END";
+function setType(courseForm) {
+ for (var i=0; i 1) {
+ for (var i=0; i{$action}) eq 'ARRAY') {
+ while ($i<@{$states->{$action}} && !$done) {
+ if ($states->{$action}[$i] eq $$state) {
+ $page = $i;
+ $done = 1;
+ }
+ $i++;
}
}
- if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
- my @curr = split(',',$env{'environment.reqcrsotherdom.'.$type});
- if (@curr > 0) {
- $canreq ++;
- unless ($dom eq $env{'user.domain'}) {
- if (grep(/^\Q$dom\E$/,@curr)) {
- $can_request->{$type} = 1;
+ if ($env{'form.crstype'} eq 'official') {
+ if ($page > 1) {
+ if ($states->{$action}[$page-1] eq 'codepick') {
+ if ($env{'form.instcode'} eq '') {
+ ($newinstcode,$numtitles) = &get_instcode($dom);
+ if ($numtitles) {
+ if ($newinstcode eq '') {
+ $$state = 'codepick';
+ $page --;
+ } else {
+ ($codechk,$description) =
+ &Apache::lonnet::auto_validate_instcode('',
+ $dom,$newinstcode);
+ if ($codechk ne 'valid') {
+ $$state = 'codepick';
+ $page --;
+ }
+ $checkedcode = 1;
+ }
+ }
}
}
}
}
+ 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')) {
+ &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=>$firstcrumb});
+ $crumb = &Apache::lonhtmlcommon::breadcrumbs($crumbtitle,$crumbhelp);
+ }
+ } else {
+ &Apache::lonhtmlcommon::add_breadcrumb(
+ {text=>$firstcrumb});
+ $crumb = &Apache::lonhtmlcommon::breadcrumbs($crumbtitle,$crumbhelp);
+ }
+ return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description);
+}
+
+sub header {
+ my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
+ if ($jscript) {
+ $jscript = ''."\n";
+ }
+ if ($loaditems) {
+ if (ref($args) eq 'HASH') {
+ my %loadhash = (
+ 'add_entries' => $loaditems,
+ );
+ my %arghash = (%loadhash,%{$args});
+ $args = \%arghash;
+ } else {
+ $args = {'add_entries' => $loaditems,};
+ }
+ }
+ return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
+}
+
+sub form_elements {
+ my ($dom) = @_;
+ my %elements =
+ (
+ new => {
+ crstype => {
+ crstype => 'selectbox',
+ action => 'selectbox',
+ origcnum => 'hidden',
+ },
+ courseinfo => {
+ cdescr => 'text',
+ cloning => 'radio',
+ clonecrs => 'text',
+ clonedom => 'selectbox',
+ datemode => 'radio',
+ dateshift => 'text',
+ },
+ enrollment => {
+ accessstart_month => 'selectbox',
+ accessstart_hour => 'selectbox',
+ accessend_month => 'selectbox',
+ accessend_hour => 'selectbox',
+ accessstart_day => 'text',
+ accessstart_year => 'text',
+ accessstart_minute => 'text',
+ accessstart_second => 'text',
+ accessend_day => 'text',
+ accessend_year => 'text',
+ accessend_minute => 'text',
+ accessend_second => 'text',
+ no_end_date => 'checkbox',
+ },
+ personnel => {
+ addperson => 'checkbox',
+ },
+ review => {
+ cnum => 'hidden',
+ },
+ },
+ view => {
+ crstype => {
+ crstype => 'selectbox',
+ action => 'selectbox',
+ },
+ },
+ );
+ my %servers = &Apache::lonnet::get_servers($dom,'library');
+ if ($dom eq 'gcitest') {
+ %{$elements{'new'}{'courseinfo'}} = (
+ cdescr => 'text',
+ concepttest => 'radio',
+ );
+ 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);
+ my $numtitles = scalar(@codetitles);
+ if ($numtitles) {
+ my %extras;
+ $lastitem = pop(@codetitles);
+ $extras{'instcode_'.$lastitem} = 'text';
+ foreach my $item (@codetitles) {
+ $extras{'instcode_'.$item} = 'selectbox';
+ }
+ $elements{'new'}{'codepick'} = \%extras;
+ }
+ if (&Apache::lonnet::auto_run('',$dom)) {
+ my %extras = (
+ sectotal => 'hidden',
+ enrollstart_month => 'selectbox',
+ enrollstart_hour => 'selectbox',
+ enrollend_month => 'selectbox',
+ enrollend_hour => 'selectbox',
+ enrollstart_day => 'text',
+ enrollstart_year => 'text',
+ enrollstart_minute => 'text',
+ enrollstart_second => 'text',
+ enrollend_day => 'text',
+ enrollend_year => 'text',
+ enrollend_minute => 'text',
+ enrollend_second => 'text',
+ 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 $crosslisttotal = $env{'form.crosslisttotal'};
+ if ($env{'form.addcrosslist'}) {
+ $crosslisttotal ++;
+ }
+ if (!$crosslisttotal) {
+ $crosslisttotal = 1;
+ }
+
+ for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
+ if ($numtitles) {
+ $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
+ }
+ if (@codetitles > 0) {
+ foreach my $item (@codetitles) {
+ $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
+ }
+ }
+ $extras{'crosslist_'.$i} = 'checkbox';
+ $extras{'crosslist_'.$i.'_instsec'} = 'text',
+ $extras{'crosslist_'.$i.'_lcsec'} = 'text',
+ }
+ my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
+ %{$elements{'new'}{'enrollment'}} = %mergedhash;
+ }
+ my %people;
+ my $persontotal = $env{'form.persontotal'};
+ if ($env{'form.addperson'}) {
+ $persontotal ++;
+ }
+ if ((!defined($persontotal)) || (!$persontotal)) {
+ $persontotal = 1;
+ }
+ for (my $i=0; $i<$persontotal; $i++) {
+ $people{'person_'.$i.'_uname'} = 'text',
+ $people{'person_'.$i.'_dom'} = 'selectbox',
+ $people{'person_'.$i.'_hidedom'} = 'hidden',
+ $people{'person_'.$i.'_firstname'} = 'text',
+ $people{'person_'.$i.'_lastname'} = 'text',
+ $people{'person_'.$i.'_emailaddr'} = 'text',
+ $people{'person_'.$i.'_role'} = 'selectbox',
+ $people{'person_'.$i.'_sec'} = 'selectbox',
+ $people{'person_'.$i.'_newsec'} = 'text',
+ }
+ my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
+ %{$elements{'new'}{'personnel'}} = %personnelhash;
+ return %elements;
+}
+
+sub onload_action {
+ my ($action,$state) = @_;
+ my %loaditems;
+ if (($action eq 'new') || ($action eq 'view')) {
+ if ($state eq 'crstype') {
+ $loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)';
+ } else {
+ $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs);';
+ }
+ if ($state eq 'courseinfo') {
+ if (&show_cloneable()) {
+ $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);';
+ }
+ }
+ if (($state eq 'process') && ($env{'form.concepttest'} eq 'editmyown')) {
+ $loaditems{'onload'} = 'javascript:setInitialVisibility()';
}
}
- return $canreq;
+ return \%loaditems;
}
sub print_main_menu {
- my ($r,$can_request,$dom) = @_;
+ my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$request_domains) = @_;
+ my ($types,$typename) = &Apache::loncommon::course_types();
my $onchange;
unless ($env{'form.interface'} eq 'textual') {
- $onchange = 1;
+ $onchange = 'this.form.submit()';
}
- &Apache::lonhtmlcommon::clear_breadcrumbs();
-
- my $js = <
+ my $nextstate_setter = "\n";
+ if (ref($states) eq 'HASH') {
+ foreach my $key (keys(%{$states})) {
+ if (ref($states->{$key}) eq 'ARRAY') {
+ $nextstate_setter .=
+" if (actionchoice == '$key') {
+ nextstate = '".$states->{$key}[1]."';
+ }
+";
+ }
+ }
+ }
-function nextPage(formname,nextstate) {
- if (check_can_request() == true) {
+ my $js;
+ unless ($dom eq 'gcitest') {
+ $js = <<"END";
+
+function nextPage(formname) {
+ var crschoice = document.mainmenu_coursetype.crstype.value;
+ var actionchoice = document.mainmenu_action.action.value;
+ if (check_can_request(crschoice,actionchoice) == true) {
+ if ((actionchoice == 'new') && (crschoice == 'official')) {
+ nextstate = 'codepick';
+ } else {
+$nextstate_setter
+ }
+ formname.crstype.value = crschoice;
+ formname.action.value = actionchoice;
formname.state.value= nextstate;
formname.submit();
}
return;
}
-function backPage(formname,prevstate) {
- formname.state.value = prevstate;
- formname.submit();
-}
-
-function check_can_request() {
+function check_can_request(crschoice,actionchoice) {
var official = '';
var unofficial = '';
var community = '';
END
-
- 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 this domain.',
+ all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
+ );
+ $js .= <
-
END
+ }
+ my ($pagetitle,$pageinfo,$domaintitle);
+ if (ref($can_request) eq 'HASH') {
+ if (($can_request->{'official'}) || ($can_request->{'unofficial'})) {
+ if ($can_request->{'community'}) {
+ $pagetitle = 'Course/Community Requests';
+ $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.');
+ $domaintitle = &mt('Course/Community Domain');
+ } else {
+ $pagetitle = 'Course Requests';
+ $pageinfo = &mt('Request creation of a new course, or review your pending course requests.');
+ $domaintitle = &mt('Course Domain');
+ }
+ } elsif ($can_request->{'community'}) {
+ $pagetitle = 'Community Requests';
+ $pageinfo = &mt('Request creation of a new course, or review your pending requests.');
+ $domaintitle = &mt('Community Domain');
+ } else {
+ $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');
+ }
+ }
+
+ 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' full e-mail addresses should be used as their usernames to ensure uniqueness.").'
'.
+ &close_popup_form());
} elsif ($action eq 'log') {
- $r->print(&coursereq_log());
+ $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
+ }
+ $r->print(&Apache::loncommon::end_page());
+ return;
+}
+
+sub enrollment_lcsec_js {
+ my %alerts = §ion_check_alerts();
+ my $secname = $alerts{'badsec'};
+ my $secnone = $alerts{'reserved'};
+ my $output = '
+function validateEnrollSections(formname,nextstate) {
+ var badsectotal = 0;
+ var reservedtotal = 0;
+ var secTest = "";
+';
+ for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
+ $output .= "
+ var selSec = 0;
+ for (var j=0; j "You need to change one or more LON-CAPA section names - none is a reserved word in the system, and may not be used.",
+ badsec => 'You need to change one or more LON-CAPA section names - names may only contain letters or numbers.',
+ separate => 'Separate multiple sections with a comma.'
+ );
+ return %lt;
+}
+
+sub section_check_javascript {
+ return <<"END";
+function validsection(field,mult) {
+ var str = field.value;
+ var badsec=0;
+ var reserved=0;
+ if (window.RegExp) {
+ var badsecnum=0;
+ var reservednum=0;
+ var pattern=/[^a-zA-Z0-9]/;
+ str = str.replace(/(^\\s*)|(\\s*\$)/gi,"");
+ str = str.replace(/[ ]{2,}/gi," ");
+ if (mult == '1') {
+ var sections = new Array();
+ sections = str.split(/\\s*[\\s,;:]\\s*/);
+ var i;
+ for (i=0; i 0) {
+ return 'badsec';
+ }
+ if (reservednum > 0) {
+ return 'reserved';
+ }
}
return;
}
+END
+}
+
+sub close_popup_form {
+ my $close= &mt('Close Window');
+ return << "END";
+
+
+
+END
+}
+
+sub get_instcode {
+ my ($dom) = @_;
+ my ($instcode,$numtitles);
+ my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
+ &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
+ \%cat_order,\@code_order);
+ $numtitles = scalar(@codetitles);
+ if (@code_order > 0) {
+ my $message;
+ foreach my $item (@code_order) {
+ $instcode .= $env{'form.instcode_'.$item};
+ }
+ }
+ return ($instcode,$numtitles);
+}
sub print_request_form {
- my ($r,$state,$dom) = @_;
+ my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
+ $description,$invalidcrosslist) = @_;
my $formname = 'requestcrs';
- my ($next,$prev,$message,$output,$codepicker);
- my $prev = 'crstype';
- $r->print('
');
- my $crstype = $env{'form.crstype'};
- my $xlist = 0;
+ my ($next,$prev,$message,$output,$codepicker,$crstype);
+ $prev = $states->{$action}[$page-1];
+ $next = $states->{$action}[$page+1];
+ my %navtxt = &Apache::lonlocal::texthash (
+ prev => 'Back',
+ next => 'Next',
+ );
+ $crstype = $env{'form.crstype'};
+ $r->print('
');
+ my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk,
+ @disallowed);
if ($crstype eq 'official') {
- my (@codetitles,%cat_titles,%cat_order,@code_order);
+ if ($env{'form.instcode'} ne '') {
+ $instcode = $env{'form.instcode'};
+ } elsif ($newinstcode ne '') {
+ $instcode = $newinstcode;
+ }
+ if ($checkedcode) {
+ if ($codechk eq 'valid') {
+ $message = '
'.
+ &mt('No course was found matching your choice of institutional course category.');
+ if ($codechk ne '') {
+ $message .= ' '.$codechk;
+ }
+ $message .= '
';
+ $prev = 'crstype';
+ }
+ $r->print($message);
+ }
+ }
+ if ($prev eq 'crstype') {
+ if ($crstype eq 'official') {
+ &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
+ \%cat_order,\@code_order);
+ }
+ if (@code_order > 0) {
+ $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
+ \%cat_titles,\%cat_order);
+ if ($codepicker) {
+ $r->print(&mt('Specify the course to be created.').
+ '
'.&mt('You may also add users later, once the community has been created, by using the "Manage community users" link, accessible from the "Main Menu".').'
';
+ } else {
+ $output .= '
'.&mt('You may also add users later, once the course has been created, by using the "Manage course users" link, accessible from the "Main Menu".').'
';
}
return $output;
}
+sub current_lc_sections {
+ my @currsecs;
+ if ($env{'form.sectotal'}) {
+ for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
+ if ($env{'form.sec_'.$i}) {
+ if (defined($env{'form.loncapasec_'.$i})) {
+ my $lcsec = $env{'form.loncapasec_'.$i};
+ unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
+ push(@currsecs,$lcsec);
+ }
+ }
+ }
+ }
+ }
+ return @currsecs;
+}
+
sub print_request_status {
+ my ($dom) = @_;
+ my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
+ $env{'user.name'},'^status:'.$dom);
+ my ($output,$formname,%queue_by_date);
+ my ($types,$typenames) = &Apache::loncommon::course_types();
+ foreach my $key (keys(%statusinfo)) {
+ if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) {
+ (undef,my($cdom,$cnum)) = split(':',$key);
+ next if ($cdom ne $dom);
+ my $requestkey = $cdom.'_'.$cnum;
+ if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
+ my %history = &Apache::lonnet::restore($requestkey,'courserequests',
+ $env{'user.domain'},$env{'user.name'});
+ my $entry;
+ my $timestamp = $history{'reqtime'};
+ my $crstype = $history{'crstype'};
+ my $disposition = $history{'disposition'};
+ next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
+ next unless (($env{'form.crstype'} eq 'any') ||
+ ($env{'form.crstype'} eq $crstype));
+ next unless (($disposition eq 'approval') ||
+ ($disposition eq 'pending'));
+ if (ref($history{'details'}) eq 'HASH') {
+ $entry = $requestkey.':'.$crstype.':'.
+ &escape($history{'details'}{'cdescr'});
+ if ($crstype eq 'official') {
+ $entry .= ':'.&escape($history{'details'}{'instcode'});
+ }
+ }
+ if ($entry ne '') {
+ if (exists($queue_by_date{$timestamp})) {
+ if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
+ push(@{$queue_by_date{$timestamp}},$entry);
+ }
+ } else {
+ @{$queue_by_date{$timestamp}} = ($entry);
+ }
+ }
+ }
+ }
+ }
+ $formname = 'requestcrs';
+ my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
+ $output = ''."\n".
+
+ ''."\n".
+ ''."\n".
+ ''."\n".
+ ''."\n";
+ if (@sortedtimes > 0) {
+ my $desctitle;
+ if ($env{'form.crstype'} eq 'any') {
+ $desctitle = &mt('Course/Community Description')
+ } elsif ($env{'form.crstype'} eq 'community') {
+ $desctitle = &mt('Community Description')
+ } else {
+ $desctitle = &mt('Course Description');
+ }
+ $output .= &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ '
'.&mt('You have no matching course or community requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'
'.&mt('You have no matching community requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'
';
+ } else {
+ $output .= '
'.&mt('You have no matching course requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'
';
+ }
+ }
+ $output .= '
+ ';
+ return $output;
+}
+
+sub print_cancel_request {
+ my ($dom,$cnum) = @_;
+ my $requestkey = $dom.'_'.$cnum;
+ my ($result,$output);
+ if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
+ my %history = &Apache::lonnet::restore($requestkey,'courserequests',
+ $env{'user.domain'},$env{'user.name'});
+ my $timestamp = $history{'reqtime'};
+ my $crstype = $history{'crstype'};
+ my $status = $history{'status'};
+ if (($status eq 'cancelled') || ($status eq 'created')) {
+ if ($status eq 'cancelled') {
+ $output = &mt('This request has already been cancelled.');
+ } elsif ($status eq 'created') {
+ $output = &mt('This request has already been processed, and a course created.');
+ }
+ $output = &mt('No further action will be taken');
+ } elsif (ref($history{'details'}) eq 'HASH') {
+ my ($types,$typename) = &Apache::loncommon::course_types();
+ my $showtype = $crstype;
+ if (defined($typename->{$crstype})) {
+ $showtype = $typename->{$crstype};
+ }
+ $output = '
');
}
sub print_request_outcome {
+ my ($r,$dom,$codetitles,$code_order) = @_;
+ my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
+ %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
+ my $sectotal = $env{'form.sectotal'};
+ my $crosslisttotal = 0;
+ $cnum = $env{'form.cnum'};
+ unless ($cnum =~ /^$match_courseid$/) {
+ $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
+ return $output;
+ }
+
+ %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
+ if (ref($domconfig{'requestcourses'}) eq 'HASH') {
+ if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
+ $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
+ }
+ }
+ $now = time;
+ $crstype = $env{'form.crstype'};
+ my $ccrole = 'cc';
+ if ($crstype eq 'community') {
+ $ccrole = 'co';
+ }
+ my @instsections;
+ if ($crstype eq 'official') {
+ if (&Apache::lonnet::auto_run('',$dom)) {
+ ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
+ }
+ for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
+ if ($env{'form.sec_'.$i}) {
+ if ($env{'form.secnum_'.$i} ne '') {
+ my $sec = $env{'form.secnum_'.$i};
+ $sections{$i}{'inst'} = $sec;
+ if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
+ push(@instsections,$sec);
+ }
+ $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
+ $sections{$i}{'loncapa'} =~ s/\W//g;
+ if ($sections{$i}{'loncapa'} eq 'none') {
+ $sections{$i}{'loncapa'} = '';
+ }
+ }
+ }
+ }
+ for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
+ if ($env{'form.crosslist_'.$i}) {
+ my $xlistinfo = '';
+ if (ref($code_order) eq 'ARRAY') {
+ if (@{$code_order} > 0) {
+ foreach my $item (@{$code_order}) {
+ $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
+ }
+ }
+ }
+ $crosslistings{$i}{'instcode'} = $xlistinfo;
+ if ($xlistinfo ne '') {
+ $crosslisttotal ++;
+ }
+ $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
+ $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
+ }
+ }
+ } else {
+ $enrollstart = '';
+ $enrollend = '';
+ }
+ for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
+ my $uname = $env{'form.person_'.$i.'_uname'};
+ my $udom = $env{'form.person_'.$i.'_dom'};
+ if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
+ if (&Apache::lonnet::domain($udom) ne '') {
+ unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
+ $personnel{$uname.':'.$udom} = {
+ firstname => $env{'form.person_'.$i.'_firstname'},
+ lastname => $env{'form.person_'.$i.'_lastname'},
+ emailaddr => $env{'form.person_'.$i.'_emailaddr'},
+ };
+ }
+ my $role = $env{'form.person_'.$i.'_role'};
+ unless ($role eq '') {
+ if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
+ my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
+ unless (grep(/^\Q$role\E$/,@curr_roles)) {
+ push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
+ }
+ } else {
+ @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
+ }
+ if ($role eq $ccrole) {
+ @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
+ } else {
+ my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
+ my @allsecs;
+ foreach my $sec (@currsec) {
+ next unless ($sec =~ /\w/);
+ next if ($sec =~ /\W/);
+ next if ($sec eq 'none');
+ push(@allsecs,$sec);
+ }
+ my $newsec = $env{'form.person_'.$i.'_newsec'};
+ $newsec =~ s/^\s+//;
+ $newsec =~s/\s+$//;
+ my @newsecs = split(/[\s,;]+/,$newsec);
+ foreach my $sec (@newsecs) {
+ next if ($sec =~ /\W/);
+ next if ($sec eq 'none');
+ if ($sec ne '') {
+ unless (grep(/^\Q$sec\E$/,@allsecs)) {
+ push(@allsecs,$sec);
+ }
+ }
+ }
+ @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
+ }
+ }
+ } else {
+ push(@missingdom,$uname.':'.$udom);
+ }
+ } else {
+ push(@baduname,$uname.':'.$udom);
+ }
+ }
+ my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
+ my $autodrops = 0;
+ if ($env{'form.autodrops'}) {
+ $autodrops = $env{'form.autodrops'};
+ }
+ my $autoadds = 0;
+ if ($env{'form.autoadds'}) {
+ $autodrops = $env{'form.autoadds'};
+ }
+ if ($env{'form.autoadds'}) {
+ $autodrops = $env{'form.autoadds'};
+ }
+ my $instcode = '';
+ if (exists($env{'form.instcode'})) {
+ $instcode = $env{'form.instcode'};
+ }
+ my $clonecrs = '';
+ my $clonedom = '';
+ if ((($env{'form.cloning'}) ||
+ (($dom eq 'gcitest') && ($env{'form.concepttest'} eq 'cloning'))) &&
+ ($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
+ ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
+ if ($dom eq 'gcitest') {
+ $env{'form.clonedom'} = 'gcitest';
+ }
+ my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
+ $env{'form.clonedom'});
+ if ($clonehome ne 'no_host') {
+ my $canclone =
+ &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
+ $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
+ $crstype);
+ if ($canclone) {
+ $clonecrs = $env{'form.clonecrs'};
+ $clonedom = $env{'form.clonedom'};
+ }
+ }
+ }
+ my $details = {
+ owner => $env{'user.name'},
+ domain => $env{'user.domain'},
+ cdom => $dom,
+ cnum => $cnum,
+ coursehome => $env{'form.chome'},
+ cdescr => $env{'form.cdescr'},
+ crstype => $env{'form.crstype'},
+ instcode => $instcode,
+ clonedom => $clonedom,
+ clonecrs => $clonecrs,
+ datemode => $env{'form.datemode'},
+ dateshift => $env{'form.dateshift'},
+ sectotal => $sectotal,
+ sections => \%sections,
+ crosslisttotal => $crosslisttotal,
+ crosslists => \%crosslistings,
+ autoadds => $autoadds,
+ autodrops => $autodrops,
+ enrollstart => $enrollstart,
+ enrollend => $enrollend,
+ accessstart => $accessstart,
+ accessend => $accessend,
+ personnel => \%personnel,
+ };
+ if ($dom eq 'gcitest') {
+ if ($env{'form.concepttest'} eq 'editmyown') {
+ $details->{'firstres'} = 'nav';
+ } else {
+ $details->{'firstres'} = 'blank';
+ }
+ if ($env{'form.concepttest'} eq 'cloning') {
+ if (($clonecrs) && ($clonedom eq 'gcitest')) {
+ $details->{'cloneroster'} = $env{'form.cloneroster'};
+ } else {
+ $details->{'clonedom'} = 'gci';
+ $details->{'clonecrs'} = '8v226795a882b4bcagcil1';
+ }
+ } else {
+ $details->{'clonedom'} = 'gci';
+ $details->{'clonecrs'} = '8v226795a882b4bcagcil1';
+ }
+ $details->{'datemode'} = 'delete';
+ }
+ my (@inststatuses,$storeresult,$creationresult);
+ my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
+ if ($val eq '') {
+ if ($crstype eq 'official') {
+ $output = &mt('You are not permitted to request creation of official courses.');
+ } elsif ($crstype eq 'unofficial') {
+ $output = &mt('You are not permitted to request creation of unofficial courses.');
+ } elsif ($crstype eq 'community') {
+ $output = &mt('You are not permitted to request creation of communities');
+ } else {
+ $output = &mt('Unrecognized course type: [_1]',$crstype);
+ }
+ $storeresult = 'notpermitted';
+ } else {
+ my ($disposition,$message,$reqstatus);
+ my %reqhash = (
+ reqtime => $now,
+ crstype => $crstype,
+ details => $details,
+ );
+ my $requestkey = $dom.'_'.$cnum;
+ my $validationerror;
+ if ($val eq 'autolimit=') {
+ $disposition = 'process';
+ } elsif ($val =~ /^autolimit=(\d+)$/) {
+ my $limit = $1;
+ $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
+ $dom,$crstype,$limit,\$message);
+ } elsif ($val eq 'validate') {
+ my ($inststatuslist,$validationchk,$validation);
+ if (@inststatuses > 0) {
+ $inststatuslist = join(',',@inststatuses);
+ }
+ my $instseclist;
+ if (@instsections > 0) {
+ $instseclist = join(',',@instsections);
+ }
+ $validationchk =
+ &Apache::lonnet::auto_courserequest_validation($dom,
+ $env{'user.name'}.':'.$env{'user.domain'},$crstype,
+ $inststatuslist,$instcode,$instseclist);
+ if ($validationchk =~ /:/) {
+ ($validation,$message) = split(':',$validationchk);
+ } else {
+ $validation = $validationchk;
+ }
+ if ($validation =~ /^error(.*)$/) {
+ $disposition = 'approval';
+ $validationerror = $1;
+ } else {
+ $disposition = $validation;
+ }
+ } else {
+ $disposition = 'approval';
+ }
+ $reqhash{'disposition'} = $disposition;
+ $reqstatus = $disposition;
+ my ($modified,$queued);
+ if ($disposition eq 'rejected') {
+ if ($crstype eq 'community') {
+ $output = &mt('Your community request was rejected.');
+ } else {
+ $output = &mt('Your course request was rejected.');
+ }
+ if ($message) {
+ $output .= '
'.$message.'
';
+ }
+ $storeresult = 'rejected';
+ } elsif ($disposition eq 'process') {
+ my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
+ my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
+ my $type = 'Course';
+ if ($crstype eq 'community') {
+ $type = 'Community';
+ }
+ my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
+ foreach my $role (@roles) {
+ $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
+ }
+ my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
+ 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
+ \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
+ if ($result eq 'created') {
+ $disposition = 'created';
+ $reqstatus = 'created';
+ my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
+ \%longroles);
+ if ($crstype eq 'community') {
+ $output = '
'.&mt('Your community request has been processed and the community has been created.');
+ } else {
+ $output = '
'.&mt('Your course request has been processed and the course has been created.');
+ }
+ if ($dom eq 'gcitest') {
+ my $caller = 'requestcrs';
+ &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',
+ );
+ 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 .= '
'.$showrole;
+ if ($usec ne '') {
+ $future .= ' - '.&mt('section:').' '.$usec;
+ }
+ $future .= '
';
+ $numfuture ++;
+ }
+ }
+ }
+ }
+ }
+ }
+ if ($active) {
+ if ($numactive == 1) {
+ if ($crstype eq 'Community') {
+ $output = &mt('Use the following link to enter the community:');
+ } else {
+ $output = &mt('Use the following link to enter the course:');
+ }
+ } else {
+ if ($crstype eq 'Community') {
+ $output = &mt('Use the following links to your new roles to enter the community:');
+ } else {
+ $output = &mt('Use the following links to your new roles to enter the course:');
+ }
+ }
+ $output .= '
'.$active.'
';
+ }
+ if ($future) {
+ if ($crstype eq 'Community') {
+ $output .= &mt('The following community [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'','',&Apache::lonlocal::locallocaltime($details->{'accessstart'}))
+ } else {
+ $output .= &mt('The following course [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'','',&Apache::lonlocal::locallocaltime($details->{'accessstart'}));
+ }
+ $output .= '
'.$future.'
';
+ }
+ 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) = @_;
+ $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 at a later date by visiting the [_1]"Menu"[_2] page and choosing: [_1]"Manage Enrollment"[_2].','','').'
');
+}
+
+sub notification_information {
+ my ($disposition,$req_notifylist,$cnum,$now) = @_;
+ my %emails = &Apache::loncommon::getemails();
+ my $address;
+ if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
+ $address = $emails{'permanentemail'};
+ if ($address eq '') {
+ $address = $emails{'notification'};
+ }
+ }
+ my $output;
+ if ($disposition eq 'approval') {
+ $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').' '.
+ &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').' ';
+ if ($address ne '') {
+ $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).' ';
+ }
+ if ($req_notifylist) {
+ my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+ $env{'user.domain'});
+ 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);
+ }
+ } elsif ($disposition eq 'pending') {
+ $output .= '
'.
+&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.').
+ '
';
+ } else {
+ $output .= '
'.
+ &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;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } 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;
+ }
+ last;
+ }
+ }
+ @{$inststatuses} = ('_external_');
+ }
+ }
+ return $val;
+}
+
+sub check_autolimit {
+ my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
+ my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
+ 'userroles',['active','future'],['cc','co'],[$dom]);
+ my ($types,$typename) = &Apache::loncommon::course_types();
+ my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
+ my $count = 0;
+ foreach my $key (keys(%requests)) {
+ my ($cdom,$cnum) = split('_',$key);
+ if (ref($requests{$key}) eq 'HASH') {
+ next if ($requests{$key}{'crstype'} ne $crstype);
+ if (($crstype eq 'community') &&
+ (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
+ $count ++;
+ } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial')) &&
+ (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
+ $count ++;
+ }
+ }
+ }
+ if ($count < $limit) {
+ return 'process';
+ } else {
+ if (ref($typename) eq 'HASH') {
+ if ($crstype eq 'community') {
+ $$message = &mt('Your request has not been processed because you have reached the limit for the number of communities.').
+ ' '.&mt("Your limit is [_1].",$limit);
+ } else {
+ $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').
+ ' '.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
+ }
+ }
+ return 'rejected';
+ }
+ return;
+}
+
+sub retrieve_settings {
+ my ($dom,$cnum,$udom,$uname) = @_;
+ if ($udom eq '' || $uname eq '') {
+ $udom = $env{'user.domain'};
+ $uname = $env{'user.name'};
+ }
+ my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
+ if ($result eq 'ok') {
+ if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
+ $env{'form.chome'} = $reqinfo{'coursehome'};
+ $env{'form.cdescr'} = $reqinfo{'cdescr'};
+ $env{'form.crstype'} = $reqinfo{'crstype'};
+ &generate_date_items($reqinfo{'accessstart'},'accessstart');
+ &generate_date_items($reqinfo{'accessend'},'accessend');
+ if ($reqinfo{'accessend'} == 0) {
+ $env{'form.no_end_date'} = 1;
+ }
+ if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
+ &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
+ &generate_date_items($reqinfo{'enrollend'},'enrollend');
+ }
+ $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
+ $env{'form.clonedom'} = $reqinfo{'clonedom'};
+ $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);
+ }
+ my @currsec;
+ if (ref($reqinfo{'sections'}) eq 'HASH') {
+ foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
+ if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
+ my $sec = $reqinfo{'sections'}{$i}{'inst'};
+ $env{'form.secnum_'.$i} = $sec;
+ $env{'form.sec_'.$i} = '1';
+ if (!grep(/^\Q$sec\E$/,@currsec)) {
+ push(@currsec,$sec);
+ }
+ $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
+ }
+ }
+ }
+ if (ref($reqinfo{'crosslists'}) eq 'HASH') {
+ foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
+ if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
+ $env{'form.crosslist_'.$i} = '1';
+ $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
+ $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
+ if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
+ my $key = $cnum.$i;
+ my $crscode = {
+ $key => $reqinfo{'crosslists'}{$i}{'instcode'},
+ };
+ &extract_instcode($dom,'crosslist',$crscode,$key,$i);
+ }
+ }
+ }
+ }
+ if (ref($reqinfo{'personnel'}) eq 'HASH') {
+ my $i = 0;
+ foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
+ my ($uname,$udom) = split(':',$user);
+ if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
+ if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
+ foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
+ $env{'form.person_'.$i.'_role'} = $role;
+ $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
+ $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
+ $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
+ $env{'form.person_'.$i.'_uname'} = $uname;
+ $env{'form.person_'.$i.'_dom'} = $udom;
+ if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
+ if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
+ my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
+ my @newsecs;
+ if (@usecs > 0) {
+ foreach my $sec (@usecs) {
+ if (grep(/^\Q$sec\E/,@currsec)) {
+ $env{'form.person_'.$i.'_sec'} = $sec;
+ } else {
+ push(@newsecs,$sec);
+ }
+ }
+ }
+ if (@newsecs > 0) {
+ $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
+ }
+ }
+ }
+ $i ++;
+ }
+ }
+ }
+ }
+ $env{'form.persontotal'} = $i;
+ }
+ }
+ }
+ return $result;
+}
+
+sub get_request_settings {
+ my ($dom,$cnum,$udom,$uname) = @_;
+ my $requestkey = $dom.'_'.$cnum;
+ my ($result,%reqinfo);
+ if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
+ my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
+ my $disposition = $history{'disposition'};
+ if (($disposition eq 'approval') || ($disposition eq 'pending')) {
+ if (ref($history{'details'}) eq 'HASH') {
+ %reqinfo = %{$history{'details'}};
+ $result = 'ok';
+ } else {
+ $result = 'nothash';
+ }
+ } else {
+ $result = 'notqueued';
+ }
+ } else {
+ $result = 'invalid';
+ }
+ return ($result,%reqinfo);
+}
+
+sub extract_instcode {
+ my ($cdom,$element,$crscode,$crskey,$counter) = @_;
+ my (%codes,@codetitles,%cat_titles,%cat_order);
+ if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
+ \@codetitles,\%cat_titles,
+ \%cat_order) eq 'ok') {
+ if (ref($codes{$crskey}) eq 'HASH') {
+ if (@codetitles > 0) {
+ my $sel = $element;
+ if ($element eq 'crosslist') {
+ $sel .= '_'.$counter;
+ }
+ foreach my $title (@codetitles) {
+ $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
+ }
+ }
+ }
+ }
+ return;
+}
+
+sub generate_date_items {
+ my ($currentval,$item) = @_;
+ if ($currentval =~ /\d+/) {
+ my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
+ &Apache::lonhtmlcommon::get_timedates($currentval);
+ $env{'form.'.$item.'_day'} = $mday;
+ $env{'form.'.$item.'_month'} = $month+1;
+ $env{'form.'.$item.'_year'} = $year;
+ }
+ 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;
+ } else {
+ return 1;
+ }
+}
+
1;