From: Mike G. v. a. <we...@ma...> - 2010-06-04 00:47:16
|
Log Message: ----------- make it easy to switch between local server and hosted2 Modified Files: -------------- webwork2/clients: renderProblem.pl Revision Data ------------- Index: renderProblem.pl =================================================================== RCS file: /webwork/cvs/system/webwork2/clients/renderProblem.pl,v retrieving revision 1.5 retrieving revision 1.6 diff -Lclients/renderProblem.pl -Lclients/renderProblem.pl -u -r1.5 -r1.6 --- clients/renderProblem.pl +++ clients/renderProblem.pl @@ -50,27 +50,33 @@ # the rest can be configured later to use a different server +my $use_local = 1; +our ($PROTOCOL,$HOSTNAME, $HOSTPORT, $FULL_URL,$FORM_ACTION_URL, $XML_PASSWORD, $XML_COURSE); +if ($use_local) { # the rest can work!! -# use constant PROTOCOL => 'http'; -# use constant HOSTNAME => 'localhost'; -# use constant HOSTPORT => 80; -# our $FORM_ACTION_URL ='http://localhost/webwork2/html2xml'; + $PROTOCOL = 'http'; + $HOSTNAME = 'localhost'; + $HOSTPORT = 80; + $FULL_URL = "$PROTOCOL://$HOSTNAME:$HOSTPORT"; + $FORM_ACTION_URL = "$FULL_URL/webwork2/html2xml"; + $XML_PASSWORD = 'xmlwebwork'; + $XML_COURSE = 'daemon_course'; +} else { + $PROTOCOL = 'https'; # or 'https'; + $HOSTNAME = "hosted2.webwork.rochester.edu"; # 'localhost'; + $HOSTPORT = 443; #( for secure https) # 80 or 443; + $FULL_URL = "$PROTOCOL://$HOSTNAME:$HOSTPORT"; + $FORM_ACTION_URL = "$FULL_URL/webwork2/html2xml"; # server parameter + $XML_PASSWORD = 'xmlwebwork'; + $XML_COURSE = 'daemon_course'; - -use constant PROTOCOL => 'https'; # or 'http'; -use constant HOSTNAME => 'hosted2.webwork.rochester.edu'; # 'localhost'; -use constant HOSTPORT => 443; #( for secure https) # 80; -our $FULL_URL = PROTOCOL."://".HOSTNAME; # .":".HOSTPORT; -our $FORM_ACTION_URL = "$FULL_URL/webwork2/html2xml"; # server parameter +} use constant TRANSPORT_METHOD => 'XMLRPC::Lite'; use constant REQUEST_CLASS => 'WebworkXMLRPC'; # WebworkXMLRPC is used for soap also!! use constant REQUEST_URI => 'mod_xmlrpc'; -use constant XML_PASSWORD => 'xmlwebwork'; -use constant XML_COURSE => 'daemon_course'; - @@ -141,7 +147,6 @@ $command = 'listLibraries' unless $command; my $requestResult = TRANSPORT_METHOD - #->uri('http://'.HOSTNAME.':'.HOSTPORT.'/'.REQUEST_CLASS) -> proxy($FULL_URL.'/'.REQUEST_URI); my $input = $self->setInputTable(); @@ -160,7 +165,7 @@ $self->{output} = $self->formatRenderedProblem($rh_result); } else { - $self->{output} = 'Error from server: ', join( ",\n ", + $self->{output} = 'Error from server: '. join( ",\n ", $result->faultcode, $result->faultstring); } @@ -171,43 +176,38 @@ encode_base64($source); } - -sub pretty_print_rh { - shift if UNIVERSAL::isa($_[0] => __PACKAGE__); - my $rh = shift; - my $indent = shift || 0; - my $out = ""; - my $type = ref($rh); - - if (defined($type) and $type) { - $out .= " type = $type; "; - } elsif (! defined($rh )) { - $out .= " type = UNDEFINED; "; - } - return $out." " unless defined($rh); - - if ( ref($rh) =~/HASH/ or "$rh" =~/HASH/ ) { - $out .= "{\n"; - $indent++; - foreach my $key (sort keys %{$rh}) { - $out .= " "x$indent."$key => " . pretty_print_rh( $rh->{$key}, $indent ) . "\n"; - } - $indent--; - $out .= "\n"." "x$indent."}\n"; - - } elsif (ref($rh) =~ /ARRAY/ or "$rh" =~/ARRAY/) { - $out .= " ( "; - foreach my $elem ( @{$rh} ) { - $out .= pretty_print_rh($elem, $indent); - - } - $out .= " ) \n"; - } elsif ( ref($rh) =~ /SCALAR/ ) { - $out .= "scalar reference ". ${$rh}; - } elsif ( ref($rh) =~/Base64/ ) { - $out .= "base64 reference " .$$rh; +sub pretty_print { # provides html output -- NOT a method + my $r_input = shift; + my $level = shift; + $level = 4 unless defined($level); + $level--; + return '' unless $level > 0; # only print three levels of hashes (safety feature) + my $out = ''; + if ( not ref($r_input) ) { + $out = $r_input if defined $r_input; # not a reference + $out =~ s/</</g ; # protect for HTML output + } elsif ("$r_input" =~/hash/i) { # this will pick up objects whose '$self' is hash and so works better than ref($r_iput). + local($^W) = 0; + + $out .= "$r_input " ."<TABLE border = \"2\" cellpadding = \"3\" BGCOLOR = \"#FFFFFF\">"; + + + foreach my $key ( sort ( keys %$r_input )) { + $out .= "<tr><TD> $key</TD><TD>=></td><td> ".pretty_print($r_input->{$key}) . "</td></tr>"; + } + $out .="</table>"; + } elsif (ref($r_input) eq 'ARRAY' ) { + my @array = @$r_input; + $out .= "( " ; + while (@array) { + $out .= pretty_print(shift @array, $level) . " , "; + } + $out .= " )"; + } elsif (ref($r_input) eq 'CODE') { + $out = "$r_input"; } else { - $out .= $rh; + $out = $r_input; + $out =~ s/</</g; # protect for HTML output } return $out." "; @@ -216,7 +216,7 @@ sub setInputTable_for_listLib { my $self = shift; my $out = { - pw => XML_PASSWORD(), + pw => $XML_PASSWORD, set => 'set0', library_name => 'Library', command => 'all', @@ -227,11 +227,11 @@ sub setInputTable { my $self = shift; my $out = { - pw => XML_PASSWORD(), + pw => $XML_PASSWORD, library_name => 'Library', command => 'renderProblem', answer_form_submitted => 1, - course => XML_COURSE(), + course => $XML_COURSE, extra_packages_to_load => [qw( AlgParserWithImplicitExpand Expr ExprWithImplicitExpand AnswerEvaluator AnswerEvaluatorMaker @@ -266,7 +266,7 @@ envir => $self->environment(), problem_state => { - num_of_correct_ans => 2, + num_of_correct_ans => 0, num_of_incorrect_ans => 4, recorded_score => 1.0, }, @@ -294,6 +294,7 @@ courseScriptsDirectory=>'not defined', displayMode=>DISPLAYMODE, dueDate=> '4014438528', + effectivePermissionLevel => 10, externalGif2EpsPath=>'not defined', externalPng2EpsPath=>'not defined', externalTTHPath=>'/usr/local/bin/tth', @@ -321,6 +322,7 @@ numZeroLevelDefault =>0.000001, numZeroLevelTolDefault =>0.000001, openDate=> '3014438528', + permissionLevel =>10, PRINT_FILE_NAMES_FOR => [ 'gage'], probFileName => 'set0/prob1a.pg', problemSeed => 1234, @@ -340,6 +342,10 @@ templateDirectory=>'not defined', tempURL=>'not defined', webworkDocsURL => 'not defined', + + showHints => 1, # extra options -- usually passed from the input form + showSolutions => 1, + }; $envir; }; @@ -350,7 +356,7 @@ my $problemNumber = shift; my $answerString = $rh_answer->{original_student_ans}||' '; my $correctAnswer = $rh_answer->{correct_ans}||''; - my $ans_message = $rh_answer->{ans_message}; + my $ans_message = $rh_answer->{ans_message}||''; my $score = ($rh_answer->{score}) ? 'Correct' : 'Incorrect'; my $row = qq{ <tr> @@ -385,8 +391,11 @@ $warnings = "<div style=\"background-color:pink\"> <p >WARNINGS</p><p>".decode_base64($rh_result->{WARNINGS})."</p></div>"; } - - ; + #warn "keys: ", join(" | ", sort keys %{$rh_result }); + my $debug_messages = $rh_result->{flags}->{DEBUG_messages} || []; + $debug_messages = join("<br/>\n", @{ $debug_messages } ); + my $internal_debug_messages = $rh_result->{internal_debug_messages} || []; + $internal_debug_messages = join("<br/>\n", @{ $internal_debug_messages } ); # collect answers my $answerTemplate = q{<hr>ANSWERS <table border="3" align="center">}; my $problemNumber = 1; @@ -400,11 +409,11 @@ my $problemTemplate = <<ENDPROBLEMTEMPLATE; <html> <head> +<base href="$FULL_URL"> <title>WeBWorK Editor</title> </head> <body> $answerTemplate - $warnings <form action="$FORM_ACTION_URL" method="post"> $problemText <input type="hidden" name="answersSubmitted" value="1"> @@ -414,6 +423,18 @@ <input type="hidden" name="pathToProblemFile" value="foobar"> <p><input type="submit" name="submit" value="submit answers"></p> </form> +<HR> +<h3> Warning section </h3> +$warnings +<h3> +Debug message section +</h3> +$debug_messages +<h3> +internal errors +</h3> +$internal_debug_messages + </body> </html> |