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