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