--- loncom/homework/structuretags.pm 2003/10/03 15:27:02 1.212 +++ loncom/homework/structuretags.pm 2003/11/26 19:35:28 1.227 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.212 2003/10/03 15:27:02 albertel Exp $ +# $Id: structuretags.pm,v 1.227 2003/11/26 19:35:28 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -171,8 +171,10 @@ sub setup_rndseed { if (defined($rndseed) && $rndseed ne int($rndseed)) { $rndseed=join(',',&Math::Random::random_seed_from_phrase($rndseed)); } - &Apache::lonxml::debug("Setting rndseed to $rndseed"); - &Apache::run::run('$external::randomseed='.$rndseed.';',$safeeval); + if ($safeeval) { + &Apache::lonxml::debug("Setting rndseed to $rndseed"); + &Apache::run::run('$external::randomseed='.$rndseed.';',$safeeval); + } } return $rndseed; } @@ -355,7 +357,7 @@ sub start_problem { } #added vars to the scripting enviroment - my $expression='$external::part='.$Apache::inputtags::part.';'; + my $expression='$external::part=\''.$Apache::inputtags::part.'\';'; &Apache::run::run($expression,$safeeval); my $status; my $accessmsg; @@ -400,7 +402,8 @@ sub start_problem { if (( $status eq 'CLOSED' ) || ( $status eq 'UNCHECKEDOUT') || ( $status eq 'BANNED') || - ( $status eq 'UNAVAILABLE')) { + ( $status eq 'UNAVAILABLE') || + ( $status eq 'INVALID_ACCESS')) { my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser); if ( $target eq "web" ) { $result.= $head_tag_start.''; @@ -410,7 +413,7 @@ sub start_problem { } else { $result.='

'.&mt('Not open to be viewed').'

