Annotation of rat/lonpage.pm, revision 1.111.2.3
1.1 www 1: # The LearningOnline Network with CAPA
2: # Page Handler
3: #
1.111.2.3! raeburn 4: # $Id: lonpage.pm,v 1.111.2.2 2016/08/10 04:37:32 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.5 www 319: my $output=Apache::lonnet::ssi($src,%posthash);
1.77 albertel 320: $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+?// END LON-CAPA Internal\s*(-->)?\s||gs;
1.94 raeburn 321: if (($target eq 'tex') || ($target eq 'tex_answer')) {
1.111.2.1 raeburn 322: $output =~ s/^([^&]+)\\begin\{document}//;
323: $output =~ s/\\end\{document}//;
1.92 foxr 324: # $output = '\parbox{\minipagewidth}{ '.$output.' }';
1.46 sakharuk 325: #some additional cleanup necessary for LateX (due to limitations of table environment
326: $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
327: }
1.107 raeburn 328: my $matheditor;
329: if ($output =~ /\Qjavascript:LC_mathedit_HWVAL_\E/) {
330: $matheditor = 'dragmath';
331: } elsif ($output =~ /LCmathField/) {
332: $matheditor = 'lcmath';
333: }
1.6 www 334: my $parser=HTML::TokeParser->new(\$output);
335: my $token;
1.12 www 336: my $thisdir=$src;
1.6 www 337: my $bodydef=0;
1.7 www 338: my $thisxml=0;
1.12 www 339: my @rlinks=();
1.7 www 340: if ($output=~/\?xml/) {
341: $isxml=1;
342: $thisxml=1;
343: $output=~
344: /((?:\<(?:\?xml|\!DOC|html)[^\>]*(?:\>|\>\]\>)\s*)+)\<body[^\>]*\>/si;
345: $xmlheader=$1;
346: }
1.12 www 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') {
1.7 www 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: }
1.12 www 372: } elsif ($token->[1] eq 'meta') {
1.28 albertel 373: if ($token->[4] !~ m:/>$:) {
1.7 www 374: $allmeta.="\n".$token->[4].'</meta>';
1.28 albertel 375: } else {
376: $allmeta.="\n".$token->[4];
377: }
1.12 www 378: } elsif (($token->[1] eq 'script') &&
379: ($bodydef==0)) {
1.7 www 380: $allscript.="\n\n"
381: .$parser->get_text('/script');
1.6 www 382: }
1.12 www 383: }
384: }
1.6 www 385: if ($output=~/\<body[^\>]*\>(.*)/si) {
386: $output=$1;
387: }
388: $output=~s/\<\/body\>.*//si;
1.7 www 389: if ($output=~/\<form/si) {
1.110 raeburn 390: my $hastimer;
1.7 www 391: $nforms++;
392: $output=~s/\<form[^\>]*\>//gsi;
393: $output=~s/\<\/form[^\>]*\>//gsi;
1.96 raeburn 394: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*HWFILE/) {
395: $nuploads++;
396: }
1.110 raeburn 397: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*accessbutton/) {
398: $ntimers++;
399: $hastimer = 1;
400: }
1.17 www 401: $output=~
1.80 albertel 402: s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
1.101 raeburn 403: $output=~
404: s/\<((?:input|select|button|textarea)[^\>]+)id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 id="$idprefix$2" $3\>/gsi;
1.110 raeburn 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: }
1.107 raeburn 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: }
1.105 raeburn 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;
1.96 raeburn 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: }
1.95 raeburn 433: $output=~
434: s/\<((?:input|select)[^\>]+\Qjavascript:setSubmittedPart\E)\(\s*[\'\"]([^\'\"]+)[\'\"]*\s*\)/\<$1('$2','$prefix')/gsi;
1.108 raeburn 435: $output=~
436: s/\<(input[^\>]+\Qonfocus=\"javascript:disableAutoComplete\E)\(\'([^\']+)\'\)(;\")/\<$1('$idprefix$2')$3/gsi;
1.111 raeburn 437: unless ($hastimer) {
1.111.2.3! raeburn 438: if ($plainsrc =~ /$LONCAPA::assess_re/) {
1.111 raeburn 439: %Apache::lonhomework::history =
440: &Apache::lonnet::restore($symb,$courseid,$domain,$name);
441: my $type = 'problem';
1.111.2.3! raeburn 442: if ($extension eq 'task') {
1.111 raeburn 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: }
1.7 www 490: }
1.12 www 491: $thisdir=~s/\/[^\/]*$//;
1.30 harris41 492: foreach (@rlinks) {
1.91 raeburn 493: unless (($_=~/^https?\:\/\//i) ||
1.31 albertel 494: ($_=~/^\//) ||
495: ($_=~/^javascript:/i) ||
496: ($_=~/^mailto:/i) ||
497: ($_=~/^\#/)) {
1.12 www 498: my $newlocation=
499: &Apache::lonnet::hreflocation($thisdir,$_);
500: $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
501: }
1.30 harris41 502: }
1.24 www 503: # -------------------------------------------------- Deal with Applet codebases
504: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
1.5 www 505: $ssibody{$_}=$output;
1.3 www 506: # ---------------------------------------------------------------- End SSI cell
507: }
1.30 harris41 508: }
1.4 www 509: }
1.2 www 510: }
1.6 www 511: unless ($contents) {
1.53 www 512: &Apache::loncommon::content_type($r,'text/html');
1.3 www 513: $r->send_http_header;
1.74 albertel 514: $r->print(&Apache::loncommon::start_page(undef,undef,
1.111.2.3! raeburn 515: {'force_register' => 1}));
1.59 raeburn 516: $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
1.74 albertel 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());
1.3 www 519: } else {
520: # ------------------------------------------------------------------ Build page
1.7 www 521:
522: # ---------------------------------------------------------------- Send headers
1.94 raeburn 523: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 524: if ($isxml) {
1.53 www 525: &Apache::loncommon::content_type($r,'text/xml');
1.37 sakharuk 526: } else {
1.53 www 527: &Apache::loncommon::content_type($r,'text/html');
1.37 sakharuk 528: }
1.74 albertel 529: $r->send_http_header;
1.7 www 530: # ------------------------------------------------------------------------ Head
1.37 sakharuk 531: if ($allscript) {
1.85 albertel 532: $allscript =
533: "\n".'<script type="text/javascript">'."\n".
534: $allscript.
535: "\n</script>\n";
1.37 sakharuk 536: }
1.96 raeburn 537: if (($nforms) && ($nuploads)) {
538: $allscript .= &Apache::lonhtmlcommon::file_submissionchk_js(\%turninpaths,\%multiresps);
539: }
1.101 raeburn 540: if (($nforms) && (&Apache::lonhtmlcommon::htmlareabrowser())) {
541: my %textarea_args = (
542: dragmath => 'math',
543: );
544: $allscript .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
545: }
1.110 raeburn 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: }
1.111 raeburn 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: }
1.111.2.3! raeburn 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: }
1.7 www 599: # ------------------------------------------------------------------ Start body
1.85 albertel 600: $r->print(&Apache::loncommon::start_page(undef,$allscript,
1.74 albertel 601: {'force_register' => 1,
1.111.2.3! raeburn 602: 'bgcolor' => '#ffffff',
! 603: 'hide_buttons' => $pagebuttonshide}));
1.7 www 604: # ------------------------------------------------------------------ Start form
1.37 sakharuk 605: if ($nforms) {
1.96 raeburn 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="'.
1.61 albertel 615: &Apache::lonenc::check_encrypt($requrl)
1.105 raeburn 616: .'" id="LC_page">';
1.96 raeburn 617: $r->print($fmtag);
1.40 sakharuk 618: }
1.94 raeburn 619: } elsif (($target eq 'tex') || ($target eq 'tex_answer')) {
1.92 foxr 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}');
1.40 sakharuk 631: }
1.7 www 632: # ----------------------------------------------------------------- Start table
1.94 raeburn 633: if (($target eq 'tex') || ($target eq 'tex_answer')) {
1.92 foxr 634: # # $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
1.43 sakharuk 635: if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
1.40 sakharuk 636: } else {
1.63 albertel 637: $r->print('<table width="100%" cols="'.$lcm.'" border="0">');
1.37 sakharuk 638: }
1.78 www 639: # generate rows
1.5 www 640: for ($i=0;$i<=$#rows;$i++) {
641: if ($rows[$i]) {
1.94 raeburn 642: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 643: $r->print("\n<tr>");
644: }
1.4 www 645: my @colcont=split(/\&/,$rows[$i]);
1.6 www 646: my $avespan=$lcm/($#colcont+1);
647: for ($j=0;$j<=$#colcont;$j++) {
648: my $rid=$colcont[$j];
1.111.2.3! raeburn 649: my $metainfo =&get_buttons(\%hash,$rid,\%buttonshide).'<br />';
1.94 raeburn 650: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 651: $r->print('<td colspan="'.$avespan.'"');
652: }
1.99 raeburn 653: if (($cellemb{$rid} eq 'ssi') || ($cellexternal{$rid})) {
1.94 raeburn 654: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 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: }
1.99 raeburn 675: unless (($cellexternal{$rid}) &&
676: ($target eq 'tex') && ($target eq 'tex_answer')) {
677: $r->print($ssibody{$rid});
678: }
1.94 raeburn 679: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 680: $r->print('</font>');
1.41 www 681: }
1.70 albertel 682: if ($env{'course.'.
683: $env{'request.course.id'}.
1.41 www 684: '.pageseparators'} eq 'yes') {
1.94 raeburn 685: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.41 www 686: $r->print('<hr />');
1.77 albertel 687: }
1.37 sakharuk 688: }
689: } elsif ($cellemb{$rid} eq 'img') {
1.14 www 690: $r->print('>'.$metainfo.'<img src="'.
1.77 albertel 691: $hash{'src_'.$rid}.'" />');
1.13 www 692: } elsif ($cellemb{$rid} eq 'emb') {
1.14 www 693: $r->print('>'.$metainfo.'<embed src="'.
1.13 www 694: $hash{'src_'.$rid}.'"></embed>');
1.60 raeburn 695: } elsif (&Apache::lonnet::declutter($hash{'src_'.$rid}) !~/\.(sequence|page)$/) {
1.104 raeburn 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 />');
1.13 www 705: }
1.94 raeburn 706: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 707: $r->print('</td>');
1.40 sakharuk 708: } else {
1.92 foxr 709: # for (my $incol=1;$incol<=$avespan;$incol++) {
710: # $r->print(' & ');
711: # }
1.37 sakharuk 712: }
1.4 www 713: }
1.94 raeburn 714: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 715: $r->print('</tr>');
1.40 sakharuk 716: } else {
1.92 foxr 717: # $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
1.37 sakharuk 718: }
1.5 www 719: }
1.4 www 720: }
1.94 raeburn 721: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 722: $r->print("\n</table>");
1.40 sakharuk 723: } else {
1.92 foxr 724: # $r->print('\end{longtable}\strut');
1.37 sakharuk 725: }
1.7 www 726: # ---------------------------------------------------------------- Submit, etc.
727: if ($nforms) {
1.106 raeburn 728: my $class;
729: if ($nforms > 1) {
730: $class = ' class="LC_hwk_submit"';
1.110 raeburn 731: if ($ntimers) {
732: $nforms = 1;
733: $class = '';
734: }
1.106 raeburn 735: }
1.7 www 736: $r->print(
1.103 bisitz 737: '<input name="all_submit" value="'.&mt('Submit All').'" type="'.
1.106 raeburn 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>');
1.7 www 741: }
1.94 raeburn 742: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.76 albertel 743: $r->print(&Apache::loncommon::end_page({'discussion'
744: => 1,}));
1.40 sakharuk 745: } else {
746: $r->print('\end{document}'.$number_of_columns);
747: }
1.66 albertel 748: &Apache::lonnet::symblist($requrl,%symbhash);
1.69 albertel 749: my ($map,$id,$url)=&Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
750: &Apache::lonnet::symblist($map,'last_known'=>[$url,$id]);
1.3 www 751: # -------------------------------------------------------------------- End page
752: }
1.1 www 753: # ------------------------------------------------------------- End render page
754: } else {
1.67 albertel 755: &Apache::loncommon::content_type($r,'text/html');
1.3 www 756: $r->send_http_header;
1.39 www 757: &Apache::lonsequence::viewmap($r,$requrl);
1.1 www 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: }
1.67 albertel 770: &Apache::loncommon::content_type($r,'text/html');
1.39 www 771: $r->send_http_header;
772: &Apache::lonsequence::viewmap($r,$requrl);
773: return OK;
1.1 www 774: }
775:
1.83 albertel 776: sub get_buttons {
1.111.2.3! raeburn 777: my ($hash,$rid,$buttonshide) = @_;
1.83 albertel 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});
1.109 raeburn 785: unless ($env{'request.role.adv'}) {
1.111.2.3! raeburn 786: if ($buttonshide->{$symb} eq 'yes') {
1.109 raeburn 787: return;
788: }
789: }
1.83 albertel 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/-
1.99 raeburn 795: && $hash->{'src_'.$rid} !~ m{^https?://}
1.83 albertel 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">'.
1.100 bisitz 801: '<img src="/res/adm/pages/catalog.png" class="LC_icon"'.
802: ' alt="'.&mt('Show Metadata').'"'.
803: ' title="'.&mt('Show Metadata').'" />'.
1.83 albertel 804: '</a>';
805: }
1.99 raeburn 806: if (($hash->{'src_'.$rid} !~ m{^/uploaded/}) &&
807: ($hash->{'src_'.$rid} !~ m{^https?://})) {
1.98 raeburn 808: $metainfo .= '<a href="/adm/evaluate?postdata='.
809: &escape($esrc).
810: '" target="LONcatInfo">'.
1.100 bisitz 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').'" />'.
1.98 raeburn 814: '</a>';
815: }
1.97 www 816: if (($hash->{'src_'.$rid}=~/$LONCAPA::assess_re/) &&
1.83 albertel 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">'.
1.100 bisitz 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').'" />'.
1.83 albertel 827: '</a>'.
828: '<a href="/adm/grades?symb='.&escape($symb).
829: # '&command=gradingmenu" target="LONcatInfo">'.
830: '&command=gradingmenu">'.
1.100 bisitz 831: '<img src="/res/adm/pages/pgrd.png" class="LC_icon"'.
832: ' alt="'.&mt('Content Grades').'"'.
833: ' title="'.&mt('Content Grades').'" />'.
1.83 albertel 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: '" >'.
1.100 bisitz 841: '<img src="/adm/lonMisc/pprm_button.png" class="LC_icon"'.
842: ' alt="'.&mt('Content Settings').'"'.
843: ' title="'.&mt('Content Settings').'" />'.
1.83 albertel 844: '</a>';
845: }
846: }
1.102 raeburn 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: }
1.83 albertel 867: return $metainfo;
868: }
869:
1.111 raeburn 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:
1.1 www 899: 1;
900: __END__
901:
902:
1.89 jms 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
1.1 www 952:
1.89 jms 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
1.1 www 1002:
1003:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>