[LON-CAPA-cvs] cvs: loncom /interface lonpickcourse.pm

raeburn raeburn@source.lon-capa.org
Tue, 16 Mar 2010 05:11:40 -0000


raeburn		Tue Mar 16 05:11:40 2010 EDT

  Modified files:              
    /loncom/interface	lonpickcourse.pm 
  Log:
  - Bug 6175.
    - Course created filter available to DCs - today, last week, last month etc.
      for domains responding to lonnet::get_server_loncaparev(), 
      i.e., 2.9 or later (also have creation date in nohist_courseids.db).
    - selector for activity and creation date from new routine:
      &timebased_select_form().
  
  
Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.93 loncom/interface/lonpickcourse.pm:1.94
--- loncom/interface/lonpickcourse.pm:1.93	Mon Mar  8 14:43:46 2010
+++ loncom/interface/lonpickcourse.pm	Tue Mar 16 05:11:40 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Pick a course
 #
-# $Id: lonpickcourse.pm,v 1.93 2010/03/08 14:43:46 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.94 2010/03/16 05:11:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -142,8 +142,16 @@
     my $action = '/adm/pickcourse';
     my ($numtitles,$showroles,$nohost);
     if (!$onlyown) {
-        my $filterlist = ['domainfilter','descriptfilter',
-                          'instcodefilter'];
+        my $filterlist = ['domainfilter'];
+        # created filter for DCs only
+        if ($env{'user.adv'} && $env{'form.domainfilter'} &&
+            exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
+            my $loncaparev = &Apache::lonnet::get_server_loncaparev($env{'form.domainfilter'});
+            if ($loncaparev ne 'unknown_cmd') {
+                push(@{$filterlist},'createdfilter');
+            }
+        }
+        push(@{$filterlist},('descriptfilter','instcodefilter'));
         if ($env{'form.form'} eq 'rules') {
             push(@{$filterlist},'personfilter');
             if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) {
@@ -531,8 +539,9 @@
     unless ($env{'form.interface'} eq 'textual') {
         $onchange = 'javascript:updateFilters(this)';
     }
-    my ($domainselectform,$sincefilterform,$ownerdomselectform,$persondomselectform,
-        $instcodeform,$typeselectform,$instcodetitle);
+    my ($domainselectform,$sincefilterform,$createdfilterform,
+        $ownerdomselectform,$persondomselectform,$instcodeform,
+        $typeselectform,$instcodetitle);
     foreach my $item (@{$filterlist}) {
         $filter->{$item} = $env{'form.'.$item};
         if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
@@ -595,25 +604,16 @@
     }
 
     # last course activity filter and selection
-    $filter->{'sincefilter'} = $env{'form.sincefilter'};
-    $filter->{'sincefilter'} =~ s/[^\d-]//g;
-    if (!$filter->{'sincefilter'}) { $filter->{'sincefilter'}=-1; }
-    $sincefilterform=&Apache::loncommon::select_form(
-        $filter->{'sincefilter'},
-        'sincefilter',
-        (      '-1' => '',
-            '86400' => &mt('today'),
-           '604800' => &mt('last week'),
-          '2592000' => &mt('last month'),
-          '7776000' => &mt('last three months'),
-         '15552000' => &mt('last six months'),
-         '31104000' => &mt('last year'),
-         'select_form_order' =>
-            ['-1','86400','604800','2592000','7776000',
-             '15552000','31104000']));
+    $sincefilterform = &timebased_select_form('sincefilter',$filter);
+
+    # course created filter and selection
+    if (exists($filter->{'createdfilter'})) {
+        $createdfilterform = &timebased_select_form('createdfilter',$filter);
+    }
 
     my %lt = &Apache::lonlocal::texthash(
                 'cac' => "$type Activity",
+                'ccr' => "$type Created", 
                 'cde' => "$type Title",
                 'cdo' => "$type Domain",
                 'ins' => 'Institutional Code',
@@ -719,6 +719,11 @@
                   .$sincefilterform
                   .&Apache::lonhtmlcommon::row_closure();
     }
+    if ($createdfilterform) {
+        $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
+                  .$createdfilterform
+                  .&Apache::lonhtmlcommon::row_closure();
+    }
     if ($domainselectform) {
         $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
                   .$domainselectform
@@ -788,6 +793,28 @@
     return $jscript.$warning.$output;
 }
 
+sub timebased_select_form {
+    my ($item,$filter) = @_;
+    if (ref($filter) eq 'HASH') {
+        $filter->{$item} = $env{'form.'.$item};
+        $filter->{$item} =~ s/[^\d-]//g;
+        if (!$filter->{$item}) { $filter->{$item}=-1; }
+        return &Apache::loncommon::select_form( 
+                            $filter->{$item},
+                            $item,
+                            (      '-1' => '',
+                                '86400' => &mt('today'),
+                               '604800' => &mt('last week'),
+                              '2592000' => &mt('last month'),
+                              '7776000' => &mt('last three months'),
+                             '15552000' => &mt('last six months'),
+                             '31104000' => &mt('last year'),
+                    'select_form_order' =>
+                           ['-1','86400','604800','2592000','7776000',
+                            '15552000','31104000']));
+    }
+}
+
 sub get_coordinator_cloneable {
     my ($cloneruname,$clonerudom,$type) = @_;
     if (&Apache::lonnet::homeserver($cloneruname,$clonerudom) eq 'no_host') {
@@ -860,8 +887,14 @@
                 $filter->{$item}='.';
             }
         }
+        my $now = time;
         my $timefilter = 
-           ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
+           ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
+        my ($createdbefore,$createdafter);
+        if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
+            $createdbefore = $now;
+            $createdafter = $now-$filter->{'createdfilter'};
+        }
         my ($instcodefilter,$regexpok);
         if ($numtitles) {
             if ($env{'form.official'} eq 'on') {
@@ -892,7 +925,8 @@
                                           $filter->{'coursefilter'},
                                           undef,undef,$type,$regexpok,undef,undef,
                                           undef,undef,$cloner,$env{'form.cc_clone'},
-                                          $filter->{'cloneableonly'});
+                                          $filter->{'cloneableonly'},
+                                          $createdbefore,$createdafter);
         if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
             my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
                                                          $filter->{'persondomfilter'},