!distribute items exams/.exam, sheets/.sheet, 4, 3, 3, 5\
	into file_E, file_S, line_E, line_S, linei_E, linei_S

!for ss in $listsh
  !distribute items 0,0,0,0,0,0,0,0,0,0 into\
  sreq, sweight, scid, snewcnt, ssccnt, sscsum, sdursum, sdur
  !set sn=!char 2 to -1 of $ss
  !set st=!char 1 of $ss
  !set l_=!record $sn of wimshome/log/classes/$wims_class/$(file_$st)s
  !set shtit=!line $(line_$st) of $l_
  !set table_id=TABLE_$ss
  !set table_class=sortable
  $table_header
  <caption>
  <b>$(name_$st) $sn.</b> $shtit
  <span class="small">($name_theoric $[rint($sdur)] $name_minute)</span>
  </caption>
  <thead>
  !if $hdrow=1
    $table_hdtr
    <th scope="col">$wims_name_Exercise</th>
    !if req isitemof $show and $st=S
      <th scope="col" class="small" data-sort-method="number">$name_required_points</th>
    !endif
    !if weight isitemof $show
      <th scope="col" class="small" data-sort-method="number">$name_coeff</th>
    !endif
    !if cid isitemof $show
      <th scope="col" class="small" data-sort-method="number">$name_index</th>
    !endif
    </tr>
  !else
    <tr>
    <th></th>
    !if req isitemof $show and $st=S
      <th></th>
    !endif
    !if weight isitemof $show
      <th></th>
    !endif
    !if cid isitemof $show
      <th></th>
    !endif
    !if tot isitemof $show
      <th colspan="4">$name_totals</th>
    !endif
    !if scoremean isitemof $show
      <th colspan="2" class="small">$name_avg_score</th>
    !endif
    !if partmean isitemof $show
      <th colspan="4" class="small">$name_avg_participant</th>
    !endif
    !if minmax isitemof $show
      <th colspan="2">$name_min</th>
      <th colspan="2">$name_max</th>
    !endif
    !if deviat isitemof $show
      <th colspan="2">$name_deviation</th>
    !endif
    </tr>
    $table_hdtr
      <th scope="col">$wims_name_Exercise</th>
    !if req isitemof $show and $st=S
        <th scope="col" class="small" data-sort-method="number">$name_required_points</th>
    !endif
    !if weight isitemof $show
      <th scope="col" class="small" data-sort-method="number">$name_coeff</th>
    !endif
    !if cid isitemof $show
      <th scope="col" class="small" data-sort-method="number" >$name_index</th>
    !endif
    !if tot isitemof $show
      <th scope="col" class="small" data-sort-method="number">$name_new</th>
      <th scope="col" class="small" data-sort-method="number">$name_score</th>
      <th scope="col" class="small" data-sort-method="number">$name_points</th>
      <th scope="col" class="small" data-sort-method="number">$name_duration</th>
    !endif
    !if scoremean isitemof $show
      <th scope="col" class="small" data-sort-method="number">$name_points</th>
      <th scope="col" class="small" data-sort-method="number">$name_duration</th>
    !endif
    !if partmean isitemof $show
      <th scope="col" class="small" data-sort-method="number">$name_new</th>
      <th scope="col" class="small" data-sort-method="number">$name_score</th>
      <th scope="col" class="small" data-sort-method="number">$name_points</th>
      <th scope="col" class="small" data-sort-method="number">$name_duration</th>
    !endif
    !if minmax isitemof $show
      <th scope="col" class="small" data-sort-method="number">$name_points</th>
      <th scope="col" class="small" data-sort-method="number">$name_duration</th>
      <th scope="col" class="small" data-sort-method="number">$name_points</th>
      <th scope="col" class="small" data-sort-method="number">$name_duration</th>
    !endif
    !if deviat isitemof $show
      <th scope="col" class="small" data-sort-method="number">$name_points</th>
      <th scope="col" class="small" data-sort-method="number">$name_duration</th>
    !endif
       </tr>
  !endif
  </thead>
  <tbody>
  !for i=$(start$st$sn) to $(end$st$sn)
    !set l_=!record $i of wimshome/log/classes/$wims_class/exostat
    !distribute words $l_ into $fields
    !set l_=!record $exo of wimshome/log/classes/$wims_class/$(file_$st)$sn
    !if $l_=$empty
      !goto next
    !endif
    !distribute lines $l_ into 1_,2_,3_,4_,5_,6_
    !set t_=$($(linei_$st)_)
    !if $scavg>0 and $st=S
      !set sdur=$[$sdur+$duravg*$3_/$scavg]
    !endif
    $table_tr<td class="small">$exo.
    !if $st=S
      !href target=wims_exo module=$1_&cmd=new&worksheet=$sn&$2_ $t_
    !else
      $t_
    !endif
    </td>
    !if req isitemof $show and $st=S
      <td>$3_</td>
      !set sreq=$[$sreq+$3_]
    !endif
    !if weight isitemof $show
      !if $st=S
        <td>$4_</td>
        !set sweight=$[$sweight+$4_]
      !else
        <td>$1_</td>
      !endif
    !endif
    !if cid isitemof $show
      <td>$cid</td>
      !set scid=$[$scid+$cid*($3_/10)]
    !endif
    !distribute item $[$snewcnt+$newcnt],$[$ssccnt+$sccnt],\
       $[$sscsum+$scsum],$[$sdursum+$dursum] into\
       snewcnt,ssccnt,sscsum,sdursum
    !if tot isitemof $show
      <td style="text-align:right">$newcnt</td>
      <td style="text-align:right">$sccnt</td>
      <td style="text-align:right">$scsum</td>
      <td style="text-align:right">$dursum</td>
    !endif
    !if scoremean isitemof $show
      <td>$[rint(10*$scavg)/10]</td>
      <td>$[rint(10*$duravg)/10]</td>
    !endif
    !if partmean isitemof $show
      <td>$[rint(10*$newcnt/$usercnt)/10]</td>
      <td>$[rint(10*$sccnt/$usercnt)/10]</td>
      <td>$[rint(10*$scsum/$usercnt)/10]</td>
      <td>$[rint(10*$dursum/$usercnt)/10]</td>
    !endif
    !if minmax isitemof $show
      <td style="text-align:right">$scmin</td>
      <td style="text-align:right">$durmin</td>
      <td style="text-align:right">$scmax</td>
      <td style="text-align:right">$durmax</td>
    !endif
    !if deviat isitemof $show
      <td style="text-align:right">$scdev</td>
      <td style="text-align:right">$durdev</td>
    !endif
    :next
    </tr>
  !next i
  </tbody>
  !set test=!listintersect $show and req,weight,cid,tot,scoremean,partmean
  !if $st=S and $(start$st$sn)<$(end$st$sn) and $test!=$empty
    <tfoot>$table_hdtr<th scope="row">$name_sum</th>
    !if req isitemof $show
      <td>$sreq</td>
    !endif
    !if weight isitemof $show
      <td>$sweight</td>
    !endif
    !if cid isitemof $show
      <td>$scid</td>
    !endif
    !if tot isitemof $show
      <td style="text-align:right">$snewcnt</td>
      <td style="text-align:right">$ssccnt</td>
      <td style="text-align:right">$sscsum</td>
      <td style="text-align:right">$sdursum</td>
    !endif
    !if scoremean isitemof $show
      <td>-</td>
      <td>-</td>
    !endif
    !if partmean isitemof $show
      <td>$[rint(10*$snewcnt/$usercnt)/10]</td>
      <td>$[rint(10*$ssccnt/$usercnt)/10]</td>
      <td>$[rint(10*$sscsum/$usercnt)/10]</td>
      <td>$[rint(10*$sdursum/$usercnt)/10]</td>
    !endif
    !if minmax isitemof $show
      <td>-</td>
      <td>-</td>
      <td>-</td>
      <td>-</td>
    !endif
    !if deviat isitemof $show
      <td>-</td>
      <td>-</td>
    !endif
    </tr></tfoot>
  !endif
  $table_end
  !read tablesort.phtml
!next ss
