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