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