forked from drlippman/IMathAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiembedq.php
More file actions
225 lines (201 loc) · 7.29 KB
/
multiembedq.php
File metadata and controls
225 lines (201 loc) · 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<?php
//Embed for Econ questions
/*
- Page for econ stuff:
- one or multiple questions displayed
- use Embed approach (so submit one question/part at a time)
- One regen button for the whole page (will regen whole question group)
- show results on submit, allow reattempts
- No Show Answers
- On initial page load:
- choose seed. fill $seeds array for group
- Display "try new version of this/these problem(s)" button
- Triggers each embed to regen, or reload page
- Each question is displayed ala embedded showtest
- Each question gets submit button, does background submit
- On submit, show scored, but no show answer
*/
require("./config.php");
require("i18n/i18n.php");
require("includes/JWT.php");
header('P3P: CP="ALL CUR ADM OUR"');
$sessiondata = array();
if (isset($_GET['graphdisp'])) {
$sessiondata['graphdisp'] = intval($_GET['graphdisp']);
setcookie("multiembedq-graphdisp", $sessiondata['graphdisp']);
} else if (isset($_COOKIE['multiembedq-graphdisp'])) {
$sessiondata['graphdisp'] = intval($_COOKIE['multiembedq-graphdisp']);
} else {
$sessiondata['graphdisp'] = 1;
}
$sessiondata['mathdisp'] = 3;
$showtips = 2;
$useeqnhelper = 4;
$useeditor = 1;
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://';
}
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 {
$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();
}
foreach ($qids as $i=>$v) {
$qids[$i] = intval($v);
}
foreach ($seeds as $i=>$v) {
$seeds[$i] = intval($v);
}
require("./assessment/displayq2.php");
$GLOBALS['assessver'] = 1;
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 = $_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],false,$showhints,$attempts[$qn],false,false,false,$colors);
$quesout .= ob_get_clean();
$quesout = substr($quesout,0,-7).'<br/><input type="button" class="btn" value="'. _('Submit'). '" onclick="assessbackgsubmit('.$qn.',\'submitnotice'.$qn.'\')" /><span id="submitnotice'.$qn.'"></span></div>';
echo '<input type="hidden" id="verattempts'.$qn.'" value="'.$attempts[$qn].'"/>';
echo $quesout;
//"save" session
echo '<script type="text/javscript">$("#asidverify").val("'.$jwtstring.'");</script>';
exit;
}
$flexwidth = true; //tells header to use non _fw stylesheet
$placeinhead = '<style type="text/css">html,body {margin:0px;} div.question {width: auto;} div.review {width: auto; margin-top: 5px;} body {height:auto;}</style>';
if ($theme != '') {
$sessiondata['coursetheme'] = $theme.'.css';
}
require("./assessment/header.php");
if ($sessiondata['graphdisp'] == 1) {
echo '<div style="position:absolute;width:1px;height:1px;left:0px:top:-1px;overflow:hidden;"><a href="multiembedq.php?'.$_SERVER['QUERY_STRING'].'&graphdisp=0">Enable text based alternatives for graph display and drawing entry</a></div>';
}
echo '<script type="text/javascript">var assesspostbackurl="' .$urlmode. $_SERVER['HTTP_HOST'] . $imasroot . '/multiembedq.php?embedpostback=true&action=scoreembed";</script>';
echo '<input type="hidden" id="asidverify" value="'.$jwtstring.'"/>';
echo '<input type="hidden" id="disptime" value="'.time().'"/>';
echo '<input type="hidden" id="isreview" value="0"/>';
echo '<p><a href="multiembedq.php?id='.$_GET['id'].'&regen=1&sameseed='.$sameseed.'&theme='.$theme.'&iframe_resize_id='.$targetid.'">Try Another Version of ';
if (count($qids)>1) {
echo 'These Questions</a></p>';
} else {
echo 'This Question</a></p>';
}
$showhints = true;
foreach ($qids as $i=>$qid) {
echo '<div id="embedqwrapper'.$i.'" class="embedqwrapper">';
$quesout = '';
ob_start();
displayq($i,$qid,$seeds[$i],false,$showhints,$attempts[$i]);
$quesout .= ob_get_clean();
$quesout = substr($quesout,0,-7).'<br/><input type="button" class="btn" value="'. _('Submit'). '" onclick="assessbackgsubmit('.$i.',\'submitnotice'.$i.'\')" /><span id="submitnotice'.$i.'"></span></div>';
echo $quesout;
echo '<input type="hidden" id="verattempts'.$i.'" value="'.$attempts[$i].'"/>';
echo '</div>';
}
if ($targetid != '') {
echo '<script type="text/javascript">
function sendresizemsg() {
if(self != top){
var default_height = Math.max(
document.body.scrollHeight, document.body.offsetHeight,
document.documentElement.clientHeight, document.documentElement.scrollHeight,
document.documentElement.offsetHeight);
window.parent.postMessage( JSON.stringify({
subject: "lti.frameResize",
height: default_height,
iframe_resize_id: "'.$targetid.'",
element_id: "'.$targetid.'",
frame_id: "'.$targetid.'"
}), "*");
}
}
if (MathJax) {
MathJax.Hub.Queue(function () {
sendresizemsg();
});
} else {
$(function() {
sendresizemsg();
});
}
$(function() {
$(window).on("ImathasEmbedReload", sendresizemsg);
});
</script>';
}
require("./footer.php");
?>