[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface domainprefs.pm

raeburn raeburn at source.lon-capa.org
Fri Mar 1 16:17:26 EST 2013


raeburn		Fri Mar  1 21:17:26 2013 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	domainprefs.pm 
  Log:
  - For 2.11.
    - Backport 1.191, 1.192
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.160.6.15 loncom/interface/domainprefs.pm:1.160.6.16
--- loncom/interface/domainprefs.pm:1.160.6.15	Sat Feb  2 02:54:04 2013
+++ loncom/interface/domainprefs.pm	Fri Mar  1 21:17:24 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.160.6.15 2013/02/02 02:54:04 raeburn Exp $
+# $Id: domainprefs.pm,v 1.160.6.16 2013/03/01 21:17:24 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -210,13 +210,13 @@
                 'quotas','autoenroll','autoupdate','autocreate',
                 'directorysrch','usercreation','usermodification',
                 'contacts','defaults','scantron','coursecategories',
-                'serverstatuses','requestcourses','usersessions',
-                'loadbalancing','requestauthor'],$dom);
+                'serverstatuses','requestcourses','coursedefaults',
+                'usersessions','loadbalancing','requestauthor'],$dom);
     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
                        'autoupdate','autocreate','directorysrch','contacts',
                        'usercreation','usermodification','scantron',
                        'requestcourses','requestauthor','coursecategories',
-                       'serverstatuses','usersessions');
+                       'serverstatuses','coursedefaults','usersessions');
     my %existing;
     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
         %existing = %{$domconfig{'loadbalancing'}};
@@ -353,6 +353,12 @@
                               col3 => 'Specific IPs',
                             }],
                  },
+        'coursedefaults' =>
+                 {text => 'Course/Community defaults',
+                  help => 'Domain_Configuration_Course_Defaults',
+                  header => [{col1 => 'Defaults which can be overridden for each course by a DC',
+                              col2 => 'Value',},],
+                 },
         'usersessions' =>
                  {text  => 'User session hosting/offloading',
                   help  => 'Domain_Configuration_User_Sessions',
@@ -395,7 +401,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);
@@ -513,6 +520,8 @@
         $output = &modify_quotas($dom,$action,%domconfig);
     } elsif ($action eq 'requestauthor') {
         $output = &modify_quotas($dom,$action,%domconfig);
+    } elsif ($action eq 'coursedefaults') {
+        $output = &modify_coursedefaults($dom,%domconfig);
     } elsif ($action eq 'usersessions') {
         $output = &modify_usersessions($dom,%domconfig);
     } elsif ($action eq 'loadbalancing') {
@@ -671,8 +680,6 @@
               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                        &print_usersessions('bottom',$dom,$settings,\$rowtotal);
             $rowtotal ++;
-        } elsif ($action eq 'coursedefaults') {
-            $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'rolecolors') {
             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
            </table>
@@ -769,6 +776,8 @@
             $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'loadbalancing') {
             $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
+        } elsif ($action eq 'coursedefaults') {
+            $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
         }
     }
     $output .= '
@@ -1898,35 +1907,16 @@
 
 sub print_requestmail {
     my ($dom,$action,$settings,$rowtotal) = @_;
-    my ($now,$datatable,%dompersonnel, at domcoord, at currapproval,$rows);
+    my ($now,$datatable,%currapp,$rows);
     $now = time;
-    $rows = 0;
-    %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
-    foreach my $server (keys(%dompersonnel)) {
-        foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
-            my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
-            if (!grep(/^$uname:$udom$/, at domcoord)) {
-                push(@domcoord,$uname.':'.$udom);
-            }
-        }
-    }
     if (ref($settings) eq 'HASH') {
         if (ref($settings->{'notify'}) eq 'HASH') {
             if ($settings->{'notify'}{'approval'} ne '') {
-               @currapproval = split(',',$settings->{'notify'}{'approval'});
-            }
-        }
-    }
-    if (@currapproval) {
-        foreach my $dc (@currapproval) {
-            unless (grep(/^\Q$dc\E$/, at domcoord)) {
-                push(@domcoord,$dc);
+               map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
             }
         }
     }
