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

www lon-capa-cvs-allow@mail.lon-capa.org
Sun, 20 May 2007 21:10:56 -0000


www		Sun May 20 17:10:56 2007 EDT

  Modified files:              
    /loncom/homework	grades.pm 
    /loncom/interface	lonpreferences.pm 
  Log:
  Saving my work on clicker registration. Buttons commented out.
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.399 loncom/homework/grades.pm:1.400
--- loncom/homework/grades.pm:1.399	Thu May 10 12:06:09 2007
+++ loncom/homework/grades.pm	Sun May 20 17:10:46 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.399 2007/05/10 16:06:09 albertel Exp $
+# $Id: grades.pm,v 1.400 2007/05/20 21:10:46 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -6078,6 +6078,11 @@
 	'<input type="button" onClick="javascript:checkChoice(this.form,\'3\',\'csvform\');" value="'.&mt('Upload').'" />'.
 	' '.&mt('scores from file').' </td></tr>'."\n";
 
+#    $result.='<tr bgcolor="#ffffe6"><td>'.
+#        '<input type="button" onClick="javascript:checkChoice(this.form,\'6\',\'processclicker\');" value="'.&mt('Process').'" />'.
+#        ' '.&mt('clicker file').' </td></tr>'."\n";
+
+
     $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
 	'<input type="button" onClick="javascript:checkChoice(this.form,\'4\',\'scantron_selectphase\');'.
 	'" value="'.&mt('Grade').'" /> scantron forms</td></tr>'."\n";
@@ -6125,6 +6130,80 @@
     }
 }
 
+sub gather_clicker_ids {
+    my %clickerids=();
+
+    my $classlist = &Apache::loncoursedata::get_classlist();
+
+    # Set up a couple variables.
+    my $usernameidx = &Apache::loncoursedata::CL_SNAME();
+    my $domainidx   = &Apache::loncoursedata::CL_SDOM();
+
+    foreach my $student (keys %$classlist) {
+
+        my $username = $classlist->{$student}->[$usernameidx];
+        my $domain   = $classlist->{$student}->[$domainidx];
+        my $clickers =
+	   (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
+        foreach my $id (split(/\,/,$clickers)) {
+            if (exists($clickerids{$id})) {
+               $clickerids{$id}.=','.$username.':'.$domain;
+            } else {
+               $clickerids{$id}=$username.':'.$domain;
+            }
+        }
+    }
+    return %clickerids;
+}
+
+sub process_clicker {
+    my ($r)=@_;
+    my ($symb)=&get_symb($r);
+    if (!$symb) {return '';}
+    my $result=&checkforfile_js();
+    $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
+    my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
+    $result.=$table;
+    $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
+    $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
+    $result.='&nbsp;<b>'.&mt('Specify a file containing the clicker information for this resource').
+        '.</b></td></tr>'."\n";
+    $result.='<tr bgcolor=#ffffe6><td>'."\n";
+    my $upload=&mt("Upload File");
+    my $type=&mt("Type");
+    my $selectform=&Apache::loncommon::select_form('iclicker','upfiletype',
+                                  ('iclicker' => 'iClicker'));
+
+    $result.=<<ENDUPFORM;
+<form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
+<input type="hidden" name="symb" value="$symb" />
+<input type="hidden" name="command" value="processclickerfile" />
+<input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
+<input type="hidden" name="saveState"  value="$env{'form.saveState'}" />
+<input type="file" name="upfile" size="50" />
+<br /><label>$type: $selectform</label>
+<br /><input type="button" onClick="javascript:checkUpload(this.form);" value="$upload" />
+</form>
+ENDUPFORM
+    $result.='</td></tr></table>'."\n".
+             '</td></tr></table><br /><br />'."\n";
+    $result.=&show_grading_menu_form($symb);
+    return $result;
+}
+
+sub process_clicker_file {
+    my ($r)=@_;
+    my ($symb)=&get_symb($r);
+    if (!$symb) {return '';}
+    my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
+    $result.=&show_grading_menu_form($symb);
+    my %clickerids=&gather_clicker_ids();
+    foreach my $key (keys %clickerids) {
+       $result.='<br />'.$key.' - '.$clickerids{$key};
+    }
+    return $result;
+}
+
 sub handler {
     my $request=$_[0];
 
@@ -6192,6 +6271,10 @@
 	    $request->print(&editgrades($request));
 	} elsif ($command eq 'verify' && $perm{'vgr'}) {
 	    $request->print(&verifyreceipt($request));
+        } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
+            $request->print(&process_clicker($request));
+        } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
+            $request->print(&process_clicker_file($request));
 	} elsif ($command eq 'csvform' && $perm{'mgr'}) {
 	    $request->print(&upcsvScores_form($request));
 	} elsif ($command eq 'csvupload' && $perm{'mgr'}) {
Index: loncom/interface/lonpreferences.pm
diff -u loncom/interface/lonpreferences.pm:1.104 loncom/interface/lonpreferences.pm:1.105
--- loncom/interface/lonpreferences.pm:1.104	Sun May 13 18:04:06 2007
+++ loncom/interface/lonpreferences.pm	Sun May 20 17:10:53 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Preferences
 #
-# $Id: lonpreferences.pm,v 1.104 2007/05/13 22:04:06 raeburn Exp $
+# $Id: lonpreferences.pm,v 1.105 2007/05/20 21:10:53 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -562,6 +562,45 @@
 }
 
 ################################################################
