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