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