[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Thu Feb 28 23:17:31 EST 2013


raeburn		Fri Mar  1 04:17:31 2013 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Domain configuration to specify defaults for credits earned in a course
    (Course defaults) for official or unofficial courses.
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.191 loncom/interface/domainprefs.pm:1.192
--- loncom/interface/domainprefs.pm:1.191	Mon Feb 25 17:43:41 2013
+++ loncom/interface/domainprefs.pm	Fri Mar  1 04:17:15 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.191 2013/02/25 17:43:41 raeburn Exp $
+# $Id: domainprefs.pm,v 1.192 2013/03/01 04:17:15 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -417,7 +417,8 @@
     if ($phase eq 'process') {
         &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
     } elsif ($phase eq 'display') {
-        my $js = &recaptcha_js();
+        my $js = &recaptcha_js().
+                 &credits_js();
         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
             my ($othertitle,$usertypes,$types) =
                 &Apache::loncommon::sorted_inst_types($dom);
@@ -2372,7 +2373,8 @@
 }
 
 sub radiobutton_prefs {
-    my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
+    my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
+        $additional) = @_;
     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                    (ref($choices) eq 'HASH'));
 
@@ -2398,17 +2400,22 @@
             }
         }
     }
+    if ($onclick) {
+        $onclick = ' onclick="'.$onclick.'"';
+    }
     foreach my $item (@{$toggles}) {
         $css_class = $itemcount%2?' class="LC_odd_row"':'';
         $datatable .=
-            '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
+            '<tr'.$css_class.'><td valign="top">'.
+            '<span class="LC_nobreak">'.$choices->{$item}.
             '</span></td>'.
             '<td class="LC_right_item"><span class="LC_nobreak">'.
             '<label><input type="radio" name="'.
-            $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
+            $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
             '</label> <label><input type="radio" name="'.$item.'" '.
-            $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
-            '</span></td>'.
+            $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
+            '</span>'.$additional.
+            '</td>'.
             '</tr>';
         $itemcount ++;
     }
@@ -2417,28 +2424,31 @@
 
 sub print_coursedefaults {
     my ($position,$dom,$settings,$rowtotal) = @_;
-    my ($css_class,$datatable);
+    my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked, at toggles);
     my $itemcount = 1;
+    my %choices =  &Apache::lonlocal::texthash (
+        canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
+        anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
+        coursecredits        => 'Credits can be specified for courses',
+    );
     if ($position eq 'top') {
-        my (%checkedon,%checkedoff,%choices,%defaultchecked, at toggles);
-        %choices =
-            &Apache::lonlocal::texthash (
-                canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
-        );
         %defaultchecked = ('canuse_pdfforms' => 'off');
-        @toggles = ('canuse_pdfforms',);
+        @toggles = ('canuse_pdfforms');
         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                                                  \%choices,$itemcount);
-        $$rowtotal += $itemcount;
     } else {
         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
-        my %choices =
-            &Apache::lonlocal::texthash (
-                anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
-        );
-        my $currdefresponder;
+        my ($currdefresponder,$def_official_credits,$def_unofficial_credits);
+        my $currusecredits = 0;
         if (ref($settings) eq 'HASH') {
             $currdefresponder = $settings->{'anonsurvey_threshold'};
+            if (ref($settings->{'coursecredits'}) eq 'HASH') {
+                $def_official_credits = $settings->{'coursecredits'}->{'official'};
+                $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
+                if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
+                    $currusecredits = 1;
+                }
+            }
         }
         if (!$currdefresponder) {
             $currdefresponder = 10;
@@ -2446,13 +2456,41 @@
             $currdefresponder = 1;
         }
         $datatable .=
-               '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
+                '<tr'.$css_class.'><td><span class="LC_nobreak">'.
+                $choices{'anonsurvey_threshold'}.
                 '</span></td>'.
                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                 '<input type="text" name="anonsurvey_threshold"'.
                 ' value="'.$currdefresponder.'" size="5" /></span>'.
