1: # The LearningOnline Network with CAPA
2: # Page Handler
3: #
4: # $Id: lonpage.pm,v 1.111.2.4 2016/10/29 13:47:21 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=$_.'_';
286: my $idprefix= 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: if ($hastimer) {
409: $output=~
410: s/\<(input[^\>]+name=\Q"$prefix\Eaccessbutton"[^\>]+)(?:\Qdocument.markaccess.submit();\E)([^\>]*)\>/\<$1pageTimer(this.form,'$prefix')$2\>/gsi;
411: $output=~ s/\<(input[^\>]+name=\Q"$prefix\Emarkaccess"[^\>]+value=["'])(?:yes)(['"][^\>]*)\>/\<$1$2\>/gsi;
412: }
413: if ($matheditor eq 'dragmath') {
414: $output=~
415: s/(\Qjavascript:LC_mathedit_\E)(HWVAL_)([^'"]+?)(\(['"]*)(\QHWVAL_\E\3['"]\)\;void\(0\)\;)/$1$idprefix$2$3$4$idprefix$5/g;
416: $output=~
417: s/(function\s+LC_mathedit_)(HWVAL_)([^'"]+?)(\s+\(LCtextline\))/$1$idprefix$2$3$4/g;
418: } elsif ($matheditor eq 'lcmath') {
419: $output=~
420: s/(var\s+LCmathField\s+=\s+document\.getElementById\(['"])([^'"]+?)(['"]\)\;)/$1$idprefix$2$3/g;
421: }
422: $output=~
423: 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;
424: $output=~
425: s/(\Q<td class="LC_status_\E)(\Qsubmit_\E)([^\"]*)(\s*[^\"]*"\>)/$1$idprefix$2$3$4/g;
426: if ($nuploads) {
427: $output=~
428: s/\<(input[^\>]+name=\"\Q$prefix\EHWFILE[^\>]+)\s*id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\)]*)\>/\<$1 id="$prefix$2" $3\>/gsi;
429: ($turninpaths{$prefix},$multiresps{$prefix}) =
430: &Apache::loncommon::get_turnedin_filepath($symb,$env{'user.name'},$env{'user.domain'});
431: if ($turninparent eq '') {
432: $turninparent = $turninpaths{$prefix};
433: $turninparent =~ s{(/[^/]+)$}{};
434: }
435: }
436: $output=~
437: s/\<((?:input|select)[^\>]+\Qjavascript:setSubmittedPart\E)\(\s*[\'\"]([^\'\"]+)[\'\"]*\s*\)/\<$1('$2','$prefix')/gsi;
438: $output=~
439: s/\<(input[^\>]+\Qonfocus=\"javascript:disableAutoComplete\E)\(\'([^\']+)\'\)(;\")/\<$1('$idprefix$2')$3/gsi;
440: unless ($hastimer) {
441: if ($plainsrc =~ /$LONCAPA::assess_re/) {
442: %Apache::lonhomework::history =
443: &Apache::lonnet::restore($symb,$courseid,$domain,$name);
444: my $type = 'problem';
445: if ($extension eq 'task') {
446: $type = 'Task';
447: }
448: my ($status,$accessmsg,$slot_name,$slot) =
449: &Apache::lonhomework::check_slot_access('0',$type,$symb);
450: undef(%Apache::lonhomework::history);
451: my $probstatus = &Apache::lonnet::EXT("resource.0.problemstatus",$symb);
452: if (($status eq 'CAN_ANSWER') || (($status eq 'CANNOT_ANSWER') &&
453: (($probstatus eq 'no') || ($probstatus eq 'no_feedback_ever')))) {
454: my ($slothastime,$timerhastime);
455: if ($slot_name ne '') {
456: if (ref($slot) eq 'HASH') {
457: if (($slot->{'starttime'} < $now) &&
458: ($slot->{'endtime'} > $now)) {
459: $slothastime = $now - $slot->{'endtime'};
460: }
461: }
462: }
463: my $duedate = &Apache::lonnet::EXT("resource.0.duedate",$symb);
464: my @interval=&Apache::lonnet::EXT("resource.0.interval",$symb);
465: if (@interval > 1) {
466: my $first_access=&Apache::lonnet::get_first_access($interval[1],$symb);
467: if ($first_access > 0) {
468: my $timeremains = $first_access+$interval[0] - $now;
469: if ($timeremains > 0) {
470: $timerhastime = $timeremains;
471: }
472: }
473: }
474: if (($duedate && $duedate > $now) ||
475: (!$duedate && $timerhastime > 0) ||
476: ($slot_name ne '' && $slothastime)) {
477: if ((@interval > 1 && $timerhastime) ||
478: ($type eq 'Task' && $slothastime)) {
479: $countdowndisp{$symb} = 'inline';
480: if ((@interval > 1) && ($timerhastime)) {
481: $hastimeleft{$symb} = $timerhastime;
482: } else {
483: $hastimeleft{$symb} = $slothastime;
484: }
485: } else {
486: $hastimeleft{$symb} = $duedate - $now;
487: $countdowndisp{$symb} = 'none';
488: }
489: }
490: }
491: }
492: }
493: }
494: $thisdir=~s/\/[^\/]*$//;
495: foreach (@rlinks) {
496: unless (($_=~/^https?\:\/\//i) ||
497: ($_=~/^\//) ||
498: ($_=~/^javascript:/i) ||
499: ($_=~/^mailto:/i) ||
500: ($_=~/^\#/)) {
501: my $newlocation=
502: &Apache::lonnet::hreflocation($thisdir,$_);
503: $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
504: }
505: }
506: # -------------------------------------------------- Deal with Applet codebases
507: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
508: $ssibody{$_}=$output;
509: # ---------------------------------------------------------------- End SSI cell
510: }
511: }
512: }
513: }
514: unless ($contents) {
515: &Apache::loncommon::content_type($r,'text/html');
516: $r->send_http_header;
517: $r->print(&Apache::loncommon::start_page(undef,undef,
518: {'force_register' => 1}));
519: $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
520: $r->print('<br /><br />'.&mt('Please use the LON-CAPA navigation arrows to move to another item in the course').
521: &Apache::loncommon::end_page());
522: } else {
523: # ------------------------------------------------------------------ Build page
524:
525: # ---------------------------------------------------------------- Send headers
526: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
527: if ($isxml) {
528: &Apache::loncommon::content_type($r,'text/xml');
529: } else {
530: &Apache::loncommon::content_type($r,'text/html');
531: }
532: $r->send_http_header;
533: # ------------------------------------------------------------------------ Head
534: if ($allscript) {
535: $allscript =
536: "\n".'<script type="text/javascript">'."\n".
537: $allscript.
538: "\n</script>\n";
539: }
540: if (($nforms) && ($nuploads)) {
541: $allscript .= &Apache::lonhtmlcommon::file_submissionchk_js(\%turninpaths,\%multiresps);
542: }
543: if (($nforms) && (&Apache::lonhtmlcommon::htmlareabrowser())) {
544: my %textarea_args = (
545: dragmath => 'math',
546: );
547: $allscript .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
548: }
549: if ($ntimers) {
550: $allscript .= '<script type="text/javascript">'."\n".
551: '// <![CDATA['."\n".
552: 'function pageTimer(form,prefix) {'."\n".
553: " form.elements[prefix+'markaccess'].value = 'yes';\n".
554: " form.submit();\n".
555: '}'."\n".
556: '// ]]>'.
557: "\n</script>\n";
558: }
559: if (keys(%hastimeleft)) {
560: my (%uniquetimes,%uniquedisplays);
561: foreach my $item (values(%hastimeleft)) {
562: if (exists($uniquetimes{$item})) {
563: $uniquetimes{$item} ++;
564: } else {
565: $uniquetimes{$item} = 1;
566: }
567: }
568: if (keys(%uniquetimes) == 1) {
569: my (%uniquedisplays,%uniquedones,$currdisp);
570: if (keys(%countdowndisp)) {
571: foreach my $item (values(%countdowndisp)) {
572: if (exists($uniquedisplays{$item})) {
573: $uniquedisplays{$item} ++;
574: } else {
575: $uniquedisplays{$item} = 1;
576: }
577: }
578: my @countdowndisplay = keys(%uniquedisplays);
579: if (scalar(@countdowndisplay) == 1) {
580: $currdisp = $countdowndisplay[0];
581: }
582: }
583: &add_countdown_timer($currdisp);
584: }
585: }
586: my $pagebuttonshide;
587: if (keys(%buttonshide)) {
588: my %uniquebuttonhide;
589: foreach my $item (values(%buttonshide)) {
590: if (exists($uniquebuttonhide{$item})) {
591: $uniquebuttonhide{$item} ++;
592: } else {
593: $uniquebuttonhide{$item} = 1;
594: }
595: }
596: if (keys(%uniquebuttonhide) == 1) {
597: if (lc((keys(%uniquebuttonhide))[0]) eq 'yes') {
598: $pagebuttonshide = 'yes';
599: }
600: }
601: }
602: # ------------------------------------------------------------------ Start body
603: $r->print(&Apache::loncommon::start_page(undef,$allscript,
604: {'force_register' => 1,
605: 'bgcolor' => '#ffffff',
606: 'hide_buttons' => $pagebuttonshide}));
607: # ------------------------------------------------------------------ Start form
608: if ($nforms) {
609: my $fmtag = '<form name="lonhomework" method="post" enctype="multipart/form-data"';
610: if ($nuploads) {
611: my $multi;
612: if ($nuploads > 1) {
613: $multi = 1;
614: }
615: $fmtag .= 'onsubmit="return file_submission_check(this,'."'$turninparent','$multi'".');"';
616: }
617: $fmtag .= ' action="'.
618: &Apache::lonenc::check_encrypt($requrl)
619: .'" id="LC_page">';
620: $r->print($fmtag);
621: }
622: } elsif (($target eq 'tex') || ($target eq 'tex_answer')) {
623: # I think this is not needed as the header
624: # will be put in for each of the page parts
625: # by the londefdef.pm now that we are opening up
626: # the parts of a page.
627: #$r->print('\documentclass{article}
628: # \newcommand{\keephidden}[1]{}
629: # \usepackage[dvips]{graphicx}
630: # \usepackage{epsfig}
631: # \usepackage{calc}
632: # \usepackage{longtable}
633: # \begin{document}');
634: }
635: # ----------------------------------------------------------------- Start table
636: if (($target eq 'tex') || ($target eq 'tex_answer')) {
637: # # $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
638: if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
639: } else {
640: $r->print('<table width="100%" cols="'.$lcm.'" border="0">');
641: }
642: # generate rows
643: for ($i=0;$i<=$#rows;$i++) {
644: if ($rows[$i]) {
645: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
646: $r->print("\n<tr>");
647: }
648: my @colcont=split(/\&/,$rows[$i]);
649: my $avespan=$lcm/($#colcont+1);
650: for ($j=0;$j<=$#colcont;$j++) {
651: my $rid=$colcont[$j];
652: my $metainfo =&get_buttons(\%hash,$rid,\%buttonshide).'<br />';
653: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
654: $r->print('<td colspan="'.$avespan.'"');
655: }
656: if (($cellemb{$rid} eq 'ssi') || ($cellexternal{$rid})) {
657: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
658: if ($ssibgcolor{$rid}) {
659: $r->print(' bgcolor="'.
660: $ssibgcolor{$rid}.'"');
661: }
662: $r->print('>'.$metainfo.'<font');
663:
664: if ($ssitext{$rid}) {
665: $r->print(' text="'.$ssitext{$rid}.'"');
666: }
667: if ($ssilink{$rid}) {
668: $r->print(' link="'.$ssilink{$rid}.'"');
669: }
670: if ($ssitext{$rid}) {
671: $r->print(' vlink="'.$ssivlink{$rid}.'"');
672: }
673: if ($ssialink{$rid}) {
674: $r->print(' alink="'.$ssialink{$rid}.'"');
675: }
676: $r->print('>');
677: }
678: unless (($cellexternal{$rid}) &&
679: ($target eq 'tex') && ($target eq 'tex_answer')) {
680: $r->print($ssibody{$rid});
681: }
682: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
683: $r->print('</font>');
684: }
685: if ($env{'course.'.
686: $env{'request.course.id'}.
687: '.pageseparators'} eq 'yes') {
688: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
689: $r->print('<hr />');
690: }
691: }
692: } elsif ($cellemb{$rid} eq 'img') {
693: $r->print('>'.$metainfo.'<img src="'.
694: $hash{'src_'.$rid}.'" />');
695: } elsif ($cellemb{$rid} eq 'emb') {
696: $r->print('>'.$metainfo.'<embed src="'.
697: $hash{'src_'.$rid}.'"></embed>');
698: } elsif (&Apache::lonnet::declutter($hash{'src_'.$rid}) !~/\.(sequence|page)$/) {
699: $r->print($metainfo.'<b>'.$hash{'title_'.$rid}.'</b><br />');
700: unless ($cellemb{$rid} eq 'wrp') {
701: $r->print(&mt('It is recommended that you use an up-to-date virus scanner before handling this file.'));
702: }
703: $r->print('</p><p><table>'.
704: &Apache::londocs::entryline(0,
705: &mt("Click to download or use your browser's Save Link function"),
706: '/'.&Apache::lonnet::declutter($hash{'src_'.$rid})).
707: '</table></p><br />');
708: }
709: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
710: $r->print('</td>');
711: } else {
712: # for (my $incol=1;$incol<=$avespan;$incol++) {
713: # $r->print(' & ');
714: # }
715: }
716: }
717: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
718: $r->print('</tr>');
719: } else {
720: # $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
721: }
722: }
723: }
724: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
725: $r->print("\n</table>");
726: } else {
727: # $r->print('\end{longtable}\strut');
728: }
729: # ---------------------------------------------------------------- Submit, etc.
730: if ($nforms) {
731: my $class;
732: if ($nforms > 1) {
733: $class = ' class="LC_hwk_submit"';
734: if ($ntimers) {
735: $nforms = 1;
736: $class = '';
737: }
738: }
739: $r->print(
740: '<input name="all_submit" value="'.&mt('Submit All').'" type="'.
741: (($nforms>1)?'submit':'hidden').'"'.$class.' id="all_submit" />'.
742: '<div id="msg_all_submit" style="display:none">'.
743: &mt('Processing your submission ...').'</div></form>');
744: }
745: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
746: $r->print(&Apache::loncommon::end_page({'discussion'
747: => 1,}));
748: } else {
749: $r->print('\end{document}'.$number_of_columns);
750: }
751: &Apache::lonnet::symblist($requrl,%symbhash);
752: my ($map,$id,$url)=&Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
753: &Apache::lonnet::symblist($map,'last_known'=>[$url,$id]);
754: # -------------------------------------------------------------------- End page
755: }
756: # ------------------------------------------------------------- End render page
757: } else {
758: &Apache::loncommon::content_type($r,'text/html');
759: $r->send_http_header;
760: &Apache::lonsequence::viewmap($r,$requrl);
761: }
762: # ------------------------------------------------------------------ Untie hash
763: unless (untie(%hash)) {
764: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
765: "Could not untie coursemap $fn (browse).</font>");
766: }
767: # -------------------------------------------------------------------- All done
768: return OK;
769: # ----------------------------------------------- Errors, hash could no be tied
770: }
771: }
772: }
773: &Apache::loncommon::content_type($r,'text/html');
774: $r->send_http_header;
775: &Apache::lonsequence::viewmap($r,$requrl);
776: return OK;
777: }
778:
779: sub get_buttons {
780: my ($hash,$rid,$buttonshide) = @_;
781:
782: my $metainfo = '';
783: my $esrc=&Apache::lonnet::declutter($hash->{'src_'.$rid});
784: my ($mapid,$resid)=split(/\./,$rid);
785: my $symb=&Apache::lonnet::encode_symb($hash->{'map_id_'.$mapid},
786: $resid,
787: $hash->{'src_'.$rid});
788: unless ($env{'request.role.adv'}) {
789: if ($buttonshide->{$symb} eq 'yes') {
790: return;
791: }
792: }
793: if ($hash->{'encrypted_'.$rid}) {
794: $symb=&Apache::lonenc::encrypted($symb);
795: $esrc=&Apache::lonenc::encrypted($esrc);
796: }
797: if ($hash->{'src_'.$rid} !~ m-^/uploaded/-
798: && $hash->{'src_'.$rid} !~ m{^https?://}
799: && !$env{'request.enc'}
800: && ($env{'request.role.adv'}
801: || !$hash->{'encrypted_'.$rid})) {
802: $metainfo .='<a name="'.&escape($symb).'" />'.
803: '<a href="'.$hash->{'src_'.$rid}.'.meta'.'" target="LONcatInfo">'.
804: '<img src="/res/adm/pages/catalog.png" class="LC_icon"'.
805: ' alt="'.&mt('Show Metadata').'"'.
806: ' title="'.&mt('Show Metadata').'" />'.
807: '</a>';
808: }
809: if (($hash->{'src_'.$rid} !~ m{^/uploaded/}) &&
810: ($hash->{'src_'.$rid} !~ m{^https?://})) {
811: $metainfo .= '<a href="/adm/evaluate?postdata='.
812: &escape($esrc).
813: '" target="LONcatInfo">'.
814: '<img src="/res/adm/pages/eval.png" class="LC_icon"'.
815: ' alt="'.&mt('Provide my evaluation of this resource').'"'.
816: ' title="'.&mt('Provide my evaluation of this resource').'" />'.
817: '</a>';
818: }
819: if (($hash->{'src_'.$rid}=~/$LONCAPA::assess_re/) &&
820: ($hash->{'src_'.$rid} !~ m-^/uploaded/-)) {
821:
822: if (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) {
823: $metainfo.=
824: '<a href="/adm/grades?symb='.&escape($symb).
825: # '&command=submission" target="LONcatInfo">'.
826: '&command=submission">'.
827: '<img src="/adm/lonMisc/subm_button.png" class="LC_icon"'.
828: ' alt="'.&mt('View Submissions for a Student or a Group of Students').'"'.
829: ' title="'.&mt('View Submissions for a Student or a Group of Students').'" />'.
830: '</a>'.
831: '<a href="/adm/grades?symb='.&escape($symb).
832: # '&command=gradingmenu" target="LONcatInfo">'.
833: '&command=gradingmenu">'.
834: '<img src="/res/adm/pages/pgrd.png" class="LC_icon"'.
835: ' alt="'.&mt('Content Grades').'"'.
836: ' title="'.&mt('Content Grades').'" />'.
837: '</a>';
838: }
839: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
840: $metainfo.=
841: '<a href="/adm/parmset?symb='.&escape($symb).
842: # '" target="LONcatInfo">'.
843: '" >'.
844: '<img src="/adm/lonMisc/pprm_button.png" class="LC_icon"'.
845: ' alt="'.&mt('Content Settings').'"'.
846: ' title="'.&mt('Content Settings').'" />'.
847: '</a>';
848: }
849: }
850: if (($env{'request.course.id'}) && (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
851: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
852: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
853: my $file=&Apache::lonnet::declutter($hash->{'src_'.$rid});
854: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
855: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,$hash->{'src_'.$rid},$symb);
856: if ($cfile ne '') {
857: my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
858: $forceedit,1,$symb,undef,
859: &escape($env{'form.title'}));
860: if ($jscall) {
861: my $icon = 'pcstr.png';
862: my $label = &mt('Edit');
863: my $title = &mt('Edit this resource');
864: my $pic = '<img src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$icon).'"'.
865: ' class="LC_icon" alt="'.$label.'" title="'.$title.'" />';
866: $metainfo .= ' <a href="javascript:'.$jscall.';">'.$pic.'</a>';
867: }
868: }
869: }
870: return $metainfo;
871: }
872:
873: sub add_countdown_timer {
874: my ($currdisp) = @_;
875: my ($collapse,$expand,$alttxt,$title);
876: if ($currdisp eq 'inline') {
877: $collapse = '► ';
878: } else {
879: $expand = '◄ ';
880: }
881: unless ($env{'environment.icons'} eq 'iconsonly') {
882: $alttxt = &mt('Timer');
883: $title = $alttxt.' ';
884: }
885: my $desc = &mt('Countdown to due date/time');
886: my $output = <<END;
887: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
888: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
889: $collapse
890: </span></a>
891: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
892: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
893: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
894: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
895: END
896: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
897: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$output);
898: return;
899: }
900:
901:
902: 1;
903: __END__
904:
905:
906: =head1 NAME
907:
908: Apache::lonpage - Page Handler
909:
910: =head1 SYNOPSIS
911:
912: Invoked by /etc/httpd/conf/srm.conf:
913:
914: <LocationMatch "^/res/.*\.page$>
915: SetHandler perl-script
916: PerlHandler Apache::lonpage
917: </LocationMatch>
918:
919: =head1 INTRODUCTION
920:
921: This module renders a .page resource.
922:
923: This is part of the LearningOnline Network with CAPA project
924: described at http://www.lon-capa.org.
925:
926: =head1 HANDLER SUBROUTINE
927:
928: This routine is called by Apache and mod_perl.
929:
930: =over 4
931:
932: =item *
933:
934: set document type for header only
935:
936: =item *
937:
938: tie db file
939:
940: =item *
941:
942: render page
943:
944: =item *
945:
946: add to symb list
947:
948: =item *
949:
950: page parms
951:
952: =item *
953:
954: Get SSI output, post parameters
955:
956: =item *
957:
958: SSI cell rendering
959:
960: =item *
961:
962: Deal with Applet codebases
963:
964: =item *
965:
966: Build page
967:
968: =item *
969:
970: send headers
971:
972: =item *
973:
974: start body
975:
976: =item *
977:
978: start form
979:
980: =item *
981:
982: start table
983:
984: =item *
985:
986: submit element, etc, render page, untie hash
987:
988: =back
989:
990: =head1 OTHER SUBROUTINES
991:
992: =over 4
993:
994: =item *
995:
996: euclid() : Euclid's method for determining the greatest common denominator.
997:
998: =item *
999:
1000: tracetable() : Build page table.
1001:
1002: =back
1003:
1004: =cut
1005:
1006:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>