'.&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_request_logs {
+ my ($jscript,$loaditems,$crumb) = @_;
return;
}
sub print_review {
- my ($r,$state,$dom) = @_;
- return;
+ my ($formname,$dom,$codetitles,$cat_titles,$cat_order,$code_order) = @_;
+ my ($types,$typename) = &course_types();
+ my ($owner,$ownername,$owneremail);
+ $owner = $env{'user.name'}.':'.$env{'user.domain'};
+ $ownername = &Apache::loncommon::plainname($env{'user.name'},
+ $env{'user.domain'},'first');
+ my %emails = &Apache::loncommon::getemails();
+ foreach my $email ('permanentemail','critnotification','notification') {
+ $owneremail = $emails{$email};
+ last if ($owneremail ne '');
+ }
+ my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
+ $section_headers,$section_values,$personnel_headers,$personnel_values);
+
+ $crstypename = $env{'form.crstype'};
+ if (ref($typename) eq 'HASH') {
+ unless ($typename->{$env{'form.crstype'}} eq '') {
+ $crstypename = $typename->{$env{'form.crstype'}};
+ }
+ }
+
+ $inst_headers = '
'.&mt('Description').'
'.&mt('Type').'
';
+ $inst_values = '
'.$env{'form.cdescr'}.'
'.$crstypename.'
';
+
+ if ($env{'form.crstype'} eq 'official') {
+ if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
+ foreach my $title (@{$codetitles}) {
+ if ($env{'form.instcode_'.$title} ne '') {
+ $inst_headers .= '
'.$title.'
';
+ my $longitem = $env{'form.instcode_'.$title};
+ if (ref($cat_titles->{$title}) eq 'HASH') {
+ if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
+ $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
+ }
+ }
+ $inst_values .= '
';
+ }
+ } elsif ($disposition eq 'process') {
+ my $type = 'Course';
+ if ($crstype eq 'community') {
+ $type = 'Community';
+ }
+ my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
+ my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
+ my @roles = &Apache::lonuserutils::roles_by_context('course');
+ foreach my $role (@roles) {
+ $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
+ }
+ my $owneremail;
+ my %emails = &Apache::loncommon::getemails();
+ foreach my $email ('permanentemail','critnotification','notification') {
+ $owneremail = $emails{$email};
+ last if ($owneremail ne '');
+ }
+ my %reqdetails = &build_batchcreatehash($dom,$details,$owneremail,\%domdefs);
+ my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses',\%reqdetails,\%longroles,\$logmsg,\$newusermsg,\$addresult,\$enrollcount,\$output,\$keysmsg,$env{'user.domain'},$env{'user.name'},$cnum,$crstype);
+ $disposition = 'created';
+ if ($cid eq "/$dom/$cnum") {
+ $disposition = 'created';
+ $output = &mt('Your course request has been processed and the course has been created.').' '.&mt('You will need to logout and log-in again to be able to select a role in the course.');
+ } else {
+ $output = &mt('An error occurred when processing your course request.').' '.&mt('You may want to review the request details and submit the request again.');
+ }
+ } else {
+ my $requestid = $cnum.'_'.$disposition;
+ my $request = {
+ $requestid => {
+ timestamp => $now,
+ crstype => $crstype,
+ ownername => $env{'user.name'},
+ ownerdom => $env{'user.domain'},
+ description => $env{'form.cdescr'},
+ },
+ };
+ my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
+ $dom);
+ if ($putresult eq 'ok') {
+ my %emails = &Apache::loncommon::getemails();
+ my $address;
+ if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
+ $address = $emails{'permanentemail'};
+ if ($address eq '') {
+ $address = $emails{'notification'};
+ }
+ }
+ $output = &mt('Your course request has been recorded.').' ';
+ if ($disposition eq 'approval') {
+ $output .= &mt('Your course request has been recorded.').' '.
+ &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'});
+ &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,$fullname,$now,$dom,$details);
+ }
+ } else {
+ $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 {
+ $reqhash{'status'} = 'domainerror';
+ $reqhash{'disposition'} = $disposition;
+ my $warning = &mt('An error occurred saving your request in the pending requests queue.');
+ $output = ''.$warning.' ';
+
+ }
+ }
+ my $storeresult;
+ if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
+ $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
+ 'courserequests');
+ } 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");
+ }
+ }
+ 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','approve');
+ 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'}) && (exists($settings{$crstype}{'_LC_adv'}))) {
+ $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'}) {
+ my @doms = split(',',$userenv{'reqcrsotherdom'});
+ my $optregex = join('|',@options);
+ if (grep(/^\Q$dom\E:($optregex=?\d*)/,@doms)) {
+ $val = $1;
+ }
+ @{$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'],[$dom]);
+ my ($types,$typename) = &course_types();
+ my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
+ my %count;
+ if (ref($types) eq 'ARRAY') {
+ foreach my $type (@{$types}) {
+ $count{$type} = 0;
+ }
+ }
+ foreach my $key (keys(%requests)) {
+ my ($cdom,$cnum) = split('_',$key);
+ if (exists($crsroles{$cnum.':'.$cdom.':cc'})) {
+ if (ref($requests{$key}) eq 'HASH') {
+ my $type = $requests{$key}{'crstype'};
+ if ($type =~ /^official|unofficial|community$/) {
+ $count{$type} ++;
+ }
+ }
+ }
+ }
+ if ($count{$crstype} < $limit) {
+ return 'process';
+ } else {
+ if (ref($typename) eq 'HASH') {
+ $$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 build_batchcreatehash {
+ my ($dom,$details,$owneremail,$domdefs) = @_;
+ my %batchhash;
+ my @items = qw{owner domain coursehome clonecrs clonedom datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users};
+ if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) {
+ my $emailenc = &Apache::lonnet::escape($owneremail);
+ my $owner = $details->{'owner'}.':'.$details->{'domain'};
+ foreach my $item (@items) {
+ $batchhash{$item} = $details->{$item};
+ }
+ $batchhash{'title'} = $details->{'cdescr'};
+ $batchhash{'coursecode'} = $details->{'instcode'};
+ $batchhash{'emailenc'} = $emailenc;
+ $batchhash{'adds'} = $details->{'autoadds'};
+ $batchhash{'drops'} = $details->{'autodrops'};
+ $batchhash{'authtype'} = $domdefs->{'auth_def'};
+ $batchhash{'authparam'} = $domdefs->{'auth_arg_def'};
+ if ($details->{'crstype'} eq 'community') {
+ $batchhash{'crstype'} = 'Community';
+ } else {
+ $batchhash{'crstype'} = 'Course';
+ }
+ $batchhash{'users'}{$details->{$owner}} = {
+ firstname => $env{'environment.first'},
+ lastname => $env{'environment.last'},
+ emailenc => $emailenc,
+ email => $owneremail,
+ };
+ }
+ return %batchhash;
+}
+
+sub retrieve_settings {
+ my ($dom,$request_id) = @_;
+ my %reqinfo = &get_request_settings($request_id,$dom);
+ my %stored;
+ $stored{'cdescr'} = &unescape($reqinfo{'description'});
+ $stored{'accessstart'} = $reqinfo{'accessstart'};
+ $stored{'accessend'} = $reqinfo{'accessend'};
+ if ($stored{'accessend'} == 0) {
+ $stored{'no_end_date'} = 1;
+ }
+ $stored{'enrollstart'} = $reqinfo{'enrollstart'};
+ $stored{'enrollend'} = $reqinfo{'enrollend'};
+ $stored{'crosslist'} = $reqinfo{'crosslist'};
+ $stored{'clonecrs'} = $reqinfo{'clonecrs'};
+ $stored{'clonedom'} = $reqinfo{'clonedom'};
+ $stored{'sections'} = $reqinfo{'sections'};
+ $stored{'personnel'} = $reqinfo{'personnel'};
+
+ return %stored;
+}
+
+sub get_request_settings {
+ my ($request_id,$dom);
+}
+
1;