--- loncom/interface/lonsyllabus.pm 2013/05/15 18:45:29 1.126
+++ loncom/interface/lonsyllabus.pm 2013/09/21 23:44:46 1.134
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Syllabus
#
-# $Id: lonsyllabus.pm,v 1.126 2013/05/15 18:45:29 raeburn Exp $
+# $Id: lonsyllabus.pm,v 1.134 2013/09/21 23:44:46 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') {
@@ -73,12 +74,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; }
@@ -103,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$}) {
@@ -124,19 +119,29 @@ 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);
+ 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;
- 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 +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;
}
}
+# ------------------------------------------------------------ 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
@@ -332,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?
@@ -406,10 +431,6 @@ sub handler {
}
# ---------------------------------------------------------------- Get syllabus
if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
- if ($allowed) {
- $r->print('
'.
+ $r->print(''.
&Apache::lonhtmlcommon::htmlareaselectactive());
}
} else {
@@ -675,6 +696,9 @@ ENDSCRIPT
);
$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) {
@@ -940,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().
+ ''.&mt('Role hidden?').' | '.&mt('Role').' | '.
+ ''.&mt('Personnel (hidden if checked)').' | '.
+ &Apache::loncommon::end_data_table_header_row());
+ } else {
+ $r->print(&Apache::lonhtmlcommon::start_pick_box());
+ }
} else {
$r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
}
my @personnel=sort(keys(%coursepersonnel));
my $lastpers=$personnel[$#personnel];
foreach my $element (@personnel) {
+ unless ($allowed) {
+ next if ($hiddenroles{$element})
+ }
+ my ($role,$sec);
+ if ($element =~ /:/) {
+ ($role,$sec) = split(/:/,$element);
+ } else {
+ $role = $element;
+ }
+ my $roletext = &Apache::lonnet::plaintext($role,$crstype);
+ if ($sec) {
+ $roletext .=' ('.&Apache::lonlocal::mt('Section [_1]',$sec).')';
+ }
if ($target ne 'tex') {
- $r->print(&Apache::lonhtmlcommon::row_title($element));
+ if ($allowed) {
+ my $checked;
+ if ($hiddenroles{$element}) {
+ $checked = ' checked="checked"';
+ }
+ $r->print(&Apache::loncommon::start_data_table_row().
+ ''.
+ ''.
+ ' | '.$roletext.' | ');
+ } else {
+ $r->print(&Apache::lonhtmlcommon::row_title($roletext));
+ }
} else {
- $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
+ $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$roletext).' & ');
}
my @coursepersonlist;
foreach my $user (split(/\,/,$coursepersonnel{$element})) {
my ($puname,$pudom)=split(/\:/,$user);
if ($target ne 'tex') {
my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
- if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
- ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
- push(@coursepersonlist,$courseperson);
+ my $checked;
+ if ($hiddenusers{$element.'&'.$puname.':'.$pudom}) {
+ $checked = ' checked="checked"';
+ }
+ if ($allowed) {
+ my $item = ''.(' 'x2).' ';
+ push(@coursepersonlist,$item);
+
} else {
- push(@coursepersonlist,&Apache::loncommon::aboutmewrapper($courseperson,
- $puname,$pudom));
+ next if ($hiddenusers{$element.'&'.$puname.':'.$pudom});
+ if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
+ ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
+ push(@coursepersonlist,$courseperson);
+ } else {
+ push(@coursepersonlist,&Apache::loncommon::aboutmewrapper($courseperson,
+ $puname,$pudom));
+ }
}
} else {
push(@coursepersonlist,&Apache::loncommon::plainname($puname,
$pudom).' ');
}
}
- $r->print(join(", ",@coursepersonlist));
+ if ($allowed) {
+ $r->print(join('',@coursepersonlist));
+ } else {
+ $r->print(join(', ',@coursepersonlist));
+ }
if ($target ne 'tex') {
- my $lastclose=$element eq $lastpers?1:0;
- $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
+ if ($allowed) {
+ $r->print(' | '.&Apache::loncommon::end_data_table_row());
+ } else {
+ my $lastclose=$element eq $lastpers?1:0;
+ $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
+ }
} else {
$r->print('\\\\ \hline');
}
}
if ($target ne 'tex') {
- $r->print(&Apache::lonhtmlcommon::end_pick_box());
+ if ($allowed) {
+ $r->print(&Apache::loncommon::end_data_table());
+ } else {
+ $r->print(&Apache::lonhtmlcommon::end_pick_box());
+ }
} else {
$r->print('\end{tabular}\\\\');
}
@@ -992,13 +1088,18 @@ sub get_personnel {
sub save_changes {
my ($cnum,$cdom,$uploaded,$external,$minimal,$syllabus,$syllabusfields,$courseenv) = @_;
my ($earlyout,$output);
- unless ((ref($syllabus) eq 'HASH') && (ref($syllabusfields) eq 'HASH')) {
+ unless ((ref($syllabus) eq 'HASH') && (ref($syllabusfields) eq 'HASH') ||
+ (ref($courseenv) eq 'HASH')) {
return ($earlyout,$uploaded,$external,$minimal,$output);
}
- if ($env{'form.deleteuploaded'}) {
+ if (($env{'form.deleteuploaded_file'}) || ($env{'form.deleteuploaded_minimal'})) {
my %storehash;
if (($env{'form.choice'} eq 'file') &&
- ($env{'form.deleteuploaded'} eq 'file') && ($uploaded =~ /\w/)) {
+ ($env{'form.deleteuploaded_file'}) && ($uploaded =~ /\w/)) {
+ if ($courseenv->{'uploadedsyllabus'} =~ m{^\Q/uploaded/$cdom/$cnum/portfolio\E(/syllabus/.+)$}) {
+ my $filename = $1;
+ &update_access_permissions($cdom,$cnum,$filename);
+ }
&Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');
&Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
$storehash{'uploadedsyllabus'} = '';
@@ -1007,7 +1108,18 @@ sub save_changes {
undef($uploaded);
undef($external);
} elsif (($env{'form.choice'} eq 'minimal') &&
- ($env{'form.deleteuploaded'} eq 'minimal') && ($minimal =~ /\w/)) {
+ ($env{'form.deleteuploaded_minimal'}) && ($minimal =~ /\w/)) {
+ my $minimalurl = "/uploaded/$cdom/$cnum/portfolio/syllabus/loncapa.html";
+ if ($courseenv->{'minimalsyllabus'} eq "$minimalurl") {
+ my $filecontents=&Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$minimalurl));
+ unless ($filecontents eq -1) {
+ $env{'form.output'} = $filecontents;
+ &Apache::lonnet::finishuserfileupload($cnum,$cdom,'output',
+ 'portfolio/syllabus/loncapa.html.bak');
+ $minimalurl = &default_minimal_syllabus($cnum,$cdom);
+ }
+ }
+ &update_access_permissions($cdom,$cnum,'/syllabus/loncapa.html');
&Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
&Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.minimalsyllabus');
$storehash{'externalsyllabus'} = '';
@@ -1030,16 +1142,41 @@ sub save_changes {
my ($prefix) = split(/_/,$field);
$syllabus->{'uploaded.fields'} .= $prefix.',';
}
+ if ($field eq '000_showpeople') {
+ my @hideusers = &Apache::loncommon::get_env_multiple('form.hideuser');
+ my @hideroles = &Apache::loncommon::get_env_multiple('form.hiderole');
+ my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum,1);
+ my %personnel;
+ foreach my $key (keys(%coursepersonnel)) {
+ map { $personnel{$key}{$_} = 1; } split(/,/,$coursepersonnel{$key});
+ }
+ %{$syllabus->{'personnel'}} = ();
+ $syllabus->{'personnel'}{'hideuser'} = '';
+ $syllabus->{'personnel'}{'hiderole'} = '';
+ foreach my $role (@hideroles) {
+ if (exists($personnel{$role})) {
+ $syllabus->{'personnel'}{'hiderole'} .= $role.',';
+ }
+ }
+ foreach my $item (@hideusers) {
+ my ($role,$user) = split(/\&/,$item);
+ if (ref($personnel{$role}) eq 'HASH') {
+ if ($personnel{$role}{$user}) {
+ $syllabus->{'personnel'}{'hideuser'} .= $item.',';
+ }
+ }
+ }
+ $syllabus->{'personnel'}{'hideuser'} =~ s/,$//;
+ $syllabus->{'personnel'}{'hiderole'} =~ s/,$//;
+ }
}
$syllabus->{'uploaded.fields'} =~ s/,$//;
}
foreach my $syl_field (keys(%{$syllabusfields})) {
my $field=$env{'form.'.$syl_field};
chomp($field);
- $field=~s/\s+$//s;
- $field=~s/^\s+//s;
- $field=~s/\
$//s;
- $field=&Apache::lonfeedback::clear_out_html($field,1);
+ my $gateway = Apache::lonhtmlgateway->new();
+ $field = $gateway->process_incoming_html($field,1);
#here it will be stored
$syllabus->{$syl_field}=$field;
if ($syl_field eq 'lll_includeurl') { # clean up included URLs
@@ -1134,34 +1271,16 @@ sub save_changes {
($url,$needlink) = &process_upload(\$output,$cnum,$cdom,
\%allfiles,\%codebase);
} else {
- $output = '';
+ $output = '
'.
&mt('No file uploaded').
'
';
}
} elsif ($env{'form.choice'} eq 'minimal') {
- my $title = $env{'form.syllabustitle'};
- $title =~ s{`}{}g;
- $title=~s/^\s+//;
- $title=~s/\s+$//;
- if ($title eq '') {
- $title = &mt('Syllabus');
+ $url = "/uploaded/$cdom/$cnum/portfolio/syllabus/loncapa.html";
+ my $filecontents=&Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$url));
+ if ($filecontents eq -1) {
+ $url = &default_minimal_syllabus($cnum,$cdom);
}
- my $initialtext = &mt('Replace with your own content.');
- my $newhtml = <
-
-$title
-
-
-$title
-$initialtext
-
-