Diff for /loncom/interface/lonhelper.pm between versions 1.54 and 1.55

version 1.54, 2003/10/09 14:37:48 version 1.55, 2003/10/09 15:20:15
Line 172  before parsing XML fragments and B<Apach Line 172  before parsing XML fragments and B<Apach
 when you are done. See lonprintout.pm for examples of this usage in the  when you are done. See lonprintout.pm for examples of this usage in the
 printHelper subroutine.  printHelper subroutine.
   
   =head2 Localization
   
   The helper framework tries to handle as much localization as
   possible. The text is always run through
   Apache::lonlocal::normalize_string, so be sure to run the keys through
   that function for maximum usefulness and robustness.
   
 =cut  =cut
   
 package Apache::lonhelper;  package Apache::lonhelper;
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use Apache::File;  use Apache::File;
 use Apache::lonxml;  use Apache::lonxml;
   use Apache::lonlocal;
   
 # Register all the tags with the helper, so the helper can   # Register all the tags with the helper, so the helper can 
 # push and pop them  # push and pop them
Line 257  sub real_handler { Line 265  sub real_handler {
     # Send header, don't cache this page      # Send header, don't cache this page
     if ($r->header_only) {      if ($r->header_only) {
         if ($ENV{'browser.mathml'}) {          if ($ENV{'browser.mathml'}) {
             $r->content_type('text/xml');              $r->content_type('text/xml; charset=UTF-8');
         } else {          } else {
             $r->content_type('text/html');              $r->content_type('text/html; charset=UTF-8');
         }          }
         $r->send_http_header;          $r->send_http_header;
         return OK;          return OK;
Line 359  sub end_state { Line 367  sub end_state {
 package Apache::lonhelper::helper;  package Apache::lonhelper::helper;
   
 use Digest::MD5 qw(md5_hex);  use Digest::MD5 qw(md5_hex);
 use HTML::Entities;  use HTML::Entities();
 use Apache::loncommon;  use Apache::loncommon;
 use Apache::File;  use Apache::File;
   use Apache::lonlocal;
   
 sub new {  sub new {
     my $proto = shift;      my $proto = shift;
Line 523  sub process { Line 532  sub process {
     # Phase 1: Post processing for state of previous screen (which is actually      # Phase 1: Post processing for state of previous screen (which is actually
     # the "current state" in terms of the helper variables), if it wasn't the       # the "current state" in terms of the helper variables), if it wasn't the 
     # beginning state.      # beginning state.
     if ($self->{STATE} ne "START" || $ENV{"form.SUBMIT"} eq "Next ->") {      if ($self->{STATE} ne "START" || $ENV{"form.SUBMIT"} eq &mt("Next ->")) {
  my $prevState = $self->{STATES}{$self->{STATE}};   my $prevState = $self->{STATES}{$self->{STATE}};
         $prevState->postprocess();          $prevState->postprocess();
     }      }
Line 574  sub display { Line 583  sub display {
     }      }
   
     # Phase 4: Display.      # Phase 4: Display.
     my $stateTitle = $state->title();      my $stateTitle = &mt($state->title());
     my $bodytag = &Apache::loncommon::bodytag("$self->{TITLE}",'','');      my $helperTitle = &mt($self->{TITLE});
       my $bodytag = &Apache::loncommon::bodytag($helperTitle,'','');
       my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"');
       my $next = HTML::Entities::encode(&mt("Next ->"), '<>&"');
       # FIXME: This should be parameterized, not concatenated - Jeremy
       my $loncapaHelper = &mt("LON-CAPA Helper:");
   
     $result .= <<HEADER;      $result .= <<HEADER;
 <html>  <html>
     <head>      <head>
         <title>LON-CAPA Helper: $self->{TITLE}</title>          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
           <title>$loncapaHelper: $helperTitle</title>
     </head>      </head>
     $bodytag      $bodytag
 HEADER  HEADER
Line 607  HEADER Line 622  HEADER
         }          }
         if ($self->{DONE}) {          if ($self->{DONE}) {
             my $returnPage = $self->{RETURN_PAGE};              my $returnPage = $self->{RETURN_PAGE};
             $result .= "<a href=\"$returnPage\">End Helper</a>";              $result .= "<a href=\"$returnPage\">" . &mt("End Helper") . "</a>";
         }          }
         else {          else {
             $result .= '<nobr><input name="back" type="button" ';              $result .= '<nobr><input name="back" type="button" ';
             $result .= 'value="&lt;- Previous" onclick="history.go(-1)" /> ';              $result .= 'value="' . $previous . '" onclick="history.go(-1)" /> ';
             $result .= '<input name="SUBMIT" type="submit" value="Next -&gt;" /></nobr>';              $result .= '<input name="SUBMIT" type="submit" value="' . $next . '" /></nobr>';
         }          }
     }      }
   
Line 626  HEADER Line 641  HEADER
         }          }
         if ($self->{DONE}) {          if ($self->{DONE}) {
             my $returnPage = $self->{RETURN_PAGE};              my $returnPage = $self->{RETURN_PAGE};
             $result .= "<a href=\"$returnPage\">End Helper</a>";              $result .= "<a href=\"$returnPage\">" . &mt('End Helper') . "</a>";
         }          }
         else {          else {
             $result .= '<nobr><input name="back" type="button" ';              $result .= '<nobr><input name="back" type="button" ';
             $result .= 'value="&lt;- Previous" onclick="history.go(-1)" /> ';              $result .= 'value="' . $previous . '" onclick="history.go(-1)" /> ';
             $result .= '<input name="SUBMIT" type="submit" value="Next -&gt;" /></nobr>';              $result .= '<input name="SUBMIT" type="submit" value="' . $next . '" /></nobr>';
         }          }
     }      }
   
Line 883  sub start_defaultvalue { Line 898  sub start_defaultvalue {
   
 sub end_defaultvalue { return ''; }  sub end_defaultvalue { return ''; }
   
   # Validators may need to take language specifications
 sub start_validator {  sub start_validator {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   
Line 952  within each other.) Line 968  within each other.)
 This is also a good template for creating your own new states, as it has  This is also a good template for creating your own new states, as it has
 very little code beyond the state template.  very little code beyond the state template.
   
   =head3 Localization
   
   The contents of the message tag will be run through the
   normalize_string function and that will be used as a call to &mt.
   
 =cut  =cut
   
 no strict;  no strict;
 @ISA = ("Apache::lonhelper::element");  @ISA = ("Apache::lonhelper::element");
 use strict;  use strict;
   use Apache::lonlocal;
   
 BEGIN {  BEGIN {
     &Apache::lonhelper::register('Apache::lonhelper::message',      &Apache::lonhelper::register('Apache::lonhelper::message',
Line 998  sub end_message { Line 1020  sub end_message {
 sub render {  sub render {
     my $self = shift;      my $self = shift;
   
     return $self->{MESSAGE_TEXT};      return &mtn($self->{MESSAGE_TEXT});
 }  }
 # If a NEXTSTATE was given, switch to it  # If a NEXTSTATE was given, switch to it
 sub postprocess {  sub postprocess {
Line 1100  tag is stored in the {VARS} hash. Line 1122  tag is stored in the {VARS} hash.
 no strict;  no strict;
 @ISA = ("Apache::lonhelper::element");  @ISA = ("Apache::lonhelper::element");
 use strict;  use strict;
   use Apache::lonlocal;
   
 BEGIN {  BEGIN {
     &Apache::lonhelper::register('Apache::lonhelper::choices',      &Apache::lonhelper::register('Apache::lonhelper::choices',
Line 1253  BUTTONS Line 1276  BUTTONS
             $choiceLabel = eval($choiceLabel);              $choiceLabel = eval($choiceLabel);
             $choiceLabel = &$choiceLabel($helper, $self);              $choiceLabel = &$choiceLabel($helper, $self);
         }          }
         $result .= "/></td><td> " . $choiceLabel . "</td></tr>\n";          $result .= "/></td><td> " . &mtn($choiceLabel) . "</td></tr>\n";
     }      }
     $result .= "</table>\n\n\n";      $result .= "</table>\n\n\n";
     $result .= $buttons;      $result .= $buttons;
Line 1312  the result is stored in. Line 1335  the result is stored in.
   
 =cut  =cut
   
   # This really ought to be a sibling class to "choice" which is itself
   # a child of some abstract class.... *shrug*
   
 no strict;  no strict;
 @ISA = ("Apache::lonhelper::element");  @ISA = ("Apache::lonhelper::element");
 use strict;  use strict;
   use Apache::lonlocal;
   
 BEGIN {  BEGIN {
     &Apache::lonhelper::register('Apache::lonhelper::dropdown',      &Apache::lonhelper::register('Apache::lonhelper::dropdown',
Line 1404  sub render { Line 1431  sub render {
             $choiceLabel = eval($choiceLabel);              $choiceLabel = eval($choiceLabel);
             $choiceLabel = &$choiceLabel($helper, $self);              $choiceLabel = &$choiceLabel($helper, $self);
         }          }
         $result .= ">" . $choiceLabel . "\n";          $result .= ">" . &mtn($choiceLabel) . "\n";
     }      }
     $result .= "</select>\n";      $result .= "</select>\n";
   
Line 1473  Example: Line 1500  Example:
 no strict;  no strict;
 @ISA = ("Apache::lonhelper::element");  @ISA = ("Apache::lonhelper::element");
 use strict;  use strict;
   use Apache::lonlocal; # A localization nightmare
   
 use Time::localtime;  use Time::localtime;
   
Line 1537  sub render { Line 1565  sub render {
         } else {          } else {
             $result .= "<option value='$i'>";              $result .= "<option value='$i'>";
         }          }
         $result .= $months[$i] . "</option>\n";          $result .= &mt($months[$i]) . "</option>\n";
     }      }
     $result .= "</select>\n";      $result .= "</select>\n";
   
Line 1624  sub postprocess { Line 1652  sub postprocess {
         $hour = $ENV{'form.' . $var . 'hour'};          $hour = $ENV{'form.' . $var . 'hour'};
     }      }
   
     my $chosenDate = Time::Local::timelocal(0, $min, $hour, $day, $month, $year);      my $chosenDate;
       eval {$chosenDate = Time::Local::timelocal(0, $min, $hour, $day, $month, $year);};
       my $error = $@;
   
     # Check to make sure that the date was not automatically co-erced into a       # Check to make sure that the date was not automatically co-erced into a 
     # valid date, as we want to flag that as an error      # valid date, as we want to flag that as an error
     # This happens for "Feb. 31", for instance, which is coerced to March 2 or      # This happens for "Feb. 31", for instance, which is coerced to March 2 or
     # 3, depending on if it's a leapyear      # 3, depending on if it's a leap year
     my $checkDate = localtime($chosenDate);      my $checkDate = localtime($chosenDate);
   
     if ($checkDate->mon != $month || $checkDate->mday != $day ||      if ($error || $checkDate->mon != $month || $checkDate->mday != $day ||
         $checkDate->year + 1900 != $year) {          $checkDate->year + 1900 != $year) {
    unless (Apache::lonlocal::current_language()== ~/^en/) {
       $self->{ERROR_MSG} = &mt("Invalid date entry");
       return 0;
    }
    # LOCALIZATION FIXME: Needs to be parameterized
         $self->{ERROR_MSG} = "Can't use " . $months[$month] . " $day, $year as a "          $self->{ERROR_MSG} = "Can't use " . $months[$month] . " $day, $year as a "
             . "date because it doesn't exist. Please enter a valid date.";              . "date because it doesn't exist. Please enter a valid date.";
   
         return 0;          return 0;
     }      }
   
Line 2044  sub render { Line 2081  sub render {
             }              }
         }          }
     }      }
     function checksec(value) {      function checksec() {
  for (i=0; i<document.forms.helpform.elements.length; i++) {   for (i=0; i<document.forms.helpform.elements.length; i++) {
     comp = document.forms.helpform.elements.chksec.value;      comp = document.forms.helpform.elements.chksec.value;
             if (document.forms.helpform.elements[i].value.indexOf(':'+comp+':') != -1) {              if (document.forms.helpform.elements[i].value.indexOf(':'+comp+':') != -1) {
                 document.forms.helpform.elements[i].checked=value;                  document.forms.helpform.elements[i].checked=true;
             }              }
         }          }
     }      }
Line 2066  SCRIPT Line 2103  SCRIPT
 <input type="button" onclick="checkactive()" value="Select Only Current Students" />  <input type="button" onclick="checkactive()" value="Select Only Current Students" />
 <input type="button" onclick="checkall(true, '$var')" value="Select All Students" />  <input type="button" onclick="checkall(true, '$var')" value="Select All Students" />
 <input type="button" onclick="checkall(false, '$var')" value="Unselect All Students" />  <input type="button" onclick="checkall(false, '$var')" value="Unselect All Students" />
 <br />  <input type="button" onclick="checksec()" value="Check for Section/Group">
 <input type="button" onclick="checksec(true)" value="Select for Section/Group">  
 <input type="text" size="5" name="chksec">&nbsp;  <input type="text" size="5" name="chksec">&nbsp;
 <input type="button" onclick="checksec(false)" value="Unselect for Section/Group">  
   
 <br />  <br />
 BUTTONS  BUTTONS
     }      }

Removed from v.1.54  
changed lines
  Added in v.1.55


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