Diff for /loncom/interface/lonhelper.pm between versions 1.73 and 1.91

version 1.73, 2004/04/21 19:03:02 version 1.91, 2005/01/05 12:07:27
Line 585  sub display { Line 585  sub display {
   
     $result .= <<HEADER;      $result .= <<HEADER;
 <html>  <html>
 <script type="text/javascript" language="Javascript" >  
     var editbrowser;  
     function openbrowser(formname,elementname,only,omit) {  
         var url = '/res/?';  
         if (editbrowser == null) {  
             url += 'launch=1&';  
         }  
         url += 'catalogmode=interactive&';  
         url += 'mode=parmset&';  
         url += 'form=' + formname + '&';  
         if (only != null) {  
             url += 'only=' + only + '&';  
         }   
         if (omit != null) {  
             url += 'omit=' + omit + '&';  
         }  
         url += 'element=' + elementname + '';  
         var title = 'Browser';  
         var options = 'scrollbars=1,resizable=1,menubar=0';  
         options += ',width=700,height=600';  
         editbrowser = open(url,title,options,'1');  
         editbrowser.focus();  
     }  
 </script>  
     <head>      <head>
         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
         <title>$loncapaHelper: $helperTitle</title>          <title>$loncapaHelper: $helperTitle</title>
Line 1198  sub end_choice { Line 1174  sub end_choice {
     return '';      return '';
 }  }
   
   {
       # used to generate unique id attributes for <input> tags. 
       # internal use only.
       my $id = 0;
       sub new_id { return $id++; }
   }
   
 sub render {  sub render {
     my $self = shift;      my $self = shift;
     my $var = $self->{'variable'};      my $var = $self->{'variable'};
Line 1280  BUTTONS Line 1263  BUTTONS
     my $type = "radio";      my $type = "radio";
     if ($self->{'multichoice'}) { $type = 'checkbox'; }      if ($self->{'multichoice'}) { $type = 'checkbox'; }
     foreach my $choice (@{$self->{CHOICES}}) {      foreach my $choice (@{$self->{CHOICES}}) {
           my $id = &new_id();
         $result .= "<tr>\n<td width='20'>&nbsp;</td>\n";          $result .= "<tr>\n<td width='20'>&nbsp;</td>\n";
         $result .= "<td valign='top'><input type='$type' name='$var.forminput'"          $result .= "<td valign='top'><input type='$type' name='$var.forminput'"
             . "' value='" .               . "' value='" . 
             HTML::Entities::encode($choice->[1],'<>&"')               HTML::Entities::encode($choice->[1],"<>&\"'") 
             . "'";              . "'";
         if ($checkedChoices{$choice->[1]}) {          if ($checkedChoices{$choice->[1]}) {
             $result .= " checked ";              $result .= " checked ";
         }          }
           $result .= qq{id="$id"};
         my $choiceLabel = $choice->[0];          my $choiceLabel = $choice->[0];
         if ($choice->[4]) {  # if we need to evaluate this choice          if ($choice->[4]) {  # if we need to evaluate this choice
             $choiceLabel = "sub { my $helper = shift; my $state = shift;" .              $choiceLabel = "sub { my $helper = shift; my $state = shift;" .
Line 1295  BUTTONS Line 1280  BUTTONS
             $choiceLabel = eval($choiceLabel);              $choiceLabel = eval($choiceLabel);
             $choiceLabel = &$choiceLabel($helper, $self);              $choiceLabel = &$choiceLabel($helper, $self);
         }          }
  &Apache::lonnet::logthis("TITLE TRANSLATION >$choiceLabel<");          $result .= "/></td><td> ".qq{<label for="$id">}.
         $result .= "/></td><td> " . &mtn($choiceLabel) . "</td></tr>\n";              &mtn($choiceLabel). "</label></td></tr>\n";
     }      }
     $result .= "</table>\n\n\n";      $result .= "</table>\n\n\n";
     $result .= $buttons;      $result .= $buttons;
Line 1439  sub render { Line 1424  sub render {
     $result .= "<select name='${var}.forminput'>\n";      $result .= "<select name='${var}.forminput'>\n";
     foreach my $choice (@{$self->{CHOICES}}) {      foreach my $choice (@{$self->{CHOICES}}) {
         $result .= "<option value='" .           $result .= "<option value='" . 
             HTML::Entities::encode($choice->[1],'<>&"')               HTML::Entities::encode($choice->[1],"<>&\"'") 
             . "'";              . "'";
         if ($checkedChoices{$choice->[1]}) {          if ($checkedChoices{$choice->[1]}) {
             $result .= " selected";              $result .= " selected";
Line 1775  BEGIN { Line 1760  BEGIN {
     &Apache::lonhelper::register('Apache::lonhelper::resource',      &Apache::lonhelper::register('Apache::lonhelper::resource',
                               ('resource', 'filterfunc',                                 ('resource', 'filterfunc', 
                                'choicefunc', 'valuefunc',                                 'choicefunc', 'valuefunc',
                                'mapurl'));                                 'mapurl','option'));
 }  }
   
 sub new {  sub new {
Line 1880  sub start_mapurl { Line 1865  sub start_mapurl {
   
 sub end_mapurl { return ''; }  sub end_mapurl { return ''; }
   
   
   sub start_option {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
       if (!defined($paramHash->{OPTION_TEXTS})) {
    $paramHash->{OPTION_TEXTS} = [ ];
    $paramHash->{OPTION_VARS}  = [ ];
   
       }
       # OPTION_TEXTS is a list of the text attribute
       #               values used to create column headings.
       # OPTION_VARS is a list of the variable names, used to create the checkbox
       #             inputs.
       #  We're ok with empty elements. as place holders
       # Although the 'variable' element should really exist.
       #
   
       my $option_texts  = $paramHash->{OPTION_TEXTS};
       my $option_vars   = $paramHash->{OPTION_VARS};
       push(@$option_texts,  $token->[2]{'text'});
       push(@$option_vars,   $token->[2]{'variable'});
   
       #  Need to create and declare the option variables as well to make them
       # persistent.
       #
       my $varname = $token->[2]{'variable'};
       $helper->declareVar($varname);
   
   
       return '';
   }
   
   sub end_option {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
       return '';
   }
   
 # A note, in case I don't get to this before I leave.  # A note, in case I don't get to this before I leave.
 # If someone complains about the "Back" button returning them  # If someone complains about the "Back" button returning them
 # to the previous folder state, instead of returning them to  # to the previous folder state, instead of returning them to
Line 1931  BUTTONS Line 1952  BUTTONS
   
     $result .= $buttons;      $result .= $buttons;
   
     my $filterFunc = $self->{FILTER_FUNC};      my $filterFunc     = $self->{FILTER_FUNC};
     my $choiceFunc = $self->{CHOICE_FUNC};      my $choiceFunc     = $self->{CHOICE_FUNC};
     my $valueFunc = $self->{VALUE_FUNC};      my $valueFunc      = $self->{VALUE_FUNC};
     my $multichoice = $self->{'multichoice'};      my $multichoice   = $self->{'multichoice'};
       my $option_vars    = $self->{OPTION_VARS};
       my $option_texts   = $self->{OPTION_TEXTS};
       my $headings_done  = 0;
   
     # Evaluate the map url as needed      # Evaluate the map url as needed
     my $mapUrl;      my $mapUrl;
Line 1952  BUTTONS Line 1976  BUTTONS
     my $checked = 0;      my $checked = 0;
     my $renderColFunc = sub {      my $renderColFunc = sub {
         my ($resource, $part, $params) = @_;          my ($resource, $part, $params) = @_;
    my $result = "";
   
    if(!$headings_done) {
       if ($option_texts) {
    foreach my $text (@$option_texts) {
       $result .= "<th>$text</th>";
    }
       }
       $result .= "<th>Select</th>";
       $result .= "</tr><tr>"; # Close off the extra row and start a new one.
       $headings_done = 1;
    }
   
         my $inputType;          my $inputType;
         if ($multichoice) { $inputType = 'checkbox'; }          if ($multichoice) { $inputType = 'checkbox'; }
         else {$inputType = 'radio'; }          else {$inputType = 'radio'; }
   
         if (!&$choiceFunc($resource)) {          if (!&$choiceFunc($resource)) {
             return '<td>&nbsp;</td>';      $result .= '<td>&nbsp;</td>';
               return $result;
         } else {          } else {
             my $col = "<td><input type='$inputType' name='${var}.forminput' ";      my $col = "";
       my $resource_name =   
                      HTML::Entities::encode(&$valueFunc($resource),"<>&\"'");
       if($option_vars) {
    foreach my $option_var (@$option_vars) {
       $col .= 
                           "<td align='center'><input type='checkbox' name ='$option_var".
    ".forminput' value='".
    $resource_name . "' /> </td>";
    }
       }
   
               $col .= "<td align='center'><input type='$inputType' name='${var}.forminput' ";
             if (!$checked && !$multichoice) {              if (!$checked && !$multichoice) {
                 $col .= "checked ";                  $col .= "checked ";
                 $checked = 1;                  $checked = 1;
Line 1969  BUTTONS Line 2018  BUTTONS
  $col .= "checked ";   $col .= "checked ";
  $checked = 1;   $checked = 1;
     }      }
             $col .= "value='" .               $col .= "value='" . $resource_name  . "' /></td>";
                 HTML::Entities::encode(&$valueFunc($resource),'<>&"')               return $result.$col;
                 . "' /></td>";  
             return $col;  
         }          }
     };      };
   
Line 2114  sub render { Line 2161  sub render {
  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;   if (document.forms.helpform.elements[i].value.indexOf(':Active') != -1) {
       document.forms.helpform.elements[i].checked=value;
    }
             }              }
         }          }
     }      }
Line 2122  sub render { Line 2171  sub render {
  for (i=0; i<document.forms.helpform.elements.length; i++) {   for (i=0; i<document.forms.helpform.elements.length; i++) {
             if (document.forms.helpform.elements[i].value.indexOf(':Active') != -1) {              if (document.forms.helpform.elements[i].value.indexOf(':Active') != -1) {
                 document.forms.helpform.elements[i].checked=true;                  document.forms.helpform.elements[i].checked=true;
             }              } 
           }
       }
       function uncheckexpired() {
    for (i=0; i<document.forms.helpform.elements.length; i++) {
               if (document.forms.helpform.elements[i].value.indexOf(':Expired') != -1) {
                   document.forms.helpform.elements[i].checked=false;
               } 
         }          }
     }      }
 </script>  </script>
Line 2130  SCRIPT Line 2186  SCRIPT
   
         my %lt=&Apache::lonlocal::texthash(          my %lt=&Apache::lonlocal::texthash(
                     'ocs'  => "Select Only Current Students",                      'ocs'  => "Select Only Current Students",
                       'ues'  => "Unselect Expired Students",
                     'sas'  => "Select All Students",                      'sas'  => "Select All Students",
                     'uas'  => "Unselect All Students",                      'uas'  => "Unselect All Students",
                     'sfsg' => "Select for Section/Group",                      'sfsg' => "Select Current Students for Section/Group",
     'ufsg' => "Unselect for Section/Group");      'ufsg' => "Unselect for Section/Group");
     
         $buttons = <<BUTTONS;          $buttons = <<BUTTONS;
 <br />  <br />
 <input type="button" onclick="checkactive()" value="$lt{'ocs'}" />  <input type="button" onclick="checkactive()" value="$lt{'ocs'}" />
   <input type="button" onclick="uncheckexpired()" value="$lt{'ues'}" /><br />
 <input type="button" onclick="checkall(true, '$var')" value="$lt{'sas'}" />  <input type="button" onclick="checkall(true, '$var')" value="$lt{'sas'}" />
 <input type="button" onclick="checkall(false, '$var')" value="$lt{'uas'}" />  <input type="button" onclick="checkall(false, '$var')" value="$lt{'uas'}" /><br />
 <input type="button" onclick="checksec(true)" value="$lt{'sfsg'}">  <input type="button" onclick="checksec(true)" value="$lt{'sfsg'}">
 <input type="text" size="5" name="chksec">&nbsp;  <input type="text" size="5" name="chksec">&nbsp;
 <input type="button" onclick="checksec(false)" value="$lt{'ufsg'}">  <input type="button" onclick="checksec(false)" value="$lt{'ufsg'}">
Line 2202  BUTTONS Line 2260  BUTTONS
     }      }
   
     my $name = $self->{'coursepersonnel'} ? &mt('Name') : &mt('Student Name');      my $name = $self->{'coursepersonnel'} ? &mt('Name') : &mt('Student Name');
     &Apache::lonnet::logthis("THE NAME IS >$name<");  
     my $type = 'radio';      my $type = 'radio';
     if ($self->{'multichoice'}) { $type = 'checkbox'; }      if ($self->{'multichoice'}) { $type = 'checkbox'; }
     $result .= "<table cellspacing='2' cellpadding='2' border='0'>\n";      $result .= "<table cellspacing='2' cellpadding='2' border='0'>\n";
Line 2222  BUTTONS Line 2279  BUTTONS
             $checked = 1;              $checked = 1;
         }          }
         $result .=          $result .=
             " value='" . HTML::Entities::encode($choice->[0] . ':' . $choice->[2] . ':' . $choice->[1] . ':' . $choice->[3],'<>&"')              " value='" . HTML::Entities::encode($choice->[0] . ':' 
    .$choice->[2] . ':' 
    .$choice->[1] . ':' 
    .$choice->[3], "<>&\"'")
             . "' /></td><td>"              . "' /></td><td>"
             . HTML::Entities::encode($choice->[1],'<>&"')              . HTML::Entities::encode($choice->[1],'<>&"')
             . "</td><td align='center'>"               . "</td><td align='center'>" 
Line 2390  sub start_filefilter { Line 2450  sub start_filefilter {
   
 sub end_filefilter { return ''; }  sub end_filefilter { return ''; }
   
   { 
       # used to generate unique id attributes for <input> tags. 
       # internal use only.
       my $id=0;
       sub new_id { return $id++;}
   }
   
 sub render {  sub render {
     my $self = shift;      my $self = shift;
     my $result = '';      my $result = '';
Line 2476  BUTTONS Line 2543  BUTTONS
     }      }
   
     # Sort the fileList into order      # Sort the fileList into order
     @fileList = sort @fileList;      @fileList = sort {lc($a) cmp lc($b)} @fileList;
   
     $result .= $buttons;      $result .= $buttons;
   
Line 2528  BUTTONS Line 2595  BUTTONS
             if ($status eq 'Published' && $helper->{VARS}->{'construction'}) {              if ($status eq 'Published' && $helper->{VARS}->{'construction'}) {
                 $onclick = 'onclick="a=1" ';                  $onclick = 'onclick="a=1" ';
             }              }
               my $id = &new_id();
             $result .= '<tr><td align="right"' . " bgcolor='$color'>" .              $result .= '<tr><td align="right"' . " bgcolor='$color'>" .
                 "<input $onclick type='$type' name='" . $var                  "<input $onclick type='$type' name='" . $var
             . ".forminput' value='" . HTML::Entities::encode($fileName,'<>&"').              . ".forminput' ".qq{id="$id"}." value='" . HTML::Entities::encode($fileName,"<>&\"'").
                 "'";                  "'";
             if (!$self->{'multichoice'} && $choices == 0) {              if (!$self->{'multichoice'} && $choices == 0) {
                 $result .= ' checked';                  $result .= ' checked';
             }              }
             $result .= "/></td><td bgcolor='$color'>" . $file . "</td>" .              $result .= "/></td><td bgcolor='$color'>".
                   qq{<label for="$id">}. $file . "</label></td>" .
                 "<td bgcolor='$color'>$title</td>" .                  "<td bgcolor='$color'>$title</td>" .
                 "<td bgcolor='$color'>$status</td>" . "</tr>\n";                  "<td bgcolor='$color'>$status</td>" . "</tr>\n";
             $choices++;              $choices++;
Line 2563  sub fileState { Line 2632  sub fileState {
     my $constructionSpaceDir = shift;      my $constructionSpaceDir = shift;
     my $file = shift;      my $file = shift;
           
       my ($uname,$udom)=($ENV{'user.name'},$ENV{'user.domain'});
       if ($ENV{'request.role'}=~/^ca\./) {
    (undef,$udom,$uname)=split(/\//,$ENV{'request.role'});
       }
     my $docroot = $Apache::lonnet::perlvar{'lonDocRoot'};      my $docroot = $Apache::lonnet::perlvar{'lonDocRoot'};
     my $subdirpart = $constructionSpaceDir;      my $subdirpart = $constructionSpaceDir;
     $subdirpart =~ s/^\/home\/$ENV{'user.name'}\/public_html//;      $subdirpart =~ s/^\/home\/$uname\/public_html//;
     my $resdir = $docroot . '/res/' . $ENV{'user.domain'} . '/' . $ENV{'user.name'} .      my $resdir = $docroot . '/res/' . $udom . '/' . $uname .
         $subdirpart;          $subdirpart;
   
     my @constructionSpaceFileStat = stat($constructionSpaceDir . '/' . $file);      my @constructionSpaceFileStat = stat($constructionSpaceDir . '/' . $file);
Line 2695  string honors the validation function, i Line 2768  string honors the validation function, i
 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::string',      &Apache::lonhelper::register('Apache::lonhelper::string',
Line 2813  be able to call methods on it. Line 2887  be able to call methods on it.
   
 =cut  =cut
   
   use Apache::lonlocal;
   
 BEGIN {  BEGIN {
     &Apache::lonhelper::register('Apache::lonhelper::general',      &Apache::lonhelper::register('Apache::lonhelper::general',
                                  'exec', 'condition', 'clause',                                   'exec', 'condition', 'clause',
Line 3126  sub render { Line 3202  sub render {
   
     # Print the granularity, depending on the action      # Print the granularity, depending on the action
     if ($vars->{GRANULARITY} eq 'whole_course') {      if ($vars->{GRANULARITY} eq 'whole_course') {
         $resourceString .= '<li>'.&mt('for').' <b>'.&mt('all resources in the course').'</b></li>';          $resourceString .= '<li>'.&mt('for <b>all resources in the course</b>').'</li>';
         $level = 9; # general course, see lonparmset.pm perldoc          $level = 9; # general course, see lonparmset.pm perldoc
         $affectedResourceId = "0.0";          $affectedResourceId = "0.0";
         $symb = 'a';          $symb = 'a';
Line 3136  sub render { Line 3212  sub render {
         my $res = $navmap->getByMapPc($vars->{RESOURCE_ID});          my $res = $navmap->getByMapPc($vars->{RESOURCE_ID});
         my $title = $res->compTitle();          my $title = $res->compTitle();
         $symb = $res->symb();          $symb = $res->symb();
         $navmap->untieHashes();          $resourceString .= '<li>'.&mt('for the map named [_1]',"<b>$title</b>").'</li>';
         $resourceString .= "<li>for the map named <b>$title</b></li>";  
         $level = 8;          $level = 8;
         $affectedResourceId = $vars->{RESOURCE_ID};          $affectedResourceId = $vars->{RESOURCE_ID};
         $paramlevel = 'map';          $paramlevel = 'map';
Line 3146  sub render { Line 3221  sub render {
         my $res = $navmap->getById($vars->{RESOURCE_ID});          my $res = $navmap->getById($vars->{RESOURCE_ID});
         $symb = $res->symb();          $symb = $res->symb();
         my $title = $res->compTitle();          my $title = $res->compTitle();
         $navmap->untieHashes();          $resourceString .= '<li>'.&mt('for the resource named [_1]',"<b>$title</b>").'</li>';
         $resourceString .= "<li>for the resource named <b>$title</b></li>";  
         $level = 7;          $level = 7;
         $affectedResourceId = $vars->{RESOURCE_ID};          $affectedResourceId = $vars->{RESOURCE_ID};
         $paramlevel = 'full';          $paramlevel = 'full';
Line 3165  sub render { Line 3239  sub render {
  $extra =  $vars->{WEIGHT};   $extra =  $vars->{WEIGHT};
     }      }
     $result .= "<li>";      $result .= "<li>";
     my $what = &mt($dateTypeHash{$vars->{ACTION_TYPE}})       my $what = &mt($dateTypeHash{$vars->{ACTION_TYPE}});
     if ($extra) {      if ($extra) {
  $result .= &mt('Setting the [_1] to [_2]',"<b>$what</b>",$extra);   $result .= &mt('Setting the [_1] to [_2]',"<b>$what</b>",$extra);
     } else {      } else {
Line 3200  sub render { Line 3274  sub render {
           
     # Print targets      # Print targets
     if ($vars->{TARGETS} eq 'course') {      if ($vars->{TARGETS} eq 'course') {
         $result .= '<li>'.&mt('for').' <b>'.&mt('all students in course').'</b></li>';          $result .= '<li>'.&mt('for <b>all students in course</b>').'</li>';
     } elsif ($vars->{TARGETS} eq 'section') {      } elsif ($vars->{TARGETS} eq 'section') {
         my $section = $vars->{SECTION_NAME};          my $section = $vars->{SECTION_NAME};
         $result .= "<li>".&mt('for section')." <b>$section</b></li>";          $result .= '<li>'.&mt('for section [_1]',"<b>$section</b>").'</li>';
         $level -= 3;          $level -= 3;
         $result .= "<input type='hidden' name='csec' value='" .          $result .= "<input type='hidden' name='csec' value='" .
             HTML::Entities::encode($section,'<>&"') . "' />\n";              HTML::Entities::encode($section,"'<>&\"") . "' />\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();
Line 3214  sub render { Line 3288  sub render {
         # Chop off everything after the last colon (section)          # Chop off everything after the last colon (section)
         $username = substr($username, 0, rindex($username, ':'));          $username = substr($username, 0, rindex($username, ':'));
         my $name = $classlist->{$username}->[6];          my $name = $classlist->{$username}->[6];
         $result .= "<li>".&mt('for')." <b>$name</b></li>";          $result .= '<li>'.&mt('for [_1]',"<b>$name</b>").'</li>';
         $level -= 6;          $level -= 6;
         my ($uname, $udom) = split /:/, $vars->{USER_NAME};          my ($uname, $udom) = split /:/, $vars->{USER_NAME};
         $result .= "<input type='hidden' name='uname' value='".          $result .= "<input type='hidden' name='uname' value='".
             HTML::Entities::encode($uname,'<>&"') . "' />\n";              HTML::Entities::encode($uname,"'<>&\"") . "' />\n";
         $result .= "<input type='hidden' name='udom' value='".          $result .= "<input type='hidden' name='udom' value='".
             HTML::Entities::encode($udom,'<>&"') . "' />\n";              HTML::Entities::encode($udom,"'<>&\"") . "' />\n";
     }      }
   
     # Print value      # Print value
     if ($vars->{ACTION_TYPE} ne 'tries' && $vars->{ACTION_TYPE} ne 'weight') {      if ($vars->{ACTION_TYPE} ne 'tries' && $vars->{ACTION_TYPE} ne 'weight') {
  $result .= "<li>".&mt('to')." <b>" . ctime($vars->{PARM_DATE}) . "</b> (" .   $result .= '<li>'.&mt('to [_1] ([_2])',"<b>".ctime($vars->{PARM_DATE})."</b>",Apache::lonnavmaps::timeToHumanString($vars->{PARM_DATE}))."</li>\n";
     Apache::lonnavmaps::timeToHumanString($vars->{PARM_DATE})   
     . ")</li>\n";  
     }      }
     
     # print pres_marker      # print pres_marker

Removed from v.1.73  
changed lines
  Added in v.1.91


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