1: # The LearningOnline Network with CAPA
2: # Page Handler
3: #
4: # $Id: lonpage.pm,v 1.120.2.3 2020/06/03 11:24:55 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 Apache::lonhomework;
44: use Apache::lonparmset;
45: use HTML::TokeParser;
46: use GDBM_File;
47: use Apache::lonsequence;
48: use lib '/home/httpd/lib/perl/';
49: use LONCAPA;
50:
51:
52: # -------------------------------------------------------------- Module Globals
53: my %hash;
54: my @rows;
55:
56: # ------------------------------------------------------------------ Euclid gcd
57:
58: sub euclid {
59: my ($e,$f)=@_;
60: my $a; my $b; my $r;
61: if ($e>$f) { $b=$e; $r=$f; } else { $r=$e; $b=$f; }
62: while ($r!=0) {
63: $a=$b; $b=$r;
64: $r=$a%$b;
65: }
66: return $b;
67: }
68:
69: # ------------------------------------------------------------ Build page table
70:
71: sub tracetable {
72: my ($sofar,$rid,$beenhere)=@_;
73: my $further=$sofar;
74: my $randomout=0;
75: unless ($env{'request.role.adv'}) {
76: $randomout = $hash{'randomout_'.$rid};
77: }
78: unless ($beenhere=~/\&$rid\&/) {
79: $beenhere.=$rid.'&';
80: unless ($randomout) {
81: if (defined($hash{'is_map_'.$rid})) {
82: if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
83: (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
84: my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
85: $sofar=
86: &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
87: '&'.$frid.$beenhere);
88: $sofar++;
89: if ($hash{'src_'.$frid}) {
90: my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});
91: if (($brepriv eq '2') || ($brepriv eq 'F')) {
92: if (defined($rows[$sofar])) {
93: $rows[$sofar].='&'.$frid;
94: } else {
95: $rows[$sofar]=$frid;
96: }
97: }
98: }
99: }
100: } else {
101: $sofar++;
102: if ($hash{'src_'.$rid}) {
103: my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid});
104: if (($brepriv eq '2') || ($brepriv eq 'F')) {
105: if (defined($rows[$sofar])) {
106: $rows[$sofar].='&'.$rid;
107: } else {
108: $rows[$sofar]=$rid;
109: }
110: }
111: }
112: }
113: }
114:
115: if (defined($hash{'to_'.$rid})) {
116: my $mincond=1;
117: my $next='';
118: foreach (split(/\,/,$hash{'to_'.$rid})) {
119: my $thiscond=
120: &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
121: if ($thiscond>=$mincond) {
122: if ($next) {
123: $next.=','.$_.':'.$thiscond;
124: } else {
125: $next=$_.':'.$thiscond;
126: }
127: if ($thiscond>$mincond) { $mincond=$thiscond; }
128: }
129: }
130: foreach (split(/\,/,$next)) {
131: my ($linkid,$condval)=split(/\:/,$_);
132: if ($condval>=$mincond) {
133: my $now=&tracetable($sofar,$hash{'goesto_'.$linkid},$beenhere);
134: if ($now>$further) { $further=$now; }
135: }
136: }
137: }
138: }
139: return $further;
140: }
141:
142: # ================================================================ Main Handler
143:
144: sub handler {
145: my $r=shift;
146:
147: # ------------------------------------------- Set document type for header only
148:
149: if ($r->header_only) {
150: if ($env{'browser.mathml'}) {
151: &Apache::loncommon::content_type($r,'text/xml');
152: } else {
153: &Apache::loncommon::content_type($r,'text/html');
154: }
155: $r->send_http_header;
156: return OK;
157: }
158:
159: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
160: ['forceselect','launch']);
161: my $number_of_columns = 1;
162: my $requrl=$r->uri;
163: my $target = $env{'form.grade_target'};
164:
165: # Short term solution: define target as 'tex_answer' when retrieving answers
166: # for resources in a .page when generating printouts.
167: # A better long-term fix would be to modify the way problem rendering, and
168: # answer rendering are retrieved for individual resources when printing a .page,
169: # so rendered problem and answer are sequential for individual resources in
170: # the .page
171: #
172: if ($target eq 'answer') {
173: if ($env{'form.answer_output_mode'} eq 'tex') {
174: $target = 'tex_answer';
175: }
176: }
177: # &Apache::lonnet::logthis("Got a target of $target");
178: if ($target eq 'meta') {
179: &Apache::loncommon::content_type($r,'text/html');
180: $r->send_http_header;
181: return OK;
182: }
183: # ----------------------------------------------------------------- Tie db file
184: if (($env{'request.course.fn'}) && (!$env{'form.forceselect'})) {
185: my $fn=$env{'request.course.fn'};
186: if (-e "$fn.db") {
187: my %buttonshide;
188: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) {
189: # ------------------------------------------------------------------- Hash tied
190: my $firstres=$hash{'map_start_'.$requrl};
191: my $lastres=$hash{'map_finish_'.$requrl};
192: if (($firstres) && ($lastres)) {
193: # ------------------------------------------------------------- Countdown Timer
194: my $now = time;
195: my ($pagefirstaccess,%hastimeleft,%countdowndisp,%donebutton,
196: %donebtnextra,%buttonbytime,$donetime,$symbtosetdone);
197: my ($pagesymb,$courseid,$domain,$name)=&Apache::lonnet::whichuser();
198: unless ($pagesymb) {
199: $pagesymb=&Apache::lonnet::symbread($requrl);
200: }
201: if ($pagesymb && ($courseid ne '') && ($domain ne '') && ($name ne '')) {
202: my %times=&Apache::lonnet::get('firstaccesstimes',
203: [$courseid."\0".$pagesymb],
204: $domain,$name);
205: if ($times{$courseid."\0".$pagesymb} =~ /^\d+$/) {
206: $pagefirstaccess = $times{$courseid."\0".$pagesymb};
207: if ($pagefirstaccess && $env{'form.LC_interval_done'} eq 'true') {
208: $donetime = $now - $pagefirstaccess;
209: }
210: }
211: }
212:
213: # ----------------------------------------------------------------- Render page
214:
215: @rows=();
216:
217: &tracetable(0,$firstres,'&');
218:
219: # ------------------------------------------------------------ Add to symb list
220:
221: my $i;
222: my %symbhash=();
223: for ($i=0;$i<=$#rows;$i++) {
224: if ($rows[$i]) {
225: my @colcont=split(/\&/,$rows[$i]);
226: foreach my $rid (@colcont) {
227: my ($mapid,$resid)=split(/\./,$rid);
228: $symbhash{$hash{'src_'.$rid}}=
229: [$hash{'src_'.$rid},$resid];
230: if (($donetime) && ($symbtosetdone eq '')) {
231: my $src = $hash{'src_'.$rid};
232: if ($hash{'encrypted_'.$rid}) {
233: $src=&Apache::lonenc::encrypted($src);
234: }
235: my ($mapid,$resid)=split(/\./,$rid);
236: my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$src);
237: if ($src =~ /$LONCAPA::assess_re/) {
238: my @interval=&Apache::lonnet::EXT("resource.0.interval",$symb);
239: if (@interval > 1) {
240: if (($interval[1] eq 'map') && ($pagefirstaccess)) {
241: my ($timelimit) = ($interval[0] =~ /^(\d+)/);
242: if ($timelimit) {
243: if ($pagefirstaccess + $timelimit > $now) {
244: $symbtosetdone = $symb;
245: }
246: }
247: }
248: }
249: }
250: }
251: }
252: }
253: }
254: &Apache::lonnet::symblist($requrl,%symbhash);
255:
256: # ------------------------------------------------------------------ Page parms
257:
258: my $j;
259: my $lcm=1;
260: my $contents=0;
261: my $nforms=0;
262: my $nuploads=0;
263: my $ntimers=0;
264: my %turninpaths;
265: my %multiresps;
266: my $turninparent;
267:
268: my %ssibody=();
269: my %ssibgcolor=();
270: my %ssitext=();
271: my %ssilink=();
272: my %ssivlink=();
273: my %ssialink=();
274:
275: my %cellemb=();
276: my %cellexternal=();
277:
278: my $allscript='';
279: my $allmeta='';
280:
281: my $isxml=0;
282: my $xmlheader='';
283: my $xmlbody='';
284:
285: # ---------------------------------------------------------- Handle Done button
286:
287: # Set the event timer to zero if the "done button" was clicked.
288: if ($donetime && $symbtosetdone) {
289: &Apache::lonparmset::storeparm_by_symb_inner($symbtosetdone,'0_interval',
290: 2,$donetime,'date_interval',
291: $name,$domain);
292: undef($env{'form.LC_interval_done'});
293: }
294:
295: # --------------------------------------------- Get SSI output, post parameters
296:
297: for ($i=0;$i<=$#rows;$i++) {
298: if ($rows[$i]) {
299: $contents++;
300: my @colcont=split(/\&/,$rows[$i]);
301: $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
302: foreach (@colcont) {
303: my $src=$hash{'src_'.$_};
304: my $plainsrc = $src;
305: my ($extension)=($src=~/\.(\w+)$/);
306: $cellexternal{$_}=($hash{'ext_'.$_} eq 'true:');
307: if ($hash{'encrypted_'.$_}) {
308: $src=&Apache::lonenc::encrypted($src);
309: }
310: my ($mapid,$resid)=split(/\./,$_);
311: my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$src);
312: unless ($env{'request.role.adv'}) {
313: $buttonshide{$symb} = &Apache::lonnet::EXT("resource.0.buttonshide",$symb);
314: }
315: $cellemb{$_}=
316: &Apache::loncommon::fileembstyle($extension);
317: if ($cellexternal{$_}) {
318: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
319: $ssibody{$_} = <<ENDEXT;
320: <iframe src="$src" width="100%">No iframe support!</iframe>
321: ENDEXT
322: }
323: } elsif ($cellemb{$_} eq 'ssi') {
324: # --------------------------------------------------------- This is an SSI cell
325: my $prefix='p_'.$_.'_';
326: my $idprefix='p_'.join('_',($mapid,$resid,''));
327: my %posthash=('request.prefix' => $prefix,
328: 'LONCAPA_INTERNAL_no_discussion' => 'true',
329: 'symb' => $symb);
330: if (($env{'form.grade_target'} eq 'tex') ||
331: ($env{'form.answer_output_mode'} eq 'tex')) {
332: $posthash{'grade_target'}=$env{'form.grade_target'};
333: $posthash{'textwidth'}=$env{'form.textwidth'};
334: $posthash{'problem_split'}=$env{'form.problem_split'};
335: $posthash{'latex_type'}=$env{'form.latex_type'};
336: $posthash{'rndseed'}=$env{'form.rndseed'};
337: $posthash{'answer_output_mode'} = $env{'form.answer_output_mode'};
338: }
339: my $submitted=$env{'form.all_submit_pressed'};
340: if (!$submitted) {
341: foreach my $key (keys(%env)) {
342: if ($key=~/^\Qform.$prefix\Esubmit_(.+)_pressed$/) {
343: if ($env{$key}) {
344: $submitted=1;
345: last;
346: }
347: }
348: }
349: }
350: if ($submitted) {
351: foreach my $key (keys(%env)) {
352: if ($key=~/^\Qform.$prefix\E/) {
353: my $name=$key;
354: $name=~s/^\Qform.$prefix\E//;
355: $posthash{$name}=$env{$key};
356: }
357: }
358: if ($env{'form.all_submit_pressed'}) {
359: $posthash{'all_submit'}='yes';
360: }
361: } elsif ($env{'form.'.$prefix.'markaccess'} eq 'yes') {
362: $posthash{'markaccess'} = $env{'form.'.$prefix.'markaccess'};
363: }
364: if ($env{'environment.remote'} eq 'on') {
365: $posthash{'inhibitmenu'} = 'yes';
366: }
367: my $output=Apache::lonnet::ssi($src,%posthash);
368: $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+?// END LON-CAPA Internal\s*(-->)?\s||gs;
369: if (($target eq 'tex') || ($target eq 'tex_answer')) {
370: $output =~ s/^([^&]+)\\begin\{document}//;
371: $output =~ s/\\end\{document}//;
372: # $output = '\parbox{\minipagewidth}{ '.$output.' }';
373: #some additional cleanup necessary for LateX (due to limitations of table environment
374: $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
375: }
376: my $matheditor;
377: if ($output =~ /\Qjavascript:LC_mathedit_HWVAL_\E/) {
378: $matheditor = 'dragmath';
379: } elsif ($output =~ /LCmathField/) {
380: $matheditor = 'lcmath';
381: }
382: my $parser=HTML::TokeParser->new(\$output);
383: my $token;
384: my $thisdir=$src;
385: my $bodydef=0;
386: my $thisxml=0;
387: my @rlinks=();
388: if ($output=~/\?xml/) {
389: $isxml=1;
390: $thisxml=1;
391: $output=~
392: /((?:\<(?:\?xml|\!DOC|html)[^\>]*(?:\>|\>\]\>)\s*)+)\<body[^\>]*\>/si;
393: $xmlheader=$1;
394: }
395: while ($token=$parser->get_token) {
396: if ($token->[0] eq 'S') {
397: if ($token->[1] eq 'a') {
398: if ($token->[2]->{'href'}) {
399: $rlinks[$#rlinks+1]=
400: $token->[2]->{'href'};
401: }
402: } elsif ($token->[1] eq 'img') {
403: $rlinks[$#rlinks+1]=
404: $token->[2]->{'src'};
405: } elsif ($token->[1] eq 'embed') {
406: $rlinks[$#rlinks+1]=
407: $token->[2]->{'src'};
408: } elsif ($token->[1] eq 'base') {
409: $thisdir=$token->[2]->{'href'};
410: } elsif ($token->[1] eq 'body') {
411: $bodydef=1;
412: $ssibgcolor{$_}=$token->[2]->{'bgcolor'};
413: $ssitext{$_}=$token->[2]->{'text'};
414: $ssilink{$_}=$token->[2]->{'link'};
415: $ssivlink{$_}=$token->[2]->{'vlink'};
416: $ssialink{$_}=$token->[2]->{'alink'};
417: if ($thisxml) {
418: $xmlbody=$token->[4];
419: }
420: } elsif ($token->[1] eq 'meta') {
421: if ($token->[4] !~ m:/>$:) {
422: $allmeta.="\n".$token->[4].'</meta>';
423: } else {
424: $allmeta.="\n".$token->[4];
425: }
426: } elsif (($token->[1] eq 'script') &&
427: ($bodydef==0)) {
428: $allscript.="\n\n"
429: .$parser->get_text('/script');
430: }
431: }
432: }
433: if ($output=~/\<body[^\>]*\>(.*)/si) {
434: $output=$1;
435: }
436: $output=~s/\<\/body\>.*//si;
437: if ($output=~/\<form/si) {
438: my $hastimer;
439: $nforms++;
440: $output=~s/\<form[^\>]*\>//gsi;
441: $output=~s/\<\/form[^\>]*\>//gsi;
442: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*HWFILE/) {
443: $nuploads++;
444: }
445: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*accessbutton/) {
446: $ntimers++;
447: $hastimer = 1;
448: }
449: $output=~
450: s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
451: $output=~
452: s/\<((?:input|select|button|textarea)[^\>]+)id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 id="$idprefix$2" $3\>/gsi;
453: $output=~
454: s/(\Qthis.form.elements['\E)(HW(?:VAL|CHK)_[^']+\'\]\.(?:value=\'|checked))/$1$prefix$2/gsi;
455: if ($hastimer) {
456: $output=~
457: s/\<(input[^\>]+name=\Q"$prefix\Eaccessbutton"[^\>]+)(?:\Qdocument.markaccess.submit();\E)([^\>]*)\>/\<$1pageTimer(this.form,'$prefix')$2\>/gsi;
458: $output=~ s/\<(input[^\>]+name=\Q"$prefix\Emarkaccess"[^\>]+value=["'])(?:yes)(['"][^\>]*)\>/\<$1$2\>/gsi;
459: }
460: if ($matheditor eq 'dragmath') {
461: $output=~
462: s/(\Qjavascript:LC_mathedit_\E)(HWVAL_)([^'"]+?)(\(['"]*)(\QHWVAL_\E\3['"]\)\;void\(0\)\;)/$1$idprefix$2$3$4$idprefix$5/g;
463: $output=~
464: s/(function\s+LC_mathedit_)(HWVAL_)([^'"]+?)(\s+\(LCtextline\))/$1$idprefix$2$3$4/g;
465: } elsif ($matheditor eq 'lcmath') {
466: $output=~
467: s/(var\s+LCmathField\s+=\s+document\.getElementById\(['"])([^'"]+?)(['"]\)\;)/$1$idprefix$2$3/g;
468: }
469: $output=~
470: 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;
471: $output=~
472: s/(\Q<td class="LC_status_\E)(\Qsubmit_\E)([^\"]*)(\s*[^\"]*"\>)/$1$idprefix$2$3$4/g;
473: if ($nuploads) {
474: ($turninpaths{$prefix},$multiresps{$prefix}) =
475: &Apache::loncommon::get_turnedin_filepath($symb,$env{'user.name'},$env{'user.domain'});
476: if ($turninparent eq '') {
477: $turninparent = $turninpaths{$prefix};
478: $turninparent =~ s{(/[^/]+)$}{};
479: }
480: }
481: $output=~
482: s/\<((?:input|select)[^\>]+\Qjavascript:setSubmittedPart\E)\(\s*[\'\"]([^\'\"]+)[\'\"]*\s*\)/\<$1('$2','$prefix')/gsi;
483: $output=~
484: s/\<(input[^\>]+\Qonfocus=\"javascript:disableAutoComplete\E)\(\'([^\']+)\'\)(;\")/\<$1('$idprefix$2')$3/gsi;
485: unless ($hastimer) {
486: if ($plainsrc =~ /$LONCAPA::assess_re/) {
487: %Apache::lonhomework::history =
488: &Apache::lonnet::restore($symb,$courseid,$domain,$name);
489: my $type = 'problem';
490: if ($extension eq 'task') {
491: $type = 'Task';
492: }
493: my ($status,$accessmsg,$slot_name,$slot) =
494: &Apache::lonhomework::check_slot_access('0',$type,$symb);
495: undef(%Apache::lonhomework::history);
496: my $probstatus = &Apache::lonnet::EXT("resource.0.problemstatus",$symb);
497: if (($status eq 'CAN_ANSWER') || (($status eq 'CANNOT_ANSWER') &&
498: (($probstatus eq 'no') || ($probstatus eq 'no_feedback_ever'))) ||
499: (($status eq 'NOT_YET_VIEWED') && ($posthash{'markaccess'} eq 'yes'))) {
500: my ($slothastime,$timerhastime);
501: if ($slot_name ne '') {
502: if (ref($slot) eq 'HASH') {
503: if (($slot->{'starttime'} < $now) &&
504: ($slot->{'endtime'} > $now)) {
505: $slothastime = $now - $slot->{'endtime'};
506: }
507: }
508: }
509: my $duedate = &Apache::lonnet::EXT("resource.0.duedate",$symb);
510: my @interval=&Apache::lonnet::EXT("resource.0.interval",$symb);
511: if (@interval > 1) {
512: my $first_access;
513: if ($interval[1] eq 'map') {
514: my $ignorecache;
515: if ($env{'form.'.$prefix.'markaccess'} eq 'yes') {
516: $ignorecache = 1;
517: }
518: $first_access=&Apache::lonnet::get_first_access($interval[1],undef,$pagesymb,$ignorecache);
519: if (($first_access) && (!$pagefirstaccess)) {
520: $pagefirstaccess = $first_access;
521: }
522: } else {
523: $first_access=&Apache::lonnet::get_first_access($interval[1],$symb);
524: }
525: if ($first_access > 0) {
526: my ($timelimit) = ($interval[0] =~ /^(\d+)/);
527: if ($timelimit) {
528: my $timeremains = $timelimit + $first_access - $now;
529: if ($timeremains > 0) {
530: $timerhastime = $timeremains;
531: }
532: }
533: }
534: }
535: if (($duedate && $duedate > $now) ||
536: (!$duedate && $timerhastime > 0) ||
537: ($slot_name ne '' && $slothastime)) {
538: if ((@interval > 1 && $timerhastime) ||
539: ($type eq 'Task' && $slothastime)) {
540: $countdowndisp{$symb} = 'inline';
541: if ((@interval > 1) && ($timerhastime)) {
542: $hastimeleft{$symb} = $timerhastime;
543: if ($pagefirstaccess) {
544: my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
545: ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
546: if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
547: $usesdone = 'done';
548: $donebuttontext = $1;
549: (undef,$proctor,$secret) = split(/_/,$2);
550: } elsif ($donesuffix =~ /^done(|_.+)$/) {
551: $donebuttontext = &mt('Done');
552: ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
553: }
554: if ($usesdone eq 'done') {
555: $donebutton{$symb} = $timelimit;
556: push(@{$buttonbytime{$timelimit}},$symb);
557: $donebtnextra{$symb} = {
558: text => $donebuttontext,
559: proctor => $proctor,
560: secret => $secret,
561: type => $interval[1],
562: };
563: }
564: }
565: } else {
566: $hastimeleft{$symb} = $slothastime;
567: }
568: } else {
569: $hastimeleft{$symb} = $duedate - $now;
570: $countdowndisp{$symb} = 'none';
571: }
572: unless ($donebutton{$symb}) {
573: $donebutton{$symb} = 0;
574: }
575: }
576: }
577: }
578: }
579: }
580: $thisdir=~s/\/[^\/]*$//;
581: foreach (@rlinks) {
582: unless (($_=~/^https?\:\/\//i) ||
583: ($_=~/^\//) ||
584: ($_=~/^javascript:/i) ||
585: ($_=~/^mailto:/i) ||
586: ($_=~/^\#/)) {
587: my $newlocation=
588: &Apache::lonnet::hreflocation($thisdir,$_);
589: $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
590: }
591: }
592: # -------------------------------------------------- Deal with Applet codebases
593: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
594: $ssibody{$_}=$output;
595: # ---------------------------------------------------------------- End SSI cell
596: }
597: }
598: }
599: }
600: unless ($contents) {
601: &Apache::loncommon::content_type($r,'text/html');
602: $r->send_http_header;
603: $r->print(&Apache::loncommon::start_page(undef,undef,
604: {'force_register' => 1,}));
605: $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
606: $r->print('<br /><br />'.&mt('Please use the LON-CAPA navigation arrows to move to another item in the course').
607: &Apache::loncommon::end_page());
608: } else {
609: # ------------------------------------------------------------------ Build page
610:
611: # ---------------------------------------------------------------- Send headers
612: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
613: if ($isxml) {
614: &Apache::loncommon::content_type($r,'text/xml');
615: } else {
616: &Apache::loncommon::content_type($r,'text/html');
617: }
618: $r->send_http_header;
619: # ------------------------------------------------------------------------ Head
620: if ($allscript) {
621: $allscript =
622: "\n".'<script type="text/javascript">'."\n".
623: $allscript.
624: "\n</script>\n";
625: }
626: if (($nforms) && ($nuploads)) {
627: $allscript .= &Apache::lonhtmlcommon::file_submissionchk_js(\%turninpaths,\%multiresps);
628: }
629: if (($nforms) && (&Apache::lonhtmlcommon::htmlareabrowser())) {
630: my %textarea_args = (
631: dragmath => 'math',
632: );
633: $allscript .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
634: }
635: if ($ntimers) {
636: $allscript .= '<script type="text/javascript">'."\n".
637: '// <![CDATA['."\n".
638: 'function pageTimer(form,prefix) {'."\n".
639: " form.elements[prefix+'markaccess'].value = 'yes';\n".
640: " form.submit();\n".
641: '}'."\n".
642: '// ]]>'.
643: "\n</script>\n";
644: }
645: if (keys(%hastimeleft)) {
646: my (%uniquetimes,%uniquedisplays);
647: foreach my $item (values(%hastimeleft)) {
648: if (exists($uniquetimes{$item})) {
649: $uniquetimes{$item} ++;
650: } else {
651: $uniquetimes{$item} = 1;
652: }
653: }
654: if (scalar(keys(%uniquetimes)) == 1) {
655: my (%uniquedisplays,%uniquedones,$currdisp,$donebuttontime,
656: $donebuttonextras);
657: if (keys(%countdowndisp)) {
658: foreach my $item (values(%countdowndisp)) {
659: if (exists($uniquedisplays{$item})) {
660: $uniquedisplays{$item} ++;
661: } else {
662: $uniquedisplays{$item} = 1;
663: }
664: }
665: my @countdowndisplay = keys(%uniquedisplays);
666: if (scalar(@countdowndisplay) == 1) {
667: $currdisp = $countdowndisplay[0];
668: }
669: }
670: if (keys(%donebutton)) {
671: foreach my $item (values(%donebutton)) {
672: if (exists($uniquedones{$item})) {
673: $uniquedones{$item} ++;
674: } else {
675: $uniquedones{$item} = 1;
676: }
677: }
678: my @donebuttons = sort { $ <=> $b } (keys(%uniquedones));
679: if (scalar(@donebuttons) == 1) {
680: if ($donebuttons[0]) {
681: $donebuttontime = $donebuttons[0];
682: if (ref($buttonbytime{$donebuttontime}) eq 'ARRAY') {
683: $donebuttonextras = $donebtnextra{$buttonbytime{$donebuttontime}->[0]};
684: }
685: }
686: }
687: }
688: &add_countdown_timer($currdisp,$donebuttontime,$donebuttonextras);
689: }
690: }
691: my $pagebuttonshide;
692: if (keys(%buttonshide)) {
693: my %uniquebuttonhide;
694: foreach my $item (values(%buttonshide)) {
695: if (exists($uniquebuttonhide{$item})) {
696: $uniquebuttonhide{$item} ++;
697: } else {
698: $uniquebuttonhide{$item} = 1;
699: }
700: }
701: if (keys(%uniquebuttonhide) == 1) {
702: if (lc((keys(%uniquebuttonhide))[0]) eq 'yes') {
703: $pagebuttonshide = 'yes';
704: }
705: }
706: }
707: # ------------------------------------------------------------------ Start body
708: $r->print(&Apache::loncommon::start_page(undef,$allscript,
709: {'force_register' => 1,
710: 'bgcolor' => '#ffffff',
711: 'hide_buttons' => $pagebuttonshide}));
712: # ------------------------------------------------------------------ Start form
713: if ($nforms) {
714: my $fmtag = '<form name="lonhomework" method="post" enctype="multipart/form-data"';
715: if ($nuploads) {
716: my $multi;
717: if ($nuploads > 1) {
718: $multi = 1;
719: }
720: $fmtag .= 'onsubmit="return file_submission_check(this,'."'$turninparent','$multi'".');"';
721: }
722: $fmtag .= ' action="'.
723: &Apache::lonenc::check_encrypt($requrl)
724: .'" id="LC_page">';
725: $r->print($fmtag);
726: }
727: } elsif (($target eq 'tex') || ($target eq 'tex_answer')) {
728: # I think this is not needed as the header
729: # will be put in for each of the page parts
730: # by the londefdef.pm now that we are opening up
731: # the parts of a page.
732: #$r->print('\documentclass{article}
733: # \newcommand{\keephidden}[1]{}
734: # \usepackage[dvips]{graphicx}
735: # \usepackage{epsfig}
736: # \usepackage{calc}
737: # \usepackage{longtable}
738: # \begin{document}');
739: }
740: # ----------------------------------------------------------------- Start table
741: if (($target eq 'tex') || ($target eq 'tex_answer')) {
742: # # $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
743: if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
744: } else {
745: $r->print('<table width="100%" cols="'.$lcm.'" border="0">');
746: }
747: # generate rows
748: for ($i=0;$i<=$#rows;$i++) {
749: if ($rows[$i]) {
750: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
751: $r->print("\n<tr>");
752: }
753: my @colcont=split(/\&/,$rows[$i]);
754: my $avespan=$lcm/($#colcont+1);
755: for ($j=0;$j<=$#colcont;$j++) {
756: my $rid=$colcont[$j];
757: my $metainfo =&get_buttons(\%hash,$rid,\%buttonshide).'<br />';
758: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
759: $r->print('<td colspan="'.$avespan.'"');
760: }
761: if (($cellemb{$rid} eq 'ssi') || ($cellexternal{$rid})) {
762: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
763: if ($ssibgcolor{$rid}) {
764: $r->print(' bgcolor="'.
765: $ssibgcolor{$rid}.'"');
766: }
767: $r->print('>'.$metainfo.'<font');
768:
769: if ($ssitext{$rid}) {
770: $r->print(' text="'.$ssitext{$rid}.'"');
771: }
772: if ($ssilink{$rid}) {
773: $r->print(' link="'.$ssilink{$rid}.'"');
774: }
775: if ($ssitext{$rid}) {
776: $r->print(' vlink="'.$ssivlink{$rid}.'"');
777: }
778: if ($ssialink{$rid}) {
779: $r->print(' alink="'.$ssialink{$rid}.'"');
780: }
781: $r->print('>');
782: }
783: unless (($cellexternal{$rid}) &&
784: ($target eq 'tex') && ($target eq 'tex_answer')) {
785: $r->print($ssibody{$rid});
786: }
787: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
788: $r->print('</font>');
789: }
790: if ($env{'course.'.
791: $env{'request.course.id'}.
792: '.pageseparators'} eq 'yes') {
793: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
794: $r->print('<hr />');
795: }
796: }
797: } elsif ($cellemb{$rid} eq 'img') {
798: $r->print('>'.$metainfo.'<img src="'.
799: $hash{'src_'.$rid}.'" />');
800: } elsif ($cellemb{$rid} eq 'emb') {
801: $r->print('>'.$metainfo.'<embed src="'.
802: $hash{'src_'.$rid}.'"></embed>');
803: } elsif (&Apache::lonnet::declutter($hash{'src_'.$rid}) !~/\.(sequence|page)$/) {
804: $r->print($metainfo.'<b>'.$hash{'title_'.$rid}.'</b><br />');
805: unless ($cellemb{$rid} eq 'wrp') {
806: $r->print(&mt('It is recommended that you use an up-to-date virus scanner before handling this file.'));
807: }
808: $r->print('</p><p><table>'.
809: &Apache::londocs::entryline(0,
810: &mt("Click to download or use your browser's Save Link function"),
811: '/'.&Apache::lonnet::declutter($hash{'src_'.$rid})).
812: '</table></p><br />');
813: }
814: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
815: $r->print('</td>');
816: } else {
817: # for (my $incol=1;$incol<=$avespan;$incol++) {
818: # $r->print(' & ');
819: # }
820: }
821: }
822: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
823: $r->print('</tr>');
824: } else {
825: # $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
826: }
827: }
828: }
829: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
830: $r->print("\n</table>");
831: } else {
832: # $r->print('\end{longtable}\strut');
833: }
834: # ---------------------------------------------------------------- Submit, etc.
835: if ($nforms) {
836: my $class;
837: if ($nforms > 1) {
838: $class = ' class="LC_hwk_submit"';
839: if ($ntimers) {
840: $nforms = 1;
841: $class = '';
842: }
843: }
844: $r->print(
845: '<input name="all_submit" value="'.&mt('Submit All').'" type="'.
846: (($nforms>1)?'submit':'hidden').'"'.$class.' id="all_submit" />'.
847: '<input type="hidden" name="all_submit_pressed" '.
848: 'id="all_submit_pressed" value="" />'.
849: '<div id="msg_all_submit" style="display:none">'.
850: &mt('Processing your submission ...').'</div></form>');
851: }
852: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
853: $r->print(&Apache::loncommon::end_page({'discussion'
854: => 1,}));
855: } else {
856: $r->print('\end{document}'.$number_of_columns);
857: }
858: &Apache::lonnet::symblist($requrl,%symbhash);
859: my ($map,$id,$url)=&Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
860: &Apache::lonnet::symblist($map,'last_known'=>[$url,$id]);
861: # -------------------------------------------------------------------- End page
862: }
863: # ------------------------------------------------------------- End render page
864: } else {
865: &Apache::loncommon::content_type($r,'text/html');
866: $r->send_http_header;
867: &Apache::lonsequence::viewmap($r,$requrl);
868: }
869: # ------------------------------------------------------------------ Untie hash
870: unless (untie(%hash)) {
871: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
872: "Could not untie coursemap $fn (browse).</font>");
873: }
874: # -------------------------------------------------------------------- All done
875: return OK;
876: # ----------------------------------------------- Errors, hash could no be tied
877: }
878: }
879: }
880: &Apache::loncommon::content_type($r,'text/html');
881: $r->send_http_header;
882: &Apache::lonsequence::viewmap($r,$requrl);
883: return OK;
884: }
885:
886: sub get_buttons {
887: my ($hash,$rid,$buttonshide) = @_;
888:
889: my $metainfo = '';
890: my $esrc=&Apache::lonnet::declutter($hash->{'src_'.$rid});
891: my ($mapid,$resid)=split(/\./,$rid);
892: my $symb=&Apache::lonnet::encode_symb($hash->{'map_id_'.$mapid},
893: $resid,
894: $hash->{'src_'.$rid});
895: unless ($env{'request.role.adv'}) {
896: if ($buttonshide->{$symb} eq 'yes') {
897: return;
898: }
899: }
900: if ($hash->{'encrypted_'.$rid}) {
901: $symb=&Apache::lonenc::encrypted($symb);
902: $esrc=&Apache::lonenc::encrypted($esrc);
903: }
904: if ($hash->{'src_'.$rid} !~ m-^/uploaded/-
905: && $hash->{'src_'.$rid} !~ m{^https?://}
906: && !$env{'request.enc'}
907: && ($env{'request.role.adv'}
908: || !$hash->{'encrypted_'.$rid})) {
909: $metainfo .='<a name="'.&escape($symb).'" />'.
910: '<a href="'.$hash->{'src_'.$rid}.'.meta'.'" target="LONcatInfo">'.
911: '<img src="/res/adm/pages/catalog.png" class="LC_icon"'.
912: ' alt="'.&mt('Show Metadata').'"'.
913: ' title="'.&mt('Show Metadata').'" />'.
914: '</a>';
915: }
916: if (($hash->{'src_'.$rid} !~ m{^/uploaded/}) &&
917: ($hash->{'src_'.$rid} !~ m{^https?://})) {
918: $metainfo .= '<a href="/adm/evaluate?postdata='.
919: &escape($esrc).
920: '" target="LONcatInfo">'.
921: '<img src="/res/adm/pages/eval.png" class="LC_icon"'.
922: ' alt="'.&mt('Provide my evaluation of this resource').'"'.
923: ' title="'.&mt('Provide my evaluation of this resource').'" />'.
924: '</a>';
925: }
926: if (($hash->{'src_'.$rid}=~/$LONCAPA::assess_re/) &&
927: ($hash->{'src_'.$rid} !~ m-^/uploaded/-)) {
928:
929: if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) {
930: $metainfo.=
931: '<a href="/adm/grades?symb='.&escape($symb).
932: # '&command=submission" target="LONcatInfo">'.
933: '&command=submission">'.
934: '<img src="/adm/lonMisc/subm_button.png" class="LC_icon"'.
935: ' alt="'.&mt('View Submissions for a Student or a Group of Students').'"'.
936: ' title="'.&mt('View Submissions for a Student or a Group of Students').'" />'.
937: '</a>'.
938: '<a href="/adm/grades?symb='.&escape($symb).
939: # '&command=gradingmenu" target="LONcatInfo">'.
940: '&command=gradingmenu">'.
941: '<img src="/res/adm/pages/pgrd.png" class="LC_icon"'.
942: ' alt="'.&mt('Content Grades').'"'.
943: ' title="'.&mt('Content Grades').'" />'.
944: '</a>';
945: }
946: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
947: $metainfo.=
948: '<a href="/adm/parmset?symb='.&escape($symb).
949: # '" target="LONcatInfo">'.
950: '" >'.
951: '<img src="/adm/lonMisc/pprm_button.png" class="LC_icon"'.
952: ' alt="'.&mt('Content Settings').'"'.
953: ' title="'.&mt('Content Settings').'" />'.
954: '</a>';
955: }
956: }
957: if (($env{'request.course.id'}) && (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
958: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
959: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
960: my $file=&Apache::lonnet::declutter($hash->{'src_'.$rid});
961: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
962: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,$hash->{'src_'.$rid},$symb);
963: if ($cfile ne '') {
964: my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
965: $forceedit,1,$symb,undef,
966: &escape($env{'form.title'}));
967: if ($jscall) {
968: my $icon = 'pcstr.png';
969: my $label = &mt('Edit');
970: my $title = &mt('Edit this resource');
971: my $pic = '<img src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$icon).'"'.
972: ' class="LC_icon" alt="'.$label.'" title="'.$title.'" />';
973: $metainfo .= ' <a href="javascript:'.$jscall.';">'.$pic.'</a>';
974: }
975: }
976: }
977: return $metainfo;
978: }
979:
980: sub add_countdown_timer {
981: my ($currdisp,$donebuttontime,$donebuttonextras) = @_;
982: my ($collapse,$expand,$alttxt,$title,$donebutton);
983: if ($currdisp eq 'inline') {
984: $collapse = '► ';
985: } else {
986: $expand = '◄ ';
987: }
988: if ($donebuttontime) {
989: my ($type,$proctor,$donebuttontext);
990: if (ref($donebuttonextras) eq 'HASH') {
991: $proctor = $donebuttonextras->{'proctor'};
992: $donebuttontext = $donebuttonextras->{'text'};
993: $type = $donebuttonextras->{'type'};
994: } else {
995: $donebuttontext = &mt('Done');
996: $type = 'map';
997: }
998: $donebutton =
999: &Apache::lonmenu::done_button_js($type,'','',$proctor,$donebuttontext);
1000: }
1001: unless ($env{'environment.icons'} eq 'iconsonly') {
1002: $alttxt = &mt('Timer');
1003: $title = $alttxt.' ';
1004: }
1005: my $desc = &mt('Countdown to due date/time');
1006: my $output = <<END;
1007: $donebutton
1008: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
1009: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
1010: $collapse
1011: </span></a>
1012: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
1013: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
1014: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1015: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
1016: END
1017: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1018: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$output);
1019: return;
1020: }
1021:
1022:
1023: 1;
1024: __END__
1025:
1026:
1027: =head1 NAME
1028:
1029: Apache::lonpage - Page Handler
1030:
1031: =head1 SYNOPSIS
1032:
1033: Invoked by /etc/httpd/conf/srm.conf:
1034:
1035: <LocationMatch "^/res/.*\.page$>
1036: SetHandler perl-script
1037: PerlHandler Apache::lonpage
1038: </LocationMatch>
1039:
1040: =head1 INTRODUCTION
1041:
1042: This module renders a .page resource.
1043:
1044: This is part of the LearningOnline Network with CAPA project
1045: described at http://www.lon-capa.org.
1046:
1047: =head1 HANDLER SUBROUTINE
1048:
1049: This routine is called by Apache and mod_perl.
1050:
1051: =over 4
1052:
1053: =item *
1054:
1055: set document type for header only
1056:
1057: =item *
1058:
1059: tie db file
1060:
1061: =item *
1062:
1063: render page
1064:
1065: =item *
1066:
1067: add to symb list
1068:
1069: =item *
1070:
1071: page parms
1072:
1073: =item *
1074:
1075: Get SSI output, post parameters
1076:
1077: =item *
1078:
1079: SSI cell rendering
1080:
1081: =item *
1082:
1083: Deal with Applet codebases
1084:
1085: =item *
1086:
1087: Build page
1088:
1089: =item *
1090:
1091: send headers
1092:
1093: =item *
1094:
1095: start body
1096:
1097: =item *
1098:
1099: start form
1100:
1101: =item *
1102:
1103: start table
1104:
1105: =item *
1106:
1107: submit element, etc, render page, untie hash
1108:
1109: =back
1110:
1111: =head1 OTHER SUBROUTINES
1112:
1113: =over 4
1114:
1115: =item *
1116:
1117: euclid() : Euclid's method for determining the greatest common denominator.
1118:
1119: =item *
1120:
1121: tracetable() : Build page table.
1122:
1123: =back
1124:
1125: =cut
1126:
1127:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>