Annotation of rat/lonpage.pm, revision 1.104
1.1 www 1: # The LearningOnline Network with CAPA
2: # Page Handler
3: #
1.104 ! raeburn 4: # $Id: lonpage.pm,v 1.103 2014/02/11 15:56:47 bisitz 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;
219: my %turninpaths;
220: my %multiresps;
221: my $turninparent;
1.6 www 222:
223: my %ssibody=();
224: my %ssibgcolor=();
225: my %ssitext=();
226: my %ssilink=();
227: my %ssivlink=();
228: my %ssialink=();
1.14 www 229:
1.6 www 230: my %cellemb=();
1.99 raeburn 231: my %cellexternal=();
1.3 www 232:
1.7 www 233: my $allscript='';
234: my $allmeta='';
235:
236: my $isxml=0;
237: my $xmlheader='';
238: my $xmlbody='';
239:
1.3 www 240: # --------------------------------------------- Get SSI output, post parameters
241:
1.2 www 242: for ($i=0;$i<=$#rows;$i++) {
1.4 www 243: if ($rows[$i]) {
1.6 www 244: $contents++;
1.3 www 245: my @colcont=split(/\&/,$rows[$i]);
1.6 www 246: $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
1.30 harris41 247: foreach (@colcont) {
1.3 www 248: my $src=$hash{'src_'.$_};
1.99 raeburn 249: my ($extension)=($src=~/\.(\w+)$/);
250: $cellexternal{$_}=($hash{'ext_'.$_} eq 'true:');
1.61 albertel 251: if ($hash{'encrypted_'.$_}) {
252: $src=&Apache::lonenc::encrypted($src);
253: }
254: $cellemb{$_}=
255: &Apache::loncommon::fileembstyle($extension);
1.99 raeburn 256: if ($cellexternal{$_}) {
257: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
258: $ssibody{$_} = <<ENDEXT;
259: <iframe src="$src" width="100%">No iframe support!</iframe>
260: ENDEXT
261: }
262: } elsif ($cellemb{$_} eq 'ssi') {
1.3 www 263: # --------------------------------------------------------- This is an SSI cell
1.64 albertel 264: my ($mapid,$resid)=split(/\./,$_);
265: my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$src);
266:
1.5 www 267: my $prefix=$_.'_';
1.101 raeburn 268: my $idprefix= join('_',($mapid,$resid,''));
1.64 albertel 269: my %posthash=('request.prefix' => $prefix,
1.71 albertel 270: 'LONCAPA_INTERNAL_no_discussion' => 'true',
1.64 albertel 271: 'symb' => $symb);
1.94 raeburn 272: if (($env{'form.grade_target'} eq 'tex') ||
273: ($env{'form.answer_output_mode'} eq 'tex')) {
1.70 albertel 274: $posthash{'grade_target'}=$env{'form.grade_target'};
275: $posthash{'textwidth'}=$env{'form.textwidth'};
276: $posthash{'problem_split'}=$env{'form.problem_split'};
277: $posthash{'latex_type'}=$env{'form.latex_type'};
278: $posthash{'rndseed'}=$env{'form.rndseed'};
1.94 raeburn 279: $posthash{'answer_output_mode'} = $env{'form.answer_output_mode'};
1.56 sakharuk 280: }
1.72 albertel 281: my $submitted=exists($env{'form.all_submit'});
282: if (!$submitted) {
283: foreach my $key (keys(%env)) {
284: if ($key=~/^form.\Q$prefix\Esubmit_/) {
285: $submitted=1;last;
286: }
287: }
288: }
289: if ($submitted) {
290: foreach my $key (keys(%env)) {
291: if ($key=~/^form.\Q$prefix\E/) {
292: my $name=$key;
293: $name=~s/^form.\Q$prefix\E//;
294: $posthash{$name}=$env{$key};
295: }
296: }
297: if (exists($env{'form.all_submit'})) {
298: $posthash{'all_submit'}='yes';
299: }
1.7 www 300: }
1.5 www 301: my $output=Apache::lonnet::ssi($src,%posthash);
1.77 albertel 302: $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+?// END LON-CAPA Internal\s*(-->)?\s||gs;
1.94 raeburn 303: if (($target eq 'tex') || ($target eq 'tex_answer')) {
1.46 sakharuk 304: $output =~ s/^([^&]+)\\begin{document}//;
305: $output =~ s/\\end{document}//;
1.92 foxr 306: # $output = '\parbox{\minipagewidth}{ '.$output.' }';
1.46 sakharuk 307: #some additional cleanup necessary for LateX (due to limitations of table environment
308: $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
309: }
1.6 www 310: my $parser=HTML::TokeParser->new(\$output);
311: my $token;
1.12 www 312: my $thisdir=$src;
1.6 www 313: my $bodydef=0;
1.7 www 314: my $thisxml=0;
1.12 www 315: my @rlinks=();
1.7 www 316: if ($output=~/\?xml/) {
317: $isxml=1;
318: $thisxml=1;
319: $output=~
320: /((?:\<(?:\?xml|\!DOC|html)[^\>]*(?:\>|\>\]\>)\s*)+)\<body[^\>]*\>/si;
321: $xmlheader=$1;
322: }
1.12 www 323: while ($token=$parser->get_token) {
324: if ($token->[0] eq 'S') {
325: if ($token->[1] eq 'a') {
326: if ($token->[2]->{'href'}) {
327: $rlinks[$#rlinks+1]=
328: $token->[2]->{'href'};
329: }
330: } elsif ($token->[1] eq 'img') {
331: $rlinks[$#rlinks+1]=
332: $token->[2]->{'src'};
333: } elsif ($token->[1] eq 'embed') {
334: $rlinks[$#rlinks+1]=
335: $token->[2]->{'src'};
336: } elsif ($token->[1] eq 'base') {
337: $thisdir=$token->[2]->{'href'};
338: } elsif ($token->[1] eq 'body') {
1.7 www 339: $bodydef=1;
340: $ssibgcolor{$_}=$token->[2]->{'bgcolor'};
341: $ssitext{$_}=$token->[2]->{'text'};
342: $ssilink{$_}=$token->[2]->{'link'};
343: $ssivlink{$_}=$token->[2]->{'vlink'};
344: $ssialink{$_}=$token->[2]->{'alink'};
345: if ($thisxml) {
346: $xmlbody=$token->[4];
347: }
1.12 www 348: } elsif ($token->[1] eq 'meta') {
1.28 albertel 349: if ($token->[4] !~ m:/>$:) {
1.7 www 350: $allmeta.="\n".$token->[4].'</meta>';
1.28 albertel 351: } else {
352: $allmeta.="\n".$token->[4];
353: }
1.12 www 354: } elsif (($token->[1] eq 'script') &&
355: ($bodydef==0)) {
1.7 www 356: $allscript.="\n\n"
357: .$parser->get_text('/script');
1.6 www 358: }
1.12 www 359: }
360: }
1.6 www 361: if ($output=~/\<body[^\>]*\>(.*)/si) {
362: $output=$1;
363: }
364: $output=~s/\<\/body\>.*//si;
1.7 www 365: if ($output=~/\<form/si) {
366: $nforms++;
367: $output=~s/\<form[^\>]*\>//gsi;
368: $output=~s/\<\/form[^\>]*\>//gsi;
1.96 raeburn 369: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*HWFILE/) {
370: $nuploads++;
371: }
1.17 www 372: $output=~
1.80 albertel 373: s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
1.101 raeburn 374: $output=~
375: s/\<((?:input|select|button|textarea)[^\>]+)id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 id="$idprefix$2" $3\>/gsi;
1.96 raeburn 376: if ($nuploads) {
377: $output=~
378: s/\<(input[^\>]+name=\"\Q$prefix\EHWFILE[^\>]+)\s*id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\)]*)\>/\<$1 id="$prefix$2" $3\>/gsi;
379: ($turninpaths{$prefix},$multiresps{$prefix}) =
380: &Apache::loncommon::get_turnedin_filepath($symb,$env{'user.name'},$env{'user.domain'});
381: if ($turninparent eq '') {
382: $turninparent = $turninpaths{$prefix};
383: $turninparent =~ s{(/[^/]+)$}{};
384: }
385: }
1.95 raeburn 386: $output=~
387: s/\<((?:input|select)[^\>]+\Qjavascript:setSubmittedPart\E)\(\s*[\'\"]([^\'\"]+)[\'\"]*\s*\)/\<$1('$2','$prefix')/gsi;
1.7 www 388: }
1.12 www 389: $thisdir=~s/\/[^\/]*$//;
1.30 harris41 390: foreach (@rlinks) {
1.91 raeburn 391: unless (($_=~/^https?\:\/\//i) ||
1.31 albertel 392: ($_=~/^\//) ||
393: ($_=~/^javascript:/i) ||
394: ($_=~/^mailto:/i) ||
395: ($_=~/^\#/)) {
1.12 www 396: my $newlocation=
397: &Apache::lonnet::hreflocation($thisdir,$_);
398: $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
399: }
1.30 harris41 400: }
1.24 www 401: # -------------------------------------------------- Deal with Applet codebases
402: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
1.5 www 403: $ssibody{$_}=$output;
1.3 www 404: # ---------------------------------------------------------------- End SSI cell
405: }
1.30 harris41 406: }
1.4 www 407: }
1.2 www 408: }
1.6 www 409: unless ($contents) {
1.53 www 410: &Apache::loncommon::content_type($r,'text/html');
1.3 www 411: $r->send_http_header;
1.74 albertel 412: $r->print(&Apache::loncommon::start_page(undef,undef,
413: {'force_register' => 1,}));
1.59 raeburn 414: $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
1.74 albertel 415: $r->print('<br /><br />'.&mt('Please use the LON-CAPA navigation arrows to move to another item in the course').
416: &Apache::loncommon::end_page());
1.3 www 417: } else {
418: # ------------------------------------------------------------------ Build page
1.7 www 419:
420: # ---------------------------------------------------------------- Send headers
1.94 raeburn 421: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 422: if ($isxml) {
1.53 www 423: &Apache::loncommon::content_type($r,'text/xml');
1.37 sakharuk 424: } else {
1.53 www 425: &Apache::loncommon::content_type($r,'text/html');
1.37 sakharuk 426: }
1.74 albertel 427: $r->send_http_header;
1.7 www 428: # ------------------------------------------------------------------------ Head
1.37 sakharuk 429: if ($allscript) {
1.85 albertel 430: $allscript =
431: "\n".'<script type="text/javascript">'."\n".
432: $allscript.
433: "\n</script>\n";
1.37 sakharuk 434: }
1.96 raeburn 435: if (($nforms) && ($nuploads)) {
436: $allscript .= &Apache::lonhtmlcommon::file_submissionchk_js(\%turninpaths,\%multiresps);
437: }
1.101 raeburn 438: if (($nforms) && (&Apache::lonhtmlcommon::htmlareabrowser())) {
439: my %textarea_args = (
440: dragmath => 'math',
441: );
442: $allscript .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
443: }
1.7 www 444: # ------------------------------------------------------------------ Start body
1.85 albertel 445: $r->print(&Apache::loncommon::start_page(undef,$allscript,
1.74 albertel 446: {'force_register' => 1,
447: 'bgcolor' => '#ffffff',}));
1.7 www 448: # ------------------------------------------------------------------ Start form
1.37 sakharuk 449: if ($nforms) {
1.96 raeburn 450: my $fmtag = '<form name="lonhomework" method="post" enctype="multipart/form-data"';
451: if ($nuploads) {
452: my $multi;
453: if ($nuploads > 1) {
454: $multi = 1;
455: }
456: $fmtag .= 'onsubmit="return file_submission_check(this,'."'$turninparent','$multi'".');"';
457: }
458: $fmtag .= ' action="'.
1.61 albertel 459: &Apache::lonenc::check_encrypt($requrl)
1.96 raeburn 460: .'">';
461: $r->print($fmtag);
1.40 sakharuk 462: }
1.94 raeburn 463: } elsif (($target eq 'tex') || ($target eq 'tex_answer')) {
1.92 foxr 464: # I think this is not needed as the header
465: # will be put in for each of the page parts
466: # by the londefdef.pm now that we are opening up
467: # the parts of a page.
468: #$r->print('\documentclass{article}
469: # \newcommand{\keephidden}[1]{}
470: # \usepackage[dvips]{graphicx}
471: # \usepackage{epsfig}
472: # \usepackage{calc}
473: # \usepackage{longtable}
474: # \begin{document}');
1.40 sakharuk 475: }
1.7 www 476: # ----------------------------------------------------------------- Start table
1.94 raeburn 477: if (($target eq 'tex') || ($target eq 'tex_answer')) {
1.92 foxr 478: # # $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
1.43 sakharuk 479: if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
1.40 sakharuk 480: } else {
1.63 albertel 481: $r->print('<table width="100%" cols="'.$lcm.'" border="0">');
1.37 sakharuk 482: }
1.78 www 483: # generate rows
1.5 www 484: for ($i=0;$i<=$#rows;$i++) {
485: if ($rows[$i]) {
1.94 raeburn 486: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 487: $r->print("\n<tr>");
488: }
1.4 www 489: my @colcont=split(/\&/,$rows[$i]);
1.6 www 490: my $avespan=$lcm/($#colcont+1);
491: for ($j=0;$j<=$#colcont;$j++) {
492: my $rid=$colcont[$j];
1.83 albertel 493: my $metainfo =&get_buttons(\%hash,$rid).'<br />';
1.94 raeburn 494: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 495: $r->print('<td colspan="'.$avespan.'"');
496: }
1.99 raeburn 497: if (($cellemb{$rid} eq 'ssi') || ($cellexternal{$rid})) {
1.94 raeburn 498: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 499: if ($ssibgcolor{$rid}) {
500: $r->print(' bgcolor="'.
501: $ssibgcolor{$rid}.'"');
502: }
503: $r->print('>'.$metainfo.'<font');
504:
505: if ($ssitext{$rid}) {
506: $r->print(' text="'.$ssitext{$rid}.'"');
507: }
508: if ($ssilink{$rid}) {
509: $r->print(' link="'.$ssilink{$rid}.'"');
510: }
511: if ($ssitext{$rid}) {
512: $r->print(' vlink="'.$ssivlink{$rid}.'"');
513: }
514: if ($ssialink{$rid}) {
515: $r->print(' alink="'.$ssialink{$rid}.'"');
516: }
517: $r->print('>');
518: }
1.99 raeburn 519: unless (($cellexternal{$rid}) &&
520: ($target eq 'tex') && ($target eq 'tex_answer')) {
521: $r->print($ssibody{$rid});
522: }
1.94 raeburn 523: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 524: $r->print('</font>');
1.41 www 525: }
1.70 albertel 526: if ($env{'course.'.
527: $env{'request.course.id'}.
1.41 www 528: '.pageseparators'} eq 'yes') {
1.94 raeburn 529: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.41 www 530: $r->print('<hr />');
1.77 albertel 531: }
1.37 sakharuk 532: }
533: } elsif ($cellemb{$rid} eq 'img') {
1.14 www 534: $r->print('>'.$metainfo.'<img src="'.
1.77 albertel 535: $hash{'src_'.$rid}.'" />');
1.13 www 536: } elsif ($cellemb{$rid} eq 'emb') {
1.14 www 537: $r->print('>'.$metainfo.'<embed src="'.
1.13 www 538: $hash{'src_'.$rid}.'"></embed>');
1.60 raeburn 539: } elsif (&Apache::lonnet::declutter($hash{'src_'.$rid}) !~/\.(sequence|page)$/) {
1.104 ! raeburn 540: $r->print($metainfo.'<b>'.$hash{'title_'.$rid}.'</b><br />');
! 541: unless ($cellemb{$rid} eq 'wrp') {
! 542: $r->print(&mt('It is recommended that you use an up-to-date virus scanner before handling this file.'));
! 543: }
! 544: $r->print('</p><p><table>'.
! 545: &Apache::londocs::entryline(0,
! 546: &mt("Click to download or use your browser's Save Link function"),
! 547: '/'.&Apache::lonnet::declutter($hash{'src_'.$rid})).
! 548: '</table></p><br />');
1.13 www 549: }
1.94 raeburn 550: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 551: $r->print('</td>');
1.40 sakharuk 552: } else {
1.92 foxr 553: # for (my $incol=1;$incol<=$avespan;$incol++) {
554: # $r->print(' & ');
555: # }
1.37 sakharuk 556: }
1.4 www 557: }
1.94 raeburn 558: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 559: $r->print('</tr>');
1.40 sakharuk 560: } else {
1.92 foxr 561: # $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
1.37 sakharuk 562: }
1.5 www 563: }
1.4 www 564: }
1.94 raeburn 565: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 566: $r->print("\n</table>");
1.40 sakharuk 567: } else {
1.92 foxr 568: # $r->print('\end{longtable}\strut');
1.37 sakharuk 569: }
1.7 www 570: # ---------------------------------------------------------------- Submit, etc.
571: if ($nforms) {
572: $r->print(
1.103 bisitz 573: '<input name="all_submit" value="'.&mt('Submit All').'" type="'.
1.7 www 574: (($nforms>1)?'submit':'hidden').'"></input></form>');
575: }
1.94 raeburn 576: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.76 albertel 577: $r->print(&Apache::loncommon::end_page({'discussion'
578: => 1,}));
1.40 sakharuk 579: } else {
580: $r->print('\end{document}'.$number_of_columns);
581: }
1.66 albertel 582: &Apache::lonnet::symblist($requrl,%symbhash);
1.69 albertel 583: my ($map,$id,$url)=&Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
584: &Apache::lonnet::symblist($map,'last_known'=>[$url,$id]);
1.3 www 585: # -------------------------------------------------------------------- End page
586: }
1.1 www 587: # ------------------------------------------------------------- End render page
588: } else {
1.67 albertel 589: &Apache::loncommon::content_type($r,'text/html');
1.3 www 590: $r->send_http_header;
1.39 www 591: &Apache::lonsequence::viewmap($r,$requrl);
1.1 www 592: }
593: # ------------------------------------------------------------------ Untie hash
594: unless (untie(%hash)) {
595: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
596: "Could not untie coursemap $fn (browse).</font>");
597: }
598: # -------------------------------------------------------------------- All done
599: return OK;
600: # ----------------------------------------------- Errors, hash could no be tied
601: }
602: }
603: }
1.67 albertel 604: &Apache::loncommon::content_type($r,'text/html');
1.39 www 605: $r->send_http_header;
606: &Apache::lonsequence::viewmap($r,$requrl);
607: return OK;
1.1 www 608: }
609:
1.83 albertel 610: sub get_buttons {
611: my ($hash,$rid) = @_;
612:
613: my $metainfo = '';
614: my $esrc=&Apache::lonnet::declutter($hash->{'src_'.$rid});
615: my ($mapid,$resid)=split(/\./,$rid);
616: my $symb=&Apache::lonnet::encode_symb($hash->{'map_id_'.$mapid},
617: $resid,
618: $hash->{'src_'.$rid});
619: if ($hash->{'encrypted_'.$rid}) {
620: $symb=&Apache::lonenc::encrypted($symb);
621: $esrc=&Apache::lonenc::encrypted($esrc);
622: }
623: if ($hash->{'src_'.$rid} !~ m-^/uploaded/-
1.99 raeburn 624: && $hash->{'src_'.$rid} !~ m{^https?://}
1.83 albertel 625: && !$env{'request.enc'}
626: && ($env{'request.role.adv'}
627: || !$hash->{'encrypted_'.$rid})) {
628: $metainfo .='<a name="'.&escape($symb).'" />'.
629: '<a href="'.$hash->{'src_'.$rid}.'.meta'.'" target="LONcatInfo">'.
1.100 bisitz 630: '<img src="/res/adm/pages/catalog.png" class="LC_icon"'.
631: ' alt="'.&mt('Show Metadata').'"'.
632: ' title="'.&mt('Show Metadata').'" />'.
1.83 albertel 633: '</a>';
634: }
1.99 raeburn 635: if (($hash->{'src_'.$rid} !~ m{^/uploaded/}) &&
636: ($hash->{'src_'.$rid} !~ m{^https?://})) {
1.98 raeburn 637: $metainfo .= '<a href="/adm/evaluate?postdata='.
638: &escape($esrc).
639: '" target="LONcatInfo">'.
1.100 bisitz 640: '<img src="/res/adm/pages/eval.png" class="LC_icon"'.
641: ' alt="'.&mt('Provide my evaluation of this resource').'"'.
642: ' title="'.&mt('Provide my evaluation of this resource').'" />'.
1.98 raeburn 643: '</a>';
644: }
1.97 www 645: if (($hash->{'src_'.$rid}=~/$LONCAPA::assess_re/) &&
1.83 albertel 646: ($hash->{'src_'.$rid} !~ m-^/uploaded/-)) {
647:
648: if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) {
649: $metainfo.=
650: '<a href="/adm/grades?symb='.&escape($symb).
651: # '&command=submission" target="LONcatInfo">'.
652: '&command=submission">'.
1.100 bisitz 653: '<img src="/adm/lonMisc/subm_button.png" class="LC_icon"'.
654: ' alt="'.&mt('View Submissions for a Student or a Group of Students').'"'.
655: ' title="'.&mt('View Submissions for a Student or a Group of Students').'" />'.
1.83 albertel 656: '</a>'.
657: '<a href="/adm/grades?symb='.&escape($symb).
658: # '&command=gradingmenu" target="LONcatInfo">'.
659: '&command=gradingmenu">'.
1.100 bisitz 660: '<img src="/res/adm/pages/pgrd.png" class="LC_icon"'.
661: ' alt="'.&mt('Content Grades').'"'.
662: ' title="'.&mt('Content Grades').'" />'.
1.83 albertel 663: '</a>';
664: }
665: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
666: $metainfo.=
667: '<a href="/adm/parmset?symb='.&escape($symb).
668: # '" target="LONcatInfo">'.
669: '" >'.
1.100 bisitz 670: '<img src="/adm/lonMisc/pprm_button.png" class="LC_icon"'.
671: ' alt="'.&mt('Content Settings').'"'.
672: ' title="'.&mt('Content Settings').'" />'.
1.83 albertel 673: '</a>';
674: }
675: }
1.102 raeburn 676: if (($env{'request.course.id'}) && (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
677: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
678: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
679: my $file=&Apache::lonnet::declutter($hash->{'src_'.$rid});
680: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
681: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,$hash->{'src_'.$rid},$symb);
682: if ($cfile ne '') {
683: my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
684: $forceedit,1,$symb,undef,
685: &escape($env{'form.title'}));
686: if ($jscall) {
687: my $icon = 'pcstr.png';
688: my $label = &mt('Edit');
689: my $title = &mt('Edit this resource');
690: my $pic = '<img src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$icon).'"'.
691: ' class="LC_icon" alt="'.$label.'" title="'.$title.'" />';
692: $metainfo .= ' <a href="javascript:'.$jscall.';">'.$pic.'</a>';
693: }
694: }
695: }
1.83 albertel 696: return $metainfo;
697: }
698:
1.1 www 699: 1;
700: __END__
701:
702:
1.89 jms 703: =head1 NAME
704:
705: Apache::lonpage - Page Handler
706:
707: =head1 SYNOPSIS
708:
709: Invoked by /etc/httpd/conf/srm.conf:
710:
711: <LocationMatch "^/res/.*\.page$>
712: SetHandler perl-script
713: PerlHandler Apache::lonpage
714: </LocationMatch>
715:
716: =head1 INTRODUCTION
717:
718: This module renders a .page resource.
719:
720: This is part of the LearningOnline Network with CAPA project
721: described at http://www.lon-capa.org.
722:
723: =head1 HANDLER SUBROUTINE
724:
725: This routine is called by Apache and mod_perl.
726:
727: =over 4
728:
729: =item *
730:
731: set document type for header only
732:
733: =item *
734:
735: tie db file
736:
737: =item *
738:
739: render page
740:
741: =item *
742:
743: add to symb list
744:
745: =item *
746:
747: page parms
748:
749: =item *
750:
751: Get SSI output, post parameters
1.1 www 752:
1.89 jms 753: =item *
754:
755: SSI cell rendering
756:
757: =item *
758:
759: Deal with Applet codebases
760:
761: =item *
762:
763: Build page
764:
765: =item *
766:
767: send headers
768:
769: =item *
770:
771: start body
772:
773: =item *
774:
775: start form
776:
777: =item *
778:
779: start table
780:
781: =item *
782:
783: submit element, etc, render page, untie hash
784:
785: =back
786:
787: =head1 OTHER SUBROUTINES
788:
789: =over 4
790:
791: =item *
792:
793: euclid() : Euclid's method for determining the greatest common denominator.
794:
795: =item *
796:
797: tracetable() : Build page table.
798:
799: =back
800:
801: =cut
1.1 www 802:
803:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>