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