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