Diff for /loncom/interface/loncreateuser.pm between versions 1.120 and 1.130

version 1.120, 2006/06/02 13:58:31 version 1.130, 2006/08/16 19:47:42
Line 142  sub print_username_entry_form { Line 142  sub print_username_entry_form {
                     'nr'   => "Name of Role",                      'nr'   => "Name of Role",
                     'cre'  => "Custom Role Editor"                      'cre'  => "Custom Role Editor"
        );         );
     my $help = &Apache::loncommon::help_open_menu('',undef,undef,'',282,'Instructor Interface');      my $help = &Apache::loncommon::help_open_menu(undef,undef,282,'Instructor Interface');
     my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');      my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
     my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');      my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
     $r->print(<<"ENDDOCUMENT");      $r->print(<<"ENDDOCUMENT");
Line 378  ENDSCRIPT Line 378  ENDSCRIPT
             var str = document.cu.elements[i].name;              var str = document.cu.elements[i].name;
             var checkcurr = str.match(re1);              var checkcurr = str.match(re1);
             if (checkcurr != null) {              if (checkcurr != null) {
                 var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;  
                 if (document.cu.elements[i-1].checked == true) {                  if (document.cu.elements[i-1].checked == true) {
                     var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;                      var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;
                     match = re2.exec(str);                      match = re2.exec(str);
Line 415  ENDSCRIPT Line 414  ENDSCRIPT
                             sections = document.cu.elements[i+1].value;                              sections = document.cu.elements[i+1].value;
                         }                          }
                         var newsecs = document.cu.elements[i+1].value;                          var newsecs = document.cu.elements[i+1].value;
    var numsplit;
                         if (newsecs != null && newsecs != "") {                          if (newsecs != null && newsecs != "") {
                             var numsplit = newsecs.split(/,/g);                              numsplit = newsecs.split(/,/g);
                             numsec = numsec + numsplit.length;                              numsec = numsec + numsplit.length;
                         }                          }
   
                         if ((role == 'st') && (numsec > 1)) {                          if ((role == 'st') && (numsec > 1)) {
                             alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.")                              alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.")
                             return;                              return;
                         }                          }
                         else {                          else if (numsplit != null) {
                             for (var j=0; j<numsplit.length; j++) {                              for (var j=0; j<numsplit.length; j++) {
                                 if ((numsplit[j] == 'all') ||                                  if ((numsplit[j] == 'all') ||
                                     (numsplit[j] == 'none')) {                                      (numsplit[j] == 'none')) {
Line 437  ENDSCRIPT Line 438  ENDSCRIPT
                                     }                                      }
                                 }                                  }
                             }                              }
                             document.cu.elements[i+2].value = sections;  
                         }                          }
                           document.cu.elements[i+2].value = sections;
                     }                      }
                 }                  }
             }              }
