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