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

raeburn raeburn at source.lon-capa.org
Tue Oct 2 14:55:46 EDT 2018


raeburn		Tue Oct  2 18:55:46 2018 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm 
  Log:
  - Prevent ISE in first print helper screen when checking printability of
    current resource if no resource object.
  
  
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.662 loncom/interface/lonprintout.pm:1.663
--- loncom/interface/lonprintout.pm:1.662	Tue Jun 19 11:39:26 2018
+++ loncom/interface/lonprintout.pm	Tue Oct  2 18:55:45 2018
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.662 2018/06/19 11:39:26 raeburn Exp $
+# $Id: lonprintout.pm,v 1.663 2018/10/02 18:55:45 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4072,6 +4072,7 @@
     my $subdir;
     my $is_published=0;		# True when printing from resource space.
     my $res_printable = 1;	# By default the current resource is printable.    
+    my $res_error;
     my $userCanPrint = ($perm{'pav'} || $perm{'pfo'});
     my $res_printstartdate;
     my $res_printenddate;
@@ -4093,13 +4094,22 @@
 	    ($map, $id, $url) = &Apache::lonnet::decode_symb($symb);
 	    $helper->{VARS}->{'postdata'} = 
 		&Apache::lonenc::check_encrypt(&Apache::lonnet::clutter($url));
-	    my $navmap = Apache::lonnavmaps::navmap->new();
-	    my $res   = $navmap->getBySymb($symb);
-	    $res_printable  = $res->resprintable() || $userCanPrint; #printability in course context
-	    ($res_printstartdate, $res_printenddate) = 	&get_print_dates($res);
-	    ($course_open, $course_close) = &course_print_dates($res);
-	    ($map_open, $map_close)       = &map_print_dates($res);
-
+            if (!$userCanPrint) {
+	        my $navmap = Apache::lonnavmaps::navmap->new();
+                if (ref($navmap)) {
+	            my $res = $navmap->getBySymb($symb);
+                    if (ref($res)) {
+	                $res_printable = $res->resprintable(); #printability in course context
+	                ($res_printstartdate, $res_printenddate) = &get_print_dates($res);
+	                ($course_open, $course_close) = &course_print_dates($res);
+	                ($map_open, $map_close) = &map_print_dates($res);
+                    } else {
+                        $res_error = 1; 
+                    }
+                } else {
+                    $res_error = 1;
+                }
+            }
 	} else {
 	    # Resource space.
 
@@ -4701,23 +4711,27 @@
     # Generate the first state, to select which resources get printed.
     Apache::lonhelper::state->new("START", "Select Printing Options:");
     if (!$res_printable) {
-        my $now = time;
-        my $shownprintstart = &Apache::lonlocal::locallocaltime($res_printstartdate);
-        my $shownprintend = &Apache::lonlocal::locallocaltime($res_printenddate);
         my $noprintmsg;
-        if (($res_printenddate) && ($res_printenddate < $now)) {
+        if ($res_error) {
+            $noprintmsg = &mt('Print availability for current resource could not be determined');
+        } else {
+            my $now = time;
+            my $shownprintstart = &Apache::lonlocal::locallocaltime($res_printstartdate);
+            my $shownprintend = &Apache::lonlocal::locallocaltime($res_printenddate);
+            if (($res_printenddate) && ($res_printenddate < $now)) {
                 $noprintmsg = &mt('Printing for current resource no longer available (ended: [_1])',
                                   $shownprintend);
-        } else {
-            if (($res_printstartdate) && ($res_printstartdate > $now)) {
-                if (($res_printenddate) && ($res_printenddate > $now) && ($res_printenddate > $res_printstartdate)) {
-                    $noprintmsg = &mt('Printing for current resource is only possible between [_1] and [_2]',
-                                  $shownprintstart,$shownprintend);
-                } elsif (!$res_printenddate) {
-                    $noprintmsg = &mt('Printing for current resource will only be possible starting [_1]',
-                                      $shownprintstart);
-                } else {
-                    $noprintmsg = &mt('Printing for current resource is unavailable');
+            } else {
+                if (($res_printstartdate) && ($res_printstartdate > $now)) {
+                    if (($res_printenddate) && ($res_printenddate > $now) && ($res_printenddate > $res_printstartdate)) {
+                        $noprintmsg = &mt('Printing for current resource is only possible between [_1] and [_2]',
+                                          $shownprintstart,$shownprintend);
+                    } elsif (!$res_printenddate) {
+                        $noprintmsg = &mt('Printing for current resource will only be possible starting [_1]',
+                                          $shownprintstart);
+                    } else {
+                        $noprintmsg = &mt('Printing for current resource is unavailable');
+                    }
                 }
             }
         }




More information about the LON-CAPA-cvs mailing list