示例#1
0
function printscore($sc, $qsetid, $seed)
{
    $poss = 1;
    if (strpos($sc, '~') === false) {
        $sc = str_replace('-1', 'N/A', $sc);
        $out = "{$sc} out of {$poss}";
        $pts = $sc;
        if (!is_numeric($pts)) {
            $pts = 0;
        }
    } else {
        $query = "SELECT control FROM imas_questionset WHERE id='{$qsetid}'";
        $result = mysql_query($query) or die("Query failed: {$query}: " . mysql_error());
        $control = mysql_result($result, 0, 0);
        $ptposs = getansweights($control, $seed);
        $weightsum = array_sum($ptposs);
        if ($weightsum > 1.1) {
            $poss = $weightsum;
        } else {
            $poss = count($ptposs);
        }
        for ($i = 0; $i < count($ptposs) - 1; $i++) {
            $ptposs[$i] = round($ptposs[$i] / $weightsum * $poss, 2);
        }
        //adjust for rounding
        $diff = $poss - array_sum($ptposs);
        $ptposs[count($ptposs) - 1] += $diff;
        $pts = getpts($sc, $poss);
        $sc = str_replace('-1', 'N/A', $sc);
        //$sc = str_replace('~',', ',$sc);
        $scarr = explode('~', $sc);
        foreach ($scarr as $k => $v) {
            $v = round($v * $poss, 2);
            if ($ptposs[$k] == 0) {
                $pm = 'gchk';
            } else {
                if (!is_numeric($v) || $v == 0) {
                    $pm = 'redx';
                } else {
                    if (abs($v - $ptposs[$k]) < 0.011) {
                        $pm = 'gchk';
                    } else {
                        $pm = 'ychk';
                    }
                }
            }
            $bar = "<img src=\"{$imasroot}/img/{$pm}.gif\" />";
            $scarr[$k] = "{$bar} {$v}/{$ptposs[$k]}";
        }
        $sc = implode(', ', $scarr);
        //$ptposs = implode(', ',$ptposs);
        $out = "{$pts} out of {$poss} (parts: {$sc})";
    }
    $bar = '<span class="scorebarholder">';
    if ($poss == 0) {
        $w = 30;
    } else {
        $w = round(30 * $pts / $poss);
    }
    if ($w == 0) {
        $w = 1;
    }
    if ($w < 15) {
        $color = "#f" . dechex(floor(16 * $w / 15)) . "0";
    } else {
        if ($w == 15) {
            $color = '#ff0';
        } else {
            $color = "#" . dechex(floor(16 * (2 - $w / 15))) . "f0";
        }
    }
    $bar .= '<span class="scorebarinner" style="background-color:' . $color . ';width:' . $w . 'px;">&nbsp;</span></span> ';
    return $bar . $out;
}
示例#2
0
function getquestioninfo($qns, $testsettings)
{
    if (!is_array($qns)) {
        $qns = array($qns);
    }
    $qnlist = "'" . implode("','", $qns) . "'";
    if ($testsettings['defoutcome'] != 0) {
        //we'll need to run two simpler queries rather than a single join query
        $outcomenames = array();
        $query = "SELECT id,name FROM imas_outcomes WHERE courseid='{$testsettings['courseid']}'";
        $result = mysql_query($query) or die("Query failed: {$query}: " . mysql_error());
        while ($row = mysql_fetch_row($result)) {
            $outcomenames[$row[0]] = $row[1];
        }
        $query = "SELECT iq.id,iq.questionsetid,iq.category,iq.points,iq.penalty,iq.attempts,iq.regen,iq.showans,iq.withdrawn,iq.showhints,iqs.qtype,iqs.control ";
        $query .= "FROM imas_questions AS iq JOIN imas_questionset AS iqs ON iq.questionsetid=iqs.id WHERE iq.id IN ({$qnlist})";
    } else {
        $query = "SELECT iq.id,iq.questionsetid,iq.category,iq.points,iq.penalty,iq.attempts,iq.regen,iq.showans,iq.withdrawn,iq.showhints,io.name,iqs.qtype,iqs.control ";
        $query .= "FROM (imas_questions AS iq JOIN imas_questionset AS iqs ON iq.questionsetid=iqs.id) LEFT JOIN imas_outcomes as io ";
        $query .= "ON iq.category=io.id WHERE iq.id IN ({$qnlist})";
    }
    $result = mysql_query($query) or die("Query failed: {$query}: " . mysql_error());
    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
        if (is_numeric($line['category'])) {
            if ($testsettings['defoutcome'] != 0) {
                if ($line['category'] == 0) {
                    $line['category'] = $outcomenames[$testsettings['defoutcome']];
                } else {
                    $line['category'] = $outcomenames[$line['category']];
                }
            } else {
                if ($line['name'] != null) {
                    $line['category'] = $line['name'];
                }
            }
        }
        unset($line['name']);
        if ($line['points'] == 9999) {
            $line['points'] = $testsettings['defpoints'];
        }
        if ($line['attempts'] == 9999) {
            $line['attempts'] = $testsettings['defattempts'];
        }
        if ($line['qtype'] == 'multipart') {
            //if (preg_match('/answeights\s*=\s*("|\')([\d\.\,\s]+)/',$line['control'],$match)) {
            /*$foundweights = false;
            		if (($p = strpos($line['control'],'answeights'))!==false || strpos($line['control'],'anstypes')===false) {
            			$p = strpos($line['control'],"\n",$p);
            			$weights = getansweights($line['id'],$line['control']);
            			if (is_array($weights)) {
            				$line['answeights'] = $weights;
            				$foundweights = true;
            			}
            			
            		} 
            		if (!$foundweights) {
            			if (preg_match('/anstypes\s*=(.*)/',$line['control'],$match)) {
            				$n = substr_count($match[1],',')+1;
            				if ($n>1) {
            					$line['answeights'] = array_fill(0,$n-1,round(1/$n,5));
            					$line['answeights'][] = 1-array_sum($line['answeights']);
            				} else {
            					$line['answeights'] = array(1);
            				}
            			} else {
            				$line['answeights'] = getansweights($line['id'],$line['control']);
            			}
            		}
            		*/
            $line['answeights'] = getansweights($line['id'], $line['control']);
        }
        $line['allowregen'] = 1 - floor($line['regen'] / 3);
        //0 if no, 1 if use default
        $line['regen'] = $line['regen'] % 3;
        unset($line['qtype']);
        unset($line['control']);
        $out[$line['id']] = $line;
    }
    return $out;
}
示例#3
0
         //if (preg_match('/answeights\s*=\s*("|\')([\d\.\,\s]+)/',$line['control'],$match)) {
         /*if (($p = strpos($r[4],'answeights'))!==false) {
         			$p = strpos($r[4],"\n",$p);
         			$answeights[$r[0]] = getansweights($r[0],$r[4]);
         		} else {
         			preg_match('/anstypes(.*)/',$r[4],$match);
         			$n = substr_count($match[1],',')+1;
         			if ($n>1) {
         				$answeights[$r[0]] = array_fill(0,$n-1,round(1/$n,3));
         				$answeights[$r[0]][] = 1-array_sum($answeights[$r[0]]);
         			} else {
         				$answeights[$r[0]] = array(1);
         			}
         		}
         		*/
         $answeights[$r[0]] = getansweights($r[0], $r[4]);
         for ($i = 0; $i < count($answeights[$r[0]]) - 1; $i++) {
             $answeights[$r[0]][$i] = round($answeights[$r[0]][$i] * $pts[$r[0]], 2);
         }
         //adjust for rounding
         $diff = $pts[$r[0]] - array_sum($answeights[$r[0]]);
         $answeights[$r[0]][count($answeights[$r[0]]) - 1] += $diff;
     }
     if ($line['showhints'] == 1 && $r[6] != 1 || $r[6] == 2) {
         if ($r[7] != '') {
             $extref[$r[0]] = explode('~~', $r[7]);
         }
     }
     $owners[$r[0]] = $r[8];
 }
 echo '<script type="text/javascript">
