Diff for /loncom/interface/lonhelper.pm between versions 1.114 and 1.128

version 1.114, 2005/09/28 19:02:02 version 1.128, 2005/11/22 12:49:50
Line 1536  sub start_date { Line 1536  sub start_date {
     $paramHash->{'variable'} = $token->[2]{'variable'};      $paramHash->{'variable'} = $token->[2]{'variable'};
     $helper->declareVar($paramHash->{'variable'});      $helper->declareVar($paramHash->{'variable'});
     $paramHash->{'hoursminutes'} = $token->[2]{'hoursminutes'};      $paramHash->{'hoursminutes'} = $token->[2]{'hoursminutes'};
       $paramHash->{'anytime'} = $token->[2]{'anytime'};
 }  }
   
 sub end_date {  sub end_date {
Line 1554  sub render { Line 1555  sub render {
     my $var = $self->{'variable'};      my $var = $self->{'variable'};
   
     my $date;      my $date;
       
       my $time=time;
       my ($anytime,$onclick);
   
       if (defined($self->{DEFAULT_VALUE})) {
           my $valueFunc = eval($self->{DEFAULT_VALUE});
           die('Error in default value code for variable ' . 
               $self->{'variable'} . ', Perl said: ' . $@) if $@;
           $time = &$valueFunc($helper, $self);
    if (lc($time) eq 'anytime') { $time=time; $anytime=1; }
       }
       if ($anytime) {
    $onclick = "onclick=\"javascript:updateCheck(this.form,'${var}anytime',false)\"";
       }
     # Default date: The current hour.      # Default date: The current hour.
     $date = localtime();      $date = localtime($time);
     $date->min(0);      $date->min(0);
   
     if (defined $self->{ERROR_MSG}) {      if (defined $self->{ERROR_MSG}) {
Line 1565  sub render { Line 1579  sub render {
   
     # Month      # Month
     my $i;      my $i;
     $result .= "<select name='${var}month'>\n";      $result .= "<select $onclick name='${var}month'>\n";
     for ($i = 0; $i < 12; $i++) {      for ($i = 0; $i < 12; $i++) {
         if ($i == $date->mon) {          if ($i == $date->mon) {
             $result .= "<option value='$i' selected='selected'>";              $result .= "<option value='$i' selected='selected'>";
Line 1577  sub render { Line 1591  sub render {
     $result .= "</select>\n";      $result .= "</select>\n";
   
     # Day      # Day
     $result .= "<select name='${var}day'>\n";      $result .= "<select $onclick name='${var}day'>\n";
     for ($i = 1; $i < 32; $i++) {      for ($i = 1; $i < 32; $i++) {
         if ($i == $date->mday) {          if ($i == $date->mday) {
             $result .= '<option selected="selected">';              $result .= '<option selected="selected">';
Line 1589  sub render { Line 1603  sub render {
     $result .= "</select>,\n";      $result .= "</select>,\n";
   
     # Year      # Year
     $result .= "<select name='${var}year'>\n";      $result .= "<select $onclick name='${var}year'>\n";
     for ($i = 2000; $i < 2030; $i++) { # update this after 64-bit dates      for ($i = 2000; $i < 2030; $i++) { # update this after 64-bit dates
         if ($date->year + 1900 == $i) {          if ($date->year + 1900 == $i) {
             $result .= "<option selected='selected'>";              $result .= "<option selected='selected'>";
Line 1606  sub render { Line 1620  sub render {
  my $am = &mt('a.m.');   my $am = &mt('a.m.');
  my $pm = &mt('p.m.');   my $pm = &mt('p.m.');
         # Build hour          # Build hour
         $result .= "<select name='${var}hour'>\n";          $result .= "<select $onclick name='${var}hour'>\n";
         $result .= "<option " . ($date->hour == 0 ? 'selected="selected" ':'') .          $result .= "<option " . ($date->hour == 0 ? 'selected="selected" ':'') .
             " value='0'>" . &mt('midnight') . "</option>\n";              " value='0'>" . &mt('midnight') . "</option>\n";
         for ($i = 1; $i < 12; $i++) {          for ($i = 1; $i < 12; $i++) {
Line 1629  sub render { Line 1643  sub render {
   
         $result .= "</select> :\n";          $result .= "</select> :\n";
   
         $result .= "<select name='${var}minute'>\n";          $result .= "<select $onclick name='${var}minute'>\n";
         for ($i = 0; $i < 60; $i++) {   my $selected=0;
           for my $i ((0,15,30,45,59,undef,0..59)) {
             my $printedMinute = $i;              my $printedMinute = $i;
             if ($i < 10) {              if (defined($i) && $i < 10) {
                 $printedMinute = "0" . $printedMinute;                  $printedMinute = "0" . $printedMinute;
             }              }
             if ($date->min == $i) {              if (!$selected && $date->min == $i) {
                 $result .= "<option selected='selected'>";                  $result .= "<option selected='selected'>";
    $selected=1;
             } else {              } else {
                 $result .= "<option>";                  $result .= "<option>";
             }              }
Line 1644  sub render { Line 1660  sub render {
         }          }
         $result .= "</select>\n";          $result .= "</select>\n";
     }      }
       if ($self->{'anytime'}) {
    $result.=(<<CHECK);
   <script type="text/javascript">
   // <!--
       function updateCheck(form,name,value) {
    var checkbox=form[name];
    checkbox.checked = value;
       }
   // -->
   </script>
   CHECK
    $result.="&nbsp;or&nbsp;<label><input type='checkbox' ";
    if ($anytime) {
       $result.=' checked="checked" '
    }
    $result.="name='${var}anytime'/>".&mt('Anytime').'</label>'
       }
     return $result;      return $result;
   
 }  }
Line 1652  sub render { Line 1684  sub render {
 sub postprocess {  sub postprocess {
     my $self = shift;      my $self = shift;
     my $var = $self->{'variable'};      my $var = $self->{'variable'};
     my $month = $env{'form.' . $var . 'month'};       if ($env{'form.' . $var . 'anytime'}) {
     my $day = $env{'form.' . $var . 'day'};    $helper->{VARS}->{$var} = undef;
     my $year = $env{'form.' . $var . 'year'};       } else {
     my $min = 0;    my $month = $env{'form.' . $var . 'month'}; 
     my $hour = 0;   my $day = $env{'form.' . $var . 'day'}; 
     if ($self->{'hoursminutes'}) {   my $year = $env{'form.' . $var . 'year'}; 
         $min = $env{'form.' . $var . 'minute'};   my $min = 0; 
         $hour = $env{'form.' . $var . 'hour'};   my $hour = 0;
     }   if ($self->{'hoursminutes'}) {
       $min = $env{'form.' . $var . 'minute'};
       $hour = $env{'form.' . $var . 'hour'};
    }
   
    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 
    # 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
    # 3, depending on if it's a leap year
    my $checkDate = localtime($chosenDate);
   
    if ($error || $checkDate->mon != $month || $checkDate->mday != $day ||
       $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 "
    . "date because it doesn't exist. Please enter a valid date.";
   
     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   
     # 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  
     # 3, depending on if it's a leap year  
     my $checkDate = localtime($chosenDate);  
   
     if ($error || $checkDate->mon != $month || $checkDate->mday != $day ||  
         $checkDate->year + 1900 != $year) {  
  unless (Apache::lonlocal::current_language()== ~/^en/) {  
     $self->{ERROR_MSG} = &mt("Invalid date entry");  
     return 0;      return 0;
  }   }
  # LOCALIZATION FIXME: Needs to be parameterized   $helper->{VARS}->{$var} = $chosenDate;
         $self->{ERROR_MSG} = "Can't use " . $months[$month] . " $day, $year as a "  
             . "date because it doesn't exist. Please enter a valid date.";  
   
         return 0;  
     }      }
   
     $helper->{VARS}->{$var} = $chosenDate;  
   
     if (defined($self->{NEXTSTATE})) {      if (defined($self->{NEXTSTATE})) {
         $helper->changeState($self->{NEXTSTATE});          $helper->changeState($self->{NEXTSTATE});
     }      }
Line 1982  BUTTONS Line 2017  BUTTONS
  $mapUrl = $self->{MAP_URL};   $mapUrl = $self->{MAP_URL};
     }      }
   
       my %defaultSymbs;
       if (defined($self->{DEFAULT_VALUE})) {
           my $valueFunc = eval($self->{DEFAULT_VALUE});
           die 'Error in default value code for variable ' . 
               $self->{'variable'} . ', Perl said: ' . $@ if $@;
           my @defaultSymbs = &$valueFunc($helper, $self);
    if (!$multichoice && @defaultSymbs) { # only allowed 1
       @defaultSymbs = ($defaultSymbs[0]);
    }
    %defaultSymbs = map { if ($_) {($_,1) } } @defaultSymbs;
    delete($defaultSymbs{''});
       }
   
     # Create the composite function that renders the column on the nav map      # Create the composite function that renders the column on the nav map
     # have to admit any language that lets me do this can't be all bad      # have to admit any language that lets me do this can't be all bad
Line 2030  BUTTONS Line 2077  BUTTONS
     }      }
   
             $col .= "<td align='center'><input type='$inputType' name='${var}.forminput' ";              $col .= "<td align='center'><input type='$inputType' name='${var}.forminput' ";
             if (!$checked && !$multichoice) {      if (%defaultSymbs) {
                 $col .= "checked='checked' ";   my $symb=$resource->symb();
                 $checked = 1;   if (exists($defaultSymbs{$symb})) {
             }      $col .= "checked='checked' ";
     if ($multichoice) { # all resources start checked; see bug 1174      $checked = 1;
  $col .= "checked='checked' ";   }
  $checked = 1;      } else {
    if (!$checked && !$multichoice) {
       $col .= "checked='checked' ";
       $checked = 1;
    }
    if ($multichoice) { # all resources start checked; see bug 1174
       $col .= "checked='checked' ";
       $checked = 1;
    }
     }      }
             $col .= "value='" . $resource_name  . "' /></td>";              $col .= "value='" . $resource_name  . "' /></td>";
   
Line 2154  selection. Defaults to false. Line 2209  selection. Defaults to false.
 If true, only active students and course personnel will be  If true, only active students and course personnel will be
 shown. Defaults to false.  shown. Defaults to false.
   
   =item * B<emptyallowed>:
   
   If true, the selection of no users is allowed. Defaults to false.
   
 =back  =back
   
 =cut  =cut
Line 2189  sub start_student { Line 2248  sub start_student {
     if (defined($token->[2]{'nextstate'})) {      if (defined($token->[2]{'nextstate'})) {
         $paramHash->{NEXTSTATE} = $token->[2]{'nextstate'};          $paramHash->{NEXTSTATE} = $token->[2]{'nextstate'};
     }      }
       $paramHash->{'emptyallowed'} = $token->[2]{'emptyallowed'};
           
 }      }    
   
Line 2257  sub render { Line 2317  sub render {
         numSections  = document.forms.helpform.chosensections.length;          numSections  = document.forms.helpform.chosensections.length;
  desiredState = getDesiredState();   desiredState = getDesiredState();
   
  for (option = 0; option , numSections; option++) {   for (var option = 0; option < numSections; option++) {
     if(document.forms.helpform.chosensections.options[option].selected) {      if(document.forms.helpform.chosensections.options[option].selected) {
  section = document.forms.helpform.chosensections.options[option].text;   section = document.forms.helpform.chosensections.options[option].text;
  if (section == "Staff") {   // Staff are indicated by an empty section.   if (section == "none") {
     section ="";      section ="";
  }   }
  for (i = 0; i < document.forms.helpform.elements.length; i++ ) {   for (i = 0; i < document.forms.helpform.elements.length; i++ ) {
Line 2268  sub render { Line 2328  sub render {
  info = document.forms.helpform.elements[i].value.split(':');   info = document.forms.helpform.elements[i].value.split(':');
  hisSection = info[2];   hisSection = info[2];
  hisState   = info[4];   hisState   = info[4];
                         if((hisSection == section)  && ((desiredState ==hisState) ||  (section =="") || (desiredState == "All"))) {   if (desiredState == hisState ||
     document.forms.helpform.elements[i].checked = value;      desiredState == "All") {
       if(hisSection == section ||
          section =="" ) {
    document.forms.helpform.elements[i].checked = value;
       }
  }   }
     }      }
  }   }
Line 2306  BUTTONS Line 2370  BUTTONS
         $result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />';          $result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />';
     }      }
   
       my %defaultUsers;
       if (defined($self->{DEFAULT_VALUE})) {
           my $valueFunc = eval($self->{DEFAULT_VALUE});
           die 'Error in default value code for variable ' . 
               $self->{'variable'} . ', Perl said: ' . $@ if $@;
           my @defaultUsers = &$valueFunc($helper, $self);
    if (!$self->{'multichoice'} && @defaultUsers) { # only allowed 1
       @defaultUsers = ($defaultUsers[0]);
    }
    %defaultUsers = map { if ($_) {($_,1) } } @defaultUsers;
    delete($defaultUsers{''});
       }
     my $choices = [];      my $choices = [];
   
     # Load up the non-students, if necessary      # Load up the non-students, if necessary
Line 2371  BUTTONS Line 2447  BUTTONS
         $result .= "<tr><td><input type='$type' name='" .          $result .= "<tr><td><input type='$type' name='" .
             $self->{'variable'} . '.forminput' . "'";              $self->{'variable'} . '.forminput' . "'";
                           
         if (!$self->{'multichoice'} && !$checked) {   if (%defaultUsers) {
       my $user=$choice->[0];
       if (exists($defaultUsers{$user})) {
    $result .= " checked='checked' ";
    $checked = 1;
       }
    } elsif (!$self->{'multichoice'} && !$checked) {
             $result .= " checked='checked' ";              $result .= " checked='checked' ";
             $checked = 1;              $checked = 1;
         }          }
Line 2397  BUTTONS Line 2479  BUTTONS
     $result .= $buttons;         $result .= $buttons;   
     #      #
     #  now add the fancy section choice... first enumerate the sections:      #  now add the fancy section choice... first enumerate the sections:
       if ($self->{'multichoice'}) {
    my %sections;
    for my $key (@keys) {
       my $section_name = $classlist->{$key}->[$section];
       if ($section_name ne "") {
    $sections{$section_name} = 1;
       }
    }
    #  The variable $choice_widget will have the html to make the choice 
    #  selector.
    my $size=5;
    if (scalar(keys(%sections)) < 5) {
       $size=scalar(keys(%sections));
    }
    my $choice_widget = '<select multiple name="chosensections" size="'.$size.'">'."\n";
    foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) {
       $choice_widget .= "<option name=\"$sec\">$sec</option>\n";
    }
    $choice_widget .= "<option>none</option></select>\n";
   
     my %sections;   # Build a table without any borders to contain the section based
     for my $key (@keys) {   # selection:
  my $section_name = $classlist->{$key}->[$section];  
  if ($section_name ne "") {  
     $sections{$section_name} = 1;  
  }  
     }  
     #  The variable $choice_widget will have the html to make the choice   
     #  selector.  
   
     my $choice_widget = '<select multiple name="chosensections" size="5">'."\n";  
     foreach my $sec (sort (keys %sections)) {  
  $choice_widget .= "<option name=\"$sec\">$sec</option>\n";  
     }  
     $choice_widget .= "<option>Staff</option></select>\n";  
   
     # Build a table without any borders to contain the section based  
     # selection:  
   
     my $section_selectors = '<table border="0">'."\n";  
     $section_selectors   .= "<tr valign=\"top\">\n<td>For Sections:</td><td>$choice_widget</td>\n";  
     $section_selectors   .= '    <td><input type="radio" name="personstate" value="Active" checked />';  
     $section_selectors   .= "         Current Students</td>\n";  
     $section_selectors   .= '    <td><input type="radio" name="personstate" value="All" />';  
     $section_selectors   .= "         All students</td>\n";  
     $section_selectors   .= '    <td><input type="radio" name="personstate" value="Expired" />';  
     $section_selectors   .= "          Expired Students</td>\n";  
     $section_selectors   .= "</tr>\n";  
     $section_selectors   .= "<tr>\n";  
     $section_selectors   .= '    <td><input type="button" value="Select" onclick="checksections(true);" /></td>'."\n";  
     $section_selectors   .= '    <td><input type="button" value="Unselect" onclick="checksections(false);" /></td></tr>'."\n</table>\n";  
     $section_selectors   .= "<br />";  
   
     $result .= $section_selectors;   my $section_selectors =<<SECTIONSELECT;
   <table border="0">
     <tr valign="top">
      <td>For Sections:</td><td>$choice_widget</td>
      <td><label><input type="radio" name="personstate" value="Active" checked />
                  Current Students</label></td>
      <td><label><input type="radio" name="personstate" value="All" />
                  All students</label></td>
      <td><label><input type="radio" name="personstate" value="Expired" />
                  Expired Students</label></td>
     </tr>
     <tr>
      <td><input type="button" value="Select" onclick="checksections(true);" /></td>
      <td><input type="button" value="Unselect" onclick="checksections(false);" /></td></tr>
   </table>
   <br />
   SECTIONSELECT
            $result .= $section_selectors;
       }
     return $result;      return $result;
 }  }
   
Line 2439  sub postprocess { Line 2528  sub postprocess {
     my $self = shift;      my $self = shift;
   
     my $result = $env{'form.' . $self->{'variable'} . '.forminput'};      my $result = $env{'form.' . $self->{'variable'} . '.forminput'};
     if (!$result) {      if (!$result && !$self->{'emptyallowed'}) {
         $self->{ERROR_MSG} =    if ($self->{'coursepersonnel'}) {
     &mt('You must choose at least one student to continue.');      $self->{ERROR_MSG} = 
    &mt('You must choose at least one user to continue.');
    } else {
       $self->{ERROR_MSG} = 
    &mt('You must choose at least one student to continue.');
    }
         return 0;          return 0;
     }      }
   
Line 2886  sub end_section { Line 2980  sub end_section {
 }      }    
 1;  1;
   
   package Apache::lonhelper::group;
   
   =pod
    
   =head2 Element: groupX<group, helper element>
    
   <section> allows the user to choose one or more groups from the current course.
   
   It takes the standard attributes "variable", "multichoice", and "nextstate", meaning what they do for most other elements.
    
   =cut
   
   no strict;
   @ISA = ("Apache::lonhelper::choices");
   use strict;
   
   BEGIN {
       &Apache::lonhelper::register('Apache::lonhelper::group',
                                    ('group'));
   }
   
   sub new {
       my $ref = Apache::lonhelper::choices->new();
       bless($ref);
   }
    
   sub start_group {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
    
       if ($target ne 'helper') {
           return '';
       }
   
       $paramHash->{CHOICES} = [];
   
       $paramHash->{'variable'} = $token->[2]{'variable'};
       $helper->declareVar($paramHash->{'variable'});
       $paramHash->{'multichoice'} = $token->[2]{'multichoice'};
       if (defined($token->[2]{'nextstate'})) {
           $paramHash->{NEXTSTATE} = $token->[2]{'nextstate'};
       }
   
       # Populate the CHOICES element
       my %choices;
   
       my $numgroups;
       my %curr_groups;
       if (&Apache::loncommon::coursegroups(\%curr_groups)) {
           foreach my $group_name (keys %curr_groups) {
               $choices{$group_name} = $group_name;
           }
       }
       foreach my $group_name (sort(keys(%choices))) {
           push @{$paramHash->{CHOICES}}, [$group_name, $group_name];
       }
   }
                                                                                       
   sub end_group {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   
       if ($target ne 'helper') {
           return '';
       }
       Apache::lonhelper::group->new();
   }
   1;
   
 package Apache::lonhelper::string;  package Apache::lonhelper::string;
   
 =pod  =pod
Line 3267  sub render { Line 3428  sub render {
     }      }
     my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"');      my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"');
     my $next = HTML::Entities::encode(&mt("Next ->"), '<>&"');      my $next = HTML::Entities::encode(&mt("Next ->"), '<>&"');
       my $target = " target='loncapaclient'";
       if (($env{'browser.interface'} eq 'textual') ||
           ($env{'environment.remote'} eq 'off')) {  $target='';  }
     $result .= "<center>\n" .      $result .= "<center>\n" .
  "<form action='".$actionURL."' method='post' target='loncapaclient'>\n" .   "<form action='".$actionURL."' method='post' $target>\n" .
  "<input type='button' onclick='history.go(-1)' value='$previous' />" .   "<input type='button' onclick='history.go(-1)' value='$previous' />" .
  "<input type='hidden' name='orgurl' value='$targetURL' />" .   "<input type='hidden' name='orgurl' value='$targetURL' />" .
  "<input type='hidden' name='selectrole' value='1' />\n" .   "<input type='hidden' name='selectrole' value='1' />\n" .
Line 3469  sub render { Line 3633  sub render {
         $result .= '<li>'.&mt('for section [_1]',"<b>$section</b>").'</li>';          $result .= '<li>'.&mt('for section [_1]',"<b>$section</b>").'</li>';
  $result .= "<input type='hidden' name='csec' value='" .   $result .= "<input type='hidden' name='csec' value='" .
             HTML::Entities::encode($section,"'<>&\"") . "' />\n";              HTML::Entities::encode($section,"'<>&\"") . "' />\n";
       } elsif ($vars->{TARGETS} eq 'group') {
           my $group = $vars->{GROUP_NAME};
           $result .= '<li>'.&mt('for group [_1]',"<b>$group</b>").'</li>';
           $result .= "<input type='hidden' name='cgroup' value='" .
               HTML::Entities::encode($group,"'<>&\"") . "' />\n";
     } else {      } else {
         # FIXME: This is probably wasteful! Store the name!          # FIXME: This is probably wasteful! Store the name!
         my $classlist = Apache::loncoursedata::get_classlist();          my $classlist = Apache::loncoursedata::get_classlist();

Removed from v.1.114  
changed lines
  Added in v.1.128


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