File:
[LON-CAPA] /
rat /
lonpage.pm
Revision
1.126:
download - view:
text,
annotated -
select for diffs
Wed Feb 28 14:41:47 2018 UTC (6 years, 5 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 6862.
Avoid a javascript error in Internet Explorer and MS Edge when using
form.elements[name] when name begins with a number by prepending p_
to the prefix used to create the name.
1: # The LearningOnline Network with CAPA
2: # Page Handler
3: #
4: # $Id: lonpage.pm,v 1.126 2018/02/28 14:41:47 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30:
31:
32:
33: package Apache::lonpage;
34:
35: use strict;
36: use Apache::Constants qw(:common :http);
37: use Apache::lonnet;
38: use Apache::loncommon();
39: use Apache::lonhtmlcommon;
40: use Apache::lonxml();
41: use Apache::lonlocal;
42: use Apache::lonmenu;
43: use 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=exists($env{'form.all_submit'});
342: if (!$submitted) {
343: foreach my $key (keys(%env)) {
344: if ($key=~/^form.\Q$prefix\Esubmit_/) {
345: $submitted=1;last;
346: }
347: }
348: }
349: if ($submitted) {
350: foreach my $key (keys(%env)) {
351: if ($key=~/^form.\Q$prefix\E/) {
352: my $name=$key;
353: $name=~s/^form.\Q$prefix\E//;
354: $posthash{$name}=$env{$key};
355: }
356: }
357: if (exists($env{'form.all_submit'})) {
358: $posthash{'all_submit'}='yes';
359: }
360: }
361: my $output=Apache::lonnet::ssi($src,%posthash);
362: $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+?// END LON-CAPA Internal\s*(-->)?\s||gs;
363: if (($target eq 'tex') || ($target eq 'tex_answer')) {
364: $output =~ s/^([^&]+)\\begin\{document}//;
365: $output =~ s/\\end\{document}//;
366: # $output = '\parbox{\minipagewidth}{ '.$output.' }';
367: #some additional cleanup necessary for LateX (due to limitations of table environment
368: $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
369: }
370: my $matheditor;
371: if ($output =~ /\Qjavascript:LC_mathedit_HWVAL_\E/) {
372: $matheditor = 'dragmath';
373: } elsif ($output =~ /LCmathField/) {
374: $matheditor = 'lcmath';
375: }
376: my $parser=HTML::TokeParser->new(\$output);
377: my $token;
378: my $thisdir=$src;
379: my $bodydef=0;
380: my $thisxml=0;
381: my @rlinks=();
382: if ($output=~/\?xml/) {
383: $isxml=1;
384: $thisxml=1;
385: $output=~
386: /((?:\<(?:\?xml|\!DOC|html)[^\>]*(?:\>|\>\]\>)\s*)+)\<body[^\>]*\>/si;
387: $xmlheader=$1;
388: }
389: while ($token=$parser->get_token) {
390: if ($token->[0] eq 'S') {
391: if ($token->[1] eq 'a') {
392: if ($token->[2]->{'href'}) {
393: $rlinks[$#rlinks+1]=
394: $token->[2]->{'href'};
395: }
396: } elsif ($token->[1] eq 'img') {
397: $rlinks[$#rlinks+1]=
398: $token->[2]->{'src'};
399: } elsif ($token->[1] eq 'embed') {
400: $rlinks[$#rlinks+1]=
401: $token->[2]->{'src'};
402: } elsif ($token->[1] eq 'base') {
403: $thisdir=$token->[2]->{'href'};
404: } elsif ($token->[1] eq 'body') {
405: $bodydef=1;
406: $ssibgcolor{$_}=$token->[2]->{'bgcolor'};
407: $ssitext{$_}=$token->[2]->{'text'};
408: $ssilink{$_}=$token->[2]->{'link'};
409: $ssivlink{$_}=$token->[2]->{'vlink'};
410: $ssialink{$_}=$token->[2]->{'alink'};
411: if ($thisxml) {
412: $xmlbody=$token->[4];
413: }
414: } elsif ($token->[1] eq 'meta') {
415: if ($token->[4] !~ m:/>$:) {
416: $allmeta.="\n".$token->[4].'</meta>';
417: } else {
418: $allmeta.="\n".$token->[4];
419: }
420: } elsif (($token->[1] eq 'script') &&
421: ($bodydef==0)) {
422: $allscript.="\n\n"
423: .$parser->get_text('/script');
424: }
425: }
426: }
427: if ($output=~/\<body[^\>]*\>(.*)/si) {
428: $output=$1;
429: }
430: $output=~s/\<\/body\>.*//si;
431: if ($output=~/\<form/si) {
432: my $hastimer;
433: $nforms++;
434: $output=~s/\<form[^\>]*\>//gsi;
435: $output=~s/\<\/form[^\>]*\>//gsi;
436: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*HWFILE/) {
437: $nuploads++;
438: }
439: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*accessbutton/) {
440: $ntimers++;
441: $hastimer = 1;
442: }
443: $output=~
444: s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
445: $output=~
446: s/\<((?:input|select|button|textarea)[^\>]+)id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 id="$idprefix$2" $3\>/gsi;
447: $output=~
448: s/(\Qthis.form.elements['\E)(HW(?:VAL|CHK)_[^']+\'\]\.(?:value=\'|checked))/$1$prefix$2/gsi;
449: if ($hastimer) {
450: $output=~
451: s/\<(input[^\>]+name=\Q"$prefix\Eaccessbutton"[^\>]+)(?:\Qdocument.markaccess.submit();\E)([^\>]*)\>/\<$1pageTimer(this.form,'$prefix')$2\>/gsi;
452: $output=~ s/\<(input[^\>]+name=\Q"$prefix\Emarkaccess"[^\>]+value=["'])(?:yes)(['"][^\>]*)\>/\<$1$2\>/gsi;
453: }
454: if ($matheditor eq 'dragmath') {
455: $output=~
456: s/(\Qjavascript:LC_mathedit_\E)(HWVAL_)([^'"]+?)(\(['"]*)(\QHWVAL_\E\3['"]\)\;void\(0\)\;)/$1$idprefix$2$3$4$idprefix$5/g;
457: $output=~
458: s/(function\s+LC_mathedit_)(HWVAL_)([^'"]+?)(\s+\(LCtextline\))/$1$idprefix$2$3$4/g;
459: } elsif ($matheditor eq 'lcmath') {
460: $output=~
461: s/(var\s+LCmathField\s+=\s+document\.getElementById\(['"])([^'"]+?)(['"]\)\;)/$1$idprefix$2$3/g;
462: }
463: $output=~
464: 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;
465: $output=~
466: s/(\Q<td class="LC_status_\E)(\Qsubmit_\E)([^\"]*)(\s*[^\"]*"\>)/$1$idprefix$2$3$4/g;
467: if ($nuploads) {
468: $output=~
469: s/\<(input[^\>]+name=\"\Q$prefix\EHWFILE[^\>]+)\s*id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\)]*)\>/\<$1 id="$prefix$2" $3\>/gsi;
470: ($turninpaths{$prefix},$multiresps{$prefix}) =
471: &Apache::loncommon::get_turnedin_filepath($symb,$env{'user.name'},$env{'user.domain'});
472: if ($turninparent eq '') {
473: $turninparent = $turninpaths{$prefix};
474: $turninparent =~ s{(/[^/]+)$}{};
475: }
476: }
477: $output=~
478: s/\<((?:input|select)[^\>]+\Qjavascript:setSubmittedPart\E)\(\s*[\'\"]([^\'\"]+)[\'\"]*\s*\)/\<$1('$2','$prefix')/gsi;
479: $output=~
480: s/\<(input[^\>]+\Qonfocus=\"javascript:disableAutoComplete\E)\(\'([^\']+)\'\)(;\")/\<$1('$idprefix$2')$3/gsi;
481: unless ($hastimer) {
482: if ($plainsrc =~ /$LONCAPA::assess_re/) {
483: %Apache::lonhomework::history =
484: &Apache::lonnet::restore($symb,$courseid,$domain,$name);
485: my $type = 'problem';
486: if ($extension eq 'task') {
487: $type = 'Task';
488: }
489: my ($status,$accessmsg,$slot_name,$slot) =
490: &Apache::lonhomework::check_slot_access('0',$type,$symb);
491: undef(%Apache::lonhomework::history);
492: my $probstatus = &Apache::lonnet::EXT("resource.0.problemstatus",$symb);
493: if (($status eq 'CAN_ANSWER') || (($status eq 'CANNOT_ANSWER') &&
494: (($probstatus eq 'no') || ($probstatus eq 'no_feedback_ever'))) ||
495: (($status eq 'NOT_YET_VIEWED') && ($posthash{'markaccess'} eq 'yes'))) {
496: my ($slothastime,$timerhastime);
497: if ($slot_name ne '') {
498: if (ref($slot) eq 'HASH') {
499: if (($slot->{'starttime'} < $now) &&
500: ($slot->{'endtime'} > $now)) {
501: $slothastime = $now - $slot->{'endtime'};
502: }
503: }
504: }
505: my $duedate = &Apache::lonnet::EXT("resource.0.duedate",$symb);
506: my @interval=&Apache::lonnet::EXT("resource.0.interval",$symb);
507: if (@interval > 1) {
508: my $first_access;
509: if ($interval[1] eq 'map') {
510: my $ignorecache;
511: if ($env{'form.'.$prefix.'markaccess'} eq 'yes') {
512: $ignorecache = 1;
513: }
514: $first_access=&Apache::lonnet::get_first_access($interval[1],undef,$pagesymb,$ignorecache);
515: if (($first_access) && (!$pagefirstaccess)) {
516: $pagefirstaccess = $first_access;
517: }
518: } else {
519: $first_access=&Apache::lonnet::get_first_access($interval[1],$symb);
520: }
521: if ($first_access > 0) {
522: my ($timelimit) = ($interval[0] =~ /^(\d+)/);
523: if ($timelimit) {
524: my $timeremains = $timelimit + $first_access - $now;
525: if ($timeremains > 0) {
526: $timerhastime = $timeremains;
527: }
528: }
529: }
530: }
531: if (($duedate && $duedate > $now) ||
532: (!$duedate && $timerhastime > 0) ||
533: ($slot_name ne '' && $slothastime)) {
534: if ((@interval > 1 && $timerhastime) ||
535: ($type eq 'Task' && $slothastime)) {
536: $countdowndisp{$symb} = 'inline';
537: if ((@interval > 1) && ($timerhastime)) {
538: $hastimeleft{$symb} = $timerhastime;
539: if ($pagefirstaccess) {
540: my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
541: ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
542: if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
543: $usesdone = 'done';
544: $donebuttontext = $1;
545: (undef,$proctor,$secret) = split(/_/,$2);
546: } elsif ($donesuffix =~ /^done(|_.+)$/) {
547: $donebuttontext = &mt('Done');
548: ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
549: }
550: if ($usesdone eq 'done') {
551: $donebutton{$symb} = $timelimit;
552: push(@{$buttonbytime{$timelimit}},$symb);
553: $donebtnextra{$symb} = {
554: text => $donebuttontext,
555: proctor => $proctor,
556: secret => $secret,
557: type => $interval[1],
558: };
559: }
560: }
561: } else {
562: $hastimeleft{$symb} = $slothastime;
563: }
564: } else {
565: $hastimeleft{$symb} = $duedate - $now;
566: $countdowndisp{$symb} = 'none';
567: }
568: unless ($donebutton{$symb}) {
569: $donebutton{$symb} = 0;
570: }
571: }
572: }
573: }
574: }
575: }
576: $thisdir=~s/\/[^\/]*$//;
577: foreach (@rlinks) {
578: unless (($_=~/^https?\:\/\//i) ||
579: ($_=~/^\//) ||
580: ($_=~/^javascript:/i) ||
581: ($_=~/^mailto:/i) ||
582: ($_=~/^\#/)) {
583: my $newlocation=
584: &Apache::lonnet::hreflocation($thisdir,$_);
585: $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
586: }
587: }
588: # -------------------------------------------------- Deal with Applet codebases
589: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
590: $ssibody{$_}=$output;
591: # ---------------------------------------------------------------- End SSI cell
592: }
593: }
594: }
595: }
596: unless ($contents) {
597: &Apache::loncommon::content_type($r,'text/html');
598: $r->send_http_header;
599: $r->print(&Apache::loncommon::start_page(undef,undef,
600: {'force_register' => 1,}));
601: $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
602: $r->print('<br /><br />'.&mt('Please use the LON-CAPA navigation arrows to move to another item in the course').
603: &Apache::loncommon::end_page());
604: } else {
605: # ------------------------------------------------------------------ Build page
606:
607: # ---------------------------------------------------------------- Send headers
608: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
609: if ($isxml) {
610: &Apache::loncommon::content_type($r,'text/xml');
611: } else {
612: &Apache::loncommon::content_type($r,'text/html');
613: }
614: $r->send_http_header;
615: # ------------------------------------------------------------------------ Head
616: if ($allscript) {
617: $allscript =
618: "\n".'<script type="text/javascript">'."\n".
619: $allscript.
620: "\n</script>\n";
621: }
622: if (($nforms) && ($nuploads)) {
623: $allscript .= &Apache::lonhtmlcommon::file_submissionchk_js(\%turninpaths,\%multiresps);
624: }
625: if (($nforms) && (&Apache::lonhtmlcommon::htmlareabrowser())) {
626: my %textarea_args = (
627: dragmath => 'math',
628: );
629: $allscript .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
630: }
631: if ($ntimers) {
632: $allscript .= '<script type="text/javascript">'."\n".
633: '// <![CDATA['."\n".
634: 'function pageTimer(form,prefix) {'."\n".
635: " form.elements[prefix+'markaccess'].value = 'yes';\n".
636: " form.submit();\n".
637: '}'."\n".
638: '// ]]>'.
639: "\n</script>\n";
640: }
641: if (keys(%hastimeleft)) {
642: my (%uniquetimes,%uniquedisplays);
643: foreach my $item (values(%hastimeleft)) {
644: if (exists($uniquetimes{$item})) {
645: $uniquetimes{$item} ++;
646: } else {
647: $uniquetimes{$item} = 1;
648: }
649: }
650: if (scalar(keys(%uniquetimes)) == 1) {
651: my (%uniquedisplays,%uniquedones,$currdisp,$donebuttontime,
652: $donebuttonextras);
653: if (keys(%countdowndisp)) {
654: foreach my $item (values(%countdowndisp)) {
655: if (exists($uniquedisplays{$item})) {
656: $uniquedisplays{$item} ++;
657: } else {
658: $uniquedisplays{$item} = 1;
659: }
660: }
661: my @countdowndisplay = keys(%uniquedisplays);
662: if (scalar(@countdowndisplay) == 1) {
663: $currdisp = $countdowndisplay[0];
664: }
665: }
666: if (keys(%donebutton)) {
667: foreach my $item (values(%donebutton)) {
668: if (exists($uniquedones{$item})) {
669: $uniquedones{$item} ++;
670: } else {
671: $uniquedones{$item} = 1;
672: }
673: }
674: my @donebuttons = sort { $ <=> $b } (keys(%uniquedones));
675: if (scalar(@donebuttons) == 1) {
676: if ($donebuttons[0]) {
677: $donebuttontime = $donebuttons[0];
678: if (ref($buttonbytime{$donebuttontime}) eq 'ARRAY') {
679: $donebuttonextras = $donebtnextra{$buttonbytime{$donebuttontime}->[0]};
680: }
681: }
682: }
683: }
684: &add_countdown_timer($currdisp,$donebuttontime,$donebuttonextras);
685: }
686: }
687: my $pagebuttonshide;
688: if (keys(%buttonshide)) {
689: my %uniquebuttonhide;
690: foreach my $item (values(%buttonshide)) {
691: if (exists($uniquebuttonhide{$item})) {
692: $uniquebuttonhide{$item} ++;
693: } else {
694: $uniquebuttonhide{$item} = 1;
695: }
696: }
697: if (keys(%uniquebuttonhide) == 1) {
698: if (lc((keys(%uniquebuttonhide))[0]) eq 'yes') {
699: $pagebuttonshide = 'yes';
700: }
701: }
702: }
703: # ------------------------------------------------------------------ Start body
704: $r->print(&Apache::loncommon::start_page(undef,$allscript,
705: {'force_register' => 1,
706: 'bgcolor' => '#ffffff',
707: 'hide_buttons' => $pagebuttonshide}));
708: # ------------------------------------------------------------------ Start form
709: if ($nforms) {
710: my $fmtag = '<form name="lonhomework" method="post" enctype="multipart/form-data"';
711: if ($nuploads) {
712: my $multi;
713: if ($nuploads > 1) {
714: $multi = 1;
715: }
716: $fmtag .= 'onsubmit="return file_submission_check(this,'."'$turninparent','$multi'".');"';
717: }
718: $fmtag .= ' action="'.
719: &Apache::lonenc::check_encrypt($requrl)
720: .'" id="LC_page">';
721: $r->print($fmtag);
722: }
723: } elsif (($target eq 'tex') || ($target eq 'tex_answer')) {
724: # I think this is not needed as the header
725: # will be put in for each of the page parts
726: # by the londefdef.pm now that we are opening up
727: # the parts of a page.
728: #$r->print('\documentclass{article}
729: # \newcommand{\keephidden}[1]{}
730: # \usepackage[dvips]{graphicx}
731: # \usepackage{epsfig}
732: # \usepackage{calc}
733: # \usepackage{longtable}
734: # \begin{document}');
735: }
736: # ----------------------------------------------------------------- Start table
737: if (($target eq 'tex') || ($target eq 'tex_answer')) {
738: # # $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
739: if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
740: } else {
741: $r->print('<table width="100%" cols="'.$lcm.'" border="0">');
742: }
743: # generate rows
744: for ($i=0;$i<=$#rows;$i++) {
745: if ($rows[$i]) {
746: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
747: $r->print("\n<tr>");
748: }
749: my @colcont=split(/\&/,$rows[$i]);
750: my $avespan=$lcm/($#colcont+1);
751: for ($j=0;$j<=$#colcont;$j++) {
752: my $rid=$colcont[$j];
753: my $metainfo =&get_buttons(\%hash,$rid,\%buttonshide,$hostname).'<br />';
754: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
755: $r->print('<td colspan="'.$avespan.'"');
756: }
757: if (($cellemb{$rid} eq 'ssi') || ($cellexternal{$rid})) {
758: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
759: if ($ssibgcolor{$rid}) {
760: $r->print(' bgcolor="'.
761: $ssibgcolor{$rid}.'"');
762: }
763: $r->print('>'.$metainfo.'<font');
764:
765: if ($ssitext{$rid}) {
766: $r->print(' text="'.$ssitext{$rid}.'"');
767: }
768: if ($ssilink{$rid}) {
769: $r->print(' link="'.$ssilink{$rid}.'"');
770: }
771: if ($ssitext{$rid}) {
772: $r->print(' vlink="'.$ssivlink{$rid}.'"');
773: }
774: if ($ssialink{$rid}) {
775: $r->print(' alink="'.$ssialink{$rid}.'"');
776: }
777: $r->print('>');
778: }
779: unless (($cellexternal{$rid}) &&
780: ($target eq 'tex') && ($target eq 'tex_answer')) {
781: $r->print($ssibody{$rid});
782: }
783: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
784: $r->print('</font>');
785: }
786: if ($env{'course.'.
787: $env{'request.course.id'}.
788: '.pageseparators'} eq 'yes') {
789: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
790: $r->print('<hr />');
791: }
792: }
793: } elsif ($cellemb{$rid} eq 'img') {
794: $r->print('>'.$metainfo.'<img src="'.
795: $hash{'src_'.$rid}.'" />');
796: } elsif ($cellemb{$rid} eq 'emb') {
797: $r->print('>'.$metainfo.'<embed src="'.
798: $hash{'src_'.$rid}.'"></embed>');
799: } elsif (&Apache::lonnet::declutter($hash{'src_'.$rid}) !~/\.(sequence|page)$/) {
800: $r->print($metainfo.'<b>'.$hash{'title_'.$rid}.'</b><br />');
801: unless ($cellemb{$rid} eq 'wrp') {
802: $r->print(&mt('It is recommended that you use an up-to-date virus scanner before handling this file.'));
803: }
804: $r->print('</p><p><table>'.
805: &Apache::londocs::entryline(0,
806: &mt("Click to download or use your browser's Save Link function"),
807: '/'.&Apache::lonnet::declutter($hash{'src_'.$rid})).
808: '</table></p><br />');
809: }
810: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
811: $r->print('</td>');
812: } else {
813: # for (my $incol=1;$incol<=$avespan;$incol++) {
814: # $r->print(' & ');
815: # }
816: }
817: }
818: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
819: $r->print('</tr>');
820: } else {
821: # $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
822: }
823: }
824: }
825: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
826: $r->print("\n</table>");
827: } else {
828: # $r->print('\end{longtable}\strut');
829: }
830: # ---------------------------------------------------------------- Submit, etc.
831: if ($nforms) {
832: my $class;
833: if ($nforms > 1) {
834: $class = ' class="LC_hwk_submit"';
835: if ($ntimers) {
836: $nforms = 1;
837: $class = '';
838: }
839: }
840: $r->print(
841: '<input name="all_submit" value="'.&mt('Submit All').'" type="'.
842: (($nforms>1)?'submit':'hidden').'"'.$class.' id="all_submit" />'.
843: '<div id="msg_all_submit" style="display:none">'.
844: &mt('Processing your submission ...').'</div></form>');
845: }
846: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
847: $r->print(&Apache::loncommon::end_page({'discussion'
848: => 1,}));
849: } else {
850: $r->print('\end{document}'.$number_of_columns);
851: }
852: &Apache::lonnet::symblist($requrl,%symbhash);
853: my ($map,$id,$url)=&Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
854: &Apache::lonnet::symblist($map,'last_known'=>[$url,$id]);
855: # -------------------------------------------------------------------- End page
856: }
857: # ------------------------------------------------------------- End render page
858: } else {
859: &Apache::loncommon::content_type($r,'text/html');
860: $r->send_http_header;
861: &Apache::lonsequence::viewmap($r,$requrl);
862: }
863: # ------------------------------------------------------------------ Untie hash
864: unless (untie(%hash)) {
865: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
866: "Could not untie coursemap $fn (browse).</font>");
867: }
868: # -------------------------------------------------------------------- All done
869: return OK;
870: # ----------------------------------------------- Errors, hash could no be tied
871: }
872: }
873: }
874: &Apache::loncommon::content_type($r,'text/html');
875: $r->send_http_header;
876: &Apache::lonsequence::viewmap($r,$requrl);
877: return OK;
878: }
879:
880: sub get_buttons {
881: my ($hash,$rid,$buttonshide,$hostname) = @_;
882:
883: my $metainfo = '';
884: my $esrc=&Apache::lonnet::declutter($hash->{'src_'.$rid});
885: my ($mapid,$resid)=split(/\./,$rid);
886: my $symb=&Apache::lonnet::encode_symb($hash->{'map_id_'.$mapid},
887: $resid,
888: $hash->{'src_'.$rid});
889: unless ($env{'request.role.adv'}) {
890: if ($buttonshide->{$symb} eq 'yes') {
891: return;
892: }
893: }
894: if ($hash->{'encrypted_'.$rid}) {
895: $symb=&Apache::lonenc::encrypted($symb);
896: $esrc=&Apache::lonenc::encrypted($esrc);
897: }
898: if ($hash->{'src_'.$rid} !~ m-^/uploaded/-
899: && $hash->{'src_'.$rid} !~ m{^https?://}
900: && !$env{'request.enc'}
901: && ($env{'request.role.adv'}
902: || !$hash->{'encrypted_'.$rid})) {
903: $metainfo .='<a name="'.&escape($symb).'" />'.
904: '<a href="'.$hash->{'src_'.$rid}.'.meta'.'" target="LONcatInfo">'.
905: '<img src="/res/adm/pages/catalog.png" class="LC_icon"'.
906: ' alt="'.&mt('Show Metadata').'"'.
907: ' title="'.&mt('Show Metadata').'" />'.
908: '</a>';
909: }
910: if (($hash->{'src_'.$rid} !~ m{^/uploaded/}) &&
911: ($hash->{'src_'.$rid} !~ m{^https?://})) {
912: $metainfo .= '<a href="/adm/evaluate?postdata='.
913: &escape($esrc).
914: '" target="LONcatInfo">'.
915: '<img src="/res/adm/pages/eval.png" class="LC_icon"'.
916: ' alt="'.&mt('Provide my evaluation of this resource').'"'.
917: ' title="'.&mt('Provide my evaluation of this resource').'" />'.
918: '</a>';
919: }
920: if (($hash->{'src_'.$rid}=~/$LONCAPA::assess_re/) &&
921: ($hash->{'src_'.$rid} !~ m-^/uploaded/-)) {
922:
923: if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) {
924: $metainfo.=
925: '<a href="/adm/grades?symb='.&escape($symb).
926: # '&command=submission" target="LONcatInfo">'.
927: '&command=submission">'.
928: '<img src="/adm/lonMisc/subm_button.png" class="LC_icon"'.
929: ' alt="'.&mt('View Submissions for a Student or a Group of Students').'"'.
930: ' title="'.&mt('View Submissions for a Student or a Group of Students').'" />'.
931: '</a>'.
932: '<a href="/adm/grades?symb='.&escape($symb).
933: # '&command=gradingmenu" target="LONcatInfo">'.
934: '&command=gradingmenu">'.
935: '<img src="/res/adm/pages/pgrd.png" class="LC_icon"'.
936: ' alt="'.&mt('Content Grades').'"'.
937: ' title="'.&mt('Content Grades').'" />'.
938: '</a>';
939: }
940: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
941: $metainfo.=
942: '<a href="/adm/parmset?symb='.&escape($symb).
943: # '" target="LONcatInfo">'.
944: '" >'.
945: '<img src="/adm/lonMisc/pprm_button.png" class="LC_icon"'.
946: ' alt="'.&mt('Content Settings').'"'.
947: ' title="'.&mt('Content Settings').'" />'.
948: '</a>';
949: }
950: }
951: if ($env{'request.course.id'}) {
952: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
953: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
954: my $file=&Apache::lonnet::declutter($hash->{'src_'.$rid});
955: my $editbutton = '';
956: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
957: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
958: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,$hash->{'src_'.$rid},$symb);
959: if ($cfile ne '') {
960: my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
961: $forceedit,1,$symb,undef,
962: &escape($env{'form.title'}),
963: $hostname);
964: if ($jscall) {
965: $editbutton = 1;
966: my $icon = 'pcstr.png';
967: my $label = &mt('Edit');
968: my $title = &mt('Edit this resource');
969: my $pic = '<img src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$icon).'"'.
970: ' class="LC_icon" alt="'.$label.'" title="'.$title.'" />';
971: $metainfo .= ' <a href="javascript:'.$jscall.';">'.$pic.'</a>';
972: }
973: }
974: }
975: if ((!$editbutton) && ($file=~/$LONCAPA::assess_re/)) {
976: my $url = &Apache::lonnet::clutter($file);
977: my $viewsrcbutton;
978: if ((&Apache::lonnet::allowed('cre','/')) &&
979: (&Apache::lonnet::metadata($url,'sourceavail') eq 'open')) {
980: $viewsrcbutton = 1;
981: } elsif (&Apache::lonnet::allowed('vxc',$env{'request.course.id'})) {
982: if ($url =~ m{^\Q/res/$cdom/\E($LONCAPA::match_username)/}) {
983: my $auname = $1;
984: if (($env{'request.course.adhocsrcaccess'} ne '') &&
985: (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) {
986: $viewsrcbutton = 1;
987: }
988: }
989: }
990: if ($viewsrcbutton) {
991: my $icon = 'pcstr.png';
992: my $label = &mt('View Source');
993: my $title = &mt('View source code');
994: my $jsrid = $rid;
995: $jsrid =~ s/\./_/g;
996: my $showurl = &escape(&Apache::lonenc::check_encrypt($url));
997: my $pic = '<img src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$icon).'"'.
998: ' class="LC_icon" alt="'.$label.'" title="'.$title.'" />';
999: $metainfo .= ' <a href="javascript:open_source_'.$jsrid.'();">'.$pic.'</a>'."\n".
1000: '<script type="text/javascript">'."\n".
1001: "function open_source_$jsrid() {\n".
1002: " sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename=$showurl','LONsource',".
1003: "'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');\n".
1004: "}\n".
1005: "</script>\n";
1006: }
1007: }
1008: }
1009: return $metainfo;
1010: }
1011:
1012: sub add_countdown_timer {
1013: my ($currdisp,$donebuttontime,$donebuttonextras) = @_;
1014: my ($collapse,$expand,$alttxt,$title,$donebutton);
1015: if ($currdisp eq 'inline') {
1016: $collapse = '► ';
1017: } else {
1018: $expand = '◄ ';
1019: }
1020: if ($donebuttontime) {
1021: my ($type,$proctor,$donebuttontext);
1022: if (ref($donebuttonextras) eq 'HASH') {
1023: $proctor = $donebuttonextras->{'proctor'};
1024: $donebuttontext = $donebuttonextras->{'text'};
1025: $type = $donebuttonextras->{'type'};
1026: } else {
1027: $donebuttontext = &mt('Done');
1028: $type = 'map';
1029: }
1030: $donebutton =
1031: &Apache::lonmenu::done_button_js($type,'','',$proctor,$donebuttontext);
1032: }
1033: unless ($env{'environment.icons'} eq 'iconsonly') {
1034: $alttxt = &mt('Timer');
1035: $title = $alttxt.' ';
1036: }
1037: my $desc = &mt('Countdown to due date/time');
1038: my $output = <<END;
1039: $donebutton
1040: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
1041: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
1042: $collapse
1043: </span></a>
1044: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
1045: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
1046: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1047: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
1048: END
1049: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1050: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$output);
1051: return;
1052: }
1053:
1054:
1055: 1;
1056: __END__
1057:
1058:
1059: =head1 NAME
1060:
1061: Apache::lonpage - Page Handler
1062:
1063: =head1 SYNOPSIS
1064:
1065: Invoked by /etc/httpd/conf/srm.conf:
1066:
1067: <LocationMatch "^/res/.*\.page$>
1068: SetHandler perl-script
1069: PerlHandler Apache::lonpage
1070: </LocationMatch>
1071:
1072: =head1 INTRODUCTION
1073:
1074: This module renders a .page resource.
1075:
1076: This is part of the LearningOnline Network with CAPA project
1077: described at http://www.lon-capa.org.
1078:
1079: =head1 HANDLER SUBROUTINE
1080:
1081: This routine is called by Apache and mod_perl.
1082:
1083: =over 4
1084:
1085: =item *
1086:
1087: set document type for header only
1088:
1089: =item *
1090:
1091: tie db file
1092:
1093: =item *
1094:
1095: render page
1096:
1097: =item *
1098:
1099: add to symb list
1100:
1101: =item *
1102:
1103: page parms
1104:
1105: =item *
1106:
1107: Get SSI output, post parameters
1108:
1109: =item *
1110:
1111: SSI cell rendering
1112:
1113: =item *
1114:
1115: Deal with Applet codebases
1116:
1117: =item *
1118:
1119: Build page
1120:
1121: =item *
1122:
1123: send headers
1124:
1125: =item *
1126:
1127: start body
1128:
1129: =item *
1130:
1131: start form
1132:
1133: =item *
1134:
1135: start table
1136:
1137: =item *
1138:
1139: submit element, etc, render page, untie hash
1140:
1141: =back
1142:
1143: =head1 OTHER SUBROUTINES
1144:
1145: =over 4
1146:
1147: =item *
1148:
1149: euclid() : Euclid's method for determining the greatest common denominator.
1150:
1151: =item *
1152:
1153: tracetable() : Build page table.
1154:
1155: =back
1156:
1157: =cut
1158:
1159:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>