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