--- loncom/xml/lonxml.pm 2009/10/04 03:40:13 1.494.4.2 +++ loncom/xml/lonxml.pm 2010/03/21 18:32:02 1.507 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.494.4.2 2009/10/04 03:40:13 raeburn Exp $ +# $Id: lonxml.pm,v 1.507 2010/03/21 18:32:02 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -111,6 +111,7 @@ use Apache::loncacc(); use Apache::lonmaxima(); use Apache::lonr(); use Apache::lonlocal; +use Apache::lonhtmlcommon(); #==================================== Main subroutine: xmlparse @@ -221,101 +222,6 @@ sub xmlend { return $discussion; } -sub tokeninputfield { - my $defhost=$Apache::lonnet::perlvar{'lonHostID'}; - $defhost=~tr/a-z/A-Z/; - return (<<ENDINPUTFIELD) -<script type="text/javascript"> - function updatetoken() { - var comp=new Array; - var barcode=unescape(document.tokeninput.barcode.value); - comp=barcode.split('*'); - if (typeof(comp[0])!="undefined") { - document.tokeninput.codeone.value=comp[0]; - } - if (typeof(comp[1])!="undefined") { - document.tokeninput.codetwo.value=comp[1]; - } - if (typeof(comp[2])!="undefined") { - comp[2]=comp[2].toUpperCase(); - document.tokeninput.codethree.value=comp[2]; - } - document.tokeninput.barcode.value=''; - } -</script> -<form method="post" name="tokeninput"> -<table border="2" bgcolor="#FFFFBB"> -<tr><th>DocID Checkin</th></tr> -<tr><td> -<table> -<tr> -<td>Scan in Barcode</td> -<td><input type="text" size="22" name="barcode" -onChange="updatetoken()"/></td> -</tr> -<tr><td><i>or</i> Type in DocID</td> -<td> -<input type="text" size="5" name="codeone" /> -<b><font size="+2">*</font></b> -<input type="text" size="5" name="codetwo" /> -<b><font size="+2">*</font></b> -<input type="text" size="10" name="codethree" value="$defhost" -onChange="this.value=this.value.toUpperCase()" /> -</td></tr> -</table> -</td></tr> -<tr><td><input type="submit" value="Check in DocID" /></td></tr> -</table> -</form> -ENDINPUTFIELD -} - -sub maketoken { - my ($symb,$tuname,$tudom,$tcrsid)=@_; - unless ($symb) { - $symb=&Apache::lonnet::symbread(); - } - unless ($tuname) { - $tuname=$env{'user.name'}; - $tudom=$env{'user.domain'}; - $tcrsid=$env{'request.course.id'}; - } - - return &Apache::lonnet::checkout($symb,$tuname,$tudom,$tcrsid); -} - -sub printtokenheader { - my ($target,$token,$tsymb,$tcrsid,$tudom,$tuname)=@_; - unless ($token) { return ''; } - - my ($symb,$courseid,$domain,$name) = &Apache::lonnet::whichuser(); - unless ($tsymb) { - $tsymb=$symb; - } - unless ($tuname) { - $tuname=$name; - $tudom=$domain; - $tcrsid=$courseid; - } - - my $plainname=&Apache::loncommon::plainname($tuname,$tudom); - - if ($target eq 'web') { - my %idhash=&Apache::lonnet::idrget($tudom,($tuname)); - return - '<img align="right" src="/cgi-bin/barcode.png?encode='.$token.'" />'. - &mt('Checked out for').' '.$plainname. - '<br />'.&mt('User').': '.$tuname.' at '.$tudom. - '<br />'.&mt('ID').': '.$idhash{$tuname}. - '<br />'.&mt('CourseID').': '.$tcrsid. - '<br />'.&mt('Course').': '.$env{'course.'.$tcrsid.'.description'}. - '<br />'.&mt('DocID').': '.$token. - '<br />'.&mt('Time').': '.&Apache::lonlocal::locallocaltime().'<hr />'; - } else { - return $token; - } -} - sub printalltags { my $temp; foreach $temp (sort keys %Apache::lonxml::alltags) { @@ -1043,7 +949,7 @@ sub get_id { my ($parstack,$safeeval)=@_; my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval); if ($env{'request.state'} eq 'construct' && $id =~ /([._]|[^\w\d\s[:punct:]])/) { - &error(&mt("ID [_1] contains invalid characters, IDs are only allowed to contain letters, numbers, spaces and -",'<tt>'.$id.'</tt>')); + &error(&mt('ID [_1] contains invalid characters. IDs are only allowed to contain letters, numbers, spaces and -','"<tt>'.$id.'</tt>"')); } if ($id =~ /^\s*$/) { $id = $Apache::lonxml::curdepth; } return $id; @@ -1546,20 +1452,30 @@ sub renderingoptions { = &Apache::loncommon::plainlanguagedescription($_); } } - return - '<span class="LC_nobreak">'. - &mt('Language:').' '. - &Apache::loncommon::select_form($env{'form.languages'},'languages', - %langchoices).' - </span> - <span class="LC_nobreak">'. + my $output; + unless ($env{'form.forceedit'}) { + $output .= + '<span class="LC_nobreak">'. + &mt('Language:').' '. + &Apache::loncommon::select_form( + $env{'form.languages'}, + 'languages', + &Apache::lonlocal::texthash(%langchoices)). + '</span>'; + } + $output .= + ' <span class="LC_nobreak">'. &mt('Math Rendering:').' '. - &Apache::loncommon::select_form($env{'form.texengine'},'texengine', - ('' => '', - 'tth' => 'tth (TeX to HTML)', - 'jsMath' => 'jsMath', - 'mimetex' => 'mimetex (Convert to Images)')).' - </span>'; + &Apache::loncommon::select_form( + $env{'form.texengine'}, + 'texengine', + &Apache::lonlocal::texthash + ('' => '', + 'tth' => 'tth (TeX to HTML)', + 'jsMath' => 'jsMath', + 'mimetex' => 'mimetex (Convert to Images)')). + '</span>'; + return $output; } sub inserteditinfo { @@ -1606,7 +1522,7 @@ FULLPAGE } </script> FULLPAGE - if ($filetype eq 'html') { + if ($filetype eq 'html' || $filetype eq 'tex') { $initialize .= "\n".&Apache::lonhtmlcommon::dragmath_js('EditMathPopup'); $dragmath_button = &Apache::lonhtmlcommon::dragmath_button('filecont',1); } @@ -1620,6 +1536,7 @@ FULLPAGE } my $titledisplay=&display_title(); + my $wysiwyglink; my %lt=&Apache::lonlocal::texthash('st' => 'Save and Edit', 'vi' => 'Save and View', 'dv' => 'Discard Edits and View', @@ -1634,6 +1551,13 @@ FULLPAGE if ($htmlerror) { $htmlerror='<span class="LC_error">'.$htmlerror.'</span>'; } + if (&Apache::lonhtmlcommon::htmlareabrowser()) { + if (&Apache::lonhtmlcommon::htmlareablocked()) { + $wysiwyglink = &Apache::lonhtmlcommon::enablelink($textarea_id); + } else { + $wysiwyglink = &Apache::lonhtmlcommon::disablelink($textarea_id); + } + } } my $editfooter=(<<ENDFOOTER); $initialize @@ -1658,6 +1582,7 @@ $initialize </div> <textarea $textarea_events style="width:100%" cols="80" rows="44" name="filecont" id="filecont">$filecontents</textarea> <div id="LC_aftertextarea"> + $wysiwyglink <br /> $titledisplay </div> @@ -1706,8 +1631,8 @@ sub handler { $request->set_last_modified(&Apache::lonnet::metadata($request->uri, 'lastrevisiondate')); } - # Embedded Flash movies (e.g., from Camtasia) served from https will not display in IE - # if XML config file has expired from cache. + # Embedded Flash movies from Camtasia served from https will not display in IE + # if XML config file has expired from cache. if ($ENV{'SERVER_PORT'} == 443) { if ($request->uri =~ /\.xml$/) { my ($httpbrowser,$clientbrowser) = @@ -1727,12 +1652,25 @@ sub handler { my $file=&Apache::lonnet::filelocation("",$request->uri); - my $filetype; - if ($file =~ /\.(sty|css|js|txt)$/) { + my ($filetype,$breadcrumbtext); + if ($file =~ /\.(sty|css|js|txt|tex)$/) { $filetype=$1; } else { $filetype='html'; } + if ($filetype eq 'sty') { + $breadcrumbtext = 'Style File Editor'; + } elsif ($filetype eq 'js') { + $breadcrumbtext = 'Javascript Editor'; + } elsif ($filetype eq 'css') { + $breadcrumbtext = 'CSS Editor'; + } elsif ($filetype eq 'txt') { + $breadcrumbtext = 'Text Editor'; + } elsif ($filetype eq 'tex') { + $breadcrumbtext = 'TeX Editor'; + } else { + $breadcrumbtext = 'HTML Editor'; + } # # Edit action? Save file. @@ -1752,10 +1690,13 @@ sub handler { if ($filecontents eq -1) { my $start_page=&Apache::loncommon::start_page('File Error'); my $end_page=&Apache::loncommon::end_page(); - my $fnf=&mt('File not found'); + my $errormsg='<p class="LC_error">' + .&mt('File not found: [_1]' + ,'<span class="LC_filename">'.$file.'</span>') + .'</p>'; $result=(<<ENDNOTFOUND); $start_page -<b>$fnf: $file</b> +$errormsg $end_page ENDNOTFOUND $filecontents=''; @@ -1764,7 +1705,7 @@ ENDNOTFOUND $filecontents=&createnewsty(); } elsif ($filetype eq 'js') { $filecontents=&createnewjs(); - } elsif (($filetype ne 'css') && ($filetype ne 'txt')) { + } elsif ($filetype ne 'css' && $filetype ne 'txt' && $filetype ne 'tex') { $filecontents=&createnewhtml(); } $env{'form.editmode'}='Edit'; #force edit mode @@ -1788,36 +1729,55 @@ ENDNOTFOUND # up if it did &Apache::structuretags::reset_problem_globals(); &Apache::lonhomework::finished_parsing(); + } elsif ($filetype eq 'tex') { + $result = &Apache::lontexconvert::converted(\$filecontents, + $env{'form.texengine'}); + if ($env{'form.return_only_error_and_warning_counts'}) { + if (&verify_html('<html><body>'.$result.'</body></html>')) { + $errorcount++; + } + $result = "$errorcount:$warningcount"; + } } else { $result = $filecontents; } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['rawmode']); if ($env{'form.rawmode'}) { $result = $filecontents; } - if ($filetype ne 'html') { - my $nochgview = 1; - my $controls = - ($env{'request.state'} eq 'construct') ? &Apache::londefdef::edit_controls($nochgview) - : ''; - if ($filetype ne 'sty') { + if (($filetype ne 'html') && + (!$env{'form.return_only_error_and_warning_counts'})) { + my $nochgview = 1; + my $controls = ''; + if ($env{'request.state'} eq 'construct') { + $controls = &Apache::loncommon::head_subbox( + &Apache::loncommon::CSTR_pageheader() + .&Apache::londefdef::edit_controls($nochgview)); + } + if ($filetype ne 'sty' && $filetype ne 'tex') { $result =~ s/</</g; $result =~ s/>/>/g; $result = '<table class="LC_sty_begin">'. '<tr><td><b><pre>'.$result. '</pre></b></td></tr></table>'; } - if ($env{'environment.remote'} eq 'off') { - my %options = ('bgcolor' => '#FFFFFF'); - $result = - &Apache::loncommon::start_page(undef,undef,\%options). - $controls. - $result. - &Apache::loncommon::end_page(); + my $brcrum; + if ($env{'request.state'} eq 'construct') { + $brcrum = [{'href' => &Apache::loncommon::authorspace(), + 'text' => 'Construction Space'}, + {'href' => '', + 'text' => $breadcrumbtext}]; } else { - $result = $controls.$result; + $brcrum = ''; # FIXME: Where are we? } + my %options = ('bread_crumbs' => $brcrum, + 'bgcolor' => '#FFFFFF'); + $result = + &Apache::loncommon::start_page(undef,undef,\%options) + .$controls + .$result + .&Apache::loncommon::end_page(); } - } + } } # @@ -1834,26 +1794,32 @@ ENDNOTFOUND my %options = ('add_entries' => - {'onresize' => $add_to_onresize, - 'onload' => $add_to_onload, }); - - if ($env{'environment.remote'} ne 'off') { - $options{'bgcolor'} = '#FFFFFF'; - $options{'only_body'} = 1; - } + {'onresize' => $add_to_onresize, + 'onload' => $add_to_onload, }); + my $header; + if ($env{'request.state'} eq 'construct') { + $options{'bread_crumbs'} = [{ + 'href' => &Apache::loncommon::authorspace(), + 'text' => 'Construction Space'}, + {'href' => '', + 'text' => $breadcrumbtext}]; + $header = &Apache::loncommon::head_subbox( + &Apache::loncommon::CSTR_pageheader()); + } my $js = &Apache::edit::js_change_detection(). &Apache::loncommon::resize_textarea_js(); my $start_page = &Apache::loncommon::start_page(undef,$js, \%options); - $result=$start_page. - &Apache::lonxml::message_location(). - $edit_info. - &Apache::loncommon::end_page(); + $result = $start_page + .$header + .&Apache::lonxml::message_location() + .$edit_info + .&Apache::loncommon::end_page(); } } if ($filetype eq 'html') { &writeallows($request->uri); } - + &Apache::lonxml::add_messages(\$result); $request->print($result);