Skip to content

Commit

Permalink
Merge branch 'hacking' of github.com:xiongchiamiov/IMathAS into hacking
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongchiamiov committed Jul 13, 2010
2 parents 95c4e65 + 28d3cf7 commit f8564d2
Show file tree
Hide file tree
Showing 55 changed files with 2,178 additions and 378 deletions.
2 changes: 1 addition & 1 deletion actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@
$query .= "WHERE id='$userid'";
mysql_query($query) or die("Query failed : " . mysql_error());
if (is_uploaded_file($_FILES['stupic']['tmp_name'])) {
processImage($_FILES['stupic'],$userid,100,100);
processImage($_FILES['stupic'],$userid,200,200);
processImage($_FILES['stupic'],'sm'.$userid,40,40);
} else if (isset($_POST['removepic'])) {
$curdir = rtrim(dirname(__FILE__), '/\\');
Expand Down
6 changes: 3 additions & 3 deletions admin/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
mysql_query($query) or die("Query failed : $query " . mysql_error());
//todo: delete user picture files
//todo: delete user file uploads
require("../includes/filehandler.php");
require_once("../includes/filehandler.php");
deletealluserfiles($_GET['id']);
//todo: delete courses if any
break;
Expand Down Expand Up @@ -254,8 +254,8 @@

$query = "SELECT id FROM imas_assessments WHERE courseid='{$_GET['id']}'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
require_once("../includes/filehandler.php");
while ($line = mysql_fetch_row($result)) {
require("../includes/filehandler.php");
deleteallaidfiles($line[0]);
$query = "DELETE FROM imas_questions WHERE assessmentid='{$line[0]}'";
mysql_query($query) or die("Query failed : " . mysql_error());
Expand Down Expand Up @@ -492,7 +492,7 @@
if ($myrights <100) { echo "You don't have the authority for this action"; break;}
$old = time() - 60*60*24*30*$_POST['months'];
$who = $_POST['who'];
require("../includes/filehandler.php");
require_once("../includes/filehandler.php");
if ($who=="students") {
$query = "SELECT id FROM imas_users WHERE lastaccess<$old AND (rights=0 OR rights=10)";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
Expand Down
45 changes: 36 additions & 9 deletions assessment/displayq2.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function displayq($qnidx,$qidx,$seed,$doshowans,$showhints,$attemptn,$returnqtxt
$seqinactive = false;
}*/

$query = "SELECT qtype,control,qcontrol,qtext,answer,hasimg FROM imas_questionset WHERE id='$qidx'";
$query = "SELECT qtype,control,qcontrol,qtext,answer,hasimg,extref FROM imas_questionset WHERE id='$qidx'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$qdata = mysql_fetch_array($result, MYSQL_ASSOC);

Expand Down Expand Up @@ -139,7 +139,9 @@ function displayq($qnidx,$qidx,$seed,$doshowans,$showhints,$attemptn,$returnqtxt

//create hintbuttons
if (isset($hints) && $showhints) {
$lastkey = end(array_keys($hints));
//$hintkeys = array_keys($hints);
//$lastkey = array_pop($hintkeys);
$lastkey = max(array_keys($hints));
if ($qdata['qtype']=="multipart" && is_array($hints[$lastkey])) { //individual part hints
foreach ($hints as $iidx=>$hintpart) {
$lastkey = end(array_keys($hintpart));
Expand All @@ -149,7 +151,11 @@ function displayq($qnidx,$qidx,$seed,$doshowans,$showhints,$attemptn,$returnqtxt
$usenum = $attemptn;
}
if ($hintpart[$usenum]!='') {
$hintloc[$iidx] = "<p><i>Hint:</i> {$hintpart[$usenum]}</p>\n";
if (strpos($hintpart[$usenum],'button"')!==false) {
$hintloc[$iidx] = "<p>{$hintpart[$usenum]}</p>\n";
} else {
$hintloc[$iidx] = "<p><i>Hint:</i> {$hintpart[$usenum]}</p>\n";
}
}

}
Expand All @@ -161,7 +167,11 @@ function displayq($qnidx,$qidx,$seed,$doshowans,$showhints,$attemptn,$returnqtxt
$usenum = $attemptn;
}
if ($hints[$usenum]!='') {
$hintloc = "<p><i>Hint:</i> {$hints[$usenum]}</p>\n";
if (strpos($hints[$usenum],'button"')!==false) {
$hintloc = "<p>{$hints[$usenum]}</p>\n";
} else {
$hintloc = "<p><i>Hint:</i> {$hints[$usenum]}</p>\n";
}
}

}
Expand Down Expand Up @@ -227,12 +237,27 @@ function displayq($qnidx,$qidx,$seed,$doshowans,$showhints,$attemptn,$returnqtxt
if (isset($helptext) && $showhints) {
echo '<div><p class="tips">'.filter($helptext).'</p></div>';
}
if ($showhints && $qdata['extref']!='') {
$extref = explode('~~',$qdata['extref']);
echo '<div><p class="tips">Get help: ';
for ($i=0;$i<count($extref);$i++) {
$extrefpt = explode('!!',$extref[$i]);
if ($extrefpt[0]=='video') {
$url = "http://" . $_SERVER['HTTP_HOST'] . "$imasroot/assessment/watchvid.php?url=".urlencode($extrefpt[1]);
echo formpopup("Video",$url,660,525,"button",true,"video");
} else if ($extrefpt[0]=='read') {
echo formpopup("Read",$extrefpt[1],730,500,"button",true,"text");
}
}
echo '</p></div>';
}

echo "<div>";
foreach($tips as $iidx=>$tip) {
if ((!isset($hidetips) || (is_array($hidetips) && !isset($hidetips[$iidx])))&& !$seqinactive && $showtips>0) {
echo "<p class=\"tips\" ";
if ($showtips!=1) { echo 'style="display:none;" ';}
echo ">Box ".($iidx+1).": <span id=\"tips$qnidx-$iidx\">$tip</span></p>";
echo ">Box ".($iidx+1).": <span id=\"tips$qnidx-$iidx\">".filter($tip)."</span></p>";
}
if ($doshowans && (!isset($showanswer) || (is_array($showanswer) && !isset($showanswer[$iidx]))) && $shanspt[$iidx]!=='') {
if ($nosabutton) {
Expand Down Expand Up @@ -2547,6 +2572,7 @@ function scorepart($anstype,$qn,$givenans,$options,$multi) {
}
$orarr = explode('U',$_POST["tc$qn"]);
foreach ($orarr as $opt) {
$opt = trim($opt);
$opts = explode(',',substr($opt,1,strlen($opt)-2));
if (strpos($opts[0],'oo')===false && !checkanswerformat($opts[0],$ansformats)) {
return 0;
Expand Down Expand Up @@ -2921,7 +2947,7 @@ function scorepart($anstype,$qn,$givenans,$options,$multi) {
continue;
}
if ($ansline[0]!=$lines[$i][0]) {
if (abs(abs($ansline[1])-1)<.3) {
if (abs(abs($ansline[1])-1)<.4) {
//check intercept
if (abs($ansline[2]-$lines[$i][3])>$defpttol*$reltolerance) {
continue;
Expand Down Expand Up @@ -3058,12 +3084,13 @@ function scorepart($anstype,$qn,$givenans,$options,$multi) {
$scores[$key] = 0;
for ($i=0; $i<count($ineqlines); $i++) {
if ($ansline[2]!=$ineqlines[$i][2]) { continue;}
if ($ansline[1]!=$ineqlines[$i][1]) { continue;}
//check slope
if (abs($ansline[3]-$ineqlines[$i][3])/(abs($ansline[3])+.000001)>$deftol*$reltolerance) {
continue;
}
if ($ansline[0]!=$ineqlines[$i][0]) {
if (abs(abs($ansline[3])-1)<.3) {
if (abs(abs($ansline[3])-1)<.4) {
//check intercept
if (abs($ansline[4]-$ineqlines[$i][5])>$defpttol*$reltolerance) {
continue;
Expand Down Expand Up @@ -3624,13 +3651,13 @@ function formathint($eword,$ansformats,$calledfrom, $islist=false,$doshort=false
$tip .= "Enter $eword as a reduced fraction (like 5/3, not 10/6) or as a whole number (like 4 or -2)";
$shorttip = $islist?'Enter a list of reduced fractions or whole numbers':'Enter a reduced fraction or whole number';
} else if (in_array('mixednumber',$ansformats)) {
$tip .= "Enter $eword as a reduced mixed number or as a whole number. Example: 2 1/2 = `2 1/2`, or 2_1/2 = `2 1/2`";
$tip .= "Enter $eword as a reduced mixed number or as a whole number. Example: 2 1/2 = 2 &frac12;";
$shorttip = $islist?'Enter a list of mixed numbers or whole numbers':'Enter a mixed number or whole number';
} else if (in_array('fracordec',$ansformats)) {
$tip .= "Enter $eword as a fraction (like 3/5 or 10/4), a whole number (like 4 or -2), or exact decimal (like 0.5 or 1.25)";
$shorttip = $islist?'Enter a list of fractions or exact decimals':'Enter a fraction or exact decimal';
} else if (in_array('scinot',$ansformats)) {
$tip .= "Enter $eword as in scientific notation. Example: 3*10^2 = `3*10^2`";
$tip .= "Enter $eword as in scientific notation. Example: 3*10^2 = 3 &middot; 10<sup>2</sup>";
$shorttip = $islist?'Enter a list of numbers using scientific notation':'Enter a number using scientific notation';
} else {
$tip .= "Enter $eword as a number (like 5, -3, 2.2) or as a calculation (like 5/3, 2^3, 5+4)";
Expand Down
12 changes: 6 additions & 6 deletions assessment/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function init() {
window.onload = init;
var imasroot = '<?php echo $imasroot; ?>';
</script>
<link rel="stylesheet" href="<?php echo $imasroot . "/assessment/mathtest.css?ver=020710";?>" type="text/css"/>
<link rel="stylesheet" href="<?php echo $imasroot . "/assessment/mathtest.css?ver=060810";?>" type="text/css"/>
<?php
echo "<script type=\"text/javascript\" src=\"$imasroot/javascript/general.js?ver=020710\"></script>\n";
if (isset($sessiondata['coursetheme'])) {
Expand All @@ -38,18 +38,18 @@ function init() {
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$imasroot/assessment/print.css\" media=\"print\"/>\n";
}
if ($sessiondata['mathdisp']==1) {
echo "<script type=\"text/javascript\" src=\"$imasroot/javascript/ASCIIMathML_min.js\"></script>\n";
echo "<script type=\"text/javascript\" src=\"$imasroot/javascript/ASCIIMathML_min.js?v=052510\"></script>\n";
} else if ($sessiondata['mathdisp']==2) {
echo '<script type="text/javascript">var AMTcgiloc = "'.$mathimgurl.'";</script>';
echo "<script src=\"$imasroot/javascript/ASCIIMathTeXImg_min.js\" type=\"text/javascript\"></script>\n";
echo "<script src=\"$imasroot/javascript/ASCIIMathTeXImg_min.js?v=050110\" type=\"text/javascript\"></script>\n";
} else if ($sessiondata['mathdisp']==0) {
echo '<script type="text/javascript">var noMathRender = true;</script>';
}

if ($sessiondata['graphdisp']==1) {
echo "<script src=\"$imasroot/javascript/ASCIIsvg_min.js?v=020310\" type=\"text/javascript\"></script>\n";
echo "<script src=\"$imasroot/javascript/ASCIIsvg_min.js?v=042810\" type=\"text/javascript\"></script>\n";
} else {
echo "<script src=\"$imasroot/javascript/mathjs.js\" type=\"text/javascript\"></script>\n";
echo "<script src=\"$imasroot/javascript/mathjs.js?v=042810\" type=\"text/javascript\"></script>\n";
}
?>
<!--[if lte IE 6]>
Expand All @@ -63,7 +63,7 @@ function init() {
}
</style>
<![endif]-->
<script src="<?php echo $imasroot . "/javascript/AMhelpers_min.js?v=040810";?>" type="text/javascript"></script>
<script src="<?php echo $imasroot . "/javascript/AMhelpers_min.js?v=042410";?>" type="text/javascript"></script>
<script src="<?php echo $imasroot . "/javascript/confirmsubmit.js";?>" type="text/javascript"></script>
<!--[if IE]><script type="text/javascript" src="<?php echo $imasroot;?>/javascript/excanvas_min.js"></script><![endif]-->
<script type="text/javascript" src="<?php echo $imasroot;?>/javascript/drawing_min.js?v=030110"></script>
Expand Down
36 changes: 31 additions & 5 deletions assessment/macros.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


array_push($allowedmacros,"exp","sec","csc","cot","sech","csch","coth","rand","rrand","rands","rrands","randfrom","randsfrom","jointrandfrom","diffrandsfrom","nonzerorand","nonzerorrand","nonzerorands","nonzerorrands","diffrands","diffrrands","nonzerodiffrands","nonzerodiffrrands","singleshuffle","jointshuffle","makepretty","makeprettydisp","showplot","addlabel","showarrays","horizshowarrays","showasciisvg","listtoarray","arraytolist","calclisttoarray","sortarray","consecutive","gcd","lcm","calconarray","mergearrays","sumarray","dispreducedfraction","diffarrays","intersectarrays","joinarray","unionarrays","count","polymakepretty","polymakeprettydisp","makexpretty","makexprettydisp","calconarrayif","in_array","prettyint","prettyreal","arraystodots","subarray","showdataarray","arraystodoteqns","array_flip","arrayfindindex","fillarray","array_reverse","root");
array_push($allowedmacros,"numtowords","randname","randmalename","randfemalename","randnames","randmalenames","randfemalenames","randcity","randcities","prettytime","definefunc","evalfunc","safepow","arrayfindindices","stringtoarray","strtoupper","strtolower","ucfirst","makereducedfraction","stringappend","stringprepend","textonimage","addplotborder","addlabelabs","makescinot","today","numtoroman","sprintf","arrayhasduplicates","addfractionaxislabels","decimaltofraction","ifthen","multicalconarray","htmlentities","formhoverover","formpopup","connectthedots","jointsort","stringpos","stringlen","stringclean","substr","makexxpretty","makexxprettydisp");
array_push($allowedmacros,"numtowords","randname","randmalename","randfemalename","randnames","randmalenames","randfemalenames","randcity","randcities","prettytime","definefunc","evalfunc","safepow","arrayfindindices","stringtoarray","strtoupper","strtolower","ucfirst","makereducedfraction","stringappend","stringprepend","textonimage","addplotborder","addlabelabs","makescinot","today","numtoroman","sprintf","arrayhasduplicates","addfractionaxislabels","decimaltofraction","ifthen","multicalconarray","htmlentities","formhoverover","formpopup","connectthedots","jointsort","stringpos","stringlen","stringclean","substr","makexxpretty","makexxprettydisp","forminlinebutton");
function mergearrays($a,$b) {
if (!is_array($a)) {
$a = array($a);
Expand Down Expand Up @@ -719,13 +719,13 @@ function polyclean($exp) {
$outstr .= $parr[0].' '.$parr[1];
}
} else if ($parr[2]=='1') {
if ($parr[0]==1) {
if ($parr[0]=='1') {
$outstr .= $parr[1];
} else {
$outstr .= $parr[0] . ' ' . $parr[1]; //n x^1
}
} else {
if ($parr[0]==1) {
if ($parr[0]=='1') {
$outstr .= $parr[1] . '^' . $parr[2]; // 1 x^m
} else {
$outstr .= $parr[0] . ' ' . $parr[1] . '^' . $parr[2]; // n x^m
Expand Down Expand Up @@ -1932,7 +1932,7 @@ function formpopup($label,$content,$width=600,$height=400,$type='link',$scroll='
$height = "'fit'";
}
if (strpos($label,'<img')!==false) {
return str_replace('<img', '<img class="clickable" onClick="popupwindow(\''.$id.'\',\''.str_replace('\'','\\\'',htmlentities($content)).'\','.$width.','.$height.','.$scroll.')"',$label);
return str_replace('<img', '<img class="clickable" onClick="popupwindow(\''.$id.'\',\''.str_replace('\'','\\\'',htmlentities($content)).'\','.$width.','.$height.$scroll.')"',$label);
} else {
if ($type=='link') {
return '<span class="link" onClick="popupwindow(\''.$id.'\',\''.str_replace('\'','\\\'',htmlentities($content)).'\','.$width.','.$height.$scroll.')">'.$label.'</span>';
Expand All @@ -1942,6 +1942,32 @@ function formpopup($label,$content,$width=600,$height=400,$type='link',$scroll='
}
}

function forminlinebutton($label,$content,$style='button',$outstyle='block') {
if (isset($GLOBALS['inlinebuttoncnt'])) {
$r = $GLOBALS['inlinebuttoncnt'];
$GLOBALS['inlinebuttoncnt']++;
//$out = '';
} else {
$r = 1;
$GLOBALS['inlinebuttoncnt'] = 2;
//$out = '<script type="text/javascript">function toggleinlinebtn(n){var el=document.getElementById(n);el.style.display=="none"?el.style.display="":el.style.display="none";}</script>';
}
$label = str_replace('"','',$label);
if ($style=='classic') {
$out = '<input type="button" value="'.$label.'" onClick="toggleinlinebtn(\'inlinebtn'.$r.'\');" />';
} else if ($style=='link') {
$out = '<span class="link" onClick="toggleinlinebtn(\'inlinebtn'.$r.'\');">'.$label.'</span>';
} else {
$out = '<span class="spanbutton" onClick="toggleinlinebtn(\'inlinebtn'.$r.'\');">'.$label.'</span>';
}
if ($outstyle=='inline') {
$out .= ' <span id="inlinebtn'.$r.'" style="display:none;">'.$content.'</span>';
} else {
$out .= '<div id="inlinebtn'.$r.'" style="display:none;">'.$content.'</div>';
}
return $out;
}

function intervaltoineq($str,$var) {
if ($str=='DNE') {
return 'DNE';
Expand Down Expand Up @@ -2036,7 +2062,7 @@ function cleanbytoken($str,$funcs = array()) {
} else if ($tokens[$i+1][0]=='*') {
$i++; //skip over *
$dontuse = true;
} else if ($tokens[$i+1][0]!= '+' && $tokens[$i+1][0]!= '-') {
} else if ($tokens[$i+1][0]!= '+' && $tokens[$i+1][0]!= '-' && $tokens[$i+1][0]!= '/') {
// 1x, 1(), 1sin
if ($lastout<2 || ($out[$lastout-1] != '^' || $out[$lastout] != '-')) { //exclude ^-1 case
$dontuse = true;
Expand Down
4 changes: 2 additions & 2 deletions assessment/printtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ function getpointspossible($qn,$defpts,$defatt) {
$result = mysql_query($query) or die("Query failed : $query: " . mysql_error());
echo '<div>ID:'.$qsetid.', '.mysql_result($result,0,0).'</div>';
} else {
list($points,$attempts) = getpointspossible($questions[$i],$testsettings['defpoints'],$testsettings['defattempts']);
echo "<div>#".($i+1)." Points possible: $points. Total attempts: $attempts</div>";
list($points,$qattempts) = getpointspossible($questions[$i],$testsettings['defpoints'],$testsettings['defattempts']);
echo "<div>#".($i+1)." Points possible: $points. Total attempts: $qattempts</div>";
}
displayq($i,$qsetid,$seeds[$i],$showa,($testsettings['showhints']==1),$attempts[$i]);
echo "<hr />";
Expand Down
13 changes: 11 additions & 2 deletions assessment/showtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@
//if a group assessment and already in a group, we'll create asids for all the group members now
$query = "SELECT userid FROM imas_stugroupmembers WHERE stugroupid=$stugroupid AND userid<>$userid";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$query = "INSERT INTO imas_assessment_sessions (userid,assessmentid,questions,seeds,scores,attempts,lastanswers,starttime,bestscores,bestattempts,bestseeds,bestlastanswers,reviewscores,reviewattempts,reviewseeds,reviewlastanswers,agroupid) ";
$query = "INSERT INTO imas_assessment_sessions (userid,assessmentid,questions,seeds,scores,attempts,lastanswers,starttime,bestscores,bestattempts,bestseeds,bestlastanswers,reviewscores,reviewattempts,reviewseeds,reviewlastanswers,agroupid) VALUES ";
$cnt = 0;
if (mysql_num_rows($result)>0) {
while ($row = mysql_fetch_row($result)) {
if ($cnt>0) {$query .= ',';}
$query .= "VALUES ('{$row[0]}','{$_GET['id']}','$qlist','$seedlist','$scorelist','$attemptslist','$lalist',$starttime,'$bestscorelist','$bestattemptslist','$bestseedslist','$bestlalist','$scorelist','$attemptslist','$reviewseedlist','$lalist',$stugroupid);";
$query .= "('{$row[0]}','{$_GET['id']}','$qlist','$seedlist','$scorelist','$attemptslist','$lalist',$starttime,'$bestscorelist','$bestattemptslist','$bestseedslist','$bestlalist','$scorelist','$attemptslist','$reviewseedlist','$lalist',$stugroupid)";
$cnt++;
}
mysql_query($query) or die("Query failed : " . mysql_error());
Expand Down Expand Up @@ -633,6 +633,7 @@
$rowgrptest = mysql_fetch_row($result);
$rowgrptest = addslashes_deep($rowgrptest);
$insrow = "'".implode("','",$rowgrptest)."'";
$loginfo = "$userfullname creating group. ";
for ($i=1;$i<$testsettings['groupmax'];$i++) {
if (isset($_POST['user'.$i]) && $_POST['user'.$i]!=0) {
$query = "SELECT password,LastName,FirstName FROM imas_users WHERE id='{$_POST['user'.$i]}'";
Expand All @@ -654,6 +655,7 @@
$row = mysql_fetch_row($result);
if ($row[1]>0) {
echo "<p>$thisusername already has a group. No change made</p>";
$loginfo .= "$thisusername already in group. ";
} else {
$query = "INSERT INTO imas_stugroupmembers (userid,stugroupid) VALUES ('$userid','{$sessiondata['groupid']}')";
mysql_query($query) or die("Query failed : $query:" . mysql_error());
Expand All @@ -673,6 +675,7 @@
//$query = "UPDATE imas_assessment_sessions SET agroupid='$agroupid' WHERE id='{$row[0]}'";
mysql_query($query) or die("Query failed : $query:" . mysql_error());
echo "<p>$thisusername added to group, overwriting existing attempt.</p>";
$loginfo .= "$thisusername switched to group. ";
}
} else {
$query = "INSERT INTO imas_stugroupmembers (userid,stugroupid) VALUES ('{$_POST['user'.$i]}','{$sessiondata['groupid']}')";
Expand All @@ -682,9 +685,15 @@
$query .= "VALUES ('{$_POST['user'.$i]}',$insrow)";
mysql_query($query) or die("Query failed : $query:" . mysql_error());
echo "<p>$thisusername added to group.</p>";
$loginfo .= "$thisusername added to group. ";
}
}
}
$now = time();
if (isset($GLOBALS['CFG']['log'])) {
$query = "INSERT INTO imas_log (time,log) VALUES ($now,'".addslashes($loginfo)."')";
mysql_query($query) or die("Query failed : " . mysql_error());
}
} else {
echo '<div id="headershowtest" class="pagetitle"><h2>Select group members</h2></div>';
if ($sessiondata['groupid']==0) {
Expand Down
Loading

0 comments on commit f8564d2

Please sign in to comment.