-                '</td></tr>';
+                '</td></tr>'."\n";
+        $itemcount ++;
+        my $onclick = 'toggleCredits(this.form);';
+        my $display = 'none';  
+        if ($currusecredits) {
+            $display = 'block';
+        }
+        my $additional = '<div id="credits" style="display: '.$display.'">'.
+                         '<span class="LC_nobreak">'.
+                         &mt('Default credits for official courses [_1]',
+                         '<input type="text" name="official_credits" value="'.
+                         $def_official_credits.'" size="3" />').
+                         '</span><br />'.
+                         '<span class="LC_nobreak">'.
+                         &mt('Default credits for unofficial courses [_1]',
+                         '<input type="text" name="unofficial_credits" value="'.
+                         $def_unofficial_credits.'" size="3" />').
+                         '</span></div>'."\n";
+        %defaultchecked = ('coursecredits' => 'off');
+        @toggles = ('coursecredits');
+        my $current = {
+                        'coursecredits' => $currusecredits,
+                      };
+        (my $table,$itemcount) =
+            &radiobutton_prefs($current,\@toggles,\%defaultchecked,
+                               \%choices,$itemcount,$onclick,$additional);
+        $datatable .= $table;
     }
+    $$rowtotal += $itemcount;
     return $datatable;
 }
 
@@ -7811,7 +7849,6 @@
     my ($dom,%domconfig) = @_;
     my ($resulttext,$errors,%changes,%defaultshash);
     my %defaultchecked = ('canuse_pdfforms' => 'off');
-    my @offon = ('off','on');
     my @toggles = ('canuse_pdfforms');
 
     $defaultshash{'coursedefaults'} = {};
@@ -7828,7 +7865,7 @@
                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                     ($env{'form.'.$item} eq '0')) {
                     $changes{$item} = 1;
-                } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
+                } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                     $changes{$item} = 1;
                 }
             } elsif ($defaultchecked{$item} eq 'off') {
@@ -7853,14 +7890,42 @@
                 $changes{'anonsurvey_threshold'} = 1;
             }
         }
+        my $officialcreds = $env{'form.official_credits'};
+        $officialcreds =~ s/^[^\d\.]//g;
+        my $unofficialcreds = $env{'form.unofficial_credits'};
+        $unofficialcreds =~ s/^[^\d\.]//g;
+        if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
+                ($env{'form.coursecredits'} eq '1')) {
+                $changes{'coursecredits'} = 1;
+        } else {
+            if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds)  ||
+                ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
+                $changes{'coursecredits'} = 1;
+            }
+        }
+        $defaultshash{'coursedefaults'}{'coursecredits'} = {
+            official   => $officialcreds,
+            unofficial => $unofficialcreds,
+        }
     }
     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                                              $dom);
     if ($putresult eq 'ok') {
+        my %domdefaults;
         if (keys(%changes) > 0) {
-            if ($changes{'canuse_pdfforms'}) {
-                my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
-                $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
+            if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'})) {
+                %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+                if ($changes{'canuse_pdfforms'}) {
+                    $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
+                }
+                if ($changes{'coursecredits'}) {
+                    if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
+                        $domdefaults{'officialcredits'} =
+                            $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
+                        $domdefaults{'unofficialcredits'} =
+                            $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
+                    }
+                }
                 my $cachetime = 24*60*60;
                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
             }
@@ -7873,7 +7938,22 @@
                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                     }
                 } elsif ($item eq 'anonsurvey_threshold') {
-                        $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
+                    $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
+                } elsif ($item eq 'coursecredits') {
+                    if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
+                        if (($domdefaults{'officialcredits'} eq '') &&
+                            ($domdefaults{'unofficialcredits'} eq '')) {
+                            $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
+                        } else {
+                            $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
+                                           '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
+                                           '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
+                                           '</ul>'.
+                                           '</li>';
+                        }
+                    } else {
+                        $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
+                    }
                 }
             }
             $resulttext .= '</ul>';
@@ -9015,6 +9095,40 @@
 
 }
 
