Annotation of rat/lonpage.pm, revision 1.111.2.13.2.5
1.1 www 1: # The LearningOnline Network with CAPA
2: # Page Handler
3: #
1.111.2.13.2. (raeburn 4:): # $Id: lonpage.pm,v 1.111.2.13.2.4 2022/10/05 22:59:06 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.111.2.13.2. (raeburn 44:): use Apache::lonparmset;
1.111.2.6 raeburn 45: use Apache::lonenc();
1.6 www 46: use HTML::TokeParser;
1.111.2.11 raeburn 47: use HTML::Entities();
1.1 www 48: use GDBM_File;
1.39 www 49: use Apache::lonsequence;
1.75 www 50: use lib '/home/httpd/lib/perl/';
51: use LONCAPA;
52:
1.1 www 53:
1.2 www 54: # -------------------------------------------------------------- Module Globals
55: my %hash;
56: my @rows;
1.6 www 57:
58: # ------------------------------------------------------------------ Euclid gcd
59:
60: sub euclid {
61: my ($e,$f)=@_;
62: my $a; my $b; my $r;
63: if ($e>$f) { $b=$e; $r=$f; } else { $r=$e; $b=$f; }
64: while ($r!=0) {
65: $a=$b; $b=$r;
66: $r=$a%$b;
67: }
68: return $b;
69: }
1.2 www 70:
71: # ------------------------------------------------------------ Build page table
72:
73: sub tracetable {
74: my ($sofar,$rid,$beenhere)=@_;
75: my $further=$sofar;
1.57 raeburn 76: my $randomout=0;
1.70 albertel 77: unless ($env{'request.role.adv'}) {
1.57 raeburn 78: $randomout = $hash{'randomout_'.$rid};
79: }
1.2 www 80: unless ($beenhere=~/\&$rid\&/) {
1.57 raeburn 81: $beenhere.=$rid.'&';
82: unless ($randomout) {
83: if (defined($hash{'is_map_'.$rid})) {
84: if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
85: (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
86: my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
87: $sofar=
88: &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
1.87 albertel 89: '&'.$frid.$beenhere);
1.57 raeburn 90: $sofar++;
91: if ($hash{'src_'.$frid}) {
92: my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});
93: if (($brepriv eq '2') || ($brepriv eq 'F')) {
94: if (defined($rows[$sofar])) {
95: $rows[$sofar].='&'.$frid;
96: } else {
97: $rows[$sofar]=$frid;
98: }
99: }
100: }
101: }
102: } else {
103: $sofar++;
104: if ($hash{'src_'.$rid}) {
1.111.2.13.2. (raeburn 105:): my ($mapid,$resid)=split(/\./,$rid);
106:): my $symb = &Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$hash{'src_'.$rid});
107:): my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid},$symb);
1.57 raeburn 108: if (($brepriv eq '2') || ($brepriv eq 'F')) {
109: if (defined($rows[$sofar])) {
110: $rows[$sofar].='&'.$rid;
111: } else {
112: $rows[$sofar]=$rid;
113: }
114: }
115: }
116: }
117: }
118:
119: if (defined($hash{'to_'.$rid})) {
120: my $mincond=1;
121: my $next='';
122: foreach (split(/\,/,$hash{'to_'.$rid})) {
123: my $thiscond=
1.11 www 124: &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
1.57 raeburn 125: if ($thiscond>=$mincond) {
126: if ($next) {
127: $next.=','.$_.':'.$thiscond;
128: } else {
129: $next=$_.':'.$thiscond;
130: }
131: if ($thiscond>$mincond) { $mincond=$thiscond; }
132: }
133: }
134: foreach (split(/\,/,$next)) {
135: my ($linkid,$condval)=split(/\:/,$_);
136: if ($condval>=$mincond) {
137: my $now=&tracetable($sofar,$hash{'goesto_'.$linkid},$beenhere);
138: if ($now>$further) { $further=$now; }
139: }
140: }
141: }
1.2 www 142: }
143: return $further;
144: }
145:
1.1 www 146: # ================================================================ Main Handler
147:
148: sub handler {
149: my $r=shift;
150:
1.3 www 151: # ------------------------------------------- Set document type for header only
1.1 www 152:
1.3 www 153: if ($r->header_only) {
1.70 albertel 154: if ($env{'browser.mathml'}) {
1.53 www 155: &Apache::loncommon::content_type($r,'text/xml');
1.3 www 156: } else {
1.53 www 157: &Apache::loncommon::content_type($r,'text/html');
1.3 www 158: }
159: $r->send_http_header;
160: return OK;
161: }
1.43 sakharuk 162:
1.39 www 163: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
164: ['forceselect','launch']);
1.43 sakharuk 165: my $number_of_columns = 1;
1.37 sakharuk 166: my $requrl=$r->uri;
1.70 albertel 167: my $target = $env{'form.grade_target'};
1.94 raeburn 168:
169: # Short term solution: define target as 'tex_answer' when retrieving answers
170: # for resources in a .page when generating printouts.
171: # A better long-term fix would be to modify the way problem rendering, and
172: # answer rendering are retrieved for individual resources when printing a .page,
173: # so rendered problem and answer are sequential for individual resources in
174: # the .page
175: #
176: if ($target eq 'answer') {
177: if ($env{'form.answer_output_mode'} eq 'tex') {
178: $target = 'tex_answer';
179: }
180: }
1.55 www 181: # &Apache::lonnet::logthis("Got a target of $target");
1.54 albertel 182: if ($target eq 'meta') {
183: &Apache::loncommon::content_type($r,'text/html');
184: $r->send_http_header;
185: return OK;
186: }
1.1 www 187: # ----------------------------------------------------------------- Tie db file
1.70 albertel 188: if (($env{'request.course.fn'}) && (!$env{'form.forceselect'})) {
189: my $fn=$env{'request.course.fn'};
1.1 www 190: if (-e "$fn.db") {
1.111.2.3 raeburn 191: my %buttonshide;
1.111.2.7 raeburn 192: my $hostname = $r->hostname();
1.111.2.11 raeburn 193: my $lonhost = $r->dir_config('lonHostID');
194: my $ip = &Apache::lonnet::get_host_ip($lonhost);
1.44 albertel 195: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) {
1.1 www 196: # ------------------------------------------------------------------- Hash tied
197: my $firstres=$hash{'map_start_'.$requrl};
198: my $lastres=$hash{'map_finish_'.$requrl};
199: if (($firstres) && ($lastres)) {
1.111 raeburn 200: # ------------------------------------------------------------- Countdown Timer
201: my $now = time;
1.111.2.13.2. (raeburn 202:): my ($pagefirstaccess,%hastimeleft,%countdowndisp,%donebutton,
203:): %donebtnextra,%buttonbytime,$donetime,$symbtosetdone);
1.111 raeburn 204: my ($pagesymb,$courseid,$domain,$name)=&Apache::lonnet::whichuser();
1.111.2.13.2. (raeburn 205:): unless ($pagesymb) {
206:): $pagesymb=&Apache::lonnet::symbread($requrl);
207:): }
1.111.2.2 raeburn 208: if ($pagesymb && ($courseid ne '') && ($domain ne '') && ($name ne '')) {
1.111 raeburn 209: my %times=&Apache::lonnet::get('firstaccesstimes',
210: [$courseid."\0".$pagesymb],
211: $domain,$name);
212: if ($times{$courseid."\0".$pagesymb} =~ /^\d+$/) {
213: $pagefirstaccess = $times{$courseid."\0".$pagesymb};
1.111.2.13.2. (raeburn 214:): if ($pagefirstaccess && $env{'form.LC_interval_done'} eq 'true') {
215:): $donetime = $now - $pagefirstaccess;
216:): }
1.111 raeburn 217: }
218: }
1.111.2.13.2. (raeburn 219:):
1.1 www 220: # ----------------------------------------------------------------- Render page
221:
1.3 www 222: @rows=();
1.2 www 223:
1.45 www 224: &tracetable(0,$firstres,'&');
1.2 www 225:
1.9 www 226: # ------------------------------------------------------------ Add to symb list
227:
1.2 www 228: my $i;
1.9 www 229: my %symbhash=();
230: for ($i=0;$i<=$#rows;$i++) {
231: if ($rows[$i]) {
232: my @colcont=split(/\&/,$rows[$i]);
1.73 albertel 233: foreach my $rid (@colcont) {
234: my ($mapid,$resid)=split(/\./,$rid);
235: $symbhash{$hash{'src_'.$rid}}=
236: [$hash{'src_'.$rid},$resid];
1.111.2.13.2. (raeburn 237:): if (($donetime) && ($symbtosetdone eq '')) {
238:): my $src = $hash{'src_'.$rid};
239:): if ($hash{'encrypted_'.$rid}) {
240:): $src=&Apache::lonenc::encrypted($src);
241:): }
242:): my ($mapid,$resid)=split(/\./,$rid);
243:): my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$src);
244:): if ($src =~ /$LONCAPA::assess_re/) {
245:): my @interval=&Apache::lonnet::EXT("resource.0.interval",$symb);
246:): if (@interval > 1) {
247:): if (($interval[1] eq 'map') && ($pagefirstaccess)) {
248:): my ($timelimit) = ($interval[0] =~ /^(\d+)/);
249:): if ($timelimit) {
250:): if ($pagefirstaccess + $timelimit > $now) {
251:): $symbtosetdone = $symb;
252:): }
253:): }
254:): }
255:): }
256:): }
257:): }
1.30 harris41 258: }
1.9 www 259: }
260: }
261: &Apache::lonnet::symblist($requrl,%symbhash);
262:
263: # ------------------------------------------------------------------ Page parms
264:
1.4 www 265: my $j;
1.6 www 266: my $lcm=1;
267: my $contents=0;
1.7 www 268: my $nforms=0;
1.96 raeburn 269: my $nuploads=0;
1.110 raeburn 270: my $ntimers=0;
1.96 raeburn 271: my %turninpaths;
272: my %multiresps;
273: my $turninparent;
1.6 www 274:
275: my %ssibody=();
276: my %ssibgcolor=();
277: my %ssitext=();
278: my %ssilink=();
279: my %ssivlink=();
280: my %ssialink=();
1.111.2.13 raeburn 281: my %cssrefs=();
282: my %httpref=();
1.14 www 283:
1.6 www 284: my %cellemb=();
1.99 raeburn 285: my %cellexternal=();
1.3 www 286:
1.7 www 287: my $allscript='';
288: my $allmeta='';
289:
290: my $isxml=0;
291: my $xmlheader='';
292: my $xmlbody='';
293:
1.111.2.13.2. (raeburn 294:): # ---------------------------------------------------------- Handle Done button
295:):
296:): # Set the event timer to zero if the "done button" was clicked.
297:): if ($donetime && $symbtosetdone) {
298:): &Apache::lonparmset::storeparm_by_symb_inner($symbtosetdone,'0_interval',
299:): 2,$donetime,'date_interval',
300:): $name,$domain);
301:): undef($env{'form.LC_interval_done'});
302:): }
303:):
1.3 www 304: # --------------------------------------------- Get SSI output, post parameters
305:
1.2 www 306: for ($i=0;$i<=$#rows;$i++) {
1.4 www 307: if ($rows[$i]) {
1.6 www 308: $contents++;
1.3 www 309: my @colcont=split(/\&/,$rows[$i]);
1.6 www 310: $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
1.30 harris41 311: foreach (@colcont) {
1.3 www 312: my $src=$hash{'src_'.$_};
1.111.2.3 raeburn 313: my $plainsrc = $src;
1.111.2.11 raeburn 314: my $anchor;
315: if ($hash{'ext_'.$_} eq 'true:') {
316: $cellexternal{$_}=($hash{'ext_'.$_} eq 'true:');
317: $src =~ s{^/ext/}{http://};
318: $src =~ s{http://https://}{https://};
319: if ($src =~ /(\#[^#]+)$/) {
320: $anchor = $1;
321: $src =~ s/\#[^#]+$//;
322: }
323: }
324: my $unencsrc = $src;
1.99 raeburn 325: my ($extension)=($src=~/\.(\w+)$/);
1.61 albertel 326: if ($hash{'encrypted_'.$_}) {
327: $src=&Apache::lonenc::encrypted($src);
328: }
1.111.2.3 raeburn 329: my ($mapid,$resid)=split(/\./,$_);
1.111.2.11 raeburn 330: my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$plainsrc);
1.111.2.3 raeburn 331: unless ($env{'request.role.adv'}) {
332: $buttonshide{$symb} = &Apache::lonnet::EXT("resource.0.buttonshide",$symb);
333: }
1.61 albertel 334: $cellemb{$_}=
335: &Apache::loncommon::fileembstyle($extension);
1.99 raeburn 336: if ($cellexternal{$_}) {
1.111.2.11 raeburn 337: if (($target eq 'tex') || ($target eq 'tex_answer')) {
338: my $shown = $src.$anchor;
339: if (($hash{'encrypted_'.$_}) && (!$env{'request.role.adv'})) {
340: $shown = &mt('URL not shown (encrypted)');
341: }
342: my $title=&Apache::lonnet::gettitle($symb);
343: $title = &Apache::lonxml::latex_special_symbols($title);
344: $shown = &Apache::lonxml::latex_special_symbols($shown);
345: $ssibody{$_} = ' \strut \\\\ \textit{'.$title.'} \strut \\\\ '.$shown.'\\\\';
346: } else {
347: my $showsrc = $src;
348: my ($is_pdf,$title,$linktext);
349: if ($unencsrc =~ /\.pdf$/i) {
350: $is_pdf = 1;
351: }
352: if (($hash{'encrypted_'.$_}) && ($symb)) {
353: $title=&Apache::lonnet::gettitle(&Apache::lonenc::encrypted($symb));
354: } else {
355: $title=&Apache::lonnet::gettitle($symb);
356: }
357: if ($env{'browser.mobile'}) {
358: if ($is_pdf) {
359: $linktext = &mt('Link to PDF (for mobile devices)');
360: $ssibody{$_} = &create_extlink($unencsrc,$anchor,$title,$linktext);
361: } else {
362: $linktext = &mt('Link to resource');
363: $ssibody{$_} = &create_extlink($unencsrc,$anchor,$title,$linktext);
364: }
365: } else {
366: my $absolute = $env{'request.use_absolute'};
367: my $uselink = &Apache::loncommon::is_nonframeable($unencsrc,$absolute,$hostname,$ip);
368: if (($uselink) || (($ENV{'SERVER_PORT'} == 443) && ($unencsrc =~ m{^http://}))) {
369: $linktext = &mt('Link to resource');
370: $ssibody{$_} = &create_extlink($unencsrc,$anchor,$title,$linktext);
371: } else {
372: if (($hash{'encrypted_'.$_}) && ($symb) && (!$env{'request.role.adv'})) {
373: $showsrc .= '?symb='.&Apache::lonenc::encrypted($symb);
374: } elsif ($anchor) {
1.111.2.12 raeburn 375: $showsrc .= $anchor;
1.111.2.11 raeburn 376: }
377: $ssibody{$_} = <<ENDEXT;
378: <iframe src="$showsrc" width="100%" height="300px">No iframe support!</iframe>
1.99 raeburn 379: ENDEXT
1.111.2.11 raeburn 380: }
381: }
1.99 raeburn 382: }
383: } elsif ($cellemb{$_} eq 'ssi') {
1.3 www 384: # --------------------------------------------------------- This is an SSI cell
1.111.2.5 raeburn 385: my $prefix='p_'.$_.'_';
386: my $idprefix='p_'.join('_',($mapid,$resid,''));
1.64 albertel 387: my %posthash=('request.prefix' => $prefix,
1.71 albertel 388: 'LONCAPA_INTERNAL_no_discussion' => 'true',
1.64 albertel 389: 'symb' => $symb);
1.94 raeburn 390: if (($env{'form.grade_target'} eq 'tex') ||
391: ($env{'form.answer_output_mode'} eq 'tex')) {
1.70 albertel 392: $posthash{'grade_target'}=$env{'form.grade_target'};
393: $posthash{'textwidth'}=$env{'form.textwidth'};
394: $posthash{'problem_split'}=$env{'form.problem_split'};
395: $posthash{'latex_type'}=$env{'form.latex_type'};
396: $posthash{'rndseed'}=$env{'form.rndseed'};
1.94 raeburn 397: $posthash{'answer_output_mode'} = $env{'form.answer_output_mode'};
1.56 sakharuk 398: }
1.111.2.8 raeburn 399: my $submitted=$env{'form.all_submit_pressed'};
1.72 albertel 400: if (!$submitted) {
401: foreach my $key (keys(%env)) {
1.111.2.8 raeburn 402: if ($key=~/^\Qform.$prefix\Esubmit_(.+)_pressed$/) {
403: if ($env{$key}) {
404: $submitted=1;
405: last;
406: }
1.72 albertel 407: }
1.111.2.8 raeburn 408: }
1.72 albertel 409: }
410: if ($submitted) {
411: foreach my $key (keys(%env)) {
1.111.2.8 raeburn 412: if ($key=~/^\Qform.$prefix\E/) {
1.72 albertel 413: my $name=$key;
1.111.2.8 raeburn 414: $name=~s/^\Qform.$prefix\E//;
1.72 albertel 415: $posthash{$name}=$env{$key};
1.111.2.8 raeburn 416: }
1.72 albertel 417: }
1.111.2.8 raeburn 418: if ($env{'form.all_submit_pressed'}) {
1.72 albertel 419: $posthash{'all_submit'}='yes';
420: }
1.111.2.9 raeburn 421: } elsif ($env{'form.'.$prefix.'markaccess'} eq 'yes') {
422: $posthash{'markaccess'} = $env{'form.'.$prefix.'markaccess'};
423: }
1.111.2.4 raeburn 424: if ($env{'environment.remote'} eq 'on') {
425: $posthash{'inhibitmenu'} = 'yes';
426: }
1.5 www 427: my $output=Apache::lonnet::ssi($src,%posthash);
1.77 albertel 428: $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+?// END LON-CAPA Internal\s*(-->)?\s||gs;
1.94 raeburn 429: if (($target eq 'tex') || ($target eq 'tex_answer')) {
1.111.2.1 raeburn 430: $output =~ s/^([^&]+)\\begin\{document}//;
431: $output =~ s/\\end\{document}//;
1.92 foxr 432: # $output = '\parbox{\minipagewidth}{ '.$output.' }';
1.46 sakharuk 433: #some additional cleanup necessary for LateX (due to limitations of table environment
434: $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
435: }
1.107 raeburn 436: my $matheditor;
437: if ($output =~ /\Qjavascript:LC_mathedit_HWVAL_\E/) {
438: $matheditor = 'dragmath';
439: } elsif ($output =~ /LCmathField/) {
440: $matheditor = 'lcmath';
441: }
1.6 www 442: my $parser=HTML::TokeParser->new(\$output);
443: my $token;
1.12 www 444: my $thisdir=$src;
1.6 www 445: my $bodydef=0;
1.7 www 446: my $thisxml=0;
1.12 www 447: my @rlinks=();
1.111.2.13 raeburn 448: my @css_hrefs=();
1.7 www 449: if ($output=~/\?xml/) {
450: $isxml=1;
451: $thisxml=1;
452: $output=~
453: /((?:\<(?:\?xml|\!DOC|html)[^\>]*(?:\>|\>\]\>)\s*)+)\<body[^\>]*\>/si;
454: $xmlheader=$1;
455: }
1.12 www 456: while ($token=$parser->get_token) {
457: if ($token->[0] eq 'S') {
458: if ($token->[1] eq 'a') {
459: if ($token->[2]->{'href'}) {
460: $rlinks[$#rlinks+1]=
461: $token->[2]->{'href'};
462: }
463: } elsif ($token->[1] eq 'img') {
464: $rlinks[$#rlinks+1]=
465: $token->[2]->{'src'};
466: } elsif ($token->[1] eq 'embed') {
467: $rlinks[$#rlinks+1]=
468: $token->[2]->{'src'};
469: } elsif ($token->[1] eq 'base') {
470: $thisdir=$token->[2]->{'href'};
471: } elsif ($token->[1] eq 'body') {
1.7 www 472: $bodydef=1;
473: $ssibgcolor{$_}=$token->[2]->{'bgcolor'};
474: $ssitext{$_}=$token->[2]->{'text'};
475: $ssilink{$_}=$token->[2]->{'link'};
476: $ssivlink{$_}=$token->[2]->{'vlink'};
477: $ssialink{$_}=$token->[2]->{'alink'};
478: if ($thisxml) {
479: $xmlbody=$token->[4];
480: }
1.12 www 481: } elsif ($token->[1] eq 'meta') {
1.28 albertel 482: if ($token->[4] !~ m:/>$:) {
1.7 www 483: $allmeta.="\n".$token->[4].'</meta>';
1.28 albertel 484: } else {
485: $allmeta.="\n".$token->[4];
486: }
1.12 www 487: } elsif (($token->[1] eq 'script') &&
488: ($bodydef==0)) {
1.7 www 489: $allscript.="\n\n"
490: .$parser->get_text('/script');
1.111.2.13 raeburn 491: } elsif (($token->[1] eq 'link') &&
492: ($bodydef==0)) {
493: if (($token->[2]->{'href'} !~ m{^/adm/}) &&
494: ($token->[2]->{'rel'} eq 'stylesheet')) {
495: $css_hrefs[$#css_hrefs+1]=
496: $token->[2]->{'href'};
497:
498: }
1.6 www 499: }
1.12 www 500: }
501: }
1.6 www 502: if ($output=~/\<body[^\>]*\>(.*)/si) {
503: $output=$1;
504: }
505: $output=~s/\<\/body\>.*//si;
1.7 www 506: if ($output=~/\<form/si) {
1.110 raeburn 507: my $hastimer;
1.7 www 508: $nforms++;
509: $output=~s/\<form[^\>]*\>//gsi;
510: $output=~s/\<\/form[^\>]*\>//gsi;
1.96 raeburn 511: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*HWFILE/) {
512: $nuploads++;
513: }
1.110 raeburn 514: if ($output=~/\<input[^\>]+name\s*=\s*[\'\"]*accessbutton/) {
515: $ntimers++;
516: $hastimer = 1;
517: }
1.17 www 518: $output=~
1.80 albertel 519: s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
1.101 raeburn 520: $output=~
521: s/\<((?:input|select|button|textarea)[^\>]+)id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 id="$idprefix$2" $3\>/gsi;
1.111.2.5 raeburn 522: $output=~
523: s/(\Qthis.form.elements['\E)(HW(?:VAL|CHK)_[^']+\'\]\.(?:value=\'|checked))/$1$prefix$2/gsi;
1.110 raeburn 524: if ($hastimer) {
525: $output=~
526: s/\<(input[^\>]+name=\Q"$prefix\Eaccessbutton"[^\>]+)(?:\Qdocument.markaccess.submit();\E)([^\>]*)\>/\<$1pageTimer(this.form,'$prefix')$2\>/gsi;
527: $output=~ s/\<(input[^\>]+name=\Q"$prefix\Emarkaccess"[^\>]+value=["'])(?:yes)(['"][^\>]*)\>/\<$1$2\>/gsi;
528: }
1.107 raeburn 529: if ($matheditor eq 'dragmath') {
530: $output=~
531: s/(\Qjavascript:LC_mathedit_\E)(HWVAL_)([^'"]+?)(\(['"]*)(\QHWVAL_\E\3['"]\)\;void\(0\)\;)/$1$idprefix$2$3$4$idprefix$5/g;
532: $output=~
533: s/(function\s+LC_mathedit_)(HWVAL_)([^'"]+?)(\s+\(LCtextline\))/$1$idprefix$2$3$4/g;
534: } elsif ($matheditor eq 'lcmath') {
535: $output=~
536: s/(var\s+LCmathField\s+=\s+document\.getElementById\(['"])([^'"]+?)(['"]\)\;)/$1$idprefix$2$3/g;
537: }
1.105 raeburn 538: $output=~
539: 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;
540: $output=~
541: s/(\Q<td class="LC_status_\E)(\Qsubmit_\E)([^\"]*)(\s*[^\"]*"\>)/$1$idprefix$2$3$4/g;
1.96 raeburn 542: if ($nuploads) {
543: ($turninpaths{$prefix},$multiresps{$prefix}) =
544: &Apache::loncommon::get_turnedin_filepath($symb,$env{'user.name'},$env{'user.domain'});
545: if ($turninparent eq '') {
546: $turninparent = $turninpaths{$prefix};
547: $turninparent =~ s{(/[^/]+)$}{};
548: }
549: }
1.95 raeburn 550: $output=~
551: s/\<((?:input|select)[^\>]+\Qjavascript:setSubmittedPart\E)\(\s*[\'\"]([^\'\"]+)[\'\"]*\s*\)/\<$1('$2','$prefix')/gsi;
1.108 raeburn 552: $output=~
553: s/\<(input[^\>]+\Qonfocus=\"javascript:disableAutoComplete\E)\(\'([^\']+)\'\)(;\")/\<$1('$idprefix$2')$3/gsi;
1.111 raeburn 554: unless ($hastimer) {
1.111.2.3 raeburn 555: if ($plainsrc =~ /$LONCAPA::assess_re/) {
1.111 raeburn 556: %Apache::lonhomework::history =
557: &Apache::lonnet::restore($symb,$courseid,$domain,$name);
558: my $type = 'problem';
1.111.2.3 raeburn 559: if ($extension eq 'task') {
1.111 raeburn 560: $type = 'Task';
561: }
562: my ($status,$accessmsg,$slot_name,$slot) =
563: &Apache::lonhomework::check_slot_access('0',$type,$symb);
564: undef(%Apache::lonhomework::history);
565: my $probstatus = &Apache::lonnet::EXT("resource.0.problemstatus",$symb);
566: if (($status eq 'CAN_ANSWER') || (($status eq 'CANNOT_ANSWER') &&
1.111.2.13.2. (raeburn 567:): (($probstatus eq 'no') || ($probstatus eq 'no_feedback_ever'))) ||
568:): (($status eq 'NOT_YET_VIEWED') && ($posthash{'markaccess'} eq 'yes'))) {
1.111 raeburn 569: my ($slothastime,$timerhastime);
570: if ($slot_name ne '') {
571: if (ref($slot) eq 'HASH') {
572: if (($slot->{'starttime'} < $now) &&
573: ($slot->{'endtime'} > $now)) {
574: $slothastime = $now - $slot->{'endtime'};
575: }
576: }
577: }
578: my $duedate = &Apache::lonnet::EXT("resource.0.duedate",$symb);
579: my @interval=&Apache::lonnet::EXT("resource.0.interval",$symb);
580: if (@interval > 1) {
1.111.2.13.2. (raeburn 581:): my $first_access;
582:): if ($interval[1] eq 'map') {
583:): my $ignorecache;
584:): if ($env{'form.'.$prefix.'markaccess'} eq 'yes') {
585:): $ignorecache = 1;
586:): }
587:): $first_access=&Apache::lonnet::get_first_access($interval[1],undef,$pagesymb,$ignorecache);
588:): if (($first_access) && (!$pagefirstaccess)) {
589:): $pagefirstaccess = $first_access;
590:): }
591:): } else {
592:): $first_access=&Apache::lonnet::get_first_access($interval[1],$symb);
593:): }
1.111 raeburn 594: if ($first_access > 0) {
1.111.2.13.2. (raeburn 595:): my ($timelimit) = ($interval[0] =~ /^(\d+)/);
596:): if ($timelimit) {
597:): my $timeremains = $timelimit + $first_access - $now;
598:): if ($timeremains > 0) {
599:): $timerhastime = $timeremains;
600:): }
1.111 raeburn 601: }
602: }
603: }
604: if (($duedate && $duedate > $now) ||
605: (!$duedate && $timerhastime > 0) ||
606: ($slot_name ne '' && $slothastime)) {
607: if ((@interval > 1 && $timerhastime) ||
608: ($type eq 'Task' && $slothastime)) {
609: $countdowndisp{$symb} = 'inline';
610: if ((@interval > 1) && ($timerhastime)) {
611: $hastimeleft{$symb} = $timerhastime;
1.111.2.13.2. (raeburn 612:): if ($pagefirstaccess) {
613:): my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
614:): ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
615:): if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
616:): $usesdone = 'done';
617:): $donebuttontext = $1;
618:): (undef,$proctor,$secret) = split(/_/,$2);
619:): } elsif ($donesuffix =~ /^done(|_.+)$/) {
620:): $donebuttontext = &mt('Done');
621:): ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
622:): }
623:): if ($usesdone eq 'done') {
624:): $donebutton{$symb} = $timelimit;
625:): push(@{$buttonbytime{$timelimit}},$symb);
626:): $donebtnextra{$symb} = {
627:): text => $donebuttontext,
628:): proctor => $proctor,
629:): secret => $secret,
630:): type => $interval[1],
631:): };
632:): }
633:): }
1.111 raeburn 634: } else {
635: $hastimeleft{$symb} = $slothastime;
636: }
637: } else {
638: $hastimeleft{$symb} = $duedate - $now;
639: $countdowndisp{$symb} = 'none';
640: }
1.111.2.13.2. (raeburn 641:): unless ($donebutton{$symb}) {
642:): $donebutton{$symb} = 0;
643:): }
1.111 raeburn 644: }
645: }
646: }
647: }
1.7 www 648: }
1.12 www 649: $thisdir=~s/\/[^\/]*$//;
1.30 harris41 650: foreach (@rlinks) {
1.91 raeburn 651: unless (($_=~/^https?\:\/\//i) ||
1.31 albertel 652: ($_=~/^\//) ||
653: ($_=~/^javascript:/i) ||
654: ($_=~/^mailto:/i) ||
655: ($_=~/^\#/)) {
1.12 www 656: my $newlocation=
657: &Apache::lonnet::hreflocation($thisdir,$_);
658: $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
659: }
1.30 harris41 660: }
1.111.2.13 raeburn 661: foreach my $css_href (@css_hrefs) {
662: next if ($css_href eq '');
663: unless ($css_href =~ m{https?://}) {
664: my $proburl = &Apache::lonnet::clutter($plainsrc);
665: unless ($css_href =~ m{^/}) {
666: my $probdir = $proburl;
667: $probdir=~s/\/[^\/]*$//;
668: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
669: }
670: if ($css_href =~ m{^/(res|uploaded)/}) {
671: unless (($env{'httpref.'.$css_href}) ||
672: ($httpref{'httpref.'.$css_href}) ||
673: (&Apache::lonnet::is_on_map($css_href))) {
674: if ($env{'httpref.'.$proburl}) {
675: $proburl = $env{'httpref.'.$proburl};
676: }
677: $httpref{'httpref.'.$css_href} = $proburl;
678: }
679: }
680: }
681: $cssrefs{$css_href} = 1;
682: }
1.24 www 683: # -------------------------------------------------- Deal with Applet codebases
684: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
1.5 www 685: $ssibody{$_}=$output;
1.3 www 686: # ---------------------------------------------------------------- End SSI cell
687: }
1.30 harris41 688: }
1.111.2.13.2. (raeburn 689:): }
1.2 www 690: }
1.6 www 691: unless ($contents) {
1.53 www 692: &Apache::loncommon::content_type($r,'text/html');
1.3 www 693: $r->send_http_header;
1.74 albertel 694: $r->print(&Apache::loncommon::start_page(undef,undef,
1.111.2.3 raeburn 695: {'force_register' => 1}));
1.59 raeburn 696: $r->print(&mt('This page is either empty or it only contains resources that are currently hidden').'. ');
1.74 albertel 697: $r->print('<br /><br />'.&mt('Please use the LON-CAPA navigation arrows to move to another item in the course').
698: &Apache::loncommon::end_page());
1.3 www 699: } else {
700: # ------------------------------------------------------------------ Build page
1.7 www 701:
702: # ---------------------------------------------------------------- Send headers
1.94 raeburn 703: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 704: if ($isxml) {
1.53 www 705: &Apache::loncommon::content_type($r,'text/xml');
1.37 sakharuk 706: } else {
1.53 www 707: &Apache::loncommon::content_type($r,'text/html');
1.37 sakharuk 708: }
1.74 albertel 709: $r->send_http_header;
1.7 www 710: # ------------------------------------------------------------------------ Head
1.37 sakharuk 711: if ($allscript) {
1.85 albertel 712: $allscript =
713: "\n".'<script type="text/javascript">'."\n".
714: $allscript.
715: "\n</script>\n";
1.37 sakharuk 716: }
1.96 raeburn 717: if (($nforms) && ($nuploads)) {
1.111.2.8 raeburn 718: $allscript .= &Apache::lonhtmlcommon::file_submissionchk_js(\%turninpaths,\%multiresps).
719: '<script type="text/javascript" '.
720: 'src="/res/adm/includes/file_upload.js"></script>';
1.96 raeburn 721: }
1.101 raeburn 722: if (($nforms) && (&Apache::lonhtmlcommon::htmlareabrowser())) {
723: my %textarea_args = (
724: dragmath => 'math',
725: );
726: $allscript .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
727: }
1.110 raeburn 728: if ($ntimers) {
729: $allscript .= '<script type="text/javascript">'."\n".
730: '// <![CDATA['."\n".
731: 'function pageTimer(form,prefix) {'."\n".
732: " form.elements[prefix+'markaccess'].value = 'yes';\n".
733: " form.submit();\n".
734: '}'."\n".
735: '// ]]>'.
736: "\n</script>\n";
737: }
1.111.2.11 raeburn 738: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1.111 raeburn 739: if (keys(%hastimeleft)) {
740: my (%uniquetimes,%uniquedisplays);
741: foreach my $item (values(%hastimeleft)) {
742: if (exists($uniquetimes{$item})) {
743: $uniquetimes{$item} ++;
744: } else {
745: $uniquetimes{$item} = 1;
746: }
747: }
1.111.2.13.2. (raeburn 748:): if (scalar(keys(%uniquetimes)) == 1) {
749:): my (%uniquedisplays,%uniquedones,$currdisp,$donebuttontime,
750:): $donebuttonextras);
1.111 raeburn 751: if (keys(%countdowndisp)) {
752: foreach my $item (values(%countdowndisp)) {
753: if (exists($uniquedisplays{$item})) {
754: $uniquedisplays{$item} ++;
755: } else {
756: $uniquedisplays{$item} = 1;
757: }
758: }
759: my @countdowndisplay = keys(%uniquedisplays);
760: if (scalar(@countdowndisplay) == 1) {
761: $currdisp = $countdowndisplay[0];
762: }
763: }
1.111.2.13.2. (raeburn 764:): if (keys(%donebutton)) {
765:): foreach my $item (values(%donebutton)) {
766:): if (exists($uniquedones{$item})) {
767:): $uniquedones{$item} ++;
768:): } else {
769:): $uniquedones{$item} = 1;
770:): }
771:): }
772:): my @donebuttons = sort { $ <=> $b } (keys(%uniquedones));
773:): if (scalar(@donebuttons) == 1) {
774:): if ($donebuttons[0]) {
775:): $donebuttontime = $donebuttons[0];
776:): if (ref($buttonbytime{$donebuttontime}) eq 'ARRAY') {
777:): $donebuttonextras = $donebtnextra{$buttonbytime{$donebuttontime}->[0]};
778:): }
779:): }
780:): }
781:): }
782:): &add_countdown_timer($currdisp,$donebuttontime,$donebuttonextras);
1.111 raeburn 783: }
784: }
1.111.2.3 raeburn 785: my $pagebuttonshide;
786: if (keys(%buttonshide)) {
787: my %uniquebuttonhide;
788: foreach my $item (values(%buttonshide)) {
789: if (exists($uniquebuttonhide{$item})) {
790: $uniquebuttonhide{$item} ++;
791: } else {
792: $uniquebuttonhide{$item} = 1;
793: }
794: }
795: if (keys(%uniquebuttonhide) == 1) {
796: if (lc((keys(%uniquebuttonhide))[0]) eq 'yes') {
797: $pagebuttonshide = 'yes';
798: }
799: }
800: }
1.111.2.13 raeburn 801: if (keys(%cssrefs)) {
802: my $links;
803: if (keys(%cssrefs)) {
804: foreach my $css_href (keys(%cssrefs)) {
805: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
806: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
807: }
808: }
809: if ($links) {
810: if (keys(%httpref)) {
811: &Apache::lonnet::appenv(\%httpref);
812: }
813: $allscript .= "\n$links";
814: }
815: }
1.7 www 816: # ------------------------------------------------------------------ Start body
1.85 albertel 817: $r->print(&Apache::loncommon::start_page(undef,$allscript,
1.74 albertel 818: {'force_register' => 1,
1.111.2.3 raeburn 819: 'bgcolor' => '#ffffff',
820: 'hide_buttons' => $pagebuttonshide}));
1.7 www 821: # ------------------------------------------------------------------ Start form
1.37 sakharuk 822: if ($nforms) {
1.96 raeburn 823: my $fmtag = '<form name="lonhomework" method="post" enctype="multipart/form-data"';
824: if ($nuploads) {
825: my $multi;
826: if ($nuploads > 1) {
827: $multi = 1;
828: }
829: $fmtag .= 'onsubmit="return file_submission_check(this,'."'$turninparent','$multi'".');"';
830: }
831: $fmtag .= ' action="'.
1.61 albertel 832: &Apache::lonenc::check_encrypt($requrl)
1.105 raeburn 833: .'" id="LC_page">';
1.96 raeburn 834: $r->print($fmtag);
1.40 sakharuk 835: }
1.94 raeburn 836: } elsif (($target eq 'tex') || ($target eq 'tex_answer')) {
1.92 foxr 837: # I think this is not needed as the header
838: # will be put in for each of the page parts
839: # by the londefdef.pm now that we are opening up
840: # the parts of a page.
841: #$r->print('\documentclass{article}
842: # \newcommand{\keephidden}[1]{}
843: # \usepackage[dvips]{graphicx}
844: # \usepackage{epsfig}
845: # \usepackage{calc}
846: # \usepackage{longtable}
847: # \begin{document}');
1.40 sakharuk 848: }
1.7 www 849: # ----------------------------------------------------------------- Start table
1.94 raeburn 850: if (($target eq 'tex') || ($target eq 'tex_answer')) {
1.92 foxr 851: # # $r->print('\begin{longtable}INSERTTHEHEADOFLONGTABLE\endfirsthead\endhead ');
1.43 sakharuk 852: if ($number_of_columns le $lcm) {$number_of_columns=$lcm;};
1.40 sakharuk 853: } else {
1.63 albertel 854: $r->print('<table width="100%" cols="'.$lcm.'" border="0">');
1.37 sakharuk 855: }
1.78 www 856: # generate rows
1.5 www 857: for ($i=0;$i<=$#rows;$i++) {
858: if ($rows[$i]) {
1.94 raeburn 859: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 860: $r->print("\n<tr>");
861: }
1.4 www 862: my @colcont=split(/\&/,$rows[$i]);
1.6 www 863: my $avespan=$lcm/($#colcont+1);
864: for ($j=0;$j<=$#colcont;$j++) {
865: my $rid=$colcont[$j];
1.111.2.7 raeburn 866: my $metainfo =&get_buttons(\%hash,$rid,\%buttonshide,$hostname).'<br />';
1.94 raeburn 867: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 868: $r->print('<td colspan="'.$avespan.'"');
869: }
1.99 raeburn 870: if (($cellemb{$rid} eq 'ssi') || ($cellexternal{$rid})) {
1.94 raeburn 871: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 872: if ($ssibgcolor{$rid}) {
873: $r->print(' bgcolor="'.
874: $ssibgcolor{$rid}.'"');
875: }
876: $r->print('>'.$metainfo.'<font');
877:
878: if ($ssitext{$rid}) {
879: $r->print(' text="'.$ssitext{$rid}.'"');
880: }
881: if ($ssilink{$rid}) {
882: $r->print(' link="'.$ssilink{$rid}.'"');
883: }
884: if ($ssitext{$rid}) {
885: $r->print(' vlink="'.$ssivlink{$rid}.'"');
886: }
887: if ($ssialink{$rid}) {
888: $r->print(' alink="'.$ssialink{$rid}.'"');
889: }
890: $r->print('>');
891: }
1.111.2.11 raeburn 892: $r->print($ssibody{$rid});
1.94 raeburn 893: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 894: $r->print('</font>');
1.41 www 895: }
1.70 albertel 896: if ($env{'course.'.
897: $env{'request.course.id'}.
1.41 www 898: '.pageseparators'} eq 'yes') {
1.94 raeburn 899: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.41 www 900: $r->print('<hr />');
1.77 albertel 901: }
1.37 sakharuk 902: }
903: } elsif ($cellemb{$rid} eq 'img') {
1.14 www 904: $r->print('>'.$metainfo.'<img src="'.
1.77 albertel 905: $hash{'src_'.$rid}.'" />');
1.13 www 906: } elsif ($cellemb{$rid} eq 'emb') {
1.14 www 907: $r->print('>'.$metainfo.'<embed src="'.
1.13 www 908: $hash{'src_'.$rid}.'"></embed>');
1.60 raeburn 909: } elsif (&Apache::lonnet::declutter($hash{'src_'.$rid}) !~/\.(sequence|page)$/) {
1.104 raeburn 910: $r->print($metainfo.'<b>'.$hash{'title_'.$rid}.'</b><br />');
911: unless ($cellemb{$rid} eq 'wrp') {
912: $r->print(&mt('It is recommended that you use an up-to-date virus scanner before handling this file.'));
913: }
914: $r->print('</p><p><table>'.
915: &Apache::londocs::entryline(0,
916: &mt("Click to download or use your browser's Save Link function"),
917: '/'.&Apache::lonnet::declutter($hash{'src_'.$rid})).
918: '</table></p><br />');
1.13 www 919: }
1.94 raeburn 920: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 921: $r->print('</td>');
1.40 sakharuk 922: } else {
1.92 foxr 923: # for (my $incol=1;$incol<=$avespan;$incol++) {
924: # $r->print(' & ');
925: # }
1.37 sakharuk 926: }
1.4 www 927: }
1.94 raeburn 928: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 929: $r->print('</tr>');
1.40 sakharuk 930: } else {
1.92 foxr 931: # $r->print('REMOVETHEHEADOFLONGTABLE\\\\');
1.37 sakharuk 932: }
1.5 www 933: }
1.4 www 934: }
1.94 raeburn 935: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.37 sakharuk 936: $r->print("\n</table>");
1.40 sakharuk 937: } else {
1.92 foxr 938: # $r->print('\end{longtable}\strut');
1.37 sakharuk 939: }
1.7 www 940: # ---------------------------------------------------------------- Submit, etc.
941: if ($nforms) {
1.106 raeburn 942: my $class;
943: if ($nforms > 1) {
944: $class = ' class="LC_hwk_submit"';
1.110 raeburn 945: if ($ntimers) {
946: $nforms = 1;
947: $class = '';
948: }
1.106 raeburn 949: }
1.7 www 950: $r->print(
1.103 bisitz 951: '<input name="all_submit" value="'.&mt('Submit All').'" type="'.
1.106 raeburn 952: (($nforms>1)?'submit':'hidden').'"'.$class.' id="all_submit" />'.
1.111.2.8 raeburn 953: '<input type="hidden" name="all_submit_pressed" '.
954: 'id="all_submit_pressed" value="" />'.
1.106 raeburn 955: '<div id="msg_all_submit" style="display:none">'.
956: &mt('Processing your submission ...').'</div></form>');
1.7 www 957: }
1.94 raeburn 958: unless (($target eq 'tex') || ($target eq 'tex_answer')) {
1.76 albertel 959: $r->print(&Apache::loncommon::end_page({'discussion'
960: => 1,}));
1.40 sakharuk 961: } else {
962: $r->print('\end{document}'.$number_of_columns);
963: }
1.66 albertel 964: &Apache::lonnet::symblist($requrl,%symbhash);
1.69 albertel 965: my ($map,$id,$url)=&Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
966: &Apache::lonnet::symblist($map,'last_known'=>[$url,$id]);
1.3 www 967: # -------------------------------------------------------------------- End page
968: }
1.1 www 969: # ------------------------------------------------------------- End render page
970: } else {
1.111.2.13.2. (raeburn 971:): if ($hash{'map_type_'.$hash{'map_pc_'.$requrl}} eq 'none') {
972:): &Apache::loncommon::content_type($r,'text/html');
973:): $r->send_http_header;
974:): $r->print(&Apache::loncommon::start_page(undef,undef,
975:): {'force_register' => 1,}));
976:): my $crstype = &Apache::loncommon::course_type();
977:): if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
978:): $r->print('<span class="LC_warning">'.&mt('Missing composite page file.').'</span><br />'.
979:): &mt("You may want to use the $crstype Editor to remove this item."));
980:): } else {
981:): $r->print('<span class="LC_info">'.
982:): &mt('This resource was unavailable when your '.lc($crstype).' session was loaded').'<br />'.
983:): &mt("Please use 'Contents' to list items available in the $crstype.").'</span>');
984:): }
985:): $r->print(&Apache::loncommon::end_page());
986:): } else {
987:): &Apache::loncommon::content_type($r,'text/html');
988:): $r->send_http_header;
989:): &Apache::lonsequence::viewmap($r,$requrl);
990:): }
1.1 www 991: }
992: # ------------------------------------------------------------------ Untie hash
993: unless (untie(%hash)) {
994: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
995: "Could not untie coursemap $fn (browse).</font>");
996: }
997: # -------------------------------------------------------------------- All done
998: return OK;
999: # ----------------------------------------------- Errors, hash could no be tied
1000: }
1001: }
1002: }
1.67 albertel 1003: &Apache::loncommon::content_type($r,'text/html');
1.39 www 1004: $r->send_http_header;
1005: &Apache::lonsequence::viewmap($r,$requrl);
1006: return OK;
1.1 www 1007: }
1008:
1.83 albertel 1009: sub get_buttons {
1.111.2.7 raeburn 1010: my ($hash,$rid,$buttonshide,$hostname) = @_;
1.83 albertel 1011:
1012: my ($mapid,$resid)=split(/\./,$rid);
1013: my $symb=&Apache::lonnet::encode_symb($hash->{'map_id_'.$mapid},
1014: $resid,
1015: $hash->{'src_'.$rid});
1.111.2.13.2. (raeburn 1016:): my ($aname,$shownsymb);
1.111.2.11 raeburn 1017: if (($hash->{'encrypted_'.$rid}) && (!$env{'request.role.adv'})) {
1018: $aname = 'LC_'.$rid;
1.111.2.13.2. (raeburn 1019:): $shownsymb = &Apache::lonenc::encrypted($symb);
1.111.2.11 raeburn 1020: } else {
1.111.2.13.2. (raeburn 1021:): $shownsymb = $symb;
1022:): my $dispsymb = $symb;
1.111.2.12 raeburn 1023: if ($symb =~ /\#([^\#]+)$/) {
1024: my $escan = &escape('#');
1.111.2.13.2. (raeburn 1025:): $dispsymb =~ s/#([^\#]+)$/$escan$1/;
1.111.2.12 raeburn 1026: }
1.111.2.13.2. (raeburn 1027:): $aname = &escape($dispsymb);
1.111.2.11 raeburn 1028: }
1029: my $metainfo = '<a name="'.$aname.'"></a>';
1.109 raeburn 1030: unless ($env{'request.role.adv'}) {
1.111.2.3 raeburn 1031: if ($buttonshide->{$symb} eq 'yes') {
1.111.2.11 raeburn 1032: return $metainfo;
1.109 raeburn 1033: }
1034: }
1.111.2.11 raeburn 1035: my $crs_sec = $env{'request.course.id'} . (($env{'request.course.sec'} ne '')
1036: ? "/$env{'request.course.sec'}"
1037: : '');
1038: my $esrc=&Apache::lonnet::declutter($hash->{'src_'.$rid});
1.83 albertel 1039: if ($hash->{'encrypted_'.$rid}) {
1040: $esrc=&Apache::lonenc::encrypted($esrc);
1041: }
1042: if ($hash->{'src_'.$rid} !~ m-^/uploaded/-
1.111.2.11 raeburn 1043: && $hash->{'src_'.$rid} !~ m{^/ext/}
1.83 albertel 1044: && !$env{'request.enc'}
1045: && ($env{'request.role.adv'}
1046: || !$hash->{'encrypted_'.$rid})) {
1.111.2.11 raeburn 1047: $metainfo .= '<a href="'.$hash->{'src_'.$rid}.'.meta'.'" '.
1048: 'target="LONcatInfo">'.
1.100 bisitz 1049: '<img src="/res/adm/pages/catalog.png" class="LC_icon"'.
1050: ' alt="'.&mt('Show Metadata').'"'.
1051: ' title="'.&mt('Show Metadata').'" />'.
1.83 albertel 1052: '</a>';
1053: }
1.99 raeburn 1054: if (($hash->{'src_'.$rid} !~ m{^/uploaded/}) &&
1.111.2.11 raeburn 1055: ($hash->{'src_'.$rid} !~ m{^/ext/})) {
1.98 raeburn 1056: $metainfo .= '<a href="/adm/evaluate?postdata='.
1057: &escape($esrc).
1058: '" target="LONcatInfo">'.
1.100 bisitz 1059: '<img src="/res/adm/pages/eval.png" class="LC_icon"'.
1060: ' alt="'.&mt('Provide my evaluation of this resource').'"'.
1061: ' title="'.&mt('Provide my evaluation of this resource').'" />'.
1.98 raeburn 1062: '</a>';
1063: }
1.97 www 1064: if (($hash->{'src_'.$rid}=~/$LONCAPA::assess_re/) &&
1.83 albertel 1065: ($hash->{'src_'.$rid} !~ m-^/uploaded/-)) {
1066:
1.111.2.11 raeburn 1067: if ((&Apache::lonnet::allowed('mgr',$crs_sec)) ||
1068: (&Apache::lonnet::allowed('vgr',$crs_sec))) {
1.83 albertel 1069: $metainfo.=
1070: '<a href="/adm/grades?symb='.&escape($symb).
1071: # '&command=submission" target="LONcatInfo">'.
1072: '&command=submission">'.
1.100 bisitz 1073: '<img src="/adm/lonMisc/subm_button.png" class="LC_icon"'.
1074: ' alt="'.&mt('View Submissions for a Student or a Group of Students').'"'.
1075: ' title="'.&mt('View Submissions for a Student or a Group of Students').'" />'.
1.111.2.11 raeburn 1076: '</a>';
1077: }
1078: if (&Apache::lonnet::allowed('mgr',$crs_sec)) {
1079: $metainfo.=
1.83 albertel 1080: '<a href="/adm/grades?symb='.&escape($symb).
1081: # '&command=gradingmenu" target="LONcatInfo">'.
1082: '&command=gradingmenu">'.
1.100 bisitz 1083: '<img src="/res/adm/pages/pgrd.png" class="LC_icon"'.
1084: ' alt="'.&mt('Content Grades').'"'.
1085: ' title="'.&mt('Content Grades').'" />'.
1.83 albertel 1086: '</a>';
1087: }
1.111.2.11 raeburn 1088: if ((&Apache::lonnet::allowed('opa',$crs_sec)) ||
1089: (&Apache::lonnet::allowed('vpa',$crs_sec))) {
1.83 albertel 1090: $metainfo.=
1091: '<a href="/adm/parmset?symb='.&escape($symb).
1092: # '" target="LONcatInfo">'.
1093: '" >'.
1.100 bisitz 1094: '<img src="/adm/lonMisc/pprm_button.png" class="LC_icon"'.
1095: ' alt="'.&mt('Content Settings').'"'.
1096: ' title="'.&mt('Content Settings').'" />'.
1.83 albertel 1097: '</a>';
1098: }
1099: }
1.111.2.6 raeburn 1100: if ($env{'request.course.id'}) {
1.102 raeburn 1101: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1102: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1103: my $file=&Apache::lonnet::declutter($hash->{'src_'.$rid});
1.111.2.6 raeburn 1104: my $editbutton = '';
1105: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1106: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1107: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,$hash->{'src_'.$rid},$symb);
1108: if ($cfile ne '') {
1109: my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
1.111.2.13.2. (raeburn 1110:): $forceedit,1,$symb,$shownsymb,
1111:): undef,&escape($env{'form.title'}),
1.111.2.10 raeburn 1112: $hostname);
1.111.2.6 raeburn 1113: if ($jscall) {
1114: $editbutton = 1;
1115: my $icon = 'pcstr.png';
1116: my $label = &mt('Edit');
1117: my $title = &mt('Edit this resource');
1118: my $pic = '<img src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$icon).'"'.
1119: ' class="LC_icon" alt="'.$label.'" title="'.$title.'" />';
1120: $metainfo .= ' <a href="javascript:'.$jscall.';">'.$pic.'</a>';
1121: }
1122: }
1123: }
1124: if ((!$editbutton) && ($file=~/$LONCAPA::assess_re/)) {
1125: my $url = &Apache::lonnet::clutter($file);
1126: my $viewsrcbutton;
1127: if ((&Apache::lonnet::allowed('cre','/')) &&
1128: (&Apache::lonnet::metadata($url,'sourceavail') eq 'open')) {
1129: $viewsrcbutton = 1;
1.111.2.11 raeburn 1130: } elsif (&Apache::lonnet::allowed('vxc',$crs_sec)) {
1.111.2.6 raeburn 1131: if ($url =~ m{^\Q/res/$cdom/\E($LONCAPA::match_username)/}) {
1132: my $auname = $1;
1133: if (($env{'request.course.adhocsrcaccess'} ne '') &&
1134: (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) {
1135: $viewsrcbutton = 1;
1.111.2.11 raeburn 1136: } elsif ((&Apache::lonnet::metadata($url,'sourceavail') eq 'open') &&
1137: (&Apache::lonnet::allowed('bre',$crs_sec))) {
1138: $viewsrcbutton = 1;
1.111.2.6 raeburn 1139: }
1140: }
1141: }
1142: if ($viewsrcbutton) {
1.102 raeburn 1143: my $icon = 'pcstr.png';
1.111.2.6 raeburn 1144: my $label = &mt('View Source');
1145: my $title = &mt('View source code');
1146: my $jsrid = $rid;
1147: $jsrid =~ s/\./_/g;
1148: my $showurl = &escape(&Apache::lonenc::check_encrypt($url));
1.102 raeburn 1149: my $pic = '<img src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$icon).'"'.
1150: ' class="LC_icon" alt="'.$label.'" title="'.$title.'" />';
1.111.2.6 raeburn 1151: $metainfo .= ' <a href="javascript:open_source_'.$jsrid.'();">'.$pic.'</a>'."\n".
1152: '<script type="text/javascript">'."\n".
1153: "function open_source_$jsrid() {\n".
1154: " sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename=$showurl','LONsource',".
1155: "'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');\n".
1156: "}\n".
1157: "</script>\n";
1.102 raeburn 1158: }
1159: }
1160: }
1.83 albertel 1161: return $metainfo;
1162: }
1163:
1.111 raeburn 1164: sub add_countdown_timer {
1.111.2.13.2. (raeburn 1165:): my ($currdisp,$donebuttontime,$donebuttonextras) = @_;
1166:): my ($collapse,$expand,$alttxt,$title,$donebutton);
1.111 raeburn 1167: if ($currdisp eq 'inline') {
1168: $collapse = '► ';
1169: } else {
1170: $expand = '◄ ';
1171: }
1.111.2.13.2. (raeburn 1172:): if ($donebuttontime) {
1173:): my ($type,$proctor,$donebuttontext);
1174:): if (ref($donebuttonextras) eq 'HASH') {
1175:): $proctor = $donebuttonextras->{'proctor'};
1176:): $donebuttontext = $donebuttonextras->{'text'};
1177:): $type = $donebuttonextras->{'type'};
1178:): } else {
1179:): $donebuttontext = &mt('Done');
1180:): $type = 'map';
1181:): }
1182:): $donebutton =
1183:): &Apache::lonmenu::done_button_js($type,'','',$proctor,$donebuttontext);
1184:): }
1.111 raeburn 1185: unless ($env{'environment.icons'} eq 'iconsonly') {
1186: $alttxt = &mt('Timer');
1187: $title = $alttxt.' ';
1188: }
1189: my $desc = &mt('Countdown to due date/time');
1190: my $output = <<END;
1.111.2.13.2. (raeburn 1191:): $donebutton
1.111 raeburn 1192: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
1193: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
1194: $collapse
1195: </span></a>
1196: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
1197: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
1198: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1199: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
1200: END
1201: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$output);
1202: return;
1203: }
1204:
1.111.2.11 raeburn 1205: sub create_extlink {
1206: my ($url,$anchor,$title,$linktext) = @_;
1207: my $shownlink;
1208: unless ($title eq '') {
1209: $shownlink = '<span style="font-weight:bold;">'.$title.'</span><br />';
1210: }
1211: my $dest = &HTML::Entities::encode($url.$anchor,'&<>"');
1212: $shownlink .= '<a href="'.$dest.'">'.$linktext.'</a>';
1213: return $shownlink;
1214: }
1.111 raeburn 1215:
1.1 www 1216: 1;
1217: __END__
1218:
1219:
1.89 jms 1220: =head1 NAME
1221:
1222: Apache::lonpage - Page Handler
1223:
1224: =head1 SYNOPSIS
1225:
1226: Invoked by /etc/httpd/conf/srm.conf:
1227:
1228: <LocationMatch "^/res/.*\.page$>
1229: SetHandler perl-script
1230: PerlHandler Apache::lonpage
1231: </LocationMatch>
1232:
1233: =head1 INTRODUCTION
1234:
1235: This module renders a .page resource.
1236:
1237: This is part of the LearningOnline Network with CAPA project
1238: described at http://www.lon-capa.org.
1239:
1240: =head1 HANDLER SUBROUTINE
1241:
1242: This routine is called by Apache and mod_perl.
1243:
1244: =over 4
1245:
1246: =item *
1247:
1248: set document type for header only
1249:
1250: =item *
1251:
1252: tie db file
1253:
1254: =item *
1255:
1256: render page
1257:
1258: =item *
1259:
1260: add to symb list
1261:
1262: =item *
1263:
1264: page parms
1265:
1266: =item *
1267:
1268: Get SSI output, post parameters
1.1 www 1269:
1.89 jms 1270: =item *
1271:
1272: SSI cell rendering
1273:
1274: =item *
1275:
1276: Deal with Applet codebases
1277:
1278: =item *
1279:
1280: Build page
1281:
1282: =item *
1283:
1284: send headers
1285:
1286: =item *
1287:
1288: start body
1289:
1290: =item *
1291:
1292: start form
1293:
1294: =item *
1295:
1296: start table
1297:
1298: =item *
1299:
1300: submit element, etc, render page, untie hash
1301:
1302: =back
1303:
1304: =head1 OTHER SUBROUTINES
1305:
1306: =over 4
1307:
1308: =item *
1309:
1310: euclid() : Euclid's method for determining the greatest common denominator.
1311:
1312: =item *
1313:
1314: tracetable() : Build page table.
1315:
1316: =back
1317:
1318: =cut
1.1 www 1319:
1320:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>