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