--- loncom/interface/lonhtmlcommon.pm	2004/04/12 20:03:31	1.64
+++ loncom/interface/lonhtmlcommon.pm	2004/06/03 16:42:02	1.73
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.64 2004/04/12 20:03:31 albertel Exp $
+# $Id: lonhtmlcommon.pm,v 1.73 2004/06/03 16:42:02 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -163,9 +163,15 @@ sub textbox {
 ##############################################
 ##############################################
 sub checkbox {
-    my ($name,$value) = @_;
-    my $Str = '<input type="checkbox" name="'.$name.'"'.
-	($value?' checked="1"':'').' />';
+    my ($name,$checked,$value) = @_;
+    my $Str = '<input type="checkbox" name="'.$name.'" ';
+    if (defined($value)) {
+        $Str .= 'value="'.$value.'"';
+    } 
+    if ($checked) {
+        $Str .= ' checked="1"';
+    }
+    $Str .= ' />';
     return $Str;
 }
 
@@ -219,10 +225,14 @@ The method used to restrict user input w
 ##############################################
 ##############################################
 sub date_setter {
-    my ($formname,$dname,$currentvalue,$special,$includeempty,$state) = @_;
+    my ($formname,$dname,$currentvalue,$special,$includeempty,$state,
+        $no_hh_mm_ss) = @_;
     if (! defined($state) || $state ne 'disabled') {
         $state = '';
     }
+    if (! defined($no_hh_mm_ss)) {
+        $no_hh_mm_ss = 0;
+    }
     if (! defined($currentvalue) || $currentvalue eq 'now') {
 	unless ($includeempty) {
 	    $currentvalue = time;
@@ -231,7 +241,7 @@ sub date_setter {
 	}
     }
     # other potentially useful values:     wkday,yrday,is_daylight_savings
-    my ($sec,$min,$hour,$mday,$month,$year)=('','','','','','');
+    my ($sec,$min,$hour,$mday,$month,$year)=('','',undef,'','','');
     if ($currentvalue) {
 	($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) = 
 	    localtime($currentvalue);
@@ -305,6 +315,7 @@ ENDJS
     $result .= "  <nobr><select name=\"$dname\_month\" ".$special.' '.
         $state.' '.
         "onChange=\"javascript:$dname\_checkday()\" >\n";
+    # Month
     my @Months = qw/January February  March     April   May      June 
                     July    August    September October November December/;
     # Pad @Months with a bogus value to make indexing easier
@@ -316,39 +327,47 @@ ENDJS
         $result .= "> ".&mt($Months[$m])." </option>\n";
     }
     $result .= "  </select>\n";
+    # Day
     $result .= "  <input type=\"text\" name=\"$dname\_day\" ".$state.' '.
             "value=\"$mday\" size=\"3\" ".$special.' '.
             "onChange=\"javascript:$dname\_checkday()\" />\n";
+    # Year
     $result .= "  <input type=\"year\" name=\"$dname\_year\" ".$state.' '.
             "value=\"$year\" size=\"5\" ".$special.' '.
             "onChange=\"javascript:$dname\_checkday()\" />\n";
     $result .= "&nbsp;&nbsp;";
-    $result .= "  <select name=\"$dname\_hour\" ".$special." ".$state.' '.">\n";
-    if ($includeempty) { $result.="<option value=''></option>"; }
-    for (my $h = 0;$h<24;$h++) {
-        $result .= "      <option value=\"$h\" ";
-        $result .= "selected " if ($hour == $h);
-        $result .= "> ";
-	my $timest='';
-        if ($h == 0) {
-            $timest .= "12 am";
-        } elsif($h == 12) {
-            $timest .= "12 noon";
-        } elsif($h < 12) {
-            $timest .= "$h am";
-        } else {
-            $timest .= $h-12 ." pm";
-        }
-	$timest=&mt($timest);
-        $result .= $timest." </option>\n";
-    } 
-    $result .= "  </select>\n";
-    $result .= "  <input type=\"text\" name=\"$dname\_minute\" ".$special.' '.
-        $state.' '.
-        "value=\"$min\" size=\"3\" /> m\n";
-    $result .= "  <input type=\"text\" name=\"$dname\_second\" ".$special.' '.
-        $state.' '.
-        "value=\"$sec\" size=\"3\" /> s\n";
+    if (! $no_hh_mm_ss) {
+        # Hours
+        $result .= "  <select name=\"$dname\_hour\" ".$special." ".$state.' '.
+            ">\n";
+        if ($includeempty) { $result.="<option value=''></option>"; }
+        for (my $h = 0;$h<24;$h++) {
+            $result .= "      <option value=\"$h\" ";
+            $result .= "selected " if (defined($hour) && $hour == $h);
+            $result .= "> ";
+            my $timest='';
+            if ($h == 0) {
+                $timest .= "12 am";
+            } elsif($h == 12) {
+                $timest .= "12 noon";
+            } elsif($h < 12) {
+                $timest .= "$h am";
+            } else {
+                $timest .= $h-12 ." pm";
+            }
+            $timest=&mt($timest);
+            $result .= $timest." </option>\n";
+        } 
+        $result .= "  </select>\n";
+        $result .= "  <input type=\"text\" name=\"$dname\_minute\" ".
+            $special.' '.
+            $state.' '.
+            "value=\"$min\" size=\"3\" /> m\n";
+        $result .= "  <input type=\"text\" name=\"$dname\_second\" ".
+            $special.' '.
+            $state.' '.
+            "value=\"$sec\" size=\"3\" /> s\n";
+    }
     $result .= "<a href=\"javascript:$dname\_opencalendar()\">".
     &mt('Select Date')."</a></nobr>\n<!-- end $dname date setting form -->\n";
     return $result;
@@ -393,6 +412,8 @@ sub get_date_from_form {
             $sec = $tmpsec;
         }
 	if (!defined($tmpsec) || $tmpsec eq '') { $sec = 0; }
+    } else {
+        $sec = 0;
     }
     if (defined($ENV{'form.'.$dname.'_minute'})) {
         my $tmpmin = $ENV{'form.'.$dname.'_minute'};
@@ -400,12 +421,16 @@ sub get_date_from_form {
             $min = $tmpmin;
         }
 	if (!defined($tmpmin) || $tmpmin eq '') { $min = 0; }
+    } else {
+        $min = 0;
     }
     if (defined($ENV{'form.'.$dname.'_hour'})) {
         my $tmphour = $ENV{'form.'.$dname.'_hour'};
         if (($tmphour =~ /^\d+$/) && ($tmphour >= 0) && ($tmphour < 24)) {
             $hour = $tmphour;
         }
+    } else {
+        $hour = 0;
     }
     if (defined($ENV{'form.'.$dname.'_day'})) {
         my $tmpday = $ENV{'form.'.$dname.'_day'};
@@ -843,25 +868,24 @@ sub crumbs {
 # ------------------------------------------------- Output headers for HTMLArea
 
 sub htmlareaheaders {
-    unless (&htmlareablocked()) { return ''; }
+    if (&htmlareablocked()) { return ''; }
     my $lang='en';
+    if (&mt('htmlarea_lang') ne 'htmlarea_lang') {
+	$lang=&mt('htmlarea_lang');
+    }
     return (<<ENDHEADERS);
 <script type="text/javascript">
-    _editor_url="/htmlarea/";
+_editor_url='/htmlarea/';
+_editor_lang='$lang';
 </script>
 <script type="text/javascript" src="/htmlarea/htmlarea.js"></script>
-<script type="text/javascript" src="/htmlarea/lang/$lang.js"></script>
-<script type="text/javascript" src="/htmlarea/dialog.js"></script>
-<style type="text/css">
-\@import url(/htmlarea/htmlarea.css);
-</style>
 ENDHEADERS
 }
 
 # ---------------------------------------------------------- Script to activate
 
 sub htmlareaactive {
-    unless (&htmlareablocked()) { return ''; }
+    if (&htmlareablocked()) { return ''; }
     return (<<ENDSCRIPT);
 <script type="text/javascript" defer="1">
     HTMLArea.replaceAll();
@@ -869,11 +893,24 @@ sub htmlareaactive {
 ENDSCRIPT
 }
 
+# ----------------------------------------- Script to activate only some fields
+
+sub htmlareaselectactive {
+    my @fields=@_;
+    if (&htmlareablocked()) { return ''; }
+    my $output='<script type="text/javascript" defer="1">';
+    foreach(@fields) {
+	$output.="\nHTMLArea.replace('$_');";
+    }
+    $output.="\nwindow.status='Activated Editfields';\n</script>";
+    return $output;
+}
+
 # --------------------------------------------------------------------- Blocked
 
 sub htmlareablocked {
-    unless (&htmlareabrowser()) { return ''; }
-    return 1;
+    unless (&htmlareabrowser()) { return 1; }
+    return 0;
 }
 
 # ---------------------------------------- Browser capable of running HTMLArea?
@@ -950,23 +987,34 @@ returns: nothing
         # The last breadcrumb does not have a link, so handle it separately.
         my $last = pop(@Crumbs);
         #
-        # The first one should be the course, I guess.
+        # The first one should be the course or a menu link
 	if (!defined($menulink)) { $menulink=1; }
-        if ($menulink && exists($ENV{'request.course.id'})) {
-            my $cid = $ENV{'request.course.id'};
+        if ($menulink) {
+            my $description = 'Menu';
+            if (exists($ENV{'request.course.id'}) && 
+                $ENV{'request.course.id'} ne '') {
+                $description = 
+                    $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
+            }
             unshift(@Crumbs,{
-                             href=>'/adm/menu',
-                             title=>'Go to main menu',
-                             text=>$ENV{'course.'.$cid.'.description'},
-                            });
+                    href   =>'/adm/menu',
+                    title  =>'Go to main menu',
+                    target =>'_top',
+                    text   =>$description,
+                });
         }
         my $links .= 
             join('-&gt;',
                  map {
                      $faq = $_->{'faq'} if (exists($_->{'faq'}));
                      $bug = $_->{'bug'} if (exists($_->{'bug'}));
-                     '<a href="'.$_->{'href'}.'" title="'.&mt($_->{'title'}).'">'.
-                         &mt($_->{'text'}).'</a>' 
+                     my $result = '<a href="'.$_->{'href'}.'" ';
+                     if (defined($_->{'target'}) && $_->{'target'} ne '') {
+                         $result .= 'target="'.$_->{'target'}.'" ';
+                     }
+                     $result .='title="'.&mt($_->{'title'}).'">'.
+                         &mt($_->{'text'}).'</a>';
+                     $result;
                      } @Crumbs
                  );
         $links .= '-&gt;' if ($links ne '');