Diff for /loncom/interface/lonrequestcourse.pm between versions 1.47 and 1.48

version 1.47, 2010/03/16 22:40:12 version 1.48, 2010/03/19 13:23:05
Line 138  sub handler { Line 138  sub handler {
   
     $states{'display'} = ['details'];      $states{'display'} = ['details'];
     $states{'view'} = ['pick_request','details','cancel','removal'];      $states{'view'} = ['pick_request','details','cancel','removal'];
     $states{'log'} = ['filter','display'];      $states{'log'} = ['display'];
     $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];      $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
   
     if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {      if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
Line 166  sub handler { Line 166  sub handler {
                  details       => 'Request Details',                   details       => 'Request Details',
                  cancel        => 'Cancel Request',                   cancel        => 'Cancel Request',
                  removal       => 'Outcome',                   removal       => 'Outcome',
                    display       => 'Request Logs',
                 );                  );
   
     if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {      if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
Line 325  sub handler { Line 326  sub handler {
                                     $loaditems,$crumb,'','','','','',$uname,$udom);                                      $loaditems,$crumb,'','','','','',$uname,$udom);
         }          }
     } elsif ($action eq 'log') {      } elsif ($action eq 'log') {
         &print_request_logs($jscript,$loaditems,$crumb);          if ($state eq 'crstype') {
               &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains);
           } else {
               $jscript .= <<ENDJS;
   
   function backPage(formname,prevstate) {
       formname.state.value = prevstate;
       formname.submit();
   }
   
   function setPage(formname) {
       formname.page.value = '1';
       return;
   }
   
   ENDJS
               &print_request_logs($r,$dom,$jscript,$loaditems,$crumb);
           }
     } else {      } else {
         &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains);          &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains);
     }      }
Line 894  END Line 912  END
                 $title = &mt('Pending course/community requests');                   $title = &mt('Pending course/community requests'); 
             }              }
             $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".              $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
                       &print_request_status($dom).'</form></div>');                        &print_request_status($dom,$action).'</form></div>');
         } elsif ($state eq 'details') {          } elsif ($state eq 'details') {
             my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);              my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
             my $origcnum = $env{'form.cnum'};              my $origcnum = $env{'form.cnum'};
Line 1016  END Line 1034  END
                   &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,                    &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
                                 \@code_order,$uname,$udom)."\n".'</div>'.                                  \@code_order,$uname,$udom)."\n".'</div>'.
                   &close_popup_form());                    &close_popup_form());
     } elsif ($action eq 'log') {  
         $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);  
     }      }
     $r->print(&Apache::loncommon::end_page());      $r->print(&Apache::loncommon::end_page());
     return;      return;
