Diff for /loncom/interface/Attic/lonspreadsheet.pm between versions 1.100.4.1 and 1.102

version 1.100.4.1, 2002/09/27 18:43:10 version 1.102, 2002/08/28 19:50:29
Line 146  undef %v; Line 146  undef %v;
 undef %t;  undef %t;
 undef %f;  undef %f;
 undef %c;  undef %c;
 undef %rl;  undef %rowlabel;
 undef @os;  undef @os;
   
 $maxrow=0;  $maxrow=0;
Line 904  sub outrowassess { Line 904  sub outrowassess {
     my @cols=();      my @cols=();
     if ($n) {      if ($n) {
        my ($usy,$ufn)=split(/\_\_\&\&\&\_\_/,$f{'A'.$n});         my ($usy,$ufn)=split(/\_\_\&\&\&\_\_/,$f{'A'.$n});
       if ($rl{$usy}) {        if ($rowlabel{$usy}) {
        $cols[0]=$rl{$usy}.'<br>'.         $cols[0]=$rowlabel{$usy}.'<br>'.
                 '<select name="sel_'.$n.'" onChange="changesheet('.$n.                  '<select name="sel_'.$n.'" onChange="changesheet('.$n.
                 ')"><option name="default">Default</option>';                  ')"><option name="default">Default</option>';
       } else { $cols[0]=''; }        } else { $cols[0]=''; }
Line 935  sub outrow { Line 935  sub outrow {
     my $n=shift;      my $n=shift;
     my @cols=();      my @cols=();
     if ($n) {      if ($n) {
        $cols[0]=$rl{$f{'A'.$n}};         $cols[0]=$rowlabel{$f{'A'.$n}};
     } else {      } else {
        $cols[0]='<b><font size=+1>Export</font></b>';         $cols[0]='<b><font size=+1>Export</font></b>';
     }      }
Line 989  sub setothersheets { Line 989  sub setothersheets {
 # ------------------------------------------------ Add or change formula values  # ------------------------------------------------ Add or change formula values
   
 sub setrowlabels {  sub setrowlabels {
     my ($safeeval,%rl)=@_;      my ($safeeval,%rowlabel)=@_;
     %{$safeeval->varglob('rl')}=%rl;      %{$safeeval->varglob('rowlabel')}=%rowlabel;
 }  }
   
 # ------------------------------------------------------- Calculate spreadsheet  # ------------------------------------------------------- Calculate spreadsheet
Line 1187  sub rown { Line 1187  sub rown {
    if ($vl eq '') {     if ($vl eq '') {
        $vl='<font size=+2 color='.$bgcolor.'>&#35;</font>';         $vl='<font size=+2 color='.$bgcolor.'>&#35;</font>';
            }             }
            $rowdata.='<td bgcolor='.$bgcolor.'>';             $rowdata.=
            if ($ENV{'request.role'} =~ /^st\./) {         '<td bgcolor='.$bgcolor.'><a href="javascript:celledit('.$fm.');">'.$vl.
                $rowdata.=$vl;         '</a></td>';
            } else {  
                $rowdata.='<a href="javascript:celledit('.$fm.');">'.  
                    $vl.'</a>';  
            }  
            $rowdata.='</td>';  
        } else {         } else {
            $rowdata.='<td bgcolor='.$bgcolor.'>&nbsp;'.$vl.'&nbsp;</td>';             $rowdata.='<td bgcolor='.$bgcolor.'>&nbsp;'.$vl.'&nbsp;</td>';
        }         }
Line 1236  sub outsheet { Line 1231  sub outsheet {
                   '><b><font size=+1>Import</font></b></td>'.                    '><b><font size=+1>Import</font></b></td>'.
                   '<td colspan='.$maxyellow.                    '<td colspan='.$maxyellow.
   '><b><font size=+1>Calculations</font></b></td></tr><tr>';    '><b><font size=+1>Calculations</font></b></td></tr><tr>';
     my $showf=0;         my $showf=0;
     foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',         foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',
      'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',                  'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
      'a','b','c','d','e','f','g','h','i','j','k','l','m',                  'a','b','c','d','e','f','g','h','i','j','k','l','m',
      'n','o','p','q','r','s','t','u','v','w','x','y','z') {                  'n','o','p','q','r','s','t','u','v','w','x','y','z') {
         $showf++;             $showf++;
         if ($showf<=$maxred) {              if ($showf<=$maxred) { 
            $tabledata.='<td bgcolor="#FFDDDD">';                  $tabledata.='<td bgcolor="#FFDDDD">'; 
         } else {             } else {
            $tabledata.='<td>';                 $tabledata.='<td>';
         }             }
         $tabledata.="<b><font size=+1>$_</font></b></td>";             $tabledata.="<b><font size=+1>$_</font></b></td>";
     }         }
     $tabledata.='</tr>'.&rown($safeeval,'-').&rown($safeeval,0);         $tabledata.='</tr>'.&rown($safeeval,'-').&rown($safeeval,0);
    } else { $tabledata='<pre>'; }     } else { $tabledata='<pre>'; }
   
     $r->print($tabledata);      $r->print($tabledata);
Line 1264  sub outsheet { Line 1259  sub outsheet {
        $sortidx[$row-1]=$row-1;         $sortidx[$row-1]=$row-1;
     }      }
     @sortidx=sort { $sortby[$a] cmp $sortby[$b]; } @sortidx;      @sortidx=sort { $sortby[$a] cmp $sortby[$b]; } @sortidx;
   
         my $what='Student';          my $what='Student';
         if (&gettype($safeeval) eq 'assesscalc') {          if (&gettype($safeeval) eq 'assesscalc') {
     $what='Item';      $what='Item';
Line 1274  sub outsheet { Line 1268  sub outsheet {
   
     my $n=0;      my $n=0;
     for ($row=0;$row<$maxrow;$row++) {      for ($row=0;$row<$maxrow;$row++) {
      my $thisrow=&rown($safeeval,$sortidx[$row]+1);          my $thisrow=&rown($safeeval,$sortidx[$row]+1);
      if ($thisrow) {          if ($thisrow) {
        if (($n/25==int($n/25)) && (!$ENV{'form.showcsv'})) {              if (($n/25==int($n/25)) && (!$ENV{'form.showcsv'})) {
  $r->print("</table>\n<br>\n");                  $r->print("</table>\n<br>\n");
         $r->rflush();                  $r->rflush();
         $r->print('<table border=2><tr><td>&nbsp;<td>'.$what.'</td>');                  $r->print('<table border=2><tr><td>&nbsp;<td>'.$what.'</td>');
         foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',                  $r->print('<td>'.join('</td><td>',
  'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',                                        (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
  'a','b','c','d','e','f','g','h','i','j','k','l','m',                                              'abcdefghijklmnopqrstuvwxyz'))).
  'n','o','p','q','r','s','t','u','v','w','x','y','z') {                            "</td></tr>\n");
            $r->print('<td>'.$_.'</td>');              }
               $n++;
               $r->print($thisrow);
         }          }
         $r->print('</tr>');  
        }  
        $n++;  
        $r->print($thisrow);  
       }  
     }      }
     $r->print($ENV{'form.showcsv'}?'</pre>':'</table>');      $r->print($ENV{'form.showcsv'}?'</pre>':'</table>');
 }  }
Line 1652  sub updateclasssheet { Line 1643  sub updateclasssheet {
     my $cdom=&getcdom($safeeval);      my $cdom=&getcdom($safeeval);
     my $cid=&getcid($safeeval);      my $cid=&getcid($safeeval);
     my $chome=&getchome($safeeval);      my $chome=&getchome($safeeval);
       #
 # ---------------------------------------------- Read class list and row labels      # Read class list and row labels
       my %classlist;
     my $classlst=&Apache::lonnet::reply      my @tmp = &Apache::lonnet::dump('classlist',$cdom,$cnum);
                                  ('dump:'.$cdom.':'.$cnum.':classlist',$chome);      if ($tmp[0] !~ /^error/) {
           %classlist = @tmp;
       } else {
           return 'Could not access course data';
       }
       undef @tmp;
       #
     my %currentlist=();      my %currentlist=();
     my $now=time;      my $now=time;
     unless ($classlst=~/^error\:/) {      foreach my $student (keys(%classlist)) {
         foreach (split(/\&/,$classlst)) {          my ($end,$start)=split(/\:/,$classlist{$student});
             my ($name,$value)=split(/\=/,$_);          my $active=1;
             my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value));          $active = 0 if (($end) && ($now>$end));
             my $active=1;          $active = 1 if ($ENV{'form.Status'} eq 'Any');
             if (($end) && ($now>$end)) { $active=0; }          $active = !$active if ($ENV{'form.Status'} eq 'Expired');
             $active = 1 if ($ENV{'form.Status'} eq 'Any');          if ($active) {
             $active = !$active if ($ENV{'form.Status'} eq 'Expired');              my $rowlabel='';
             if ($active) {              my ($studentName,$studentDomain)=split(/\:/,$student);
                 my $rowlabel='';              my $studentSection=&Apache::lonnet::usection($studentDomain,
                 $name=&Apache::lonnet::unescape($name);                                                           $studentName,$cid);
                 my ($sname,$sdom)=split(/\:/,$name);              if ($studentSection==-1) {
                 my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);                  unless ($ENV{'form.showcsv'}) {
 #                if ($ssec==-1) {                      $rowlabel='<font color=red>Data not available: '.
 #   unless ($ENV{'form.showcsv'}) {                          $studentName.'</font>';
 #                    $rowlabel='<font color=red>Data not available: '.$name.                  } else {
 #      '</font>';                      $rowlabel='ERROR","'.$studentName.
 #   } else {                          '","Data not available","","","';
 #       $rowlabel='ERROR","'.$name.                  }
 #                                 '","Data not available","","","';              } else {
 #                   }                  my %reply=&Apache::lonnet::idrget($studentDomain,$studentName);
 #                } else {                  my %studentInformation=&Apache::lonnet::get
                     my %reply=&Apache::lonnet::idrget($sdom,$sname);                      ('environment',
                     my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.                       ['lastname','generation','firstname','middlename','id'],
       ':environment:firstname&middlename&lastname&generation',                       $studentDomain,$studentName);
                       &Apache::lonnet::homeserver($sname,$sdom));                  if (! $ENV{'form.showcsv'}) {
    unless ($ENV{'form.showcsv'}) {                      $rowlabel='<a href="/adm/studentcalc?uname='.$studentName.
                     $rowlabel='<a href="/adm/studentcalc?uname='.$sname.                          '&udom='.$studentDomain.'">'.
                               '&udom='.$sdom.'">'.                              $studentSection.'&nbsp;';
                               $ssec.'&nbsp;'.$reply{$sname}.'<br>';                      foreach ('id','firstname','middlename',
                     foreach ( split(/\&/,$reply)) {                               'lastname','generation'){
                         $rowlabel.=&Apache::lonnet::unescape($_).' ';                          $rowlabel.=$studentInformation{$_}."&nbsp;";
                     }                      }
                     $rowlabel.='</a>';                      $rowlabel.='</a>';
    } else {                  } else {
     $rowlabel=$ssec.'","'.$reply{$sname}.'"';                      $rowlabel= '"'.join('","',
                     my $ncount=0;                                          ($studentSection,
                     foreach (split(/\&/,$reply)) {                                           $studentInformation{'id'},
                         $rowlabel.=',"'.&Apache::lonnet::unescape($_).'"';                                           $studentInformation{'firstname'},
                         $ncount++;                                           $studentInformation{'middlename'},
                     }                                           $studentInformation{'lastname'},
                     unless ($ncount==4) { $rowlabel.=',""'; }                                           $studentInformation{'generation'})
                     $rowlabel=~s/\"$//;                                          ).'"';
    }  
 #                }  
  $currentlist{&Apache::lonnet::unescape($name)}=$rowlabel;  
             }  
         } # end of foreach (split(/\&/,$classlst))  
 #  
 # -------------------- Find discrepancies between the course row table and this  
 #  
         my %f=&getformulas($safeeval);  
         my $changed=0;  
   
         my $maxrow=0;  
         my %existing=();  
   
 # ----------------------------------------------------------- Now obsolete rows  
  foreach (keys(%f)) {  
     if ($_=~/^A(\d+)/) {  
                 $maxrow=($1>$maxrow)?$1:$maxrow;  
                 $existing{$f{$_}}=1;  
  unless ((defined($currentlist{$f{$_}})) || (!$1) ||  
                         ($f{$_}=~/^(\~\~\~|\-\-\-)/)) {  
    $f{$_}='!!! Obsolete';  
                    $changed=1;  
                 }                  }
             }              }
         }              $currentlist{$student}=$rowlabel;
           } # end of if ($active)
 # -------------------------------------------------------- New and unknown keys      } # end of foreach my $student (keys(%classlist))
            #
         foreach (sort keys(%currentlist)) {      # Find discrepancies between the course row table and this
             unless ($existing{$_}) {      #
  $changed=1;      my %f=&getformulas($safeeval);
                 $maxrow++;      my $changed=0;
                 $f{'A'.$maxrow}=$_;      #
       my $maxrow=0;
       my %existing=();
       #
       # Now obsolete rows
       foreach (keys(%f)) {
           if ($_=~/^A(\d+)/) {
               $maxrow=($1>$maxrow)?$1:$maxrow;
               $existing{$f{$_}}=1;
               unless ((defined($currentlist{$f{$_}})) || (!$1) ||
                       ($f{$_}=~/^(\~\~\~|\-\-\-)/)) {
                   $f{$_}='!!! Obsolete';
                   $changed=1;
             }              }
         }          }
        
         if ($changed) { &setformulas($safeeval,%f); }  
   
         &setmaxrow($safeeval,$maxrow);  
         &setrowlabels($safeeval,%currentlist);  
   
     } else {  
         return 'Could not access course data';  
     }      }
       #
       # New and unknown keys
       foreach (sort keys(%currentlist)) {
           unless ($existing{$_}) {
               $changed=1;
               $maxrow++;
               $f{'A'.$maxrow}=$_;
           }
       }
       if ($changed) { &setformulas($safeeval,%f); }
       #
       &setmaxrow($safeeval,$maxrow);
       &setrowlabels($safeeval,%currentlist);
 }  }
   
 # ----------------------------------- Update rows for student and assess sheets  # ----------------------------------- Update rows for student and assess sheets
Line 1755  sub updatestudentassesssheet { Line 1746  sub updatestudentassesssheet {
     my $safeeval=shift;      my $safeeval=shift;
     my %bighash;      my %bighash;
     my $stype=&gettype($safeeval);      my $stype=&gettype($safeeval);
     my $uname=&getuname($safeeval);  
     my $udom =&getudom($safeeval);  
     my %current=();      my %current=();
     unless ($updatedata{      unless ($updatedata{$ENV{'request.course.fn'}.'_'.$stype}) {
         $ENV{'request.course.fn'}.'_'.$stype.'_'.$uname.'_'.$udom}) {  
 # -------------------------------------------------------------------- Tie hash  # -------------------------------------------------------------------- Tie hash
       if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',        if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
                        &GDBM_READER(),0640)) {                         &GDBM_READER(),0640)) {
Line 1840  sub updatestudentassesssheet { Line 1828  sub updatestudentassesssheet {
         } elsif ($stype eq 'studentcalc') {          } elsif ($stype eq 'studentcalc') {
             %current=%allassess;              %current=%allassess;
         }          }
         $updatedata{$ENV{'request.course.fn'}.'_'.$stype.'_'.$uname.'_'.$udom}=          $updatedata{$ENV{'request.course.fn'}.'_'.$stype}=
     join('___;___',%current);      join('___;___',%current);
     } else {      } else {
         return 'Could not access course data';          return 'Could not access course data';
Line 1848  sub updatestudentassesssheet { Line 1836  sub updatestudentassesssheet {
 # ------------------------------------------------------ Get current from cache  # ------------------------------------------------------ Get current from cache
     } else {      } else {
         %current=split(/\_\_\_\;\_\_\_/,          %current=split(/\_\_\_\;\_\_\_/,
      $updatedata{$ENV{'request.course.fn'}.'_'.$stype.'_'.$uname.'_'.$udom});         $updatedata{$ENV{'request.course.fn'}.'_'.$stype});
     }      }
 # -------------------- Find discrepancies between the course row table and this  # -------------------- Find discrepancies between the course row table and this
 #  #
Line 1901  sub loadstudent { Line 1889  sub loadstudent {
     my %c=();      my %c=();
     my %f=&getformulas($safeeval);      my %f=&getformulas($safeeval);
     $cachedassess=&getuname($safeeval).':'.&getudom($safeeval);      $cachedassess=&getuname($safeeval).':'.&getudom($safeeval);
     %cachedstores=();      # Get ALL the student preformance data
     {      my @tmp = &Apache::lonnet::dump(&getcid($safeeval),
       my $reply=&Apache::lonnet::reply('dump:'.&getudom($safeeval).':'.                                      &getudom($safeeval),
                                                &getuname($safeeval).':'.                                      &getuname($safeeval),
                                                &getcid($safeeval),                                      undef);
                                                &getuhome($safeeval));      if ($tmp[0] !~ /^error:/) {
       unless ($reply=~/^error\:/) {          %cachedstores = @tmp;
  foreach ( split(/\&/,$reply)) {  
             my ($name,$value)=split(/\=/,$_);  
             $cachedstores{&Apache::lonnet::unescape($name)}=  
                   &Apache::lonnet::unescape($value);  
  }  
       }  
     }      }
       undef @tmp;
       # 
     my @assessdata=();      my @assessdata=();
     foreach (keys(%f)) {      foreach (keys(%f)) {
  if ($_=~/^A(\d+)/) {   if ($_=~/^A(\d+)/) {
    my $row=$1;     my $row=$1;
            unless (($f{$_}=~/^[\!\~\-]/) || ($row==0)) {             unless (($f{$_}=~/^[\!\~\-]/) || ($row==0)) {
       my ($usy,$ufn)=split(/\_\_\&\&\&\_\_/,$f{$_});        my ($usy,$ufn)=split(/__&&&\__/,$f{$_});
       @assessdata=&exportsheet(&getuname($safeeval),        @assessdata=&exportsheet(&getuname($safeeval),
                                        &getudom($safeeval),                                         &getudom($safeeval),
                                        'assesscalc',$usy,$ufn);                                         'assesscalc',$usy,$ufn);
Line 1989  ENDPOP Line 1973  ENDPOP
               $r->rflush();                 $r->rflush(); 
   
               my $index=0;                my $index=0;
              foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',                foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',
               'N','O','P','Q','R','S','T','U','V','W','X','Y','Z') {                         'N','O','P','Q','R','S','T','U','V','W','X','Y','Z') {
                   if ($studentdata[$index]) {                    if ($studentdata[$index]) {
      my $col=$_;                        my $col=$_;
      if ($studentdata[$index]=~/\D/) {                        if ($studentdata[$index]=~/\D/) {
                          $c{$col.$row}="'".$studentdata[$index]."'";                            $c{$col.$row}="'".$studentdata[$index]."'";
       } else {                        } else {
          $c{$col.$row}=$studentdata[$index];                            $c{$col.$row}=$studentdata[$index];
      }                        }
                      unless ($col eq 'A') {                         unless ($col eq 'A') { 
  $f{$col.$row}='import';                            $f{$col.$row}='import';
                      }                        }
   }    }
                   $index++;                    $index++;
               }                }
Line 2466  sub handler { Line 2450  sub handler {
       return OK;        return OK;
     }      }
   
     if ($ENV{'request.role'} =~ /^st\./) {  
         delete $ENV{'form.unewfield'}   if (exists($ENV{'form.unewfield'}));  
         delete $ENV{'form.unewformula'} if (exists($ENV{'form.unewformula'}));  
     }  
   
 # ---------------------------------------------------- Global directory configs  # ---------------------------------------------------- Global directory configs
   
 $includedir=$r->dir_config('lonIncludes');  $includedir=$r->dir_config('lonIncludes');
Line 2516  $tmpdir=$r->dir_config('lonDaemons').'/t Line 2495  $tmpdir=$r->dir_config('lonDaemons').'/t
 # --------------------------------------------------------------- Screen output  # --------------------------------------------------------------- Screen output
   
     $r->print('<html><head><title>LON-CAPA Spreadsheet</title>');      $r->print('<html><head><title>LON-CAPA Spreadsheet</title>');
     if ($ENV{'request.role'} !~ /^st\./) {      $r->print(<<ENDSCRIPT);
         $r->print(<<ENDSCRIPT);  
 <script language="JavaScript">  <script language="JavaScript">
   
     function celledit(cn,cf) {      function celledit(cn,cf) {
Line 2543  $tmpdir=$r->dir_config('lonDaemons').'/t Line 2521  $tmpdir=$r->dir_config('lonDaemons').'/t
   
 </script>  </script>
 ENDSCRIPT  ENDSCRIPT
     }     $r->print('</head>'.&Apache::loncommon::bodytag('Grades Spreadsheet').
     $r->print('</head><body bgcolor="#FFFFFF">'.  
        '<img align=right src=/adm/lonIcons/lonlogos.gif>'.  
        '<h1>LON-CAPA Spreadsheet</h1>'.  
        '<form action="'.$r->uri.'" name=sheet method=post>'.         '<form action="'.$r->uri.'" name=sheet method=post>'.
        &hiddenfield('uname',$ENV{'form.uname'}).         &hiddenfield('uname',$ENV{'form.uname'}).
        &hiddenfield('udom',$ENV{'form.udom'}).         &hiddenfield('udom',$ENV{'form.udom'}).
Line 2599  ENDSCRIPT Line 2574  ENDSCRIPT
     unless (&gettype($asheet) eq 'classcalc') {      unless (&gettype($asheet) eq 'classcalc') {
         $r->print('<p><b>User:</b> '.&getuname($asheet).          $r->print('<p><b>User:</b> '.&getuname($asheet).
                   '<br><b>Domain:</b> '.&getudom($asheet));                    '<br><b>Domain:</b> '.&getudom($asheet));
 #        if (&getcsec($asheet) eq '-1') {          if (&getcsec($asheet) eq '-1') {
 #           $r->print('<h3><font color=red>'.             $r->print('<h3><font color=red>'.
 #                     'Not a student in this course</font></h3>');                       'Not a student in this course</font></h3>');
 #        } else {          } else {
            $r->print('<br><b>Section/Group:</b> '.&getcsec($asheet));             $r->print('<br><b>Section/Group:</b> '.&getcsec($asheet));
 #        }          }
         if ($ENV{'form.usymb'}) {          if ($ENV{'form.usymb'}) {
            $r->print('<br><b>Assessment:</b> <tt>'.$ENV{'form.usymb'}.'</tt>');             $r->print('<br><b>Assessment:</b> <tt>'.$ENV{'form.usymb'}.'</tt>');
         }          }
     }      }
   
 # ---------------------------------------------------------------- Course title  
   
     $r->print('<h1>'.  
             $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.  
              '</h1><h3>'.localtime().'</h3>');  
   
 # ---------------------------------------------------- See if user can see this  # ---------------------------------------------------- See if user can see this
   
     if ((&gettype($asheet) eq 'classcalc') ||       if ((&gettype($asheet) eq 'classcalc') || 

Removed from v.1.100.4.1  
changed lines
  Added in v.1.102


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