--- loncom/lti/ltipassback.pm	2017/12/09 01:36:59	1.1
+++ loncom/lti/ltipassback.pm	2017/12/12 02:13:21	1.4
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # LTI Consumer Module to receive grades passed back by Provider 
 #
-# $Id: ltipassback.pm,v 1.1 2017/12/09 01:36:59 raeburn Exp $
+# $Id: ltipassback.pm,v 1.4 2017/12/12 02:13:21 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -141,7 +141,7 @@ sub handler {
 
     unless (&LONCAPA::ltiutils::check_nonce($params->{'oauth_nonce'},$params->{'oauth_timestamp'},
                                             $ltitools{'lifetime'},$cdom,$r->dir_config('lonLTIDir'))) {
-        $errors{15} = 1;
+        $errors{16} = 1;
         &invalid_request($r,$params,\%errors);
         return OK;
     }
@@ -168,7 +168,7 @@ sub handler {
             %maproles = %{$ltitools{'roles'}};
         }
         unless (keys(%maproles)) {
-            $errors{20} = 1;
+            $errors{21} = 1;
             &invalid_request($r,$params,\%errors);
             return OK;
         }
@@ -205,12 +205,12 @@ sub handler {
             }
         }
         unless ($hasrole) {
-            $errors{21} = 1;
+            $errors{22} = 1;
             &invalid_request($r,$params,\%errors);
             return OK;
         }
     } else {
-        $errors{22} = 1;
+        $errors{23} = 1;
         &invalid_request($r,$params,\%errors);
         return OK;
     }
@@ -222,10 +222,10 @@ sub handler {
 
     my ($result,$resulttype,$lang,$pcf);
     if (exists($params->{'result_resultvaluesourcedid'})) {
-        $resulttype = 'decimal';
-    } else {
         $resulttype = $params->{'result_resultvaluesourcedid'};
         $resulttype =~ s/(^\s+|\s+)$//g;
+    } else {
+        $resulttype = 'decimal';
     } 
     $result = $params->{'result_resultscore_textstring'};
     $result =~ s/(^\s+|\s+)$//g;
@@ -245,7 +245,7 @@ sub handler {
                      };
             }
             if ($@) {
-                $errors{22} = 1;
+                $errors{24} = 1;
                 &invalid_request($r,$params,\%errors);
                 return OK;
             }
@@ -283,21 +283,23 @@ sub handler {
                 }
             }
             if (%newrecord) {
+                $env{'request.course.id'} = $cdom.'_'.$cnum;
                 my $result = &Apache::lonnet::cstore(\%newrecord,$symb,$cdom.'_'.$cnum,
                                                      $udom,$uname);
+                delete($env{'request.course.id'});
                 if (($result eq 'ok') || ($result eq 'con_delayed')) {
                     &success($r,$params->{'sourcedid'},$resulttype,$result,$lang);
                 } else {
-                    $errors{23} = 1;
+                    $errors{25} = 1;
                     &invalid_request($r,$params,\%errors);
                 }
             }
         } else {
-            $errors{24} = 1;
+            $errors{26} = 1;
             &invalid_request($r,$params,\%errors);
         }
     } else {
-        $errors{25} = 1;
+        $errors{27} = 1;
         &invalid_request($r,$params,\%errors);
     }
     return OK;