--- loncom/interface/lonsyllabus.pm 2013/05/14 14:30:15 1.123 +++ loncom/interface/lonsyllabus.pm 2014/01/09 15:18:40 1.136 @@ -1,7 +1,7 @@ # The LearningOnline Network # Syllabus # -# $Id: lonsyllabus.pm,v 1.123 2013/05/14 14:30:15 raeburn Exp $ +# $Id: lonsyllabus.pm,v 1.136 2014/01/09 15:18:40 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -35,6 +35,7 @@ use Apache::loncommon; use Apache::lonnet; use Apache::lontexconvert; use Apache::lonfeedback; +use Apache::lonhtmlgateway; use Apache::lonannounce; use Apache::lonlocal; use Apache::lonhtmlcommon; @@ -53,7 +54,7 @@ sub handler { # ------------------------------------------------------------ Get query string &Apache::loncommon::get_unprocessed_cgi ($ENV{'QUERY_STRING'},['register','forceedit','todocs', - 'folderpath','title']); + 'folderpath','title','only_body']); # ----------------------------------------------------- Is this even a course? my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom); if ($homeserver eq 'no_host') { @@ -71,12 +72,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); @@ -102,7 +98,7 @@ sub handler { my $uploaded=$courseenv{'uploadedsyllabus'}; my $minimal=$courseenv{'minimalsyllabus'}; - if (($minimal =~/\w/) || ($uploaded =~/\w/)) { + if (($minimal =~/\w/) || ($uploaded =~/\w/)) { my $item; if ($minimal =~/\w/) { if ($external =~ m{\Q$minimal\E$}) { @@ -117,24 +113,36 @@ sub handler { } 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') { + 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); + if ($env{'form.only_body'}) { + $args{'only_body'} = 1; + } + $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; - $result = &Apache::lonxml::xmlparse($r,'web',$filecontents, - '',%mystyle); + my $result = &Apache::lonxml::xmlparse($r,$target,$filecontents, + '',%mystyle); &Apache::structuretags::reset_problem_globals(); &Apache::lonhomework::finished_parsing(); $env{'request.filename'} = $oldfile; @@ -142,18 +150,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; } } - 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 @@ -330,18 +357,18 @@ sub handler { } &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box', 'box_000_showpeople',$display); - $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed)); + $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,\%syllabus)); &Apache::lontemplate::print_end_template($r); } else { unless ($hidepersonnel) { &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box'); - $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed)); + $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,\%syllabus)); &Apache::lontemplate::print_end_template($r); } } } else { unless ($hidepersonnel) { - $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed)); + $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,%syllabus)); } } # -------------------------------------------------------------- Announcements? @@ -383,7 +410,7 @@ sub handler { } $rsslinktext = &mt('Manage Course RSS Feeds/Blogs'); if ($crstype eq 'Community') { - $rsslinktext = &mt('Manage Communiity RSS Feeds/Blogs'); + $rsslinktext = &mt('Manage Community RSS Feeds/Blogs'); } } my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html'; @@ -404,10 +431,6 @@ sub handler { } # ---------------------------------------------------------------- Get syllabus if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) { - if ($allowed) { - $r->print('
'. + $r->print(''. &Apache::lonhtmlcommon::htmlareaselectactive()); } } else { @@ -664,7 +687,29 @@ ENDSCRIPT {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; + } + if ($env{'form.only_body'}) { + $args->{'only_body'} = 1; + } + 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 +730,7 @@ ENDSCRIPT ]; } } - 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 +852,16 @@ sub syllabus_file_info { 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 +876,13 @@ sub syllabus_file_info { \%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); } @@ -920,49 +964,121 @@ sub fields_check_uncheck { } sub get_personnel { - my ($r,$target,$cdom,$cnum,$allowed) = @_; + my ($r,$target,$cdom,$cnum,$allowed,$crstype,$syllabus) = @_; + my (%hiddenroles,%hiddenusers); + if (ref($syllabus) eq 'HASH') { + if (ref($syllabus->{'personnel'}) eq 'HASH') { + if ($syllabus->{'personnel'}{'hiderole'}) { + map { $hiddenroles{$_} = 1; } split(/,/,$syllabus->{'personnel'}{'hiderole'}); + } + if ($syllabus->{'personnel'}{'hideuser'}) { + map { $hiddenusers{$_} = 1; } split(/,/,$syllabus->{'personnel'}{'hideuser'}); + } + } + } my $output; - my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum); + my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum,1); if ($target ne 'tex') { - $r->print(&Apache::lonhtmlcommon::start_pick_box()); + if ($allowed) { + $r->print(&Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + '