#!/usr/bin/perl # # $Id: sbalib.pl # # Source File: sbalib.pl sub create_subjarea_file { my ($clid, $tstid, $mid) = @_; my $sasysfn; my $sacmfn; my $sactfn; my $bOK; $sasysfn = join( $pathsep, $dataroot, "subjarea.std"); $sactfn = join( $pathsep, $questionroot, "$tstid.$clid.sba"); $sacmfn = join( $pathsep, $dataroot, "subjarea.$clid"); $bOK=true; if (&file_exists($sacmfn)==0) { $bOK=&make_file($sacmfn,$sasysfn,0); } if ($bOK) { if (&file_exists($satcfn)==0) { $bOK=&make_file($sactfn,$sacmfn,1); } } return $bOK; } sub add_subjarea_to_master { my ($clid, $tstid, $opts) = @_; my @satrecs; my $satrec; my @samrecs; my $samrec; my $ntrecs; my $nmrecs; my $nadd; my @flds; my @xflds; my $i; my $j; my $k; my $n; my $rid; my $bfound; my @sbamids = split(/\,/, $opts); $nadd=$#sbamids; if (($nadd==-1) && ($opts eq "")) { return 1;} @samrecs=&get_subjarea_masters($clid,"",""); $nmrecs=$#samrecs; if ($nmrecs == -1) { $rid=0; } else { $samrec=$samrecs[$nmrecs]; @flds=split(/&/,$samrec); $rid=int($flds[0]); } @satrecs=&get_subjarea_masters($clid,$tstid,""); $ntrecs=$#satrecs; $n=0; for $i (1 .. $ntrecs) { $satrec=$satrecs[$i]; for $j (0 .. $nadd) { if ($sbamids[$j] ne "") { @flds=split(/&/,$satrec); if ($flds[0] eq $sbamids[$j]) { $bfound=0; for $k (1 .. $nmrecs) { $samrec=$samrecs[$k]; @xflds=split(/&/,$samrec); if ($xflds[1] eq $flds[0]) { $bfound=1; break; } } if ($bfound==0) { $rid++; $samrec=join('&',$rid,$flds[0],"$flds[2]"); push @samrecs, $samrec; $n++; } } } if ($bfound) { break;} } } if ($n) { my $trash = join( $pathsep, $dataroot, "subjarea.$clid"); open (TSTFILE, ">$trash"); foreach $samrec (@samrecs) { print TSTFILE "$samrec"; } close TSTFILE; } return 1; } sub add_subjarea_fm_master { my ($clid, $tstid, $opts) = @_; my @satrecs; my $satrec; my @samrecs; my $samrec; my $ntrecs; my $nmrecs; my $nadd; my @flds; my @xflds; my $i; my $j; my $k; my $n; my $bfound; my @sbamids = split(/\,/, $opts); $nadd=$#sbamids; if (($nadd==-1) && ($opts eq "")) { return 1;} @samrecs=&get_subjarea_masters($clid,"",""); $nmrecs=$#samrecs; @satrecs=&get_subjarea_masters($clid,$tstid,""); $ntrecs=$#satrecs; $n=0; for $i (1 .. $nmrecs) { $samrec=$samrecs[$i]; chop($samrec); for $j (0 .. $nadd) { if ($sbamids[$j] ne "") { @flds=split(/&/,$samrec); if ($flds[0] eq $sbamids[$j]) { $bfound=0; for $k (1 .. $ntrecs) { $satrec=$satrecs[$k]; @xflds=split(/&/,$satrec); if ($xflds[0] eq $flds[1]) { $bfound=1; break; } } if ($bfound==0) { $k=&count_subj_skill_questions($clid,$tstid,1,"$flds[1]"); $satrec=join('&',$flds[1],$flds[0],$flds[2],"$k\n"); push @satrecs, $satrec; $n++; } } } if ($bfound) { break;} } } if ($n) { $satrec = shift @satrecs; @samrecs = sort(@satrecs); unshift @samrecs, $satrec; my $trash = join( $pathsep, $questionroot, "$tstid.$clid.sba"); open (TSTFILE, ">$trash"); foreach $satrec (@samrecs) { print TSTFILE "$satrec"; } close TSTFILE; } return 1; } sub get_subjarea_pctinptbl { my ($clid, $tstid, $opts) = @_; my $i; my $j; my $inpnm; my $rowhtml; my $htmlcode=""; my @sarecs=(); my $sarec=""; my @flds=(); if ($opts) { @sarecs=split(/\n/,$opts); } else { @sarecs=&get_subjarea_masters($clid,$tstid,""); } my $nsarecs=$#sarecs; $j=0; for $i (1 .. $nsarecs) { $rowhtml=""; $sarec=$sarecs[$i]; @flds=split(/&/,$sarec); $flds[3]=&count_subj_skill_questions($clid,$tstid,1,"$flds[0]"); $rowhtml=join('', $rowhtml, "\n"); $inpnm=join('', "sapmtxr","$j", "n"); $rowhtml=join('', $rowhtml, ""); $inpnm=join('', "sapmtxrnm","$j"); $rowhtml=join('', $rowhtml, "\n"); $rowhtml=join('', $rowhtml, "$flds[3]\ \n"); $rowhtml=join('', $rowhtml, "$flds[0]\ \n"); $inpnm=join('', "sapmtxrnd","$j"); $rowhtml=join('', $rowhtml, "\n"); $inpnm=join('', "sapmtxrord","$j"); $rowhtml=join('', $rowhtml, "\n"); $rowhtml=join('', $rowhtml, "\n"); $htmlcode = join('', $htmlcode, $rowhtml); $j++; } return $htmlcode; } sub get_skilllvl_masters { my ($clid, $tstid, $opts) = @_; my $skdata = "id\&lvl\&qcnt;BASIC\&0\&0;INTERMEDIATE\&1\&0;ADVANCED\&2\&0"; my @skrecs = split(/\;/,$skdata); return @skrecs; } sub count_subj_skill_questions { my ($clid, $tstid, $opts, $svalue) = @_; my $i; my $j; my $c; my $sfind; my @flds=(); my @qcnts=(); my @qrs = &get_question_list($tstid,$clid); my $qrec = shift @qrs; my $nq=$#qrs; @flds=split(/&/, $qrec); for $i (0 .. $#flds) { if ($flds[$i] eq "subj") { $j=$i; break; } } for $i (0 .. $nq) { @flds=split(/&/,$qrs[$i]); if ($flds[$j] =~ /\./ ) { $qrs[$i]="\&$flds[$j]\&\n"; } else { $qrs[$i]="\&$flds[$j].0\&\n"; } } if ($opts == 1) { $sfind="\&$svalue\."; } elsif ($opts == 2) { $sfind="\.$svalue\&"; } else { $sfind="\&$svalue\&"; } @qcnts=grep(/$sfind/,@qrs); $c=$#qcnts+1; @qcnts=(); return "$c"; } sub get_skilllevel_pctinptbl { my ($clid, $tstid, $opts) = @_; my $i; my $j; my $inpnm; my $rowhtml; my $htmlcode=""; my @skrecs=(); my $skrec=""; my @flds=(); if ($opts) { @skrecs=split(/\n/,$opts); } else { @skrecs=&get_skilllvl_masters($clid,$tstid,""); } my $nskrecs=$#skrecs; $j=0; for $i (1 .. $nskrecs) { $rowhtml=""; $inpnm=join('', "sapmtxc","$j","n"); $skrec=$skrecs[$i]; @flds=split(/&/,$skrec); $flds[2]=&count_subj_skill_questions($clid,$tstid,2,"$flds[1]"); $rowhtml=join('', $rowhtml, "\n\ "); $rowhtml=join('', $rowhtml, ""); $inpnm=join('', "sapmtxcnm","$j"); $rowhtml=join('', $rowhtml, ""); $rowhtml=join('', $rowhtml, "\n"); $rowhtml=join('', $rowhtml, ""); $rowhtml=join('', $rowhtml, "$flds[2]"); $rowhtml=join('', $rowhtml, "\ "); $rowhtml=join('', $rowhtml, "$flds[0]"); $rowhtml=join('', $rowhtml, "\ \n"); $htmlcode = join('', $htmlcode, $rowhtml); $j++; } return $htmlcode; } sub get_subjskill_cntgrdtbl { my ($clid, $tstid, $opts) = @_; my $i; my $j; my $k; my $htmlcode=""; my @flds=(); # # get subject areas # &upd_subjarea_qcount($clid,$tstid,""); my @sarecs=&get_subjarea_masters($clid,$tstid,""); my $nsarecs=$#sarecs; my $sarec=""; # # get skill levels # my @skrecs=&get_skilllvl_masters($clid,$tstid,""); my $nskrecs=$#skrecs; my $skrec=""; # # get subject areas percentage input table rows html code # my $rowhtml=""; for $i (0 .. $nsarecs) { $rowhtml = join('', $rowhtml, "$sarecs[$i]"); } $SUBJAREA{'subjareapit'}=&get_subjarea_pctinptbl($clid, $tstid, $rowhtml); # # get skill level percentage input table rows html code # $rowhtml=""; for $i (0 .. $nskrecs) { $rowhtml = join('', $rowhtml, "$skrecs[$i]\n"); } $SUBJAREA{'skilllvlpit'}=&get_skilllevel_pctinptbl($clid, $tstid, $rowhtml); # # build subject area - skill level counts grid table html code # $rowhtml=""; $tablestarthtml="\n"; $htmlcode = join('', $htmlcode, $tablestarthtml); $tableYcols=""; for $i (1 .. $nskrecs) { $tableYcols= join('', $tableYcols, ""); } $tableYcols= join('', $tableYcols, "\n"); $htmlcode = join('', $htmlcode, $tableYcols); for $i (1 .. $nsarecs) { @flds = split(/&/, $sarecs[$i]); $i--; $rowhtml = "\n"; $rowhtml = join('', $rowhtml, ""); $inpnm=join('', "cbuser", "$i"); $rowhtml = join('', $rowhtml, "\n"); for $j (1 .. $nskrecs) { $j--; $defltval=&count_subj_skill_questions($clid,$tstid,2,"$flds[0].$j"); $inpnm = join('', "sapmtxr", "$i", "c", "$j"); $rowhtml = join('', $rowhtml, "\n"); $j++; } $rowhtml = join('', $rowhtml, "<\TR>\n"); $htmlcode = join('', $htmlcode, $rowhtml); $i++; } $tableendhtml="\n\n"; $j=0; for $i (1 .. $nskrecs) { $tableendhtml= join('', $tableendhtml, "\n"); $j++; } $tableendhtml=join('', $tableendhtml, "\n"); $tableendhtml=join('', $tableendhtml, "\n"); $tableendhtml=join('', $tableendhtml, "\n"); for $i (1 .. $nskrecs) { $tableendhtml= join('', $tableendhtml, "\n"); } $tableendhtml= join('', $tableendhtml, "\n"); for $i (1 .. $nskrecs) { $tableendhtml=join('', $tableendhtml, "\n"); @flds = split(/&/, $skrecs[$i]); $k=$i+1; $tableendhtml= join('', $tableendhtml, "\n"); $tableendhtml= join('', $tableendhtml, "\n"); for $j ($i .. $nskrecs) { if ($j != $i) { $tableendhtml= join('', $tableendhtml, "\n"); } } $tableendhtml=join('', $tableendhtml, "\n"); } $tableendhtml= join('', $tableendhtml, "\n

(Subject Area)
\#
\ $flds[0]\ "); $rowhtml = join('', $rowhtml, ""); $rowhtml = join('', $rowhtml, ""); $rowhtml = join('', $rowhtml, "$defltval"); $rowhtml = join('', $rowhtml, "
(use)\n"); $tableendhtml= join('', $tableendhtml, ""); $tableendhtml= join('', $tableendhtml, "
(Skill Level)"); $tableendhtml= join('', $tableendhtml, ""); $tableendhtml= join('', $tableendhtml, "
$flds[0]"); $tableendhtml= join('', $tableendhtml, ""); $tableendhtml= join('', $tableendhtml, ""); $tableendhtml= join('', $tableendhtml, ""); $tableendhtml= join('', $tableendhtml, "
\n"); $htmlcode = join('', $htmlcode, $tableendhtml); $htmlcode = join('', $htmlcode, "\n"); $htmlcode = join('', $htmlcode, "\n"); return $htmlcode; } sub get_subjarea_masters { my ($clid, $tstid, $opts) = @_; my @sarecs; if ($tstid) { my $trash = join( $pathsep, $questionroot, "$tstid.$clid.sba"); if ( ! open (TMPFILE, "<$trash") ) { if ($opts) { return ""; } else { return @sarecs; } } @sarecs = ; close TMPFILE; } else { @sarecs = &get_data("subjarea.$clid"); } if ($opts) { my $sarec; my $htmlcode; my $slbls; my @flds; my $nflds; my $nopts; my $i; my $j; my @lbls; my $nrecs; my @optflds; my $optval; my $opttxt; my $stmp; my $ssadata; my @sadata = (); $htmlcode=""; $sarec=$sarecs[0]; chop ($sarec); @lbls = split(/&/, $sarec); $nrecs = $#lbls; $slbls=""; @optflds=split(/\,/,$opts); $nopts=$#optflds; for $i (0 .. $nrecs) { for $j (0 .. $nopts) { if ($lbls[$i] eq $optflds[$j]) { $stmp=$slbls; $slbls=join('&',$stmp,$i); } } } @lbls = split(/&/, $slbls); $nopts=$#lbls; $nrecs = $#sarecs; for $i (1 .. $nrecs) { $sarec=$sarecs[$i]; chop ($sarec); @flds = split(/&/, $sarec); $opttxt=""; for $j (1 .. $nopts) { $slbls=$lbls[$j]; if ($j==1) { $optval=$flds[$slbls]; } else { $opttxt=join(' ', $opttxt, $flds[$slbls]); } } if ($tstid) { $htmlcode=join('', $htmlcode, "