Diff for /loncom/interface/loncommon.pm between versions 1.612 and 1.630

version 1.612, 2007/11/10 03:51:46 version 1.630, 2008/01/01 20:27:29
Line 472  sub setsec_javascript { Line 472  sub setsec_javascript {
     my ($sec_element,$formname) = @_;      my ($sec_element,$formname) = @_;
     my $setsections = qq|      my $setsections = qq|
 function setSect(sectionlist) {  function setSect(sectionlist) {
     var sectionsArray = sectionlist.split(",");      var sectionsArray = new Array();
       if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
           sectionsArray = sectionlist.split(",");
       }
     var numSections = sectionsArray.length;      var numSections = sectionsArray.length;
     document.$formname.$sec_element.length = 0;      document.$formname.$sec_element.length = 0;
     if (numSections == 0) {      if (numSections == 0) {
Line 1942  sub authform_kerberos { Line 1945  sub authform_kerberos {
     if (defined($in{'curr_authtype'})) {      if (defined($in{'curr_authtype'})) {
         if ($in{'curr_authtype'} eq 'krb') {          if ($in{'curr_authtype'} eq 'krb') {
             $krbcheck = ' checked="on"';              $krbcheck = ' checked="on"';
               if (defined($in{'mode'})) {
                   if ($in{'mode'} eq 'modifyuser') {
                       $krbcheck = '';
                   }
               }
             if (defined($in{'curr_kerb_ver'})) {              if (defined($in{'curr_kerb_ver'})) {
                 if ($in{'curr_krb_ver'} eq '5') {                  if ($in{'curr_krb_ver'} eq '5') {
                     $check5 = ' checked="on"';                      $check5 = ' checked="on"';
Line 2039  sub authform_internal{ Line 2047  sub authform_internal{
         if ($in{'curr_authtype'} eq 'int') {          if ($in{'curr_authtype'} eq 'int') {
             if ($can_assign{'int'}) {              if ($can_assign{'int'}) {
                 $intcheck = 'checked="on" ';                  $intcheck = 'checked="on" ';
                   if (defined($in{'mode'})) {
                       if ($in{'mode'} eq 'modifyuser') {
                           $intcheck = '';
                       }
                   }
                 if (defined($in{'curr_autharg'})) {                  if (defined($in{'curr_autharg'})) {
                     $intarg = $in{'curr_autharg'};                      $intarg = $in{'curr_autharg'};
                 }                  }
Line 2073  sub authform_internal{ Line 2086  sub authform_internal{
     $result = &mt      $result = &mt
         ('[_1] Internally authenticated (with initial password [_2])',          ('[_1] Internally authenticated (with initial password [_2])',
          '<label>'.$authtype,'</label>'.$autharg);           '<label>'.$authtype,'</label>'.$autharg);
       $result.="<label><input type=\"checkbox\" name=\"visible\" onClick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
     return $result;      return $result;
 }  }
   
Line 2088  sub authform_local{ Line 2102  sub authform_local{
         if ($in{'curr_authtype'} eq 'loc') {          if ($in{'curr_authtype'} eq 'loc') {
             if ($can_assign{'loc'}) {              if ($can_assign{'loc'}) {
                 $loccheck = 'checked="on" ';                  $loccheck = 'checked="on" ';
                   if (defined($in{'mode'})) {
                       if ($in{'mode'} eq 'modifyuser') {
                           $loccheck = '';
                       }
                   }
                 if (defined($in{'curr_autharg'})) {                  if (defined($in{'curr_autharg'})) {
                     $locarg = $in{'curr_autharg'};                      $locarg = $in{'curr_autharg'};
                 }                  }
Line 2137  sub authform_filesystem{ Line 2156  sub authform_filesystem{
         if ($in{'curr_authtype'} eq 'fsys') {          if ($in{'curr_authtype'} eq 'fsys') {
             if ($can_assign{'fsys'}) {              if ($can_assign{'fsys'}) {
                 $fsyscheck = 'checked="on" ';                  $fsyscheck = 'checked="on" ';
                   if (defined($in{'mode'})) {
                       if ($in{'mode'} eq 'modifyuser') {
                           $fsyscheck = '';
                       }
                   }
             } else {              } else {
                 $result = &mt('Currently Filesystem Authenticated.');                  $result = &mt('Currently Filesystem Authenticated.');
                 return $result;                  return $result;
Line 4834  table.LC_descriptive_input td.LC_descrip Line 4858  table.LC_descriptive_input td.LC_descrip
   font-weight: bold;    font-weight: bold;
 }  }
 div.LC_feedback_link {  div.LC_feedback_link {
     clear: both;
   background: white;    background: white;
   width: 100%;      width: 100%;  
 }  }
Line 5037  div.LC_clear_float_footer { Line 5062  div.LC_clear_float_footer {
   
   
 div.LC_grade_select_mode {  div.LC_grade_select_mode {
   float: left;  
   font-family: $sans;    font-family: $sans;
 }  }
 div.LC_grade_select_mode div div {  div.LC_grade_select_mode div div {
Line 5097  span.LC_grade_check_note { Line 5121  span.LC_grade_check_note {
   right: 1em;    right: 1em;
 }  }
   
   table.LC_scantron_action {
     width: 100%;
   }
   table.LC_scantron_action tr th {
     font: normal bold $sans;
   }
   
 div.LC_edit_problem_header {  div.LC_edit_problem_header, 
   div.LC_edit_problem_footer {
   font: normal medium $sans;    font: normal medium $sans;
   margin: 2px;    margin: 2px;
 }  }
 div.LC_edit_problem_header,  div.LC_edit_problem_header,
 div.LC_edit_problem_header div,  div.LC_edit_problem_header div,
   div.LC_edit_problem_footer,
   div.LC_edit_problem_footer div,
 div.LC_edit_problem_editxml_header,  div.LC_edit_problem_editxml_header,
 div.LC_edit_problem_editxml_header div {  div.LC_edit_problem_editxml_header div {
   margin-top: 5px;    margin-top: 5px;
Line 5818  previous, future, or all. Line 5851  previous, future, or all.
 6. reference to results object (hash of hashes).  6. reference to results object (hash of hashes).
 7. reference to optional userdata hash  7. reference to optional userdata hash
 8. reference to optional statushash  8. reference to optional statushash
   9. flag if privileged users (except those set to unhide in
      course settings) should be excluded    
 Keys of top level results hash are roles.  Keys of top level results hash are roles.
 Keys of inner hashes are username:domain, with   Keys of inner hashes are username:domain, with 
 values set to access type.  values set to access type.
Line 5834  of the possibility of multiple values fo Line 5869  of the possibility of multiple values fo
 ###############################################  ###############################################
   
 sub get_course_users {  sub get_course_users {
     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash) = @_;      my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
     my %idx = ();      my %idx = ();
     my %seclists;      my %seclists;
   
Line 5851  sub get_course_users { Line 5886  sub get_course_users {
         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);          my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
         my $now = time;          my $now = time;
         foreach my $student (keys(%{$classlist})) {          foreach my $student (keys(%{$classlist})) {
             my $status;  
             my $match = 0;              my $match = 0;
             my $secmatch = 0;              my $secmatch = 0;
             my $section = $$classlist{$student}[$idx{section}];              my $section = $$classlist{$student}[$idx{section}];
Line 5911  sub get_course_users { Line 5945  sub get_course_users {
                               active   => 'Active',                                active   => 'Active',
                               future   => 'Future',                                future   => 'Future',
                             );                              );
           my %nothide;
           if ($hidepriv) {
               my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
               foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   if ($user !~ /:/) {
                       $nothide{join(':',split(/[\@]/,$user))}=1;
                   } else {
                       $nothide{$user} = 1;
                   }
               }
           }
         foreach my $person (sort(keys(%coursepersonnel))) {          foreach my $person (sort(keys(%coursepersonnel))) {
             my $match = 0;              my $match = 0;
             my $secmatch = 0;              my $secmatch = 0;
Line 5944  sub get_course_users { Line 5989  sub get_course_users {
                     $usec = 'none';                      $usec = 'none';
                 }                  }
                 if ($uname ne '' && $udom ne '') {                  if ($uname ne '' && $udom ne '') {
                       if ($hidepriv) {
                           if ((&Apache::lonnet::privileged($uname,$udom)) &&
                               (!$nothide{$uname.':'.$udom})) {
                               next;
                           }
                       }
                     if ($end > 0 && $end < $now) {                      if ($end > 0 && $end < $now) {
                         $status = 'previous';                          $status = 'previous';
                     } elsif ($start > $now) {                      } elsif ($start > $now) {
Line 6138  sub default_quota { Line 6189  sub default_quota {
     my ($udom,$inststatus) = @_;      my ($udom,$inststatus) = @_;
     my ($defquota,$settingstatus);      my ($defquota,$settingstatus);
     my %quotahash = &Apache::lonnet::get_dom('configuration',      my %quotahash = &Apache::lonnet::get_dom('configuration',
                                             ['quota'],$udom);                                              ['quotas'],$udom);
     if (ref($quotahash{'quota'}) eq 'HASH') {      if (ref($quotahash{'quotas'}) eq 'HASH') {
         if ($inststatus ne '') {          if ($inststatus ne '') {
             my @statuses = split(/:/,$inststatus);              my @statuses = split(/:/,$inststatus);
             foreach my $item (@statuses) {              foreach my $item (@statuses) {
                 if ($quotahash{'quota'}{$item} ne '') {                  if ($quotahash{'quotas'}{$item} ne '') {
                     if ($defquota eq '') {                      if ($defquota eq '') {
                         $defquota = $quotahash{'quota'}{$item};                          $defquota = $quotahash{'quotas'}{$item};
                         $settingstatus = $item;                          $settingstatus = $item;
                     } elsif ($quotahash{'quota'}{$item} > $defquota) {                      } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                         $defquota = $quotahash{'quota'}{$item};                          $defquota = $quotahash{'quotas'}{$item};
                         $settingstatus = $item;                          $settingstatus = $item;
                     }                      }
                 }                  }
             }              }
         }          }
         if ($defquota eq '') {          if ($defquota eq '') {
             $defquota = $quotahash{'quota'}{'default'};              $defquota = $quotahash{'quotas'}{'default'};
             $settingstatus = 'default';              $settingstatus = 'default';
         }          }
     } else {      } else {
Line 6207  sub get_secgrprole_info { Line 6258  sub get_secgrprole_info {
 }  }
   
 sub user_picker {  sub user_picker {
     my ($dom,$srch,$forcenewuser,$caller) = @_;      my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
     my $currdom = $dom;      my $currdom = $dom;
     my %curr_selected = (      my %curr_selected = (
                         srchin => 'dom',                          srchin => 'dom',
                         srchby => 'lastname',                          srchby => 'lastname',
                       );                        );
     my $srchterm;      my $srchterm;
     if (ref($srch) eq 'HASH') {      if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
         if ($srch->{'srchby'} ne '') {          if ($srch->{'srchby'} ne '') {
             $curr_selected{'srchby'} = $srch->{'srchby'};              $curr_selected{'srchby'} = $srch->{'srchby'};
         }          }
Line 6301  sub user_picker { Line 6352  sub user_picker {
     if ($forcenewuser) {      if ($forcenewuser) {
         if (ref($srch) eq 'HASH') {          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'}) {              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>';                  if ($cancreate) {
                       $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>';
                   } else {
                       my $helplink = ' href="javascript:helpMenu('."'display'".')"';
                       my %usertypetext = (
                           official   => 'institutional',
                           unofficial => 'non-institutional',
                       );
                       $new_user_create = '<br /><span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
                   }
             }              }
         }          }
   
Line 6431  END_BLOCK Line 6491  END_BLOCK
 }  }
   
 sub user_rule_check {  sub user_rule_check {
     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules) = @_;      my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
     my $response;      my $response;
     if (ref($usershash) eq 'HASH') {      if (ref($usershash) eq 'HASH') {
         my %got_rules;  
         foreach my $user (keys(%{$usershash})) {          foreach my $user (keys(%{$usershash})) {
             my ($uname,$udom) = split(/:/,$user);              my ($uname,$udom) = split(/:/,$user);
             next if ($udom eq '' || $uname eq '');              next if ($udom eq '' || $uname eq '');
             my ($userstatus,$id);              my ($id,$newuser);
             if (ref($usershash->{$user}) eq 'HASH') {              if (ref($usershash->{$user}) eq 'HASH') {
                 $userstatus = $usershash->{$user}->{'status'};                  $newuser = $usershash->{$user}->{'newuser'};
                 $id = $usershash->{$user}->{'id'};                  $id = $usershash->{$user}->{'id'};
             }              }
             my $inst_response;              my $inst_response;
             if (ref($checks) eq 'HASH') {              if (ref($checks) eq 'HASH') {
                 if (defined($checks->{'username'})) {                  if (defined($checks->{'username'})) {
                     ($inst_response,%{$inst_results}) =                       ($inst_response,%{$inst_results->{$user}}) = 
                         &Apache::lonnet::get_instuser($udom,$uname);                          &Apache::lonnet::get_instuser($udom,$uname);
                 } elsif (defined($checks->{'id'})) {                  } elsif (defined($checks->{'id'})) {
                     ($inst_response,%{$inst_results}) =                      ($inst_response,%{$inst_results->{$user}}) =
                         &Apache::lonnet::get_instuser($udom,undef,$id);                          &Apache::lonnet::get_instuser($udom,undef,$id);
                 }                  }
               } else {
                   ($inst_response,%{$inst_results->{$user}}) =
                       &Apache::lonnet::get_instuser($udom,$uname);
                   return;
             }              }
             if (!$got_rules{$udom}) {              if (!$got_rules->{$udom}) {
                 my %domconfig = &Apache::lonnet::get_dom('configuration',                  my %domconfig = &Apache::lonnet::get_dom('configuration',
                                                   ['usercreation'],$udom);                                                    ['usercreation'],$udom);
                 if (ref($domconfig{'usercreation'}) eq 'HASH') {                  if (ref($domconfig{'usercreation'}) eq 'HASH') {
                     foreach my $item (keys(%{$checks})) {                      foreach my $item ('username','id') {
                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {                          if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                             $$curr_rules{$udom}{$item} =                               $$curr_rules{$udom}{$item} = 
                                 $domconfig{'usercreation'}{$item.'_rule'};                                  $domconfig{'usercreation'}{$item.'_rule'};
                         }                          }
                     }                      }
                 }                  }
                 $got_rules{$udom} = 1;                  $got_rules->{$udom} = 1;  
             }              }
             foreach my $item (keys(%{$checks})) {              foreach my $item (keys(%{$checks})) {
                 if (ref($$curr_rules{$udom}) eq 'HASH') {                  if (ref($$curr_rules{$udom}) eq 'HASH') {
                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {                      if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                         if (@{$$curr_rules{$udom}{$item}} > 0) {                          if (@{$$curr_rules{$udom}{$item}} > 0) {
                             my %rule_check;  
                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});                              my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {                              foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                                 if ($rule_check{$rule}) {                                  if ($rule_check{$rule}) {
                                     $$rulematch{$user}{$item} = $rule;                                      $$rulematch{$user}{$item} = $rule;
                                     if ($inst_response eq 'ok') {                                      if ($inst_response eq 'ok') {
                                         if (keys(%{$inst_results}) == 0) {                                          if (ref($inst_results) eq 'HASH') {
                                             if ($userstatus eq 'new') {                                              if (ref($inst_results->{$user}) eq 'HASH') {
                                                 $$alerts{$user}{$item} = 1;                                                  if (keys(%{$inst_results->{$user}}) == 0) {
                                                       $$alerts{$item}{$udom}{$uname} = 1;
                                                   }
                                             }                                              }
                                         }                                          }
                                     }                                        }
                                       last;
                                 }                                  }
                             }                              }
                             last;  
                         }                          }
                     }                      }
                 }                  }
Line 6522  sub user_rule_formats { Line 6586  sub user_rule_formats {
 }  }
   
 sub instrule_disallow_msg {  sub instrule_disallow_msg {
     my ($checkitem,$domdesc,$count) = @_;      my ($checkitem,$domdesc,$count,$mode) = @_;
     my $response;      my $response;
     my %text = (      my %text = (
                   item   => 'username',                    item   => 'username',
Line 6543  sub instrule_disallow_msg { Line 6607  sub instrule_disallow_msg {
         $text{'items'} = 'IDs';          $text{'items'} = 'IDs';
         $text{'item'} = 'ID';          $text{'item'} = 'ID';
         $text{'action'} = 'an ID';          $text{'action'} = 'an ID';
           if ($count > 1) {
               $text{'item'} = 'IDs';
               $text{'action'} = 'IDs';
           }
     }      }
     $response = &mt("The $text{'item'} you chose $text{'match'} the format of $text{'items'} defined for <span class=\"LC_cusr_emph\">[_1]</span>, but the $text{'item'} $text{'do'} not exist in the institutional directory.",$domdesc).'<br />';      $response = &mt("The $text{'item'} you chose $text{'match'} the format of $text{'items'} defined for <span class=\"LC_cusr_emph\">[_1]</span>, but the $text{'item'} $text{'do'} not exist in the institutional directory.",$domdesc).'<br />';
     if ($checkitem eq 'username') {      if ($mode eq 'upload') {
         $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");          if ($checkitem eq 'username') {
     } elsif ($checkitem eq 'id') {              $response .= &mt("You will need to modify your upload file so it will include $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
        $response .= &mt("You must either choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or leave this field blank.");          } elsif ($checkitem eq 'id') {
               $response .= &mt("Either upload a file which includes $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or when associating fields with data columns, omit an association for the ID/Student Number field.");
           }
       } else {
           if ($checkitem eq 'username') {
               $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
           } elsif ($checkitem eq 'id') {
               $response .= &mt("You must either choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or leave the ID field blank.");
           }
     }      }
     return $response;      return $response;
 }  }
   
   sub personal_data_fieldtitles {
       my %fieldtitles = &Apache::lonlocal::texthash (
                           id => 'Student/Employee ID',
                           permanentemail => 'E-mail address',
                           lastname => 'Last Name',
                           firstname => 'First Name',
                           middlename => 'Middle Name',
                           generation => 'Generation',
                           gen => 'Generation',
                      );
       return %fieldtitles;
   }
   
 =pod  =pod
   
 =back  =back
Line 7611  sub restore_settings { Line 7700  sub restore_settings {
     }      }
 }  }
   
   #######################################################
   #######################################################
   
   =pod
   
   =head1 Domain E-mail Routines  
   
   =over 4
   
   =item &build_recipient_list
   
   Build recipient lists for three types of e-mail:
   (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
   lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
   
   Inputs:
   defmail (scalar - email address of default recipient), 
   mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
   defdom (domain for which to retrieve configuration settings),
   origmail (scalar - email address of recipient from loncapa.conf, 
   i.e., predates configuration by DC via domainprefs.pm 
   
   Returns: comma separated list of addresses to which to send e-mail.   
   
   =cut
   
   ############################################################
   ############################################################
   sub build_recipient_list {
       my ($defmail,$mailing,$defdom,$origmail) = @_;
       my @recipients;
       my $otheremails;
       my %domconfig =
            &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
       if (ref($domconfig{'contacts'}) eq 'HASH') {
           if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
               my @contacts = ('adminemail','supportemail');
               foreach my $item (@contacts) {
                   if ($domconfig{'contacts'}{$mailing}{$item}) {
                       my $addr = $domconfig{'contacts'}{$item}; 
                       if (!grep(/^\Q$addr\E$/,@recipients)) {
                           push(@recipients,$addr);
                       }
                   }
                   $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
               }
           }
       } elsif ($origmail ne '') {
           push(@recipients,$origmail);
       }
       if ($defmail ne '') {
           push(@recipients,$defmail);
       }
       if ($otheremails) {
           my @others;
           if ($otheremails =~ /,/) {
               @others = split(/,/,$otheremails);
           } else {
               push(@others,$otheremails);
           }
           foreach my $addr (@others) {
               if (!grep(/^\Q$addr\E$/,@recipients)) {
                   push(@recipients,$addr);
               }
           }
       }
       my $recipientlist = join(',',@recipients); 
       return $recipientlist;
   }
   
 ############################################################  ############################################################
 ############################################################  ############################################################
   
 sub commit_customrole {  sub commit_customrole {
     my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;      my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.      my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
                          ($start?', '.&mt('starting').' '.localtime($start):'').                           ($start?', '.&mt('starting').' '.localtime($start):'').
                          ($end?', ending '.localtime($end):'').': <b>'.                           ($end?', ending '.localtime($end):'').': <b>'.
               &Apache::lonnet::assigncustomrole(                &Apache::lonnet::assigncustomrole(
Line 7637  sub commit_standardrole { Line 7796  sub commit_standardrole {
         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,          my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                                          $one,$two,$sec,$context);                                           $one,$two,$sec,$context);
         if (($result =~ /^error/) || ($result eq 'not_in_class') ||           if (($result =~ /^error/) || ($result eq 'not_in_class') || 
             ($result eq 'unknown_course')) {              ($result eq 'unknown_course') || ($result eq 'refused')) {
             $output = "Error: $result\n";               $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
         } else {          } else {
             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.              $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
                ($start?', '.&mt('starting').' '.localtime($start):'').                 ($start?', '.&mt('starting').' '.localtime($start):'').
Line 7667  sub commit_standardrole { Line 7826  sub commit_standardrole {
   
 sub commit_studentrole {  sub commit_studentrole {
     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;      my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
     my ($result,$linefeed);      my ($result,$linefeed,$oldsecurl,$newsecurl);
     if ($context eq 'auto') {      if ($context eq 'auto') {
         $linefeed = "\n";          $linefeed = "\n";
     } else {      } else {
Line 7679  sub commit_studentrole { Line 7838  sub commit_studentrole {
         my $secchange = 0;          my $secchange = 0;
         my $expire_role_result;          my $expire_role_result;
         my $modify_section_result;          my $modify_section_result;
         unless ($oldsec eq '-1') {          if ($oldsec ne '-1') { 
             unless ($sec eq $oldsec) {              if ($oldsec ne $sec) {
                 $secchange = 1;                  $secchange = 1;
                   my $now = time;
                 my $uurl='/'.$cid;                  my $uurl='/'.$cid;
                 $uurl=~s/\_/\//g;                  $uurl=~s/\_/\//g;
                 if ($oldsec) {                  if ($oldsec) {
                     $uurl.='/'.$oldsec;                      $uurl.='/'.$oldsec;
                 }                  }
                 $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);                  $oldsecurl = $uurl;
                   $expire_role_result = 
                       &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now);
                   if ($env{'request.course.sec'} ne '') { 
                       if ($expire_role_result eq 'refused') {
                           my @roles = ('st');
                           my @statuses = ('previous');
                           my @roledoms = ($one);
                           my $withsec = 1;
                           my %roleshash = 
                               &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                                                 \@statuses,\@roles,\@roledoms,$withsec);
                           if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                               my ($oldstart,$oldend) = 
                                   split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                               if ($oldend > 0 && $oldend <= $now) {
                                   $expire_role_result = 'ok';
                               }
                           }
                       }
                   }
                 $result = $expire_role_result;                  $result = $expire_role_result;
             }              }
         }          }
Line 7695  sub commit_studentrole { Line 7875  sub commit_studentrole {
             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);              $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
             if ($modify_section_result =~ /^ok/) {              if ($modify_section_result =~ /^ok/) {
                 if ($secchange == 1) {                  if ($secchange == 1) {
                     $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;                      if ($sec eq '') {
                           $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                       } else {
                           $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                       }
                 } elsif ($oldsec eq '-1') {                  } elsif ($oldsec eq '-1') {
                     $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;                      if ($sec eq '') {
                           $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                       } else {
                           $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                       }
                 } else {                  } else {
                     $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;                      if ($sec eq '') {
                           $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                       } else {
                           $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                       }
                 }                  }
             } else {              } else {
                 $$logmsg .= "Error when attempting section change for $uname from old section $oldsec to new section: $sec in course $cid -error: $modify_section_result".$linefeed;                  if ($secchange) {       
                       $$logmsg .= &mt('Error when attempting section change for [_1] from old section "[_2]" to new section: "[_3]" in course [_4] -error:',$uname,$oldsec,$sec,$cid).' '.$modify_section_result.$linefeed;
                   } else {
                       $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   }
             }              }
             $result = $modify_section_result;              $result = $modify_section_result;
         } elsif ($secchange == 1) {          } elsif ($secchange == 1) {
             $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;              if ($oldsec eq '') {
                   $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
               } else {
                   $$logmsg .= &mt('Error when attempting to expire existing role for [_1] in section [_2] in course [_3] -error: ',$uname,$oldsec,$cid).' '.$expire_role_result.$linefeed;
               }
               if ($expire_role_result eq 'refused') {
                   my $newsecurl = '/'.$cid;
                   $newsecurl =~ s/\_/\//g;
                   if ($sec ne '') {
                       $newsecurl.='/'.$sec;
                   }
                   if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                       if ($sec eq '') {
                           $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments unaffiliated with any section.',$sec).$linefeed;
                       } else {
                           $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',$sec).$linefeed;
                       }
                   }
               }
         }          }
     } else {      } else {
         $$logmsg .= "Incomplete course id defined.  Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";          $$logmsg .= &mt('Incomplete course id defined.').$linefeed.&mt('Addition of user [_1] from domain [_2] to course [_3], section [_4] not completed.',$uname,$udom,$one.'_'.$two,$sec).$linefeed;
         $result = "error: incomplete course id\n";          $result = "error: incomplete course id\n";
     }      }
     return $result;      return $result;
Line 7921  sub construct_course { Line 8135  sub construct_course {
     }      }
     if ($args->{'notify_dc'}) {      if ($args->{'notify_dc'}) {
         if ($uname ne '') {           if ($uname ne '') { 
             push(@notified,$uname.'@'.$udom);              push(@notified,$uname.':'.$udom);
         }          }
     }      }
     if (@notified > 0) {      if (@notified > 0) {

Removed from v.1.612  
changed lines
  Added in v.1.630


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