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