+sub credits_js {
+    return <<"END";
+
+<script type="text/javascript">
+// <![CDATA[
+
+function toggleCredits(domForm) {
+    if (document.getElementById('credits')) {
+        creditsitem = document.getElementById('credits');
+        var creditsLength = domForm.coursecredits.length;
+        if (creditsLength) {
+            var currval;
+            for (var i=0; i<creditsLength; i++) {
+                if (domForm.coursecredits[i].checked) {
+                   currval = domForm.coursecredits[i].value;
+                }
+            }
+            if (currval == 1) {
+                creditsitem.style.display = 'block';
+            } else {
+                creditsitem.style.display = 'none';
+            }
+        }
+    }
+    return;
+}
+
+// ]]>
+</script>
+
+END
+
+}
+
 sub captcha_phrases {
     return &Apache::lonlocal::texthash (
                  priv => 'Private key',
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1215 loncom/lonnet/perl/lonnet.pm:1.1216
--- loncom/lonnet/perl/lonnet.pm:1.1215	Thu Feb 14 16:52:11 2013
+++ loncom/lonnet/perl/lonnet.pm	Fri Mar  1 04:17:31 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1215 2013/02/14 16:52:11 raeburn Exp $
+# $Id: lonnet.pm,v 1.1216 2013/03/01 04:17:31 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2010,6 +2010,10 @@
         foreach my $item ('canuse_pdfforms') {
             $domdefaults{$item} = $domconfig{'coursedefaults'}{$item};
         }
+        if (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
+            $domdefaults{'officialcredits'} = $domconfig{'coursedefaults'}{'coursecredits'}{'official'};
+            $domdefaults{'unofficialcredits'} = $domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'};
+        }
     }
     if (ref($domconfig{'usersessions'}) eq 'HASH') {
         if (ref($domconfig{'usersessions'}{'remote'}) eq 'HASH') {
@@ -7441,8 +7445,8 @@
     }
     $response=&unescape(&reply('autovalidateinstcode:'.$cdom.':'.
                         &escape($instcode).':'.&escape($owner),$homeserver));
-    my ($outcome,$description) = map { &unescape($_); } split('&',$response,2);
-    return ($outcome,$description);
+    my ($outcome,$description,$defaultcredits) = map { &unescape($_); } split('&',$response,3);
+    return ($outcome,$description,$defaultcredits);
 }
 
 sub auto_create_password {
@@ -8382,7 +8386,7 @@
 sub modifystudent {
     my ($udom,$uname,$uid,$umode,$upass,$first,$middle,$last,$gene,$usec,
         $end,$start,$forceid,$desiredhome,$email,$type,$locktype,$cid,
-        $selfenroll,$context,$inststatus)=@_;
+        $selfenroll,$context,$inststatus,$credits)=@_;
     if (!$cid) {
 	unless ($cid=$env{'request.course.id'}) {
 	    return 'not_in_class';
@@ -8397,12 +8401,14 @@
     # students environment
     $uid = undef if (!$forceid);
     $reply = &modify_student_enrollment($udom,$uname,$uid,$first,$middle,$last,
-					$gene,$usec,$end,$start,$type,$locktype,$cid,$selfenroll,$context);
+                                        $gene,$usec,$end,$start,$type,$locktype,
+                                        $cid,$selfenroll,$context,$credits);
     return $reply;
 }
 
 sub modify_student_enrollment {
-    my ($udom,$uname,$uid,$first,$middle,$last,$gene,$usec,$end,$start,$type,$locktype,$cid,$selfenroll,$context) = @_;
+    my ($udom,$uname,$uid,$first,$middle,$last,$gene,$usec,$end,$start,$type,
+        $locktype,$cid,$selfenroll,$context,$credits) = @_;
     my ($cdom,$cnum,$chome);
     if (!$cid) {
 	unless ($cid=$env{'request.course.id'}) {
@@ -8449,7 +8455,7 @@
     my %old_entry = &Apache::lonnet::get('classlist',[$user],$cdom,$cnum);
     my $reply=cput('classlist',
 		   {$user => 
-			join(':',$end,$start,$uid,$usec,$fullname,$type,$locktype) },
+			join(':',$end,$start,$uid,$usec,$fullname,$type,$locktype,$credits) },
 		   $cdom,$cnum);
     if (($reply eq 'ok') || ($reply eq 'delayed')) {
         &devalidate_getsection_cache($udom,$uname,$cid);
@@ -12645,7 +12651,9 @@
 
 =item B<$context> role change context (shown in User Management Logs display in a course)
 
-=item B<$inststatus> institutional status of user - : separated string of escaped status types  
+=item B<$inststatus> institutional status of user - : separated string of escaped status types
+
+=item B<$credits> Number of credits student will earn from this class - only needs to be supplied if value needs to be different from default credits for class.
 
 =back
 
@@ -12690,6 +12698,8 @@
 
 =item $context
 
+=item $credits, number of credits student will earn from this class
+
 =back
 
 


More information about the LON-CAPA-cvs mailing list