Diff for /loncom/interface/loncommon.pm between versions 1.564.2.6 and 1.569

version 1.564.2.6, 2007/09/04 23:59:03 version 1.569, 2007/08/25 19:52:29
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 3458  sub bodytag { Line 3515  sub bodytag {
     if (!$realm) { $realm='&nbsp;'; }      if (!$realm) { $realm='&nbsp;'; }
 # Set messages  # Set messages
     my $messages=&domainlogo($domain);      my $messages=&domainlogo($domain);
   # Port for miniserver
       my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
       if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
   
     my $extra_body_attr = &make_attr_string($forcereg,\%design);      my $extra_body_attr = &make_attr_string($forcereg,\%design);
   
Line 3575  ENDROLE Line 3635  ENDROLE
   
     my $imgsrc = $img;      my $imgsrc = $img;
     if ($img =~ /^\/adm/) {      if ($img =~ /^\/adm/) {
         $imgsrc = &lonhttpdurl($img);          $imgsrc = 'http://'.$ENV{'HTTP_HOST'}.':'.$lonhttpdPort.$img;
     }      }
     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';      my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
   
Line 5549  sub get_secgrprole_info { Line 5609  sub get_secgrprole_info {
 }  }
   
 sub user_picker {  sub user_picker {
     my ($dom,$srch,$forcenewuser,$caller) = @_;      my ($dom,$srch,$forcenewuser) = @_;
     my $currdom = $dom;      my $currdom = $dom;
     my %curr_selected = (      my %curr_selected = (
                         srchin => 'dom',                          srchin => 'dom',
Line 5583  sub user_picker { Line 5643  sub user_picker {
                     'exact'     => 'is',                      'exact'     => 'is',
                     'contains'  => 'contains',                      'contains'  => 'contains',
                     'begins'    => 'begins with',                      'begins'    => 'begins with',
                     'youm'      => "You must include some text to search for.",  
                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",  
                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",  
                     'yomc'      => "You must choose a domain when using an institutional directory search.",  
                     'ymcd'      => "You must choose a domain when using a domain search.",  
                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",  
                     'whse'      => "When searching by last,first you must include at least one character in the first name.",  
                      'thfo'     => "The following need to be corrected before the search can be run:",  
                                        );                                         );
     my $domform = &select_dom_form($currdom,'srchdomain',1,1);      my $domform = &select_dom_form($currdom,'srchdomain',1,1);
     my $srchinsel = ' <select name="srchin">';      my $srchinsel = ' <select name="srchin">';
Line 5640  sub user_picker { Line 5692  sub user_picker {
     my ($newuserscript,$new_user_create);      my ($newuserscript,$new_user_create);
   
     if ($forcenewuser) {      if ($forcenewuser) {
  $new_user_create = '<p> <input type="submit" name="forcenew" value="'.&HTML::Entities::encode(&mt('Make new user "[_1]"',$srchterm),'<>&"').'" onclick="javascript:setSearch(\'1\','.$caller.');" /> </p>';   $new_user_create = '<p> <input type="submit" name="forcenew" value="'.&HTML::Entities::encode(&mt('Make new user "[_1]"',$srchterm),'<>&"').'" onclick="javascript:setSearch(\'1\');" /> </p>';
         $newuserscript = <<"ENDSCRIPT";          $newuserscript = <<"ENDSCRIPT";
   
 function setSearch(createnew,callingForm) {  function setSearch(createnew) {
     if (createnew == 1) {      if (createnew == 1) {
         for (var i=0; i<callingForm.srchby.length; i++) {          for (var i=0; i<document.crtuser.srchby.length; i++) {
             if (callingForm.srchby.options[i].value == 'uname') {              if (document.crtuser.srchby.options[i].value == 'uname') {
                 callingForm.srchby.selectedIndex = i;                  document.crtuser.srchby.selectedIndex = i;
             }              }
         }          }
         for (var i=0; i<callingForm.srchin.length; i++) {          for (var i=0; i<document.crtuser.srchin.length; i++) {
             if ( callingForm.srchin.options[i].value == 'dom') {              if ( document.crtuser.srchin.options[i].value == 'dom') {
  callingForm.srchin.selectedIndex = i;   document.crtuser.srchin.selectedIndex = i;
             }              }
         }          }
         for (var i=0; i<callingForm.srchtype.length; i++) {          for (var i=0; i<document.crtuser.srchtype.length; i++) {
             if (callingForm.srchtype.options[i].value == 'exact') {              if (document.crtuser.srchtype.options[i].value == 'exact') {
                 callingForm.srchtype.selectedIndex = i;                  document.crtuser.srchtype.selectedIndex = i;
             }              }
         }          }
         for (var i=0; i<callingForm.srchdomain.length; i++) {          for (var i=0; i<document.crtuser.srchdomain.length; i++) {
             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {              if (document.crtuser.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                 callingForm.srchdomain.selectedIndex = i;                  document.crtuser.srchdomain.selectedIndex = i;
             }              }
         }          }
     }      }
Line 5673  ENDSCRIPT Line 5725  ENDSCRIPT
   
     my $output = <<"END_BLOCK";      my $output = <<"END_BLOCK";
 <script type="text/javascript">  <script type="text/javascript">
 function validateEntry(callingForm) {  function validateEntry() {
   
     var checkok = 1;      var checkok = 1;
     var srchin;      var srchin;
     for (var i=0; i<callingForm.srchin.length; i++) {      for (var i=0; i<document.crtuser.srchin.length; i++) {
  if ( callingForm.srchin[i].checked ) {   if ( document.crtuser.srchin[i].checked ) {
     srchin = callingForm.srchin[i].value;      srchin = document.crtuser.srchin[i].value;
  }   }
     }      }
   
     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;      var srchtype = document.crtuser.srchtype.options[document.crtuser.srchtype.selectedIndex].value;
     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;      var srchby = document.crtuser.srchby.options[document.crtuser.srchby.selectedIndex].value;
     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;      var srchdomain = document.crtuser.srchdomain.options[document.crtuser.srchdomain.selectedIndex].value;
     var srchterm =  callingForm.srchterm.value;      var srchterm =  document.crtuser.srchterm.value;
     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;      var srchin = document.crtuser.srchin.options[document.crtuser.srchin.selectedIndex].value;
     var msg = "";      var msg = "";
   
     if (srchterm == "") {      if (srchterm == "") {
         checkok = 0;          checkok = 0;
         msg += "$lt{'youm'}\\n";          msg += "You must include some text to search for.\\n";
     }      }
   
     if (srchtype== 'begins') {      if (srchtype== 'begins') {
         if (srchterm.length < 2) {          if (srchterm.length < 2) {
             checkok = 0;              checkok = 0;
             msg += "$lt{'thte'}\\n";              msg += "The text you are searching for must contain at least two characters when using a 'begins' type search.\\n";
         }          }
     }      }
   
     if (srchtype== 'contains') {      if (srchtype== 'contains') {
         if (srchterm.length < 3) {          if (srchterm.length < 3) {
             checkok = 0;              checkok = 0;
             msg += "$lt{'thet'}\\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') {
         if (srchdomain == '') {          if (srchdomain == '') {
             checkok = 0;              checkok = 0;
             msg += "$lt{'yomc'}\\n";              msg += "You must choose a domain when using an institutional directory search.\\n";
         }          }
     }      }
     if (srchin == 'dom') {      if (srchin == 'dom') {
         if (srchdomain == '') {          if (srchdomain == '') {
             checkok = 0;              checkok = 0;
             msg += "$lt{'ymcd'}\\n";              msg += "You must choose a domain when using a domain search.\\n";
         }          }
     }      }
     if (srchby == 'lastfirst') {      if (srchby == 'lastfirst') {
         if (srchterm.indexOf(",") == -1) {          if (srchterm.indexOf(",") == -1) {
             checkok = 0;              checkok = 0;
             msg += "$lt{'whus'}\\n";              msg += "When using searching by last,first you must include a comma as separator between last name and first name.\\n";
         }          }
         if (srchterm.indexOf(",") == srchterm.length -1) {          if (srchterm.indexOf(",") == srchterm.length -1) {
             checkok = 0;              checkok = 0;
             msg += "$lt{'whse'}\\n";              msg += "When searching by last,first you must include at least one character in the first name.\\n";
         }          }
     }      }
     if (checkok == 0) {      if (checkok == 0) {
         alert("$lt{'thfo'}\\n"+msg);          alert("The following need to be corrected before the search can be run:\\n"+msg);
         return;          return;
     }      }
     if (checkok == 1) {      if (checkok == 1) {
         callingForm.submit();          document.crtuser.submit();
     }      }
 }  }
   
Line 7318  sub icon { Line 7370  sub icon {
     return &lonhttpdurl($iconname);      return &lonhttpdurl($iconname);
 }   } 
   
 sub lonhttpd_port {  
     my $lonhttpd_port=$Apache::lonnet::perlvar{'lonhttpdPort'};  
     if (!defined($lonhttpd_port)) { $lonhttpd_port='8080'; }  
     # IE doesn't like a secure page getting images from a non-secure  
     # port (when logging we haven't parsed the browser type so default  
     # back to secure  
     if ((!exists($env{'browser.type'}) || $env{'browser.type'} eq 'explorer')  
  && $ENV{'SERVER_PORT'} == 443) {  
  return 443;  
     }  
     return $lonhttpd_port;  
   
 }  
   
 sub lonhttpdurl {  sub lonhttpdurl {
     my ($url)=@_;      my ($url)=@_;
       my $lonhttpd_port=$Apache::lonnet::perlvar{'lonhttpdPort'};
     my $lonhttpd_port = &lonhttpd_port();      if (!defined($lonhttpd_port)) { $lonhttpd_port='8080'; }
     if ($lonhttpd_port == 443) {  
  return 'https://'.$ENV{'SERVER_NAME'}.$url;  
     }  
     return 'http://'.$ENV{'SERVER_NAME'}.':'.$lonhttpd_port.$url;      return 'http://'.$ENV{'SERVER_NAME'}.':'.$lonhttpd_port.$url;
 }  }
   

Removed from v.1.564.2.6  
changed lines
  Added in v.1.569


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