Diff for /loncom/interface/spreadsheet/lonspreadsheet.pm between versions 1.56 and 1.66

version 1.56, 2010/05/03 16:41:54 version 1.66, 2020/08/10 19:28:21
Line 64  use Apache::lonnet; Line 64  use Apache::lonnet;
 use Apache::lonhtmlcommon;  use Apache::lonhtmlcommon;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::loncoursedata();  use Apache::loncoursedata();
   use Apache::lonquickgrades();
 use HTML::Entities();  use HTML::Entities();
   
 ##  ##
Line 106  sub file_dialogs { Line 107  sub file_dialogs {
         $spreadsheet->filename($env{'form.savefilename'});          $spreadsheet->filename($env{'form.savefilename'});
         my $save_status = $spreadsheet->save();          my $save_status = $spreadsheet->save();
         if ($save_status ne 'ok') {          if ($save_status ne 'ok') {
             $message .= "An error occurred while saving the spreadsheet".              $message .= '<span class="LC_error">'.
                 "There error is:".$save_status;                  &mt('An error occurred while saving the spreadsheet. The error is: [_1].',
                       $save_status).'</span>';
         } else {          } else {
             $message .= "Spreadsheet saved as ".$spreadsheet->filename();              $message .= '<span class="LC_info">'.&mt('Spreadsheet saved as: [_1] .',
                           '<span class="LC_filename">'.$spreadsheet->filename().'</span>').
                           '</span>';
         }          }
     } elsif (exists($env{'form.newformula'}) &&       } elsif (exists($env{'form.newformula'}) && 
              exists($env{'form.cell'})       &&                exists($env{'form.cell'})       && 
Line 217  sub handler { Line 221  sub handler {
             $r->uri.":opa:0:0:Cannot modify spreadsheet";              $r->uri.":opa:0:0:Cannot modify spreadsheet";
         return HTTP_NOT_ACCEPTABLE;           return HTTP_NOT_ACCEPTABLE; 
     }      }
       my ($sheettype) = ($r->uri=~/\/(\w+)$/);
     my $courseid = $env{'request.course.id'};      my $courseid = $env{'request.course.id'};
   
       ##
       ## Check permissions
       my $allowed_to_edit = &Apache::lonnet::allowed('mgr',
                                                   $env{'request.course.id'});
       # Only those instructors/tas/whatevers with complete access
       # (not section restricted) are able to modify spreadsheets.
       my $allowed_to_view =  &Apache::lonnet::allowed('vgr',
                                                   $env{'request.course.id'});
       if (! $allowed_to_view) {
           $allowed_to_view = &Apache::lonnet::allowed('vgr',
                       $env{'request.course.id'}.'/'.$env{'request.course.sec'});
           # Those who are restricted by section are allowed to view.
           # The routines in lonstatistics which decide which students'
           # will be shown take care of the restriction by section.
       }
   
     #      #
     # Do not allow students to continue if standard or external grading is in      # Check if display of course gradebook is blocked
     # effect.  
     #      #
     if ($env{'request.role'} =~ /^st\./) {  
         if ($env{'course.'.$courseid.'.grading'} eq 'standard' ||      if ($env{'request.course.id'}) {
     $env{'course.'.$courseid.'.grading'} eq 'external' ) {          my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
             return HTTP_NOT_ACCEPTABLE;          my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
           my ($blocked,$blocktext) =
               &Apache::loncommon::blocking_status('grades',$cnum,$cdom);
           if ($blocked) {
               my $checkrole = "cm./$cdom/$cnum";
               if ($env{'request.course.sec'} ne '') {
                   $checkrole .= "/$env{'request.course.sec'}";
               }
               unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
                       ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
                   &Apache::lonquickgrades::grades_blocked($r,$blocktext,'spreadsheet');
                   return OK;
               }
           }
       }
   
       #
       # Do not allow users without vgr or mgr priv to continue unless 
       # grading type is set to spreadsheet. 
       #
   
       if ((!$allowed_to_view) && (!$allowed_to_edit)) {
           if ($env{'course.'.$courseid.'.grading'} eq 'spreadsheet') {
               if ($sheettype ne 'studentcalc') {
                   $r->internal_redirect('/adm/studentcalc');
                   return OK;
               }
           } else {
               $r->internal_redirect('/adm/quickgrades');
               return OK;
         }          }
     }      }
     #      #
Line 243  sub handler { Line 293  sub handler {
     }      }
     #      #
     # Determine basic information about the spreadsheet      # Determine basic information about the spreadsheet
     my ($sheettype) = ($r->uri=~/\/(\w+)$/);  
     #      #
     my $symb   = undef;      my $symb   = undef;
     $symb = $env{'form.usymb'} if (exists($env{'form.usymb'}));      $symb = $env{'form.usymb'} if (exists($env{'form.usymb'}));
     my $name   = $env{'user.name'};      my $name   = $env{'user.name'};
     my $domain = $env{'user.domain'};      my $domain = $env{'user.domain'};
       my $warning;
     if (exists($env{'form.sname'}) && $env{'form.sname'} ne '') {      if (exists($env{'form.sname'}) && $env{'form.sname'} ne '') {
         $name   = $env{'form.sname'};          if (($env{'form.sname'} ne $env{'user.name'}) ||
         $domain = $env{'form.sdomain'};              ($env{'form.sdomain'} ne $env{'user.domain'})) {
               if (($allowed_to_view) || ($allowed_to_edit)) {
                   if (&Apache::lonnet::homeserver($env{'form.sname'},$env{'form.sdomain'}) ne 'no_host') {
                       $name   = $env{'form.sname'};
                       $domain = $env{'form.sdomain'};
                   } else {
                       $warning = &mt('Requested user: "[_1]" does not exist; your own sheet is displayed instead.',$env{'form.sname'}.':'.$env{'form.sdomain'});
                   }
               } else {
                   $warning = &mt('Your current role is not permitted to display this sheet for the requested user: "[_1]"; your own sheet is displayed instead.',$env{'form.sname'}.':'.$env{'form.sdomain'});
               }
           }
     }      }
     $env{'form.sname'} = $name;      $env{'form.sname'} = $name;
     $env{'form.sdomain'} = $domain;      $env{'form.sdomain'} = $domain;
Line 266  sub handler { Line 327  sub handler {
                                                     $env{'request.course.id'});                                                      $env{'request.course.id'});
     }      }
   
     ##  
     ## Check permissions  
     my $allowed_to_edit = &Apache::lonnet::allowed('mgr',  
                                                 $env{'request.course.id'});  
     # Only those instructors/tas/whatevers with complete access  
     # (not section restricted) are able to modify spreadsheets.  
     my $allowed_to_view =  &Apache::lonnet::allowed('vgr',  
                                                 $env{'request.course.id'});  
     if (! $allowed_to_view) {  
         $allowed_to_view = &Apache::lonnet::allowed('vgr',  
                     $env{'request.course.id'}.'/'.$env{'request.course.sec'});  
         # Those who are restricted by section are allowed to view.  
         # The routines in lonstatistics which decide which students'   
         # will be shown take care of the restriction by section.  
     }  
     #      #
     # Only those able to view others grades will be allowed to continue       # Only those able to view others grades will be allowed to continue 
     # if they are not requesting their own.      # if they are not requesting their own.
     if ($sheettype eq 'classcalc') {      if ($sheettype eq 'classcalc') {
         if (! $allowed_to_view) {          if (!$allowed_to_view) {
     $env{'user.error.msg'}=              $r->internal_redirect('/adm/studentcalc');
  $r->uri.":vgr:0:0:Access Permission Denied";              return OK;
     return HTTP_NOT_ACCEPTABLE;   
  }   }
     }      }
     if ((($name   ne $env{'user.name'} ) ||      if ((($name   ne $env{'user.name'} ) ||
Line 322  sub handler { Line 367  sub handler {
     ##      ##
     my $js;      my $js;
     if ($allowed_to_edit) {      if ($allowed_to_edit) {
  my %lt=(   my %lt=&Apache::lonlocal::texthash(
  'ce' => 'Cell',   'ce' => 'Cell',
  'ac' => 'Accept',   'ac' => 'Save',
  'dc' => 'Discard Changes'   'dc' => 'Cancel'
  );   );
         my $extra_javascript =           my $extra_javascript = 
             &Apache::loncommon::browser_and_searcher_javascript();              &Apache::loncommon::browser_and_searcher_javascript();
Line 354  sub handler { Line 399  sub handler {
         // cellformula may contain less-than and greater-than symbols, so          // cellformula may contain less-than and greater-than symbols, so
         // we need to escape them?            // we need to escape them?  
         edit_text +='$cell_edit_start';          edit_text +='$cell_edit_start';
         edit_text += '<form name="editwinform">';          edit_text += '<form name="editwinform" action="">';
         edit_text += '<center><h3>$lt{'ce'} '+cellname+'</h3>';          edit_text += '<center><h3>$lt{'ce'} '+cellname+'</h3>';
         edit_text += '<textarea id="LC_newformula" name="newformula" ';          edit_text += '<textarea id="LC_newformula" name="newformula" ';
         edit_text += ' cols="60" rows="12"; wrap="off" style="width:100%">';          edit_text += ' cols="60" rows="12"; wrap="off" style="width:100%">';
  edit_text += cellformula+'</textarea>';   edit_text += cellformula+'</textarea>';
         edit_text += '<div id="LC_aftertextarea"><br />';          edit_text += '<div id="LC_aftertextarea"><br />';
         edit_text += '<input type="button" name="accept" value="$lt{'ac'}"';          edit_text += '<input type="button" name="accept" value="$lt{'ac'}"';
         edit_text += ' onClick=\\\'javascript:';          edit_text += ' onclick=\\\'javascript:';
         edit_text += 'opener.document.sheet.cell.value=';          edit_text += 'opener.document.sheet.cell.value=';
         edit_text +=     '"'+cellname+'";';          edit_text +=     '"'+cellname+'";';
         edit_text += 'opener.document.sheet.newformula.value=';          edit_text += 'opener.document.sheet.newformula.value=';
Line 371  sub handler { Line 416  sub handler {
         edit_text += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';          edit_text += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
         edit_text += '<input type="button" name="abort" ';          edit_text += '<input type="button" name="abort" ';
         edit_text +=     'value="$lt{'dc'}"';          edit_text +=     'value="$lt{'dc'}"';
         edit_text += ' onClick="javascript:self.close()" />';          edit_text += ' onclick="javascript:self.close()" />';
         edit_text += '</center></div></form>$cell_edit_end';          edit_text += '</center></div></form>$cell_edit_end';
   
         if (editwin != null && !(editwin.closed) ) {          if (editwin != null && !(editwin.closed) ) {
Line 395  ENDSCRIPT Line 440  ENDSCRIPT
           bug   => 'Spreadsheet'});            bug   => 'Spreadsheet'});
     $r->print(&Apache::loncommon::start_page('Grades Spreadsheet',$js).      $r->print(&Apache::loncommon::start_page('Grades Spreadsheet',$js).
               &Apache::lonhtmlcommon::breadcrumbs('Spreadsheet',                &Apache::lonhtmlcommon::breadcrumbs('Spreadsheet',
   'Spreadsheet_About').    'Spreadsheet_About'));
               '<form action="'.$r->uri.'" name="sheet" method="post">');  
       #
       # Tabs
       # 
       &Apache::lonquickgrades::startGradeScreen($r,'spreadsheet');
   
       #
       # Open the form
       # 
       if ($warning) {
           $r->print('<p class="LC_info">'.$warning.'</p>');
       }
       $r->print('<form action="'.$r->uri.'" name="sheet" method="post">');
     $r->print(&hiddenfield('sname'  ,$env{'form.sname'}).      $r->print(&hiddenfield('sname'  ,$env{'form.sname'}).
               &hiddenfield('sdomain',$env{'form.sdomain'}).                &hiddenfield('sdomain',$env{'form.sdomain'}).
               &hiddenfield('usymb'  ,$env{'form.usymb'}));                &hiddenfield('usymb'  ,$env{'form.usymb'}));
Line 418  ENDSCRIPT Line 475  ENDSCRIPT
         if (exists($env{'form.recalc'})) {          if (exists($env{'form.recalc'})) {
             &Apache::loncoursedata::delete_caches($env{'requres.course.id'});              &Apache::loncoursedata::delete_caches($env{'requres.course.id'});
         }          }
         if ($env{'form.recalc'} eq 'ilovewastingtime') {          if ($env{'form.recalc'} eq 'expireallsheets') {
             &Apache::lonnet::logthis('spreadsheet expired: entire course');              &Apache::lonnet::logthis('spreadsheet expired: entire course');
             # expire ALL spreadsheets              # expire ALL spreadsheets
             &Apache::lonnet::expirespread('','','studentcalc');              &Apache::lonnet::expirespread('','','studentcalc');
Line 500  ENDSCRIPT Line 557  ENDSCRIPT
                   '</td>'.                    '</td>'.
                   '<td valign="center">'.$html."</td></tr></table>\n");                    '<td valign="center">'.$html."</td></tr></table>\n");
         if ($action_message ne '') {          if ($action_message ne '') {
             $r->print(<<END);              $r->print(
 <table>                  &Apache::loncommon::confirmwrapper(
 <tr><td valign="top"><b>Last Action:</b></td>                      &mt('Last Action:')
     <td>&nbsp;</td>                     .$action_message)
     <td>$action_message</td>              );
 </tr>  
 </table>  
 END  
         }          }
         $r->rflush();          $r->rflush();
     } else {      } else {
Line 523  END Line 577  END
     if ($allowed_to_view) {      if ($allowed_to_view) {
         $r->print('<td>'.          $r->print('<td>'.
                   &Apache::loncommon::help_open_topic("Spreadsheet_About",                    &Apache::loncommon::help_open_topic("Spreadsheet_About",
                                                       'Spreadsheet Help').                                                        &mt('Spreadsheet Help')).
                   '</td>');                    '</td>');
     }      }
     if ($allowed_to_edit) {      if ($allowed_to_edit) {
         $r->print('<td>'.          $r->print('<td>'.
                   &Apache::loncommon::help_open_topic("Spreadsheet_Editing",                    &Apache::loncommon::help_open_topic("Spreadsheet_Editing",
                                                       'Editing Help').                                                        &mt('Editing Help')).
                   '</td>');                    '</td>');
     }      }
     $r->print('</tr></table>');      $r->print('</tr></table>');
Line 538  END Line 592  END
     $r->print(&hiddenfield('filename',$filename));      $r->print(&hiddenfield('filename',$filename));
     #      #
     # Keep track of the number of times we have been called, sort of.      # Keep track of the number of times we have been called, sort of.
     $r->print(&hiddenfield('not_first_run','whatever'));      $r->print(&hiddenfield('not_first_run','1'));
     #      #
     if (exists($env{'form.not_first_run'}) || $sheettype ne 'classcalc') {      if (exists($env{'form.not_first_run'}) || $sheettype ne 'classcalc') {
         $r->print($spreadsheet->get_html_title());          $r->print($spreadsheet->get_html_title());
Line 548  END Line 602  END
         $r->rflush();          $r->rflush();
         $spreadsheet->display($r);          $spreadsheet->display($r);
     }      }
     $r->print('</form>'.&Apache::loncommon::end_page());      $r->print('</form>');
       &Apache::lonquickgrades::endGradeScreen($r);
       $r->print(&Apache::loncommon::end_page());
     $spreadsheet->clear_package();      $spreadsheet->clear_package();
     return OK;      return OK;
 }  }

Removed from v.1.56  
changed lines
  Added in v.1.66


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