[LON-CAPA-cvs] cvs: loncom /interface lonpopulate.pm

raeburn raeburn at source.lon-capa.org
Tue Nov 8 19:48:53 EST 2016


raeburn		Wed Nov  9 00:48:53 2016 EDT

  Modified files:              
    /loncom/interface	lonpopulate.pm 
  Log:
  - Automated enrollment settings in a course displayed to roles with 'opa' priv,
    but 'cst' priv is required for editing.  
  
  
-------------- next part --------------
Index: loncom/interface/lonpopulate.pm
diff -u loncom/interface/lonpopulate.pm:1.84 loncom/interface/lonpopulate.pm:1.85
--- loncom/interface/lonpopulate.pm:1.84	Sun Jul 24 14:34:59 2016
+++ loncom/interface/lonpopulate.pm	Wed Nov  9 00:48:52 2016
@@ -1,5 +1,5 @@
 # automated enrollment configuration handler
-# $Id: lonpopulate.pm,v 1.84 2016/07/24 14:34:59 raeburn Exp $
+# $Id: lonpopulate.pm,v 1.85 2016/11/09 00:48:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -40,8 +40,8 @@
 
 ###############################################################
 sub header {
-    my ($action) = @_;
-    my $args = &make_crumbs($action);
+    my ($action,$permref) = @_;
+    my $args = &make_crumbs($action,$permref);
     return 
         &Apache::loncommon::start_page('Classlist Manager',undef,$args);
 }
