--- loncom/interface/lonhtmlcommon.pm 2011/05/15 23:57:32 1.285.2.1 +++ loncom/interface/lonhtmlcommon.pm 2012/03/26 10:24:08 1.306 @@ -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.306 2012/03/26 10:24:08 foxr 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,42 +1053,27 @@ 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 { my ($uri,$target,$prefix,$form,$skiplast)=@_; +# You cannot crumbnify uploaded or adm resources + if ($uri=~/^\/*(uploaded|adm)\//) { return &mt('(Internal Course/Group Content)'); } if ($target) { $target = ' target="'. &Apache::loncommon::escape_single($target).'"'; @@ -1169,6 +1111,7 @@ sub crumbs { if ($uri !~ m|/$|) { $output=~s|/$||; } $output.=''; + return $output; } @@ -1227,9 +1170,14 @@ sub htmlareaheaders { ENDEDITOR } $s.=(< - - + + + + + + + ENDJQUERY return $s; } @@ -1358,8 +1306,33 @@ sub htmlareaselectactive { $(this).before("
Rich formatting »
"); $("#LC_rt_"+id).click(editorHandler); }); + $.fn.jPicker.defaults.images.clientPath="/adm/jpicker/images/"; + $(".colorchooser").jPicker(); + + }); '; + # Code to put a due date countdown in 'duedatecountdown' span. + # This is currently located in the breadcrumb headers. + # note that the dueDateLayout is internatinoalized below. + # Here document is used to support the substitution into the javascript below. + # ..which unfortunately necessitates escaping the $'s in the javascript. + + my $dueDateLayout = '' . &mt('Due in: {dn} {dl} {hnn}{sep}{mnn}{sep}{snn}') . ''; + $output .= <", + { href => '/adm/flip?postdata=return:', + title => &mt("Back to most recent content resource") }); + $links=&htmltag('li',$links); + } + $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,9 +1559,12 @@ 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}); + $links .= '
  • '; + my $icons = ''; $faq = $last->{'faq'} if (exists($last->{'faq'})); $bug = $last->{'bug'} if (exists($last->{'bug'})); @@ -1537,31 +1582,39 @@ returns: nothing $faq,$bug); } # + 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; + .$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); shift(@Crumbs); + + # Return the breadcrumb's line + + + return "$links"; } @@ -1611,9 +1664,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; @@ -2029,26 +2080,41 @@ sub course_custom_roles { sub resource_info_box { - my ($symb,$onlyfolderflag)=@_; + my ($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp)=@_; my $return=''; + if ($stuvcurrent ne '') { + $return = '
    '; + } if ($symb) { - $return=&Apache::loncommon::start_data_table(); + $return.=&Apache::loncommon::start_data_table(); my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symb); my $folder=&Apache::lonnet::gettitle($map); $return.=&Apache::loncommon::start_data_table_row(). - ''.&mt('Folder:').''.$folder.''. + ''.&mt('Folder:').''.$folder.''. &Apache::loncommon::end_data_table_row(); unless ($onlyfolderflag) { $return.=&Apache::loncommon::start_data_table_row(). - ''.&mt('Resource:').''.&Apache::lonnet::gettitle($symb).''. + ''.&mt('Resource:').''.&Apache::lonnet::gettitle($symb).''. + &Apache::loncommon::end_data_table_row(); + } + if ($stuvcurrent ne '') { + $return .= &Apache::loncommon::start_data_table_row(). + ''.&mt("Student's current version:").''.$stuvcurrent.''. + &Apache::loncommon::end_data_table_row(); + } + if ($stuvdisp ne '') { + $return .= &Apache::loncommon::start_data_table_row(). + ''.&mt("Student's version displayed:").''.$stuvdisp.''. &Apache::loncommon::end_data_table_row(); } $return.=&Apache::loncommon::end_data_table(); } else { $return='

    '.&mt('No context provided.').'

    '; } + if ($stuvcurrent ne '') { + $return .= '
    '; + } return $return; - } ############################################## @@ -2287,6 +2353,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