[LON-CAPA-cvs] cvs: loncom /cgi lonauthcgi.pm /interface coursecatalog.pm domainprefs.pm

raeburn raeburn at source.lon-capa.org
Mon May 4 11:43:57 EDT 2015


raeburn		Mon May  4 15:43:57 2015 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm coursecatalog.pm 
    /loncom/cgi	lonauthcgi.pm 
  Log:
  - Display of Course/Community Catalog with enrollment data added to "server
    status" pages for which access can be IP-based or available to specified
    authenticated users (DC role not required).
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.261 loncom/interface/domainprefs.pm:1.262
--- loncom/interface/domainprefs.pm:1.261	Wed Apr  1 23:22:10 2015
+++ loncom/interface/domainprefs.pm	Mon May  4 15:43:47 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.261 2015/04/01 23:22:10 raeburn Exp $
+# $Id: domainprefs.pm,v 1.262 2015/05/04 15:43:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5326,7 +5326,7 @@
     return ('userstatus','lonstatus','loncron','server-status','codeversions',
             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
             'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
-            'uniquecodes','diskusage');
+            'uniquecodes','diskusage','coursecatalog');
 }
 
 sub defaults_javascript {
Index: loncom/interface/coursecatalog.pm
diff -u loncom/interface/coursecatalog.pm:1.85 loncom/interface/coursecatalog.pm:1.86
--- loncom/interface/coursecatalog.pm:1.85	Sat May 17 23:14:41 2014
+++ loncom/interface/coursecatalog.pm	Mon May  4 15:43:48 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler for displaying the course catalog interface
 #
-# $Id: coursecatalog.pm,v 1.85 2014/05/17 23:14:41 raeburn Exp $
+# $Id: coursecatalog.pm,v 1.86 2015/05/04 15:43:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -38,6 +38,7 @@
 use Apache::courseclassifier;
 use Apache::lonacc;
 use LONCAPA;
+use LONCAPA::lonauthcgi;
 
 sub handler {
     my ($r) = @_;
@@ -79,11 +80,12 @@
     my %domconfig =
         &Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom);
     my $knownuser = &user_is_known();
-
+    my $canviewall = &canview_all();
+    
     my ($cathash,$cattype);
     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
         $cathash = $domconfig{'coursecategories'}{'cats'};
-        if ($knownuser) {
+        if ($knownuser || $canviewall) {
             $cattype = $domconfig{'coursecategories'}{'auth'};
         } else {
             $cattype = $domconfig{'coursecategories'}{'unauth'};
@@ -101,7 +103,7 @@
         ({href=>"/adm/coursecatalog",
           text=>"Course/Community Catalog"});
         $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
-        if ($knownuser) {
+        if ($knownuser || $canviewall) {
             $r->print('<div>'.&mt('No catalog of LON-CAPA courses/communities is provided for: [_1]',$domdesc).'</div>');
         } else {
             if ($domconfig{'coursecategories'}{'auth'} eq 'none') {
@@ -149,8 +151,8 @@
                 my %courses = &Apache::lonnet::courseiddump($codedom,'.',1,'.','.',
                                                             $cnum,undef,undef,'.',1);
                 if (keys(%courses)) {
-                    $env{'form.coursenum'} = $cnum;  
-                    my %courseinfo = &build_courseinfo_hash(\%courses,$knownuser,$codedom);
+                    $env{'form.coursenum'} = $cnum;
+                    my %courseinfo = &build_courseinfo_hash(\%courses,$knownuser,$codedom,$canviewall);
                     undef($env{'form.coursenum'});
                     if (ref($courseinfo{$codedom.'_'.$cnum}) eq 'HASH') {
                         $r->print(&Apache::lonhtmlcommon::start_pick_box());
@@ -249,7 +251,7 @@
 
 ENDSCRIPT
         $catjs .= &courselink_javascript();
-        if (&user_is_dc($codedom)) {
+        if (&user_is_dc($codedom) || $canviewall) {
             $catjs .= <<ENDTOGGJS
 
 function toggleStatuses() {
@@ -280,10 +282,10 @@
         }
         if ($env{'form.currcat_0'} eq 'instcode::0') {
             $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,
-                                                   $catlinks,$catjs,\@codetitles,$cattype);
+                                                   $catlinks,$catjs,\@codetitles,$cattype,$canviewall);
             if ($env{'form.state'} eq 'listing') {
                 $r->print(&print_course_listing($codedom,$numtitles,undef,undef,undef,
-                                                \@codetitles));
+                                                \@codetitles,$canviewall));
             }
         } else {
             my (%add_entries);
@@ -307,7 +309,7 @@
             if ($env{'form.currcat_0'} ne '') {
                 $r->print('<form name="'.$formname.
                           '" method="post" action="/adm/coursecatalog">'.
-                          &additional_filters($codedom,$has_subcats)."\n");
+                          &additional_filters($codedom,$has_subcats,$canviewall)."\n");
                 $r->print('<input type="hidden" name="catalog_maxdepth" value="'.
                           $deeper.'" />'."\n");
                 for (my $i=0; $i<$deeper; $i++) {
@@ -328,7 +330,8 @@
                           $display_button.'" /></form><br /><br />');
             }
             if ($env{'form.state'} eq 'listing') {
-                $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats,\@codetitles));
+                $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats,\@codetitles,
+                                                $canviewall));
             }
         }
     }
