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