@@ -49,7 +49,7 @@
 ###############################################################
 
 sub choose_header {
-    my ($action) = @_;
+    my ($action,$permref) = @_;
     my $notify_check = '/^note_[0-9]+$/';
     my %js_lt = 
         &Apache::lonlocal::texthash(
@@ -60,14 +60,25 @@
             eras => 'Click "OK" to erase all recipients, or "Cancel".',
             ynot => 'You have indicated that you want notification of roster changes messages to be sent, but you have not selected any recipients.',
             atle => 'You must check at least one checkbox, before proceeding to the next page',
+            noed => 'You do not have rights to modify automated enrollment settings',
     );
     $js_lt{'both'} = &mt('You have selected "No" for both addition and removal of students[_1] in the institutional classlist but not in your LON-CAPA course.[_1]',"\n");
     $js_lt{'nnot'} = &mt('You have indicated that you do not want notification of roster changes messages to be sent, but [_1] have been checked as recipients.[_2]',"'+totalnote+'","\n");
     &js_escape(\%js_lt);
-    
-    my $scripttag = <<ENDJSONE;
+
+    my $scripttag = '
 <script type="text/javascript" language="JavaScript">
 // <![CDATA[
+';
+    if ((ref($permref) ne 'HASH') || (!$permref->{'edit'})) {
+        $scripttag .= <<ENDJS;
+function process(calling,numauto,nummanual,numlock,numunlock) {
+    alert('$js_lt{'noed'}');
+    return false;
+}
+ENDJS
+    } else {
+        $scripttag .= <<ENDJSONE;
 function process(calling,numauto,nummanual,numlock,numunlock) {
  var checker = 1
  var rad1 = 0
@@ -187,6 +198,7 @@
  }
 }
 ENDJSONE
+    }
     if ($action eq 'viewclass') {
         $scripttag .= &Apache::loncommon::check_uncheck_jscript();
         $scripttag .= <<ENDJSTWO;
@@ -212,14 +224,14 @@
 // ]]>
 </script>
 ENDJS
-    my $args = &make_crumbs($action);
+    my $args = &make_crumbs($action,$permref);
     return &Apache::loncommon::start_page('Classlist Manager',
 					  $scripttag,$args);
 }
 
 sub make_crumbs {
-    my ($action) = @_;
-    my ($tasklong,$tasktitle) = &get_task_text();
+    my ($action,$permref) = @_;
+    my ($tasklong,$tasktitle) = &get_task_text($permref);
     my $brcrum = [{href=>"/adm/createuser",
                    text=>"User Management",},
                  {href=>"/adm/populate",
@@ -231,7 +243,6 @@
     } elsif ($action eq 'newsections') {
         $action = 'sections';
     }
-    my ($tasklong,$tasktitle) = &get_task_text();
     my $text;
     if (ref($tasklong) eq 'HASH') {
         $text = $tasklong->{$action};
@@ -282,11 +293,16 @@
 ###############################################################
 
 sub print_main_frame {
-  my ($r,$realm,$dom,$crs,$tasktitleref) = @_;
+  my ($r,$realm,$dom,$crs,$tasktitleref,$permref) = @_;
   my $action = "information";
   if (exists($env{'form.action'}) ) {
       $action = $env{'form.action'};
   }
+  my ($disabled,$readonly);
+  unless ($permref->{'edit'}) {
+      $disabled = ' disabled="disabled"';
+      $readonly = 1;
+  }
 
 # Get course settings
   my %enrollvar;
@@ -305,7 +321,9 @@
             <tr>
               <td> </td>
               <td><b>'.&mt('Use the menu on the left to choose an enrollment management task.').'</b><br /><br /></td>
-            </tr>
+            </tr>');
+      if ($permref->{'edit'}) {
+          $r->print(' 
             <tr>
               <td> </td>
               <td>'.&mt('Use [_1]Automated adds/drops[_2] to enable or disable automatic nightly adds or drops in your LON-CAPA course based on institutional enrollment information.','<i>"','"</i>').'</td>
@@ -352,8 +370,55 @@
             <tr>
             <td> </td>
               <td>'.&mt('Use [_1]Change zero enrollment failsafe[_2] to set number of existing enrollments in an institutional section above which no automated drops occur whenever section enrollment retrieved from institutional data is zero.','<i>"','"</i>').'</td>
+            </tr>');
+      } else {
+          if (($permref->{'view'}) || ($permref->{'view_section'} ne '')) {
+              $r->print('
+            <tr>
+              <td> </td>
+              <td>'.&mt('Use [_1]Automated adds/drops[_2] to display status of automatic nightly adds or drops based on institutional enrollment information.','<i>"','"</i>').'</td>
+            </tr>
+            <tr>
+              <td> </td>
+              <td>'.&mt('Use [_1]Enrollment dates[_2] to display the date of first automated enrollment and last automated enrollment for registered students.','<i>"','"</i>').'</td>
+            </tr>
+            <tr>
+              <td> </td>
+              <td>'.&mt('Use [_1]Access dates[_2] to display the default start and/or end dates for student roles created by automated enrollment.','<i>"','"</i>').'</td>
+            </tr>
+            <tr>
+              <td> </td>
+              <td>'.&mt('Use [_1]Notification of changes[_2] to display which course coordinators (if any) receive notification of enrollment changes.','<i>"','"</i>').'</td>
+            </tr>
+            <tr>
+              <td> </td>
+              <td>'.&mt('Use [_1]Crosslisting[_2] to display enrollment settings for crosslisted classes.',
+                        '<i>"','"</i>').'</td>
+            </tr>
+            <tr>
+              <td> </td>
+              <td>'.&mt('Use [_1]Section settings[_2] to display sections included for enrollment.',
+                        '<i>"','"</i>').'</td>
+            </tr>
+            <tr>
+              <td> </td>
+              <td>'.&mt('Use [_1]Student photo settings[_2] to display settings for automatic import of photos for registered students.',
+                        '<i>"','"</i>').'</td>
             </tr>
             <tr>
+            <td> </td>
+              <td>'.&mt('Use [_1]Zero enrollment failsafe[_2] to set number of existing enrollments in an institutional section above which no automated drops occur whenever section enrollment retrieved from institutional data is zero.','<i>"','"</i>').'</td>
+            </tr>');
+          }
+          if (($permref->{'show'}) || ($permref->{'show_section'} ne '')) {
+              $r->print('
+            <tr>
+              <td> </td>
+              <td>'.&mt('Use [_1]View students and enrollment type[_2] to display the current course roster and enrollment type ("auto" or "manual").','<i>"','"</i>').'</td>
+            </tr>');
+          }
+          $r->print('
+            <tr>
              <td colspan="2"> </td>
             </tr>
             <tr>
@@ -361,6 +426,7 @@
              <td><b>'.&mt('Note: if automated adds and/or drops are enabled, the nightly enrollment update will ONLY occur once the first enrollment date has been reached.').'</b></td>
             </tr>
           </table>');
+      }
   } elsif ($action eq 'chgsettings') {
       my @autosets = (&mt('OFF'),&mt('ON'));
       $r->print('
@@ -378,15 +444,15 @@
 		        '.&mt('Additions based on classlist changes:').'  ');
       if ($enrollvar{autoadds}) {
           $r->print('
-			    <label><input type="radio" name="autoadds" value="1" checked="checked" /> '.
+			    <label><input type="radio" name="autoadds" value="1" checked="checked"'.$disabled.' /> '.
                             &mt('Enable').'   </label>
-			    <label><input type="radio" name="autoadds" value="0" /> '.
+			    <label><input type="radio" name="autoadds" value="0"'.$disabled.' /> '.
                             &mt('Disable').'</label>');
       } else {
           $r->print('
-                            <label><input type="radio" name="autoadds" value="1" /> '.
+                            <label><input type="radio" name="autoadds" value="1"'.$disabled.' /> '.
                             &mt('Enable').'   </label>
-                            <label><input type="radio" name="autoadds" value="0" checked="checked" /> '.
+                            <label><input type="radio" name="autoadds" value="0" checked="checked"'.$disabled.' /> '.
                             &mt('Disable').'</label>');
       }
       $r->print('
@@ -397,15 +463,15 @@
  	       '.&mt('Removals based on classlist changes:').'  ');
       if ($enrollvar{autodrops}) {
           $r->print('
-                <label><input type="radio" name="autodrops" value="1" checked="checked" /> '.
+                <label><input type="radio" name="autodrops" value="1" checked="checked"'.$disabled.' /> '.
                 &mt('Enable').'   </label>
-                <label><input type="radio" name="autodrops" value="0" /> '.
+                <label><input type="radio" name="autodrops" value="0"'.$disabled.' /> '.
                 &mt('Disable').'</label>');
       } else {
           $r->print('
-                <label><input type="radio" name="autodrops" value="1" /> '.
+                <label><input type="radio" name="autodrops" value="1"'.$disabled.' /> '.
                 &mt('Enable').'   </label>
-                <label><input type="radio" name="autodrops" value="0" checked="checked" /> '.
+                <label><input type="radio" name="autodrops" value="0" checked="checked"'.$disabled,' /> '.
                 &mt('Disable').'</label>');
       }
       $r->print('
@@ -420,7 +486,7 @@
              </tr>
              <tr>
               <td align="right">
-               <input type="button" name="chgsettings" value="'.&mt('Go').'" onclick="process('."'chgsettings'".')" />
+               <input type="button" name="chgsettings" value="'.&mt('Go').'" onclick="process('."'chgsettings'".')"'.$disabled.' />
 	      </td>
              </tr>
 	    </table>
@@ -463,7 +529,7 @@
             <tr>
              <td><b>
             '.&mt('Failsafe (enter an integer)').'</b>  
-              <input type="textbox" name="autodropfailsafe" value="'.$enrollvar{'autodropfailsafe'}.'" size="4" /><br />');
+              <input type="textbox" name="autodropfailsafe" value="'.$enrollvar{'autodropfailsafe'}.'" size="4"'.$disabled.' /><br />');
        if ($enrollvar{'autodropfailsafe'}) {
           if ($autofailsafe) {  
               $r->print(&mt('Leave blank to use domain default of [_1].',$autofailsafe));
@@ -484,7 +550,7 @@
             </tr>
             <tr>
              <td align="right">
-              <input type="button" name="updatefailsafe" value="'.&mt('Go').'" onclick="'."process('chgfailsafe')".'" />
+              <input type="button" name="updatefailsafe" value="'.&mt('Go').'" onclick="'."process('chgfailsafe')".'"'.$disabled.' />
              </td>
             </tr>
            </table>
@@ -492,7 +558,7 @@
            <input type="hidden" name="state" value="process" />
            </form>'."\n");
   } elsif ($action eq 'setdates') {
-      my ($start_table,$end_table) = &date_setting_table($enrollvar{autostart},$enrollvar{autoend},$action);
+      my ($start_table,$end_table) = &date_setting_table($enrollvar{autostart},$enrollvar{autoend},$action,$readonly);
       my $oldstartshow = '';
       my $oldendshow = '';
       if ( defined($enrollvar{autostart}) ) {
@@ -563,7 +629,7 @@
                   <table width="100%">
                    <tr>
                     <td align="right">
-                      <input type="button" name="setdates" value="'.&mt('Go').'" onclick="process('."'setdates'".')" />
+                      <input type="button" name="setdates" value="'.&mt('Go').'" onclick="process('."'setdates'".')"'.$disabled.' />
                     </td>
 	           </tr>
                   </table>
@@ -572,12 +638,12 @@
                   </form>
 ');
   } elsif ($action eq 'setaccess') {
-      &print_accessdate_table($r,\%enrollvar,$tasktitleref,$action);
+      &print_accessdate_table($r,\%enrollvar,$tasktitleref,$action,$readonly);
       $r->print('
                   <table width="100%">
                    <tr>
                     <td align="right">
-                      <input type="button" name="'.$action.'" value="'.&mt('Go').'" onclick="'."process('$action')".'" />
+                      <input type="button" name="'.$action.'" value="'.&mt('Go').'" onclick="'."process('$action')".'"'.$disabled.' />
                     </td>
                    </tr>
                   </table>
@@ -640,13 +706,13 @@
       );
       if ($notifycount) {
           $r->print('
-                        <label><input type="radio" name="notify" value="1" checked="checked" /> '.&mt('Yes').'   </label>
-                        <label><input type="radio" name="notify" value="0" /> '.&mt('No').'</label>
+                        <label><input type="radio" name="notify" value="1" checked="checked"'.$disabled.' /> '.&mt('Yes').'   </label>
+                        <label><input type="radio" name="notify" value="0"'.$disabled.' /> '.&mt('No').'</label>
           ');
       } else {
           $r->print('
-                        <label><input type="radio" name="notify" value="1" /> '.&mt('Yes').'   </label>
-                        <label><input type="radio" name="notify" value="0" checked="checked" /> '.&mt('No').'</label>
+                        <label><input type="radio" name="notify" value="1"'.$disabled.' /> '.&mt('Yes').'   </label>
+                        <label><input type="radio" name="notify" value="0" checked="checked"'.$disabled.' /> '.&mt('No').'</label>
           ');
       }
       $r->print('
@@ -709,7 +775,7 @@
               <td>
           ');
           $r->print(&notifier_tables('cc',\%lt,\@ccs,\%status,\%notifystate,
-                                     \%pname,\$notifyshow));
+                                     \%pname,\$notifyshow,undef,undef,$disabled));
           $r->print('</td></tr>');
       } else {
           $r->print('
@@ -769,7 +835,7 @@
              <tr>
               <td>');
           $r->print(&notifier_tables('dc',\%lt,\@showdom,\%status,\%notifystate,\%pname,
-                                     \$notifyshow,\@olddomcoord,\@futuredomcoord));
+                                     \$notifyshow,\@olddomcoord,\@futuredomcoord,$disabled));
           $r->print('
              </td>
           </tr>');
@@ -787,7 +853,7 @@
            <table width="100%" border="0" cellpadding="2" cellspacing="2">
             <tr>
              <td align="right">
-              <input type="button" name="notifyset" value="'.&mt('Go').'" onclick="'."process('notify')".'" />
+              <input type="button" name="notifyset" value="'.&mt('Go').'" onclick="'."process('notify')".'"'.$disabled.' />
              </td>
             </tr>
            </table>
@@ -846,9 +912,9 @@
               }               
               $r->print(&Apache::loncommon::start_data_table_row());
               $r->print('
-                 <td><input type="checkbox" name="cross_'.$i.'" checked="checked" /></td>
+                 <td><input type="checkbox" name="cross_'.$i.'" checked="checked"'.$disabled.' /></td>
                  <td>'.$xl.'</td>
-                 <td><input type="text" size="10" name="lcsec_'.$i.'" value="'.$lc_sec.'" /></td>
+                 <td><input type="text" size="10" name="lcsec_'.$i.'" value="'.$lc_sec.'"'.$disabled.' /></td>
               ');
               $r->print(&Apache::loncommon::end_data_table_row());
           }
@@ -868,7 +934,7 @@
              <tr>
               <td align="left">
                <b>'.&mt('Add new crosslistings.').'</b><br />'.
-               &mt('Number of new crosslistings to add:[_1]','  <input type="text" size="2" name="numcross" value="0" />').'
+               &mt('Number of new crosslistings to add:[_1]','  <input type="text" size="2" name="numcross" value="0"'.$disabled.' />').'
               </td>
              </tr>
             </table>
@@ -876,7 +942,7 @@
             <table width="100%" border="0" cellpadding="2" cellspacing="2">
              <tr>
               <td align="right">
-               <input type="button" name="crosslist" value="',&mt('Go').'" onclick="'."process('crosslist')".'" />
+               <input type="button" name="crosslist" value="',&mt('Go').'" onclick="'."process('crosslist')".'"'.$disabled.' />
               </td>
              </tr>
             </table>
@@ -931,9 +997,9 @@
                   $checked = ' checked="checked"';
               }
               $r->print(&Apache::loncommon::start_data_table_row().'
-                  <td><input type="checkbox" name="sec_'.$i.'"'.$checked.' /></td>
+                  <td><input type="checkbox" name="sec_'.$i.'"'.$checked.$disabled.' /></td>
                   <td>'.$sections[$i].'<input type="hidden" name="secnum_'.$i.'" value="'.$sections[$i].'" /></td>
-                  <td><input type="text" size="10" name="loncapasec_'.$i.'" value="'.$sec_id{$sections[$i]}.'" /></td>'.
+                  <td><input type="text" size="10" name="loncapasec_'.$i.'" value="'.$sec_id{$sections[$i]}.'"'.$disabled.' /></td>'.
                   &Apache::loncommon::end_data_table_row());
           }
           $r->print(&Apache::loncommon::end_data_table());
@@ -943,7 +1009,7 @@
              <tr> 
               <td align="right">
                <input type="hidden" name="secshow" value="'.$secshow.'" />
-               <input type="button" name="sections" value="'.&mt('Go').'" onclick="'."process('sections')".'" />
+               <input type="button" name="sections" value="'.&mt('Go').'" onclick="'."process('sections')".'"'.$disabled.' />
               </td>
              </tr>
             </table>
@@ -983,9 +1049,9 @@
               for (my $j=0; $j<@currsections; $j++) {
                   $r->print(
                  &Apache::loncommon::start_data_table_row().
-                 '<td><input type="checkbox" name="sec_'.$j.'" checked="checked" /></td>
+                 '<td><input type="checkbox" name="sec_'.$j.'" checked="checked"'.$disabled.' /></td>
                  <td>'.$currsections[$j].'</td>
-                 <td><input type="text" name="lcsec_'.$j.'" size="10" value="'.$sec_id{$currsections[$j]}.'" /></td>
+                 <td><input type="text" name="lcsec_'.$j.'" size="10" value="'.$sec_id{$currsections[$j]}.'"'.$disabled.' /></td>
                  '.&Apache::loncommon::end_data_table_row());
               }
               $r->print(&Apache::loncommon::end_data_table());
@@ -1003,7 +1069,7 @@
              <tr>
               <td align="left">
                <b>'.&mt('Add enrollment from additional sections.').'</b><br />'.
-               &mt('Number of new sections to add:').'  <input type="text" size="2" name="numsec" value="0" />
+               &mt('Number of new sections to add:').'  <input type="text" size="2" name="numsec" value="0"'.$disabled.' />
               </td>
              </tr>
             </table>
@@ -1011,7 +1077,7 @@
             <table width="100%" border="0" cellpadding="2" cellspacing="2">
              <tr>
               <td align="right">
-               <input type="button" name="sections" value="'.&mt('Go').'" onclick="'."process('sections')".'" />
+               <input type="button" name="sections" value="'.&mt('Go').'" onclick="'."process('sections')".'"'.$disabled.' />
               </td>
              </tr>
             </table>
@@ -1037,13 +1103,13 @@
                          '.&mt('Automatic import of student photos from institutional data repository:').'  ');
       if ($enrollvar{showphoto}) {
           $r->print('
-                        <label><input type="radio" name="showphotos" value="1" checked="checked" /> '.&mt('Yes').'   </label>
-                        <label><input type="radio" name="showphotos" value="0" /> '.&mt('No').'</label>
+                        <label><input type="radio" name="showphotos" value="1" checked="checked"'.$disabled.' /> '.&mt('Yes').'   </label>
+                        <label><input type="radio" name="showphotos" value="0"'.$disabled.' /> '.&mt('No').'</label>
           ');
       } else {
           $r->print('
-                        <label><input type="radio" name="showphotos" value="1" /> '.&mt('Yes').'   </label>
-                        <label><input type="radio" name="showphotos" value="0" checked="checked" /> '.&mt('No').'</label>
+                        <label><input type="radio" name="showphotos" value="1"'.$disabled.' /> '.&mt('Yes').'   </label>
+                        <label><input type="radio" name="showphotos" value="0" checked="checked"'.$disabled.' /> '.&mt('No').'</label>
           ');
       }
       $r->print('
@@ -1065,7 +1131,7 @@
 &mt('Previously the owner of this course agreed to the conditions of use of digital student photos required by [_1].', $institution).'<br />'.
 &mt('As a result [_1]s can choose to automatically import student photos into this course.',&Apache::lonnet::plaintext('cc')).
 '<br /><span class="LC_nobreak"><label>'.
-&mt('[_1]Cancel[_2] owner acceptance of these conditions of use?','<b>','</b>').' <input type="checkbox" name="cancel_agreement" value="1" /></label></span>
+&mt('[_1]Cancel[_2] owner acceptance of these conditions of use?','<b>','</b>').' <input type="checkbox" name="cancel_agreement" value="1"'.$disabled.' /></label></span>
                      </td>
                     </tr>
                       ');
@@ -1132,7 +1198,7 @@
                     </tr>
                     <tr>
                      <td align="right">
-                      <input type="button" name="showphotos" value="'.&mt('Go').'" onclick="process('."'photos'".')" />
+                      <input type="button" name="showphotos" value="'.&mt('Go').'" onclick="process('."'photos'".')"'.$disabled.' />
                      </td>
                     </tr>
                    </table>
@@ -1153,15 +1219,15 @@
 		    <tr>
 		     <td>'.
 	             &mt('Add any students currently included in institutional classlist(s) but not enrolled in your LON-CAPA course.').'<br />  
-		      <label><input type="radio" name="updateadds" value="1" /> '.&mt('Yes').' </label>
-                      <label><input type="radio" name="updateadds" value="0" /> '.&mt('No').' </label>
+		      <label><input type="radio" name="updateadds" value="1"'.$disabled.' /> '.&mt('Yes').' </label>
+                      <label><input type="radio" name="updateadds" value="0"'.$disabled.' /> '.&mt('No').' </label>
                      </td>
                     </tr>
                     <tr>
                      <td>'.
  	             &mt('Expire students previously added by nightly enrollment process, but no longer listed in institutional classlist(s).').'<br />
-                      <label><input type="radio" name="updatedrops" value="1" /> '.&mt('Yes').' </label>
-                      <label><input type="radio" name="updatedrops" value="0" /> '.&mt('No').' </label><br />
+                      <label><input type="radio" name="updatedrops" value="1"'.$disabled.' /> '.&mt('Yes').' </label>
+                      <label><input type="radio" name="updatedrops" value="0"'.$disabled.' /> '.&mt('No').' </label><br />
                      </td>
                     </tr>
                     <tr>
@@ -1173,13 +1239,13 @@
                     <tr>
                      <td>
       ');
-      &print_accessdate_table($r,\%enrollvar,$tasktitleref,$action);
+      &print_accessdate_table($r,\%enrollvar,$tasktitleref,$action,$readonly);
       $r->print('
                      </td>
                     </tr>
                     <tr>
                      <td align="right">
-                      <input type="button" name="updatenow" value="'.&mt('Go').'" onclick="'."process('updatenow')".'" />
+                      <input type="button" name="updatenow" value="'.&mt('Go').'" onclick="'."process('updatenow')".'"'.$disabled.' />
                      </td>
                     </tr>
 	           </table>
@@ -1201,7 +1267,7 @@
               $r->print('<br />'.$commentary.'<br /><br />
 <form name="photoupdate" method="post" action="">
 <input type="button" name="retrieve" value="'.&mt('Update photo repository').'"
-onclick="javascript:document.photoupdate.submit()" />
+onclick="javascript:document.photoupdate.submit()"'.$disabled.' />
 <input type="hidden" name="action" value="'.$action.'" />
 <input type="hidden" name="state" value="process" />
 </form>');
@@ -1275,7 +1341,8 @@
               "\n");
           my $context = 'course';
           my $mode = 'autoenroll';
-          my ($studentcount,$autocount,$manualcount,$lockcount,$unlockcount) = &Apache::lonuserutils::show_users_list($r,$context,$mode,$permission,$env{'form.Status'},\%userlist,$keylist);
+          my ($studentcount,$autocount,$manualcount,$lockcount,$unlockcount) = 
+              &Apache::lonuserutils::show_users_list($r,$context,$mode,$permission,$env{'form.Status'},\%userlist,$keylist);
           $r->print('
                      </td>
                     </tr>
@@ -1288,15 +1355,15 @@
               if ($autocount > 0) {
                   $cellcount ++;
                   $r->print('
-                      <td><fieldset><legend>'.&mt('Change auto').'</legend><input type="button" value="'.&mt('check all').'" onclick="javascript:checkAll(document.studentform.chgauto)" />  
-                      <input type="button" value="'.&mt('uncheck all').'" onclick="javascript:uncheckAll(document.studentform.chgauto)" /></fieldset></td>
+                      <td><fieldset><legend>'.&mt('Change auto').'</legend><input type="button" value="'.&mt('check all').'" onclick="javascript:checkAll(document.studentform.chgauto)"'.$disabled.' />  
+                      <input type="button" value="'.&mt('uncheck all').'" onclick="javascript:uncheckAll(document.studentform.chgauto)"'.$disabled.' /></fieldset></td>
                   ');
               }
               if ($manualcount > 0) {
                   $cellcount ++;
                   $r->print('
-                      <td><fieldset><legend>'.&mt('Change manual').'</legend><input type="button" value="'.&mt('check all').'" onclick="javascript:checkAll(document.studentform.chgmanual)" />  
-                      <input type="button" value="'.&mt('uncheck all').'" onclick="javascript:uncheckAll(document.studentform.chgmanual)" /></fieldset></td>
+                      <td><fieldset><legend>'.&mt('Change manual').'</legend><input type="button" value="'.&mt('check all').'" onclick="javascript:checkAll(document.studentform.chgmanual)"'.$disabled.' />  
+                      <input type="button" value="'.&mt('uncheck all').'" onclick="javascript:uncheckAll(document.studentform.chgmanual)"'.$disabled.' /></fieldset></td>
                   ');
               }
               if ($lockcount > 0) {
@@ -1305,8 +1372,8 @@
                   }
                   $cellcount ++;
                   $r->print('
-                       <td><fieldset><legend>'.&mt('Lock manual').'</legend><input type="button" value="'.&mt('check all').'" onclick="javascript:checkAll(document.studentform.lockchg)" />  
-                       <input type="button" value="'.&mt('uncheck all').'" onclick="javascript:uncheckAll(document.studentform.lockchg)" /></fieldset></td>
+                       <td><fieldset><legend>'.&mt('Lock manual').'</legend><input type="button" value="'.&mt('check all').'" onclick="javascript:checkAll(document.studentform.lockchg)"'.$disabled.' />  
+                       <input type="button" value="'.&mt('uncheck all').'" onclick="javascript:uncheckAll(document.studentform.lockchg)"'.$disabled.' /></fieldset></td>
                   ');
               }
               if ($unlockcount > 0) {
@@ -1316,8 +1383,8 @@
                   $cellcount ++;
                   $r->print('
                        <td><fieldset><legend>'.&mt('Unlock manual').'
-                       </legend><input type="button" value="'.&mt('check all').'" onclick="javascript:checkAll(document.studentform.unlockchg)" />  
-                       <input type="button" value="'.&mt('uncheck all').'" onclick="javascript:uncheckAll(document.studentform.unlockchg)" /></fieldset></td>');
+                       </legend><input type="button" value="'.&mt('check all').'" onclick="javascript:checkAll(document.studentform.unlockchg)"'.$disabled.' />  
+                       <input type="button" value="'.&mt('uncheck all').'" onclick="javascript:uncheckAll(document.studentform.unlockchg)"'.$disabled.' /></fieldset></td>');
               }
               $r->print('
                        </tr>
@@ -1326,7 +1393,7 @@
                     </tr>
                     <tr>
                      <td align="right">
-                      <input type="button" name="viewclass" value="'.&mt('Go').'" onclick="'."process('viewclass','$autocount','$manualcount','$lockcount','$unlockcount')".'" />
+                      <input type="button" name="viewclass" value="'.&mt('Go').'" onclick="'."process('viewclass','$autocount','$manualcount','$lockcount','$unlockcount')".'"'.$disabled.' />
                      </td>
                     </tr>
               ');
@@ -1351,7 +1418,7 @@
 
 sub notifier_tables {
     my ($role,$lt,$users,$status,$notifystate,$pname,$notifyshow,$olddomcoord,
-        $futuredomcoord) = @_;
+        $futuredomcoord,$disabled) = @_;
     my $output = &Apache::loncommon::start_data_table();
     $output .= &Apache::loncommon::start_data_table_header_row();
     $output .= "<th>$$lt{name}</th>
@@ -1394,7 +1461,7 @@
         if ($$notifystate{$$users[$i]} == 1) {
             $output .= ' checked="checked"';
         }
-        $output .= ' /></td>';
+        $output .= $disabled.' /></td>';
         $output .= &Apache::loncommon::end_data_table_row();
         $$notifyshow ++;
     }
@@ -1403,8 +1470,8 @@
 }
 
 sub print_accessdate_table {
-    my ($r,$enrollvar,$tasktitleref,$action) = @_;
-    my ($start_table,$end_table) = &date_setting_table($$enrollvar{'default_enrollment_start_date'},$$enrollvar{'default_enrollment_end_date'},$action);
+    my ($r,$enrollvar,$tasktitleref,$action,$readonly) = @_;
+    my ($start_table,$end_table) = &date_setting_table($$enrollvar{'default_enrollment_start_date'},$$enrollvar{'default_enrollment_end_date'},$action,$readonly);
     my ($oldstartshow,$oldendshow);
     if ( defined($$enrollvar{'default_enrollment_start_date'}) ) {
         $oldstartshow = &Apache::lonlocal::locallocaltime($$enrollvar{'default_enrollment_start_date'});
@@ -3154,7 +3221,11 @@
 }
 
 sub setup_date_selectors {
-    my ($starttime,$endtime,$action) = @_;
+    my ($starttime,$endtime,$action,$readonly) = @_;
+    my $disabled;
+    if ($readonly) {
+        $disabled = 'disabled';
+    }
     if (! defined($starttime)) {
         $starttime = time;
         if ($action eq 'setdates') {
@@ -3177,10 +3248,10 @@
     }
     my $startdateform = &Apache::lonhtmlcommon::date_setter('enter',
                                                             'startdate',
-                                                            $starttime);
+                                                            $starttime,'','',$disabled);
     my $enddateform = &Apache::lonhtmlcommon::date_setter('enter',
                                                           'enddate',
-                                                          $endtime);
+                                                          $endtime,'','',$disabled);
     return ($startdateform,$enddateform);
 }
 
@@ -3195,9 +3266,13 @@
 }
 
 sub date_setting_table {
-    my ($starttime,$endtime,$action) = @_;
+    my ($starttime,$endtime,$action,$readonly) = @_;
+    my $disabled;
+    if ($readonly) {
+        $disabled = ' disabled="disabled"';
+    }
     my ($startform,$endform) = 
-        &setup_date_selectors($starttime,$endtime,$action);
+        &setup_date_selectors($starttime,$endtime,$action,$readonly);
     my $perpetual = '<span class="LC_nobreak"><label>'.
                     '<input type="checkbox" name="no_end_date"';
     if (($action eq 'setdates' && defined($endtime) && $endtime == 0) || 
@@ -3205,7 +3280,7 @@
          ($endtime eq '' || $endtime == 0)) ) {
         $perpetual .= ' checked="checked"';
     }
-    $perpetual.= ' /> '.&mt('no end date').'</label></span>';
+    $perpetual.= $disabled.' /> '.&mt('no end date').'</label></span>';
     my $start_table = "<table>\n".
                       '<tr><td align="right">'.&mt('Starting Date').'</td>'.
                       '<td>'.$startform.'</td>'.
@@ -3243,42 +3318,95 @@
 }
 
 sub get_task_text {
-    my %tasklong = 
+    my ($permref) = @_;
+    my %tasklong =
         &Apache::lonlocal::texthash(
-               information   => 'Task information',
-               chgsettings   => 'Automated adds/drops',
-               chgfailsafe   => 'Change zero enrollment failsafe',
-               setdates      => 'Change enrollment dates',
-               setaccess     => 'Change access dates',
-               notify        => 'Notification of changes',
-               crosslist     => 'Change crosslistings',
-               sections      => 'Section settings',
-               photos        => 'Student photo settings',
-               updatephotos  => 'Update student photos',
-               updatenow     => 'Update roster now',
-               newcross      => 'Add crosslistings',
-               newsections   => 'Add sections',
-               viewclass     => 'View students and change type',
+           information   => 'Task information',
+           chgsettings   => 'Automated adds/drops',
+           chgfailsafe   => 'Change zero enrollment failsafe',
+           setdates      => 'Change enrollment dates',
+           setaccess     => 'Change access dates',
+           notify        => 'Notification of changes',
+           crosslist     => 'Change crosslistings',
+           sections      => 'Section settings',
+           photos        => 'Student photo settings',
+           updatephotos  => 'Update student photos',
+           updatenow     => 'Update roster now',
+           newcross      => 'Add crosslistings',
+           newsections   => 'Add sections',
+           viewclass     => 'View students and change type',
     );
 
-    my %tasktitle = 
+    my %tasktitle =
         &Apache::lonlocal::texthash(
-               chgsettings  => 'Changes to nightly automated enrollments',
-               chgfailsafe  => 'Changes to failsafe protection for data retrieval problems',
-               setdates     => 'Changes to first and/or last automated enrollment dates',
-               setaccess    => 'Changes to default start and/or end dates for student access',
-               notify       => 'Notification of enrollment changes',
-               crosslist    => 'Changes to crosslistings',
-               sections     => 'Changes to section settings',
-               photos       => 'Student photo settings',
-               updatephotos => 'Update student photos',
-               updatenow => "Immediate course roster update",
-               newcross => "Adding new crosslisted courses",
-               newsections => "Adding new course sections",
-               viewclass => "Viewing class roster and enrollment type"
+           chgsettings  => 'Changes to nightly automated enrollments',
+           chgfailsafe  => 'Changes to failsafe protection for data retrieval problems',
+           setdates     => 'Changes to first and/or last automated enrollment dates',
+           setaccess    => 'Changes to default start and/or end dates for student access',
+           notify       => 'Notification of enrollment changes',
+           crosslist    => 'Changes to crosslistings',
+           sections     => 'Changes to section settings',
+           photos       => 'Student photo settings',
+           updatephotos => 'Update student photos',
+           updatenow => "Immediate course roster update",
+           newcross => "Adding new crosslisted courses",
+           newsections => "Adding new course sections",
+           viewclass => "Viewing class roster and enrollment type"
     );
+
+    if ((ref($permref) eq 'HASH') && (!$permref->{'edit'})) {
+        $tasklong{'chgfailsafe'} = &mt('Zero enrollment failsafe');
+        $tasklong{'setdates'}    = &mt('Enrollment dates');
+        $tasklong{'setaccess'}   = &mt('Access dates');
+        $tasklong{'crosslist'}   = &mt('Crosslistings');
+        $tasklong{'viewclass'}   = &mt('View students and type');
+    }
     return (\%tasklong,\%tasktitle);
 }
+
+sub check_permission {
+    my ($permref) = @_;
+    return unless (ref($permref) eq 'HASH');
+    my $hasaccess;
+    if ($env{'request.course.id'}) {
+        foreach my $priv ('cst','vpa','vcl') {
+            my ($allowed,$section);
+            if (&Apache::lonnet::allowed($priv,$env{'request.course.id'})) {
+                $allowed = 1;
+            } elsif ($env{'request.course.sec'} ne '') {
+                if (&Apache::lonnet::allowed($priv,$env{'request.course.id'}.'/'.
+                                                   $env{'request.course.sec'})) {
+                    $allowed = 1;
+                    $section = $env{'request.course.sec'};
+                }
+            }
+            if ($allowed) {
+                $hasaccess = 1;
+                if ($priv eq 'cst') {
+                    if ($section ne '') {
+                        $permref->{'edit_section'} = $section;
+                    } else {
+                        $permref->{'edit'} = 1;
+                    }
+                } elsif ($priv eq 'vpa') {
+                    if ($section ne '') {
+                        $permref->{'view_section'} = $section;
+                    } else {
+                        $permref->{'view'} = 1;
+                    }
+                } elsif ($priv eq 'vcl') {
+                    if ($section ne '') {
+                        $permref->{'show_section'} = $section;
+                    } else {
+                        $permref->{'show'} = 1;
+                    }
+                }
+            }
+        }
+    }
+    return $hasaccess;
+}
+
     
 ###################################################################
 sub handler {
@@ -3290,12 +3418,16 @@
     }
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                                             ['action','state']);
+    my %permhash;
     #  Needs to be in a course
-    if (! (($env{'request.course.fn'}) &&  
-           (&Apache::lonnet::allowed('cst',$env{'request.course.id'})))) {
-        # Not in a course, or not allowed to modify parms
-        $env{'user.error.msg'}="/adm/populate:cst:0:0:Cannot drop or add students";
+    if (!($env{'request.course.fn'})) {
+        # Not in a course
+        $env{'user.error.msg'}="/adm/populate:cst:0:0:Cannot display automated enrollment";
         return HTTP_NOT_ACCEPTABLE;
+    } elsif (!&check_permission(\%permhash)) {
+        # Not allowed to modify students, view settings, or view classlist.
+        $env{'user.error.msg'}="/adm/populate:cst:0:0:Cannot display automated enrollment";
+        return HTTP_NOT_ACCEPTABLE; 
     }
     # Start page
     &Apache::loncommon::content_type($r,'text/html');
@@ -3304,7 +3436,7 @@
     my @tasks = ('information','chgsettings','setdates','setaccess','notify','crosslist',
                  'sections','photos','updatenow','updatephotos','viewclass','chgfailsafe');
  
-    my ($tasklong,$tasktitle) = &get_task_text();
+    my ($tasklong,$tasktitle) = &get_task_text(\%permhash);
     my $realm;
     if ( exists($env{'request.course.id'}) ) {
         $realm=$env{'course.'.$env{'request.course.id'}.'.description'};
@@ -3312,7 +3444,7 @@
     unless ($realm) { $realm=' '; }
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
-    
+
     #
     # Main switch on form.action and form.state, as appropriate
     #
@@ -3328,33 +3460,33 @@
     }
 
     if ($action eq "information") {
-        $r->print(&header($action));
+        $r->print(&header($action,\%permhash));
     } else {
         if ($state eq "choose") {
-            $r->print(&choose_header($action));
+            $r->print(&choose_header($action,\%permhash));
         } else {
             if ($action eq "crosslist") {
                 if ( exists($env{'form.numcross'}) ) {
                     if ( $env{'form.numcross'} > 0 ) {
-                        $r->print(&choose_header($action));
+                        $r->print(&choose_header($action,\%permhash));
                     } else {
-                        $r->print(&header($action));
+                        $r->print(&header($action,\%permhash));
                     }
                 } else {
-                    $r->print(&header());
+                    $r->print(&header(undef,\%permhash));
                 }
             } elsif ($action eq "sections") {
                 if ( exists($env{'form.numsec'}) ) {
                     if ( $env{'form.numsec'} > 0 ) {
-                        $r->print(&choose_header($action));
+                        $r->print(&choose_header($action,\%permhash));
                     } else {
-                        $r->print(&header($action));
+                        $r->print(&header($action,\%permhash));
                     }
                 } else {
-                    $r->print(&header($action));
+                    $r->print(&header($action,\%permhash));
                 }
             } else {
-                $r->print(&header($action));
+                $r->print(&header($action,\%permhash));
             }
         }
     }
@@ -3365,36 +3497,36 @@
     &print_navmenu($r,\@tasks,$tasklong,$action,$state);
 
     if (($state eq "choose") || ($action eq "information")) {
-        &print_main_frame($r,$realm,$dom,$crs,$tasktitle);
-    } elsif ($action eq "chgsettings") {
+        &print_main_frame($r,$realm,$dom,$crs,$tasktitle,\%permhash);
+    } elsif (($action eq "chgsettings") && ($permhash{'edit'})) {
         &print_chgsettings_response($r,$realm,$dom,$crs,$action,$tasktitle);
-    } elsif ($action eq "chgfailsafe") {
+    } elsif (($action eq "chgfailsafe") && ($permhash{'edit'})) {
         &print_chgfailsafe_response($r,$realm,$dom,$crs,$action,$tasktitle);
-    } elsif ($action eq "setdates") {
+    } elsif (($action eq "setdates") && ($permhash{'edit'})) {
         &print_setdates_response($r,$realm,$dom,$crs,$action,$tasktitle);
-    } elsif ($action eq "setaccess") {
+    } elsif (($action eq "setaccess") && ($permhash{'edit'})) {
         &print_setaccess_response($r,$realm,$dom,$crs,$action,$tasktitle);
-    } elsif ($action eq "notify") {
+    } elsif (($action eq "notify") && ($permhash{'edit'})) {
         &print_notify_response($r,$realm,$dom,$crs,$action,$tasktitle);
-    } elsif ($action eq "sections") {
+    } elsif (($action eq "sections") && ($permhash{'edit'})) {
         &print_sections_menu($r,$realm,$dom,$crs,$action,$tasktitle);
-    } elsif ($action eq "crosslist") {
+    } elsif (($action eq "crosslist") && ($permhash{'edit'})) {
         &print_crosslistings_menu($r,$realm,$dom,$crs,$action,$tasktitle);
-    } elsif ($action eq "updatenow") {
+    } elsif (($action eq "updatenow") && ($permhash{'edit'})) {
         &print_update_result($r,$realm,$dom,$crs,$action,$tasktitle);
-    } elsif ($action eq "photos") {
+    } elsif (($action eq "photos") && ($permhash{'edit'})) {
         if ($state eq "photoupdate") {
             &print_photoupdate_response($r,$realm,$dom,$crs,$action,$tasktitle);
-        } else { 
+        } else {
             &photo_permission($r,$realm,$dom,$crs,$action,$tasktitle);
         }
-    } elsif ($action eq "updatephotos") {
+    } elsif (($action eq "updatephotos") && ($permhash{'edit'})) {
         &print_photoupdate_response($r,$realm,$dom,$crs,$action,$tasktitle);
-    } elsif ($action eq "newcross") {
+    } elsif (($action eq "newcross") && ($permhash{'edit'})) {
         &print_crosslistings_response($r,$realm,$dom,$crs,$action,$tasktitle);    
-    } elsif ($action eq "newsections") {
+    } elsif (($action eq "newsections") && ($permhash{'edit'})) {
         &print_sections_response($r,$realm,$dom,$crs,$action,$tasktitle);
-    } elsif ($action eq "viewclass") {
+    } elsif (($action eq "viewclass") && ($permhash{'edit'})) {
         &print_viewclass_response($r,$realm,$dom,$crs,$action,$tasktitle);
     }
     &print_doc_base($r);  


More information about the LON-CAPA-cvs mailing list