--- loncom/homework/structuretags.pm 2001/08/20 15:56:47 1.62
+++ loncom/homework/structuretags.pm 2015/09/14 13:45:19 1.539
@@ -1,26 +1,191 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
-# 2/19 Guy
-# 6/26/2001 fixed extra web display at end of tags
-# 8/17,8/18,8/20 Gerd Kortemeyer
+#
+# $Id: structuretags.pm,v 1.539 2015/09/14 13:45:19 raeburn Exp $
+#
+# Copyright Michigan State University Board of Trustees
+#
+# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
+#
+# LON-CAPA is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# LON-CAPA is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with LON-CAPA; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# /home/httpd/html/adm/gpl.txt
+#
+# http://www.lon-capa.org/
+#
+###
+
+=pod
+
+=head1 NAME
+
+Apache::structuretags
+
+=head1 SYNOPSIS
+
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+
+=head1 NOTABLE SUBROUTINES
+
+=over
+
+=item
+
+=back
+
+=cut
+
package Apache::structuretags;
use strict;
use Apache::lonnet;
+use Apache::File();
+use Apache::lonmenu;
+use Apache::lonlocal;
+use Apache::lonxml;
+use Apache::londefdef;
+use Apache::lonenc();
+use Apache::loncommon();
+use Time::HiRes qw( gettimeofday tv_interval );
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
+
+BEGIN {
+ &Apache::lonxml::register('Apache::structuretags',('block','languageblock','translated','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startpartmarker','startouttext','endpartmarker','endouttext','simpleeditbutton','definetag'));
+}
+
+
+#---------------------------------------------------------------------------------
+#
+# This section of code deals with hyphenation management.
+# We must do three things:
+# - keep track fo the desired languages to alter the header.
+# - provide hyphenation selection as needed by each language that appears in the
+# text.
+# - Provide the header text needed to make available the desired hyphenations.
+#
+#
+
+# Hash whose keys are the languages encountered in the document/resource.
+#
+
+my %languages_required;
+##
+# Given a language selection as input returns a chunk of LaTeX that
+# selects the required hyphenator.
+#
+# @param language - the language being selected.
+# @return string
+# @retval The LaTeX needed to select the hyphenation appropriate to the language.
+#
+sub select_hyphenation {
+ my $language = shift;
+
+ $language = &Apache::loncommon::latexlanguage($language); # Translate -> latex language.
+
+ # If there is no latex language there's not much we can do:
+
+ if ($language) {
+ &require_language($language);
+ my $babel_hyphenation = "\\selectlanguage{$language}";
+
+ return $babel_hyphenation;
+ } else {
+ return '';
+ }
+}
+##
+# Selects hyphenation based on the current problem metadata.
+# This requires that
+# - There is a language metadata item set for the problem.
+# - The language has a latex/babel hyphenation.
+#
+# @note: Uses &Apache::lonxml::request to locate the Uri associated with
+# this problem.
+# @return string (possibly empty).
+# @retval If not empty an appropriate \selectlanguage{} directive.
+#
+sub select_metadata_hyphenation {
+ my $uri = $Apache::lonxml::request->uri;
+ my $language = &Apache::lonnet::metadata($uri, 'language');
+ my $latex_language = &Apache::loncommon::latexhyphenation($language);
+ if ($latex_language) {
+ return '\selectlanguage{'.$latex_language."}\n";
+ }
+ return ''; # no latex hyphenation or no lang metadata.
+}
+
-sub BEGIN {
- &Apache::lonxml::register('Apache::structuretags',('block','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','startouttext','endouttext'));
-# &Apache::lonxml::register_insert('problem','',('part','postanswerdate','preduedate'))
+##
+# Clears the set of languages required by the document being rendered.
+#
+sub clear_required_languages {
+ %languages_required = ();
+}
+##
+# Allows an external client of this module to register a need for a language:
+#
+# @param LaTeX language required:
+#
+sub require_language {
+ my $language = shift;
+ $languages_required{$language} = 1;
+}
+
+##
+# Provides the header for babel that indicates the languages
+# the document requires.
+# @return string
+# @retval \usepackage[lang1,lang2...]{babel}
+# @retval '' if there are no languages_required.
+sub languages_header {
+ my $header ='';
+ my @languages = (keys(%languages_required));
+
+ # Only generate the header if there are languages:
+
+ if (scalar @languages) {
+ my $language_list = join(',', (@languages));
+ $header = '\usepackage['.$language_list."]{babel}\n";
+ }
+ return $header;
}
+#----------------------------------------------------------------------------------
+
sub start_web {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
- my $bodytext=&Apache::lonxml::get_all_text("/web",$$parser[$#$parser]);
- if ($target eq 'web') {
- return $bodytext;
- }
- return '';
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ if ($target ne 'edit' && $target ne 'modified') {
+ my $bodytext=&Apache::lonxml::get_all_text("/web",$parser,$style);
+ if ($target eq 'web' || $target eq 'webgrade') {
+ return $bodytext;
+ }
+ } elsif ($target eq "edit" ) {
+ my $bodytext =
+ &Apache::lonxml::get_all_text_unbalanced("/web",$parser);
+ my $result = &Apache::edit::tag_start($target,$token);
+ $result .= &Apache::edit::editfield($token->[1],$bodytext,'',80,1);
+ return $result;
+ } elsif ( $target eq "modified" ) {
+ return $token->[4].&Apache::edit::modifiedfield("/web",$parser);
+ }
+ return '';
}
sub end_web {
@@ -28,513 +193,2904 @@ sub end_web {
}
sub start_tex {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
- my $bodytext=&Apache::lonxml::get_all_text("/tex",$$parser[$#$parser]);
- if ($target eq 'tex') {
- return $bodytext
- }
- return '';
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ my $result='';
+ if ($target ne 'edit' && $target ne 'modified') {
+ my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser,$style);
+ if ($target eq 'tex') {
+
+ # If inside a table, occurrences of \\ must be removed;
+ # else the table blows up.
+
+ if (&Apache::londefdef::is_inside_of($tagstack, "table")) {
+ $bodytext =~ s/\\\\//g;
+ }
+ return $bodytext.'{}';
+ }
+ } elsif ($target eq "edit" ) {
+ my $bodytext =
+ &Apache::lonxml::get_all_text_unbalanced("/tex",$parser);
+ my $result = &Apache::edit::tag_start($target,$token);
+ $result .= &Apache::edit::editfield($token->[1],$bodytext,'',80,1);
+ return $result;
+ } elsif ( $target eq "modified" ) {
+ return $token->[4].&Apache::edit::modifiedfield("/tex",$parser);
+ }
+ return $result;;
}
sub end_tex {
return '';
}
-sub page_start {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
- my $result=&Apache::londefdef::start_html($target,$token,$tagstack,$parstack,$parser,$safeeval);
- my $head_tag_start='
'.&Apache::lonxml::registerurl();
- my $body_tag_start='
+// 0) {
+ setTimeout(function(){
+ \$( "#msg_"+buttonId ).css({"display": "none"});
+ if (( \$(this.form).id == "LC_page" ) && (\$('input[name="all_submit"]').length )) {
+ if (buttonId != "all_submit") {
+ if (( "#"+buttonId+"_pressed" ).length) {
+ \$( "#"+buttonId+"_pressed" ).val( "" );
+ }
+ }
+ }
+ \$( ".LC_hwk_submit" ).prop( "disabled", false);
+ \$( ".LC_textline" ).prop( "readonly", false);
+ submithandled = 0;
+ keypresshandled = 0;
+ }, timeout);
+ }
+ return true;
+ }
+ }
+ });
}
- $body_tag_start.='>';
- return ($result,$head_tag_start,$body_tag_start);
+});
+
+// ]]>
+
+JS
+}
+
+sub setmode_javascript {
+ return <<"ENDSCRIPT";
+
+ENDSCRIPT
}
-sub start_problem {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+sub page_start {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name,
+ $extra_head)=@_;
+ my %found;
+ foreach my $taginside (@$tagstack) {
+ foreach my $taglookedfor ('html','body','form') {
+ if ($taginside =~ /^$taglookedfor$/i) {$found{$taglookedfor} = 1;}
+ }
+ }
+
+ if ($target eq 'tex') {
+ return
+ &Apache::londefdef::start_html($target,$token,$tagstack,
+ $parstack,$parser,$safeeval);
+ }
-#intialize globals
- $Apache::inputtags::part='0';
- @Apache::inputtags::responselist = ();
- @Apache::inputtags::previous=();
- $Apache::lonhomework::type=&Apache::lonnet::EXT('resource.0.type');
- &Apache::lonxml::debug("Found this to be of type :$Apache::lonhomework::type:");
- if ($Apache::lonhomework::type eq '') {
- my $uri=$ENV{'request.uri'};
- if ($uri=~/\.(\w+)$/) {
- $Apache::lonhomework::type=$1;
- &Apache::lonxml::debug("Using type of $1");
+ $extra_head .= &homework_js().
+ &Apache::lonhtmlcommon::dragmath_js("EditMathPopup");
+ if (&Apache::lonhtmlcommon::htmlareabrowser()) {
+ my %textarea_args = (
+ dragmath => 'math',
+ );
+ $extra_head .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
+ }
+ my $is_task = ($env{'request.uri'} =~ /\.task$/);
+ my ($needs_upload,$partlist);
+ my ($symb)= &Apache::lonnet::whichuser();
+ my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
+ if ($is_task) {
+ $extra_head .= &Apache::lonhtmlcommon::file_submissionchk_js();
} else {
- $Apache::lonhomework::type='problem';
- &Apache::lonxml::debug("Using default type, problem, :$uri:");
+ if (&Apache::lonnet::EXT("resource.$Apache::inputtags::part.uploadedfiletypes") ne '') {
+ unless ($env{'request.state'} eq 'construct') {
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (ref($navmap)) {
+ my $mapres = $navmap->getResourceByUrl($map);
+ my $is_page;
+ if (ref($mapres)) {
+ $is_page = $mapres->is_page();
+ }
+ unless ($is_page) {
+ $needs_upload = 1;
+ }
+ if ((ref($tagstack) eq 'ARRAY') && ($tagstack->[-1] eq 'problem')) {
+ my $res = $navmap->getBySymb($symb);
+ if (ref($res)) {
+ $partlist = $res->parts();
+ }
+ }
+ }
+ }
+ } else {
+ unless ($env{'request.state'} eq 'construct') {
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (ref($navmap)) {
+ my $mapres = $navmap->getResourceByUrl($map);
+ my $is_page;
+ if (ref($mapres)) {
+ $is_page = $mapres->is_page();
+ }
+ if ($is_page) {
+ if ((ref($tagstack) eq 'ARRAY') && ($tagstack->[-1] eq 'problem')) {
+ my $res = $navmap->getBySymb($symb);
+ if (ref($res)) {
+ $partlist = $res->parts();
+ }
+ }
+ } else {
+ my $res = $navmap->getBySymb($symb);
+ if (ref($res)) {
+ $partlist = $res->parts();
+ if (ref($partlist) eq 'ARRAY') {
+ foreach my $part (@{$partlist}) {
+ my @types = $res->responseType($part);
+ my @ids = $res->responseIds($part);
+ for (my $i=0; $i < scalar(@ids); $i++) {
+ if ($types[$i] eq 'essay') {
+ my $partid = $part.'_'.$ids[$i];
+ if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
+ $needs_upload = 1;
+ last;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if ($needs_upload) {
+ $extra_head .= &Apache::lonhtmlcommon::file_submissionchk_js()
+ .'';
+ }
}
- }
-#adeed vars to the scripting enviroment
- my $expression='$external::part='.$Apache::inputtags::part.';';
- &Apache::run::run($expression,$safeeval);
- my $status;
- my $accessmsg;
-
- #should get back a or the neccesary stuff to start XML/MathML
- my ($result,$head_tag_start,$body_tag_start)=
- &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
-
- if ($Apache::lonhomework::type eq 'exam') {
- if ($target eq 'web') {
- my $token=$Apache::lonhomework::history{"resource.0.outtoken"};
- if (($ENV{'form.doescheckout'}) && (!$token)) {
- $token=&Apache::lonxml::maketoken();
- $Apache::lonhomework::history{"resource.0.outtoken"}=$token;
- }
- $body_tag_start.=&Apache::lonxml::printtokenheader($target,$token);
- if ($ENV{'user.adv'}) {
- $body_tag_start.=&Apache::lonxml::tokeninputfield;
- }
- }
- if ($target eq 'meta') {
-
- return (<
-
-
-
-
-
-
-ENDSTORES
- }
- }
- if ($target eq 'web' || $target eq 'grade') {
- ($status,$accessmsg) = &Apache::lonhomework::check_access('0');
- push (@Apache::inputtags::status,$status);
- my $expression='$external::datestatus="'.$status.'";';
- $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
- &Apache::run::run($expression,$safeeval);
- if (( $status eq 'CLOSED' ) ||
- ( $status eq 'UNCHECKEDOUT') ||
- ( $status eq 'BANNED')) {
- my $bodytext=&Apache::lonxml::get_all_text("/problem",$$parser[$#$parser]);
- if ( $target eq "web" ) {
- $result.= $head_tag_start.'';
- my $msg=$body_tag_start.
- '
Not open to be viewed
';
- if ($status eq 'CLOSED') {
- $msg.='The problem '.$accessmsg;
- } elsif ($status eq 'UNCHECKEDOUT') {
- $msg.=(<The resource needs to be checked out
-As a resource gets checked out, a unique timestamped ID is given to it, and a
-permanent record is left in the system.
-
-Checking out resources is subject to course policies, and may exclude future
-credit even if done erroneously.
-
-\n".&Apache::loncommon::end_page();
+}
+
+sub option {
+ my ($value,$name) = @_;
+ my $result ="