--- loncom/interface/lonsyllabus.pm 2012/12/07 17:15:56 1.116 +++ loncom/interface/lonsyllabus.pm 2013/05/06 16:15:59 1.120 @@ -1,7 +1,7 @@ # The LearningOnline Network # Syllabus # -# $Id: lonsyllabus.pm,v 1.116 2012/12/07 17:15:56 raeburn Exp $ +# $Id: lonsyllabus.pm,v 1.120 2013/05/06 16:15:59 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -77,14 +77,74 @@ sub handler { 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; } + 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 $externalsyllabus=$courseenv{'externalsyllabus'}; + my $external=$courseenv{'externalsyllabus'}; + my $uploaded=$courseenv{'uploadedsyllabus'}; - if ($externalsyllabus=~/\w/) { - $r->print( Apache::lonwrapper::wrapper($externalsyllabus) ); - return OK; + if ($uploaded =~/\w/) { + if ($external =~ m{\Q$uploaded\E$}) { + undef($external); + } + 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 $filecontents=&Apache::lonnet::getfile($file); + if ($filecontents eq -1) { + $r->print(&mt('Syllabus file unavailable')); + } elsif ($filetype eq 'html') { + my %mystyle; + &Apache::structuretags::reset_problem_globals(); + my $oldfile = $env{'request.filename'}; + $env{'request.filename'} = $uploaded; + $result = &Apache::lonxml::xmlparse($r,'web',$filecontents, + '',%mystyle); + &Apache::structuretags::reset_problem_globals(); + &Apache::lonhomework::finished_parsing(); + $env{'request.filename'} = $oldfile; + &Apache::lonxml::add_messages(\$result); + $r->print($result); + } + } else { + $r->print(&Apache::lonwrapper::wrapper($uploaded)); + } + return OK; + } + } elsif ($external=~/\w/) { + unless ($allowed && $forceedit) { + $r->print(&Apache::lonwrapper::wrapper($external)); + return OK; + } } + my $crstype = &Apache::loncommon::course_type(); + # ------------------------------ The buck stops here: internal syllabus display # --------------------------------------------------------- The syllabus fields my %syllabusfields=&Apache::lonlocal::texthash( @@ -103,12 +163,6 @@ sub handler { 'jjj_weblinks' => 'Web Links', 'kkk_textbook' => 'Textbook', 'lll_includeurl' => 'URLs To Include in Syllabus'); -# --------------------------------------------------------------- Force Student - my ($forceedit,$forcestudent); - if ($env{'form.forceedit'}) { $forceedit=1; } - if (!$forceedit) { - $forcestudent=1; - } # ----------------------------------------------------------------- Make header if ($target ne 'tex') { my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom); @@ -117,6 +171,8 @@ sub handler { $js .= <<"ENDSCRIPT"; + +ENDSCRIPT + } + if ($allowed && $forceedit) { + my $check_uncheck = &Apache::loncommon::check_uncheck_jscript(); + my $invurl = &mt('Invalid URL'); + my $urlregexp = <<'ENDREGEXP'; +/^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-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DSCRIPT text=>"Course syllabus"}); $args->{'bread_crumbs'} = $brcrum; } elsif ($env{'form.folderpath'} =~ /^supplemental/) { - my $crstype = &Apache::loncommon::course_type(); my $title = $env{'form.title'}; if ($title eq '') { $title = &mt('Syllabus'); @@ -180,20 +310,13 @@ ENDSCRIPT } # ---------------------------------------------------------- Load syllabus info my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum); - my $allowed=0; + my %displayfields; # 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'} - && $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; } - } -#store what the user typed in - if (($allowed) && ($env{'form.storesyl'})) { + if ($allowed) { +#store what the user typed in to the template + if ($env{'form.storesyl'}) { foreach my $syl_field (keys(%syllabusfields)) { my $field=$env{'form.'.$syl_field}; chomp($field); @@ -238,6 +361,160 @@ ENDSCRIPT $syllabus{'uploaded.name'}=$env{'user.name'}; $syllabus{'uploaded.lastmodified'}=time; &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum); + my %storehash; + if ($courseenv{'uploadedsyllabus'}) { + &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus'); + $storehash{'uploadedsyllabus'} = ''; + } + if ($courseenv{'externalsyllabus'}) { + &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus'); + $storehash{'externalsyllabus'} = ''; + } + if ($courseenv{'externalsyllabus'} || $courseenv{'uploadedsyllabus'}) { + &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum); + undef($uploaded); + undef($external); + } + } elsif ($env{'form.storeurl'}) { + if ($env{'form.externalsyllabus'} =~ m{^https?://}) { + if ($env{'form.externalsyllabus'} eq $external) { + $r->print('
' - .&mt('This syllabus can be publicly viewed at [_1]' - ,''.$protocol.'://'.&Apache::lonnet::hostname($homeserver).$r->uri.'') - .' '.&Apache::loncommon::help_open_topic('Syllabus_ExtLink') - .'
' - .'' - .&mt('Instead of using this template you can specify an external URL as Syllabus in the [_1]Course Configuration[_2].' - ,'','') - .'
' - .''. + &mt('All feeds currently hidden'). + $msg. + '
'); + } else { + $r->print(''. + &mt('No current feeds'). + $msg. + '
'); + } + $rsslinktext = &mt('Manage Course RSS Feeds/Blogs'); + if ($crstype eq 'Community') { + $rsslinktext = &mt('Manage Communiity RSS Feeds/Blogs'); + } + } my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html'; - $r->print( ''.&mt('New RSS Feed or Blog').''); - &Apache::lontemplate::print_end_template($r); - } elsif (&Apache::lonrss::advertisefeeds($cnum,$cdom) ne '') { - &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box'); - $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit)); + $r->print( ''.$rsslinktext.''); &Apache::lontemplate::print_end_template($r); + } else { + unless ($syllabus{'000_showrssfeeds'} eq 'no') { + my $feeds = &Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit); + if ($feeds ne '') { + &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box'); + $r->print($feeds); + &Apache::lontemplate::print_end_template($r); + } + } } - } else { $r->print(&Apache::lonxml::xmlparse($r,'tex',$day)); } @@ -381,8 +693,9 @@ ENDSCRIPT $r->print('