Diff for /loncom/interface/loncommon.pm between versions 1.564 and 1.564.2.9

version 1.564, 2007/08/15 18:03:22 version 1.564.2.9, 2007/09/05 00:25:52
Line 3458  sub bodytag { Line 3458  sub bodytag {
     if (!$realm) { $realm=' '; }      if (!$realm) { $realm=' '; }
 # 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 3578  ENDROLE Line 3575  ENDROLE
   
     my $imgsrc = $img;      my $imgsrc = $img;
     if ($img =~ /^\/adm/) {      if ($img =~ /^\/adm/) {
         $imgsrc = 'http://'.$ENV{'HTTP_HOST'}.':'.$lonhttpdPort.$img;          $imgsrc = &lonhttpdurl($img);
     }      }
     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';      my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
   
Line 4454  span.LC_nobreak { Line 4451  span.LC_nobreak {
   white-space: nowrap;    white-space: nowrap;
 }  }
   
   span.LC_cusr_emph {
     font-style: italic;
   }
   
 table.LC_docs_documents {  table.LC_docs_documents {
   background: #BBBBBB;    background: #BBBBBB;
   border-width: 0px;    border-width: 0px;
Line 5552  sub get_secgrprole_info { Line 5553  sub get_secgrprole_info {
 }  }
   
 sub user_picker {  sub user_picker {
     my ($dom,$srch,$forcenewuser) = @_;      my ($dom,$srch,$forcenewuser,$caller) = @_;
     my $currdom = $dom;      my $currdom = $dom;
     my %curr_selected = (      my %curr_selected = (
                         srchin => 'dom',                          srchin => 'dom',
Line 5575  sub user_picker { Line 5576  sub user_picker {
         $srchterm = $srch->{'srchterm'};          $srchterm = $srch->{'srchterm'};
     }      }
     my %lt=&Apache::lonlocal::texthash(      my %lt=&Apache::lonlocal::texthash(
                       'usr'       => 'Search criteria',
                     'doma'      => 'Domain/institution to search',                      'doma'      => 'Domain/institution to search',
                     'uname'     => 'username',                      'uname'     => 'username',
                     'lastname'  => 'last name',                      'lastname'  => 'last name',
                     'lastfirst' => 'last name, first name',                      'lastfirst' => 'last name, first name',
                     'crs'       => 'in this course',                      'crs'       => 'in this course',
                     'dom'       => 'in this domain',                       'dom'       => 'in selected LON-CAPA domain', 
                     'alc'       => 'all LON-CAPA',                      'alc'       => 'all LON-CAPA',
                     'instd'     => 'in institutional directory',                      'instd'     => 'in institutional directory for selected domain',
                     'exact'     => 'is',                      'exact'     => 'is',
                     'contains'  => 'contains',                      'contains'  => 'contains',
                       '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 5620  sub user_picker { Line 5631  sub user_picker {
     $srchbysel .= "\n  </select>\n";      $srchbysel .= "\n  </select>\n";
   
     my $srchtypesel = ' <select name="srchtype">';      my $srchtypesel = ' <select name="srchtype">';
     foreach my $option ('exact','contains') {      foreach my $option ('exact','begins','contains') {
         if ($curr_selected{'srchtype'} eq $option) {          if ($curr_selected{'srchtype'} eq $option) {
             $srchtypesel .= '              $srchtypesel .= '
    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';     <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
Line 5634  sub user_picker { Line 5645  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\');" /> </p>';          if (ref($srch) eq 'HASH') {
               if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
           $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>';
               }
           }
   
         $newuserscript = <<"ENDSCRIPT";          $newuserscript = <<"ENDSCRIPT";
   
 function setSearch(createnew) {  function setSearch(createnew,callingForm) {
     if (createnew == 1) {      if (createnew == 1) {
         for (var i=0; i<document.crtuser.srchby.length; i++) {          for (var i=0; i<callingForm.srchby.length; i++) {
             if (document.crtuser.srchby.options[i].value == 'uname') {              if (callingForm.srchby.options[i].value == 'uname') {
                 document.crtuser.srchby.selectedIndex = i;                  callingForm.srchby.selectedIndex = i;
             }              }
         }          }
         for (var i=0; i<document.crtuser.srchin.length; i++) {          for (var i=0; i<callingForm.srchin.length; i++) {
             if ( document.crtuser.srchin.options[i].value == 'dom') {              if ( callingForm.srchin.options[i].value == 'dom') {
  document.crtuser.srchin.selectedIndex = i;   callingForm.srchin.selectedIndex = i;
             }              }
         }          }
         for (var i=0; i<document.crtuser.srchtype.length; i++) {          for (var i=0; i<callingForm.srchtype.length; i++) {
             if (document.crtuser.srchtype.options[i].value == 'exact') {              if (callingForm.srchtype.options[i].value == 'exact') {
                 document.crtuser.srchtype.selectedIndex = i;                  callingForm.srchtype.selectedIndex = i;
             }              }
         }          }
         for (var i=0; i<document.crtuser.srchdomain.length; i++) {          for (var i=0; i<callingForm.srchdomain.length; i++) {
             if (document.crtuser.srchdomain.options[i].value == '$env{'request.role.domain'}') {              if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                 document.crtuser.srchdomain.selectedIndex = i;                  callingForm.srchdomain.selectedIndex = i;
             }              }
         }          }
     }      }
Line 5667  ENDSCRIPT Line 5683  ENDSCRIPT
   
     my $output = <<"END_BLOCK";      my $output = <<"END_BLOCK";
 <script type="text/javascript">  <script type="text/javascript">
 function validateEntry() {  function validateEntry(callingForm) {
   
     var checkok = 1;      var checkok = 1;
     var srchin;      var srchin;
     for (var i=0; i<document.crtuser.srchin.length; i++) {      for (var i=0; i<callingForm.srchin.length; i++) {
  if ( document.crtuser.srchin[i].checked ) {   if ( callingForm.srchin[i].checked ) {
     srchin = document.crtuser.srchin[i].value;      srchin = callingForm.srchin[i].value;
  }   }
     }      }
   
     var srchtype = document.crtuser.srchtype.options[document.crtuser.srchtype.selectedIndex].value;      var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
     var srchby = document.crtuser.srchby.options[document.crtuser.srchby.selectedIndex].value;      var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
     var srchdomain = document.crtuser.srchdomain.options[document.crtuser.srchdomain.selectedIndex].value;      var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
     var srchterm =  document.crtuser.srchterm.value;      var srchterm =  callingForm.srchterm.value;
     var srchin = document.crtuser.srchin.options[document.crtuser.srchin.selectedIndex].value;      var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
     var msg = "";      var msg = "";
   
     if (srchterm == "") {      if (srchterm == "") {
         checkok = 0;          checkok = 0;
         msg += "You must include some text to search for.\\n";          msg += "$lt{'youm'}\\n";
       }
   
       if (srchtype== 'begins') {
           if (srchterm.length < 2) {
               checkok = 0;
               msg += "$lt{'thte'}\\n";
           }
     }      }
   
     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 'contains' type search.\\n";              msg += "$lt{'thet'}\\n";
         }          }
     }      }
     if (srchin == 'instd') {      if (srchin == 'instd') {
         if (srchdomain == '') {          if (srchdomain == '') {
             checkok = 0;              checkok = 0;
             msg += "You must choose a domain when using an institutional directory search.\\n";              msg += "$lt{'yomc'}\\n";
         }          }
     }      }
     if (srchin == 'dom') {      if (srchin == 'dom') {
         if (srchdomain == '') {          if (srchdomain == '') {
             checkok = 0;              checkok = 0;
             msg += "You must choose a domain when using a domain search.\\n";              msg += "$lt{'ymcd'}\\n";
         }          }
     }      }
     if (srchby == 'lastfirst') {      if (srchby == 'lastfirst') {
         if (srchterm.indexOf(",") == -1) {          if (srchterm.indexOf(",") == -1) {
             checkok = 0;              checkok = 0;
             msg += "When using searching by last,first you must include a comma as separator between last name and first name.\\n";              msg += "$lt{'whus'}\\n";
         }          }
         if (srchterm.indexOf(",") == srchterm.length -1) {          if (srchterm.indexOf(",") == srchterm.length -1) {
             checkok = 0;              checkok = 0;
             msg += "When searching by last,first you must include at least one character in the first name.\\n";              msg += "$lt{'whse'}\\n";
         }          }
     }      }
     if (checkok == 0) {      if (checkok == 0) {
         alert("The following need to be corrected before the search can be run:\\n"+msg);          alert("$lt{'thfo'}\\n"+msg);
         return;          return;
     }      }
     if (checkok == 1) {      if (checkok == 1) {
         document.crtuser.submit();          callingForm.submit();
     }      }
 }  }
   
Line 5734  $new_user_create Line 5757  $new_user_create
   
 <table>  <table>
  <tr>   <tr>
     <td>$lt{'doma'}:</td>
     <td>$domform</td>
     </td>
    </tr>
    <tr>
     <td>$lt{'usr'}:</td>
   <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         $srchinsel 
   </td>    </td>
  </tr>   </tr>
  <tr>  
   <td>$lt{'doma'}: $domform</td>  
   </td>  
  </tr>  
 </table>  </table>
 <br />  <br />
 END_BLOCK  END_BLOCK
Line 5751  END_BLOCK Line 5776  END_BLOCK
     return $output;      return $output;
 }  }
   
   
   
 =pod  =pod
   
 =back  =back
Line 6912  sub commit_studentrole { Line 6935  sub commit_studentrole {
 ############################################################  ############################################################
 ############################################################  ############################################################
   
   sub check_clone {
       my ($args) = @_;
       my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
       my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
       my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
       my $clonemsg;
       my $can_clone = 0;
   
       if ($clonehome eq 'no_host') {
    $clonemsg = &mt('Attempting to clone non-existing [_1]',
    $args->{'crstype'});
       } else {
    my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
    if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
       $can_clone = 1;
    } else {
       my %clonehash = &Apache::lonnet::get('environment',['cloners'],
    $args->{'clonedomain'},$args->{'clonecourse'});
       my @cloners = split(/,/,$clonehash{'cloners'});
       my %roleshash =
    &Apache::lonnet::get_my_roles($args->{'ccuname'},
         $args->{'ccdomain'},'userroles',['active'],['cc'],
         [$args->{'clonedomain'}]);
       if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
    $can_clone = 1;
       } else {
    $clonemsg = &mt('The new course was not cloned from an existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
       }
    }
       }
   
       return ($can_clone, $clonemsg, $cloneid, $clonehome);
   }
   
 sub construct_course {  sub construct_course {
     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;      my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
     my $outcome;      my $outcome;
Line 6919  sub construct_course { Line 6976  sub construct_course {
     if ($context eq 'auto') {      if ($context eq 'auto') {
         $linefeed = "\n";          $linefeed = "\n";
     }      }
   
   #
   # Are we cloning?
   #
       my ($can_clone, $clonemsg, $cloneid, $clonehome);
       if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
    ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args);
    if ($context ne 'auto') {
       $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
    }
    $outcome .= $clonemsg.$linefeed;
   
           if (!$can_clone) {
       return (0,$outcome);
    }
       }
   
 #  #
 # Open course  # Open course
 #  #
Line 6939  sub construct_course { Line 7013  sub construct_course {
     # if anyone ever decides to not show this, and Utils::Course::new      # if anyone ever decides to not show this, and Utils::Course::new
     # will need to be suitably modified.      # will need to be suitably modified.
     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;      $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
   
 #  #
 # Check if created correctly  # Check if created correctly
 #  #
     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);      ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);      my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;      $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
   
 #  #
 # Are we cloning?  # Do the cloning
 #  #   
     my $cloneid='';      if ($can_clone && $cloneid) {
     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {   $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
         my $can_clone = 0;   if ($context ne 'auto') {
  $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};      $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
         my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);   }
  my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);   $outcome .= $clonemsg.$linefeed;
         my $clonemsg;   my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
  if ($clonehome eq 'no_host') {  
             $clonemsg = &mt('Attempting to clone non-existing [_1]',$crstype);  
             if ($context eq 'auto') {  
                 $outcome .= $clonemsg;  
             } else {  
         $outcome .= '<font color="red">'.$clonemsg.'</font>';  
             }  
             $outcome .= $linefeed;  
  } else {  
             my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});  
             if ($env{'request.role.domain'} eq $args->{'form.clonedomain'}) {  
                 $can_clone = 1;  
             } else {  
                 my %clonehash = &Apache::lonnet::get('environment',['cloners'],  
                             $args->{'clonedomain'},$args->{'clonecourse'});  
                 my @cloners = split(/,/,$clonehash{'cloners'});  
                 my %roleshash =  
                     &Apache::lonnet::get_my_roles($args->{'ccuname'},  
                         $args->{'ccdomain'},'userroles',['active'],['cc'],  
                         [$args->{'clonedomain'}]);  
                 if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {  
                     $can_clone = 1;  
                 } else {  
                     $clonemsg = &mt('The new course was not cloned from an existing course because the course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});  
                     if ($context eq 'auto') {  
                         $outcome .= $clonemsg;  
                     } else {  
                         $outcome .= '<font color="red">'.$clonemsg.'</font>';  
                     }  
                     $outcome .= $linefeed;  
                 }  
             }  
         }  
         if ($can_clone) {  
     $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);  
             if ($context eq 'auto') {  
                 $outcome = $clonemsg;  
             } else {   
                 $outcome .= '<font color="green">'.$clonemsg.'</font>';  
             }  
             $outcome .= $linefeed;  
     my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);  
 # Copy all files  # Copy all files
     &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid);   &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid);
 # Restore URL  # Restore URL
     $cenv{'url'}=$oldcenv{'url'};   $cenv{'url'}=$oldcenv{'url'};
 # Restore title  # Restore title
     $cenv{'description'}=$oldcenv{'description'};   $cenv{'description'}=$oldcenv{'description'};
 # restore grading mode  # restore grading mode
     if (defined($oldcenv{'grading'})) {   if (defined($oldcenv{'grading'})) {
  $cenv{'grading'}=$oldcenv{'grading'};      $cenv{'grading'}=$oldcenv{'grading'};
     }  
 # Mark as cloned  
     $cenv{'clonedfrom'}=$cloneid;  
     delete($cenv{'default_enrollment_start_date'});  
     delete($cenv{'default_enrollment_end_date'});  
  }   }
   # Mark as cloned
    $cenv{'clonedfrom'}=$cloneid;
    delete($cenv{'default_enrollment_start_date'});
    delete($cenv{'default_enrollment_end_date'});
     }      }
   
 #  #
 # Set environment (will override cloned, if existing)  # Set environment (will override cloned, if existing)
 #  #
Line 7121  sub construct_course { Line 7153  sub construct_course {
                            ' ('.$lt{'adby'}.')';                             ' ('.$lt{'adby'}.')';
         if ($context eq 'auto') {          if ($context eq 'auto') {
             $outcome .= $badclass_msg.$linefeed;              $outcome .= $badclass_msg.$linefeed;
             $outcome .= '<font color="red">'.$badclass_msg.$linefeed.'<ul>'."\n";              $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
             foreach my $item (@badclasses) {              foreach my $item (@badclasses) {
                 if ($context eq 'auto') {                  if ($context eq 'auto') {
                     $outcome .= " - $item\n";                      $outcome .= " - $item\n";
Line 7132  sub construct_course { Line 7164  sub construct_course {
             if ($context eq 'auto') {              if ($context eq 'auto') {
                 $outcome .= $linefeed;                  $outcome .= $linefeed;
             } else {              } else {
                 $outcome .= "</ul><br /><br /></font>\n";                  $outcome .= "</ul><br /><br /></div>\n";
             }              }
         }           } 
     }      }
Line 7154  sub construct_course { Line 7186  sub construct_course {
             if ($context eq 'auto') {              if ($context eq 'auto') {
                 $outcome .= $krb_msg;                  $outcome .= $krb_msg;
             } else {              } else {
                 $outcome .= '<font color="red" size="+1">'.$krb_msg.'</font>';                  $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
             }              }
             $outcome .= $linefeed;              $outcome .= $linefeed;
         }          }
Line 7252  sub construct_course { Line 7284  sub construct_course {
  if ($errtext) { $fatal=2; }   if ($errtext) { $fatal=2; }
         $outcome .= ($fatal?$errtext:'write ok').$linefeed;          $outcome .= ($fatal?$errtext:'write ok').$linefeed;
     }      }
     return $outcome;  
       return (1,$outcome);
 }  }
   
 ############################################################  ############################################################
Line 7295  sub icon { Line 7328  sub icon {
     return &lonhttpdurl($iconname);      return &lonhttpdurl($iconname);
 }   } 
   
 sub lonhttpdurl {  sub lonhttpd_port {
     my ($url)=@_;  
     my $lonhttpd_port=$Apache::lonnet::perlvar{'lonhttpdPort'};      my $lonhttpd_port=$Apache::lonnet::perlvar{'lonhttpdPort'};
     if (!defined($lonhttpd_port)) { $lonhttpd_port='8080'; }      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 {
       my ($url)=@_;
   
       my $lonhttpd_port = &lonhttpd_port();
       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  
changed lines
  Added in v.1.564.2.9


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