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