Line 1844  sub current_lc_sections { Line 1860  sub current_lc_sections {
     return @currsecs;      return @currsecs;
 }  }
   
 sub print_request_status {  sub sorted_request_history {
     my ($dom) = @_;      my ($dom,$action,$after,$before) = @_;
     my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},      my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
                                            $env{'user.name'},'^status:'.$dom);                                             $env{'user.name'},'^status:'.$dom);
     my ($output,$formname,%queue_by_date);      my %queue_by_date;
     my ($types,$typenames) = &Apache::loncommon::course_types();      my ($types,$typenames) = &Apache::loncommon::course_types();
     foreach my $key (keys(%statusinfo)) {      foreach my $key (keys(%statusinfo)) {
         if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) {           if ($action eq 'view') {
             (undef,my($cdom,$cnum)) = split(':',$key);              next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
             next if ($cdom ne $dom);             } else {
             my $requestkey = $cdom.'_'.$cnum;              next unless (($env{'form.status'} eq 'any') ||
             if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {                            ($env{'form.status'} eq $statusinfo{$key}));
                 my %history = &Apache::lonnet::restore($requestkey,'courserequests',          }
                                                        $env{'user.domain'},$env{'user.name'});          (undef,my($cdom,$cnum)) = split(':',$key);
                 my $entry;          next if ($cdom ne $dom);   
                 my $timestamp = $history{'reqtime'};          my $requestkey = $cdom.'_'.$cnum;
                 my $crstype = $history{'crstype'};          if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
                 my $disposition = $history{'disposition'};              my %history = &Apache::lonnet::restore($requestkey,'courserequests',
                                                      $env{'user.domain'},$env{'user.name'});
               my $entry;
               my $reqtime = $history{'reqtime'};
               my $lastupdate = $history{'timestamp'};
               my $crstype = $history{'crstype'};
               my $disposition = $history{'disposition'};
               my $status = $history{'status'};
               if ($action eq 'view') {
                 next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));                  next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
                 next unless (($env{'form.crstype'} eq 'any') ||               } else {
                             ($env{'form.crstype'} eq $crstype));                  next if (($reqtime < $after) || ($reqtime > $before));
               }
               next unless (($env{'form.crstype'} eq 'any') || 
                            ($env{'form.crstype'} eq $crstype));
               if ($action eq 'view') {
                 next unless (($disposition eq 'approval') ||                   next unless (($disposition eq 'approval') || 
                              ($disposition eq 'pending'));                               ($disposition eq 'pending'));
                 if (ref($history{'details'}) eq 'HASH') {              }
                     $entry = $requestkey.':'.$crstype.':'.              if (ref($history{'details'}) eq 'HASH') {
                              &escape($history{'details'}{'cdescr'});                  $entry = $requestkey.':'.$crstype.':'.
                     if ($crstype eq 'official') {                           &escape($history{'details'}{'cdescr'});
                         $entry .= ':'.&escape($history{'details'}{'instcode'});                   if ($action eq 'log') {
                       $entry .= ':'.$lastupdate.':';
                       if ($statusinfo{$key} ne '') {
                           $entry .= $statusinfo{$key};
                       } elsif ($status ne '') {
                           $entry .= $status;
                       } else {
                           $entry .= $disposition;
                     }                      }
                 }                  }
                 if ($entry ne '') {                  if ($crstype eq 'official') {
                     if (exists($queue_by_date{$timestamp})) {                      $entry .= ':'.&escape($history{'details'}{'instcode'}); 
                         if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {                  }
                             push(@{$queue_by_date{$timestamp}},$entry);              }
                         }              if ($entry ne '') {
                     } else {                  if (exists($queue_by_date{$reqtime})) {
                         @{$queue_by_date{$timestamp}} = ($entry);                      if (ref($queue_by_date{$reqtime}) eq 'ARRAY') {
                           push(@{$queue_by_date{$reqtime}},$entry);
                     }                      }
                   } else {
                       @{$queue_by_date{$reqtime}} = ($entry);
                 }                  }
             }              }
         }          }
     }      }
     $formname = 'requestcrs';      return %queue_by_date;
   }
   
   sub print_request_status {
       my ($dom,$action) = @_;
       my %queue_by_date = &sorted_request_history($dom,$action);
     my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));      my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
     $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".      my $formname = 'requestcrs';
       my ($types,$typenames) = &Apache::loncommon::course_types();
       my $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
   
               '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".                '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
               '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".                '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
