--- loncom/interface/lonhtmlcommon.pm 2011/05/15 23:57:32 1.285.2.1 +++ loncom/interface/lonhtmlcommon.pm 2011/12/21 21:25:40 1.297 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.285.2.1 2011/05/15 23:57:32 raeburn Exp $ +# $Id: lonhtmlcommon.pm,v 1.297 2011/12/21 21:25:40 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -60,6 +60,7 @@ use Time::Local; use Time::HiRes; use Apache::lonlocal; use Apache::lonnet; +use HTML::Entities(); use LONCAPA; sub java_not_enabled { @@ -71,7 +72,7 @@ sub java_not_enabled { sub coursepreflink { my ($text,$category)=@_; if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) { - return '&"').'">'.$text.''; + return '&"').'">'.$text.''; } else { return ''; } @@ -83,6 +84,22 @@ sub raw_href_to_link { return $message; } +sub entity_encode { + my ($text)=@_; + return &HTML::Entities::encode($text, '<>&"'); +} + +sub direct_parm_link { + my ($linktext,$symb,$filter,$part,$target)=@_; + $symb=&entity_encode($symb); + $filter=&entity_encode($filter); + $part=&entity_encode($part); + if (($symb) && (&Apache::lonnet::allowed('opa')) && ($target ne 'tex')) { + return "$linktext"; + } else { + return $linktext; + } +} ############################################## ############################################## @@ -731,13 +748,12 @@ parameter setting wizard. sub pjump_javascript_definition { my $Str = < 1, - 'bgcolor' => '#88DDFF', - 'js_ready' => 1}); - my $end_page = &Apache::loncommon::end_page({'js_ready' => 1}); - - #the whole function called through timeout is due to issues - #in mozilla Read BUG #2665 if you want to know the whole story - &r_print($r,&Apache::lonhtmlcommon::scripttag( - "var popwin; - function openpopwin () { - popwin=open(\'\',\'popwin\',\'width=400,height=100\');". - "popwin.document.writeln(\'".$start_page. - "

