Diff for /loncom/interface/spreadsheet/lonspreadsheet.pm between versions 1.4 and 1.5

version 1.4, 2003/05/23 19:36:04 version 1.5, 2003/05/27 19:17:07
Line 58  use Apache::classcalc(); Line 58  use Apache::classcalc();
 use Apache::studentcalc();  use Apache::studentcalc();
 use Apache::assesscalc();  use Apache::assesscalc();
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http);
   use Apache::lonmenu();
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::lonhtmlcommon;  use Apache::lonhtmlcommon;
 use HTML::Entities();  use HTML::Entities();
Line 88  sub selectbox { Line 89  sub selectbox {
     return $selout.'</select>';      return $selout.'</select>';
 }  }
   
   sub file_dialogs {
       my ($spreadsheet) = @_;
       my $bgcolor = "#FFFFFF";
       my $sheettype = $spreadsheet->{'type'};
       my $result = '';
       ##
       ## Deal with saving the spreadsheet
       if (exists($ENV{'form.save'}) && 
           exists($ENV{'form.savefilename'})) {
           $spreadsheet->filename($ENV{'form.savefilename'});
           my $save_status = $spreadsheet->save();
           if ($save_status ne 'ok') {
               $result .= "An error occurred while saving the spreadsheet".
                   "There error is:".$save_status;
               return $result;
           } else {
               $result .= "Spreadsheet saved as ".$ENV{'form.savefilename'};
           }
       } elsif (exists($ENV{'form.newformula'}) && 
                exists($ENV{'form.cell'})       && 
                $ENV{'form.cell'} ne '' ) {
           ##
           ## Make any requested modifications to the spreadsheet
           $spreadsheet->modify_cell($ENV{'form.cell'},
                                     $ENV{'form.newformula'});
           $spreadsheet->save_tmp();
           # output that we are dealing with a temporary file
           $result .=&hiddenfield('workcopy',$sheettype);
           $result .='<pre>'.$ENV{'form.cell'}.' = '.
                     $ENV{'form.newformula'}."</pre>\n";
       }
       ##
       ## Editing code
       $result .=&hiddenfield('cell','').
                 &hiddenfield('newformula','');
       ##
       ## Create the save and load dialogs
       my $filename = $spreadsheet->filename();
       $filename = '' if ($filename =~ /^default\.$sheettype/i);
       $filename =~ s/_$sheettype$//;
       my $save_dialog = '<nobr>'.
           '<input type="submit" name="save" value="Save as" /> '.
           '<input type="text" name="savefilename" size="30" value="'.
           $filename.'" />'.
           '</nobr>';
       my $makedefault_dialog = '<input type="submit" name="makedefault" '.
           'value="Make This Sheet the Default"/>';
       #
       my $link = '<a href="javascript:openbrowser'.
           "('sheet','loadfilename','spreadsheet')\">Browse</a>";
       my $load_dialog = <<END;
   <table bgcolor="$bgcolor">
   <tr><td><input type="submit" name="load" value="Load" /></td>
       <td><nobr>
           <input type="text" name="loadfilename" size="25" value="$filename" />
           $link</nobr>
       </td></tr>
   <tr><td>&nbsp;</td><td>
       <select name="fileselect" onchange="document.sheet.loadfilename.value=document.sheet.fileselect.value" >
       <option name="Default">Default</option>
   END
       foreach my $sheetfilename ($spreadsheet->othersheets()) {
           $sheetfilename =~ s/_$sheettype$//;
           $load_dialog .= '    <option name="'.$sheetfilename.'"';
           if ($filename eq $sheetfilename) {
               $load_dialog .= ' selected';
           }
           $load_dialog .= '>'.$sheetfilename."</option>\n";
       }
       $load_dialog .= "</td><td>&nbsp;</td></tr>\n</table>\n";
           #
       $result .=<<END;
   <!-- load / save dialogs -->
   <table cellspacing="2">
   <tr>
       <td>$load_dialog</td>
       <td>
           <table bgcolor="$bgcolor">
           <tr><td>$save_dialog</td></tr>
           <tr><td align="center">$makedefault_dialog</td></tr>
           </table>
       </td>
   </tr>
   </table>
   END
       return $result;
   }
   
 sub handler {  sub handler {
     my $r=shift;      my $r=shift;
     #      #
Line 155  sub handler { Line 244  sub handler {
                                                 $ENV{'request.course.id'});                                                  $ENV{'request.course.id'});
     my $allowed_to_view =  &Apache::lonnet::allowed('vgr',      my $allowed_to_view =  &Apache::lonnet::allowed('vgr',
                                                 $ENV{'request.course.id'});                                                  $ENV{'request.course.id'});
   
     #      #
     # 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.
Line 175  sub handler { Line 265  sub handler {
     ##      ##
     ## Spit out the javascript required for editing      ## Spit out the javascript required for editing
     ##      ##
     if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {      if ($allowed_to_edit) {
           my $extra_javascript = 
               &Apache::loncommon::browser_and_searcher_javascript();
         $r->print(<<ENDSCRIPT);          $r->print(<<ENDSCRIPT);
 <script language="JavaScript">  <script language="JavaScript">
   
       $extra_javascript
   
     var editwin;      var editwin;
   
     function celledit(cellname,cellformula) {      function celledit(cellname,cellformula) {
Line 219  ENDSCRIPT Line 313  ENDSCRIPT
               '<form action="'.$r->uri.'" name="sheet" method="post">');                '<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'}).
                 &Apache::lonmenu::regflush());
     $r->rflush();      $r->rflush();
     ##      ##
     ## Determine the filename to use      ## Determine the filename to use
Line 250  ENDSCRIPT Line 345  ENDSCRIPT
         # error error - run in circles, scream and shout          # error error - run in circles, scream and shout
         return;          return;
     }      }
       #
       # Output selector
       $r->print('<input type="submit" value="Update Display" /><br />');
     ##      ##
     ## Editing/loading/saving      ## Editing/loading/saving
     if ($allowed_to_edit) {      if ($allowed_to_edit) {
         ##          $r->print('<table><tr><td>'.$spreadsheet->html_header().'</td>'.
         ## Deal with saving the spreadsheet                    '<td valign="bottom">'.
         if (exists($ENV{'form.save'}) &&                     &file_dialogs($spreadsheet)."</td></tr></table>\n");
             exists($ENV{'form.savefilename'})) {  
             $spreadsheet->filename($ENV{'form.savefilename'});  
             my $save_status = $spreadsheet->save();  
             if ($save_status ne 'ok') {  
                 $r->print("An error occurred while saving the spreadsheet".  
                           "There error is:".$save_status);  
             } else {  
                 $r->print("Spreadsheet saved as ".$ENV{'form.savefilename'});  
             }  
         } elsif (exists($ENV{'form.newformula'}) &&   
                  exists($ENV{'form.cell'})       &&   
                  $ENV{'form.cell'} ne '' ) {  
             ##  
             ## Make any requested modifications to the spreadsheet  
             $spreadsheet->modify_cell($ENV{'form.cell'},  
                                       $ENV{'form.newformula'});  
             $spreadsheet->save_tmp();  
             # output that we are dealing with a temporary file  
             $r->print(&hiddenfield('workcopy',$sheettype));  
             $r->print('<pre>'.$ENV{'form.cell'}.' = '.  
                       $ENV{'form.newformula'}.'</pre>'."\n");  
         }  
         ##  
         ## Editing code  
         $r->print(&hiddenfield('cell','').  
                   &hiddenfield('newformula',''));  
         ##  
         ## Create the save and load dialogs  
         $filename = $spreadsheet->filename();  
         $filename = '' if ($filename =~ /^default\.$sheettype/i);  
         $filename =~ s/_$sheettype$//;  
         my $save_dialog =   
             '<input type="submit" name="save" value="Save as ..." /> '.  
                 '<input type="text" name="savefilename" size="30" value="'.  
                     $filename.'" />';  
         my $makedefault_dialog =   
             '<input type="submit" name="makedefault" value="Make Default"/>';  
         #  
         my $load_dialog =   
             '<input type="submit" name="load" value="Load ..." />'.  
                 '<select name="loadfilename">'.  
                     '<option name="Default">Default</option>'."\n";  
         foreach my $sheetfilename ($spreadsheet->othersheets()) {  
             $sheetfilename =~ s/_$sheettype$//;  
             $load_dialog .= '<option name="'.$sheetfilename.'"';  
             if ($filename eq $sheetfilename) {  
                 $load_dialog .= ' selected';  
             }  
             $load_dialog .= '>'.$sheetfilename."</option>\n";  
         }  
         #  
         $r->print(<<END);  
 <!-- load / save dialogs -->  
 <table cellspacing="3">  
 <tr>  
 <td>$load_dialog</td>  
 <td>$save_dialog</td>  
 <td>$makedefault_dialog</td>  
 </tr>  
 </table>  
 END  
         $r->rflush();          $r->rflush();
       } else {
           $r->print('<table><tr><td>'.$spreadsheet->html_header().
                     "</td></tr></table>\n");
     }      }
     #      #
     # Output selector  
     $r->print($spreadsheet->html_header());  
     #  
     # Keep track of the filename      # Keep track of the filename
     $r->print(&hiddenfield('filename',$filename));      $r->print(&hiddenfield('filename',$filename));
     #      #
     $r->print($spreadsheet->get_html_title());      # Keep track of the number of times we have been called, sort of.
     if ($allowed_to_view || $allowed_to_edit) {      $r->print(&hiddenfield('not_first_run','whatever'));
         $r->print($spreadsheet->parent_link());      #
       if (exists($ENV{'form.not_first_run'}) || $sheettype ne 'classcalc') {
           $r->print($spreadsheet->get_html_title());
           if ($allowed_to_view || $allowed_to_edit) {
               $r->print($spreadsheet->parent_link());
           }
           $spreadsheet->display($r);
       } else {
           $r->print("<h2>Make your selections and bonk the 'update display' button</h2>");
     }      }
     $spreadsheet->display($r);  
     $r->print('</form></body></html>');      $r->print('</form></body></html>');
     return OK;      return OK;
 }  }

Removed from v.1.4  
changed lines
  Added in v.1.5


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