1,
'graphdisp'=>1,
'drawentry'=>1,
'useed'=>1,
'livepreview'=>1);
$prefcookie = json_decode($_COOKIE["embedquserprefs"] ?? '', true);
$_SESSION['userprefs'] = array();
foreach($prefdefaults as $key=>$def) {
if ($prefcookie!==null && isset($prefcookie[$key])) {
$_SESSION['userprefs'][$key] = filter_var($prefcookie[$key], FILTER_SANITIZE_NUMBER_INT);
} else {
$_SESSION['userprefs'][$key] = $def;
}
}
if (isset($_GET['graphdisp'])) { //currently same is used for graphdisp and drawentry
$_SESSION['userprefs']['graphdisp'] = filter_var($_GET['graphdisp'], FILTER_SANITIZE_NUMBER_INT);
$_SESSION['userprefs']['drawentry'] = filter_var($_GET['graphdisp'], FILTER_SANITIZE_NUMBER_INT);
setsecurecookie("embedquserprefs", json_encode(array(
'graphdisp'=>$_SESSION['userprefs']['graphdisp'],
'drawentry'=>$_SESSION['userprefs']['drawentry']
)),0);
}
foreach(array('graphdisp','mathdisp','useed') as $key) {
$_SESSION[$key] = $_SESSION['userprefs'][$key];
}
$showtips = 2;
$useeqnhelper = 4;
$useeditor = 1;
$courseUIver = 1;
$_SESSION['secsalt'] = $CFG['GEN']['embedsecret'] ?? "12345";
$cid = "embedq";
if (isset($CFG['GEN']['JWTsecret'])) {
$JWTsecret = $CFG['GEN']['JWTsecret'];
} else if (getenv('AWS_SECRET_KEY')) {
$JWTsecret = getenv('AWS_SECRET_KEY');
} else {
$JWTsecret = "testing";
}
if((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO']=='https')) {
$urlmode = 'https://';
} else {
$urlmode = 'http://';
}
//settings option:
// 0: never show answer
// 1: show answer button after an attempt
// 2: always show answer button
if (isset($CFG['multiembed-showans'])) {
$showanstype = $CFG['multiembed-showans'];
} else {
$showanstype = 1;
}
function saveAssessData() {
global $qids, $seeds, $rawscores, $attempts, $lastanswers, $sameseed, $theme, $targetid, $JWTsecret;
$JWTsess['qids'] = $qids;
$JWTsess['seeds'] = $seeds;
$JWTsess['rawscores'] = $rawscores;
$JWTsess['attempts'] = $attempts;
$JWTsess['lastanswers'] = $lastanswers;
$JWTsess['sameseed'] = $sameseed;
$JWTsess['theme'] = $theme;
$JWTsess['targetid'] = $targetid;
return JWT::encode($JWTsess, $JWTsecret);
}
$JWTsess = array();
if (isset($_REQUEST['asidverify'])) {
try {
$JWTsess = JWT::decode($_REQUEST['asidverify'], $JWTsecret);
} catch (Exception $e) {
echo "Invalid session or something";
exit;
}
}
if (isset($JWTsess->qids) && (!isset($_GET['id']) || $_GET['id']==implode('-',$JWTsess->qids)) && !isset($_GET['regen'])) {
$qids = $JWTsess->qids;
$seeds = $JWTsess->seeds;
$rawscores = $JWTsess->rawscores;
$attempts = $JWTsess->attempts;
$lastanswers = $JWTsess->lastanswers;
$sameseed = $JWTsess->sameseed;
$theme = $JWTsess->theme;
$targetid = $JWTsess->targetid;
} else {
if (empty($_GET['id'])) {
echo 'Need to supply an id';
exit;
}
$qids = explode("-",$_GET['id']);
if (isset($_GET['sameseed']) && $_GET['sameseed']==1) {
$seeds = array_fill(0,count($qids), rand(5000,9999));
$sameseed = 1;
} else {
$seeds = array();
foreach ($qids as $i=>$v) {
$seeds[$i] = rand(5000,9999);
}
$sameseed = 0;
}
$rawscores = array_fill(0,count($qids), -1);
$attempts = array_fill(0,count($qids), 0);
$lastanswers = array_fill(0,count($qids), '');
if (isset($_GET['theme'])) {
$theme = preg_replace('/\W/','',$_GET['theme']);
}
if (isset($_GET['iframe_resize_id'])) {
$targetid = preg_replace('/[^\w:.-]/','',$_GET['iframe_resize_id']);
} else if (isset($_GET['frame_id'])) {
$targetid = preg_replace('/[^\w:.-]/','',$_GET['frame_id']);
}
$jwtstring = saveAssessData();
}
$qids = array_map('Sanitize::onlyInt',$qids);
$seeds = array_map('Sanitize::onlyInt',$seeds);
require_once "./assessment/displayq2.php";
$GLOBALS['assessver'] = 2;
$showhints = true;
if (isset($_GET['action']) && $_GET['action']=='scoreembed') {
//load filter
$loadgraphfilter = true;
require_once "./filter/filter.php";
//need question ids, attempts, seeds. Put in query string, or??
$qn = Sanitize::onlyInt($_POST['toscore']);
$colors = array();
$GLOBALS['scoremessages'] = '';
$GLOBALS['questionmanualgrade'] = false;
list($unitrawscore,$rawscores[$qn]) = scoreq($qn,$qids[$qn],$seeds[$qn],$_POST["qn$qn"],$attempts[$qn],1);
$attempts[$qn]++;
$jwtstring = saveAssessData();
if (strpos($rawscores[$qn],'~')!==false) {
$colors = explode('~',$rawscores[$qn]);
} else {
$colors = array($rawscores[$qn]);
}
$quesout = '';
ob_start();
displayq($qn,$qids[$qn],$seeds[$qn],($showanstype>0),$showhints,$attempts[$qn],false,false,false,$colors);
$quesout .= ob_get_clean();
$quesout = substr($quesout,0,-7).'
';
echo '';
echo $quesout;
//"save" session
echo '';
$scoremessage = array(
'action' => 'updatescores',
'scores' => $rawscores,
'jwt' => $jwtstring
);
echo '';
exit;
}
$flexwidth = true; //tells header to use non _fw stylesheet
$placeinhead = '';
if ($targetid != '') {
$placeinhead .= '';
if ($_SESSION['mathdisp']==1 || $_SESSION['mathdisp']==3) {
//in case MathJax isn't loaded yet
$placeinhead .= '';
}
}
if ($theme != '') {
$_SESSION['coursetheme'] = $theme.'.css';
}
require_once "./assessment/header.php";
if ($_SESSION['graphdisp'] == 1) {
echo '
'; if (count($qids)>1) { echo _('Try Another Version of These Questions').'
'; } else { echo _('Try Another Version of This Question').''; } //preload qsdata $placeholders = Sanitize::generateQueryPlaceholders($qids); $stm = $DBH->prepare("SELECT id,qtype,control,qcontrol,qtext,answer,hasimg,extref,solution,solutionopts FROM imas_questionset WHERE id IN ($placeholders)"); $stm->execute($qids); $qsdata = array(); while ($row = $stm->fetch(PDO::FETCH_ASSOC)) { $qsdata[$row['id']] = $row; } foreach ($qids as $i=>$qid) { $i = Sanitize::onlyInt($i); echo ''; echo $quesout; echo ''; echo ''; } require_once "./footer.php"; ?>