@@ -431,7 +434,7 @@
 }
 
 sub instcode_course_selector {
-    my ($r,$codedom,$formname,$domdesc,$catlinks,$catjs,$codetitles,$cattype) = @_;
+    my ($r,$codedom,$formname,$domdesc,$catlinks,$catjs,$codetitles,$cattype,$canviewall) = @_;
     my %coursecodes = ();
     my %codes = ();
     my %cat_titles = ();
@@ -453,7 +456,7 @@
         if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) {
             $add_entries{'onLoad'} = 'setElements();';
         }
-        if (&user_is_dc($codedom)) {
+        if (&user_is_dc($codedom) || $canviewall) {
             $add_entries{'onLoad'} .= ' toggleStatuses();toggleWasActive();'
         }
         &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles,$cattype);
@@ -462,7 +465,7 @@
                   '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'."\n".
                   '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'."\n".
                   '<input type="hidden" name="currcat_0" value="instcode::0" />'.
-                  &additional_filters($codedom));
+                  &additional_filters($codedom,undef,$canviewall));
         if ($numtitles > 0) {
             $r->print('<b>'.&mt('Choose which course(s) to list.').'</b><br />'.
                       &Apache::courseclassifier::build_instcode_selectors($numtitles,
@@ -683,10 +686,10 @@
 }
 
 sub additional_filters {
-    my ($codedom,$has_subcats) = @_;
+    my ($codedom,$has_subcats,$canviewall) = @_;
     my $is_dc = &user_is_dc($codedom);
     my $output = '<div class="LC_left_float">';
-    if ($is_dc) {
+    if ($is_dc || $canviewall) {
         $output .= '<fieldset><legend>'.&mt('Options').'</legend>';
     }
     $output .= '<table><tr><td valign="top">';
@@ -727,7 +730,7 @@
                '<label><input type="checkbox" name="showselfenroll" value="1" '.
                $show_selfenroll_status.'/>'.$selfenroll_text.
                '</label></span><br />';
-    if ($is_dc) {
+    if ($is_dc || $canviewall) {
         my ($titlesref,$orderref) = &get_statustitles('filters');
         my $showdetails_status;
         if ($env{'form.showdetails'}) {
@@ -758,11 +761,13 @@
             $details_text = &mt('Show full details for each course ([_1] only)',$dc_title);
             $hidden_text = &mt('Include courses set to be hidden from catalog ([_1] only)',$dc_title);
         }
+        if ($is_dc) {
+            $output .= '<span class="LC_nobreak">'.
+                       '<label><input type="checkbox" name="showhidden" value="1" '.
+                       $showhidden_status.'/>'.$hidden_text.
+                       '</label></span><br />'."\n";
+        }
         $output .= '<span class="LC_nobreak">'.
-                   '<label><input type="checkbox" name="showhidden" value="1" '.
-                   $showhidden_status.'/>'.$hidden_text.
-                   '</label></span><br />'."\n".
-                   '<span class="LC_nobreak">'.
                    '<label><input type="checkbox" name="showdetails" value="1" '.
                    $showdetails_status.'onclick="toggleStatuses();" />'.
                    $details_text.'</label></span></td>'."\n".
@@ -868,6 +873,17 @@
     return;
 }
 
+sub canview_all {
+    my $canviewall = 0;
+    my $page = 'coursecatalog';
+    if (&LONCAPA::lonauthcgi::can_view($page)) {
+        $canviewall = 1;
+    } elsif (&LONCAPA::lonauthcgi::check_ipbased_access($page)) {
+        $canviewall= 1;
+    }
+    return $canviewall;
+}
+
 sub get_statustitles {
     my ($caller) = @_;
     my @status_order = ('Active','Future','Previous');
@@ -961,12 +977,13 @@
 }
 
 sub print_course_listing {
-    my ($domain,$numtitles,$trails,$allitems,$subcats,$codetitles) = @_;
+    my ($domain,$numtitles,$trails,$allitems,$subcats,$codetitles,$canviewall) = @_;
     my $output;
     my %courses;
     my $knownuser = &user_is_known();
+    my $canviewall = &canview_all();
     my $details = $env{'form.coursenum'};
-    if (&user_is_dc($domain)) {
+    if (&user_is_dc($domain) || $canviewall) {
         if ($env{'form.showdetails'}) {
             $details = 1;
         }
@@ -1001,7 +1018,7 @@
             $output .= '</p>';
             return $output;
         }
-        if (($knownuser) && (!$env{'form.showdetails'}) && (!&user_is_dc($domain))) {
+        if (($knownuser) && (!$env{'form.showdetails'}) && (!&user_is_dc($domain)) && (!$canviewall)) {
             $output = '<b>'.&mt('Note for students:').'</b> '
                      .&mt('If you are officially enrolled in a course but the course is not listed in your LON-CAPA courses, click the "Show more details" link for the specific course and check the default access dates and/or automated enrollment settings.')
                      .'<br /><br />';
@@ -1009,7 +1026,7 @@
     }
     my $now = time;
     $output .= &construct_data_table($knownuser,$domain,\%courses,$details,undef,
-                                     $now,$trails,$allitems);
+                                     $now,$trails,$allitems,$canviewall);
     $output .= "\n".'<form name="linklaunch" method="post" action="">'.
                '<input type="hidden" name="backto" value="coursecatalog" />'.
                '<input type="hidden" name="courseid" value="" />'.
@@ -1018,7 +1035,7 @@
 }
 
 sub construct_data_table {
-    my ($knownuser,$domain,$courses,$details,$usersections,$now,$trails,$allitems) = @_;
+    my ($knownuser,$domain,$courses,$details,$usersections,$now,$trails,$allitems,$canviewall) = @_;
     my %sortname;
     if (($details eq '') || ($env{'form.showdetails'})) {
         $sortname{'Code'} = 'code';
@@ -1050,7 +1067,7 @@
         $output .= '</th>';
     }
     my (@fields,%fieldtitles,$wasactiveon);
-    if ($knownuser) {
+    if ($knownuser || ($canviewall && $details)) {
         if ($details) {
             if ($env{'form.currcat_0'} eq 'communities::0') {
                 $output .= '<th>'.&mt('Default Access Dates for Members').'</th>'.
@@ -1063,7 +1080,7 @@
             }
             my ($titlesref,$orderref) = &get_statustitles();
             my @statuses;
-            if (&user_is_dc($domain)) {
+            if (&user_is_dc($domain) || $canviewall) {
                 @statuses = &Apache::loncommon::get_env_multiple('form.showcounts');
                 if (grep(/^Previous$/, at statuses)) {
                     if ($env{'form.wasactive'} eq 'date') { 
@@ -1110,7 +1127,7 @@
             $deftextbook = $domdefaults{'textbookcredits'};
         }
     }
-    my %courseinfo = &build_courseinfo_hash($courses,$knownuser,$domain,$details,
+    my %courseinfo = &build_courseinfo_hash($courses,$knownuser,$domain,$canviewall,$details,
                                             $usersections,\@fields,\%fieldtitles,
                                             $wasactiveon,\%numbers,\%creditsum,
                                             $showcredits,$defofficial,$defunofficial,$deftextbook);
@@ -1144,12 +1161,12 @@
         foreach my $course (@{$Sortby{$item}}) {
             $output.=&Apache::loncommon::start_data_table_row(); 
             $output.=&courseinfo_row($courseinfo{$course},$knownuser,$details,
-                                     \$count,$now,$course,$trails,$allitems,\%numbers);
+                                     \$count,$now,$course,$trails,$allitems,\%numbers,$canviewall);
             $output.=&Apache::loncommon::end_data_table_row();
         }
     }
-    if (($knownuser) && ($count > 1) && $env{'form.showdetails'}) {
-        if (&user_is_dc($domain)) {
+    if (($knownuser || $canviewall) && ($count > 1) && $env{'form.showdetails'}) {
+        if (&user_is_dc($domain) || $canviewall) {
             my %lt = &Apache::lonlocal::texthash (
                                                      'Active'   => 'Total current students',
                                                      'Future'   => 'Total future students',
@@ -1208,12 +1225,12 @@
 }
 
 sub build_courseinfo_hash {
-    my ($courses,$knownuser,$domain,$details,$usersections,$fields,$fieldtitles,
+    my ($courses,$knownuser,$domain,$canviewall,$details,$usersections,$fields,$fieldtitles,
         $wasactiveon,$numbers,$creditsum,$showcredits,$defofficial,$defunofficial) = @_;
     my %courseinfo;
     my $now = time;
     my $gettotals;
-    if ((keys(%{$courses}) > 0) && (&user_is_dc($domain)) && ($details)) {
+    if ((keys(%{$courses}) > 0) && (&user_is_dc($domain) || $canviewall) && ($details)) {
         $gettotals = 1;
     }
     my (%uniquecodes,$nocodes,$defcreds);
@@ -1309,7 +1326,7 @@
             $defcreds = $courseinfo{$course}{'defaultcredits'};
         }
         if (((defined($env{'form.coursenum'}) && ($cnum eq $env{'form.coursenum'}))) ||
-            ($knownuser && ($details == 1))) {
+            (($knownuser || $canviewall) && ($details == 1))) {
             my $milestone;
             if ($wasactiveon eq 'accessend') {
                 if ($coursehash{'default_enrollment_end_date'}) {
@@ -1462,7 +1479,7 @@
 }
 
 sub courseinfo_row {
-    my ($info,$knownuser,$details,$countref,$now,$course,$trails,$allitems,$numbers) = @_;
+    my ($info,$knownuser,$details,$countref,$now,$course,$trails,$allitems,$numbers,$canviewall) = @_;
     my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
         $accessdates,$showsyllabus,$counts,$autoenrollment,$output,$categories);
     if (ref($info) eq 'HASH') {
@@ -1511,7 +1528,7 @@
     }
     $output .= '</font></td>'.
                '<td>'.$ownerlast.'</td>';
-    if ($knownuser) {
+    if (($knownuser) || ($canviewall && $details)) {
         if ($details) {
             $output .=
                 '<td>'.$accessdates.'</td>'.
Index: loncom/cgi/lonauthcgi.pm
diff -u loncom/cgi/lonauthcgi.pm:1.13 loncom/cgi/lonauthcgi.pm:1.14
--- loncom/cgi/lonauthcgi.pm:1.13	Sun Apr  6 14:55:24 2014
+++ loncom/cgi/lonauthcgi.pm	Mon May  4 15:43:57 2015
@@ -1,7 +1,7 @@
 #
 # LON-CAPA authorization for cgi-bin scripts
 #
-# $Id: lonauthcgi.pm,v 1.13 2014/04/06 14:55:24 raeburn Exp $
+# $Id: lonauthcgi.pm,v 1.14 2015/05/04 15:43:57 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -392,6 +392,7 @@
                    'ping'              => 'Cause server to ping another server',   
                    'domconf'           => 'Text Display of Domain Configuration',
                    'uniquecodes'       => 'Six-character Course Codes',
+                   'coursecatalog'     => 'Course/Community Catalog with enrollment data',
                  );
     return \%titles;
 }


More information about the LON-CAPA-cvs mailing list