Line 2068  ENDJS Line 2113  ENDJS
 }  }
   
 sub print_request_logs {  sub print_request_logs {
     my ($jscript,$loaditems,$crumb) = @_;      my ($r,$dom,$jscript,$loaditems,$crumb) = @_;
       my $title;
       if ($env{'form.crstype'} eq 'community') {
           $title = 'Community Request Logs';
       } elsif ($env{'form.crstype'} eq 'any') {
           $title = 'Course/Community Request Logs';
       } else {
           $title = 'Course Request Logs';
       }
       $r->print(&header($title,$jscript,$loaditems).$crumb);
       my $formname = 'requestcrs';
       $r->print('<form action="/adm/requestcourse" method="post" name="'.$formname.'" onsubmit="javascript:setPage(this);">'."\n".
                 '<input type="hidden" name="action" value="log" />'."\n".
                 '<input type="hidden" name="state" value="display" />'."\n");
       # set defaults
       my $now = time();
       my $defstart = $now - (7*24*3600); #7 days ago
       my %defaults = (
                        page                => '1',
                        show                => '10',
                        crstype             => 'any',
                        status              => 'any',
                        requested_before_date => $now,
                        requested_after_date  => $defstart,
                      );
       my ($types,$typenames) = &Apache::loncommon::course_types();
       my $more_records = 0;
       my %curr;
       foreach my $item ('show','page','crstype','status') {
           $curr{$item} = $env{'form.'.$item};
       }
       $curr{'requested_after_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_after_date');
       $curr{'requested_before_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_before_date');
       foreach my $key (keys(%defaults)) {
           if ($curr{$key} eq '') {
               $curr{$key} = $defaults{$key};
           }
       }
       my ($statuses,$statusnames) = &reqstatus_names($curr{'crstype'});
       $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
                 &requestlog_display_filter($formname,\%curr));
       my %queue_by_date = &sorted_request_history($dom,$env{'form.action'},
                                                   $curr{'requested_after_date'},
                                                   $curr{'requested_before_date'});
       my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
       my $showntablehdr = 0;
       my $tablehdr = &Apache::loncommon::start_data_table().
                      &Apache::loncommon::start_data_table_header_row().
                      '<th>&nbsp;</th><th>'.&mt('Request Date').'</th>'.
                      '<th>'.&mt('Description').'</th>';
       if ($curr{'crstype'} eq 'any') {
           $tablehdr .= '<th>'.&mt('Course Type').'</th>';
       }
       if (($curr{'crstype'} eq 'official') || ($curr{'crstype'} eq 'any')) {
           $tablehdr .= '<th>'.&mt('Institutional Code').'</th>';
       }
       if ($curr{'status'} eq 'any') {
           $tablehdr .= '<th>'.&mt('Status').'</th>';
       } elsif ($curr{'status'} eq 'created') {
           $tablehdr .= '<th>'.&mt('Creation Date').'</th>';
       } elsif ($curr{'status'} eq 'cancelled') {
           $tablehdr .= '<th>'.&mt('Cancellation Date').'</th>';
       } elsif ($curr{'status'} eq 'rejected') {
           $tablehdr .= '<th>'.&mt('Rejection Date').'</th>';
       }
       $tablehdr .= &Apache::loncommon::end_data_table_header_row();
       my ($minshown,$maxshown);
       $minshown = 1;
       my $count = 0;
       if ($curr{'show'} ne &mt('all')) {
           $maxshown = $curr{'page'} * $curr{'show'};
           if ($curr{'page'} > 1) {
               $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
           }
       }
       my $norecords;
       if (@sortedtimes > 0) {
           foreach my $item (@sortedtimes) {
               if ($curr{'show'} ne &mt('all')) {
                   if ($count >= $curr{'page'} * $curr{'show'}) {
                       $more_records = 1;
                       last;
                   }
               }
               $count ++;
               next if ($count < $minshown);
               if (!$showntablehdr) {
                   $r->print($tablehdr);
                   $showntablehdr = 1;
               }
               my $showtime = &Apache::lonlocal::locallocaltime($item);
               if (ref($queue_by_date{$item}) eq 'ARRAY') {
                   foreach my $request (sort(@{$queue_by_date{$item}})) {
                       my ($key,$crstype,$desc,$timestamp,$status,$instcode) = split(':',$request);
                       my ($cdom,$cnum) = split('_',$key);
                       my $output = &Apache::loncommon::start_data_table_row().
        '<td>'.$count.'</td>'.
        '<td>'.$showtime.'</td>'.
        '<td>'.&unescape($desc).'</td>';
                       if ($curr{'crstype'} eq 'any') {
                           my $typename;
                           if (ref($typenames) eq 'HASH') {
                               $typename = &mt($typenames->{$crstype});
                           }
                           if ($typename eq '') {
                               $typename = &mt('Unknown type');
                           }
                           $output .= '<td>'.$typename.'</td>';
                       }
                       if (($curr{'crstype'} eq 'any') ||
                           ($curr{'crstype'} eq 'official')) {
                           my $showinstcode;
                           if ($crstype eq 'official') {
                               $showinstcode = &unescape($instcode);
                           } else {
                               $showinstcode = &mt('Not applicable');
                           }
                           $output .= '<td>'.$showinstcode.'</td>';
                       }
                       if ($curr{'status'} eq 'any') {
                           my $statusname = &mt('Unknown status');
                           if (ref($statusnames) eq 'HASH') {
                               if ($statusnames->{$status} ne '') {
                                   $statusname = $statusnames->{$status};
                               }
                           }
                           if (($status eq 'created') || ($status eq 'cancelled') ||
                               ($status eq 'rejected')) {
                               $statusname .= ' '.&Apache::lonlocal::locallocaltime($timestamp);
                           }
                           $output .= '<td>'.$statusname.'</td>';
                       } elsif (($status eq 'created') || ($status eq 'cancelled') ||
                                ($status eq 'rejected')) {
                            $output .= '<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>';
                       }
                       $output .= &Apache::loncommon::end_data_table_row();
                       $r->print($output);
                   }
               }
           }
           if ($showntablehdr) {  
               $r->print(&Apache::loncommon::end_data_table());
               if (($curr{'page'} > 1) || ($more_records)) {
                   $r->print('<table><tr>');
                   if ($curr{'page'} > 1) {
                       $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
                   }
                   if ($more_records) {
                       $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
                   }
                   $r->print('</tr></table>');
                   $r->print(<<"ENDSCRIPT");
   <script type="text/javascript">
   // <![CDATA[
   function chgPage(caller) {
       if (caller == 'previous') {
           document.$formname.page.value --;
       }
       if (caller == 'next') {
           document.$formname.page.value ++;
       }
       document.$formname.submit();
     return;      return;
 }  }
   // ]]>
   </script>
   ENDSCRIPT
               }
           } else {
               $norecords = 1;
           }
       } else {
           $norecords = 1;
       }
       if ($norecords) {
           $r->print('<p class="LC_info">'.
                     &mt('There are no records to display').
                     '</p>');
       }
       $r->print('</form>'.
                 &Apache::loncommon::end_page());
       return;
   }
   
   sub reqstatus_names {
       my ($crstype) = @_;
       my @statuses = qw(created approval pending rejected cancelled);
       my %statusnames =
               &Apache::lonlocal::texthash (
                           created   => 'Course/Community created',
                           approval  => 'Queued pending approval',
                           pending   => 'Queued pending validation',
                           rejected  => 'Request rejected',
                           cancelled => 'Request cancelled',
               );
       if (($crstype eq 'official') || ($crstype eq 'unofficial')) {
           $statusnames{'created'} = &mt('Course created');
       } elsif ($crstype eq 'community') {
           $statusnames{'created'} = &mt('Community created');
       }
       return (\@statuses,\%statusnames);
   }
   
   sub requestlog_display_filter {
       my ($formname,$curr) = @_;
       my $nolink = 1;
       my $output = '<table><tr><td valign="top">'.
                    '<span class="LC_nobreak"><b>'.&mt('Records/page:').'</b></span><br />'.
                    &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
                                                 (&mt('all'),5,10,20,50,100,1000,10000)).
                    '</td><td>&nbsp;&nbsp;</td>';
       my $startform =
           &Apache::lonhtmlcommon::date_setter($formname,'requested_after_date',
                                               $curr->{'requested_after_date'},undef,
                                               undef,undef,undef,undef,undef,undef,$nolink);
       my $endform =
           &Apache::lonhtmlcommon::date_setter($formname,'requested_before_date',
                                               $curr->{'requested_before_date'},undef,
                                               undef,undef,undef,undef,undef,undef,$nolink);
       $output .= '<td valign="top"><b>'.&mt('Window during which course/community was requested:').'</b><br />'.
                  '<table><tr><td>'.&mt('After:').
                  '</td><td>'.$startform.'</td></tr>'.
                  '<tr><td>'.&mt('Before:').'</td>'.
                  '<td>'.$endform.'</td></tr></table>'.
                  '</td>'.
                  '<td>&nbsp;&nbsp;</td>';
       my ($types,$typenames) = &Apache::loncommon::course_types();
       if (ref($types) eq 'ARRAY') {
           if (@{$types} > 1) {
               $output .= '<td valign="top"><b>'.
                          &mt('Course Type:').'</b><br /><select name="crstype">';
               my $selstr = '';
               if ($curr->{'crstype'} eq 'any') {
                   $selstr = ' selected="selected"';
               }
               $output .= '<option value="any"'.$selstr.'>'.&mt('All types').'</option>'."\n";
               foreach my $crstype (@{$types}) {
                   my $selstr = '';
                   if ($curr->{'crstype'} eq $crstype) {
                       $selstr = ' selected="selected"';
                   }
                   my $typename = $crstype;
                   if (ref($typenames) eq 'HASH') {
                       if ($typenames->{$crstype} ne '') {
                           $typename = $typenames->{$crstype};
                       }
                   }
                   $output .= '<option value="'.$crstype.'"'.$selstr.'>'.$typename.'</option>'."\n";
               }
               $output .= '</select></td>';
           }
       }
       my ($statuses,$statusnames) = &reqstatus_names($curr->{'crstype'});
       if (ref($statuses) eq 'ARRAY') {
           if (@{$statuses} > 1) {
               $output .= '<td valign="top"><b>'.
                          &mt('Request Status:').'</b><br /><select name="status">';
               my $selstr = '';
               if ($curr->{'status'} eq 'any') {
                   $selstr = ' selected="selected"';
               }
               $output .= '<option value="any"'.$selstr.'>'.&mt('Any status').'</option>'."\n";
               foreach my $status (@{$statuses}) {
                   my $selstr = '';
                   if ($curr->{'status'} eq $status) {
                       $selstr = ' selected="selected"';
                   }
                   my $statusname = $status;
                   if (ref($statusnames) eq 'HASH') {
                       if ($statusnames->{$status} ne '') {
                           $statusname = $statusnames->{$status};
                       }
                   }
                   $output .= '<option value="'.$status.'"'.$selstr.'>'.$statusname.'</option>'."\n";
               }
               $output .= '</select></td>';
           }
       }
       $output .= '</tr></table>';
   
       # Update Display button
       $output .= '<p>'.
                  '<input type="submit" value="'.&mt('Update Display').'" />'.
                  '</p><hr />';
       return $output;
   }
   
 sub print_review {  sub print_review {
     my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,      my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,

Removed from v.1.47  
changed lines
  Added in v.1.48


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