[LON-CAPA-cvs] cvs: loncom /homework lonhomework.pm

foxr lon-capa-cvs@mail.lon-capa.org
Mon, 20 Dec 2004 12:16:47 -0000


foxr		Mon Dec 20 07:16:47 2004 EDT

  Modified files:              
    /loncom/homework	lonhomework.pm 
  Log:
  - Add debug log capability conditionalized on my favorite $DEBUG global.
  - Pre-declare Apache::lonhomework::viewgrades before assigning to it out of
    the blue.
  - Put in a few comments (very few for now)
  
  
Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.187 loncom/homework/lonhomework.pm:1.188
--- loncom/homework/lonhomework.pm:1.187	Fri Dec 17 17:30:30 2004
+++ loncom/homework/lonhomework.pm	Mon Dec 20 07:16:47 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Homework handler
 #
-# $Id: lonhomework.pm,v 1.187 2004/12/17 22:30:30 albertel Exp $
+# $Id: lonhomework.pm,v 1.188 2004/12/20 12:16:47 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -53,12 +53,76 @@
 use Apache::loncommon();
 use Apache::lonlocal;
 use Time::HiRes qw( gettimeofday tv_interval );
+use Apache::lonnet();
+#
+# FIXME!!!!!!!
+#   Be nice if someone 
+#    - Took credit/blame for this module.
+#    - At least commented the purpose of each major
+#      sub
+#    - Even better commented the major blocks.
+#
+#  I'll have a go at it for what I need.
+#     ?'s- mean maybe this is right.
+#          The number of ?'s represents the rough level
+#          of doubt I have about rightness, with ??? representing
+#          uncertainty based on the first blush interpretation.
+#          ?? - I have some code to back up this interpretation.
+#          ?  - I"m pretty sure I understand the code that backs up this
+#               interpretation.
+#         ???? - Absolutely clueless.
+#          .  - I'm pretty sure the interpretation is correct.
+#  RF.
+
+
+# 'Exported' Variables:
+
+#   viewgrades is 'F' if users are not allowed to view the grades.. T otherwise.
+
+$Apache::lonhomework::viewgrades = 'F';		# By default cannot.
+
+#  Internal variables.
+
+my $DEBUG=0;			# set nonzero to enable debugging.
 
 BEGIN {
     &Apache::lonxml::register_insert();
 }
 
+#
+#   Issue debug log messages.  
+# Parameters:
+#    The log message to issue.
+# Implicit Inputs:
+#    DEBUG   - If non zero the message is issued, otherwise not.
+#
+sub Debug {
+    my ($message) = @_;
+
+    if($DEBUG) {
+	my @call_context = caller(1);
+	my $prefix = "$call_context[3]:$call_context[2]:: ";
+	&Apache::lonnet::logthis($prefix.$message);
+    }
+}
+
+#
+#   I believe this sub defines how to render the
+#   problem based on the context of the rendering?
+# Implicit inputs:
+#   Various session environment variables:
+#      request.state - State of the resource actually ??
+#                       published  - Examining in resource space.
+#                       uploaded   - Not sure how this happens?????
+#                       contruct   - Rendering in construction space for viewing.
+#      form.grade_target - 
 sub get_target {
+    &Debug("request.state = $ENV{'request.state'}");
+    if( defined($ENV{'form.grade_target'})) {
+	&Debug("form.grade_target = $ENV{'form.grade_target'}");
+    } else {
+	&Debug("form.grade_target <undefined>");
+    }
     if (($ENV{'request.state'} eq "published") ||
 	($ENV{'request.state'} eq "uploaded")) {
 	if ( defined($ENV{'form.grade_target'}  ) 
@@ -384,7 +448,7 @@
 	$viewgrades = &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}.
                                                '/'.$ENV{'request.course.sec'});
     }
-    $Apache::lonhomework::viewgrades = $viewgrades;
+    $Apache::lonhomework::viewgrades = $viewgrades; # File global variable...dirt.
     if ($Apache::lonhomework::browse eq 'F' && 
 	$ENV{'form.devalidatecourseresdata'} eq 'on') {
 	my (undef,$courseid) = &Apache::lonxml::whichuser();
@@ -607,6 +671,9 @@
     }
     return '';
 }
+#
+#    Render the page in whatever target desired.
+#
 
 sub renderpage {
     my ($request,$file) = @_;