-    @domcoord = sort(@domcoord);
-    my $numinrow = 4;
-    my $numdc = @domcoord;
+    my $numinrow = 2;
     my $css_class = 'class="LC_odd_row"';
     my $text;
     if ($action eq 'requestcourses') {
@@ -1937,42 +1927,12 @@
     $datatable = '<tr '.$css_class.'>'.
                  ' <td>'.$text.'</td>'.
                  ' <td class="LC_left_item">';
-    if (@domcoord > 0) {
-        $datatable .= '<table>';
-        for (my $i=0; $i<$numdc; $i++) {
-            my $rem = $i%($numinrow);
-            if ($rem == 0) {
-                if ($i > 0) {
-                    $datatable .= '</tr>';
-                }
-                $datatable .= '<tr>';
-                $rows ++;
-            }
-            my $check = ' ';
-            if (grep(/^\Q$domcoord[$i]\E$/, at currapproval)) {
-                $check = ' checked="checked" ';
-            }
-            my ($uname,$udom) = split(':',$domcoord[$i]);
-            my $fullname = &Apache::loncommon::plainname($uname,$udom);
-            if ($i == $numdc-1) {
-                my $colsleft = $numinrow-$rem;
-                if ($colsleft > 1) {
-                    $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
-                } else {
-                    $datatable .= '<td class="LC_left_item">';
-                }
-            } else {
-                $datatable .= '<td class="LC_left_item">';
-            }
-            $datatable .= '<span class="LC_nobreak"><label>'.
-                          '<input type="checkbox" name="reqapprovalnotify" '.
-                          'value="'.$domcoord[$i].'"'.$check.'/>'.
-                          $fullname.' ('.$uname.':'.$udom.')</label></span></td>';
-        }
-        $datatable .= '</tr></table>';
+    my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
+                                                 'reqapprovalnotify',%currapp);
+    if ($numdc > 0) {
+        $datatable .= $table;
     } else {
         $datatable .= &mt('There are no active Domain Coordinators');
-        $rows ++;
     }
     $datatable .='</td></tr>';
     $$rowtotal += $rows;
@@ -2127,8 +2087,7 @@
 
 sub print_autocreate {
     my ($dom,$settings,$rowtotal) = @_;
-    my (%createon,%createoff);
-    my $curr_dc;
+    my (%createon,%createoff,%currhash);
     my @types = ('xml','req');
     if (ref($settings) eq 'HASH') {
         foreach my $item (@types) {
@@ -2141,7 +2100,9 @@
                 }
             }
         }
-        $curr_dc = $settings->{'xmldc'};
+        if ($settings->{'xmldc'} ne '') {
+            $currhash{$settings->{'xmldc'}} = 1;
+        }
     } else {
         foreach my $item (@types) {
             $createoff{$item} = ' checked="checked" ';
@@ -2149,6 +2110,7 @@
         }
     }
     $$rowtotal += 2;
+    my $numinrow = 2;
     my $datatable='<tr class="LC_odd_row">'.
                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
@@ -2163,15 +2125,16 @@
                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
                   '<label><input type="radio" name="autocreate_req"'.
                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
-    my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
+    my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
+                                                   'autocreate_xmldc',%currhash);
     if ($numdc > 1) {
         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
                       &mt('Course creation processed as: (choose Dom. Coord.)').
                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
-        $$rowtotal ++ ;
     } else {
         $datatable .= $dctable.'</td></tr>';
     }
+    $$rowtotal += $rows;
     return $datatable;
 }
 
@@ -2390,7 +2353,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'));
 
@@ -2416,17 +2380,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 ++;
     }
@@ -2435,28 +2404,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;
@@ -2464,13 +2436,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;
 }
 
@@ -7829,7 +7829,6 @@
     my ($dom,%domconfig) = @_;
     my ($resulttext,$errors,%changes,%defaultshash);
     my %defaultchecked = ('canuse_pdfforms' => 'off');
-    my @offon = ('off','on');
     my @toggles = ('canuse_pdfforms');
 
     $defaultshash{'coursedefaults'} = {};
@@ -7846,7 +7845,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') {
@@ -7871,14 +7870,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);
             }
@@ -7892,6 +7919,21 @@
                     }
                 } 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>';