+#                     Clicker Subroutines                      #
+################################################################
+
+sub clickerchanger {
+    my $r = shift;
+    my $user       = $env{'user.name'};
+    my $domain     = $env{'user.domain'};
+    my %userenv = &Apache::lonnet::get
+        ('environment',['clickers']);
+    my $clickers=$userenv{'clickers'};
+    $clickers=~s/\,/\n/gs;
+    my $text=&mt('Enter response device ("clicker") numbers');
+    my $change=&mt('Register');
+    $r->print(<<ENDSCREEN);
+<form name="prefs" action="/adm/preferences" method="post">
+<input type="hidden" name="action" value="verify_and_change_clicker" />
+<label>$text<br />
+<textarea name="clickers" rows="5" cols="10">$clickers</textarea>
+</label>
+<input type="submit" value="$change" />
+</form>
+ENDSCREEN
+}
+
+sub verify_and_change_clicker {
+    my $r = shift;
+    my $user       = $env{'user.name'};
+    my $domain     = $env{'user.domain'};
+    my $newclickers  = $env{'form.clickers'};
+    $newclickers=~s/\W+/\,/gs;
+    $newclickers=~tr/a-z/A-Z/;
+    $newclickers=~s/^\,//;
+    $newclickers=~s/\,$//;
+    &Apache::lonnet::put('environment',{'clickers' => $newclickers});
+    &Apache::lonnet::appenv('environment.clickers' => $newclickers);
+    $r->print(&mt('Registering clickers: [_1]',$newclickers));
+}
+
+################################################################
 #         Message Forward                                      #
 ################################################################
 
@@ -1762,6 +1801,23 @@
                       printmenu => 'yes',
                       }));
 
+#    push (@Options,({ action   => 'changeclicker',
+#                      linktext => 'Register Response Devices ("Clickers")',
+#                      href     => '/adm/preferences',
+#                      subroutine => \&clickerchanger,
+#                      breadcrumb =>
+#                          { href => '/adm/preferences?action=changeicons',
+#                            text => 'Register Clicker'},
+#                      },
+#                    { action   => 'verify_and_change_clicker',
+#                      subroutine => \&verify_and_change_clicker,
+#                      breadcrumb =>
+#                          { href => '/adm/preferences?action=changeclicker',
+#                            text => 'Register Clicker'},
+#                      printmenu => 'yes',
+#                      }));
+
+
     if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
 	|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
 				    .$env{'request.course.sec'})) {