Diff for /loncom/interface/spreadsheet/lonspreadsheet.pm between versions 1.40 and 1.59

version 1.40, 2005/04/07 06:56:23 version 1.59, 2011/09/26 12:15:39
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 73  use HTML::Entities(); Line 74  use HTML::Entities();
 sub textfield {  sub textfield {
     my ($title,$name,$value)=@_;      my ($title,$name,$value)=@_;
     return "\n<p><b>$title:</b><br />".      return "\n<p><b>$title:</b><br />".
         '<input type=text name="'.$name.'" size=80 value="'.$value.'" />';          '<input type="text" name="'.$name.'" size="80" value="'.$value.'" />';
 }  }
   
 sub hiddenfield {  sub hiddenfield {
     my ($name,$value)=@_;      my ($name,$value)=@_;
     return '<input type=hidden name="'.$name.'" value="'.$value.'" />'."\n";      return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n";
 }  }
   
 sub selectbox {  sub selectbox {
Line 86  sub selectbox { Line 87  sub selectbox {
     my $selout="\n<p><b>$title:</b><br />".'<select name="'.$name.'">';      my $selout="\n<p><b>$title:</b><br />".'<select name="'.$name.'">';
     foreach (sort keys(%options)) {      foreach (sort keys(%options)) {
         $selout.='<option value="'.$_.'"';          $selout.='<option value="'.$_.'"';
         if ($_ eq $value) { $selout.=' selected'; }          if ($_ eq $value) { $selout.=' selected="selected"'; }
         $selout.='>'.&mt($options{$_}).'</option>';          $selout.='>'.&mt($options{$_}).'</option>';
     }      }
     return $selout.'</select>';      return $selout.'</select>';
Line 100  sub file_dialogs { Line 101  sub file_dialogs {
     my $message = '';      my $message = '';
     ##      ##
     ## Deal with saving the spreadsheet      ## Deal with saving the spreadsheet
       $spreadsheet->check_formulas_loaded();
     if ((exists($env{'form.save'}) || exists($env{'form.makedefault'})) &&       if ((exists($env{'form.save'}) || exists($env{'form.makedefault'})) && 
         exists($env{'form.savefilename'})) {          exists($env{'form.savefilename'})) {
         $spreadsheet->filename($env{'form.savefilename'});          $spreadsheet->filename($env{'form.savefilename'});
Line 139  sub file_dialogs { Line 141  sub file_dialogs {
     if ($spreadsheet->is_default()) {      if ($spreadsheet->is_default()) {
         $filename = 'Default';          $filename = 'Default';
     }      }
     my $save_dialog = '<nobr>'.      my $save_dialog = '<span class="LC_nobreak">'.
         '<input type="submit" name="save" value="'.&mt('Save as').'" /> '.          '<input type="submit" name="save" value="'.&mt('Save as').'" /> '.
         '<input type="text" name="savefilename" size="30" value="'.          '<input type="text" name="savefilename" size="30" value="'.
         $truefilename.'" />'.          $truefilename.'" />'.
         '</nobr>';          '</span>';
     my $makedefault_dialog = '<input type="submit" name="makedefault" '.      my $makedefault_dialog = '<input type="submit" name="makedefault" '.
         'value="'.&mt('Save as & Make This Sheet the Default').'"/>';          'value="'.&mt('Save as &amp; Make This Sheet the Default').'"/>';
     #      #
     my $link = '<a href="javascript:openbrowser'.      my $link = '<a href="javascript:openbrowser'.
         "('sheet','loadfilename','spreadsheet')\">".&mt('Select Spreadsheet File')."</a>";          "('sheet','loadfilename','spreadsheet')\">".&mt('Select Spreadsheet File')."</a>";
Line 153  sub file_dialogs { Line 155  sub file_dialogs {
     my $load_dialog = <<END;      my $load_dialog = <<END;
 <table bgcolor="$bgcolor">  <table bgcolor="$bgcolor">
 <tr><td><input type="submit" name="load" value="$load" /></td>  <tr><td><input type="submit" name="load" value="$load" /></td>
     <td><nobr>      <td><span class="LC_nobreak">
         <input type="text" name="loadfilename" size="20" value="$filename" />          <input type="text" name="loadfilename" size="20" value="$filename" />
         $link</nobr>          $link</span>
     </td></tr>      </td></tr>
 <tr><td>&nbsp;</td><td>  <tr><td>&nbsp;</td><td>
     <select name="fileselect" onchange="document.sheet.loadfilename.value=document.sheet.fileselect.value" >      <select name="fileselect" onchange="document.sheet.loadfilename.value=document.sheet.fileselect.value" >
Line 164  END Line 166  END
     foreach my $sheetfilename ($spreadsheet->othersheets()) {      foreach my $sheetfilename ($spreadsheet->othersheets()) {
         $load_dialog .= '    <option value="'.$sheetfilename.'"';          $load_dialog .= '    <option value="'.$sheetfilename.'"';
         if ($filename eq $sheetfilename) {          if ($filename eq $sheetfilename) {
             $load_dialog .= ' selected';              $load_dialog .= ' selected="selected"';
             $default_filename_set = 1;              $default_filename_set = 1;
         }          }
         $load_dialog .= '>'.$sheetfilename."</option>\n";          $load_dialog .= '>'.$sheetfilename."</option>\n";
     }      }
     $load_dialog .= "</select>\n</td><td>&nbsp;</td></tr>\n</table>\n";      $load_dialog .= "</select>\n</td><td>&nbsp;</td></tr>\n</table>\n";
         #          #
       my $headline = &mt('File Dialogs');
     $result .=<<END;      $result .=<<END;
 <!--   <!-- 
     <fieldset title="File Dialogs" >      <fieldset title="File Dialogs" >
     <legend>File Dialogs</legend>      <legend>$headline</legend>
   -->    -->
 <!-- load / save dialogs -->  <!-- load / save dialogs -->
 <table cellspacing="2">  <table cellspacing="2">
Line 198  END Line 201  END
 sub handler {  sub handler {
     my $r=shift;      my $r=shift;
     #      #
     # Overload checking  
     #  
     # Check this server  
     my $loaderror=&Apache::lonnet::overloaderror($r);  
     if ($loaderror) { return $loaderror; }  
     # Check the course homeserver  
     $loaderror= &Apache::lonnet::overloaderror($r,  
                       $env{'course.'.$env{'request.course.id'}.'.home'});  
 #    if ($loaderror) { return $loaderror; }   
     #  
     # HTML Header      # HTML Header
     #      #
     if ($r->header_only) {      if ($r->header_only) {
Line 225  sub handler { Line 218  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      # Do not allow users without vgr or mgr priv to continue unless 
     # effect.      # grading type is set to spreadsheet. 
     #      #
     if ($env{'request.role'} =~ /^st\./) {  
         if ($env{'course.'.$courseid.'.grading'} eq 'standard' ||      if ((!$allowed_to_view) && (!$allowed_to_edit)) {
     $env{'course.'.$courseid.'.grading'} eq 'external' ) {          if ($env{'course.'.$courseid.'.grading'} eq 'spreadsheet') {
             return HTTP_NOT_ACCEPTABLE;              if ($sheettype ne 'studentcalc') {
                   $r->internal_redirect('/adm/studentcalc');
                   return OK;
               }
           } else {
               $r->internal_redirect('/adm/quickgrades');
               return OK;
         }          }
     }      }
     #      #
Line 251  sub handler { Line 268  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'}));
Line 263  sub handler { Line 279  sub handler {
     }      }
     $env{'form.sname'} = $name;      $env{'form.sname'} = $name;
     $env{'form.sdomain'} = $domain;      $env{'form.sdomain'} = $domain;
     ##      my $section = &Apache::lonnet::getsection($domain,$name,
     ## Check permissions        $env{'request.course.id'});
     my $allowed_to_edit = &Apache::lonnet::allowed('mgr',      my @groups;
                                                 $env{'request.course.id'});      if (($env{'user.name'} eq $name) && ($env{'user.domain'} eq $domain)) {
     # Only those instructors/tas/whatevers with complete access          @groups = &Apache::lonnet::sort_course_groups($env{'request.course.id'},
     # (not section restricted) are able to modify spreadsheets.                                      split(':',$env{'request.course.groups'}));
     my $allowed_to_view =  &Apache::lonnet::allowed('vgr',      } else {
                                                 $env{'request.course.id'});          @groups = &Apache::lonnet::get_users_groups($domain,$name,
     if (! $allowed_to_view) {                                                      $env{'request.course.id'});
         $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 313  sub handler { Line 324  sub handler {
     #      #
     # Header....      # Header....
     #      #
     $r->print('<html><head><title>LON-CAPA Spreadsheet</title>');  
     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();      my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
     ##      ##
     ## Spit out the javascript required for editing      ## Spit out the javascript required for editing
     ##      ##
       my $js;
     if ($allowed_to_edit) {      if ($allowed_to_edit) {
  my %lt=(   my %lt=(
  'ce' => 'Cell',   'ce' => 'Cell',
Line 326  sub handler { Line 337  sub handler {
  );   );
         my $extra_javascript =           my $extra_javascript = 
             &Apache::loncommon::browser_and_searcher_javascript();              &Apache::loncommon::browser_and_searcher_javascript();
         $r->print(<<ENDSCRIPT);  
    my $cell_extra_js   = &Apache::loncommon::resize_textarea_js();
    my $cell_edit_start = 
       &Apache::loncommon::start_page('Cell Edit Window',$cell_extra_js,
      {'only_body' => 1,
       'js_ready'  => 1,
       'add_entries'  => {
    'onresize' => "resize_textarea('LC_newformula','LC_aftertextarea')",
    'onload'   => "resize_textarea('LC_newformula','LC_aftertextarea')",
       }});
    my $cell_edit_end = 
       &Apache::loncommon::end_page({'js_ready'  => 1,});
   
           $js = <<ENDSCRIPT;
 <script type="text/javascript">  <script type="text/javascript">
 //<!--  //<!--
     $extra_javascript      $extra_javascript
Line 337  sub handler { Line 361  sub handler {
         var edit_text = '';          var edit_text = '';
         // 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 +='<html><head><title>Cell Edit Window</title></head><body>';          edit_text +='$cell_edit_start';
         edit_text += '<form name="editwinform">';          edit_text += '<form name="editwinform">';
         edit_text += '<center><h3>$lt{'ce'} '+cellname+'</h3>';          edit_text += '<center><h3>$lt{'ce'} '+cellname+'</h3>';
         edit_text += '<textarea name="newformula" cols="60" rows="12"';          edit_text += '<textarea id="LC_newformula" name="newformula" ';
         edit_text += ' wrap="off" >'+cellformula+'</textarea>';          edit_text += ' cols="60" rows="12"; wrap="off" style="width:100%">';
         edit_text += '</br>';   edit_text += cellformula+'</textarea>';
           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=';
Line 355  sub handler { Line 380  sub handler {
         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></body></html>';          edit_text += '</center></div></form>$cell_edit_end';
   
         if (editwin != null && !(editwin.closed) ) {          if (editwin != null && !(editwin.closed) ) {
             editwin.close();              editwin.close();
Line 363  sub handler { Line 388  sub handler {
   
         editwin = window.open($nothing,'CellEditWin','height=280,width=480,scrollbars=no,resizable=yes,alwaysRaised=yes,dependent=yes',true);          editwin = window.open($nothing,'CellEditWin','height=280,width=480,scrollbars=no,resizable=yes,alwaysRaised=yes,dependent=yes',true);
         editwin.document.write(edit_text);          editwin.document.write(edit_text);
           editwin.document.close();
     }      }
 //-->  //-->
 </script>  </script>
Line 375  ENDSCRIPT Line 401  ENDSCRIPT
           text  => 'Spreadsheet',            text  => 'Spreadsheet',
           faq   => 134,            faq   => 134,
           bug   => 'Spreadsheet'});            bug   => 'Spreadsheet'});
     $r->print('</head>'.&Apache::loncommon::bodytag('Grades Spreadsheet').      $r->print(&Apache::loncommon::start_page('Grades Spreadsheet',$js).
               &Apache::lonhtmlcommon::breadcrumbs(undef,'Spreadsheet').                &Apache::lonhtmlcommon::breadcrumbs('Spreadsheet',
               '<form action="'.$r->uri.'" name="sheet" method="post">');    'Spreadsheet_About'));
   
       #
       # Tabs
       # 
       &Apache::lonquickgrades::startGradeScreen($r,'spreadsheet');
   
       #
       # Open the form
       # 
       $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 399  ENDSCRIPT Line 435  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 437  ENDSCRIPT Line 473  ENDSCRIPT
     &Apache::Spreadsheet::initialize_spreadsheet_package();      &Apache::Spreadsheet::initialize_spreadsheet_package();
     my $spreadsheet = undef;      my $spreadsheet = undef;
     if ($sheettype eq 'classcalc') {      if ($sheettype eq 'classcalc') {
         $spreadsheet = Apache::classcalc->new($name,$domain,$filename,undef);          $spreadsheet = Apache::classcalc->new($name,$domain,$filename,undef,
         $section,\@groups);
     } elsif ($sheettype eq 'studentcalc') {      } elsif ($sheettype eq 'studentcalc') {
         $spreadsheet = Apache::studentcalc->new($name,$domain,$filename,undef);          $spreadsheet = Apache::studentcalc->new($name,$domain,$filename,undef,
    $section,\@groups);
     } elsif ($sheettype eq 'assesscalc' &&       } elsif ($sheettype eq 'assesscalc' && 
              defined($symb) &&                defined($symb) && 
              $allowed_to_edit) {               $allowed_to_edit) {
         $spreadsheet = Apache::assesscalc->new($name,$domain,$filename,$symb);          $spreadsheet = Apache::assesscalc->new($name,$domain,$filename,$symb,
          $section,\@groups);
     } else {      } else {
         return HTTP_NOT_ACCEPTABLE;          return HTTP_NOT_ACCEPTABLE;
     }      }
Line 516  END Line 555  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 526  END Line 565  END
         $r->rflush();          $r->rflush();
         $spreadsheet->display($r);          $spreadsheet->display($r);
     }      }
     $r->print('</form></body></html>');      $r->print('</form>');
       &Apache::lonquickgrades::endGradeScreen($r);
       $r->print(&Apache::loncommon::end_page());
       $spreadsheet->clear_package();
     return OK;      return OK;
 }  }
   

Removed from v.1.40  
changed lines
  Added in v.1.59


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