+                } 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>';
@@ -8416,73 +8458,94 @@
 
 sub get_active_dcs {
     my ($dom) = @_;
-    my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
+    my $now = time;
+    my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
     my %domcoords;
     my $numdcs = 0;
-    my $now = time;
     foreach my $server (keys(%dompersonnel)) {
         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
-            my ($end,$start) = split(':',$dompersonnel{$server}{$user});
-            if (($end eq '') || ($end == 0) || ($end > $now)) {
-                if ($start <= $now) {
-                    $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
-                }
-            }
+            $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
         }
     }
     return %domcoords;
 }
 
 sub active_dc_picker {
-    my ($dom,$curr_dc) = @_;
+    my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
     my %domcoords = &get_active_dcs($dom); 
-    my @dcs = sort(keys(%domcoords));
-    my $numdcs = scalar(@dcs); 
-    my $datatable;
-    my $numinrow = 2;
+    my @domcoord = keys(%domcoords);
+    if (keys(%currhash)) {
+        foreach my $dc (keys(%currhash)) {
+            unless (exists($domcoords{$dc})) {
+                push(@domcoord,$dc);
+            }
+        }
+    }
+    @domcoord = sort(@domcoord);
+    my $numdcs = scalar(@domcoord);
+    my $rows = 0;
+    my $table;
     if ($numdcs > 1) {
-        $datatable = '<table>';
-        for (my $i=0; $i<@dcs; $i++) {
+        $table = '<table>';
+        for (my $i=0; $i<@domcoord; $i++) {
             my $rem = $i%($numinrow);
             if ($rem == 0) {
                 if ($i > 0) {
-                    $datatable .= '</tr>';
+                    $table .= '</tr>';
                 }
-                $datatable .= '<tr>';
+                $table .= '<tr>';
+                $rows ++;
             }
-            my $check = ' ';
-            if ($curr_dc eq '') {
-                if (!$i) { 
-                    $check = ' checked="checked" ';
+            my $check = '';
+            if ($inputtype eq 'radio') {
+                if (keys(%currhash) == 0) {
+                    if (!$i) {
+                        $check = ' checked="checked"';
+                    }
+                } elsif (exists($currhash{$domcoord[$i]})) {
+                    $check = ' checked="checked"';
+                }
+            } else {
+                if (exists($currhash{$domcoord[$i]})) {
+                    $check = ' checked="checked"';
                 }
-            } elsif ($dcs[$i] eq $curr_dc) {
-                $check = ' checked="checked" ';
             }
-            if ($i == @dcs - 1) {
+            if ($i == @domcoord - 1) {
                 my $colsleft = $numinrow - $rem;
                 if ($colsleft > 1) {
-                    $datatable .= '<td colspan="'.$colsleft.'">';
+                    $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
                 } else {
-                    $datatable .= '<td>';
+                    $table .= '<td class="LC_left_item">';
                 }
             } else {
-                $datatable .= '<td>';
+                $table .= '<td class="LC_left_item">';
+            }
+            my ($dcname,$dcdom) = split(':',$domcoord[$i]);
+            my $user = &Apache::loncommon::plainname($dcname,$dcdom);
+            $table .= '<span class="LC_nobreak"><label>'.
+                      '<input type="'.$inputtype.'" name="'.$name.'"'.
+                      ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
+            if ($user ne $dcname.':'.$dcdom) {
+                $table .=  ' ('.$dcname.':'.$dcdom.')'.
+                           '</label></span></td>';
             }
-            my ($dcname,$dcdom) = split(':',$dcs[$i]);
-            $datatable .= '<span class="LC_nobreak"><label>'.
-                          '<input type="radio" name="autocreate_xmldc"'.
-                          ' value="'.$dcs[$i].'"'.$check.'/>'.
-                          &Apache::loncommon::plainname($dcname,$dcdom).
-                          ' ('.$dcname.':'.$dcdom.')'.
-                          '</label></span></td>';
         }
-        $datatable .= '</tr></table>';
-    } elsif (@dcs) {
-        $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
-                      $dcs[0].'" />';
+        $table .= '</tr></table>';
+    } elsif ($numdcs == 1) {
+        if ($inputtype eq 'radio') {
+            $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
+        } else {
+            my $check;
+            if (exists($currhash{$domcoord[0]})) {
+                $check = ' checked="checked"';
+            }
+            $table .= '<input type="checkbox" name="'.$name.'" '.
+                      'value="'.$domcoord[0].'"'.$check.' />';
+            $rows ++;
+        }
     }
-    return ($numdcs,$datatable);
+    return ($numdcs,$table,$rows);
 }
 
 sub usersession_titles {
@@ -9011,6 +9074,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',


More information about the LON-CAPA-cvs mailing list