Diff for /loncom/homework/structuretags.pm between versions 1.397 and 1.408

version 1.397, 2007/09/11 23:53:05 version 1.408, 2007/10/31 01:37:52
Line 92  sub end_tex { Line 92  sub end_tex {
     return '';      return '';
 }  }
   
   sub homework_js {
       return &Apache::loncommon::resize_textarea_js().
    <<'JS';
   <script type="text/javascript">
   function setSubmittedPart (part) {
      this.document.lonhomework.submitted.value="part_"+part;
   }
   
   function image_response_click (which, e) {
       init_geometry();
       if (!e) { e = window.event; } //IE
       var input_element = document.lonhomework.elements[which];
       var token_element = document.lonhomework.elements[which+'_token'];
       var token = token_element.value;
       var img_element   = document.getElementById(which+'_imageresponse');
       var x= e.clientX-getX(img_element)+Geometry.getHorizontalScroll();
       var y= e.clientY-getY(img_element)+Geometry.getVerticalScroll();
       var click = x+':'+y;
       input_element.value = click;
       img_element.src = '/adm/randomlabel.png?token='+token+'&clickdata='+click;
   }
   </script>
   JS
   }
   
 sub page_start {  sub page_start {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name,      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name,
  $extra_head)=@_;   $extra_head)=@_;
