Diff for /loncom/interface/loncommon.pm between versions 1.558 and 1.565

version 1.558, 2007/08/02 01:07:00 version 1.565, 2007/08/18 00:01:37
Line 1084  sub changable_area { Line 1084  sub changable_area {
   
 =pod  =pod
   
   =item * resize_textarea_js
   
   emits the needed javascript to resize a textarea to be as big as possible
   
   creates a function resize_textrea that takes two IDs first should be
   the id of the element to resize, second should be the id of a div that
   surrounds everything that comes after the textarea, this routine needs
   to be attached to the <body> for the onload and onresize events.
   
   
   =cut
   
   sub resize_textarea_js {
       return <<"RESIZE";
       <script type="text/javascript">
   var Geometry = {};
   function init_geometry() {
       if (Geometry.init) { return };
       Geometry.init=1;
       if (window.innerHeight) {
    Geometry.getViewportHeight = function() { return window.innerHeight; };
       }
       else if (document.documentElement && document.documentElement.clientHeight) {
    Geometry.getViewportHeight = 
       function() { return document.documentElement.clientHeight; };
       }
       else if (document.body.clientHeight) {
    Geometry.getViewportHeight = 
       function() { return document.body.clientHeight; };
       }
   }
   
   function resize_textarea(textarea_id,bottom_id) {
       init_geometry();
       var textarea        = document.getElementById(textarea_id);
       //alert(textarea);
   
       var textarea_top    = textarea.offsetTop;
       var textarea_height = textarea.offsetHeight;
       var bottom          = document.getElementById(bottom_id);
       var bottom_top      = bottom.offsetTop;
       var bottom_height   = bottom.offsetHeight;
       var window_height   = Geometry.getViewportHeight();
       var fudge           = 23; 
       var new_height      = window_height-fudge-textarea_top-bottom_height;
       if (new_height < 300) {
    new_height = 300;
       }
       textarea.style.height=new_height+'px';
   }
   </script>
   RESIZE
   
   }
   
   =pod
   
 =back  =back
     
 =head1 Excel and CSV file utility routines  =head1 Excel and CSV file utility routines
Line 1424  sub select_level_form { Line 1481  sub select_level_form {
   
 =pod  =pod
   
 =item * select_dom_form($defdom,$name,$includeempty)  =item * select_dom_form($defdom,$name,$includeempty,$showdomdesc)
   
 Returns a string containing a <select name='$name' size='1'> form to   Returns a string containing a <select name='$name' size='1'> form to 
 allow a user to select the domain to preform an operation in.    allow a user to select the domain to preform an operation in.  
Line 1433  See loncreateuser.pm for an example invo Line 1490  See loncreateuser.pm for an example invo
 If the $includeempty flag is set, it also includes an empty choice ("no domain  If the $includeempty flag is set, it also includes an empty choice ("no domain
 selected");  selected");
   
   If the $showdomdesc flag is set, the domain name is followed by the domain description. 
   
 =cut  =cut
   
 #-------------------------------------------  #-------------------------------------------
 sub select_dom_form {  sub select_dom_form {
     my ($defdom,$name,$includeempty) = @_;      my ($defdom,$name,$includeempty,$showdomdesc) = @_;
     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());      my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
     if ($includeempty) { @domains=('',@domains); }      if ($includeempty) { @domains=('',@domains); }
     my $selectdomain = "<select name=\"$name\" size=\"1\">\n";      my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
     foreach my $dom (@domains) {      foreach my $dom (@domains) {
         $selectdomain.="<option value=\"$dom\" ".          $selectdomain.="<option value=\"$dom\" ".
             ($dom eq $defdom ? 'selected="selected" ' : '').              ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                 ">$dom</option>\n";          if ($showdomdesc) {
               if ($dom ne '') {
                   my $domdesc = &Apache::lonnet::domain($dom,'description');
                   if ($domdesc ne '') {
                       $selectdomain .= ' ('.$domdesc.')';
                   }
               } 
           }
           $selectdomain .= "</option>\n";
     }      }
     $selectdomain.="</select>";      $selectdomain.="</select>";
     return $selectdomain;      return $selectdomain;
Line 3397  Inputs: Line 3464  Inputs:
   
 =item * $args, optional argument valid values are  =item * $args, optional argument valid values are
             no_auto_mt_title -> prevents &mt()ing the title arg              no_auto_mt_title -> prevents &mt()ing the title arg
               inherit_jsmath -> when creating popup window in a page,
                                 should it have jsmath forced on by the
                                 current page
   
 =back  =back
   
Line 3453  sub bodytag { Line 3523  sub bodytag {
   
 # construct main body tag  # construct main body tag
     my $bodytag = "<body $extra_body_attr>".      my $bodytag = "<body $extra_body_attr>".
  &Apache::lontexconvert::init_math_support();   &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
   
     if ($bodyonly) {      if ($bodyonly) {
         return $bodytag;          return $bodytag;
Line 4711  Inputs: $title - optional title for the Line 4781  Inputs: $title - optional title for the
   
                   no_auto_mt_title -> prevent &mt()ing the title arg                    no_auto_mt_title -> prevent &mt()ing the title arg
   
                     inherit_jsmath -> when creating popup window in a page,
                                       should it have jsmath forced on by the
                                       current page
   
 =cut  =cut
   
 sub start_page {  sub start_page {
Line 5557  sub user_picker { Line 5631  sub user_picker {
         }          }
         $srchterm = $srch->{'srchterm'};          $srchterm = $srch->{'srchterm'};
     }      }
     use Data::Dumper;  
     &Apache::lonnet::logthis(&Dumper($srch));  
     my %lt=&Apache::lonlocal::texthash(      my %lt=&Apache::lonlocal::texthash(
                     'usr'       => 'Search for',                      'doma'      => 'Domain/institution to search',
                     'or'        => 'or',  
                     'doma'      => 'domain',  
                     'uname'     => 'username',                      'uname'     => 'username',
                     'lastname'  => 'last name',                      'lastname'  => 'last name',
                     'lastfirst' => 'last name, first name',                      'lastfirst' => 'last name, first name',
Line 5573  sub user_picker { Line 5643  sub user_picker {
                     'exact'     => 'is',                      'exact'     => 'is',
                     'contains'  => 'contains',                      'contains'  => 'contains',
                                        );                                         );
     my $domform = &select_dom_form($currdom,'srchdomain',1);      my $domform = &select_dom_form($currdom,'srchdomain',1,1);
       my $srchinsel = ' <select name="srchin">';
     my $srchin;  
   
     my @srchins = ('crs','dom','alc','instd');      my @srchins = ('crs','dom','alc','instd');
   
Line 5585  sub user_picker { Line 5654  sub user_picker {
         #       has been completed.          #       has been completed.
         next if ($option eq 'alc');          next if ($option eq 'alc');
         next if ($option eq 'crs' && !$env{'request.course.id'});          next if ($option eq 'crs' && !$env{'request.course.id'});
         my $checked =($curr_selected{'srchin'} eq $option) ?'checked="checked"'          if ($curr_selected{'srchin'} eq $option) {
                                                    :'';              $srchinsel .= ' 
  my $extra = ($option eq 'dom') ? $domform     <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                                : '';          } else {
  $srchin.=<<ROW              $srchinsel .= '
  <tr>     <option value="'.$option.'">'.$lt{$option}.'</option>';
    <td>          }
      <label><input type="radio" name="srchin" value="$option" $checked /> $lt{$option}</label> $extra  
    </td>  
 </tr>  
 ROW  
     }      }
       $srchinsel .= "\n  </select>\n";
   
     my $srchbysel =  ' <select name="srchby">';      my $srchbysel =  ' <select name="srchby">';
     foreach my $option ('uname','lastname','lastfirst') {      foreach my $option ('uname','lastname','lastfirst') {
Line 5636  function setSearch(createnew) { Line 5702  function setSearch(createnew) {
             }              }
         }          }
         for (var i=0; i<document.crtuser.srchin.length; i++) {          for (var i=0; i<document.crtuser.srchin.length; i++) {
             if ( document.crtuser.srchin[i].value == 'dom') {              if ( document.crtuser.srchin.options[i].value == 'dom') {
  document.crtuser.srchin[i].checked = 1;   document.crtuser.srchin.selectedIndex = i;
             }              }
         }          }
         for (var i=0; i<document.crtuser.srchtype.length; i++) {          for (var i=0; i<document.crtuser.srchtype.length; i++) {
Line 5672  function validateEntry() { Line 5738  function validateEntry() {
     var srchby = document.crtuser.srchby.options[document.crtuser.srchby.selectedIndex].value;      var srchby = document.crtuser.srchby.options[document.crtuser.srchby.selectedIndex].value;
     var srchdomain = document.crtuser.srchdomain.options[document.crtuser.srchdomain.selectedIndex].value;      var srchdomain = document.crtuser.srchdomain.options[document.crtuser.srchdomain.selectedIndex].value;
     var srchterm =  document.crtuser.srchterm.value;      var srchterm =  document.crtuser.srchterm.value;
       var srchin = document.crtuser.srchin.options[document.crtuser.srchin.selectedIndex].value;
     var msg = "";      var msg = "";
   
     if (srchterm == "") {      if (srchterm == "") {
Line 5682  function validateEntry() { Line 5749  function validateEntry() {
     if (srchtype== 'contains') {      if (srchtype== 'contains') {
         if (srchterm.length < 3) {          if (srchterm.length < 3) {
             checkok = 0;              checkok = 0;
             msg += "The text you are searching for must contain at least three characters when using a 'contained in' type search.\\n";              msg += "The text you are searching for must contain at least three characters when using a 'contains' type search.\\n";
         }          }
     }      }
     if (srchin == 'instd') {      if (srchin == 'instd') {
Line 5724  $new_user_create Line 5791  $new_user_create
   
 <table>  <table>
  <tr>   <tr>
   <td> $srchbysel    <td>$srchbysel
        $srchtypesel         $srchtypesel 
        <input type="text" size="15" name="srchterm" value="$srchterm" />        <input type="text" size="15" name="srchterm" value="$srchterm" />
         $srchinsel 
     </td>
    </tr>
    <tr>
     <td>$lt{'doma'}: $domform</td>
   </td>    </td>
  </tr>   </tr>
 $srchin  
 </table>  </table>
 <br />  <br />
 END_BLOCK  END_BLOCK
Line 5996  sub record_sep { Line 6067  sub record_sep {
             $i++;              $i++;
         }          }
     } else {      } else {
         my @allfields;          my $separator=',';
         if ($env{'form.upfiletype'} eq 'semisv') {          if ($env{'form.upfiletype'} eq 'semisv') {
             @allfields=split(/;/,$record,-1);              $separator=';';
         } else {  
             @allfields=split(/\,/,$record,-1);  
         }          }
         my $i=0;          my $i=0;
         my $j;  # the character we are looking for to indicate the end of a quote or a record 
         for ($j=0;$j<=$#allfields;$j++) {          my $looking_for=$separator;
             my $field=$allfields[$j];  # do not add the characters to the fields
             if ($field=~/^\s*(\"|\')/) {          my $ignore=0;
  my $delimiter=$1;  # we just encountered a separator (or the beginning of the record)
                 while (($field!~/$delimiter$/) && ($j<$#allfields)) {          my $just_found_separator=1;
     $j++;  # store the field we are working on here
     $field.=','.$allfields[$j];          my $field='';
  }  # work our way through all characters in record
                 $field=~s/^\s*$delimiter//;          foreach my $character ($record=~/(.)/g) {
                 $field=~s/$delimiter\s*$//;              if ($character eq $looking_for) {
             }                 if ($character ne $separator) {
             $components{&takeleft($i)}=$field;  # Found the end of a quote, again looking for separator
     $i++;                    $looking_for=$separator;
                     $ignore=1;
                  } else {
   # Found a separator, store away what we got
                     $components{&takeleft($i)}=$field;
             $i++;
                     $just_found_separator=1;
                     $ignore=0;
                     $field='';
                  }
                  next;
               }
   # single or double quotation marks after a separator indicate beginning of a quote
   # we are now looking for the end of the quote and need to ignore separators
               if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                  $looking_for=$character;
                  next;
               }
   # ignore would be true after we reached the end of a quote
               if ($ignore) { next; }
               if (($just_found_separator) && ($character=~/\s/)) { next; }
               $field.=$character;
               $just_found_separator=0; 
         }          }
   # catch the very last entry, since we never encountered the separator
           $components{&takeleft($i)}=$field;
     }      }
     return %components;      return %components;
 }  }

Removed from v.1.558  
changed lines
  Added in v.1.565


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