Diff for /loncom/interface/lonpickcourse.pm between versions 1.123 and 1.127

version 1.123, 2017/01/02 19:44:06 version 1.127, 2017/04/08 14:28:56
Line 44  sub handler { Line 44  sub handler {
     if ($env{'form.context'} eq 'adhoc') {      if ($env{'form.context'} eq 'adhoc') {
         &Apache::loncommon::content_type($r,'application/json');          &Apache::loncommon::content_type($r,'application/json');
         $r->send_http_header;          $r->send_http_header;
         my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.cid'});          my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.cid'},1);
         if ((ref($possroles) eq 'ARRAY') && (ref($description) eq 'HASH')) {          if ((ref($possroles) eq 'ARRAY') && (ref($description) eq 'HASH')) {
             my $response = [];              my $response = [];
             if (@{$possroles}) {              if (@{$possroles}) {
Line 89  sub handler { Line 89  sub handler {
         $title = 'Selecting '.$type.'(s)';          $title = 'Selecting '.$type.'(s)';
     }      }
   
     # if called when a DC or DH is selecting a course       # if called when a DC, DH or DA is selecting a course 
     my ($roledom,$rolename) = split(/:/,$env{'form.roleelement'});      my ($roledom,$rolename) = split(/:/,$env{'form.roleelement'});
     if ($roledom) {      if ($roledom) {
         $roleelement = '<input type="hidden" name="roleelement" value="'.$env{'form.roleelement'}.'" />';          $roleelement = '<input type="hidden" name="roleelement" value="'.$env{'form.roleelement'}.'" />';
         $submitopener = &processpick();          $submitopener = &processpick();
         $autosubmit = 'process_pick("'.$roledom.'","'.$rolename.'")';          $autosubmit = 'process_pick("'.$roledom.'","'.$rolename.'")';
         if ($rolename eq 'dh') {          if (($rolename eq 'dh') || ($rolename eq 'da')) {
             my %lt = &Apache::lonlocal::texthash(              my %lt = &Apache::lonlocal::texthash(
                      title    => 'Ad hoc role selection',                       title    => 'Ad hoc role selection',
                      preamble => 'Please choose an ad hoc role in the course.',                       preamble => 'Please choose an ad hoc role in the course.',
Line 103  sub handler { Line 103  sub handler {
             );              );
   
             $rolechooser = <<"END";              $rolechooser = <<"END";
 <div id="LC_adhocrole_chooser" title="$lt{'title'}">  <div id="LC_adhocrole_chooser" title="$lt{'title'}" style="display:none">
   <p>$lt{'preamble'}</p>    <p>$lt{'preamble'}</p>
   <form name="LChelpdeskadhoc" id="LChelpdeskpicker" action="">    <form name="LChelpdeskadhoc" id="LChelpdeskpicker" action="">
     <div id="LC_choose_adhoc">      <div id="LC_choose_adhoc">
Line 440  sub display_matched_courses { Line 440  sub display_matched_courses {
         $action = '/adm/portfolio';          $action = '/adm/portfolio';
     }      }
     my $numcourses = keys(%courses);      my $numcourses = keys(%courses);
     $r->print('<form name="courselist" method="post" action="'.$action.'">');      $r->print('<form name="courselist" method="post" action="'.$action.'" id="LCcoursepicker">');
     if ($env{'form.form'} eq 'modifycourse') {      if ($env{'form.form'} eq 'modifycourse') {
         if ($numcourses > 0) {          if ($numcourses > 0) {
             my $ccrole = 'cc';              my $ccrole = 'cc';
Line 469  sub display_matched_courses { Line 469  sub display_matched_courses {
                     $r->print(&mt('Enter the course with the role of [_1].',$cctitle));                      $r->print(&mt('Enter the course with the role of [_1].',$cctitle));
                 }                  }
             } elsif (&Apache::lonnet::allowed('rar',$crsdom)) {              } elsif (&Apache::lonnet::allowed('rar',$crsdom)) {
                 my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},                  my ($roles_by_num,$description,$accessref,$accessinfo) = &Apache::lonnet::get_all_adhocroles($crsdom);
                                                                   'adhocroles.'.$crsdom);                  if ((ref($roles_by_num) eq 'ARRAY') && (ref($description) eq 'HASH')) {
                 if ($adhocroles{'adhocroles.'.$crsdom} ne '') {                      if (@{$roles_by_num} > 1) {
                     $possrole = 1;                          $r->print($roleradio);
                     $r->print($roleradio);  
                     my @adhoc = split(/,/,$adhocroles{'adhocroles.'.$crsdom});  
                     if (@adhoc > 1) {  
                         my %adhochash;  
                         map { $adhochash{$_} = $_; } @adhoc;   
                         my $selector = &Apache::loncommon::select_form($adhoc[0],'adhocrole',\%adhochash);  
                         if ($type eq 'Community') {                          if ($type eq 'Community') {
                             $r->print(&mt('Enter the community with one of the available ad hoc roles: [_1].',                              $r->print(&mt('Enter the community with one of the available ad hoc roles.'));
                                           $selector));   
                         } elsif ($type eq 'Placement') {                          } elsif ($type eq 'Placement') {
                             $r->print(&mt('Enter the placement test with one of the available ad hoc roles: [_1].',                              $r->print(&mt('Enter the placement test with one of the available ad hoc roles.'));
                                           $selector));  
                         } else {                          } else {
                             $r->print(&mt('Enter the course with one of the available ad hoc roles: [_1].',                              $r->print(&mt('Enter the course with one of the available ad hoc roles.'));
                                           $selector));  
                         }                          }
                     } else {                          $possrole = 1;
                       } elsif (@{$roles_by_num} == 1) {
                           $r->print($roleradio);
                           my $rolename = $description->{$roles_by_num->[0]};
                         if ($type eq 'Community') {                          if ($type eq 'Community') {
                             $r->print(&mt('Enter the community with the ad hoc role of: [_1]',$adhoc[0]));                              $r->print(&mt('Enter the community with the ad hoc role of: [_1]',$rolename));
                         } elsif ($type eq 'Placement') {                          } elsif ($type eq 'Placement') {
                             $r->print(&mt('Enter the placement test with the ad hoc role of: [_1]',$adhoc[0]));                              $r->print(&mt('Enter the placement test with the ad hoc role of: [_1]',$rolename));
                         } else {                          } else {
                             $r->print(&mt('Enter the course with the ad hoc role of: [_1]',$adhoc[0]));                              $r->print(&mt('Enter the course with the ad hoc role of: [_1]',$rolename));
                         }                          }
                         $r->print('<input type="hidden" name="adhocrole" value="'.$adhoc[0].'" />');                          $possrole = 1;
                       }
                       if ($possrole) {
                           $r->print('<input type="hidden" name="adhocrole" value="" />');
                     }                      }
                 }                  }
             }              }
             if ($possrole) {               if ($possrole) {
                 $r->print('</label></span><br />');                  $r->print('</label></span><br />');
             }              }
             $r->print('<span class="LC_nobreak"><label>'              $r->print('<span class="LC_nobreak"><label>'
Line 766  sub display_matched_courses { Line 763  sub display_matched_courses {
         $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');          $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
         $r->print('<input type="hidden" name="action" value="rolepicker" />');          $r->print('<input type="hidden" name="action" value="rolepicker" />');
     } elsif ($env{'form.form'} eq 'modifycourse') {      } elsif ($env{'form.form'} eq 'modifycourse') {
         $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state']));          $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state','adhocrole']));
     } else {      } else {
         $r->print('<input type="hidden" name="cnumelement" value="'.          $r->print('<input type="hidden" name="cnumelement" value="'.
                   $env{'form.cnumelement'}.'" />'."\n".                      $env{'form.cnumelement'}.'" />'."\n".  
Line 872  sub gochoose_javascript { Line 869  sub gochoose_javascript {
     my $output;      my $output;
     if ($rolechooser) {      if ($rolechooser) {
         $output .= qq|          $output .= qq|
 \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });  \$(document).ready(function(){
       \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
   });
 |;  |;
     }      }
     $output .= qq|      $output .= qq|
Line 959  ENDNAMECODE Line 958  ENDNAMECODE
         document.courselist.cnum.value = cname;          document.courselist.cnum.value = cname;
         document.courselist.cdom.value = cdom;          document.courselist.cdom.value = cdom;
     }      }
     if ((openerForm == 'rolechoice') && (openerRole == 'dh')) {      if ((openerForm == 'rolechoice') && ((openerRole == 'dh') || (openerRole == 'da'))) {
 \$("#LC_choose_adhoc").empty();  \$("#LC_choose_adhoc").empty();
 var http = new XMLHttpRequest();  var http = new XMLHttpRequest();
 var url = "/adm/pickcourse";  var url = "/adm/pickcourse";
Line 978  http.onreadystatechange = function() { Line 977  http.onreadystatechange = function() {
                 $lastaction;                  $lastaction;
             } else {              } else {
                 var str = '';                  var str = '';
                   \$("#LC_choose_adhoc").empty();
                 for (var i=0; i<data.roles.length; i++) {                   for (var i=0; i<data.roles.length; i++) { 
                     \$("<label><input type='radio' value='"+data.roles[i].name+"' name='LC_get_role' id='LC_get_role_"+i+"' />"+data.roles[i].desc+"</label><span>&nbsp;&nbsp;</span>")                      \$("<label><input type='radio' value='"+data.roles[i].name+"' name='LC_get_role' id='LC_get_role_"+i+"' />"+data.roles[i].desc+"</label><span>&nbsp;&nbsp;</span>")
                     .appendTo("#LC_choose_adhoc");                      .appendTo("#LC_choose_adhoc");
                 }                  }
                   \$( "#LC_adhocrole_chooser" ).toggle( true );
                 \$( "#LC_get_role_0").prop("checked", true);                  \$( "#LC_get_role_0").prop("checked", true);
                 \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });                  \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
                 \$( "#LC_adhocrole_chooser" ).dialog("open");                  \$( "#LC_adhocrole_chooser" ).dialog("open");
Line 1030  ENDJS Line 1031  ENDJS
     return $rolechooser.&Apache::lonhtmlcommon::scripttag($output);      return $rolechooser.&Apache::lonhtmlcommon::scripttag($output);
 }  }
   
 sub get_my_adhocroles {  
     my (@okroles,%description);  
     if ($env{'form.cid'} =~ /^($match_domain)_($match_courseid)$/) {  
         my $cdom = $1;  
         my $cnum = $2;  
         if ($env{"user.role.dh./$cdom/"}) {  
             my $then=$env{'user.login.time'};  
             my $update=$env{'user.update.time'};  
             my $liverole = 1;  
             my ($tstart,$tend)=split(/\./,$env{'user.role.dh./'.$cdom});  
             my $limit = $update;  
             if ($env{'request.role'} eq 'dh./'.$cdom.'/') {  
                 $limit = $then;  
             }  
             if ($tstart && $tstart>$limit) { $liverole = 0; }  
             if ($tend   && $tend  <$limit) { $liverole = 0; }  
             if ($liverole) {  
                 if (&Apache::lonnet::homeserver($cnum,$cdom) ne 'no_host') {  
                     my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);  
                     if (ref($domdefaults{'adhocroles'}) eq 'HASH') {  
                         my $count = 0;  
                         my %domcurrent = %{$domdefaults{'adhocroles'}};  
                         my (%ordered,%access_in_dom);  
                         foreach my $role (sort(keys(%{$domdefaults{'adhocroles'}}))) {  
                             my ($order,$desc,$access_in_dom);  
                             if (ref($domcurrent{$role}) eq 'HASH') {  
                                 $order = $domcurrent{$role}{'order'};  
                                 $desc = $domcurrent{$role}{'desc'};  
                                 $access_in_dom{$role} = $domcurrent{$role}{'access'};  
                             }  
                             if ($order eq '') {  
                                 $order = $count;  
                             }  
                             $ordered{$order} = $role;  
                             if ($desc ne '') {  
                                 $description{$role} = $desc;  
                             } else {  
                                 $description{$role}= $role;  
                             }  
                             $count++;  
                         }  
                         my @roles_by_num = ();  
                         foreach my $item (sort {$a <=> $b } (keys(%ordered))) {  
                             push(@roles_by_num,$ordered{$item});  
                         }  
                         if (@roles_by_num) {  
                             my %settings = &Apache::lonnet::dump('environment',$cdom,$cnum,'internal\.adhoc');  
                             my %setincrs;  
                             if ($settings{'internal.adhocaccess'}) {  
                                 map { $setincrs{$_} = 1; } split(/,/,$settings{'internal.adhocaccess'});  
                             }  
                             my @statuses;  
                             if ($env{'environment.inststatus'}) {  
                                 @statuses = split(/,/,$env{'environment.inststatus'});  
                             }  
                             my $user = $env{'user.name'}.':'.$env{'user.domain'};  
                             foreach my $role (@roles_by_num) {  
                                 my ($curraccess,@okstatus,@personnel);  
                                 if ($setincrs{$role}) {  
                                     ($curraccess,my $rest) = split(/=/,$settings{'internal.adhoc.'.$role});  
                                     if ($curraccess eq 'none') {  
                                         next;  
                                     } elsif ($curraccess eq 'all') {  
                                         push(@okroles,$role);  
                                     } elsif ($curraccess eq 'status') {  
                                         @okstatus = split(/\&/,$rest);  
                                     } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {  
                                         @personnel = split(/\&/,$rest);  
                                     }  
                                 } else {  
                                     $curraccess = $access_in_dom{$role};  
                                     if ($curraccess eq 'status') {  
                                         if (ref($domcurrent{$role}{$curraccess}) eq 'ARRAY') {  
                                             @okstatus = @{$domcurrent{$role}{$curraccess}};  
                                         }  
                                     } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {  
                                         if (ref($domcurrent{$role}{$curraccess}) eq 'ARRAY') {  
                                             @personnel = @{$domcurrent{$role}{$curraccess}};  
                                         }  
                                     }  
                                 }  
                                 if ($curraccess eq 'none') {  
                                     next;  
                                 } elsif ($curraccess eq 'all') {  
                                     push(@okroles,$role);  
                                 } elsif ($curraccess eq 'status') {  
                                     if (@okstatus) {  
                                         if (!@statuses) {  
                                             if (grep(/^default$/,@okstatus)) {  
                                                 push(@okroles,$role);  
                                             }  
                                         } else {  
                                             foreach my $status (@okstatus) {  
                                                 if (grep(/^\Q$status\E$/,@statuses)) {  
                                                     push(@okroles,$role);  
                                                     last;  
                                                 }  
                                             }  
                                         }  
                                     }  
                                 } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {  
                                     if (grep(/^\Q$user\E$/,@personnel)) {  
                                         if ($curraccess eq 'exc') {  
                                             push(@okroles,$role);  
                                         }  
                                     } elsif ($curraccess eq 'inc') {  
                                         push(@okroles,$role);  
                                     }  
                                 }  
                             }  
                         }  
                     }  
                 }  
             }  
         }  
     }  
   
     my $response = [];  
     if (@okroles) {  
         foreach my $role (@okroles) {  
             push(@{$response},  
                               { name => $role,  
                                 desc => $description{$role},  
                               });  
         }  
     }  
     my $json = JSON::DWIW->to_json({roles => $response});  
     return $json;  
 }  
   
 1;  1;
 __END__  __END__
   

Removed from v.1.123  
changed lines
  Added in v.1.127


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