Line 108  sub page_start { Line 133  sub page_start {
    $parstack,$parser,$safeeval);     $parstack,$parser,$safeeval);
     }      }
   
     $extra_head.= '      $extra_head .= &homework_js();
 <script type="text/javascript">  
 function setSubmittedPart (part) {  
    this.document.lonhomework.submitted.value="part_"+part;  
 }  
 </script>  
 ';  
   
     my %body_args;      my %body_args;
     if (defined($found{'html'})) {      if (defined($found{'html'})) {
Line 139  function setSubmittedPart (part) { Line 158  function setSubmittedPart (part) {
     } elsif (!defined($found{'body'})       } elsif (!defined($found{'body'}) 
      && $env{'request.state'} eq 'construct') {       && $env{'request.state'} eq 'construct') {
  if ($target eq 'web' || $target eq 'edit') {   if ($target eq 'web' || $target eq 'edit') {
     # no extra args to bodytag      if ($env{'environment.remote'} ne 'off') {
    $body_args{'only_body'}  = 1;
       }
  }   }
     } elsif (!defined($found{'body'})) {      } elsif (!defined($found{'body'})) {
  my %add_entries;   my %add_entries;
Line 281  sub remember_problem_state { Line 302  sub remember_problem_state {
 sub problem_edit_header {  sub problem_edit_header {
     return '<input type="hidden" name="submitted" value="edit" />'.      return '<input type="hidden" name="submitted" value="edit" />'.
  &Apache::structuretags::remember_problem_state().'   &Apache::structuretags::remember_problem_state().'
   <div class="LC_edit_problem_header">
   <div class="LC_edit_problem_header_title">
   '.&mt('Problem Editing').&Apache::loncommon::help_open_menu('Problem Editing','Problem_Editor_XML_Index',5,'Authoring').'
   </div>
   <div class="LC_edit_problem_discards">
        <input type="hidden" name="problemmode" value="'.&mt('Edit').'" />         <input type="hidden" name="problemmode" value="'.&mt('Edit').'" />
        <input type="submit" name="problemmode" accesskey="d" value="'.&mt('Discard Edits and View').'" />         <input type="submit" name="problemmode" accesskey="d" value="'.&mt('Discard Edits and View').'" />
        <input '.&Apache::edit::submit_ask_anyway().' type="submit" name="problemmode" accesskey="x" value="'.&mt('EditXML').'" />         <input '.&Apache::edit::submit_ask_anyway().' type="submit" name="problemmode" accesskey="x" value="'.&mt('EditXML').'" />
        <input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" /> <hr />         <input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" />
        <input type="submit" name="submit" accesskey="s" value="'.&mt('Submit Changes and Edit').'" />  </div>
        <input type="submit" name="submit" accesskey="v" value="'.&mt('Submit Changes and View').'" /><table><tr><td>'.  <div class="LC_edit_problem_saves">
        &Apache::loncommon::help_open_menu('Problem Editing Help','Problem_Editor_XML_Index',5,'Authoring',undef,undef,undef,'Problem Editing Help')         <input type="submit" name="submit" accesskey="s" value="'.&mt('Save and Edit').'" />
        .'</td></tr></table>'.         <input type="submit" name="submit" accesskey="v" value="'.&mt('Save and View').'" />
     </div>
   <hr class="LC_edit_problem_divide" />
   </div>
   '.
        '<table border="0" width="100%"><tr><td bgcolor="#DDDDDD">';         '<table border="0" width="100%"><tr><td bgcolor="#DDDDDD">';
 }  }
   
Line 311  sub option { Line 341  sub option {
   
 sub problem_web_to_edit_header {  sub problem_web_to_edit_header {
     my ($rndseed)=@_;      my ($rndseed)=@_;
     my $result.='<input type="hidden" name="problemmode" value="'.&mt('View').'" />';      my $result .= '<div class="LC_edit_problem_header">';
     $result .= '<input type="submit" name="problemmode" accesskey="e" value="'.&mt('Edit').'" />';  
     $result .= '<input type="submit" name="problemmode" accesskey="x" value="'.&mt('EditXML').'" />      if (!$Apache::lonhomework::parsing_a_task) {
              <input type="submit" name="newrandomization" accesskey="a" value="'.&mt('New Randomization').'" />   $result .= 
              <input type="submit" name="resetdata" accesskey="r" value="'.&mt('Reset Submissions').'" />      '<div class="LC_edit_problem_header_title">'.
              <nobr><input type="submit" name="changerandseed" value="'.&mt('Change Random Seed To:').'" />      &mt('Problem Testing').
               <input type="text" name="rndseed" size="10" value="'.      &Apache::loncommon::help_open_topic('Problem_Editor_Testing_Area').
        $rndseed.'"      '</div>';
            onchange="javascript:document.lonhomework.changerandseed.click()" /></nobr>      } else {
              <span class="LC_nobreak"><label><input type="checkbox" name="showallfoils" ';   $result .= 
       '<div class="LC_edit_problem_header_title">'.
       &mt('Task Testing').
       '</div>';
       }
       
     my $show_all_foils_text =       my $show_all_foils_text = 
  ($Apache::lonhomework::parsing_a_task) ?   ($Apache::lonhomework::parsing_a_task) ?
  &mt('&nbsp;Show&nbsp;All&nbsp;Instances')   &mt('&nbsp;Show&nbsp;All&nbsp;Instances')
  : &mt('&nbsp;Show&nbsp;All&nbsp;Foils');   : &mt('&nbsp;Show&nbsp;All&nbsp;Foils');
   
     if (defined($env{'form.showallfoils'})) { $result.='checked="on"'; }      my $show_all= '<span class="LC_nobreak"><label><input type="checkbox" name="showallfoils" ';
     $result.= ' />'.$show_all_foils_text.'</label></span>'.      if (defined($env{'form.showallfoils'})) { $show_all.='checked="checked"'; }
  &Apache::loncommon::help_open_topic('Problem_Editor_Testing_Area','Testing Problems').      $show_all.= ' />'.$show_all_foils_text.'</label></span>';
  '<hr />';  
     $result.=&mt('Apply style file: ').'  
 <input type="text" name="style_file" value="'.&HTML::Entities::encode($env{'construct.style'},'"<>&').'" />  
  <a href="javascript:openbrowser(\'lonhomework\',\'style_file\',\'sty\')">'.&mt('Select').'</a>  
 <input type="submit" name="clear_style_file" value="'.&mt('Clear').'" />  
 <br />';  
   
   
       $result .= '<div class="LC_edit_problem_header_status_row">';
     if (!$Apache::lonhomework::parsing_a_task) {      if (!$Apache::lonhomework::parsing_a_task) {
  $result.="   $result.="
 <nobr>  <div class='LC_edit_problem_header_row1'>
 Problem Status:  <span class=\"LC_nobreak\">
   ".&mt("Problem Status:")."
 <select name='problemstate'>  <select name='problemstate'>
   <option value=''></option>    <option value=''></option>
   ".&option('CLOSED'               ,'problemstate').&mt("Closed")."</option>    ".&option('CLOSED'               ,'problemstate').&mt("Closed")."</option>
Line 348  Problem Status: Line 381  Problem Status:
   ".&option('CANNOT_ANSWER_correct','problemstate').&mt("Open and correct")."</option>    ".&option('CANNOT_ANSWER_correct','problemstate').&mt("Open and correct")."</option>
   ".&option('SHOW_ANSWER'          ,'problemstate').&mt("Show Answer")."</option>    ".&option('SHOW_ANSWER'          ,'problemstate').&mt("Show Answer")."</option>
 </select>  </select>
 </nobr>  </span>
 <nobr>  <span class=\"LC_nobreak\">
 Problem Type:  ".&mt("Problem Type:")."
 <select name='problemtype'>  <select name='problemtype'>
   <option value=''></option>    <option value=''></option>
   ".&option('exam'   ,'problemtype').&mt("Exam Problem")."</option>    ".&option('exam'   ,'problemtype').&mt("Exam Problem")."</option>
   ".&option('problem','problemtype').&mt("Homework problem")."</option>    ".&option('problem','problemtype').&mt("Homework problem")."</option>
   ".&option('survey' ,'problemtype').&mt("Survey Question")."</option>    ".&option('survey' ,'problemtype').&mt("Survey Question")."</option>
 </select>  </select>
 </nobr>  </span>
 <nobr>  $show_all
 Feedback Mode:  </div>
   <div class='LC_edit_problem_header_row2'>
   <span class=\"LC_nobreak\">
   ".&mt("Feedback Mode:")."
 <select name='problemstatus'>  <select name='problemstatus'>
   <option value=''></option>    <option value=''></option>
   ".&option('yes','problemstatus').&mt("Show Feedback")."</option>    ".&option('yes','problemstatus').&mt("Show Feedback")."</option>
   ".&option('no', 'problemstatus').&mt("Don't Show Feedback")."</option>    ".&option('no', 'problemstatus').&mt("Don't Show Incorect/Correct Feedback")."</option>
     ".&option('no_feedback_ever', 'problemstatus').&mt("Don't Show Any Feedback")."</option>
 </select>  </select>
 </nobr>  </span>
 <input type='submit' name='changeproblemmode' value='".&mt("Change")."' />  ";
 <hr />";  
  my $numtoanalyze=$env{'form.numtoanalyze'};  
  if (!$numtoanalyze) { $numtoanalyze=20; }  
  $result.= '<input type="submit" name="problemmode" value='.  
     &mt('"Calculate answers').'" /> for  
              <input type="text" name="numtoanalyze" value="'.  
      $numtoanalyze.'" size="5" /> '.&mt('versions of this problem').  
      '.'.&Apache::loncommon::help_open_topic("Analyze_Problem",  
      '',undef,undef,300).  
      '<hr />';  
     } elsif ($Apache::lonhomework::parsing_a_task) {      } elsif ($Apache::lonhomework::parsing_a_task) {
  $result.="   $result.="
 <nobr>  <div class='LC_edit_problem_header_row1'>
 Problem Status:  <span class=\"LC_nobreak\">
   ".&mt("Problem Status:")."
 <select name='problemstate'>  <select name='problemstate'>
   <option value=''></option>    <option value=''></option>
   ".&option('CLOSED'               ,'problemstate').&mt("Closed")."</option>    ".&option('CLOSED'               ,'problemstate').&mt("Closed")."</option>
Line 388  Problem Status: Line 417  Problem Status:
   ".&option('WEB_GRADE'            ,'problemstate').&mt("Criteria Grading")."</option>    ".&option('WEB_GRADE'            ,'problemstate').&mt("Criteria Grading")."</option>
   ".&option('SHOW_ANSWER'          ,'problemstate').&mt("Show Feedback")."</option>    ".&option('SHOW_ANSWER'          ,'problemstate').&mt("Show Feedback")."</option>
 </select>  </select>
 </nobr>  </span>
 <input type='submit' name='changeproblemmode' value='".&mt("Change")."' />  $show_all
 <hr />";  ";
       }
   
       $result.='
          <span class="LC_nobreak">
          '.&mt('Apply style file: ').'
            <input type="text" name="style_file" value="'.&HTML::Entities::encode($env{'construct.style'},'"<>&').'" />
            <a href="javascript:openbrowser(\'lonhomework\',\'style_file\',\'sty\')">'.&mt('Select').'</a>
          </span>
        </div>
        <input type="submit" name="changeproblemmode" value="'.&mt("Change View").'" />
        <input type="submit" name="clear_style_file" accesskey="d" value="'.&mt('Show Default View').'" />
        <input type="submit" name="resetdata" accesskey="r" value="'.&mt('Reset Submissions').'" />
      </div>
      <hr class="LC_edit_problem_divide" />
      <div class="LC_edit_problem_header_randomize_row">
        <input type="submit" name="newrandomization" accesskey="a" value="'.&mt('New Randomization').'" />
        <input type="submit" name="changerandseed" value="'.&mt('Change Random Seed To:').'" />
        <input type="text" name="rndseed" size="10" value="'.
          $rndseed.'"
                onchange="javascript:document.lonhomework.changerandseed.click()" />';
   
       if (!$Apache::lonhomework::parsing_a_task) {
    my $numtoanalyze=$env{'form.numtoanalyze'};
    if (!$numtoanalyze) { $numtoanalyze=20; }
    $result .= '<span class="LC_nobreak">'.
       &mt('[_1] for [_2] versions.',
    '<input type="submit" name="problemmode" value='.&mt('"Calculate answers').'" />',
    '<input type="text" name="numtoanalyze" value="'.
    $numtoanalyze.'" size="5" />').
    &Apache::loncommon::help_open_topic("Analyze_Problem",'',undef,undef,300).
    '</span>';
       
     }      }
   
       $result.='
      </div>
      <div class="LC_edit_problem_header_edit_row">';
       $result.='<input type="hidden" name="problemmode" value="'.&mt('View').'" />';
       $result .= '<input type="submit" name="problemmode" accesskey="e" value="'.&mt('Edit').'" />';
       $result .= '<input type="submit" name="problemmode" accesskey="x" value="'.&mt('EditXML').'" />';
   
       $result.='
      </div>
   </div>';
     return $result;      return $result;
 }  }
   
Line 555  sub init_problem_globals { Line 627  sub init_problem_globals {
     if ($type eq 'problem') {      if ($type eq 'problem') {
  $Apache::inputtags::part='0';   $Apache::inputtags::part='0';
  @Apache::inputtags::partlist=('0');   @Apache::inputtags::partlist=('0');
  $Apache::lonhomework::problemstatus=&get_problem_status('0');   &Apache::lonhomework::set_show_problem_status(&get_problem_status('0'));
  $Apache::lonhomework::ignore_response_errors=0;   $Apache::lonhomework::ignore_response_errors=0;
   
     } elsif ($type eq 'library') {      } elsif ($type eq 'library') {
  $Apache::inputtags::part='';   $Apache::inputtags::part='';
  @Apache::inputtags::partlist=();   @Apache::inputtags::partlist=();
  $Apache::lonhomework::problemstatus='';   &Apache::lonhomework::reset_show_problem_status();
  $Apache::lonhomework::ignore_response_errors=1;   $Apache::lonhomework::ignore_response_errors=1;
   
     } elsif ($type eq 'Task') {      } elsif ($type eq 'Task') {
  $Apache::inputtags::part='0';   $Apache::inputtags::part='0';
  @Apache::inputtags::partlist=('0');   @Apache::inputtags::partlist=('0');
  $Apache::lonhomework::problemstatus='';   &Apache::lonhomework::reset_show_problem_status();
  $Apache::lonhomework::ignore_response_errors=1;   $Apache::lonhomework::ignore_response_errors=1;
     }      }
     @Apache::inputtags::responselist = ();      @Apache::inputtags::responselist = ();
Line 596  sub reset_problem_globals { Line 668  sub reset_problem_globals {
     undef($Apache::lonhomework::default_type);      undef($Apache::lonhomework::default_type);
     undef($Apache::lonhomework::type);      undef($Apache::lonhomework::type);
     undef($Apache::lonhomework::scantronmode);      undef($Apache::lonhomework::scantronmode);
     undef($Apache::lonhomework::problemstatus);  
     undef($Apache::lonhomework::ignore_response_errors);      undef($Apache::lonhomework::ignore_response_errors);
       &Apache::lonhomework::reset_show_problem_status();
 }  }
   
 sub set_problem_state {  sub set_problem_state {
Line 1143  sub start_languageblock { Line 1215  sub start_languageblock {
  $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {   $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
  my $include = $token->[2]->{'include'};   my $include = $token->[2]->{'include'};
  my $exclude = $token->[2]->{'exclude'};   my $exclude = $token->[2]->{'exclude'};
         my $preferred_language=(&Apache::loncommon::preferred_languages)[0];          my @preferred_languages=&Apache::loncommon::preferred_languages();
 # This should not even happen, since we should at least have the server language  # This should not even happen, since we should at least have the server language
         if (!$preferred_language) { $preferred_language='en'; }          if (!$preferred_languages[0]) { $preferred_languages[0]='en'; }
   # Now loop over all languages in order of preference
           foreach my $preferred_language (@preferred_languages) {
 # If the languageblock has no arguments, show the contents  # If the languageblock has no arguments, show the contents
         $result='1';             $result=1;
              my $found=0;
 # Do we have an include argument?  # Do we have an include argument?
  if ($include) {     if ($include) {
 # If include is specified, by default, don't render the block  # If include is specified, by default, don't render the block
             $result='';                $result=0;
             foreach my $included_language (split(/\,/,$include)) {                foreach my $included_language (split(/\,/,$include)) {
 # ... but if my preferred language is included, render it  # ... but if my preferred language is included, render it
                 if ($included_language eq $preferred_language) { $result='1'; }                   if ($included_language eq $preferred_language) {
             }                      $result=1; 
  }                      $found=1; 
                    }
                 }
      }
 # Do we have an exclude argument?  # Do we have an exclude argument?
         if ($exclude) {             if ($exclude) {
             $result='1';                $result=1;
             foreach my $excluded_language (split(/\,/,$exclude)) {                foreach my $excluded_language (split(/\,/,$exclude)) {
                 if ($excluded_language eq $preferred_language) { $result='0'; }                   if ($excluded_language eq $preferred_language) {
             }                      $result=0;
  }                      $found=1;
                    }
                 }
      }
              if ($found) { last; }
           }
  if ( ! $result ) {   if ( ! $result ) {
     my $skip=&Apache::lonxml::get_all_text("/languageblock",$parser,      my $skip=&Apache::lonxml::get_all_text("/languageblock",$parser,
    $style);     $style);
Line 1456  sub start_part { Line 1539  sub start_part {
     @Apache::inputtags::response=();      @Apache::inputtags::response=();
     @Apache::inputtags::previous=();      @Apache::inputtags::previous=();
     @Apache::inputtags::previous_version=();      @Apache::inputtags::previous_version=();
     $Apache::lonhomework::problemstatus=&get_problem_status($id);      &Apache::lonhomework::set_show_problem_status(&get_problem_status($id));
       &Apache::response::reset_params();
   
     my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);      my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
     my $newtype=&Apache::lonnet::EXT("resource.$id.type");      my $newtype=&Apache::lonnet::EXT("resource.$id.type");
     if ($newtype) { $Apache::lonhomework::type=$newtype; }      if ($newtype) { $Apache::lonhomework::type=$newtype; }
Line 1713  sub start_startouttext { Line 1798  sub start_startouttext {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my @result=(''.'');      my @result=(''.'');
     if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }      if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
       
       my $nesting = 
    &Apache::lonxml::set_state('outtext',
      &Apache::lonxml::get_state('outtext')+1);
       if ($nesting > 1 && $env{'request.state'} eq 'construct') {
    &Apache::lonxml::error("Nesting of &lt;startouttext /&gt; not allowed, on line ".$token->[5]);
       }
     return (@result);      return (@result);
 }  }
   
Line 1752  sub start_endouttext { Line 1844  sub start_endouttext {
  $result='<endouttext />'.   $result='<endouttext />'.
     &Apache::edit::handle_insertafter('startouttext');      &Apache::edit::handle_insertafter('startouttext');
     }      }
   
       my $nesting = 
    &Apache::lonxml::set_state('outtext',
      &Apache::lonxml::get_state('outtext')-1);
       if ($nesting < 0 && $env{'request.state'} eq 'construct') {
    &Apache::lonxml::error(" Extraneous &lt;endouttext /&gt; not allowed on line ".$token->[5]);
    &Apache::lonxml::set_state('outtext', 0);
       }
     return $result;      return $result;
 }  }
   

Removed from v.1.397  
changed lines
  Added in v.1.408


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>