--- loncom/interface/lonsyllabus.pm	2013/05/19 15:48:51	1.128
+++ loncom/interface/lonsyllabus.pm	2013/08/27 03:00:38	1.130
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Syllabus
 #
-# $Id: lonsyllabus.pm,v 1.128 2013/05/19 15:48:51 raeburn Exp $
+# $Id: lonsyllabus.pm,v 1.130 2013/08/27 03:00:38 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -73,12 +73,6 @@ sub handler {
     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
     my $crstype = &Apache::loncommon::course_type();
 
-# ------------------------------------------------------------ Print the screen
-
-    if ($target eq 'tex') {
-        $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
-    }
-
 # --------------------------------------------------------------- Force Student
     my ($forceedit,$forcestudent);
     if ($env{'form.forceedit'}) { $forceedit=1; }
@@ -124,19 +118,26 @@ sub handler {
                 if ($filecontents eq -1) {
                     $r->print(&mt('Syllabus file unavailable'));
                 } elsif ($filetype eq 'tex') {
-                    my $result = &Apache::lontexconvert::converted(\$filecontents,
-                                                                $env{'form.texengine'});
-                    my %args;
-                    &get_breadcrumbs($cdom,$cnum,$crstype,\%args);
-                    $r->print(&Apache::loncommon::start_page("Syllabus",undef,\%args).
-                              $result.
-                              &Apache::loncommon::end_page());
+                    if ($target eq 'tex') {
+                        $r->print($filecontents);
+                    } else {
+                        my $result = &Apache::lontexconvert::converted(\$filecontents,
+                                                                       $env{'form.texengine'});
+                        my %args;
+                        &get_breadcrumbs($cdom,$cnum,$crstype,\%args);
+                        $r->print(&Apache::loncommon::start_page("Syllabus",undef,\%args).
+                                  $result.
+                                  &Apache::loncommon::end_page());
+                    }
                 } else {
                     my %mystyle;
+                    unless ($target eq 'tex') {
+                        $target = 'web';
+                    }
                     &Apache::structuretags::reset_problem_globals();
                     my $oldfile = $env{'request.filename'};
                     $env{'request.filename'} = $item;
-                    my $result = &Apache::lonxml::xmlparse($r,'web',$filecontents,
+                    my $result = &Apache::lonxml::xmlparse($r,$target,$filecontents,
                                                            '',%mystyle);
                     &Apache::structuretags::reset_problem_globals();
                     &Apache::lonhomework::finished_parsing();
@@ -145,17 +146,37 @@ sub handler {
                     $r->print($result);
                 }
             } else {
-                $r->print(&Apache::lonwrapper::wrapper($item));
+                if ($target eq 'tex') {
+                    $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}).
+                              ' \strut \\\\ \textbf{'.&mt('Syllabus').'} \strut \\\\ '.
+                              &mt('Unsupported file type.').' \strut \\\\ '.
+                              &mt('Print the syllabus directly from your web browser').
+                              '\end{document}');
+                } else {
+                    $r->print(&Apache::lonwrapper::wrapper($item));
+                }
             }
             return OK;
         }
     } elsif ($external=~/\w/) {
         unless ($allowed && $forceedit) {
-            $r->print(&Apache::lonwrapper::wrapper($external));
+            if ($target eq 'tex') {
+                $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}).
+                         ' \strut \\\\ \textbf{'.&mt('Syllabus').'} \strut \\\\ '.$external.' '.
+                         ' \strut \\\\ '.&mt('Print the syllabus directly from your web browser').
+                         '\end{document}');
+            } else {
+                $r->print(&Apache::lonwrapper::wrapper($external));
+            }
             return OK;
         }
     }
 
+# ------------------------------------------------------------ Print the screen
+
+    if ($target eq 'tex') {
+        $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
+    }
 
 # ------------------------------ The buck stops here: internal syllabus display
 # --------------------------------------------------------- The syllabus fields
@@ -406,10 +427,6 @@ sub handler {
     }
 # ---------------------------------------------------------------- Get syllabus
     if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
-        if ($allowed) {
-            $r->print('<form method="post" action="">');
-        }
-
 		my $url_include_handler = sub {
 			my ($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed, $display) = @_;
 			my %data = %{$data_ref};
@@ -456,7 +473,7 @@ sub handler {
 			$target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash,
                         undef,\%displayfields,\%noshow);
         if ($allowed) {
-            $r->print('</form>'.
+            $r->print('</div></form>'.
             &Apache::lonhtmlcommon::htmlareaselectactive());
         }
     } else {
@@ -1011,7 +1028,7 @@ sub get_personnel {
                 }
                 if ($allowed) {
                     my $item = '<span class="LC_nobreak"><label>'.
-                               '<input type="checkbox" name="hideuser" value="'.$element.'&'.$puname.':'.$pudom.'"'.$checked.' />'.
+                               '<input type="checkbox" name="hideuser" value="'.$element.'&amp;'.$puname.':'.$pudom.'"'.$checked.' />'.
                                &Apache::loncommon::aboutmewrapper($courseperson
 ,
                                                $puname,$pudom).
@@ -1040,7 +1057,7 @@ sub get_personnel {
         }
         if ($target ne 'tex') {
             if ($allowed) {
-                $r->print(&Apache::loncommon::end_data_table_row());
+                $r->print('</td>'.&Apache::loncommon::end_data_table_row());
             } else {
                 my $lastclose=$element eq $lastpers?1:0;
                 $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
@@ -1367,7 +1384,6 @@ sub update_syllabus_env {
         $storehash{'updatedsyllabus'} = $now;
         &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.updatedsyllabus' => $now
 });
-
     } elsif ($saved eq 'url') {
         my $prefix = &home_http_host($cdom,$cnum);
         if ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus/\E(.+)$}) {
@@ -1399,7 +1415,7 @@ sub update_syllabus_env {
     if (@envkeys > 0) {
         foreach my $item (@envkeys) {
             my $key = $item.'syllabus';
-            if ($courseenv->{$key}) {
+            if ($courseenv->{$key} ne '') {
                 &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
                 $storehash{$key} = '';
             }