".&mt("$heading")."<\/h4>". - "
". - '<\\/form>'.$end_page. - "\');". - "popwin.document.close();}". - "\nwindow.setTimeout(openpopwin,0)" - )); - $prog_state{'formname'}='popremain'; - $prog_state{'inputname'}="remaining"; - } elsif ($type eq 'inline') { - $prog_state{'window'}='window'; - if (!$formname) { - $prog_state{'formname'}=&get_uniq_name(); - &r_print($r,''); - } else { - $prog_state{'formname'}=$formname; - } - if (!$inputname) { - $prog_state{'inputname'}=&get_uniq_name(); - &r_print($r,&mt("$heading [_1]",' ')); - } else { - $prog_state{'inputname'}=$inputname; - - } - if (!$formname) { &r_print($r,'
'); } - &Update_PrgWin($r,\%prog_state,&mt('Starting')); - } - $prog_state{'done'}=0; $prog_state{'firststart'}=&Time::HiRes::time(); $prog_state{'laststart'}=&Time::HiRes::time(); $prog_state{'max'}=$number_to_do; - + &Apache::loncommon::LCprogressbar($r); return %prog_state; } # update progress sub Update_PrgWin { my ($r,$prog_state,$displayString)=@_; - &r_print($r,&Apache::lonhtmlcommon::scripttag( - $$prog_state{'window'}.'.document.'. - $$prog_state{'formname'}.'.'. - $$prog_state{'inputname'}.'.value="'. - $displayString.'";' - )); + &Apache::loncommon::LCprogressbarUpdate($r,undef,$displayString); $$prog_state{'laststart'}=&Time::HiRes::time(); } @@ -1096,38 +1053,21 @@ sub Increment_PrgWin { $min, $sec, $lasttime); - - &r_print($r,&Apache::lonhtmlcommon::scripttag( - $$prog_state{'window'}.'.document.'. - $$prog_state{'formname'}.'.'. - $$prog_state{'inputname'}.'.value="'.$timeinfo.'";' - )); + my $percent=0; + if ($$prog_state{'max'}) { + $percent=int(100.*$current/$$prog_state{'max'}); + } + &Apache::loncommon::LCprogressbarUpdate($r,$percent,$timeinfo); $$prog_state{'laststart'}=&Time::HiRes::time(); } # close Progress Line sub Close_PrgWin { my ($r,$prog_state)=@_; - if ($$prog_state{'type'} eq 'popup') { - &r_print($r,&Apache::lonhtmlcommon::scripttag( - 'popwin.close()' - )); - } elsif ($$prog_state{'type'} eq 'inline') { - &Update_PrgWin($r,$prog_state,&mt('Done')); - } + &Apache::loncommon::LCprogressbarClose($r); undef(%$prog_state); } -sub r_print { - my ($r,$to_print)=@_; - if ($r) { - $r->print($to_print); - $r->rflush(); - } else { - print($to_print); - } -} - # ------------------------------------------------------- Puts directory header sub crumbs { @@ -1227,9 +1167,9 @@ sub htmlareaheaders { ENDEDITOR } $s.=(< - - + + + ENDJQUERY return $s; } @@ -1407,6 +1347,34 @@ sub htmlareabrowser { return 1; } +# +# Should the "return to content" link be shown? +# + +sub show_return_link { + + unless ($env{'request.course.id'}) { return 0; } + if ($env{'request.noversionuri'}=~m{^/priv/} || + $env{'request.uri'}=~m{^/~}) { return 1; } + + if (($env{'request.noversionuri'} =~ m{^/adm/(viewclasslist|navmaps)($|\?)}) + || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) { + + return if ($env{'form.register'}); + } + return (($env{'request.noversionuri'}=~m{^/(res|public)/} && + $env{'request.symb'} eq '') + || + ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl}) + || + (($env{'request.noversionuri'}=~/^\/adm\//) && + ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) && + ($env{'request.noversionuri'}!~ + m{^/adm/.*/(smppg|bulletinboard)($|\?)}) + )); +} + + ############################################################ ############################################################ @@ -1492,22 +1460,28 @@ returns: nothing $last = $menulink; } } - my $links = join "", + my $links; + if ((&show_return_link) && (!$CourseBreadcrumbs)) { + $links=&htmltag( 'a',"", + { href => '/adm/flip?postdata=return:', + title => &mt("Back to most recent content resource") }); + } + $links.= join "", map { $faq = $_->{'faq'} if (exists($_->{'faq'})); $bug = $_->{'bug'} if (exists($_->{'bug'})); $help = $_->{'help'} if (exists($_->{'help'})); - my $result = $_->{no_mt} ? $_->{text} : mt($_->{text}); + my $result = $_->{no_mt} ? $_->{text} : &mt($_->{text}); if ($_->{href}){ - $result = htmltag( 'a', $result, + $result = &htmltag( 'a', $result, { href => $_->{href}, - title => $_->{no_mt} ? $_->{title} : mt($_->{title}), + title => $_->{no_mt} ? $_->{title} : &mt($_->{title}), target => $_->{target}, }); } - $result = htmltag( 'li', "$result $crumbsymbol"); + $result = &htmltag( 'li', "$result $crumbsymbol"); } @Crumbs; #should the last Element be translated? @@ -1517,7 +1491,7 @@ returns: nothing # last breadcrumb is the first order heading of a page # for course breadcrumbs it's just bold - $links .= htmltag( 'li', htmltag($CourseBreadcrumbs ? 'b' : 'h1', + $links .= &htmltag( 'li', htmltag($CourseBreadcrumbs ? 'b' : 'h1', $lasttext), {title => $lasttext}); my $icons = ''; @@ -1540,23 +1514,23 @@ returns: nothing unless ($CourseBreadcrumbs) { - $links = htmltag('ol', $links, { id => "LC_MenuBreadcrumbs" }); + $links = &htmltag('ol', $links, { id => "LC_MenuBreadcrumbs" }); } else { - $links = htmltag('ul', $links, { class => "LC_CourseBreadcrumbs" }); + $links = &htmltag('ul', $links, { class => "LC_CourseBreadcrumbs" }); } if ($component) { - $links = htmltag('span', + $links = &htmltag('span', ( $no_mt ? $component : mt($component) ). ( $icons ? $icons : '' ), { class => 'LC_breadcrumbs_component' } ) .$links; } - render_tools(\$links); - $links = htmltag('div', $links, + &render_tools(\$links); + $links = &htmltag('div', $links, { id => "LC_breadcrumbs" }) unless ($CourseBreadcrumbs) ; - render_advtools(\$links); + &render_advtools(\$links); # Return the @Crumbs stack to what we started with push(@Crumbs,$last); @@ -1611,9 +1585,7 @@ returns: nothing @html = grep {defined $_ && $_ ne ''} @html; for (@html) { s/align="(right|left)"//; - if (($category ne 'advtools') && ($category ne 'tools')) { - s///; - } +# s/// if $category ne 'advtools'; } push @{$tools{$category}}, @html; @@ -2287,6 +2259,251 @@ sub set_form_elements { } ############################################## +############################################## + +sub file_submissionchk_js { + my ($turninpaths,$multiples) = @_; + my $overwritewarn = &mt('File(s) you uploaded for your submission will overwrite existing file(s) submitted for this item').'\\n'. + &mt('Continue submission and overwrite the file(s)?'); + my $delfilewarn = &mt('You have indicated you wish to remove some files previously included in your submission.').'\\n'. + &mt('Continue submission with these files removed?'); + my ($turninpathtext,$multtext,$arrayindexofjs); + if (ref($turninpaths) eq 'HASH') { + foreach my $key (sort(keys(%{$turninpaths}))) { + $turninpathtext .= " if (prefix == '$key') {\n". + " return '$turninpaths->{$key}';\n". + " }\n"; + } + } + $turninpathtext .= " return '';\n"; + if (ref($multiples) eq 'HASH') { + foreach my $key (sort(keys(%{$multiples}))) { + $multtext .= " if (prefix == '$key') {\n". + " return '$multiples->{$key}';\n". + " }\n"; + } + } + $multtext .= " return '';\n"; + + $arrayindexofjs = &Apache::loncommon::javascript_array_indexof(); + return <<"ENDSCRIPT"; + + +$arrayindexofjs + +ENDSCRIPT +} + +############################################## ############################################## # javascript_valid_email