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