[LON-CAPA-cvs] cvs: loncom(GCI_3) /interface lonmenu.pm

raeburn raeburn@source.lon-capa.org
Sun, 05 Dec 2010 17:24:13 -0000


raeburn		Sun Dec  5 17:24:13 2010 EDT

  Modified files:              (Branch: GCI_3)
    /loncom/interface	lonmenu.pm 
  Log:
  - Customization for GCI_3.
    - Suport for multiple Concept Inventories.
  
  
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.309.2.21 loncom/interface/lonmenu.pm:1.309.2.22
--- loncom/interface/lonmenu.pm:1.309.2.21	Thu Dec  2 16:44:09 2010
+++ loncom/interface/lonmenu.pm	Sun Dec  5 17:24:13 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.309.2.21 2010/12/02 16:44:09 raeburn Exp $
+# $Id: lonmenu.pm,v 1.309.2.22 2010/12/05 17:24:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -166,12 +166,15 @@
     my $menu;
     my $custommenu = &Apache::loncommon::needs_gci_custom();
     my $numdc = &Apache::loncommon::check_for_gci_dc();
+    my %allnums = &Apache::loncommon::get_faculty_cnums();
     # each element of @primary contains following array:
     # (link url, icon path, alt text, link text, condition)
-    my $public;
+    my ($public,$faculty);
     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
         || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
         $public = 1;
+    } elsif (ref($allnums{$env{'user.domain'}}) eq 'HASH') {
+        $faculty = 1;
     }
     foreach my $menuitem (@primary_menu) {
         # evaluate conditions 
@@ -186,13 +189,13 @@
         next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
                 && !$public;                           # only visible to public
                                                        # users
-        next if    $$menuitem[4]        eq 'gci'
-                && (!$custommenu || $env{'request.role'} =~ m{^st\./gcitest/});
+        next if    $$menuitem[4]        eq 'ci'
+                && (!$custommenu || $env{'request.role'} =~ m{^st\./\w+citest/});
         next if    $$menuitem[4]        eq 'home'
-                && (($custommenu) || ($env{'user.domain'} eq 'gcitest') || 
-                    (($env{'user.domain'} eq 'gci') && !$numdc));
-        next if    $$menuitem[4]        eq 'gcitest'
-                && (($env{'user.domain'} eq 'gci') || ($env{'request.role'} eq 'cm'));
+                && (($custommenu) || ($env{'user.domain'} =~ /^\w+citest$/) || 
+                    ($faculty && !$numdc));
+        next if    $$menuitem[4]        eq 'citest'
+                && ($faculty || ($env{'request.role'} eq 'cm'));
         next if    $$menuitem[4]        eq 'roles'     # hide links which are
                 && $custommenu;                        # not visible when GCI
         next if    $$menuitem[4]        eq 'courses'   # tabbed interface in use
@@ -316,11 +319,20 @@
 }
 
 sub gci_secondary_menu {
-    my %courses = (
-        'review' => 'gci_9615072b469884921gcil1',
-        'submit' => 'gci_1H96711d710194bfegcil1',
-        'tutorial' => 'gci_5422913620b814c90gcil1',
-    );
+    my %courses;
+    my $inventory;
+    if ($env{'user.domain'} =~ /^(\w+ci)test$/) {
+        $inventory = $1;
+    } else {
+        $inventory = $env{'user.domain'};
+    }
+    my %allnums = &Apache::loncommon::get_faculty_cnums();
+    if ($inventory ne '' && ref($allnums{$inventory} eq 'HASH') {
+        foreach my $key (%{$allnums{$inventory}}) {
+            $courses{$inventory.'_'.$key} = $allnums{$inventory}->{$key};
+        }
+    }
+
     my %linktext = (
         'review'      => 'Review Questions',
         'submit'      => 'Submit Questions',
@@ -331,7 +343,7 @@
                   'managetest' => '/adm/menu',
                 );
     my $current = 'managetest';
-    if ($env{'form.destinationurl'} eq '/adm/gci_info') {
+    if ($env{'form.destinationurl'} eq '/adm/ci_info') {
         undef($current);
     }
     foreach my $key (keys(%courses)) {
@@ -1457,9 +1469,9 @@
             }
             $switcher = $switcher_js.$switcher;
         }
-        if ($env{'user.domain'} eq 'gci') {
+        if ($env{'user.domain'} !~ /^\w+citest$/) {
             $canreq =
-                &Apache::lonnet::check_can_request('gcitest',\%can_request,\%request_domains);
+                &Apache::lonnet::check_can_request($env{'user.domain'}.'test',\%can_request,\%request_domains);
             $createtext = &mt('Create Concept Test');
             if ($numcourses) {
                 $createtext = &mt('Create New Test');
@@ -1500,7 +1512,7 @@
             } else {
                 my $navtext = &mt('Table of Contents');
                 my $navdesc = &mt('Display Table of Contents for Geoscience Concept Inventory');
-                if ($env{'request.role.domain'} eq 'gcitest') {
+                if ($env{'request.role.domain'} =~ /^\w+citest$/) {
                     $navtext = &mt('Display Test Contents');
                     $navdesc = &mt('Display the table of contents for this Concept Test');
                 }
@@ -1890,7 +1902,7 @@
         my $managetesturl = '/adm/menu';
         my $createtesturl = '/adm/requestcourse';
         if (($env{'request.course.id'}) &&
-            ($env{'course.'.$env{'request.course.id'}.'.domain'} eq 'gci')) {
+            ($env{'course.'.$env{'request.course.id'}.'.domain'} !~ /^\w+citest$/)) {
             my @items = keys(%concepttests);
             if (@items== 1) {
                 my $newrole = $items[0];
@@ -1903,14 +1915,24 @@
         if ($env{'request.course.id'}) {
             $createtesturl = '/adm/roles?selectrole=1&cm=1&orgurl=%2fadm%2frequestcourse';
         }
+        my %allnums = &Apache::loncommon::get_faculty_cnums();
+        my $udom = $env{'user.domain'};
+        my %crs_by_caller;
+        if (ref($allnums{$udom}) eq 'HASH') {
+            foreach my $key (%{$allnums{$udom}}) {
+                $crs_by_caller{$allnums{$udom}->{$key}} = 'st./'.$udom.'/'.$key.'=1';
+            }
+        }
+    }
+
         $gcimenujs = <<"ENDCUSTOM";
 
 function switchpage(caller) {
     if (caller == 'review') {
-        document.location.href = '/adm/roles?selectrole=1&st./gci/9615072b469884921gcil1=1';
+        document.location.href = '/adm/roles?selectrole=1&'.$crs_by_caller{'review'};
     }
     if (caller == 'submit') {
-        document.location.href = '/adm/roles?selectrole=1&st./gci/1H96711d710194bfegcil1=1';
+        document.location.href = '/adm/roles?selectrole=1&'.$crs_by_caller{'submit'};
     }
     if (caller == 'createtest') {
         document.location.href = '$createtesturl';
@@ -1919,7 +1941,7 @@
         document.location.href = '$managetesturl';
     }
     if (caller == 'tutorial') {
-        document.location.href = '/adm/roles?selectrole=1&st./gci/5422913620b814c90gcil1=1';
+        document.location.href = '/adm/roles?selectrole=1&'.$crs_by_caller{'tutorial'};
     }
     return;
 }