1: # The LearningOnline Network with CAPA
2: # Page Handler
3: #
4: # $Id: lonpage.pm,v 1.110 2015/07/17 19:00:47 raeburn Exp $
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: #
28: ###
29:
30:
31:
32:
33: package Apache::lonpage;
34:
35: use strict;
36: use Apache::Constants qw(:common :http);
37: use Apache::lonnet;
38: use Apache::loncommon();
39: use Apache::lonhtmlcommon;
40: use Apache::lonxml();
41: use Apache::lonlocal;
42: use Apache::lonmenu;
43: use HTML::TokeParser;
44: use GDBM_File;
45: use Apache::lonsequence;
46: use lib '/home/httpd/lib/perl/';
47: use LONCAPA;
48:
49:
50: # -------------------------------------------------------------- Module Globals
51: my %hash;
52: my @rows;
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: }
66:
67: # ------------------------------------------------------------ Build page table
68:
69: sub tracetable {
70: my ($sofar,$rid,$beenhere)=@_;
71: my $further=$sofar;
72: my $randomout=0;
73: unless ($env{'request.role.adv'}) {
74: $randomout = $hash{'randomout_'.$rid};
75: }
76: unless ($beenhere=~/\&$rid\&/) {
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}},
85: '&'.$frid.$beenhere);
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=
118: &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
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: }
136: }
137: return $further;
138: }
139:
140: # ================================================================ Main Handler
141:
142: sub handler {
143: my $r=shift;
144:
145: # ------------------------------------------- Set document type for header only
146:
147: if ($r->header_only) {
148: if ($env{'browser.mathml'}) {
149: &Apache::loncommon::content_type($r,'text/xml');
150: } else {
151: &Apache::loncommon::content_type($r,'text/html');
152: }
153: $r->send_http_header;
154: return OK;
155: }
156:
157: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
158: ['forceselect','launch']);
159: my $number_of_columns = 1;
160: my $requrl=$r->uri;
161: my $target = $env{'form.grade_target'};
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: }
175: # &Apache::lonnet::logthis("Got a target of $target");
176: if ($target eq 'meta') {
177: &Apache::loncommon::content_type($r,'text/html');
178: $r->send_http_header;
179: return OK;
180: }
181: # ----------------------------------------------------------------- Tie db file
182: if (($env{'request.course.fn'}) && (!$env{'form.forceselect'})) {
183: my $fn=$env{'request.course.fn'};
184: if (-e "$fn.db") {
185: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) {
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:
192: @rows=();
193:
194: &tracetable(0,$firstres,'&');
195:
196: # ------------------------------------------------------------ Add to symb list
197:
198: my $i;
199: my %symbhash=();
200: for ($i=0;$i<=$#rows;$i++) {
201: if ($rows[$i]) {
202: my @colcont=split(/\&/,$rows[$i]);
203: foreach my $rid (@colcont) {
204: my ($mapid,$resid)=split(/\./,$rid);
205: $symbhash{$hash{'src_'.$rid}}=
206: [$hash{'src_'.$rid},$resid];
207: }
208: }
209: }
210: &Apache::lonnet::symblist($requrl,%symbhash);
211:
212: # ------------------------------------------------------------------ Page parms
213:
214: my $j;
215: my $lcm=1;
216: my $contents=0;
217: my $nforms=0;
218: my $nuploads=0;
219: my $ntimers=0;
220: my %turninpaths;
221: my %multiresps;
222: my $turninparent;
223:
224: my %ssibody=();
225: my %ssibgcolor=();
226: my %ssitext=();
227: my %ssilink=();
228: my %ssivlink=();
229: my %ssialink=();
230:
231: my %cellemb=();
232: my %cellexternal=();
233:
234: my $allscript='';
235: my $allmeta='';
236:
237: my $isxml=0;
238: my $xmlheader='';
239: my $xmlbody='';
240:
241: # --------------------------------------------- Get SSI output, post parameters
242:
243: for ($i=0;$i<=$#rows;$i++) {
244: if ($rows[$i]) {
245: $contents++;
246: my @colcont=split(/\&/,$rows[$i]);
247: $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
248: foreach (@colcont) {
249: my $src=$hash{'src_'.$_};
250: my ($extension)=($src=~/\.(\w+)$/);
251: $cellexternal{$_}=($hash{'ext_'.$_} eq 'true:');
252: if ($hash{'encrypted_'.$_}) {
253: $src=&Apache::lonenc::encrypted($src);
254: }
255: $cellemb{$_}=
256: &Apache::loncommon::fileembstyle($extension);
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') {
264: # --------------------------------------------------------- This is an SSI cell
265: my ($mapid,$resid)=split(/\./,$_);
266: my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$src);
267:
268: my $prefix=$_.'_';
269: my $idprefix= join('_',($mapid,$resid,''));
270: my %posthash=('request.prefix' => $prefix,
271: 'LONCAPA_INTERNAL_no_discussion' => 'true',
272: 'symb' => $symb);
273: if (($env{'form.grade_target'} eq 'tex') ||
274: ($env{'form.answer_output_mode'} eq 'tex')) {
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'};
280: $posthash{'answer_output_mode'} = $env{'form.answer_output_mode'};
281: }
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: }
301: }
302: my $output=Apache::lonnet::ssi($src,%posthash);
303: $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+?// END LON-CAPA Internal\s*(-->)?\s||gs;
304: if (($target eq 'tex') || ($target eq 'tex_answer')) {
305: $output =~ s/^([^&]+)\\begin{document}//;
306: $output =~ s/\\end{document}//;
307: # $output = '\parbox{\minipagewidth}{ '.$output.' }';
308: #some additional cleanup necessary for LateX (due to limitations of table environment
309: $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
310: }
311: my $matheditor;
312: if ($output =~ /\Qjavascript:LC_mathedit_HWVAL_\E/) {
313: $matheditor = 'dragmath';
314: } elsif ($output =~ /LCmathField/) {
315: $matheditor = 'lcmath';
316: }
317: my $parser=HTML::TokeParser->new(\$output);
318: my $token;
319: my $thisdir=$src;
320: my $bodydef=0;
321: my $thisxml=0;
322: my @rlinks=();
323: if ($output=~/\?xml/) {
324: $isxml=1;
325: $thisxml=1;
326: $output=~
327: /((?:\<(?:\?xml|\!DOC|html)[^\>]*(?:\>|\>\]\>)\s*)+)\<body[^\>]*\>/si;
328: $xmlheader=$1;
329: }
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') {
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: }
355: } elsif ($token->[1] eq 'meta') {
356: if ($token->[4] !~ m:/>$:) {
357: $allmeta.="\n".$token->[4].'</meta>';
358: } else {
359: $allmeta.="\n".$token->[4];
360: }
361: } elsif (($token->[1] eq 'script') &&
362: ($bodydef==0)) {
363: $allscript.="\n\n"
364: .$parser->get_text('/script');
365: }
366: }
367: }
368: if ($output=~/\<body[^\>]*\>(.*)/si) {
369: $output=$1;
370: }
371: $output=~s/\<\/body\>.*//si;
372: if ($output=~/\<form/si) {
373: my $hastimer;
374: $nforms++;
375: $output=~s/\<form[^\>]*\>//gsi;
376: $output=~s/\<\/form[^\>]*\>//gsi;
377: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*HWFILE/) {
378: $nuploads++;
379: }
380: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*accessbutton/) {
381: $ntimers++;
382: $hastimer = 1;
383: }
384: $output=~
385: s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
386: $output=~
387: s/\<((?:input|select|button|textarea)[^\>]+)id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 id="$idprefix$2" $3\>/gsi;
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: }
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: }
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;
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: }
416: $output=~
417: s/\<((?:input|select)[^\>]+\Qjavascript:setSubmittedPart\E)\(\s*[\'\"]([^\'\"]+)[\'\"]*\s*\)/\<$1('$2','$prefix')/gsi;
418: $output=~
419: s/\<(input[^\>]+\Qonfocus=\"javascript:disableAutoComplete\E)\(\'([^\']+)\'\)(;\")/\<$1('$idprefix$2')$3/gsi;
420: }
421: $thisdir=~s/\/[^\/]*$//;
422: foreach (@rlinks) {
423: unless (($_=~/^https?\:\/\//i) ||
424: ($_=~/^\//) ||
425: ($_=~/^javascript:/i) ||
426: ($_=~/^mailto:/i) ||
427: ($_=~/^\#/)) {
428: my $newlocation=
429: &Apache::lonnet::hreflocation($thisdir,$_);
430: $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
431: }
432: }
433: # -------------------------------------------------- Deal with Applet codebases
434: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
435: $ssibody{$_}=$output;
436: # ---------------------------------------------------------------- End SSI cell
437: }
438: }
439: }
440: }
441: unless ($contents) {
442: &Apache::loncommon::content_type($r,'text/html');
443: $r->send_http_header;
444: $r->print(&Apache::loncommon::start_page(undef,undef,
445: {'force_register' => 1,}));
446: $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
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());
449: } else {
450: # ------------------------------------------------------------------ Build page
451:
452: # ---------------------------------------------------------------- Send headers
453: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
454: if ($isxml) {
455: &Apache::loncommon::content_type($r,'text/xml');
456: } else {
457: &Apache::loncommon::content_type($r,'text/html');
458: }
459: $r->send_http_header;
460: # ------------------------------------------------------------------------ Head
461: if ($allscript) {
462: $allscript =
463: "\n".'<script type="text/javascript">'."\n".
464: $allscript.
465: "\n</script>\n";
466: }
467: if (($nforms) && ($nuploads)) {
468: $allscript .= &Apache::lonhtmlcommon::file_submissionchk_js(\%turninpaths,\%multiresps);
469: }
470: if (($nforms) && (&Apache::lonhtmlcommon::htmlareabrowser())) {
471: my %textarea_args = (
472: dragmath => 'math',
473: );
474: $allscript .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
475: }
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: }
486: # ------------------------------------------------------------------ Start body
487: $r->print(&Apache::loncommon::start_page(undef,$allscript,
488: {'force_register' => 1,
489: 'bgcolor' => '#ffffff',}));
490: # ------------------------------------------------------------------ Start form
491: if ($nforms) {
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="'.
501: &Apache::lonenc::check_encrypt($requrl)
502: .'" id="LC_page">';
503: $r->print($fmtag);
504: }
505: } elsif (($target eq 'tex') || ($target eq 'tex_answer')) {
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}');
517: }
518: # ----------------------------------------------------------------- Start table
519: if (($target eq 'tex') || ($target eq 'tex_answer')) {
520: # # $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
521: if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
522: } else {
523: $r->print('<table width="100%" cols="'.$lcm.'" border="0">');
524: }
525: # generate rows
526: for ($i=0;$i<=$#rows;$i++) {
527: if ($rows[$i]) {
528: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
529: $r->print("\n<tr>");
530: }
531: my @colcont=split(/\&/,$rows[$i]);
532: my $avespan=$lcm/($#colcont+1);
533: for ($j=0;$j<=$#colcont;$j++) {
534: my $rid=$colcont[$j];
535: my $metainfo =&get_buttons(\%hash,$rid).'<br />';
536: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
537: $r->print('<td colspan="'.$avespan.'"');
538: }
539: if (($cellemb{$rid} eq 'ssi') || ($cellexternal{$rid})) {
540: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
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: }
561: unless (($cellexternal{$rid}) &&
562: ($target eq 'tex') && ($target eq 'tex_answer')) {
563: $r->print($ssibody{$rid});
564: }
565: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
566: $r->print('</font>');
567: }
568: if ($env{'course.'.
569: $env{'request.course.id'}.
570: '.pageseparators'} eq 'yes') {
571: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
572: $r->print('<hr />');
573: }
574: }
575: } elsif ($cellemb{$rid} eq 'img') {
576: $r->print('>'.$metainfo.'<img src="'.
577: $hash{'src_'.$rid}.'" />');
578: } elsif ($cellemb{$rid} eq 'emb') {
579: $r->print('>'.$metainfo.'<embed src="'.
580: $hash{'src_'.$rid}.'"></embed>');
581: } elsif (&Apache::lonnet::declutter($hash{'src_'.$rid}) !~/\.(sequence|page)$/) {
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 />');
591: }
592: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
593: $r->print('</td>');
594: } else {
595: # for (my $incol=1;$incol<=$avespan;$incol++) {
596: # $r->print(' & ');
597: # }
598: }
599: }
600: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
601: $r->print('</tr>');
602: } else {
603: # $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
604: }
605: }
606: }
607: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
608: $r->print("\n</table>");
609: } else {
610: # $r->print('\end{longtable}\strut');
611: }
612: # ---------------------------------------------------------------- Submit, etc.
613: if ($nforms) {
614: my $class;
615: if ($nforms > 1) {
616: $class = ' class="LC_hwk_submit"';
617: if ($ntimers) {
618: $nforms = 1;
619: $class = '';
620: }
621: }
622: $r->print(
623: '<input name="all_submit" value="'.&mt('Submit All').'" type="'.
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>');
627: }
628: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
629: $r->print(&Apache::loncommon::end_page({'discussion'
630: => 1,}));
631: } else {
632: $r->print('\end{document}'.$number_of_columns);
633: }
634: &Apache::lonnet::symblist($requrl,%symbhash);
635: my ($map,$id,$url)=&Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
636: &Apache::lonnet::symblist($map,'last_known'=>[$url,$id]);
637: # -------------------------------------------------------------------- End page
638: }
639: # ------------------------------------------------------------- End render page
640: } else {
641: &Apache::loncommon::content_type($r,'text/html');
642: $r->send_http_header;
643: &Apache::lonsequence::viewmap($r,$requrl);
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: }
656: &Apache::loncommon::content_type($r,'text/html');
657: $r->send_http_header;
658: &Apache::lonsequence::viewmap($r,$requrl);
659: return OK;
660: }
661:
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});
671: unless ($env{'request.role.adv'}) {
672: if (&Apache::lonnet::EXT('resource.0.buttonshide',$symb)) {
673: return;
674: }
675: }
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/-
681: && $hash->{'src_'.$rid} !~ m{^https?://}
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">'.
687: '<img src="/res/adm/pages/catalog.png" class="LC_icon"'.
688: ' alt="'.&mt('Show Metadata').'"'.
689: ' title="'.&mt('Show Metadata').'" />'.
690: '</a>';
691: }
692: if (($hash->{'src_'.$rid} !~ m{^/uploaded/}) &&
693: ($hash->{'src_'.$rid} !~ m{^https?://})) {
694: $metainfo .= '<a href="/adm/evaluate?postdata='.
695: &escape($esrc).
696: '" target="LONcatInfo">'.
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').'" />'.
700: '</a>';
701: }
702: if (($hash->{'src_'.$rid}=~/$LONCAPA::assess_re/) &&
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">'.
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').'" />'.
713: '</a>'.
714: '<a href="/adm/grades?symb='.&escape($symb).
715: # '&command=gradingmenu" target="LONcatInfo">'.
716: '&command=gradingmenu">'.
717: '<img src="/res/adm/pages/pgrd.png" class="LC_icon"'.
718: ' alt="'.&mt('Content Grades').'"'.
719: ' title="'.&mt('Content Grades').'" />'.
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: '" >'.
727: '<img src="/adm/lonMisc/pprm_button.png" class="LC_icon"'.
728: ' alt="'.&mt('Content Settings').'"'.
729: ' title="'.&mt('Content Settings').'" />'.
730: '</a>';
731: }
732: }
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: }
753: return $metainfo;
754: }
755:
756: 1;
757: __END__
758:
759:
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
809:
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
859:
860:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>