Diff for /loncom/homework/lonhomework.pm between versions 1.277 and 1.283

version 1.277, 2007/10/17 00:22:51 version 1.283, 2007/11/10 01:38:21
Line 49  use Apache::matchresponse(); Line 49  use Apache::matchresponse();
 use Apache::chemresponse();  use Apache::chemresponse();
 use Apache::drawimage();  use Apache::drawimage();
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use HTML::Entities();  
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonlocal;  use Apache::lonlocal;
 use Time::HiRes qw( gettimeofday tv_interval );  use Time::HiRes qw( gettimeofday tv_interval );
 use Apache::lonnet();  use HTML::Entities();
   use File::Copy();
   
 # FIXME - improve commenting  # FIXME - improve commenting
   
Line 149  sub get_target { Line 149  sub get_target {
     } elsif ( $env{'form.problemmode'} eq &mt('Edit') ||      } elsif ( $env{'form.problemmode'} eq &mt('Edit') ||
       $env{'form.problemmode'} eq 'Edit') {        $env{'form.problemmode'} eq 'Edit') {
  if ( $env{'form.submitted'} eq 'edit' ) {   if ( $env{'form.submitted'} eq 'edit' ) {
     if ( $env{'form.submit'} eq &mt('Submit Changes and View') ) {      if ( $env{'form.submit'} eq &mt('Save and View') ) {
  return ('modified','web','answer');   return ('modified','web','answer');
     } else {      } else {
  return ('modified','no_output_web','edit');   return ('modified','no_output_web','edit');
Line 543  sub due_date { Line 543  sub due_date {
  &Apache::lonxml::debug("looking for first_access $first_access");   &Apache::lonxml::debug("looking for first_access $first_access");
  if (defined($first_access)) {   if (defined($first_access)) {
     $interval = $first_access+$interval;      $interval = $first_access+$interval;
     $date = ($interval < $due_date)? $interval : $due_date;      $date = (!$due_date || $interval < $due_date) ? $interval
                                                             : $due_date;
  } else {   } else {
     $date = $due_date;      $date = $due_date;
  }   }
Line 746  sub analyze_header { Line 747  sub analyze_header {
             <form name="lonhomework" method="POST" action="'.              <form name="lonhomework" method="POST" action="'.
     &HTML::Entities::encode($env{'request.uri'},'<>&"').'">'.      &HTML::Entities::encode($env{'request.uri'},'<>&"').'">'.
     &Apache::structuretags::remember_problem_state().'      &Apache::structuretags::remember_problem_state().'
               <div class="LC_edit_problem_analyze_header">
             <input type="submit" name="problemmode" value="'.&mt("EditXML").'" />              <input type="submit" name="problemmode" value="'.&mt("EditXML").'" />
             <input type="submit" name="problemmode" value="'.&mt('Edit').'" />              <input type="submit" name="problemmode" value="'.&mt('Edit').'" />
             <hr />              <hr class="LC_edit_problem_divide" />
   
             <input type="submit" name="submit" value="'.&mt("View").'" />              <input type="submit" name="submit" value="'.&mt("View").'" />
             <hr />              <hr class="LC_edit_problem_divide" />
               </div>
             </form>';              </form>';
     &Apache::lonxml::add_messages(\$result);      &Apache::lonxml::add_messages(\$result);
     $request->print($result);      $request->print($result);
Line 823  sub analyze { Line 827  sub analyze {
     }      }
     &Apache::lonhtmlcommon::Update_PrgWin($request,\%prog_state,      &Apache::lonhtmlcommon::Update_PrgWin($request,\%prog_state,
   &mt('Analyzing Results'));    &mt('Analyzing Results'));
     $request->print('<hr />'.&mt('List of possible answers').': ');      $request->print('<hr class="LC_edit_problem_divide" />'.&mt('List of possible answers').': ');
     foreach my $part (sort(keys(%allparts))) {      foreach my $part (sort(keys(%allparts))) {
  if (defined(@{ $overall{$part.'.answer'} })) {   if (defined(@{ $overall{$part.'.answer'} })) {
     for (my $i=0;$i<scalar(@{ $overall{$part.'.answer'} });$i++) {      for (my $i=0;$i<scalar(@{ $overall{$part.'.answer'} });$i++) {
Line 906  sub editxmlmode { Line 910  sub editxmlmode {
  if (!$error) { $problem=&Apache::lonnet::getfile($file); }   if (!$error) { $problem=&Apache::lonnet::getfile($file); }
     }      }
     &Apache::lonhomework::showhashsubset(\%env,'^form');      &Apache::lonhomework::showhashsubset(\%env,'^form');
     if ( $env{'form.submit'} eq &mt('Submit Changes and View') ) {      if ( $env{'form.submit'} eq &mt('Save and View') ) {
  &Apache::lonhomework::showhashsubset(\%env,'^form');   &Apache::lonhomework::showhashsubset(\%env,'^form');
  $env{'form.problemmode'}='View';   $env{'form.problemmode'}='View';
  &renderpage($request,$file);   &renderpage($request,$file);
Line 936  sub editxmlmode { Line 940  sub editxmlmode {
   
  $result.=$start_page.   $result.=$start_page.
     &renderpage($request,$file,['no_output_web'],1).      &renderpage($request,$file,['no_output_web'],1).
     &Apache::lonxml::message_location().'              '<form '.&Apache::edit::form_change_detection().' name="lonhomework" method="POST" action="'.
             <form '.&Apache::edit::form_change_detection().' name="lonhomework" method="POST" action="'.  
     &HTML::Entities::encode($env{'request.uri'},'<>&"').'">'.      &HTML::Entities::encode($env{'request.uri'},'<>&"').'">'.
     &Apache::structuretags::remember_problem_state().'      &Apache::structuretags::remember_problem_state().'
             <input type="hidden" name="problemmode" value="'.&mt('EditXML').'" />              <div class="LC_edit_problem_editxml_header">
             <input type="submit" name="problemmode" accesskey="d" value="'.&mt('Discard Edits and View').'" />                <table class="LC_edit_problem_header_title"><tr><td>
             <input type="submit" '.&Apache::edit::submit_ask_anyway().'name="problemmode" accesskey="e" value="'.&mt('Edit').'" />                 '.&mt('Problem Editing').&Apache::loncommon::help_open_topic('Problem_Editor_XML_Index').'
             <input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" />                  </td><td align="right">
             <hr />                    '.&Apache::loncommon::helpLatexCheatsheet().'
             <input type="submit" name="submit" accesskey="s" value="'.&mt('Submit Changes').'" />                  </td></tr>
             <input type="submit" name="submit" accesskey="v" value="'.&mt('Submit Changes and View').'" />                </table>
             <hr />                <div class="LC_edit_problem_discards">
             ' . $xml_help . '                  <input type="hidden" name="problemmode" value="'.&mt('EditXML').'" />
                   <input type="submit" name="problemmode" accesskey="d" value="'.&mt('Discard Edits and View').'" />
                   <input type="submit" '.&Apache::edit::submit_ask_anyway().'name="problemmode" accesskey="e" value="'.&mt('Edit').'" />
                   <input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" />
                 </div>
                 <div class="LC_edit_problem_saves">
                   <input type="submit" name="submit" accesskey="s" value="'.&mt('Save').'" />
                   <input type="submit" name="submit" accesskey="v" value="'.&mt('Save and View').'" />
                 </div>
                 <hr class="LC_edit_problem_divide" />
         '.&Apache::lonxml::message_location().'
               </div>
               '  . '
             <textarea '.&Apache::edit::element_change_detection().              <textarea '.&Apache::edit::element_change_detection().
               ' rows="'.$rows.'" cols="'.$cols.'" style="width:100%" '.                ' rows="'.$rows.'" cols="'.$cols.'" style="width:100%" '.
       ' name="editxmltext" id="LC_editxmltext">'.        ' name="editxmltext" id="LC_editxmltext">'.
       &HTML::Entities::encode($problem,'<>&"').'</textarea>        &HTML::Entities::encode($problem,'<>&"').'</textarea>
             <div id="LC_aftertextarea">              <div id="LC_aftertextarea">
                 <input type="submit" name="submit" accesskey="s" value="'.&mt('Submit Changes').'" />  
                 <input type="submit" name="submit" accesskey="v" value="'.&mt('Submit Changes and View').'" />  
             </div>              </div>
             </form>'.&Apache::loncommon::end_page();              </form>'.&Apache::loncommon::end_page();
  &Apache::lonxml::add_messages(\$result);   &Apache::lonxml::add_messages(\$result);
Line 1047  sub finished_parsing { Line 1060  sub finished_parsing {
     undef($Apache::lonhomework::parsing_a_task);      undef($Apache::lonhomework::parsing_a_task);
 }  }
   
 # with no arg it returns a HTML <option> list of the template titles  
 # with one arg it returns the filename associated with the arg passed  
 sub get_template_list {  sub get_template_list {
     my ($namewanted,$extension) = @_;      my ($extension) = @_;
     my $result;      my $result;
     my @allnames;      my @allnames;
     &Apache::lonxml::debug("Looking for :$extension:");      &Apache::lonxml::debug("Looking for :$extension:");
     foreach my $file (</home/httpd/html/res/adm/includes/templates/*.$extension>) {      my $glob_extension  = $extension;
  &Apache::lonxml::debug("Looking at $file");      if ($extension eq 'survey' || $extension eq 'exam') {
  my $name=&Apache::lonnet::metadata($file,'title');   $glob_extension = 'problem';
  &Apache::lonxml::debug("Got a name $name");      }
  if ($namewanted && ($name eq $namewanted)) {      my @files = glob($Apache::lonnet::perlvar{'lonIncludes'}.
     $result=$file;       '/templates/*.'.$glob_extension);
     last;      @files = map {[$_,&mt(&Apache::lonnet::metadata($_, 'title'))]} (@files);
  } else {      @files = sort {$a->[1] cmp $b->[1]} (@files);
     if ($name) { push (@allnames, $name); }      foreach my $file (@files) {
  }   next if ($file->[1] !~ /\S/);
     }   $result .=
     if (@allnames && !$result) {      '<label><input type="radio" name="template" value="'.$file->[0].'" />'.
  $result="<option>".&mt("Select a")." $extension ".&mt('template')."</option>\n<option>".      $file->[1].'</label><br />';
     join('</option><option>',sort(@allnames)).'</option>';  
     }      }
     return $result;      return $result;
 }  }
   
 sub newproblem {  sub newproblem {
     my ($request) = @_;      my ($request) = @_;
     my $extension=$request->uri;  
     $extension=~s:^.*\.([\w]+)$:$1:;      if ($env{'form.template'}) {
     &Apache::lonxml::debug("Looking for :$extension:");   my $file = $env{'form.template'};
     my $templatelist=&get_template_list('',$extension);  
     if ($env{'form.template'} &&  
  $env{'form.template'} ne "Select a $extension template") {  
  use File::Copy;  
  my $file = &get_template_list($env{'form.template'},$extension);  
  my $dest = &Apache::lonnet::filelocation("",$request->uri);   my $dest = &Apache::lonnet::filelocation("",$request->uri);
  copy($file,$dest);   &File::Copy::copy($file,$dest);
  &renderpage($request,$dest);   &renderpage($request,$dest);
     } elsif($env{'form.newfile'} && !$templatelist) {   return;
  # I don't like hard-coded filenames but for now, this will work.      }
  use File::Copy;  
       my ($extension) = ($request->uri =~ m/\.(\w+)$/);
       &Apache::lonxml::debug("Looking for :$extension:");
       my $templatelist=&get_template_list($extension);
       if ($env{'form.newfile'} && !$templatelist) {
    # no templates found
  my $templatefilename =   my $templatefilename =
     $request->dir_config('lonIncludes').'/templates/blank.'.$extension;      $request->dir_config('lonIncludes').'/templates/blank.'.$extension;
  &Apache::lonxml::debug("$templatefilename");   &Apache::lonxml::debug("$templatefilename");
  my $dest = &Apache::lonnet::filelocation("",$request->uri);   my $dest = &Apache::lonnet::filelocation("",$request->uri);
  copy($templatefilename,$dest);   &File::Copy::copy($templatefilename,$dest);
  &renderpage($request,$dest);   &renderpage($request,$dest);
     } else {      } else {
  my $url=&HTML::Entities::encode($request->uri,'<>&"');   my $url=&HTML::Entities::encode($request->uri,'<>&"');
Line 1100  sub newproblem { Line 1110  sub newproblem {
  $shownurl=~s-^/~-/priv/-;   $shownurl=~s-^/~-/priv/-;
  my $dest = &Apache::lonnet::filelocation("",$request->uri);   my $dest = &Apache::lonnet::filelocation("",$request->uri);
  my $errormsg;   my $errormsg;
  if ($env{'form.newfile'}) {  
     $errormsg='<p><span class="LC_error">'.&mt('You did not select a template.').'</span></p>'."\n";  
  }  
  my $instructions;   my $instructions;
  my $start_page =    my $start_page = 
     &Apache::loncommon::start_page("Create New $extension");      &Apache::loncommon::start_page("Create New $extension");
Line 1115  $errormsg Line 1122  $errormsg
 <p>  <p>
 <b>  <b>
 ".&mt("To create a new $extension, select a template from the".  ".&mt("To create a new $extension, select a template from the".
       "pull-down menu below. Then click on the \"Create $extension\" button.")."</b>        " list below. Then click on the \"Create $extension\" button.")."</b>
 </p><form action=\"$url\" method=\"POST\">");  </p><form action=\"$url\" method=\"POST\">");
   
  if (defined($templatelist)) {   if (defined($templatelist)) {
     $request->print("<select name=\"template\">$templatelist</select>");      $request->print($templatelist);
  }   }
  $request->print("<br /><input type=\"submit\" name=\"newfile\" value=\"".&mt('Create')." $extension\" />");   $request->print('<br /><input type="submit" name="newfile" value="'.
    &mt("Create $extension").'" />');
  $request->print("</form></p>".&Apache::loncommon::end_page());   $request->print("</form></p>".&Apache::loncommon::end_page());
     }      }
     return '';      return;
 }  }
   
 sub update_construct_style {  sub update_construct_style {

Removed from v.1.277  
changed lines
  Added in v.1.283


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