--- loncom/interface/lonhtmlcommon.pm	2010/05/30 18:30:52	1.273
+++ loncom/interface/lonhtmlcommon.pm	2010/08/30 02:55:17	1.283
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.273 2010/05/30 18:30:52 droeschl Exp $
+# $Id: lonhtmlcommon.pm,v 1.283 2010/08/30 02:55:17 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -121,7 +121,7 @@ sub dragmath_button {
     my ($textarea,$helpicon) = @_;
     my $help_text; 
     if ($helpicon) {
-        $help_text = &Apache::loncommon::help_open_topic('Authoring_Math_Editor');
+        $help_text = &Apache::loncommon::help_open_topic('Authoring_Math_Editor',undef,undef,undef,undef,'mathhelpicon_'.$textarea);
     }
     my $buttontext=&mt('Edit Math');
     return <<ENDDRAGMATH;
@@ -927,7 +927,7 @@ Returns: none
 
 =item Increment_PrgWin
 
-Increment the count of items completed for the progress window by 1.  
+Increment the count of items completed for the progress window by $step or 1 if no step is provided.
 
 Inputs:
 
@@ -940,6 +940,8 @@ Inputs:
 =item $extraInfo A description of the items being iterated over.  Typically
 'student'.
 
+=item $step (optional) counter step. Will be set to default 1 if ommited. step must be greater than 0 or empty.
+
 =back
 
 Returns: none
