--- loncom/interface/lonsyllabus.pm 2013/05/09 05:43:30 1.121 +++ 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.121 2013/05/09 05:43:30 raeburn Exp $ +# $Id: lonsyllabus.pm,v 1.130 2013/08/27 03:00:38 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -71,12 +71,7 @@ sub handler { } # ------------------------------------- There is such a course, get environment my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum); - -# ------------------------------------------------------------ Print the screen - - if ($target eq 'tex') { - $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'})); - } + my $crstype = &Apache::loncommon::course_type(); # --------------------------------------------------------------- Force Student my ($forceedit,$forcestudent); @@ -100,31 +95,50 @@ sub handler { # -------------------------------------------------- Let's see who handles this my $external=$courseenv{'externalsyllabus'}; my $uploaded=$courseenv{'uploadedsyllabus'}; + my $minimal=$courseenv{'minimalsyllabus'}; - if ($uploaded =~/\w/) { - if ($external =~ m{\Q$uploaded\E$}) { - undef($external); + if (($minimal =~/\w/) || ($uploaded =~/\w/)) { + my $item; + if ($minimal =~/\w/) { + if ($external =~ m{\Q$minimal\E$}) { + undef($external); + } + $item = $minimal; + } elsif ($uploaded =~/\w/) { + if ($external =~ m{\Q$uploaded\E$}) { + undef($external); + } + $item = $uploaded; } unless ($allowed && $forceedit) { - my $file=&Apache::lonnet::filelocation("",$uploaded); - if ($file =~ /\.(sty|css|js|txt|tex|html?)$/) { - my $filetype; - if ($file =~ /\.(sty|css|js|txt|tex)$/) { - $filetype=$1; - } else { - $filetype='html'; - } - my $result = ''; + my $file=&Apache::lonnet::filelocation("",$item); + if ($file =~ /\.(tex|x?html?)$/) { + my $filetype = $1; my $filecontents=&Apache::lonnet::getfile($file); if ($filecontents eq -1) { $r->print(&mt('Syllabus file unavailable')); - } elsif ($filetype eq 'html') { + } elsif ($filetype eq 'tex') { + 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'} = $uploaded; - $result = &Apache::lonxml::xmlparse($r,'web',$filecontents, - '',%mystyle); + $env{'request.filename'} = $item; + my $result = &Apache::lonxml::xmlparse($r,$target,$filecontents, + '',%mystyle); &Apache::structuretags::reset_problem_globals(); &Apache::lonhomework::finished_parsing(); $env{'request.filename'} = $oldfile; @@ -132,18 +146,37 @@ sub handler { $r->print($result); } } else { - $r->print(&Apache::lonwrapper::wrapper($uploaded)); + 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; } } - my $crstype = &Apache::loncommon::course_type(); +# ------------------------------------------------------------ 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 @@ -170,17 +203,25 @@ sub handler { # This handler might be called anonymously ... # ----------------------------------------------------- Only if not public call if ($allowed) { - if (($env{'form.choice'} =~ /^(template|url|file)$/) || + if (($env{'form.choice'} =~ /^(template|minimal|url|file)$/) || ($env{'form.phase'} =~ /^(upload|check)_embedded$/)) { my $earlyout; - ($earlyout,$uploaded,$external,$output) = - &save_changes($cnum,$cdom,$uploaded,$external,\%syllabus, - \%syllabusfields,\%courseenv); + ($earlyout,$uploaded,$external,$minimal,$output) = + &save_changes($cnum,$cdom,$uploaded,$external,$minimal, + \%syllabus,\%syllabusfields,\%courseenv); + if (($env{'form.choice'} eq 'minimal') && + ($minimal eq "/uploaded/$cdom/$cnum/portfolio/syllabus/loncapa.html")) { + delete($env{'form.symb'}); + delete($env{'request.symb'}); + $r->internal_redirect("$minimal?editmode=1&forceedit=1"); + return OK; + } if ($earlyout) { if ($target ne 'tex') { &print_header($r,$cnum,$cdom,$crstype,$allowed,$forceedit, \%syllabus,\%syllabusfields); - $r->print($output); + $r->print($output. + &Apache::loncommon::end_page()); } return OK; } @@ -237,8 +278,8 @@ sub handler { .'' .'
'."\n"); my $lonhost = $r->dir_config('lonHostID'); - $r->print(&chooser($external,$uploaded,$cdom,$cnum,$lonhost,\%syllabusfields, - \%syllabus)); + $r->print(&chooser($external,$uploaded,$minimal,$cdom,$cnum,$lonhost, + \%syllabusfields,\%syllabus)); } } else { #--------------------------------------------- Print last update unless editing @@ -277,7 +318,7 @@ sub handler { #-------------------------------------------------------------- Print Headtitle if ($target ne 'tex') { my $display = 'block'; - if ($external || $uploaded) { + if ($external || $uploaded || $minimal) { $display = 'none'; } $r->print('