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

www lon-capa-cvs-allow@mail.lon-capa.org
Fri, 15 Jun 2007 21:21:18 -0000


www		Fri Jun 15 17:21:18 2007 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  Saving my work: clickers
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.404 loncom/homework/grades.pm:1.405
--- loncom/homework/grades.pm:1.404	Thu Jun 14 17:36:12 2007
+++ loncom/homework/grades.pm	Fri Jun 15 17:21:16 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.404 2007/06/14 21:36:12 www Exp $
+# $Id: grades.pm,v 1.405 2007/06/15 21:21:16 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -6145,6 +6145,7 @@
         my $clickers =
 	   (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
         foreach my $id (split(/\,/,$clickers)) {
+            $id=~s/^0+//;
             if (exists($clickerids{$id})) {
                $clickerids{$id}.=','.$username.':'.$domain;
             } else {
@@ -6165,13 +6166,14 @@
             my ($puname,$pudom)=split(/\:/,$person);
             my $clickers =
                (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
-               foreach my $id (split(/\,/,$clickers)) {
+            foreach my $id (split(/\,/,$clickers)) {
+               $id=~s/^0+//;
                if (exists($clickerids{$id})) {
                   $clickerids{$id}.=','.$puname.':'.$pudom;
                } else {
                   $clickerids{$id}=$puname.':'.$pudom;
                }
-           }
+            }
         }
     }
     return %clickerids;
@@ -6198,7 +6200,7 @@
     my $pcorrect=&mt("Percentage points for correct solution");
     my $pincorrect=&mt("Percentage points for incorrect solution");
     my $selectform=&Apache::loncommon::select_form('iclicker','upfiletype',
-                                  ('iclicker' => 'iClicker'));
+                                  ('iclicker' => 'i>clicker'));
 
     $result.=<<ENDUPFORM;
 <script type="text/javascript">
@@ -6281,6 +6283,7 @@
        my $correctid=$env{'form.specificid'};
        $correctid=~tr/a-z/A-Z/;
        $correctid=~s/\s//gs;
+       $correctid=~s/^0+//;
        $correctids{$correctid}='specified';
     }
     if ($env{'form.gradingmechanism'} eq 'attendance') {
@@ -6304,9 +6307,42 @@
           return $result.&show_grading_menu_form($symb);
        }
     }
+    if (length($env{'form.upfile'}) < 2) {
+        $result.="<span class=\"LC_error\">Error:</span> The file you attempted to upload, <tt>".&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"')."</tt>, contained no information. Please check that you entered the correct filename.";
+        return $result.&show_grading_menu_form($symb);
+    }
+    my %contents=();
+    my $errormsg='';
+    my $number=0;
+    if ($env{'form.upfiletype'} eq 'iclicker') {
+       ($errormsg,$number,%contents)=&iclicker_eval();
+       $result.=$errormsg;
+    }
     return $result.&show_grading_menu_form($symb);
 }
 
+sub iclicker_eval {
+    my $number=0;
+    my $errormsg='';
+    foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
+       chomp($line);
+       foreach my $quoted ($line=~/\,\s*\"([^\"]*)\"\s*\,/g) {
+          my $replace=$quoted;
+          $replace=~s/\,//g;
+          &Apache::lonnet::logthis($quoted.' - '.$replace.'<br />');
+          $line=~s/\,\s*\"\Q$quoted\E\"\s*\,/,$replace,/gs;
+       }
+       my @entries=split(/\,/,$line);
+       if ($entries[0] eq 'Question') {
+          for (my $i=3;$i<$#entries;$i+=6) {
+              $number++;
+              $errormsg.='<br />'.$entries[$i];
+          }
+       }
+    }
+    return ($errormsg,$number);
+}
+
 sub handler {
     my $request=$_[0];