Line 603  END Line 604  END
                if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {                 if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
    $class='Course';     $class='Course';
                    my ($coursedom,$coursedir) = ($1,$2);                     my ($coursedom,$coursedir) = ($1,$2);
    $sortkey.="\0$1";     $sortkey.="\0$coursedom";
                    # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).                     # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
                    my %coursedata=                     my %coursedata=
                        &Apache::lonnet::coursedescription($1.'_'.$2);                         &Apache::lonnet::coursedescription($1.'_'.$2);
Line 618  END Line 619  END
        $carea=&mt('Unavailable course').': '.$area;         $carea=&mt('Unavailable course').': '.$area;
        $sortkey.="\0".&mt('Unavailable course').': '.$area;         $sortkey.="\0".&mt('Unavailable course').': '.$area;
    }     }
      $sortkey.="\0$coursedir";
                    $inccourses{$1.'_'.$2}=1;                     $inccourses{$1.'_'.$2}=1;
                    if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||                     if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
                        (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {                         (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
Line 1249  END Line 1251  END
                 my $output;                  my $output;
                 if ($role eq 'st') {                  if ($role eq 'st') {
                     if ($url =~ m-^/(\w+)/(\w+)/?(\w*)$-) {                      if ($url =~ m-^/(\w+)/(\w+)/?(\w*)$-) {
                         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);                          my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
                         if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {                          if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
                             $output = "Error: $result\n";                              $output = "Error: $result\n";
                         } else {                          } else {
Line 1296  END Line 1298  END
                 my %sections = ();                  my %sections = ();
                 my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);                  my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
                 if ($num_sections == 0) {                  if ($num_sections == 0) {
                     $r->print(&commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));                      $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
                 } else {                  } else {
     my %curr_groups =      my %curr_groups =
  &Apache::longroup::coursegroups($one,$two);   &Apache::longroup::coursegroups($one,$two);
Line 1307  END Line 1309  END
                             next;                              next;
                         }                          }
                         my $securl = $url.'/'.$sec;                          my $securl = $url.'/'.$sec;
         $r->print(&commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));          $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
                     }                      }
                 }                  }
     } elsif ($_=~/^form\.act\_([^\_]+)\_(\w+)\_([^\_]+)$/) {      } elsif ($_=~/^form\.act\_([^\_]+)\_(\w+)\_([^\_]+)$/) {
Line 1326  END Line 1328  END
                 my %sections = ();                  my %sections = ();
                 my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);                  my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
                 if ($num_sections == 0) {                  if ($num_sections == 0) {
                     $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));                      $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
                 } else {                  } else {
                     my %curr_groups =                       my %curr_groups = 
  &Apache::longroup::coursegroups($one,$two);   &Apache::longroup::coursegroups($one,$two);
Line 1340  END Line 1342  END
                                 next;                                  next;
                             }                              }
                             my $securl = $url.'/'.$sec;                              my $securl = $url.'/'.$sec;
                             $r->print(&commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));                              $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
                         } else {                          } else {
                             $emptysec = 1;                              $emptysec = 1;
                         }                          }
                     }                      }
                     if ($emptysec) {                      if ($emptysec) {
                         $r->print(&commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));                          $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
                     }                      }
                 }                   } 
     } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {      } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
