--- loncom/interface/lonsyllabus.pm 2006/03/06 22:17:48 1.45
+++ 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.45 2006/03/06 22:17:48 www Exp $
+# $Id: lonsyllabus.pm,v 1.130 2013/08/27 03:00:38 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -29,6 +29,7 @@
package Apache::lonsyllabus;
use strict;
+use Apache::lontemplate;
use Apache::Constants qw(:common);
use Apache::loncommon;
use Apache::lonnet;
@@ -38,41 +39,146 @@ use Apache::lonannounce;
use Apache::lonlocal;
use Apache::lonhtmlcommon;
use Apache::lonspeller();
+use HTML::Entities();
sub handler {
my $r = shift;
+ &Apache::loncommon::content_type($r,'text/html');
+ $r->send_http_header;
+ return OK if $r->header_only;
+ my $target=$env{'form.grade_target'};
# --------------------------------------------------- Get course info from URL
my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
+# ------------------------------------------------------------ Get query string
+ &Apache::loncommon::get_unprocessed_cgi
+ ($ENV{'QUERY_STRING'},['register','forceedit','todocs',
+ 'folderpath','title']);
# ----------------------------------------------------- Is this even a course?
my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
if ($homeserver eq 'no_host') {
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
- $r->print('
'.&mt('No syllabus available').'');
+ &Apache::loncommon::simple_error_page($r,'No syllabus available',
+ 'No syllabus available');
+ return OK;
+ } elsif (!&Apache::lonnet::is_course($cdom,$cnum)) {
+ &Apache::loncommon::content_type($r,'text/html');
+ $r->send_http_header;
+ &Apache::loncommon::simple_error_page($r,'No syllabus available',
+ 'The course/community for which the syllabus was requested does not exist.');
return OK;
}
# ------------------------------------- There is such a course, get environment
my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
-
- &Apache::loncommon::content_type($r,'text/html');
- $r->send_http_header;
- return OK if $r->header_only;
+ my $crstype = &Apache::loncommon::course_type();
+
+# --------------------------------------------------------------- Force Student
+ my ($forceedit,$forcestudent);
+ if ($env{'form.forceedit'}) { $forceedit=1; }
+ if (!$forceedit) {
+ $forcestudent=1;
+ }
+
+# --------------------------------------------------------------- Check Privileges
+ my $allowed = 0;
+ if ($env{'user.environment'}) {
+# does this user have privileges to post, etc?
+ if ($env{'request.course.id'}
+ && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
+ && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
+ $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
+ if ($forcestudent or $target eq 'tex') { $allowed=0; }
+ }
+ }
+
+# -------------------------------------------------- Let's see who handles this
+ my $external=$courseenv{'externalsyllabus'};
+ my $uploaded=$courseenv{'uploadedsyllabus'};
+ my $minimal=$courseenv{'minimalsyllabus'};
+
+ 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("",$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 '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'} = $item;
+ my $result = &Apache::lonxml::xmlparse($r,$target,$filecontents,
+ '',%mystyle);
+ &Apache::structuretags::reset_problem_globals();
+ &Apache::lonhomework::finished_parsing();
+ $env{'request.filename'} = $oldfile;
+ &Apache::lonxml::add_messages(\$result);
+ $r->print($result);
+ }
+ } else {
+ 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) {
+ 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
- my $target=$env{'form.grade_target'};
- my $feedurl='feed://'.$ENV{'HTTP_HOST'}.'/public/'.$cdom.'/'.$cnum.'/Course_Announcements.rss';
- if ($target ne 'tex') {
- my $html=&Apache::lonxml::xmlbegin();
- $r->print(<
-The LearningOnline Network with CAPA
-
-ENDDOCUMENT
- } else {
- $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
- }
+ 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
my %syllabusfields=&Apache::lonlocal::texthash(
'aaa_instructorinfo' => 'Instructor Information',
@@ -90,247 +196,1390 @@ ENDDOCUMENT
'jjj_weblinks' => 'Web Links',
'kkk_textbook' => 'Textbook',
'lll_includeurl' => 'URLs To Include in Syllabus');
+# ---------------------------------------------------------- Load syllabus info
+ my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
+ my ($output,%displayfields,%noshow);
-# ------------------------------------------------------------ Get query string
- &Apache::loncommon::get_unprocessed_cgi
- ($ENV{'QUERY_STRING'},['forcestudent','register','forceedit']);
-# ----------------------------------------------------- Force menu registration
- my $addentries='';
- if ($env{'form.register'}) {
- $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
- '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
- $r->print(&Apache::lonmenu::registerurl(1));
+# This handler might be called anonymously ...
+# ----------------------------------------------------- Only if not public call
+ if ($allowed) {
+ if (($env{'form.choice'} =~ /^(template|minimal|url|file)$/) ||
+ ($env{'form.phase'} =~ /^(upload|check)_embedded$/)) {
+ my $earlyout;
+ ($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.
+ &Apache::loncommon::end_page());
+ }
+ return OK;
+ }
+ }
}
-# --------------------------------------------------------------- Force Student
- my $forcestudent='';
- if ($env{'form.forcestudent'}) { $forcestudent='student'; };
- my $forceedit='';
- if ($env{'form.forceedit'}) { $forceedit='edit'; }
-
-# ----------------------------------------------------------------- Make header
if ($target ne 'tex') {
- $r->print(&Apache::lonhtmlcommon::htmlareaheaders().
- ''.&Apache::loncommon::bodytag
- ("Syllabus",$forcestudent,$addentries,'',$cdom,$env{'form.register'}));
- $r->print('
'.$courseenv{'description'}.'
'.
- $Apache::lonnet::domaindescription{$cdom}.'
');
+ &print_header($r,$cnum,$cdom,$crstype,$allowed,$forceedit,\%syllabus,
+ \%syllabusfields);
+ $r->print($output);
+ }
+
+# -------------------------------------------- Determine which fields are shown
+
+ if ($syllabus{'uploaded.fields'}) {
+ if ($syllabus{'uploaded.fields'} eq 'none') {
+ foreach my $field (keys(%syllabusfields)) {
+ $displayfields{$field} = ' style="display:none;"';
+ $noshow{$field} = 1;
+ }
+ } else {
+ my %included;
+ map { $included{$_} = 1; } split(/,/,$syllabus{'uploaded.fields'});
+ foreach my $field (keys(%syllabusfields)) {
+ my ($prefix) = split(/_/,$field);
+ if ($included{$prefix}) {
+ $displayfields{$field} = ' style="display:block;"';
+ } else {
+ $displayfields{$field} = ' style="display:none;"';
+ $noshow{$field} = 1;
+ }
+ }
+ }
+ } else {
+ foreach my $field (keys(%syllabusfields)) {
+ if ($syllabus{$field} ne '') {
+ $displayfields{$field} = ' style="display:block;"';
+ } else {
+ $displayfields{$field} = ' style="display:none;"';
+ }
+ }
+ }
+
+ if ($allowed) {
+#---------------------------------- Print External URL Syllabus Info if editing
+ if ($target ne 'tex') {
+ my $protocol = $Apache::lonnet::protocol{$homeserver};
+ $protocol = 'http' if ($protocol ne 'https');
+ my $link = $protocol.'://'.&Apache::lonnet::hostname($homeserver).$r->uri;
+ $r->print('
'
+ .''
+ .''
+ .&mt('Public link (no log-in): [_1]',''.$link.'')
+ .' '.&Apache::loncommon::help_open_topic('Syllabus_ExtLink')
+ .''
+ .'
'."\n");
+ my $lonhost = $r->dir_config('lonHostID');
+ $r->print(&chooser($external,$uploaded,$minimal,$cdom,$cnum,$lonhost,
+ \%syllabusfields,\%syllabus));
+ }
+ } else {
+#--------------------------------------------- Print last update unless editing
+ my $lastmod=$syllabus{'uploaded.lastmodified'};
+ $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
+ my $who;
+ if ($syllabus{'uploaded.lastmodified'}) {
+ if (($env{'user.name'} ne 'public') && ($env{'user.domain'} ne 'public')) {
+ $who = &Apache::loncommon::aboutmewrapper(
+ &Apache::loncommon::plainname($syllabus{'uploaded.name'},
+ $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
+ $syllabus{'uploaded.domain'});
+ } else {
+# Public user?
+# Only display name of user, but no link to personal information page
+ $who = &Apache::loncommon::plainname(
+ $syllabus{'uploaded.name'},
+ $syllabus{'uploaded.domain'});
+ }
+ }
+ if ($target ne 'tex') {
+ $r->print('
'.
+ &Apache::lonhtmlcommon::htmlareaselectactive());
+ }
+ } else {
+ if ($target ne 'tex') {$r->print('
');} else {$r->print('\par ');}
+ $r->print(&mt('No syllabus information provided.'));
+ if ($target ne 'tex') {$r->print('
');}
}
-# -------------------------------------------------------- Get course personnel
- my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
if ($target ne 'tex') {
- $r->print('
');
+ if ($allowed) {
+ $r->print(&Apache::loncommon::end_data_table());
+ } else {
+ $r->print(&Apache::lonhtmlcommon::end_pick_box());
+ }
} else {
- $r->print('\end{tabular}\\\\');
+ $r->print('\end{tabular}\\\\');
}
-# ---------------------------------------------------------- Load syllabus info
- my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
- my $allowed=0;
- my $privileged=0;
+ return;
+}
-# This handler might be called anonymously ...
-# ----------------------------------------------------- Only if not public call
- if ($env{'user.environment'}) {
-# does this user have privileges to post, etc?
- if ($env{'request.course.id'}) {
- $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
- $privileged=$allowed;
- if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
- $forcestudent='student';
- }
- if ($forcestudent or $target eq 'tex') { $allowed=0; }
- }
- if ($allowed) {
- $r->print('
'.
-&Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'
'.&mt('This syllabus can be publicly viewed at')
- .' http://'.
- $Apache::lonnet::hostname{$homeserver}.$r->uri.''.
- &Apache::loncommon::help_open_topic('Syllabus_ExtLink').'