@@ -1049,30 +1051,25 @@ sub Update_PrgWin {
 
 # increment progress state
 sub Increment_PrgWin {
-    my ($r,$prog_state,$extraInfo)=@_;
-    $$prog_state{'done'}++;
+    my ($r,$prog_state,$extraInfo,$step)=@_;
+    $step = $step > 0 ? $step : 1;
+    $$prog_state{'done'} += $step;
+
+    # Catch (max modulo step) <> 0
+    my $current = $$prog_state{'done'};
+    my $last = ($$prog_state{'max'} - $current);
+    if ($last <= 0) {
+        $last = 1;
+        $current = $$prog_state{'max'};
+    }
+
     my $time_est= (&Time::HiRes::time() - $$prog_state{'firststart'})/
-        $$prog_state{'done'} *
-	($$prog_state{'max'}-$$prog_state{'done'});
+        $current * $last;
     $time_est = int($time_est);
     #
     my $min = int($time_est/60);
     my $sec = $time_est % 60;
-    # 
-    my $str;
-    if ($min == 0 && $sec > 1) {
-        $str = '[_1] seconds';
-    } elsif ($min == 1 && $sec > 1) {
-        $str = '1 minute [_2] seconds';
-    } elsif ($min == 1 && $sec < 2) {
-        $str = '1 minute';
-    } elsif ($min < 10 && $sec > 1) {
-        $str = '[_1] minutes, [_2] seconds';
-    } elsif ($min >= 10 || $sec < 2) {
-        $str = '[_1] minutes';
-    }
-    $time_est = &mt($str,$min,$sec);
-    #
+
     my $lasttime = &Time::HiRes::time()-$$prog_state{'laststart'};
     if ($lasttime > 9) {
         $lasttime = int($lasttime);
@@ -1081,27 +1078,24 @@ sub Increment_PrgWin {
     } else {
         $lasttime = sprintf("%3.2f",$lasttime);
     }
-    if ($lasttime == 1) {
-        $lasttime = '('.$lasttime.' '.&mt('second for').' '.$extraInfo.')';
-    } else {
-        $lasttime = '('.$lasttime.' '.&mt('seconds for').' '.$extraInfo.')';
-    }
-    #
-    my $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
-    my $user_os      = $env{'browser.os'}   if (exists($env{'browser.os'}));
-    if (! defined($user_browser) || ! defined($user_os)) {
-        (undef,$user_browser,undef,undef,undef,$user_os) = 
-                           &Apache::loncommon::decode_user_agent();
-    }
-    if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
-        $lasttime = '';
-    }
+
+    $sec = 0 if ($min >= 10); # Don't show seconds if remaining time >= 10 min.
+    $sec = 1 if ( ($min == 0) && ($sec == 0) ); # Little cheating: pretend to have 1 second remaining instead of 0 to have something to display
+
+    my $timeinfo =
+        &mt('[_1]/[_2]:'
+           .' [quant,_3,minute,minutes,] [quant,_4,second ,seconds ,]remaining'
+           .' ([quant,_5,second] for '.$extraInfo.')',
+            $current,
+            $$prog_state{'max'},
+            $min,
+            $sec,
+            $lasttime);
+
     &r_print($r,&Apache::lonhtmlcommon::scripttag(
         $$prog_state{'window'}.'.document.'.
         $$prog_state{'formname'}.'.'.
-        $$prog_state{'inputname'}.'.value="'.
-        $$prog_state{'done'}.'/'.$$prog_state{'max'}.
-        ': '.$time_est.' '.&mt('remaining').' '.$lasttime.'";'
+        $$prog_state{'inputname'}.'.value="'.$timeinfo.'";'
     ));
     $$prog_state{'laststart'}=&Time::HiRes::time();
 }
@@ -1218,23 +1212,7 @@ sub spelllink {
 ENDLINK
 }
 
-# ------------------------------------------------- Output headers for HTMLArea
-
-{
-    my @htmlareafields;
-    sub init_htmlareafields {
-	undef(@htmlareafields);
-    }
-    
-    sub add_htmlareafields {
-	my (@newfields) = @_;
-	push(@htmlareafields,@newfields);
-    }
-
-    sub get_htmlareafields {
-	return @htmlareafields;
-    }
-}
+# ------------------------------------------------- Output headers for CKEditor
 
 sub htmlareaheaders {
 	my $s="";
@@ -1253,22 +1231,6 @@ ENDJQUERY
 
 # ----------------------------------------------------------------- Preferences
 
-sub disablelink {
-    my @fields=@_;
-    if (defined($#fields)) {
-	unless ($#fields>=0) { return ''; }
-    }
-    return '<a href="'.&HTML::Entities::encode('/adm/preferences?action=set_wysiwyg&wysiwyg=off&returnurl=','<>&"').&escape($ENV{'REQUEST_URI'}).'">'.&mt('Disable WYSIWYG Editor').'</a>';
-}
-
-sub enablelink {
-    my @fields=@_;
-    if (defined($#fields)) {
-	unless ($#fields>=0) { return ''; }
-    }
-    return '<a href="'.&HTML::Entities::encode('/adm/preferences?action=set_wysiwyg&wysiwyg=on&returnurl=','<>&"').&escape($ENV{'REQUEST_URI'}).'">'.&mt('Enable WYSIWYG Editor').'</a>';
-}
-
 # ------------------------------------------------- lang to use in html editor
 sub htmlarea_lang {
     my $lang='en';
@@ -1281,22 +1243,45 @@ sub htmlarea_lang {
 # ----------------------------------------- Script to activate only some fields
 
 sub htmlareaselectactive {
-    my @fields=@_;
+    my ($args) = @_; 
     unless (&htmlareabrowser()) { return ''; }
     my $output='<script type="text/javascript" defer="defer">'."\n"
               .'// <![CDATA['."\n";
     my $lang = &htmlarea_lang();
+    my $fullpage = 'false';
+    my ($dragmath_prefix,$dragmath_helpicon,$dragmath_whitespace);
+    if (ref($args) eq 'HASH') {
+        if (exists($args->{'lang'})) {
+            if ($args->{'lang'} ne '') {
+                $lang = $args->{'lang'};
+            }
+        }
+        if (exists($args->{'fullpage'})) { 
+            if ($args->{'fullpage'} eq 'true') {
+                $fullpage = $args->{'fullpage'};
+            }
+        }
+        if (exists($args->{'dragmath'})) {
+            if ($args->{'dragmath'} ne '') {
+                $dragmath_prefix = $args->{'dragmath'};
+                $dragmath_helpicon=&Apache::loncommon::lonhttpdurl("/adm/help/help.png");
+                $dragmath_whitespace=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/transparent1x1.gif");
+            }
+        }
+    }
     $output.='
     
     function containsBlockHtml(id) {
-		var re = $("#"+id).html().search(/(?:\&lt\;|\<)(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div)[\s]*((?:\/[\s]*(?:\&gt\;|\>)|(?:\&gt\;|\>)[\s\S]*(?:\&lt\;|\<)\/[\s]*\1[\s]*\(?:\&gt\;|\>))/im);
+		var re = $("#"+id).html().search(/(?:\&lt\;|\<)(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div)[\s]*((?:[\/]*[\s]*(?:\&gt\;|\>)|(?:\&gt\;|\>)[\s\S]*(?:\&lt\;|\<)\/[\s]*\1[\s]*\(?:\&gt\;|\>))/im);
     	return (re >= 0);
     }
     
     function startRichEditor(id) {
     	CKEDITOR.replace(id, 
     		{
-    			customConfig: "/ckeditor/loncapaconfig.js"
+    			customConfig: "/ckeditor/loncapaconfig.js",
+                        language : "'.$lang.'",
+                        fullPage : '.$fullpage.',
     		}
     	);
     }
@@ -1307,9 +1292,10 @@ sub htmlareaselectactive {
     
     function editorHandler(event) {
     	var rawid = $(this).attr("id");
-    	var id = new RegExp("LC_rt_(.*)").exec(rawid)[1]
+    	var id = new RegExp("LC_rt_(.*)").exec(rawid)[1];
     	event.preventDefault();
-    	if ($(this).hasClass("LC_enable_rt")) {
+    	var rt_enabled  = $(this).hasClass("LC_enable_rt");
+        if (rt_enabled) {
     		startRichEditor(id);
 			$("#LC_rt_"+id).html("<b>&laquo; Plain text</b>");
 			$("#LC_rt_"+id).attr("title", "Disable rich text formatting and edit in plain text");
@@ -1321,24 +1307,40 @@ sub htmlareaselectactive {
 			$("#LC_rt_"+id).attr("title", "Enable rich text formatting (bold, italic, etc.)");
 			$("#LC_rt_"+id).addClass("LC_enable_rt");
 			$("#LC_rt_"+id).removeClass("LC_disable_rt");
-		}
-	}
-    
+	}';
+    if ($dragmath_prefix ne '') {
+        $output .= "\n                 var visible = '';
+                                       if (rt_enabled) {
+                                           visible = 'none';
+                                       }
+                                       editmath_visibility(id,visible);\n";
+    }
+    $output .= '
+    }
     $(document).ready(function(){
 		$(".LC_richAlwaysOn").each(function() {
 			startRichEditor($(this).attr("id"));
 		});
 		$(".LC_richDetectHtml").each(function() {
 			var id = $(this).attr("id");
-			if(containsBlockHtml(id)) {
+                        var rt_enabled = containsBlockHtml(id);
+			if(rt_enabled) {
 				$(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Disable rich text formatting and edit in plain text\" class=\"LC_disable_rt\"><b>&laquo; Plain text</b></a></div>");				
 				startRichEditor(id);
-				$("#LC_rt_"+id).click(editorHandler);				
+				$("#LC_rt_"+id).click(editorHandler);
 			}
 			else {
 				$(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Enable rich text formatting (bold, italic, etc.)\" class=\"LC_enable_rt\"><b>Rich formatting &raquo;</b></a></div>");
 				$("#LC_rt_"+id).click(editorHandler);
-			}
+			}';
+    if ($dragmath_prefix ne '') {
+        $output .= "\n                 var visible = '';
+                                       if (rt_enabled) {
+                                           visible = 'none';
+                                       }
+                                       editmath_visibility(id,visible);\n";
+    }
+    $output .= '
 		});
 		$(".LC_richDefaultOn").each(function() {
 			var id = $(this).attr("id");
@@ -1349,14 +1351,41 @@ sub htmlareaselectactive {
 		$(".LC_richDefaultOff").each(function() {
 			var id = $(this).attr("id");
 			$(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Enable rich text formatting (bold, italic, etc.)\" class=\"LC_enable_rt\"><b>Rich formatting &raquo;</b></a></div>");
-			$("#LC_rt_"+id).click(editorHandler);			
+			$("#LC_rt_"+id).click(editorHandler);
 		});
-		
 	});
-'; 
+';
+    if ($dragmath_prefix ne '') {
+        $output .= '
+
+     function editmath_visibility(id,value) {
+
+         if ((id == "") || (id == null)) {
+             return;
+         }
+         var mathid = "'.$dragmath_prefix.'_"+id;
+         mathele = document.getElementById(mathid);
+         if (mathele == null) {
+             return;
+         }
+         mathele.style.display = value;
+         var mathhelpicon = "'.$dragmath_prefix.'helpicon'.'_"+id;
+         mathhelpiconele = document.getElementById(mathhelpicon);
+         if (mathhelpiconele == null) {
+             return;
+         }
+         if (value == "none") {
+             mathhelpiconele.src = "'.$dragmath_whitespace.'";
+         } else {
+             mathhelpiconele.src = "'.$dragmath_helpicon.'";
+         }
+     }
+';
+
+    }
     $output.="\nwindow.status='Activated Editfields';\n"
             .'// ]]>'."\n"
-            .'</script><br />';
+            .'</script>';
     return $output;
 }
 
@@ -1481,7 +1510,10 @@ returns: nothing
         my $lasttext = $last->{'no_mt'} ? $last->{'text'} 
                      : mt( $last->{'text'} );
 
-        $links .= htmltag( 'li', htmltag('h1', $lasttext), {title => $lasttext});
+        # last breadcrumb is the first order heading of a page
+        # for course breadcrumbs it's just bold
+        $links .= htmltag( 'li', htmltag($CourseBreadcrumbs ? 'b' : 'h1',
+                $lasttext), {title => $lasttext});
 
         my $icons = '';
         $faq  = $last->{'faq'}  if (exists($last->{'faq'}));
@@ -1812,15 +1844,15 @@ sub role_select_row {
 
 sub course_select_row {
     my ($title,$formname,$totcodes,$codetitles,$idlist,$idlist_titles,
-	$css_class,$crstype) = @_;
+	$css_class,$crstype,$standardnames) = @_;
     my $output = &row_title($title,$css_class);
-    $output .= &course_selection($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype);
+    $output .= &course_selection($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype,$standardnames);
     $output .= &row_closure();
     return $output;
 }
 
 sub course_selection {
-    my ($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype) = @_;
+    my ($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype,$standardnames) = @_;
     my $output = qq|
 <script type="text/javascript">
 // <![CDATA[
@@ -1867,7 +1899,7 @@ sub course_selection {
         if ($numtitles > 0) {
             $output .= '<input type="radio" name="coursepick" value="category" onclick="coursePick(this.form);alert('."'".&mt('Choose categories, from left to right')."'".')" />'.&mt('Pick courses by category:').' <br />';
             $output .= '<table><tr><td>'.$$codetitles[0].'<br />'."\n".
-               '<select name="'.$$codetitles[0].
+               '<select name="'.$standardnames->[0].
                '" onChange="setPick(this.form);courseSet('."'$$codetitles[0]'".')">'."\n".
                ' <option value="-1" />Select'."\n";
             my @items = ();
@@ -1897,7 +1929,7 @@ sub course_selection {
             $output .= '</select></td>';
             for (my $i=1; $i<$numtitles; $i++) {
                 $output .= '<td>'.$$codetitles[$i].'<br />'."\n".
-                          '<select name="'.$$codetitles[$i].
+                          '<select name="'.$standardnames->[$i].
                           '" onChange="courseSet('."'$$codetitles[$i]'".')">'."\n".
                           '<option value="-1">&lt;-Pick '.$$codetitles[$i-1].'</option>'."\n".
                           '</select>'."\n".
@@ -2443,11 +2475,15 @@ sub generate_menu {
             # create the markup for the current $link and push it into @links.
             # each entry consists of an image and a text optionally followed 
             # by a help link.
+            my $src;
+            if ($$link{icon} ne '') {
+                $src = '/res/adm/pages/'.$$link{icon};
+            }
             push(@links,$li->(
                         $a->(
                             $img->("", {
                                 class => "LC_noBorder LC_middle",
-                                src   => "/res/adm/pages/$$link{icon}",
+                                src   => $src,
                                 alt   => mt(defined($$link{alttext}) ?
                                 $$link{alttext} : $$link{linktext})
                             }), {