[LON-CAPA-cvs] cvs: loncom /interface lonsyllabus.pm
raeburn
raeburn at source.lon-capa.org
Wed May 15 13:47:57 EDT 2013
raeburn Wed May 15 17:47:57 2013 EDT
Modified files:
/loncom/interface lonsyllabus.pm
Log:
- Use lontexconvert::converted() to display a pure .tex file uploaded as
the syllabus.
- Move breadcrumbs generation for syllabus to get_breadcrumbs() routine to
facilitate reuse.
- If a plain text (.txt) file is uploaded as the syllabus, prepend
/adm/wrapper for display of file.
- Both "Edit" and "Delete" buttons shown for HTML files uploaded to syllabus.
Other file types only receive "Delete" button.
Index: loncom/interface/lonsyllabus.pm
diff -u loncom/interface/lonsyllabus.pm:1.124 loncom/interface/lonsyllabus.pm:1.125
--- loncom/interface/lonsyllabus.pm:1.124 Wed May 15 17:31:52 2013
+++ loncom/interface/lonsyllabus.pm Wed May 15 17:47:57 2013
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Syllabus
#
-# $Id: lonsyllabus.pm,v 1.124 2013/05/15 17:31:52 raeburn Exp $
+# $Id: lonsyllabus.pm,v 1.125 2013/05/15 17:47:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -71,6 +71,7 @@
}
# ------------------------------------- There is such a course, get environment
my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
+ my $crstype = &Apache::loncommon::course_type();
# ------------------------------------------------------------ Print the screen
@@ -117,24 +118,26 @@
}
unless ($allowed && $forceedit) {
my $file=&Apache::lonnet::filelocation("",$item);
- if ($file =~ /\.(sty|css|js|txt|tex|html?)$/) {
- my $filetype;
- if ($file =~ /\.(sty|css|js|txt|tex)$/) {
- $filetype=$1;
- } else {
- $filetype='html';
- }
- my $result = '';
+ 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') {
+ 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;
&Apache::structuretags::reset_problem_globals();
my $oldfile = $env{'request.filename'};
$env{'request.filename'} = $item;
- $result = &Apache::lonxml::xmlparse($r,'web',$filecontents,
- '',%mystyle);
+ my $result = &Apache::lonxml::xmlparse($r,'web',$filecontents,
+ '',%mystyle);
&Apache::structuretags::reset_problem_globals();
&Apache::lonhomework::finished_parsing();
$env{'request.filename'} = $oldfile;
@@ -153,7 +156,6 @@
}
}
- my $crstype = &Apache::loncommon::course_type();
# ------------------------------ The buck stops here: internal syllabus display
# --------------------------------------------------------- The syllabus fields
@@ -664,7 +666,26 @@
{href=>$r->uri,
text=>"Course syllabus"});
$args->{'bread_crumbs'} = $brcrum;
- } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
+ } else {
+ &get_breadcrumbs($cdom,$cnum,$crstype,$args);
+ }
+ if ($allowed) {
+ my %loaditem = (
+ onload => 'setTemplateBoxes();',
+ );
+ $args->{'add_entries'} = \%loaditem;
+ }
+ my $start_page =
+ &Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args);
+ if ($start_page) {
+ $r->print($start_page);
+ }
+}
+
+sub get_breadcrumbs{
+ my ($cdom,$cnum,$crstype,$args) = @_;
+ return unless (ref($args) eq 'HASH');
+ if ($env{'form.folderpath'} =~ /^supplemental/) {
my $title = $env{'form.title'};
if ($title eq '') {
$title = &mt('Syllabus');
@@ -685,17 +706,7 @@
];
}
}
- if ($allowed) {
- my %loaditem = (
- onload => 'setTemplateBoxes();',
- );
- $args->{'add_entries'} = \%loaditem;
- }
- my $start_page =
- &Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args);
- if ($start_page) {
- $r->print($start_page);
- }
+ return;
}
sub chooser {
@@ -817,8 +828,16 @@
my $absurl = $protocol.'://'.&Apache::lonnet::hostname($lonhost).$item;
my ($filename) = ($item =~ m{([^/]+)$});
my $file=&Apache::lonnet::filelocation("",$item);
- my $depbutton;
- if ($file =~ /\.html?$/) {
+ my ($depbutton,$filetype,$editable);
+ if ($file =~ /\.(xhtml|xml|tex|html|htm)$/) {
+ $filetype=$1;
+ }
+ if ($filetype) {
+ unless ($filetype eq 'tex') {
+ $filetype='html';
+ }
+ }
+ if ($filetype eq 'html') {
my $filecontents=&Apache::lonnet::getfile($file);
unless ($filecontents eq -1) {
my $mm = new File::MMagic;
@@ -833,12 +852,13 @@
\%codebase,
{'context' => 'rewrites',
'ignore_remote_references' => 1,});
- $depbutton = (' ' x 3).
- &editfile_button($item,$context).
- &editbutton_js();
+ $editable = 1;
}
}
}
+ $depbutton = (' ' x 3).
+ &editfile_button($item,$context,$editable).
+ &editbutton_js();
return ($absurl,$filename,$depbutton);
}
@@ -1232,7 +1252,7 @@
sub update_syllabus_env {
my ($cdom,$cnum,$courseenv,$saved,$uploaded,$minimal,$external) = @_;
- return unless(ref($courseenv) eq 'HASH');
+ return ($uploaded,$minimal,$external) unless(ref($courseenv) eq 'HASH');
my $now = time;
my (@envkeys,%storehash);
if ($saved eq 'template') {
@@ -1307,7 +1327,7 @@
if ($home ne 'no_host') {
my $protocol = $Apache::lonnet::protocol{$home};
$protocol = 'http' if ($protocol ne 'https');
- return $protocol.'//'.$home;
+ return $protocol.'://'.$home;
}
return;
}
@@ -1397,15 +1417,20 @@
}
sub editfile_button {
- my ($url,$context) = @_;
+ my ($url,$context,$editable) = @_;
my $edittext=&mt('Edit');
my $deltext=&mt('Delete');
- return <<"END";
- <input type="button" value="$edittext" onclick="javascript:gotoeditor('$url');" name="edit_$context" />
-
- <input type="button" value="$deltext" onclick="javascript:dodelete('$context');" name="del_$context" />
+ my $output;
+ if ($editable) {
+ $output = '
+ <input type="button" value="'.$edittext.'" onclick="javascript:gotoeditor('."'$url'".');" name="edit_'.$context.'" />
+ ';
+ }
+ $output .= '
+ <input type="button" value="'.$deltext.'" onclick="javascript:dodelete('."'$context'".');" name="del_'.$context.'" />
<input type="hidden" value="" name="deleteuploaded" />
-END
+ ';
+ return $output;
}
sub editbutton_js {
More information about the LON-CAPA-cvs
mailing list