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