'; } - if ($status eq 'CLOSED') { + if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') { $msg.='The problem '.$accessmsg; } elsif ($status eq 'UNCHECKEDOUT') { $msg.=&checkout_msg; @@ -426,25 +429,19 @@ sub start_problem { } } elsif ($target eq 'web') { my $name= &get_resource_name($parstack,$safeeval); - if ($status eq 'CAN_ANSWER') { - # create a page header and exit - $result.="$head_tag_start$name + $result.="$head_tag_start$name $body_tag_start \n $form_tag_start". - ''; - if ($ENV{'request.state'} eq "construct") { - $result.= &problem_web_to_edit_header($ENV{'form.rndseed'}); - } - # if we are viewing someone else preserve that info - if (defined $ENV{'form.grade_symb'}) { - foreach my $field ('symb','courseid','domain','username') { - $result .= ''."\n"; - } + ''; + # create a page header and exit + if ($ENV{'request.state'} eq "construct") { + $result.= &problem_web_to_edit_header($ENV{'form.rndseed'}); + } + # if we are viewing someone else preserve that info + if (defined $ENV{'form.grade_symb'}) { + foreach my $field ('symb','courseid','domain','username') { + $result .= ''."\n"; } - } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER' - || $status eq 'CLOSED' || $status eq 'UNAVALAILABLE') { - $result.=$head_tag_start. - "$name\n$body_tag_start\n"; } } elsif ($target eq 'tex') { my $startminipage = ''; @@ -453,12 +450,12 @@ sub start_problem { } my $id = $Apache::inputtags::part; my $weight = &Apache::lonnet::EXT("resource.$id.weight"); - my $allkeys=&Apache::lonnet::metadata($ENV{'request.uri'},'keys'); - my @allkeys = split /,/,$allkeys; + my $packages=&Apache::lonnet::metadata($ENV{'request.uri'},'packages'); + my @packages = split /,/,$packages; my $allow_print_points = 0; - foreach my $partial_key (@allkeys) { - if ($partial_key=~m/weight/) { - $allow_print_points++; + foreach my $partial_key (@packages) { + if ($partial_key=~m/part_0/) { + $allow_print_points=1; } } my $duedate = &Apache::lonnet::EXT("resource.$id.duedate"); @@ -499,6 +496,8 @@ sub start_problem { } elsif ($target eq 'edit') { $result.=$head_tag_start."".$body_tag_start.$form_tag_start. &problem_edit_header(); + $Apache::lonxml::warnings_error_header= + &mt("Editor Errors - these errors might not effect the running of the problem, but they will likely cause problems with further use of the Edit mode. Please use the EditXML mode to fix these errors.")."
"; my $temp=&Apache::edit::insertlist($target,$token); $result.=$temp; } elsif ($target eq 'modified') { @@ -533,17 +532,9 @@ sub end_problem { (($target eq 'web') && ($ENV{'request.state'} ne 'construct')) || ($target eq 'answer') || ($target eq 'tex') ) { - if ($status eq 'CAN_ANSWER') { - if ($target ne 'tex' && - $ENV{'form.answer_output_mode'} ne 'tex') { - $result.="\n"; - } - } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER' || - $status eq 'UNCHECKEDOUT' ) { - if ($target ne 'tex' && - $ENV{'form.answer_output_mode'} ne 'tex') { - $result.="\n"; - } + if ($target ne 'tex' && + $ENV{'form.answer_output_mode'} ne 'tex') { + $result.="\n"; } if ($target eq 'web') { $result.=&Apache::lonxml::xmlend(); @@ -574,6 +565,7 @@ sub end_problem { @Apache::inputtags::response=(); $result=&Apache::response::mandatory_part_meta; } + $result.=&Apache::response::meta_part_order(); } elsif ($target eq 'edit') { &Apache::lonxml::debug("in end_problem with $target, edit"); $result = &problem_edit_footer(); @@ -939,11 +931,13 @@ sub start_part { $Apache::lonhomework::problemstatus= &Apache::lonnet::EXT("resource.$id.problemstatus"); my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part); - my $expression='$external::part='.$Apache::inputtags::part.';'; + my $expression='$external::part=\''.$Apache::inputtags::part.'\';'; &Apache::run::run($expression,$safeeval); if ($target eq 'meta') { - return &Apache::response::mandatory_part_meta; + my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval); + return &Apache::response::mandatory_part_meta. + &Apache::response::meta_parameter_write('display','string',$display,'Part Description'); } elsif ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') { if ($hidden) { @@ -954,7 +948,11 @@ sub start_part { my $expression='$external::datestatus="'.$status.'";'; $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";'; &Apache::run::run($expression,$safeeval); - if ( $status eq 'CLOSED' ) { + if (( $status eq 'CLOSED' ) || + ( $status eq 'UNCHECKEDOUT') || + ( $status eq 'BANNED') || + ( $status eq 'UNAVAILABLE') || + ( $status eq 'INVALID_ACCESS')) { my $bodytext=&Apache::lonxml::get_all_text("/part",$parser); if ( $target eq "web" ) { $result="
".&mt('Part is not open to be viewed. It')." $accessmsg
"; @@ -971,7 +969,15 @@ sub start_part { $result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent'; } my $weight = &Apache::lonnet::EXT("resource.$id.weight"); - if ($Apache::lonhomework::type eq 'exam') { $result .= '\fbox{\textit{'.$weight.' pt}}';} + my $allkeys=&Apache::lonnet::metadata($ENV{'request.uri'},'keys'); + my @allkeys = split /,/,$allkeys; + my $allow_print_points = 0; + foreach my $partial_key (@allkeys) { + if ($partial_key=~m/\_(\d*)\_weight/) { + if ($1 ne '0') {$allow_print_points=1;} + } + } + if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) { $result .= '\fbox{\textit{'.$weight.' pt}}';} } } } @@ -979,11 +985,15 @@ sub start_part { $result.=&Apache::edit::tag_start($target,$token); $result.=&Apache::edit::text_arg('Part ID:','id',$token). &Apache::loncommon::help_open_topic("Part_Tag_Edit_Help"). + '  '. +&Apache::edit::text_arg('Displayed Part Description:','display',$token). &Apache::edit::end_row().&Apache::edit::start_spanning_row(); } elsif ($target eq 'modified') { my $constructtag=&Apache::edit::get_new_args($token,$parstack, - $safeeval,'id'); + $safeeval,'id','display'); if ($constructtag) { + #limiting ids to only letters numbers, and space + $token->[2]->{'id'}=~s/[^A-Za-z0-9 ]//gs; $result = &Apache::edit::rebuild_tag($token); $result.=&Apache::edit::handle_insert(); } @@ -1108,8 +1118,7 @@ sub end_startouttext { &Apache::edit::editfield($token->[1],$text,"",80,4); } if ($target eq 'modified') { - $text=&Apache::lonxml::get_all_text("endouttext",$parser); - $result=''.&Apache::edit::modifiedfield(); + $result=''.&Apache::edit::modifiedfield("endouttext",$parser); } if ($target eq 'tex') { $result .= '\noindent '; @@ -1153,7 +1162,7 @@ sub start_simpleeditbutton { my $result=''; if (($target eq 'web') && (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) { - my $url=$ENV{'REQUEST_URI'}; + my $url=$ENV{'request.noversionuri'}; $url=~s/\?.*$//; $result='
'. ''.&mt('Simple Problem Editor').' - '.&mt('Note: it can take up to 10 minutes for changes to take effect for all users.').