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