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