--- loncom/interface/courseprefs.pm	2011/01/14 00:18:47	1.41
+++ loncom/interface/courseprefs.pm	2012/08/01 17:31:37	1.49.2.3
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set configuration settings for a course
 #
-# $Id: courseprefs.pm,v 1.41 2011/01/14 00:18:47 www Exp $
+# $Id: courseprefs.pm,v 1.49.2.3 2012/08/01 17:31:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -287,7 +287,7 @@ sub handler {
                 defd => 'Default dates for member access',
                 stuv => 'Member-viewable membership list options',
                 stul => 'Member agreement needed to be listed',
-                clas => 'Membership and Facilitator Listing',
+                clas => 'Membership and facilitator listing',
                 priv => 'Privileged users (Domain Coordinators) in facilitator listing',
                 defc => 'Default Community Spreadsheet',
                 defs => 'Default User Spreadsheet',
@@ -314,7 +314,7 @@ sub handler {
                 defd => 'Default dates for student access',
                 stuv => 'Student-viewable classlist options',
                 stul => 'Student agreement needed to be listed',
-                clas => 'Classlists and Staff Listing',
+                clas => 'Classlists and staff listing',
                 priv => 'Privileged users (Domain Coordinators) in staff listing',
                 defc => 'Default Course Spreadsheet',
                 defs => 'Default Student Spreadsheet',
@@ -353,7 +353,7 @@ sub handler {
     my %prefs = (
         'courseinfo' =>
                    { text => $lt{'gens'},
-                     help => 'Course_Environment',
+                     help => 'Course_Prefs_General',
                      ordered => ['owner','co-owners','loncaparev','description',
                                  'courseid','categories','hidefromcat',
                                  'externalsyllabus','cloners','url','rolenames'],
@@ -372,8 +372,8 @@ sub handler {
                                  },
                     },
         'localization' =>
-                    { text => 'Language and Time Localization',
-                      help => 'Course_Environment',
+                    { text => 'Language and time localization',
+                      help => 'Course_Prefs_Language',
                       ordered => ['languages','timezone','datelocale'],
                       itemtext => {
                                     languages  => 'Languages used',
@@ -383,7 +383,7 @@ sub handler {
                     },
         'feedback' =>
                     { text => 'Feedback messages',
-                      help => 'Course_Environment',
+                      help => 'Course_Prefs_Feedback',
                       header => [{col1 => 'Questions about:',
                                   col2 => 'Recipients'}],
                       ordered => ['question.email','comment.email','policy.email'],
@@ -395,11 +395,12 @@ sub handler {
                     },
         'discussion' =>
                     { text => 'Discussion and Chat',
-                      help => 'Course_Environment',
+                      help => 'Course_Prefs_Discussions',
                       ordered => ['pch.roles.denied','pch.users.denied',
                                   'plc.roles.denied','plc.users.denied',
                                   'allow_limited_html_in_feedback',
-                                  'allow_discussion_post_editing'],
+                                  'allow_discussion_post_editing',
+                                  'discussion_post_fonts'],
                       itemtext => {
                          'pch.roles.denied'             => 'No Resource Discussion',
                          'pch.users.denied'             => 'No Resource Discussion',
@@ -407,11 +408,12 @@ sub handler {
                          'plc.users.denied'             => 'No Chat room use',
                          allow_limited_html_in_feedback => 'Allow limited HTML in discussion',
                          allow_discussion_post_editing  => 'Users can edit/delete own discussion posts',
+                         discussion_post_fonts       => 'Discussion post fonts based on likes/unlikes',
                                   },
                     },
         'classlists' =>
                    { text => $lt{'clas'},
-                     help => 'Course_Environment',
+                     help => 'Course_Prefs_Classlists',
                      header => [{col1 => 'Type',
                                  col2 => $lt{'defd'}},
                                 {col1 => 'Setting',
@@ -433,7 +435,7 @@ sub handler {
                    },
         'appearance' =>
                    { text => 'Display of resources ',
-                     help => 'Course_Environment',
+                     help => 'Course_Prefs_Display',
                      ordered => ['default_xml_style','pageseparators',
                                  'disable_receipt_display','texengine',
                                  'tthoptions'],
@@ -447,7 +449,7 @@ sub handler {
                   },
         'grading' =>
                   { text => 'Grading',
-                    help => 'Course_Environment',
+                    help => 'Course_Prefs_Grading',
                     ordered => ['grading','rndseed',
                                 'receiptalg','disablesigfigs'],
                     itemtext => {
@@ -460,10 +462,10 @@ sub handler {
                   },
         'printouts' =>
                   { text => 'Printout generation',
-                    help => 'Course_Environment',
+                    help => 'Course_Prefs_Printouts',
                     ordered => ['problem_stream_switch','suppress_tries',
                                 'default_paper_size','print_header_format',
-                                'disableexampointprint','canuse_pdfforms'],
+                                'disableexampointprint'],
                     itemtext => {
                         problem_stream_switch => 'Allow problems to be split over pages',
                         suppress_tries        => 'Suppress number of tries in printing',
@@ -475,7 +477,7 @@ sub handler {
                   },
         'spreadsheet' =>
                   { text => 'Spreadsheets',
-                    help => 'Course_Environment',
+                    help => 'Course_Prefs_Spreadsheet',
                     ordered => ['spreadsheet_default_classcalc',
                                 'spreadsheet_default_studentcalc',
                                 'spreadsheet_default_assesscalc','hideemptyrows'],
@@ -488,7 +490,7 @@ sub handler {
                   },
         'bridgetasks' =>
                   { text => 'Bridge tasks',
-                    help => 'Course_Environment',
+                    help => 'Course_Prefs_Bridgetasks',
                     ordered => ['task_messages','task_grading',
                                 'suppress_embed_prompt'],
                     itemtext => {
@@ -499,7 +501,7 @@ sub handler {
                   },
         'other' =>
                   { text => 'Other settings',
-                    help => 'Course_Environment',
+                    help => 'Course_Prefs_Other',
                     header => [ {col1 => 'Item',
                                  col2 => 'Value',
                               }],
@@ -509,15 +511,15 @@ sub handler {
         my @allitems = &get_allitems(%prefs);
         &Apache::lonconfigsettings::make_changes($r,$cdom,$phase,$context,
                                                  \@prefs_order,\%prefs,\%values,
-                                                  $cnum,undef,\@allitems);
+                                                  $cnum,undef,\@allitems,'coursepref');
     } elsif ($phase eq 'display') {
         my $jscript = &get_jscript($cid,$cdom,$phase,$crstype);
         my @allitems = &get_allitems(%prefs);
         &Apache::lonconfigsettings::display_settings($r,$cdom,$phase,$context,
-            \@prefs_order,\%prefs,\%values,undef,$jscript,\@allitems,$crstype);
+            \@prefs_order,\%prefs,\%values,undef,$jscript,\@allitems,$crstype,'coursepref');
     } else {
         &Apache::lonconfigsettings::display_choices($r,$phase,$context,
-                                                    \@prefs_order,\%prefs);
+                                                    \@prefs_order,\%prefs,'coursepref');
     }
     return OK;
 }
@@ -544,11 +546,16 @@ sub print_config_box {
     my $itemtext = $item->{'itemtext'};
     my $rowtotal = 0;
     my $output =
-        '<h3><a href="#">'.&mt($item->{text}).'</a></h3>
-        <div>&nbsp;<span style="float:right">'.
-         &Apache::loncommon::help_open_topic($item->{'help'}).'</span>';
+         '<table class="LC_nested_outer">
+          <tr>
+           <th align="left" valign="middle"><span class="LC_nobreak" style="font-size: larger;" >'.
+           &mt($item->{text}).'&nbsp;'.
+           &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
+          '</tr>';
     if (($action eq 'feedback') || ($action eq 'classlists')) {
         $output .= '
+          <tr>
+           <td>
             <table class="LC_nested">';   
         if (exists $item->{'header'}->[0]->{'col1'} || 
             exists $item->{'header'}->[0]->{'col2'}) {
@@ -566,6 +573,10 @@ sub print_config_box {
         }
         $output .= '
            </table>
+          </td>
+         </tr>
+         <tr>
+          <td>
             <table class="LC_nested">
              <tr class="LC_info_row">
               <td class="LC_left_item">'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
@@ -576,18 +587,24 @@ sub print_config_box {
             $output .= &print_classlists('middle',$cdom,$settings,$itemtext,\$rowtotal,$crstype).
                        '
             </table>
+           </td>
+          </tr>
+          <tr>
+           <td>
             <table class="LC_nested">';
-            if (exists $item->{'header'}->[0]->{'col1'} || 
-            	exists $item->{'header'}->[0]->{'col2'}) {
+            if (exists $item->{'header'}->[2]->{'col1'} || 
+            	exists $item->{'header'}->[2]->{'col2'}) {
 				$output .= '          
 				<tr class="LC_info_row">
-				  <td class="LC_left_item">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
-				  <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
+				  <td class="LC_left_item">'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
+				  <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
 				</tr>';
         	}
         }
     } else {
         $output .= '
+          <tr>
+           <td>
             <table class="LC_nested">';
         if (exists $item->{'header'}->[0]->{'col1'} || 
             exists $item->{'header'}->[0]->{'col2'}) {
@@ -624,7 +641,9 @@ sub print_config_box {
     }
     $output .= '
    </table>
-</div>';
+  </td>
+ </tr>
+</table><br />';
     return ($output,$rowtotal);
 }
 
@@ -648,7 +667,21 @@ sub process_changes {
                     }
                 }
             } elsif (ref($item->{'ordered'}) eq 'ARRAY') {
-                @ordered = @{$item->{'ordered'}};
+                if ($action eq 'courseinfo') {
+                    my ($can_toggle_cat,$can_categorize) =
+                        &can_modify_catsettings($cdom,$crstype);
+                    foreach my $entry (@{$item->{'ordered'}}) {
+                        next if (($entry eq 'hidefromcat') &&
+                                 (!$can_toggle_cat));
+                        next if (($entry eq 'categories') &&
+                                 (!$can_categorize));
+                        next if (($entry eq 'loncaparev') || 
+                                ($entry eq 'owner'));
+                        push(@ordered,$entry);
+                    }
+                } else {
+                    @ordered = @{$item->{'ordered'}};
+                }
             }
             if (@ordered > 0) {
                 if ($action eq 'feedback') {
@@ -690,7 +723,6 @@ sub process_changes {
                     }
                 } else {
                     foreach my $entry (@ordered) {
-                        next if (($entry eq 'loncaparev') || ($entry eq 'owner'));
                         if ($entry eq 'cloners') {
                             if ($env{'form.cloners_all'}) {
                                 $newvalues{$entry} = '*';
@@ -957,6 +989,35 @@ sub process_changes {
                                 }
                             }
                             $newvalues{$entry} =~ s/,$//;
+                        } elsif ($entry eq 'discussion_post_fonts') {
+                            my ($classorder,$classtitles) = &discussion_vote_classes();
+                            my $fontchange = 0;
+                            foreach my $class (@{$classorder}) {
+                                my $ext_entry = $entry.'_'.$class;
+                                my $size = $env{'form.'.$ext_entry.'_size'};
+                                my $unit = $env{'form.'.$ext_entry.'_unit'};
+                                my $weight = $env{'form.'.$ext_entry.'_weight'};
+                                my $style = $env{'form.'.$ext_entry.'_style'};
+                                my $other = $env{'form.'.$ext_entry.'_other'};
+                                $size =~ s/,//g;
+                                $unit =~ s/,//g;
+                                $weight =~ s/,//g;
+                                $style =~ s/,//g;
+                                $other =~ s/[^\w;:\s\-\%.]//g;
+                                $other =~ s/(^\s+|\s+$)//g;
+                                $newvalues{$ext_entry} = join(',',($size.$unit,$weight,$style,$other));
+                                my $current = $values->{$ext_entry};
+                                if ($values->{$ext_entry} eq '') {
+                                    $current = ',,,';
+                                }
+                                if ($newvalues{$ext_entry} ne $current) {
+                                    $changes->{$ext_entry} = $newvalues{$ext_entry};
+                                    $fontchange ++;
+                                }
+                            }
+                            if ($fontchange) {
+                                $changes->{$entry} = 1;
+                            }
                         } elsif ($entry eq 'nothideprivileged') {
                             my @curr_nothide;
                             my @new_nothide;
@@ -1060,7 +1121,7 @@ sub process_changes {
                         } else {
                             $newvalues{$entry} = $env{'form.'.$entry};
                         }
-                        unless ($entry eq 'co-owners') {
+                        unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts')) {
                             if ($newvalues{$entry} ne $values->{$entry}) {
                                 $changes->{$entry} = $newvalues{$entry};
                             }
@@ -1187,7 +1248,7 @@ sub store_changes {
                                     my ($displayname,$text);
                                     $text = $prefs->{$item}->{'itemtext'}{$key};
                                     my $displayval;
-                                    unless ($key eq 'co-owners') {
+                                    unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts')) {
                                         $displayval = $changes->{$item}{$key};
                                     }
                                     if ($item eq 'feedback') {
@@ -1223,6 +1284,36 @@ sub store_changes {
                                                     }
                                                     $displayval = join(', ',@longroles);
                                                 }
+                                            } elsif ($key eq 'discussion_post_fonts') {
+                                                my ($classorder,$classtitles)=&discussion_vote_classes();
+                                                my ($styleorder,$styleitems)=&discussion_vote_styles();
+                                                my $count = 1;
+                                                my $total = scalar(keys(%{$changes->{$item}}));
+                                                foreach my $class (@{$classorder}) {
+                                                    $count ++;
+                                                    next unless ($changes->{$item}{$key.'_'.$class});
+                                                    my @vals = split(/,/,$changes->{$item}{$key.'_'.$class});
+                                                    my $showval = '';
+                                                    for (my $i=0; $i<@{$styleorder}; $i++) {
+                                                        if ($vals[$i] ne '') {
+                                                            $showval .= 'font-'.$styleorder->[$i].': '.$vals[$i].'; ';
+                                                        }
+                                                    }
+                                                    if ($vals[3] ne '') {
+                                                        $showval .= $vals[3];
+                                                    }
+                                                    if ($showval ne '') {
+                                                        $displayval .= $classtitles->{$class}.':{ '.
+                                                                       $showval.'}';
+                                                        $storehash{$key.'_'.$class} = $changes->{$item}{$key.'_'.$class};
+                                                    } else {
+                                                        $displayval .= $classtitles->{$class}.': '.&mt('None');
+                                                        push(@delkeys,$key.'_'.$class);
+                                                    }
+                                                    unless ($count == $total) {
+                                                        $displayval .= ('&nbsp;'x2);
+                                                    }
+                                                }
                                             }
                                             $displayname = &mt($text);
                                         }
@@ -1322,7 +1413,9 @@ sub store_changes {
                                             }
                                         }
                                     } else {
-                                        $storehash{$key} = $changes->{$item}{$key};
+                                        unless ($key eq 'discussion_post_fonts') {
+                                            $storehash{$key} = $changes->{$item}{$key};
+                                        }
                                     }
                                 }
                                 if ($key eq 'cloners') {
@@ -1346,9 +1439,9 @@ sub store_changes {
                     $output .= '</ul>';
                 } else {
                     if ($crstype eq 'Community') {
-                        $output = &mt('No changes made to community settings.');
+                        $output .= &mt('No changes made to community settings.');
                     } else {
-                        $output = &mt('No changes made to course settings.');
+                        $output .= &mt('No changes made to course settings.');
                     }
                 }
             }
@@ -2375,7 +2468,7 @@ sub show_contents_view {
                     }
                     $r->print(&Apache::loncommon::start_data_table_row().
                               '<td rowspan="'.$rowspan.'">'.$indent.$icon.'&nbsp;'.$title.'</td>');
-                    &releases_by_map($r,$bymap,$url,$scopeorder);
+                    &releases_by_map($r,$bymap,$url,$scopeorder,$lt);
                     $r->print(&Apache::loncommon::end_data_table_row());
                 } else {
                     my $rowspan;
@@ -2940,6 +3033,11 @@ sub print_discussion {
                    text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
                    input => 'checkbox',
                  },
+        'discussion_post_fonts' => {
+                   text => '<b>'.&mt($itemtext->{'discussion_post_fonts'}).'</b>',
+                   input => 'textbox',
+                   size  => '20',
+                 },
     );
     my $datatable;
     my $count;
@@ -2979,6 +3077,17 @@ sub print_discussion {
                           &Apache::loncommon::end_data_table_row().
                           &role_checkboxes($cdom,$cnum,$item,$settings,1).
                           &Apache::loncommon::end_data_table();
+        } elsif ($item eq 'discussion_post_fonts') {
+            $datatable .= &Apache::loncommon::start_data_table().
+                          &Apache::loncommon::start_data_table_row().
+                          '<th align="center">'.&mt('Sum of likes/dislikes').'</th>'.
+                          '<th align="center">'.&mt('font-size').'</th>'.
+                          '<th align="center">'.&mt('font-weight').'</th>'.
+                          '<th align="center">'.&mt('font-style').'</th>'.
+                          '<th align="center">'.&mt('Other css').'</th>'.
+                          &Apache::loncommon::end_data_table_row().
+                          &set_discussion_fonts($cdom,$cnum,$item,$settings).
+                          &Apache::loncommon::end_data_table();
         }
         $datatable .= &item_table_row_end();
     }
@@ -3100,6 +3209,75 @@ sub role_checkboxes {
     return $output;
 }
 
+sub set_discussion_fonts {
+    my ($cdom,$cnum,$item,$settings) = @_;
+    my ($classorder,$classtitles) = &discussion_vote_classes();
+    my ($styleorder,$styleitems) = &discussion_vote_styles();
+    my $output;
+    if (ref($classorder) eq 'ARRAY') {
+        foreach my $cat (@{$classorder}) {
+            my %curr = ();
+            ($curr{'size'},$curr{'weight'},$curr{'style'},$curr{'other'}) =
+                split(/,/,$settings->{'discussion_post_fonts_'.$cat});
+            $output .= &Apache::loncommon::start_data_table_row().
+                       '<td>'.$classtitles->{$cat}.'</td>';
+            if (ref($styleorder) eq 'ARRAY') {
+                foreach my $item (@{$styleorder}) {
+                    $output .= '<td><span class="LC_nobreak">';
+                    my $selitem = $item;
+                    if ($item eq 'size') {
+                        my ($currsize,$currunit);
+                        if ($curr{'size'} =~ /^(\d+)(px|%)$/) {
+                            ($currsize,$currunit) = ($1,$2);
+                            $curr{'size'} = $currunit;
+                        }
+                        $output .= '<input type="textbox" name="discussion_post_fonts_'.$cat.'_'.$item.'" value="'.$currsize.'" size="5">'.
+                                   '&nbsp;';
+                        $selitem = 'unit';
+                    }
+                    if ((ref($styleitems) eq 'HASH') && (ref($styleitems->{$item}) eq 'ARRAY')) {
+                        $output .= '<select name="discussion_post_fonts_'.$cat.'_'.$selitem.'">';
+                        foreach my $val (@{$styleitems->{$item}}) {
+                            my $sel;
+                            if ($val eq $curr{$item}) {
+                                $sel = ' selected="selected"';
+                            }
+                            $output .= '<option value="'.$val.'"'.$sel.'>'.$val.'</option>';
+                        }
+                    }
+                }
+            }
+            $output .= '</span></td><td><input type="textbox" size="10" name="discussion_post_fonts_'.$cat.'_other" value="'.$curr{'other'}.'" /></td>';
+       }
+       $output .= &Apache::loncommon::end_data_table_row();
+    }
+    return $output;
+}
+
+sub discussion_vote_classes {
+    my $classorder = ['twoplus','oneplus','zero','oneminus','twominus'];
+    my %classtitles = &Apache::lonlocal::texthash(
+                        'twoplus'  => 'Two sigma above mean',
+                        'oneplus'  => 'One sigma above mean',
+                        'zero'     => 'Within one sigma of mean',
+                        'oneminus' => 'One sigma below mean',
+                        'twominus' => 'Two sigma below mean',
+                      );
+    return ($classorder,\%classtitles);
+}
+
+sub discussion_vote_styles {
+    my $styleorder = ['size','weight','style'];
+    my $styleitems = {
+                         size => ['','px','%','xx-small','x-small','small','medium','large',
+                                  'x-large','xx-large','smaller','larger'],
+                         weight => ['','normal','bold','bolder','lighter','100','200','300','400',
+                                    '500','600','700','800','900'],
+                         style => ['','normal','italic','oblique'],
+                     };
+    return ($styleorder,$styleitems);
+}
+
 sub print_classlists {
     my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype) = @_;
     my @ordered;
@@ -3228,12 +3406,11 @@ sub print_grading {
                    input => 'selectbox',
                    options => {
                                 standard => &mt('Standard: shows points'),
-                                categories => &mt('Categories: shows points according to categories'),
                                 external => &mt('External: shows number of completed parts and totals'),
                                 externalnototals => &mt('External: shows only number of completed parts'),
                                 spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'), 
                               },
-                   order => ['standard','categories','external','externalnototals','spreadsheet'],
+                   order => ['standard','external','externalnototals','spreadsheet'],
                  },
         'rndseed' => {
                    text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
@@ -3442,7 +3619,8 @@ sub get_other_items {
             unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
                     ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
                     || ($parameter eq 'type') ||
-                    ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)) {
+                    ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)
+                    || ($parameter =~ m/^discussion_post_fonts/)) {
                 push(@ordered,$parameter);
             }
         }