--- loncom/xml/londefdef.pm	2010/11/13 01:43:01	1.403.4.3
+++ loncom/xml/londefdef.pm	2011/09/15 19:10:45	1.415.4.4
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.403.4.3 2010/11/13 01:43:01 raeburn Exp $
+# $Id: londefdef.pm,v 1.415.4.4 2011/09/15 19:10:45 raeburn Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -48,6 +48,7 @@ use Image::Magick;
 use Apache::lonmenu();
 use Apache::lonmeta();
 use Apache::lonlocal;
+use Apache::loncommon();
 use Apache::Constants qw(:common);
 use File::Basename;
 use LONCAPA();
@@ -538,29 +539,58 @@ sub start_body {
 	
 	my $extra_head = &generate_css_links();
 
+    # Breadcrumbs
+    &Apache::lonhtmlcommon::clear_breadcrumbs();
+    if ($env{'request.state'} eq 'construct') {
+        &Apache::lonhtmlcommon::add_breadcrumb({
+            'text'  => 'Construction Space',
+            'href'  => &Apache::loncommon::authorspace(),
+        });
+        &Apache::lonhtmlcommon::add_breadcrumb({
+            'text'  => 'HTML Editor',
+            'href'  => '',
+        });
+        # breadcrumbs (and tools) will be created 
+        # in start_page->bodytag->innerregister
+    } else {
+        # FIXME Where are we?
+    }
+
 	$currentstring = 
 	    &Apache::loncommon::start_page($Apache::londefdef::title,
 					   $Apache::londefdef::head
 					      .$extra_head,
 					   {'add_entries'    => $token->[2],
-					    'no_title'       => 1,
+#					    'no_title'       => 1,
 					    'force_register' => 1});
 
-	if ($env{'request.state'} ne 'published') {
-	    $currentstring.=&Apache::lonmenu::constspaceform();
-	    $currentstring.=&Apache::londefdef::edit_controls();
-	}
-	$currentstring.=&Apache::lonxml::message_location();
+        my $header = '';
+        if ($env{'request.state'} ne 'published' &&
+            $env{'request.state'} ne 'construct') {
+            $header=&Apache::lonmenu::constspaceform();
+        }
+        if ($env{'request.state'} ne 'published') {
+            $header.=&Apache::londefdef::edit_controls();
+        }
+        if ($env{'request.state'} eq 'construct') {
+            $currentstring.=&Apache::loncommon::head_subbox(
+                                &Apache::loncommon::CSTR_pageheader()
+                               .$header);
+        } elsif ($env{'request.state'} eq 'edit') {
+            $currentstring.=&Apache::loncommon::head_subbox($header);
+        }
+        $currentstring.=&Apache::lonxml::message_location();
     } elsif ($target eq 'tex') {
-	$currentstring = '';   #  '\begin{document}' is in header.
-    } 
+        $currentstring = '';   #  '\begin{document}' is in header.
+    }
+
     return $currentstring;
 }
 
 sub edit_controls {
     my ($nochgview) = @_;
     my $result .= '
-<form method="post">
+<form method="post" action="">
 <div class="LC_edit_problem_header">';
     unless ($nochgview) {
         $result .= '
@@ -570,9 +600,19 @@ sub edit_controls {
 </div>';
     }
     $result .= '
-<div class="LC_edit_problem_header_edit_row"><input type="submit" name="editmode" accesskey="e" value="'.&mt('Edit').'" /></div></div>
+<div><input type="submit" name="editmode" accesskey="e" value="'.&mt('Edit').'" />';
+    if (($env{'request.course.id'}) && ($env{'form.forceedit'})) {
+        my $viewtext = &mt('Course View');
+        if (&Apache::loncommon::course_type() eq 'Community') {
+            $viewtext = &mt('Community View');
+        }
+        $result .= ('&nbsp;' x 3).'<input type="button" value="'.
+                   $viewtext.'" onclick="javascript:location.href=currentURL" />';
+    }
+    $result .= '</div>
+</div>
 </form>
-<br />';
+';
     return $result;
 }
 
@@ -1349,10 +1389,6 @@ sub start_font {
     my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {
 	my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
-	if ($face!~/symbol/i) {
-	    if (($env{'browser.fontenhance'} eq 'on') || 
-		($env{'browser.blackwhite'} eq 'on')) { return ''; }
-	}
 	$currentstring = $token->[4];     
     }  elsif ($target eq 'tex') {
 	my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
@@ -2009,9 +2045,6 @@ sub start_table {
     } elsif ($target eq 'tex') {
 	&disable_para();	# Can't have paras in a table.
 
-
-	#  New table code:
-
 	#  Get the parameters that we can do something about:
 
 	my $border = &Apache::lonxml::get_param('border', $parstack, $safeeval, undef, 0);
@@ -2028,17 +2061,25 @@ sub start_table {
         if ((defined $border) && ($border > 0)) {
         #    &Apache::lonnet::logthis("Turning on table borders: $border");
             $table->table_border(1);
-            if ($cell_border ne 'none') {
-                $table->cell_border(1); # html specs that border turns on both...unless rules='none'.
+            if (!defined $cell_border) {
+                $table->cell_border(1); # Default for rules is all if rules not defined.
             }
         }
-        # Only all or nothing for cell borders for now:
 
-        if ((defined $cell_border) && ($cell_border ne 'none')) {
-        #    &Apache::lonnet::logthis("Turning on cell borders: $cell_border");
-            $table->cell_border(1);
+        if ((defined $cell_border)) {
+            if ($cell_border eq 'all') {
+                $table->cell_border(1);
+            } elsif ($cell_border eq 'rows') {
+                $table->cell_border(2);
+            } elsif ($cell_border eq 'cols') {
+                $table->cell_border(3);
+            } elsif($cell_border eq 'groups') {
+                $table->cell_border(4);
+            } else {
+                $table->cell_border(0);
+            }
         }
-	if (defined $theme) {
+        if (defined $theme) {
 	    $table->theme($theme);
 	}
 	if (defined $align) {
@@ -2050,7 +2091,7 @@ sub start_table {
 	if (!(defined $width)) {
 	    $width = '70%';
 	}
-
+	
 	# If a percentage, need to calculate what this means in terms of
 	# page width:
 	
@@ -2065,88 +2106,6 @@ sub start_table {
 	push(@Apache::londefdef::table, $table);
         $currentstring.=' \keephidden{NEW TABLE ENTRY}';
 
-	#--------------------------------------------------------
-	#  Old table code here.
-	#--------------------------------------------------------
-
-
-	if (0) {
-	push(@Apache::londefdef::table, {}); 
-	$Apache::londefdef::table[-1]{'row_number'} = -1;
-        #maximum table's width (default coincides with text line length)
-	if ($#Apache::londefdef::table==0) {
-	    $textwidth=&recalc($env{'form.textwidth'}); #result is always in mm
-	    $textwidth=~/(\d+\.?\d*)/;
-	    $textwidth=0.85*$1; #accounts "internal" LaTeX space for table frame
-	} else {
-	    if ($Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]=~/\d/) {
-		#the maximum width of nested table is determined by LATeX width of parent cell
-		$textwidth=$Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]; 
-	    } else {
-              #try to use all space not used before (minus 5% for LaTeX table internal) - rather silly
-		$textwidth=$Apache::londefdef::table[-2]{'width'};
-		for (my $i=0;$i<$Apache::londefdef::table[-2]{'counter_columns'};$i++) {
-		    $textwidth=$textwidth-$Apache::londefdef::table[-2]{'TeXlen'}[0][$i];
-		}
-	    }
-	}
-
-	# width either comes forced from the TeXwidth or the width parameters.
-	# in either case it can be a percentage or absolute width.
-	# in the width case we ignore absolute width 
-	my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
-	if (!defined($TeXwidth)) {
-	    my $htmlwidth = &Apache::lonxml::get_param('width',$parstack,
-						       $safeeval,undef,1);
-	    if ($htmlwidth =~ /%/) {
-		$TeXwidth = $htmlwidth;
-	    } else { 
-		$TeXwidth = $textwidth;
-	    }
-	}
-	# if the width is specified as a % it is converted to an absolute width.
-	# otherwise.. just plugged right in the hash
-
-	if ($TeXwidth=~/%/) {
-	    $TeXwidth=~/(\d+)/;
-            $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100;
-	} else {
-	    $Apache::londefdef::table[-1]{'width'}=$TeXwidth;
-	}
-        #  In the end, however the table width cannot be wider than $textwidth...
-	
-	if ($Apache::londefdef::table[-1]{'width'} > $textwidth) {
-	    $Apache::londefdef::table[-1]{'width'} = $textwidth;
-	}
-        #table's border
-	my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval); 
-        my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0);
-	unless (defined $border) { $border = 0; }
-	if ($border) { 
-	    $Apache::londefdef::table[-1]{'hinc'} = '\hline '; 
-	    $Apache::londefdef::table[-1]{'vinc'} = '&'; 
-	    $Apache::londefdef::table[-1]{'vvinc'} = '|';
-	} else {
-	    $Apache::londefdef::table[-1]{'hinc'} = ''; 
-	    $Apache::londefdef::table[-1]{'vinc'} = '&'; 
-	    $Apache::londefdef::table[-1]{'vvinc'} = '';
-	}
-	if ($#Apache::londefdef::table==0) {
-	    #    Note that \newline seems to destroy the alignment envs.
-	    # $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}';
-	    $Apache::londefdef::table[-1]{'output'}='\strut'.'\\\\'."\n".'\strut\setlength{\tabcolsep}{1 mm}';
-	}
-	$Apache::londefdef::table[-1]{'output'}.=' \noindent \begin{tabular} ';
-        $Apache::londefdef::table[-1]{'TeXlen'}=[];
-        $Apache::londefdef::table[-1]{'objectlen'}=[];
-        $Apache::londefdef::table[-1]{'objectsignal'}=[];
-        $Apache::londefdef::table[-1]{'maxlen'}=[];
-        $Apache::londefdef::table[-1]{'minlen'}=[];
-        $Apache::londefdef::table[-1]{'content'}=[];
-        $Apache::londefdef::table[-1]{'align'}=[];
-        $currentstring.=' \keephidden{NEW TABLE ENTRY}';
-    }
-
     }
     return $currentstring;
 }
@@ -2159,8 +2118,6 @@ sub end_table {
     } elsif ($target eq 'tex') {
 
 
-	#  New table code:
-
 	my $table = pop(@Apache::londefdef::table);
 	my $t     = $table->generate();
 	$currentstring = $t->generate_string();
@@ -2703,14 +2660,20 @@ sub tag_check {
 
 sub cell_config_hash {
     my ($align, $rowspan, $colspan, $width) = @_;
+    if ($rowspan ne '') {
+        $rowspan =~ s/^\s+|\s+$//g;
+    }
+    if ($colspan ne '') {
+        $colspan =~ s/^\s+|\s+$//g;
+    }
     my %config;
     if ($align ne '') {
 	$config{'halign'} = $align;
     }
-    if ($colspan ne "") {
+    if (($colspan =~ /^\d+$/) && ($colspan > 0)) {
 	$config{'colspan'} = $colspan;
     }
-    if ($rowspan ne '') {
+    if (($rowspan =~ /^\d+$/) && ($rowspan > 0)) {
 	$config{'rowspan'} = $rowspan;
     }
     if ($width ne '') {
@@ -3274,10 +3237,10 @@ sub start_img {
         if ($token->[2]{'src'}=~/\$/) {
            $currentstring.=&mt('Variable image source');
         } elsif ($token->[2]{'src'}=~/\S/) {
-	   $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
-	   if ($width) { $currentstring.=' width="'.$width.'" '; }
-	   if ($height) { $currentstring.=' height="'.$height.'" '; }
-	   $currentstring .= ' />';
+           $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
+           if ($width) { $currentstring.=' width="'.$width.'" '; }
+           if ($height) { $currentstring.=' height="'.$height.'" '; }
+           $currentstring .= ' />';
         } else {
            $currentstring.=&mt("No image source specified");
         }
@@ -3528,7 +3491,7 @@ sub start_frameset {
 	    &Apache::loncommon::start_page($Apache::londefdef::title,
 					   $Apache::londefdef::head,
 					   {'add_entries'    => $token->[2],
-					    'no_title'       => 1,
+#					    'no_title'       => 1,
 					    'force_register' => 1,
 					    'frameset'       => 1,});