Annotation of rat/lonpage.pm, revision 1.111.2.4
1.1 www 1: # The LearningOnline Network with CAPA
2: # Page Handler
3: #
1.111.2.4! raeburn 4: # $Id: lonpage.pm,v 1.111.2.3 2016/10/29 05:59:30 raeburn Exp $
1.29 www 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: #
1.30 harris41 28: ###
1.1 www 29:
1.88 jms 30:
31:
32:
1.1 www 33: package Apache::lonpage;
34:
35: use strict;
36: use Apache::Constants qw(:common :http);
1.70 albertel 37: use Apache::lonnet;
1.30 harris41 38: use Apache::loncommon();
1.102 raeburn 39: use Apache::lonhtmlcommon;
1.21 www 40: use Apache::lonxml();
1.57 raeburn 41: use Apache::lonlocal;
1.49 www 42: use Apache::lonmenu;
1.111 raeburn 43: use Apache::lonhomework;
1.6 www 44: use HTML::TokeParser;
1.1 www 45: use GDBM_File;
1.39 www 46: use Apache::lonsequence;
1.75 www 47: use lib '/home/httpd/lib/perl/';
48: use LONCAPA;
49:
1.1 www 50:
1.2 www 51: # -------------------------------------------------------------- Module Globals
52: my %hash;
53: my @rows;
1.6 www 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: }
1.2 www 67:
68: # ------------------------------------------------------------ Build page table
69:
70: sub tracetable {
71: my ($sofar,$rid,$beenhere)=@_;
72: my $further=$sofar;
1.57 raeburn 73: my $randomout=0;
1.70 albertel 74: unless ($env{'request.role.adv'}) {
1.57 raeburn 75: $randomout = $hash{'randomout_'.$rid};
76: }
1.2 www 77: unless ($beenhere=~/\&$rid\&/) {
1.57 raeburn 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}},
1.87 albertel 86: '&'.$frid.$beenhere);
1.57 raeburn 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=
1.11 www 119: &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
1.57 raeburn 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: }
1.2 www 137: }
138: return $further;
139: }
140:
1.1 www 141: # ================================================================ Main Handler
142:
143: sub handler {
144: my $r=shift;
145:
1.3 www 146: # ------------------------------------------- Set document type for header only
1.1 www 147:
1.3 www 148: if ($r->header_only) {
1.70 albertel 149: if ($env{'browser.mathml'}) {
1.53 www 150: &Apache::loncommon::content_type($r,'text/xml');
1.3 www 151: } else {
1.53 www 152: &Apache::loncommon::content_type($r,'text/html');
1.3 www 153: }
154: $r->send_http_header;
155: return OK;
156: }
1.43 sakharuk 157:
1.39 www 158: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
159: ['forceselect','launch']);
1.43 sakharuk 160: my $number_of_columns = 1;
1.37 sakharuk 161: my $requrl=$r->uri;
1.70 albertel 162: my $target = $env{'form.grade_target'};
1.94 raeburn 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: }
1.55 www 176: # &Apache::lonnet::logthis("Got a target of $target");
1.54 albertel 177: if ($target eq 'meta') {
178: &Apache::loncommon::content_type($r,'text/html');
179: $r->send_http_header;
180: return OK;
181: }
1.1 www 182: # ----------------------------------------------------------------- Tie db file
1.70 albertel 183: if (($env{'request.course.fn'}) && (!$env{'form.forceselect'})) {
184: my $fn=$env{'request.course.fn'};
1.1 www 185: if (-e "$fn.db") {
1.111.2.3 raeburn 186: my %buttonshide;
1.44 albertel 187: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) {
1.1 www 188: # ------------------------------------------------------------------- Hash tied
189: my $firstres=$hash{'map_start_'.$requrl};
190: my $lastres=$hash{'map_finish_'.$requrl};
191: if (($firstres) && ($lastres)) {
1.111 raeburn 192: # ------------------------------------------------------------- Countdown Timer
193: my $now = time;
194: my ($pagefirstaccess,%hastimeleft,%countdowndisp);
195: my ($pagesymb,$courseid,$domain,$name)=&Apache::lonnet::whichuser();
1.111.2.2 raeburn 196: if ($pagesymb && ($courseid ne '') && ($domain ne '') && ($name ne '')) {
1.111 raeburn 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: }
1.1 www 204: # ----------------------------------------------------------------- Render page
205:
1.3 www 206: @rows=();
1.2 www 207:
1.45 www 208: &tracetable(0,$firstres,'&');
1.2 www 209:
1.9 www 210: # ------------------------------------------------------------ Add to symb list
211:
1.2 www 212: my $i;
1.9 www 213: my %symbhash=();
214: for ($i=0;$i<=$#rows;$i++) {
215: if ($rows[$i]) {
216: my @colcont=split(/\&/,$rows[$i]);
1.73 albertel 217: foreach my $rid (@colcont) {
218: my ($mapid,$resid)=split(/\./,$rid);
219: $symbhash{$hash{'src_'.$rid}}=
220: [$hash{'src_'.$rid},$resid];
1.30 harris41 221: }
1.9 www 222: }
223: }
224: &Apache::lonnet::symblist($requrl,%symbhash);
225:
226: # ------------------------------------------------------------------ Page parms
227:
1.4 www 228: my $j;
1.6 www 229: my $lcm=1;
230: my $contents=0;
1.7 www 231: my $nforms=0;
1.96 raeburn 232: my $nuploads=0;
1.110 raeburn 233: my $ntimers=0;
1.96 raeburn 234: my %turninpaths;
235: my %multiresps;
236: my $turninparent;
1.6 www 237:
238: my %ssibody=();
239: my %ssibgcolor=();
240: my %ssitext=();
241: my %ssilink=();
242: my %ssivlink=();
243: my %ssialink=();
1.14 www 244:
1.6 www 245: my %cellemb=();
1.99 raeburn 246: my %cellexternal=();
1.3 www 247:
1.7 www 248: my $allscript='';
249: my $allmeta='';
250:
251: my $isxml=0;
252: my $xmlheader='';
253: my $xmlbody='';
254:
1.3 www 255: # --------------------------------------------- Get SSI output, post parameters
256:
1.2 www 257: for ($i=0;$i<=$#rows;$i++) {
1.4 www 258: if ($rows[$i]) {
1.6 www 259: $contents++;
1.3 www 260: my @colcont=split(/\&/,$rows[$i]);
1.6 www 261: $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
1.30 harris41 262: foreach (@colcont) {
1.3 www 263: my $src=$hash{'src_'.$_};
1.111.2.3 raeburn 264: my $plainsrc = $src;
1.99 raeburn 265: my ($extension)=($src=~/\.(\w+)$/);
266: $cellexternal{$_}=($hash{'ext_'.$_} eq 'true:');
1.61 albertel 267: if ($hash{'encrypted_'.$_}) {
268: $src=&Apache::lonenc::encrypted($src);
269: }
1.111.2.3 raeburn 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: }
1.61 albertel 275: $cellemb{$_}=
276: &Apache::loncommon::fileembstyle($extension);
1.99 raeburn 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') {
1.3 www 284: # --------------------------------------------------------- This is an SSI cell
1.5 www 285: my $prefix=$_.'_';
1.101 raeburn 286: my $idprefix= join('_',($mapid,$resid,''));
1.64 albertel 287: my %posthash=('request.prefix' => $prefix,
1.71 albertel 288: 'LONCAPA_INTERNAL_no_discussion' => 'true',
1.64 albertel 289: 'symb' => $symb);
1.94 raeburn 290: if (($env{'form.grade_target'} eq 'tex') ||
291: ($env{'form.answer_output_mode'} eq 'tex')) {
1.70 albertel 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'};
1.94 raeburn 297: $posthash{'answer_output_mode'} = $env{'form.answer_output_mode'};
1.56 sakharuk 298: }
1.72 albertel 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: }
1.7 www 318: }
1.111.2.4! raeburn 319: if ($env{'environment.remote'} eq 'on') {
! 320: $posthash{'inhibitmenu'} = 'yes';
! 321: }
1.5 www 322: my $output=Apache::lonnet::ssi($src,%posthash);
1.77 albertel 323: $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+?// END LON-CAPA Internal\s*(-->)?\s||gs;
1.94 raeburn 324: if (($target eq 'tex') || ($target eq 'tex_answer')) {
1.111.2.1 raeburn 325: $output =~ s/^([^&]+)\\begin\{document}//;
326: $output =~ s/\\end\{document}//;
1.92 foxr 327: # $output = '\parbox{\minipagewidth}{ '.$output.' }';
1.46 sakharuk 328: #some additional cleanup necessary for LateX (due to limitations of table environment
329: $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
330: }
1.107 raeburn 331: my $matheditor;
332: if ($output =~ /\Qjavascript:LC_mathedit_HWVAL_\E/) {
333: $matheditor = 'dragmath';
334: } elsif ($output =~ /LCmathField/) {
335: $matheditor = 'lcmath';
336: }
1.6 www 337: my $parser=HTML::TokeParser->new(\$output);
338: my $token;
1.12 www 339: my $thisdir=$src;
1.6 www 340: my $bodydef=0;
1.7 www 341: my $thisxml=0;
1.12 www 342: my @rlinks=();
1.7 www 343: if ($output=~/\?xml/) {
344: $isxml=1;
345: $thisxml=1;
346: $output=~
347: /((?:\<(?:\?xml|\!DOC|html)[^\>]*(?:\>|\>\]\>)\s*)+)\<body[^\>]*\>/si;
348: $xmlheader=$1;
349: }
1.12 www 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') {
1.7 www 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: }
1.12 www 375: } elsif ($token->[1] eq 'meta') {
1.28 albertel 376: if ($token->[4] !~ m:/>$:) {
1.7 www 377: $allmeta.="\n".$token->[4].'</meta>';
1.28 albertel 378: } else {
379: $allmeta.="\n".$token->[4];
380: }
1.12 www 381: } elsif (($token->[1] eq 'script') &&
382: ($bodydef==0)) {
1.7 www 383: $allscript.="\n\n"
384: .$parser->get_text('/script');
1.6 www 385: }
1.12 www 386: }
387: }
1.6 www 388: if ($output=~/\<body[^\>]*\>(.*)/si) {
389: $output=$1;
390: }
391: $output=~s/\<\/body\>.*//si;
1.7 www 392: if ($output=~/\<form/si) {
1.110 raeburn 393: my $hastimer;
1.7 www 394: $nforms++;
395: $output=~s/\<form[^\>]*\>//gsi;
396: $output=~s/\<\/form[^\>]*\>//gsi;
1.96 raeburn 397: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*HWFILE/) {
398: $nuploads++;
399: }
1.110 raeburn 400: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*accessbutton/) {
401: $ntimers++;
402: $hastimer = 1;
403: }
1.17 www 404: $output=~
1.80 albertel 405: s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
1.101 raeburn 406: $output=~
407: s/\<((?:input|select|button|textarea)[^\>]+)id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 id="$idprefix$2" $3\>/gsi;
1.110 raeburn 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: }
1.107 raeburn 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: }
1.105 raeburn 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;
1.96 raeburn 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: }
1.95 raeburn 436: $output=~
437: s/\<((?:input|select)[^\>]+\Qjavascript:setSubmittedPart\E)\(\s*[\'\"]([^\'\"]+)[\'\"]*\s*\)/\<$1('$2','$prefix')/gsi;
1.108 raeburn 438: $output=~
439: s/\<(input[^\>]+\Qonfocus=\"javascript:disableAutoComplete\E)\(\'([^\']+)\'\)(;\")/\<$1('$idprefix$2')$3/gsi;
1.111 raeburn 440: unless ($hastimer) {
1.111.2.3 raeburn 441: if ($plainsrc =~ /$LONCAPA::assess_re/) {
1.111 raeburn 442: %Apache::lonhomework::history =
443: &Apache::lonnet::restore($symb,$courseid,$domain,$name);
444: my $type = 'problem';
1.111.2.3 raeburn 445: if ($extension eq 'task') {
1.111 raeburn 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: }
1.7 www 493: }
1.12 www 494: $thisdir=~s/\/[^\/]*$//;
1.30 harris41 495: foreach (@rlinks) {
1.91 raeburn 496: unless (($_=~/^https?\:\/\//i) ||
1.31 albertel 497: ($_=~/^\//) ||
498: ($_=~/^javascript:/i) ||
499: ($_=~/^mailto:/i) ||
500: ($_=~/^\#/)) {
1.12 www 501: my $newlocation=
502: &Apache::lonnet::hreflocation($thisdir,$_);
503: $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
504: }
1.30 harris41 505: }
1.24 www 506: # -------------------------------------------------- Deal with Applet codebases
507: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
1.5 www 508: $ssibody{$_}=$output;
1.3 www 509: # ---------------------------------------------------------------- End SSI cell
510: }
1.30 harris41 511: }
1.4 www 512: }
1.2 www 513: }
1.6 www 514: unless ($contents) {
1.53 www 515: &Apache::loncommon::content_type($r,'text/html');
1.3 www 516: $r->send_http_header;
1.74 albertel 517: $r->print(&Apache::loncommon::start_page(undef,undef,
1.111.2.3 raeburn 518: {'force_register' => 1}));
1.59 raeburn 519: $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
1.74 albertel 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());
1.3 www 522: } else {
523: # ------------------------------------------------------------------ Build page
1.7 www 524:
525: # ---------------------------------------------------------------- Send headers
1.94 raeburn 526: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 527: if ($isxml) {
1.53 www 528: &Apache::loncommon::content_type($r,'text/xml');
1.37 sakharuk 529: } else {
1.53 www 530: &Apache::loncommon::content_type($r,'text/html');
1.37 sakharuk 531: }
1.74 albertel 532: $r->send_http_header;
1.7 www 533: # ------------------------------------------------------------------------ Head
1.37 sakharuk 534: if ($allscript) {
1.85 albertel 535: $allscript =
536: "\n".'<script type="text/javascript">'."\n".
537: $allscript.
538: "\n</script>\n";
1.37 sakharuk 539: }
1.96 raeburn 540: if (($nforms) && ($nuploads)) {
541: $allscript .= &Apache::lonhtmlcommon::file_submissionchk_js(\%turninpaths,\%multiresps);
542: }
1.101 raeburn 543: if (($nforms) && (&Apache::lonhtmlcommon::htmlareabrowser())) {
544: my %textarea_args = (
545: dragmath => 'math',
546: );
547: $allscript .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
548: }
1.110 raeburn 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: }
1.111 raeburn 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: }
1.111.2.3 raeburn 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: }
1.7 www 602: # ------------------------------------------------------------------ Start body
1.85 albertel 603: $r->print(&Apache::loncommon::start_page(undef,$allscript,
1.74 albertel 604: {'force_register' => 1,
1.111.2.3 raeburn 605: 'bgcolor' => '#ffffff',
606: 'hide_buttons' => $pagebuttonshide}));
1.7 www 607: # ------------------------------------------------------------------ Start form
1.37 sakharuk 608: if ($nforms) {
1.96 raeburn 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="'.
1.61 albertel 618: &Apache::lonenc::check_encrypt($requrl)
1.105 raeburn 619: .'" id="LC_page">';
1.96 raeburn 620: $r->print($fmtag);
1.40 sakharuk 621: }
1.94 raeburn 622: } elsif (($target eq 'tex') || ($target eq 'tex_answer')) {
1.92 foxr 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}');
1.40 sakharuk 634: }
1.7 www 635: # ----------------------------------------------------------------- Start table
1.94 raeburn 636: if (($target eq 'tex') || ($target eq 'tex_answer')) {
1.92 foxr 637: # # $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
1.43 sakharuk 638: if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
1.40 sakharuk 639: } else {
1.63 albertel 640: $r->print('<table width="100%" cols="'.$lcm.'" border="0">');
1.37 sakharuk 641: }
1.78 www 642: # generate rows
1.5 www 643: for ($i=0;$i<=$#rows;$i++) {
644: if ($rows[$i]) {
1.94 raeburn 645: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 646: $r->print("\n<tr>");
647: }
1.4 www 648: my @colcont=split(/\&/,$rows[$i]);
1.6 www 649: my $avespan=$lcm/($#colcont+1);
650: for ($j=0;$j<=$#colcont;$j++) {
651: my $rid=$colcont[$j];
1.111.2.3 raeburn 652: my $metainfo =&get_buttons(\%hash,$rid,\%buttonshide).'<br />';
1.94 raeburn 653: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 654: $r->print('<td colspan="'.$avespan.'"');
655: }
1.99 raeburn 656: if (($cellemb{$rid} eq 'ssi') || ($cellexternal{$rid})) {
1.94 raeburn 657: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 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: }
1.99 raeburn 678: unless (($cellexternal{$rid}) &&
679: ($target eq 'tex') && ($target eq 'tex_answer')) {
680: $r->print($ssibody{$rid});
681: }
1.94 raeburn 682: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 683: $r->print('</font>');
1.41 www 684: }
1.70 albertel 685: if ($env{'course.'.
686: $env{'request.course.id'}.
1.41 www 687: '.pageseparators'} eq 'yes') {
1.94 raeburn 688: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.41 www 689: $r->print('<hr />');
1.77 albertel 690: }
1.37 sakharuk 691: }
692: } elsif ($cellemb{$rid} eq 'img') {
1.14 www 693: $r->print('>'.$metainfo.'<img src="'.
1.77 albertel 694: $hash{'src_'.$rid}.'" />');
1.13 www 695: } elsif ($cellemb{$rid} eq 'emb') {
1.14 www 696: $r->print('>'.$metainfo.'<embed src="'.
1.13 www 697: $hash{'src_'.$rid}.'"></embed>');
1.60 raeburn 698: } elsif (&Apache::lonnet::declutter($hash{'src_'.$rid}) !~/\.(sequence|page)$/) {
1.104 raeburn 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 />');
1.13 www 708: }
1.94 raeburn 709: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 710: $r->print('</td>');
1.40 sakharuk 711: } else {
1.92 foxr 712: # for (my $incol=1;$incol<=$avespan;$incol++) {
713: # $r->print(' & ');
714: # }
1.37 sakharuk 715: }
1.4 www 716: }
1.94 raeburn 717: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 718: $r->print('</tr>');
1.40 sakharuk 719: } else {
1.92 foxr 720: # $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
1.37 sakharuk 721: }
1.5 www 722: }
1.4 www 723: }
1.94 raeburn 724: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 725: $r->print("\n</table>");
1.40 sakharuk 726: } else {
1.92 foxr 727: # $r->print('\end{longtable}\strut');
1.37 sakharuk 728: }
1.7 www 729: # ---------------------------------------------------------------- Submit, etc.
730: if ($nforms) {
1.106 raeburn 731: my $class;
732: if ($nforms > 1) {
733: $class = ' class="LC_hwk_submit"';
1.110 raeburn 734: if ($ntimers) {
735: $nforms = 1;
736: $class = '';
737: }
1.106 raeburn 738: }
1.7 www 739: $r->print(
1.103 bisitz 740: '<input name="all_submit" value="'.&mt('Submit All').'" type="'.
1.106 raeburn 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>');
1.7 www 744: }
1.94 raeburn 745: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.76 albertel 746: $r->print(&Apache::loncommon::end_page({'discussion'
747: => 1,}));
1.40 sakharuk 748: } else {
749: $r->print('\end{document}'.$number_of_columns);
750: }
1.66 albertel 751: &Apache::lonnet::symblist($requrl,%symbhash);
1.69 albertel 752: my ($map,$id,$url)=&Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
753: &Apache::lonnet::symblist($map,'last_known'=>[$url,$id]);
1.3 www 754: # -------------------------------------------------------------------- End page
755: }
1.1 www 756: # ------------------------------------------------------------- End render page
757: } else {
1.67 albertel 758: &Apache::loncommon::content_type($r,'text/html');
1.3 www 759: $r->send_http_header;
1.39 www 760: &Apache::lonsequence::viewmap($r,$requrl);
1.1 www 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: }
1.67 albertel 773: &Apache::loncommon::content_type($r,'text/html');
1.39 www 774: $r->send_http_header;
775: &Apache::lonsequence::viewmap($r,$requrl);
776: return OK;
1.1 www 777: }
778:
1.83 albertel 779: sub get_buttons {
1.111.2.3 raeburn 780: my ($hash,$rid,$buttonshide) = @_;
1.83 albertel 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});
1.109 raeburn 788: unless ($env{'request.role.adv'}) {
1.111.2.3 raeburn 789: if ($buttonshide->{$symb} eq 'yes') {
1.109 raeburn 790: return;
791: }
792: }
1.83 albertel 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/-
1.99 raeburn 798: && $hash->{'src_'.$rid} !~ m{^https?://}
1.83 albertel 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">'.
1.100 bisitz 804: '<img src="/res/adm/pages/catalog.png" class="LC_icon"'.
805: ' alt="'.&mt('Show Metadata').'"'.
806: ' title="'.&mt('Show Metadata').'" />'.
1.83 albertel 807: '</a>';
808: }
1.99 raeburn 809: if (($hash->{'src_'.$rid} !~ m{^/uploaded/}) &&
810: ($hash->{'src_'.$rid} !~ m{^https?://})) {
1.98 raeburn 811: $metainfo .= '<a href="/adm/evaluate?postdata='.
812: &escape($esrc).
813: '" target="LONcatInfo">'.
1.100 bisitz 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').'" />'.
1.98 raeburn 817: '</a>';
818: }
1.97 www 819: if (($hash->{'src_'.$rid}=~/$LONCAPA::assess_re/) &&
1.83 albertel 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">'.
1.100 bisitz 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').'" />'.
1.83 albertel 830: '</a>'.
831: '<a href="/adm/grades?symb='.&escape($symb).
832: # '&command=gradingmenu" target="LONcatInfo">'.
833: '&command=gradingmenu">'.
1.100 bisitz 834: '<img src="/res/adm/pages/pgrd.png" class="LC_icon"'.
835: ' alt="'.&mt('Content Grades').'"'.
836: ' title="'.&mt('Content Grades').'" />'.
1.83 albertel 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: '" >'.
1.100 bisitz 844: '<img src="/adm/lonMisc/pprm_button.png" class="LC_icon"'.
845: ' alt="'.&mt('Content Settings').'"'.
846: ' title="'.&mt('Content Settings').'" />'.
1.83 albertel 847: '</a>';
848: }
849: }
1.102 raeburn 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: }
1.83 albertel 870: return $metainfo;
871: }
872:
1.111 raeburn 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:
1.1 www 902: 1;
903: __END__
904:
905:
1.89 jms 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
1.1 www 955:
1.89 jms 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
1.1 www 1005:
1006:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>