--- loncom/interface/lonrequestcourse.pm 2010/03/16 22:40:12 1.47 +++ loncom/interface/lonrequestcourse.pm 2010/03/19 13:23:05 1.48 @@ -1,7 +1,7 @@ # The LearningOnline Network # Request a course # -# $Id: lonrequestcourse.pm,v 1.47 2010/03/16 22:40:12 raeburn Exp $ +# $Id: lonrequestcourse.pm,v 1.48 2010/03/19 13:23:05 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -138,7 +138,7 @@ sub handler { $states{'display'} = ['details']; $states{'view'} = ['pick_request','details','cancel','removal']; - $states{'log'} = ['filter','display']; + $states{'log'} = ['display']; $states{'new'} = ['courseinfo','enrollment','personnel','review','process']; if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) { @@ -166,6 +166,7 @@ sub handler { details => 'Request Details', cancel => 'Cancel Request', removal => 'Outcome', + display => 'Request Logs', ); if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) { @@ -325,7 +326,24 @@ sub handler { $loaditems,$crumb,'','','','','',$uname,$udom); } } elsif ($action eq 'log') { - &print_request_logs($jscript,$loaditems,$crumb); + if ($state eq 'crstype') { + &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains); + } else { + $jscript .= <print('

'.$title.'

'."\n".$form."\n". - &print_request_status($dom).'
'); + &print_request_status($dom,$action).''); } elsif ($state eq 'details') { my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk); my $origcnum = $env{'form.cnum'}; @@ -1016,8 +1034,6 @@ END &print_review($dom,\@codetitles,\%cat_titles,\%cat_order, \@code_order,$uname,$udom)."\n".''. &close_popup_form()); - } elsif ($action eq 'log') { - $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb); } $r->print(&Apache::loncommon::end_page()); return; @@ -1844,51 +1860,80 @@ sub current_lc_sections { return @currsecs; } -sub print_request_status { - my ($dom) = @_; +sub sorted_request_history { + my ($dom,$action,$after,$before) = @_; my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'}, $env{'user.name'},'^status:'.$dom); - my ($output,$formname,%queue_by_date); + my %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'}; + if ($action eq 'view') { + next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')); + } else { + next unless (($env{'form.status'} eq 'any') || + ($env{'form.status'} eq $statusinfo{$key})); + } + (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 $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 unless (($env{'form.crstype'} eq 'any') || - ($env{'form.crstype'} eq $crstype)); + } else { + 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') || ($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 (ref($history{'details'}) eq 'HASH') { + $entry = $requestkey.':'.$crstype.':'. + &escape($history{'details'}{'cdescr'}); + 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 (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); + if ($crstype eq 'official') { + $entry .= ':'.&escape($history{'details'}{'instcode'}); + } + } + if ($entry ne '') { + if (exists($queue_by_date{$reqtime})) { + 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)); - $output = ''."\n". + my $formname = 'requestcrs'; + my ($types,$typenames) = &Apache::loncommon::course_types(); + my $output = ''."\n". ''."\n". ''."\n". @@ -2068,9 +2113,292 @@ ENDJS } 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('
'."\n". + ''."\n". + ''."\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(''. + &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(). + ' '.&mt('Request Date').''. + ''.&mt('Description').''; + if ($curr{'crstype'} eq 'any') { + $tablehdr .= ''.&mt('Course Type').''; + } + if (($curr{'crstype'} eq 'official') || ($curr{'crstype'} eq 'any')) { + $tablehdr .= ''.&mt('Institutional Code').''; + } + if ($curr{'status'} eq 'any') { + $tablehdr .= ''.&mt('Status').''; + } elsif ($curr{'status'} eq 'created') { + $tablehdr .= ''.&mt('Creation Date').''; + } elsif ($curr{'status'} eq 'cancelled') { + $tablehdr .= ''.&mt('Cancellation Date').''; + } elsif ($curr{'status'} eq 'rejected') { + $tablehdr .= ''.&mt('Rejection Date').''; + } + $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(). + ''.$count.''. + ''.$showtime.''. + ''.&unescape($desc).''; + if ($curr{'crstype'} eq 'any') { + my $typename; + if (ref($typenames) eq 'HASH') { + $typename = &mt($typenames->{$crstype}); + } + if ($typename eq '') { + $typename = &mt('Unknown type'); + } + $output .= ''.$typename.''; + } + if (($curr{'crstype'} eq 'any') || + ($curr{'crstype'} eq 'official')) { + my $showinstcode; + if ($crstype eq 'official') { + $showinstcode = &unescape($instcode); + } else { + $showinstcode = &mt('Not applicable'); + } + $output .= ''.$showinstcode.''; + } + 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 .= ''.$statusname.''; + } elsif (($status eq 'created') || ($status eq 'cancelled') || + ($status eq 'rejected')) { + $output .= ''.&Apache::lonlocal::locallocaltime($timestamp).''; + } + $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(''); + if ($curr{'page'} > 1) { + $r->print(''); + } + if ($more_records) { + $r->print(''); + } + $r->print('
'.&mt('Previous [_1] changes',$curr{'show'}).''.&mt('Next [_1] changes',$curr{'show'}).'
'); + $r->print(<<"ENDSCRIPT"); + +ENDSCRIPT + } + } else { + $norecords = 1; + } + } else { + $norecords = 1; + } + if ($norecords) { + $r->print('

'. + &mt('There are no records to display'). + '

'); + } + $r->print('
'. + &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 = ''; + 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 .= ''. + ''; + my ($types,$typenames) = &Apache::loncommon::course_types(); + if (ref($types) eq 'ARRAY') { + if (@{$types} > 1) { + $output .= ''; + } + } + my ($statuses,$statusnames) = &reqstatus_names($curr->{'crstype'}); + if (ref($statuses) eq 'ARRAY') { + if (@{$statuses} > 1) { + $output .= ''; + } + } + $output .= '
'. + ''.&mt('Records/page:').'
'. + &Apache::lonmeta::selectbox('show',$curr->{'show'},undef, + (&mt('all'),5,10,20,50,100,1000,10000)). + '
  '.&mt('Window during which course/community was requested:').'
'. + ''. + ''. + '
'.&mt('After:'). + ''.$startform.'
'.&mt('Before:').''.$endform.'
'. + '
  '. + &mt('Course Type:').'
'. + &mt('Request Status:').'
'; + + # Update Display button + $output .= '

'. + ''. + '


'; + return $output; +} sub print_review { my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,