--- loncom/homework/lonsimpleproblemedit.pm 2010/01/27 23:26:09 1.31 +++ loncom/homework/lonsimpleproblemedit.pm 2013/07/15 16:13:12 1.36 @@ -1,7 +1,7 @@ # The LearningOnline Network # Simple Problem Parameter Setting "Editor" # -# $Id: lonsimpleproblemedit.pm,v 1.31 2010/01/27 23:26:09 raeburn Exp $ +# $Id: lonsimpleproblemedit.pm,v 1.36 2013/07/15 16:13:12 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -137,11 +137,11 @@ sub foil { my $selectvalue=&Apache::loncommon::select_form( $value, 'value'.$number, - %values); + \%values); my $selectposition=&Apache::loncommon::select_form( $position, 'position'.$number, - &Apache::lonlocal::texthash(%positions)); + {&Apache::lonlocal::texthash(%positions)}); my $text=$qparms{$prefix.'text'.$number}; my %lt=&Apache::lonlocal::texthash('foil' => 'Foil', 'value' => 'Value', @@ -205,7 +205,7 @@ sub handler { my $weightprefix=$env{'request.course.id'}.'.'.$symb.'.'; # ---------------------------------------------------------- Anything to store? - + my $storeresult; if (($symb) && (defined($env{'form.questiontype'}))) { my %storecontent=(); undef %storecontent; @@ -247,7 +247,17 @@ sub handler { &Apache::lonnet::devalidatecourseresdata( $env{'course.'.$env{'request.course.id'}.'.num'}, $env{'course.'.$env{'request.course.id'}.'.domain'}); - + if ($reply eq 'ok') { + if ($env{'form.forceview'}) { + my $dest = &get_parent_uri($symb); + if ($dest) { + $r->internal_redirect($dest); + return OK; + } + } + } else { + $storeresult = $reply; + } } # ------------------------------------------------------------------- Read Data @@ -256,21 +266,34 @@ sub handler { $env{'course.'.$env{'request.course.id'}.'.num'}, $env{'request.course.id'}.'.'.$symb); + my $js = <<"ENDJS"; + +<script type="text/javascript"> +// <![CDATA[ + +function setForceView() { + if (document.getElementById('spview')) { + document.getElementById('spview').value = 1; + } + return true; +} +// END LON-CAPA Internal --> +// ]]> +</script> + +ENDJS + # ------------------------------------------------------------ Print the screen my $spell_header=&Apache::lonhtmlcommon::spellheader(); $r->print(&Apache::loncommon::start_page('Simple Problem Editor', - $spell_header)); + $spell_header.$js)); if ($symb) { my $title='<h1>'.&Apache::lonnet::gettitle($symb).'</h1>'; - my $displaylink = &get_parent_uri($symb); - if ($displaylink ne '') { - my $functions=&Apache::lonhtmlcommon::start_funclist() - .&Apache::lonhtmlcommon::add_item_funclist( - '<a href="'.$displaylink.'">' - .&mt('Student View').'</a>') - .&Apache::lonhtmlcommon::end_funclist(); - $r->print(&Apache::loncommon::head_subbox($functions) - .$title); + if (&get_parent_uri($symb)) { + $r->print($title); + if ($storeresult) { + $r->print('<p class="LC_error">'.&mt('An error: [_1] occurred saving your changes',$storeresult).'</p>'); + } } else { $r->print($title .'<p class="LC_error">' @@ -292,7 +315,7 @@ sub handler { .&rawrendering($symb) .'</div>' ); - $r->print('<form name="simpleedit" method="post">'); + $r->print('<form name="simpleedit" method="post" action="">'); # Question Type my %questiontypes=( 'radio' => '1 out of N multiple choice (radio button)', @@ -309,12 +332,15 @@ sub handler { .&Apache::loncommon::select_form( $qtype, 'questiontype', - &Apache::lonlocal::texthash(%questiontypes)) + {&Apache::lonlocal::texthash(%questiontypes)}) .'</fieldset>' ); $r->print( '<p>' + .'<input type="hidden" name="forceview" value="" id="spview" />' .'<input type="submit" value="'.&mt('Save and Edit').'" />' + .(' ' x3) + .'<input type="submit" value="'.&mt('Save and View').'" onclick="javascript:setForceView();" />' .'</p>' ); # Script @@ -343,7 +369,7 @@ sub handler { &Apache::loncommon::select_form( $randomize, 'randomize', - &Apache::lonlocal::texthash(%randomizes)). + {&Apache::lonlocal::texthash(%randomizes)}). '</td></tr><tr><td bgcolor="#F0F0F0">'); # Option Response: Options if ($qtype eq 'option') { @@ -356,7 +382,7 @@ sub handler { $options.'" />'.&mt('Add new option').': '. '<input type="text" name="newopt" size="15" />'. &mt('Delete an option').': '. - &Apache::loncommon::select_form('','delopt',('' => '',%optionshash)). + &Apache::loncommon::select_form('','delopt',{'' => '',%optionshash}). '</td></tr><tr><td>'); } # Foils @@ -389,7 +415,7 @@ sub handler { &Apache::loncommon::select_form( $stringtype, 'stringtype', - &Apache::lonlocal::texthash(%stringtypes)). + {&Apache::lonlocal::texthash(%stringtypes)}). '</td></tr></table><br />'); # Hint $r->print(&hint()); @@ -414,13 +440,16 @@ sub handler { } # Store Button $r->print( - '<input type="submit" value="'.&mt('Save and Edit').'" /></form>'); + '<input type="submit" value="'.&mt('Save and Edit').'" />'. + (' ' x3). + '<input type="submit" value="'.&mt('Save and View').'" onclick="javascript:setForceView();" />'. + '</form>'); } else { $r->print(&mt('Could not identify problem.')); } $r->print(&Apache::loncommon::end_page()); return OK; -} +} 1; __END__