示例#4
0
 if ($qtype == 'multipart') {
     /*if (($p = strpos($qcontrol,'answeights'))!==false) {
     			$p = strpos($qcontrol,"\n",$p);
     			$answeights = getansweights($loc,substr($qcontrol,0,$p));
     		} else {
     			preg_match('/anstypes(.*)/',$qcontrol,$match);
     			$n = substr_count($match[1],',')+1;
     			if ($n>1) {
     				$answeights = array_fill(0,$n-1,round(1/$n,3));
     				$answeights[] = 1-array_sum($answeights);
     			} else {
     				$answeights = array(1);
     			}
     		}
     		*/
     $answeights = getansweights($loc, $qcontrol);
     for ($i = 0; $i < count($answeights) - 1; $i++) {
         $answeights[$i] = round($answeights[$i] * $points, 2);
     }
     //adjust for rounding
     $diff = $points - array_sum($answeights);
     $answeights[count($answeights) - 1] += $diff;
 }
 if ($qtype == 'multipart') {
     $GLOBALS['questionscoreref'] = array("ud-{$line['id']}-{$loc}", $answeights);
 } else {
     $GLOBALS['questionscoreref'] = array("ud-{$line['id']}-{$loc}", $points);
 }
 $qtypes = displayq($cnt, $qsetid, $seeds[$loc], true, false, $attempts[$loc]);
 echo '</div>';
 echo "<div class=review>";