Diff for /loncom/interface/loncoursequeueadmin.pm between versions 1.30 and 1.42

version 1.30, 2012/08/14 15:45:06 version 1.42, 2014/01/08 17:18:11
Line 70  described at http://www.lon-capa.org. Line 70  described at http://www.lon-capa.org.
   
 =item process_official_reqs()  =item process_official_reqs()
   
   =item is_active_author()
   
   =item author_prompt()
   
   =item reqauthor_check()
   
   =item process_reqauthor()
   
 =back  =back
   
 =cut  =cut
Line 101  sub send_selfserve_notification { Line 109  sub send_selfserve_notification {
     } elsif ($context eq 'domainmanagers') {      } elsif ($context eq 'domainmanagers') {
         $rawsubj = 'Course/Community requests reviewed';          $rawsubj = 'Course/Community requests reviewed';
         push(@rawmsg,{          push(@rawmsg,{
                       mt  => 'Course/Community creation requests in the following domain: [_1] have been reviewed.',                        mt  => 'Course/Community creation requests in the following domain: "[_1]" have been reviewed.',
                       args => ["\n$contextdesc"],                        args => ["\n$contextdesc"],
                      });                       });
         if (ref($textstr) eq 'ARRAY') {          if (ref($textstr) eq 'ARRAY') {
             push(@rawmsg,@{$textstr});              push(@rawmsg,@{$textstr});
         }          }
     } elsif ($context eq 'authormanagers') {      } elsif ($context eq 'authormanagers') {
         $rawsubj = 'Authoring space requests reviewed';          $rawsubj = 'Authoring Space requests reviewed';
         push(@rawmsg,{          push(@rawmsg,{
                       mt  => 'Authoring requests in the following domain: [_1] have been reviewed.',                        mt  => 'Authoring requests in the following domain: "[_1]" have been reviewed.',
                       args => ["\n$contextdesc"],                        args => ["\n$contextdesc"],
                      });                       });
         if (ref($textstr) eq 'ARRAY') {          if (ref($textstr) eq 'ARRAY') {
Line 170  sub send_selfserve_notification { Line 178  sub send_selfserve_notification {
                      },                       },
                      {                       {
                       mt =>'[_1]As Domain Coordinator, use: [_2]Main Menu -> Course and community creation -> Approve or reject requests[_3]to display a list of pending requests, which you can either approve or reject.',                        mt =>'[_1]As Domain Coordinator, use: [_2]Main Menu -> Course and community creation -> Approve or reject requests[_3]to display a list of pending requests, which you can either approve or reject.',
                       args => ["\n","\n\n  ","\n\n"],                        args => ["\n","\n\n","\n\n"],
                      });                       });
     } elsif ($context eq 'selfenrollreq') {      } elsif ($context eq 'selfenrollreq') {
         $rawsubj = 'Self-enrollment request';          $rawsubj = 'Self-enrollment request';
         if ($crstype eq 'community') {          if ($crstype eq 'community') {
             $msgtxt = 'Enrollment in the following community: [_1] was requested by [_2] on [_3].'              $msgtxt = 'Enrollment in the following community: [_1]was requested by [_2] on [_3].'
         } else {          } else {
             $msgtxt = 'Enrollment in the following course: [_1] was requested by [_2] on [_3].'              $msgtxt = 'Enrollment in the following course: [_1]was requested by [_2] on [_3].'
         }          }
         push(@rawmsg,{          push(@rawmsg,{
                       mt  => $msgtxt,                        mt  => $msgtxt,
Line 195  sub send_selfserve_notification { Line 203  sub send_selfserve_notification {
                       args => ["  \n\n","\n"],                        args => ["  \n\n","\n"],
                      });                       });
     } elsif ($context eq 'authorreq') {      } elsif ($context eq 'authorreq') {
         $rawsubj = 'Authoring space request to review';          $rawsubj = 'Authoring Space request to review';
         $msgtxt = 'Assignment of an author role in the [_1] domain[_2] was requested by [_3] on [_4].';          $msgtxt = 'Assignment of an author role in the [_1] domain[_2]was requested by [_3] on [_4].';
         push(@rawmsg,{          push(@rawmsg,{
                       mt  => $msgtxt,                        mt  => $msgtxt,
                       args => [$contextdesc,"\n",$textstr,$timestamp],                        args => [$contextdesc,"\n",$textstr,$timestamp],
                      },                       },
                      {                       {
                       mt =>'[_1]As Domain Coordinator, use: [_2]Main Menu -> Create users or modify the roles and privileges of users -> Authoring space reqests[_3]to display a list of pending requests, which you can either approve or reject.',                        mt =>'[_1]As Domain Coordinator, use: [_2]Main Menu -> Create users or modify the roles and privileges of users -> Authoring Space requests[_3]to display a list of pending requests, which you can either approve or reject.',
                       args => ["\n","\n\n  ","\n\n"],                        args => ["\n","\n\n  ","\n\n"],
                      });                       });
   
     } elsif ($context eq 'requestauthor') {      } elsif ($context eq 'requestauthor') {
         $rawsubj = 'Authoring space request';          $rawsubj = 'Authoring Space request';
         $msgtxt = 'Your request for an authoring space requested on [_1]has been reviewed by a Domain Coordinator.';          $msgtxt = 'Your request for an Authoring Space requested on [_1]has been reviewed by a Domain Coordinator.';
         push(@rawmsg,{          push(@rawmsg,{
                       mt  => $msgtxt,                        mt  => $msgtxt,
                       args => [$timestamp."\n"],                        args => [$timestamp."\n"],
Line 216  sub send_selfserve_notification { Line 223  sub send_selfserve_notification {
         if (ref($textstr) eq 'ARRAY') {          if (ref($textstr) eq 'ARRAY') {
             push(@rawmsg,@{$textstr});              push(@rawmsg,@{$textstr});
         }          }
       } elsif ($context eq 'uniquecode') {
           $rawsubj = 'Course Identifier';
           if (ref($textstr) eq 'ARRAY') {
               push(@rawmsg,@{$textstr});
           }
       } elsif ($context eq 'queuedcrsreq') {
           $rawsubj = 'Course Request Queued';
           if (ref($textstr) eq 'ARRAY') {
               push(@rawmsg,@{$textstr});
           }
       } elsif ($context eq 'createdcrsreq') {
           $rawsubj = 'Course Creation Information';
           if (ref($textstr) eq 'ARRAY') {
               push(@rawmsg,@{$textstr});
           }
     }      }
     my @to_notify = split(/,/,$notifylist);      my @to_notify = split(/,/,$notifylist);
     my $numsent = 0;      my $numsent = 0;
Line 362  sub display_queued_requests { Line 384  sub display_queued_requests {
                            '<p>'.&mt('Requests are validated against institutional data to confirm that the requestor is an instructor of record.').'<br />'.                             '<p>'.&mt('Requests are validated against institutional data to confirm that the requestor is an instructor of record.').'<br />'.
                            &mt('Validation is attempted when the request is submitted.').' '.&mt('If unvalidated, the request will be held in a queue.').' '.&mt('Validation of pending requests is automatically repeated daily.').'</p>';                             &mt('Validation is attempted when the request is submitted.').' '.&mt('If unvalidated, the request will be held in a queue.').' '.&mt('Validation of pending requests is automatically repeated daily.').'</p>';
             } elsif ($context eq 'requestauthor') {              } elsif ($context eq 'requestauthor') {
                 $output .= '<h3>'.&mt('Requests for authoring space queued pending approval by a Domain Coordinator').'</h3>';                  $output .= '<h3>'.&mt('Requests for Authoring Space queued pending approval by a Domain Coordinator').'</h3>';
             } else {              } else {
                 $output .= '<h3>'.&mt('Course/Community requests queued pending approval by a Domain Coordinator').'</h3>';                  $output .= '<h3>'.&mt('Course/Community requests queued pending approval by a Domain Coordinator').'</h3>';
             }               } 
Line 375  sub display_queued_requests { Line 397  sub display_queued_requests {
             } elsif ($context eq 'pending') {              } elsif ($context eq 'pending') {
                 $output .= &mt('There are currently no requests for official courses awaiting validation.');                  $output .= &mt('There are currently no requests for official courses awaiting validation.');
             } elsif ($context eq 'requestauthor') {              } elsif ($context eq 'requestauthor') {
                 $output .= &mt('There are currently no requests for authoring space awaiting approval.');                  $output .= &mt('There are currently no requests for Authoring Space awaiting approval.');
             } elsif ($context eq 'domain') {              } elsif ($context eq 'domain') {
                 $output .= &mt('There are currently no course or community requests awaiting approval.');                  $output .= &mt('There are currently no course or community requests awaiting approval.');
             }              }
Line 427  sub build_queue_display { Line 449  sub build_queue_display {
                         official   => 'Official course',                          official   => 'Official course',
                         unofficial => 'Unofficial course',                          unofficial => 'Unofficial course',
                         community  => 'Community',                          community  => 'Community',
                           textbook   => 'Textbook course',
                     );                      );
         $output .= '<th>'.&mt('Type').'</th>'.          $output .= '<th>'.&mt('Type').'</th>'.
                    '<th>'.&mt('Date requested').'</th>'.                     '<th>'.&mt('Date requested').'</th>'.
Line 525  sub update_request_queue { Line 548  sub update_request_queue {
         @processing_errors,@warn_approves,@warn_rejects,@approvals,@warn_dels,          @processing_errors,@warn_approves,@warn_rejects,@approvals,@warn_dels,
         @rejections,@rejectionerrors,@nopermissions,%courseroles,@toremove,          @rejections,@rejectionerrors,@nopermissions,%courseroles,@toremove,
         %communityroles,%domdefs,%approvalmsg,%rejectionmsg,$crstype,$queue,          %communityroles,%domdefs,%approvalmsg,%rejectionmsg,$crstype,$queue,
         $firsturl);          $firsturl,$uniquecode,%codes);
     my $count=0;      my $count=0;
     while (my @course = &Apache::loncommon::get_env_multiple('form.'.$count.'radioreq')) {      while (my @course = &Apache::loncommon::get_env_multiple('form.'.$count.'radioreq')) {
         if (@course[0] =~ /^\d+:.*/) {          if ($course[0] =~ /^\d+:.*/) {
             push(@approvals,@course[0]);              push(@approvals,$course[0]);
         } elsif (@course[0] =~ /^later:.*/) {          } elsif ($course[0] =~ /^later:.*/) {
             #decide later              #decide later
         } else {          } else {
             push(@rejections,@course[0]);              push(@rejections,$course[0]);
         }          }
         $count+=1;          $count+=1;
     }      }
Line 576  sub update_request_queue { Line 599  sub update_request_queue {
         my $domconfiguser = &Apache::lonnet::get_domainconfiguser($cdom);          my $domconfiguser = &Apache::lonnet::get_domainconfiguser($cdom);
         $firsturl = &course_portal_url($domconfiguser,$cdom);          $firsturl = &course_portal_url($domconfiguser,$cdom);
         $approvedmsg = [{          $approvedmsg = [{
                             mt => 'Your request for authoring space has been approved.',                              mt => 'Your request for Authoring Space has been approved.',
                         },                          },
                         {                          {
                             mt   => 'Visit [_1] to log-in and select your author role',                              mt   => 'Visit [_1] to log-in and select your author role',
                             args => [$firsturl],                              args => [$firsturl],
                         }];                          }];
         $rejectedmsg =  [{          $rejectedmsg =  [{
                             mt => 'Your request for authoring space has not been approved.',                              mt => 'Your request for Authoring Space has not been approved.',
                         }];                          }];
         $domdesc = &Apache::lonnet::domain($cdom);          $domdesc = &Apache::lonnet::domain($cdom);
     } else {      } else {
Line 775  sub update_request_queue { Line 798  sub update_request_queue {
                                                      $ownerdom,$ownername);                                                       $ownerdom,$ownername);
                         if ((ref($history{'details'}) eq 'HASH') &&                           if ((ref($history{'details'}) eq 'HASH') && 
                             ($history{'disposition'} eq $queue)) {                              ($history{'disposition'} eq $queue)) {
                             my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg);                              my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,$code,%customitems);
                             my $result = &course_creation($cdom,$cnum,$context,$history{'details'},\$logmsg,                              my $fullname = '';
                                                       \$newusermsg,\$addresult,\$enrollcount,                              my $inprocess = &Apache::lonnet::auto_crsreq_update($cdom,$cnum,$crstype,'process',$ownername,
                                                       \$response,\$keysmsg,\%domdefs,$longroles);                                                                                  $ownerdom,$fullname,$coursedesc);
                               if (ref($inprocess) eq 'HASH') {
                                   foreach my $key (keys(%{$inprocess})) {
                                       if (exists($history{'details'}{$key})) { 
                                           $customitems{$key} = $history{'details'}{$key};
                                       }
                                   }
                               }
                               my ($result,$postprocess) = &course_creation($cdom,$cnum,$context,$history{'details'},\$logmsg,
                                                           \$newusermsg,\$addresult,\$enrollcount,
                                                           \$response,\$keysmsg,\%domdefs,$longroles,\$code,\%customitems);
                             if ($result eq 'created') {                              if ($result eq 'created') {
                                 if ($crstype eq 'community') {                                  if ($crstype eq 'community') {
                                     $approvedmsg = $approvalmsg{'community'};                                      $approvedmsg = $approvalmsg{'community'};
Line 790  sub update_request_queue { Line 823  sub update_request_queue {
                                     if (ref($approvedmsg->[1]) eq 'HASH') {                                      if (ref($approvedmsg->[1]) eq 'HASH') {
                                         $approvedmsg->[1]->{'args'} = [$firsturl];                                          $approvedmsg->[1]->{'args'} = [$firsturl];
                                     }                                      }
                                       if ($code) {
                                           push(@{$approvedmsg},
                                               {
                                                 mt   => 'Students can automatically select your course by entering this code: [_1]',
                                                 args => [$code],
                                               });
                                           $codes{$cnum} = $code;
                                       }
                                       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(@{$approvedmsg},$item);
                                                       }
                                                   }
                                               }
                                           }
                                       }
                                 }                                  }
                                 push(@completed,$cnum);                                  push(@completed,$cnum);
                                                                   
Line 998  sub update_request_queue { Line 1050  sub update_request_queue {
                                                  $approvedlist,$rejectedlist,$crstype);                                                   $approvedlist,$rejectedlist,$crstype);
                 }                  }
             } elsif ($context eq 'requestauthor') {              } elsif ($context eq 'requestauthor') {
                 $chgmsg = "'Action was taken on the following authoring space requests by [_1].',$namelink";                  $chgmsg = "'Action was taken on the following Authoring Space requests by [_1].',$namelink";
                 if (@completed) {                  if (@completed) {
                     $approvedlist = join("\n",@completed);                      $approvedlist = join("\n",@completed);
                     $output .= '<p>'.&mt('The following requests were approved:').'<ul>';                      $output .= '<p>'.&mt('The following requests were approved:').'<ul>';
Line 1039  sub update_request_queue { Line 1091  sub update_request_queue {
                         }                          }
                         my $syllabuslink =                          my $syllabuslink =
                             &Apache::loncommon::syllabuswrapper($showcourse,$cnum,$cdom);                              &Apache::loncommon::syllabuswrapper($showcourse,$cnum,$cdom);
                           if ($codes{$cnum}) {
                               $syllabuslink .= &mt('Unique code: [_1]',$codes{$cnum});
                           }
                         $output .= '<li>'.$syllabuslink.'</li>';                          $output .= '<li>'.$syllabuslink.'</li>';
                     }                      }
                     $output .= '</ul></p>';                      $output .= '</ul></p>';
Line 1073  sub update_request_queue { Line 1128  sub update_request_queue {
             }              }
             $output .= '</ul></p>';              $output .= '</ul></p>';
         } elsif ($context eq 'requestauthor') {          } elsif ($context eq 'requestauthor') {
             $output .= '<p>'.&mt('Authoring space requests from the following users were deleted because one already exists:').'<ul>';              $output .= '<p>'.&mt('Authoring Space requests from the following users were deleted because one already exists:').'<ul>';
             foreach my $uname (@existing) {              foreach my $uname (@existing) {
                 my $userlink =                  my $userlink =
                     &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);                      &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
Line 1126  sub update_request_queue { Line 1181  sub update_request_queue {
             }              }
             $output .= '</ul></p>';              $output .= '</ul></p>';
         } elsif ($context eq 'requestauthor') {          } elsif ($context eq 'requestauthor') {
             $output .= '<p>'.&mt('The following authoring space requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>';              $output .= '<p>'.&mt('The following Authoring Space requests were deleted because the requestor does not have a LON-CAPA account:').'<ul>';
             foreach my $uname (@invalidusers) {              foreach my $uname (@invalidusers) {
                 my $userlink =                  my $userlink =
                     &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);                      &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
Line 1158  sub update_request_queue { Line 1213  sub update_request_queue {
             }              }
             $output .= '</ul></p>';              $output .= '</ul></p>';
         } elsif ($context eq 'requestauthor') {          } elsif ($context eq 'requestauthor') {
             $output .= '<p>'.&mt('The following requests could not be processed because the requestor does not have rights to request an authoring space:').'<ul>';              $output .= '<p>'.&mt('The following requests could not be processed because the requestor does not have rights to request an Authoring Space:').'<ul>';
             foreach my $uname (@nopermissions) {              foreach my $uname (@nopermissions) {
                 my $userlink =                  my $userlink =
                     &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);                      &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$cdom),$uname,$cdom);
Line 1248  sub update_request_queue { Line 1303  sub update_request_queue {
             }              }
             $output .= '</ul></p>';              $output .= '</ul></p>';
         } else {          } else {
             $output .= '<p>'.&mt("For the following course/community requests an error occurred when removing requests for the following from the pending queue:").'<ul>';              $output .= '<p>'.&mt("For the following course/community requests an error occurred when removing requests from the pending queue:").'<ul>';
             foreach my $cnum (@warn_dels) {              foreach my $cnum (@warn_dels) {
                 my $showcourse;                  my $showcourse;
                 if (ref($requesthash{$cnum.'_'.$queue})) {                  if (ref($requesthash{$cnum.'_'.$queue})) {
Line 1300  sub get_student_counts { Line 1355  sub get_student_counts {
   
 sub course_creation {  sub course_creation {
     my ($dom,$cnum,$context,$details,$logmsg,$newusermsg,$addresult,$enrollcount,$output,      my ($dom,$cnum,$context,$details,$logmsg,$newusermsg,$addresult,$enrollcount,$output,
         $keysmsg,$domdefs,$longroles) =  @_;          $keysmsg,$domdefs,$longroles,$coderef,$customhash) =  @_;
     unless ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH') &&       unless ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH') && 
             (ref($longroles) eq 'HASH')) {              (ref($longroles) eq 'HASH')) {
         return 'error: Invalid request';          return 'error: Invalid request';
     }      }
     my ($result,$ownername,$ownerdom);      my ($result,$ownername,$ownerdom);
     my $crstype = $details->{'crstype'};      my $crstype = $details->{'crstype'};
       my $coursedesc = $details->{'cdescr'};
       my %domconfig = &Apache::lonnet::get_dom('configuration',['requestauthor'],$dom);
       if (ref($domconfig{'requestcourses'}) eq 'HASH') {
           if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
               if ($domconfig{'requestcourses'}{'uniquecode'}{$crstype}) {
                   $details->{'uniquecode'} = 1;
               }
           }
       }
     if ($context eq 'domain') {      if ($context eq 'domain') {
         $ownername = $details->{'owner'};          $ownername = $details->{'owner'};
         $ownerdom  = $details->{'domain'};          $ownerdom  = $details->{'domain'};
Line 1314  sub course_creation { Line 1378  sub course_creation {
         $ownername = $env{'user.name'};          $ownername = $env{'user.name'};
         $ownerdom  = $env{'user.domain'};          $ownerdom  = $env{'user.domain'};
     }      }
       my $fullname = &Apache::loncommon::plainname($ownername,$ownerdom);
     my $owneremail;      my $owneremail;
     my %emails = &Apache::loncommon::getemails($ownername,$ownerdom);      my %emails = &Apache::loncommon::getemails($ownername,$ownerdom);
     foreach my $email ('permanentemail','critnotification','notification') {      foreach my $email ('permanentemail','critnotification','notification') {
Line 1323  sub course_creation { Line 1388  sub course_creation {
     my %reqdetails = &build_batchcreatehash($dom,$context,$details,$owneremail,$domdefs);      my %reqdetails = &build_batchcreatehash($dom,$context,$details,$owneremail,$domdefs);
     my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses',      my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses',
                   \%reqdetails,$longroles,$logmsg,$newusermsg,$addresult,                    \%reqdetails,$longroles,$logmsg,$newusermsg,$addresult,
                   $enrollcount,$output,$keysmsg,$ownerdom,$ownername,$cnum,$crstype);                    $enrollcount,$output,$keysmsg,$ownerdom,$ownername,$cnum,$crstype,$coderef);
       my $postprocess;
     if ($cid eq "/$dom/$cnum") {      if ($cid eq "/$dom/$cnum") {
         $result = 'created';          $result = 'created';
           my $code;
           if (ref($coderef)) {
               $code = $$coderef;
           }
           $postprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,$result,$ownername,
                                                              $ownerdom,$fullname,$coursedesc,$code,$customhash);
     } else {      } else {
         $result = 'error: '.$cid;          $result = 'error: '.$cid;
     }      }
     return $result;      return ($result,$postprocess);
 }  }
   
 sub build_batchcreatehash {  sub build_batchcreatehash {
     my ($dom,$context,$details,$owneremail,$domdefs) = @_;      my ($dom,$context,$details,$owneremail,$domdefs) = @_;
     my %batchhash;      my %batchhash;
     my @items = qw{owner domain coursehome clonecrs clonedom datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users};      my @items = qw{owner domain coursehome clonecrs clonedom datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users uniquecode};
     if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) {      if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) {
         my $emailenc = &escape($owneremail);          my $emailenc = &escape($owneremail);
         my $owner = $details->{'owner'}.':'.$details->{'domain'};          my $owner = $details->{'owner'}.':'.$details->{'domain'};
Line 1344  sub build_batchcreatehash { Line 1416  sub build_batchcreatehash {
         }          }
         $batchhash{'title'} = $details->{'cdescr'};          $batchhash{'title'} = $details->{'cdescr'};
         $batchhash{'coursecode'} = $details->{'instcode'};          $batchhash{'coursecode'} = $details->{'instcode'};
           if ($domdefs->{'officialcredits'} || $domdefs->{'unofficialcredits'}) {
               $batchhash{'defaultcredits'} = $details->{'defaultcredits'};
           }
         $batchhash{'emailenc'} = $emailenc;          $batchhash{'emailenc'} = $emailenc;
         $batchhash{'adds'} = $details->{'autoadds'};          $batchhash{'adds'} = $details->{'autoadds'};
         $batchhash{'drops'} = $details->{'autodrops'};          $batchhash{'drops'} = $details->{'autodrops'};
Line 1352  sub build_batchcreatehash { Line 1427  sub build_batchcreatehash {
         if ($details->{'crstype'} eq 'community') {          if ($details->{'crstype'} eq 'community') {
             $batchhash{'crstype'} = 'Community';              $batchhash{'crstype'} = 'Community';
         } else {          } else {
               if ($details->{'crstype'} eq 'textbook') {
                   if ($details->{'clonecrs'} && $details->{'clonedom'}) {
                       my %clonedfrom = &Apache::lonnet::coursedescription($details->{'clonedom'}.'_'.$details->{'clonecrs'});
                       $batchhash{'textbook'} = $clonedfrom{'description'};
                   }
               }
             $batchhash{'crstype'} = 'Course';              $batchhash{'crstype'} = 'Course';
         }          }
         my ($owner_firstname,$owner_lastname);          my ($owner_firstname,$owner_lastname);
Line 1462  sub get_processtype { Line 1543  sub get_processtype {
         } else {          } else {
             my %alltasks;              my %alltasks;
             if (($isadv) && ($settings{'_LC_adv'} ne '')) {              if (($isadv) && ($settings{'_LC_adv'} ne '')) {
                 $val = $settings{$crstype}{'_LC_adv'};                  $val = $settings{'_LC_adv'};
                 @{$inststatuses} = ('_LC_adv_');                  @{$inststatuses} = ('_LC_adv_');
             } else {              } else {
                 if ($userenv{'inststatus'} ne '') {                  if ($userenv{'inststatus'} ne '') {
Line 1548  sub queued_selfenrollment { Line 1629  sub queued_selfenrollment {
     }      }
     if (keys(%reqs_by_date)) {      if (keys(%reqs_by_date)) {
         unless ($notitle) {          unless ($notitle) {
             $output .= '<b>'.&mt('Enrollment requests pending Course Coordinator approval').'</b><br />';              $output .= '<br /><b>'.&mt('Enrollment requests pending Course Coordinator approval').'</b><br />';
         }          }
         $output .= &Apache::loncommon::start_data_table().          $output .= &Apache::loncommon::start_data_table().
                    &Apache::loncommon::start_data_table_header_row().                     &Apache::loncommon::start_data_table_header_row().
Line 1688  sub process_official_reqs { Line 1769  sub process_official_reqs {
                 }                  }
                 $reqstatus = $disposition;                  $reqstatus = $disposition;
                 if ($disposition eq 'process') {                  if ($disposition eq 'process') {
                     my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg);                      my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,$code);
                     my $result = &course_creation($dom,$cnum,'domain',$history{'details'},\$logmsg,\$newusermsg,\$addresult,\$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);                      my %customitems;
                       my $fullname = &Apache::loncommon::plainname($ownername,$ownerdom);
                       my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'process',$ownername,
                                                                           $ownerdom,$fullname,$cdescr);
                       if (ref($inprocess) eq 'HASH') {
                           foreach my $key (keys(%{$inprocess})) {
                               if (exists($history{'details'}{$key})) {
                                   $customitems{$key} = $history{'details'}{$key};
                               }
                           }
                       }
                       my ($result,$postprocess) = 
                           &course_creation($dom,$cnum,'domain',$history{'details'},\$logmsg,\$newusermsg,\$addresult,
                                            \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,\$code,\%customitems);
                     if ($result eq 'created') {                      if ($result eq 'created') {
                         $disposition = 'created';                          $disposition = 'created';
                         $reqstatus = 'created';                          $reqstatus = 'created';
Line 1713  sub process_official_reqs { Line 1807  sub process_official_reqs {
                                     mt => 'If currently logged-in to LON-CAPA, log-out and log-in again to select your new course role.'                                      mt => 'If currently logged-in to LON-CAPA, log-out and log-in again to select your new course role.'
                                  }];                                   }];
                             my $sender = $dcname.':'.$dcdom;                              my $sender = $dcname.':'.$dcdom;
                               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(@{$approvedmsg},$item);
                                                }
                                           }
                                       }
                                   }
                               }
                             &send_selfserve_notification($owner,$approvedmsg,                              &send_selfserve_notification($owner,$approvedmsg,
                                                          $cid,$cdescr,$now,                                                           $cid,$cdescr,$now,
                                                          $beneficiary,$sender,                                                           $beneficiary,$sender,
Line 1781  sub process_official_reqs { Line 1886  sub process_official_reqs {
         }          }
     }      }
     return $output;      return $output;
   }
   
   sub is_active_author {
       if ($env{'user.role.au./'.$env{'user.domain'}.'/'} =~ /^(\d*)\.(\d*)$/) {
           if ((!$1 || $1 < time) &&
               (!$2 || $2 > time)) {
               return 1;
           }
       }
   }
   
   sub author_prompt {
       my ($is_active_author,$offer_author);
       if ($env{'environment.canrequest.author'}) {
           unless (&is_active_author()) {
               unless (&reqauthor_check() =~ /^approval:\d+$/) {
                   $offer_author = 1;
               }
           }
       }
       return $offer_author;
   }
   
   sub reqauthor_check {
       my $queued = $env{'environment.requestauthorqueued'};
       my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
                                            $env{'user.domain'},$env{'user.name'});
       my $reqstatus = $reqauthor{'author_status'};
       if (($reqstatus eq '' && $queued ne '') ||
           ($env{'environment.requestauthorqueued'} !~ /^\Q$reqstatus\E/)) {
           if (ref($reqauthor{'author'}) eq 'HASH') {
               $queued = $reqstatus.':'.$reqauthor{'author'}{'timestamp'};
           } else {
               undef($queued);
           }
           &Apache::lonnet::appenv({'environment.requestauthorqueued' => $queued});
       }
       return $queued;
   }
   
   sub process_reqauthor {
       my ($dispositionref,$updateref) = @_;
       if (&is_active_author()) {
           return '<span class="LC_warning">'.
                   &mt('An Authoring Space has already been assigned to you.').'<br />'.
                   &mt('Please select the Author role from your [_1]roles page[_2].','<a href="/adm/roles">',
                   '</a>').'</span>';
       }
       unless ($env{'environment.canrequest.author'}) {
           return '<span class="LC_warning">'.
                   &mt('You do not currently have rights to request an Authoring Space.').'<br />'.
                   &mt('Please contact the [_1]helpdesk[_2] for assistance.','<a href="/adm/helpdesk">',
                   '</a>').'</span>';
       }
       my $queued = &reqauthor_check();
       if ($queued =~ /^approval:(\d+)$/) {
           my $timestamp = $1;
           return '<span class="LC_info">'.
                  &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
                  &Apache::lonlocal::locallocaltime($timestamp)).
                  '</span>';
       } elsif ($queued =~ /^approved:(\d+)$/) {
           my $timestamp = $1;   
           my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
                                                         ['active'],['au'],[$env{'user.domain'}]);
           if (keys(%roleshash) > 0) {
               return '<span class="LC_info">'.
                      &mt('A request for Authoring Space submitted on [_1] has been approved.',
                      &Apache::lonlocal::locallocaltime($timestamp)).
                      '</span>';
           }
       }
       my ($output,@inststatuses,%domconfig);
       %domconfig = &Apache::lonnet::get_dom('configuration',['requestauthor'],
                                             $env{'user.domain'});
       my $val = &get_processtype('requestauthor',$env{'user.name'},$env{'user.domain'},
                                  $env{'user.adv'},$env{'user.domain'},undef,
                                  \@inststatuses,\%domconfig);
       my $now = time;
       if ($val eq 'automatic') {
           my $start = $now-1;
           if (&Apache::lonnet::assignrole($env{'user.domain'},$env{'user.name'},'/'.$env{'user.domain'}.'/',
                                           'au',undef,$start,undef,undef,'requestauthor') eq 'ok') {
               $output = '<span class="LC_info">'.
                         &mt('Access to Authoring Space has been activated').'</span><br />';
                         &Apache::lonroles::update_session_roles();
               &Apache::lonnet::appenv({'user.update.time'  => $now});
               if (ref($updateref)) {
                   $$updateref = $now;
               }
               if (ref($dispositionref)) {
                   $$dispositionref = 'created';
               }
           } else {
               $output = '<span class="LC_info">'.
                         &mt('An error occurred while activating your access to Authoring Space');
           }
       } elsif ($val eq 'approval') {
           my $domconfiguser = &Apache::lonnet::get_domainconfiguser($env{'user.domain'});
           if (&Apache::lonnet::put('requestauthorqueue',{ $env{'user.name'}.'_'.$val => $now },
                                    $env{'user.domain'},$domconfiguser) eq 'ok') {
               my %userrequest = (
                   author => {
                               timestamp   => $now,
                               status      => $val,
                             },
                   author_status => $val,
               );
               my $req_notifylist;
               if (ref($domconfig{'requestauthor'}) eq 'HASH') {
                   if (ref($domconfig{'requestauthor'}{'notify'}) eq 'HASH') {
                       my $req_notifylist = $domconfig{'requestauthor'}{'notify'}{'approval'};
                       if ($req_notifylist) {
                           my $fullname = &Apache::loncommon::plainname($env{'user.name'},
                                                                        $env{'user.domain'});
                           my $sender = $env{'user.name'}.':'.$env{'user.domain'};
                           my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
                           &send_selfserve_notification($req_notifylist,
                                                        "$fullname ($env{'user.name'}:$env{'user.domain'})",
                                                        undef,$domdesc,$now,'authorreq',$sender);
                       }
                   }
               }
               my $userresult =
                   &Apache::lonnet::put('requestauthor',\%userrequest,$env{'user.domain'},$env{'user.name'});
               $output = '<span class="LC_info">'.
                         &mt('Your request for Authoring Space has been submitted for approval.').
                         '</span>';
               &Apache::lonnet::appenv({'environment.requestauthorqueued' => $val.':'.$now});
           } else {
               $output = '<span class="LC_info">'.
                         &mt('An error occurred saving your request for Authoring Space.').
                         '</span>';
           }
       }
       return $output;
 }  }
   
 1;  1;

Removed from v.1.30  
changed lines
  Added in v.1.42


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>