forked from whynotyet/QualTurk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
296 lines (279 loc) · 13.7 KB
/
index.php
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?
session_start();
include 'functions.php';
$in_session=0;
$logout=0;
$incorrect=0;
$added=0;
$inactive = 600; // set timeout period in seconds
if(isset($_SESSION['timeout']) ) {
$session_life = time() - $_SESSION['timeout'];
if($session_life > $inactive){
session_destroy();
header("Location: ?logout=2");
}
}
$_SESSION['timeout'] = time();
if(isset($_GET['logout']) and $_GET['logout']){
session_unset();
session_destroy();
$in_session=0;
$logout=1;
if($_GET['logout']==2){
$logout=2;
}
if($_GET['logout']==3){//password reset
$logout=3;
}
if($_GET['logout']==4){//new account
$logout=4;
}
}
if(isset($_POST['login'])){
$login_check = check_login($_POST['username'],$_POST['pwd']);
if(!empty($_POST['username']) and !empty($_POST['pwd']) and is_numeric($login_check)){
$_SESSION['username']=$_POST['username'];
$_SESSION['user_id']=$login_check;
$in_session=1;
}else{
$in_session=0;
$incorrect=1;
}
}
if(isset($_SESSION['username']) and !empty($_SESSION['username'])){
$in_session=1;
}
if(isset($_POST['add']) and $_POST['add']=="Add Survey"){
if(!empty($_POST['survey_name']) and !empty($_POST['survey_id']) and !empty($_POST['survey_link']) and strlen($_POST['min_time'])!=0){
if(strstr($_POST['survey_link'],$_POST['survey_id'])){
if(is_numeric($_POST['min_time'])){
connectDB();
$check_q=sprintf("SELECT survey_id FROM surveys WHERE survey_id='%s'", mysql_real_escape_string($_POST['survey_id']));
$check=mysql_query($check_q);
if(mysql_num_rows($check)==0){
if(mysql_real_escape_string($_POST['debrief'])==" Debrief Text (optional, displayed with completion code)"){
$_POST['debrief']='';
}
$query = sprintf("INSERT INTO surveys(survey_name,survey_id,survey_link,min_time,debrief,created_by) VALUES('%s','%s','%s','%s','%s',%s)",
mysql_real_escape_string($_POST['survey_name']),
mysql_real_escape_string($_POST['survey_id']),
mysql_real_escape_string($_POST['survey_link']),
mysql_real_escape_string($_POST['min_time']),
mysql_real_escape_string($_POST['debrief']),
$_SESSION['user_id']);
mysql_query($query);
$added=1;
}else{
$added=4;
}
}else{
$added=5;
}
}else{
$added=2;
}
}else{
$added=3;
}
}
if(isset($_GET['del']) and !empty($_GET['del'])){
connectDB();
$delq=sprintf("DELETE FROM surveys WHERE md5(concat(survey_id,'bla919'))='%s'",
mysql_real_escape_string($_GET['del']));
$del=mysql_query($delq);
$deleted=1;
if(mysql_affected_rows()>0){
$deleted=2;
}
}
?>
<html>
<head>
<title>QualTurk</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="QualTurk helps reduce low-quality survey data by filtering participants based on pre- and post-screening questions. The system is designed to support Amazon's Mechanical Turk in conjunction with Qualtrics."/>
<meta name="keywords" content="Mechanical Turk, Qualtrics, Survey Tricks, Survey Tipps, survey research, Mturk, quality survey data, get quality suvey data, mturk identify bad workers"/>
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" href="frontend.css" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$("input").not(".subm").blur(function(){
if($(this).val()==""){
$(this).val($(this).prev("label").text());
}
});
$("input").not(".subm").click(function(){
if($(this).val()==$(this).prev("label").text()){
$(this).val("");
}
});
$('a.open_link').click(function(){
var qid=$(this).attr('id');
var linkWindow = window.open('','Link Window','width=600,height=300');
var html = 'http://www.qualturk.com/survey.php?l=c&surveyid='+qid+'&partid=${e://Field/workerid}&long=${q://QIDxxx/ChoiceGroup/SelectedChoices}&comm=${q://QIDyyy/ChoiceTextEntryValue}';
linkWindow.document.open();
linkWindow.document.write(html);
linkWindow.document.close();
return false;
});
$('a.open_html').click(function(){
var qid=$(this).attr('id');
var htmlWindow = window.open('','HTML Window','width=1150,height=600');
var html = '<textarea style="height:100%;width:100%">'+$("#overlay").html().replace('A123A',qid)+'</textarea>';
htmlWindow.document.open();
htmlWindow.document.write(html);
htmlWindow.document.close();
return false;
});
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-32828578-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<? if(!$in_session){ ?>
<div id="top_bar">
<h1 onclick="location.href='http://www.qualturk.com/'">QualTurk</h1>
<span><a href="signup.php" target="_blank" onclick="var w=window.open(this.href,this.target,'width=650,height=550,scrollbars=0'); return w?false:true">sign up</a></span>
</div>
<div id="quote"></div>
<div id="login_form">
<h3>Researcher Login</h3>
<? if($logout==1){ ?>
<div class="success">You have successfully logged out.</div>
<? }elseif($logout==2){ ?>
<div class="error">Your session expired.</div>
<? }elseif($logout==3){ ?>
<div class="success">Password successfully reset.</div>
<? }elseif($logout==4){ ?>
<div class="success">Your account is now activated.</div>
<? }elseif($incorrect){ ?>
<div class="error">Incorrect login details. <a href="forgot_password.php" target="_blank" onclick="var w=window.open(this.href,this.target,'width=650,height=550,scrollbars=0'); return w?false:true">Forgot password?</a></div>
<? } ?>
<form action="/" method="post">
<label for="user"> user</label><input type="text" name="username" value=" user" /><br />
<label for="pwd"> password</label><input type="password" name="pwd" value=" password" /><br />
<input type="submit" name="login" class="subm" value="Login" />
</form>
</div>
<!--
<div id="footer">
<span>support@qualturk.com</span>
</div>
-->
<? } ?>
<? if($in_session){ ?>
<div id="top_bar">
<h1 onclick="location.href='http://www.qualturk.com/'">QualTurk</h1>
<span>Hello, <?=$_SESSION['username']?>! <a href="reset_password.php" target="_blank" onclick="var w=window.open(this.href,this.target,'width=650,height=550,scrollbars=0'); return w?false:true">reset password</a> <a href="?logout=1">logout</a></span>
</div>
<div id="wrapper">
<div id="instructions">
<h2>About QualTurk</h2>
<p>QualTurk helps reduce low-quality survey data by filtering participants based on pre- and post-screening questions. The system is designed to support Amazon's Mechanical Turk in conjunction with Qualtrics.<br /><br />
<em>How it works:</em> MTurk workers are automatically registered by this system and forwarded to your Qualtrics survey. If workers do not pass the screening questions or complete the HIT too quickly, they are redirected to this system and informed that they are now disqualified from taking this survey (if they fail the post-screening, they are told why). Otherwise, if they pass the screening questions and complete the survey, they are redirected to this system to receive a 'completion code' (and optional debrief text). This code enables them to complete the HIT.<br /><br />
<em>What you get:</em> All competed HITs on MTurk are from screened ('good') workers. Responses to your Qualtrics survey are a mixed bag of 'good' and 'bad' work. Process only survey responses from workers with a 'worker ID' 'completion code' combination matching those on your QualTurk account. Reject workers who cannot provide the assigned 'completion code'.
</p>
<h2>Instructions</h2>
<ol id="steps">
<li><p>Add your (launched) Qualtrics survey to your QualTurk account using the form below.</p></li>
<li><p>In MTurk, copy/paste the survey-specific HTML code (1) into the 'Design Layout' box while in 'Edit HTML Source' mode. Switch back to normal viewing mode and change the study time and study description accordingly.</p></li>
<li><p>In Qualtrics, add your own pre-screening block with skip logic at the beginning of the study
(<a href="block_pre.jpg" target="_blank" onclick="var w=window.open(this.href,this.target,'width=1170,height=600,scrollbars=1'); return w?false:true">example</a>).
Add this exact post-screening block at the end of the study (<a href="block_post.jpg" target="_blank" onclick="var w=window.open(this.href,this.target,'width=1170,height=600,scrollbars=1'); return w?false:true">picture</a>, <a href="block_post_text.txt" target="_blank" onclick="var w=window.open(this.href,this.target,'width=1000,height=350,scrollbars=1'); return w?false:true">text</a>) and enable Force Response on both.</p></li>
<li><p>In Qualtrics, open 'Survey Options', in 'Survey Termination' select 'Redirect to a URL' and copy/paste the link (2) that was generated for your survey. Replace xxx, yyy with the post-screening question IDs (xxx for 'How long...?') that can be retrieved using the 'Piped Text...' menu.</p></li>
<li><p>In Qualtrics, open 'Survey Flow', click 'Add Below' and select 'Embedded Data'. Type "workerid" in the yellow box and move the box to the top.</p></li>
<li><p>Release your HITs on MTurk and check the QualTurk records (3) to reject HITs that failed screening (status is not 'done').</p></li>
</ol>
</div>
<div id="item_table">
<h2>Your Surveys</h2>
<?
if($deleted==1){
echo '<div class="error">Survey could not be deleted</div>';
}elseif($deleted==2){
echo '<div class="success">Survey deleted successfully</div>';
}
survey_table($_SESSION['user_id']);
?>
</div>
<div id="add_survey">
<h2>Add Survey</h2>
<? if($added==1){ ?>
<div class="success">Survey added successfully</div>
<? }elseif($added==2){ ?>
<div class="error">Problem with Survey ID and Survey Link. The ID should be part of the link.</div>
<? }elseif($added==3){ ?>
<div class="error">Survey Name, ID, Link and min. HIT completion time are mandatory fields.</div>
<? }elseif($added==4){ ?>
<div class="error">Cannot add survey: duplicate Survey ID</div>
<? }elseif($added==5){ ?>
<div class="error">Min. HIT completion time must be numeric: 0 for off, e.g. 12 for 12min.</div>
<? } ?>
<form action="/" method="post" name="add_form">
<label for="survey_name"> Survey Name (for your reference)</label><input type="text" name="survey_name" value="<?=(isset($_POST['survey_name']))?$_POST['survey_name']:" Survey Name (for your reference)"?>" /><br />
<label for="survey_id"> Qualtrics Survey ID (e.g. SV_bC5L8txgtzoVRNb)</label><input type="text" name="survey_id" value="<?=(isset($_POST['survey_id']))?$_POST['survey_id']:" Qualtrics Survey ID (e.g. SV_bC5L8txgtzoVRNb)"?>" /><br />
<label for="survey_link"> Qualtrics Survey Link (with https://)</label><input type="text" name="survey_link" value="<?=(isset($_POST['survey_link']))?$_POST['survey_link']:" Qualtrics Survey Link (with https://)"?>" /><br />
<label for="min_time"> Minimum HIT completion time (in minutes, 0=off)</label><input type="text" name="min_time" value="<?=(isset($_POST['min_time']))?$_POST['min_time']:" Minimum HIT completion time (in minutes, 0=off)"?>" /><br />
<label for="debrief"> Debrief Text (optional, displayed with completion code)</label><textarea name="debrief"><?=(isset($_POST['debrief']))?$_POST['debrief']:" Debrief Text (optional, displayed with completion code)"?></textarea><br />
<input type="submit" name="add" class="subm" value="Add Survey" />
</form>
</div>
</div>
<div id="footer">
<span>support@qualturk.com</span>
</div>
<div id="overlay">
<p>
<style type="text/css"><!-- .body { font-size: 10pt; font-family: arial, sans-serif; width: 600px; } --> </style>
<script type="text/javascript">
function loader() {
if(urlParam("workerId")==0) {
alert("You must first accept the HIT.");
} else {
var url='http://www.qualturk.com/survey.php?l=c&surveyid=A123A&workerid=' + urlParam("workerId");
window.open(url,"mywindow");
}
}
function urlParam(name) {
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(document.location.href);
if (!results) {
return 0;
}
return results[1] || 0;
}
</script>
</p>
<div class="body"><img src="http://www.emief.com/oc/check.gif" alt="" style="float: right; padding:5px;" />
<h1><font color="#333399">Stanford Study: Announcement</font></h1>
We are researching ABCDEFGHIJKLMN. This HIT is part of a research project at Stanford.<br />
<h3>Confidentiality</h3>
<p>No personally identifiable information will be stored after the study. You will remain completely anonymous.</p>
<h3>Requirements</h3>
<ul><li>Complete a survey</li></ul>
<h3>Eligibility</h3>
<ol><li style="text-align: left;">You have about <b>12345678</b><b> minutes</b> of time right now</li>
<li style="text-align: left;">You must not have completed this HIT before</li> </ol>
<div style="text-align: center;"><input type="button" onClick='loader();' value="Start" name="start" style="height: 30px; width: 150px;" /></div>
</div>
<div class="body" style="text-align: center;"> </div>
<div class="body"><hr />
<h2>Task Confirmation</h2>
<p>After completing the initial survey today you will receive a code to enter below:</p>
<p><input type="text" id="confirmationCode" size="50" name="Q2age" /></p>
<p>Thank you very much for your participation!</p>
</div> <p> </p>
</div>
<? } ?>
</body>
</html>