Annotation of rat/lonpage.pm, revision 1.110
1.1 www 1: # The LearningOnline Network with CAPA
2: # Page Handler
3: #
1.110 ! raeburn 4: # $Id: lonpage.pm,v 1.109 2015/07/09 00:11:56 raeburn Exp $
1.29 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.30 harris41 28: ###
1.1 www 29:
1.88 jms 30:
31:
32:
1.1 www 33: package Apache::lonpage;
34:
35: use strict;
36: use Apache::Constants qw(:common :http);
1.70 albertel 37: use Apache::lonnet;
1.30 harris41 38: use Apache::loncommon();
1.102 raeburn 39: use Apache::lonhtmlcommon;
1.21 www 40: use Apache::lonxml();
1.57 raeburn 41: use Apache::lonlocal;
1.49 www 42: use Apache::lonmenu;
1.6 www 43: use HTML::TokeParser;
1.1 www 44: use GDBM_File;
1.39 www 45: use Apache::lonsequence;
1.75 www 46: use lib '/home/httpd/lib/perl/';
47: use LONCAPA;
48:
1.1 www 49:
1.2 www 50: # -------------------------------------------------------------- Module Globals
51: my %hash;
52: my @rows;
1.6 www 53:
54: # ------------------------------------------------------------------ Euclid gcd
55:
56: sub euclid {
57: my ($e,$f)=@_;
58: my $a; my $b; my $r;
59: if ($e>$f) { $b=$e; $r=$f; } else { $r=$e; $b=$f; }
60: while ($r!=0) {
61: $a=$b; $b=$r;
62: $r=$a%$b;
63: }
64: return $b;
65: }
1.2 www 66:
67: # ------------------------------------------------------------ Build page table
68:
69: sub tracetable {
70: my ($sofar,$rid,$beenhere)=@_;
71: my $further=$sofar;
1.57 raeburn 72: my $randomout=0;
1.70 albertel 73: unless ($env{'request.role.adv'}) {
1.57 raeburn 74: $randomout = $hash{'randomout_'.$rid};
75: }
1.2 www 76: unless ($beenhere=~/\&$rid\&/) {
1.57 raeburn 77: $beenhere.=$rid.'&';
78: unless ($randomout) {
79: if (defined($hash{'is_map_'.$rid})) {
80: if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
81: (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
82: my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
83: $sofar=
84: &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
1.87 albertel 85: '&'.$frid.$beenhere);
1.57 raeburn 86: $sofar++;
87: if ($hash{'src_'.$frid}) {
88: my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});
89: if (($brepriv eq '2') || ($brepriv eq 'F')) {
90: if (defined($rows[$sofar])) {
91: $rows[$sofar].='&'.$frid;
92: } else {
93: $rows[$sofar]=$frid;
94: }
95: }
96: }
97: }
98: } else {
99: $sofar++;
100: if ($hash{'src_'.$rid}) {
101: my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid});
102: if (($brepriv eq '2') || ($brepriv eq 'F')) {
103: if (defined($rows[$sofar])) {
104: $rows[$sofar].='&'.$rid;
105: } else {
106: $rows[$sofar]=$rid;
107: }
108: }
109: }
110: }
111: }
112:
113: if (defined($hash{'to_'.$rid})) {
114: my $mincond=1;
115: my $next='';
116: foreach (split(/\,/,$hash{'to_'.$rid})) {
117: my $thiscond=
1.11 www 118: &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
1.57 raeburn 119: if ($thiscond>=$mincond) {
120: if ($next) {
121: $next.=','.$_.':'.$thiscond;
122: } else {
123: $next=$_.':'.$thiscond;
124: }
125: if ($thiscond>$mincond) { $mincond=$thiscond; }
126: }
127: }
128: foreach (split(/\,/,$next)) {
129: my ($linkid,$condval)=split(/\:/,$_);
130: if ($condval>=$mincond) {
131: my $now=&tracetable($sofar,$hash{'goesto_'.$linkid},$beenhere);
132: if ($now>$further) { $further=$now; }
133: }
134: }
135: }
1.2 www 136: }
137: return $further;
138: }
139:
1.1 www 140: # ================================================================ Main Handler
141:
142: sub handler {
143: my $r=shift;
144:
1.3 www 145: # ------------------------------------------- Set document type for header only
1.1 www 146:
1.3 www 147: if ($r->header_only) {
1.70 albertel 148: if ($env{'browser.mathml'}) {
1.53 www 149: &Apache::loncommon::content_type($r,'text/xml');
1.3 www 150: } else {
1.53 www 151: &Apache::loncommon::content_type($r,'text/html');
1.3 www 152: }
153: $r->send_http_header;
154: return OK;
155: }
1.43 sakharuk 156:
1.39 www 157: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
158: ['forceselect','launch']);
1.43 sakharuk 159: my $number_of_columns = 1;
1.37 sakharuk 160: my $requrl=$r->uri;
1.70 albertel 161: my $target = $env{'form.grade_target'};
1.94 raeburn 162:
163: # Short term solution: define target as 'tex_answer' when retrieving answers
164: # for resources in a .page when generating printouts.
165: # A better long-term fix would be to modify the way problem rendering, and
166: # answer rendering are retrieved for individual resources when printing a .page,
167: # so rendered problem and answer are sequential for individual resources in
168: # the .page
169: #
170: if ($target eq 'answer') {
171: if ($env{'form.answer_output_mode'} eq 'tex') {
172: $target = 'tex_answer';
173: }
174: }
1.55 www 175: # &Apache::lonnet::logthis("Got a target of $target");
1.54 albertel 176: if ($target eq 'meta') {
177: &Apache::loncommon::content_type($r,'text/html');
178: $r->send_http_header;
179: return OK;
180: }
1.1 www 181: # ----------------------------------------------------------------- Tie db file
1.70 albertel 182: if (($env{'request.course.fn'}) && (!$env{'form.forceselect'})) {
183: my $fn=$env{'request.course.fn'};
1.1 www 184: if (-e "$fn.db") {
1.44 albertel 185: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) {
1.1 www 186: # ------------------------------------------------------------------- Hash tied
187: my $firstres=$hash{'map_start_'.$requrl};
188: my $lastres=$hash{'map_finish_'.$requrl};
189: if (($firstres) && ($lastres)) {
190: # ----------------------------------------------------------------- Render page
191:
1.3 www 192: @rows=();
1.2 www 193:
1.45 www 194: &tracetable(0,$firstres,'&');
1.2 www 195:
1.9 www 196: # ------------------------------------------------------------ Add to symb list
197:
1.2 www 198: my $i;
1.9 www 199: my %symbhash=();
200: for ($i=0;$i<=$#rows;$i++) {
201: if ($rows[$i]) {
202: my @colcont=split(/\&/,$rows[$i]);
1.73 albertel 203: foreach my $rid (@colcont) {
204: my ($mapid,$resid)=split(/\./,$rid);
205: $symbhash{$hash{'src_'.$rid}}=
206: [$hash{'src_'.$rid},$resid];
1.30 harris41 207: }
1.9 www 208: }
209: }
210: &Apache::lonnet::symblist($requrl,%symbhash);
211:
212: # ------------------------------------------------------------------ Page parms
213:
1.4 www 214: my $j;
1.6 www 215: my $lcm=1;
216: my $contents=0;
1.7 www 217: my $nforms=0;
1.96 raeburn 218: my $nuploads=0;
1.110 ! raeburn 219: my $ntimers=0;
1.96 raeburn 220: my %turninpaths;
221: my %multiresps;
222: my $turninparent;
1.6 www 223:
224: my %ssibody=();
225: my %ssibgcolor=();
226: my %ssitext=();
227: my %ssilink=();
228: my %ssivlink=();
229: my %ssialink=();
1.14 www 230:
1.6 www 231: my %cellemb=();
1.99 raeburn 232: my %cellexternal=();
1.3 www 233:
1.7 www 234: my $allscript='';
235: my $allmeta='';
236:
237: my $isxml=0;
238: my $xmlheader='';
239: my $xmlbody='';
240:
1.3 www 241: # --------------------------------------------- Get SSI output, post parameters
242:
1.2 www 243: for ($i=0;$i<=$#rows;$i++) {
1.4 www 244: if ($rows[$i]) {
1.6 www 245: $contents++;
1.3 www 246: my @colcont=split(/\&/,$rows[$i]);
1.6 www 247: $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
1.30 harris41 248: foreach (@colcont) {
1.3 www 249: my $src=$hash{'src_'.$_};
1.99 raeburn 250: my ($extension)=($src=~/\.(\w+)$/);
251: $cellexternal{$_}=($hash{'ext_'.$_} eq 'true:');
1.61 albertel 252: if ($hash{'encrypted_'.$_}) {
253: $src=&Apache::lonenc::encrypted($src);
254: }
255: $cellemb{$_}=
256: &Apache::loncommon::fileembstyle($extension);
1.99 raeburn 257: if ($cellexternal{$_}) {
258: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
259: $ssibody{$_} = <<ENDEXT;
260: <iframe src="$src" width="100%">No iframe support!</iframe>
261: ENDEXT
262: }
263: } elsif ($cellemb{$_} eq 'ssi') {
1.3 www 264: # --------------------------------------------------------- This is an SSI cell
1.64 albertel 265: my ($mapid,$resid)=split(/\./,$_);
266: my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$src);
267:
1.5 www 268: my $prefix=$_.'_';
1.101 raeburn 269: my $idprefix= join('_',($mapid,$resid,''));
1.64 albertel 270: my %posthash=('request.prefix' => $prefix,
1.71 albertel 271: 'LONCAPA_INTERNAL_no_discussion' => 'true',
1.64 albertel 272: 'symb' => $symb);
1.94 raeburn 273: if (($env{'form.grade_target'} eq 'tex') ||
274: ($env{'form.answer_output_mode'} eq 'tex')) {
1.70 albertel 275: $posthash{'grade_target'}=$env{'form.grade_target'};
276: $posthash{'textwidth'}=$env{'form.textwidth'};
277: $posthash{'problem_split'}=$env{'form.problem_split'};
278: $posthash{'latex_type'}=$env{'form.latex_type'};
279: $posthash{'rndseed'}=$env{'form.rndseed'};
1.94 raeburn 280: $posthash{'answer_output_mode'} = $env{'form.answer_output_mode'};
1.56 sakharuk 281: }
1.72 albertel 282: my $submitted=exists($env{'form.all_submit'});
283: if (!$submitted) {
284: foreach my $key (keys(%env)) {
285: if ($key=~/^form.\Q$prefix\Esubmit_/) {
286: $submitted=1;last;
287: }
288: }
289: }
290: if ($submitted) {
291: foreach my $key (keys(%env)) {
292: if ($key=~/^form.\Q$prefix\E/) {
293: my $name=$key;
294: $name=~s/^form.\Q$prefix\E//;
295: $posthash{$name}=$env{$key};
296: }
297: }
298: if (exists($env{'form.all_submit'})) {
299: $posthash{'all_submit'}='yes';
300: }
1.7 www 301: }
1.5 www 302: my $output=Apache::lonnet::ssi($src,%posthash);
1.77 albertel 303: $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+?// END LON-CAPA Internal\s*(-->)?\s||gs;
1.94 raeburn 304: if (($target eq 'tex') || ($target eq 'tex_answer')) {
1.46 sakharuk 305: $output =~ s/^([^&]+)\\begin{document}//;
306: $output =~ s/\\end{document}//;
1.92 foxr 307: # $output = '\parbox{\minipagewidth}{ '.$output.' }';
1.46 sakharuk 308: #some additional cleanup necessary for LateX (due to limitations of table environment
309: $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
310: }
1.107 raeburn 311: my $matheditor;
312: if ($output =~ /\Qjavascript:LC_mathedit_HWVAL_\E/) {
313: $matheditor = 'dragmath';
314: } elsif ($output =~ /LCmathField/) {
315: $matheditor = 'lcmath';
316: }
1.6 www 317: my $parser=HTML::TokeParser->new(\$output);
318: my $token;
1.12 www 319: my $thisdir=$src;
1.6 www 320: my $bodydef=0;
1.7 www 321: my $thisxml=0;
1.12 www 322: my @rlinks=();
1.7 www 323: if ($output=~/\?xml/) {
324: $isxml=1;
325: $thisxml=1;
326: $output=~
327: /((?:\<(?:\?xml|\!DOC|html)[^\>]*(?:\>|\>\]\>)\s*)+)\<body[^\>]*\>/si;
328: $xmlheader=$1;
329: }
1.12 www 330: while ($token=$parser->get_token) {
331: if ($token->[0] eq 'S') {
332: if ($token->[1] eq 'a') {
333: if ($token->[2]->{'href'}) {
334: $rlinks[$#rlinks+1]=
335: $token->[2]->{'href'};
336: }
337: } elsif ($token->[1] eq 'img') {
338: $rlinks[$#rlinks+1]=
339: $token->[2]->{'src'};
340: } elsif ($token->[1] eq 'embed') {
341: $rlinks[$#rlinks+1]=
342: $token->[2]->{'src'};
343: } elsif ($token->[1] eq 'base') {
344: $thisdir=$token->[2]->{'href'};
345: } elsif ($token->[1] eq 'body') {
1.7 www 346: $bodydef=1;
347: $ssibgcolor{$_}=$token->[2]->{'bgcolor'};
348: $ssitext{$_}=$token->[2]->{'text'};
349: $ssilink{$_}=$token->[2]->{'link'};
350: $ssivlink{$_}=$token->[2]->{'vlink'};
351: $ssialink{$_}=$token->[2]->{'alink'};
352: if ($thisxml) {
353: $xmlbody=$token->[4];
354: }
1.12 www 355: } elsif ($token->[1] eq 'meta') {
1.28 albertel 356: if ($token->[4] !~ m:/>$:) {
1.7 www 357: $allmeta.="\n".$token->[4].'</meta>';
1.28 albertel 358: } else {
359: $allmeta.="\n".$token->[4];
360: }
1.12 www 361: } elsif (($token->[1] eq 'script') &&
362: ($bodydef==0)) {
1.7 www 363: $allscript.="\n\n"
364: .$parser->get_text('/script');
1.6 www 365: }
1.12 www 366: }
367: }
1.6 www 368: if ($output=~/\<body[^\>]*\>(.*)/si) {
369: $output=$1;
370: }
371: $output=~s/\<\/body\>.*//si;
1.7 www 372: if ($output=~/\<form/si) {
1.110 ! raeburn 373: my $hastimer;
1.7 www 374: $nforms++;
375: $output=~s/\<form[^\>]*\>//gsi;
376: $output=~s/\<\/form[^\>]*\>//gsi;
1.96 raeburn 377: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*HWFILE/) {
378: $nuploads++;
379: }
1.110 ! raeburn 380: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*accessbutton/) {
! 381: $ntimers++;
! 382: $hastimer = 1;
! 383: }
1.17 www 384: $output=~
1.80 albertel 385: s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
1.101 raeburn 386: $output=~
387: s/\<((?:input|select|button|textarea)[^\>]+)id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 id="$idprefix$2" $3\>/gsi;
1.110 ! raeburn 388: if ($hastimer) {
! 389: $output=~
! 390: s/\<(input[^\>]+name=\Q"$prefix\Eaccessbutton"[^\>]+)(?:\Qdocument.markaccess.submit();\E)([^\>]*)\>/\<$1pageTimer(this.form,'$prefix')$2\>/gsi;
! 391: $output=~ s/\<(input[^\>]+name=\Q"$prefix\Emarkaccess"[^\>]+value=["'])(?:yes)(['"][^\>]*)\>/\<$1$2\>/gsi;
! 392: }
1.107 raeburn 393: if ($matheditor eq 'dragmath') {
394: $output=~
395: s/(\Qjavascript:LC_mathedit_\E)(HWVAL_)([^'"]+?)(\(['"]*)(\QHWVAL_\E\3['"]\)\;void\(0\)\;)/$1$idprefix$2$3$4$idprefix$5/g;
396: $output=~
397: s/(function\s+LC_mathedit_)(HWVAL_)([^'"]+?)(\s+\(LCtextline\))/$1$idprefix$2$3$4/g;
398: } elsif ($matheditor eq 'lcmath') {
399: $output=~
400: s/(var\s+LCmathField\s+=\s+document\.getElementById\(['"])([^'"]+?)(['"]\)\;)/$1$idprefix$2$3/g;
401: }
1.105 raeburn 402: $output=~
403: s/(\Q<div id="msg_\E)(\Qsubmit_\E)([^"]*)(\Q" style="display:none">\E)/<input type="hidden" name="$prefix$2$3_pressed" id="$idprefix$2$3_pressed" value="" \/>$1$idprefix$2$3$4/g;
404: $output=~
405: s/(\Q<td class="LC_status_\E)(\Qsubmit_\E)([^\"]*)(\s*[^\"]*"\>)/$1$idprefix$2$3$4/g;
1.96 raeburn 406: if ($nuploads) {
407: $output=~
408: s/\<(input[^\>]+name=\"\Q$prefix\EHWFILE[^\>]+)\s*id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\)]*)\>/\<$1 id="$prefix$2" $3\>/gsi;
409: ($turninpaths{$prefix},$multiresps{$prefix}) =
410: &Apache::loncommon::get_turnedin_filepath($symb,$env{'user.name'},$env{'user.domain'});
411: if ($turninparent eq '') {
412: $turninparent = $turninpaths{$prefix};
413: $turninparent =~ s{(/[^/]+)$}{};
414: }
415: }
1.95 raeburn 416: $output=~
417: s/\<((?:input|select)[^\>]+\Qjavascript:setSubmittedPart\E)\(\s*[\'\"]([^\'\"]+)[\'\"]*\s*\)/\<$1('$2','$prefix')/gsi;
1.108 raeburn 418: $output=~
419: s/\<(input[^\>]+\Qonfocus=\"javascript:disableAutoComplete\E)\(\'([^\']+)\'\)(;\")/\<$1('$idprefix$2')$3/gsi;
1.7 www 420: }
1.12 www 421: $thisdir=~s/\/[^\/]*$//;
1.30 harris41 422: foreach (@rlinks) {
1.91 raeburn 423: unless (($_=~/^https?\:\/\//i) ||
1.31 albertel 424: ($_=~/^\//) ||
425: ($_=~/^javascript:/i) ||
426: ($_=~/^mailto:/i) ||
427: ($_=~/^\#/)) {
1.12 www 428: my $newlocation=
429: &Apache::lonnet::hreflocation($thisdir,$_);
430: $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
431: }
1.30 harris41 432: }
1.24 www 433: # -------------------------------------------------- Deal with Applet codebases
434: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
1.5 www 435: $ssibody{$_}=$output;
1.3 www 436: # ---------------------------------------------------------------- End SSI cell
437: }
1.30 harris41 438: }
1.4 www 439: }
1.2 www 440: }
1.6 www 441: unless ($contents) {
1.53 www 442: &Apache::loncommon::content_type($r,'text/html');
1.3 www 443: $r->send_http_header;
1.74 albertel 444: $r->print(&Apache::loncommon::start_page(undef,undef,
445: {'force_register' => 1,}));
1.59 raeburn 446: $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
1.74 albertel 447: $r->print('<br /><br />'.&mt('Please use the LON-CAPA navigation arrows to move to another item in the course').
448: &Apache::loncommon::end_page());
1.3 www 449: } else {
450: # ------------------------------------------------------------------ Build page
1.7 www 451:
452: # ---------------------------------------------------------------- Send headers
1.94 raeburn 453: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 454: if ($isxml) {
1.53 www 455: &Apache::loncommon::content_type($r,'text/xml');
1.37 sakharuk 456: } else {
1.53 www 457: &Apache::loncommon::content_type($r,'text/html');
1.37 sakharuk 458: }
1.74 albertel 459: $r->send_http_header;
1.7 www 460: # ------------------------------------------------------------------------ Head
1.37 sakharuk 461: if ($allscript) {
1.85 albertel 462: $allscript =
463: "\n".'<script type="text/javascript">'."\n".
464: $allscript.
465: "\n</script>\n";
1.37 sakharuk 466: }
1.96 raeburn 467: if (($nforms) && ($nuploads)) {
468: $allscript .= &Apache::lonhtmlcommon::file_submissionchk_js(\%turninpaths,\%multiresps);
469: }
1.101 raeburn 470: if (($nforms) && (&Apache::lonhtmlcommon::htmlareabrowser())) {
471: my %textarea_args = (
472: dragmath => 'math',
473: );
474: $allscript .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
475: }
1.110 ! raeburn 476: if ($ntimers) {
! 477: $allscript .= '<script type="text/javascript">'."\n".
! 478: '// <![CDATA['."\n".
! 479: 'function pageTimer(form,prefix) {'."\n".
! 480: " form.elements[prefix+'markaccess'].value = 'yes';\n".
! 481: " form.submit();\n".
! 482: '}'."\n".
! 483: '// ]]>'.
! 484: "\n</script>\n";
! 485: }
1.7 www 486: # ------------------------------------------------------------------ Start body
1.85 albertel 487: $r->print(&Apache::loncommon::start_page(undef,$allscript,
1.74 albertel 488: {'force_register' => 1,
489: 'bgcolor' => '#ffffff',}));
1.7 www 490: # ------------------------------------------------------------------ Start form
1.37 sakharuk 491: if ($nforms) {
1.96 raeburn 492: my $fmtag = '<form name="lonhomework" method="post" enctype="multipart/form-data"';
493: if ($nuploads) {
494: my $multi;
495: if ($nuploads > 1) {
496: $multi = 1;
497: }
498: $fmtag .= 'onsubmit="return file_submission_check(this,'."'$turninparent','$multi'".');"';
499: }
500: $fmtag .= ' action="'.
1.61 albertel 501: &Apache::lonenc::check_encrypt($requrl)
1.105 raeburn 502: .'" id="LC_page">';
1.96 raeburn 503: $r->print($fmtag);
1.40 sakharuk 504: }
1.94 raeburn 505: } elsif (($target eq 'tex') || ($target eq 'tex_answer')) {
1.92 foxr 506: # I think this is not needed as the header
507: # will be put in for each of the page parts
508: # by the londefdef.pm now that we are opening up
509: # the parts of a page.
510: #$r->print('\documentclass{article}
511: # \newcommand{\keephidden}[1]{}
512: # \usepackage[dvips]{graphicx}
513: # \usepackage{epsfig}
514: # \usepackage{calc}
515: # \usepackage{longtable}
516: # \begin{document}');
1.40 sakharuk 517: }
1.7 www 518: # ----------------------------------------------------------------- Start table
1.94 raeburn 519: if (($target eq 'tex') || ($target eq 'tex_answer')) {
1.92 foxr 520: # # $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
1.43 sakharuk 521: if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
1.40 sakharuk 522: } else {
1.63 albertel 523: $r->print('<table width="100%" cols="'.$lcm.'" border="0">');
1.37 sakharuk 524: }
1.78 www 525: # generate rows
1.5 www 526: for ($i=0;$i<=$#rows;$i++) {
527: if ($rows[$i]) {
1.94 raeburn 528: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 529: $r->print("\n<tr>");
530: }
1.4 www 531: my @colcont=split(/\&/,$rows[$i]);
1.6 www 532: my $avespan=$lcm/($#colcont+1);
533: for ($j=0;$j<=$#colcont;$j++) {
534: my $rid=$colcont[$j];
1.83 albertel 535: my $metainfo =&get_buttons(\%hash,$rid).'<br />';
1.94 raeburn 536: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 537: $r->print('<td colspan="'.$avespan.'"');
538: }
1.99 raeburn 539: if (($cellemb{$rid} eq 'ssi') || ($cellexternal{$rid})) {
1.94 raeburn 540: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 541: if ($ssibgcolor{$rid}) {
542: $r->print(' bgcolor="'.
543: $ssibgcolor{$rid}.'"');
544: }
545: $r->print('>'.$metainfo.'<font');
546:
547: if ($ssitext{$rid}) {
548: $r->print(' text="'.$ssitext{$rid}.'"');
549: }
550: if ($ssilink{$rid}) {
551: $r->print(' link="'.$ssilink{$rid}.'"');
552: }
553: if ($ssitext{$rid}) {
554: $r->print(' vlink="'.$ssivlink{$rid}.'"');
555: }
556: if ($ssialink{$rid}) {
557: $r->print(' alink="'.$ssialink{$rid}.'"');
558: }
559: $r->print('>');
560: }
1.99 raeburn 561: unless (($cellexternal{$rid}) &&
562: ($target eq 'tex') && ($target eq 'tex_answer')) {
563: $r->print($ssibody{$rid});
564: }
1.94 raeburn 565: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 566: $r->print('</font>');
1.41 www 567: }
1.70 albertel 568: if ($env{'course.'.
569: $env{'request.course.id'}.
1.41 www 570: '.pageseparators'} eq 'yes') {
1.94 raeburn 571: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.41 www 572: $r->print('<hr />');
1.77 albertel 573: }
1.37 sakharuk 574: }
575: } elsif ($cellemb{$rid} eq 'img') {
1.14 www 576: $r->print('>'.$metainfo.'<img src="'.
1.77 albertel 577: $hash{'src_'.$rid}.'" />');
1.13 www 578: } elsif ($cellemb{$rid} eq 'emb') {
1.14 www 579: $r->print('>'.$metainfo.'<embed src="'.
1.13 www 580: $hash{'src_'.$rid}.'"></embed>');
1.60 raeburn 581: } elsif (&Apache::lonnet::declutter($hash{'src_'.$rid}) !~/\.(sequence|page)$/) {
1.104 raeburn 582: $r->print($metainfo.'<b>'.$hash{'title_'.$rid}.'</b><br />');
583: unless ($cellemb{$rid} eq 'wrp') {
584: $r->print(&mt('It is recommended that you use an up-to-date virus scanner before handling this file.'));
585: }
586: $r->print('</p><p><table>'.
587: &Apache::londocs::entryline(0,
588: &mt("Click to download or use your browser's Save Link function"),
589: '/'.&Apache::lonnet::declutter($hash{'src_'.$rid})).
590: '</table></p><br />');
1.13 www 591: }
1.94 raeburn 592: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 593: $r->print('</td>');
1.40 sakharuk 594: } else {
1.92 foxr 595: # for (my $incol=1;$incol<=$avespan;$incol++) {
596: # $r->print(' & ');
597: # }
1.37 sakharuk 598: }
1.4 www 599: }
1.94 raeburn 600: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 601: $r->print('</tr>');
1.40 sakharuk 602: } else {
1.92 foxr 603: # $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
1.37 sakharuk 604: }
1.5 www 605: }
1.4 www 606: }
1.94 raeburn 607: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 608: $r->print("\n</table>");
1.40 sakharuk 609: } else {
1.92 foxr 610: # $r->print('\end{longtable}\strut');
1.37 sakharuk 611: }
1.7 www 612: # ---------------------------------------------------------------- Submit, etc.
613: if ($nforms) {
1.106 raeburn 614: my $class;
615: if ($nforms > 1) {
616: $class = ' class="LC_hwk_submit"';
1.110 ! raeburn 617: if ($ntimers) {
! 618: $nforms = 1;
! 619: $class = '';
! 620: }
1.106 raeburn 621: }
1.7 www 622: $r->print(
1.103 bisitz 623: '<input name="all_submit" value="'.&mt('Submit All').'" type="'.
1.106 raeburn 624: (($nforms>1)?'submit':'hidden').'"'.$class.' id="all_submit" />'.
625: '<div id="msg_all_submit" style="display:none">'.
626: &mt('Processing your submission ...').'</div></form>');
1.7 www 627: }
1.94 raeburn 628: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.76 albertel 629: $r->print(&Apache::loncommon::end_page({'discussion'
630: => 1,}));
1.40 sakharuk 631: } else {
632: $r->print('\end{document}'.$number_of_columns);
633: }
1.66 albertel 634: &Apache::lonnet::symblist($requrl,%symbhash);
1.69 albertel 635: my ($map,$id,$url)=&Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
636: &Apache::lonnet::symblist($map,'last_known'=>[$url,$id]);
1.3 www 637: # -------------------------------------------------------------------- End page
638: }
1.1 www 639: # ------------------------------------------------------------- End render page
640: } else {
1.67 albertel 641: &Apache::loncommon::content_type($r,'text/html');
1.3 www 642: $r->send_http_header;
1.39 www 643: &Apache::lonsequence::viewmap($r,$requrl);
1.1 www 644: }
645: # ------------------------------------------------------------------ Untie hash
646: unless (untie(%hash)) {
647: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
648: "Could not untie coursemap $fn (browse).</font>");
649: }
650: # -------------------------------------------------------------------- All done
651: return OK;
652: # ----------------------------------------------- Errors, hash could no be tied
653: }
654: }
655: }
1.67 albertel 656: &Apache::loncommon::content_type($r,'text/html');
1.39 www 657: $r->send_http_header;
658: &Apache::lonsequence::viewmap($r,$requrl);
659: return OK;
1.1 www 660: }
661:
1.83 albertel 662: sub get_buttons {
663: my ($hash,$rid) = @_;
664:
665: my $metainfo = '';
666: my $esrc=&Apache::lonnet::declutter($hash->{'src_'.$rid});
667: my ($mapid,$resid)=split(/\./,$rid);
668: my $symb=&Apache::lonnet::encode_symb($hash->{'map_id_'.$mapid},
669: $resid,
670: $hash->{'src_'.$rid});
1.109 raeburn 671: unless ($env{'request.role.adv'}) {
672: if (&Apache::lonnet::EXT('resource.0.buttonshide',$symb)) {
673: return;
674: }
675: }
1.83 albertel 676: if ($hash->{'encrypted_'.$rid}) {
677: $symb=&Apache::lonenc::encrypted($symb);
678: $esrc=&Apache::lonenc::encrypted($esrc);
679: }
680: if ($hash->{'src_'.$rid} !~ m-^/uploaded/-
1.99 raeburn 681: && $hash->{'src_'.$rid} !~ m{^https?://}
1.83 albertel 682: && !$env{'request.enc'}
683: && ($env{'request.role.adv'}
684: || !$hash->{'encrypted_'.$rid})) {
685: $metainfo .='<a name="'.&escape($symb).'" />'.
686: '<a href="'.$hash->{'src_'.$rid}.'.meta'.'" target="LONcatInfo">'.
1.100 bisitz 687: '<img src="/res/adm/pages/catalog.png" class="LC_icon"'.
688: ' alt="'.&mt('Show Metadata').'"'.
689: ' title="'.&mt('Show Metadata').'" />'.
1.83 albertel 690: '</a>';
691: }
1.99 raeburn 692: if (($hash->{'src_'.$rid} !~ m{^/uploaded/}) &&
693: ($hash->{'src_'.$rid} !~ m{^https?://})) {
1.98 raeburn 694: $metainfo .= '<a href="/adm/evaluate?postdata='.
695: &escape($esrc).
696: '" target="LONcatInfo">'.
1.100 bisitz 697: '<img src="/res/adm/pages/eval.png" class="LC_icon"'.
698: ' alt="'.&mt('Provide my evaluation of this resource').'"'.
699: ' title="'.&mt('Provide my evaluation of this resource').'" />'.
1.98 raeburn 700: '</a>';
701: }
1.97 www 702: if (($hash->{'src_'.$rid}=~/$LONCAPA::assess_re/) &&
1.83 albertel 703: ($hash->{'src_'.$rid} !~ m-^/uploaded/-)) {
704:
705: if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) {
706: $metainfo.=
707: '<a href="/adm/grades?symb='.&escape($symb).
708: # '&command=submission" target="LONcatInfo">'.
709: '&command=submission">'.
1.100 bisitz 710: '<img src="/adm/lonMisc/subm_button.png" class="LC_icon"'.
711: ' alt="'.&mt('View Submissions for a Student or a Group of Students').'"'.
712: ' title="'.&mt('View Submissions for a Student or a Group of Students').'" />'.
1.83 albertel 713: '</a>'.
714: '<a href="/adm/grades?symb='.&escape($symb).
715: # '&command=gradingmenu" target="LONcatInfo">'.
716: '&command=gradingmenu">'.
1.100 bisitz 717: '<img src="/res/adm/pages/pgrd.png" class="LC_icon"'.
718: ' alt="'.&mt('Content Grades').'"'.
719: ' title="'.&mt('Content Grades').'" />'.
1.83 albertel 720: '</a>';
721: }
722: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
723: $metainfo.=
724: '<a href="/adm/parmset?symb='.&escape($symb).
725: # '" target="LONcatInfo">'.
726: '" >'.
1.100 bisitz 727: '<img src="/adm/lonMisc/pprm_button.png" class="LC_icon"'.
728: ' alt="'.&mt('Content Settings').'"'.
729: ' title="'.&mt('Content Settings').'" />'.
1.83 albertel 730: '</a>';
731: }
732: }
1.102 raeburn 733: if (($env{'request.course.id'}) && (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
734: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
735: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
736: my $file=&Apache::lonnet::declutter($hash->{'src_'.$rid});
737: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
738: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,$hash->{'src_'.$rid},$symb);
739: if ($cfile ne '') {
740: my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
741: $forceedit,1,$symb,undef,
742: &escape($env{'form.title'}));
743: if ($jscall) {
744: my $icon = 'pcstr.png';
745: my $label = &mt('Edit');
746: my $title = &mt('Edit this resource');
747: my $pic = '<img src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$icon).'"'.
748: ' class="LC_icon" alt="'.$label.'" title="'.$title.'" />';
749: $metainfo .= ' <a href="javascript:'.$jscall.';">'.$pic.'</a>';
750: }
751: }
752: }
1.83 albertel 753: return $metainfo;
754: }
755:
1.1 www 756: 1;
757: __END__
758:
759:
1.89 jms 760: =head1 NAME
761:
762: Apache::lonpage - Page Handler
763:
764: =head1 SYNOPSIS
765:
766: Invoked by /etc/httpd/conf/srm.conf:
767:
768: <LocationMatch "^/res/.*\.page$>
769: SetHandler perl-script
770: PerlHandler Apache::lonpage
771: </LocationMatch>
772:
773: =head1 INTRODUCTION
774:
775: This module renders a .page resource.
776:
777: This is part of the LearningOnline Network with CAPA project
778: described at http://www.lon-capa.org.
779:
780: =head1 HANDLER SUBROUTINE
781:
782: This routine is called by Apache and mod_perl.
783:
784: =over 4
785:
786: =item *
787:
788: set document type for header only
789:
790: =item *
791:
792: tie db file
793:
794: =item *
795:
796: render page
797:
798: =item *
799:
800: add to symb list
801:
802: =item *
803:
804: page parms
805:
806: =item *
807:
808: Get SSI output, post parameters
1.1 www 809:
1.89 jms 810: =item *
811:
812: SSI cell rendering
813:
814: =item *
815:
816: Deal with Applet codebases
817:
818: =item *
819:
820: Build page
821:
822: =item *
823:
824: send headers
825:
826: =item *
827:
828: start body
829:
830: =item *
831:
832: start form
833:
834: =item *
835:
836: start table
837:
838: =item *
839:
840: submit element, etc, render page, untie hash
841:
842: =back
843:
844: =head1 OTHER SUBROUTINES
845:
846: =over 4
847:
848: =item *
849:
850: euclid() : Euclid's method for determining the greatest common denominator.
851:
852: =item *
853:
854: tracetable() : Build page table.
855:
856: =back
857:
858: =cut
1.1 www 859:
860:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>