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