Line 1363  END Line 1365  END
                 my %sections = ();                  my %sections = ();
                 my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);                  my $num_sections = &build_roles($env{'form.sec_'.$1.'_'.$2},\%sections,$2);
                 if ($num_sections == 0) {                  if ($num_sections == 0) {
                     $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));                      $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
                 } else {                  } else {
                     my $emptysec = 0;                      my $emptysec = 0;
                     foreach my $sec (sort {$a cmp $b} keys %sections) {                      foreach my $sec (sort {$a cmp $b} keys %sections) {
                         if ($sec ne '') {                          if ($sec ne '') {
                             my $securl = $url.'/'.$sec;                              my $securl = $url.'/'.$sec;
                             $r->print(&commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));                              $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$2,$start,$end,$1,undef,$sec));
                         } else {                          } else {
                             $emptysec = 1;                              $emptysec = 1;
                         }                          }
                     }                      }
                     if ($emptysec) {                      if ($emptysec) {
                         $r->print(&commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));                          $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$2,$start,$end,$1,undef,''));
                     }                      }
                 }                  }
     } else {      } else {
Line 1397  END Line 1399  END
     $r->print(&Apache::loncommon::end_page());      $r->print(&Apache::loncommon::end_page());
 }  }
   
 sub commit_customrole {  
     my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;  
     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.  
                          ($start?', '.&mt('starting').' '.localtime($start):'').  
                          ($end?', ending '.localtime($end):'').': <b>'.  
               &Apache::lonnet::assigncustomrole(  
                  $udom,$uname,$url,$three,$four,$five,$end,$start).  
                  '</b><br />';  
     return $output;  
 }  
   
 sub commit_standardrole {  
     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;  
     my $output;  
     my $logmsg;  
     if ($three eq 'st') {  
         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec);  
         if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {  
             $output = "Error: $result\n";   
         } else {  
             $output = &mt('Assigning').' '.$three.' in '.$url.  
                ($start?', '.&mt('starting').' '.localtime($start):'').  
                ($end?', '.&mt('ending').' '.localtime($end):'').  
                ': <b>'.$result.'</b><br />'.  
                &mt('Add to classlist').': <b>ok</b><br />';  
         }  
     } else {  
         $output = &mt('Assigning').' '.$three.' in '.$url.  
                ($start?', '.&mt('starting').' '.localtime($start):'').  
                ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.  
                &Apache::lonnet::assignrole(  
                    $udom,$uname,$url,$three,$end,$start).  
                    '</b><br />';  
     }  
     return $output;  
 }  
   
 sub commit_studentrole {  
     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec) = @_;  
     my $linefeed =  '<br />'."\n";  
     my $result;  
     if (defined($one) && defined($two)) {  
         my $cid=$one.'_'.$two;  
         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);  
         my $secchange = 0;  
         my $expire_role_result;  
         my $modify_section_result;  
         unless ($oldsec eq '-1') {  
             unless ($sec eq $oldsec) {  
                 $secchange = 1;  
                 my $uurl='/'.$cid;  
                 $uurl=~s/\_/\//g;  
                 if ($oldsec) {  
                     $uurl.='/'.$oldsec;  
                 }  
                 $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);  
                 $result = $expire_role_result;  
             }  
         }  
         if (($expire_role_result eq 'ok') || ($secchange == 0)) {  
             $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 ($secchange == 1) {  
                     $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;  
                 } elsif ($oldsec eq '-1') {  
                     $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;  
                 } else {  
                     $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;  
                 }  
             } 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;  
             }  
             $result = $modify_section_result;  
         } elsif ($secchange == 1) {  
             $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;  
         }  
     } else {  
         $$logmsg .= "Incomplete course id defined.  Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";  
         $result = "error: incomplete course id\n";  
     }  
     return $result;  
 }  
   
 sub build_roles {  sub build_roles {
     my ($sectionstr,$sections,$role) = @_;      my ($sectionstr,$sections,$role) = @_;
     my $num_sections = 0;      my $num_sections = 0;
Line 1509  sub build_roles { Line 1428  sub build_roles {
             $num_sections ++;              $num_sections ++;
         }          }
     }      }
                                                                                        
     return $num_sections;      return $num_sections;
 }  }
   
Line 1598  sub custom_role_editor { Line 1517  sub custom_role_editor {
 ENDCCF  ENDCCF
     foreach my $priv (sort keys %full) {      foreach my $priv (sort keys %full) {
         my $privtext = &Apache::lonnet::plaintext($priv);          my $privtext = &Apache::lonnet::plaintext($priv);
         if ($env{'course.'.$env{'request.course.id'}.'.type'}) {  
             $privtext =~ s/Student/Member/;  
             $privtext =~ s/student/member/;  
             $privtext =~ s/course/group/;  
         }   
  $r->print('<tr><td>'.$privtext.'</td><td>'.   $r->print('<tr><td>'.$privtext.'</td><td>'.
     ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.':c" '.      ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.':c" '.
     ($courselevelcurrent{$priv}?'checked="1"':'').' />':'&nbsp;').      ($courselevelcurrent{$priv}?'checked="1"':'').' />':'&nbsp;').
Line 1770  sub course_level_table { Line 1684  sub course_level_table {
  foreach  ('st','ta','ep','in','cc') {   foreach  ('st','ta','ep','in','cc') {
     if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {      if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
  my $plrole=&Apache::lonnet::plaintext($_);   my $plrole=&Apache::lonnet::plaintext($_);
                 if ($type eq 'Group') {  
                     $plrole = &Apache::loncommon::convert_role($plrole,$type);  
                 }   
  $table .= <<ENDEXTENT;   $table .= <<ENDEXTENT;
 <tr bgcolor="#$bgcol">  <tr bgcolor="#$bgcol">
 <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>  <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>

Removed from v.1.120  
changed lines
  Added in v.1.130


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