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

version 1.101, 2002/08/21 17:18:08 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 1231  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 1259  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 1269  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 1647  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.  
       '</font>';  
    } else {  
        $rowlabel='ERROR","'.$name.  
                                  '","Data not available","","","';  
                    }  
                 } else {                  } else {
                     my %reply=&Apache::lonnet::idrget($sdom,$sname);                      $rowlabel='ERROR","'.$studentName.
                     my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.                          '","Data not available","","","';
       ':environment:firstname&middlename&lastname&generation',                  }
                       &Apache::lonnet::homeserver($sname,$sdom));              } else {
    unless ($ENV{'form.showcsv'}) {                  my %reply=&Apache::lonnet::idrget($studentDomain,$studentName);
                     $rowlabel='<a href="/adm/studentcalc?uname='.$sname.                  my %studentInformation=&Apache::lonnet::get
                               '&udom='.$sdom.'">'.                      ('environment',
                               $ssec.'&nbsp;'.$reply{$sname}.'<br>';                       ['lastname','generation','firstname','middlename','id'],
                     foreach ( split(/\&/,$reply)) {                       $studentDomain,$studentName);
                         $rowlabel.=&Apache::lonnet::unescape($_).' ';                  if (! $ENV{'form.showcsv'}) {
                       $rowlabel='<a href="/adm/studentcalc?uname='.$studentName.
                           '&udom='.$studentDomain.'">'.
                               $studentSection.'&nbsp;';
                       foreach ('id','firstname','middlename',
                                'lastname','generation'){
                           $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))              $currentlist{$student}=$rowlabel;
 #          } # end of if ($active)
 # -------------------- Find discrepancies between the course row table and this      } # end of foreach my $student (keys(%classlist))
 #      #
         my %f=&getformulas($safeeval);      # Find discrepancies between the course row table and this
         my $changed=0;      #
       my %f=&getformulas($safeeval);
         my $maxrow=0;      my $changed=0;
         my %existing=();      #
       my $maxrow=0;
 # ----------------------------------------------------------- Now obsolete rows      my %existing=();
  foreach (keys(%f)) {      #
     if ($_=~/^A(\d+)/) {      # Now obsolete rows
                 $maxrow=($1>$maxrow)?$1:$maxrow;      foreach (keys(%f)) {
                 $existing{$f{$_}}=1;          if ($_=~/^A(\d+)/) {
  unless ((defined($currentlist{$f{$_}})) || (!$1) ||              $maxrow=($1>$maxrow)?$1:$maxrow;
                         ($f{$_}=~/^(\~\~\~|\-\-\-)/)) {              $existing{$f{$_}}=1;
    $f{$_}='!!! Obsolete';              unless ((defined($currentlist{$f{$_}})) || (!$1) ||
                    $changed=1;                      ($f{$_}=~/^(\~\~\~|\-\-\-)/)) {
                 }                  $f{$_}='!!! Obsolete';
                   $changed=1;
             }              }
         }          }
       }
 # -------------------------------------------------------- New and unknown keys      #
            # New and unknown keys
         foreach (sort keys(%currentlist)) {      foreach (sort keys(%currentlist)) {
             unless ($existing{$_}) {          unless ($existing{$_}) {
  $changed=1;              $changed=1;
                 $maxrow++;              $maxrow++;
                 $f{'A'.$maxrow}=$_;              $f{'A'.$maxrow}=$_;
             }  
         }          }
        
         if ($changed) { &setformulas($safeeval,%f); }  
   
         &setmaxrow($safeeval,$maxrow);  
         &setrowlabels($safeeval,%currentlist);  
   
     } else {  
         return 'Could not access course data';  
     }      }
       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 1893  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 1981  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++;
               }                }

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


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